Sync usage with man page.
[netbsd-mini2440.git] / sys / arch / evbarm / smdk2xx0 / smdk2410_lcd.c
blobaf858df0c6a59b6c68cce2acc1cf8fb9b6753f1a
1 /* $NetBSD: smdk2410_lcd.c,v 1.3 2007/03/04 05:59:45 christos Exp $ */
3 /*
4 * Copyright (c) 2004 Genetec Corporation. All rights reserved.
5 * Written by Hiroyuki Bessho for Genetec Corporation.
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.
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.
33 #include <sys/cdefs.h>
34 __KERNEL_RCSID(0, "$NetBSD: smdk2410_lcd.c,v 1.3 2007/03/04 05:59:45 christos Exp $");
37 * LCD driver for Samsung SMDK2410.
39 * Controlling LCD is almost completely done through S3C2410's
40 * integrated LCD controller. Codes for it is arm/s3c2xx0/s3c24x0_lcd.c.
42 * Codes in this file provide the platform's LCD panel information.
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>
52 #include <dev/cons.h>
53 #include <dev/wscons/wsconsio.h>
54 #include <dev/wscons/wsdisplayvar.h>
55 #include <dev/wscons/wscons_callbacks.h>
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>
63 #include "wsdisplay.h"
65 int lcd_match(struct device *, struct cfdata *, void *);
66 void lcd_attach(struct device *, struct device *, void *);
68 #ifdef LCD_DEBUG
69 void draw_test_pattern(struct s3c24x0_lcd_softc *,
70 struct s3c24x0_lcd_screen *scr);
71 #endif
73 #if NWSDISPLAY > 0
76 * Screen geometries.
78 * S3C24x0's LCD controller can have virtual screens that are bigger
79 * than actual LCD panel. (XXX: wscons can't manage such screens for now)
81 struct s3c24x0_wsscreen_descr lcd_bpp16_30x32 = {
83 "30x32bpp16", 30, 32,
84 &s3c24x0_lcd_emulops,
85 8, 10,
86 WSSCREEN_WSCOLORS,
88 16 /* bits per pixel */
89 }, lcd_bpp16_30x20 = {
91 "30x20bpp16", 30, 20,
92 &s3c24x0_lcd_emulops,
93 8, 16,
94 WSSCREEN_WSCOLORS,
97 }, lcd_bpp8_30x32 = {
99 "30x32bpp8", 30, 32,
100 &s3c24x0_lcd_emulops,
101 8, 10,
102 WSSCREEN_WSCOLORS,
105 }, lcd_bpp8_40x25 = { /* with big virtual screen */
107 "40x25bpp8", 40, 25,
108 &s3c24x0_lcd_emulops,
109 8, 16,
110 WSSCREEN_WSCOLORS,
113 }, lcd_bpp4_30x32 = {
115 "30x32bpp4", 30, 32,
116 &s3c24x0_lcd_emulops,
117 8, 10,
118 0, /* 4bpp mode is grayscale */
124 static const struct wsscreen_descr *lcd_scr_descr[] = {
125 #if 0
126 /* bpp4 needs a patch to rasops4 */
127 &lcd_bpp4_30x32.c,
128 #endif
129 &lcd_bpp8_30x32.c,
130 &lcd_bpp8_40x25.c,
131 &lcd_bpp16_30x32.c,
132 &lcd_bpp16_30x20.c,
135 #define N_SCR_DESCR (sizeof lcd_scr_descr / sizeof lcd_scr_descr[0])
137 const struct wsscreen_list lcd_screen_list = {
138 N_SCR_DESCR,
139 lcd_scr_descr
142 const struct wsdisplay_accessops lcd_accessops = {
143 s3c24x0_lcd_ioctl,
144 s3c24x0_lcd_mmap,
145 s3c24x0_lcd_alloc_screen,
146 s3c24x0_lcd_free_screen,
147 s3c24x0_lcd_show_screen,
148 NULL, /* load_font */
151 #else /* NWSDISPLAY */
153 * Interface to LCD framebuffer without wscons
155 extern struct cfdriver lcd_cd;
157 dev_type_open(lcdopen);
158 dev_type_close(lcdclose);
159 dev_type_ioctl(lcdioctl);
160 dev_type_mmap(lcdmmap);
161 const struct cdevsw lcd_cdevsw = {
162 lcdopen, lcdclose, noread, nowrite, lcdioctl,
163 nostop, notty, nopoll, lcdmmap, nokqfilter, D_TTY
166 #endif /* NWSDISPLAY */
168 CFATTACH_DECL(lcd_ssio, sizeof (struct s3c24x0_lcd_softc), lcd_match,
169 lcd_attach, NULL, NULL);
172 lcd_match(struct device *parent, struct cfdata *cf, void *aux)
174 struct s3c2xx0_attach_args *sa = aux;
176 if (sa->sa_addr == SSIOCF_ADDR_DEFAULT)
177 sa->sa_addr = S3C2410_LCDC_BASE;
179 return 1;
182 static const struct s3c24x0_lcd_panel_info samsung_LTS350Q1 =
184 240, /* Width */
185 320, /* Height */
186 10*1000*1000, /* pixel clock = 10MHz */
188 #define _(field, val) (((val)-1) << (field##_SHIFT))
190 LCDCON1_PNRMODE_TFT,
192 /* LCDCON2: vertical timings */
193 _(LCDCON2_VBPD, 2) |
194 _(LCDCON2_VFPD, 3) |
195 _(LCDCON2_LINEVAL, 320) |
196 _(LCDCON2_VPSW, 2),
198 /* LCDCON3: horizontal timings */
199 _(LCDCON3_HBPD, 7) |
200 _(LCDCON3_HFPD, 3),
202 /* LCDCON4: horizontaol pulse width */
203 _(LCDCON4_HPSW, 4),
205 /* LCDCON5: signal polarities */
206 LCDCON5_FRM565 | LCDCON5_INVVLINE | LCDCON5_INVVFRAME,
208 /* LPCSEL register */
209 LPCSEL_LPC_EN | LPCSEL_RES_SEL | LPCSEL_MODE_SEL,
210 #undef _
213 void
214 lcd_attach(struct device *parent, struct device *self, void *aux)
216 struct s3c24x0_lcd_softc *sc = (struct s3c24x0_lcd_softc *)self;
217 bus_space_tag_t iot = s3c2xx0_softc->sc_iot;
218 bus_space_handle_t gpio_ioh = s3c2xx0_softc->sc_gpio_ioh;
219 #if NWSDISPLAY > 0
220 struct wsemuldisplaydev_attach_args aa;
221 #else
222 struct s3c24x0_lcd_screen *screen;
223 #endif
226 aprint_normal( "\n" );
228 /* setup GPIO ports for LCD */
229 /* XXX: some LCD panels may not need all VD signals */
230 gpio_ioh = s3c2xx0_softc->sc_gpio_ioh;
231 bus_space_write_4(iot, gpio_ioh, GPIO_PCUP, ~0);
232 bus_space_write_4(iot, gpio_ioh, GPIO_PCCON, 0xaaaaaaaa);
233 bus_space_write_4(iot, gpio_ioh, GPIO_PDUP, ~0);
234 bus_space_write_4(iot, gpio_ioh, GPIO_PDCON, 0xaaaaaaaa);
236 s3c24x0_lcd_attach_sub(sc, aux, &samsung_LTS350Q1);
238 #if NWSDISPLAY > 0
240 aa.console = 0;
241 aa.scrdata = &lcd_screen_list;
242 aa.accessops = &lcd_accessops;
243 aa.accesscookie = sc;
246 (void) config_found(self, &aa, wsemuldisplaydevprint);
247 #else
249 screen = s3c24x0_lcd_new_screen(sc, 240, 320, 16);
251 if( screen ){
252 sc->active = screen;
253 s3c24x0_lcd_start_dma(sc, screen);
254 s3c24x0_lcd_power(sc, 1);
256 #endif /* NWSDISPLAY */
260 #if NWSDISPLAY == 0
263 lcdopen( dev_t dev, int oflags, int devtype, struct proc *p )
265 return 0;
269 lcdclose( dev_t dev, int fflag, int devtype, struct proc *p )
271 return 0;
274 paddr_t
275 lcdmmap( dev_t dev, off_t offset, int size )
277 struct s3c24x0_lcd_softc *sc =
278 device_lookup_private(&lcd_cd, minor(dev));
279 struct s3c24x0_lcd_screen *scr = sc->active;
281 return bus_dmamem_mmap(sc->dma_tag, scr->segs, scr->nsegs,
282 offset, 0, BUS_DMA_WAITOK|BUS_DMA_COHERENT);
286 lcdioctl( dev_t dev, u_long cmd, void *data,
287 int fflag, struct lwp *l )
289 return EOPNOTSUPP;
292 #endif /* NWSDISPLAY>0 */
294 #ifdef LCD_DEBUG
295 static void
296 draw_test_pattern_16(struct s3c24x0_lcd_softc *sc,
297 struct s3c24x0_lcd_screen *scr)
299 int x, y;
300 uint16_t color, *line;
301 char *buf = (char *)(scr->buf_va);
303 #define rgb(r,g,b) (((r)<<11) | ((g)<<5) | (b))
305 for (y=0; y < sc->panel_info->panel_height; ++y) {
306 line = (uint16_t *)(buf + scr->stride * y);
308 for (x=0; x < sc->panel_info->panel_width; ++x) {
309 switch (((x/30) + (y/10)) % 8) {
310 default:
311 case 0: color = rgb(0x00, 0x00, 0x00); break;
312 case 1: color = rgb(0x00, 0x00, 0x1f); break;
313 case 2: color = rgb(0x00, 0x3f, 0x00); break;
314 case 3: color = rgb(0x00, 0x3f, 0x1f); break;
315 case 4: color = rgb(0x1f, 0x00, 0x00); break;
316 case 5: color = rgb(0x1f, 0x00, 0x1f); break;
317 case 6: color = rgb(0x1f, 0x3f, 0x00); break;
318 case 7: color = rgb(0x1f, 0x3f, 0x1f); break;
321 line[x] = color;
325 for (x=0; x < MIN(sc->panel_info->panel_height,
326 sc->panel_info->panel_width); ++x) {
328 line = (uint16_t *)(buf + scr->stride * x);
329 line[x] = rgb(0x1f, 0x3f, 0x1f);
333 static void
334 draw_test_pattern_8(struct s3c24x0_lcd_softc *sc,
335 struct s3c24x0_lcd_screen *scr)
337 int x, y;
338 uint8_t *line;
339 char *buf = (char *)(scr->buf_va);
342 for (y=0; y < sc->panel_info->panel_height; ++y) {
343 line = (uint8_t *)(buf + scr->stride * y);
345 for (x=0; x < sc->panel_info->panel_width; ++x) {
346 line[x] = (((x/15) + (y/20)) % 16);
350 for (x=0; x < MIN(sc->panel_info->panel_height,
351 sc->panel_info->panel_width); ++x) {
353 line = (uint8_t *)(buf + scr->stride * x);
354 line[x] = 7;
359 void
360 draw_test_pattern(struct s3c24x0_lcd_softc *sc, struct s3c24x0_lcd_screen *scr)
362 switch (scr->depth) {
363 case 16:
364 draw_test_pattern_16(sc, scr);
365 break;
366 case 8:
367 draw_test_pattern_8(sc, scr);
368 break;
373 #endif /* LCD_DEBUG */