Home | History | Annotate | Line # | Download | only in lubbock
lubbock_lcd.c revision 1.7.48.1
      1  1.7.48.1    simonb /* $NetBSD: lubbock_lcd.c,v 1.7.48.1 2008/06/18 16:32:40 simonb 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.7.48.1    simonb __KERNEL_RCSID(0, "$NetBSD: lubbock_lcd.c,v 1.7.48.1 2008/06/18 16:32:40 simonb 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.1       bsh #include <machine/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.1       bsh int	lcd_match( struct device *, struct cfdata *, void *);
     67       1.1       bsh void	lcd_attach( struct device *, struct device *, 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.1       bsh CFATTACH_DECL(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.1       bsh lcd_match( struct device *parent, struct cfdata *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.1       bsh void lcd_attach( struct device *parent, struct device *self, void *aux )
    175       1.1       bsh {
    176       1.1       bsh 	struct pxa2x0_lcd_softc *sc = (struct pxa2x0_lcd_softc *)self;
    177       1.1       bsh 
    178       1.1       bsh 	pxa2x0_lcd_attach_sub(sc, aux, &sharp_LM8V31);
    179       1.1       bsh 
    180       1.1       bsh 
    181       1.1       bsh #if NWSDISPLAY > 0
    182       1.1       bsh 
    183       1.1       bsh 	{
    184       1.1       bsh 		struct wsemuldisplaydev_attach_args aa;
    185       1.1       bsh 
    186       1.1       bsh 		/* make wsdisplay screen list */
    187       1.1       bsh 		pxa2x0_lcd_setup_wsscreen( &lcd_bpp16_screen, &sharp_LM8V31, NULL );
    188       1.1       bsh 		pxa2x0_lcd_setup_wsscreen( &lcd_bpp8_screen, &sharp_LM8V31, NULL );
    189       1.1       bsh 		pxa2x0_lcd_setup_wsscreen( &lcd_bpp4_screen, &sharp_LM8V31, NULL );
    190       1.1       bsh 
    191       1.1       bsh 		aa.console = 0;
    192       1.1       bsh 		aa.scrdata = &lcd_screen_list;
    193       1.1       bsh 		aa.accessops = &lcd_accessops;
    194       1.1       bsh 		aa.accesscookie = sc;
    195       1.1       bsh 
    196       1.1       bsh 		printf( "\n" );
    197       1.1       bsh 
    198       1.1       bsh 		(void) config_found(self, &aa, wsemuldisplaydevprint);
    199       1.1       bsh 	}
    200       1.1       bsh #else
    201       1.1       bsh 	{
    202       1.6    nonaka 		struct pxa2x0_lcd_screen *screen;
    203       1.6    nonaka 		int error;
    204       1.1       bsh 
    205       1.6    nonaka 		error = pxa2x0_lcd_new_screen( sc, 8, &screen );
    206       1.6    nonaka 		if( error == 0 ){
    207       1.1       bsh 			sc->active = screen;
    208       1.1       bsh 			pxa2x0_lcd_start_dma( sc, screen );
    209       1.1       bsh 		}
    210       1.1       bsh 
    211       1.1       bsh 		printf( "\n" );
    212       1.1       bsh 	}
    213       1.1       bsh #endif
    214       1.1       bsh 
    215       1.1       bsh }
    216       1.1       bsh 
    217       1.1       bsh #if NWSDISPLAY > 0
    218       1.1       bsh 
    219       1.1       bsh int
    220       1.7  christos lcd_ioctl(void *v, void *vs, u_long cmd, void *data, int flag, struct lwp *l)
    221       1.1       bsh {
    222       1.1       bsh 	struct obio_softc *osc =
    223       1.3   thorpej 	    (struct obio_softc *) device_parent((struct device *)v);
    224       1.1       bsh 	uint16_t reg;
    225       1.1       bsh 
    226       1.1       bsh 	switch (cmd) {
    227       1.1       bsh 	case WSDISPLAYIO_SVIDEO:
    228       1.1       bsh 		reg = bus_space_read_2( osc->sc_iot, osc->sc_obioreg_ioh,
    229       1.1       bsh 		    LUBBOCK_MISCWR );
    230       1.1       bsh 		if( *(int *)data == WSDISPLAYIO_VIDEO_ON )
    231       1.1       bsh 			reg |= MISCWR_LCDDISP;
    232       1.1       bsh 		else
    233       1.1       bsh 			reg &= ~MISCWR_LCDDISP;
    234       1.1       bsh 		bus_space_write_2( osc->sc_iot, osc->sc_obioreg_ioh,
    235       1.1       bsh 			LUBBOCK_MISCWR, reg );
    236       1.1       bsh 		break;			/* turn on/off LCD controller */
    237       1.1       bsh 	}
    238       1.1       bsh 
    239       1.5      jmmv 	return pxa2x0_lcd_ioctl( v, vs, cmd, data, flag, l );
    240       1.1       bsh }
    241       1.1       bsh 
    242       1.1       bsh int
    243       1.1       bsh lcd_show_screen(void *v, void *cookie, int waitok,
    244       1.1       bsh     void (*cb)(void *, int, int), void *cbarg)
    245       1.1       bsh {
    246       1.1       bsh 	struct obio_softc *osc =
    247       1.3   thorpej 	    (struct obio_softc *) device_parent((struct device *)v);
    248       1.1       bsh 
    249       1.1       bsh 	pxa2x0_lcd_show_screen(v,cookie,waitok,cb,cbarg);
    250       1.1       bsh 
    251       1.1       bsh 	/* Turn on LCD */
    252       1.1       bsh 	bus_space_write_4( osc->sc_iot, osc->sc_obioreg_ioh, LUBBOCK_MISCWR,
    253       1.1       bsh 	    MISCWR_LCDDISP |
    254       1.1       bsh 	    bus_space_read_4( osc->sc_iot, osc->sc_obioreg_ioh, LUBBOCK_MISCWR ) );
    255       1.1       bsh 
    256       1.1       bsh 	return (0);
    257       1.1       bsh }
    258       1.1       bsh 
    259       1.1       bsh 
    260       1.1       bsh 
    261       1.1       bsh #else  /* NWSDISPLAY==0 */
    262       1.1       bsh 
    263       1.1       bsh int
    264       1.2  christos lcdopen( dev_t dev, int oflags, int devtype, struct lwp *l )
    265       1.1       bsh {
    266       1.1       bsh 	return 0;
    267       1.1       bsh }
    268       1.1       bsh 
    269       1.1       bsh int
    270       1.2  christos lcdclose( dev_t dev, int fflag, 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 paddr_t
    276       1.1       bsh lcdmmap( dev_t dev, off_t offset, int size )
    277       1.1       bsh {
    278  1.7.48.1    simonb 	struct pxa2x0_lcd_softc *sc =
    279  1.7.48.1    simonb 		device_lookup_private(&lcd_cd, minor(dev));
    280       1.1       bsh 	struct pxa2x0_lcd_screen *scr = sc->active;
    281       1.1       bsh 
    282       1.1       bsh 	return bus_dmamem_mmap( &pxa2x0_bus_dma_tag, scr->segs, scr->nsegs,
    283       1.1       bsh 	    offset, 0, BUS_DMA_WAITOK|BUS_DMA_COHERENT );
    284       1.1       bsh }
    285       1.1       bsh 
    286       1.1       bsh int
    287       1.7  christos lcdioctl( dev_t dev, u_long cmd, void *data,
    288       1.2  christos 	    int fflag, struct lwp *l )
    289       1.1       bsh {
    290       1.1       bsh 	return EOPNOTSUPP;
    291       1.1       bsh }
    292       1.1       bsh 
    293       1.1       bsh #endif /* NWSDISPLAY>0 */
    294