xref: /rk3399_rockchip-uboot/drivers/video/hitachi_tx18d42vm_lcd.c (revision e72d344386bf80738fab7a6bd37cb321f443093a)
1*a5464f2bSHans de Goede /*
2*a5464f2bSHans de Goede  * Hitachi tx18d42vm LVDS LCD panel driver
3*a5464f2bSHans de Goede  *
4*a5464f2bSHans de Goede  * (C) Copyright 2015 Hans de Goede <hdegoede@redhat.com>
5*a5464f2bSHans de Goede  *
6*a5464f2bSHans de Goede  * SPDX-License-Identifier:	GPL-2.0+
7*a5464f2bSHans de Goede  */
8*a5464f2bSHans de Goede 
9*a5464f2bSHans de Goede #include <common.h>
10*a5464f2bSHans de Goede 
11*a5464f2bSHans de Goede #include <asm/gpio.h>
12*a5464f2bSHans de Goede #include <errno.h>
13*a5464f2bSHans de Goede 
14*a5464f2bSHans de Goede /*
15*a5464f2bSHans de Goede  * Very simple write only SPI support, this does not use the generic SPI infra
16*a5464f2bSHans de Goede  * because that assumes R/W SPI, requiring a MISO pin. Also the necessary glue
17*a5464f2bSHans de Goede  * code alone would be larger then this minimal version.
18*a5464f2bSHans de Goede  */
lcd_panel_spi_write(int cs,int clk,int mosi,unsigned int data,int bits)19*a5464f2bSHans de Goede static void lcd_panel_spi_write(int cs, int clk, int mosi,
20*a5464f2bSHans de Goede 				unsigned int data, int bits)
21*a5464f2bSHans de Goede {
22*a5464f2bSHans de Goede 	int i, offset;
23*a5464f2bSHans de Goede 
24*a5464f2bSHans de Goede 	gpio_direction_output(cs, 0);
25*a5464f2bSHans de Goede 	for (i = 0; i < bits; i++) {
26*a5464f2bSHans de Goede 		gpio_direction_output(clk, 0);
27*a5464f2bSHans de Goede 		offset = (bits - 1) - i;
28*a5464f2bSHans de Goede 		gpio_direction_output(mosi, (data >> offset) & 1);
29*a5464f2bSHans de Goede 		udelay(2);
30*a5464f2bSHans de Goede 		gpio_direction_output(clk, 1);
31*a5464f2bSHans de Goede 		udelay(2);
32*a5464f2bSHans de Goede 	}
33*a5464f2bSHans de Goede 	gpio_direction_output(cs, 1);
34*a5464f2bSHans de Goede 	udelay(2);
35*a5464f2bSHans de Goede }
36*a5464f2bSHans de Goede 
hitachi_tx18d42vm_init(void)37*a5464f2bSHans de Goede int hitachi_tx18d42vm_init(void)
38*a5464f2bSHans de Goede {
39*a5464f2bSHans de Goede 	const u16 init_data[] = {
40*a5464f2bSHans de Goede 		0x0029,		/* reset */
41*a5464f2bSHans de Goede 		0x0025,		/* standby */
42*a5464f2bSHans de Goede 		0x0840,		/* enable normally black */
43*a5464f2bSHans de Goede 		0x0430,		/* enable FRC/dither */
44*a5464f2bSHans de Goede 		0x385f,		/* enter test mode(1) */
45*a5464f2bSHans de Goede 		0x3ca4,		/* enter test mode(2) */
46*a5464f2bSHans de Goede 		0x3409,		/* enable SDRRS, enlarge OE width */
47*a5464f2bSHans de Goede 		0x4041,		/* adopt 2 line / 1 dot */
48*a5464f2bSHans de Goede 	};
49*a5464f2bSHans de Goede 	int i, cs, clk, mosi, ret = 0;
50*a5464f2bSHans de Goede 
51*a5464f2bSHans de Goede 	cs = name_to_gpio(CONFIG_VIDEO_LCD_SPI_CS);
52*a5464f2bSHans de Goede 	clk = name_to_gpio(CONFIG_VIDEO_LCD_SPI_SCLK);
53*a5464f2bSHans de Goede 	mosi = name_to_gpio(CONFIG_VIDEO_LCD_SPI_MOSI);
54*a5464f2bSHans de Goede 
55*a5464f2bSHans de Goede 	if (cs == -1 || clk == -1 || mosi == 1) {
56*a5464f2bSHans de Goede 		printf("Error tx18d42vm spi gpio config is invalid\n");
57*a5464f2bSHans de Goede 		return -EINVAL;
58*a5464f2bSHans de Goede 	}
59*a5464f2bSHans de Goede 
60*a5464f2bSHans de Goede 	if (gpio_request(cs, "tx18d42vm-spi-cs") != 0 ||
61*a5464f2bSHans de Goede 	    gpio_request(clk, "tx18d42vm-spi-clk") != 0 ||
62*a5464f2bSHans de Goede 	    gpio_request(mosi, "tx18d42vm-spi-mosi") != 0) {
63*a5464f2bSHans de Goede 		printf("Error cannot request tx18d42vm spi gpios\n");
64*a5464f2bSHans de Goede 		ret = -EBUSY;
65*a5464f2bSHans de Goede 		goto out;
66*a5464f2bSHans de Goede 	}
67*a5464f2bSHans de Goede 
68*a5464f2bSHans de Goede 	for (i = 0; i < ARRAY_SIZE(init_data); i++)
69*a5464f2bSHans de Goede 		lcd_panel_spi_write(cs, clk, mosi, init_data[i], 16);
70*a5464f2bSHans de Goede 
71*a5464f2bSHans de Goede 	mdelay(50); /* All the tx18d42vm drivers have a delay here ? */
72*a5464f2bSHans de Goede 
73*a5464f2bSHans de Goede 	lcd_panel_spi_write(cs, clk, mosi, 0x00ad, 16); /* display on */
74*a5464f2bSHans de Goede 
75*a5464f2bSHans de Goede out:
76*a5464f2bSHans de Goede 	gpio_free(mosi);
77*a5464f2bSHans de Goede 	gpio_free(clk);
78*a5464f2bSHans de Goede 	gpio_free(cs);
79*a5464f2bSHans de Goede 
80*a5464f2bSHans de Goede 	return ret;
81*a5464f2bSHans de Goede }
82