lubbock_lcd.c revision 1.13 1 1.13 chs /* $NetBSD: lubbock_lcd.c,v 1.13 2012/10/27 17:17:48 chs Exp $ */
2 1.1 bsh
3 1.1 bsh /*
4 1.1 bsh * Copyright (c) 2002, 2003 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 * LCD driver for Intel Lubbock.
34 1.1 bsh *
35 1.1 bsh * Controlling LCD is almost completely done through PXA2X0's
36 1.1 bsh * integrated LCD controller. Codes for it is arm/xscale/pxa2x0_lcd.c.
37 1.1 bsh *
38 1.1 bsh * Codes in this file provide platform specific things including:
39 1.1 bsh * LCD on/off switch in on-board PLD register.
40 1.1 bsh * LCD panel geometry
41 1.1 bsh */
42 1.1 bsh #include <sys/cdefs.h>
43 1.13 chs __KERNEL_RCSID(0, "$NetBSD: lubbock_lcd.c,v 1.13 2012/10/27 17:17:48 chs Exp $");
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/uio.h>
49 1.1 bsh #include <sys/malloc.h>
50 1.1 bsh
51 1.1 bsh #include <dev/cons.h>
52 1.1 bsh #include <dev/wscons/wsconsio.h>
53 1.1 bsh #include <dev/wscons/wsdisplayvar.h>
54 1.1 bsh #include <dev/wscons/wscons_callbacks.h>
55 1.1 bsh
56 1.12 dyoung #include <sys/bus.h>
57 1.1 bsh #include <arm/xscale/pxa2x0var.h>
58 1.1 bsh #include <arm/xscale/pxa2x0reg.h>
59 1.1 bsh #include <arm/xscale/pxa2x0_lcd.h>
60 1.1 bsh
61 1.1 bsh #include <arch/evbarm/lubbock/lubbock_reg.h>
62 1.1 bsh #include <arch/evbarm/lubbock/lubbock_var.h>
63 1.1 bsh
64 1.1 bsh #include "wsdisplay.h"
65 1.1 bsh
66 1.9 nonaka int lcd_match(device_t, cfdata_t, void *);
67 1.9 nonaka void lcd_attach(device_t, device_t, void *);
68 1.1 bsh int lcdintr(void *);
69 1.1 bsh
70 1.1 bsh #if NWSDISPLAY > 0
71 1.1 bsh
72 1.1 bsh /*
73 1.1 bsh * wsdisplay glue
74 1.1 bsh */
75 1.1 bsh struct pxa2x0_wsscreen_descr lcd_bpp16_screen = {
76 1.1 bsh {
77 1.1 bsh "bpp16", 0, 0,
78 1.1 bsh &pxa2x0_lcd_emulops,
79 1.1 bsh 0, 0,
80 1.1 bsh WSSCREEN_WSCOLORS,
81 1.1 bsh },
82 1.1 bsh 16 /* bits per pixel */
83 1.1 bsh }, lcd_bpp8_screen = {
84 1.1 bsh {
85 1.1 bsh "bpp8", 0, 0,
86 1.1 bsh &pxa2x0_lcd_emulops,
87 1.1 bsh 0, 0,
88 1.1 bsh WSSCREEN_WSCOLORS,
89 1.1 bsh },
90 1.1 bsh 8 /* bits per pixel */
91 1.1 bsh }, lcd_bpp4_screen = {
92 1.1 bsh {
93 1.1 bsh "bpp4", 0, 0,
94 1.1 bsh &pxa2x0_lcd_emulops,
95 1.1 bsh 0, 0,
96 1.1 bsh WSSCREEN_WSCOLORS,
97 1.1 bsh },
98 1.1 bsh 4 /* bits per pixel */
99 1.1 bsh };
100 1.1 bsh
101 1.1 bsh
102 1.1 bsh static const struct wsscreen_descr *lcd_scr_descr[] = {
103 1.1 bsh #if 0
104 1.1 bsh /* bpp4 needs a patch to rasops4 */
105 1.1 bsh &lcd_bpp4_screen.c,
106 1.1 bsh #endif
107 1.1 bsh &lcd_bpp8_screen.c,
108 1.1 bsh &lcd_bpp16_screen.c,
109 1.1 bsh };
110 1.1 bsh
111 1.1 bsh const struct wsscreen_list lcd_screen_list = {
112 1.1 bsh sizeof lcd_scr_descr / sizeof lcd_scr_descr[0],
113 1.1 bsh lcd_scr_descr
114 1.1 bsh };
115 1.1 bsh
116 1.7 christos int lcd_ioctl(void *, void *, u_long, void *, int, struct lwp *);
117 1.1 bsh
118 1.1 bsh int lcd_show_screen(void *, void *, int,
119 1.1 bsh void (*)(void *, int, int), void *);
120 1.1 bsh
121 1.1 bsh const struct wsdisplay_accessops lcd_accessops = {
122 1.1 bsh lcd_ioctl,
123 1.1 bsh pxa2x0_lcd_mmap,
124 1.1 bsh pxa2x0_lcd_alloc_screen,
125 1.1 bsh pxa2x0_lcd_free_screen,
126 1.1 bsh lcd_show_screen,
127 1.1 bsh NULL, /* load_font */
128 1.1 bsh };
129 1.1 bsh
130 1.1 bsh #else
131 1.1 bsh /*
132 1.1 bsh * Interface to LCD framebuffer without wscons
133 1.1 bsh */
134 1.1 bsh dev_type_open(lcdopen);
135 1.1 bsh dev_type_close(lcdclose);
136 1.1 bsh dev_type_ioctl(lcdioctl);
137 1.1 bsh dev_type_mmap(lcdmmap);
138 1.1 bsh const struct cdevsw lcd_cdevsw = {
139 1.1 bsh lcdopen, lcdclose, noread, nowrite,
140 1.1 bsh lcdioctl, nostop, notty, nopoll, lcdmmap, D_TTY
141 1.1 bsh };
142 1.1 bsh
143 1.1 bsh #endif
144 1.1 bsh
145 1.9 nonaka CFATTACH_DECL_NEW(lcd_obio, sizeof (struct pxa2x0_lcd_softc), lcd_match,
146 1.1 bsh lcd_attach, NULL, NULL);
147 1.1 bsh
148 1.1 bsh int
149 1.9 nonaka lcd_match( device_t parent, cfdata_t cf, void *aux )
150 1.1 bsh {
151 1.1 bsh return 1;
152 1.1 bsh }
153 1.1 bsh
154 1.1 bsh static const struct lcd_panel_geometry sharp_LM8V31 =
155 1.1 bsh {
156 1.1 bsh 640, /* Width */
157 1.1 bsh 480, /* Height */
158 1.1 bsh 0, /* No extra lines */
159 1.1 bsh
160 1.1 bsh LCDPANEL_DUAL|LCDPANEL_PASSIVE|LCDPANEL_PCP,
161 1.1 bsh 10, /* clock divider */
162 1.1 bsh 0xff, /* AC bias pin freq */
163 1.1 bsh
164 1.1 bsh 2, /* horizontal sync pulse width */
165 1.1 bsh 3, /* BLW */
166 1.1 bsh 3, /* ELW */
167 1.1 bsh
168 1.1 bsh 1, /* vertical sync pulse width */
169 1.1 bsh 0, /* BFW */
170 1.1 bsh 0, /* EFW */
171 1.1 bsh
172 1.1 bsh };
173 1.1 bsh
174 1.9 nonaka void lcd_attach( device_t parent, device_t self, void *aux )
175 1.1 bsh {
176 1.9 nonaka struct pxa2x0_lcd_softc *sc = device_private(self);
177 1.11 bsh struct obio_attach_args *oba = aux;
178 1.11 bsh struct pxaip_attach_args paa;
179 1.9 nonaka
180 1.9 nonaka sc->dev = self;
181 1.1 bsh
182 1.11 bsh paa.pxa_name = "obio";
183 1.11 bsh paa.pxa_iot = oba->oba_iot;
184 1.11 bsh paa.pxa_addr = oba->oba_addr;
185 1.11 bsh paa.pxa_size = 0; /* XXX */
186 1.11 bsh paa.pxa_intr = oba->oba_intr;
187 1.11 bsh
188 1.11 bsh pxa2x0_lcd_attach_sub(sc, &paa, &sharp_LM8V31);
189 1.1 bsh
190 1.1 bsh
191 1.1 bsh #if NWSDISPLAY > 0
192 1.1 bsh
193 1.1 bsh {
194 1.1 bsh struct wsemuldisplaydev_attach_args aa;
195 1.1 bsh
196 1.1 bsh /* make wsdisplay screen list */
197 1.1 bsh pxa2x0_lcd_setup_wsscreen( &lcd_bpp16_screen, &sharp_LM8V31, NULL );
198 1.1 bsh pxa2x0_lcd_setup_wsscreen( &lcd_bpp8_screen, &sharp_LM8V31, NULL );
199 1.1 bsh pxa2x0_lcd_setup_wsscreen( &lcd_bpp4_screen, &sharp_LM8V31, NULL );
200 1.1 bsh
201 1.1 bsh aa.console = 0;
202 1.1 bsh aa.scrdata = &lcd_screen_list;
203 1.1 bsh aa.accessops = &lcd_accessops;
204 1.1 bsh aa.accesscookie = sc;
205 1.1 bsh
206 1.1 bsh (void) config_found(self, &aa, wsemuldisplaydevprint);
207 1.1 bsh }
208 1.1 bsh #else
209 1.1 bsh {
210 1.6 nonaka struct pxa2x0_lcd_screen *screen;
211 1.6 nonaka int error;
212 1.1 bsh
213 1.6 nonaka error = pxa2x0_lcd_new_screen( sc, 8, &screen );
214 1.6 nonaka if( error == 0 ){
215 1.1 bsh sc->active = screen;
216 1.1 bsh pxa2x0_lcd_start_dma( sc, screen );
217 1.1 bsh }
218 1.1 bsh }
219 1.1 bsh #endif
220 1.1 bsh
221 1.1 bsh }
222 1.1 bsh
223 1.1 bsh #if NWSDISPLAY > 0
224 1.1 bsh
225 1.1 bsh int
226 1.7 christos lcd_ioctl(void *v, void *vs, u_long cmd, void *data, int flag, struct lwp *l)
227 1.1 bsh {
228 1.13 chs struct pxa2x0_lcd_softc *sc = v;
229 1.10 rjs struct obio_softc *osc = device_private(device_parent(sc->dev));
230 1.1 bsh uint16_t reg;
231 1.1 bsh
232 1.1 bsh switch (cmd) {
233 1.1 bsh case WSDISPLAYIO_SVIDEO:
234 1.1 bsh reg = bus_space_read_2( osc->sc_iot, osc->sc_obioreg_ioh,
235 1.1 bsh LUBBOCK_MISCWR );
236 1.1 bsh if( *(int *)data == WSDISPLAYIO_VIDEO_ON )
237 1.1 bsh reg |= MISCWR_LCDDISP;
238 1.1 bsh else
239 1.1 bsh reg &= ~MISCWR_LCDDISP;
240 1.1 bsh bus_space_write_2( osc->sc_iot, osc->sc_obioreg_ioh,
241 1.1 bsh LUBBOCK_MISCWR, reg );
242 1.1 bsh break; /* turn on/off LCD controller */
243 1.1 bsh }
244 1.1 bsh
245 1.5 jmmv return pxa2x0_lcd_ioctl( v, vs, cmd, data, flag, l );
246 1.1 bsh }
247 1.1 bsh
248 1.1 bsh int
249 1.1 bsh lcd_show_screen(void *v, void *cookie, int waitok,
250 1.1 bsh void (*cb)(void *, int, int), void *cbarg)
251 1.1 bsh {
252 1.13 chs struct pxa2x0_lcd_softc *sc = v;
253 1.10 rjs struct obio_softc *osc = device_private(device_parent(sc->dev));
254 1.1 bsh
255 1.1 bsh pxa2x0_lcd_show_screen(v,cookie,waitok,cb,cbarg);
256 1.1 bsh
257 1.1 bsh /* Turn on LCD */
258 1.1 bsh bus_space_write_4( osc->sc_iot, osc->sc_obioreg_ioh, LUBBOCK_MISCWR,
259 1.1 bsh MISCWR_LCDDISP |
260 1.1 bsh bus_space_read_4( osc->sc_iot, osc->sc_obioreg_ioh, LUBBOCK_MISCWR ) );
261 1.1 bsh
262 1.1 bsh return (0);
263 1.1 bsh }
264 1.1 bsh
265 1.1 bsh
266 1.1 bsh
267 1.1 bsh #else /* NWSDISPLAY==0 */
268 1.1 bsh
269 1.1 bsh int
270 1.2 christos lcdopen( dev_t dev, int oflags, int devtype, struct lwp *l )
271 1.1 bsh {
272 1.1 bsh return 0;
273 1.1 bsh }
274 1.1 bsh
275 1.1 bsh int
276 1.2 christos lcdclose( dev_t dev, int fflag, int devtype, struct lwp *l )
277 1.1 bsh {
278 1.1 bsh return 0;
279 1.1 bsh }
280 1.1 bsh
281 1.1 bsh paddr_t
282 1.1 bsh lcdmmap( dev_t dev, off_t offset, int size )
283 1.1 bsh {
284 1.8 cegger struct pxa2x0_lcd_softc *sc =
285 1.8 cegger device_lookup_private(&lcd_cd, minor(dev));
286 1.1 bsh struct pxa2x0_lcd_screen *scr = sc->active;
287 1.1 bsh
288 1.1 bsh return bus_dmamem_mmap( &pxa2x0_bus_dma_tag, scr->segs, scr->nsegs,
289 1.1 bsh offset, 0, BUS_DMA_WAITOK|BUS_DMA_COHERENT );
290 1.1 bsh }
291 1.1 bsh
292 1.1 bsh int
293 1.7 christos lcdioctl( dev_t dev, u_long cmd, void *data,
294 1.2 christos int fflag, struct lwp *l )
295 1.1 bsh {
296 1.1 bsh return EOPNOTSUPP;
297 1.1 bsh }
298 1.1 bsh
299 1.1 bsh #endif /* NWSDISPLAY>0 */
300