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 msleep(a) udelay(a * 1000)
46 #define printk(x...) /* printf(x) */
48 static struct mipi_screen *gmipi_screen;
50 static void rk_mipi_screen_pwr_disable(struct mipi_screen *screen)
52 if (screen->lcd_en_gpio != INVALID_GPIO) {
53 gpio_direction_output(screen->lcd_en_gpio, !screen->lcd_en_atv_val);
54 msleep(screen->lcd_en_delay);
56 MIPI_SCREEN_DBG("lcd_en_gpio is null");
59 if (screen->lcd_rst_gpio != INVALID_GPIO) {
61 gpio_direction_output(screen->lcd_rst_gpio, !screen->lcd_rst_atv_val);
62 msleep(screen->lcd_rst_delay);
64 MIPI_SCREEN_DBG("lcd_rst_gpio is null");
68 static void rk_mipi_screen_pwr_enable(struct mipi_screen *screen)
70 if (screen->lcd_en_gpio != INVALID_GPIO) {
71 gpio_direction_output(screen->lcd_en_gpio, !screen->lcd_en_atv_val);
72 msleep(screen->lcd_en_delay);
73 gpio_direction_output(screen->lcd_en_gpio, screen->lcd_en_atv_val);
74 msleep(screen->lcd_en_delay);
76 MIPI_SCREEN_DBG("lcd_en_gpio is null\n");
78 if (screen->lcd_rst_gpio != INVALID_GPIO) {
79 gpio_direction_output(screen->lcd_rst_gpio, !screen->lcd_rst_atv_val);
80 msleep (screen->lcd_rst_delay);
81 gpio_direction_output(screen->lcd_rst_gpio, screen->lcd_rst_atv_val);
82 msleep(screen->lcd_rst_delay);
84 MIPI_SCREEN_DBG("lcd_rst_gpio is null\n");
87 static void rk_mipi_screen_cmd_init(struct mipi_screen *screen)
91 struct list_head *screen_pos;
92 struct mipi_dcs_cmd_ctr_list *dcs_cmd;
93 #ifdef CONFIG_RK_3288_DSI_UBOOT
94 cmds = calloc(1, 0x400);
96 printf("request cmds fail!\n");
101 #ifdef CONFIG_LCD_MIPI
102 cmds = kmalloc(0x400, GFP_KERNEL);
104 printk("request cmds fail!\n");
108 list_for_each(screen_pos, &screen->cmdlist_head) {
109 dcs_cmd = list_entry(screen_pos, struct mipi_dcs_cmd_ctr_list, list);
110 len = dcs_cmd->dcs_cmd.cmd_len + 1;
111 for (i = 1; i < len ; i++) {
112 cmds[i] = dcs_cmd->dcs_cmd.cmds[i-1];
114 MIPI_SCREEN_DBG("dcs_cmd.name:%s\n", dcs_cmd->dcs_cmd.name);
115 if (dcs_cmd->dcs_cmd.type == LPDT) {
117 if (dcs_cmd->dcs_cmd.dsi_id == 0) {
118 MIPI_SCREEN_DBG("dcs_cmd.dsi_id == 0 line=%d\n", __LINE__);
119 dsi_send_packet(0, cmds, len);
120 } else if (dcs_cmd->dcs_cmd.dsi_id == 1) {
121 MIPI_SCREEN_DBG("dcs_cmd.dsi_id == 1 line=%d\n", __LINE__);
122 dsi_send_packet(1, cmds, len);
123 } else if (dcs_cmd->dcs_cmd.dsi_id == 2) {
124 MIPI_SCREEN_DBG("dcs_cmd.dsi_id == 2 line=%d\n", __LINE__);
125 dsi_send_packet(0, cmds, len);
126 dsi_send_packet(1, cmds, len);
128 MIPI_SCREEN_DBG("dsi is err.\n");
130 msleep(dcs_cmd->dcs_cmd.delay);
131 } else if (dcs_cmd->dcs_cmd.type == HSDT) {
133 if (dcs_cmd->dcs_cmd.dsi_id == 0) {
134 MIPI_SCREEN_DBG("dcs_cmd.dsi_id == 0 line=%d\n", __LINE__);
135 dsi_send_packet(0, cmds, len);
136 } else if (dcs_cmd->dcs_cmd.dsi_id == 1) {
137 MIPI_SCREEN_DBG("dcs_cmd.dsi_id == 1 line=%d\n", __LINE__);
138 dsi_send_packet(1, cmds, len);
139 } else if (dcs_cmd->dcs_cmd.dsi_id == 2) {
140 MIPI_SCREEN_DBG("dcs_cmd.dsi_id == 2 line=%d\n", __LINE__);
141 dsi_send_packet(0, cmds, len);
142 dsi_send_packet(1, cmds, len);
144 MIPI_SCREEN_DBG("dsi is err.");
146 msleep(dcs_cmd->dcs_cmd.delay);
148 MIPI_SCREEN_DBG("cmd type err.\n");
151 #ifdef CONFIG_RK_3288_DSI_UBOOT
154 #ifdef CONFIG_LCD_MIPI
159 int rk_mipi_screen(void)
161 u8 dcs[16] = {0}, rk_dsi_num;
162 rk_dsi_num = gmipi_screen->mipi_dsi_num;
163 if (gmipi_screen->screen_init == 0) {
164 rk_mipi_screen_pwr_enable(gmipi_screen);
165 dsi_enable_hs_clk(0, 1);
166 if (rk_dsi_num == 2) {
167 dsi_enable_hs_clk(1, 1);
170 dsi_enable_video_mode(0, 0);
171 if (rk_dsi_num == 2) {
172 dsi_enable_video_mode(1, 0);
175 dsi_enable_command_mode(0, 1);
176 if (rk_dsi_num == 2) {
177 dsi_enable_command_mode(1, 1);
181 dcs[1] = DTYPE_DCS_SWRITE_0P;
182 dcs[2] = dcs_exit_sleep_mode;
183 dsi_send_packet(0, dcs, 3);
185 dsi_send_packet(1, dcs, 3);
190 dcs[1] = DTYPE_DCS_SWRITE_0P;
191 dcs[2] = dcs_set_display_on;
192 dsi_send_packet(0, dcs, 3);
194 dsi_send_packet(1, dcs, 3);
198 dsi_enable_command_mode(0, 0);
199 if (rk_dsi_num == 2) {
200 dsi_enable_command_mode(1, 0);
203 dsi_enable_video_mode(0, 1);
204 if (rk_dsi_num == 2) {
205 dsi_enable_video_mode(1, 1);
208 rk_mipi_screen_pwr_enable(gmipi_screen);
210 dsi_enable_hs_clk(0, 1);
211 if (rk_dsi_num == 2) {
212 dsi_enable_hs_clk(1, 1);
215 dsi_enable_video_mode(0, 0);
216 if (rk_dsi_num == 2) {
217 dsi_enable_video_mode(1, 0);
220 dsi_enable_command_mode(0, 1);
221 if (rk_dsi_num == 2) {
222 dsi_enable_command_mode(1, 1);
225 rk_mipi_screen_cmd_init(gmipi_screen);
227 dsi_enable_command_mode(0, 0);
228 if (rk_dsi_num == 2) {
229 dsi_enable_command_mode(1, 0);
232 dsi_enable_video_mode(0, 1);
233 if (rk_dsi_num == 2) {
234 dsi_enable_video_mode(1, 1);
238 MIPI_SCREEN_DBG("++++++++++++++++%s:%d\n", __func__, __LINE__);
242 int rk_mipi_screen_standby(u8 enable)
244 u8 dcs[16] = {0}, rk_dsi_num;
245 rk_dsi_num = gmipi_screen->mipi_dsi_num;
247 if (dsi_is_active(0) != 1)
251 if ((dsi_is_active(0) != 1) || (dsi_is_active(1) != 1))
255 /* below is changeable */
257 dcs[1] = DTYPE_DCS_SWRITE_0P;
258 dcs[2] = dcs_set_display_off;
259 dsi_send_packet(0, dcs, 3);
261 dsi_send_packet(1, dcs, 3);
266 dcs[1] = DTYPE_DCS_SWRITE_0P;
267 dcs[2] = dcs_enter_sleep_mode;
268 dsi_send_packet(0, dcs, 3);
270 dsi_send_packet(1, dcs, 3);
273 rk_mipi_screen_pwr_disable(gmipi_screen);
274 MIPI_SCREEN_DBG("++++enable++++++++++++%s:%d\n", __func__, __LINE__);
280 #ifdef CONFIG_LCD_MIPI
281 static int rk_mipi_screen_init_dt(struct mipi_screen *screen)
283 struct device_node *childnode, *grandchildnode, *root;
284 struct mipi_dcs_cmd_ctr_list *dcs_cmd;
285 struct list_head *pos;
286 struct property *prop;
287 enum of_gpio_flags flags;
288 u32 value, i, debug, gpio, ret, cmds[25], length;
290 memset(screen, 0, sizeof(*screen));
292 INIT_LIST_HEAD(&screen->cmdlist_head);
294 childnode = of_find_node_by_name(NULL, "mipi_dsi_init");
296 MIPI_SCREEN_DBG("%s: Can not get child => mipi_init.\n", __func__);
298 ret = of_property_read_u32(childnode, "rockchip,screen_init", &value);
300 MIPI_SCREEN_DBG("%s: Can not read property: screen_init.\n", __func__);
302 if ((value != 0) && (value != 1)) {
303 printk("err: rockchip,mipi_dsi_init not match.\n");
306 screen->screen_init = value ;
308 MIPI_SCREEN_DBG("%s: lcd->screen_init = %d.\n", __func__, screen->screen_init);
311 ret = of_property_read_u32(childnode, "rockchip,dsi_lane", &value);
313 MIPI_SCREEN_DBG("%s: Can not read property: dsi_lane.\n", __func__);
315 screen->dsi_lane = value;
316 MIPI_SCREEN_DBG("%s: mipi_lcd->dsi_lane = %d.\n", __func__, screen->dsi_lane);
319 ret = of_property_read_u32(childnode, "rockchip,dsi_hs_clk", &value);
321 MIPI_SCREEN_DBG("%s: Can not read property: dsi_hs_clk.\n", __func__);
323 if ((value <= 90) || (value >= 1500)) {
324 printk("err: rockchip,hs_tx_clk not match.");
327 screen->hs_tx_clk = value*MHz;
330 MIPI_SCREEN_DBG("%s: lcd->screen->hs_tx_clk = %d.\n", __func__, screen->hs_tx_clk);
333 ret = of_property_read_u32(childnode, "rockchip,mipi_dsi_num", &value);
335 MIPI_SCREEN_DBG("%s: Can not read property: mipi_dsi_num.\n", __func__);
337 if ((value != 1) && (value != 2)) {
338 printk("err: rockchip,mipi_dsi_num not match.\n");
341 screen->mipi_dsi_num = value ;
344 MIPI_SCREEN_DBG("%s: lcd->screen.mipi_dsi_num = %d.\n", __func__, screen->mipi_dsi_num);
348 childnode = of_find_node_by_name(NULL, "mipi_power_ctr");
350 screen->lcd_rst_gpio = INVALID_GPIO;
351 screen->lcd_en_gpio = INVALID_GPIO;
352 MIPI_SCREEN_DBG("%s: Can not get child => mipi_power_ctr.\n", __func__);
354 grandchildnode = of_get_child_by_name(childnode, "mipi_lcd_rst");
355 if (!grandchildnode) {
356 screen->lcd_rst_gpio = INVALID_GPIO;
357 MIPI_SCREEN_DBG("%s: Can not read property: mipi_lcd_rst.\n", __func__);
359 ret = of_property_read_u32(grandchildnode, "rockchip,delay", &value);
361 MIPI_SCREEN_DBG("%s: Can not read property: delay.\n", __func__);
363 screen->lcd_rst_delay = value;
364 MIPI_SCREEN_DBG("%s: lcd->screen->lcd_rst_delay = %d.\n", __func__, screen->lcd_rst_delay);
367 gpio = of_get_named_gpio_flags(grandchildnode, "rockchip,gpios", 0, &flags);
368 if (!gpio_is_valid(gpio)) {
369 MIPI_SCREEN_DBG("rest: Can not read property: %s->gpios.\n", __func__);
372 ret = gpio_request(gpio, "mipi_lcd_rst");
374 screen->lcd_rst_gpio = INVALID_GPIO;
375 MIPI_SCREEN_DBG("request mipi_lcd_rst gpio fail:%d\n", gpio);
379 screen->lcd_rst_gpio = gpio;
380 screen->lcd_rst_atv_val = (flags == GPIO_ACTIVE_HIGH) ? 1:0;
382 MIPI_SCREEN_DBG("lcd->lcd_rst_gpio=%d,dsi->lcd_rst_atv_val=%d\n", screen->lcd_rst_gpio, screen->lcd_rst_atv_val);
385 grandchildnode = of_get_child_by_name(childnode, "mipi_lcd_en");
386 if (!grandchildnode) {
387 screen->lcd_en_gpio = INVALID_GPIO;
388 MIPI_SCREEN_DBG("%s: Can not read property: mipi_lcd_en.\n", __func__);
390 ret = of_property_read_u32(grandchildnode, "rockchip,delay", &value);
392 MIPI_SCREEN_DBG("%s: Can not read property: mipi_lcd_en-delay.\n", __func__);
394 screen->lcd_en_delay = value;
395 MIPI_SCREEN_DBG("%s: lcd->screen.lcd_en_delay = %d.\n", __func__, screen->lcd_en_delay);
398 gpio = of_get_named_gpio_flags(grandchildnode, "rockchip,gpios", 0, &flags);
399 if (!gpio_is_valid(gpio)) {
400 MIPI_SCREEN_DBG("rest: Can not read property: %s->gpios.\n", __func__);
403 ret = gpio_request(gpio, "mipi_lcd_en");
405 screen->lcd_en_gpio = INVALID_GPIO;
406 MIPI_SCREEN_DBG("request mipi_lcd_en gpio fail:%d\n", gpio);
409 screen->lcd_en_gpio = gpio;
410 screen->lcd_en_atv_val = (flags == GPIO_ACTIVE_HIGH) ? 1:0;
411 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);
415 root = of_find_node_by_name(NULL, "screen-on-cmds");
417 MIPI_SCREEN_DBG("can't find screen-on-cmds node\n");
419 for_each_child_of_node(root, childnode) {
420 dcs_cmd = kmalloc(sizeof(struct mipi_dcs_cmd_ctr_list), GFP_KERNEL);
421 strcpy(dcs_cmd->dcs_cmd.name, childnode->name);
423 prop = of_find_property(childnode, "rockchip,cmd", &length);
425 MIPI_SCREEN_DBG("Can not read property: cmds\n");
429 MIPI_SCREEN_DBG("\n childnode->name =%s:length=%d\n", childnode->name, (length / sizeof(u32)));
431 ret = of_property_read_u32_array(childnode, "rockchip,cmd", cmds, (length / sizeof(u32)));
433 MIPI_SCREEN_DBG("%s: Can not read property: %s--->cmds\n", __func__, childnode->name);
436 dcs_cmd->dcs_cmd.cmd_len = length / sizeof(u32);
437 for (i = 0; i < (length / sizeof(u32)); i++) {
438 MIPI_SCREEN_DBG("cmd[%d]=%02x£¬", i+1, cmds[i]);
439 dcs_cmd->dcs_cmd.cmds[i] = cmds[i];
442 MIPI_SCREEN_DBG("dcs_cmd->dcs_cmd.cmd_len=%d\n", dcs_cmd->dcs_cmd.cmd_len);
444 ret = of_property_read_u32(childnode, "rockchip,dsi_id", &value);
446 MIPI_SCREEN_DBG("%s: Can not read property: %s--->cmd_type\n", __func__, childnode->name);
448 if (screen->mipi_dsi_num == 1) {
450 printk("err: rockchip,dsi_id not match.\n");
452 dcs_cmd->dcs_cmd.dsi_id = value;
455 if ((value < 0) || (value > 2))
456 printk("err: rockchip,dsi_id not match.\n");
458 dcs_cmd->dcs_cmd.dsi_id = value;
462 ret = of_property_read_u32(childnode, "rockchip,cmd_type", &value);
464 MIPI_SCREEN_DBG("%s: Can not read property: %s--->cmd_type\n", __func__, childnode->name);
466 if ((value != 0) && (value != 1)) {
467 printk("err: rockchip, cmd_type not match.\n");
469 dcs_cmd->dcs_cmd.type = value;
473 ret = of_property_read_u32(childnode, "rockchip,cmd_delay", &value);
475 MIPI_SCREEN_DBG("%s: Can not read property: %s--->cmd_delay\n", __func__, childnode->name);
477 dcs_cmd->dcs_cmd.delay = value;
479 list_add_tail(&dcs_cmd->list, &screen->cmdlist_head);
482 ret = of_property_read_u32(root, "rockchip,cmd_debug", &debug);
484 MIPI_SCREEN_DBG("%s: Can not read property: rockchip,cmd_debug.\n", __func__);
487 list_for_each(pos, &screen->cmdlist_head) {
488 dcs_cmd = list_entry(pos, struct mipi_dcs_cmd_ctr_list, list);
489 printk("\n dcs_name:%s,dcs_type:%d,side_id:%d,cmd_len:%d,delay:%d\n\n",
490 dcs_cmd->dcs_cmd.name,
491 dcs_cmd->dcs_cmd.type,
492 dcs_cmd->dcs_cmd.dsi_id,
493 dcs_cmd->dcs_cmd.cmd_len,
494 dcs_cmd->dcs_cmd.delay);
495 for (i = 0; i < (dcs_cmd->dcs_cmd.cmd_len); i++) {
496 printk("[%d]=%02x,", i+1, dcs_cmd->dcs_cmd.cmds[i]);
500 MIPI_SCREEN_DBG("---close cmd debug---\n");
506 int rk_mipi_get_dsi_num(void)
508 return gmipi_screen->mipi_dsi_num;
510 #ifdef CONFIG_LCD_MIPI
511 EXPORT_SYMBOL(rk_mipi_get_dsi_num);
513 int rk_mipi_get_dsi_lane(void)
515 return gmipi_screen->dsi_lane;
517 #ifdef CONFIG_LCD_MIPI
518 EXPORT_SYMBOL(rk_mipi_get_dsi_lane);
521 int rk_mipi_get_dsi_clk(void)
523 return gmipi_screen->hs_tx_clk;
525 #ifdef CONFIG_LCD_MIPI
526 EXPORT_SYMBOL(rk_mipi_get_dsi_clk);
528 #ifdef CONFIG_RK_3288_DSI_UBOOT
529 #ifdef CONFIG_OF_LIBFDT
530 static int rk_mipi_screen_init_dt(struct mipi_screen *screen)
532 struct mipi_dcs_cmd_ctr_list *dcs_cmd;
538 struct fdt_gpio_state gpio_val;
541 INIT_LIST_HEAD(&screen->cmdlist_head);
543 blob = gd->fdt_blob; /* getenv_hex("fdtaddr", 0); */
544 node = fdtdec_next_compatible(blob, 0, COMPAT_ROCKCHIP_MIPI_INIT);
546 MIPI_SCREEN_DBG("Can not get node of COMPAT_ROCKCHIP_MIPI_INIT\n");
548 screen->screen_init = fdtdec_get_int(blob, node, "rockchip,screen_init", -1);
549 if (screen->screen_init < 0) {
550 MIPI_SCREEN_DBG("Can not get screen_init\n");
552 screen->dsi_lane = fdtdec_get_int(blob, node, "rockchip,dsi_lane", -1);
553 if (screen->dsi_lane < 0) {
554 MIPI_SCREEN_DBG("Can not get dsi_lane\n");
556 screen->hs_tx_clk = fdtdec_get_int(blob, node, "rockchip,dsi_hs_clk", -1);
557 if (screen->hs_tx_clk < 0) {
558 MIPI_SCREEN_DBG("Can not get dsi_hs_clk\n");
560 screen->hs_tx_clk = screen->hs_tx_clk*MHZ;
562 screen->mipi_dsi_num = fdtdec_get_int(blob, node, "rockchip,mipi_dsi_num", -1);
563 if (screen->mipi_dsi_num < 0) {
564 MIPI_SCREEN_DBG("Can't get mipi_dsi_num\n");
567 node = fdtdec_next_compatible(blob, 0, COMPAT_ROCKCHIP_MIPI_PWR);
569 printf("Can not get node of COMPAT_ROCKCHIP_MIPI_PWR\n");
574 /*get the lcd rst status
575 handle = fdt_getprop_u32_default(blob, "/mipi_power_ctr", "mipi_lcd_rst", -1);
576 node = fdt_node_offset_by_phandle(blob, handle);
578 node = fdtdec_next_compatible(blob, 0, COMPAT_ROCKCHIP_MIPI_PWR);
580 printf("Can not get node of COMPAT_ROCKCHIP_MIPI_PWR\n");
582 subnode = fdtdec_next_compatible_subnode(blob, node,
583 COMPAT_ROCKCHIP_MIPI_LCD_RST, &depth);
585 screen->lcd_rst_gpio = INVALID_GPIO;
586 printf("Can't get pin of mipi_lcd_rst\n");
588 err = fdtdec_decode_gpio(blob, subnode, "rockchip,gpios", &gpio_val);
589 gpio_val.gpio = rk_gpio_base_to_bank(gpio_val.gpio & RK_GPIO_BANK_MASK) | (gpio_val.gpio & RK_GPIO_PIN_MASK);
591 screen->lcd_rst_gpio = INVALID_GPIO;
592 printf("Can't find GPIO rst\n");
594 screen->lcd_rst_gpio = gpio_val.gpio;
595 screen->lcd_rst_atv_val = !(gpio_val.flags & OF_GPIO_ACTIVE_LOW);
597 screen->lcd_rst_delay = fdtdec_get_int(blob, subnode, "rockchip,delay", -1);
598 if (screen->lcd_rst_delay < 0) {
599 printf("Can't get delay of rst delay\n");
601 printf("Get lcd rst gpio and delay successfully!\n");
605 /* get the lcd rst & en status */
606 node = fdtdec_next_compatible(blob, 0, COMPAT_ROCKCHIP_MIPI_PWR);
608 MIPI_SCREEN_DBG("Can not get node of COMPAT_ROCKCHIP_MIPI_PWR\n");
611 noffset = fdt_first_subnode(blob, node);
612 const char *name = fdt_get_name(blob, noffset, NULL);
613 printf("XJH_DEBUG1:%s\n", name);
614 noffset = fdt_next_subnode(blob, noffset);
615 const char *name1 = fdt_get_name(blob, noffset, NULL);
616 printf("XJH_DEBUG2:%s\n", name1);
618 for (noffset = fdt_first_subnode(blob, node);
620 noffset = fdt_next_subnode(blob, noffset)) {
621 if (0 == fdt_node_check_compatible(blob, noffset, "rockchip,lcd_rst")) {
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_rst_gpio = INVALID_GPIO;
626 MIPI_SCREEN_DBG("Can't find GPIO rst\n");
628 screen->lcd_rst_gpio = gpio_val.gpio;
629 screen->lcd_rst_atv_val = !(gpio_val.flags & OF_GPIO_ACTIVE_LOW);
631 screen->lcd_rst_delay = fdtdec_get_int(blob, noffset, "rockchip,delay", -1);
632 if (screen->lcd_rst_delay < 0) {
633 MIPI_SCREEN_DBG("Can't get delay of rst delay\n");
635 MIPI_SCREEN_DBG("Get lcd rst gpio and delay successfully!\n");
637 if (0 == fdt_node_check_compatible(blob, noffset, "rockchip,lcd_en")) {
638 err = fdtdec_decode_gpio(blob, noffset, "rockchip,gpios", &gpio_val);
639 gpio_val.gpio = rk_gpio_base_to_bank(gpio_val.gpio & RK_GPIO_BANK_MASK) | (gpio_val.gpio & RK_GPIO_PIN_MASK);
641 screen->lcd_en_gpio = INVALID_GPIO;
642 MIPI_SCREEN_DBG("Can't find GPIO en\n");
644 screen->lcd_en_gpio = gpio_val.gpio;
645 screen->lcd_en_atv_val = !(gpio_val.flags & OF_GPIO_ACTIVE_LOW);
647 screen->lcd_en_delay = fdtdec_get_int(blob, noffset, "rockchip,delay", -1);
648 if (screen->lcd_en_delay < 0) {
649 MIPI_SCREEN_DBG("Can't get delay of lcd_en delay\n");
651 MIPI_SCREEN_DBG("Get lcd en gpio and delay successfully:delay %d!\n", screen->lcd_en_delay);
656 /*get the initial command list*/
657 node = fdtdec_next_compatible(blob, 0, COMPAT_ROCKCHIP_MIPI_SONCMDS);
659 MIPI_SCREEN_DBG("Can not get node of COMPAT_ROCKCHIP_MIPI_SONCMDS\n");
661 for (noffset = fdt_first_subnode(blob, node);
663 noffset = fdt_next_subnode(blob, noffset)) {
665 MIPI_SCREEN_DBG("build MIPI LCD init cmd tables\n");
667 subnode = fdtdec_next_compatible_subnode(blob, node,
668 COMPAT_ROCKCHIP_MIPI_ONCMDS, &depth);
672 dcs_cmd = calloc(1, sizeof(struct mipi_dcs_cmd_ctr_list));
673 /* node = fdt_node_offset_by_phandle(blob, handle); */
674 strcpy(dcs_cmd->dcs_cmd.name, fdt_get_name(blob, noffset, NULL));
675 MIPI_SCREEN_DBG("%s\n", dcs_cmd->dcs_cmd.name);
676 dcs_cmd->dcs_cmd.type = fdtdec_get_int(blob, noffset, "rockchip,cmd_type", -1);
677 MIPI_SCREEN_DBG("dcs_cmd.type=%02x\n", dcs_cmd->dcs_cmd.type);
678 dcs_cmd->dcs_cmd.dsi_id = fdtdec_get_int(blob, noffset, "rockchip,dsi_id", -1);
679 MIPI_SCREEN_DBG("dcs_cmd.dsi_id=%02x\n", dcs_cmd->dcs_cmd.dsi_id);
680 fdt_getprop(blob, noffset, "rockchip,cmd", &length);
681 dcs_cmd->dcs_cmd.cmd_len = length / sizeof(u32) ;
682 err = fdtdec_get_int_array(blob, noffset, "rockchip,cmd", cmds, dcs_cmd->dcs_cmd.cmd_len);
683 MIPI_SCREEN_DBG("length=%d,cmd_len = %d err = %d\n", length, dcs_cmd->dcs_cmd.cmd_len, err);
684 for (i = 0; i < (length / sizeof(u32)); i++) {
685 MIPI_SCREEN_DBG("cmd[%d]=0x%08x, ", i+1, cmds[i]);
686 dcs_cmd->dcs_cmd.cmds[i] = cmds[i];
688 MIPI_SCREEN_DBG("\n");
689 dcs_cmd->dcs_cmd.delay = fdtdec_get_int(blob, noffset, "rockchip,cmd_delay", -1);
690 MIPI_SCREEN_DBG("dcs_cmd.delay=%d\n", dcs_cmd->dcs_cmd.delay);
691 list_add_tail(&dcs_cmd->list, &screen->cmdlist_head);
696 #endif /* CONFIG_OF_LIBFDT */
698 int rk_mipi_screen_probe(void)
701 gmipi_screen = calloc(1, sizeof(struct mipi_screen));
703 printf("request struct screen fail!\n");
706 #ifdef CONFIG_OF_LIBFDT
707 ret = rk_mipi_screen_init_dt(gmipi_screen);
709 printf(" rk_mipi_screen_init_dt fail!\n");
712 #endif /* CONFIG_OF_LIBFDT */
714 MIPI_SCREEN_DBG("---rk_mipi_screen_probe--end\n");
718 #endif /* CONFIG_RK_3288_DSI_UBOOT */
719 #ifdef CONFIG_LCD_MIPI
720 static int __init rk_mipi_screen_probe(struct platform_device *pdev)
724 gmipi_screen = devm_kzalloc(&pdev->dev, sizeof(struct mipi_screen), GFP_KERNEL);
726 dev_err(&pdev->dev, "request struct screen fail!\n");
730 ret = rk_mipi_screen_init_dt(gmipi_screen);
732 dev_err(&pdev->dev, " rk_mipi_screen_init_dt fail!\n");
736 MIPI_SCREEN_DBG("---rk_mipi_screen_probe--end\n");
740 static struct platform_driver mipi_screen_platform_driver = {
742 .name = "rk_mipi_screen",
746 static int __init rk_mipi_screen_init(void)
748 platform_device_register_simple("rk_mipi_screen", -1, NULL, 0);
749 return platform_driver_probe(&mipi_screen_platform_driver, rk_mipi_screen_probe);
752 static void __exit rk_mipi_screen_exit(void)
754 platform_driver_unregister(&mipi_screen_platform_driver);
757 subsys_initcall_sync(rk_mipi_screen_init);
758 module_exit(rk_mipi_screen_exit);