1
2
3
4
5
6
7
8
9#include <common.h>
10
11#include <asm/gpio.h>
12#include <errno.h>
13
14
15
16
17
18
19static void lcd_panel_spi_write(int cs, int clk, int mosi,
20 unsigned int data, int bits)
21{
22 int i, offset;
23
24 gpio_direction_output(cs, 0);
25 for (i = 0; i < bits; i++) {
26 gpio_direction_output(clk, 0);
27 offset = (bits - 1) - i;
28 gpio_direction_output(mosi, (data >> offset) & 1);
29 udelay(2);
30 gpio_direction_output(clk, 1);
31 udelay(2);
32 }
33 gpio_direction_output(cs, 1);
34 udelay(2);
35}
36
37int hitachi_tx18d42vm_init(void)
38{
39 const u16 init_data[] = {
40 0x0029,
41 0x0025,
42 0x0840,
43 0x0430,
44 0x385f,
45 0x3ca4,
46 0x3409,
47 0x4041,
48 };
49 int i, cs, clk, mosi, ret = 0;
50
51 cs = name_to_gpio(CONFIG_VIDEO_LCD_SPI_CS);
52 clk = name_to_gpio(CONFIG_VIDEO_LCD_SPI_SCLK);
53 mosi = name_to_gpio(CONFIG_VIDEO_LCD_SPI_MOSI);
54
55 if (cs == -1 || clk == -1 || mosi == 1) {
56 printf("Error tx18d42vm spi gpio config is invalid\n");
57 return -EINVAL;
58 }
59
60 if (gpio_request(cs, "tx18d42vm-spi-cs") != 0 ||
61 gpio_request(clk, "tx18d42vm-spi-clk") != 0 ||
62 gpio_request(mosi, "tx18d42vm-spi-mosi") != 0) {
63 printf("Error cannot request tx18d42vm spi gpios\n");
64 ret = -EBUSY;
65 goto out;
66 }
67
68 for (i = 0; i < ARRAY_SIZE(init_data); i++)
69 lcd_panel_spi_write(cs, clk, mosi, init_data[i], 16);
70
71 mdelay(50);
72
73 lcd_panel_spi_write(cs, clk, mosi, 0x00ad, 16);
74
75out:
76 gpio_free(mosi);
77 gpio_free(clk);
78 gpio_free(cs);
79
80 return ret;
81}
82