Home | History | Annotate | Line # | Download | only in netwalker
netwalker_lcd.c revision 1.2
      1 /*	$NetBSD: netwalker_lcd.c,v 1.2 2014/03/16 05:20:24 dholland Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2011, 2012 Genetec corp. All rights reserved.
      5  * Written by Hashimoto Kenichi for Genetec corp.
      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  *
     16  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
     17  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
     18  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
     19  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
     20  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
     21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
     22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
     23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
     24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
     25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
     26  * POSSIBILITY OF SUCH DAMAGE.
     27  */
     28 #include <sys/param.h>
     29 #include <sys/systm.h>
     30 #include <sys/conf.h>
     31 #include <sys/uio.h>
     32 #include <sys/malloc.h>
     33 #include <sys/device.h>
     34 
     35 #include <dev/cons.h>
     36 #include <dev/wscons/wsconsio.h>
     37 #include <dev/wscons/wsdisplayvar.h>
     38 #include <dev/wscons/wscons_callbacks.h>
     39 
     40 #include <sys/bus.h>
     41 #include <arm/imx/imx51var.h>
     42 #include <arm/imx/imx51reg.h>
     43 #include <arm/imx/imx51_ipuv3var.h>
     44 #include <arm/imx/imx51_ipuv3reg.h>
     45 #include <arm/imx/imx51_iomuxreg.h>
     46 #include <arm/imx/imxgpiovar.h>
     47 
     48 #include "opt_imx51_ipuv3.h"
     49 #include "opt_netwalker_lcd.h"
     50 
     51 #include "wsdisplay.h"
     52 #include "ioconf.h"
     53 
     54 int lcd_match(device_t, cfdata_t, void *);
     55 void lcd_attach(device_t, device_t, void *);
     56 
     57 void netwalker_cnattach(void);
     58 
     59 #if NWSDISPLAY > 0
     60 #else
     61 #ifdef LCD_DEBUG
     62 static void draw_test_pattern(struct imx51_ipuv3_softc *,
     63     struct imx51_ipuv3_screen *);
     64 #endif
     65 
     66 /*
     67  * Interface to LCD framebuffer without wscons
     68  */
     69 extern struct cfdriver ipu_cd;
     70 
     71 dev_type_open(lcdopen);
     72 dev_type_close(lcdclose);
     73 dev_type_ioctl(lcdioctl);
     74 dev_type_mmap(lcdmmap);
     75 const struct cdevsw ipu_cdevsw = {
     76 	.d_open = lcdopen,
     77 	.d_close = lcdclose,
     78 	.d_read = noread,
     79 	.d_write = nowrite,
     80 	.d_ioctl = lcdioctl,
     81 	.d_stop = nostop,
     82 	.d_tty = notty,
     83 	.d_poll = nopoll,
     84 	.d_mmap = lcdmmap,
     85 	.d_kqfilter = nokqfilter,
     86 	.d_flag = D_TTY
     87 };
     88 
     89 #endif
     90 
     91 CFATTACH_DECL_NEW(lcd_netwalker, sizeof (struct imx51_ipuv3_softc),
     92     lcd_match, lcd_attach, NULL, NULL);
     93 
     94 int
     95 lcd_match( device_t parent, cfdata_t cf, void *aux )
     96 {
     97 	return 1;
     98 }
     99 
    100 /* Sharp's LCD */
    101 static const struct lcd_panel_geometry sharp_panel =
    102 {
    103 	.panel_width = 1024,	/* Width */
    104 	.panel_height = 600,	/* Height */
    105 
    106 	.pixel_clk = 30076000,
    107 
    108 	.hsync_width = 8,
    109 	.left  = 20,
    110 	.right = 20,
    111 
    112 	.vsync_width = 4,
    113 	.upper = 2,
    114 	.lower = 2,
    115 
    116 	.panel_info = 0,
    117 };
    118 
    119 #define PANEL	sharp_panel
    120 
    121 void lcd_attach( device_t parent, device_t self, void *aux )
    122 {
    123 	struct imx51_ipuv3_softc *sc = device_private(self);
    124 	struct axi_attach_args *axia = aux;
    125 	bus_space_tag_t iot = axia->aa_iot;
    126 
    127 	sc->dev = self;
    128 
    129 #if (NWSDISPLAY > 0) && defined(IMXIPUCONSOLE)
    130 	netwalker_cnattach();
    131 #endif
    132 
    133 #if 0
    134 	/* IOMUX registers are already set correctly for LCD display */
    135 	iomux_mux_config(iomux_ipuv3_config);
    136 #endif
    137 
    138 	/* XXX move this to imx51_ipuv3.c */
    139 	{
    140 		bus_space_handle_t mipi_ioh;
    141 		uint32_t reg;
    142 
    143 		if (bus_space_map(iot, 0x83fdc000, 0x1000, 0, &mipi_ioh))
    144 			aprint_error_dev(self, "can't map MIPI HSC");
    145 		else {
    146 			bus_space_write_4(iot, mipi_ioh, 0x000, 0xf00);
    147 
    148 			reg = bus_space_read_4(iot, mipi_ioh, 0x800);
    149 			bus_space_write_4(iot, mipi_ioh, 0x800, reg | 0x0ff);
    150 
    151 			reg = bus_space_read_4(iot, mipi_ioh, 0x800);
    152 			bus_space_write_4(iot, mipi_ioh, 0x800, reg | 0x10000);
    153 		}
    154 	}
    155 
    156 	/* LCD power on */
    157 	gpio_set_direction(GPIO_NO(4, 9), GPIO_DIR_OUT);
    158 	gpio_set_direction(GPIO_NO(4, 10), GPIO_DIR_OUT);
    159 	gpio_set_direction(GPIO_NO(3, 3), GPIO_DIR_OUT);
    160 
    161 	gpio_data_write(GPIO_NO(3, 3), 1);
    162 	gpio_data_write(GPIO_NO(4, 9), 1);
    163 	delay(180 * 1000);
    164 	gpio_data_write(GPIO_NO(4, 10), 1);
    165 
    166 	/* pwm pin (100%) */
    167 	gpio_set_direction(GPIO_NO(1, 2), GPIO_DIR_OUT);
    168 	gpio_data_write(GPIO_NO(1, 2), 1);
    169 
    170 	gpio_set_direction(GPIO_NO(2, 13), GPIO_DIR_OUT);
    171 	gpio_data_write(GPIO_NO(2, 13), 1);
    172 
    173 	imx51_ipuv3_attach_sub(sc, aux, &PANEL);
    174 
    175 #if NWSDISPLAY == 0
    176 	{
    177 		struct imx51_ipuv3_screen *screen;
    178 		int error;
    179 
    180 		error = imx51_ipuv3_new_screen(sc, 16, &screen);
    181 #ifdef LCD_DEBUG
    182 		draw_test_pattern(sc, screen);
    183 #endif
    184 		if (error == 0) {
    185 			sc->active = screen;
    186 			imx51_ipuv3_start_dma(sc, screen);
    187 		}
    188 	}
    189 #endif
    190 }
    191 
    192 #if NWSDISPLAY > 0
    193 void
    194 netwalker_cnattach(void)
    195 {
    196 	imx51_ipuv3_cnattach(&PANEL);
    197 	return;
    198 }
    199 #else
    200 
    201 int
    202 lcdopen(dev_t dev, int oflags, int devtype, struct lwp *l)
    203 {
    204 	return 0;
    205 }
    206 
    207 int
    208 lcdclose(dev_t dev, int fflag, int devtype, struct lwp *l)
    209 {
    210 	return 0;
    211 }
    212 
    213 paddr_t
    214 lcdmmap(dev_t dev, off_t offset, int size)
    215 {
    216 	struct imx51_ipuv3_softc *sc =
    217 	    device_lookup_private(&ipu_cd, minor(dev));
    218 	struct imx51_ipuv3_screen *scr = sc->active;
    219 
    220 	return bus_dmamem_mmap(sc->dma_tag, scr->segs, scr->nsegs,
    221 	    offset, 0, BUS_DMA_WAITOK|BUS_DMA_COHERENT);
    222 }
    223 
    224 int
    225 lcdioctl(dev_t dev, u_long cmd, void *data,
    226     int fflag, struct lwp *l)
    227 {
    228 	return EOPNOTSUPP;
    229 }
    230 
    231 #ifdef LCD_DEBUG
    232 static void
    233 draw_test_pattern(struct imx51_ipuv3_softc *sc,
    234     struct imx51_ipuv3_screen *scr)
    235 {
    236 	int x, y;
    237 	uint16_t color, *line;
    238 	char *buf = (char *)(scr->buf_va);
    239 
    240 	printf("%s: buf_va %p, size 0x%x\n", __func__, buf,
    241 	       (uint)scr->buf_size);
    242 	printf("%s: panel %d x %d\n", __func__,
    243 	    sc->geometry->panel_width,
    244 	    sc->geometry->panel_height);
    245 #define	rgb(r,g,b)	(((r)<<11) | ((g)<<5) | (b))
    246 
    247 	for (y=0; y < sc->geometry->panel_height; ++y) {
    248 		line = (uint16_t *)(buf + scr->stride * y);
    249 
    250 		for (x=0; x < sc->geometry->panel_width; ++x) {
    251 			switch (((x/30) + (y/10)) % 8) {
    252 			default:
    253 			case 0: color = rgb(0x00, 0x00, 0x00); break;
    254 			case 1: color = rgb(0x00, 0x00, 0x1f); break;
    255 			case 2: color = rgb(0x00, 0x3f, 0x00); break;
    256 			case 3: color = rgb(0x00, 0x3f, 0x1f); break;
    257 			case 4: color = rgb(0x1f, 0x00, 0x00); break;
    258 			case 5: color = rgb(0x1f, 0x00, 0x1f); break;
    259 			case 6: color = rgb(0x1f, 0x3f, 0x00); break;
    260 			case 7: color = rgb(0x1f, 0x3f, 0x1f); break;
    261 			}
    262 
    263 			line[x] = color;
    264 		}
    265 	}
    266 
    267 	for (x=0; x < MIN(sc->geometry->panel_height,
    268 		sc->geometry->panel_width); ++x) {
    269 		line = (uint16_t *)(buf + scr->stride * x);
    270 		line[x] = rgb(0x1f, 0x3f, 0x1f);
    271 	}
    272 }
    273 #endif
    274 
    275 #endif /* NWSDISPLAY > 0 */
    276 
    277 
    278