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