tizen 2.4 release
[profile/mobile/platform/kernel/u-boot-tm1.git] / drivers / video / sprdfb / lcd / lcd_rm68180_mipi.c
1 /* drivers/video/sprdfb/lcd_rm68180_mipi.c
2  *
3  * Support for rm68180 mipi LCD device
4  *
5  * Copyright (C) 2010 Spreadtrum
6  *
7  */
8
9 #include <asm/arch/sprd_lcd.h>
10 #include "../sprdfb.h"
11
12 #define printk printf
13
14 //#define  LCD_DEBUG
15 #ifdef LCD_DEBUG
16 #define LCD_PRINT printk
17 #else
18 #define LCD_PRINT(...)
19 #endif
20
21 #define MAX_DATA   58
22
23 typedef struct LCM_Init_Code_tag {
24         unsigned int tag;
25         unsigned char data[MAX_DATA];
26 }LCM_Init_Code;
27
28 typedef struct LCM_force_cmd_code_tag{
29         unsigned int datatype;
30         LCM_Init_Code real_cmd_code;
31 }LCM_Force_Cmd_Code;
32 #define LCM_TAG_SHIFT 24
33 #define LCM_TAG_MASK  ((1 << 24) -1)
34 #define LCM_SEND(len) ((1 << LCM_TAG_SHIFT)| len)
35 #define LCM_SLEEP(ms) ((2 << LCM_TAG_SHIFT)| ms)
36 //#define ARRAY_SIZE(array) ( sizeof(array) / sizeof(array[0]))
37
38 #define LCM_TAG_SEND  (1<< 0)
39 #define LCM_TAG_SLEEP (1 << 1)
40
41 static LCM_Init_Code init_data[] = {
42 #if 1  //l901 shengjing  rm68180
43      {LCM_SEND(8),{6,0,0xF0,0x55,0xAA,0x52,0x08,0x01}},
44      {LCM_SEND(6),{4,0,0xB0,0x0D,0x0D,0x0D}},
45      {LCM_SEND(6),{4,0,0xB1,0x05,0x05,0x05}},
46      {LCM_SEND(6),{4,0,0xB6,0x34,0x34,0x34}},
47      {LCM_SEND(6),{4,0,0xB7,0x34,0x34,0x34}},
48      {LCM_SEND(6),{4,0,0xB8,0x24,0x24,0x24}},
49      {LCM_SEND(6),{4,0,0xB9,0x34,0x34,0x34}},
50      {LCM_SEND(6),{4,0,0xBA,0x04,0x04,0x04}},
51      {LCM_SEND(6),{4,0,0xBC,0x00,0x90,0x00}},
52      {LCM_SEND(6),{4,0,0xBD,0x00,0x90,0x00}},
53      {LCM_SEND(5),{3,0,0xBE,0x00,0x75}},
54      {LCM_SEND(2),{0xCC,0x05}},
55      {LCM_SEND(55),{53,0,0xD1,0x00,0x00,0x00,0x01,0x00,0x18,0x00,0x3B,0x00,0x60,0x00,0x9E,0x00,0xCF,0x01,0x17,0x01,0x4B,0x01,0x93,0x01,0xC6,0x02,0x10,0x02,0x48,0x02,0x49,0x02,0x79,0x02,0xAA,0x02,0xC4,0x02,0xE4,0x02,0xF8,0x03,0x10,0x03,0x20,0x03,0x36,0x03,0x46,0x03,0x5C,0x03,0x8B,0x03,0xFF}},
56      {LCM_SEND(55),{53,0,0xD2,0x00,0x00,0x00,0x01,0x00,0x18,0x00,0x3B,0x00,0x60,0x00,0x9E,0x00,0xCF,0x01,0x17,0x01,0x4B,0x01,0x93,0x01,0xC6,0x02,0x10,0x02,0x48,0x02,0x49,0x02,0x79,0x02,0xAA,0x02,0xC4,0x02,0xE4,0x02,0xF8,0x03,0x10,0x03,0x20,0x03,0x36,0x03,0x46,0x03,0x5C,0x03,0x8B,0x03,0xFF}},
57      {LCM_SEND(55),{53,0,0xD3,0x00,0x00,0x00,0x01,0x00,0x18,0x00,0x3B,0x00,0x60,0x00,0x9E,0x00,0xCF,0x01,0x17,0x01,0x4B,0x01,0x93,0x01,0xC6,0x02,0x10,0x02,0x48,0x02,0x49,0x02,0x79,0x02,0xAA,0x02,0xC4,0x02,0xE4,0x02,0xF8,0x03,0x10,0x03,0x20,0x03,0x36,0x03,0x46,0x03,0x5C,0x03,0x8B,0x03,0xFF}},
58      {LCM_SEND(55),{53,0,0xD4,0x00,0x00,0x00,0x01,0x00,0x18,0x00,0x3B,0x00,0x60,0x00,0x9E,0x00,0xCF,0x01,0x17,0x01,0x4B,0x01,0x93,0x01,0xC6,0x02,0x10,0x02,0x48,0x02,0x49,0x02,0x79,0x02,0xAA,0x02,0xC4,0x02,0xE4,0x02,0xF8,0x03,0x10,0x03,0x20,0x03,0x36,0x03,0x46,0x03,0x5C,0x03,0x8B,0x03,0xFF}},
59      {LCM_SEND(55),{53,0,0xD5,0x00,0x00,0x00,0x01,0x00,0x18,0x00,0x3B,0x00,0x60,0x00,0x9E,0x00,0xCF,0x01,0x17,0x01,0x4B,0x01,0x93,0x01,0xC6,0x02,0x10,0x02,0x48,0x02,0x49,0x02,0x79,0x02,0xAA,0x02,0xC4,0x02,0xE4,0x02,0xF8,0x03,0x10,0x03,0x20,0x03,0x36,0x03,0x46,0x03,0x5C,0x03,0x8B,0x03,0xFF}},
60      {LCM_SEND(55),{53,0,0xD6,0x00,0x00,0x00,0x01,0x00,0x18,0x00,0x3B,0x00,0x60,0x00,0x9E,0x00,0xCF,0x01,0x17,0x01,0x4B,0x01,0x93,0x01,0xC6,0x02,0x10,0x02,0x48,0x02,0x49,0x02,0x79,0x02,0xAA,0x02,0xC4,0x02,0xE4,0x02,0xF8,0x03,0x10,0x03,0x20,0x03,0x36,0x03,0x46,0x03,0x5C,0x03,0x8B,0x03,0xFF}},
61      {LCM_SEND(8),{6,0,0xF0,0x55,0xAA,0x52,0x08,0x00}},
62      {LCM_SEND(2),{0xB1,0xFC}},
63      {LCM_SEND(2),{0xB4,0x10}},
64      {LCM_SEND(2),{0xB6,0x01}},
65      {LCM_SEND(7),{5,0,0xB8,0x01,0x04,0x04,0x04}},
66      {LCM_SEND(2),{0xBA,0x01}},
67      {LCM_SEND(6),{4,0,0xBC,0x02,0x02,0x02}},
68      {LCM_SEND(2),{0x3A,0x77}}, //0x55
69      {LCM_SEND(5),{3,0,0xC9,0xC0,0x01}},
70      {LCM_SEND(8),{6,0,0xF0,0x55,0xAA,0x52,0x08,0x02}},
71      {LCM_SEND(2),{0xF6,0x60}},
72      {LCM_SEND(2),{0x35,0x00}},
73      {LCM_SEND(2),{0x36,0x00}},
74      {LCM_SEND(5),{3,0,0x44,0x00,0x50}},
75      {LCM_SEND(8),{6,0,0xF0,0x55,0xAA,0x52,0x08,0x01}},
76      {LCM_SEND(7),{5,0,0x2A,0x00,0x00,0x01,0xDF}},
77      {LCM_SEND(7),{5,0,0x2B,0x00,0x00,0x03,0x1F}}, //0x355
78      {LCM_SEND(1),{0x11}},
79      {LCM_SLEEP(120)},
80      {LCM_SEND(1),{0x29}},
81      {LCM_SLEEP(100)},
82 #endif
83 };
84
85 static LCM_Force_Cmd_Code rd_prep_code[]={
86         {0x39, {LCM_SEND(8), {0x6, 0, 0xF0, 0x55, 0xAA, 0x52, 0x08, 0x01}}},
87         {0x37, {LCM_SEND(2), {0x3, 0}}},
88 };
89
90 static LCM_Init_Code disp_on =  {LCM_SEND(1), {0x29}};
91
92 static LCM_Init_Code sleep_in =  {LCM_SEND(1), {0x10}};
93
94 static LCM_Init_Code sleep_out =  {LCM_SEND(1), {0x11}};
95
96 static int32_t rm68180_mipi_init(struct panel_spec *self)
97 {
98         int32_t i;
99         LCM_Init_Code *init = init_data;
100         unsigned int tag;
101
102         mipi_set_cmd_mode_t mipi_set_cmd_mode = self->info.mipi->ops->mipi_set_cmd_mode;
103         mipi_gen_write_t mipi_gen_write = self->info.mipi->ops->mipi_gen_write;
104         mipi_dcs_write_t mipi_dcs_write = self->info.mipi->ops->mipi_dcs_write;
105
106         LCD_PRINT("rm68180_init\n");
107         mipi_eotp_set_t mipi_eotp_set = self->info.mipi->ops->mipi_eotp_set;
108         mipi_set_cmd_mode();
109         mipi_eotp_set(1,0);
110
111         for(i = 0; i < ARRAY_SIZE(init_data); i++){
112                 tag = (init->tag >>24);
113                 if(tag & LCM_TAG_SEND){
114                         mipi_gen_write(init->data, (init->tag & LCM_TAG_MASK));
115                         udelay(20);
116                 }else if(tag & LCM_TAG_SLEEP){
117                         udelay((init->tag & LCM_TAG_MASK) * 1000);
118                 }
119                 init++;
120         }
121         mipi_eotp_set(1,1);
122
123         return 0;
124 }
125
126 static uint32_t rm68180_readid(struct panel_spec *self)
127 {
128
129 //{LCM_SEND(8), {6,0,0xF0,0x55,0xAA,0x52,0x08,0x01}},   
130         /*Jessica TODO: need read id*/
131         int32_t i = 0;
132         uint32_t j =0;
133         LCM_Force_Cmd_Code * rd_prepare = rd_prep_code;
134         
135         uint8_t read_data[3] = {0};
136         uint8_t read_c5[3] = {0};
137         int32_t read_rtn = 0;
138         unsigned int tag = 0;
139 #if 1
140         mipi_set_cmd_mode_t mipi_set_cmd_mode = self->info.mipi->ops->mipi_set_cmd_mode;
141         mipi_force_write_t mipi_force_write = self->info.mipi->ops->mipi_force_write;
142         mipi_force_read_t mipi_force_read = self->info.mipi->ops->mipi_force_read;
143         mipi_set_lp_mode_t mipi_set_lp_mode = self->info.mipi->ops->mipi_set_lp_mode;
144         mipi_set_hs_mode_t mipi_set_hs_mode = self->info.mipi->ops->mipi_set_hs_mode;
145         mipi_eotp_set_t mipi_eotp_set = self->info.mipi->ops->mipi_eotp_set;
146
147         printk("lcd_rm68180_mipi read id!\n");
148         mipi_set_cmd_mode();
149         mipi_eotp_set(1,0);
150         //mipi_force_read(0x0, 3,(uint8_t *)read_data);
151
152         for(j = 0; j < 4; j++){
153                 for(i = 0; i < ARRAY_SIZE(rd_prep_code); i++){
154                         tag = (rd_prepare->real_cmd_code.tag >> 24);
155                         if(tag & LCM_TAG_SEND){
156                                 mipi_force_write(rd_prepare->datatype, rd_prepare->real_cmd_code.data, (rd_prepare->real_cmd_code.tag & LCM_TAG_MASK));
157                         }else if(tag & LCM_TAG_SLEEP){
158                                 udelay((rd_prepare->real_cmd_code.tag & LCM_TAG_MASK) * 1000);
159                         }
160                         rd_prepare++;   
161                 }
162                 read_rtn = mipi_force_read(0x04, 3,(uint8_t *)read_data);
163                 printk("lcd_rm68180_mipi read id value is 0x%x, 0x%x, 0x%x!\n", read_data[0], read_data[1], read_data[2]);      
164                 //0x00 0x80 0x00
165                 //return 0x80;
166                 if((0x80 == read_data[1])){
167                         self->info.mipi->ops->mipi_set_hs_mode();
168                         printk("lcd_rm68180_mipi read id success!\n");
169                         mipi_eotp_set(1,1);
170                         return 0x80;
171                 }
172                 else 
173                         printk("lcd_rm68180_mipi read id failed!\n");
174
175         }
176         mipi_eotp_set(1,1);
177 #endif
178         return 0x00;
179 }
180
181 static struct panel_operations lcd_rm68180_mipi_operations = {
182         .panel_init = rm68180_mipi_init,
183         .panel_readid = rm68180_readid,
184 };
185
186 static struct timing_rgb lcd_rm68180_mipi_timing = {
187 #if 1
188         .hfp = 20,  /* unit: pixel */
189         .hbp = 20,
190         .hsync = 6,//4,
191         .vfp = 20, /*unit: line*/
192         .vbp = 20,
193         .vsync = 6,//6
194
195 #else
196 /*
197         .hfp = 120,  
198         .hbp = 120,
199         .hsync = 60,
200         .vfp = 6, 
201         .vbp = 6,
202         .vsync = 4,
203 */
204         .hfp =70,  /* unit: pixel */
205         .hbp = 40,
206         .hsync = 10,
207         .vfp = 10, /*unit: line*/
208         .vbp = 10,
209         .vsync = 12,
210 #endif
211 };
212
213 static struct info_mipi lcd_rm68180_mipi_info = {
214         .work_mode  = SPRDFB_MIPI_MODE_VIDEO,
215         .video_bus_width = 24, /*18,16*/
216         .lan_number = 2,
217         .phy_feq = 360*1000,
218         .h_sync_pol = SPRDFB_POLARITY_POS,
219         .v_sync_pol = SPRDFB_POLARITY_POS,
220         .de_pol = SPRDFB_POLARITY_POS,
221         .te_pol = SPRDFB_POLARITY_POS,
222         .color_mode_pol = SPRDFB_POLARITY_NEG,
223         .shut_down_pol = SPRDFB_POLARITY_NEG,
224         .timing = &lcd_rm68180_mipi_timing,
225         .ops = NULL,
226 };
227
228 struct panel_spec lcd_rm68180_mipi_spec = {
229         .width = 480,
230         .height = 800, //854,
231         .fps = 60,
232         .type = LCD_MODE_DSI,
233         .direction = LCD_DIRECT_NORMAL,
234         .info = {
235                 .mipi = &lcd_rm68180_mipi_info
236         },
237         .ops = &lcd_rm68180_mipi_operations,
238 };