g42xxeb_lcd.c revision 1.1.8.2 1 1.1.8.2 kent /* $NetBSD: g42xxeb_lcd.c,v 1.1.8.2 2005/04/29 11:28:07 kent Exp $ */
2 1.1.8.2 kent
3 1.1.8.2 kent /*-
4 1.1.8.2 kent * Copyright (c) 2001, 2002, 2005 Genetec corp.
5 1.1.8.2 kent * All rights reserved.
6 1.1.8.2 kent *
7 1.1.8.2 kent * LCD driver for Genetec G4250EB-X002.
8 1.1.8.2 kent * Written by Hiroyuki Bessho for Genetec corp.
9 1.1.8.2 kent *
10 1.1.8.2 kent * Redistribution and use in source and binary forms, with or without
11 1.1.8.2 kent * modification, are permitted provided that the following conditions
12 1.1.8.2 kent * are met:
13 1.1.8.2 kent * 1. Redistributions of source code must retain the above copyright
14 1.1.8.2 kent * notice, this list of conditions and the following disclaimer.
15 1.1.8.2 kent * 2. Redistributions in binary form must reproduce the above copyright
16 1.1.8.2 kent * notice, this list of conditions and the following disclaimer in the
17 1.1.8.2 kent * documentation and/or other materials provided with the distribution.
18 1.1.8.2 kent * 3. Neither the name of The NetBSD Foundation nor the names of its
19 1.1.8.2 kent * contributors may be used to endorse or promote products derived
20 1.1.8.2 kent * from this software without specific prior written permission.
21 1.1.8.2 kent *
22 1.1.8.2 kent * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
23 1.1.8.2 kent * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
24 1.1.8.2 kent * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
25 1.1.8.2 kent * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
26 1.1.8.2 kent * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
27 1.1.8.2 kent * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
28 1.1.8.2 kent * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
29 1.1.8.2 kent * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
30 1.1.8.2 kent * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
31 1.1.8.2 kent * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
32 1.1.8.2 kent * POSSIBILITY OF SUCH DAMAGE.
33 1.1.8.2 kent */
34 1.1.8.2 kent #include "opt_g42xxlcd.h"
35 1.1.8.2 kent
36 1.1.8.2 kent #include <sys/param.h>
37 1.1.8.2 kent #include <sys/systm.h>
38 1.1.8.2 kent #include <sys/conf.h>
39 1.1.8.2 kent #include <sys/uio.h>
40 1.1.8.2 kent #include <sys/malloc.h>
41 1.1.8.2 kent
42 1.1.8.2 kent #include <dev/cons.h>
43 1.1.8.2 kent #include <dev/wscons/wsconsio.h>
44 1.1.8.2 kent #include <dev/wscons/wsdisplayvar.h>
45 1.1.8.2 kent #include <dev/wscons/wscons_callbacks.h>
46 1.1.8.2 kent
47 1.1.8.2 kent #include <machine/bus.h>
48 1.1.8.2 kent #include <arm/sa11x0/sa11x0_var.h>
49 1.1.8.2 kent #include <arm/xscale/pxa2x0var.h>
50 1.1.8.2 kent #include <arm/xscale/pxa2x0reg.h>
51 1.1.8.2 kent #include <arm/xscale/pxa2x0_lcd.h>
52 1.1.8.2 kent
53 1.1.8.2 kent #include <arch/evbarm/g42xxeb/g42xxeb_reg.h>
54 1.1.8.2 kent #include <arch/evbarm/g42xxeb/g42xxeb_var.h>
55 1.1.8.2 kent
56 1.1.8.2 kent #include "wsdisplay.h"
57 1.1.8.2 kent #include "ioconf.h"
58 1.1.8.2 kent
59 1.1.8.2 kent int lcd_match( struct device *, struct cfdata *, void *);
60 1.1.8.2 kent void lcd_attach( struct device *, struct device *, void *);
61 1.1.8.2 kent int lcdintr(void *);
62 1.1.8.2 kent
63 1.1.8.2 kent #if NWSDISPLAY > 0
64 1.1.8.2 kent
65 1.1.8.2 kent /*
66 1.1.8.2 kent * wsdisplay glue
67 1.1.8.2 kent */
68 1.1.8.2 kent struct pxa2x0_wsscreen_descr lcd_bpp16_screen = {
69 1.1.8.2 kent {
70 1.1.8.2 kent "bpp16", 0, 0,
71 1.1.8.2 kent &pxa2x0_lcd_emulops,
72 1.1.8.2 kent 0, 0,
73 1.1.8.2 kent WSSCREEN_WSCOLORS,
74 1.1.8.2 kent },
75 1.1.8.2 kent 16 /* bits per pixel */
76 1.1.8.2 kent }, lcd_bpp8_screen = {
77 1.1.8.2 kent {
78 1.1.8.2 kent "bpp8", 0, 0,
79 1.1.8.2 kent &pxa2x0_lcd_emulops,
80 1.1.8.2 kent 0, 0,
81 1.1.8.2 kent WSSCREEN_WSCOLORS,
82 1.1.8.2 kent },
83 1.1.8.2 kent 8 /* bits per pixel */
84 1.1.8.2 kent }, lcd_bpp4_screen = {
85 1.1.8.2 kent {
86 1.1.8.2 kent "bpp4", 0, 0,
87 1.1.8.2 kent &pxa2x0_lcd_emulops,
88 1.1.8.2 kent 0, 0,
89 1.1.8.2 kent WSSCREEN_WSCOLORS,
90 1.1.8.2 kent },
91 1.1.8.2 kent 4 /* bits per pixel */
92 1.1.8.2 kent };
93 1.1.8.2 kent
94 1.1.8.2 kent
95 1.1.8.2 kent static const struct wsscreen_descr *lcd_scr_descr[] = {
96 1.1.8.2 kent &lcd_bpp4_screen.c,
97 1.1.8.2 kent &lcd_bpp8_screen.c,
98 1.1.8.2 kent &lcd_bpp16_screen.c,
99 1.1.8.2 kent };
100 1.1.8.2 kent
101 1.1.8.2 kent const struct wsscreen_list lcd_screen_list = {
102 1.1.8.2 kent sizeof lcd_scr_descr / sizeof lcd_scr_descr[0],
103 1.1.8.2 kent lcd_scr_descr
104 1.1.8.2 kent };
105 1.1.8.2 kent
106 1.1.8.2 kent int lcd_ioctl(void *, u_long, caddr_t, int, struct proc *);
107 1.1.8.2 kent
108 1.1.8.2 kent int lcd_show_screen(void *, void *, int,
109 1.1.8.2 kent void (*)(void *, int, int), void *);
110 1.1.8.2 kent
111 1.1.8.2 kent const struct wsdisplay_accessops lcd_accessops = {
112 1.1.8.2 kent lcd_ioctl,
113 1.1.8.2 kent pxa2x0_lcd_mmap,
114 1.1.8.2 kent pxa2x0_lcd_alloc_screen,
115 1.1.8.2 kent pxa2x0_lcd_free_screen,
116 1.1.8.2 kent lcd_show_screen,
117 1.1.8.2 kent NULL, /* load_font */
118 1.1.8.2 kent };
119 1.1.8.2 kent
120 1.1.8.2 kent #else
121 1.1.8.2 kent /*
122 1.1.8.2 kent * Interface to LCD framebuffer without wscons
123 1.1.8.2 kent */
124 1.1.8.2 kent dev_type_open(lcdopen);
125 1.1.8.2 kent dev_type_close(lcdclose);
126 1.1.8.2 kent dev_type_ioctl(lcdioctl);
127 1.1.8.2 kent dev_type_mmap(lcdmmap);
128 1.1.8.2 kent const struct cdevsw lcd_cdevsw = {
129 1.1.8.2 kent lcdopen, lcdclose, noread, nowrite,
130 1.1.8.2 kent lcdioctl, nostop, notty, nopoll, lcdmmap, D_TTY
131 1.1.8.2 kent };
132 1.1.8.2 kent
133 1.1.8.2 kent #endif
134 1.1.8.2 kent
135 1.1.8.2 kent CFATTACH_DECL(lcd_obio, sizeof (struct pxa2x0_lcd_softc), lcd_match, lcd_attach,
136 1.1.8.2 kent NULL, NULL);
137 1.1.8.2 kent
138 1.1.8.2 kent int
139 1.1.8.2 kent lcd_match( struct device *parent, struct cfdata *cf, void *aux )
140 1.1.8.2 kent {
141 1.1.8.2 kent return 1;
142 1.1.8.2 kent }
143 1.1.8.2 kent
144 1.1.8.2 kent #ifdef G4250_LCD_NEC_NL3224BC35
145 1.1.8.2 kent /* NEC's QVGA LCD */
146 1.1.8.2 kent static const struct lcd_panel_geometry nec_NL3224BC35 =
147 1.1.8.2 kent {
148 1.1.8.2 kent 320, /* Width */
149 1.1.8.2 kent 240, /* Height */
150 1.1.8.2 kent 0, /* No extra lines */
151 1.1.8.2 kent
152 1.1.8.2 kent LCDPANEL_SINGLE|LCDPANEL_ACTIVE|LCDPANEL_PCP|
153 1.1.8.2 kent LCDPANEL_VSP|LCDPANEL_HSP,
154 1.1.8.2 kent 7, /* clock divider, 6.25MHz at 100MHz */
155 1.1.8.2 kent 0xff, /* AC bias pin freq */
156 1.1.8.2 kent
157 1.1.8.2 kent 6, /* horizontal sync pulse width */
158 1.1.8.2 kent 70, /* BLW */
159 1.1.8.2 kent 7, /* ELW */
160 1.1.8.2 kent
161 1.1.8.2 kent 10, /* vertical sync pulse width */
162 1.1.8.2 kent 11, /* BFW */
163 1.1.8.2 kent 1, /* EFW */
164 1.1.8.2 kent };
165 1.1.8.2 kent #endif
166 1.1.8.2 kent
167 1.1.8.2 kent #ifdef G4250_LCD_TOSHIBA_LTM035
168 1.1.8.2 kent const struct lcd_panel_geometry toshiba_LTM035 =
169 1.1.8.2 kent {
170 1.1.8.2 kent 240, /* Width */
171 1.1.8.2 kent 320, /* Height */
172 1.1.8.2 kent 0, /* No extra lines */
173 1.1.8.2 kent
174 1.1.8.2 kent LCDPANEL_SINGLE|LCDPANEL_ACTIVE| /* LCDPANEL_PCP| */
175 1.1.8.2 kent LCDPANEL_VSP|LCDPANEL_HSP,
176 1.1.8.2 kent 11, /* clock divider, 4.5MHz at 100Mhz */
177 1.1.8.2 kent /* required: 4.28..4.7 MHz */
178 1.1.8.2 kent 0xff, /* AC bias pin freq */
179 1.1.8.2 kent
180 1.1.8.2 kent 4, /* horizontal sync pulse width */
181 1.1.8.2 kent 8, /* BLW (back porch) */
182 1.1.8.2 kent 4, /* ELW (front porch) */
183 1.1.8.2 kent
184 1.1.8.2 kent 2, /* vertical sync pulse width */
185 1.1.8.2 kent 2, /* BFW (back porch) */
186 1.1.8.2 kent 3, /* EFW (front porch) */
187 1.1.8.2 kent
188 1.1.8.2 kent };
189 1.1.8.2 kent #endif /* G4250_LCD_TOSHIBA_LTM035 */
190 1.1.8.2 kent
191 1.1.8.2 kent void lcd_attach( struct device *parent, struct device *self, void *aux )
192 1.1.8.2 kent {
193 1.1.8.2 kent struct pxa2x0_lcd_softc *sc = (struct pxa2x0_lcd_softc *)self;
194 1.1.8.2 kent
195 1.1.8.2 kent #ifdef G4250_LCD_TOSHIBA_LTM035
196 1.1.8.2 kent # define PANEL toshiba_LTM035
197 1.1.8.2 kent #else
198 1.1.8.2 kent # define PANEL nec_NL3224BC35
199 1.1.8.2 kent #endif
200 1.1.8.2 kent
201 1.1.8.2 kent pxa2x0_lcd_attach_sub(sc, aux, &PANEL);
202 1.1.8.2 kent
203 1.1.8.2 kent
204 1.1.8.2 kent #if NWSDISPLAY > 0
205 1.1.8.2 kent
206 1.1.8.2 kent {
207 1.1.8.2 kent struct wsemuldisplaydev_attach_args aa;
208 1.1.8.2 kent
209 1.1.8.2 kent /* make wsdisplay screen list */
210 1.1.8.2 kent pxa2x0_lcd_setup_wsscreen(&lcd_bpp16_screen, &PANEL, NULL);
211 1.1.8.2 kent pxa2x0_lcd_setup_wsscreen(&lcd_bpp8_screen, &PANEL, NULL);
212 1.1.8.2 kent pxa2x0_lcd_setup_wsscreen(&lcd_bpp4_screen, &PANEL, NULL);
213 1.1.8.2 kent
214 1.1.8.2 kent aa.console = 0;
215 1.1.8.2 kent aa.scrdata = &lcd_screen_list;
216 1.1.8.2 kent aa.accessops = &lcd_accessops;
217 1.1.8.2 kent aa.accesscookie = sc;
218 1.1.8.2 kent
219 1.1.8.2 kent printf("\n");
220 1.1.8.2 kent
221 1.1.8.2 kent (void) config_found(self, &aa, wsemuldisplaydevprint);
222 1.1.8.2 kent }
223 1.1.8.2 kent #else
224 1.1.8.2 kent {
225 1.1.8.2 kent struct pxa2x0_lcd_screen *screen = pxa2x0_lcd_new_screen( sc, 16 );
226 1.1.8.2 kent
227 1.1.8.2 kent if (screen) {
228 1.1.8.2 kent sc->active = screen;
229 1.1.8.2 kent pxa2x0_lcd_start_dma(sc, screen);
230 1.1.8.2 kent }
231 1.1.8.2 kent
232 1.1.8.2 kent printf("\n");
233 1.1.8.2 kent }
234 1.1.8.2 kent #endif
235 1.1.8.2 kent
236 1.1.8.2 kent #undef PANEL
237 1.1.8.2 kent
238 1.1.8.2 kent }
239 1.1.8.2 kent
240 1.1.8.2 kent #if NWSDISPLAY > 0
241 1.1.8.2 kent
242 1.1.8.2 kent int
243 1.1.8.2 kent lcd_ioctl(void *v, u_long cmd, caddr_t data, int flag, struct proc *p)
244 1.1.8.2 kent {
245 1.1.8.2 kent struct obio_softc *osc =
246 1.1.8.2 kent (struct obio_softc *)((struct device *)v)->dv_parent;
247 1.1.8.2 kent uint16_t reg;
248 1.1.8.2 kent
249 1.1.8.2 kent switch (cmd) {
250 1.1.8.2 kent case WSDISPLAYIO_SVIDEO:
251 1.1.8.2 kent reg = bus_space_read_2(osc->sc_iot, osc->sc_obioreg_ioh,
252 1.1.8.2 kent G42XXEB_LCDCTL);
253 1.1.8.2 kent if (*(int *)data == WSDISPLAYIO_VIDEO_ON)
254 1.1.8.2 kent reg |= LCDCTL_BL_ON;
255 1.1.8.2 kent else
256 1.1.8.2 kent reg &= ~LCDCTL_BL_ON;
257 1.1.8.2 kent bus_space_write_2(osc->sc_iot, osc->sc_obioreg_ioh,
258 1.1.8.2 kent G42XXEB_LCDCTL, reg);
259 1.1.8.2 kent bus_space_write_1(osc->sc_iot, osc->sc_obioreg_ioh,
260 1.1.8.2 kent G42XXEB_LED, reg);
261 1.1.8.2 kent printf("LCD control: %x\n", reg);
262 1.1.8.2 kent break; /* turn on/off LCD controller */
263 1.1.8.2 kent }
264 1.1.8.2 kent
265 1.1.8.2 kent return pxa2x0_lcd_ioctl(v, cmd, data, flag, p);
266 1.1.8.2 kent }
267 1.1.8.2 kent
268 1.1.8.2 kent int
269 1.1.8.2 kent lcd_show_screen(void *v, void *cookie, int waitok,
270 1.1.8.2 kent void (*cb)(void *, int, int), void *cbarg)
271 1.1.8.2 kent {
272 1.1.8.2 kent struct obio_softc *osc =
273 1.1.8.2 kent (struct obio_softc *)((struct device *)v)->dv_parent;
274 1.1.8.2 kent uint16_t reg;
275 1.1.8.2 kent
276 1.1.8.2 kent pxa2x0_lcd_show_screen(v,cookie,waitok,cb,cbarg);
277 1.1.8.2 kent
278 1.1.8.2 kent /* Turn on LCD backlight.
279 1.1.8.2 kent XXX: with fixed blightness. want new ioctl to set blightness. */
280 1.1.8.2 kent reg = bus_space_read_2(osc->sc_iot, osc->sc_obioreg_ioh, G42XXEB_LCDCTL);
281 1.1.8.2 kent bus_space_write_2(osc->sc_iot, osc->sc_obioreg_ioh, G42XXEB_LCDCTL,
282 1.1.8.2 kent (reg & ~LCDCTL_BL_PWN) | 0x4000 | LCDCTL_BL_ON);
283 1.1.8.2 kent
284 1.1.8.2 kent return 0;
285 1.1.8.2 kent }
286 1.1.8.2 kent
287 1.1.8.2 kent
288 1.1.8.2 kent
289 1.1.8.2 kent #else /* NWSDISPLAY==0 */
290 1.1.8.2 kent
291 1.1.8.2 kent int
292 1.1.8.2 kent lcdopen(dev_t dev, int oflags, int devtype, struct proc *p)
293 1.1.8.2 kent {
294 1.1.8.2 kent return 0;
295 1.1.8.2 kent }
296 1.1.8.2 kent
297 1.1.8.2 kent int
298 1.1.8.2 kent lcdclose(dev_t dev, int fflag, int devtype, struct proc *p)
299 1.1.8.2 kent {
300 1.1.8.2 kent return 0;
301 1.1.8.2 kent }
302 1.1.8.2 kent
303 1.1.8.2 kent paddr_t
304 1.1.8.2 kent lcdmmap(dev_t dev, off_t offset, int size)
305 1.1.8.2 kent {
306 1.1.8.2 kent struct pxa2x0_lcd_softc *sc = device_lookup(&lcd_cd, minor(dev));
307 1.1.8.2 kent struct pxa2x0_lcd_screen *scr = sc->active;
308 1.1.8.2 kent
309 1.1.8.2 kent return bus_dmamem_mmap( &pxa2x0_bus_dma_tag, scr->segs, scr->nsegs,
310 1.1.8.2 kent offset, 0, BUS_DMA_WAITOK|BUS_DMA_COHERENT );
311 1.1.8.2 kent }
312 1.1.8.2 kent
313 1.1.8.2 kent int
314 1.1.8.2 kent lcdioctl(dev_t dev, u_long cmd, caddr_t data,
315 1.1.8.2 kent int fflag, struct proc *p)
316 1.1.8.2 kent {
317 1.1.8.2 kent return EOPNOTSUPP;
318 1.1.8.2 kent }
319 1.1.8.2 kent
320 1.1.8.2 kent #endif /* NWSDISPLAY>0 */
321