Home | History | Annotate | Line # | Download | only in xscale
pxa2x0_lcd.c revision 1.23
      1  1.23    nonaka /* $NetBSD: pxa2x0_lcd.c,v 1.23 2007/06/28 15:05:27 nonaka Exp $ */
      2   1.1       bsh 
      3   1.1       bsh /*
      4   1.1       bsh  * Copyright (c) 2002  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. All advertising materials mentioning features or use of this software
     16   1.1       bsh  *    must display the following acknowledgement:
     17   1.1       bsh  *	This product includes software developed for the NetBSD Project by
     18   1.1       bsh  *	Genetec Corporation.
     19   1.1       bsh  * 4. The name of Genetec Corporation may not be used to endorse or
     20   1.1       bsh  *    promote products derived from this software without specific prior
     21   1.1       bsh  *    written permission.
     22   1.1       bsh  *
     23   1.1       bsh  * THIS SOFTWARE IS PROVIDED BY GENETEC CORPORATION ``AS IS'' AND
     24   1.1       bsh  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     25   1.1       bsh  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     26   1.1       bsh  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL GENETEC CORPORATION
     27   1.1       bsh  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     28   1.1       bsh  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     29   1.1       bsh  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     30   1.1       bsh  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     31   1.1       bsh  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     32   1.1       bsh  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     33   1.1       bsh  * POSSIBILITY OF SUCH DAMAGE.
     34   1.1       bsh  */
     35   1.1       bsh 
     36   1.1       bsh /*
     37   1.1       bsh  * Support PXA2[15]0's integrated LCD controller.
     38   1.1       bsh  */
     39   1.6     lukem 
     40   1.6     lukem #include <sys/cdefs.h>
     41  1.23    nonaka __KERNEL_RCSID(0, "$NetBSD: pxa2x0_lcd.c,v 1.23 2007/06/28 15:05:27 nonaka Exp $");
     42   1.6     lukem 
     43   1.1       bsh #include <sys/param.h>
     44   1.1       bsh #include <sys/systm.h>
     45   1.1       bsh #include <sys/conf.h>
     46   1.1       bsh #include <sys/uio.h>
     47   1.1       bsh #include <sys/malloc.h>
     48   1.1       bsh #include <sys/kernel.h>			/* for cold */
     49   1.1       bsh 
     50   1.2   thorpej #include <uvm/uvm_extern.h>
     51   1.2   thorpej 
     52   1.1       bsh #include <dev/cons.h>
     53   1.1       bsh #include <dev/wscons/wsconsio.h>
     54   1.1       bsh #include <dev/wscons/wsdisplayvar.h>
     55   1.1       bsh #include <dev/wscons/wscons_callbacks.h>
     56   1.1       bsh #include <dev/rasops/rasops.h>
     57   1.1       bsh #include <dev/wsfont/wsfont.h>
     58   1.1       bsh 
     59   1.1       bsh #include <machine/bus.h>
     60   1.1       bsh #include <machine/cpu.h>
     61   1.1       bsh #include <arm/cpufunc.h>
     62   1.1       bsh 
     63  1.10       bsh #include <arm/xscale/pxa2x0cpu.h>
     64   1.1       bsh #include <arm/xscale/pxa2x0var.h>
     65   1.1       bsh #include <arm/xscale/pxa2x0reg.h>
     66   1.1       bsh #include <arm/xscale/pxa2x0_lcd.h>
     67   1.5       bsh #include <arm/xscale/pxa2x0_gpio.h>
     68   1.1       bsh 
     69   1.1       bsh #include "wsdisplay.h"
     70   1.1       bsh 
     71  1.16    nonaka /*
     72  1.16    nonaka  * Console variables. These are necessary since console is setup very early,
     73  1.16    nonaka  * before devices get attached.
     74  1.16    nonaka  */
     75  1.16    nonaka struct {
     76  1.16    nonaka 	int				 is_console;
     77  1.16    nonaka 	struct pxa2x0_wsscreen_descr	*descr;
     78  1.16    nonaka 	const struct lcd_panel_geometry *geom;
     79  1.16    nonaka } pxa2x0_lcd_console;
     80  1.16    nonaka 
     81  1.15     peter int		lcdintr(void *);
     82  1.15     peter 
     83  1.15     peter static void	pxa2x0_lcd_initialize(struct pxa2x0_lcd_softc *,
     84  1.15     peter 		    const struct lcd_panel_geometry *);
     85  1.15     peter static void	pxa2x0_lcd_setup_rasops(struct pxa2x0_lcd_softc *,
     86  1.15     peter 		    struct rasops_info *, struct pxa2x0_wsscreen_descr *,
     87  1.15     peter 		    const struct lcd_panel_geometry *);
     88   1.1       bsh 
     89   1.1       bsh void
     90   1.4       bsh pxa2x0_lcd_geometry(struct pxa2x0_lcd_softc *sc,
     91   1.4       bsh     const struct lcd_panel_geometry *info)
     92   1.1       bsh {
     93  1.14      ober 	bus_space_tag_t iot;
     94  1.14      ober 	bus_space_handle_t ioh;
     95  1.14      ober 	uint32_t ccr0;
     96   1.1       bsh 	int lines;
     97   1.1       bsh 
     98  1.15     peter 	iot = sc->iot;
     99  1.15     peter 	ioh = sc->ioh;
    100  1.15     peter 	sc->geometry = info;
    101   1.1       bsh 
    102   1.1       bsh 	ccr0 = LCCR0_IMASK;
    103  1.22    nonaka 	if (CPU_IS_PXA270)
    104  1.23    nonaka 		ccr0 |= LCCR0_CMDIM|LCCR0_RDSTM|LCCR0_LDDALT;
    105   1.4       bsh 	if (info->panel_info & LCDPANEL_ACTIVE)
    106   1.4       bsh 		ccr0 |= LCCR0_PAS;	/* active mode */
    107   1.4       bsh 	if ((info->panel_info & (LCDPANEL_DUAL|LCDPANEL_ACTIVE))
    108   1.4       bsh 	    == LCDPANEL_DUAL)
    109   1.1       bsh 		ccr0 |= LCCR0_SDS; /* dual panel */
    110   1.4       bsh 	if (info->panel_info & LCDPANEL_MONOCHROME)
    111   1.1       bsh 		ccr0 |= LCCR0_CMS;
    112   1.4       bsh 	bus_space_write_4(iot, ioh, LCDC_LCCR0, ccr0);
    113   1.1       bsh 
    114   1.4       bsh 	bus_space_write_4(iot, ioh, LCDC_LCCR1,
    115   1.1       bsh 	    (info->panel_width-1)
    116   1.1       bsh 	    | ((info->hsync_pulse_width-1)<<10)
    117   1.1       bsh 	    | ((info->end_line_wait-1)<<16)
    118   1.4       bsh 	    | ((info->beg_line_wait-1)<<24));
    119   1.1       bsh 
    120   1.4       bsh 	if (info->panel_info & LCDPANEL_DUAL)
    121   1.1       bsh 		lines = info->panel_height/2 + info->extra_lines;
    122   1.1       bsh 	else
    123   1.1       bsh 		lines = info->panel_height + info->extra_lines;
    124   1.1       bsh 
    125   1.4       bsh 	bus_space_write_4(iot, ioh, LCDC_LCCR2,
    126   1.1       bsh 	    (lines-1)
    127   1.1       bsh 	    | (info->vsync_pulse_width<<10)
    128   1.1       bsh 	    | (info->end_frame_wait<<16)
    129   1.4       bsh 	    | (info->beg_frame_wait<<24));
    130   1.1       bsh 
    131   1.4       bsh 	bus_space_write_4(iot, ioh, LCDC_LCCR3,
    132   1.1       bsh 	    (info->pixel_clock_div<<0)
    133   1.1       bsh 	    | (info->ac_bias << 8)
    134   1.1       bsh 	    | ((info->panel_info &
    135   1.1       bsh 		(LCDPANEL_VSP|LCDPANEL_HSP|LCDPANEL_PCP|LCDPANEL_OEP))
    136   1.1       bsh 		<<20)
    137   1.4       bsh 	    | (4 << 24) /* 16bpp */
    138   1.1       bsh 	    | ((info->panel_info & LCDPANEL_DPC) ? (1<<27) : 0)
    139   1.1       bsh 	    );
    140   1.1       bsh }
    141   1.1       bsh 
    142  1.14      ober /*
    143  1.14      ober  * Initialize the LCD controller.
    144  1.14      ober  */
    145   1.1       bsh void
    146  1.14      ober pxa2x0_lcd_initialize(struct pxa2x0_lcd_softc *sc,
    147  1.14      ober     const struct lcd_panel_geometry *geom)
    148   1.1       bsh {
    149  1.14      ober 	bus_space_tag_t iot;
    150   1.1       bsh 	bus_space_handle_t ioh;
    151  1.14      ober 	uint32_t lccr0, lscr;
    152  1.14      ober 	int nldd;
    153   1.1       bsh 
    154  1.15     peter 	iot = sc->iot;
    155  1.15     peter 	ioh = sc->ioh;
    156   1.1       bsh 
    157  1.14      ober 	/* Check if LCD is enabled before programming, it should not
    158  1.14      ober 	 * be enabled while it is being reprogrammed, therefore disable
    159  1.14      ober 	 * it first.
    160  1.14      ober 	 */
    161  1.14      ober 	lccr0 = bus_space_read_4(iot, ioh, LCDC_LCCR0);
    162  1.14      ober 	if (lccr0 & LCCR0_ENB) {
    163  1.14      ober 		lccr0 |= LCCR0_LDM;
    164  1.14      ober 		bus_space_write_4(iot, ioh, LCDC_LCCR0, lccr0);
    165  1.14      ober 		lccr0 = bus_space_read_4(iot, ioh, LCDC_LCCR0); /* paranoia */
    166  1.14      ober 		lccr0 |= LCCR0_DIS;
    167  1.14      ober 		bus_space_write_4(iot, ioh, LCDC_LCCR0, lccr0);
    168  1.14      ober 		do {
    169  1.14      ober 			lscr = bus_space_read_4(iot, ioh, LCDC_LCSR);
    170  1.14      ober 		} while (!(lscr & LCSR_LDD));
    171   1.1       bsh 	}
    172   1.1       bsh 
    173   1.1       bsh 	/* enable clock */
    174   1.5       bsh 	pxa2x0_clkman_config(CKEN_LCD, 1);
    175   1.1       bsh 
    176  1.22    nonaka 	lccr0 = LCCR0_IMASK;
    177  1.22    nonaka 	if (CPU_IS_PXA270)
    178  1.22    nonaka 		lccr0 |= LCCR0_CMDIM|LCCR0_RDSTM;
    179  1.22    nonaka 	bus_space_write_4(iot, ioh, LCDC_LCCR0, lccr0);
    180   1.1       bsh 
    181   1.1       bsh 	/*
    182   1.1       bsh 	 * setup GP[77:58] for LCD
    183   1.1       bsh 	 */
    184   1.3       scw 	/* Always use [FLP]CLK, ACBIAS */
    185   1.3       scw 	pxa2x0_gpio_set_function(74, GPIO_ALT_FN_2_OUT);
    186   1.3       scw 	pxa2x0_gpio_set_function(75, GPIO_ALT_FN_2_OUT);
    187   1.3       scw 	pxa2x0_gpio_set_function(76, GPIO_ALT_FN_2_OUT);
    188   1.3       scw 	pxa2x0_gpio_set_function(77, GPIO_ALT_FN_2_OUT);
    189   1.3       scw 
    190   1.3       scw 	if ((geom->panel_info & LCDPANEL_ACTIVE) ||
    191   1.3       scw 	    ((geom->panel_info & (LCDPANEL_MONOCHROME|LCDPANEL_DUAL)) ==
    192   1.3       scw 	    LCDPANEL_DUAL)) {
    193   1.3       scw 		/* active and color dual panel need L_DD[15:0] */
    194   1.3       scw 		nldd = 16;
    195  1.14      ober 	} else if ((geom->panel_info & LCDPANEL_DUAL) ||
    196   1.3       scw 	    !(geom->panel_info & LCDPANEL_MONOCHROME)) {
    197   1.3       scw 		/* dual or color need L_DD[7:0] */
    198   1.3       scw 		nldd = 8;
    199   1.3       scw 	} else {
    200   1.3       scw 		/* Otherwise just L_DD[3:0] */
    201   1.3       scw 		nldd = 4;
    202   1.1       bsh 	}
    203   1.1       bsh 
    204   1.3       scw 	while (nldd--)
    205   1.3       scw 		pxa2x0_gpio_set_function(58 + nldd, GPIO_ALT_FN_2_OUT);
    206   1.1       bsh 
    207   1.4       bsh 	pxa2x0_lcd_geometry(sc, geom);
    208   1.1       bsh }
    209   1.1       bsh 
    210  1.14      ober /*
    211  1.14      ober  * Common driver attachment code.
    212  1.14      ober  */
    213  1.14      ober void
    214  1.14      ober pxa2x0_lcd_attach_sub(struct pxa2x0_lcd_softc *sc,
    215  1.16    nonaka     struct pxaip_attach_args *pxa, const struct lcd_panel_geometry *geom)
    216  1.14      ober {
    217  1.14      ober 	bus_space_tag_t iot = pxa->pxa_iot;
    218  1.14      ober 	bus_space_handle_t ioh;
    219  1.14      ober 	int error;
    220  1.14      ober 
    221  1.14      ober 	sc->n_screens = 0;
    222  1.14      ober 	LIST_INIT(&sc->screens);
    223   1.1       bsh 
    224  1.14      ober 	/* map controller registers */
    225  1.15     peter 	error = bus_space_map(iot, PXA2X0_LCDC_BASE,
    226  1.15     peter 			       PXA2X0_LCDC_SIZE, 0, &ioh);
    227  1.15     peter 	if (error) {
    228  1.15     peter 		printf(": failed to map registers (errno=%d)\n", error);
    229  1.15     peter 		return;
    230  1.15     peter 	}
    231  1.15     peter 
    232  1.15     peter 	sc->iot = iot;
    233  1.15     peter 	sc->ioh = ioh;
    234  1.15     peter 	sc->dma_tag = &pxa2x0_bus_dma_tag;
    235  1.15     peter 
    236  1.15     peter 	sc->ih = pxa2x0_intr_establish(PXA2X0_INT_LCD, IPL_BIO, lcdintr, sc);
    237  1.15     peter 	if (sc->ih == NULL) {
    238  1.15     peter 		printf(": unable to establish interrupt at irq %d\n",
    239  1.15     peter 		    PXA2X0_INT_LCD);
    240  1.15     peter 		return;
    241  1.15     peter 	}
    242  1.15     peter 
    243  1.15     peter 	printf(": PXA2x0 LCD controller\n");
    244  1.15     peter 
    245  1.15     peter 	pxa2x0_lcd_initialize(sc, geom);
    246  1.15     peter 
    247  1.16    nonaka 	if (pxa2x0_lcd_console.is_console) {
    248  1.16    nonaka 		struct pxa2x0_wsscreen_descr *descr = pxa2x0_lcd_console.descr;
    249  1.15     peter 		struct pxa2x0_lcd_screen *scr;
    250  1.15     peter 		struct rasops_info *ri;
    251  1.15     peter 		long defattr;
    252  1.15     peter 
    253  1.15     peter 		error = pxa2x0_lcd_new_screen(sc, descr->depth, &scr);
    254  1.14      ober 		if (error) {
    255  1.15     peter 			printf("%s: unable to create new screen (errno=%d)",
    256  1.15     peter 			    sc->dev.dv_xname, error);
    257  1.14      ober 			return;
    258  1.14      ober 		}
    259  1.14      ober 
    260  1.15     peter 		ri = &scr->rinfo;
    261  1.15     peter 		ri->ri_hw = (void *)scr;
    262  1.15     peter 		ri->ri_bits = scr->buf_va;
    263  1.15     peter 		pxa2x0_lcd_setup_rasops(sc, ri, descr, geom);
    264  1.15     peter 
    265  1.15     peter 		/* assumes 16 bpp */
    266  1.15     peter 		(*ri->ri_ops.allocattr)(ri, 0, 0, 0, &defattr);
    267  1.15     peter 
    268  1.15     peter 		pxa2x0_lcd_start_dma(sc, scr);
    269  1.15     peter 		sc->active = scr;
    270  1.15     peter 
    271  1.15     peter 		wsdisplay_cnattach(&descr->c, ri, ri->ri_ccol, ri->ri_crow,
    272  1.15     peter 		    defattr);
    273  1.14      ober 
    274  1.15     peter 		printf("%s: console\n", sc->dev.dv_xname);
    275  1.16    nonaka 	}
    276  1.16    nonaka }
    277  1.16    nonaka 
    278  1.16    nonaka int
    279  1.16    nonaka pxa2x0_lcd_cnattach(struct pxa2x0_wsscreen_descr *descr,
    280  1.16    nonaka     const struct lcd_panel_geometry *geom)
    281  1.16    nonaka {
    282  1.16    nonaka 
    283  1.16    nonaka 	pxa2x0_lcd_console.descr = descr;
    284  1.16    nonaka 	pxa2x0_lcd_console.geom = geom;
    285  1.16    nonaka 	pxa2x0_lcd_console.is_console = 1;
    286  1.14      ober 
    287  1.16    nonaka 	return 0;
    288  1.14      ober }
    289  1.14      ober 
    290  1.14      ober /*
    291  1.14      ober  * Interrupt handler.
    292  1.14      ober  */
    293   1.1       bsh int
    294   1.1       bsh lcdintr(void *arg)
    295   1.1       bsh {
    296  1.15     peter 	struct pxa2x0_lcd_softc *sc = (struct pxa2x0_lcd_softc *)arg;
    297   1.1       bsh 	bus_space_tag_t iot = sc->iot;
    298   1.1       bsh 	bus_space_handle_t ioh = sc->ioh;
    299  1.15     peter 	uint32_t status;
    300   1.1       bsh 
    301   1.4       bsh 	status = bus_space_read_4(iot, ioh, LCDC_LCSR);
    302   1.1       bsh 	/* Clear stickey status bits */
    303   1.4       bsh 	bus_space_write_4(iot, ioh, LCDC_LCSR, status);
    304   1.1       bsh 
    305   1.1       bsh 	return 1;
    306   1.1       bsh }
    307   1.1       bsh 
    308  1.14      ober /*
    309  1.14      ober  * Enable DMA to cause the display to be refreshed periodically.
    310  1.14      ober  * This brings the screen to life...
    311  1.14      ober  */
    312   1.1       bsh void
    313   1.4       bsh pxa2x0_lcd_start_dma(struct pxa2x0_lcd_softc *sc,
    314   1.4       bsh     struct pxa2x0_lcd_screen *scr)
    315   1.1       bsh {
    316  1.14      ober 	bus_space_tag_t iot;
    317  1.14      ober 	bus_space_handle_t ioh;
    318   1.1       bsh 	uint32_t tmp;
    319   1.1       bsh 	int val, save;
    320   1.1       bsh 
    321  1.15     peter 	iot = sc->iot;
    322  1.15     peter 	ioh = sc->ioh;
    323  1.14      ober 
    324   1.4       bsh 	save = disable_interrupts(I32_bit);
    325   1.1       bsh 
    326   1.4       bsh 	switch (scr->depth) {
    327   1.1       bsh 	case 1: val = 0; break;
    328   1.1       bsh 	case 2: val = 1; break;
    329   1.1       bsh 	case 4: val = 2; break;
    330   1.1       bsh 	case 8: val = 3; break;
    331  1.10       bsh 	case 16: val = 4; break;
    332  1.10       bsh 	case 18: val = 5; break;
    333  1.10       bsh 	case 24: val = 33; break;
    334   1.1       bsh 	default:
    335   1.1       bsh 		val = 4; break;
    336   1.1       bsh 	}
    337   1.1       bsh 
    338   1.4       bsh 	tmp = bus_space_read_4(iot, ioh, LCDC_LCCR3);
    339  1.15     peter 	if (CPU_IS_PXA270) {
    340  1.10       bsh 		bus_space_write_4(iot, ioh, LCDC_LCCR3,
    341  1.23    nonaka 		  (tmp & ~(LCCR3_BPP|LCCR3_BPP3)) | (val << LCCR3_BPP_SHIFT));
    342  1.15     peter 	} else {
    343  1.10       bsh 		bus_space_write_4(iot, ioh, LCDC_LCCR3,
    344  1.10       bsh 		    (tmp & ~LCCR3_BPP) | (val << LCCR3_BPP_SHIFT));
    345  1.15     peter 	}
    346   1.1       bsh 
    347   1.4       bsh 	bus_space_write_4(iot, ioh, LCDC_FDADR0,
    348  1.10       bsh 	    scr->depth >= 16 ? scr->dma_desc_pa :
    349   1.4       bsh 	    scr->dma_desc_pa + 2 * sizeof (struct lcd_dma_descriptor));
    350   1.4       bsh 	bus_space_write_4(iot, ioh, LCDC_FDADR1,
    351   1.4       bsh 	    scr->dma_desc_pa + 1 * sizeof (struct lcd_dma_descriptor));
    352   1.1       bsh 
    353   1.1       bsh 	/* clear status */
    354   1.4       bsh 	bus_space_write_4(iot, ioh, LCDC_LCSR, 0);
    355   1.1       bsh 
    356   1.1       bsh 	delay(1000);			/* ??? */
    357   1.1       bsh 
    358   1.1       bsh 	/* Enable LCDC */
    359   1.4       bsh 	tmp = bus_space_read_4(iot, ioh, LCDC_LCCR0);
    360   1.1       bsh 	/*tmp &= ~LCCR0_SFM;*/
    361   1.4       bsh 	bus_space_write_4(iot, ioh, LCDC_LCCR0, tmp | LCCR0_ENB);
    362   1.1       bsh 
    363   1.4       bsh 	restore_interrupts(save);
    364   1.1       bsh }
    365   1.1       bsh 
    366   1.5       bsh #if NWSDISPLAY > 0
    367  1.14      ober /*
    368  1.14      ober  * Disable screen refresh.
    369  1.14      ober  */
    370   1.1       bsh static void
    371   1.4       bsh pxa2x0_lcd_stop_dma(struct pxa2x0_lcd_softc *sc)
    372   1.1       bsh {
    373  1.15     peter 
    374   1.1       bsh 	/* Stop LCD DMA after current frame */
    375   1.4       bsh 	bus_space_write_4(sc->iot, sc->ioh, LCDC_LCCR0,
    376   1.1       bsh 	    LCCR0_DIS |
    377   1.4       bsh 	    bus_space_read_4(sc->iot, sc->ioh, LCDC_LCCR0));
    378   1.1       bsh 
    379   1.1       bsh 	/* wait for disabling done.
    380   1.1       bsh 	   XXX: use interrupt. */
    381   1.4       bsh 	while (LCCR0_ENB &
    382   1.4       bsh 	    bus_space_read_4(sc->iot, sc->ioh, LCDC_LCCR0))
    383  1.15     peter 		continue;
    384   1.1       bsh 
    385   1.4       bsh 	bus_space_write_4(sc->iot, sc->ioh, LCDC_LCCR0,
    386   1.1       bsh 	    ~LCCR0_DIS &
    387   1.4       bsh 	    bus_space_read_4(sc->iot, sc->ioh, LCDC_LCCR0));
    388   1.1       bsh }
    389   1.5       bsh #endif
    390   1.1       bsh 
    391   1.1       bsh #define _rgb(r,g,b)	(((r)<<11) | ((g)<<5) | b)
    392   1.1       bsh #define rgb(r,g,b)	_rgb((r)>>1,g,(b)>>1)
    393   1.1       bsh 
    394   1.1       bsh #define L	0x1f			/* low intensity */
    395   1.1       bsh #define H	0x3f			/* hight intensity */
    396   1.1       bsh 
    397   1.1       bsh static uint16_t basic_color_map[] = {
    398   1.1       bsh 	rgb(	0,   0,   0),		/* black */
    399   1.1       bsh 	rgb(	L,   0,   0),		/* red */
    400   1.1       bsh 	rgb(	0,   L,   0),		/* green */
    401   1.1       bsh 	rgb(	L,   L,   0),		/* brown */
    402   1.1       bsh 	rgb(	0,   0,   L),		/* blue */
    403   1.1       bsh 	rgb(	L,   0,   L),		/* magenta */
    404   1.1       bsh 	rgb(	0,   L,   L),		/* cyan */
    405   1.1       bsh 	_rgb(0x1c,0x38,0x1c),		/* white */
    406   1.1       bsh 
    407   1.1       bsh 	rgb(	L,   L,   L),		/* black */
    408   1.1       bsh 	rgb(	H,   0,   0),		/* red */
    409   1.1       bsh 	rgb(	0,   H,   0),		/* green */
    410   1.1       bsh 	rgb(	H,   H,   0),		/* brown */
    411   1.1       bsh 	rgb(	0,   0,   H),		/* blue */
    412   1.1       bsh 	rgb(	H,   0,   H),		/* magenta */
    413   1.1       bsh 	rgb(	0,   H,   H),		/* cyan */
    414   1.1       bsh 	rgb(	H,   H,   H)
    415   1.1       bsh };
    416   1.1       bsh 
    417   1.1       bsh #undef H
    418   1.1       bsh #undef L
    419   1.1       bsh 
    420   1.1       bsh static void
    421   1.4       bsh init_pallet(uint16_t *buf, int depth)
    422   1.1       bsh {
    423   1.1       bsh 	int i;
    424   1.1       bsh 
    425   1.1       bsh 	/* convert RGB332 to RGB565 */
    426   1.4       bsh 	switch (depth) {
    427   1.1       bsh 	case 8:
    428   1.1       bsh 	case 4:
    429   1.1       bsh #if 0
    430   1.4       bsh 		for (i=0; i <= 255; ++i) {
    431   1.1       bsh 			buf[i] = ((9 * ((i>>5) & 0x07)) <<11) |
    432   1.1       bsh 			    ((9 * ((i>>2) & 0x07)) << 5) |
    433   1.4       bsh 			    ((21 * (i & 0x03))/2);
    434   1.1       bsh 		}
    435   1.1       bsh #else
    436   1.4       bsh 		memcpy(buf, basic_color_map, sizeof basic_color_map);
    437   1.4       bsh 		for (i=16; i < (1<<depth); ++i)
    438   1.1       bsh 			buf[i] = 0xffff;
    439   1.1       bsh #endif
    440   1.1       bsh 		break;
    441   1.8       bsh 	case 16:
    442   1.8       bsh 		/* pallet is not needed */
    443   1.8       bsh 		break;
    444   1.1       bsh 	default:
    445   1.8       bsh 		/* other depths are not supported */
    446   1.8       bsh 		break;
    447   1.1       bsh 	}
    448   1.1       bsh }
    449   1.1       bsh 
    450  1.14      ober /*
    451  1.14      ober  * Create and initialize a new screen buffer.
    452  1.14      ober  */
    453  1.14      ober int
    454  1.15     peter pxa2x0_lcd_new_screen(struct pxa2x0_lcd_softc *sc, int depth,
    455  1.15     peter      struct pxa2x0_lcd_screen **scrpp)
    456   1.1       bsh {
    457  1.14      ober 	bus_space_tag_t iot;
    458  1.14      ober 	bus_space_handle_t ioh;
    459  1.14      ober 	bus_dma_tag_t dma_tag;
    460  1.14      ober 	const struct lcd_panel_geometry *geometry;
    461  1.15     peter 	struct pxa2x0_lcd_screen *scr = NULL;
    462   1.1       bsh 	int width, height;
    463   1.1       bsh 	bus_size_t size;
    464  1.12    simonb 	int error, pallet_size;
    465   1.1       bsh 	int busdma_flag = (cold ? BUS_DMA_NOWAIT : BUS_DMA_WAITOK);
    466   1.1       bsh 	struct lcd_dma_descriptor *desc;
    467   1.1       bsh 	paddr_t buf_pa, desc_pa;
    468   1.1       bsh 
    469  1.15     peter 	iot = sc->iot;
    470  1.15     peter 	ioh = sc->ioh;
    471  1.15     peter 	dma_tag = sc->dma_tag;
    472  1.15     peter 	geometry = sc->geometry;
    473  1.14      ober 
    474  1.14      ober 	width = geometry->panel_width;
    475  1.14      ober 	height = geometry->panel_height;
    476   1.1       bsh 	pallet_size = 0;
    477   1.1       bsh 
    478   1.4       bsh 	switch (depth) {
    479   1.1       bsh 	case 1:
    480   1.1       bsh 	case 2:
    481   1.1       bsh 	case 4:
    482   1.1       bsh 	case 8:
    483   1.1       bsh 		pallet_size = (1<<depth) * sizeof (uint16_t);
    484   1.1       bsh 		/* FALLTHROUGH */
    485   1.1       bsh 	case 16:
    486   1.1       bsh 		size = roundup(width,4)*depth/8 * height;
    487   1.1       bsh 		break;
    488  1.10       bsh 	case 18:
    489  1.10       bsh 	case 24:
    490  1.10       bsh 		size = roundup(width,4) * 4 * height;
    491  1.10       bsh 		break;
    492  1.10       bsh 	case 19:
    493  1.10       bsh 	case 25:
    494  1.14      ober 		printf("%s: Not supported depth (%d)\n",
    495  1.15     peter 		    sc->dev.dv_xname, depth);
    496  1.14      ober 		return EINVAL;
    497   1.1       bsh 	default:
    498  1.14      ober 		printf("%s: Unknown depth (%d)\n",
    499  1.15     peter 		    sc->dev.dv_xname, depth);
    500  1.14      ober 		return EINVAL;
    501   1.1       bsh 	}
    502   1.1       bsh 
    503  1.15     peter 	scr = malloc(sizeof(*scr), M_DEVBUF, M_NOWAIT);
    504  1.15     peter 	if (scr == NULL)
    505  1.15     peter 		return ENOMEM;
    506  1.15     peter 
    507  1.14      ober 	memset(scr, 0, sizeof(*scr));
    508   1.1       bsh 
    509   1.1       bsh 	scr->nsegs = 0;
    510   1.1       bsh 	scr->depth = depth;
    511   1.1       bsh 	scr->buf_size = size;
    512   1.1       bsh 	scr->buf_va = NULL;
    513   1.1       bsh 	size = roundup(size,16) + 3 * sizeof (struct lcd_dma_descriptor)
    514   1.1       bsh 	    + pallet_size;
    515   1.1       bsh 
    516  1.15     peter 	error = bus_dmamem_alloc(dma_tag, size, 16, 0, scr->segs, 1,
    517  1.15     peter 	    &scr->nsegs, busdma_flag);
    518   1.1       bsh 
    519  1.12    simonb 	if (error || scr->nsegs != 1) {
    520  1.12    simonb 		/* XXX:
    521  1.12    simonb 		 * Actually we can handle nsegs>1 case by means
    522  1.12    simonb 		 * of multiple DMA descriptors for a panel.  It
    523  1.12    simonb 		 * will make code here a bit hairly.
    524  1.12    simonb 		 */
    525  1.14      ober 		if (error == 0)
    526  1.14      ober 			error = E2BIG;
    527   1.1       bsh 		goto bad;
    528  1.12    simonb 	}
    529   1.1       bsh 
    530  1.15     peter 	error = bus_dmamem_map(dma_tag, scr->segs, scr->nsegs, size,
    531  1.17  christos 	    (void **)&scr->buf_va, busdma_flag | BUS_DMA_COHERENT);
    532   1.4       bsh 	if (error)
    533   1.1       bsh 		goto bad;
    534   1.1       bsh 
    535  1.15     peter 	memset(scr->buf_va, 0, scr->buf_size);
    536   1.1       bsh 
    537   1.1       bsh 	/* map memory for DMA */
    538  1.15     peter 	error = bus_dmamap_create(dma_tag, 1024*1024*2, 1, 1024*1024*2, 0,
    539  1.15     peter 	    busdma_flag, &scr->dma);
    540  1.15     peter 	if (error)
    541   1.1       bsh 		goto bad;
    542  1.15     peter 
    543  1.15     peter 	error = bus_dmamap_load(dma_tag, scr->dma, scr->buf_va, size,
    544  1.15     peter 	    NULL, busdma_flag);
    545  1.15     peter 	if (error)
    546   1.1       bsh 		goto bad;
    547   1.1       bsh 
    548   1.1       bsh 	buf_pa = scr->segs[0].ds_addr;
    549   1.2   thorpej 	desc_pa = buf_pa + roundup(size, PAGE_SIZE) - 3*sizeof *desc;
    550   1.1       bsh 
    551   1.1       bsh 	/* make descriptors at the top of mapped memory */
    552   1.1       bsh 	desc = (struct lcd_dma_descriptor *)(
    553  1.18    nonaka 		(char *)(scr->buf_va) + roundup(size, PAGE_SIZE) -
    554   1.2   thorpej 			  3*sizeof *desc);
    555   1.1       bsh 
    556   1.1       bsh 	desc[0].fdadr = desc_pa;
    557   1.1       bsh 	desc[0].fsadr = buf_pa;
    558   1.1       bsh 	desc[0].ldcmd = scr->buf_size;
    559   1.1       bsh 
    560   1.4       bsh 	if (pallet_size) {
    561   1.4       bsh 		init_pallet((uint16_t *)((char *)desc - pallet_size), depth);
    562   1.1       bsh 
    563   1.1       bsh 		desc[2].fdadr = desc_pa; /* chain to panel 0 */
    564   1.1       bsh 		desc[2].fsadr = desc_pa - pallet_size;
    565   1.1       bsh 		desc[2].ldcmd = pallet_size | LDCMD_PAL;
    566   1.1       bsh 	}
    567   1.1       bsh 
    568  1.15     peter 	if (geometry->panel_info & LCDPANEL_DUAL) {
    569   1.1       bsh 		/* Dual panel */
    570   1.1       bsh 		desc[1].fdadr = desc_pa + sizeof *desc;
    571   1.1       bsh 		desc[1].fsadr = buf_pa + scr->buf_size/2;
    572   1.1       bsh 		desc[0].ldcmd = desc[1].ldcmd = scr->buf_size/2;
    573   1.1       bsh 
    574   1.1       bsh 	}
    575   1.1       bsh 
    576   1.1       bsh #if 0
    577   1.1       bsh 	desc[0].ldcmd |= LDCMD_SOFINT;
    578   1.1       bsh 	desc[1].ldcmd |= LDCMD_SOFINT;
    579   1.1       bsh #endif
    580   1.1       bsh 
    581   1.1       bsh 	scr->dma_desc = desc;
    582   1.1       bsh 	scr->dma_desc_pa = desc_pa;
    583   1.1       bsh 	scr->map_size = size;		/* used when unmap this. */
    584   1.1       bsh 
    585  1.15     peter 	LIST_INSERT_HEAD(&sc->screens, scr, link);
    586   1.1       bsh 	sc->n_screens++;
    587   1.1       bsh 
    588  1.15     peter 	*scrpp = scr;
    589  1.15     peter 
    590  1.14      ober 	return 0;
    591   1.1       bsh 
    592   1.1       bsh  bad:
    593   1.4       bsh 	if (scr) {
    594   1.4       bsh 		if (scr->buf_va)
    595  1.15     peter 			bus_dmamem_unmap(dma_tag, scr->buf_va, size);
    596   1.4       bsh 		if (scr->nsegs)
    597  1.15     peter 			bus_dmamem_free(dma_tag, scr->segs, scr->nsegs);
    598  1.15     peter 		free(scr, M_DEVBUF);
    599   1.1       bsh 	}
    600  1.15     peter 	*scrpp = NULL;
    601  1.14      ober 	return error;
    602  1.14      ober }
    603  1.14      ober 
    604  1.14      ober /*
    605  1.14      ober  * Initialize rasops for a screen, as well as struct wsscreen_descr if this
    606  1.14      ober  * is the first screen creation.
    607  1.14      ober  */
    608  1.15     peter static void
    609  1.15     peter pxa2x0_lcd_setup_rasops(struct pxa2x0_lcd_softc *sc, struct rasops_info *rinfo,
    610  1.14      ober     struct pxa2x0_wsscreen_descr *descr,
    611  1.14      ober     const struct lcd_panel_geometry *geom)
    612  1.14      ober {
    613  1.14      ober 
    614  1.14      ober 	rinfo->ri_flg = descr->flags;
    615  1.14      ober 	rinfo->ri_depth = descr->depth;
    616  1.14      ober 	rinfo->ri_width = geom->panel_width;
    617  1.14      ober 	rinfo->ri_height = geom->panel_height;
    618  1.14      ober 	rinfo->ri_stride = rinfo->ri_width * rinfo->ri_depth / 8;
    619  1.14      ober #ifdef notyet
    620  1.14      ober 	rinfo->ri_wsfcookie = -1;	/* XXX */
    621  1.14      ober #endif
    622  1.14      ober 
    623  1.14      ober 	/* swap B and R */
    624  1.14      ober 	if (descr->depth == 16) {
    625  1.14      ober 		rinfo->ri_rnum = 5;
    626  1.14      ober 		rinfo->ri_rpos = 11;
    627  1.14      ober 		rinfo->ri_gnum = 6;
    628  1.14      ober 		rinfo->ri_gpos = 5;
    629  1.14      ober 		rinfo->ri_bnum = 5;
    630  1.14      ober 		rinfo->ri_bpos = 0;
    631  1.14      ober 	}
    632  1.14      ober 
    633  1.14      ober 	if (descr->c.nrows == 0) {
    634  1.14      ober 		/* get rasops to compute screen size the first time */
    635  1.14      ober 		rasops_init(rinfo, 100, 100);
    636  1.15     peter 	} else {
    637  1.14      ober 		rasops_init(rinfo, descr->c.nrows, descr->c.ncols);
    638  1.15     peter 	}
    639  1.14      ober 
    640  1.14      ober 	descr->c.nrows = rinfo->ri_rows;
    641  1.14      ober 	descr->c.ncols = rinfo->ri_cols;
    642  1.14      ober 	descr->c.capabilities = rinfo->ri_caps;
    643  1.14      ober 	descr->c.textops = &rinfo->ri_ops;
    644  1.14      ober }
    645  1.14      ober 
    646  1.14      ober /*
    647  1.14      ober  * Power management
    648  1.14      ober  */
    649  1.14      ober void
    650  1.14      ober pxa2x0_lcd_suspend(struct pxa2x0_lcd_softc *sc)
    651  1.14      ober {
    652  1.14      ober 
    653  1.15     peter 	if (sc->active) {
    654  1.14      ober 		pxa2x0_lcd_stop_dma(sc);
    655  1.14      ober 		pxa2x0_clkman_config(CKEN_LCD, 0);
    656  1.14      ober 	}
    657  1.14      ober }
    658  1.14      ober 
    659  1.14      ober void
    660  1.14      ober pxa2x0_lcd_resume(struct pxa2x0_lcd_softc *sc)
    661  1.14      ober {
    662  1.14      ober 
    663  1.15     peter 	if (sc->active) {
    664  1.14      ober 		pxa2x0_lcd_initialize(sc, sc->geometry);
    665  1.14      ober 		pxa2x0_lcd_start_dma(sc, sc->active);
    666  1.14      ober 	}
    667   1.1       bsh }
    668   1.1       bsh 
    669  1.14      ober void
    670  1.14      ober pxa2x0_lcd_power(int why, void *v)
    671  1.14      ober {
    672  1.14      ober 	struct pxa2x0_lcd_softc *sc = v;
    673  1.14      ober 
    674  1.14      ober 	switch (why) {
    675  1.14      ober 	case PWR_SUSPEND:
    676  1.14      ober 	case PWR_STANDBY:
    677  1.14      ober 		pxa2x0_lcd_suspend(sc);
    678  1.14      ober 		break;
    679  1.14      ober 
    680  1.14      ober 	case PWR_RESUME:
    681  1.14      ober 		pxa2x0_lcd_resume(sc);
    682  1.14      ober 		break;
    683  1.14      ober 	}
    684  1.14      ober }
    685   1.1       bsh 
    686   1.1       bsh #if NWSDISPLAY > 0
    687   1.1       bsh /*
    688   1.1       bsh  * Initialize struct wsscreen_descr based on values calculated by
    689   1.1       bsh  * raster operation subsystem.
    690   1.1       bsh  */
    691   1.1       bsh int
    692   1.1       bsh pxa2x0_lcd_setup_wsscreen(struct pxa2x0_wsscreen_descr *descr,
    693   1.1       bsh     const struct lcd_panel_geometry *geom,
    694   1.4       bsh     const char *fontname)
    695   1.1       bsh {
    696   1.1       bsh 	int width = geom->panel_width;
    697   1.1       bsh 	int height = geom->panel_height;
    698   1.1       bsh 	int cookie = -1;
    699   1.1       bsh 	struct rasops_info rinfo;
    700   1.1       bsh 
    701   1.4       bsh 	memset(&rinfo, 0, sizeof rinfo);
    702   1.1       bsh 
    703   1.4       bsh 	if (fontname) {
    704   1.1       bsh 		wsfont_init();
    705   1.9        he 		cookie = wsfont_find(fontname, 0, 0, 0,
    706   1.4       bsh 		    WSDISPLAY_FONTORDER_L2R, WSDISPLAY_FONTORDER_L2R);
    707   1.4       bsh 		if (cookie < 0 ||
    708   1.4       bsh 		    wsfont_lock(cookie, &rinfo.ri_font))
    709   1.1       bsh 			return -1;
    710   1.1       bsh 	}
    711   1.1       bsh 	else {
    712   1.1       bsh 		/* let rasops_init() choose any font */
    713   1.1       bsh 	}
    714   1.1       bsh 
    715   1.1       bsh 	/* let rasops_init calculate # of cols and rows in character */
    716   1.1       bsh 	rinfo.ri_flg = 0;
    717   1.1       bsh 	rinfo.ri_depth = descr->depth;
    718   1.1       bsh 	rinfo.ri_bits = NULL;
    719   1.1       bsh 	rinfo.ri_width = width;
    720   1.1       bsh 	rinfo.ri_height = height;
    721   1.1       bsh 	rinfo.ri_stride = width * rinfo.ri_depth / 8;
    722  1.10       bsh #ifdef	CPU_XSCALE_PXA270
    723  1.15     peter 	if (rinfo.ri_depth > 16)
    724  1.15     peter 		rinfo.ri_stride = width * 4;
    725  1.10       bsh #endif
    726   1.1       bsh 	rinfo.ri_wsfcookie = cookie;
    727   1.1       bsh 
    728   1.4       bsh 	rasops_init(&rinfo, 100, 100);
    729   1.1       bsh 
    730   1.1       bsh 	descr->c.nrows = rinfo.ri_rows;
    731   1.1       bsh 	descr->c.ncols = rinfo.ri_cols;
    732   1.1       bsh 	descr->c.capabilities = rinfo.ri_caps;
    733   1.1       bsh 
    734   1.1       bsh 	return cookie;
    735   1.1       bsh }
    736   1.1       bsh 
    737   1.1       bsh int
    738   1.1       bsh pxa2x0_lcd_show_screen(void *v, void *cookie, int waitok,
    739   1.1       bsh     void (*cb)(void *, int, int), void *cbarg)
    740   1.1       bsh {
    741   1.1       bsh 	struct pxa2x0_lcd_softc *sc = v;
    742   1.1       bsh 	struct pxa2x0_lcd_screen *scr = cookie, *old;
    743   1.1       bsh 
    744   1.1       bsh 	old = sc->active;
    745   1.4       bsh 	if (old == scr)
    746   1.1       bsh 		return 0;
    747   1.1       bsh 
    748   1.4       bsh 	if (old)
    749   1.4       bsh 		pxa2x0_lcd_stop_dma(sc);
    750   1.1       bsh 
    751   1.4       bsh 	pxa2x0_lcd_start_dma(sc, scr);
    752   1.1       bsh 
    753   1.1       bsh 	sc->active = scr;
    754   1.1       bsh 	return 0;
    755   1.1       bsh }
    756   1.1       bsh 
    757   1.1       bsh int
    758   1.1       bsh pxa2x0_lcd_alloc_screen(void *v, const struct wsscreen_descr *_type,
    759   1.1       bsh     void **cookiep, int *curxp, int *curyp, long *attrp)
    760   1.1       bsh {
    761   1.1       bsh 	struct pxa2x0_lcd_softc *sc = v;
    762   1.1       bsh 	struct pxa2x0_lcd_screen *scr;
    763   1.9        he 	const struct pxa2x0_wsscreen_descr *type =
    764   1.9        he 		(const struct pxa2x0_wsscreen_descr *)_type;
    765  1.14      ober 	int error;
    766   1.1       bsh 
    767  1.15     peter 	error = pxa2x0_lcd_new_screen(sc, type->depth, &scr);
    768  1.15     peter 	if (error)
    769  1.15     peter 		return error;
    770  1.14      ober 
    771   1.1       bsh 	/*
    772   1.1       bsh 	 * initialize raster operation for this screen.
    773   1.1       bsh 	 */
    774   1.1       bsh 	scr->rinfo.ri_flg = 0;
    775   1.1       bsh 	scr->rinfo.ri_depth = type->depth;
    776   1.1       bsh 	scr->rinfo.ri_bits = scr->buf_va;
    777   1.1       bsh 	scr->rinfo.ri_width = sc->geometry->panel_width;
    778   1.1       bsh 	scr->rinfo.ri_height = sc->geometry->panel_height;
    779   1.1       bsh 	scr->rinfo.ri_stride = scr->rinfo.ri_width * scr->rinfo.ri_depth / 8;
    780  1.10       bsh #ifdef CPU_XSCALE_PXA270
    781  1.10       bsh 	if (scr->rinfo.ri_depth > 16)
    782  1.10       bsh 		scr->rinfo.ri_stride = scr->rinfo.ri_width * 4;
    783  1.10       bsh #endif
    784   1.1       bsh 	scr->rinfo.ri_wsfcookie = -1;	/* XXX */
    785   1.1       bsh 
    786   1.4       bsh 	rasops_init(&scr->rinfo, type->c.nrows, type->c.ncols);
    787   1.1       bsh 
    788   1.4       bsh 	(* scr->rinfo.ri_ops.allocattr)(&scr->rinfo, 0, 0, 0, attrp);
    789   1.1       bsh 
    790   1.1       bsh 	*cookiep = scr;
    791   1.1       bsh 	*curxp = 0;
    792   1.1       bsh 	*curyp = 0;
    793   1.1       bsh 
    794   1.1       bsh 	return 0;
    795   1.1       bsh }
    796   1.1       bsh 
    797   1.1       bsh void
    798   1.1       bsh pxa2x0_lcd_free_screen(void *v, void *cookie)
    799   1.1       bsh {
    800   1.1       bsh 	struct pxa2x0_lcd_softc *sc = v;
    801   1.1       bsh 	struct pxa2x0_lcd_screen *scr = cookie;
    802   1.1       bsh 
    803   1.4       bsh 	LIST_REMOVE(scr, link);
    804   1.1       bsh 	sc->n_screens--;
    805   1.4       bsh 	if (scr == sc->active) {
    806   1.1       bsh 		/* at first, we need to stop LCD DMA */
    807   1.1       bsh 		sc->active = NULL;
    808   1.1       bsh 
    809   1.4       bsh 		printf("lcd_free on active screen\n");
    810   1.1       bsh 
    811   1.1       bsh 		pxa2x0_lcd_stop_dma(sc);
    812   1.1       bsh 	}
    813   1.1       bsh 
    814   1.4       bsh 	if (scr->buf_va)
    815   1.4       bsh 		bus_dmamem_unmap(sc->dma_tag, scr->buf_va, scr->map_size);
    816   1.4       bsh 	if (scr->nsegs > 0)
    817   1.4       bsh 		bus_dmamem_free(sc->dma_tag, scr->segs, scr->nsegs);
    818   1.4       bsh 	free(scr, M_DEVBUF);
    819   1.1       bsh }
    820   1.1       bsh 
    821   1.1       bsh int
    822  1.17  christos pxa2x0_lcd_ioctl(void *v, void *vs, u_long cmd, void *data, int flag,
    823  1.13      jmmv 	struct lwp *l)
    824   1.1       bsh {
    825   1.1       bsh 	struct pxa2x0_lcd_softc *sc = v;
    826  1.21    nonaka 	struct pxa2x0_lcd_screen *scr = sc->active;  /* ??? */
    827   1.1       bsh 	struct wsdisplay_fbinfo *wsdisp_info;
    828   1.1       bsh 	uint32_t ccr0;
    829   1.1       bsh 
    830   1.1       bsh 	switch (cmd) {
    831   1.1       bsh 	case WSDISPLAYIO_GTYPE:
    832  1.15     peter 		*(int *)data = WSDISPLAY_TYPE_UNKNOWN;	/* XXX */
    833   1.1       bsh 		return 0;
    834   1.1       bsh 
    835   1.1       bsh 	case WSDISPLAYIO_GINFO:
    836   1.1       bsh 		wsdisp_info = (struct wsdisplay_fbinfo *)data;
    837   1.1       bsh 		wsdisp_info->height = sc->geometry->panel_height;
    838   1.1       bsh 		wsdisp_info->width = sc->geometry->panel_width;
    839  1.21    nonaka 		wsdisp_info->depth = scr->depth;
    840   1.1       bsh 		wsdisp_info->cmsize = 0;
    841   1.1       bsh 		return 0;
    842   1.1       bsh 
    843  1.21    nonaka 	case WSDISPLAYIO_LINEBYTES:
    844  1.21    nonaka 		*(u_int *)data = scr->rinfo.ri_stride;
    845  1.21    nonaka 		return 0;
    846  1.21    nonaka 
    847   1.1       bsh 	case WSDISPLAYIO_GETCMAP:
    848   1.1       bsh 	case WSDISPLAYIO_PUTCMAP:
    849   1.1       bsh 		return EPASSTHROUGH;	/* XXX Colormap */
    850   1.1       bsh 
    851   1.1       bsh 	case WSDISPLAYIO_SVIDEO:
    852   1.4       bsh 		if (*(int *)data == WSDISPLAYIO_VIDEO_ON) {
    853   1.1       bsh 		  /* turn it on */
    854   1.1       bsh 		}
    855   1.1       bsh 		else {
    856   1.1       bsh 		  /* start LCD shutdown */
    857   1.1       bsh 		  /* sleep until interrupt */
    858   1.1       bsh 		}
    859   1.1       bsh 		return 0;
    860   1.1       bsh 
    861   1.1       bsh 	case WSDISPLAYIO_GVIDEO:
    862   1.4       bsh 		ccr0 = bus_space_read_4(sc->iot, sc->ioh, LCDC_LCCR0);
    863   1.1       bsh 		*(u_int *)data = (ccr0 & (LCCR0_ENB|LCCR0_DIS)) == LCCR0_ENB ?
    864   1.1       bsh 		    WSDISPLAYIO_VIDEO_ON : WSDISPLAYIO_VIDEO_OFF;
    865   1.1       bsh 		return 0;
    866   1.1       bsh 
    867   1.1       bsh 	case WSDISPLAYIO_GCURPOS:
    868   1.1       bsh 	case WSDISPLAYIO_SCURPOS:
    869   1.1       bsh 	case WSDISPLAYIO_GCURMAX:
    870   1.1       bsh 	case WSDISPLAYIO_GCURSOR:
    871   1.1       bsh 	case WSDISPLAYIO_SCURSOR:
    872   1.1       bsh 		return EPASSTHROUGH;	/* XXX */
    873   1.1       bsh 	}
    874   1.1       bsh 
    875   1.1       bsh 	return EPASSTHROUGH;
    876   1.1       bsh }
    877   1.1       bsh 
    878   1.1       bsh paddr_t
    879  1.13      jmmv pxa2x0_lcd_mmap(void *v, void *vs, off_t offset, int prot)
    880   1.1       bsh {
    881   1.1       bsh 	struct pxa2x0_lcd_softc *sc = v;
    882  1.20    nonaka 	struct pxa2x0_lcd_screen *scr = sc->active;  /* ??? */
    883   1.1       bsh 
    884  1.20    nonaka 	if (scr == NULL)
    885  1.20    nonaka 		return -1;
    886  1.20    nonaka 
    887  1.20    nonaka 	if (offset < 0 ||
    888  1.20    nonaka 	    offset >= scr->rinfo.ri_stride * scr->rinfo.ri_height)
    889   1.1       bsh 		return -1;
    890   1.1       bsh 
    891  1.20    nonaka 	return bus_dmamem_mmap(sc->dma_tag, scr->segs, scr->nsegs,
    892   1.4       bsh 	    offset, prot, BUS_DMA_WAITOK|BUS_DMA_COHERENT);
    893   1.1       bsh }
    894   1.1       bsh 
    895   1.1       bsh 
    896   1.1       bsh static void
    897   1.4       bsh pxa2x0_lcd_cursor(void *cookie, int on, int row, int col)
    898   1.1       bsh {
    899   1.1       bsh 	struct pxa2x0_lcd_screen *scr = cookie;
    900   1.1       bsh 
    901  1.15     peter 	(*scr->rinfo.ri_ops.cursor)(&scr->rinfo, on, row, col);
    902   1.1       bsh }
    903   1.1       bsh 
    904   1.1       bsh static int
    905   1.4       bsh pxa2x0_lcd_mapchar(void *cookie, int c, unsigned int *cp)
    906   1.1       bsh {
    907   1.1       bsh 	struct pxa2x0_lcd_screen *scr = cookie;
    908   1.1       bsh 
    909  1.15     peter 	return (*scr->rinfo.ri_ops.mapchar)(&scr->rinfo, c, cp);
    910   1.1       bsh }
    911   1.1       bsh 
    912   1.1       bsh static void
    913   1.4       bsh pxa2x0_lcd_putchar(void *cookie, int row, int col, u_int uc, long attr)
    914   1.1       bsh {
    915   1.1       bsh 	struct pxa2x0_lcd_screen *scr = cookie;
    916   1.1       bsh 
    917  1.15     peter 	(*scr->rinfo.ri_ops.putchar)(&scr->rinfo, row, col, uc, attr);
    918   1.1       bsh }
    919   1.1       bsh 
    920   1.1       bsh static void
    921   1.4       bsh pxa2x0_lcd_copycols(void *cookie, int row, int src, int dst, int num)
    922   1.1       bsh {
    923   1.1       bsh 	struct pxa2x0_lcd_screen *scr = cookie;
    924   1.1       bsh 
    925  1.15     peter 	(*scr->rinfo.ri_ops.copycols)(&scr->rinfo, row, src, dst, num);
    926   1.1       bsh }
    927   1.1       bsh 
    928   1.1       bsh static void
    929   1.4       bsh pxa2x0_lcd_erasecols(void *cookie, int row, int col, int num, long attr)
    930   1.1       bsh {
    931   1.1       bsh 	struct pxa2x0_lcd_screen *scr = cookie;
    932   1.1       bsh 
    933  1.15     peter 	(*scr->rinfo.ri_ops.erasecols)(&scr->rinfo, row, col, num, attr);
    934   1.1       bsh }
    935   1.1       bsh 
    936   1.1       bsh static void
    937   1.4       bsh pxa2x0_lcd_copyrows(void *cookie, int src, int dst, int num)
    938   1.1       bsh {
    939   1.1       bsh 	struct pxa2x0_lcd_screen *scr = cookie;
    940   1.1       bsh 
    941  1.15     peter 	(*scr->rinfo.ri_ops.copyrows)(&scr->rinfo, src, dst, num);
    942   1.1       bsh }
    943   1.1       bsh 
    944   1.1       bsh static void
    945   1.4       bsh pxa2x0_lcd_eraserows(void *cookie, int row, int num, long attr)
    946   1.1       bsh {
    947   1.1       bsh 	struct pxa2x0_lcd_screen *scr = cookie;
    948   1.1       bsh 
    949  1.15     peter 	(*scr->rinfo.ri_ops.eraserows)(&scr->rinfo, row, num, attr);
    950   1.1       bsh }
    951   1.1       bsh 
    952   1.1       bsh static int
    953   1.4       bsh pxa2x0_lcd_alloc_attr(void *cookie, int fg, int bg, int flg, long *attr)
    954   1.1       bsh {
    955   1.1       bsh 	struct pxa2x0_lcd_screen *scr = cookie;
    956   1.1       bsh 
    957  1.15     peter 	return (*scr->rinfo.ri_ops.allocattr)(&scr->rinfo, fg, bg, flg, attr);
    958   1.1       bsh }
    959   1.1       bsh 
    960   1.1       bsh const struct wsdisplay_emulops pxa2x0_lcd_emulops = {
    961   1.1       bsh 	pxa2x0_lcd_cursor,
    962   1.1       bsh 	pxa2x0_lcd_mapchar,
    963   1.1       bsh 	pxa2x0_lcd_putchar,
    964   1.1       bsh 	pxa2x0_lcd_copycols,
    965   1.1       bsh 	pxa2x0_lcd_erasecols,
    966   1.1       bsh 	pxa2x0_lcd_copyrows,
    967   1.1       bsh 	pxa2x0_lcd_eraserows,
    968   1.1       bsh 	pxa2x0_lcd_alloc_attr
    969   1.1       bsh };
    970   1.1       bsh 
    971   1.1       bsh #endif /* NWSDISPLAY > 0 */
    972