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