1 /* $NetBSD: smdk2410_lcd.c,v 1.3 2007/03/04 05:59:45 christos Exp $ */
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
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
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>
48 #include <sys/event.h>
50 #include <sys/malloc.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 *);
69 void draw_test_pattern(struct s3c24x0_lcd_softc
*,
70 struct s3c24x0_lcd_screen
*scr
);
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
= {
88 16 /* bits per pixel */
89 }, lcd_bpp16_30x20
= {
100 &s3c24x0_lcd_emulops
,
105 }, lcd_bpp8_40x25
= { /* with big virtual screen */
108 &s3c24x0_lcd_emulops
,
113 }, lcd_bpp4_30x32
= {
116 &s3c24x0_lcd_emulops
,
118 0, /* 4bpp mode is grayscale */
124 static const struct wsscreen_descr
*lcd_scr_descr
[] = {
126 /* bpp4 needs a patch to rasops4 */
135 #define N_SCR_DESCR (sizeof lcd_scr_descr / sizeof lcd_scr_descr[0])
137 const struct wsscreen_list lcd_screen_list
= {
142 const struct wsdisplay_accessops lcd_accessops
= {
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
;
182 static const struct s3c24x0_lcd_panel_info samsung_LTS350Q1
=
186 10*1000*1000, /* pixel clock = 10MHz */
188 #define _(field, val) (((val)-1) << (field##_SHIFT))
192 /* LCDCON2: vertical timings */
195 _(LCDCON2_LINEVAL
, 320) |
198 /* LCDCON3: horizontal timings */
202 /* LCDCON4: horizontaol pulse width */
205 /* LCDCON5: signal polarities */
206 LCDCON5_FRM565
| LCDCON5_INVVLINE
| LCDCON5_INVVFRAME
,
208 /* LPCSEL register */
209 LPCSEL_LPC_EN
| LPCSEL_RES_SEL
| LPCSEL_MODE_SEL
,
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
;
220 struct wsemuldisplaydev_attach_args aa
;
222 struct s3c24x0_lcd_screen
*screen
;
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
);
241 aa
.scrdata
= &lcd_screen_list
;
242 aa
.accessops
= &lcd_accessops
;
243 aa
.accesscookie
= sc
;
246 (void) config_found(self
, &aa
, wsemuldisplaydevprint
);
249 screen
= s3c24x0_lcd_new_screen(sc
, 240, 320, 16);
253 s3c24x0_lcd_start_dma(sc
, screen
);
254 s3c24x0_lcd_power(sc
, 1);
256 #endif /* NWSDISPLAY */
263 lcdopen( dev_t dev
, int oflags
, int devtype
, struct proc
*p
)
269 lcdclose( dev_t dev
, int fflag
, int devtype
, struct proc
*p
)
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
)
292 #endif /* NWSDISPLAY>0 */
296 draw_test_pattern_16(struct s3c24x0_lcd_softc
*sc
,
297 struct s3c24x0_lcd_screen
*scr
)
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) {
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;
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);
334 draw_test_pattern_8(struct s3c24x0_lcd_softc
*sc
,
335 struct s3c24x0_lcd_screen
*scr
)
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
);
360 draw_test_pattern(struct s3c24x0_lcd_softc
*sc
, struct s3c24x0_lcd_screen
*scr
)
362 switch (scr
->depth
) {
364 draw_test_pattern_16(sc
, scr
);
367 draw_test_pattern_8(sc
, scr
);
373 #endif /* LCD_DEBUG */