smdk2410_lcd.c revision 1.8 1 1.8 chs /* $NetBSD: smdk2410_lcd.c,v 1.8 2012/10/27 17:17:49 chs Exp $ */
2 1.1 bsh
3 1.1 bsh /*
4 1.1 bsh * Copyright (c) 2004 Genetec Corporation. All rights reserved.
5 1.1 bsh * Written by Hiroyuki Bessho for Genetec Corporation.
6 1.1 bsh *
7 1.1 bsh * Redistribution and use in source and binary forms, with or without
8 1.1 bsh * modification, are permitted provided that the following conditions
9 1.1 bsh * are met:
10 1.1 bsh * 1. Redistributions of source code must retain the above copyright
11 1.1 bsh * notice, this list of conditions and the following disclaimer.
12 1.1 bsh * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 bsh * notice, this list of conditions and the following disclaimer in the
14 1.1 bsh * documentation and/or other materials provided with the distribution.
15 1.1 bsh * 3. The name of Genetec Corporation may not be used to endorse or
16 1.1 bsh * promote products derived from this software without specific prior
17 1.1 bsh * written permission.
18 1.1 bsh *
19 1.1 bsh * THIS SOFTWARE IS PROVIDED BY GENETEC CORPORATION ``AS IS'' AND
20 1.1 bsh * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.1 bsh * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.1 bsh * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL GENETEC CORPORATION
23 1.1 bsh * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.1 bsh * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.1 bsh * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.1 bsh * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.1 bsh * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.1 bsh * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.1 bsh * POSSIBILITY OF SUCH DAMAGE.
30 1.1 bsh *
31 1.1 bsh */
32 1.1 bsh
33 1.1 bsh #include <sys/cdefs.h>
34 1.8 chs __KERNEL_RCSID(0, "$NetBSD: smdk2410_lcd.c,v 1.8 2012/10/27 17:17:49 chs Exp $");
35 1.1 bsh
36 1.1 bsh /*
37 1.1 bsh * LCD driver for Samsung SMDK2410.
38 1.1 bsh *
39 1.1 bsh * Controlling LCD is almost completely done through S3C2410's
40 1.1 bsh * integrated LCD controller. Codes for it is arm/s3c2xx0/s3c24x0_lcd.c.
41 1.1 bsh *
42 1.1 bsh * Codes in this file provide the platform's LCD panel information.
43 1.1 bsh */
44 1.1 bsh
45 1.1 bsh #include <sys/param.h>
46 1.1 bsh #include <sys/systm.h>
47 1.1 bsh #include <sys/conf.h>
48 1.1 bsh #include <sys/event.h>
49 1.1 bsh #include <sys/uio.h>
50 1.1 bsh #include <sys/malloc.h>
51 1.1 bsh
52 1.1 bsh #include <dev/cons.h>
53 1.1 bsh #include <dev/wscons/wsconsio.h>
54 1.1 bsh #include <dev/wscons/wsdisplayvar.h>
55 1.1 bsh #include <dev/wscons/wscons_callbacks.h>
56 1.1 bsh
57 1.6 dyoung #include <sys/bus.h>
58 1.1 bsh #include <arm/s3c2xx0/s3c24x0var.h>
59 1.1 bsh #include <arm/s3c2xx0/s3c24x0reg.h>
60 1.1 bsh #include <arm/s3c2xx0/s3c2410reg.h>
61 1.1 bsh #include <arm/s3c2xx0/s3c24x0_lcd.h>
62 1.1 bsh
63 1.5 snj #include "locators.h"
64 1.1 bsh #include "wsdisplay.h"
65 1.1 bsh
66 1.8 chs int lcd_match(device_t, cfdata_t, void *);
67 1.8 chs void lcd_attach(device_t, device_t, void *);
68 1.1 bsh
69 1.1 bsh #ifdef LCD_DEBUG
70 1.1 bsh void draw_test_pattern(struct s3c24x0_lcd_softc *,
71 1.1 bsh struct s3c24x0_lcd_screen *scr);
72 1.1 bsh #endif
73 1.1 bsh
74 1.1 bsh #if NWSDISPLAY > 0
75 1.1 bsh
76 1.1 bsh /*
77 1.1 bsh * Screen geometries.
78 1.1 bsh *
79 1.1 bsh * S3C24x0's LCD controller can have virtual screens that are bigger
80 1.1 bsh * than actual LCD panel. (XXX: wscons can't manage such screens for now)
81 1.1 bsh */
82 1.1 bsh struct s3c24x0_wsscreen_descr lcd_bpp16_30x32 = {
83 1.1 bsh {
84 1.1 bsh "30x32bpp16", 30, 32,
85 1.1 bsh &s3c24x0_lcd_emulops,
86 1.1 bsh 8, 10,
87 1.1 bsh WSSCREEN_WSCOLORS,
88 1.1 bsh },
89 1.1 bsh 16 /* bits per pixel */
90 1.1 bsh }, lcd_bpp16_30x20 = {
91 1.1 bsh {
92 1.1 bsh "30x20bpp16", 30, 20,
93 1.1 bsh &s3c24x0_lcd_emulops,
94 1.1 bsh 8, 16,
95 1.1 bsh WSSCREEN_WSCOLORS,
96 1.1 bsh },
97 1.1 bsh 16
98 1.1 bsh }, lcd_bpp8_30x32 = {
99 1.1 bsh {
100 1.1 bsh "30x32bpp8", 30, 32,
101 1.1 bsh &s3c24x0_lcd_emulops,
102 1.1 bsh 8, 10,
103 1.1 bsh WSSCREEN_WSCOLORS,
104 1.1 bsh },
105 1.1 bsh 8
106 1.1 bsh }, lcd_bpp8_40x25 = { /* with big virtual screen */
107 1.1 bsh {
108 1.1 bsh "40x25bpp8", 40, 25,
109 1.1 bsh &s3c24x0_lcd_emulops,
110 1.1 bsh 8, 16,
111 1.1 bsh WSSCREEN_WSCOLORS,
112 1.1 bsh },
113 1.1 bsh 8
114 1.1 bsh }, lcd_bpp4_30x32 = {
115 1.1 bsh {
116 1.1 bsh "30x32bpp4", 30, 32,
117 1.1 bsh &s3c24x0_lcd_emulops,
118 1.1 bsh 8, 10,
119 1.1 bsh 0, /* 4bpp mode is grayscale */
120 1.1 bsh },
121 1.1 bsh 4
122 1.1 bsh };
123 1.1 bsh
124 1.1 bsh
125 1.1 bsh static const struct wsscreen_descr *lcd_scr_descr[] = {
126 1.1 bsh #if 0
127 1.1 bsh /* bpp4 needs a patch to rasops4 */
128 1.1 bsh &lcd_bpp4_30x32.c,
129 1.1 bsh #endif
130 1.1 bsh &lcd_bpp8_30x32.c,
131 1.1 bsh &lcd_bpp8_40x25.c,
132 1.1 bsh &lcd_bpp16_30x32.c,
133 1.1 bsh &lcd_bpp16_30x20.c,
134 1.1 bsh };
135 1.1 bsh
136 1.1 bsh #define N_SCR_DESCR (sizeof lcd_scr_descr / sizeof lcd_scr_descr[0])
137 1.1 bsh
138 1.1 bsh const struct wsscreen_list lcd_screen_list = {
139 1.1 bsh N_SCR_DESCR,
140 1.1 bsh lcd_scr_descr
141 1.1 bsh };
142 1.1 bsh
143 1.1 bsh const struct wsdisplay_accessops lcd_accessops = {
144 1.1 bsh s3c24x0_lcd_ioctl,
145 1.1 bsh s3c24x0_lcd_mmap,
146 1.1 bsh s3c24x0_lcd_alloc_screen,
147 1.1 bsh s3c24x0_lcd_free_screen,
148 1.1 bsh s3c24x0_lcd_show_screen,
149 1.1 bsh NULL, /* load_font */
150 1.1 bsh };
151 1.1 bsh
152 1.1 bsh #else /* NWSDISPLAY */
153 1.1 bsh /*
154 1.1 bsh * Interface to LCD framebuffer without wscons
155 1.1 bsh */
156 1.1 bsh extern struct cfdriver lcd_cd;
157 1.1 bsh
158 1.1 bsh dev_type_open(lcdopen);
159 1.1 bsh dev_type_close(lcdclose);
160 1.1 bsh dev_type_ioctl(lcdioctl);
161 1.1 bsh dev_type_mmap(lcdmmap);
162 1.1 bsh const struct cdevsw lcd_cdevsw = {
163 1.1 bsh lcdopen, lcdclose, noread, nowrite, lcdioctl,
164 1.1 bsh nostop, notty, nopoll, lcdmmap, nokqfilter, D_TTY
165 1.1 bsh };
166 1.1 bsh
167 1.1 bsh #endif /* NWSDISPLAY */
168 1.1 bsh
169 1.7 nisimura CFATTACH_DECL_NEW(lcd_ssio, sizeof (struct s3c24x0_lcd_softc), lcd_match,
170 1.1 bsh lcd_attach, NULL, NULL);
171 1.1 bsh
172 1.1 bsh int
173 1.8 chs lcd_match(device_t parent, cfdata_t cf, void *aux)
174 1.1 bsh {
175 1.1 bsh struct s3c2xx0_attach_args *sa = aux;
176 1.1 bsh
177 1.1 bsh if (sa->sa_addr == SSIOCF_ADDR_DEFAULT)
178 1.1 bsh sa->sa_addr = S3C2410_LCDC_BASE;
179 1.1 bsh
180 1.1 bsh return 1;
181 1.1 bsh }
182 1.1 bsh
183 1.1 bsh static const struct s3c24x0_lcd_panel_info samsung_LTS350Q1 =
184 1.1 bsh {
185 1.1 bsh 240, /* Width */
186 1.1 bsh 320, /* Height */
187 1.1 bsh 10*1000*1000, /* pixel clock = 10MHz */
188 1.1 bsh
189 1.1 bsh #define _(field, val) (((val)-1) << (field##_SHIFT))
190 1.1 bsh
191 1.1 bsh LCDCON1_PNRMODE_TFT,
192 1.1 bsh
193 1.1 bsh /* LCDCON2: vertical timings */
194 1.1 bsh _(LCDCON2_VBPD, 2) |
195 1.1 bsh _(LCDCON2_VFPD, 3) |
196 1.1 bsh _(LCDCON2_LINEVAL, 320) |
197 1.1 bsh _(LCDCON2_VPSW, 2),
198 1.1 bsh
199 1.1 bsh /* LCDCON3: horizontal timings */
200 1.1 bsh _(LCDCON3_HBPD, 7) |
201 1.1 bsh _(LCDCON3_HFPD, 3),
202 1.1 bsh
203 1.1 bsh /* LCDCON4: horizontaol pulse width */
204 1.1 bsh _(LCDCON4_HPSW, 4),
205 1.1 bsh
206 1.1 bsh /* LCDCON5: signal polarities */
207 1.1 bsh LCDCON5_FRM565 | LCDCON5_INVVLINE | LCDCON5_INVVFRAME,
208 1.1 bsh
209 1.1 bsh /* LPCSEL register */
210 1.1 bsh LPCSEL_LPC_EN | LPCSEL_RES_SEL | LPCSEL_MODE_SEL,
211 1.1 bsh #undef _
212 1.1 bsh };
213 1.1 bsh
214 1.1 bsh void
215 1.8 chs lcd_attach(device_t parent, device_t self, void *aux)
216 1.1 bsh {
217 1.7 nisimura struct s3c24x0_lcd_softc *sc = device_private(self);
218 1.1 bsh bus_space_tag_t iot = s3c2xx0_softc->sc_iot;
219 1.1 bsh bus_space_handle_t gpio_ioh = s3c2xx0_softc->sc_gpio_ioh;
220 1.1 bsh #if NWSDISPLAY > 0
221 1.1 bsh struct wsemuldisplaydev_attach_args aa;
222 1.1 bsh #else
223 1.1 bsh struct s3c24x0_lcd_screen *screen;
224 1.1 bsh #endif
225 1.1 bsh
226 1.1 bsh
227 1.7 nisimura sc->sc_dev = self;
228 1.1 bsh aprint_normal( "\n" );
229 1.1 bsh
230 1.1 bsh /* setup GPIO ports for LCD */
231 1.1 bsh /* XXX: some LCD panels may not need all VD signals */
232 1.1 bsh gpio_ioh = s3c2xx0_softc->sc_gpio_ioh;
233 1.1 bsh bus_space_write_4(iot, gpio_ioh, GPIO_PCUP, ~0);
234 1.1 bsh bus_space_write_4(iot, gpio_ioh, GPIO_PCCON, 0xaaaaaaaa);
235 1.1 bsh bus_space_write_4(iot, gpio_ioh, GPIO_PDUP, ~0);
236 1.1 bsh bus_space_write_4(iot, gpio_ioh, GPIO_PDCON, 0xaaaaaaaa);
237 1.1 bsh
238 1.1 bsh s3c24x0_lcd_attach_sub(sc, aux, &samsung_LTS350Q1);
239 1.1 bsh
240 1.1 bsh #if NWSDISPLAY > 0
241 1.1 bsh
242 1.1 bsh aa.console = 0;
243 1.1 bsh aa.scrdata = &lcd_screen_list;
244 1.1 bsh aa.accessops = &lcd_accessops;
245 1.1 bsh aa.accesscookie = sc;
246 1.1 bsh
247 1.1 bsh
248 1.1 bsh (void) config_found(self, &aa, wsemuldisplaydevprint);
249 1.1 bsh #else
250 1.1 bsh
251 1.1 bsh screen = s3c24x0_lcd_new_screen(sc, 240, 320, 16);
252 1.1 bsh
253 1.1 bsh if( screen ){
254 1.1 bsh sc->active = screen;
255 1.1 bsh s3c24x0_lcd_start_dma(sc, screen);
256 1.1 bsh s3c24x0_lcd_power(sc, 1);
257 1.1 bsh }
258 1.1 bsh #endif /* NWSDISPLAY */
259 1.1 bsh
260 1.1 bsh }
261 1.1 bsh
262 1.1 bsh #if NWSDISPLAY == 0
263 1.1 bsh
264 1.1 bsh int
265 1.1 bsh lcdopen( dev_t dev, int oflags, int devtype, struct proc *p )
266 1.1 bsh {
267 1.1 bsh return 0;
268 1.1 bsh }
269 1.1 bsh
270 1.1 bsh int
271 1.1 bsh lcdclose( dev_t dev, int fflag, int devtype, struct proc *p )
272 1.1 bsh {
273 1.1 bsh return 0;
274 1.1 bsh }
275 1.1 bsh
276 1.1 bsh paddr_t
277 1.1 bsh lcdmmap( dev_t dev, off_t offset, int size )
278 1.1 bsh {
279 1.4 cegger struct s3c24x0_lcd_softc *sc =
280 1.4 cegger device_lookup_private(&lcd_cd, minor(dev));
281 1.1 bsh struct s3c24x0_lcd_screen *scr = sc->active;
282 1.1 bsh
283 1.1 bsh return bus_dmamem_mmap(sc->dma_tag, scr->segs, scr->nsegs,
284 1.1 bsh offset, 0, BUS_DMA_WAITOK|BUS_DMA_COHERENT);
285 1.1 bsh }
286 1.1 bsh
287 1.1 bsh int
288 1.3 christos lcdioctl( dev_t dev, u_long cmd, void *data,
289 1.2 christos int fflag, struct lwp *l )
290 1.1 bsh {
291 1.1 bsh return EOPNOTSUPP;
292 1.1 bsh }
293 1.1 bsh
294 1.1 bsh #endif /* NWSDISPLAY>0 */
295 1.1 bsh
296 1.1 bsh #ifdef LCD_DEBUG
297 1.1 bsh static void
298 1.1 bsh draw_test_pattern_16(struct s3c24x0_lcd_softc *sc,
299 1.1 bsh struct s3c24x0_lcd_screen *scr)
300 1.1 bsh {
301 1.1 bsh int x, y;
302 1.1 bsh uint16_t color, *line;
303 1.1 bsh char *buf = (char *)(scr->buf_va);
304 1.1 bsh
305 1.1 bsh #define rgb(r,g,b) (((r)<<11) | ((g)<<5) | (b))
306 1.1 bsh
307 1.1 bsh for (y=0; y < sc->panel_info->panel_height; ++y) {
308 1.1 bsh line = (uint16_t *)(buf + scr->stride * y);
309 1.1 bsh
310 1.1 bsh for (x=0; x < sc->panel_info->panel_width; ++x) {
311 1.1 bsh switch (((x/30) + (y/10)) % 8) {
312 1.1 bsh default:
313 1.1 bsh case 0: color = rgb(0x00, 0x00, 0x00); break;
314 1.1 bsh case 1: color = rgb(0x00, 0x00, 0x1f); break;
315 1.1 bsh case 2: color = rgb(0x00, 0x3f, 0x00); break;
316 1.1 bsh case 3: color = rgb(0x00, 0x3f, 0x1f); break;
317 1.1 bsh case 4: color = rgb(0x1f, 0x00, 0x00); break;
318 1.1 bsh case 5: color = rgb(0x1f, 0x00, 0x1f); break;
319 1.1 bsh case 6: color = rgb(0x1f, 0x3f, 0x00); break;
320 1.1 bsh case 7: color = rgb(0x1f, 0x3f, 0x1f); break;
321 1.1 bsh }
322 1.1 bsh
323 1.1 bsh line[x] = color;
324 1.1 bsh }
325 1.1 bsh }
326 1.1 bsh
327 1.1 bsh for (x=0; x < MIN(sc->panel_info->panel_height,
328 1.1 bsh sc->panel_info->panel_width); ++x) {
329 1.1 bsh
330 1.1 bsh line = (uint16_t *)(buf + scr->stride * x);
331 1.1 bsh line[x] = rgb(0x1f, 0x3f, 0x1f);
332 1.1 bsh }
333 1.1 bsh }
334 1.1 bsh
335 1.1 bsh static void
336 1.1 bsh draw_test_pattern_8(struct s3c24x0_lcd_softc *sc,
337 1.1 bsh struct s3c24x0_lcd_screen *scr)
338 1.1 bsh {
339 1.1 bsh int x, y;
340 1.1 bsh uint8_t *line;
341 1.1 bsh char *buf = (char *)(scr->buf_va);
342 1.1 bsh
343 1.1 bsh
344 1.1 bsh for (y=0; y < sc->panel_info->panel_height; ++y) {
345 1.1 bsh line = (uint8_t *)(buf + scr->stride * y);
346 1.1 bsh
347 1.1 bsh for (x=0; x < sc->panel_info->panel_width; ++x) {
348 1.1 bsh line[x] = (((x/15) + (y/20)) % 16);
349 1.1 bsh }
350 1.1 bsh }
351 1.1 bsh
352 1.1 bsh for (x=0; x < MIN(sc->panel_info->panel_height,
353 1.1 bsh sc->panel_info->panel_width); ++x) {
354 1.1 bsh
355 1.1 bsh line = (uint8_t *)(buf + scr->stride * x);
356 1.1 bsh line[x] = 7;
357 1.1 bsh }
358 1.1 bsh }
359 1.1 bsh
360 1.1 bsh
361 1.1 bsh void
362 1.1 bsh draw_test_pattern(struct s3c24x0_lcd_softc *sc, struct s3c24x0_lcd_screen *scr)
363 1.1 bsh {
364 1.1 bsh switch (scr->depth) {
365 1.1 bsh case 16:
366 1.1 bsh draw_test_pattern_16(sc, scr);
367 1.1 bsh break;
368 1.1 bsh case 8:
369 1.1 bsh draw_test_pattern_8(sc, scr);
370 1.1 bsh break;
371 1.1 bsh }
372 1.1 bsh }
373 1.1 bsh
374 1.1 bsh
375 1.1 bsh #endif /* LCD_DEBUG */
376 1.1 bsh
377