2 * Copyright (C) 2014 ROCKCHIP, Inc.
3 * drivers/video/display/transmitter/rk32_mipi_dsi.c
4 * author: libing@rock-chips.com
5 * create date: 2014-04-10
6 * debug /sys/kernel/debug/mipidsi*
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.
18 #ifndef CONFIG_RK32_MIPI_DSI
22 #ifdef CONFIG_RK32_MIPI_DSI
23 #define MIPI_DSI_REGISTER_IO 0
24 #define CONFIG_MIPI_DSI_LINUX 0
26 #define DSI_RK3288 0x3288
27 #define DSI_RK312x 0x3128
28 #define DSI_RK3368 0x3368
29 #define DSI_RK3366 0x3366
30 #define DSI_RK3399 0x3399
33 #include <linux/kernel.h>
34 #include <linux/init.h>
35 #include <linux/platform_device.h>
36 #include <linux/slab.h>
37 #include <linux/rk_fb.h>
38 #include <linux/rk_screen.h>
39 #include <linux/delay.h>
40 #include <linux/clk.h>
41 #include <linux/interrupt.h>
42 #include <asm/div64.h>
45 #include <linux/debugfs.h>
46 #include <linux/seq_file.h>
47 #include <linux/regulator/machine.h>
49 #include <linux/dma-mapping.h>
51 #include "rk32_mipi_dsi.h"
52 #include <linux/rockchip/iomap.h>
53 #include <linux/rockchip/cpu.h>
54 #include<linux/mfd/syscon.h>
55 #include<linux/regmap.h>
57 #define MIPI_DBG(x...) /* printk(KERN_INFO x) */
59 #ifdef CONFIG_MIPI_DSI_LINUX
60 #define MIPI_TRACE(x...) /* printk(KERN_INFO x) */
62 #define MIPI_TRACE(...) \
73 *v1.0 : this driver is rk32 mipi dsi driver of rockchip;
74 *v1.1 : add test eye pattern;
78 #define RK_MIPI_DSI_VERSION_AND_TIME "rockchip mipi_dsi v1.1 2014-06-17"
80 static struct dsi *dsi0;
81 static struct dsi *dsi1;
83 static int rk32_mipi_dsi_is_active(void *arg);
84 static int rk32_mipi_dsi_enable_hs_clk(void *arg, u32 enable);
85 static int rk32_mipi_dsi_enable_video_mode(void *arg, u32 enable);
86 static int rk32_mipi_dsi_enable_command_mode(void *arg, u32 enable);
87 static int rk32_mipi_dsi_is_enable(void *arg, u32 enable);
88 static int rk32_mipi_power_down_DDR(void);
89 static int rk32_mipi_power_up_DDR(void);
90 int rk_mipi_screen_standby(u8 enable);
92 int rockchip_get_screen_type(void)
94 struct device_node *type_node;
95 struct device_node *childnode;
98 type_node = of_find_node_by_name(NULL, "display-timings");
100 pr_err("could not find display-timings node\n");
104 for_each_child_of_node(type_node, childnode) {
105 if (!of_property_read_u32(childnode, "screen-type", &val))
112 static int rk32_dsi_read_reg(struct dsi *dsi, u16 reg, u32 *pval)
114 if (dsi->ops.id == DSI_RK3288 ||
115 dsi->ops.id == DSI_RK3399)
116 *pval = __raw_readl(dsi->host.membase + (reg - MIPI_DSI_HOST_OFFSET));
117 else if (dsi->ops.id == DSI_RK312x ||
118 dsi->ops.id == DSI_RK3368 ||
119 dsi->ops.id == DSI_RK3366) {
120 if (reg >= MIPI_DSI_HOST_OFFSET)
121 *pval = __raw_readl(dsi->host.membase + (reg - MIPI_DSI_HOST_OFFSET));
122 else if (reg >= MIPI_DSI_PHY_OFFSET)
123 *pval = __raw_readl(dsi->phy.membase + (reg - MIPI_DSI_PHY_OFFSET));
128 static int rk32_dsi_write_reg(struct dsi *dsi, u16 reg, u32 *pval)
130 if (dsi->ops.id == DSI_RK3288 ||
131 dsi->ops.id == DSI_RK3399)
132 __raw_writel(*pval, dsi->host.membase + (reg - MIPI_DSI_HOST_OFFSET));
133 else if (dsi->ops.id == DSI_RK312x ||
134 dsi->ops.id == DSI_RK3368 ||
135 dsi->ops.id == DSI_RK3366) {
136 if (reg >= MIPI_DSI_HOST_OFFSET)
137 __raw_writel(*pval, dsi->host.membase + (reg - MIPI_DSI_HOST_OFFSET));
138 else if (reg >= MIPI_DSI_PHY_OFFSET)
139 __raw_writel(*pval, dsi->phy.membase + (reg - MIPI_DSI_PHY_OFFSET));
144 static int rk32_dsi_get_bits(struct dsi *dsi, u32 reg)
147 u32 bits = (reg >> 8) & 0xff;
148 u16 reg_addr = (reg >> 16) & 0xffff;
149 u8 offset = reg & 0xff;
152 bits = (1 << bits) - 1;
156 rk32_dsi_read_reg(dsi, reg_addr, &val);
162 static int rk32_dsi_set_bits(struct dsi *dsi, u32 data, u32 reg)
165 u32 bits = (reg >> 8) & 0xff;
166 u16 reg_addr = (reg >> 16) & 0xffff;
167 u8 offset = reg & 0xff;
170 bits = (1 << bits) - 1;
174 if (bits != 0xffffffff)
175 rk32_dsi_read_reg(dsi, reg_addr, &val);
177 val &= ~(bits << offset);
178 val |= (data & bits) << offset;
179 rk32_dsi_write_reg(dsi, reg_addr, &val);
182 MIPI_TRACE("%s error reg_addr:0x%04x, offset:%d, bits:0x%04x, value:0x%04x\n",
183 __func__, reg_addr, offset, bits, data);
188 static int rk32_dwc_phy_test_rd(struct dsi *dsi, unsigned char test_code)
191 rk32_dsi_set_bits(dsi, 1, phy_testclk);
192 rk32_dsi_set_bits(dsi, test_code, phy_testdin);
193 rk32_dsi_set_bits(dsi, 1, phy_testen);
194 rk32_dsi_set_bits(dsi, 0, phy_testclk);
195 rk32_dsi_set_bits(dsi, 0, phy_testen);;
197 rk32_dsi_set_bits(dsi, 0, phy_testen);
198 val = rk32_dsi_get_bits(dsi, phy_testdout);
199 rk32_dsi_set_bits(dsi, 1, phy_testclk);
200 rk32_dsi_set_bits(dsi, 0, phy_testclk);
205 static int rk32_dwc_phy_test_wr(struct dsi *dsi, unsigned char test_code, unsigned char *test_data, unsigned char size)
209 MIPI_DBG("test_code=0x%x,test_data=0x%x\n", test_code, test_data[0]);
210 rk32_dsi_set_bits(dsi, 0x10000 | test_code, PHY_TEST_CTRL1);
211 rk32_dsi_set_bits(dsi, 0x2, PHY_TEST_CTRL0);
212 rk32_dsi_set_bits(dsi, 0x0, PHY_TEST_CTRL0);
214 for (i = 0; i < size; i++) {
215 rk32_dsi_set_bits(dsi, test_data[i], PHY_TEST_CTRL1);
216 rk32_dsi_set_bits(dsi, 0x2, PHY_TEST_CTRL0);
217 rk32_dsi_set_bits(dsi, 0x0, PHY_TEST_CTRL0);
218 MIPI_DBG("rk32_dwc_phy_test_wr:%08x\n", rk32_dsi_get_bits(dsi, PHY_TEST_CTRL1));
223 static int rk32_phy_power_up(struct dsi *dsi)
225 /* enable ref clock */
226 clk_prepare_enable(dsi->phy.refclk);
227 clk_prepare_enable(dsi->dsi_pclk);
228 if (dsi->ops.id == DSI_RK3399)
229 clk_prepare_enable(dsi->dsi_host_pclk);
232 switch (dsi->host.lane) {
234 rk32_dsi_set_bits(dsi, 3, n_lanes);
237 rk32_dsi_set_bits(dsi, 2, n_lanes);
240 rk32_dsi_set_bits(dsi, 1, n_lanes);
243 rk32_dsi_set_bits(dsi, 0, n_lanes);
248 rk32_dsi_set_bits(dsi, 1, phy_shutdownz);
249 rk32_dsi_set_bits(dsi, 1, phy_rstz);
250 rk32_dsi_set_bits(dsi, 1, phy_enableclk);
251 rk32_dsi_set_bits(dsi, 1, phy_forcepll);
256 static int rk312x_mipi_dsi_phy_set_gotp(struct dsi *dsi, u32 offset, int n)
258 u32 val = 0, temp = 0, Tlpx = 0;
259 u32 ddr_clk = dsi->phy.ddr_clk;
260 u32 Ttxbyte_clk = dsi->phy.Ttxbyte_clk;
261 u32 Tsys_clk = dsi->phy.Tsys_clk;
262 u32 Ttxclkesc = dsi->phy.Ttxclkesc;
263 printk("%s : ddr_clk %d\n", __func__, ddr_clk);
265 case DPHY_CLOCK_OFFSET:
266 MIPI_DBG("******set DPHY_CLOCK_OFFSET gotp******\n");
268 case DPHY_LANE0_OFFSET:
269 MIPI_DBG("******set DPHY_LANE0_OFFSET gotp******\n");
271 case DPHY_LANE1_OFFSET:
272 MIPI_DBG("******set DPHY_LANE1_OFFSET gotp******\n");
274 case DPHY_LANE2_OFFSET:
275 MIPI_DBG("******set DPHY_LANE2_OFFSET gotp******\n");
277 case DPHY_LANE3_OFFSET:
278 MIPI_DBG("******set DPHY_LANE3_OFFSET gotp******\n");
284 if (ddr_clk < 110 * MHz)
286 else if (ddr_clk < 150 * MHz)
288 else if (ddr_clk < 200 * MHz)
290 else if (ddr_clk < 250 * MHz)
292 else if (ddr_clk < 300 * MHz)
294 else if (ddr_clk < 400 * MHz)
296 else if (ddr_clk < 500 * MHz)
298 else if (ddr_clk < 600 * MHz)
300 else if (ddr_clk < 700 * MHz)
302 else if (ddr_clk < 800 * MHz)
304 else if (ddr_clk <= 1000 * MHz)
306 printk("%s reg_ths_settle = 0x%x\n", __func__, val);
307 rk32_dsi_set_bits(dsi, val, reg_ths_settle + offset);
309 if (ddr_clk < 110 * MHz)
311 else if (ddr_clk < 150 * MHz)
313 else if (ddr_clk < 200 * MHz)
315 else if (ddr_clk < 250 * MHz)
317 else if (ddr_clk < 300 * MHz)
319 else if (ddr_clk < 400 * MHz)
321 else if (ddr_clk < 500 * MHz)
323 else if (ddr_clk < 600 * MHz)
325 else if (ddr_clk < 700 * MHz)
327 else if (ddr_clk < 800 * MHz)
329 else if (ddr_clk <= 1000 * MHz)
331 printk("%s reg_hs_ths_prepare = 0x%x\n", __func__, val);
332 rk32_dsi_set_bits(dsi, val, reg_hs_ths_prepare + offset);
334 if (offset != DPHY_CLOCK_OFFSET) {
335 if (ddr_clk < 110 * MHz)
337 else if (ddr_clk < 150 * MHz)
339 else if (ddr_clk < 200 * MHz)
341 else if (ddr_clk < 250 * MHz)
343 else if (ddr_clk < 300 * MHz)
345 else if (ddr_clk < 400 * MHz)
347 else if (ddr_clk < 500 * MHz)
349 else if (ddr_clk < 600 * MHz)
351 else if (ddr_clk < 700 * MHz)
353 else if (ddr_clk < 800 * MHz)
355 else if (ddr_clk <= 1000 * MHz)
358 if (ddr_clk < 110 * MHz)
360 else if (ddr_clk < 150 * MHz)
362 else if (ddr_clk < 200 * MHz)
364 else if (ddr_clk < 250 * MHz)
366 else if (ddr_clk < 300 * MHz)
368 else if (ddr_clk < 400 * MHz)
370 else if (ddr_clk < 500 * MHz)
372 else if (ddr_clk < 600 * MHz)
374 else if (ddr_clk < 700 * MHz)
376 else if (ddr_clk < 800 * MHz)
378 else if (ddr_clk <= 1000 * MHz)
381 printk("%s reg_hs_the_zero = 0x%x\n", __func__, val);
382 rk32_dsi_set_bits(dsi, val, reg_hs_the_zero + offset);
384 if (ddr_clk < 110 * MHz)
386 else if (ddr_clk < 150 * MHz)
388 else if (ddr_clk < 200 * MHz)
390 else if (ddr_clk < 250 * MHz)
392 else if (ddr_clk < 300 * MHz)
394 else if (ddr_clk < 400 * MHz)
396 else if (ddr_clk < 500 * MHz)
398 else if (ddr_clk < 600 * MHz)
400 else if (ddr_clk < 700 * MHz)
402 else if (ddr_clk < 800 * MHz)
404 else if (ddr_clk <= 1000 * MHz)
405 val = 0x21; /* 0x27 */
407 printk("%s reg_hs_ths_trail = 0x%x\n", __func__, val);
409 rk32_dsi_set_bits(dsi, val, reg_hs_ths_trail + offset);
410 val = 120000 / Ttxbyte_clk + 1;
411 MIPI_DBG("reg_hs_ths_exit: %d, %d\n", val, val*Ttxbyte_clk/1000);
412 rk32_dsi_set_bits(dsi, val, reg_hs_ths_exit + offset);
414 if (offset == DPHY_CLOCK_OFFSET) {
415 val = (60000 + 52*dsi->phy.UI) / Ttxbyte_clk + 1;
416 MIPI_DBG("reg_hs_tclk_post: %d, %d\n", val, val*Ttxbyte_clk/1000);
417 rk32_dsi_set_bits(dsi, val, reg_hs_tclk_post + offset);
418 val = 10*dsi->phy.UI / Ttxbyte_clk + 1;
419 MIPI_DBG("reg_hs_tclk_pre: %d, %d\n", val, val*Ttxbyte_clk/1000);
420 rk32_dsi_set_bits(dsi, val, reg_hs_tclk_pre + offset);
423 val = 1010000000 / Tsys_clk + 1;
424 MIPI_DBG("reg_hs_twakup: %d, %d\n", val, val*Tsys_clk/1000);
427 MIPI_DBG("val is too large, 0x3ff is the largest\n");
429 temp = (val >> 8) & 0x03;
431 rk32_dsi_set_bits(dsi, temp, reg_hs_twakup_h + offset);
432 rk32_dsi_set_bits(dsi, val, reg_hs_twakup_l + offset);
434 if (Ttxclkesc > 50000) {
436 MIPI_DBG("Ttxclkesc:%d\n", Ttxclkesc);
438 val = val / Ttxbyte_clk;
439 Tlpx = val*Ttxbyte_clk;
440 MIPI_DBG("reg_hs_tlpx: %d, %d\n", val, Tlpx);
442 rk32_dsi_set_bits(dsi, val, reg_hs_tlpx + offset);
445 val = 4*Tlpx / Ttxclkesc;
446 MIPI_DBG("reg_hs_tta_go: %d, %d\n", val, val*Ttxclkesc);
447 rk32_dsi_set_bits(dsi, val, reg_hs_tta_go + offset);
448 val = 3 * Tlpx / 2 / Ttxclkesc;
449 MIPI_DBG("reg_hs_tta_sure: %d, %d\n", val, val*Ttxclkesc);
450 rk32_dsi_set_bits(dsi, val, reg_hs_tta_sure + offset);
451 val = 5 * Tlpx / Ttxclkesc;
452 MIPI_DBG("reg_hs_tta_wait: %d, %d\n", val, val*Ttxclkesc);
453 rk32_dsi_set_bits(dsi, val, reg_hs_tta_wait + offset);
457 static void rk312x_mipi_dsi_set_hs_clk(struct dsi *dsi)
459 rk32_dsi_set_bits(dsi, dsi->phy.prediv, reg_prediv);
460 rk32_dsi_set_bits(dsi, dsi->phy.fbdiv & 0xff, reg_fbdiv);
461 rk32_dsi_set_bits(dsi, (dsi->phy.fbdiv >> 8) & 0x01, reg_fbdiv_8);
464 static int rk312x_phy_power_up(struct dsi *dsi)
466 /* enable ref clock */
467 clk_prepare_enable(dsi->phy.refclk);
468 clk_prepare_enable(dsi->dsi_pclk);
469 clk_prepare_enable(dsi->dsi_host_pclk);
470 if (dsi->ops.id == DSI_RK312x)
471 clk_prepare_enable(dsi->h2p_hclk);
475 rk312x_mipi_dsi_set_hs_clk(dsi);
476 rk32_dsi_set_bits(dsi, 0xe4, DPHY_REGISTER1);
477 switch (dsi->host.lane) {
479 rk32_dsi_set_bits(dsi, 1, lane_en_3);
481 rk32_dsi_set_bits(dsi, 1, lane_en_2);
483 rk32_dsi_set_bits(dsi, 1, lane_en_1);
485 rk32_dsi_set_bits(dsi, 1, lane_en_0);
486 rk32_dsi_set_bits(dsi, 1, lane_en_ck);
492 rk32_dsi_set_bits(dsi, 0xe0, DPHY_REGISTER1);
495 rk32_dsi_set_bits(dsi, 0x1e, DPHY_REGISTER20);
496 rk32_dsi_set_bits(dsi, 0x1f, DPHY_REGISTER20);
498 rk32_dsi_set_bits(dsi, 1, phy_enableclk);
503 static int rk_phy_power_up(struct dsi *dsi)
505 if (dsi->ops.id == DSI_RK3288 ||
506 dsi->ops.id == DSI_RK3399)
507 rk32_phy_power_up(dsi);
508 else if (dsi->ops.id == DSI_RK312x ||
509 dsi->ops.id == DSI_RK3368 ||
510 dsi->ops.id == DSI_RK3366)
511 rk312x_phy_power_up(dsi);
515 static int rk32_phy_power_down(struct dsi *dsi)
517 rk32_dsi_set_bits(dsi, 0, phy_shutdownz);
518 clk_disable_unprepare(dsi->phy.refclk);
519 clk_disable_unprepare(dsi->dsi_pclk);
520 if (dsi->ops.id == DSI_RK3399)
521 clk_disable_unprepare(dsi->dsi_host_pclk);
525 static int rk312x_phy_power_down(struct dsi *dsi)
527 rk32_dsi_set_bits(dsi, 0x01, DPHY_REGISTER0);
528 rk32_dsi_set_bits(dsi, 0xe3, DPHY_REGISTER1);
530 clk_disable_unprepare(dsi->phy.refclk);
531 clk_disable_unprepare(dsi->dsi_pclk);
532 clk_disable_unprepare(dsi->dsi_host_pclk);
534 if (dsi->ops.id == DSI_RK312x)
535 clk_disable_unprepare(dsi->h2p_hclk);
540 static int rk_phy_power_down(struct dsi *dsi)
542 if (dsi->ops.id == DSI_RK3288 ||
543 dsi->ops.id == DSI_RK3399)
544 rk32_phy_power_down(dsi);
545 else if (dsi->ops.id == DSI_RK312x ||
546 dsi->ops.id == DSI_RK3368 ||
547 dsi->ops.id == DSI_RK3366)
548 rk312x_phy_power_down(dsi);
552 static int rk32_phy_init(struct dsi *dsi)
554 u32 val = 0 , ddr_clk = 0, fbdiv = 0, prediv = 0;
555 unsigned char test_data[2] = {0};
557 ddr_clk = dsi->phy.ddr_clk;
558 prediv = dsi->phy.prediv;
559 fbdiv = dsi->phy.fbdiv;
561 if (ddr_clk < 200 * MHz)
563 else if (ddr_clk < 300 * MHz)
565 else if (ddr_clk < 500 * MHz)
567 else if (ddr_clk < 700 * MHz)
569 else if (ddr_clk < 900 * MHz)
571 else if (ddr_clk < 1100 * MHz)
573 else if (ddr_clk < 1300 * MHz)
575 else if (ddr_clk <= 1500 * MHz)
578 test_data[0] = 0x80 | val << 3 | 0x3;
579 rk32_dwc_phy_test_wr(dsi, 0x10, test_data, 1);
582 rk32_dwc_phy_test_wr(dsi, 0x11, test_data, 1);
584 test_data[0] = 0x80 | 0x40;
585 rk32_dwc_phy_test_wr(dsi, 0x12, test_data, 1);
587 if (ddr_clk < 90 * MHz)
589 else if (ddr_clk < 100 * MHz)
591 else if (ddr_clk < 110 * MHz)
593 else if (ddr_clk < 130 * MHz)
595 else if (ddr_clk < 140 * MHz)
597 else if (ddr_clk < 150 * MHz)
599 else if (ddr_clk < 170 * MHz)
601 else if (ddr_clk < 180 * MHz)
603 else if (ddr_clk < 200 * MHz)
605 else if (ddr_clk < 220 * MHz)
607 else if (ddr_clk < 240 * MHz)
609 else if (ddr_clk < 250 * MHz)
611 else if (ddr_clk < 270 * MHz)
613 else if (ddr_clk < 300 * MHz)
615 else if (ddr_clk < 330 * MHz)
617 else if (ddr_clk < 360 * MHz)
619 else if (ddr_clk < 400 * MHz)
621 else if (ddr_clk < 450 * MHz)
623 else if (ddr_clk < 500 * MHz)
625 else if (ddr_clk < 550 * MHz)
627 else if (ddr_clk < 600 * MHz)
629 else if (ddr_clk < 650 * MHz)
631 else if (ddr_clk < 700 * MHz)
633 else if (ddr_clk < 750 * MHz)
635 else if (ddr_clk < 800 * MHz)
637 else if (ddr_clk < 850 * MHz)
639 else if (ddr_clk < 900 * MHz)
641 else if (ddr_clk < 950 * MHz)
643 else if (ddr_clk < 1000 * MHz)
645 else if (ddr_clk < 1050 * MHz)
647 else if (ddr_clk < 1100 * MHz)
649 else if (ddr_clk < 1150 * MHz)
651 else if (ddr_clk < 1200 * MHz)
653 else if (ddr_clk < 1250 * MHz)
655 else if (ddr_clk < 1300 * MHz)
657 else if (ddr_clk < 1350 * MHz)
659 else if (ddr_clk < 1400 * MHz)
661 else if (ddr_clk < 1450 * MHz)
663 else if (ddr_clk <= 1500 * MHz)
666 test_data[0] = val << 1;
667 rk32_dwc_phy_test_wr(dsi, code_hs_rx_lane0, test_data, 1);
669 test_data[0] = prediv - 1;
670 rk32_dwc_phy_test_wr(dsi, code_pll_input_div_rat, test_data, 1);
672 test_data[0] = (fbdiv - 1) & 0x1f;
673 rk32_dwc_phy_test_wr(dsi, code_pll_loop_div_rat, test_data, 1);
675 test_data[0] = (fbdiv - 1) >> 5 | 0x80;
676 rk32_dwc_phy_test_wr(dsi, code_pll_loop_div_rat, test_data, 1);
679 rk32_dwc_phy_test_wr(dsi, code_pll_input_loop_div_rat, test_data, 1);
683 rk32_dwc_phy_test_wr(dsi, 0x20, test_data, 1);
686 rk32_dwc_phy_test_wr(dsi, 0x21, test_data, 1);
689 rk32_dwc_phy_test_wr(dsi, 0x21, test_data, 1);
692 rk32_dwc_phy_test_wr(dsi, 0x22, test_data, 1);
694 test_data[0] = 0x80 | 0x7;
695 rk32_dwc_phy_test_wr(dsi, 0x22, test_data, 1);
697 test_data[0] = 0x80 | 15;
698 rk32_dwc_phy_test_wr(dsi, code_hstxdatalanerequsetstatetime, test_data, 1);
700 test_data[0] = 0x80 | 85;
701 rk32_dwc_phy_test_wr(dsi, code_hstxdatalanepreparestatetime, test_data, 1);
703 test_data[0] = 0x40 | 10;
704 rk32_dwc_phy_test_wr(dsi, code_hstxdatalanehszerostatetime, test_data, 1);
709 static int rk312x_phy_init(struct dsi *dsi, int n)
712 if (dsi->ops.id == DSI_RK3366) {
713 rk32_dsi_set_bits(dsi, 0x00, DSI_DPHY_BITS(0x06 << 2, 32, 0));
714 rk32_dsi_set_bits(dsi, 0x00, DSI_DPHY_BITS(0x07 << 2, 32, 0));
716 rk32_dsi_set_bits(dsi, 0x11, DSI_DPHY_BITS(0x06 << 2, 32, 0));
717 rk32_dsi_set_bits(dsi, 0x11, DSI_DPHY_BITS(0x07 << 2, 32, 0));
719 rk32_dsi_set_bits(dsi, 0xcc, DSI_DPHY_BITS(0x09<<2, 32, 0));
721 dsi_set_bits(0x4e, DSI_DPHY_BITS(0x08<<2, 32, 0));
722 dsi_set_bits(0x84, DSI_DPHY_BITS(0x0a<<2, 32, 0));
725 /*reg1[4] 0: enable a function of "pll phase for serial data being captured
728 we disable it here because reg5[6:4] is not compatible with the HS speed.
731 if (dsi->phy.ddr_clk >= 800*MHz) {
732 if (dsi->ops.id == DSI_RK3366) {
733 rk32_dsi_set_bits(dsi, 0x00,
734 DSI_DPHY_BITS(0x05 << 2, 32, 0));
735 } else if (dsi->ops.id == DSI_RK3368) {
736 rk32_dsi_set_bits(dsi, 0x10, DSI_DPHY_BITS(0x05<<2, 32, 0));
738 rk32_dsi_set_bits(dsi, 0x30, DSI_DPHY_BITS(0x05<<2, 32, 0));
741 rk32_dsi_set_bits(dsi, 1, reg_da_ppfc);
744 switch (dsi->host.lane) {
746 rk312x_mipi_dsi_phy_set_gotp(dsi, DPHY_LANE3_OFFSET, n);
748 rk312x_mipi_dsi_phy_set_gotp(dsi, DPHY_LANE2_OFFSET, n);
750 rk312x_mipi_dsi_phy_set_gotp(dsi, DPHY_LANE1_OFFSET, n);
752 rk312x_mipi_dsi_phy_set_gotp(dsi, DPHY_LANE0_OFFSET, n);
753 rk312x_mipi_dsi_phy_set_gotp(dsi, DPHY_CLOCK_OFFSET, n);
759 rk32_dsi_set_bits(dsi, 0x00e4, reg1_phy);
760 rk32_dsi_set_bits(dsi, 0x007d, reg0_phy);
762 rk32_dsi_set_bits(dsi, 0x00e0, reg1_phy);
763 rk32_dsi_set_bits(dsi, 0x001e, reg20_phy);
765 rk32_dsi_set_bits(dsi, 0x001f, reg20_phy);
767 rk32_dsi_set_bits(dsi, 0x0063, reg10_phy);
769 if (dsi->ops.id == DSI_RK3366) {
770 /* increasing the driver strength */
771 rk32_dsi_set_bits(dsi, 0x4f, reg8_phy);
772 rk32_dsi_set_bits(dsi, 0x5f, regb_phy);
773 /* increasing the slew rate */
774 rk32_dsi_set_bits(dsi, 0xc6, rega_phy);
775 } else if (dsi->ops.id == DSI_RK3368) {
776 rk32_dsi_set_bits(dsi, 0x1, reg5_phy);
777 rk32_dsi_set_bits(dsi, 0x9, regb_0_3_phy);
779 rk32_dsi_set_bits(dsi, 0x6, reg5_phy);
780 rk32_dsi_set_bits(dsi, 0x9, regb_0_3_phy);
782 rk32_dsi_set_bits(dsi, 0x6, reg10_4_6_phy);
787 static int rk_phy_init(struct dsi *dsi)
789 if (dsi->ops.id == DSI_RK3288 ||
790 dsi->ops.id == DSI_RK3399)
792 else if (dsi->ops.id == DSI_RK312x ||
793 dsi->ops.id == DSI_RK3368 ||
794 dsi->ops.id == DSI_RK3366)
795 rk312x_phy_init(dsi, 4);
799 static int rk32_mipi_dsi_host_power_up(struct dsi *dsi)
804 /* disable all interrupt */
805 rk32_dsi_set_bits(dsi, 0x1fffff, INT_MKS0);
806 rk32_dsi_set_bits(dsi, 0x3ffff, INT_MKS1);
808 rk32_mipi_dsi_is_enable(dsi, 1);
811 while (!rk32_dsi_get_bits(dsi, phylock) && val--) {
817 MIPI_TRACE("%s:phylock fail.\n", __func__);
821 while (!rk32_dsi_get_bits(dsi, phystopstateclklane) && val--) {
828 static int rk32_mipi_dsi_host_power_down(struct dsi *dsi)
830 rk32_mipi_dsi_enable_video_mode(dsi, 0);
831 rk32_mipi_dsi_enable_hs_clk(dsi, 0);
832 rk32_mipi_dsi_is_enable(dsi, 0);
836 static int rk32_mipi_dsi_host_init(struct dsi *dsi)
838 u32 val = 0, bytes_px = 0;
839 struct mipi_dsi_screen *screen = &dsi->screen;
840 u32 decimals = dsi->phy.Ttxbyte_clk, temp = 0, i = 0;
841 u32 m = 1, lane = dsi->host.lane, Tpclk = dsi->phy.Tpclk,
842 Ttxbyte_clk = dsi->phy.Ttxbyte_clk;
844 rk32_dsi_set_bits(dsi, dsi->host.lane - 1, n_lanes);
845 rk32_dsi_set_bits(dsi, dsi->vid, dpi_vcid);
847 switch (screen->face) {
849 rk32_dsi_set_bits(dsi, 5, dpi_color_coding);
854 rk32_dsi_set_bits(dsi, 3, dpi_color_coding);
855 rk32_dsi_set_bits(dsi, 1, en18_loosely);
859 rk32_dsi_set_bits(dsi, 0, dpi_color_coding);
864 if (dsi->ops.id == DSI_RK3288 ||
865 dsi->ops.id == DSI_RK3368 ||
866 dsi->ops.id == DSI_RK3366 ||
867 dsi->ops.id == DSI_RK3399) {
868 rk32_dsi_set_bits(dsi, 1, hsync_active_low);
869 rk32_dsi_set_bits(dsi, 1, vsync_active_low);
871 rk32_dsi_set_bits(dsi, 0, dataen_active_low);
872 rk32_dsi_set_bits(dsi, 0, colorm_active_low);
873 rk32_dsi_set_bits(dsi, 0, shutd_active_low);
874 } else if (dsi->ops.id == DSI_RK312x) {
875 rk32_dsi_set_bits(dsi, !screen->pin_hsync, hsync_active_low);
876 rk32_dsi_set_bits(dsi, !screen->pin_vsync, vsync_active_low);
878 rk32_dsi_set_bits(dsi, screen->pin_den, dataen_active_low);
879 rk32_dsi_set_bits(dsi, 0, colorm_active_low);
880 rk32_dsi_set_bits(dsi, 0, shutd_active_low);
883 rk32_dsi_set_bits(dsi, dsi->host.video_mode, vid_mode_type); /* burst mode */
885 switch (dsi->host.video_mode) {
887 if (screen->type == SCREEN_DUAL_MIPI)
888 rk32_dsi_set_bits(dsi, screen->x_res / 2 + 4, vid_pkt_size);
890 rk32_dsi_set_bits(dsi, screen->x_res, vid_pkt_size);
894 for (i = 8; i < 32; i++) {
895 temp = i * lane * Tpclk % Ttxbyte_clk;
896 if (decimals > temp) {
904 rk32_dsi_set_bits(dsi, screen->x_res / m + 1, num_chunks);
905 rk32_dsi_set_bits(dsi, m, vid_pkt_size);
906 temp = m * lane * Tpclk / Ttxbyte_clk - m * bytes_px;
907 MIPI_DBG("%s:%d, %d\n", __func__, m, temp);
910 rk32_dsi_set_bits(dsi, temp - 12, null_pkt_size);
916 /* rk32_dsi_set_bits(dsi, 0, CMD_MODE_CFG << 16); */
917 if (screen->type == SCREEN_MIPI) {
918 rk32_dsi_set_bits(dsi, dsi->phy.Tpclk * (screen->x_res + screen->left_margin +
919 screen->hsync_len + screen->right_margin) \
920 / dsi->phy.Ttxbyte_clk, vid_hline_time);
921 } else { /* used for dual mipi screen */
922 rk32_dsi_set_bits(dsi, dsi->phy.Tpclk * (screen->x_res + 8 + screen->left_margin +
923 screen->hsync_len + screen->right_margin) \
924 / dsi->phy.Ttxbyte_clk, vid_hline_time);
926 MIPI_DBG("dsi->phy.Tpclk = %d\n", dsi->phy.Tpclk);
927 MIPI_DBG("screen->left_margin = %d\n", screen->left_margin);
928 MIPI_DBG("dsi->phy.Ttxbyte_clk = %d\n", dsi->phy.Ttxbyte_clk);
929 MIPI_DBG("screen->hsync_len = %d\n", screen->hsync_len);
930 rk32_dsi_set_bits(dsi, dsi->phy.Tpclk * (screen->left_margin) / dsi->phy.Ttxbyte_clk,
932 rk32_dsi_set_bits(dsi, dsi->phy.Tpclk * (screen->hsync_len) / dsi->phy.Ttxbyte_clk,
935 rk32_dsi_set_bits(dsi, screen->y_res , vid_active_lines);
936 rk32_dsi_set_bits(dsi, screen->lower_margin, vid_vfp_lines);
937 rk32_dsi_set_bits(dsi, screen->upper_margin, vid_vbp_lines);
938 rk32_dsi_set_bits(dsi, screen->vsync_len, vid_vsa_lines);
940 dsi->phy.txclkesc = 20 * MHz;
941 val = dsi->phy.txbyte_clk / dsi->phy.txclkesc + 1;
942 dsi->phy.txclkesc = dsi->phy.txbyte_clk / val;
943 rk32_dsi_set_bits(dsi, val, TX_ESC_CLK_DIVISION);
945 rk32_dsi_set_bits(dsi, 10, TO_CLK_DIVISION);
946 rk32_dsi_set_bits(dsi, 1000, hstx_to_cnt); /* no sure */
947 rk32_dsi_set_bits(dsi, 1000, lprx_to_cnt);
948 if (dsi->ops.id == DSI_RK3399)
949 rk32_dsi_set_bits(dsi, 32, phy_stop_wait_time);
951 rk32_dsi_set_bits(dsi, 100, phy_stop_wait_time);
953 /* enable send command in low power mode */
954 rk32_dsi_set_bits(dsi, 4, outvact_lpcmd_time);
955 rk32_dsi_set_bits(dsi, 4, invact_lpcmd_time);
956 rk32_dsi_set_bits(dsi, 1, lp_cmd_en);
958 rk32_dsi_set_bits(dsi, 20, phy_hs2lp_time);
959 rk32_dsi_set_bits(dsi, 16, phy_lp2hs_time);
961 rk32_dsi_set_bits(dsi, 87, phy_hs2lp_time_clk_lane);
962 rk32_dsi_set_bits(dsi, 25, phy_hs2hs_time_clk_lane);
964 rk32_dsi_set_bits(dsi, 10000, max_rd_time);
966 rk32_dsi_set_bits(dsi, 1, lp_hfp_en);
967 /* rk32_dsi_set_bits(dsi, 1, lp_hbp_en); */
968 rk32_dsi_set_bits(dsi, 1, lp_vact_en);
969 rk32_dsi_set_bits(dsi, 1, lp_vfp_en);
970 rk32_dsi_set_bits(dsi, 1, lp_vbp_en);
971 rk32_dsi_set_bits(dsi, 1, lp_vsa_en);
973 /* rk32_dsi_set_bits(dsi, 1, frame_bta_ack_en); */
974 rk32_dsi_set_bits(dsi, 1, phy_enableclk);
975 rk32_dsi_set_bits(dsi, 0, phy_tx_triggers);
977 if (screen->refresh_mode == COMMAND_MODE) {
978 rk32_dsi_set_bits(dsi, screen->x_res, edpi_cmd_size);
979 rk32_dsi_set_bits(dsi, 1, tear_fx_en);
982 /* enable non-continued function */
983 /* rk32_dsi_set_bits(dsi, 1, auto_clklane_ctrl); */
985 rk32_dsi_set_bits(dsi, 1, phy_txexitulpslan);
986 rk32_dsi_set_bits(dsi, 1, phy_txexitulpsclk);
992 * mipi protocol layer definition
994 static int rk_mipi_dsi_init(void *arg, u32 n)
996 u32 decimals = 1000, i = 0, pre = 0;
997 struct dsi *dsi = arg;
998 struct mipi_dsi_screen *screen = &dsi->screen;
1003 if ((screen->type != SCREEN_MIPI) && (screen->type != SCREEN_DUAL_MIPI)) {
1004 MIPI_TRACE("only mipi dsi lcd is supported!\n");
1008 if (((screen->type == SCREEN_DUAL_MIPI) && (rk_mipi_get_dsi_num() == 1)) || ((screen->type == SCREEN_MIPI) && (rk_mipi_get_dsi_num() == 2))) {
1009 MIPI_TRACE("dsi number and mipi type not match!\n");
1013 dsi->phy.Tpclk = rk_fb_get_prmry_screen_pixclock();
1015 if (dsi->phy.refclk)
1016 dsi->phy.ref_clk = clk_get_rate(dsi->phy.refclk) ;
1017 if (dsi->ops.id == DSI_RK312x ||
1018 dsi->ops.id == DSI_RK3368 ||
1019 dsi->ops.id == DSI_RK3366)
1020 dsi->phy.ref_clk = dsi->phy.ref_clk / 2; /* 1/2 of input refclk */
1022 dsi->phy.sys_clk = dsi->phy.ref_clk;
1024 printk("dsi->phy.sys_clk =%d\n", dsi->phy.sys_clk);
1025 if (dsi->ops.id == DSI_RK3288 ||
1026 dsi->ops.id == DSI_RK3399) {
1027 if ((screen->hs_tx_clk <= 90 * MHz) || (screen->hs_tx_clk >= 1500 * MHz))
1028 dsi->phy.ddr_clk = 1500 * MHz; /* default is 1.5HGz */
1030 dsi->phy.ddr_clk = screen->hs_tx_clk;
1031 } else if (dsi->ops.id == DSI_RK312x ||
1032 dsi->ops.id == DSI_RK3368 ||
1033 dsi->ops.id == DSI_RK3366) {
1034 if ((screen->hs_tx_clk <= 80 * MHz) || (screen->hs_tx_clk >= 1000 * MHz))
1035 dsi->phy.ddr_clk = 1000 * MHz; /* default is 1GHz */
1037 dsi->phy.ddr_clk = screen->hs_tx_clk;
1041 dsi->phy.ddr_clk = n;
1043 decimals = dsi->phy.ref_clk;
1044 for (i = 1; i < 6; i++) {
1045 pre = dsi->phy.ref_clk / i;
1046 if ((decimals > (dsi->phy.ddr_clk % pre)) && (dsi->phy.ddr_clk / pre < 512)) {
1047 decimals = dsi->phy.ddr_clk % pre;
1048 dsi->phy.prediv = i;
1049 dsi->phy.fbdiv = dsi->phy.ddr_clk / pre;
1055 MIPI_DBG("prediv:%d, fbdiv:%d,dsi->phy.ddr_clk:%d\n", dsi->phy.prediv, dsi->phy.fbdiv, dsi->phy.ref_clk / dsi->phy.prediv * dsi->phy.fbdiv);
1057 dsi->phy.ddr_clk = dsi->phy.ref_clk / dsi->phy.prediv * dsi->phy.fbdiv;
1059 MIPI_DBG("dsi->phy.ddr_clk =%d\n", dsi->phy.ddr_clk);
1060 dsi->phy.txbyte_clk = dsi->phy.ddr_clk / 8;
1062 dsi->phy.txclkesc = 20 * MHz; /* < 20MHz */
1063 dsi->phy.txclkesc = dsi->phy.txbyte_clk / (dsi->phy.txbyte_clk / dsi->phy.txclkesc + 1);
1065 dsi->phy.pclk = div_u64(1000000000000llu, dsi->phy.Tpclk);
1066 dsi->phy.Ttxclkesc = div_u64(1000000000000llu, dsi->phy.txclkesc);
1067 dsi->phy.Tsys_clk = div_u64(1000000000000llu, dsi->phy.sys_clk);
1068 dsi->phy.Tddr_clk = div_u64(1000000000000llu, dsi->phy.ddr_clk);
1069 dsi->phy.Ttxbyte_clk = div_u64(1000000000000llu, dsi->phy.txbyte_clk);
1071 dsi->phy.UI = dsi->phy.Tddr_clk;
1074 if (screen->dsi_lane > 0 && screen->dsi_lane <= 4)
1075 dsi->host.lane = screen->dsi_lane;
1079 dsi->host.video_mode = VM_BM;
1081 MIPI_DBG("UI:%d\n", dsi->phy.UI);
1082 MIPI_DBG("ref_clk:%d\n", dsi->phy.ref_clk);
1083 MIPI_DBG("pclk:%d, Tpclk:%d\n", dsi->phy.pclk, dsi->phy.Tpclk);
1084 MIPI_DBG("sys_clk:%d, Tsys_clk:%d\n", dsi->phy.sys_clk, dsi->phy.Tsys_clk);
1085 MIPI_DBG("ddr_clk:%d, Tddr_clk:%d\n", dsi->phy.ddr_clk, dsi->phy.Tddr_clk);
1086 MIPI_DBG("txbyte_clk:%d, Ttxbyte_clk:%d\n", dsi->phy.txbyte_clk,
1087 dsi->phy.Ttxbyte_clk);
1088 MIPI_DBG("txclkesc:%d, Ttxclkesc:%d\n", dsi->phy.txclkesc, dsi->phy.Ttxclkesc);
1091 rk_phy_power_up(dsi);
1092 rk32_mipi_dsi_host_power_up(dsi);
1094 rk32_mipi_dsi_host_init(dsi);
1099 static int rk32_mipi_dsi_is_enable(void *arg, u32 enable)
1101 struct dsi *dsi = arg;
1103 rk32_dsi_set_bits(dsi, enable, shutdownz);
1107 static int rk32_mipi_dsi_enable_video_mode(void *arg, u32 enable)
1109 struct dsi *dsi = arg;
1111 rk32_dsi_set_bits(dsi, !enable, cmd_video_mode);
1115 static int rk32_mipi_dsi_enable_command_mode(void *arg, u32 enable)
1117 struct dsi *dsi = arg;
1119 rk32_dsi_set_bits(dsi, enable, cmd_video_mode);
1123 static int rk32_mipi_dsi_enable_hs_clk(void *arg, u32 enable)
1125 struct dsi *dsi = arg;
1127 rk32_dsi_set_bits(dsi, enable, phy_txrequestclkhs);
1131 static int rk32_mipi_dsi_is_active(void *arg)
1133 struct dsi *dsi = arg;
1135 return rk32_dsi_get_bits(dsi, shutdownz);
1138 static int rk32_mipi_dsi_send_packet(void *arg, unsigned char cmds[], u32 length)
1140 struct dsi *dsi = arg;
1141 unsigned char *regs;
1142 u32 type, liTmp = 0, i = 0, j = 0, data = 0;
1144 if (rk32_dsi_get_bits(dsi, gen_cmd_full) == 1) {
1145 MIPI_TRACE("gen_cmd_full\n");
1148 regs = kmalloc(0x400, GFP_KERNEL);
1150 printk("request regs fail!\n");
1153 memcpy(regs, cmds, length);
1159 case DTYPE_DCS_SWRITE_0P:
1160 rk32_dsi_set_bits(dsi, regs[0], dcs_sw_0p_tx);
1161 data = regs[2] << 8 | type;
1163 case DTYPE_DCS_SWRITE_1P:
1164 rk32_dsi_set_bits(dsi, regs[0], dcs_sw_1p_tx);
1165 data = regs[2] << 8 | type;
1166 data |= regs[3] << 16;
1168 case DTYPE_DCS_LWRITE:
1169 rk32_dsi_set_bits(dsi, regs[0], dcs_lw_tx);
1170 for (i = 0; i < liTmp; i++) {
1171 regs[i] = regs[i+2];
1173 for (i = 0; i < liTmp; i++) {
1175 data |= regs[i] << (j * 8);
1176 if (j == 3 || ((i + 1) == liTmp)) {
1177 if (rk32_dsi_get_bits(dsi, gen_pld_w_full) == 1) {
1178 MIPI_TRACE("gen_pld_w_full :%d\n", i);
1181 rk32_dsi_set_bits(dsi, data, GEN_PLD_DATA);
1182 MIPI_DBG("write GEN_PLD_DATA:%d, %08x\n", i, data);
1187 data |= (liTmp & 0xffff) << 8;
1189 case DTYPE_GEN_LWRITE:
1190 rk32_dsi_set_bits(dsi, regs[0], gen_lw_tx);
1191 for (i = 0; i < liTmp; i++) {
1192 regs[i] = regs[i+2];
1194 for (i = 0; i < liTmp; i++) {
1196 data |= regs[i] << (j * 8);
1197 if (j == 3 || ((i + 1) == liTmp)) {
1198 if (rk32_dsi_get_bits(dsi, gen_pld_w_full) == 1) {
1199 MIPI_TRACE("gen_pld_w_full :%d\n", i);
1202 rk32_dsi_set_bits(dsi, data, GEN_PLD_DATA);
1203 MIPI_DBG("write GEN_PLD_DATA:%d, %08x\n", i, data);
1207 data = (dsi->vid << 6) | type;
1208 data |= (liTmp & 0xffff) << 8;
1210 case DTYPE_GEN_SWRITE_2P: /* one command and one parameter */
1211 rk32_dsi_set_bits(dsi, regs[0], gen_sw_2p_tx);
1213 /* It is used for normal Generic Short WRITE Packet with 2 parameters. */
1215 data |= regs[2] << 8; /* dcs command */
1216 data |= regs[3] << 16; /* parameter of command */
1220 /* The below is used for Generic Short WRITE Packet with 2 parameters
1221 * that more than 2 parameters. Though it is illegal dcs command, we can't
1222 * make sure the users do not send that command.
1224 for (i = 0; i < liTmp; i++) {
1225 regs[i] = regs[i+2];
1227 for (i = 0; i < liTmp; i++) {
1229 data |= regs[i] << (j * 8);
1230 if (j == 3 || ((i + 1) == liTmp)) {
1231 if (rk32_dsi_get_bits(dsi, gen_pld_w_full) == 1) {
1232 MIPI_TRACE("gen_pld_w_full :%d\n", i);
1235 rk32_dsi_set_bits(dsi, data, GEN_PLD_DATA);
1236 MIPI_DBG("write GEN_PLD_DATA:%d, %08x\n", i, data);
1241 data |= (liTmp & 0xffff) << 8;
1243 case DTYPE_GEN_SWRITE_1P: /* one command without parameter */
1244 rk32_dsi_set_bits(dsi, regs[0], gen_sw_1p_tx);
1246 data |= regs[2] << 8;
1248 case DTYPE_GEN_SWRITE_0P: /* nop packet without command and parameter */
1249 rk32_dsi_set_bits(dsi, regs[0], gen_sw_0p_tx);
1253 printk("0x%x:this type not suppport!\n", type);
1256 MIPI_DBG("%d command sent in %s size:%d\n", __LINE__, regs[0] ? "LP mode" : "HS mode", liTmp);
1258 MIPI_DBG("write GEN_HDR:%08x\n", data);
1259 rk32_dsi_set_bits(dsi, data, GEN_HDR);
1262 while (!rk32_dsi_get_bits(dsi, gen_cmd_empty) && i--) {
1271 static int rk32_mipi_dsi_read_dcs_packet(void *arg, unsigned char *data1, u32 n)
1273 struct dsi *dsi = arg;
1274 unsigned char regs[2];
1281 rk32_dsi_set_bits(dsi, regs[0], dcs_sr_0p_tx);
1283 if(type == DTYPE_GEN_SWRITE_0P)
1284 data = (dsi->vid << 6) | (n << 4) | type;
1286 data = (dsi->vid << 6) | ((n-1) << 4) | type;
1289 data |= regs[1] << 8 | type;
1291 printk("write GEN_HDR:%08x\n", data);
1293 rk32_dsi_set_bits(dsi, 0xFFFF, bta_to_cnt);
1294 rk32_dsi_set_bits(dsi, 1, bta_en);
1295 rk32_dsi_set_bits(dsi, data, GEN_HDR);
1298 printk("rk32_mipi_dsi_read_dcs_packet==0x%x\n", rk32_dsi_get_bits(dsi, GEN_PLD_DATA));
1299 rk32_dsi_set_bits(dsi, 0, bta_en);
1304 static int rk32_mipi_dsi_power_up(void *arg)
1306 struct dsi *dsi = arg;
1308 rk32_phy_power_up(dsi);
1309 rk32_mipi_dsi_host_power_up(dsi);
1313 static int rk32_mipi_dsi_power_down(void *arg)
1315 struct dsi *dsi = arg;
1316 struct mipi_dsi_screen *screen = &dsi->screen;
1321 rk32_mipi_dsi_host_power_down(dsi);
1322 rk_phy_power_down(dsi);
1324 MIPI_TRACE("%s:%d\n", __func__, __LINE__);
1328 static int rk32_mipi_dsi_get_id(void *arg)
1331 struct dsi *dsi = arg;
1333 id = rk32_dsi_get_bits(dsi, VERSION);
1337 #ifdef MIPI_DSI_REGISTER_IO
1338 #include <linux/proc_fs.h>
1339 #include <asm/uaccess.h>
1340 #include <linux/slab.h>
1342 ssize_t reg_proc_write(struct file *file, const char __user *buff, size_t count, loff_t *offp)
1344 int ret = -1, i = 0;
1346 char *buf = kmalloc(count, GFP_KERNEL);
1351 memset(buf, 0, count);
1352 ret = copy_from_user((void *)buf, buff, count);
1353 data = strstr(data, "-");
1355 goto reg_proc_write_exit;
1356 command = *(++data);
1360 data = strstr(data, "0x");
1362 goto reg_proc_write_exit;
1363 sscanf(data, "0x%llx", ®s_val);
1364 if ((regs_val & 0xffff00000000ULL) == 0)
1365 goto reg_proc_write_exit;
1366 read_val = regs_val & 0xffffffff;
1367 printk("regs_val=0x%llx\n", regs_val);
1368 rk32_dsi_write_reg(dsi0, regs_val >> 32, &read_val);
1369 rk32_dsi_read_reg(dsi0, regs_val >> 32, &read_val);
1370 regs_val &= 0xffffffff;
1371 if (read_val != regs_val)
1372 MIPI_TRACE("%s fail:0x%08x\n", __func__, read_val);
1378 data = strstr(data, "0x");
1380 goto reg_proc_write_exit;
1382 sscanf(data, "0x%llx", ®s_val);
1383 rk32_dsi_read_reg(dsi0, (u16)regs_val, &read_val);
1384 MIPI_TRACE("*%04x : %08x\n", (u16)regs_val, read_val);
1388 while (*(++data) == ' ')
1390 sscanf(data, "%d", &read_val);
1392 read_val = 11289600;
1399 while (*(++data) == ' ')
1405 MIPI_TRACE("payload entry is larger than 32\n");
1408 sscanf(data, "%x,", (unsigned int *)(str + i)); /* -c 1,29,02,03,05,06,> pro */
1409 data = strstr(data, ",");
1420 rk32_mipi_dsi_send_packet(dsi0, str, read_val);
1422 rk32_mipi_dsi_send_packet(dsi0, str, read_val);
1433 reg_proc_write_exit:
1439 int reg_proc_read(struct seq_file *s, void *v)
1443 struct dsi *dsi = s->private;
1445 for (i = VERSION; i < (VERSION + (0xdc << 16)); i += 4<<16) {
1446 val = rk32_dsi_get_bits(dsi, i);
1447 seq_printf(s, "%04x: %08x\n", i>>16, val);
1451 static int reg_proc_open(struct inode *inode, struct file *file)
1453 struct dsi *dsi = inode->i_private;
1455 return single_open(file, reg_proc_read, dsi);
1458 int reg_proc_close(struct inode *inode, struct file *file)
1463 struct file_operations reg_proc_fops = {
1464 .owner = THIS_MODULE,
1465 .open = reg_proc_open,
1466 .release = reg_proc_close,
1467 .write = reg_proc_write,
1471 ssize_t reg_proc_write1(struct file *file, const char __user *buff, size_t count, loff_t *offp)
1473 int ret = -1, i = 0;
1475 char *buf = kmalloc(count, GFP_KERNEL);
1480 memset(buf, 0, count);
1481 ret = copy_from_user((void *)buf, buff, count);
1483 data = strstr(data, "-");
1485 goto reg_proc_write_exit;
1486 command = *(++data);
1491 data = strstr(data, "0x");
1493 goto reg_proc_write_exit;
1494 sscanf(data, "0x%llx", ®s_val);
1495 if ((regs_val & 0xffff00000000ULL) == 0)
1496 goto reg_proc_write_exit;
1497 read_val = regs_val & 0xffffffff;
1498 rk32_dsi_write_reg(dsi1, regs_val >> 32, &read_val);
1499 rk32_dsi_read_reg(dsi1, regs_val >> 32, &read_val);
1500 regs_val &= 0xffffffff;
1501 if (read_val != regs_val)
1502 MIPI_TRACE("%s fail:0x%08x\n", __func__, read_val);
1508 data = strstr(data, "0x");
1510 goto reg_proc_write_exit;
1511 sscanf(data, "0x%llx", ®s_val);
1512 rk32_dsi_read_reg(dsi1, (u16)regs_val, &read_val);
1513 MIPI_TRACE("*%04x : %08x\n", (u16)regs_val, read_val);
1517 while (*(++data) == ' ')
1519 sscanf(data, "%d", &read_val);
1521 read_val = 11289600;
1528 while (*(++data) == ' ')
1534 MIPI_TRACE("payload entry is larger than 32\n");
1537 sscanf(data, "%x,", (unsigned int *)(str + i)); /* -c 1,29,02,03,05,06,> pro */
1538 data = strstr(data, ",");
1549 rk32_mipi_dsi_send_packet(dsi1, str, read_val);
1551 rk32_mipi_dsi_send_packet(dsi1, str, read_val);
1562 reg_proc_write_exit:
1568 int reg_proc_close1(struct inode *inode, struct file *file)
1573 struct file_operations reg_proc_fops1 = {
1574 .owner = THIS_MODULE,
1575 .open = reg_proc_open,
1576 .release = reg_proc_close1,
1577 .write = reg_proc_write1,
1581 #if 0/* def CONFIG_MIPI_DSI_LINUX */
1582 static irqreturn_t rk32_mipi_dsi_irq_handler(int irq, void *data)
1584 printk("-------rk32_mipi_dsi_irq_handler-------\n");
1590 static int dwc_phy_test_rd(struct dsi *dsi, unsigned char test_code)
1594 rk32_dsi_set_bits(dsi, 0x10000 | test_code, PHY_TEST_CTRL1);
1595 rk32_dsi_set_bits(dsi, 0x2, PHY_TEST_CTRL0);
1596 rk32_dsi_set_bits(dsi, 0x0, PHY_TEST_CTRL0);
1598 val = rk32_dsi_get_bits(dsi, PHY_TEST_CTRL1);
1602 static int rk32_dsi_enable(void)
1605 MIPI_DBG("rk32_dsi_enable-------\n");
1606 if (!dsi0->clk_on) {
1608 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 0))
1609 pm_runtime_get_sync(&dsi0->pdev->dev);
1611 opt_mode = dsi0->screen.refresh_mode;
1612 rk_fb_get_prmry_screen(dsi0->screen.screen);
1613 dsi0->screen.lcdc_id = dsi0->screen.screen->lcdc_id;
1614 rk32_init_phy_mode(dsi0->screen.lcdc_id);
1617 if (rk_mipi_get_dsi_num() == 2)
1620 rk_mipi_screen_standby(0);
1622 /* After the core reset, DPI waits for the first VSYNC
1623 active transition to start signal sampling, including pixel data,
1624 and preventing image transmission in the middle of a frame.
1626 dsi_is_enable(0, 0);
1627 if (rk_mipi_get_dsi_num() == 2)
1628 dsi_is_enable(1, 0);
1630 if (opt_mode != COMMAND_MODE) {
1631 dsi_enable_video_mode(0, 1);
1632 if (rk_mipi_get_dsi_num() == 2)
1633 dsi_enable_video_mode(1, 1);
1635 dsi_is_enable(0, 1);
1636 if (rk_mipi_get_dsi_num() == 2)
1637 dsi_is_enable(1, 1);
1642 static void rockchip_mipi_cmd_mode_refresh(unsigned int xpos,
1649 u32 x1 = x0 + xsize - 1;
1650 u32 y1 = y0 + ysize - 1;
1652 unsigned char x0_MSB = ((x0 >> 8) & 0xff);
1653 unsigned char x0_LSB = (x0 & 0xff);
1654 unsigned char x1_MSB = ((x1 >> 8) & 0xff);
1655 unsigned char x1_LSB = (x1 & 0xff);
1656 unsigned char y0_MSB = ((y0 >> 8) & 0xff);
1657 unsigned char y0_LSB = (y0 & 0xff);
1658 unsigned char y1_MSB = ((y1 >> 8) & 0xff);
1659 unsigned char y1_LSB = (y1 & 0xff);
1661 unsigned char set_col_cmd[7] = {0};
1662 unsigned char set_page_cmd[7] = {0};
1663 unsigned char wms[3] = {0};
1666 set_col_cmd[0] = HSDT;
1667 set_col_cmd[1] = 0x39;
1668 set_col_cmd[2] = 0x2a;
1669 set_col_cmd[3] = x0_MSB;
1670 set_col_cmd[4] = x0_LSB;
1671 set_col_cmd[5] = x1_MSB;
1672 set_col_cmd[6] = x1_LSB;
1674 len = ARRAY_SIZE(set_col_cmd);
1675 rk32_mipi_dsi_send_packet(dsi0, set_col_cmd, len);
1676 if (rk_mipi_get_dsi_num() == 2)
1677 rk32_mipi_dsi_send_packet(dsi1, set_col_cmd, len);
1679 set_page_cmd[0] = HSDT;
1680 set_page_cmd[1] = 0x39;
1681 set_page_cmd[2] = 0x2b;
1682 set_page_cmd[3] = y0_MSB;
1683 set_page_cmd[4] = y0_LSB;
1684 set_page_cmd[5] = y1_MSB;
1685 set_page_cmd[6] = y1_LSB;
1687 len = ARRAY_SIZE(set_page_cmd);
1688 rk32_mipi_dsi_send_packet(dsi0, set_page_cmd, len);
1689 if (rk_mipi_get_dsi_num() == 2)
1690 rk32_mipi_dsi_send_packet(dsi1, set_page_cmd, len);
1696 len = ARRAY_SIZE(wms);
1697 rk32_mipi_dsi_send_packet(dsi0, wms, len);
1698 if (rk_mipi_get_dsi_num() == 2)
1699 rk32_mipi_dsi_send_packet(dsi1, wms, len);
1702 #ifdef CONFIG_MIPI_DSI_LINUX
1703 static int rk32_dsi_disable(void)
1705 MIPI_DBG("rk32_dsi_disable-------\n");
1708 rk_mipi_screen_standby(1);
1710 if (rk_mipi_get_dsi_num() == 2)
1712 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 0))
1713 pm_runtime_put(&dsi0->pdev->dev);
1719 static struct rk_fb_trsm_ops trsm_dsi_ops = {
1720 .enable = rk32_dsi_enable,
1721 .disable = rk32_dsi_disable,
1722 .dsp_pwr_on = rk32_mipi_power_up_DDR,
1723 .dsp_pwr_off = rk32_mipi_power_down_DDR,
1724 .refresh = rockchip_mipi_cmd_mode_refresh,
1728 static void rockchip_3399_grf_config(int lcdc_id)
1733 dsi_num = rk_mipi_get_dsi_num();
1736 val = 0x1 << 16 | 0x1;
1737 regmap_write(dsi0->grf_base, RK3399_GRF_CON20, val);
1739 val = 0x1 << 16 | 0x0;
1740 regmap_write(dsi0->grf_base, RK3399_GRF_CON20, val);
1743 val = 0x1 << 28 | 0x0 << 12;
1744 val |= 0xf << 20 | 0x0 << 4;
1745 val |= 0xf << 16 | 0x0;
1746 regmap_write(dsi0->grf_base, RK3399_GRF_CON22, val);
1749 val = 0x1 << 16 | 0x1;
1750 val |= 0x1 << 20 | 0x1 << 4;
1751 regmap_write(dsi0->grf_base, RK3399_GRF_CON20, val);
1753 val = 0x1 << 16 | 0x0;
1754 val |= 0x1 << 20 | 0x0 << 4;
1755 regmap_write(dsi0->grf_base, RK3399_GRF_CON20, val);
1758 val = 0x1 << 28 | 0x0 << 12;
1759 val |= 0xf << 20 | 0x0 << 4;
1760 val |= 0xf << 16 | 0x0;
1761 regmap_write(dsi0->grf_base, RK3399_GRF_CON22, val);
1763 val = 0x1 << 20 | 0x0 << 0x4;
1764 regmap_write(dsi0->grf_base, RK3399_GRF_CON7, val);
1766 val = 0xf << 24 | 0x0 << 8;
1767 val |= 0xf << 20 | 0x0 << 4;
1768 val |= 0xf << 16 | 0x0;
1769 regmap_write(dsi0->grf_base, RK3399_GRF_CON23, val);
1771 val = 0x1 << 22 | 0x1 << 6;
1772 val |= 0x1 << 21 | 0x0 << 5;
1773 regmap_write(dsi0->grf_base, RK3399_GRF_CON24, val);
1775 val = 0xf << 24 | 0x0 << 8;
1776 val |= 0xf << 20 | 0x0 << 4;
1777 val |= 0xf << 16 | 0xf;
1778 regmap_write(dsi0->grf_base, RK3399_GRF_CON23, val);
1782 static void rk32_init_phy_mode(int lcdc_id)
1784 int val0 = 0, val1 = 0;
1786 MIPI_DBG("rk32_init_phy_mode----------lcdc_id=%d\n", lcdc_id);
1788 /* Only the rk3288 VOP need setting the VOP output. */
1789 if (dsi0->ops.id == DSI_RK3288) {
1790 /* D-PHY mode select */
1791 if (rk_mipi_get_dsi_num() == 1) {
1793 /* 1'b1: VOP LIT output to DSI host0;1'b0: VOP BIG output to DSI host0 */
1794 val0 = 0x1 << 22 | 0x1 << 6;
1796 val0 = 0x1 << 22 | 0x0 << 6;
1797 writel_relaxed(val0, RK_GRF_VIRT + RK3288_GRF_SOC_CON6);
1800 val0 = 0x1 << 25 | 0x1 << 9 | 0x1 << 22 | 0x1 << 6;
1801 val1 = 0x1 << 31 | 0x1 << 30 | 0x0 << 15 | 0x1 << 14;
1803 val0 = 0x1 << 25 | 0x0 << 9 | 0x1 << 22 | 0x0 << 14;
1804 val1 = 0x1 << 31 | 0x1 << 30 | 0x0 << 15 | 0x1 << 14;
1806 writel_relaxed(val0, RK_GRF_VIRT + RK3288_GRF_SOC_CON6);
1807 writel_relaxed(val1, RK_GRF_VIRT + RK3288_GRF_SOC_CON14);
1809 } else if (dsi0->ops.id == DSI_RK3399) {
1810 rockchip_3399_grf_config(lcdc_id);
1814 #ifdef CONFIG_MIPI_DSI_LINUX
1815 static int rk32_mipi_power_down_DDR(void)
1817 dsi_is_enable(0, 0);
1818 if (rk_mipi_get_dsi_num() == 2)
1819 dsi_is_enable(1, 0);
1823 static int rk32_mipi_power_up_DDR(void)
1825 dsi_is_enable(0, 0);
1826 if (rk_mipi_get_dsi_num() == 2)
1827 dsi_is_enable(1, 0);
1828 dsi_enable_video_mode(0, 1);
1829 dsi_enable_video_mode(1, 1);
1830 dsi_is_enable(0, 1);
1831 if (rk_mipi_get_dsi_num() == 2)
1832 dsi_is_enable(1, 1);
1841 static struct dsi_type dsi_rk312x = {
1842 .label = "rk312-dsi",
1843 .dsi_id = DSI_RK312x,
1846 static struct dsi_type dsi_rk32 = {
1847 .label = "rk32-dsi",
1848 .dsi_id = DSI_RK3288,
1851 static struct dsi_type dsi_rk3368 = {
1852 .label = "rk3368-dsi",
1853 .dsi_id = DSI_RK3368,
1856 static struct dsi_type dsi_rk3366 = {
1857 .label = "rk3366-dsi",
1858 .dsi_id = DSI_RK3366,
1861 static struct dsi_type dsi_rk3399 = {
1862 .label = "rk3399-dsi",
1863 .dsi_id = DSI_RK3399,
1866 static const struct of_device_id of_rk_mipi_dsi_match[] = {
1867 { .compatible = "rockchip,rk32-dsi", .data = &dsi_rk32},
1868 { .compatible = "rockchip,rk312x-dsi", .data = &dsi_rk312x},
1869 { .compatible = "rockchip,rk3368-dsi", .data = &dsi_rk3368},
1870 { .compatible = "rockchip,rk3366-dsi", .data = &dsi_rk3366},
1871 { .compatible = "rockchip,rk3399-dsi", .data = &dsi_rk3399},
1875 static int rk32_mipi_dsi_probe(struct platform_device *pdev)
1880 struct mipi_dsi_ops *ops;
1881 struct rk_screen *screen;
1882 struct mipi_dsi_screen *dsi_screen;
1883 struct resource *res_host, *res_phy;
1884 struct device_node *np = pdev->dev.of_node;
1885 const struct dsi_type *data;
1886 const struct of_device_id *of_id =
1887 of_match_device(of_rk_mipi_dsi_match, &pdev->dev);
1889 dev_err(&pdev->dev, "failed to match device\n");
1894 dsi = devm_kzalloc(&pdev->dev, sizeof(struct dsi), GFP_KERNEL);
1896 dev_err(&pdev->dev, "request struct dsi fail!\n");
1899 dsi->ops.id = data->dsi_id;
1900 printk(KERN_INFO "%s\n", data->label);
1901 if (dsi->ops.id == DSI_RK3288 ||
1902 dsi->ops.id == DSI_RK3399) {
1903 res_host = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1904 dsi->host.membase = devm_ioremap_resource(&pdev->dev, res_host);
1905 if (IS_ERR(dsi->host.membase)) {
1906 dev_err(&pdev->dev, "get resource mipi host membase fail!\n");
1907 return PTR_ERR(dsi->host.membase);
1909 } else if (dsi->ops.id == DSI_RK312x ||
1910 dsi->ops.id == DSI_RK3368 ||
1911 dsi->ops.id == DSI_RK3366) {
1912 res_host = platform_get_resource_byname(pdev, IORESOURCE_MEM, "mipi_dsi_host");
1913 dsi->host.membase = devm_ioremap_resource(&pdev->dev, res_host);
1914 if (IS_ERR(dsi->host.membase)) {
1915 dev_err(&pdev->dev, "get resource mipi host membase fail!\n");
1916 return PTR_ERR(dsi->host.membase);
1918 res_phy = platform_get_resource_byname(pdev, IORESOURCE_MEM, "mipi_dsi_phy");
1919 dsi->phy.membase = devm_ioremap_resource(&pdev->dev, res_phy);
1920 if (IS_ERR(dsi->phy.membase)) {
1921 dev_err(&pdev->dev, "get resource mipi phy membase fail!\n");
1922 return PTR_ERR(dsi->phy.membase);
1926 dsi->phy.refclk = devm_clk_get(&pdev->dev, "clk_mipi_24m");
1927 if (unlikely(IS_ERR(dsi->phy.refclk))) {
1928 dev_err(&pdev->dev, "get clk_mipi_24m clock fail\n");
1929 return PTR_ERR(dsi->phy.refclk);
1932 /* Get the APB bus clk access mipi phy */
1933 dsi->dsi_pclk = devm_clk_get(&pdev->dev, "pclk_mipi_dsi");
1934 if (unlikely(IS_ERR(dsi->dsi_pclk))) {
1935 dev_err(&pdev->dev, "get pclk_mipi_dsi clock fail\n");
1936 return PTR_ERR(dsi->dsi_pclk);
1939 if (dsi->ops.id == DSI_RK3368 ||
1940 dsi->ops.id == DSI_RK3366) {
1941 /* Get the APB bus clk access mipi host */
1942 dsi->dsi_host_pclk = devm_clk_get(&pdev->dev, "pclk_mipi_dsi_host");
1943 if (unlikely(IS_ERR(dsi->dsi_host_pclk))) {
1944 dev_err(&pdev->dev, "get pclk_mipi_dsi_host clock fail\n");
1945 return PTR_ERR(dsi->dsi_host_pclk);
1949 if (dsi->ops.id == DSI_RK312x) {
1950 /* Get the APB bus clk access mipi host */
1951 dsi->dsi_host_pclk = devm_clk_get(&pdev->dev, "pclk_mipi_dsi_host");
1952 if (unlikely(IS_ERR(dsi->dsi_host_pclk))) {
1953 dev_err(&pdev->dev, "get pclk_mipi_dsi_host clock fail\n");
1954 return PTR_ERR(dsi->dsi_host_pclk);
1956 /* Get the pd_vio AHB h2p bridge clock */
1957 dsi->h2p_hclk = devm_clk_get(&pdev->dev, "hclk_vio_h2p");
1958 if (unlikely(IS_ERR(dsi->h2p_hclk))) {
1959 dev_err(&pdev->dev, "get hclk_vio_h2p clock fail\n");
1960 return PTR_ERR(dsi->h2p_hclk);
1964 if (dsi->ops.id == DSI_RK3399) {
1965 /* Get mipi phy cfg clk */
1966 dsi->dsi_host_pclk = devm_clk_get(&pdev->dev, "mipi_dphy_cfg");
1967 if (unlikely(IS_ERR(dsi->dsi_host_pclk))) {
1968 dev_err(&pdev->dev, "get mipi_dphy_cfg clock fail\n");
1969 return PTR_ERR(dsi->dsi_host_pclk);
1972 dsi->grf_base = syscon_regmap_lookup_by_phandle(np, "rockchip,grf");
1973 if (IS_ERR(dsi->grf_base)) {
1974 dev_err(&pdev->dev, "can't find mipi grf property\n");
1975 dsi->grf_base = NULL;
1979 dsi->host.irq = platform_get_irq(pdev, 0);
1980 if (dsi->host.irq < 0) {
1981 dev_err(&pdev->dev, "no irq resource?\n");
1982 return dsi->host.irq;
1985 ret = request_irq(dsi->host.irq, rk32_mipi_dsi_irq_handler, 0,dev_name(&pdev->dev), dsi);
1987 dev_err(&pdev->dev, "request mipi_dsi irq fail\n");
1991 printk("dsi->host.irq =%d\n", dsi->host.irq);
1993 disable_irq(dsi->host.irq);
1995 screen = devm_kzalloc(&pdev->dev, sizeof(struct rk_screen), GFP_KERNEL);
1997 dev_err(&pdev->dev, "request struct rk_screen fail!\n");
2000 rk_fb_get_prmry_screen(screen);
2006 ops->get_id = rk32_mipi_dsi_get_id,
2007 ops->dsi_send_packet = rk32_mipi_dsi_send_packet;
2008 ops->dsi_read_dcs_packet = rk32_mipi_dsi_read_dcs_packet,
2009 ops->dsi_enable_video_mode = rk32_mipi_dsi_enable_video_mode,
2010 ops->dsi_enable_command_mode = rk32_mipi_dsi_enable_command_mode,
2011 ops->dsi_enable_hs_clk = rk32_mipi_dsi_enable_hs_clk,
2012 ops->dsi_is_active = rk32_mipi_dsi_is_active,
2013 ops->dsi_is_enable = rk32_mipi_dsi_is_enable,
2014 ops->power_up = rk32_mipi_dsi_power_up,
2015 ops->power_down = rk32_mipi_dsi_power_down,
2016 ops->dsi_init = rk_mipi_dsi_init,
2018 dsi_screen = &dsi->screen;
2019 dsi_screen->screen = screen;
2020 dsi_screen->type = screen->type;
2021 dsi_screen->face = screen->face;
2022 dsi_screen->lcdc_id = screen->lcdc_id;
2023 dsi_screen->screen_id = screen->screen_id;
2024 dsi_screen->pixclock = screen->mode.pixclock;
2025 dsi_screen->left_margin = screen->mode.left_margin;
2026 dsi_screen->right_margin = screen->mode.right_margin;
2027 dsi_screen->hsync_len = screen->mode.hsync_len;
2028 dsi_screen->upper_margin = screen->mode.upper_margin;
2029 dsi_screen->lower_margin = screen->mode.lower_margin;
2030 dsi_screen->vsync_len = screen->mode.vsync_len;
2031 dsi_screen->x_res = screen->mode.xres;
2032 dsi_screen->y_res = screen->mode.yres;
2033 dsi_screen->pin_hsync = screen->pin_hsync;
2034 dsi_screen->pin_vsync = screen->pin_vsync;
2035 dsi_screen->pin_den = screen->pin_den;
2036 dsi_screen->pin_dclk = screen->pin_dclk;
2037 dsi_screen->dsi_lane = rk_mipi_get_dsi_lane();
2038 dsi_screen->dsi_lane = rk_mipi_get_dsi_lane();
2039 dsi_screen->hs_tx_clk = rk_mipi_get_dsi_clk();
2040 /* dsi_screen->lcdc_id = 1; */
2041 dsi_screen->refresh_mode = screen->refresh_mode;
2045 sprintf(ops->name, "rk_mipi_dsi.%d", dsi->dsi_id);
2046 platform_set_drvdata(pdev, dsi);
2047 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 0))
2048 /* enable power domain */
2049 pm_runtime_enable(&pdev->dev);
2052 register_dsi_ops(dsi->dsi_id, &dsi->ops);
2056 if(!support_uboot_display())
2057 rk32_init_phy_mode(dsi_screen->lcdc_id);
2059 rk_fb_trsm_ops_register(&trsm_dsi_ops, SCREEN_MIPI);
2060 #ifdef MIPI_DSI_REGISTER_IO
2061 debugfs_create_file("mipidsi0", S_IFREG | S_IRUGO, dsi->debugfs_dir, dsi,
2067 #ifdef MIPI_DSI_REGISTER_IO
2068 debugfs_create_file("mipidsi1", S_IFREG | S_IRUGO, dsi->debugfs_dir, dsi,
2073 if (support_uboot_display()) {
2074 clk_prepare_enable(dsi->phy.refclk);
2075 clk_prepare_enable(dsi->dsi_pclk);
2076 if (dsi->ops.id == DSI_RK312x) {
2077 clk_prepare_enable(dsi->dsi_host_pclk);
2078 clk_prepare_enable(dsi->h2p_hclk);
2079 } else if (dsi->ops.id == DSI_RK3368 ||
2080 dsi->ops.id == DSI_RK3366)
2081 clk_prepare_enable(dsi->dsi_host_pclk);
2082 else if (dsi->ops.id == DSI_RK3399)
2083 clk_prepare_enable(dsi->dsi_host_pclk);
2089 dev_info(&pdev->dev, "rk mipi_dsi probe success!\n");
2090 dev_info(&pdev->dev, "%s\n", RK_MIPI_DSI_VERSION_AND_TIME);
2095 static int rockchip_mipi_remove(struct platform_device *pdev)
2097 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(4, 4, 0))
2098 pm_runtime_disable(&pdev->dev);
2103 static struct platform_driver rk32_mipi_dsi_driver = {
2104 .probe = rk32_mipi_dsi_probe,
2105 .remove = rockchip_mipi_remove,
2107 .name = "rk32-mipi",
2108 .owner = THIS_MODULE,
2110 .of_match_table = of_rk_mipi_dsi_match,
2115 static int __init rk32_mipi_dsi_init(void)
2117 return platform_driver_register(&rk32_mipi_dsi_driver);
2119 fs_initcall(rk32_mipi_dsi_init);
2121 static void __exit rk32_mipi_dsi_exit(void)
2123 platform_driver_unregister(&rk32_mipi_dsi_driver);
2125 module_exit(rk32_mipi_dsi_exit);