tizen 2.4 release
[profile/mobile/platform/kernel/u-boot-tm1.git] / drivers / video / sprdfb / lcd / lcd_ili9486s1_mipi.c
1 \r
2 #include <config.h>\r
3 #include <common.h>//huyue added \r
4 #include <asm/arch/sprd_lcd.h>\r
5 #include "../sprdfb.h"\r
6 #define printk printf\r
7 \r
8 #define  LCD_DEBUG\r
9 #ifdef LCD_DEBUG\r
10 #define LCD_PRINT printk\r
11 #else\r
12 #define LCD_PRINT(...)\r
13 #endif\r
14 \r
15 #define MAX_DATA   100\r
16 \r
17 typedef struct LCM_Init_Code_tag {\r
18         unsigned int tag;\r
19         unsigned char data[MAX_DATA];\r
20 }LCM_Init_Code;\r
21 \r
22 typedef struct LCM_force_cmd_code_tag{\r
23         unsigned int datatype;\r
24         LCM_Init_Code real_cmd_code;\r
25 }LCM_Force_Cmd_Code;\r
26 \r
27 #define LCM_TAG_SHIFT 24\r
28 #define LCM_TAG_MASK  ((1 << 24) -1)\r
29 #define LCM_SEND(len) ((1 << LCM_TAG_SHIFT)| len)\r
30 #define LCM_SLEEP(ms) ((2 << LCM_TAG_SHIFT)| ms)\r
31 //#define ARRAY_SIZE(array) ( sizeof(array) / sizeof(array[0]))\r
32 \r
33 #define LCM_TAG_SEND  (1<< 0)\r
34 #define LCM_TAG_SLEEP (1 << 1)\r
35 \r
36 static LCM_Init_Code init_data[] = {\r
37         //Power setting Sequence\r
38         {LCM_SEND(5),{3,0,0xC0,0x0A,0x0A}},\r
39         {LCM_SEND(2),{0xc1,0x45}},\r
40         {LCM_SEND(2),{0xc2, 0x00}},\r
41 \r
42         //Initializing Sequence\r
43         {LCM_SEND(7),{5,0,0x2A,0x00,0x00,0x01,0x3F}},\r
44         {LCM_SEND(7),{5,0,0x2B,0x00,0x00,0x01,0xDF}},\r
45         {LCM_SEND(2),{0x36,0xc8}},\r
46         {LCM_SEND(2),{0x3A,0x66}},\r
47         {LCM_SEND(2),{0xB0,0x8c}},\r
48         {LCM_SEND(2),{0xB4,0x02}},\r
49 \r
50         {LCM_SEND(6),{4,0,0xB6,0x32,0x22,0x3B}},\r
51         {LCM_SEND(2),{0xB7,0xC6}},\r
52         {LCM_SEND(5),{3,0,0xF9,0x00,0x08}},\r
53         {LCM_SEND(7),{5,0,0xF7,0xA9,0x91,0x2D,0x8A}},\r
54         {LCM_SEND(6),{4,0,0xF8,0x21,0x07,0x02}},\r
55         {LCM_SEND(11),{9,0,0xF1,0x36,0x04,0x00,0x3C,0x0F,0x0F,0x04,0x02}},\r
56         {LCM_SEND(12),{10,0,0xF2,0x18,0xA3,0x12,0x02,0xB2,0x12,0xFF,0x10,0x00}},\r
57         {LCM_SEND(6),{4,0,0xFC,0x00,0x0C,0x80}},\r
58         //gamma setting\r
59         {LCM_SEND(18),{16,0,0xE0,0x01,0x15,0x17,0x0C,0x0F,0x07,0x44,0x65,0x35,0x07,0x12,0x04,0x09,0x06,0x06}},\r
60         {LCM_SEND(18),{16,0,0xE1,0x0F,0x38,0x34,0x0B,0x0B,0x03,0x43,0x22,0x30,0x03,0x0E,0x03,0x21,0x1B,0x00}},\r
61         // 3Gamma Setting Sequence\r
62         {LCM_SEND(19),{17,0,0xE2,0x00,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x09,0x00}},\r
63         {LCM_SEND(67),{65,0,0xE3,0x00,0x00,0x00,0x00,\r
64         0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,\r
65         0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,\r
66         0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,\r
67         0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,\r
68         0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,\r
69         0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x04,0x00}},\r
70 \r
71         //Display on\r
72         {LCM_SEND(1),{0x11}},\r
73         {LCM_SLEEP(120)},\r
74         {LCM_SEND(1),{0x29}},\r
75         {LCM_SLEEP(100)},\r
76 };\r
77 \r
78 static LCM_Init_Code disp_on[] =  {\r
79         {LCM_SEND(1),{0x11}},\r
80         {LCM_SLEEP(120)},\r
81         {LCM_SEND(1),{0x29}},\r
82         {LCM_SLEEP(100)},\r
83 };\r
84 \r
85 static LCM_Init_Code sleep_in[] =  {\r
86         {LCM_SEND(1), {0x28}},\r
87         {LCM_SLEEP(50)},        //>150ms\r
88         {LCM_SEND(1), {0x10}},\r
89         {LCM_SLEEP(120)},       //>150ms\r
90 };\r
91 \r
92 static LCM_Init_Code sleep_out[] =  {\r
93         {LCM_SEND(1), {0x11}},\r
94         {LCM_SLEEP(120)},//>120ms\r
95         {LCM_SEND(1), {0x29}},\r
96         {LCM_SLEEP(20)}, //>20ms\r
97 };\r
98 \r
99 static int32_t ili9486s1_mipi_init(struct panel_spec *self)\r
100 {\r
101 \r
102         int32_t i;\r
103         LCM_Init_Code *init = init_data;\r
104         unsigned int tag;\r
105 \r
106         mipi_set_cmd_mode_t mipi_set_cmd_mode = self->info.mipi->ops->mipi_set_cmd_mode;\r
107         mipi_dcs_write_t mipi_dcs_write = self->info.mipi->ops->mipi_dcs_write;\r
108         mipi_eotp_set_t mipi_eotp_set = self->info.mipi->ops->mipi_eotp_set;\r
109 \r
110         LCD_PRINT("ili9486s1_mipi_init\n");\r
111 \r
112         mipi_set_cmd_mode();\r
113         mipi_eotp_set(0,0);\r
114 \r
115         for(i = 0; i < ARRAY_SIZE(init_data); i++){\r
116                 tag = (init->tag >>24);\r
117                 if(tag & LCM_TAG_SEND){\r
118                         mipi_dcs_write(init->data, (init->tag & LCM_TAG_MASK));\r
119                         udelay(20);\r
120                 }else if(tag & LCM_TAG_SLEEP){\r
121                         mdelay(init->tag & LCM_TAG_MASK);//udelay((init->tag & LCM_TAG_MASK) * 1000);\r
122                 }\r
123                 init++;\r
124         }\r
125 \r
126         mipi_eotp_set(0,0);\r
127 \r
128         return 0;\r
129 }\r
130 \r
131 static LCM_Force_Cmd_Code rd_prep_code[]={\r
132                 {0x37, {LCM_SEND(2), {0x3, 0}}},\r
133 \r
134 };\r
135 \r
136 static uint32_t ili9486s1_readid(struct panel_spec *self)\r
137 {\r
138 #if 0\r
139         int32_t i = 0;\r
140         uint32 j =0;\r
141         LCM_Force_Cmd_Code * rd_prepare = rd_prep_code;\r
142         uint8_t read_data[3] = {0};\r
143 \r
144         int32_t read_rtn = 0;\r
145         unsigned int tag = 0;\r
146         mipi_set_cmd_mode_t mipi_set_cmd_mode = self->info.mipi->ops->mipi_set_cmd_mode;\r
147         mipi_force_write_t mipi_force_write = self->info.mipi->ops->mipi_force_write;\r
148         mipi_force_read_t mipi_force_read = self->info.mipi->ops->mipi_force_read;\r
149         mipi_eotp_set_t mipi_eotp_set = self->info.mipi->ops->mipi_eotp_set;\r
150 \r
151         LCD_PRINT("ili9486s1_readid!\n");\r
152 \r
153         mipi_set_cmd_mode();\r
154         mipi_eotp_set(0,0);\r
155 \r
156         for(j = 0; j < 4; j++){\r
157                 rd_prepare = rd_prep_code;\r
158                 for(i = 0; i < ARRAY_SIZE(rd_prep_code); i++){\r
159                         tag = (rd_prepare->real_cmd_code.tag >> 24);\r
160                         if(tag & LCM_TAG_SEND){\r
161                                 mipi_force_write(rd_prepare->datatype, rd_prepare->real_cmd_code.data, (rd_prepare->real_cmd_code.tag & LCM_TAG_MASK));\r
162                         }else if(tag & LCM_TAG_SLEEP){\r
163                                 mdelay((rd_prepare->real_cmd_code.tag & LCM_TAG_MASK));\r
164                         }\r
165                         rd_prepare++;\r
166                 }\r
167 \r
168                 read_rtn = mipi_force_read(0xd3, 3,(uint8_t *)read_data);\r
169                 LCD_PRINT("ili9486s1_readid, 0xd3  is 0x%x,0x%x,0x%x\n",read_data[0],read_data[1],read_data[2]);\r
170         }\r
171 \r
172         mipi_eotp_set(1,1);\r
173 #endif\r
174         return 0x8370;\r
175 }\r
176 \r
177 static struct panel_operations lcd_ili9486s1_mipi_operations = {\r
178         .panel_init = ili9486s1_mipi_init,\r
179         .panel_readid = ili9486s1_readid,\r
180 };\r
181 \r
182 static struct timing_rgb lcd_ili9486s1_mipi_timing = {\r
183         .hfp = 30,  /* unit: pixel */\r
184         .hbp = 26,\r
185         .hsync = 0,\r
186         .vfp = 12, /*unit: line*/\r
187         .vbp = 8,\r
188         .vsync = 1,\r
189 };\r
190 \r
191 \r
192 static struct info_mipi lcd_ili9486s1_mipi_info = {\r
193         .work_mode  = SPRDFB_MIPI_MODE_VIDEO,\r
194         .video_bus_width = 18, /*18,16*/\r
195         .lan_number = 1,\r
196         .phy_feq =340*1000,\r
197         .h_sync_pol = SPRDFB_POLARITY_POS,\r
198         .v_sync_pol = SPRDFB_POLARITY_POS,\r
199         .de_pol = SPRDFB_POLARITY_POS,\r
200         .te_pol = SPRDFB_POLARITY_POS,\r
201         .color_mode_pol = SPRDFB_POLARITY_NEG,\r
202         .shut_down_pol = SPRDFB_POLARITY_NEG,\r
203         .timing = &lcd_ili9486s1_mipi_timing,\r
204         .ops = NULL,\r
205 };\r
206 \r
207 struct panel_spec lcd_ili9486s1_mipi_spec = {\r
208         .width = 320,\r
209         .height = 480,\r
210         .fps = 60,\r
211         .type = LCD_MODE_DSI,\r
212         .direction = LCD_DIRECT_NORMAL,\r
213         .info = {\r
214                 .mipi = &lcd_ili9486s1_mipi_info\r
215         },\r
216         .ops = &lcd_ili9486s1_mipi_operations,\r
217 };\r
218 \r