1 /* $NetBSD: g42xxeb_lcd.c,v 1.11 2008/06/11 23:24:43 cegger Exp $ */
4 * Copyright (c) 2001, 2002, 2005 Genetec corp.
7 * LCD driver for Genetec G4250EB-X002.
8 * Written by Hiroyuki Bessho for Genetec corp.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of The NetBSD Foundation nor the names of its
19 * contributors may be used to endorse or promote products derived
20 * from this software without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
23 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
24 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
26 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 * POSSIBILITY OF SUCH DAMAGE.
34 #include "opt_g42xxlcd.h"
36 #include <sys/param.h>
37 #include <sys/systm.h>
40 #include <sys/malloc.h>
43 #include <dev/wscons/wsconsio.h>
44 #include <dev/wscons/wsdisplayvar.h>
45 #include <dev/wscons/wscons_callbacks.h>
47 #include <machine/bus.h>
48 #include <arm/sa11x0/sa11x0_var.h>
49 #include <arm/xscale/pxa2x0var.h>
50 #include <arm/xscale/pxa2x0reg.h>
51 #include <arm/xscale/pxa2x0_lcd.h>
53 #include <arch/evbarm/g42xxeb/g42xxeb_reg.h>
54 #include <arch/evbarm/g42xxeb/g42xxeb_var.h>
56 #include "wsdisplay.h"
59 int lcd_match(device_t
, cfdata_t
, void *);
60 void lcd_attach(device_t
, device_t
, void *);
68 struct pxa2x0_wsscreen_descr lcd_bpp16_screen
= {
75 16 /* bits per pixel */
76 }, lcd_bpp8_screen
= {
83 8 /* bits per pixel */
84 }, lcd_bpp4_screen
= {
91 4 /* bits per pixel */
95 static const struct wsscreen_descr
*lcd_scr_descr
[] = {
101 const struct wsscreen_list lcd_screen_list
= {
102 sizeof lcd_scr_descr
/ sizeof lcd_scr_descr
[0],
106 int lcd_ioctl(void *, void *, u_long
, void *, int, struct lwp
*);
108 int lcd_show_screen(void *, void *, int,
109 void (*)(void *, int, int), void *);
111 const struct wsdisplay_accessops lcd_accessops
= {
114 pxa2x0_lcd_alloc_screen
,
115 pxa2x0_lcd_free_screen
,
117 NULL
, /* load_font */
122 * Interface to LCD framebuffer without wscons
124 dev_type_open(lcdopen
);
125 dev_type_close(lcdclose
);
126 dev_type_ioctl(lcdioctl
);
127 dev_type_mmap(lcdmmap
);
128 const struct cdevsw lcd_cdevsw
= {
129 lcdopen
, lcdclose
, noread
, nowrite
,
130 lcdioctl
, nostop
, notty
, nopoll
, lcdmmap
, D_TTY
135 CFATTACH_DECL_NEW(lcd_obio
, sizeof (struct pxa2x0_lcd_softc
),
136 lcd_match
, lcd_attach
, NULL
, NULL
);
139 lcd_match( device_t parent
, cfdata_t cf
, void *aux
)
144 #ifdef G4250_LCD_NEC_NL3224BC35
146 static const struct lcd_panel_geometry nec_NL3224BC35
=
150 0, /* No extra lines */
152 LCDPANEL_SINGLE
|LCDPANEL_ACTIVE
|LCDPANEL_PCP
|
153 LCDPANEL_VSP
|LCDPANEL_HSP
,
154 7, /* clock divider, 6.25MHz at 100MHz */
155 0xff, /* AC bias pin freq */
157 6, /* horizontal sync pulse width */
161 10, /* vertical sync pulse width */
167 #ifdef G4250_LCD_TOSHIBA_LTM035
168 const struct lcd_panel_geometry toshiba_LTM035
=
172 0, /* No extra lines */
174 LCDPANEL_SINGLE
|LCDPANEL_ACTIVE
| /* LCDPANEL_PCP| */
175 LCDPANEL_VSP
|LCDPANEL_HSP
,
176 11, /* clock divider, 4.5 MHz at 100 MHz */
177 /* required: 4.28..4.7 MHz */
178 0xff, /* AC bias pin freq */
180 4, /* horizontal sync pulse width */
181 8, /* BLW (back porch) */
182 4, /* ELW (front porch) */
184 2, /* vertical sync pulse width */
185 2, /* BFW (back porch) */
186 3, /* EFW (front porch) */
189 #endif /* G4250_LCD_TOSHIBA_LTM035 */
191 void lcd_attach( device_t parent
, device_t self
, void *aux
)
193 struct pxa2x0_lcd_softc
*sc
= device_private(self
);
197 #ifdef G4250_LCD_TOSHIBA_LTM035
198 # define PANEL toshiba_LTM035
200 # define PANEL nec_NL3224BC35
203 pxa2x0_lcd_attach_sub(sc
, aux
, &PANEL
);
209 struct wsemuldisplaydev_attach_args aa
;
211 /* make wsdisplay screen list */
212 pxa2x0_lcd_setup_wsscreen(&lcd_bpp16_screen
, &PANEL
, NULL
);
213 pxa2x0_lcd_setup_wsscreen(&lcd_bpp8_screen
, &PANEL
, NULL
);
214 pxa2x0_lcd_setup_wsscreen(&lcd_bpp4_screen
, &PANEL
, NULL
);
217 aa
.scrdata
= &lcd_screen_list
;
218 aa
.accessops
= &lcd_accessops
;
219 aa
.accesscookie
= sc
;
223 (void) config_found(self
, &aa
, wsemuldisplaydevprint
);
227 struct pxa2x0_lcd_screen
*screen
;
230 error
= pxa2x0_lcd_new_screen( sc
, 16, &screen
);
233 pxa2x0_lcd_start_dma(sc
, screen
);
247 lcd_ioctl(void *v
, void *vs
, u_long cmd
, void *data
, int flag
, struct lwp
*l
)
249 struct obio_softc
*osc
=
250 (struct obio_softc
*) device_parent((struct device
*)v
);
254 case WSDISPLAYIO_SVIDEO
:
255 reg
= bus_space_read_2(osc
->sc_iot
, osc
->sc_obioreg_ioh
,
257 if (*(int *)data
== WSDISPLAYIO_VIDEO_ON
)
260 reg
&= ~LCDCTL_BL_ON
;
261 bus_space_write_2(osc
->sc_iot
, osc
->sc_obioreg_ioh
,
262 G42XXEB_LCDCTL
, reg
);
263 bus_space_write_1(osc
->sc_iot
, osc
->sc_obioreg_ioh
,
265 printf("LCD control: %x\n", reg
);
266 break; /* turn on/off LCD controller */
269 return pxa2x0_lcd_ioctl(v
, vs
, cmd
, data
, flag
, l
);
273 lcd_show_screen(void *v
, void *cookie
, int waitok
,
274 void (*cb
)(void *, int, int), void *cbarg
)
276 struct obio_softc
*osc
=
277 (struct obio_softc
*) device_parent((struct device
*)v
);
280 pxa2x0_lcd_show_screen(v
,cookie
,waitok
,cb
,cbarg
);
282 /* Turn on LCD backlight.
283 XXX: with fixed blightness. want new ioctl to set blightness. */
284 reg
= bus_space_read_2(osc
->sc_iot
, osc
->sc_obioreg_ioh
, G42XXEB_LCDCTL
);
285 bus_space_write_2(osc
->sc_iot
, osc
->sc_obioreg_ioh
, G42XXEB_LCDCTL
,
286 (reg
& ~LCDCTL_BL_PWN
) | 0x4000 | LCDCTL_BL_ON
);
293 #else /* NWSDISPLAY==0 */
296 lcdopen(dev_t dev
, int oflags
, int devtype
, struct lwp
*l
)
302 lcdclose(dev_t dev
, int fflag
, int devtype
, struct lwp
*l
)
308 lcdmmap(dev_t dev
, off_t offset
, int size
)
310 struct pxa2x0_lcd_softc
*sc
=
311 device_lookup_private(&lcd_cd
, minor(dev
));
312 struct pxa2x0_lcd_screen
*scr
= sc
->active
;
314 return bus_dmamem_mmap( &pxa2x0_bus_dma_tag
, scr
->segs
, scr
->nsegs
,
315 offset
, 0, BUS_DMA_WAITOK
|BUS_DMA_COHERENT
);
319 lcdioctl(dev_t dev
, u_long cmd
, void *data
,
320 int fflag
, struct lwp
*l
)
325 #endif /* NWSDISPLAY>0 */