Merge tag 'efi-2019-07-rc1-2' of git://git.denx.de/u-boot-efi
[platform/kernel/u-boot.git] / drivers / video / formike.c
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * LCD: Formike, TFT 4.3", 480x800, RGB24, KWH043ST20-F01, DriverIC NT35510-16
4  * LCD initialization via SPI
5  * Based on:
6  *
7  */
8 #include <common.h>
9 #include <errno.h>
10 #include <spi.h>
11
12 #define TAG_READ        0x80
13 #define TAG_WRITE       0x00
14
15 #define TAG_DATA        0x40
16 #define TAG_COMMAND     0x00
17
18 #define TAG_ADDR_H      0x20
19 #define TAG_ADDR_L      0x00
20
21 static int spi_write_tag_val(struct spi_slave *spi, unsigned char tag,
22                              unsigned char val)
23 {
24         unsigned long flags = SPI_XFER_BEGIN;
25         u8 buf[2];
26         int ret;
27
28         buf[0] = tag;
29         ret = spi_xfer(spi, 8, buf, NULL, flags);
30         buf[0] = val;
31         flags = SPI_XFER_END;
32         ret = spi_xfer(spi, 8, buf, NULL, flags);
33
34 #ifdef KWH043ST20_F01_SPI_DEBUG
35         printf("spi_write_tag_val: tag=%02X, val=%02X ret: %d\n",
36                tag, val, ret);
37 #endif /* KWH043ST20_F01_SPI_DEBUG */
38         if (ret)
39                 debug("%s: Failed to send: %d\n", __func__, ret);
40
41         return ret;
42 }
43
44 static void spi_write_dat(struct spi_slave *spi, unsigned int val)
45 {
46         spi_write_tag_val(spi, TAG_WRITE|TAG_DATA, val);
47 }
48
49 static void spi_write_com(struct spi_slave *spi, unsigned int addr)
50 {
51         spi_write_tag_val(spi, TAG_WRITE|TAG_COMMAND|TAG_ADDR_H,
52                           (addr & 0xff00) >> 8);
53         spi_write_tag_val(spi, TAG_WRITE|TAG_COMMAND|TAG_ADDR_L,
54                           (addr & 0x00ff) >> 0);
55 }
56
57 int kwh043st20_f01_spi_startup(unsigned int bus, unsigned int cs,
58         unsigned int max_hz, unsigned int spi_mode)
59 {
60         struct spi_slave *spi;
61         int ret;
62
63         spi = spi_setup_slave(bus, cs, max_hz, spi_mode);
64         if (!spi) {
65                 debug("%s: Failed to set up slave\n", __func__);
66                 return -1;
67         }
68
69         ret = spi_claim_bus(spi);
70         if (ret) {
71                 debug("%s: Failed to claim SPI bus: %d\n", __func__, ret);
72                 goto err_claim_bus;
73         }
74
75
76         /* LV2 Page 1 enable */
77         spi_write_com(spi, 0xF000);     spi_write_dat(spi, 0x55);
78         spi_write_com(spi, 0xF001);     spi_write_dat(spi, 0xAA);
79         spi_write_com(spi, 0xF002);     spi_write_dat(spi, 0x52);
80         spi_write_com(spi, 0xF003);     spi_write_dat(spi, 0x08);
81         spi_write_com(spi, 0xF004);     spi_write_dat(spi, 0x01);
82
83         /* AVDD Set AVDD 5.2V */
84         spi_write_com(spi, 0xB000);     spi_write_dat(spi, 0x0D);
85         spi_write_com(spi, 0xB001);     spi_write_dat(spi, 0x0D);
86         spi_write_com(spi, 0xB002);     spi_write_dat(spi, 0x0D);
87
88         /* AVDD ratio */
89         spi_write_com(spi, 0xB600);     spi_write_dat(spi, 0x34);
90         spi_write_com(spi, 0xB601);     spi_write_dat(spi, 0x34);
91         spi_write_com(spi, 0xB602);     spi_write_dat(spi, 0x34);
92
93         /* AVEE  -5.2V */
94         spi_write_com(spi, 0xB100);     spi_write_dat(spi, 0x0D);
95         spi_write_com(spi, 0xB101);     spi_write_dat(spi, 0x0D);
96         spi_write_com(spi, 0xB102);     spi_write_dat(spi, 0x0D);
97
98         /* AVEE ratio */
99         spi_write_com(spi, 0xB700);     spi_write_dat(spi, 0x35);
100         spi_write_com(spi, 0xB701);     spi_write_dat(spi, 0x35);
101         spi_write_com(spi, 0xB702);     spi_write_dat(spi, 0x35);
102
103         /* VCL  -2.5V */
104         spi_write_com(spi, 0xB200);     spi_write_dat(spi, 0x00);
105         spi_write_com(spi, 0xB201);     spi_write_dat(spi, 0x00);
106         spi_write_com(spi, 0xB202);     spi_write_dat(spi, 0x00);
107
108         /* VCL ratio */
109         spi_write_com(spi, 0xB800);     spi_write_dat(spi, 0x24);
110         spi_write_com(spi, 0xB801);     spi_write_dat(spi, 0x24);
111         spi_write_com(spi, 0xB802);     spi_write_dat(spi, 0x24);
112
113         /* VGH 15V */
114         spi_write_com(spi, 0xBF00);     spi_write_dat(spi, 0x01);
115         spi_write_com(spi, 0xB300);     spi_write_dat(spi, 0x08);
116         spi_write_com(spi, 0xB301);     spi_write_dat(spi, 0x08);
117         spi_write_com(spi, 0xB302);     spi_write_dat(spi, 0x08);
118
119         /* VGH ratio */
120         spi_write_com(spi, 0xB900);     spi_write_dat(spi, 0x34);
121         spi_write_com(spi, 0xB901);     spi_write_dat(spi, 0x34);
122         spi_write_com(spi, 0xB902);     spi_write_dat(spi, 0x34);
123
124         /* VGLX ratio */
125         spi_write_com(spi, 0xBA00);     spi_write_dat(spi, 0x24);
126         spi_write_com(spi, 0xBA01);     spi_write_dat(spi, 0x24);
127         spi_write_com(spi, 0xBA02);     spi_write_dat(spi, 0x24);
128
129         /* VGMP/VGSP 4.7V/0V */
130         spi_write_com(spi, 0xBC00);     spi_write_dat(spi, 0x00);
131         spi_write_com(spi, 0xBC01);     spi_write_dat(spi, 0x88);
132         spi_write_com(spi, 0xBC02);     spi_write_dat(spi, 0x00);
133
134         /* VGMN/VGSN -4.7V/0V */
135         spi_write_com(spi, 0xBD00);     spi_write_dat(spi, 0x00);
136         spi_write_com(spi, 0xBD01);     spi_write_dat(spi, 0x88);
137         spi_write_com(spi, 0xBD02);     spi_write_dat(spi, 0x00);
138
139         /* VCOM 1.525V */
140         spi_write_com(spi, 0xBE00);     spi_write_dat(spi, 0x00);
141         spi_write_com(spi, 0xBE01);     spi_write_dat(spi, 0x7A);
142
143         /* Gamma Setting */
144         spi_write_com(spi, 0xD100);     spi_write_dat(spi, 0x00);
145         spi_write_com(spi, 0xD101);     spi_write_dat(spi, 0x05);
146         spi_write_com(spi, 0xD102);     spi_write_dat(spi, 0x00);
147         spi_write_com(spi, 0xD103);     spi_write_dat(spi, 0x15);
148         spi_write_com(spi, 0xD104);     spi_write_dat(spi, 0x00);
149         spi_write_com(spi, 0xD105);     spi_write_dat(spi, 0x30);
150         spi_write_com(spi, 0xD106);     spi_write_dat(spi, 0x00);
151         spi_write_com(spi, 0xD107);     spi_write_dat(spi, 0x47);
152         spi_write_com(spi, 0xD108);     spi_write_dat(spi, 0x00);
153         spi_write_com(spi, 0xD109);     spi_write_dat(spi, 0x5B);
154         spi_write_com(spi, 0xD10A);     spi_write_dat(spi, 0x00);
155         spi_write_com(spi, 0xD10B);     spi_write_dat(spi, 0x7D);
156         spi_write_com(spi, 0xD10C);     spi_write_dat(spi, 0x00);
157         spi_write_com(spi, 0xD10D);     spi_write_dat(spi, 0x9D);
158         spi_write_com(spi, 0xD10E);     spi_write_dat(spi, 0x00);
159         spi_write_com(spi, 0xD10F);     spi_write_dat(spi, 0xCC);
160         spi_write_com(spi, 0xD110);     spi_write_dat(spi, 0x00);
161         spi_write_com(spi, 0xD111);     spi_write_dat(spi, 0xF3);
162         spi_write_com(spi, 0xD112);     spi_write_dat(spi, 0x01);
163         spi_write_com(spi, 0xD113);     spi_write_dat(spi, 0x32);
164         spi_write_com(spi, 0xD114);     spi_write_dat(spi, 0x01);
165         spi_write_com(spi, 0xD115);     spi_write_dat(spi, 0x63);
166         spi_write_com(spi, 0xD116);     spi_write_dat(spi, 0x01);
167         spi_write_com(spi, 0xD117);     spi_write_dat(spi, 0xB1);
168         spi_write_com(spi, 0xD118);     spi_write_dat(spi, 0x01);
169         spi_write_com(spi, 0xD119);     spi_write_dat(spi, 0xF0);
170         spi_write_com(spi, 0xD11A);     spi_write_dat(spi, 0x01);
171         spi_write_com(spi, 0xD11B);     spi_write_dat(spi, 0xF2);
172         spi_write_com(spi, 0xD11C);     spi_write_dat(spi, 0x02);
173         spi_write_com(spi, 0xD11D);     spi_write_dat(spi, 0x2A);
174         spi_write_com(spi, 0xD11E);     spi_write_dat(spi, 0x02);
175         spi_write_com(spi, 0xD11F);     spi_write_dat(spi, 0x67);
176         spi_write_com(spi, 0xD120);     spi_write_dat(spi, 0x02);
177         spi_write_com(spi, 0xD121);     spi_write_dat(spi, 0x90);
178         spi_write_com(spi, 0xD122);     spi_write_dat(spi, 0x02);
179         spi_write_com(spi, 0xD123);     spi_write_dat(spi, 0xCB);
180         spi_write_com(spi, 0xD124);     spi_write_dat(spi, 0x02);
181         spi_write_com(spi, 0xD125);     spi_write_dat(spi, 0xF2);
182         spi_write_com(spi, 0xD126);     spi_write_dat(spi, 0x03);
183         spi_write_com(spi, 0xD127);     spi_write_dat(spi, 0x2A);
184         spi_write_com(spi, 0xD128);     spi_write_dat(spi, 0x03);
185         spi_write_com(spi, 0xD129);     spi_write_dat(spi, 0x51);
186         spi_write_com(spi, 0xD12A);     spi_write_dat(spi, 0x03);
187         spi_write_com(spi, 0xD12B);     spi_write_dat(spi, 0x80);
188         spi_write_com(spi, 0xD12C);     spi_write_dat(spi, 0x03);
189         spi_write_com(spi, 0xD12D);     spi_write_dat(spi, 0x9F);
190         spi_write_com(spi, 0xD12E);     spi_write_dat(spi, 0x03);
191         spi_write_com(spi, 0xD12F);     spi_write_dat(spi, 0xBE);
192         spi_write_com(spi, 0xD130);     spi_write_dat(spi, 0x03);
193         spi_write_com(spi, 0xD131);     spi_write_dat(spi, 0xF9);
194         spi_write_com(spi, 0xD132);     spi_write_dat(spi, 0x03);
195         spi_write_com(spi, 0xD133);     spi_write_dat(spi, 0xFF);
196
197         spi_write_com(spi, 0xD200);     spi_write_dat(spi, 0x00);
198         spi_write_com(spi, 0xD201);     spi_write_dat(spi, 0x05);
199         spi_write_com(spi, 0xD202);     spi_write_dat(spi, 0x00);
200         spi_write_com(spi, 0xD203);     spi_write_dat(spi, 0x15);
201         spi_write_com(spi, 0xD204);     spi_write_dat(spi, 0x00);
202         spi_write_com(spi, 0xD205);     spi_write_dat(spi, 0x30);
203         spi_write_com(spi, 0xD206);     spi_write_dat(spi, 0x00);
204         spi_write_com(spi, 0xD207);     spi_write_dat(spi, 0x47);
205         spi_write_com(spi, 0xD208);     spi_write_dat(spi, 0x00);
206         spi_write_com(spi, 0xD209);     spi_write_dat(spi, 0x5B);
207         spi_write_com(spi, 0xD20A);     spi_write_dat(spi, 0x00);
208         spi_write_com(spi, 0xD20B);     spi_write_dat(spi, 0x7D);
209         spi_write_com(spi, 0xD20C);     spi_write_dat(spi, 0x00);
210         spi_write_com(spi, 0xD20D);     spi_write_dat(spi, 0x9D);
211         spi_write_com(spi, 0xD20E);     spi_write_dat(spi, 0x00);
212         spi_write_com(spi, 0xD20F);     spi_write_dat(spi, 0xCC);
213         spi_write_com(spi, 0xD210);     spi_write_dat(spi, 0x00);
214         spi_write_com(spi, 0xD211);     spi_write_dat(spi, 0xF3);
215         spi_write_com(spi, 0xD212);     spi_write_dat(spi, 0x01);
216         spi_write_com(spi, 0xD213);     spi_write_dat(spi, 0x32);
217         spi_write_com(spi, 0xD214);     spi_write_dat(spi, 0x01);
218         spi_write_com(spi, 0xD215);     spi_write_dat(spi, 0x63);
219         spi_write_com(spi, 0xD216);     spi_write_dat(spi, 0x01);
220         spi_write_com(spi, 0xD217);     spi_write_dat(spi, 0xB1);
221         spi_write_com(spi, 0xD218);     spi_write_dat(spi, 0x01);
222         spi_write_com(spi, 0xD219);     spi_write_dat(spi, 0xF0);
223         spi_write_com(spi, 0xD21A);     spi_write_dat(spi, 0x01);
224         spi_write_com(spi, 0xD21B);     spi_write_dat(spi, 0xF2);
225         spi_write_com(spi, 0xD21C);     spi_write_dat(spi, 0x02);
226         spi_write_com(spi, 0xD21D);     spi_write_dat(spi, 0x2A);
227         spi_write_com(spi, 0xD21E);     spi_write_dat(spi, 0x02);
228         spi_write_com(spi, 0xD21F);     spi_write_dat(spi, 0x67);
229         spi_write_com(spi, 0xD220);     spi_write_dat(spi, 0x02);
230         spi_write_com(spi, 0xD221);     spi_write_dat(spi, 0x90);
231         spi_write_com(spi, 0xD222);     spi_write_dat(spi, 0x02);
232         spi_write_com(spi, 0xD223);     spi_write_dat(spi, 0xCB);
233         spi_write_com(spi, 0xD224);     spi_write_dat(spi, 0x02);
234         spi_write_com(spi, 0xD225);     spi_write_dat(spi, 0xF2);
235         spi_write_com(spi, 0xD226);     spi_write_dat(spi, 0x03);
236         spi_write_com(spi, 0xD227);     spi_write_dat(spi, 0x2A);
237         spi_write_com(spi, 0xD228);     spi_write_dat(spi, 0x03);
238         spi_write_com(spi, 0xD229);     spi_write_dat(spi, 0x51);
239         spi_write_com(spi, 0xD22A);     spi_write_dat(spi, 0x03);
240         spi_write_com(spi, 0xD22B);     spi_write_dat(spi, 0x80);
241         spi_write_com(spi, 0xD22C);     spi_write_dat(spi, 0x03);
242         spi_write_com(spi, 0xD22D);     spi_write_dat(spi, 0x9F);
243         spi_write_com(spi, 0xD22E);     spi_write_dat(spi, 0x03);
244         spi_write_com(spi, 0xD22F);     spi_write_dat(spi, 0xBE);
245         spi_write_com(spi, 0xD230);     spi_write_dat(spi, 0x03);
246         spi_write_com(spi, 0xD231);     spi_write_dat(spi, 0xF9);
247         spi_write_com(spi, 0xD232);     spi_write_dat(spi, 0x03);
248         spi_write_com(spi, 0xD233);     spi_write_dat(spi, 0xFF);
249
250         spi_write_com(spi, 0xD300);     spi_write_dat(spi, 0x00);
251         spi_write_com(spi, 0xD301);     spi_write_dat(spi, 0x05);
252         spi_write_com(spi, 0xD302);     spi_write_dat(spi, 0x00);
253         spi_write_com(spi, 0xD303);     spi_write_dat(spi, 0x15);
254         spi_write_com(spi, 0xD304);     spi_write_dat(spi, 0x00);
255         spi_write_com(spi, 0xD305);     spi_write_dat(spi, 0x30);
256         spi_write_com(spi, 0xD306);     spi_write_dat(spi, 0x00);
257         spi_write_com(spi, 0xD307);     spi_write_dat(spi, 0x47);
258         spi_write_com(spi, 0xD308);     spi_write_dat(spi, 0x00);
259         spi_write_com(spi, 0xD309);     spi_write_dat(spi, 0x5B);
260         spi_write_com(spi, 0xD30A);     spi_write_dat(spi, 0x00);
261         spi_write_com(spi, 0xD30B);     spi_write_dat(spi, 0x7D);
262         spi_write_com(spi, 0xD30C);     spi_write_dat(spi, 0x00);
263         spi_write_com(spi, 0xD30D);     spi_write_dat(spi, 0x9D);
264         spi_write_com(spi, 0xD30E);     spi_write_dat(spi, 0x00);
265         spi_write_com(spi, 0xD30F);     spi_write_dat(spi, 0xCC);
266         spi_write_com(spi, 0xD310);     spi_write_dat(spi, 0x00);
267         spi_write_com(spi, 0xD311);     spi_write_dat(spi, 0xF3);
268         spi_write_com(spi, 0xD312);     spi_write_dat(spi, 0x01);
269         spi_write_com(spi, 0xD313);     spi_write_dat(spi, 0x32);
270         spi_write_com(spi, 0xD314);     spi_write_dat(spi, 0x01);
271         spi_write_com(spi, 0xD315);     spi_write_dat(spi, 0x63);
272         spi_write_com(spi, 0xD316);     spi_write_dat(spi, 0x01);
273         spi_write_com(spi, 0xD317);     spi_write_dat(spi, 0xB1);
274         spi_write_com(spi, 0xD318);     spi_write_dat(spi, 0x01);
275         spi_write_com(spi, 0xD319);     spi_write_dat(spi, 0xF0);
276         spi_write_com(spi, 0xD31A);     spi_write_dat(spi, 0x01);
277         spi_write_com(spi, 0xD31B);     spi_write_dat(spi, 0xF2);
278         spi_write_com(spi, 0xD31C);     spi_write_dat(spi, 0x02);
279         spi_write_com(spi, 0xD31D);     spi_write_dat(spi, 0x2A);
280         spi_write_com(spi, 0xD31E);     spi_write_dat(spi, 0x02);
281         spi_write_com(spi, 0xD31F);     spi_write_dat(spi, 0x67);
282         spi_write_com(spi, 0xD320);     spi_write_dat(spi, 0x02);
283         spi_write_com(spi, 0xD321);     spi_write_dat(spi, 0x90);
284         spi_write_com(spi, 0xD322);     spi_write_dat(spi, 0x02);
285         spi_write_com(spi, 0xD323);     spi_write_dat(spi, 0xCB);
286         spi_write_com(spi, 0xD324);     spi_write_dat(spi, 0x02);
287         spi_write_com(spi, 0xD325);     spi_write_dat(spi, 0xF2);
288         spi_write_com(spi, 0xD326);     spi_write_dat(spi, 0x03);
289         spi_write_com(spi, 0xD327);     spi_write_dat(spi, 0x2A);
290         spi_write_com(spi, 0xD328);     spi_write_dat(spi, 0x03);
291         spi_write_com(spi, 0xD329);     spi_write_dat(spi, 0x51);
292         spi_write_com(spi, 0xD32A);     spi_write_dat(spi, 0x03);
293         spi_write_com(spi, 0xD32B);     spi_write_dat(spi, 0x80);
294         spi_write_com(spi, 0xD32C);     spi_write_dat(spi, 0x03);
295         spi_write_com(spi, 0xD32D);     spi_write_dat(spi, 0x9F);
296         spi_write_com(spi, 0xD32E);     spi_write_dat(spi, 0x03);
297         spi_write_com(spi, 0xD32F);     spi_write_dat(spi, 0xBE);
298         spi_write_com(spi, 0xD330);     spi_write_dat(spi, 0x03);
299         spi_write_com(spi, 0xD331);     spi_write_dat(spi, 0xF9);
300         spi_write_com(spi, 0xD332);     spi_write_dat(spi, 0x03);
301         spi_write_com(spi, 0xD333);     spi_write_dat(spi, 0xFF);
302
303         spi_write_com(spi, 0xD400);     spi_write_dat(spi, 0x00);
304         spi_write_com(spi, 0xD401);     spi_write_dat(spi, 0x05);
305         spi_write_com(spi, 0xD402);     spi_write_dat(spi, 0x00);
306         spi_write_com(spi, 0xD403);     spi_write_dat(spi, 0x15);
307         spi_write_com(spi, 0xD404);     spi_write_dat(spi, 0x00);
308         spi_write_com(spi, 0xD405);     spi_write_dat(spi, 0x30);
309         spi_write_com(spi, 0xD406);     spi_write_dat(spi, 0x00);
310         spi_write_com(spi, 0xD407);     spi_write_dat(spi, 0x47);
311         spi_write_com(spi, 0xD408);     spi_write_dat(spi, 0x00);
312         spi_write_com(spi, 0xD409);     spi_write_dat(spi, 0x5B);
313         spi_write_com(spi, 0xD40A);     spi_write_dat(spi, 0x00);
314         spi_write_com(spi, 0xD40B);     spi_write_dat(spi, 0x7D);
315         spi_write_com(spi, 0xD40C);     spi_write_dat(spi, 0x00);
316         spi_write_com(spi, 0xD40D);     spi_write_dat(spi, 0x9D);
317         spi_write_com(spi, 0xD40E);     spi_write_dat(spi, 0x00);
318         spi_write_com(spi, 0xD40F);     spi_write_dat(spi, 0xCC);
319         spi_write_com(spi, 0xD410);     spi_write_dat(spi, 0x00);
320         spi_write_com(spi, 0xD411);     spi_write_dat(spi, 0xF3);
321         spi_write_com(spi, 0xD412);     spi_write_dat(spi, 0x01);
322         spi_write_com(spi, 0xD413);     spi_write_dat(spi, 0x32);
323         spi_write_com(spi, 0xD414);     spi_write_dat(spi, 0x01);
324         spi_write_com(spi, 0xD415);     spi_write_dat(spi, 0x63);
325         spi_write_com(spi, 0xD416);     spi_write_dat(spi, 0x01);
326         spi_write_com(spi, 0xD417);     spi_write_dat(spi, 0xB1);
327         spi_write_com(spi, 0xD418);     spi_write_dat(spi, 0x01);
328         spi_write_com(spi, 0xD419);     spi_write_dat(spi, 0xF0);
329         spi_write_com(spi, 0xD41A);     spi_write_dat(spi, 0x01);
330         spi_write_com(spi, 0xD41B);     spi_write_dat(spi, 0xF2);
331         spi_write_com(spi, 0xD41C);     spi_write_dat(spi, 0x02);
332         spi_write_com(spi, 0xD41D);     spi_write_dat(spi, 0x2A);
333         spi_write_com(spi, 0xD41E);     spi_write_dat(spi, 0x02);
334         spi_write_com(spi, 0xD41F);     spi_write_dat(spi, 0x67);
335         spi_write_com(spi, 0xD420);     spi_write_dat(spi, 0x02);
336         spi_write_com(spi, 0xD421);     spi_write_dat(spi, 0x90);
337         spi_write_com(spi, 0xD422);     spi_write_dat(spi, 0x02);
338         spi_write_com(spi, 0xD423);     spi_write_dat(spi, 0xCB);
339         spi_write_com(spi, 0xD424);     spi_write_dat(spi, 0x02);
340         spi_write_com(spi, 0xD425);     spi_write_dat(spi, 0xF2);
341         spi_write_com(spi, 0xD426);     spi_write_dat(spi, 0x03);
342         spi_write_com(spi, 0xD427);     spi_write_dat(spi, 0x2A);
343         spi_write_com(spi, 0xD428);     spi_write_dat(spi, 0x03);
344         spi_write_com(spi, 0xD429);     spi_write_dat(spi, 0x51);
345         spi_write_com(spi, 0xD42A);     spi_write_dat(spi, 0x03);
346         spi_write_com(spi, 0xD42B);     spi_write_dat(spi, 0x80);
347         spi_write_com(spi, 0xD42C);     spi_write_dat(spi, 0x03);
348         spi_write_com(spi, 0xD42D);     spi_write_dat(spi, 0x9F);
349         spi_write_com(spi, 0xD42E);     spi_write_dat(spi, 0x03);
350         spi_write_com(spi, 0xD42F);     spi_write_dat(spi, 0xBE);
351         spi_write_com(spi, 0xD430);     spi_write_dat(spi, 0x03);
352         spi_write_com(spi, 0xD431);     spi_write_dat(spi, 0xF9);
353         spi_write_com(spi, 0xD432);     spi_write_dat(spi, 0x03);
354         spi_write_com(spi, 0xD433);     spi_write_dat(spi, 0xFF);
355
356         spi_write_com(spi, 0xD500);     spi_write_dat(spi, 0x00);
357         spi_write_com(spi, 0xD501);     spi_write_dat(spi, 0x05);
358         spi_write_com(spi, 0xD502);     spi_write_dat(spi, 0x00);
359         spi_write_com(spi, 0xD503);     spi_write_dat(spi, 0x15);
360         spi_write_com(spi, 0xD504);     spi_write_dat(spi, 0x00);
361         spi_write_com(spi, 0xD505);     spi_write_dat(spi, 0x30);
362         spi_write_com(spi, 0xD506);     spi_write_dat(spi, 0x00);
363         spi_write_com(spi, 0xD507);     spi_write_dat(spi, 0x47);
364         spi_write_com(spi, 0xD508);     spi_write_dat(spi, 0x00);
365         spi_write_com(spi, 0xD509);     spi_write_dat(spi, 0x5B);
366         spi_write_com(spi, 0xD50A);     spi_write_dat(spi, 0x00);
367         spi_write_com(spi, 0xD50B);     spi_write_dat(spi, 0x7D);
368         spi_write_com(spi, 0xD50C);     spi_write_dat(spi, 0x00);
369         spi_write_com(spi, 0xD50D);     spi_write_dat(spi, 0x9D);
370         spi_write_com(spi, 0xD50E);     spi_write_dat(spi, 0x00);
371         spi_write_com(spi, 0xD50F);     spi_write_dat(spi, 0xCC);
372         spi_write_com(spi, 0xD510);     spi_write_dat(spi, 0x00);
373         spi_write_com(spi, 0xD511);     spi_write_dat(spi, 0xF3);
374         spi_write_com(spi, 0xD512);     spi_write_dat(spi, 0x01);
375         spi_write_com(spi, 0xD513);     spi_write_dat(spi, 0x32);
376         spi_write_com(spi, 0xD514);     spi_write_dat(spi, 0x01);
377         spi_write_com(spi, 0xD515);     spi_write_dat(spi, 0x63);
378         spi_write_com(spi, 0xD516);     spi_write_dat(spi, 0x01);
379         spi_write_com(spi, 0xD517);     spi_write_dat(spi, 0xB1);
380         spi_write_com(spi, 0xD518);     spi_write_dat(spi, 0x01);
381         spi_write_com(spi, 0xD519);     spi_write_dat(spi, 0xF0);
382         spi_write_com(spi, 0xD51A);     spi_write_dat(spi, 0x01);
383         spi_write_com(spi, 0xD51B);     spi_write_dat(spi, 0xF2);
384         spi_write_com(spi, 0xD51C);     spi_write_dat(spi, 0x02);
385         spi_write_com(spi, 0xD51D);     spi_write_dat(spi, 0x2A);
386         spi_write_com(spi, 0xD51E);     spi_write_dat(spi, 0x02);
387         spi_write_com(spi, 0xD51F);     spi_write_dat(spi, 0x67);
388         spi_write_com(spi, 0xD520);     spi_write_dat(spi, 0x02);
389         spi_write_com(spi, 0xD521);     spi_write_dat(spi, 0x90);
390         spi_write_com(spi, 0xD522);     spi_write_dat(spi, 0x02);
391         spi_write_com(spi, 0xD523);     spi_write_dat(spi, 0xCB);
392         spi_write_com(spi, 0xD524);     spi_write_dat(spi, 0x02);
393         spi_write_com(spi, 0xD525);     spi_write_dat(spi, 0xF2);
394         spi_write_com(spi, 0xD526);     spi_write_dat(spi, 0x03);
395         spi_write_com(spi, 0xD527);     spi_write_dat(spi, 0x2A);
396         spi_write_com(spi, 0xD528);     spi_write_dat(spi, 0x03);
397         spi_write_com(spi, 0xD529);     spi_write_dat(spi, 0x51);
398         spi_write_com(spi, 0xD52A);     spi_write_dat(spi, 0x03);
399         spi_write_com(spi, 0xD52B);     spi_write_dat(spi, 0x80);
400         spi_write_com(spi, 0xD52C);     spi_write_dat(spi, 0x03);
401         spi_write_com(spi, 0xD52D);     spi_write_dat(spi, 0x9F);
402         spi_write_com(spi, 0xD52E);     spi_write_dat(spi, 0x03);
403         spi_write_com(spi, 0xD52F);     spi_write_dat(spi, 0xBE);
404         spi_write_com(spi, 0xD530);     spi_write_dat(spi, 0x03);
405         spi_write_com(spi, 0xD531);     spi_write_dat(spi, 0xF9);
406         spi_write_com(spi, 0xD532);     spi_write_dat(spi, 0x03);
407         spi_write_com(spi, 0xD533);     spi_write_dat(spi, 0xFF);
408
409         spi_write_com(spi, 0xD600);     spi_write_dat(spi, 0x00);
410         spi_write_com(spi, 0xD601);     spi_write_dat(spi, 0x05);
411         spi_write_com(spi, 0xD602);     spi_write_dat(spi, 0x00);
412         spi_write_com(spi, 0xD603);     spi_write_dat(spi, 0x15);
413         spi_write_com(spi, 0xD604);     spi_write_dat(spi, 0x00);
414         spi_write_com(spi, 0xD605);     spi_write_dat(spi, 0x30);
415         spi_write_com(spi, 0xD606);     spi_write_dat(spi, 0x00);
416         spi_write_com(spi, 0xD607);     spi_write_dat(spi, 0x47);
417         spi_write_com(spi, 0xD608);     spi_write_dat(spi, 0x00);
418         spi_write_com(spi, 0xD609);     spi_write_dat(spi, 0x5B);
419         spi_write_com(spi, 0xD60A);     spi_write_dat(spi, 0x00);
420         spi_write_com(spi, 0xD60B);     spi_write_dat(spi, 0x7D);
421         spi_write_com(spi, 0xD60C);     spi_write_dat(spi, 0x00);
422         spi_write_com(spi, 0xD60D);     spi_write_dat(spi, 0x9D);
423         spi_write_com(spi, 0xD60E);     spi_write_dat(spi, 0x00);
424         spi_write_com(spi, 0xD60F);     spi_write_dat(spi, 0xCC);
425         spi_write_com(spi, 0xD610);     spi_write_dat(spi, 0x00);
426         spi_write_com(spi, 0xD611);     spi_write_dat(spi, 0xF3);
427         spi_write_com(spi, 0xD612);     spi_write_dat(spi, 0x01);
428         spi_write_com(spi, 0xD613);     spi_write_dat(spi, 0x32);
429         spi_write_com(spi, 0xD614);     spi_write_dat(spi, 0x01);
430         spi_write_com(spi, 0xD615);     spi_write_dat(spi, 0x63);
431         spi_write_com(spi, 0xD616);     spi_write_dat(spi, 0x01);
432         spi_write_com(spi, 0xD617);     spi_write_dat(spi, 0xB1);
433         spi_write_com(spi, 0xD618);     spi_write_dat(spi, 0x01);
434         spi_write_com(spi, 0xD619);     spi_write_dat(spi, 0xF0);
435         spi_write_com(spi, 0xD61A);     spi_write_dat(spi, 0x01);
436         spi_write_com(spi, 0xD61B);     spi_write_dat(spi, 0xF2);
437         spi_write_com(spi, 0xD61C);     spi_write_dat(spi, 0x02);
438         spi_write_com(spi, 0xD61D);     spi_write_dat(spi, 0x2A);
439         spi_write_com(spi, 0xD61E);     spi_write_dat(spi, 0x02);
440         spi_write_com(spi, 0xD61F);     spi_write_dat(spi, 0x67);
441         spi_write_com(spi, 0xD620);     spi_write_dat(spi, 0x02);
442         spi_write_com(spi, 0xD621);     spi_write_dat(spi, 0x90);
443         spi_write_com(spi, 0xD622);     spi_write_dat(spi, 0x02);
444         spi_write_com(spi, 0xD623);     spi_write_dat(spi, 0xCB);
445         spi_write_com(spi, 0xD624);     spi_write_dat(spi, 0x02);
446         spi_write_com(spi, 0xD625);     spi_write_dat(spi, 0xF2);
447         spi_write_com(spi, 0xD626);     spi_write_dat(spi, 0x03);
448         spi_write_com(spi, 0xD627);     spi_write_dat(spi, 0x2A);
449         spi_write_com(spi, 0xD628);     spi_write_dat(spi, 0x03);
450         spi_write_com(spi, 0xD629);     spi_write_dat(spi, 0x51);
451         spi_write_com(spi, 0xD62A);     spi_write_dat(spi, 0x03);
452         spi_write_com(spi, 0xD62B);     spi_write_dat(spi, 0x80);
453         spi_write_com(spi, 0xD62C);     spi_write_dat(spi, 0x03);
454         spi_write_com(spi, 0xD62D);     spi_write_dat(spi, 0x9F);
455         spi_write_com(spi, 0xD62E);     spi_write_dat(spi, 0x03);
456         spi_write_com(spi, 0xD62F);     spi_write_dat(spi, 0xBE);
457         spi_write_com(spi, 0xD630);     spi_write_dat(spi, 0x03);
458         spi_write_com(spi, 0xD631);     spi_write_dat(spi, 0xF9);
459         spi_write_com(spi, 0xD632);     spi_write_dat(spi, 0x03);
460         spi_write_com(spi, 0xD633);     spi_write_dat(spi, 0xFF);
461
462         /* LV2 Page 0 enable */
463         spi_write_com(spi, 0xF000);     spi_write_dat(spi, 0x55);
464         spi_write_com(spi, 0xF001);     spi_write_dat(spi, 0xAA);
465         spi_write_com(spi, 0xF002);     spi_write_dat(spi, 0x52);
466         spi_write_com(spi, 0xF003);     spi_write_dat(spi, 0x08);
467         spi_write_com(spi, 0xF004);     spi_write_dat(spi, 0x00);
468
469         /* Display control */
470         spi_write_com(spi, 0xB100);     spi_write_dat(spi, 0xFC);
471         spi_write_com(spi, 0xB101);     spi_write_dat(spi, 0x00);
472
473         /* Source hold time */
474         spi_write_com(spi, 0xB600);     spi_write_dat(spi, 0x05);
475
476         /* Gate EQ control */
477         spi_write_com(spi, 0xB700);     spi_write_dat(spi, 0x70);
478         spi_write_com(spi, 0xB701);     spi_write_dat(spi, 0x70);
479
480         /* Source EQ control (Mode 2) */
481         spi_write_com(spi, 0xB800);     spi_write_dat(spi, 0x01);
482         spi_write_com(spi, 0xB801);     spi_write_dat(spi, 0x05);
483         spi_write_com(spi, 0xB802);     spi_write_dat(spi, 0x05);
484         spi_write_com(spi, 0xB803);     spi_write_dat(spi, 0x05);
485
486         /* Inversion mode  (Column) */
487         spi_write_com(spi, 0xBC00);     spi_write_dat(spi, 0x00);
488         spi_write_com(spi, 0xBC01);     spi_write_dat(spi, 0x00);
489         spi_write_com(spi, 0xBC02);     spi_write_dat(spi, 0x00);
490
491         /* Timing control 8phase dual side/4H/4delay/RST_EN */
492         spi_write_com(spi, 0xC900);     spi_write_dat(spi, 0xD0);
493         spi_write_com(spi, 0xC901);     spi_write_dat(spi, 0x82);
494         spi_write_com(spi, 0xC902);     spi_write_dat(spi, 0x50);
495         spi_write_com(spi, 0xC903);     spi_write_dat(spi, 0x50);
496         spi_write_com(spi, 0xC904);     spi_write_dat(spi, 0x50);
497
498         spi_write_com(spi, 0x3A00);     spi_write_dat(spi, 0x55);
499         mdelay(120);
500         spi_write_com(spi, 0x1100);
501         mdelay(120);
502         spi_write_com(spi, 0x2900);
503         mdelay(120);
504         /* spi_write_com(spi, 0x2100);  spi_write_dat(spi, 0x00); */
505         spi_write_com(spi, 0x2C00);
506
507         return 0;
508 err_claim_bus:
509         spi_free_slave(spi);
510         return -1;
511 }