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