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