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