blob: 3d39f31a5ade309cd32e8f0675341cc280922186 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Philipp Tomsich66cbacc2017-05-31 17:59:33 +02002/*
3 * Copyright (c) 2017 Theobroma Systems Design und Consulting GmbH
Philipp Tomsich66cbacc2017-05-31 17:59:33 +02004 */
5
Philipp Tomsich66cbacc2017-05-31 17:59:33 +02006#include <clk.h>
7#include <display.h>
8#include <dm.h>
9#include <dw_hdmi.h>
10#include <edid.h>
Simon Glass0f2af882020-05-10 11:40:05 -060011#include <log.h>
Simon Glass9bc15642020-02-03 07:36:16 -070012#include <malloc.h>
Philipp Tomsich66cbacc2017-05-31 17:59:33 +020013#include <regmap.h>
14#include <syscon.h>
15#include <asm/gpio.h>
Kever Yang9fbe17c2019-03-28 11:01:23 +080016#include <asm/arch-rockchip/clock.h>
17#include <asm/arch-rockchip/hardware.h>
18#include <asm/arch-rockchip/grf_rk3288.h>
Philipp Tomsich66cbacc2017-05-31 17:59:33 +020019#include <power/regulator.h>
20#include "rk_hdmi.h"
21
22static int rk3288_hdmi_enable(struct udevice *dev, int panel_bpp,
23 const struct display_timing *edid)
24{
25 struct rk_hdmi_priv *priv = dev_get_priv(dev);
Simon Glass71fa5b42020-12-03 16:55:18 -070026 struct display_plat *uc_plat = dev_get_uclass_plat(dev);
Philipp Tomsich66cbacc2017-05-31 17:59:33 +020027 int vop_id = uc_plat->source_id;
28 struct rk3288_grf *grf = priv->grf;
29
30 /* hdmi source select hdmi controller */
31 rk_setreg(&grf->soc_con6, 1 << 15);
32
33 /* hdmi data from vop id */
34 rk_clrsetreg(&grf->soc_con6, 1 << 4, (vop_id == 1) ? (1 << 4) : 0);
35
Niklas Schulze65fdabe2019-07-14 10:40:13 +000036 return dw_hdmi_enable(&priv->hdmi, edid);
Philipp Tomsich66cbacc2017-05-31 17:59:33 +020037}
38
Simon Glassaad29ae2020-12-03 16:55:21 -070039static int rk3288_hdmi_of_to_plat(struct udevice *dev)
Philipp Tomsich66cbacc2017-05-31 17:59:33 +020040{
41 struct rk_hdmi_priv *priv = dev_get_priv(dev);
42 struct dw_hdmi *hdmi = &priv->hdmi;
43
44 hdmi->i2c_clk_high = 0x7a;
45 hdmi->i2c_clk_low = 0x8d;
46
47 /*
48 * TODO(sjg@chromium.org): The above values don't work - these
49 * ones work better, but generate lots of errors in the data.
50 */
51 hdmi->i2c_clk_high = 0x0d;
52 hdmi->i2c_clk_low = 0x0d;
53
Simon Glassaad29ae2020-12-03 16:55:21 -070054 return rk_hdmi_of_to_plat(dev);
Philipp Tomsich66cbacc2017-05-31 17:59:33 +020055}
56
57static int rk3288_clk_config(struct udevice *dev)
58{
Simon Glass71fa5b42020-12-03 16:55:18 -070059 struct display_plat *uc_plat = dev_get_uclass_plat(dev);
Philipp Tomsich66cbacc2017-05-31 17:59:33 +020060 struct clk clk;
61 int ret;
62
63 /*
64 * Configure the maximum clock to permit whatever resolution the
65 * monitor wants
66 */
67 ret = clk_get_by_index(uc_plat->src_dev, 0, &clk);
Sean Andersond318eb32023-12-16 14:38:42 -050068 if (ret >= 0)
Philipp Tomsich66cbacc2017-05-31 17:59:33 +020069 ret = clk_set_rate(&clk, 384000000);
Philipp Tomsich66cbacc2017-05-31 17:59:33 +020070 if (ret < 0) {
71 debug("%s: Failed to set clock in source device '%s': ret=%d\n",
72 __func__, uc_plat->src_dev->name, ret);
73 return ret;
74 }
75
76 return 0;
77}
78
79static const char * const rk3288_regulator_names[] = {
80 "vcc50_hdmi"
81};
82
83static int rk3288_hdmi_probe(struct udevice *dev)
84{
85 /* Enable VOP clock for RK3288 */
86 rk3288_clk_config(dev);
87
88 /* Enable regulators required for HDMI */
89 rk_hdmi_probe_regulators(dev, rk3288_regulator_names,
90 ARRAY_SIZE(rk3288_regulator_names));
91
92 return rk_hdmi_probe(dev);
93}
94
95static const struct dm_display_ops rk3288_hdmi_ops = {
96 .read_edid = rk_hdmi_read_edid,
97 .enable = rk3288_hdmi_enable,
98};
99
100static const struct udevice_id rk3288_hdmi_ids[] = {
101 { .compatible = "rockchip,rk3288-dw-hdmi" },
102 { }
103};
104
105U_BOOT_DRIVER(rk3288_hdmi_rockchip) = {
106 .name = "rk3288_hdmi_rockchip",
107 .id = UCLASS_DISPLAY,
108 .of_match = rk3288_hdmi_ids,
109 .ops = &rk3288_hdmi_ops,
Simon Glassaad29ae2020-12-03 16:55:21 -0700110 .of_to_plat = rk3288_hdmi_of_to_plat,
Philipp Tomsich66cbacc2017-05-31 17:59:33 +0200111 .probe = rk3288_hdmi_probe,
Simon Glass8a2b47f2020-12-03 16:55:17 -0700112 .priv_auto = sizeof(struct rk_hdmi_priv),
Philipp Tomsich66cbacc2017-05-31 17:59:33 +0200113};