smdk2410_lcd.c revision 1.9 1 /* $NetBSD: smdk2410_lcd.c,v 1.9 2014/03/16 05:20:24 dholland 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.9 2014/03/16 05:20:24 dholland 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(device_t, cfdata_t, void *);
67 void lcd_attach(device_t, device_t, 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 .d_open = lcdopen,
164 .d_close = lcdclose,
165 .d_read = noread,
166 .d_write = nowrite,
167 .d_ioctl = lcdioctl,
168 .d_stop = nostop,
169 .d_tty = notty,
170 .d_poll = nopoll,
171 .d_mmap = lcdmmap,
172 .d_kqfilter = nokqfilter,
173 .d_flag = D_TTY
174 };
175
176 #endif /* NWSDISPLAY */
177
178 CFATTACH_DECL_NEW(lcd_ssio, sizeof (struct s3c24x0_lcd_softc), lcd_match,
179 lcd_attach, NULL, NULL);
180
181 int
182 lcd_match(device_t parent, cfdata_t cf, void *aux)
183 {
184 struct s3c2xx0_attach_args *sa = aux;
185
186 if (sa->sa_addr == SSIOCF_ADDR_DEFAULT)
187 sa->sa_addr = S3C2410_LCDC_BASE;
188
189 return 1;
190 }
191
192 static const struct s3c24x0_lcd_panel_info samsung_LTS350Q1 =
193 {
194 240, /* Width */
195 320, /* Height */
196 10*1000*1000, /* pixel clock = 10MHz */
197
198 #define _(field, val) (((val)-1) << (field##_SHIFT))
199
200 LCDCON1_PNRMODE_TFT,
201
202 /* LCDCON2: vertical timings */
203 _(LCDCON2_VBPD, 2) |
204 _(LCDCON2_VFPD, 3) |
205 _(LCDCON2_LINEVAL, 320) |
206 _(LCDCON2_VPSW, 2),
207
208 /* LCDCON3: horizontal timings */
209 _(LCDCON3_HBPD, 7) |
210 _(LCDCON3_HFPD, 3),
211
212 /* LCDCON4: horizontaol pulse width */
213 _(LCDCON4_HPSW, 4),
214
215 /* LCDCON5: signal polarities */
216 LCDCON5_FRM565 | LCDCON5_INVVLINE | LCDCON5_INVVFRAME,
217
218 /* LPCSEL register */
219 LPCSEL_LPC_EN | LPCSEL_RES_SEL | LPCSEL_MODE_SEL,
220 #undef _
221 };
222
223 void
224 lcd_attach(device_t parent, device_t self, void *aux)
225 {
226 struct s3c24x0_lcd_softc *sc = device_private(self);
227 bus_space_tag_t iot = s3c2xx0_softc->sc_iot;
228 bus_space_handle_t gpio_ioh = s3c2xx0_softc->sc_gpio_ioh;
229 #if NWSDISPLAY > 0
230 struct wsemuldisplaydev_attach_args aa;
231 #else
232 struct s3c24x0_lcd_screen *screen;
233 #endif
234
235
236 sc->sc_dev = self;
237 aprint_normal( "\n" );
238
239 /* setup GPIO ports for LCD */
240 /* XXX: some LCD panels may not need all VD signals */
241 gpio_ioh = s3c2xx0_softc->sc_gpio_ioh;
242 bus_space_write_4(iot, gpio_ioh, GPIO_PCUP, ~0);
243 bus_space_write_4(iot, gpio_ioh, GPIO_PCCON, 0xaaaaaaaa);
244 bus_space_write_4(iot, gpio_ioh, GPIO_PDUP, ~0);
245 bus_space_write_4(iot, gpio_ioh, GPIO_PDCON, 0xaaaaaaaa);
246
247 s3c24x0_lcd_attach_sub(sc, aux, &samsung_LTS350Q1);
248
249 #if NWSDISPLAY > 0
250
251 aa.console = 0;
252 aa.scrdata = &lcd_screen_list;
253 aa.accessops = &lcd_accessops;
254 aa.accesscookie = sc;
255
256
257 (void) config_found(self, &aa, wsemuldisplaydevprint);
258 #else
259
260 screen = s3c24x0_lcd_new_screen(sc, 240, 320, 16);
261
262 if( screen ){
263 sc->active = screen;
264 s3c24x0_lcd_start_dma(sc, screen);
265 s3c24x0_lcd_power(sc, 1);
266 }
267 #endif /* NWSDISPLAY */
268
269 }
270
271 #if NWSDISPLAY == 0
272
273 int
274 lcdopen( dev_t dev, int oflags, int devtype, struct proc *p )
275 {
276 return 0;
277 }
278
279 int
280 lcdclose( dev_t dev, int fflag, int devtype, struct proc *p )
281 {
282 return 0;
283 }
284
285 paddr_t
286 lcdmmap( dev_t dev, off_t offset, int size )
287 {
288 struct s3c24x0_lcd_softc *sc =
289 device_lookup_private(&lcd_cd, minor(dev));
290 struct s3c24x0_lcd_screen *scr = sc->active;
291
292 return bus_dmamem_mmap(sc->dma_tag, scr->segs, scr->nsegs,
293 offset, 0, BUS_DMA_WAITOK|BUS_DMA_COHERENT);
294 }
295
296 int
297 lcdioctl( dev_t dev, u_long cmd, void *data,
298 int fflag, struct lwp *l )
299 {
300 return EOPNOTSUPP;
301 }
302
303 #endif /* NWSDISPLAY>0 */
304
305 #ifdef LCD_DEBUG
306 static void
307 draw_test_pattern_16(struct s3c24x0_lcd_softc *sc,
308 struct s3c24x0_lcd_screen *scr)
309 {
310 int x, y;
311 uint16_t color, *line;
312 char *buf = (char *)(scr->buf_va);
313
314 #define rgb(r,g,b) (((r)<<11) | ((g)<<5) | (b))
315
316 for (y=0; y < sc->panel_info->panel_height; ++y) {
317 line = (uint16_t *)(buf + scr->stride * y);
318
319 for (x=0; x < sc->panel_info->panel_width; ++x) {
320 switch (((x/30) + (y/10)) % 8) {
321 default:
322 case 0: color = rgb(0x00, 0x00, 0x00); break;
323 case 1: color = rgb(0x00, 0x00, 0x1f); break;
324 case 2: color = rgb(0x00, 0x3f, 0x00); break;
325 case 3: color = rgb(0x00, 0x3f, 0x1f); break;
326 case 4: color = rgb(0x1f, 0x00, 0x00); break;
327 case 5: color = rgb(0x1f, 0x00, 0x1f); break;
328 case 6: color = rgb(0x1f, 0x3f, 0x00); break;
329 case 7: color = rgb(0x1f, 0x3f, 0x1f); break;
330 }
331
332 line[x] = color;
333 }
334 }
335
336 for (x=0; x < MIN(sc->panel_info->panel_height,
337 sc->panel_info->panel_width); ++x) {
338
339 line = (uint16_t *)(buf + scr->stride * x);
340 line[x] = rgb(0x1f, 0x3f, 0x1f);
341 }
342 }
343
344 static void
345 draw_test_pattern_8(struct s3c24x0_lcd_softc *sc,
346 struct s3c24x0_lcd_screen *scr)
347 {
348 int x, y;
349 uint8_t *line;
350 char *buf = (char *)(scr->buf_va);
351
352
353 for (y=0; y < sc->panel_info->panel_height; ++y) {
354 line = (uint8_t *)(buf + scr->stride * y);
355
356 for (x=0; x < sc->panel_info->panel_width; ++x) {
357 line[x] = (((x/15) + (y/20)) % 16);
358 }
359 }
360
361 for (x=0; x < MIN(sc->panel_info->panel_height,
362 sc->panel_info->panel_width); ++x) {
363
364 line = (uint8_t *)(buf + scr->stride * x);
365 line[x] = 7;
366 }
367 }
368
369
370 void
371 draw_test_pattern(struct s3c24x0_lcd_softc *sc, struct s3c24x0_lcd_screen *scr)
372 {
373 switch (scr->depth) {
374 case 16:
375 draw_test_pattern_16(sc, scr);
376 break;
377 case 8:
378 draw_test_pattern_8(sc, scr);
379 break;
380 }
381 }
382
383
384 #endif /* LCD_DEBUG */
385
386