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