1 /* drivers/video/sprdfb/lcd_hx8369b_mipi.c
3 * Support for hx8369b mipi LCD device
5 * Copyright (C) 2010 Spreadtrum
7 * This software is licensed under the terms of the GNU General Public
8 * License version 2, as published by the Free Software Foundation, and
9 * may be copied, distributed, and modified under those terms.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
17 #include <linux/kernel.h>
18 #include <linux/bug.h>
19 #include <linux/delay.h>
20 #include "../sprdfb_panel.h"
21 #include <mach/gpio.h>
25 #define LCD_PRINT printk
27 #define LCD_PRINT(...)
32 typedef struct LCM_Init_Code_tag {
34 unsigned char data[MAX_DATA];
37 typedef struct LCM_force_cmd_code_tag{
38 unsigned int datatype;
39 LCM_Init_Code real_cmd_code;
42 #define LCM_TAG_SHIFT 24
43 #define LCM_TAG_MASK ((1 << 24) -1)
44 #define LCM_SEND(len) ((1 << LCM_TAG_SHIFT)| len)
45 #define LCM_SLEEP(ms) ((2 << LCM_TAG_SHIFT)| ms)
46 //#define ARRAY_SIZE(array) ( sizeof(array) / sizeof(array[0]))
48 #define LCM_TAG_SEND (1<< 0)
49 #define LCM_TAG_SLEEP (1 << 1)
51 static LCM_Init_Code init_data[] = {
52 {LCM_SEND(6),{4,0,0xB9,0xFF,0x83,0x69}},
54 {LCM_SEND(13),{11,0,0xB1,0x0B,0x83,0x77,0x00,0x11,0x11,0x08,0x08,0x0C,0x12}},
55 {LCM_SEND(7),{5,0,0xC6,0x41,0xFF,0x7A,0xFF}},
56 {LCM_SEND(7),{5,0,0xE3,0x00,0x00,0x00,0x00}},
57 {LCM_SEND(9),{7,0,0xC0,0x73,0x50,0x00,0x34,0xC4,0x00}},
58 {LCM_SEND(18),{16,0,0xBA,0x31,0x00,0x16,0xCA,0xB0,0x0A,0x00,0x10,0x28,0x02,0x21,0x21,0x9A,0x1A,0x8F}},
59 {LCM_SEND(2),{0x3A,0x70}},
60 {LCM_SEND(10),{8,0,0xB3,0x83,0x00,0x31,0x03,0x01,0x13,0x06}},
61 {LCM_SEND(2),{0xB4,0x00}},
62 {LCM_SEND(2),{0xCC,0x0C}},
63 {LCM_SEND(2),{0xEA,0x72}},
64 {LCM_SEND(2),{0xB2,0x03}},
65 //set GIP timing control
66 {LCM_SEND(95),{93,0,0xD5,0x00,0x00,0x0D,0x00,0x00,0x00,0x00,0x12,0x40,0x00,0x00,0x00,0x01,0x60,0x37,0x00,0x00,0x0F,
67 0x01,0x02,0x47,0x03,0x00,0x03,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x03,0x00,0x00,0x18,
68 0x00,0x00,0x89,0x00,0x11,0x33,0x55,0x77,0x31,0x00,0x00,0x98,0x00,0x66,0x44,0x22,0x00,0x02,
69 0x00,0x00,0x89,0x00,0x00,0x22,0x44,0x66,0x20,0x00,0x00,0x98,0x00,0x77,0x55,0x33,0x11,0x13,
70 0x00,0x00,0x00,0x01,0x00,0x00,0x00,0x03,0x00,0xCF,0xFF,0xFF,0x03,0x00,0xCF,0xFF,0xFF,0x20,0x8C,0x5A}},
72 {LCM_SEND(38),{36,0,0xE0,0x00,0x00,0x00,0x0D,0x0C,0x3F,0x18,0x2C,0x04,0x0F,0x0E,0x14,0x17,0x15,0x16,0x10,
73 0x13,0x00,0x00,0x00,0x0C,0x12,0x3F,0x17,0x2C,0x05,0x08,0x0E,0x12,0x16,0x14,0x15,
75 {LCM_SEND(130),{128,0,0xC1,0x01,0x00,0x08,0x10,0x18,0x1F,0x27,0x2E,0x34,0x3E,0x48,0x50,0x58,0x60,0x68,0x70,0x78,
76 0x80,0x88,0x90,0x98,0xA0,0xA8,0xB0,0xB8,0xC0,0xC8,0xD0,0xD8,0xE0,0xE8,0xF0,0xF7,0xFF,
77 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x08,0x10,0x18,0x1F,0x27,0x2E,0x34,
78 0x3E,0x48,0x50,0x58,0x60,0x68,0x70,0x78,0x80,0x88,0x90,0x98,0xA0,0xA8,0xB0,0xB8,0xC0,
79 0xC8,0xD0,0xD8,0xE0,0xE8,0xF0,0xF7,0xFF,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
80 0x00,0x08,0x10,0x18,0x1F,0x27,0x2E,0x34,0x3E,0x48,0x50,0x58,0x60,0x68,0x70,0x78,0x80,
81 0x88,0x90,0x98,0xA0,0xA8,0xB0,0xB8,0xC0,0xC8,0xD0,0xD8,0xE0,0xE8,0xF0,0xF7,0xFF,0x00,
82 0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00}},
90 static LCM_Init_Code disp_on = {LCM_SEND(1), {0x29}};
92 static LCM_Init_Code sleep_in[] = {
93 {LCM_SEND(1), {0x28}},
94 {LCM_SLEEP(150)}, //>150ms
95 {LCM_SEND(1), {0x10}},
96 {LCM_SLEEP(150)}, //>150ms
99 static LCM_Init_Code sleep_out[] = {
100 {LCM_SEND(1), {0x11}},
101 {LCM_SLEEP(120)},//>120ms
102 {LCM_SEND(1), {0x29}},
103 {LCM_SLEEP(20)}, //>20ms
105 static int32_t hx8369b_mipi_init(struct panel_spec *self)
108 LCM_Init_Code *init = init_data;
111 mipi_set_cmd_mode_t mipi_set_cmd_mode = self->info.mipi->ops->mipi_set_cmd_mode;
112 mipi_dcs_write_t mipi_dcs_write = self->info.mipi->ops->mipi_dcs_write;
113 mipi_eotp_set_t mipi_eotp_set = self->info.mipi->ops->mipi_eotp_set;
115 printk("kernel hx8369b_mipi_init\n");
120 for(i = 0; i < ARRAY_SIZE(init_data); i++){
121 tag = (init->tag >>24);
122 if(tag & LCM_TAG_SEND){
123 mipi_dcs_write(init->data, (init->tag & LCM_TAG_MASK));
125 }else if(tag & LCM_TAG_SLEEP){
126 msleep(init->tag & LCM_TAG_MASK);
135 static uint32_t hx8369b_readid(struct panel_spec *self)
138 uint8_t read_data[4] = {0};
139 int32_t read_rtn = 0;
140 uint8_t param[2] = {0};
141 mipi_set_cmd_mode_t mipi_set_cmd_mode = self->info.mipi->ops->mipi_set_cmd_mode;
142 mipi_force_write_t mipi_force_write = self->info.mipi->ops->mipi_force_write;
143 mipi_force_read_t mipi_force_read = self->info.mipi->ops->mipi_force_read;
144 mipi_eotp_set_t mipi_eotp_set = self->info.mipi->ops->mipi_eotp_set;
146 LCD_PRINT("kernel lcd_hx8369b_mipi read id!\n");
151 for(j = 0; j < 4; j++){
154 mipi_force_write(0x37, param, 2);
155 read_rtn = mipi_force_read(0xda,1,&read_data[0]);
156 LCD_PRINT("lcd_hx8369b_mipi read id 0xda value is 0x%x!\n",read_data[0]);
158 read_rtn = mipi_force_read(0xdb,1,&read_data[1]);
159 LCD_PRINT("lcd_hx8369b_mipi read id 0xdb value is 0x%x!\n",read_data[1]);
161 read_rtn = mipi_force_read(0xdc,1,&read_data[2]);
162 LCD_PRINT("lcd_hx8369b_mipi read id 0xdc value is 0x%x!\n",read_data[2]);
164 if((0x55 == read_data[0])&&(0x0c == read_data[1])&&(0x90 == read_data[2])){
165 printk("lcd_hx8369b_mipi read id success!\n");
176 static int32_t hx8369b_enter_sleep(struct panel_spec *self, uint8_t is_sleep)
179 LCM_Init_Code *sleep_in_out = NULL;
183 mipi_set_cmd_mode_t mipi_set_cmd_mode = self->info.mipi->ops->mipi_set_cmd_mode;
184 mipi_dcs_write_t mipi_dcs_write = self->info.mipi->ops->mipi_dcs_write;
185 mipi_eotp_set_t mipi_eotp_set = self->info.mipi->ops->mipi_eotp_set;
187 printk("kernel hx8369b_enter_sleep, is_sleep = %d\n", is_sleep);
190 sleep_in_out = sleep_in;
191 size = ARRAY_SIZE(sleep_in);
193 sleep_in_out = sleep_out;
194 size = ARRAY_SIZE(sleep_out);
200 for(i = 0; i <size ; i++){
201 tag = (sleep_in_out->tag >>24);
202 if(tag & LCM_TAG_SEND){
203 mipi_dcs_write(sleep_in_out->data, (sleep_in_out->tag & LCM_TAG_MASK));
204 }else if(tag & LCM_TAG_SLEEP){
205 msleep(sleep_in_out->tag & LCM_TAG_MASK);
214 static struct panel_operations lcd_hx8369b_mipi_operations = {
215 .panel_init = hx8369b_mipi_init,
216 .panel_readid = hx8369b_readid,
217 .panel_enter_sleep = hx8369b_enter_sleep,
220 static struct timing_rgb lcd_hx8369b_mipi_timing = {
221 .hfp = 115, /* unit: pixel */
224 .vfp = 6, /*unit: line*/
230 static struct info_mipi lcd_hx8369b_mipi_info = {
231 .work_mode = SPRDFB_MIPI_MODE_VIDEO,
232 .video_bus_width = 24, /*18,16*/
235 .h_sync_pol = SPRDFB_POLARITY_POS,
236 .v_sync_pol = SPRDFB_POLARITY_POS,
237 .de_pol = SPRDFB_POLARITY_POS,
238 .te_pol = SPRDFB_POLARITY_POS,
239 .color_mode_pol = SPRDFB_POLARITY_NEG,
240 .shut_down_pol = SPRDFB_POLARITY_NEG,
241 .timing = &lcd_hx8369b_mipi_timing,
245 struct panel_spec lcd_hx8369b_mipi_spec = {
249 .type = LCD_MODE_DSI,
250 .direction = LCD_DIRECT_NORMAL,
252 .mipi = &lcd_hx8369b_mipi_info
254 .ops = &lcd_hx8369b_mipi_operations,
256 struct panel_cfg lcd_hx8369b_mipi = {
257 /* this panel can only be main lcd */
258 .dev_id = SPRDFB_MAINLCD_ID,
260 .lcd_name = "lcd_hx8369b_mipi",
261 .panel = &lcd_hx8369b_mipi_spec,
265 static int __init lcd_hx8369b_mipi_init(void)
268 printk("hx8369b_mipi_init: set lcd backlight.\n");
270 if (gpio_request(214, "LCD_BL")) {
271 printk("Failed ro request LCD_BL GPIO_%d \n",
275 gpio_direction_output(214, 1);
276 gpio_set_value(214, 1);
279 return sprdfb_panel_register(&lcd_hx8369b_mipi);
282 subsys_initcall(lcd_hx8369b_mipi_init);