blob: 9d42119c82611ac83d44553d8ffc0311bfa611a6 [file] [log] [blame]
Alper Nebi Yasak53f20332020-10-22 22:43:13 +03001// SPDX-License-Identifier: GPL-2.0
eric.gao@rock-chips.com9b3a6132017-06-21 11:22:01 +08002/*
3 * Copyright (c) 2017, Fuzhou Rockchip Electronics Co., Ltd
4 * Author: Eric Gao <eric.gao@rock-chips.com>
eric.gao@rock-chips.com9b3a6132017-06-21 11:22:01 +08005 */
6
7#include <common.h>
8#include <clk.h>
9#include <display.h>
10#include <dm.h>
Simon Glass0f2af882020-05-10 11:40:05 -060011#include <log.h>
eric.gao@rock-chips.com9b3a6132017-06-21 11:22:01 +080012#include <panel.h>
13#include <regmap.h>
14#include "rk_mipi.h"
15#include <syscon.h>
16#include <asm/gpio.h>
eric.gao@rock-chips.com9b3a6132017-06-21 11:22:01 +080017#include <dm/uclass-internal.h>
Simon Glassd66c5f72020-02-03 07:36:15 -070018#include <linux/err.h>
eric.gao@rock-chips.com9b3a6132017-06-21 11:22:01 +080019#include <linux/kernel.h>
Kever Yang9fbe17c2019-03-28 11:01:23 +080020#include <asm/arch-rockchip/clock.h>
Jagan Teki783acfd2020-01-09 14:22:17 +053021#include <asm/arch-rockchip/cru.h>
Kever Yang9fbe17c2019-03-28 11:01:23 +080022#include <asm/arch-rockchip/grf_rk3288.h>
23#include <asm/arch-rockchip/hardware.h>
24#include <asm/arch-rockchip/rockchip_mipi_dsi.h>
eric.gao@rock-chips.com9b3a6132017-06-21 11:22:01 +080025
eric.gao@rock-chips.com9b3a6132017-06-21 11:22:01 +080026#define MHz 1000000
27
28/* Select mipi dsi source, big or little vop */
29static int rk_mipi_dsi_source_select(struct udevice *dev)
30{
31 struct rk_mipi_priv *priv = dev_get_priv(dev);
32 struct rk3288_grf *grf = priv->grf;
Simon Glass71fa5b42020-12-03 16:55:18 -070033 struct display_plat *disp_uc_plat = dev_get_uclass_plat(dev);
eric.gao@rock-chips.com9b3a6132017-06-21 11:22:01 +080034
35 /* Select the video source */
36 switch (disp_uc_plat->source_id) {
37 case VOP_B:
38 rk_clrsetreg(&grf->soc_con6, RK3288_DSI0_LCDC_SEL_MASK,
39 RK3288_DSI0_LCDC_SEL_BIG
40 << RK3288_DSI0_LCDC_SEL_SHIFT);
41 break;
42 case VOP_L:
43 rk_clrsetreg(&grf->soc_con6, RK3288_DSI0_LCDC_SEL_MASK,
44 RK3288_DSI0_LCDC_SEL_LIT
45 << RK3288_DSI0_LCDC_SEL_SHIFT);
46 break;
47 default:
48 debug("%s: Invalid VOP id\n", __func__);
49 return -EINVAL;
50 }
51
52 return 0;
53}
54
55/* Setup mipi dphy working mode */
56static void rk_mipi_dphy_mode_set(struct udevice *dev)
57{
58 struct rk_mipi_priv *priv = dev_get_priv(dev);
59 struct rk3288_grf *grf = priv->grf;
60 int val;
61
62 /* Set Controller as TX mode */
63 val = RK3288_DPHY_TX0_RXMODE_DIS << RK3288_DPHY_TX0_RXMODE_SHIFT;
64 rk_clrsetreg(&grf->soc_con8, RK3288_DPHY_TX0_RXMODE_MASK, val);
65
66 /* Exit tx stop mode */
67 val |= RK3288_DPHY_TX0_TXSTOPMODE_EN
68 << RK3288_DPHY_TX0_TXSTOPMODE_SHIFT;
69 rk_clrsetreg(&grf->soc_con8,
70 RK3288_DPHY_TX0_TXSTOPMODE_MASK, val);
71
72 /* Disable turnequest */
73 val |= RK3288_DPHY_TX0_TURNREQUEST_EN
74 << RK3288_DPHY_TX0_TURNREQUEST_SHIFT;
75 rk_clrsetreg(&grf->soc_con8,
76 RK3288_DPHY_TX0_TURNREQUEST_MASK, val);
77}
78
79/*
80 * This function is called by rk_display_init() using rk_mipi_dsi_enable() and
81 * rk_mipi_phy_enable() to initialize mipi controller and dphy. If success,
82 * enable backlight.
83 */
84static int rk_mipi_enable(struct udevice *dev, int panel_bpp,
85 const struct display_timing *timing)
86{
87 int ret;
88 struct rk_mipi_priv *priv = dev_get_priv(dev);
89
90 /* Fill the mipi controller parameter */
91 priv->ref_clk = 24 * MHz;
92 priv->sys_clk = priv->ref_clk;
93 priv->pix_clk = timing->pixelclock.typ;
94 priv->phy_clk = priv->pix_clk * 6;
95 priv->txbyte_clk = priv->phy_clk / 8;
96 priv->txesc_clk = 20 * MHz;
97
98 /* Select vop port, big or little */
99 rk_mipi_dsi_source_select(dev);
100
101 /* Set mipi dphy work mode */
102 rk_mipi_dphy_mode_set(dev);
103
104 /* Config and enable mipi dsi according to timing */
105 ret = rk_mipi_dsi_enable(dev, timing);
106 if (ret) {
107 debug("%s: rk_mipi_dsi_enable() failed (err=%d)\n",
108 __func__, ret);
109 return ret;
110 }
111
112 /* Config and enable mipi phy */
113 ret = rk_mipi_phy_enable(dev);
114 if (ret) {
115 debug("%s: rk_mipi_phy_enable() failed (err=%d)\n",
116 __func__, ret);
117 return ret;
118 }
119
120 /* Enable backlight */
121 ret = panel_enable_backlight(priv->panel);
122 if (ret) {
123 debug("%s: panel_enable_backlight() failed (err=%d)\n",
124 __func__, ret);
125 return ret;
126 }
127
128 return 0;
129}
130
Simon Glassaad29ae2020-12-03 16:55:21 -0700131static int rk_mipi_of_to_plat(struct udevice *dev)
eric.gao@rock-chips.com9b3a6132017-06-21 11:22:01 +0800132{
133 struct rk_mipi_priv *priv = dev_get_priv(dev);
134
135 priv->grf = syscon_get_first_range(ROCKCHIP_SYSCON_GRF);
Punit Agrawal86fa4f22018-03-19 17:36:07 +0000136 if (IS_ERR_OR_NULL(priv->grf)) {
eric.gao@rock-chips.com9b3a6132017-06-21 11:22:01 +0800137 debug("%s: Get syscon grf failed (ret=%p)\n",
138 __func__, priv->grf);
139 return -ENXIO;
140 }
141 priv->regs = dev_read_addr(dev);
142 if (priv->regs == FDT_ADDR_T_NONE) {
143 debug("%s: Get MIPI dsi address failed (ret=%lu)\n", __func__,
144 priv->regs);
145 return -ENXIO;
146 }
147
148 return 0;
149}
150
151/*
152 * Probe function: check panel existence and readingit's timing. Then config
153 * mipi dsi controller and enable it according to the timing parameter.
154 */
155static int rk_mipi_probe(struct udevice *dev)
156{
157 int ret;
158 struct rk_mipi_priv *priv = dev_get_priv(dev);
159
160 ret = uclass_get_device_by_phandle(UCLASS_PANEL, dev, "rockchip,panel",
161 &priv->panel);
162 if (ret) {
163 debug("%s: Can not find panel (err=%d)\n", __func__, ret);
164 return ret;
165 }
166
167 return 0;
168}
169
170static const struct dm_display_ops rk_mipi_dsi_ops = {
171 .read_timing = rk_mipi_read_timing,
172 .enable = rk_mipi_enable,
173};
174
175static const struct udevice_id rk_mipi_dsi_ids[] = {
Johan Jonker9e259942022-04-16 10:25:16 +0200176 { .compatible = "rockchip,rk3288-mipi-dsi" },
eric.gao@rock-chips.com9b3a6132017-06-21 11:22:01 +0800177 { .compatible = "rockchip,rk3288_mipi_dsi" },
178 { }
179};
180
181U_BOOT_DRIVER(rk_mipi_dsi) = {
182 .name = "rk_mipi_dsi",
183 .id = UCLASS_DISPLAY,
184 .of_match = rk_mipi_dsi_ids,
Simon Glassaad29ae2020-12-03 16:55:21 -0700185 .of_to_plat = rk_mipi_of_to_plat,
eric.gao@rock-chips.com9b3a6132017-06-21 11:22:01 +0800186 .probe = rk_mipi_probe,
187 .ops = &rk_mipi_dsi_ops,
Simon Glass8a2b47f2020-12-03 16:55:17 -0700188 .priv_auto = sizeof(struct rk_mipi_priv),
eric.gao@rock-chips.com9b3a6132017-06-21 11:22:01 +0800189};