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