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