2 * Copyright (c) 2017, Fuzhou Rockchip Electronics Co., Ltd
3 * Author: Eric Gao <eric.gao@rock-chips.com>
5 * SPDX-License-Identifier: GPL-2.0+
18 #include <asm/hardware.h>
20 #include <dm/uclass-internal.h>
21 #include <linux/kernel.h>
22 #include <asm/arch/clock.h>
23 #include <asm/arch/cru_rk3399.h>
24 #include <asm/arch/grf_rk3399.h>
25 #include <asm/arch/rockchip_mipi_dsi.h>
27 DECLARE_GLOBAL_DATA_PTR;
29 /* Select mipi dsi source, big or little vop */
30 static int rk_mipi_dsi_source_select(struct udevice *dev)
32 struct rk_mipi_priv *priv = dev_get_priv(dev);
33 struct rk3399_grf_regs *grf = priv->grf;
34 struct display_plat *disp_uc_plat = dev_get_uclass_platdata(dev);
36 /* Select the video source */
37 switch (disp_uc_plat->source_id) {
39 rk_clrsetreg(&grf->soc_con20, GRF_DSI0_VOP_SEL_MASK,
40 GRF_DSI0_VOP_SEL_B << GRF_DSI0_VOP_SEL_SHIFT);
43 rk_clrsetreg(&grf->soc_con20, GRF_DSI0_VOP_SEL_MASK,
44 GRF_DSI0_VOP_SEL_L << GRF_DSI0_VOP_SEL_SHIFT);
47 debug("%s: Invalid VOP id\n", __func__);
54 /* Setup mipi dphy working mode */
55 static void rk_mipi_dphy_mode_set(struct udevice *dev)
57 struct rk_mipi_priv *priv = dev_get_priv(dev);
58 struct rk3399_grf_regs *grf = priv->grf;
61 /* Set Controller as TX mode */
62 val = GRF_DPHY_TX0_RXMODE_DIS << GRF_DPHY_TX0_RXMODE_SHIFT;
63 rk_clrsetreg(&grf->soc_con22, GRF_DPHY_TX0_RXMODE_MASK, val);
65 /* Exit tx stop mode */
66 val |= GRF_DPHY_TX0_TXSTOPMODE_DIS << GRF_DPHY_TX0_TXSTOPMODE_SHIFT;
67 rk_clrsetreg(&grf->soc_con22, GRF_DPHY_TX0_TXSTOPMODE_MASK, val);
69 /* Disable turnequest */
70 val |= GRF_DPHY_TX0_TURNREQUEST_DIS << GRF_DPHY_TX0_TURNREQUEST_SHIFT;
71 rk_clrsetreg(&grf->soc_con22, GRF_DPHY_TX0_TURNREQUEST_MASK, val);
75 * This function is called by rk_display_init() using rk_mipi_dsi_enable() and
76 * rk_mipi_phy_enable() to initialize mipi controller and dphy. If success,
79 static int rk_display_enable(struct udevice *dev, int panel_bpp,
80 const struct display_timing *timing)
83 struct rk_mipi_priv *priv = dev_get_priv(dev);
85 /* Fill the mipi controller parameter */
86 priv->ref_clk = 24 * MHz;
87 priv->sys_clk = priv->ref_clk;
88 priv->pix_clk = timing->pixelclock.typ;
89 priv->phy_clk = priv->pix_clk * 6;
90 priv->txbyte_clk = priv->phy_clk / 8;
91 priv->txesc_clk = 20 * MHz;
93 /* Select vop port, big or little */
94 rk_mipi_dsi_source_select(dev);
96 /* Set mipi dphy work mode */
97 rk_mipi_dphy_mode_set(dev);
99 /* Config and enable mipi dsi according to timing */
100 ret = rk_mipi_dsi_enable(dev, timing);
102 debug("%s: rk_mipi_dsi_enable() failed (err=%d)\n",
107 /* Config and enable mipi phy */
108 ret = rk_mipi_phy_enable(dev);
110 debug("%s: rk_mipi_phy_enable() failed (err=%d)\n",
115 /* Enable backlight */
116 ret = panel_enable_backlight(priv->panel);
118 debug("%s: panel_enable_backlight() failed (err=%d)\n",
126 static int rk_mipi_ofdata_to_platdata(struct udevice *dev)
128 struct rk_mipi_priv *priv = dev_get_priv(dev);
130 priv->grf = syscon_get_first_range(ROCKCHIP_SYSCON_GRF);
131 if (IS_ERR_OR_NULL(priv->grf)) {
132 debug("%s: Get syscon grf failed (ret=%p)\n",
133 __func__, priv->grf);
136 priv->regs = dev_read_addr(dev);
137 if (priv->regs == FDT_ADDR_T_NONE) {
138 debug("%s: Get MIPI dsi address failed\n", __func__);
146 * Probe function: check panel existence and readingit's timing. Then config
147 * mipi dsi controller and enable it according to the timing parameter.
149 static int rk_mipi_probe(struct udevice *dev)
152 struct rk_mipi_priv *priv = dev_get_priv(dev);
154 ret = uclass_get_device_by_phandle(UCLASS_PANEL, dev, "rockchip,panel",
157 debug("%s: Can not find panel (err=%d)\n", __func__, ret);
164 static const struct dm_display_ops rk_mipi_dsi_ops = {
165 .read_timing = rk_mipi_read_timing,
166 .enable = rk_display_enable,
169 static const struct udevice_id rk_mipi_dsi_ids[] = {
170 { .compatible = "rockchip,rk3399_mipi_dsi" },
174 U_BOOT_DRIVER(rk_mipi_dsi) = {
175 .name = "rk_mipi_dsi",
176 .id = UCLASS_DISPLAY,
177 .of_match = rk_mipi_dsi_ids,
178 .ofdata_to_platdata = rk_mipi_ofdata_to_platdata,
179 .probe = rk_mipi_probe,
180 .ops = &rk_mipi_dsi_ops,
181 .priv_auto_alloc_size = sizeof(struct rk_mipi_priv),