smdk2410_lcd.c revision 1.6.2.1 1 /* $NetBSD: smdk2410_lcd.c,v 1.6.2.1 2012/04/17 00:06:15 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.6.2.1 2012/04/17 00:06:15 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 <sys/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_NEW(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 = device_private(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 sc->sc_dev = self;
228 aprint_normal( "\n" );
229
230 /* setup GPIO ports for LCD */
231 /* XXX: some LCD panels may not need all VD signals */
232 gpio_ioh = s3c2xx0_softc->sc_gpio_ioh;
233 bus_space_write_4(iot, gpio_ioh, GPIO_PCUP, ~0);
234 bus_space_write_4(iot, gpio_ioh, GPIO_PCCON, 0xaaaaaaaa);
235 bus_space_write_4(iot, gpio_ioh, GPIO_PDUP, ~0);
236 bus_space_write_4(iot, gpio_ioh, GPIO_PDCON, 0xaaaaaaaa);
237
238 s3c24x0_lcd_attach_sub(sc, aux, &samsung_LTS350Q1);
239
240 #if NWSDISPLAY > 0
241
242 aa.console = 0;
243 aa.scrdata = &lcd_screen_list;
244 aa.accessops = &lcd_accessops;
245 aa.accesscookie = sc;
246
247
248 (void) config_found(self, &aa, wsemuldisplaydevprint);
249 #else
250
251 screen = s3c24x0_lcd_new_screen(sc, 240, 320, 16);
252
253 if( screen ){
254 sc->active = screen;
255 s3c24x0_lcd_start_dma(sc, screen);
256 s3c24x0_lcd_power(sc, 1);
257 }
258 #endif /* NWSDISPLAY */
259
260 }
261
262 #if NWSDISPLAY == 0
263
264 int
265 lcdopen( dev_t dev, int oflags, int devtype, struct proc *p )
266 {
267 return 0;
268 }
269
270 int
271 lcdclose( dev_t dev, int fflag, int devtype, struct proc *p )
272 {
273 return 0;
274 }
275
276 paddr_t
277 lcdmmap( dev_t dev, off_t offset, int size )
278 {
279 struct s3c24x0_lcd_softc *sc =
280 device_lookup_private(&lcd_cd, minor(dev));
281 struct s3c24x0_lcd_screen *scr = sc->active;
282
283 return bus_dmamem_mmap(sc->dma_tag, scr->segs, scr->nsegs,
284 offset, 0, BUS_DMA_WAITOK|BUS_DMA_COHERENT);
285 }
286
287 int
288 lcdioctl( dev_t dev, u_long cmd, void *data,
289 int fflag, struct lwp *l )
290 {
291 return EOPNOTSUPP;
292 }
293
294 #endif /* NWSDISPLAY>0 */
295
296 #ifdef LCD_DEBUG
297 static void
298 draw_test_pattern_16(struct s3c24x0_lcd_softc *sc,
299 struct s3c24x0_lcd_screen *scr)
300 {
301 int x, y;
302 uint16_t color, *line;
303 char *buf = (char *)(scr->buf_va);
304
305 #define rgb(r,g,b) (((r)<<11) | ((g)<<5) | (b))
306
307 for (y=0; y < sc->panel_info->panel_height; ++y) {
308 line = (uint16_t *)(buf + scr->stride * y);
309
310 for (x=0; x < sc->panel_info->panel_width; ++x) {
311 switch (((x/30) + (y/10)) % 8) {
312 default:
313 case 0: color = rgb(0x00, 0x00, 0x00); break;
314 case 1: color = rgb(0x00, 0x00, 0x1f); break;
315 case 2: color = rgb(0x00, 0x3f, 0x00); break;
316 case 3: color = rgb(0x00, 0x3f, 0x1f); break;
317 case 4: color = rgb(0x1f, 0x00, 0x00); break;
318 case 5: color = rgb(0x1f, 0x00, 0x1f); break;
319 case 6: color = rgb(0x1f, 0x3f, 0x00); break;
320 case 7: color = rgb(0x1f, 0x3f, 0x1f); break;
321 }
322
323 line[x] = color;
324 }
325 }
326
327 for (x=0; x < MIN(sc->panel_info->panel_height,
328 sc->panel_info->panel_width); ++x) {
329
330 line = (uint16_t *)(buf + scr->stride * x);
331 line[x] = rgb(0x1f, 0x3f, 0x1f);
332 }
333 }
334
335 static void
336 draw_test_pattern_8(struct s3c24x0_lcd_softc *sc,
337 struct s3c24x0_lcd_screen *scr)
338 {
339 int x, y;
340 uint8_t *line;
341 char *buf = (char *)(scr->buf_va);
342
343
344 for (y=0; y < sc->panel_info->panel_height; ++y) {
345 line = (uint8_t *)(buf + scr->stride * y);
346
347 for (x=0; x < sc->panel_info->panel_width; ++x) {
348 line[x] = (((x/15) + (y/20)) % 16);
349 }
350 }
351
352 for (x=0; x < MIN(sc->panel_info->panel_height,
353 sc->panel_info->panel_width); ++x) {
354
355 line = (uint8_t *)(buf + scr->stride * x);
356 line[x] = 7;
357 }
358 }
359
360
361 void
362 draw_test_pattern(struct s3c24x0_lcd_softc *sc, struct s3c24x0_lcd_screen *scr)
363 {
364 switch (scr->depth) {
365 case 16:
366 draw_test_pattern_16(sc, scr);
367 break;
368 case 8:
369 draw_test_pattern_8(sc, scr);
370 break;
371 }
372 }
373
374
375 #endif /* LCD_DEBUG */
376
377