Home | History | Annotate | Line # | Download | only in xscale
pxa2x0_lcd.c revision 1.6
      1 /* $Id: pxa2x0_lcd.c,v 1.6 2003/07/15 00:24:55 lukem Exp $ */
      2 
      3 /*
      4  * Copyright (c) 2002  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. All advertising materials mentioning features or use of this software
     16  *    must display the following acknowledgement:
     17  *	This product includes software developed for the NetBSD Project by
     18  *	Genetec Corporation.
     19  * 4. The name of Genetec Corporation may not be used to endorse or
     20  *    promote products derived from this software without specific prior
     21  *    written permission.
     22  *
     23  * THIS SOFTWARE IS PROVIDED BY GENETEC CORPORATION ``AS IS'' AND
     24  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     25  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     26  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL GENETEC CORPORATION
     27  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     28  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     29  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     30  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     31  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     32  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     33  * POSSIBILITY OF SUCH DAMAGE.
     34  */
     35 
     36 /*
     37  * Support PXA2[15]0's integrated LCD controller.
     38  */
     39 
     40 #include <sys/cdefs.h>
     41 __KERNEL_RCSID(0, "$NetBSD: pxa2x0_lcd.c,v 1.6 2003/07/15 00:24:55 lukem Exp $");
     42 
     43 #include <sys/param.h>
     44 #include <sys/systm.h>
     45 #include <sys/conf.h>
     46 #include <sys/uio.h>
     47 #include <sys/malloc.h>
     48 #include <sys/kernel.h>			/* for cold */
     49 
     50 #include <uvm/uvm_extern.h>
     51 
     52 #include <dev/cons.h>
     53 #include <dev/wscons/wsconsio.h>
     54 #include <dev/wscons/wsdisplayvar.h>
     55 #include <dev/wscons/wscons_callbacks.h>
     56 #include <dev/rasops/rasops.h>
     57 #include <dev/wsfont/wsfont.h>
     58 
     59 #include <machine/bus.h>
     60 #include <machine/cpu.h>
     61 #include <arm/cpufunc.h>
     62 
     63 #include <arm/xscale/pxa2x0var.h>
     64 #include <arm/xscale/pxa2x0reg.h>
     65 #include <arm/xscale/pxa2x0_lcd.h>
     66 #include <arm/xscale/pxa2x0_gpio.h>
     67 
     68 #include "wsdisplay.h"
     69 
     70 int lcdintr(void *);
     71 
     72 void
     73 pxa2x0_lcd_geometry(struct pxa2x0_lcd_softc *sc,
     74     const struct lcd_panel_geometry *info)
     75 {
     76 	int lines;
     77 	bus_space_tag_t iot = sc->iot;
     78 	bus_space_handle_t ioh = sc->ioh;
     79 	uint32_t ccr0;
     80 
     81 	sc->geometry = info;
     82 
     83 	ccr0 = LCCR0_IMASK;
     84 	if (info->panel_info & LCDPANEL_ACTIVE)
     85 		ccr0 |= LCCR0_PAS;	/* active mode */
     86 	if ((info->panel_info & (LCDPANEL_DUAL|LCDPANEL_ACTIVE))
     87 	    == LCDPANEL_DUAL)
     88 		ccr0 |= LCCR0_SDS; /* dual panel */
     89 	if (info->panel_info & LCDPANEL_MONOCHROME)
     90 		ccr0 |= LCCR0_CMS;
     91 	bus_space_write_4(iot, ioh, LCDC_LCCR0, ccr0);
     92 
     93 	bus_space_write_4(iot, ioh, LCDC_LCCR1,
     94 	    (info->panel_width-1)
     95 	    | ((info->hsync_pulse_width-1)<<10)
     96 	    | ((info->end_line_wait-1)<<16)
     97 	    | ((info->beg_line_wait-1)<<24));
     98 
     99 	if (info->panel_info & LCDPANEL_DUAL)
    100 		lines = info->panel_height/2 + info->extra_lines;
    101 	else
    102 		lines = info->panel_height + info->extra_lines;
    103 
    104 	bus_space_write_4(iot, ioh, LCDC_LCCR2,
    105 	    (lines-1)
    106 	    | (info->vsync_pulse_width<<10)
    107 	    | (info->end_frame_wait<<16)
    108 	    | (info->beg_frame_wait<<24));
    109 
    110 	bus_space_write_4(iot, ioh, LCDC_LCCR3,
    111 	    (info->pixel_clock_div<<0)
    112 	    | (info->ac_bias << 8)
    113 	    | ((info->panel_info &
    114 		(LCDPANEL_VSP|LCDPANEL_HSP|LCDPANEL_PCP|LCDPANEL_OEP))
    115 		<<20)
    116 	    | (4 << 24) /* 16bpp */
    117 	    | ((info->panel_info & LCDPANEL_DPC) ? (1<<27) : 0)
    118 	    );
    119 }
    120 
    121 void
    122 pxa2x0_lcd_attach_sub(struct pxa2x0_lcd_softc *sc,
    123     struct pxaip_attach_args *pxa, const struct lcd_panel_geometry *geom)
    124 {
    125 	bus_space_tag_t iot = pxa->pxa_iot;
    126 	bus_space_handle_t ioh;
    127 	int error, nldd;
    128 
    129 	sc->n_screens = 0;
    130 	LIST_INIT(&sc->screens);
    131 
    132 	/* map controller registers */
    133 	error = bus_space_map(iot, PXA2X0_LCDC_BASE,
    134 			       PXA2X0_LCDC_SIZE, 0, &ioh);
    135 	if (error) {
    136 		printf(": failed to map registers %d", error);
    137 		return;
    138 	}
    139 
    140 	sc->iot = iot;
    141 	sc->ioh = ioh;
    142 	sc->dma_tag = &pxa2x0_bus_dma_tag;
    143 
    144 	sc->ih = pxa2x0_intr_establish(17, IPL_BIO, lcdintr, sc);
    145 	if (sc->ih == NULL)
    146 		printf("%s: unable to establish interrupt at irq %d",
    147 		    sc->dev.dv_xname, 17);
    148 
    149 	/* Initialize LCD controller */
    150 
    151 	/* enable clock */
    152 	pxa2x0_clkman_config(CKEN_LCD, 1);
    153 
    154 	bus_space_write_4(iot, ioh, LCDC_LCCR0, LCCR0_IMASK);
    155 
    156 	/*
    157 	 * setup GP[77:58] for LCD
    158 	 */
    159 	/* Always use [FLP]CLK, ACBIAS */
    160 	pxa2x0_gpio_set_function(74, GPIO_ALT_FN_2_OUT);
    161 	pxa2x0_gpio_set_function(75, GPIO_ALT_FN_2_OUT);
    162 	pxa2x0_gpio_set_function(76, GPIO_ALT_FN_2_OUT);
    163 	pxa2x0_gpio_set_function(77, GPIO_ALT_FN_2_OUT);
    164 
    165 	if ((geom->panel_info & LCDPANEL_ACTIVE) ||
    166 	    ((geom->panel_info & (LCDPANEL_MONOCHROME|LCDPANEL_DUAL)) ==
    167 	    LCDPANEL_DUAL)) {
    168 		/* active and color dual panel need L_DD[15:0] */
    169 		nldd = 16;
    170 	} else
    171 	if ((geom->panel_info & LCDPANEL_DUAL) ||
    172 	    !(geom->panel_info & LCDPANEL_MONOCHROME)) {
    173 		/* dual or color need L_DD[7:0] */
    174 		nldd = 8;
    175 	} else {
    176 		/* Otherwise just L_DD[3:0] */
    177 		nldd = 4;
    178 	}
    179 
    180 	while (nldd--)
    181 		pxa2x0_gpio_set_function(58 + nldd, GPIO_ALT_FN_2_OUT);
    182 
    183 	pxa2x0_lcd_geometry(sc, geom);
    184 }
    185 
    186 
    187 int
    188 lcdintr(void *arg)
    189 {
    190 	struct pxa2x0_lcd_softc *sc = arg;
    191 	bus_space_tag_t iot = sc->iot;
    192 	bus_space_handle_t ioh = sc->ioh;
    193 
    194 	static uint32_t status;
    195 
    196 	status = bus_space_read_4(iot, ioh, LCDC_LCSR);
    197 	/* Clear stickey status bits */
    198 	bus_space_write_4(iot, ioh, LCDC_LCSR, status);
    199 
    200 	return 1;
    201 }
    202 
    203 void
    204 pxa2x0_lcd_start_dma(struct pxa2x0_lcd_softc *sc,
    205     struct pxa2x0_lcd_screen *scr)
    206 {
    207 	uint32_t tmp;
    208 	bus_space_tag_t iot = sc->iot;
    209 	bus_space_handle_t ioh = sc->ioh;
    210 	int val, save;
    211 
    212 	save = disable_interrupts(I32_bit);
    213 
    214 	switch (scr->depth) {
    215 	case 1: val = 0; break;
    216 	case 2: val = 1; break;
    217 	case 4: val = 2; break;
    218 	case 8: val = 3; break;
    219 	case 16:    /* FALLTHROUGH */
    220 	default:
    221 		val = 4; break;
    222 	}
    223 
    224 	tmp = bus_space_read_4(iot, ioh, LCDC_LCCR3);
    225 	bus_space_write_4(iot, ioh, LCDC_LCCR3,
    226 	    (tmp & ~LCCR3_BPP) | (val << LCCR3_BPP_SHIFT));
    227 
    228 	bus_space_write_4(iot, ioh, LCDC_FDADR0,
    229 	    scr->depth == 16 ? scr->dma_desc_pa :
    230 	    scr->dma_desc_pa + 2 * sizeof (struct lcd_dma_descriptor));
    231 	bus_space_write_4(iot, ioh, LCDC_FDADR1,
    232 	    scr->dma_desc_pa + 1 * sizeof (struct lcd_dma_descriptor));
    233 
    234 	/* clear status */
    235 	bus_space_write_4(iot, ioh, LCDC_LCSR, 0);
    236 
    237 	delay(1000);			/* ??? */
    238 
    239 	/* Enable LCDC */
    240 	tmp = bus_space_read_4(iot, ioh, LCDC_LCCR0);
    241 	/*tmp &= ~LCCR0_SFM;*/
    242 	bus_space_write_4(iot, ioh, LCDC_LCCR0, tmp | LCCR0_ENB);
    243 
    244 	restore_interrupts(save);
    245 
    246 }
    247 
    248 
    249 #if NWSDISPLAY > 0
    250 static void
    251 pxa2x0_lcd_stop_dma(struct pxa2x0_lcd_softc *sc)
    252 {
    253 	/* Stop LCD DMA after current frame */
    254 	bus_space_write_4(sc->iot, sc->ioh, LCDC_LCCR0,
    255 	    LCCR0_DIS |
    256 	    bus_space_read_4(sc->iot, sc->ioh, LCDC_LCCR0));
    257 
    258 	/* wait for disabling done.
    259 	   XXX: use interrupt. */
    260 	while (LCCR0_ENB &
    261 	    bus_space_read_4(sc->iot, sc->ioh, LCDC_LCCR0))
    262 		;
    263 
    264 	bus_space_write_4(sc->iot, sc->ioh, LCDC_LCCR0,
    265 	    ~LCCR0_DIS &
    266 	    bus_space_read_4(sc->iot, sc->ioh, LCDC_LCCR0));
    267 }
    268 #endif
    269 
    270 #define _rgb(r,g,b)	(((r)<<11) | ((g)<<5) | b)
    271 #define rgb(r,g,b)	_rgb((r)>>1,g,(b)>>1)
    272 
    273 #define L	0x1f			/* low intensity */
    274 #define H	0x3f			/* hight intensity */
    275 
    276 static uint16_t basic_color_map[] = {
    277 	rgb(	0,   0,   0),		/* black */
    278 	rgb(	L,   0,   0),		/* red */
    279 	rgb(	0,   L,   0),		/* green */
    280 	rgb(	L,   L,   0),		/* brown */
    281 	rgb(	0,   0,   L),		/* blue */
    282 	rgb(	L,   0,   L),		/* magenta */
    283 	rgb(	0,   L,   L),		/* cyan */
    284 	_rgb(0x1c,0x38,0x1c),		/* white */
    285 
    286 	rgb(	L,   L,   L),		/* black */
    287 	rgb(	H,   0,   0),		/* red */
    288 	rgb(	0,   H,   0),		/* green */
    289 	rgb(	H,   H,   0),		/* brown */
    290 	rgb(	0,   0,   H),		/* blue */
    291 	rgb(	H,   0,   H),		/* magenta */
    292 	rgb(	0,   H,   H),		/* cyan */
    293 	rgb(	H,   H,   H)
    294 };
    295 
    296 #undef H
    297 #undef L
    298 
    299 static void
    300 init_pallet(uint16_t *buf, int depth)
    301 {
    302 	int i;
    303 
    304 	/* convert RGB332 to RGB565 */
    305 	switch (depth) {
    306 	case 8:
    307 	case 4:
    308 #if 0
    309 		for (i=0; i <= 255; ++i) {
    310 			buf[i] = ((9 * ((i>>5) & 0x07)) <<11) |
    311 			    ((9 * ((i>>2) & 0x07)) << 5) |
    312 			    ((21 * (i & 0x03))/2);
    313 		}
    314 #else
    315 		memcpy(buf, basic_color_map, sizeof basic_color_map);
    316 		for (i=16; i < (1<<depth); ++i)
    317 			buf[i] = 0xffff;
    318 #endif
    319 		break;
    320 	default:
    321 	}
    322 }
    323 
    324 struct pxa2x0_lcd_screen *
    325 pxa2x0_lcd_new_screen(struct pxa2x0_lcd_softc *sc,
    326     int depth)
    327 {
    328 	struct pxa2x0_lcd_screen *scr = NULL;
    329 	int width, height;
    330 	bus_size_t size;
    331         int error, pallet_size;
    332 	int busdma_flag = (cold ? BUS_DMA_NOWAIT : BUS_DMA_WAITOK);
    333 	struct lcd_dma_descriptor *desc;
    334 	paddr_t buf_pa, desc_pa;
    335 
    336 	width = sc->geometry->panel_width;
    337 	height = sc->geometry->panel_height;
    338 	pallet_size = 0;
    339 
    340 	switch (depth) {
    341 	case 1:
    342 	case 2:
    343 	case 4:
    344 	case 8:
    345 		pallet_size = (1<<depth) * sizeof (uint16_t);
    346 		/* FALLTHROUGH */
    347 	case 16:
    348 		size = roundup(width,4)*depth/8 * height;
    349 		break;
    350 	default:
    351 		printf("%s: Unknown depth (%d)\n", sc->dev.dv_xname, depth);
    352 		return NULL;
    353 	}
    354 
    355 	scr = malloc(sizeof *scr, M_DEVBUF,
    356 	    M_ZERO | (cold ? M_NOWAIT : M_WAITOK));
    357 
    358 	if (scr == NULL)
    359 		return NULL;
    360 
    361 	scr->nsegs = 0;
    362 	scr->depth = depth;
    363 	scr->buf_size = size;
    364 	scr->buf_va = NULL;
    365 	size = roundup(size,16) + 3 * sizeof (struct lcd_dma_descriptor)
    366 	    + pallet_size;
    367 
    368         error = bus_dmamem_alloc(sc->dma_tag, size, 16, 0,
    369 	    scr->segs, 1, &(scr->nsegs), busdma_flag);
    370 
    371         if (error || scr->nsegs != 1) {
    372 		/* XXX: Actually we can handle nsegs>1 case by means
    373                    of multiple DMA descriptors for a panel.  it will
    374                    makes code here a bit hairly */
    375 		goto bad;
    376         }
    377 
    378 	error = bus_dmamem_map(sc->dma_tag, scr->segs, scr->nsegs,
    379 	    size, (caddr_t *)&(scr->buf_va), busdma_flag | BUS_DMA_COHERENT);
    380 	if (error)
    381 		goto bad;
    382 
    383 
    384 	memset (scr->buf_va, 0, scr->buf_size);
    385 
    386 	/* map memory for DMA */
    387 	if (bus_dmamap_create(sc->dma_tag, 1024*1024*2, 1,
    388 	    1024*1024*2, 0,  busdma_flag, &scr->dma))
    389 		goto bad;
    390 	error = bus_dmamap_load(sc->dma_tag, scr->dma,
    391 	    scr->buf_va, size, NULL, busdma_flag);
    392 	if (error) {
    393 		goto bad;
    394 	}
    395 
    396 	buf_pa = scr->segs[0].ds_addr;
    397 	desc_pa = buf_pa + roundup(size, PAGE_SIZE) - 3*sizeof *desc;
    398 
    399 	/* make descriptors at the top of mapped memory */
    400 	desc = (struct lcd_dma_descriptor *)(
    401 		(caddr_t)(scr->buf_va) + roundup(size, PAGE_SIZE) -
    402 			  3*sizeof *desc);
    403 
    404 	desc[0].fdadr = desc_pa;
    405 	desc[0].fsadr = buf_pa;
    406 	desc[0].ldcmd = scr->buf_size;
    407 
    408 	if (pallet_size) {
    409 		init_pallet((uint16_t *)((char *)desc - pallet_size), depth);
    410 
    411 		desc[2].fdadr = desc_pa; /* chain to panel 0 */
    412 		desc[2].fsadr = desc_pa - pallet_size;
    413 		desc[2].ldcmd = pallet_size | LDCMD_PAL;
    414 	}
    415 
    416 	if (sc->geometry->panel_info & LCDPANEL_DUAL) {
    417 		/* Dual panel */
    418 		desc[1].fdadr = desc_pa + sizeof *desc;
    419 		desc[1].fsadr = buf_pa + scr->buf_size/2;
    420 		desc[0].ldcmd = desc[1].ldcmd = scr->buf_size/2;
    421 
    422 	}
    423 
    424 #if 0
    425 	desc[0].ldcmd |= LDCMD_SOFINT;
    426 	desc[1].ldcmd |= LDCMD_SOFINT;
    427 #endif
    428 
    429 	scr->dma_desc = desc;
    430 	scr->dma_desc_pa = desc_pa;
    431 	scr->map_size = size;		/* used when unmap this. */
    432 
    433 	LIST_INSERT_HEAD(&(sc->screens), scr, link);
    434 	sc->n_screens++;
    435 
    436 	return scr;
    437 
    438  bad:
    439 	if (scr) {
    440 		if (scr->buf_va)
    441 			bus_dmamem_unmap(sc->dma_tag, scr->buf_va, size);
    442 		if (scr->nsegs)
    443 			bus_dmamem_free(sc->dma_tag, scr->segs, scr->nsegs);
    444 		free(scr, M_DEVBUF);
    445 	}
    446 	return NULL;
    447 }
    448 
    449 
    450 #if NWSDISPLAY > 0
    451 
    452 /*
    453  * Initialize struct wsscreen_descr based on values calculated by
    454  * raster operation subsystem.
    455  */
    456 int
    457 pxa2x0_lcd_setup_wsscreen(struct pxa2x0_wsscreen_descr *descr,
    458     const struct lcd_panel_geometry *geom,
    459     const char *fontname)
    460 {
    461 	int width = geom->panel_width;
    462 	int height = geom->panel_height;
    463 	int cookie = -1;
    464 	struct rasops_info rinfo;
    465 
    466 	memset(&rinfo, 0, sizeof rinfo);
    467 
    468 	if (fontname) {
    469 		wsfont_init();
    470 		cookie = wsfont_find((char *)fontname, 0, 0, 0,
    471 		    WSDISPLAY_FONTORDER_L2R, WSDISPLAY_FONTORDER_L2R);
    472 		if (cookie < 0 ||
    473 		    wsfont_lock(cookie, &rinfo.ri_font))
    474 			return -1;
    475 	}
    476 	else {
    477 		/* let rasops_init() choose any font */
    478 	}
    479 
    480 	/* let rasops_init calculate # of cols and rows in character */
    481 	rinfo.ri_flg = 0;
    482 	rinfo.ri_depth = descr->depth;
    483 	rinfo.ri_bits = NULL;
    484 	rinfo.ri_width = width;
    485 	rinfo.ri_height = height;
    486 	rinfo.ri_stride = width * rinfo.ri_depth / 8;
    487 	rinfo.ri_wsfcookie = cookie;
    488 
    489 	rasops_init(&rinfo, 100, 100);
    490 
    491 	descr->c.nrows = rinfo.ri_rows;
    492 	descr->c.ncols = rinfo.ri_cols;
    493 	descr->c.capabilities = rinfo.ri_caps;
    494 
    495 	return cookie;
    496 }
    497 
    498 
    499 int
    500 pxa2x0_lcd_show_screen(void *v, void *cookie, int waitok,
    501     void (*cb)(void *, int, int), void *cbarg)
    502 {
    503 	struct pxa2x0_lcd_softc *sc = v;
    504 	struct pxa2x0_lcd_screen *scr = cookie, *old;
    505 
    506 	old = sc->active;
    507 	if (old == scr)
    508 		return 0;
    509 
    510 	if (old)
    511 		pxa2x0_lcd_stop_dma(sc);
    512 
    513 	pxa2x0_lcd_start_dma(sc, scr);
    514 
    515 	sc->active = scr;
    516 	return 0;
    517 }
    518 
    519 int
    520 pxa2x0_lcd_alloc_screen(void *v, const struct wsscreen_descr *_type,
    521     void **cookiep, int *curxp, int *curyp, long *attrp)
    522 {
    523 	struct pxa2x0_lcd_softc *sc = v;
    524 	struct pxa2x0_lcd_screen *scr;
    525 	struct pxa2x0_wsscreen_descr *type = (struct pxa2x0_wsscreen_descr *)_type;
    526 
    527 	scr = pxa2x0_lcd_new_screen(sc, type->depth);
    528 	if (scr == NULL)
    529 		return -1;
    530 
    531 	/*
    532 	 * initialize raster operation for this screen.
    533 	 */
    534 	scr->rinfo.ri_flg = 0;
    535 	scr->rinfo.ri_depth = type->depth;
    536 	scr->rinfo.ri_bits = scr->buf_va;
    537 	scr->rinfo.ri_width = sc->geometry->panel_width;
    538 	scr->rinfo.ri_height = sc->geometry->panel_height;
    539 	scr->rinfo.ri_stride = scr->rinfo.ri_width * scr->rinfo.ri_depth / 8;
    540 	scr->rinfo.ri_wsfcookie = -1;	/* XXX */
    541 
    542 	rasops_init(&scr->rinfo, type->c.nrows, type->c.ncols);
    543 
    544 	(* scr->rinfo.ri_ops.allocattr)(&scr->rinfo, 0, 0, 0, attrp);
    545 
    546 	*cookiep = scr;
    547 	*curxp = 0;
    548 	*curyp = 0;
    549 
    550 	return 0;
    551 }
    552 
    553 
    554 void
    555 pxa2x0_lcd_free_screen(void *v, void *cookie)
    556 {
    557 	struct pxa2x0_lcd_softc *sc = v;
    558 	struct pxa2x0_lcd_screen *scr = cookie;
    559 
    560 	LIST_REMOVE(scr, link);
    561 	sc->n_screens--;
    562 	if (scr == sc->active) {
    563 		/* at first, we need to stop LCD DMA */
    564 		sc->active = NULL;
    565 
    566 		printf("lcd_free on active screen\n");
    567 
    568 		pxa2x0_lcd_stop_dma(sc);
    569 	}
    570 
    571 	if (scr->buf_va)
    572 		bus_dmamem_unmap(sc->dma_tag, scr->buf_va, scr->map_size);
    573 
    574 	if (scr->nsegs > 0)
    575 		bus_dmamem_free(sc->dma_tag, scr->segs, scr->nsegs);
    576 
    577 	free(scr, M_DEVBUF);
    578 }
    579 
    580 int
    581 pxa2x0_lcd_ioctl(void *v, u_long cmd, caddr_t data, int flag, struct proc *p)
    582 {
    583 	struct pxa2x0_lcd_softc *sc = v;
    584 	struct wsdisplay_fbinfo *wsdisp_info;
    585 	uint32_t ccr0;
    586 
    587 	switch (cmd) {
    588 	case WSDISPLAYIO_GTYPE:
    589 		*(u_int *)data = WSDISPLAY_TYPE_UNKNOWN; /* XXX */
    590 		return 0;
    591 
    592 	case WSDISPLAYIO_GINFO:
    593 		wsdisp_info = (struct wsdisplay_fbinfo *)data;
    594 
    595 		wsdisp_info->height = sc->geometry->panel_height;
    596 		wsdisp_info->width = sc->geometry->panel_width;
    597 		wsdisp_info->depth = 16; /* XXX */
    598 		wsdisp_info->cmsize = 0;
    599 		return 0;
    600 
    601 	case WSDISPLAYIO_GETCMAP:
    602 	case WSDISPLAYIO_PUTCMAP:
    603 		return EPASSTHROUGH;	/* XXX Colormap */
    604 
    605 	case WSDISPLAYIO_SVIDEO:
    606 		if (*(int *)data == WSDISPLAYIO_VIDEO_ON) {
    607 		  /* turn it on */
    608 		}
    609 		else {
    610 		  /* start LCD shutdown */
    611 		  /* sleep until interrupt */
    612 		}
    613 		return 0;
    614 
    615 	case WSDISPLAYIO_GVIDEO:
    616 		ccr0 = bus_space_read_4(sc->iot, sc->ioh, LCDC_LCCR0);
    617 		*(u_int *)data = (ccr0 & (LCCR0_ENB|LCCR0_DIS)) == LCCR0_ENB ?
    618 		    WSDISPLAYIO_VIDEO_ON : WSDISPLAYIO_VIDEO_OFF;
    619 		return 0;
    620 
    621 
    622 
    623 	case WSDISPLAYIO_GCURPOS:
    624 	case WSDISPLAYIO_SCURPOS:
    625 	case WSDISPLAYIO_GCURMAX:
    626 	case WSDISPLAYIO_GCURSOR:
    627 	case WSDISPLAYIO_SCURSOR:
    628 		return EPASSTHROUGH;	/* XXX */
    629 	}
    630 
    631 	return EPASSTHROUGH;
    632 }
    633 
    634 paddr_t
    635 pxa2x0_lcd_mmap(void *v, off_t offset, int prot)
    636 {
    637 	struct pxa2x0_lcd_softc *sc = v;
    638 	struct pxa2x0_lcd_screen *screen = sc->active;  /* ??? */
    639 
    640 	if (screen == NULL)
    641 		return -1;
    642 
    643 	return bus_dmamem_mmap(sc->dma_tag, screen->segs, screen->nsegs,
    644 	    offset, prot, BUS_DMA_WAITOK|BUS_DMA_COHERENT);
    645 	return -1;
    646 }
    647 
    648 
    649 static void
    650 pxa2x0_lcd_cursor(void *cookie, int on, int row, int col)
    651 {
    652 	struct pxa2x0_lcd_screen *scr = cookie;
    653 
    654 	(* scr->rinfo.ri_ops.cursor)(&scr->rinfo, on, row, col);
    655 }
    656 
    657 static int
    658 pxa2x0_lcd_mapchar(void *cookie, int c, unsigned int *cp)
    659 {
    660 	struct pxa2x0_lcd_screen *scr = cookie;
    661 
    662 	return (* scr->rinfo.ri_ops.mapchar)(&scr->rinfo, c, cp);
    663 }
    664 
    665 static void
    666 pxa2x0_lcd_putchar(void *cookie, int row, int col, u_int uc, long attr)
    667 {
    668 	struct pxa2x0_lcd_screen *scr = cookie;
    669 
    670 	(* scr->rinfo.ri_ops.putchar)(&scr->rinfo,
    671 	    row, col, uc, attr);
    672 }
    673 
    674 static void
    675 pxa2x0_lcd_copycols(void *cookie, int row, int src, int dst, int num)
    676 {
    677 	struct pxa2x0_lcd_screen *scr = cookie;
    678 
    679 	(* scr->rinfo.ri_ops.copycols)(&scr->rinfo,
    680 	    row, src, dst, num);
    681 }
    682 
    683 static void
    684 pxa2x0_lcd_erasecols(void *cookie, int row, int col, int num, long attr)
    685 {
    686 	struct pxa2x0_lcd_screen *scr = cookie;
    687 
    688 	(* scr->rinfo.ri_ops.erasecols)(&scr->rinfo,
    689 	    row, col, num, attr);
    690 }
    691 
    692 static void
    693 pxa2x0_lcd_copyrows(void *cookie, int src, int dst, int num)
    694 {
    695 	struct pxa2x0_lcd_screen *scr = cookie;
    696 
    697 	(* scr->rinfo.ri_ops.copyrows)(&scr->rinfo,
    698 	    src, dst, num);
    699 }
    700 
    701 static void
    702 pxa2x0_lcd_eraserows(void *cookie, int row, int num, long attr)
    703 {
    704 	struct pxa2x0_lcd_screen *scr = cookie;
    705 
    706 	(* scr->rinfo.ri_ops.eraserows)(&scr->rinfo,
    707 	    row, num, attr);
    708 }
    709 
    710 static int
    711 pxa2x0_lcd_alloc_attr(void *cookie, int fg, int bg, int flg, long *attr)
    712 {
    713 	struct pxa2x0_lcd_screen *scr = cookie;
    714 
    715 	return (* scr->rinfo.ri_ops.allocattr)(&scr->rinfo,
    716 	    fg, bg, flg, attr);
    717 }
    718 
    719 
    720 const struct wsdisplay_emulops pxa2x0_lcd_emulops = {
    721 	pxa2x0_lcd_cursor,
    722 	pxa2x0_lcd_mapchar,
    723 	pxa2x0_lcd_putchar,
    724 	pxa2x0_lcd_copycols,
    725 	pxa2x0_lcd_erasecols,
    726 	pxa2x0_lcd_copyrows,
    727 	pxa2x0_lcd_eraserows,
    728 	pxa2x0_lcd_alloc_attr
    729 };
    730 
    731 #endif /* NWSDISPLAY > 0 */
    732