2 * Copyright (C) 2014 ROCKCHIP, Inc.
3 * drivers/video/rockchip/screen/lcd_mipi.c
4 * author: libing@rock-chips.com
5 * create date: 2014-04-10
6 * This software is licensed under the terms of the GNU General Public
7 * License version 2, as published by the Free Software Foundation, and
8 * may be copied, distributed, and modified under those terms.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
16 #ifndef CONFIG_LCD_MIPI
19 #ifdef CONFIG_LCD_MIPI
20 #include "../transmitter/mipi_dsi.h"
21 #include <linux/delay.h>
23 #ifdef CONFIG_RK_3288_DSI_UBOOT
31 #include <asm/arch/rkplat.h>
33 #include "../transmitter/mipi_dsi.h"
36 #ifdef CONFIG_RK_3288_DSI_UBOOT
37 #define MIPI_SCREEN_DBG(x...) /* printf(x) */
38 #elif defined CONFIG_LCD_MIPI
39 #define MIPI_SCREEN_DBG(x...) /* printk(KERN_ERR x) */
41 #define MIPI_SCREEN_DBG(x...)
43 #ifdef CONFIG_RK_3288_DSI_UBOOT
44 DECLARE_GLOBAL_DATA_PTR;
45 #define printk(x...) /* printf(x) */
47 static struct mipi_screen *gmipi_screen;
49 static inline void mipidelay(unsigned int msecs)
51 usleep_range(msecs * 1000, msecs * 1000 + 200);
54 static void rk_mipi_screen_pwr_disable(struct mipi_screen *screen)
56 if (screen->lcd_en_gpio != INVALID_GPIO) {
57 gpio_direction_output(screen->lcd_en_gpio, !screen->lcd_en_atv_val);
58 mipidelay(screen->lcd_en_delay);
60 MIPI_SCREEN_DBG("lcd_en_gpio is null");
63 if (screen->lcd_rst_gpio != INVALID_GPIO) {
65 gpio_direction_output(screen->lcd_rst_gpio, !screen->lcd_rst_atv_val);
66 mipidelay(screen->lcd_rst_delay);
68 MIPI_SCREEN_DBG("lcd_rst_gpio is null");
72 static void rk_mipi_screen_pwr_enable(struct mipi_screen *screen)
74 if (screen->lcd_en_gpio != INVALID_GPIO) {
75 gpio_direction_output(screen->lcd_en_gpio, !screen->lcd_en_atv_val);
76 mipidelay(screen->lcd_en_delay);
77 gpio_direction_output(screen->lcd_en_gpio, screen->lcd_en_atv_val);
78 mipidelay(screen->lcd_en_delay);
80 MIPI_SCREEN_DBG("lcd_en_gpio is null\n");
82 if (screen->lcd_rst_gpio != INVALID_GPIO) {
83 gpio_direction_output(screen->lcd_rst_gpio, !screen->lcd_rst_atv_val);
84 mipidelay(screen->lcd_rst_delay);
85 gpio_direction_output(screen->lcd_rst_gpio, screen->lcd_rst_atv_val);
86 mipidelay(screen->lcd_rst_delay);
88 MIPI_SCREEN_DBG("lcd_rst_gpio is null\n");
91 static void rk_mipi_screen_cmd_init(struct mipi_screen *screen)
95 struct list_head *screen_pos;
96 struct mipi_dcs_cmd_ctr_list *dcs_cmd;
97 #ifdef CONFIG_RK_3288_DSI_UBOOT
98 cmds = calloc(1, 0x400);
100 printf("request cmds fail!\n");
105 #ifdef CONFIG_LCD_MIPI
106 cmds = kmalloc(0x400, GFP_KERNEL);
108 printk("request cmds fail!\n");
112 list_for_each(screen_pos, &screen->cmdlist_head) {
113 dcs_cmd = list_entry(screen_pos, struct mipi_dcs_cmd_ctr_list, list);
114 len = dcs_cmd->dcs_cmd.cmd_len + 1;
115 for (i = 1; i < len ; i++) {
116 cmds[i] = dcs_cmd->dcs_cmd.cmds[i-1];
118 MIPI_SCREEN_DBG("dcs_cmd.name:%s\n", dcs_cmd->dcs_cmd.name);
119 if (dcs_cmd->dcs_cmd.type == LPDT) {
121 if (dcs_cmd->dcs_cmd.dsi_id == 0) {
122 MIPI_SCREEN_DBG("dcs_cmd.dsi_id == 0 line=%d\n", __LINE__);
123 dsi_send_packet(0, cmds, len);
124 } else if (dcs_cmd->dcs_cmd.dsi_id == 1) {
125 MIPI_SCREEN_DBG("dcs_cmd.dsi_id == 1 line=%d\n", __LINE__);
126 dsi_send_packet(1, cmds, len);
127 } else if (dcs_cmd->dcs_cmd.dsi_id == 2) {
128 MIPI_SCREEN_DBG("dcs_cmd.dsi_id == 2 line=%d\n", __LINE__);
129 dsi_send_packet(0, cmds, len);
130 dsi_send_packet(1, cmds, len);
132 MIPI_SCREEN_DBG("dsi is err.\n");
134 if (dcs_cmd->dcs_cmd.delay)
135 mipidelay(dcs_cmd->dcs_cmd.delay);
136 } else if (dcs_cmd->dcs_cmd.type == HSDT) {
138 if (dcs_cmd->dcs_cmd.dsi_id == 0) {
139 MIPI_SCREEN_DBG("dcs_cmd.dsi_id == 0 line=%d\n", __LINE__);
140 dsi_send_packet(0, cmds, len);
141 } else if (dcs_cmd->dcs_cmd.dsi_id == 1) {
142 MIPI_SCREEN_DBG("dcs_cmd.dsi_id == 1 line=%d\n", __LINE__);
143 dsi_send_packet(1, cmds, len);
144 } else if (dcs_cmd->dcs_cmd.dsi_id == 2) {
145 MIPI_SCREEN_DBG("dcs_cmd.dsi_id == 2 line=%d\n", __LINE__);
146 dsi_send_packet(0, cmds, len);
147 dsi_send_packet(1, cmds, len);
149 MIPI_SCREEN_DBG("dsi is err.");
151 if (dcs_cmd->dcs_cmd.delay)
152 mipidelay(dcs_cmd->dcs_cmd.delay);
154 MIPI_SCREEN_DBG("cmd type err.\n");
157 #ifdef CONFIG_RK_3288_DSI_UBOOT
160 #ifdef CONFIG_LCD_MIPI
165 int rk_mipi_screen(void)
167 u8 dcs[16] = {0}, rk_dsi_num;
168 rk_dsi_num = gmipi_screen->mipi_dsi_num;
169 if (gmipi_screen->screen_init == 0) {
170 rk_mipi_screen_pwr_enable(gmipi_screen);
171 dsi_enable_hs_clk(0, 1);
172 if (rk_dsi_num == 2) {
173 dsi_enable_hs_clk(1, 1);
176 dsi_enable_command_mode(0, 1);
177 if (rk_dsi_num == 2) {
178 dsi_enable_command_mode(1, 1);
182 dcs[1] = DTYPE_DCS_SWRITE_0P;
183 dcs[2] = dcs_exit_sleep_mode;
184 dsi_send_packet(0, dcs, 3);
186 dsi_send_packet(1, dcs, 3);
191 dcs[1] = DTYPE_DCS_SWRITE_0P;
192 dcs[2] = dcs_set_display_on;
193 dsi_send_packet(0, dcs, 3);
195 dsi_send_packet(1, dcs, 3);
199 rk_mipi_screen_pwr_enable(gmipi_screen);
201 dsi_enable_hs_clk(0, 1);
202 if (rk_dsi_num == 2) {
203 dsi_enable_hs_clk(1, 1);
206 dsi_enable_command_mode(0, 1);
207 if (rk_dsi_num == 2) {
208 dsi_enable_command_mode(1, 1);
211 rk_mipi_screen_cmd_init(gmipi_screen);
214 MIPI_SCREEN_DBG("++++++++++++++++%s:%d\n", __func__, __LINE__);
218 int rk_mipi_screen_standby(u8 enable)
220 u8 dcs[16] = {0}, rk_dsi_num;
221 rk_dsi_num = gmipi_screen->mipi_dsi_num;
223 if (dsi_is_active(0) != 1)
227 if ((dsi_is_active(0) != 1) || (dsi_is_active(1) != 1))
231 /* below is changeable */
233 dcs[1] = DTYPE_DCS_SWRITE_0P;
234 dcs[2] = dcs_set_display_off;
235 dsi_send_packet(0, dcs, 3);
237 dsi_send_packet(1, dcs, 3);
242 dcs[1] = DTYPE_DCS_SWRITE_0P;
243 dcs[2] = dcs_enter_sleep_mode;
244 dsi_send_packet(0, dcs, 3);
246 dsi_send_packet(1, dcs, 3);
249 rk_mipi_screen_pwr_disable(gmipi_screen);
250 MIPI_SCREEN_DBG("++++enable++++++++++++%s:%d\n", __func__, __LINE__);
256 #ifdef CONFIG_LCD_MIPI
257 static int rk_mipi_screen_init_dt(struct device *dev,
258 struct mipi_screen *screen)
260 struct device_node *childnode, *grandchildnode, *root;
261 struct mipi_dcs_cmd_ctr_list *dcs_cmd;
262 struct list_head *pos;
263 struct property *prop;
264 enum of_gpio_flags flags;
265 u32 value, i, debug, gpio, ret, length;
267 memset(screen, 0, sizeof(*screen));
269 INIT_LIST_HEAD(&screen->cmdlist_head);
271 childnode = of_find_node_by_name(NULL, "mipi_dsi_init");
273 MIPI_SCREEN_DBG("%s: Can not get child => mipi_init.\n", __func__);
275 ret = of_property_read_u32(childnode, "rockchip,screen_init", &value);
277 MIPI_SCREEN_DBG("%s: Can not read property: screen_init.\n", __func__);
279 if ((value != 0) && (value != 1)) {
280 printk("err: rockchip,mipi_dsi_init not match.\n");
283 screen->screen_init = value ;
285 MIPI_SCREEN_DBG("%s: lcd->screen_init = %d.\n", __func__, screen->screen_init);
288 ret = of_property_read_u32(childnode, "rockchip,dsi_lane", &value);
290 MIPI_SCREEN_DBG("%s: Can not read property: dsi_lane.\n", __func__);
292 screen->dsi_lane = value;
293 MIPI_SCREEN_DBG("%s: mipi_lcd->dsi_lane = %d.\n", __func__, screen->dsi_lane);
296 ret = of_property_read_u32(childnode, "rockchip,dsi_hs_clk", &value);
298 MIPI_SCREEN_DBG("%s: Can not read property: dsi_hs_clk.\n", __func__);
300 if ((value <= 90) || (value >= 1500)) {
301 printk("err: rockchip,hs_tx_clk not match.");
304 screen->hs_tx_clk = value*MHz;
307 MIPI_SCREEN_DBG("%s: lcd->screen->hs_tx_clk = %d.\n", __func__, screen->hs_tx_clk);
310 ret = of_property_read_u32(childnode, "rockchip,mipi_dsi_num", &value);
312 MIPI_SCREEN_DBG("%s: Can not read property: mipi_dsi_num.\n", __func__);
314 if ((value != 1) && (value != 2)) {
315 printk("err: rockchip,mipi_dsi_num not match.\n");
318 screen->mipi_dsi_num = value ;
321 MIPI_SCREEN_DBG("%s: lcd->screen.mipi_dsi_num = %d.\n", __func__, screen->mipi_dsi_num);
325 childnode = of_find_node_by_name(NULL, "mipi_power_ctr");
327 screen->lcd_rst_gpio = INVALID_GPIO;
328 screen->lcd_en_gpio = INVALID_GPIO;
329 MIPI_SCREEN_DBG("%s: Can not get child => mipi_power_ctr.\n", __func__);
331 grandchildnode = of_find_node_by_name(childnode, "mipi_lcd_rst");
332 if (!grandchildnode) {
333 screen->lcd_rst_gpio = INVALID_GPIO;
334 MIPI_SCREEN_DBG("%s: Can not read property: mipi_lcd_rst.\n", __func__);
336 ret = of_property_read_u32(grandchildnode, "rockchip,delay", &value);
338 MIPI_SCREEN_DBG("%s: Can not read property: delay.\n", __func__);
340 screen->lcd_rst_delay = value;
341 MIPI_SCREEN_DBG("%s: lcd->screen->lcd_rst_delay = %d.\n", __func__, screen->lcd_rst_delay);
344 gpio = of_get_named_gpio_flags(grandchildnode, "rockchip,gpios", 0, &flags);
345 if (!gpio_is_valid(gpio)) {
346 MIPI_SCREEN_DBG("rest: Can not read property: %s->gpios.\n", __func__);
349 ret = gpio_request(gpio, "mipi_lcd_rst");
351 screen->lcd_rst_gpio = INVALID_GPIO;
352 MIPI_SCREEN_DBG("request mipi_lcd_rst gpio fail:%d\n", gpio);
356 screen->lcd_rst_gpio = gpio;
357 screen->lcd_rst_atv_val = (flags == GPIO_ACTIVE_HIGH) ? 1:0;
359 MIPI_SCREEN_DBG("lcd->lcd_rst_gpio=%d,dsi->lcd_rst_atv_val=%d\n", screen->lcd_rst_gpio, screen->lcd_rst_atv_val);
362 grandchildnode = of_find_node_by_name(childnode, "mipi_lcd_en");
363 if (!grandchildnode) {
364 screen->lcd_en_gpio = INVALID_GPIO;
365 MIPI_SCREEN_DBG("%s: Can not read property: mipi_lcd_en.\n", __func__);
367 ret = of_property_read_u32(grandchildnode, "rockchip,delay", &value);
369 MIPI_SCREEN_DBG("%s: Can not read property: mipi_lcd_en-delay.\n", __func__);
371 screen->lcd_en_delay = value;
372 MIPI_SCREEN_DBG("%s: lcd->screen.lcd_en_delay = %d.\n", __func__, screen->lcd_en_delay);
375 gpio = of_get_named_gpio_flags(grandchildnode, "rockchip,gpios", 0, &flags);
376 if (!gpio_is_valid(gpio)) {
377 MIPI_SCREEN_DBG("rest: Can not read property: %s->gpios.\n", __func__);
380 ret = gpio_request(gpio, "mipi_lcd_en");
382 screen->lcd_en_gpio = INVALID_GPIO;
383 MIPI_SCREEN_DBG("request mipi_lcd_en gpio fail:%d\n", gpio);
386 screen->lcd_en_gpio = gpio;
387 screen->lcd_en_atv_val = (flags == GPIO_ACTIVE_HIGH) ? 1:0;
388 MIPI_SCREEN_DBG("dsi->lcd_en_gpio=%d, dsi->screen.lcd_en_atv_val=%d\n", screen->lcd_en_gpio, screen->lcd_en_atv_val);
392 root = of_find_node_by_name(NULL, "screen-on-cmds");
394 MIPI_SCREEN_DBG("can't find screen-on-cmds node\n");
396 for_each_child_of_node(root, childnode) {
397 dcs_cmd = kmalloc(sizeof(struct mipi_dcs_cmd_ctr_list), GFP_KERNEL);
398 strcpy(dcs_cmd->dcs_cmd.name, childnode->name);
400 prop = of_find_property(childnode, "rockchip,cmd", &length);
402 MIPI_SCREEN_DBG("Can not read property: cmds\n");
406 MIPI_SCREEN_DBG("\n childnode->name =%s:length=%d\n", childnode->name, (length / sizeof(u32)));
408 dcs_cmd->dcs_cmd.cmds =
409 devm_kzalloc(dev, length, GFP_KERNEL);
410 if (!dcs_cmd->dcs_cmd.cmds) {
411 pr_err("malloc cmds fail!\n");
415 ret = of_property_read_u32_array(childnode,
417 dcs_cmd->dcs_cmd.cmds,
418 length / sizeof(u32));
420 MIPI_SCREEN_DBG("%s: Can not read property: %s--->cmds\n", __func__, childnode->name);
421 kfree(dcs_cmd->dcs_cmd.cmds);
422 dcs_cmd->dcs_cmd.cmds = NULL;
425 dcs_cmd->dcs_cmd.cmd_len = length / sizeof(u32);
427 ret = of_property_read_u32(childnode, "rockchip,dsi_id", &value);
429 MIPI_SCREEN_DBG("%s: Can not read property: %s--->cmd_type\n", __func__, childnode->name);
431 if (screen->mipi_dsi_num == 1) {
433 printk("err: rockchip,dsi_id not match.\n");
435 dcs_cmd->dcs_cmd.dsi_id = value;
438 if ((value < 0) || (value > 2))
439 printk("err: rockchip,dsi_id not match.\n");
441 dcs_cmd->dcs_cmd.dsi_id = value;
445 ret = of_property_read_u32(childnode, "rockchip,cmd_type", &value);
447 MIPI_SCREEN_DBG("%s: Can not read property: %s--->cmd_type\n", __func__, childnode->name);
449 if ((value != 0) && (value != 1)) {
450 printk("err: rockchip, cmd_type not match.\n");
452 dcs_cmd->dcs_cmd.type = value;
456 ret = of_property_read_u32(childnode, "rockchip,cmd_delay", &value);
458 MIPI_SCREEN_DBG("%s: Can not read property: %s--->cmd_delay\n", __func__, childnode->name);
460 dcs_cmd->dcs_cmd.delay = value;
462 list_add_tail(&dcs_cmd->list, &screen->cmdlist_head);
465 ret = of_property_read_u32(root, "rockchip,cmd_debug", &debug);
467 MIPI_SCREEN_DBG("%s: Can not read property: rockchip,cmd_debug.\n", __func__);
470 list_for_each(pos, &screen->cmdlist_head) {
471 dcs_cmd = list_entry(pos, struct mipi_dcs_cmd_ctr_list, list);
472 printk("\n dcs_name:%s,dcs_type:%d,side_id:%d,cmd_len:%d,delay:%d\n\n",
473 dcs_cmd->dcs_cmd.name,
474 dcs_cmd->dcs_cmd.type,
475 dcs_cmd->dcs_cmd.dsi_id,
476 dcs_cmd->dcs_cmd.cmd_len,
477 dcs_cmd->dcs_cmd.delay);
478 for (i = 0; i < (dcs_cmd->dcs_cmd.cmd_len); i++) {
479 printk("[%d]=%02x,", i+1, dcs_cmd->dcs_cmd.cmds[i]);
483 MIPI_SCREEN_DBG("---close cmd debug---\n");
489 int rk_mipi_get_dsi_num(void)
491 return gmipi_screen->mipi_dsi_num;
493 #ifdef CONFIG_LCD_MIPI
494 EXPORT_SYMBOL(rk_mipi_get_dsi_num);
497 int rk_mipi_get_dsi_lane(void)
499 return gmipi_screen->dsi_lane;
501 #ifdef CONFIG_LCD_MIPI
502 EXPORT_SYMBOL(rk_mipi_get_dsi_lane);
505 int rk_mipi_get_dsi_clk(void)
507 return gmipi_screen->hs_tx_clk;
509 #ifdef CONFIG_LCD_MIPI
510 EXPORT_SYMBOL(rk_mipi_get_dsi_clk);
512 #ifdef CONFIG_RK_3288_DSI_UBOOT
513 #ifdef CONFIG_OF_LIBFDT
514 static int rk_mipi_screen_init_dt(struct mipi_screen *screen)
516 struct mipi_dcs_cmd_ctr_list *dcs_cmd;
522 struct fdt_gpio_state gpio_val;
525 INIT_LIST_HEAD(&screen->cmdlist_head);
527 blob = gd->fdt_blob; /* getenv_hex("fdtaddr", 0); */
528 node = fdtdec_next_compatible(blob, 0, COMPAT_ROCKCHIP_MIPI_INIT);
530 MIPI_SCREEN_DBG("Can not get node of COMPAT_ROCKCHIP_MIPI_INIT\n");
532 screen->screen_init = fdtdec_get_int(blob, node, "rockchip,screen_init", -1);
533 if (screen->screen_init < 0) {
534 MIPI_SCREEN_DBG("Can not get screen_init\n");
536 screen->dsi_lane = fdtdec_get_int(blob, node, "rockchip,dsi_lane", -1);
537 if (screen->dsi_lane < 0) {
538 MIPI_SCREEN_DBG("Can not get dsi_lane\n");
540 screen->hs_tx_clk = fdtdec_get_int(blob, node, "rockchip,dsi_hs_clk", -1);
541 if (screen->hs_tx_clk < 0) {
542 MIPI_SCREEN_DBG("Can not get dsi_hs_clk\n");
544 screen->hs_tx_clk = screen->hs_tx_clk*MHZ;
546 screen->mipi_dsi_num = fdtdec_get_int(blob, node, "rockchip,mipi_dsi_num", -1);
547 if (screen->mipi_dsi_num < 0) {
548 MIPI_SCREEN_DBG("Can't get mipi_dsi_num\n");
551 node = fdtdec_next_compatible(blob, 0, COMPAT_ROCKCHIP_MIPI_PWR);
553 printf("Can not get node of COMPAT_ROCKCHIP_MIPI_PWR\n");
558 /*get the lcd rst status
559 handle = fdt_getprop_u32_default(blob, "/mipi_power_ctr", "mipi_lcd_rst", -1);
560 node = fdt_node_offset_by_phandle(blob, handle);
562 node = fdtdec_next_compatible(blob, 0, COMPAT_ROCKCHIP_MIPI_PWR);
564 printf("Can not get node of COMPAT_ROCKCHIP_MIPI_PWR\n");
566 subnode = fdtdec_next_compatible_subnode(blob, node,
567 COMPAT_ROCKCHIP_MIPI_LCD_RST, &depth);
569 screen->lcd_rst_gpio = INVALID_GPIO;
570 printf("Can't get pin of mipi_lcd_rst\n");
572 err = fdtdec_decode_gpio(blob, subnode, "rockchip,gpios", &gpio_val);
573 gpio_val.gpio = rk_gpio_base_to_bank(gpio_val.gpio & RK_GPIO_BANK_MASK) | (gpio_val.gpio & RK_GPIO_PIN_MASK);
575 screen->lcd_rst_gpio = INVALID_GPIO;
576 printf("Can't find GPIO rst\n");
578 screen->lcd_rst_gpio = gpio_val.gpio;
579 screen->lcd_rst_atv_val = !(gpio_val.flags & OF_GPIO_ACTIVE_LOW);
581 screen->lcd_rst_delay = fdtdec_get_int(blob, subnode, "rockchip,delay", -1);
582 if (screen->lcd_rst_delay < 0) {
583 printf("Can't get delay of rst delay\n");
585 printf("Get lcd rst gpio and delay successfully!\n");
589 /* get the lcd rst & en status */
590 node = fdtdec_next_compatible(blob, 0, COMPAT_ROCKCHIP_MIPI_PWR);
592 MIPI_SCREEN_DBG("Can not get node of COMPAT_ROCKCHIP_MIPI_PWR\n");
595 noffset = fdt_first_subnode(blob, node);
596 const char *name = fdt_get_name(blob, noffset, NULL);
597 printf("XJH_DEBUG1:%s\n", name);
598 noffset = fdt_next_subnode(blob, noffset);
599 const char *name1 = fdt_get_name(blob, noffset, NULL);
600 printf("XJH_DEBUG2:%s\n", name1);
602 for (noffset = fdt_first_subnode(blob, node);
604 noffset = fdt_next_subnode(blob, noffset)) {
605 if (0 == fdt_node_check_compatible(blob, noffset, "rockchip,lcd_rst")) {
606 err = fdtdec_decode_gpio(blob, noffset, "rockchip,gpios", &gpio_val);
607 gpio_val.gpio = rk_gpio_base_to_bank(gpio_val.gpio & RK_GPIO_BANK_MASK) | (gpio_val.gpio & RK_GPIO_PIN_MASK);
609 screen->lcd_rst_gpio = INVALID_GPIO;
610 MIPI_SCREEN_DBG("Can't find GPIO rst\n");
612 screen->lcd_rst_gpio = gpio_val.gpio;
613 screen->lcd_rst_atv_val = !(gpio_val.flags & OF_GPIO_ACTIVE_LOW);
615 screen->lcd_rst_delay = fdtdec_get_int(blob, noffset, "rockchip,delay", -1);
616 if (screen->lcd_rst_delay < 0) {
617 MIPI_SCREEN_DBG("Can't get delay of rst delay\n");
619 MIPI_SCREEN_DBG("Get lcd rst gpio and delay successfully!\n");
621 if (0 == fdt_node_check_compatible(blob, noffset, "rockchip,lcd_en")) {
622 err = fdtdec_decode_gpio(blob, noffset, "rockchip,gpios", &gpio_val);
623 gpio_val.gpio = rk_gpio_base_to_bank(gpio_val.gpio & RK_GPIO_BANK_MASK) | (gpio_val.gpio & RK_GPIO_PIN_MASK);
625 screen->lcd_en_gpio = INVALID_GPIO;
626 MIPI_SCREEN_DBG("Can't find GPIO en\n");
628 screen->lcd_en_gpio = gpio_val.gpio;
629 screen->lcd_en_atv_val = !(gpio_val.flags & OF_GPIO_ACTIVE_LOW);
631 screen->lcd_en_delay = fdtdec_get_int(blob, noffset, "rockchip,delay", -1);
632 if (screen->lcd_en_delay < 0) {
633 MIPI_SCREEN_DBG("Can't get delay of lcd_en delay\n");
635 MIPI_SCREEN_DBG("Get lcd en gpio and delay successfully:delay %d!\n", screen->lcd_en_delay);
640 /*get the initial command list*/
641 node = fdtdec_next_compatible(blob, 0, COMPAT_ROCKCHIP_MIPI_SONCMDS);
643 MIPI_SCREEN_DBG("Can not get node of COMPAT_ROCKCHIP_MIPI_SONCMDS\n");
645 for (noffset = fdt_first_subnode(blob, node);
647 noffset = fdt_next_subnode(blob, noffset)) {
649 MIPI_SCREEN_DBG("build MIPI LCD init cmd tables\n");
651 subnode = fdtdec_next_compatible_subnode(blob, node,
652 COMPAT_ROCKCHIP_MIPI_ONCMDS, &depth);
656 dcs_cmd = calloc(1, sizeof(struct mipi_dcs_cmd_ctr_list));
657 /* node = fdt_node_offset_by_phandle(blob, handle); */
658 strcpy(dcs_cmd->dcs_cmd.name, fdt_get_name(blob, noffset, NULL));
659 MIPI_SCREEN_DBG("%s\n", dcs_cmd->dcs_cmd.name);
660 dcs_cmd->dcs_cmd.type = fdtdec_get_int(blob, noffset, "rockchip,cmd_type", -1);
661 MIPI_SCREEN_DBG("dcs_cmd.type=%02x\n", dcs_cmd->dcs_cmd.type);
662 dcs_cmd->dcs_cmd.dsi_id = fdtdec_get_int(blob, noffset, "rockchip,dsi_id", -1);
663 MIPI_SCREEN_DBG("dcs_cmd.dsi_id=%02x\n", dcs_cmd->dcs_cmd.dsi_id);
664 fdt_getprop(blob, noffset, "rockchip,cmd", &length);
665 dcs_cmd->dcs_cmd.cmd_len = length / sizeof(u32) ;
667 dcs_cmd->dcs_cmd.cmds = calloc(1, length);
668 if (!dcs_cmd->dcs_cmd.cmds) {
669 pr_err("calloc cmds fail!\n");
673 err = fdtdec_get_int_array(blob, noffset,
675 dcs_cmd->dcs_cmd.cmds,
676 dcs_cmd->dcs_cmd.cmd_len);
677 dcs_cmd->dcs_cmd.delay = fdtdec_get_int(blob, noffset, "rockchip,cmd_delay", -1);
678 MIPI_SCREEN_DBG("dcs_cmd.delay=%d\n", dcs_cmd->dcs_cmd.delay);
679 list_add_tail(&dcs_cmd->list, &screen->cmdlist_head);
684 #endif /* CONFIG_OF_LIBFDT */
686 int rk_mipi_screen_probe(void)
689 gmipi_screen = calloc(1, sizeof(struct mipi_screen));
691 printf("request struct screen fail!\n");
694 #ifdef CONFIG_OF_LIBFDT
695 ret = rk_mipi_screen_init_dt(gmipi_screen);
697 printf(" rk_mipi_screen_init_dt fail!\n");
700 #endif /* CONFIG_OF_LIBFDT */
702 MIPI_SCREEN_DBG("---rk_mipi_screen_probe--end\n");
706 #endif /* CONFIG_RK_3288_DSI_UBOOT */
707 #ifdef CONFIG_LCD_MIPI
708 static int __init rk_mipi_screen_probe(struct platform_device *pdev)
712 gmipi_screen = devm_kzalloc(&pdev->dev, sizeof(struct mipi_screen), GFP_KERNEL);
714 dev_err(&pdev->dev, "request struct screen fail!\n");
718 ret = rk_mipi_screen_init_dt(&pdev->dev, gmipi_screen);
720 dev_err(&pdev->dev, " rk_mipi_screen_init_dt fail!\n");
724 MIPI_SCREEN_DBG("---rk_mipi_screen_probe--end\n");
728 static struct platform_driver mipi_screen_platform_driver = {
730 .name = "rk_mipi_screen",
734 static int __init rk_mipi_screen_init(void)
736 platform_device_register_simple("rk_mipi_screen", -1, NULL, 0);
737 return platform_driver_probe(&mipi_screen_platform_driver, rk_mipi_screen_probe);
740 static void __exit rk_mipi_screen_exit(void)
742 platform_driver_unregister(&mipi_screen_platform_driver);
745 subsys_initcall_sync(rk_mipi_screen_init);
746 module_exit(rk_mipi_screen_exit);