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