2 * Copyright (C) 2012 Spreadtrum Communications Inc.
4 * This software is licensed under the terms of the GNU General Public
5 * License version 2, as published by the Free Software Foundation, and
6 * may be copied, distributed, and modified under those terms.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
17 #include <asm/arch/tiger_lcd.h>
18 #include <asm/arch/dispc_reg.h>
23 static ushort colormap[256];
26 #ifdef CONFIG_SC8810_OPENPHONE
28 extern struct panel_spec lcd_panel_hx8357;
29 static struct panel_cfg lcd_panel[] = {
32 .panel = &lcd_panel_hx8357,
35 #elif defined CONFIG_SC8825EA_ONTIM
36 extern struct panel_spec lcd_otm8018b_mipi_spec;
37 static struct panel_cfg lcd_panel[] = {
40 .panel = &lcd_otm8018b_mipi_spec ,
44 #elif defined CONFIG_SC8825EA
45 extern struct panel_spec lcd_nt35516_mipi_spec;
46 extern struct panel_spec lcd_otm8018b_mipi_spec;
48 static struct panel_cfg lcd_panel[] = {
51 .panel = &lcd_otm8018b_mipi_spec ,
55 .panel = &lcd_nt35516_mipi_spec ,
59 #elif defined CONFIG_SC8825EB
61 extern struct panel_spec lcd_nt35516_mcu_spec;
62 static struct panel_cfg lcd_panel[] = {
65 .panel = &lcd_nt35516_mcu_spec ,
69 extern struct panel_spec lcd_panel_hx8362_rgb_spi_spec;
70 static struct panel_cfg lcd_panel[] = {
73 .panel = &lcd_panel_hx8362_rgb_spi_spec ,
78 #elif defined CONFIG_LCD_788
79 extern struct panel_spec lcd_panel_hx8357;
80 static struct panel_cfg lcd_panel[] = {
83 .panel = &lcd_panel_hx8357,
87 #elif defined CONFIG_GARDA
88 extern struct panel_spec lcd_nt35510_mipi_spec;
89 static struct panel_cfg lcd_panel[] = {
92 .panel = &lcd_nt35510_mipi_spec ,
97 #elif defined(CONFIG_SP6825GA) || defined(CONFIG_SP6825GB)
99 extern struct panel_spec lcd_nt35516_mcu_spec;
100 static struct panel_cfg lcd_panel[] = {
103 .panel = &lcd_nt35516_mcu_spec ,
107 extern struct panel_spec lcd_panel_hx8363_rgb_spi_spec;
108 static struct panel_cfg lcd_panel[] = {
111 .panel = &lcd_panel_hx8363_rgb_spi_spec ,
115 #elif defined CONFIG_SP8825GA_OPENPHONE
116 extern struct panel_spec lcd_nt35516_mipi_spec;
117 static struct panel_cfg lcd_panel[] = {
120 .panel = &lcd_nt35516_mipi_spec ,
124 #elif defined CONFIG_MACH_SP7720G2
125 extern struct panel_spec lcd_hx8363_mcu_spec;
126 static struct panel_cfg lcd_panel[] = {
129 .panel = &lcd_hx8363_mcu_spec ,
134 #ifdef CONFIG_LCD_QVGA
136 extern struct panel_spec lcd_panel_ili9341s;
137 static struct panel_cfg lcd_panel[] = {
140 .panel = &lcd_panel_ili9341s,
144 extern struct panel_spec lcd_s6d0139_spec;
145 static struct panel_cfg lcd_panel[] = {
148 .panel = &lcd_s6d0139_spec ,
152 extern struct panel_spec lcd_panel_hx8369;
153 static struct panel_cfg lcd_panel[] = {
156 .panel = &lcd_panel_hx8369,
162 #ifdef CONFIG_LCD_FWVGA
163 vidinfo_t panel_info = {
172 #ifdef CONFIG_LCD_WVGA
173 vidinfo_t panel_info = {
181 #ifdef CONFIG_LCD_HVGA
182 vidinfo_t panel_info = {
190 #ifdef CONFIG_LCD_QVGA
191 vidinfo_t panel_info = {
199 #ifdef CONFIG_LCD_QHD
200 vidinfo_t panel_info = {
208 extern struct panel_if_ctrl sprdfb_mcu_ctrl;
209 extern struct panel_if_ctrl sprdfb_rgb_ctrl;
210 extern struct panel_if_ctrl sprdfb_mipi_ctrl;
212 void sprdfb_panel_remove(struct sprdfb_device *dev);
215 static int32_t panel_reset_dispc(struct panel_spec *self)
217 dispc_write(1, DISPC_RSTN);
219 dispc_write(0, DISPC_RSTN);
221 dispc_write(1, DISPC_RSTN);
222 /* wait 10ms util the lcd is stable */
228 static void panel_reset(struct panel_spec *panel)
230 FB_PRINT("sprdfb: [%s]\n",__FUNCTION__);
233 panel_reset_dispc(panel);
236 static int panel_mount(struct sprdfb_device *dev, struct panel_spec *panel)
240 FB_PRINT("sprdfb: [%s], type = %d\n",__FUNCTION__, panel->type);
243 case SPRDFB_PANEL_TYPE_MCU:
244 dev->if_ctrl = &sprdfb_mcu_ctrl;
246 case SPRDFB_PANEL_TYPE_RGB:
247 dev->if_ctrl = &sprdfb_rgb_ctrl;
250 case SPRDFB_PANEL_TYPE_MIPI:
251 dev->if_ctrl = &sprdfb_mipi_ctrl;
255 FB_PRINT("sprdfb: [%s]: erro panel type.(%d)",__FUNCTION__, panel->type);
261 if(NULL == dev->if_ctrl){
265 if(dev->if_ctrl->panel_if_check){
266 rval = dev->if_ctrl->panel_if_check(panel);
270 FB_PRINT("sprdfb: [%s] check panel fail!\n", __FUNCTION__);
277 if(NULL == dev->panel->ops->panel_reset){
278 dev->panel->ops->panel_reset = panel_reset_dispc;
281 dev->if_ctrl->panel_if_mount(dev);
287 int panel_init(struct sprdfb_device *dev)
289 if((NULL == dev) || (NULL == dev->panel)){
290 FB_PRINT("sprdfb: [%s]: Invalid param\n", __FUNCTION__);
294 FB_PRINT("sprdfb: [%s], type = %d\n",__FUNCTION__, dev->panel->type);
296 if(NULL != dev->if_ctrl->panel_if_init){
297 dev->if_ctrl->panel_if_init(dev);
302 int panel_ready(struct sprdfb_device *dev)
304 if((NULL == dev) || (NULL == dev->panel)){
305 FB_PRINT("sprdfb: [%s]: Invalid param\n", __FUNCTION__);
309 FB_PRINT("sprdfb: [%s], type = %d\n",__FUNCTION__, dev->panel->type);
311 if(NULL != dev->if_ctrl->panel_if_ready){
312 dev->if_ctrl->panel_if_ready(dev);
319 static struct panel_spec *adapt_panel_from_readid(struct sprdfb_device *dev)
323 FB_PRINT("sprdfb: [%s]\n",__FUNCTION__);
325 for(i = 0;i<(sizeof(lcd_panel))/(sizeof(lcd_panel[0]));i++) {
326 FB_PRINT("sprdfb: [%s]: try panel 0x%x\n", __FUNCTION__, lcd_panel[i].lcd_id);
327 panel_mount(dev, lcd_panel[i].panel);
329 panel_reset(lcd_panel[i].panel);
330 id = dev->panel->ops->panel_readid(dev->panel);
331 if(id == lcd_panel[i].lcd_id) {
332 FB_PRINT("sprdfb: [%s]: LCD Panel 0x%x is attached!\n", __FUNCTION__, lcd_panel[i].lcd_id);
334 dev->panel->ops->panel_init(dev->panel); //zxdebug modify for LCD adaptor
336 save_lcd_id_to_kernel(id);
338 return lcd_panel[i].panel;
339 } else { //zxdbg for LCD adaptor
340 FB_PRINT("sprdfb: [%s]: LCD Panel 0x%x attached fail!go next ", __FUNCTION__, lcd_panel[i].lcd_id);
341 sprdfb_panel_remove(dev); //zxdebug modify for LCD adaptor
345 FB_PRINT("sprdfb: [%s]: final failed to attach LCD Panel!\n", __FUNCTION__);
349 uint16_t sprdfb_panel_probe(struct sprdfb_device *dev)
351 struct panel_spec *panel;
354 FB_PRINT("sprdfb: [%s]: Invalid param\n", __FUNCTION__);
358 FB_PRINT("sprdfb: [%s]\n",__FUNCTION__);
360 /* can not be here in normal; we should get correct device id from uboot */
361 panel = adapt_panel_from_readid(dev);
364 FB_PRINT("sprdfb: [%s] got panel\n", __FUNCTION__);
368 FB_PRINT("sprdfb: [%s] can not got panel\n", __FUNCTION__);
373 void sprdfb_panel_invalidate_rect(struct panel_spec *self,
374 uint16_t left, uint16_t top,
375 uint16_t right, uint16_t bottom)
377 FB_PRINT("sprdfb: [%s]\n, (%d, %d, %d,%d)",__FUNCTION__, left, top, right, bottom);
379 if(NULL != self->ops->panel_invalidate_rect){
380 self->ops->panel_invalidate_rect(self, left, top, right, bottom);
384 void sprdfb_panel_invalidate(struct panel_spec *self)
386 FB_PRINT("sprdfb: [%s]\n",__FUNCTION__);
388 if(NULL != self->ops->panel_invalidate){
389 self->ops->panel_invalidate(self);
393 void sprdfb_panel_before_refresh(struct sprdfb_device *dev)
395 FB_PRINT("sprdfb: [%s]\n",__FUNCTION__);
397 if(NULL != dev->if_ctrl->panel_if_before_refresh)
398 dev->if_ctrl->panel_if_before_refresh(dev);
401 void sprdfb_panel_after_refresh(struct sprdfb_device *dev)
403 FB_PRINT("sprdfb: [%s]\n",__FUNCTION__);
405 if(NULL != dev->if_ctrl->panel_if_after_refresh)
406 dev->if_ctrl->panel_if_after_refresh(dev);
409 void sprdfb_panel_remove(struct sprdfb_device *dev)
411 FB_PRINT("sprdfb: [%s]\n",__FUNCTION__);
413 if(NULL != dev->if_ctrl->panel_if_uninit){
414 dev->if_ctrl->panel_if_uninit(dev);