video: sprd: remove build warnings
[profile/mobile/platform/kernel/u-boot-tm1.git] / drivers / video / sprdfb / sprdfb_panel.c
1 /*
2  * Copyright (C) 2012 Spreadtrum Communications Inc.
3  *
4  */
5
6 #include <common.h>
7 #include <lcd.h>
8 #include <asm/arch/sprd_lcd.h>
9 #include <asm/arch/dispc_reg.h>
10
11 #include "sprdfb.h"
12
13 extern struct panel_if_ctrl sprdfb_mcu_ctrl;
14 extern struct panel_if_ctrl sprdfb_rgb_ctrl;
15 extern struct panel_if_ctrl sprdfb_mipi_ctrl;
16
17 extern struct panel_spec lcd_s6e8aa5x01_mipi_spec;
18 extern struct panel_spec lcd_s6e88oa_mipi_spec;
19 extern struct panel_spec lcd_nt35510_mipi_spec;
20 extern struct panel_spec lcd_nt35516_mipi_spec;
21 extern struct panel_spec lcd_nt35516_mcu_spec;
22 extern struct panel_spec lcd_nt35516_rgb_spi_spec;
23 extern struct panel_spec lcd_otm8018b_mipi_spec;
24 extern struct panel_spec lcd_hx8363_mcu_spec;
25 extern struct panel_spec lcd_panel_hx8363_rgb_spi_spec;
26 extern struct panel_spec lcd_panel_hx8363_rgb_spi_spec_viva;
27 extern struct panel_spec lcd_s6d0139_spec;
28 extern struct panel_spec lcd_otm1283a_mipi_spec;
29 extern struct panel_spec lcd_ssd2075_mipi_spec;
30 extern struct panel_spec lcd_panel_st7789v;
31 extern struct panel_spec lcd_panel_sc7798_rgb_spi;
32 extern struct panel_spec lcd_hx8369b_mipi_spec;
33 extern struct panel_spec lcd_sd7798d_mipi_spec;
34 extern struct panel_spec lcd_nt35502_mipi_spec;
35 extern struct panel_spec lcd_panel_ili9341;
36 extern struct panel_spec lcd_panel_ili9486;
37 extern struct panel_spec lcd_panel_ili9486_rgb_spi;
38 extern struct panel_spec lcd_ili9486s1_mipi_spec;
39 extern struct panel_spec lcd_nt51017_mipi_lvds_spec;
40 extern struct panel_spec lcd_t8861_mipi_spec;
41 extern struct panel_spec lcd_hx8379a_mipi_spec;
42 extern struct panel_spec lcd_hx8389c_mipi_spec;
43 extern struct panel_spec ili6150_lvds_spec;
44 extern struct panel_spec lcd_rm68180_mipi_spec;
45 extern struct panel_spec lcd_ili9806e_mipi_spec;
46 extern struct panel_spec lcd_ili9806e_2_mipi_spec;
47 extern struct panel_spec lcd_otm8019a_mipi_spec;
48 extern struct panel_spec lcd_fl10802_mipi_spec;
49 extern struct panel_spec lcd_jd9161_mipi_spec;
50 extern struct panel_spec lcd_hx8369b_mipi_vivaltoVE_spec;
51 extern struct panel_spec lcd_vx5b3d_mipi_spec;
52 extern struct panel_spec lcd_hx8369b_grandneo_mipi_spec;
53 extern struct panel_spec lcd_hx8369b_tshark2_j3_mipi_spec;
54 extern struct panel_spec lcd_sd7798d_mipi_spec;
55 extern struct panel_spec lcd_s6d77a1_mipi_spec;
56 extern struct panel_spec lcd_nt51017_mipi_spec;
57 extern struct panel_spec lcd_hx8394d_mipi_spec;
58
59 struct gpio_chip;
60
61 extern void save_lcd_id_to_kernel(uint32_t id);
62 extern int sprd_gpio_request(struct gpio_chip *chip, unsigned offset);
63 extern int sprd_gpio_direction_output(struct gpio_chip *chip, unsigned offset, int value);
64 extern void sprd_gpio_set(struct gpio_chip *chip, unsigned offset, int value);
65
66 void sprdfb_panel_remove(struct sprdfb_device *dev);
67
68 static ushort colormap[256];
69
70 static struct panel_cfg panel_cfg[] = {
71 #ifdef CONFIG_FB_LCD_S6E8AA5X01_MIPI
72 {
73         .lcd_id = 0x400002,
74         .panel = &lcd_s6e8aa5x01_mipi_spec,
75 },
76 #endif
77 #ifdef CONFIG_FB_LCD_S6E88OA_MIPI
78 {
79         .lcd_id = 0x6e880a,
80         .panel = &lcd_s6e88oa_mipi_spec,
81 },
82 #endif
83 #ifdef CONFIG_FB_LCD_NT35510_MIPI
84         {
85                 .lcd_id = 0x10,
86                 .panel = &lcd_nt35510_mipi_spec,
87         },
88 #endif
89
90 #ifdef CONFIG_FB_LCD_NT35516_MIPI
91         {
92                 .lcd_id = 0x16,
93                 .panel = &lcd_nt35516_mipi_spec,
94         },
95 #endif
96
97 #ifdef CONFIG_FB_LCD_HX8394D_MIPI
98         {
99                 .lcd_id = 0x8394,
100                 .panel = &lcd_hx8394d_mipi_spec,
101         },
102 #endif
103
104 #ifdef CONFIG_FB_LCD_NT35516_MCU
105         {
106                 .lcd_id = 0x16,
107                 .panel = &lcd_nt35516_mcu_spec,
108         },
109 #endif
110
111 #ifdef CONFIG_FB_LCD_NT35516_RGB_SPI
112         {
113                 .lcd_id = 0x16,
114                 .panel = &lcd_nt35516_rgb_spi_spec,
115         },
116 #endif
117
118 #ifdef CONFIG_FB_LCD_OTM8018B_MIPI
119         {
120                 .lcd_id = 0x18,
121                 .panel = &lcd_otm8018b_mipi_spec,
122         },
123 #endif
124
125 #ifdef CONFIG_FB_LCD_HX8363_MCU
126         {
127                 .lcd_id = 0x18,
128                 .panel = &lcd_hx8363_mcu_spec,
129         },
130 #endif
131
132 #ifdef CONFIG_FB_LCD_VIVA_RGB_SPI
133         {
134                 .lcd_id = 0x63,
135                 .panel = &lcd_panel_hx8363_rgb_spi_spec_viva,
136         },
137 #endif
138
139 #ifdef CONFIG_FB_LCD_RM68180_MIPI
140         {
141                 .lcd_id = 0x80,
142                 .panel = &lcd_rm68180_mipi_spec,
143         },
144 #endif
145
146 #ifdef CONFIG_FB_LCD_HX8363_RGB_SPI
147         {
148                 .lcd_id = 0x84,
149                 .panel = &lcd_panel_hx8363_rgb_spi_spec,
150         },
151 #endif
152
153 #ifdef CONFIG_FB_LCD_S6D0139
154         {
155                 .lcd_id = 0x139,
156                 .panel = &lcd_s6d0139_spec,
157         },
158 #endif
159
160 #ifdef CONFIG_FB_LCD_OTM1283A_MIPI
161         {
162                 .lcd_id = 0x1283,
163                 .panel = &lcd_otm1283a_mipi_spec,
164         },
165 #endif
166
167 #ifdef CONFIG_FB_LCD_SSD2075_MIPI
168         {
169                 .lcd_id = 0x2075,
170                 .panel = &lcd_ssd2075_mipi_spec,
171         },
172 #endif
173
174 #ifdef CONFIG_FB_LCD_ST7789V_MCU
175         {
176                 .lcd_id = 0x7789,
177                 .panel = &lcd_panel_st7789v,
178         },
179 #endif
180
181 #ifdef CONFIG_FB_LCD_SC7798_RGB_SPI
182         {
183                 .lcd_id = 0x7798,
184                 .panel = &lcd_panel_sc7798_rgb_spi,
185         },
186 #endif
187
188 #if defined(CONFIG_FB_LCD_HX8369B_MIPI) || defined(CONFIG_FB_LCD_HX8369B_MIPI_COREPRIMELITE)
189         {
190                 .lcd_id = 0x8369,
191                 .panel = &lcd_hx8369b_mipi_spec,
192         },
193 #endif
194
195 #if defined (CONFIG_FB_LCD_HX8369B_MIPI) ||defined (CONFIG_FB_LCD_HX8369B_MIPI_KIRAN3G)
196         {
197                 .lcd_id = 0x8369,
198                 .panel = &lcd_hx8369b_mipi_spec,
199         },
200 #endif
201
202 #if defined(CONFIG_FB_LCD_SD7798D_MIPI_COREPRIMELITE)
203         {
204                 .lcd_id = 0x55b8f0,
205                 .panel = &lcd_sd7798d_mipi_spec,
206         },
207 #endif
208
209 #ifdef CONFIG_FB_LCD_NT35502_MIPI
210         {
211                 .lcd_id = 0x8370,
212                 .panel = &lcd_nt35502_mipi_spec,
213         },
214 #endif
215
216 #ifdef CONFIG_FB_LCD_NT51017_MIPI
217         {
218                 .lcd_id = 0x51017,
219                 .panel = &lcd_nt51017_mipi_spec,
220         },
221 #endif
222
223
224 #ifdef CONFIG_FB_LCD_ILI9341
225         {
226                 .lcd_id = 0x9341,
227                 .panel = &lcd_panel_ili9341,
228         },
229 #endif
230
231 #ifdef CONFIG_FB_LCD_ILI9486
232         {
233                 .lcd_id = 0x9486,
234                 .panel = &lcd_panel_ili9486,
235         },
236 #endif
237
238 #ifdef CONFIG_FB_LCD_ILI9486_RGB_SPI
239         {
240                 .lcd_id = 0x9486,
241                 .panel = &lcd_panel_ili9486_rgb_spi,
242         },
243 #endif
244
245 #ifdef CONFIG_FB_LCD_ILI9486S1_MIPI
246         {
247                 .lcd_id = 0x8370,
248                 .panel = &lcd_ili9486s1_mipi_spec,
249         },
250 #endif
251
252 #ifdef CONFIG_FB_LCD_HX8369B_MIPI_VIVALTO_VE
253         {
254                 .lcd_id = 0x8369,
255                 .panel = &lcd_hx8369b_mipi_vivaltoVE_spec,
256         },
257 #endif
258
259 #ifdef CONFIG_FB_LCD_VX5B3D_MIPI
260         {
261                 .lcd_id = 0x8282,
262                 .panel = &lcd_vx5b3d_mipi_spec,
263         },
264 #endif
265
266 #ifdef CONFIG_FB_LCD_GRANDNEO_MIPI
267         {
268                 .lcd_id = 0x8369,
269                 .panel = &lcd_hx8369b_grandneo_mipi_spec,
270         },
271 #endif
272
273 #ifdef CONFIG_FB_LCD_TSHARK2_J3_MIPI
274         {
275                 .lcd_id = 0x8369,
276                 .panel = &lcd_hx8369b_tshark2_j3_mipi_spec,
277         },
278 #endif
279
280 #ifdef CONFIG_FB_LCD_SD7798D_MIPI
281         {
282                 .lcd_id = 0x55b8f0,
283                 .panel = &lcd_sd7798d_mipi_spec,
284         },
285 #endif
286
287 #ifdef CONFIG_FB_LCD_S6D77A1_MIPI_PIKEA_J1
288         {
289                 .lcd_id = 0x55b810,
290                 .panel = &lcd_s6d77a1_mipi_spec,
291         },
292 #endif
293
294 #ifdef CONFIG_FB_LCD_NT51017_LVDS
295         {
296                 .lcd_id = 0xC749,
297                 .panel = &lcd_nt51017_mipi_lvds_spec,
298         },
299 #endif
300 #ifdef CONFIG_FB_LCD_T8861_MIPI
301         {
302                 .lcd_id = 0x04,
303                 .panel = &lcd_t8861_mipi_spec,
304         },
305 #endif
306 #ifdef CONFIG_FB_LCD_HX8379A_MIPI
307         {
308                 .lcd_id = 0x8379,
309                 .panel = &lcd_hx8379a_mipi_spec,
310         },
311 #endif
312 #ifdef CONFIG_FB_LCD_HX8389C_MIPI
313 {
314         .lcd_id = 0x8389,
315         .panel = &lcd_hx8389c_mipi_spec,
316 },
317 #endif
318 #ifdef CONFIG_FB_LCD_ILI6150_LVDS
319 {
320     .lcd_id = 0x1806,
321     .panel = &ili6150_lvds_spec,
322 },
323 #endif
324 #ifdef CONFIG_FB_LCD_ILI9806E_MIPI
325 {
326     .lcd_id = 0x4,
327     .panel = &lcd_ili9806e_mipi_spec,
328 },
329 #endif
330 #ifdef CONFIG_FB_LCD_ILI9806E_2_MIPI
331 {
332     .lcd_id = 0x980602,
333     .panel = &lcd_ili9806e_2_mipi_spec,
334 },
335 #endif
336 #ifdef CONFIG_FB_LCD_OTM8019A_MIPI
337         {
338                 .lcd_id = 0x8019,
339                 .panel = &lcd_otm8019a_mipi_spec,
340         },
341 #endif
342 #ifdef CONFIG_FB_LCD_FL10802_MIPI
343         {
344                 .lcd_id = 0x1080,
345                 .panel = &lcd_fl10802_mipi_spec,
346         },
347 #endif
348 #ifdef CONFIG_FB_LCD_JD9161_MIPI
349         {
350                 .lcd_id = 0x916100,
351                 .panel = &lcd_jd9161_mipi_spec,
352         },
353 #endif
354
355 #ifdef CONFIG_FB_LCD_HX8394D_MIPI
356 {
357         .lcd_id = 0x8394,
358         .panel = &lcd_hx8394d_mipi_spec,
359 },
360 #endif
361 };
362
363 #ifdef CONFIG_LCD_FWVGA
364 vidinfo_t panel_info = {
365         .vl_col = 480,
366         .vl_bpix = 4,
367         .vl_row = 854,
368         .cmap = colormap,
369 };
370 #endif
371
372 #ifdef CONFIG_LCD_WVGA
373 vidinfo_t panel_info = {
374         .vl_col = 480,
375         .vl_bpix = 4,
376         .vl_row = 800,
377         .cmap = colormap,
378 };
379 #endif
380
381 #ifdef CONFIG_LCD_HVGA
382 vidinfo_t panel_info = {
383         .vl_col = 320,
384         .vl_bpix = 4,
385         .vl_row = 480,
386         .cmap = colormap,
387 };
388 #endif
389
390 #ifdef CONFIG_LCD_QVGA
391 vidinfo_t panel_info = {
392         .vl_col = 240,
393         .vl_bpix = 4,
394         .vl_row = 320,
395         .cmap = colormap,
396 };
397 #endif
398
399 #ifdef CONFIG_LCD_QHD
400 vidinfo_t panel_info = {
401         .vl_col = 540,
402         .vl_bpix = 4,
403         .vl_row = 960,
404         .cmap = colormap,
405 };
406 #endif
407
408 #ifdef CONFIG_LCD_PAD_1024
409 vidinfo_t panel_info = {
410         .vl_col = 1024,
411         .vl_bpix = 4,
412         .vl_row = 600,
413         .cmap = colormap,
414 };
415 #endif
416 #ifdef CONFIG_LCD_720P  //thomaszhang@20130412
417 vidinfo_t panel_info = {
418         .vl_col = 720,
419         .vl_bpix = 4,
420         .vl_row = 1280,
421         .cmap = colormap,
422 };
423 #endif
424
425 #ifdef CONFIG_LCD_HD  //LiWei
426 vidinfo_t panel_info = {
427         .vl_col = 768,
428         .vl_bpix = 4,
429         .vl_row = 1024,
430         .cmap = colormap,
431 };
432 #endif
433 #ifdef CONFIG_LCD_PAD_WXGA
434 vidinfo_t panel_info = {
435         .vl_col = 800,
436         .vl_bpix = 4,
437         .vl_row = 1280,
438         .cmap = colormap,
439 };
440 #endif
441
442
443 static int32_t panel_reset_dispc(struct panel_spec *self)
444 {
445         sprd_gpio_request(NULL, 103);
446         sprd_gpio_direction_output(NULL, 103, 0);
447         sprd_gpio_set(NULL, 103, 1);
448         mdelay(10);
449         sprd_gpio_set(NULL, 103, 0);
450         mdelay(5);
451         sprd_gpio_set(NULL, 103, 1);
452         mdelay(5);
453
454         return 0;
455 }
456
457 static void panel_reset(struct sprdfb_device *dev)
458 {
459         FB_PRINT("sprdfb: [%s]\n",__FUNCTION__);
460
461         //clk/data lane enter LP
462         if(NULL != dev->if_ctrl->panel_if_before_panel_reset){
463                 dev->if_ctrl->panel_if_before_panel_reset(dev);
464                 mdelay(5);
465         }
466
467         //reset panel
468         panel_reset_dispc(dev->panel);
469 }
470
471 static int panel_mount(struct sprdfb_device *dev, struct panel_spec *panel)
472 {
473         uint16_t rval = 1;
474
475         printf("sprdfb: [%s], type = %d\n",__FUNCTION__, panel->type);
476
477         switch(panel->type){
478         case SPRDFB_PANEL_TYPE_MCU:
479                 dev->if_ctrl = &sprdfb_mcu_ctrl;
480                 break;
481         case SPRDFB_PANEL_TYPE_RGB:
482         case SPRDFB_PANEL_TYPE_LVDS:
483                 dev->if_ctrl = &sprdfb_rgb_ctrl;
484                 break;
485 #if ((!defined(CONFIG_SC7710G2)) && (!defined(CONFIG_SPX15)))
486         case SPRDFB_PANEL_TYPE_MIPI:
487                 dev->if_ctrl = &sprdfb_mipi_ctrl;
488                 break;
489 #endif
490         default:
491                 printf("sprdfb: [%s]: erro panel type.(%d)",__FUNCTION__, panel->type);
492                 dev->if_ctrl = NULL;
493                 rval = 0 ;
494                 break;
495         };
496
497         if(NULL == dev->if_ctrl){
498                 return -1;
499         }
500
501         if(dev->if_ctrl->panel_if_check){
502                 rval = dev->if_ctrl->panel_if_check(panel);
503         }
504
505         if(0 == rval){
506                 printf("sprdfb: [%s] check panel fail!\n", __FUNCTION__);
507                 dev->if_ctrl = NULL;
508                 return -1;
509         }
510
511         dev->panel = panel;
512
513         if(NULL == dev->panel->ops->panel_reset){
514                 dev->panel->ops->panel_reset = panel_reset_dispc;
515         }
516
517         dev->if_ctrl->panel_if_mount(dev);
518
519         return 0;
520 }
521
522
523 int panel_init(struct sprdfb_device *dev)
524 {
525         if((NULL == dev) || (NULL == dev->panel)){
526                 printf("sprdfb: [%s]: Invalid param\n", __FUNCTION__);
527                 return -1;
528         }
529
530         FB_PRINT("sprdfb: [%s], type = %d\n",__FUNCTION__, dev->panel->type);
531
532         if(NULL != dev->if_ctrl->panel_if_init){
533                 dev->if_ctrl->panel_if_init(dev);
534         }
535         return 0;
536 }
537
538 int panel_ready(struct sprdfb_device *dev)
539 {
540         if((NULL == dev) || (NULL == dev->panel)){
541                 printf("sprdfb: [%s]: Invalid param\n", __FUNCTION__);
542                 return -1;
543         }
544
545         FB_PRINT("sprdfb: [%s],  type = %d\n",__FUNCTION__, dev->panel->type);
546
547         if(NULL != dev->if_ctrl->panel_if_ready){
548                 dev->if_ctrl->panel_if_ready(dev);
549         }
550
551         return 0;
552 }
553
554
555 static struct panel_spec *adapt_panel_from_readid(struct sprdfb_device *dev)
556 {
557         int id, i, ret, b_panel_reset=0;
558
559         FB_PRINT("sprdfb: [%s]\n",__FUNCTION__);
560
561         for(i = 0;i<(sizeof(panel_cfg))/(sizeof(panel_cfg[0]));i++) {
562                 printf("sprdfb: [%s]: try panel 0x%x\n", __FUNCTION__, panel_cfg[i].lcd_id);
563                 ret = panel_mount(dev, panel_cfg[i].panel);
564                 if(ret < 0){
565                         printf("sprdfb: panel_mount failed!\n");
566                         continue;
567                 }
568                 dev->ctrl->update_clk(dev);
569                 panel_init(dev);
570                 if ((b_panel_reset==0) || (1 == dev->panel->is_need_reset))
571                 {
572                         panel_reset(dev);
573                         b_panel_reset=1;
574                 }
575                 id = dev->panel->ops->panel_readid(dev->panel);
576                 if(id == panel_cfg[i].lcd_id) {
577                         printf("sprdfb: [%s]: LCD Panel 0x%x is attached!\n", __FUNCTION__, panel_cfg[i].lcd_id);
578
579                         dev->panel->ops->panel_init(dev->panel);                //zxdebug modify for LCD adaptor 
580                         save_lcd_id_to_kernel(id);
581                         dev->panel->ops->panel_check_mtp(dev->panel);
582                         dev->panel->ops->panel_check_elvss(dev->panel);
583                         dev->panel->ops->panel_check_hbm(dev->panel);
584
585                         panel_ready(dev);
586                         return panel_cfg[i].panel;
587                 } else {                                                        //zxdbg for LCD adaptor
588                         printf("sprdfb: [%s]: LCD Panel 0x%x attached fail!go next\n", __FUNCTION__, panel_cfg[i].lcd_id);
589                         sprdfb_panel_remove(dev);                               //zxdebug modify for LCD adaptor 
590                 }
591         }
592         
593         printf("sprdfb:  [%s]: final failed to attach LCD Panel!\n", __FUNCTION__);
594         return NULL;
595 }
596
597 uint16_t sprdfb_panel_probe(struct sprdfb_device *dev)
598 {
599         struct panel_spec *panel;
600
601         if(NULL == dev){
602                 printf("sprdfb: [%s]: Invalid param\n", __FUNCTION__);
603                 return -1;
604         }
605
606         FB_PRINT("sprdfb: [%s]\n",__FUNCTION__);
607
608         /* can not be here in normal; we should get correct device id from uboot */
609         panel = adapt_panel_from_readid(dev);
610
611         if (panel) {
612                 FB_PRINT("sprdfb: [%s] got panel\n", __FUNCTION__);
613                 return 0;
614         }
615
616         printf("sprdfb: [%s] can not got panel\n", __FUNCTION__);
617
618         return -1;
619 }
620
621 void sprdfb_panel_invalidate_rect(struct panel_spec *self,
622                                 uint16_t left, uint16_t top,
623                                 uint16_t right, uint16_t bottom)
624 {
625         FB_PRINT("sprdfb: [%s]\n, (%d, %d, %d,%d)",__FUNCTION__, left, top, right, bottom);
626
627         if(NULL != self->ops->panel_invalidate_rect){
628                 self->ops->panel_invalidate_rect(self, left, top, right, bottom);
629         }
630 }
631
632 void sprdfb_panel_invalidate(struct panel_spec *self)
633 {
634         FB_PRINT("sprdfb: [%s]\n",__FUNCTION__);
635
636         if(NULL != self->ops->panel_invalidate){
637                 self->ops->panel_invalidate(self);
638         }
639 }
640
641 void sprdfb_panel_before_refresh(struct sprdfb_device *dev)
642 {
643         FB_PRINT("sprdfb: [%s]\n",__FUNCTION__);
644
645         if(NULL != dev->if_ctrl->panel_if_before_refresh)
646                 dev->if_ctrl->panel_if_before_refresh(dev);
647 }
648
649 void sprdfb_panel_after_refresh(struct sprdfb_device *dev)
650 {
651         FB_PRINT("sprdfb: [%s]\n",__FUNCTION__);
652
653         if(NULL != dev->if_ctrl->panel_if_after_refresh)
654                 dev->if_ctrl->panel_if_after_refresh(dev);
655 }
656
657 void sprdfb_panel_remove(struct sprdfb_device *dev)
658 {
659         FB_PRINT("sprdfb: [%s]\n",__FUNCTION__);
660
661         if((NULL != dev->if_ctrl) && (NULL != dev->if_ctrl->panel_if_uninit)){
662                 dev->if_ctrl->panel_if_uninit(dev);
663         }
664         dev->panel = NULL;
665 }
666