smdk2410_lcd.c revision 1.4 1 1.4 cegger /* $NetBSD: smdk2410_lcd.c,v 1.4 2008/06/11 23:24:43 cegger 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.4 cegger __KERNEL_RCSID(0, "$NetBSD: smdk2410_lcd.c,v 1.4 2008/06/11 23:24:43 cegger 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.1 bsh #include <machine/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.1 bsh #include "wsdisplay.h"
64 1.1 bsh
65 1.1 bsh int lcd_match(struct device *, struct cfdata *, void *);
66 1.1 bsh void lcd_attach(struct device *, struct device *, void *);
67 1.1 bsh
68 1.1 bsh #ifdef LCD_DEBUG
69 1.1 bsh void draw_test_pattern(struct s3c24x0_lcd_softc *,
70 1.1 bsh struct s3c24x0_lcd_screen *scr);
71 1.1 bsh #endif
72 1.1 bsh
73 1.1 bsh #if NWSDISPLAY > 0
74 1.1 bsh
75 1.1 bsh /*
76 1.1 bsh * Screen geometries.
77 1.1 bsh *
78 1.1 bsh * S3C24x0's LCD controller can have virtual screens that are bigger
79 1.1 bsh * than actual LCD panel. (XXX: wscons can't manage such screens for now)
80 1.1 bsh */
81 1.1 bsh struct s3c24x0_wsscreen_descr lcd_bpp16_30x32 = {
82 1.1 bsh {
83 1.1 bsh "30x32bpp16", 30, 32,
84 1.1 bsh &s3c24x0_lcd_emulops,
85 1.1 bsh 8, 10,
86 1.1 bsh WSSCREEN_WSCOLORS,
87 1.1 bsh },
88 1.1 bsh 16 /* bits per pixel */
89 1.1 bsh }, lcd_bpp16_30x20 = {
90 1.1 bsh {
91 1.1 bsh "30x20bpp16", 30, 20,
92 1.1 bsh &s3c24x0_lcd_emulops,
93 1.1 bsh 8, 16,
94 1.1 bsh WSSCREEN_WSCOLORS,
95 1.1 bsh },
96 1.1 bsh 16
97 1.1 bsh }, lcd_bpp8_30x32 = {
98 1.1 bsh {
99 1.1 bsh "30x32bpp8", 30, 32,
100 1.1 bsh &s3c24x0_lcd_emulops,
101 1.1 bsh 8, 10,
102 1.1 bsh WSSCREEN_WSCOLORS,
103 1.1 bsh },
104 1.1 bsh 8
105 1.1 bsh }, lcd_bpp8_40x25 = { /* with big virtual screen */
106 1.1 bsh {
107 1.1 bsh "40x25bpp8", 40, 25,
108 1.1 bsh &s3c24x0_lcd_emulops,
109 1.1 bsh 8, 16,
110 1.1 bsh WSSCREEN_WSCOLORS,
111 1.1 bsh },
112 1.1 bsh 8
113 1.1 bsh }, lcd_bpp4_30x32 = {
114 1.1 bsh {
115 1.1 bsh "30x32bpp4", 30, 32,
116 1.1 bsh &s3c24x0_lcd_emulops,
117 1.1 bsh 8, 10,
118 1.1 bsh 0, /* 4bpp mode is grayscale */
119 1.1 bsh },
120 1.1 bsh 4
121 1.1 bsh };
122 1.1 bsh
123 1.1 bsh
124 1.1 bsh static const struct wsscreen_descr *lcd_scr_descr[] = {
125 1.1 bsh #if 0
126 1.1 bsh /* bpp4 needs a patch to rasops4 */
127 1.1 bsh &lcd_bpp4_30x32.c,
128 1.1 bsh #endif
129 1.1 bsh &lcd_bpp8_30x32.c,
130 1.1 bsh &lcd_bpp8_40x25.c,
131 1.1 bsh &lcd_bpp16_30x32.c,
132 1.1 bsh &lcd_bpp16_30x20.c,
133 1.1 bsh };
134 1.1 bsh
135 1.1 bsh #define N_SCR_DESCR (sizeof lcd_scr_descr / sizeof lcd_scr_descr[0])
136 1.1 bsh
137 1.1 bsh const struct wsscreen_list lcd_screen_list = {
138 1.1 bsh N_SCR_DESCR,
139 1.1 bsh lcd_scr_descr
140 1.1 bsh };
141 1.1 bsh
142 1.1 bsh const struct wsdisplay_accessops lcd_accessops = {
143 1.1 bsh s3c24x0_lcd_ioctl,
144 1.1 bsh s3c24x0_lcd_mmap,
145 1.1 bsh s3c24x0_lcd_alloc_screen,
146 1.1 bsh s3c24x0_lcd_free_screen,
147 1.1 bsh s3c24x0_lcd_show_screen,
148 1.1 bsh NULL, /* load_font */
149 1.1 bsh };
150 1.1 bsh
151 1.1 bsh #else /* NWSDISPLAY */
152 1.1 bsh /*
153 1.1 bsh * Interface to LCD framebuffer without wscons
154 1.1 bsh */
155 1.1 bsh extern struct cfdriver lcd_cd;
156 1.1 bsh
157 1.1 bsh dev_type_open(lcdopen);
158 1.1 bsh dev_type_close(lcdclose);
159 1.1 bsh dev_type_ioctl(lcdioctl);
160 1.1 bsh dev_type_mmap(lcdmmap);
161 1.1 bsh const struct cdevsw lcd_cdevsw = {
162 1.1 bsh lcdopen, lcdclose, noread, nowrite, lcdioctl,
163 1.1 bsh nostop, notty, nopoll, lcdmmap, nokqfilter, D_TTY
164 1.1 bsh };
165 1.1 bsh
166 1.1 bsh #endif /* NWSDISPLAY */
167 1.1 bsh
168 1.1 bsh CFATTACH_DECL(lcd_ssio, sizeof (struct s3c24x0_lcd_softc), lcd_match,
169 1.1 bsh lcd_attach, NULL, NULL);
170 1.1 bsh
171 1.1 bsh int
172 1.1 bsh lcd_match(struct device *parent, struct cfdata *cf, void *aux)
173 1.1 bsh {
174 1.1 bsh struct s3c2xx0_attach_args *sa = aux;
175 1.1 bsh
176 1.1 bsh if (sa->sa_addr == SSIOCF_ADDR_DEFAULT)
177 1.1 bsh sa->sa_addr = S3C2410_LCDC_BASE;
178 1.1 bsh
179 1.1 bsh return 1;
180 1.1 bsh }
181 1.1 bsh
182 1.1 bsh static const struct s3c24x0_lcd_panel_info samsung_LTS350Q1 =
183 1.1 bsh {
184 1.1 bsh 240, /* Width */
185 1.1 bsh 320, /* Height */
186 1.1 bsh 10*1000*1000, /* pixel clock = 10MHz */
187 1.1 bsh
188 1.1 bsh #define _(field, val) (((val)-1) << (field##_SHIFT))
189 1.1 bsh
190 1.1 bsh LCDCON1_PNRMODE_TFT,
191 1.1 bsh
192 1.1 bsh /* LCDCON2: vertical timings */
193 1.1 bsh _(LCDCON2_VBPD, 2) |
194 1.1 bsh _(LCDCON2_VFPD, 3) |
195 1.1 bsh _(LCDCON2_LINEVAL, 320) |
196 1.1 bsh _(LCDCON2_VPSW, 2),
197 1.1 bsh
198 1.1 bsh /* LCDCON3: horizontal timings */
199 1.1 bsh _(LCDCON3_HBPD, 7) |
200 1.1 bsh _(LCDCON3_HFPD, 3),
201 1.1 bsh
202 1.1 bsh /* LCDCON4: horizontaol pulse width */
203 1.1 bsh _(LCDCON4_HPSW, 4),
204 1.1 bsh
205 1.1 bsh /* LCDCON5: signal polarities */
206 1.1 bsh LCDCON5_FRM565 | LCDCON5_INVVLINE | LCDCON5_INVVFRAME,
207 1.1 bsh
208 1.1 bsh /* LPCSEL register */
209 1.1 bsh LPCSEL_LPC_EN | LPCSEL_RES_SEL | LPCSEL_MODE_SEL,
210 1.1 bsh #undef _
211 1.1 bsh };
212 1.1 bsh
213 1.1 bsh void
214 1.1 bsh lcd_attach(struct device *parent, struct device *self, void *aux)
215 1.1 bsh {
216 1.1 bsh struct s3c24x0_lcd_softc *sc = (struct s3c24x0_lcd_softc *)self;
217 1.1 bsh bus_space_tag_t iot = s3c2xx0_softc->sc_iot;
218 1.1 bsh bus_space_handle_t gpio_ioh = s3c2xx0_softc->sc_gpio_ioh;
219 1.1 bsh #if NWSDISPLAY > 0
220 1.1 bsh struct wsemuldisplaydev_attach_args aa;
221 1.1 bsh #else
222 1.1 bsh struct s3c24x0_lcd_screen *screen;
223 1.1 bsh #endif
224 1.1 bsh
225 1.1 bsh
226 1.1 bsh aprint_normal( "\n" );
227 1.1 bsh
228 1.1 bsh /* setup GPIO ports for LCD */
229 1.1 bsh /* XXX: some LCD panels may not need all VD signals */
230 1.1 bsh gpio_ioh = s3c2xx0_softc->sc_gpio_ioh;
231 1.1 bsh bus_space_write_4(iot, gpio_ioh, GPIO_PCUP, ~0);
232 1.1 bsh bus_space_write_4(iot, gpio_ioh, GPIO_PCCON, 0xaaaaaaaa);
233 1.1 bsh bus_space_write_4(iot, gpio_ioh, GPIO_PDUP, ~0);
234 1.1 bsh bus_space_write_4(iot, gpio_ioh, GPIO_PDCON, 0xaaaaaaaa);
235 1.1 bsh
236 1.1 bsh s3c24x0_lcd_attach_sub(sc, aux, &samsung_LTS350Q1);
237 1.1 bsh
238 1.1 bsh #if NWSDISPLAY > 0
239 1.1 bsh
240 1.1 bsh aa.console = 0;
241 1.1 bsh aa.scrdata = &lcd_screen_list;
242 1.1 bsh aa.accessops = &lcd_accessops;
243 1.1 bsh aa.accesscookie = sc;
244 1.1 bsh
245 1.1 bsh
246 1.1 bsh (void) config_found(self, &aa, wsemuldisplaydevprint);
247 1.1 bsh #else
248 1.1 bsh
249 1.1 bsh screen = s3c24x0_lcd_new_screen(sc, 240, 320, 16);
250 1.1 bsh
251 1.1 bsh if( screen ){
252 1.1 bsh sc->active = screen;
253 1.1 bsh s3c24x0_lcd_start_dma(sc, screen);
254 1.1 bsh s3c24x0_lcd_power(sc, 1);
255 1.1 bsh }
256 1.1 bsh #endif /* NWSDISPLAY */
257 1.1 bsh
258 1.1 bsh }
259 1.1 bsh
260 1.1 bsh #if NWSDISPLAY == 0
261 1.1 bsh
262 1.1 bsh int
263 1.1 bsh lcdopen( dev_t dev, int oflags, int devtype, struct proc *p )
264 1.1 bsh {
265 1.1 bsh return 0;
266 1.1 bsh }
267 1.1 bsh
268 1.1 bsh int
269 1.1 bsh lcdclose( dev_t dev, int fflag, int devtype, struct proc *p )
270 1.1 bsh {
271 1.1 bsh return 0;
272 1.1 bsh }
273 1.1 bsh
274 1.1 bsh paddr_t
275 1.1 bsh lcdmmap( dev_t dev, off_t offset, int size )
276 1.1 bsh {
277 1.4 cegger struct s3c24x0_lcd_softc *sc =
278 1.4 cegger device_lookup_private(&lcd_cd, minor(dev));
279 1.1 bsh struct s3c24x0_lcd_screen *scr = sc->active;
280 1.1 bsh
281 1.1 bsh return bus_dmamem_mmap(sc->dma_tag, scr->segs, scr->nsegs,
282 1.1 bsh offset, 0, BUS_DMA_WAITOK|BUS_DMA_COHERENT);
283 1.1 bsh }
284 1.1 bsh
285 1.1 bsh int
286 1.3 christos lcdioctl( dev_t dev, u_long cmd, void *data,
287 1.2 christos int fflag, struct lwp *l )
288 1.1 bsh {
289 1.1 bsh return EOPNOTSUPP;
290 1.1 bsh }
291 1.1 bsh
292 1.1 bsh #endif /* NWSDISPLAY>0 */
293 1.1 bsh
294 1.1 bsh #ifdef LCD_DEBUG
295 1.1 bsh static void
296 1.1 bsh draw_test_pattern_16(struct s3c24x0_lcd_softc *sc,
297 1.1 bsh struct s3c24x0_lcd_screen *scr)
298 1.1 bsh {
299 1.1 bsh int x, y;
300 1.1 bsh uint16_t color, *line;
301 1.1 bsh char *buf = (char *)(scr->buf_va);
302 1.1 bsh
303 1.1 bsh #define rgb(r,g,b) (((r)<<11) | ((g)<<5) | (b))
304 1.1 bsh
305 1.1 bsh for (y=0; y < sc->panel_info->panel_height; ++y) {
306 1.1 bsh line = (uint16_t *)(buf + scr->stride * y);
307 1.1 bsh
308 1.1 bsh for (x=0; x < sc->panel_info->panel_width; ++x) {
309 1.1 bsh switch (((x/30) + (y/10)) % 8) {
310 1.1 bsh default:
311 1.1 bsh case 0: color = rgb(0x00, 0x00, 0x00); break;
312 1.1 bsh case 1: color = rgb(0x00, 0x00, 0x1f); break;
313 1.1 bsh case 2: color = rgb(0x00, 0x3f, 0x00); break;
314 1.1 bsh case 3: color = rgb(0x00, 0x3f, 0x1f); break;
315 1.1 bsh case 4: color = rgb(0x1f, 0x00, 0x00); break;
316 1.1 bsh case 5: color = rgb(0x1f, 0x00, 0x1f); break;
317 1.1 bsh case 6: color = rgb(0x1f, 0x3f, 0x00); break;
318 1.1 bsh case 7: color = rgb(0x1f, 0x3f, 0x1f); break;
319 1.1 bsh }
320 1.1 bsh
321 1.1 bsh line[x] = color;
322 1.1 bsh }
323 1.1 bsh }
324 1.1 bsh
325 1.1 bsh for (x=0; x < MIN(sc->panel_info->panel_height,
326 1.1 bsh sc->panel_info->panel_width); ++x) {
327 1.1 bsh
328 1.1 bsh line = (uint16_t *)(buf + scr->stride * x);
329 1.1 bsh line[x] = rgb(0x1f, 0x3f, 0x1f);
330 1.1 bsh }
331 1.1 bsh }
332 1.1 bsh
333 1.1 bsh static void
334 1.1 bsh draw_test_pattern_8(struct s3c24x0_lcd_softc *sc,
335 1.1 bsh struct s3c24x0_lcd_screen *scr)
336 1.1 bsh {
337 1.1 bsh int x, y;
338 1.1 bsh uint8_t *line;
339 1.1 bsh char *buf = (char *)(scr->buf_va);
340 1.1 bsh
341 1.1 bsh
342 1.1 bsh for (y=0; y < sc->panel_info->panel_height; ++y) {
343 1.1 bsh line = (uint8_t *)(buf + scr->stride * y);
344 1.1 bsh
345 1.1 bsh for (x=0; x < sc->panel_info->panel_width; ++x) {
346 1.1 bsh line[x] = (((x/15) + (y/20)) % 16);
347 1.1 bsh }
348 1.1 bsh }
349 1.1 bsh
350 1.1 bsh for (x=0; x < MIN(sc->panel_info->panel_height,
351 1.1 bsh sc->panel_info->panel_width); ++x) {
352 1.1 bsh
353 1.1 bsh line = (uint8_t *)(buf + scr->stride * x);
354 1.1 bsh line[x] = 7;
355 1.1 bsh }
356 1.1 bsh }
357 1.1 bsh
358 1.1 bsh
359 1.1 bsh void
360 1.1 bsh draw_test_pattern(struct s3c24x0_lcd_softc *sc, struct s3c24x0_lcd_screen *scr)
361 1.1 bsh {
362 1.1 bsh switch (scr->depth) {
363 1.1 bsh case 16:
364 1.1 bsh draw_test_pattern_16(sc, scr);
365 1.1 bsh break;
366 1.1 bsh case 8:
367 1.1 bsh draw_test_pattern_8(sc, scr);
368 1.1 bsh break;
369 1.1 bsh }
370 1.1 bsh }
371 1.1 bsh
372 1.1 bsh
373 1.1 bsh #endif /* LCD_DEBUG */
374 1.1 bsh
375