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_command_mode(0, 1);
171 if (rk_dsi_num == 2) {
172 dsi_enable_command_mode(1, 1);
176 dcs[1] = DTYPE_DCS_SWRITE_0P;
177 dcs[2] = dcs_exit_sleep_mode;
178 dsi_send_packet(0, dcs, 3);
180 dsi_send_packet(1, dcs, 3);
185 dcs[1] = DTYPE_DCS_SWRITE_0P;
186 dcs[2] = dcs_set_display_on;
187 dsi_send_packet(0, dcs, 3);
189 dsi_send_packet(1, dcs, 3);
193 rk_mipi_screen_pwr_enable(gmipi_screen);
195 dsi_enable_hs_clk(0, 1);
196 if (rk_dsi_num == 2) {
197 dsi_enable_hs_clk(1, 1);
200 dsi_enable_command_mode(0, 1);
201 if (rk_dsi_num == 2) {
202 dsi_enable_command_mode(1, 1);
205 rk_mipi_screen_cmd_init(gmipi_screen);
208 MIPI_SCREEN_DBG("++++++++++++++++%s:%d\n", __func__, __LINE__);
212 int rk_mipi_screen_standby(u8 enable)
214 u8 dcs[16] = {0}, rk_dsi_num;
215 rk_dsi_num = gmipi_screen->mipi_dsi_num;
217 if (dsi_is_active(0) != 1)
221 if ((dsi_is_active(0) != 1) || (dsi_is_active(1) != 1))
225 /* below is changeable */
227 dcs[1] = DTYPE_DCS_SWRITE_0P;
228 dcs[2] = dcs_set_display_off;
229 dsi_send_packet(0, dcs, 3);
231 dsi_send_packet(1, dcs, 3);
236 dcs[1] = DTYPE_DCS_SWRITE_0P;
237 dcs[2] = dcs_enter_sleep_mode;
238 dsi_send_packet(0, dcs, 3);
240 dsi_send_packet(1, dcs, 3);
243 rk_mipi_screen_pwr_disable(gmipi_screen);
244 MIPI_SCREEN_DBG("++++enable++++++++++++%s:%d\n", __func__, __LINE__);
250 #ifdef CONFIG_LCD_MIPI
251 static int rk_mipi_screen_init_dt(struct device *dev,
252 struct mipi_screen *screen)
254 struct device_node *childnode, *grandchildnode, *root;
255 struct mipi_dcs_cmd_ctr_list *dcs_cmd;
256 struct list_head *pos;
257 struct property *prop;
258 enum of_gpio_flags flags;
259 u32 value, i, debug, gpio, ret, length;
261 memset(screen, 0, sizeof(*screen));
263 INIT_LIST_HEAD(&screen->cmdlist_head);
265 childnode = of_find_node_by_name(NULL, "mipi_dsi_init");
267 MIPI_SCREEN_DBG("%s: Can not get child => mipi_init.\n", __func__);
269 ret = of_property_read_u32(childnode, "rockchip,screen_init", &value);
271 MIPI_SCREEN_DBG("%s: Can not read property: screen_init.\n", __func__);
273 if ((value != 0) && (value != 1)) {
274 printk("err: rockchip,mipi_dsi_init not match.\n");
277 screen->screen_init = value ;
279 MIPI_SCREEN_DBG("%s: lcd->screen_init = %d.\n", __func__, screen->screen_init);
282 ret = of_property_read_u32(childnode, "rockchip,dsi_lane", &value);
284 MIPI_SCREEN_DBG("%s: Can not read property: dsi_lane.\n", __func__);
286 screen->dsi_lane = value;
287 MIPI_SCREEN_DBG("%s: mipi_lcd->dsi_lane = %d.\n", __func__, screen->dsi_lane);
290 ret = of_property_read_u32(childnode, "rockchip,dsi_hs_clk", &value);
292 MIPI_SCREEN_DBG("%s: Can not read property: dsi_hs_clk.\n", __func__);
294 if ((value <= 90) || (value >= 1500)) {
295 printk("err: rockchip,hs_tx_clk not match.");
298 screen->hs_tx_clk = value*MHz;
301 MIPI_SCREEN_DBG("%s: lcd->screen->hs_tx_clk = %d.\n", __func__, screen->hs_tx_clk);
304 ret = of_property_read_u32(childnode, "rockchip,mipi_dsi_num", &value);
306 MIPI_SCREEN_DBG("%s: Can not read property: mipi_dsi_num.\n", __func__);
308 if ((value != 1) && (value != 2)) {
309 printk("err: rockchip,mipi_dsi_num not match.\n");
312 screen->mipi_dsi_num = value ;
315 MIPI_SCREEN_DBG("%s: lcd->screen.mipi_dsi_num = %d.\n", __func__, screen->mipi_dsi_num);
319 childnode = of_find_node_by_name(NULL, "mipi_power_ctr");
321 screen->lcd_rst_gpio = INVALID_GPIO;
322 screen->lcd_en_gpio = INVALID_GPIO;
323 MIPI_SCREEN_DBG("%s: Can not get child => mipi_power_ctr.\n", __func__);
325 grandchildnode = of_find_node_by_name(childnode, "mipi_lcd_rst");
326 if (!grandchildnode) {
327 screen->lcd_rst_gpio = INVALID_GPIO;
328 MIPI_SCREEN_DBG("%s: Can not read property: mipi_lcd_rst.\n", __func__);
330 ret = of_property_read_u32(grandchildnode, "rockchip,delay", &value);
332 MIPI_SCREEN_DBG("%s: Can not read property: delay.\n", __func__);
334 screen->lcd_rst_delay = value;
335 MIPI_SCREEN_DBG("%s: lcd->screen->lcd_rst_delay = %d.\n", __func__, screen->lcd_rst_delay);
338 gpio = of_get_named_gpio_flags(grandchildnode, "rockchip,gpios", 0, &flags);
339 if (!gpio_is_valid(gpio)) {
340 MIPI_SCREEN_DBG("rest: Can not read property: %s->gpios.\n", __func__);
343 ret = gpio_request(gpio, "mipi_lcd_rst");
345 screen->lcd_rst_gpio = INVALID_GPIO;
346 MIPI_SCREEN_DBG("request mipi_lcd_rst gpio fail:%d\n", gpio);
350 screen->lcd_rst_gpio = gpio;
351 screen->lcd_rst_atv_val = (flags == GPIO_ACTIVE_HIGH) ? 1:0;
353 MIPI_SCREEN_DBG("lcd->lcd_rst_gpio=%d,dsi->lcd_rst_atv_val=%d\n", screen->lcd_rst_gpio, screen->lcd_rst_atv_val);
356 grandchildnode = of_find_node_by_name(childnode, "mipi_lcd_en");
357 if (!grandchildnode) {
358 screen->lcd_en_gpio = INVALID_GPIO;
359 MIPI_SCREEN_DBG("%s: Can not read property: mipi_lcd_en.\n", __func__);
361 ret = of_property_read_u32(grandchildnode, "rockchip,delay", &value);
363 MIPI_SCREEN_DBG("%s: Can not read property: mipi_lcd_en-delay.\n", __func__);
365 screen->lcd_en_delay = value;
366 MIPI_SCREEN_DBG("%s: lcd->screen.lcd_en_delay = %d.\n", __func__, screen->lcd_en_delay);
369 gpio = of_get_named_gpio_flags(grandchildnode, "rockchip,gpios", 0, &flags);
370 if (!gpio_is_valid(gpio)) {
371 MIPI_SCREEN_DBG("rest: Can not read property: %s->gpios.\n", __func__);
374 ret = gpio_request(gpio, "mipi_lcd_en");
376 screen->lcd_en_gpio = INVALID_GPIO;
377 MIPI_SCREEN_DBG("request mipi_lcd_en gpio fail:%d\n", gpio);
380 screen->lcd_en_gpio = gpio;
381 screen->lcd_en_atv_val = (flags == GPIO_ACTIVE_HIGH) ? 1:0;
382 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);
386 root = of_find_node_by_name(NULL, "screen-on-cmds");
388 MIPI_SCREEN_DBG("can't find screen-on-cmds node\n");
390 for_each_child_of_node(root, childnode) {
391 dcs_cmd = kmalloc(sizeof(struct mipi_dcs_cmd_ctr_list), GFP_KERNEL);
392 strcpy(dcs_cmd->dcs_cmd.name, childnode->name);
394 dcs_cmd->dcs_cmd.cmds =
395 devm_kzalloc(dev, CMD_LEN_MAX, GFP_KERNEL);
396 if (!dcs_cmd->dcs_cmd.cmds) {
397 pr_err("malloc cmds fail!\n");
401 prop = of_find_property(childnode, "rockchip,cmd", &length);
403 MIPI_SCREEN_DBG("Can not read property: cmds\n");
404 kfree(dcs_cmd->dcs_cmd.cmds);
405 dcs_cmd->dcs_cmd.cmds = NULL;
409 if ((length / sizeof(u32)) > CMD_LEN_MAX) {
410 /* the length can not longer than the cmds arrary in struct dcs_cmds */
411 MIPI_SCREEN_DBG("error: the dcs cmd length is %d, but the max length supported is %d\n",
412 length / sizeof(u32),
415 MIPI_SCREEN_DBG("\n childnode->name =%s:length=%d\n", childnode->name, (length / sizeof(u32)));
417 ret = of_property_read_u32_array(childnode,
419 dcs_cmd->dcs_cmd.cmds,
420 length / sizeof(u32));
422 MIPI_SCREEN_DBG("%s: Can not read property: %s--->cmds\n", __func__, childnode->name);
423 kfree(dcs_cmd->dcs_cmd.cmds);
424 dcs_cmd->dcs_cmd.cmds = NULL;
427 dcs_cmd->dcs_cmd.cmd_len = length / sizeof(u32);
429 ret = of_property_read_u32(childnode, "rockchip,dsi_id", &value);
431 MIPI_SCREEN_DBG("%s: Can not read property: %s--->cmd_type\n", __func__, childnode->name);
433 if (screen->mipi_dsi_num == 1) {
435 printk("err: rockchip,dsi_id not match.\n");
437 dcs_cmd->dcs_cmd.dsi_id = value;
440 if ((value < 0) || (value > 2))
441 printk("err: rockchip,dsi_id not match.\n");
443 dcs_cmd->dcs_cmd.dsi_id = value;
447 ret = of_property_read_u32(childnode, "rockchip,cmd_type", &value);
449 MIPI_SCREEN_DBG("%s: Can not read property: %s--->cmd_type\n", __func__, childnode->name);
451 if ((value != 0) && (value != 1)) {
452 printk("err: rockchip, cmd_type not match.\n");
454 dcs_cmd->dcs_cmd.type = value;
458 ret = of_property_read_u32(childnode, "rockchip,cmd_delay", &value);
460 MIPI_SCREEN_DBG("%s: Can not read property: %s--->cmd_delay\n", __func__, childnode->name);
462 dcs_cmd->dcs_cmd.delay = value;
464 list_add_tail(&dcs_cmd->list, &screen->cmdlist_head);
467 ret = of_property_read_u32(root, "rockchip,cmd_debug", &debug);
469 MIPI_SCREEN_DBG("%s: Can not read property: rockchip,cmd_debug.\n", __func__);
472 list_for_each(pos, &screen->cmdlist_head) {
473 dcs_cmd = list_entry(pos, struct mipi_dcs_cmd_ctr_list, list);
474 printk("\n dcs_name:%s,dcs_type:%d,side_id:%d,cmd_len:%d,delay:%d\n\n",
475 dcs_cmd->dcs_cmd.name,
476 dcs_cmd->dcs_cmd.type,
477 dcs_cmd->dcs_cmd.dsi_id,
478 dcs_cmd->dcs_cmd.cmd_len,
479 dcs_cmd->dcs_cmd.delay);
480 for (i = 0; i < (dcs_cmd->dcs_cmd.cmd_len); i++) {
481 printk("[%d]=%02x,", i+1, dcs_cmd->dcs_cmd.cmds[i]);
485 MIPI_SCREEN_DBG("---close cmd debug---\n");
491 int rk_mipi_get_dsi_num(void)
493 return gmipi_screen->mipi_dsi_num;
495 #ifdef CONFIG_LCD_MIPI
496 EXPORT_SYMBOL(rk_mipi_get_dsi_num);
499 int rk_mipi_get_dsi_lane(void)
501 return gmipi_screen->dsi_lane;
503 #ifdef CONFIG_LCD_MIPI
504 EXPORT_SYMBOL(rk_mipi_get_dsi_lane);
507 int rk_mipi_get_dsi_clk(void)
509 return gmipi_screen->hs_tx_clk;
511 #ifdef CONFIG_LCD_MIPI
512 EXPORT_SYMBOL(rk_mipi_get_dsi_clk);
514 #ifdef CONFIG_RK_3288_DSI_UBOOT
515 #ifdef CONFIG_OF_LIBFDT
516 static int rk_mipi_screen_init_dt(struct mipi_screen *screen)
518 struct mipi_dcs_cmd_ctr_list *dcs_cmd;
524 struct fdt_gpio_state gpio_val;
527 INIT_LIST_HEAD(&screen->cmdlist_head);
529 blob = gd->fdt_blob; /* getenv_hex("fdtaddr", 0); */
530 node = fdtdec_next_compatible(blob, 0, COMPAT_ROCKCHIP_MIPI_INIT);
532 MIPI_SCREEN_DBG("Can not get node of COMPAT_ROCKCHIP_MIPI_INIT\n");
534 screen->screen_init = fdtdec_get_int(blob, node, "rockchip,screen_init", -1);
535 if (screen->screen_init < 0) {
536 MIPI_SCREEN_DBG("Can not get screen_init\n");
538 screen->dsi_lane = fdtdec_get_int(blob, node, "rockchip,dsi_lane", -1);
539 if (screen->dsi_lane < 0) {
540 MIPI_SCREEN_DBG("Can not get dsi_lane\n");
542 screen->hs_tx_clk = fdtdec_get_int(blob, node, "rockchip,dsi_hs_clk", -1);
543 if (screen->hs_tx_clk < 0) {
544 MIPI_SCREEN_DBG("Can not get dsi_hs_clk\n");
546 screen->hs_tx_clk = screen->hs_tx_clk*MHZ;
548 screen->mipi_dsi_num = fdtdec_get_int(blob, node, "rockchip,mipi_dsi_num", -1);
549 if (screen->mipi_dsi_num < 0) {
550 MIPI_SCREEN_DBG("Can't get mipi_dsi_num\n");
553 node = fdtdec_next_compatible(blob, 0, COMPAT_ROCKCHIP_MIPI_PWR);
555 printf("Can not get node of COMPAT_ROCKCHIP_MIPI_PWR\n");
560 /*get the lcd rst status
561 handle = fdt_getprop_u32_default(blob, "/mipi_power_ctr", "mipi_lcd_rst", -1);
562 node = fdt_node_offset_by_phandle(blob, handle);
564 node = fdtdec_next_compatible(blob, 0, COMPAT_ROCKCHIP_MIPI_PWR);
566 printf("Can not get node of COMPAT_ROCKCHIP_MIPI_PWR\n");
568 subnode = fdtdec_next_compatible_subnode(blob, node,
569 COMPAT_ROCKCHIP_MIPI_LCD_RST, &depth);
571 screen->lcd_rst_gpio = INVALID_GPIO;
572 printf("Can't get pin of mipi_lcd_rst\n");
574 err = fdtdec_decode_gpio(blob, subnode, "rockchip,gpios", &gpio_val);
575 gpio_val.gpio = rk_gpio_base_to_bank(gpio_val.gpio & RK_GPIO_BANK_MASK) | (gpio_val.gpio & RK_GPIO_PIN_MASK);
577 screen->lcd_rst_gpio = INVALID_GPIO;
578 printf("Can't find GPIO rst\n");
580 screen->lcd_rst_gpio = gpio_val.gpio;
581 screen->lcd_rst_atv_val = !(gpio_val.flags & OF_GPIO_ACTIVE_LOW);
583 screen->lcd_rst_delay = fdtdec_get_int(blob, subnode, "rockchip,delay", -1);
584 if (screen->lcd_rst_delay < 0) {
585 printf("Can't get delay of rst delay\n");
587 printf("Get lcd rst gpio and delay successfully!\n");
591 /* get the lcd rst & en status */
592 node = fdtdec_next_compatible(blob, 0, COMPAT_ROCKCHIP_MIPI_PWR);
594 MIPI_SCREEN_DBG("Can not get node of COMPAT_ROCKCHIP_MIPI_PWR\n");
597 noffset = fdt_first_subnode(blob, node);
598 const char *name = fdt_get_name(blob, noffset, NULL);
599 printf("XJH_DEBUG1:%s\n", name);
600 noffset = fdt_next_subnode(blob, noffset);
601 const char *name1 = fdt_get_name(blob, noffset, NULL);
602 printf("XJH_DEBUG2:%s\n", name1);
604 for (noffset = fdt_first_subnode(blob, node);
606 noffset = fdt_next_subnode(blob, noffset)) {
607 if (0 == fdt_node_check_compatible(blob, noffset, "rockchip,lcd_rst")) {
608 err = fdtdec_decode_gpio(blob, noffset, "rockchip,gpios", &gpio_val);
609 gpio_val.gpio = rk_gpio_base_to_bank(gpio_val.gpio & RK_GPIO_BANK_MASK) | (gpio_val.gpio & RK_GPIO_PIN_MASK);
611 screen->lcd_rst_gpio = INVALID_GPIO;
612 MIPI_SCREEN_DBG("Can't find GPIO rst\n");
614 screen->lcd_rst_gpio = gpio_val.gpio;
615 screen->lcd_rst_atv_val = !(gpio_val.flags & OF_GPIO_ACTIVE_LOW);
617 screen->lcd_rst_delay = fdtdec_get_int(blob, noffset, "rockchip,delay", -1);
618 if (screen->lcd_rst_delay < 0) {
619 MIPI_SCREEN_DBG("Can't get delay of rst delay\n");
621 MIPI_SCREEN_DBG("Get lcd rst gpio and delay successfully!\n");
623 if (0 == fdt_node_check_compatible(blob, noffset, "rockchip,lcd_en")) {
624 err = fdtdec_decode_gpio(blob, noffset, "rockchip,gpios", &gpio_val);
625 gpio_val.gpio = rk_gpio_base_to_bank(gpio_val.gpio & RK_GPIO_BANK_MASK) | (gpio_val.gpio & RK_GPIO_PIN_MASK);
627 screen->lcd_en_gpio = INVALID_GPIO;
628 MIPI_SCREEN_DBG("Can't find GPIO en\n");
630 screen->lcd_en_gpio = gpio_val.gpio;
631 screen->lcd_en_atv_val = !(gpio_val.flags & OF_GPIO_ACTIVE_LOW);
633 screen->lcd_en_delay = fdtdec_get_int(blob, noffset, "rockchip,delay", -1);
634 if (screen->lcd_en_delay < 0) {
635 MIPI_SCREEN_DBG("Can't get delay of lcd_en delay\n");
637 MIPI_SCREEN_DBG("Get lcd en gpio and delay successfully:delay %d!\n", screen->lcd_en_delay);
642 /*get the initial command list*/
643 node = fdtdec_next_compatible(blob, 0, COMPAT_ROCKCHIP_MIPI_SONCMDS);
645 MIPI_SCREEN_DBG("Can not get node of COMPAT_ROCKCHIP_MIPI_SONCMDS\n");
647 for (noffset = fdt_first_subnode(blob, node);
649 noffset = fdt_next_subnode(blob, noffset)) {
651 MIPI_SCREEN_DBG("build MIPI LCD init cmd tables\n");
653 subnode = fdtdec_next_compatible_subnode(blob, node,
654 COMPAT_ROCKCHIP_MIPI_ONCMDS, &depth);
658 dcs_cmd = calloc(1, sizeof(struct mipi_dcs_cmd_ctr_list));
659 /* node = fdt_node_offset_by_phandle(blob, handle); */
660 strcpy(dcs_cmd->dcs_cmd.name, fdt_get_name(blob, noffset, NULL));
661 MIPI_SCREEN_DBG("%s\n", dcs_cmd->dcs_cmd.name);
662 dcs_cmd->dcs_cmd.type = fdtdec_get_int(blob, noffset, "rockchip,cmd_type", -1);
663 MIPI_SCREEN_DBG("dcs_cmd.type=%02x\n", dcs_cmd->dcs_cmd.type);
664 dcs_cmd->dcs_cmd.dsi_id = fdtdec_get_int(blob, noffset, "rockchip,dsi_id", -1);
665 MIPI_SCREEN_DBG("dcs_cmd.dsi_id=%02x\n", dcs_cmd->dcs_cmd.dsi_id);
666 fdt_getprop(blob, noffset, "rockchip,cmd", &length);
667 dcs_cmd->dcs_cmd.cmd_len = length / sizeof(u32) ;
669 dcs_cmd->dcs_cmd.cmds = calloc(1, CMD_LEN_MAX);
670 if (!dcs_cmd->dcs_cmd.cmds) {
671 pr_err("calloc cmds fail!\n");
675 err = fdtdec_get_int_array(blob, noffset,
677 dcs_cmd->dcs_cmd.cmds,
678 dcs_cmd->dcs_cmd.cmd_len);
679 dcs_cmd->dcs_cmd.delay = fdtdec_get_int(blob, noffset, "rockchip,cmd_delay", -1);
680 MIPI_SCREEN_DBG("dcs_cmd.delay=%d\n", dcs_cmd->dcs_cmd.delay);
681 list_add_tail(&dcs_cmd->list, &screen->cmdlist_head);
686 #endif /* CONFIG_OF_LIBFDT */
688 int rk_mipi_screen_probe(void)
691 gmipi_screen = calloc(1, sizeof(struct mipi_screen));
693 printf("request struct screen fail!\n");
696 #ifdef CONFIG_OF_LIBFDT
697 ret = rk_mipi_screen_init_dt(gmipi_screen);
699 printf(" rk_mipi_screen_init_dt fail!\n");
702 #endif /* CONFIG_OF_LIBFDT */
704 MIPI_SCREEN_DBG("---rk_mipi_screen_probe--end\n");
708 #endif /* CONFIG_RK_3288_DSI_UBOOT */
709 #ifdef CONFIG_LCD_MIPI
710 static int __init rk_mipi_screen_probe(struct platform_device *pdev)
714 gmipi_screen = devm_kzalloc(&pdev->dev, sizeof(struct mipi_screen), GFP_KERNEL);
716 dev_err(&pdev->dev, "request struct screen fail!\n");
720 ret = rk_mipi_screen_init_dt(&pdev->dev, gmipi_screen);
722 dev_err(&pdev->dev, " rk_mipi_screen_init_dt fail!\n");
726 MIPI_SCREEN_DBG("---rk_mipi_screen_probe--end\n");
730 static struct platform_driver mipi_screen_platform_driver = {
732 .name = "rk_mipi_screen",
736 static int __init rk_mipi_screen_init(void)
738 platform_device_register_simple("rk_mipi_screen", -1, NULL, 0);
739 return platform_driver_probe(&mipi_screen_platform_driver, rk_mipi_screen_probe);
742 static void __exit rk_mipi_screen_exit(void)
744 platform_driver_unregister(&mipi_screen_platform_driver);
747 subsys_initcall_sync(rk_mipi_screen_init);
748 module_exit(rk_mipi_screen_exit);