Home | History | Annotate | Line # | Download | only in g42xxeb
g42xxeb_lcd.c revision 1.16
      1 /* $NetBSD: g42xxeb_lcd.c,v 1.16 2014/07/25 08:10:33 dholland Exp $ */
      2 
      3 /*-
      4  * Copyright (c) 2001, 2002, 2005 Genetec corp.
      5  * All rights reserved.
      6  *
      7  * LCD driver for Genetec G4250EB-X002.
      8  * Written by Hiroyuki Bessho for Genetec corp.
      9  *
     10  * Redistribution and use in source and binary forms, with or without
     11  * modification, are permitted provided that the following conditions
     12  * are met:
     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.
     21  *
     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.
     33  */
     34 #include "opt_g42xxlcd.h"
     35 
     36 #include <sys/param.h>
     37 #include <sys/systm.h>
     38 #include <sys/conf.h>
     39 #include <sys/uio.h>
     40 #include <sys/malloc.h>
     41 
     42 #include <dev/cons.h>
     43 #include <dev/wscons/wsconsio.h>
     44 #include <dev/wscons/wsdisplayvar.h>
     45 #include <dev/wscons/wscons_callbacks.h>
     46 
     47 #include <sys/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>
     52 
     53 #include <arch/evbarm/g42xxeb/g42xxeb_reg.h>
     54 #include <arch/evbarm/g42xxeb/g42xxeb_var.h>
     55 
     56 #include "wsdisplay.h"
     57 #include "ioconf.h"
     58 
     59 int	lcd_match(device_t, cfdata_t, void *);
     60 void	lcd_attach(device_t, device_t, void *);
     61 int	lcdintr(void *);
     62 
     63 #if NWSDISPLAY > 0
     64 
     65 /*
     66  * wsdisplay glue
     67  */
     68 struct pxa2x0_wsscreen_descr lcd_bpp16_screen = {
     69 	{
     70 		"bpp16", 0, 0,
     71 		&pxa2x0_lcd_emulops,
     72 		0, 0,
     73 		WSSCREEN_WSCOLORS,
     74 	},
     75 	16				/* bits per pixel */
     76 }, lcd_bpp8_screen = {
     77 	{
     78 		"bpp8", 0, 0,
     79 		&pxa2x0_lcd_emulops,
     80 		0, 0,
     81 		WSSCREEN_WSCOLORS,
     82 	},
     83 	8				/* bits per pixel */
     84 }, lcd_bpp4_screen = {
     85 	{
     86 		"bpp4", 0, 0,
     87 		&pxa2x0_lcd_emulops,
     88 		0, 0,
     89 		WSSCREEN_WSCOLORS,
     90 	},
     91 	4				/* bits per pixel */
     92 };
     93 
     94 
     95 static const struct wsscreen_descr *lcd_scr_descr[] = {
     96 	&lcd_bpp4_screen.c,
     97 	&lcd_bpp8_screen.c,
     98 	&lcd_bpp16_screen.c,
     99 };
    100 
    101 const struct wsscreen_list lcd_screen_list = {
    102 	sizeof lcd_scr_descr / sizeof lcd_scr_descr[0],
    103 	lcd_scr_descr
    104 };
    105 
    106 int	lcd_ioctl(void *, void *, u_long, void *, int, struct lwp *);
    107 
    108 int	lcd_show_screen(void *, void *, int,
    109 	    void (*)(void *, int, int), void *);
    110 
    111 const struct wsdisplay_accessops lcd_accessops = {
    112 	lcd_ioctl,
    113 	pxa2x0_lcd_mmap,
    114 	pxa2x0_lcd_alloc_screen,
    115 	pxa2x0_lcd_free_screen,
    116 	lcd_show_screen,
    117 	NULL, /* load_font */
    118 };
    119 
    120 #else
    121 /*
    122  * Interface to LCD framebuffer without wscons
    123  */
    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 	.d_open = lcdopen,
    130 	.d_close = lcdclose,
    131 	.d_read = noread,
    132 	.d_write = nowrite,
    133 	.d_ioctl = lcdioctl,
    134 	.d_stop = nostop,
    135 	.d_tty = notty,
    136 	.d_poll = nopoll,
    137 	.d_mmap = lcdmmap,
    138 	.d_kqfilter = nokqfilter,
    139 	.d_discard = nodiscard,
    140 	.d_flag = D_TTY
    141 };
    142 
    143 #endif
    144 
    145 CFATTACH_DECL_NEW(lcd_obio, sizeof (struct pxa2x0_lcd_softc),
    146     lcd_match, lcd_attach, NULL, NULL);
    147 
    148 int
    149 lcd_match( device_t parent, cfdata_t cf, void *aux )
    150 {
    151 	return 1;
    152 }
    153 
    154 #ifdef G4250_LCD_NEC_NL3224BC35
    155 /* NEC's QVGA LCD */
    156 static const struct lcd_panel_geometry nec_NL3224BC35 =
    157 {
    158     320,			/* Width */
    159     240,			/* Height */
    160     0,				/* No extra lines */
    161 
    162     LCDPANEL_SINGLE|LCDPANEL_ACTIVE|LCDPANEL_PCP|
    163     LCDPANEL_VSP|LCDPANEL_HSP,
    164     7,				/* clock divider, 6.25MHz at 100MHz */
    165     0xff,			/* AC bias pin freq */
    166 
    167     6,				/* horizontal sync pulse width */
    168     70,				/* BLW */
    169     7,				/* ELW */
    170 
    171     10,				/* vertical sync pulse width */
    172     11,				/* BFW */
    173     1,				/* EFW */
    174 };
    175 #endif
    176 
    177 #ifdef G4250_LCD_TOSHIBA_LTM035
    178 const struct lcd_panel_geometry toshiba_LTM035 =
    179 {
    180     240,			/* Width */
    181     320,			/* Height */
    182     0,				/* No extra lines */
    183 
    184     LCDPANEL_SINGLE|LCDPANEL_ACTIVE|   /* LCDPANEL_PCP| */
    185     LCDPANEL_VSP|LCDPANEL_HSP,
    186     11,				/* clock divider, 4.5 MHz at 100 MHz */
    187 				/* required: 4.28..4.7 MHz  */
    188     0xff,			/* AC bias pin freq */
    189 
    190     4,				/* horizontal sync pulse width */
    191     8,				/* BLW (back porch) */
    192     4,				/* ELW (front porch) */
    193 
    194     2,				/* vertical sync pulse width */
    195     2,				/* BFW (back porch) */
    196     3,				/* EFW (front porch) */
    197 
    198 };
    199 #endif /* G4250_LCD_TOSHIBA_LTM035 */
    200 
    201 void lcd_attach(device_t parent, device_t self, void *aux)
    202 {
    203 	struct pxa2x0_lcd_softc *sc = device_private(self);
    204 	struct pxaip_attach_args paa;
    205 	struct obio_attach_args *oba = aux;
    206 
    207 	sc->dev = self;
    208 
    209 	paa.pxa_name = "obio";
    210 	paa.pxa_iot = oba->oba_iot;
    211 	paa.pxa_addr = oba->oba_addr;
    212 	paa.pxa_size = 0;		/* XXX */
    213 	paa.pxa_intr = oba->oba_intr;
    214 
    215 #ifdef G4250_LCD_TOSHIBA_LTM035
    216 # define PANEL	toshiba_LTM035
    217 #else
    218 # define PANEL	nec_NL3224BC35
    219 #endif
    220 
    221 	pxa2x0_lcd_attach_sub(sc, &paa, &PANEL);
    222 
    223 
    224 #if NWSDISPLAY > 0
    225 
    226 	{
    227 		struct wsemuldisplaydev_attach_args aa;
    228 
    229 		/* make wsdisplay screen list */
    230 		pxa2x0_lcd_setup_wsscreen(&lcd_bpp16_screen, &PANEL, NULL);
    231 		pxa2x0_lcd_setup_wsscreen(&lcd_bpp8_screen, &PANEL, NULL);
    232 		pxa2x0_lcd_setup_wsscreen(&lcd_bpp4_screen, &PANEL, NULL);
    233 
    234 		aa.console = 0;
    235 		aa.scrdata = &lcd_screen_list;
    236 		aa.accessops = &lcd_accessops;
    237 		aa.accesscookie = sc;
    238 
    239 		(void) config_found(self, &aa, wsemuldisplaydevprint);
    240 	}
    241 #else
    242 	{
    243 		struct pxa2x0_lcd_screen *screen;
    244 		int error;
    245 
    246 		error = pxa2x0_lcd_new_screen( sc, 16, &screen );
    247 		if (error == 0) {
    248 			sc->active = screen;
    249 			pxa2x0_lcd_start_dma(sc, screen);
    250 		}
    251 	}
    252 #endif
    253 
    254 #undef PANEL
    255 
    256 }
    257 
    258 #if NWSDISPLAY > 0
    259 
    260 int
    261 lcd_ioctl(void *v, void *vs, u_long cmd, void *data, int flag, struct lwp *l)
    262 {
    263 	struct pxa2x0_lcd_softc *sc = v;
    264 	struct obio_softc *osc =
    265 	    device_private(device_parent(sc->dev));
    266 	uint16_t reg;
    267 
    268 	switch (cmd) {
    269 	case WSDISPLAYIO_SVIDEO:
    270 		reg = bus_space_read_2(osc->sc_iot, osc->sc_obioreg_ioh,
    271 		    G42XXEB_LCDCTL);
    272 		if (*(int *)data == WSDISPLAYIO_VIDEO_ON)
    273 			reg |= LCDCTL_BL_ON;
    274 		else
    275 			reg &= ~LCDCTL_BL_ON;
    276 		bus_space_write_2(osc->sc_iot, osc->sc_obioreg_ioh,
    277 			G42XXEB_LCDCTL, reg);
    278 		bus_space_write_1(osc->sc_iot, osc->sc_obioreg_ioh,
    279 			G42XXEB_LED, reg);
    280 		printf("LCD control: %x\n", reg);
    281 		break;			/* turn on/off LCD controller */
    282 	}
    283 
    284 	return pxa2x0_lcd_ioctl(v, vs, cmd, data, flag, l);
    285 }
    286 
    287 int
    288 lcd_show_screen(void *v, void *cookie, int waitok,
    289     void (*cb)(void *, int, int), void *cbarg)
    290 {
    291 	struct pxa2x0_lcd_softc *sc = v;
    292 	struct obio_softc *osc =
    293 	    device_private(device_parent(sc->dev));
    294 	uint16_t reg;
    295 
    296 	pxa2x0_lcd_show_screen(v,cookie,waitok,cb,cbarg);
    297 
    298 	/* Turn on LCD backlight.
    299 	   XXX: with fixed blightness. want new ioctl to set blightness. */
    300 	reg = bus_space_read_2(osc->sc_iot, osc->sc_obioreg_ioh, G42XXEB_LCDCTL);
    301 	bus_space_write_2(osc->sc_iot, osc->sc_obioreg_ioh, G42XXEB_LCDCTL,
    302 	    (reg & ~LCDCTL_BL_PWN) | 0x4000 | LCDCTL_BL_ON);
    303 
    304 	return 0;
    305 }
    306 
    307 
    308 
    309 #else  /* NWSDISPLAY==0 */
    310 
    311 int
    312 lcdopen(dev_t dev, int oflags, int devtype, struct lwp *l)
    313 {
    314 	struct pxa2x0_lcd_softc *sc =
    315 		device_lookup_private(&lcd_cd, minor(dev));
    316 	struct obio_softc *osc =
    317 	    device_private(device_parent(sc->dev));
    318 	uint16_t reg;
    319 
    320 	/* Turn on LCD backlight.
    321 	   XXX: with fixed blightness. want new ioctl to set blightness. */
    322 	reg = bus_space_read_2(osc->sc_iot, osc->sc_obioreg_ioh, G42XXEB_LCDCTL);
    323 	bus_space_write_2(osc->sc_iot, osc->sc_obioreg_ioh, G42XXEB_LCDCTL,
    324 	    (reg & ~LCDCTL_BL_PWN) | 0x4000 | LCDCTL_BL_ON);
    325 
    326 
    327 	return 0;
    328 }
    329 
    330 int
    331 lcdclose(dev_t dev, int fflag, int devtype, struct lwp *l)
    332 {
    333 	return 0;
    334 }
    335 
    336 paddr_t
    337 lcdmmap(dev_t dev, off_t offset, int size)
    338 {
    339 	struct pxa2x0_lcd_softc *sc =
    340 		device_lookup_private(&lcd_cd, minor(dev));
    341 	struct pxa2x0_lcd_screen *scr = sc->active;
    342 
    343 	return bus_dmamem_mmap( &pxa2x0_bus_dma_tag, scr->segs, scr->nsegs,
    344 	    offset, 0, BUS_DMA_WAITOK|BUS_DMA_COHERENT );
    345 }
    346 
    347 int
    348 lcdioctl(dev_t dev, u_long cmd, void *data,
    349 	    int fflag, struct lwp *l)
    350 {
    351 	return EOPNOTSUPP;
    352 }
    353 
    354 #endif /* NWSDISPLAY>0 */
    355