1 1.14 andvar /* $NetBSD: smdk2410_lcd.c,v 1.14 2024/03/06 20:18:42 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 #include <sys/cdefs.h> 34 1.14 andvar __KERNEL_RCSID(0, "$NetBSD: smdk2410_lcd.c,v 1.14 2024/03/06 20:18:42 andvar Exp $"); 35 1.1 bsh 36 1.1 bsh /* 37 1.1 bsh * LCD driver for Samsung SMDK2410. 38 1.1 bsh * 39 1.1 bsh * Controlling LCD is almost completely done through S3C2410's 40 1.1 bsh * integrated LCD controller. Codes for it is arm/s3c2xx0/s3c24x0_lcd.c. 41 1.1 bsh * 42 1.1 bsh * Codes in this file provide the platform's LCD panel information. 43 1.1 bsh */ 44 1.1 bsh 45 1.1 bsh #include <sys/param.h> 46 1.1 bsh #include <sys/systm.h> 47 1.1 bsh #include <sys/conf.h> 48 1.1 bsh #include <sys/event.h> 49 1.1 bsh #include <sys/uio.h> 50 1.1 bsh 51 1.1 bsh #include <dev/cons.h> 52 1.1 bsh #include <dev/wscons/wsconsio.h> 53 1.1 bsh #include <dev/wscons/wsdisplayvar.h> 54 1.1 bsh #include <dev/wscons/wscons_callbacks.h> 55 1.1 bsh 56 1.6 dyoung #include <sys/bus.h> 57 1.1 bsh #include <arm/s3c2xx0/s3c24x0var.h> 58 1.1 bsh #include <arm/s3c2xx0/s3c24x0reg.h> 59 1.1 bsh #include <arm/s3c2xx0/s3c2410reg.h> 60 1.1 bsh #include <arm/s3c2xx0/s3c24x0_lcd.h> 61 1.1 bsh 62 1.5 snj #include "locators.h" 63 1.1 bsh #include "wsdisplay.h" 64 1.1 bsh 65 1.8 chs int lcd_match(device_t, cfdata_t, void *); 66 1.8 chs void lcd_attach(device_t, device_t, void *); 67 1.1 bsh 68 1.1 bsh #ifdef LCD_DEBUG 69 1.1 bsh void draw_test_pattern(struct s3c24x0_lcd_softc *, 70 1.1 bsh struct s3c24x0_lcd_screen *scr); 71 1.1 bsh #endif 72 1.1 bsh 73 1.1 bsh #if NWSDISPLAY > 0 74 1.1 bsh 75 1.1 bsh /* 76 1.1 bsh * Screen geometries. 77 1.1 bsh * 78 1.1 bsh * S3C24x0's LCD controller can have virtual screens that are bigger 79 1.1 bsh * than actual LCD panel. (XXX: wscons can't manage such screens for now) 80 1.1 bsh */ 81 1.1 bsh struct s3c24x0_wsscreen_descr lcd_bpp16_30x32 = { 82 1.1 bsh { 83 1.1 bsh "30x32bpp16", 30, 32, 84 1.1 bsh &s3c24x0_lcd_emulops, 85 1.1 bsh 8, 10, 86 1.1 bsh WSSCREEN_WSCOLORS, 87 1.1 bsh }, 88 1.1 bsh 16 /* bits per pixel */ 89 1.1 bsh }, lcd_bpp16_30x20 = { 90 1.1 bsh { 91 1.1 bsh "30x20bpp16", 30, 20, 92 1.1 bsh &s3c24x0_lcd_emulops, 93 1.1 bsh 8, 16, 94 1.1 bsh WSSCREEN_WSCOLORS, 95 1.1 bsh }, 96 1.1 bsh 16 97 1.1 bsh }, lcd_bpp8_30x32 = { 98 1.1 bsh { 99 1.1 bsh "30x32bpp8", 30, 32, 100 1.1 bsh &s3c24x0_lcd_emulops, 101 1.1 bsh 8, 10, 102 1.1 bsh WSSCREEN_WSCOLORS, 103 1.1 bsh }, 104 1.1 bsh 8 105 1.1 bsh }, lcd_bpp8_40x25 = { /* with big virtual screen */ 106 1.1 bsh { 107 1.1 bsh "40x25bpp8", 40, 25, 108 1.1 bsh &s3c24x0_lcd_emulops, 109 1.1 bsh 8, 16, 110 1.1 bsh WSSCREEN_WSCOLORS, 111 1.1 bsh }, 112 1.1 bsh 8 113 1.1 bsh }, lcd_bpp4_30x32 = { 114 1.1 bsh { 115 1.1 bsh "30x32bpp4", 30, 32, 116 1.1 bsh &s3c24x0_lcd_emulops, 117 1.1 bsh 8, 10, 118 1.1 bsh 0, /* 4bpp mode is grayscale */ 119 1.1 bsh }, 120 1.1 bsh 4 121 1.1 bsh }; 122 1.1 bsh 123 1.1 bsh 124 1.1 bsh static const struct wsscreen_descr *lcd_scr_descr[] = { 125 1.1 bsh #if 0 126 1.1 bsh /* bpp4 needs a patch to rasops4 */ 127 1.1 bsh &lcd_bpp4_30x32.c, 128 1.1 bsh #endif 129 1.1 bsh &lcd_bpp8_30x32.c, 130 1.1 bsh &lcd_bpp8_40x25.c, 131 1.1 bsh &lcd_bpp16_30x32.c, 132 1.1 bsh &lcd_bpp16_30x20.c, 133 1.1 bsh }; 134 1.1 bsh 135 1.1 bsh #define N_SCR_DESCR (sizeof lcd_scr_descr / sizeof lcd_scr_descr[0]) 136 1.1 bsh 137 1.1 bsh const struct wsscreen_list lcd_screen_list = { 138 1.1 bsh N_SCR_DESCR, 139 1.1 bsh lcd_scr_descr 140 1.1 bsh }; 141 1.1 bsh 142 1.1 bsh const struct wsdisplay_accessops lcd_accessops = { 143 1.1 bsh s3c24x0_lcd_ioctl, 144 1.1 bsh s3c24x0_lcd_mmap, 145 1.1 bsh s3c24x0_lcd_alloc_screen, 146 1.1 bsh s3c24x0_lcd_free_screen, 147 1.1 bsh s3c24x0_lcd_show_screen, 148 1.1 bsh NULL, /* load_font */ 149 1.1 bsh }; 150 1.1 bsh 151 1.1 bsh #else /* NWSDISPLAY */ 152 1.1 bsh /* 153 1.1 bsh * Interface to LCD framebuffer without wscons 154 1.1 bsh */ 155 1.1 bsh extern struct cfdriver lcd_cd; 156 1.1 bsh 157 1.1 bsh dev_type_open(lcdopen); 158 1.1 bsh dev_type_close(lcdclose); 159 1.1 bsh dev_type_ioctl(lcdioctl); 160 1.1 bsh dev_type_mmap(lcdmmap); 161 1.1 bsh const struct cdevsw lcd_cdevsw = { 162 1.9 dholland .d_open = lcdopen, 163 1.9 dholland .d_close = lcdclose, 164 1.9 dholland .d_read = noread, 165 1.9 dholland .d_write = nowrite, 166 1.9 dholland .d_ioctl = lcdioctl, 167 1.9 dholland .d_stop = nostop, 168 1.9 dholland .d_tty = notty, 169 1.9 dholland .d_poll = nopoll, 170 1.9 dholland .d_mmap = lcdmmap, 171 1.9 dholland .d_kqfilter = nokqfilter, 172 1.10 dholland .d_discard = nodiscard, 173 1.9 dholland .d_flag = D_TTY 174 1.1 bsh }; 175 1.1 bsh 176 1.1 bsh #endif /* NWSDISPLAY */ 177 1.1 bsh 178 1.7 nisimura CFATTACH_DECL_NEW(lcd_ssio, sizeof (struct s3c24x0_lcd_softc), lcd_match, 179 1.1 bsh lcd_attach, NULL, NULL); 180 1.1 bsh 181 1.1 bsh int 182 1.8 chs lcd_match(device_t parent, cfdata_t cf, void *aux) 183 1.1 bsh { 184 1.1 bsh struct s3c2xx0_attach_args *sa = aux; 185 1.1 bsh 186 1.1 bsh if (sa->sa_addr == SSIOCF_ADDR_DEFAULT) 187 1.1 bsh sa->sa_addr = S3C2410_LCDC_BASE; 188 1.1 bsh 189 1.1 bsh return 1; 190 1.1 bsh } 191 1.1 bsh 192 1.1 bsh static const struct s3c24x0_lcd_panel_info samsung_LTS350Q1 = 193 1.1 bsh { 194 1.1 bsh 240, /* Width */ 195 1.1 bsh 320, /* Height */ 196 1.1 bsh 10*1000*1000, /* pixel clock = 10MHz */ 197 1.1 bsh 198 1.1 bsh #define _(field, val) (((val)-1) << (field##_SHIFT)) 199 1.1 bsh 200 1.1 bsh LCDCON1_PNRMODE_TFT, 201 1.1 bsh 202 1.1 bsh /* LCDCON2: vertical timings */ 203 1.1 bsh _(LCDCON2_VBPD, 2) | 204 1.1 bsh _(LCDCON2_VFPD, 3) | 205 1.1 bsh _(LCDCON2_LINEVAL, 320) | 206 1.1 bsh _(LCDCON2_VPSW, 2), 207 1.1 bsh 208 1.1 bsh /* LCDCON3: horizontal timings */ 209 1.1 bsh _(LCDCON3_HBPD, 7) | 210 1.1 bsh _(LCDCON3_HFPD, 3), 211 1.1 bsh 212 1.14 andvar /* LCDCON4: horizontal pulse width */ 213 1.1 bsh _(LCDCON4_HPSW, 4), 214 1.1 bsh 215 1.1 bsh /* LCDCON5: signal polarities */ 216 1.1 bsh LCDCON5_FRM565 | LCDCON5_INVVLINE | LCDCON5_INVVFRAME, 217 1.1 bsh 218 1.1 bsh /* LPCSEL register */ 219 1.1 bsh LPCSEL_LPC_EN | LPCSEL_RES_SEL | LPCSEL_MODE_SEL, 220 1.1 bsh #undef _ 221 1.1 bsh }; 222 1.1 bsh 223 1.1 bsh void 224 1.8 chs lcd_attach(device_t parent, device_t self, void *aux) 225 1.1 bsh { 226 1.7 nisimura struct s3c24x0_lcd_softc *sc = device_private(self); 227 1.1 bsh bus_space_tag_t iot = s3c2xx0_softc->sc_iot; 228 1.1 bsh bus_space_handle_t gpio_ioh = s3c2xx0_softc->sc_gpio_ioh; 229 1.1 bsh #if NWSDISPLAY > 0 230 1.1 bsh struct wsemuldisplaydev_attach_args aa; 231 1.1 bsh #else 232 1.1 bsh struct s3c24x0_lcd_screen *screen; 233 1.1 bsh #endif 234 1.1 bsh 235 1.1 bsh 236 1.7 nisimura sc->sc_dev = self; 237 1.1 bsh aprint_normal( "\n" ); 238 1.1 bsh 239 1.1 bsh /* setup GPIO ports for LCD */ 240 1.1 bsh /* XXX: some LCD panels may not need all VD signals */ 241 1.1 bsh gpio_ioh = s3c2xx0_softc->sc_gpio_ioh; 242 1.1 bsh bus_space_write_4(iot, gpio_ioh, GPIO_PCUP, ~0); 243 1.1 bsh bus_space_write_4(iot, gpio_ioh, GPIO_PCCON, 0xaaaaaaaa); 244 1.1 bsh bus_space_write_4(iot, gpio_ioh, GPIO_PDUP, ~0); 245 1.1 bsh bus_space_write_4(iot, gpio_ioh, GPIO_PDCON, 0xaaaaaaaa); 246 1.1 bsh 247 1.1 bsh s3c24x0_lcd_attach_sub(sc, aux, &samsung_LTS350Q1); 248 1.1 bsh 249 1.1 bsh #if NWSDISPLAY > 0 250 1.1 bsh 251 1.1 bsh aa.console = 0; 252 1.1 bsh aa.scrdata = &lcd_screen_list; 253 1.1 bsh aa.accessops = &lcd_accessops; 254 1.1 bsh aa.accesscookie = sc; 255 1.1 bsh 256 1.1 bsh 257 1.12 thorpej (void) config_found(self, &aa, wsemuldisplaydevprint, CFARGS_NONE); 258 1.1 bsh #else 259 1.1 bsh 260 1.1 bsh screen = s3c24x0_lcd_new_screen(sc, 240, 320, 16); 261 1.1 bsh 262 1.1 bsh if( screen ){ 263 1.1 bsh sc->active = screen; 264 1.1 bsh s3c24x0_lcd_start_dma(sc, screen); 265 1.1 bsh s3c24x0_lcd_power(sc, 1); 266 1.1 bsh } 267 1.1 bsh #endif /* NWSDISPLAY */ 268 1.1 bsh 269 1.1 bsh } 270 1.1 bsh 271 1.1 bsh #if NWSDISPLAY == 0 272 1.1 bsh 273 1.1 bsh int 274 1.1 bsh lcdopen( dev_t dev, int oflags, int devtype, struct proc *p ) 275 1.1 bsh { 276 1.1 bsh return 0; 277 1.1 bsh } 278 1.1 bsh 279 1.1 bsh int 280 1.1 bsh lcdclose( dev_t dev, int fflag, int devtype, struct proc *p ) 281 1.1 bsh { 282 1.1 bsh return 0; 283 1.1 bsh } 284 1.1 bsh 285 1.1 bsh paddr_t 286 1.1 bsh lcdmmap( dev_t dev, off_t offset, int size ) 287 1.1 bsh { 288 1.4 cegger struct s3c24x0_lcd_softc *sc = 289 1.4 cegger device_lookup_private(&lcd_cd, minor(dev)); 290 1.1 bsh struct s3c24x0_lcd_screen *scr = sc->active; 291 1.1 bsh 292 1.1 bsh return bus_dmamem_mmap(sc->dma_tag, scr->segs, scr->nsegs, 293 1.1 bsh offset, 0, BUS_DMA_WAITOK|BUS_DMA_COHERENT); 294 1.1 bsh } 295 1.1 bsh 296 1.1 bsh int 297 1.3 christos lcdioctl( dev_t dev, u_long cmd, void *data, 298 1.2 christos int fflag, struct lwp *l ) 299 1.1 bsh { 300 1.1 bsh return EOPNOTSUPP; 301 1.1 bsh } 302 1.1 bsh 303 1.1 bsh #endif /* NWSDISPLAY>0 */ 304 1.1 bsh 305 1.1 bsh #ifdef LCD_DEBUG 306 1.1 bsh static void 307 1.1 bsh draw_test_pattern_16(struct s3c24x0_lcd_softc *sc, 308 1.1 bsh struct s3c24x0_lcd_screen *scr) 309 1.1 bsh { 310 1.1 bsh int x, y; 311 1.1 bsh uint16_t color, *line; 312 1.1 bsh char *buf = (char *)(scr->buf_va); 313 1.1 bsh 314 1.1 bsh #define rgb(r,g,b) (((r)<<11) | ((g)<<5) | (b)) 315 1.1 bsh 316 1.1 bsh for (y=0; y < sc->panel_info->panel_height; ++y) { 317 1.1 bsh line = (uint16_t *)(buf + scr->stride * y); 318 1.1 bsh 319 1.1 bsh for (x=0; x < sc->panel_info->panel_width; ++x) { 320 1.1 bsh switch (((x/30) + (y/10)) % 8) { 321 1.1 bsh default: 322 1.1 bsh case 0: color = rgb(0x00, 0x00, 0x00); break; 323 1.1 bsh case 1: color = rgb(0x00, 0x00, 0x1f); break; 324 1.1 bsh case 2: color = rgb(0x00, 0x3f, 0x00); break; 325 1.1 bsh case 3: color = rgb(0x00, 0x3f, 0x1f); break; 326 1.1 bsh case 4: color = rgb(0x1f, 0x00, 0x00); break; 327 1.1 bsh case 5: color = rgb(0x1f, 0x00, 0x1f); break; 328 1.1 bsh case 6: color = rgb(0x1f, 0x3f, 0x00); break; 329 1.1 bsh case 7: color = rgb(0x1f, 0x3f, 0x1f); break; 330 1.1 bsh } 331 1.1 bsh 332 1.1 bsh line[x] = color; 333 1.1 bsh } 334 1.1 bsh } 335 1.1 bsh 336 1.1 bsh for (x=0; x < MIN(sc->panel_info->panel_height, 337 1.1 bsh sc->panel_info->panel_width); ++x) { 338 1.1 bsh 339 1.1 bsh line = (uint16_t *)(buf + scr->stride * x); 340 1.1 bsh line[x] = rgb(0x1f, 0x3f, 0x1f); 341 1.1 bsh } 342 1.1 bsh } 343 1.1 bsh 344 1.1 bsh static void 345 1.1 bsh draw_test_pattern_8(struct s3c24x0_lcd_softc *sc, 346 1.1 bsh struct s3c24x0_lcd_screen *scr) 347 1.1 bsh { 348 1.1 bsh int x, y; 349 1.1 bsh uint8_t *line; 350 1.1 bsh char *buf = (char *)(scr->buf_va); 351 1.1 bsh 352 1.1 bsh 353 1.1 bsh for (y=0; y < sc->panel_info->panel_height; ++y) { 354 1.1 bsh line = (uint8_t *)(buf + scr->stride * y); 355 1.1 bsh 356 1.1 bsh for (x=0; x < sc->panel_info->panel_width; ++x) { 357 1.1 bsh line[x] = (((x/15) + (y/20)) % 16); 358 1.1 bsh } 359 1.1 bsh } 360 1.1 bsh 361 1.1 bsh for (x=0; x < MIN(sc->panel_info->panel_height, 362 1.1 bsh sc->panel_info->panel_width); ++x) { 363 1.1 bsh 364 1.1 bsh line = (uint8_t *)(buf + scr->stride * x); 365 1.1 bsh line[x] = 7; 366 1.1 bsh } 367 1.1 bsh } 368 1.1 bsh 369 1.1 bsh 370 1.1 bsh void 371 1.1 bsh draw_test_pattern(struct s3c24x0_lcd_softc *sc, struct s3c24x0_lcd_screen *scr) 372 1.1 bsh { 373 1.1 bsh switch (scr->depth) { 374 1.1 bsh case 16: 375 1.1 bsh draw_test_pattern_16(sc, scr); 376 1.1 bsh break; 377 1.1 bsh case 8: 378 1.1 bsh draw_test_pattern_8(sc, scr); 379 1.1 bsh break; 380 1.1 bsh } 381 1.1 bsh } 382 1.1 bsh 383 1.1 bsh 384 1.1 bsh #endif /* LCD_DEBUG */ 385 1.1 bsh 386