1 1.16 andvar /* $NetBSD: s3c24x0_lcd.c,v 1.16 2024/07/05 19:28:36 andvar Exp $ */ 2 1.1 bsh 3 1.1 bsh /* 4 1.1 bsh * Copyright (c) 2004 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 * Support S3C24[10]0's integrated LCD controller. 34 1.1 bsh */ 35 1.1 bsh 36 1.1 bsh #include <sys/cdefs.h> 37 1.16 andvar __KERNEL_RCSID(0, "$NetBSD: s3c24x0_lcd.c,v 1.16 2024/07/05 19:28:36 andvar Exp $"); 38 1.1 bsh 39 1.1 bsh #include <sys/param.h> 40 1.1 bsh #include <sys/systm.h> 41 1.1 bsh #include <sys/conf.h> 42 1.1 bsh #include <sys/uio.h> 43 1.15 thorpej #include <sys/kmem.h> 44 1.1 bsh #include <sys/kernel.h> /* for cold */ 45 1.1 bsh 46 1.1 bsh #include <uvm/uvm_extern.h> 47 1.1 bsh 48 1.1 bsh #include <dev/cons.h> 49 1.1 bsh #include <dev/wscons/wsconsio.h> 50 1.1 bsh #include <dev/wscons/wsdisplayvar.h> 51 1.1 bsh #include <dev/wscons/wscons_callbacks.h> 52 1.1 bsh #include <dev/rasops/rasops.h> 53 1.1 bsh #include <dev/wsfont/wsfont.h> 54 1.1 bsh 55 1.9 nisimura #include <dev/hpc/hpcfbio.h> 56 1.9 nisimura 57 1.7 dyoung #include <sys/bus.h> 58 1.1 bsh #include <machine/cpu.h> 59 1.1 bsh #include <arm/cpufunc.h> 60 1.1 bsh 61 1.1 bsh #include <arm/s3c2xx0/s3c24x0var.h> 62 1.1 bsh #include <arm/s3c2xx0/s3c24x0reg.h> 63 1.1 bsh #include <arm/s3c2xx0/s3c24x0_lcd.h> 64 1.1 bsh 65 1.1 bsh #include "wsdisplay.h" 66 1.1 bsh 67 1.1 bsh int lcdintr(void *); 68 1.1 bsh static void init_palette(struct s3c24x0_lcd_softc *, 69 1.1 bsh struct s3c24x0_lcd_screen *); 70 1.1 bsh 71 1.1 bsh #ifdef LCD_DEBUG 72 1.1 bsh static void 73 1.1 bsh dump_lcdcon(const char *title, bus_space_tag_t iot, bus_space_handle_t ioh) 74 1.1 bsh { 75 1.1 bsh int i; 76 1.1 bsh 77 1.1 bsh printf("%s\n", title); 78 1.1 bsh for(i=LCDC_LCDCON1; i <= LCDC_LCDSADDR3; i+=4) { 79 1.1 bsh if (i%16 == 0) 80 1.1 bsh printf("\n%03x: ", i); 81 1.1 bsh printf("%08x ", bus_space_read_4(iot, ioh, i)); 82 1.1 bsh } 83 1.1 bsh 84 1.1 bsh printf("\n"); 85 1.1 bsh } 86 1.1 bsh 87 1.1 bsh void draw_test_pattern(struct s3c24x0_lcd_softc *, 88 1.1 bsh struct s3c24x0_lcd_screen *scr); 89 1.1 bsh 90 1.1 bsh #endif 91 1.1 bsh 92 1.1 bsh void 93 1.1 bsh s3c24x0_set_lcd_panel_info(struct s3c24x0_lcd_softc *sc, 94 1.1 bsh const struct s3c24x0_lcd_panel_info *info) 95 1.1 bsh { 96 1.1 bsh bus_space_tag_t iot = sc->iot; 97 1.1 bsh bus_space_handle_t ioh = sc->ioh; 98 1.1 bsh uint32_t reg; 99 1.1 bsh int clkval; 100 1.1 bsh int tft = s3c24x0_lcd_panel_tft(info); 101 1.1 bsh int hclk = s3c2xx0_softc->sc_hclk; 102 1.1 bsh 103 1.1 bsh sc->panel_info = info; 104 1.1 bsh 105 1.1 bsh /* Set LCDCON1. BPPMODE and ENVID are set later */ 106 1.1 bsh if (tft) 107 1.1 bsh clkval = (hclk / info->pixel_clock / 2) - 1; 108 1.1 bsh else { 109 1.1 bsh /* STN display */ 110 1.13 riastrad clkval = uimax(2, hclk / info->pixel_clock / 2); 111 1.1 bsh } 112 1.1 bsh 113 1.1 bsh reg = (info->lcdcon1 & ~LCDCON1_CLKVAL_MASK) | 114 1.1 bsh (clkval << LCDCON1_CLKVAL_SHIFT); 115 1.1 bsh reg &= ~LCDCON1_ENVID; 116 1.1 bsh bus_space_write_4(iot, ioh, LCDC_LCDCON1, reg); 117 1.1 bsh 118 1.1 bsh #if 0 119 1.1 bsh printf("hclk=%d pixel clock=%d, clkval = %x lcdcon1=%x\n", 120 1.1 bsh hclk, info->pixel_clock, clkval, reg); 121 1.1 bsh #endif 122 1.1 bsh 123 1.1 bsh bus_space_write_4(iot, ioh, LCDC_LCDCON2, info->lcdcon2); 124 1.1 bsh bus_space_write_4(iot, ioh, LCDC_LCDCON3, info->lcdcon3); 125 1.1 bsh bus_space_write_4(iot, ioh, LCDC_LCDCON4, info->lcdcon4); 126 1.1 bsh bus_space_write_4(iot, ioh, LCDC_LCDCON5, info->lcdcon5); 127 1.1 bsh bus_space_write_4(iot, ioh, LCDC_LPCSEL, info->lpcsel); 128 1.1 bsh } 129 1.1 bsh 130 1.1 bsh void 131 1.1 bsh s3c24x0_lcd_attach_sub(struct s3c24x0_lcd_softc *sc, 132 1.1 bsh struct s3c2xx0_attach_args *sa, 133 1.1 bsh const struct s3c24x0_lcd_panel_info *panel_info) 134 1.1 bsh { 135 1.1 bsh bus_space_tag_t iot = sa->sa_iot; 136 1.1 bsh bus_space_handle_t ioh; 137 1.1 bsh int error; 138 1.1 bsh 139 1.1 bsh sc->n_screens = 0; 140 1.1 bsh LIST_INIT(&sc->screens); 141 1.1 bsh 142 1.1 bsh /* map controller registers */ 143 1.1 bsh error = bus_space_map(iot, sa->sa_addr, S3C24X0_LCDC_SIZE, 0, &ioh); 144 1.1 bsh if (error) { 145 1.1 bsh printf(": failed to map registers %d", error); 146 1.1 bsh return; 147 1.1 bsh } 148 1.1 bsh 149 1.1 bsh sc->iot = iot; 150 1.1 bsh sc->ioh = ioh; 151 1.1 bsh sc->dma_tag = sa->sa_dmat; 152 1.1 bsh 153 1.1 bsh #ifdef notyet 154 1.1 bsh sc->ih = s3c24x0_intr_establish(sa->sa_intr, IPL_BIO, lcdintr, sc); 155 1.1 bsh if (sc->ih == NULL) 156 1.1 bsh printf("%s: unable to establish interrupt at irq %d", 157 1.10 chs device_xname(sc->dev), sa->sa_intr); 158 1.1 bsh #endif 159 1.1 bsh 160 1.1 bsh /* mask LCD interrupts */ 161 1.1 bsh bus_space_write_4(iot, ioh, LCDC_LCDINTMSK, LCDINT_FICNT|LCDINT_FRSYN); 162 1.1 bsh 163 1.1 bsh /* Initialize controller registers based on panel geometry*/ 164 1.1 bsh s3c24x0_set_lcd_panel_info(sc, panel_info); 165 1.1 bsh 166 1.1 bsh /* XXX: enable clock to LCD controller */ 167 1.1 bsh } 168 1.1 bsh 169 1.1 bsh 170 1.1 bsh #ifdef notyet 171 1.1 bsh int 172 1.1 bsh lcdintr(void *arg) 173 1.1 bsh { 174 1.1 bsh struct s3c24x0_lcd_softc *sc = arg; 175 1.1 bsh bus_space_tag_t iot = sc->iot; 176 1.1 bsh bus_space_handle_t ioh = sc->ioh; 177 1.1 bsh 178 1.1 bsh static uint32_t status; 179 1.1 bsh 180 1.1 bsh return 1; 181 1.1 bsh } 182 1.1 bsh #endif 183 1.1 bsh 184 1.1 bsh int 185 1.1 bsh s3c24x0_lcd_start_dma(struct s3c24x0_lcd_softc *sc, 186 1.1 bsh struct s3c24x0_lcd_screen *scr) 187 1.1 bsh { 188 1.1 bsh bus_space_tag_t iot = sc->iot; 189 1.1 bsh bus_space_handle_t ioh = sc->ioh; 190 1.1 bsh const struct s3c24x0_lcd_panel_info *info = sc->panel_info; 191 1.1 bsh int tft = s3c24x0_lcd_panel_tft(info); 192 1.1 bsh int dual_panel = 193 1.1 bsh (info->lcdcon1 & LCDCON1_PNRMODE_MASK) == LCDCON1_PNRMODE_DUALSTN4; 194 1.1 bsh uint32_t lcdcon1, val; 195 1.1 bsh paddr_t pa; 196 1.1 bsh int depth = scr->depth; 197 1.1 bsh int stride = scr->stride; 198 1.1 bsh int panel_height = info->panel_height; 199 1.1 bsh int panel_width = info->panel_width; 200 1.1 bsh int offsize; 201 1.1 bsh 202 1.1 bsh switch (depth) { 203 1.1 bsh case 1: val = LCDCON1_BPPMODE_STN1; break; 204 1.1 bsh case 2: val = LCDCON1_BPPMODE_STN2; break; 205 1.1 bsh case 4: val = LCDCON1_BPPMODE_STN4; break; 206 1.1 bsh case 8: val = LCDCON1_BPPMODE_STN8; break; 207 1.1 bsh case 12: 208 1.1 bsh if (tft) 209 1.1 bsh return -1; 210 1.1 bsh val = LCDCON1_BPPMODE_STN12; 211 1.1 bsh break; 212 1.1 bsh case 16: 213 1.1 bsh if (!tft) 214 1.1 bsh return -1; 215 1.1 bsh val = LCDCON1_BPPMODE_TFT16; 216 1.1 bsh break; 217 1.1 bsh case 24: 218 1.1 bsh if (!tft) 219 1.1 bsh return -1; 220 1.1 bsh val = LCDCON1_BPPMODE_TFT24; 221 1.1 bsh break; 222 1.1 bsh default: 223 1.1 bsh return -1; 224 1.1 bsh } 225 1.1 bsh 226 1.1 bsh if (tft) 227 1.1 bsh val |= LCDCON1_BPPMODE_TFTX; 228 1.1 bsh 229 1.1 bsh lcdcon1 = bus_space_read_4(iot, ioh, LCDC_LCDCON1); 230 1.1 bsh lcdcon1 &= ~(LCDCON1_BPPMODE_MASK|LCDCON1_ENVID); 231 1.1 bsh lcdcon1 |= val; 232 1.1 bsh bus_space_write_4(iot, ioh, LCDC_LCDCON1, lcdcon1); 233 1.1 bsh 234 1.1 bsh /* Adjust LCDCON3.HOZVAL to meet with restriction */ 235 1.1 bsh val = roundup(panel_width, 16 / depth); 236 1.1 bsh bus_space_write_4(iot, ioh, LCDC_LCDCON3, 237 1.1 bsh (info->lcdcon3 & ~LCDCON3_HOZVAL_MASK) | 238 1.1 bsh (val - 1) << LCDCON3_HOZVAL_SHIFT); 239 1.1 bsh 240 1.1 bsh pa = scr->segs[0].ds_addr; 241 1.1 bsh bus_space_write_4(iot, ioh, LCDC_LCDSADDR1, pa >> 1); 242 1.1 bsh 243 1.1 bsh if (dual_panel) { 244 1.1 bsh /* XXX */ 245 1.1 bsh } 246 1.1 bsh else { 247 1.1 bsh pa += stride * panel_height; 248 1.1 bsh bus_space_write_4(iot, ioh, LCDC_LCDSADDR2, pa >> 1); 249 1.1 bsh } 250 1.1 bsh 251 1.1 bsh offsize = stride / sizeof (uint16_t) - (panel_width * depth / 16); 252 1.1 bsh bus_space_write_4(iot, ioh, LCDC_LCDSADDR3, 253 1.1 bsh (offsize << LCDSADDR3_OFFSIZE_SHIFT) | 254 1.1 bsh (panel_width * depth / 16)); 255 1.1 bsh 256 1.1 bsh /* set byte- or halfword- swap based on the depth */ 257 1.1 bsh val = bus_space_read_4(iot, ioh, LCDC_LCDCON5); 258 1.1 bsh val &= ~(LCDCON5_BSWP|LCDCON5_HWSWP); 259 1.1 bsh switch(depth) { 260 1.1 bsh case 2: 261 1.1 bsh case 4: 262 1.1 bsh case 8: 263 1.1 bsh val |= LCDCON5_BSWP; 264 1.1 bsh break; 265 1.1 bsh case 16: 266 1.1 bsh val |= LCDCON5_HWSWP; 267 1.1 bsh break; 268 1.1 bsh } 269 1.1 bsh bus_space_write_4(iot, ioh, LCDC_LCDCON5, val); 270 1.1 bsh 271 1.1 bsh 272 1.1 bsh init_palette(sc, scr); 273 1.1 bsh 274 1.1 bsh #if 0 275 1.1 bsh bus_space_write_4(iot, ioh, LCDC_TPAL, TPAL_TPALEN| 276 1.1 bsh (0xff<<TPAL_BLUE_SHIFT)); 277 1.1 bsh #endif 278 1.1 bsh 279 1.1 bsh /* Enable LCDC */ 280 1.1 bsh bus_space_write_4(iot, ioh, LCDC_LCDCON1, lcdcon1 | LCDCON1_ENVID); 281 1.1 bsh 282 1.1 bsh sc->lcd_on = 1; 283 1.1 bsh 284 1.1 bsh #ifdef LCD_DEBUG 285 1.6 perry dump_lcdcon(__func__, iot, ioh); 286 1.1 bsh #endif 287 1.1 bsh 288 1.1 bsh return 0; 289 1.1 bsh } 290 1.1 bsh 291 1.1 bsh void 292 1.1 bsh s3c24x0_lcd_power(struct s3c24x0_lcd_softc *sc, int on) 293 1.1 bsh { 294 1.1 bsh bus_space_tag_t iot = sc->iot; 295 1.1 bsh bus_space_handle_t ioh = sc->ioh; 296 1.1 bsh uint32_t reg; 297 1.1 bsh 298 1.1 bsh reg = bus_space_read_4(iot, ioh, LCDC_LCDCON5); 299 1.1 bsh 300 1.1 bsh if (on) 301 1.1 bsh reg |= LCDCON5_PWREN; 302 1.1 bsh else 303 1.1 bsh reg &= ~LCDCON5_PWREN; 304 1.1 bsh 305 1.1 bsh bus_space_write_4(iot, ioh, LCDC_LCDCON5, reg); 306 1.1 bsh } 307 1.1 bsh 308 1.1 bsh struct s3c24x0_lcd_screen * 309 1.1 bsh s3c24x0_lcd_new_screen(struct s3c24x0_lcd_softc *sc, 310 1.1 bsh int virtual_width, int virtual_height, int depth) 311 1.1 bsh { 312 1.1 bsh struct s3c24x0_lcd_screen *scr = NULL; 313 1.1 bsh bus_size_t size; 314 1.11 htodd int error; 315 1.1 bsh int busdma_flag = (cold ? BUS_DMA_NOWAIT : BUS_DMA_WAITOK) | 316 1.1 bsh BUS_DMA_WRITE; 317 1.1 bsh paddr_t align; 318 1.1 bsh 319 1.9 nisimura #if 0 /* Does this make any sense? */ 320 1.1 bsh #ifdef DIAGNOSTIC 321 1.1 bsh if (size > 1 << 22) { 322 1.10 chs aprint_error_dev(sc->dev, "too big screen size\n"); 323 1.1 bsh return NULL; 324 1.1 bsh } 325 1.1 bsh #endif 326 1.9 nisimura #endif 327 1.1 bsh 328 1.1 bsh switch (depth) { 329 1.1 bsh case 1: case 2: case 4: case 8: 330 1.1 bsh virtual_width = roundup(virtual_width, 16 / depth); 331 1.1 bsh break; 332 1.1 bsh case 16: 333 1.1 bsh break; 334 1.1 bsh case 12: case 24: 335 1.1 bsh default: 336 1.1 bsh aprint_error("%s: Unknown depth (%d)\n", 337 1.9 nisimura device_xname(sc->sc_dev), depth); 338 1.1 bsh return NULL; 339 1.1 bsh } 340 1.1 bsh 341 1.15 thorpej scr = kmem_zalloc(sizeof *scr, KM_SLEEP); 342 1.1 bsh scr->nsegs = 0; 343 1.1 bsh scr->depth = depth; 344 1.1 bsh scr->stride = virtual_width * depth / 8; 345 1.1 bsh scr->buf_size = size = scr->stride * virtual_height; 346 1.1 bsh scr->buf_va = NULL; 347 1.1 bsh 348 1.1 bsh /* calculate the alignment for LCD frame buffer. 349 1.1 bsh the buffer can't across 4MB boundary */ 350 1.1 bsh align = 1 << 20; 351 1.1 bsh while (align < size) 352 1.1 bsh align <<= 1; 353 1.1 bsh 354 1.9 nisimura printf("%s: Allocating LCD frame buffer of size %ld\n", 355 1.9 nisimura device_xname(sc->sc_dev), size); 356 1.9 nisimura 357 1.1 bsh error = bus_dmamem_alloc(sc->dma_tag, size, align, 0, 358 1.1 bsh scr->segs, 1, &(scr->nsegs), busdma_flag); 359 1.1 bsh 360 1.1 bsh if (error || scr->nsegs != 1) 361 1.1 bsh goto bad; 362 1.1 bsh 363 1.1 bsh error = bus_dmamem_map(sc->dma_tag, scr->segs, scr->nsegs, 364 1.5 christos size, (void **)&(scr->buf_va), busdma_flag | BUS_DMA_COHERENT); 365 1.1 bsh if (error) 366 1.1 bsh goto bad; 367 1.1 bsh 368 1.1 bsh 369 1.1 bsh memset (scr->buf_va, 0, scr->buf_size); 370 1.1 bsh 371 1.1 bsh /* map memory for DMA */ 372 1.1 bsh if (bus_dmamap_create(sc->dma_tag, 1024*1024*2, 1, 373 1.1 bsh 1024*1024*2, 0, busdma_flag, &scr->dma)) 374 1.1 bsh goto bad; 375 1.1 bsh error = bus_dmamap_load(sc->dma_tag, scr->dma, 376 1.1 bsh scr->buf_va, size, NULL, busdma_flag); 377 1.1 bsh if (error) 378 1.1 bsh goto bad; 379 1.1 bsh 380 1.1 bsh LIST_INSERT_HEAD(&(sc->screens), scr, link); 381 1.1 bsh sc->n_screens++; 382 1.1 bsh 383 1.1 bsh #ifdef LCD_DEBUG 384 1.1 bsh draw_test_pattern(sc, scr); 385 1.6 perry dump_lcdcon(__func__, sc->iot, sc->ioh); 386 1.1 bsh #endif 387 1.1 bsh return scr; 388 1.1 bsh 389 1.1 bsh bad: 390 1.1 bsh if (scr) { 391 1.1 bsh if (scr->buf_va) 392 1.1 bsh bus_dmamem_unmap(sc->dma_tag, scr->buf_va, size); 393 1.1 bsh if (scr->nsegs) 394 1.1 bsh bus_dmamem_free(sc->dma_tag, scr->segs, scr->nsegs); 395 1.15 thorpej kmem_free(scr, sizeof(*scr)); 396 1.1 bsh } 397 1.1 bsh return NULL; 398 1.1 bsh } 399 1.1 bsh 400 1.1 bsh 401 1.1 bsh #define _rgb(r,g,b) (((r)<<11) | ((g)<<5) | b) 402 1.1 bsh #define rgb(r,g,b) _rgb((r)>>1,g,(b)>>1) 403 1.1 bsh 404 1.1 bsh #define L 0x30 /* low intensity */ 405 1.16 andvar #define H 0x3f /* high intensity */ 406 1.1 bsh 407 1.1 bsh static const uint16_t basic_color_map[] = { 408 1.1 bsh rgb( 0, 0, 0), /* black */ 409 1.1 bsh rgb( L, 0, 0), /* red */ 410 1.1 bsh rgb( 0, L, 0), /* green */ 411 1.1 bsh rgb( L, L, 0), /* brown */ 412 1.1 bsh rgb( 0, 0, L), /* blue */ 413 1.1 bsh rgb( L, 0, L), /* magenta */ 414 1.1 bsh rgb( 0, L, L), /* cyan */ 415 1.1 bsh _rgb(0x1c,0x38,0x1c), /* white */ 416 1.1 bsh 417 1.1 bsh rgb( L, L, L), /* black */ 418 1.1 bsh rgb( H, 0, 0), /* red */ 419 1.1 bsh rgb( 0, H, 0), /* green */ 420 1.1 bsh rgb( H, H, 0), /* brown */ 421 1.1 bsh rgb( 0, 0, H), /* blue */ 422 1.1 bsh rgb( H, 0, H), /* magenta */ 423 1.1 bsh rgb( 0, H, H), /* cyan */ 424 1.1 bsh rgb( H, H, H), /* white */ 425 1.1 bsh }; 426 1.1 bsh 427 1.1 bsh #define COLORMAP_LEN (sizeof basic_color_map / sizeof basic_color_map[0]) 428 1.1 bsh 429 1.1 bsh #undef H 430 1.1 bsh #undef L 431 1.1 bsh 432 1.1 bsh static void 433 1.1 bsh init_palette(struct s3c24x0_lcd_softc *sc, struct s3c24x0_lcd_screen *scr) 434 1.1 bsh { 435 1.1 bsh int depth = scr->depth; 436 1.1 bsh bus_space_tag_t iot = sc->iot; 437 1.1 bsh bus_space_handle_t ioh = sc->ioh; 438 1.1 bsh int i; 439 1.1 bsh 440 1.1 bsh i = 0; 441 1.1 bsh 442 1.1 bsh switch(depth) { 443 1.1 bsh default: 444 1.1 bsh case 16: /* not using palette */ 445 1.1 bsh return; 446 1.1 bsh case 8: 447 1.1 bsh while (i < COLORMAP_LEN) { 448 1.1 bsh bus_space_write_4(iot, ioh, LCDC_PALETTE + 4*i, 449 1.1 bsh basic_color_map[i]); 450 1.1 bsh ++i; 451 1.1 bsh } 452 1.1 bsh break; 453 1.1 bsh case 4: 454 1.1 bsh case 2: 455 1.1 bsh /* XXX */ 456 1.1 bsh break; 457 1.1 bsh case 1: 458 1.1 bsh bus_space_write_4(iot, ioh, LCDC_PALETTE + 4 * i, 459 1.1 bsh basic_color_map[i]); /* black */ 460 1.1 bsh ++i; 461 1.1 bsh bus_space_write_4(iot, ioh, LCDC_PALETTE + 4 * i, 462 1.1 bsh basic_color_map[7]); /* white */ 463 1.1 bsh break; 464 1.1 bsh } 465 1.1 bsh 466 1.1 bsh #ifdef DIAGNOSTIC 467 1.1 bsh /* Fill unused entries */ 468 1.1 bsh for ( ; i < 256; ++i ) 469 1.1 bsh bus_space_write_4(iot, ioh, LCDC_PALETTE + 4 * i, 470 1.1 bsh basic_color_map[1]); /* red */ 471 1.1 bsh #endif 472 1.1 bsh } 473 1.1 bsh 474 1.1 bsh 475 1.1 bsh #if NWSDISPLAY > 0 476 1.1 bsh 477 1.1 bsh static void 478 1.1 bsh s3c24x0_lcd_stop_dma(struct s3c24x0_lcd_softc *sc) 479 1.1 bsh { 480 1.1 bsh /* Stop LCD output */ 481 1.1 bsh bus_space_write_4(sc->iot, sc->ioh, LCDC_LCDCON1, 482 1.1 bsh ~LCDCON1_ENVID & 483 1.1 bsh bus_space_read_4(sc->iot, sc->ioh, LCDC_LCDCON1)); 484 1.1 bsh 485 1.1 bsh 486 1.1 bsh sc->lcd_on = 0; 487 1.1 bsh } 488 1.1 bsh 489 1.1 bsh int 490 1.1 bsh s3c24x0_lcd_show_screen(void *v, void *cookie, int waitok, 491 1.1 bsh void (*cb)(void *, int, int), void *cbarg) 492 1.1 bsh { 493 1.1 bsh struct s3c24x0_lcd_softc *sc = v; 494 1.1 bsh struct s3c24x0_lcd_screen *scr = cookie, *old; 495 1.1 bsh 496 1.1 bsh /* XXX: make sure the clock is provided for LCD controller */ 497 1.1 bsh 498 1.1 bsh old = sc->active; 499 1.1 bsh if (old == scr && sc->lcd_on) 500 1.1 bsh return 0; 501 1.1 bsh 502 1.1 bsh if (old) 503 1.1 bsh s3c24x0_lcd_stop_dma(sc); 504 1.1 bsh 505 1.1 bsh s3c24x0_lcd_start_dma(sc, scr); 506 1.1 bsh sc->active = scr; 507 1.1 bsh s3c24x0_lcd_power(sc, 1); 508 1.1 bsh 509 1.1 bsh /* XXX: callback */ 510 1.1 bsh 511 1.1 bsh return 0; 512 1.1 bsh } 513 1.1 bsh 514 1.1 bsh int 515 1.1 bsh s3c24x0_lcd_alloc_screen(void *v, const struct wsscreen_descr *_type, 516 1.1 bsh void **cookiep, int *curxp, int *curyp, long *attrp) 517 1.1 bsh { 518 1.1 bsh struct s3c24x0_lcd_softc *sc = v; 519 1.1 bsh struct s3c24x0_lcd_screen *scr; 520 1.2 he const struct s3c24x0_wsscreen_descr *type = 521 1.2 he (const struct s3c24x0_wsscreen_descr *)_type; 522 1.1 bsh 523 1.1 bsh int width, height; 524 1.1 bsh 525 1.1 bsh width = type->c.ncols * type->c.fontwidth; 526 1.1 bsh height = type->c.nrows * type->c.fontwidth; 527 1.1 bsh 528 1.1 bsh if (width < sc->panel_info->panel_width) 529 1.1 bsh width = sc->panel_info->panel_width; 530 1.1 bsh if (height < sc->panel_info->panel_height) 531 1.1 bsh height = sc->panel_info->panel_height; 532 1.1 bsh 533 1.1 bsh 534 1.1 bsh scr = s3c24x0_lcd_new_screen(sc, width, height, type->depth); 535 1.1 bsh if (scr == NULL) 536 1.1 bsh return -1; 537 1.1 bsh 538 1.1 bsh /* 539 1.1 bsh * initialize raster operation for this screen. 540 1.1 bsh */ 541 1.1 bsh scr->rinfo.ri_flg = 0; 542 1.1 bsh scr->rinfo.ri_depth = type->depth; 543 1.1 bsh scr->rinfo.ri_bits = scr->buf_va; 544 1.1 bsh scr->rinfo.ri_width = width; 545 1.1 bsh scr->rinfo.ri_height = height; 546 1.1 bsh scr->rinfo.ri_stride = scr->stride; 547 1.1 bsh 548 1.1 bsh if (type->c.fontwidth || type->c.fontheight) { 549 1.1 bsh /* 550 1.1 bsh * find a font with specified size 551 1.1 bsh */ 552 1.1 bsh int cookie; 553 1.1 bsh 554 1.1 bsh wsfont_init(); 555 1.1 bsh 556 1.1 bsh cookie = wsfont_find(NULL, type->c.fontwidth, 557 1.1 bsh type->c.fontheight, 0, WSDISPLAY_FONTORDER_L2R, 558 1.8 macallan WSDISPLAY_FONTORDER_L2R, WSFONT_FIND_BITMAP); 559 1.1 bsh 560 1.1 bsh if (cookie > 0) { 561 1.1 bsh if (wsfont_lock(cookie, &scr->rinfo.ri_font)) 562 1.1 bsh scr->rinfo.ri_wsfcookie = cookie; 563 1.1 bsh } 564 1.1 bsh } 565 1.1 bsh 566 1.1 bsh rasops_init(&scr->rinfo, type->c.nrows, type->c.ncols); 567 1.1 bsh 568 1.1 bsh (* scr->rinfo.ri_ops.allocattr)(&scr->rinfo, 0, 0, 0, attrp); 569 1.1 bsh 570 1.1 bsh if (type->c.nrows != scr->rinfo.ri_rows || 571 1.1 bsh type->c.ncols != scr->rinfo.ri_cols) { 572 1.1 bsh 573 1.1 bsh aprint_error("%s: can't allocate a screen with requested size:" 574 1.1 bsh "%d x %d -> %d x %d\n", 575 1.9 nisimura device_xname(sc->sc_dev), 576 1.1 bsh type->c.ncols, type->c.nrows, 577 1.1 bsh scr->rinfo.ri_cols, scr->rinfo.ri_rows); 578 1.1 bsh } 579 1.1 bsh 580 1.1 bsh *cookiep = scr; 581 1.1 bsh *curxp = 0; 582 1.1 bsh *curyp = 0; 583 1.1 bsh 584 1.1 bsh return 0; 585 1.1 bsh } 586 1.1 bsh 587 1.1 bsh 588 1.1 bsh void 589 1.1 bsh s3c24x0_lcd_free_screen(void *v, void *cookie) 590 1.1 bsh { 591 1.1 bsh struct s3c24x0_lcd_softc *sc = v; 592 1.1 bsh struct s3c24x0_lcd_screen *scr = cookie; 593 1.1 bsh 594 1.1 bsh LIST_REMOVE(scr, link); 595 1.1 bsh sc->n_screens--; 596 1.1 bsh if (scr == sc->active) { 597 1.1 bsh sc->active = NULL; 598 1.1 bsh 599 1.1 bsh /* XXX: We need a good procedure to shutdown the LCD. */ 600 1.1 bsh 601 1.1 bsh s3c24x0_lcd_stop_dma(sc); 602 1.1 bsh s3c24x0_lcd_power(sc, 0); 603 1.1 bsh } 604 1.1 bsh 605 1.1 bsh if (scr->buf_va) 606 1.1 bsh bus_dmamem_unmap(sc->dma_tag, scr->buf_va, scr->map_size); 607 1.1 bsh 608 1.1 bsh if (scr->nsegs > 0) 609 1.1 bsh bus_dmamem_free(sc->dma_tag, scr->segs, scr->nsegs); 610 1.1 bsh 611 1.15 thorpej kmem_free(scr, sizeof(*scr)); 612 1.1 bsh } 613 1.1 bsh 614 1.1 bsh int 615 1.5 christos s3c24x0_lcd_ioctl(void *v, void *vs, u_long cmd, void *data, int flag, 616 1.4 jmmv struct lwp *l) 617 1.1 bsh { 618 1.1 bsh struct s3c24x0_lcd_softc *sc = v; 619 1.1 bsh struct wsdisplay_fbinfo *wsdisp_info; 620 1.1 bsh struct s3c24x0_lcd_screen *scr; 621 1.1 bsh 622 1.1 bsh 623 1.1 bsh switch (cmd) { 624 1.1 bsh case WSDISPLAYIO_GTYPE: 625 1.1 bsh *(u_int *)data = WSDISPLAY_TYPE_UNKNOWN; /* XXX */ 626 1.1 bsh return 0; 627 1.1 bsh 628 1.1 bsh case WSDISPLAYIO_GINFO: 629 1.1 bsh wsdisp_info = (struct wsdisplay_fbinfo *)data; 630 1.1 bsh 631 1.1 bsh wsdisp_info->height = sc->panel_info->panel_height; 632 1.1 bsh wsdisp_info->width = sc->panel_info->panel_width; 633 1.1 bsh wsdisp_info->depth = 16; /* XXX */ 634 1.1 bsh wsdisp_info->cmsize = 0; 635 1.1 bsh return 0; 636 1.1 bsh 637 1.9 nisimura case WSDISPLAYIO_LINEBYTES: 638 1.9 nisimura *(u_int *)data = sc->panel_info->panel_width * (16/8); 639 1.9 nisimura return 0; 640 1.9 nisimura 641 1.1 bsh case WSDISPLAYIO_GETCMAP: 642 1.1 bsh case WSDISPLAYIO_PUTCMAP: 643 1.1 bsh return EPASSTHROUGH; /* XXX Colormap */ 644 1.1 bsh 645 1.1 bsh case WSDISPLAYIO_SVIDEO: 646 1.1 bsh if (*(int *)data == WSDISPLAYIO_VIDEO_ON) { 647 1.1 bsh scr = sc->active; 648 1.1 bsh if (scr == NULL) 649 1.1 bsh scr = LIST_FIRST(&sc->screens); 650 1.1 bsh 651 1.1 bsh if (scr == NULL) 652 1.1 bsh return ENXIO; 653 1.1 bsh 654 1.1 bsh s3c24x0_lcd_show_screen(sc, scr, 1, NULL, NULL); 655 1.1 bsh } 656 1.1 bsh else { 657 1.1 bsh s3c24x0_lcd_stop_dma(sc); 658 1.1 bsh s3c24x0_lcd_power(sc, 0); 659 1.1 bsh } 660 1.1 bsh return 0; 661 1.1 bsh 662 1.1 bsh case WSDISPLAYIO_GVIDEO: 663 1.1 bsh *(u_int *)data = sc->lcd_on; 664 1.1 bsh return 0; 665 1.1 bsh 666 1.9 nisimura /* XXX: Hack to support /usr/sbin/tpctl */ 667 1.9 nisimura case HPCFBIO_GCONF: 668 1.9 nisimura { 669 1.9 nisimura struct hpcfb_fbconf *fbconf = (struct hpcfb_fbconf*)data; 670 1.9 nisimura if (fbconf->hf_conf_index != 0 && 671 1.9 nisimura fbconf->hf_conf_index != HPCFB_CURRENT_CONFIG) 672 1.9 nisimura return EINVAL; 673 1.9 nisimura 674 1.9 nisimura fbconf->hf_nconfs = 1; 675 1.9 nisimura fbconf->hf_class = HPCFB_CLASS_RGBCOLOR; 676 1.9 nisimura strncpy(fbconf->hf_name, "S3C24X0 LCD", HPCFB_MAXNAMELEN); 677 1.9 nisimura strncpy(fbconf->hf_conf_name, "default", HPCFB_MAXNAMELEN); 678 1.9 nisimura fbconf->hf_height = sc->panel_info->panel_height; 679 1.9 nisimura fbconf->hf_width = sc->panel_info->panel_width; 680 1.9 nisimura fbconf->hf_baseaddr = 0x0; 681 1.9 nisimura fbconf->hf_offset = 0x0; 682 1.9 nisimura fbconf->hf_bytes_per_line = sc->panel_info->panel_width * (16/8); 683 1.9 nisimura fbconf->hf_nplanes = 0; 684 1.9 nisimura fbconf->hf_bytes_per_plane = 0; 685 1.9 nisimura fbconf->hf_pack_width = 16; 686 1.9 nisimura fbconf->hf_pixels_per_pack = 1; 687 1.9 nisimura fbconf->hf_pixel_width = 16; 688 1.9 nisimura 689 1.9 nisimura fbconf->hf_access_flags = 0; 690 1.9 nisimura fbconf->hf_order_flags = HPCFB_REVORDER_WORD; 691 1.9 nisimura fbconf->hf_reg_offset = 0x0; 692 1.9 nisimura 693 1.9 nisimura fbconf->hf_u.hf_rgb.hf_red_width = 5; 694 1.9 nisimura fbconf->hf_u.hf_rgb.hf_red_shift = 11; 695 1.9 nisimura fbconf->hf_u.hf_rgb.hf_green_width = 6; 696 1.9 nisimura fbconf->hf_u.hf_rgb.hf_green_shift = 5; 697 1.9 nisimura fbconf->hf_u.hf_rgb.hf_blue_width = 5; 698 1.9 nisimura fbconf->hf_u.hf_rgb.hf_blue_shift = 0; 699 1.9 nisimura 700 1.9 nisimura fbconf->hf_ext_size = 0; 701 1.9 nisimura fbconf->hf_ext_data = NULL; 702 1.9 nisimura 703 1.9 nisimura return 0; 704 1.9 nisimura } 705 1.9 nisimura 706 1.1 bsh case WSDISPLAYIO_GCURPOS: 707 1.1 bsh case WSDISPLAYIO_SCURPOS: 708 1.1 bsh case WSDISPLAYIO_GCURMAX: 709 1.1 bsh case WSDISPLAYIO_GCURSOR: 710 1.1 bsh case WSDISPLAYIO_SCURSOR: 711 1.1 bsh return EPASSTHROUGH; /* XXX */ 712 1.1 bsh } 713 1.1 bsh 714 1.1 bsh return EPASSTHROUGH; 715 1.1 bsh } 716 1.1 bsh 717 1.1 bsh paddr_t 718 1.4 jmmv s3c24x0_lcd_mmap(void *v, void *vs, off_t offset, int prot) 719 1.1 bsh { 720 1.1 bsh struct s3c24x0_lcd_softc *sc = v; 721 1.1 bsh struct s3c24x0_lcd_screen *screen = sc->active; /* ??? */ 722 1.9 nisimura paddr_t ret; 723 1.9 nisimura 724 1.9 nisimura /* printf("s3c24x0_lcd_mmap: screen: %p, offset: %ld\n", screen, (long)offset);*/ 725 1.1 bsh 726 1.1 bsh if (screen == NULL) 727 1.1 bsh return -1; 728 1.1 bsh 729 1.9 nisimura ret = bus_dmamem_mmap(sc->dma_tag, screen->segs, screen->nsegs, 730 1.1 bsh offset, prot, BUS_DMA_WAITOK|BUS_DMA_COHERENT); 731 1.9 nisimura /* printf("s3c24x0_lcd_mmap: ret: %lx\n", ret);*/ 732 1.9 nisimura return ret; 733 1.1 bsh } 734 1.1 bsh 735 1.1 bsh 736 1.1 bsh static void 737 1.1 bsh s3c24x0_lcd_cursor(void *cookie, int on, int row, int col) 738 1.1 bsh { 739 1.1 bsh struct s3c24x0_lcd_screen *scr = cookie; 740 1.1 bsh 741 1.1 bsh (* scr->rinfo.ri_ops.cursor)(&scr->rinfo, on, row, col); 742 1.1 bsh } 743 1.1 bsh 744 1.1 bsh static int 745 1.1 bsh s3c24x0_lcd_mapchar(void *cookie, int c, unsigned int *cp) 746 1.1 bsh { 747 1.1 bsh struct s3c24x0_lcd_screen *scr = cookie; 748 1.1 bsh 749 1.1 bsh return (* scr->rinfo.ri_ops.mapchar)(&scr->rinfo, c, cp); 750 1.1 bsh } 751 1.1 bsh 752 1.1 bsh static void 753 1.1 bsh s3c24x0_lcd_putchar(void *cookie, int row, int col, u_int uc, long attr) 754 1.1 bsh { 755 1.1 bsh struct s3c24x0_lcd_screen *scr = cookie; 756 1.1 bsh 757 1.1 bsh (* scr->rinfo.ri_ops.putchar)(&scr->rinfo, 758 1.1 bsh row, col, uc, attr); 759 1.1 bsh } 760 1.1 bsh 761 1.1 bsh static void 762 1.1 bsh s3c24x0_lcd_copycols(void *cookie, int row, int src, int dst, int num) 763 1.1 bsh { 764 1.1 bsh struct s3c24x0_lcd_screen *scr = cookie; 765 1.1 bsh 766 1.1 bsh (* scr->rinfo.ri_ops.copycols)(&scr->rinfo, 767 1.1 bsh row, src, dst, num); 768 1.1 bsh } 769 1.1 bsh 770 1.1 bsh static void 771 1.1 bsh s3c24x0_lcd_erasecols(void *cookie, int row, int col, int num, long attr) 772 1.1 bsh { 773 1.1 bsh struct s3c24x0_lcd_screen *scr = cookie; 774 1.1 bsh 775 1.1 bsh (* scr->rinfo.ri_ops.erasecols)(&scr->rinfo, 776 1.1 bsh row, col, num, attr); 777 1.1 bsh } 778 1.1 bsh 779 1.1 bsh static void 780 1.1 bsh s3c24x0_lcd_copyrows(void *cookie, int src, int dst, int num) 781 1.1 bsh { 782 1.1 bsh struct s3c24x0_lcd_screen *scr = cookie; 783 1.1 bsh 784 1.1 bsh (* scr->rinfo.ri_ops.copyrows)(&scr->rinfo, 785 1.1 bsh src, dst, num); 786 1.1 bsh } 787 1.1 bsh 788 1.1 bsh static void 789 1.1 bsh s3c24x0_lcd_eraserows(void *cookie, int row, int num, long attr) 790 1.1 bsh { 791 1.1 bsh struct s3c24x0_lcd_screen *scr = cookie; 792 1.1 bsh 793 1.1 bsh (* scr->rinfo.ri_ops.eraserows)(&scr->rinfo, 794 1.1 bsh row, num, attr); 795 1.1 bsh } 796 1.1 bsh 797 1.1 bsh static int 798 1.1 bsh s3c24x0_lcd_alloc_attr(void *cookie, int fg, int bg, int flg, long *attr) 799 1.1 bsh { 800 1.1 bsh struct s3c24x0_lcd_screen *scr = cookie; 801 1.1 bsh 802 1.1 bsh return (* scr->rinfo.ri_ops.allocattr)(&scr->rinfo, 803 1.1 bsh fg, bg, flg, attr); 804 1.1 bsh } 805 1.1 bsh 806 1.1 bsh 807 1.1 bsh const struct wsdisplay_emulops s3c24x0_lcd_emulops = { 808 1.1 bsh s3c24x0_lcd_cursor, 809 1.1 bsh s3c24x0_lcd_mapchar, 810 1.1 bsh s3c24x0_lcd_putchar, 811 1.1 bsh s3c24x0_lcd_copycols, 812 1.1 bsh s3c24x0_lcd_erasecols, 813 1.1 bsh s3c24x0_lcd_copyrows, 814 1.1 bsh s3c24x0_lcd_eraserows, 815 1.1 bsh s3c24x0_lcd_alloc_attr 816 1.1 bsh }; 817 1.1 bsh 818 1.1 bsh #endif /* NWSDISPLAY > 0 */ 819