2020-10-22 19:43:13 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0
|
2017-06-21 03:22:01 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2017, Fuzhou Rockchip Electronics Co., Ltd
|
|
|
|
* Author: Eric Gao <eric.gao@rock-chips.com>
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <clk.h>
|
|
|
|
#include <display.h>
|
|
|
|
#include <dm.h>
|
2020-05-10 17:40:05 +00:00
|
|
|
#include <log.h>
|
2017-06-21 03:22:01 +00:00
|
|
|
#include <panel.h>
|
|
|
|
#include <regmap.h>
|
|
|
|
#include "rk_mipi.h"
|
|
|
|
#include <syscon.h>
|
|
|
|
#include <asm/gpio.h>
|
|
|
|
#include <asm/io.h>
|
|
|
|
#include <dm/uclass-internal.h>
|
2020-02-03 14:36:15 +00:00
|
|
|
#include <linux/err.h>
|
2017-06-21 03:22:01 +00:00
|
|
|
#include <linux/kernel.h>
|
2019-03-28 03:01:23 +00:00
|
|
|
#include <asm/arch-rockchip/clock.h>
|
2020-01-09 08:52:17 +00:00
|
|
|
#include <asm/arch-rockchip/cru.h>
|
2019-03-28 03:01:23 +00:00
|
|
|
#include <asm/arch-rockchip/grf_rk3288.h>
|
|
|
|
#include <asm/arch-rockchip/hardware.h>
|
|
|
|
#include <asm/arch-rockchip/rockchip_mipi_dsi.h>
|
2017-06-21 03:22:01 +00:00
|
|
|
|
|
|
|
#define MHz 1000000
|
|
|
|
|
|
|
|
/* Select mipi dsi source, big or little vop */
|
|
|
|
static int rk_mipi_dsi_source_select(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct rk_mipi_priv *priv = dev_get_priv(dev);
|
|
|
|
struct rk3288_grf *grf = priv->grf;
|
2020-12-03 23:55:18 +00:00
|
|
|
struct display_plat *disp_uc_plat = dev_get_uclass_plat(dev);
|
2017-06-21 03:22:01 +00:00
|
|
|
|
|
|
|
/* Select the video source */
|
|
|
|
switch (disp_uc_plat->source_id) {
|
|
|
|
case VOP_B:
|
|
|
|
rk_clrsetreg(&grf->soc_con6, RK3288_DSI0_LCDC_SEL_MASK,
|
|
|
|
RK3288_DSI0_LCDC_SEL_BIG
|
|
|
|
<< RK3288_DSI0_LCDC_SEL_SHIFT);
|
|
|
|
break;
|
|
|
|
case VOP_L:
|
|
|
|
rk_clrsetreg(&grf->soc_con6, RK3288_DSI0_LCDC_SEL_MASK,
|
|
|
|
RK3288_DSI0_LCDC_SEL_LIT
|
|
|
|
<< RK3288_DSI0_LCDC_SEL_SHIFT);
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
debug("%s: Invalid VOP id\n", __func__);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Setup mipi dphy working mode */
|
|
|
|
static void rk_mipi_dphy_mode_set(struct udevice *dev)
|
|
|
|
{
|
|
|
|
struct rk_mipi_priv *priv = dev_get_priv(dev);
|
|
|
|
struct rk3288_grf *grf = priv->grf;
|
|
|
|
int val;
|
|
|
|
|
|
|
|
/* Set Controller as TX mode */
|
|
|
|
val = RK3288_DPHY_TX0_RXMODE_DIS << RK3288_DPHY_TX0_RXMODE_SHIFT;
|
|
|
|
rk_clrsetreg(&grf->soc_con8, RK3288_DPHY_TX0_RXMODE_MASK, val);
|
|
|
|
|
|
|
|
/* Exit tx stop mode */
|
|
|
|
val |= RK3288_DPHY_TX0_TXSTOPMODE_EN
|
|
|
|
<< RK3288_DPHY_TX0_TXSTOPMODE_SHIFT;
|
|
|
|
rk_clrsetreg(&grf->soc_con8,
|
|
|
|
RK3288_DPHY_TX0_TXSTOPMODE_MASK, val);
|
|
|
|
|
|
|
|
/* Disable turnequest */
|
|
|
|
val |= RK3288_DPHY_TX0_TURNREQUEST_EN
|
|
|
|
<< RK3288_DPHY_TX0_TURNREQUEST_SHIFT;
|
|
|
|
rk_clrsetreg(&grf->soc_con8,
|
|
|
|
RK3288_DPHY_TX0_TURNREQUEST_MASK, val);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This function is called by rk_display_init() using rk_mipi_dsi_enable() and
|
|
|
|
* rk_mipi_phy_enable() to initialize mipi controller and dphy. If success,
|
|
|
|
* enable backlight.
|
|
|
|
*/
|
|
|
|
static int rk_mipi_enable(struct udevice *dev, int panel_bpp,
|
|
|
|
const struct display_timing *timing)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
struct rk_mipi_priv *priv = dev_get_priv(dev);
|
|
|
|
|
|
|
|
/* Fill the mipi controller parameter */
|
|
|
|
priv->ref_clk = 24 * MHz;
|
|
|
|
priv->sys_clk = priv->ref_clk;
|
|
|
|
priv->pix_clk = timing->pixelclock.typ;
|
|
|
|
priv->phy_clk = priv->pix_clk * 6;
|
|
|
|
priv->txbyte_clk = priv->phy_clk / 8;
|
|
|
|
priv->txesc_clk = 20 * MHz;
|
|
|
|
|
|
|
|
/* Select vop port, big or little */
|
|
|
|
rk_mipi_dsi_source_select(dev);
|
|
|
|
|
|
|
|
/* Set mipi dphy work mode */
|
|
|
|
rk_mipi_dphy_mode_set(dev);
|
|
|
|
|
|
|
|
/* Config and enable mipi dsi according to timing */
|
|
|
|
ret = rk_mipi_dsi_enable(dev, timing);
|
|
|
|
if (ret) {
|
|
|
|
debug("%s: rk_mipi_dsi_enable() failed (err=%d)\n",
|
|
|
|
__func__, ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Config and enable mipi phy */
|
|
|
|
ret = rk_mipi_phy_enable(dev);
|
|
|
|
if (ret) {
|
|
|
|
debug("%s: rk_mipi_phy_enable() failed (err=%d)\n",
|
|
|
|
__func__, ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Enable backlight */
|
|
|
|
ret = panel_enable_backlight(priv->panel);
|
|
|
|
if (ret) {
|
|
|
|
debug("%s: panel_enable_backlight() failed (err=%d)\n",
|
|
|
|
__func__, ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-12-03 23:55:21 +00:00
|
|
|
static int rk_mipi_of_to_plat(struct udevice *dev)
|
2017-06-21 03:22:01 +00:00
|
|
|
{
|
|
|
|
struct rk_mipi_priv *priv = dev_get_priv(dev);
|
|
|
|
|
|
|
|
priv->grf = syscon_get_first_range(ROCKCHIP_SYSCON_GRF);
|
2018-03-19 17:36:07 +00:00
|
|
|
if (IS_ERR_OR_NULL(priv->grf)) {
|
2017-06-21 03:22:01 +00:00
|
|
|
debug("%s: Get syscon grf failed (ret=%p)\n",
|
|
|
|
__func__, priv->grf);
|
|
|
|
return -ENXIO;
|
|
|
|
}
|
|
|
|
priv->regs = dev_read_addr(dev);
|
|
|
|
if (priv->regs == FDT_ADDR_T_NONE) {
|
|
|
|
debug("%s: Get MIPI dsi address failed (ret=%lu)\n", __func__,
|
|
|
|
priv->regs);
|
|
|
|
return -ENXIO;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Probe function: check panel existence and readingit's timing. Then config
|
|
|
|
* mipi dsi controller and enable it according to the timing parameter.
|
|
|
|
*/
|
|
|
|
static int rk_mipi_probe(struct udevice *dev)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
struct rk_mipi_priv *priv = dev_get_priv(dev);
|
|
|
|
|
|
|
|
ret = uclass_get_device_by_phandle(UCLASS_PANEL, dev, "rockchip,panel",
|
|
|
|
&priv->panel);
|
|
|
|
if (ret) {
|
|
|
|
debug("%s: Can not find panel (err=%d)\n", __func__, ret);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct dm_display_ops rk_mipi_dsi_ops = {
|
|
|
|
.read_timing = rk_mipi_read_timing,
|
|
|
|
.enable = rk_mipi_enable,
|
|
|
|
};
|
|
|
|
|
|
|
|
static const struct udevice_id rk_mipi_dsi_ids[] = {
|
2022-04-16 08:25:16 +00:00
|
|
|
{ .compatible = "rockchip,rk3288-mipi-dsi" },
|
2017-06-21 03:22:01 +00:00
|
|
|
{ .compatible = "rockchip,rk3288_mipi_dsi" },
|
|
|
|
{ }
|
|
|
|
};
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(rk_mipi_dsi) = {
|
|
|
|
.name = "rk_mipi_dsi",
|
|
|
|
.id = UCLASS_DISPLAY,
|
|
|
|
.of_match = rk_mipi_dsi_ids,
|
2020-12-03 23:55:21 +00:00
|
|
|
.of_to_plat = rk_mipi_of_to_plat,
|
2017-06-21 03:22:01 +00:00
|
|
|
.probe = rk_mipi_probe,
|
|
|
|
.ops = &rk_mipi_dsi_ops,
|
2020-12-03 23:55:17 +00:00
|
|
|
.priv_auto = sizeof(struct rk_mipi_priv),
|
2017-06-21 03:22:01 +00:00
|
|
|
};
|