blob: 0ac0a3a1ecd0d0d7b780e4af5b13f8ec1a593379 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glass0139ae62016-01-21 19:45:03 -07002/*
Philipp Tomsich66cbacc2017-05-31 17:59:33 +02003 * Copyright (c) 2017 Theobroma Systems Design und Consulting GmbH
Simon Glass0139ae62016-01-21 19:45:03 -07004 * Copyright (c) 2015 Google, Inc
5 * Copyright 2014 Rockchip Inc.
Simon Glass0139ae62016-01-21 19:45:03 -07006 */
7
Simon Glass0139ae62016-01-21 19:45:03 -07008#include <clk.h>
9#include <display.h>
10#include <dm.h>
Jernej Skrabec2ae12ee2017-03-20 23:01:22 +010011#include <dw_hdmi.h>
Simon Glass0139ae62016-01-21 19:45:03 -070012#include <edid.h>
Simon Glass0f2af882020-05-10 11:40:05 -060013#include <log.h>
Simon Glass0139ae62016-01-21 19:45:03 -070014#include <regmap.h>
15#include <syscon.h>
16#include <asm/gpio.h>
Kever Yang9fbe17c2019-03-28 11:01:23 +080017#include <asm/arch-rockchip/clock.h>
18#include <asm/arch-rockchip/hardware.h>
Philipp Tomsich66cbacc2017-05-31 17:59:33 +020019#include "rk_hdmi.h"
20#include "rk_vop.h" /* for rk_vop_probe_regulators */
Simon Glass0139ae62016-01-21 19:45:03 -070021
Simon Glass0139ae62016-01-21 19:45:03 -070022static const struct hdmi_phy_config rockchip_phy_config[] = {
23 {
Nickey Yang Nickey Yang5a808a92016-12-29 14:01:26 +080024 .mpixelclock = 74250000,
Simon Glass0139ae62016-01-21 19:45:03 -070025 .sym_ctr = 0x8009, .term = 0x0004, .vlev_ctr = 0x0272,
26 }, {
Nickey Yang Nickey Yang5a808a92016-12-29 14:01:26 +080027 .mpixelclock = 148500000,
Simon Glass0139ae62016-01-21 19:45:03 -070028 .sym_ctr = 0x802b, .term = 0x0004, .vlev_ctr = 0x028d,
29 }, {
Nickey Yang Nickey Yang5a808a92016-12-29 14:01:26 +080030 .mpixelclock = 297000000,
Simon Glass0139ae62016-01-21 19:45:03 -070031 .sym_ctr = 0x8039, .term = 0x0005, .vlev_ctr = 0x028d,
32 }, {
Philipp Tomsicha35ccec2017-05-31 17:59:32 +020033 .mpixelclock = 584000000,
34 .sym_ctr = 0x8039, .term = 0x0000, .vlev_ctr = 0x019d,
35 }, {
Simon Glass0139ae62016-01-21 19:45:03 -070036 .mpixelclock = ~0ul,
37 .sym_ctr = 0x0000, .term = 0x0000, .vlev_ctr = 0x0000,
38 }
39};
40
41static const struct hdmi_mpll_config rockchip_mpll_cfg[] = {
42 {
Nickey Yang Nickey Yang5a808a92016-12-29 14:01:26 +080043 .mpixelclock = 40000000,
Simon Glass0139ae62016-01-21 19:45:03 -070044 .cpce = 0x00b3, .gmp = 0x0000, .curr = 0x0018,
45 }, {
Nickey Yang Nickey Yang5a808a92016-12-29 14:01:26 +080046 .mpixelclock = 65000000,
Simon Glass0139ae62016-01-21 19:45:03 -070047 .cpce = 0x0072, .gmp = 0x0001, .curr = 0x0028,
48 }, {
Nickey Yang Nickey Yang5a808a92016-12-29 14:01:26 +080049 .mpixelclock = 66000000,
Simon Glass0139ae62016-01-21 19:45:03 -070050 .cpce = 0x013e, .gmp = 0x0003, .curr = 0x0038,
51 }, {
Nickey Yang Nickey Yang8b221cf2017-02-27 17:04:21 +080052 .mpixelclock = 83500000,
Simon Glass0139ae62016-01-21 19:45:03 -070053 .cpce = 0x0072, .gmp = 0x0001, .curr = 0x0028,
54 }, {
Nickey Yang Nickey Yang5a808a92016-12-29 14:01:26 +080055 .mpixelclock = 146250000,
Simon Glass0139ae62016-01-21 19:45:03 -070056 .cpce = 0x0051, .gmp = 0x0002, .curr = 0x0038,
57 }, {
Nickey Yang Nickey Yang5a808a92016-12-29 14:01:26 +080058 .mpixelclock = 148500000,
Simon Glass0139ae62016-01-21 19:45:03 -070059 .cpce = 0x0051, .gmp = 0x0003, .curr = 0x0000,
60 }, {
Philipp Tomsicha35ccec2017-05-31 17:59:32 +020061 .mpixelclock = 272000000,
62 .cpce = 0x0040, .gmp = 0x0003, .curr = 0x0000,
63 }, {
64 .mpixelclock = 340000000,
65 .cpce = 0x0040, .gmp = 0x0003, .curr = 0x0000,
66 }, {
Simon Glass0139ae62016-01-21 19:45:03 -070067 .mpixelclock = ~0ul,
68 .cpce = 0x0051, .gmp = 0x0003, .curr = 0x0000,
69 }
70};
71
Philipp Tomsich66cbacc2017-05-31 17:59:33 +020072int rk_hdmi_read_edid(struct udevice *dev, u8 *buf, int buf_size)
Simon Glass0139ae62016-01-21 19:45:03 -070073{
74 struct rk_hdmi_priv *priv = dev_get_priv(dev);
Simon Glass0139ae62016-01-21 19:45:03 -070075
Jernej Skrabec2ae12ee2017-03-20 23:01:22 +010076 return dw_hdmi_read_edid(&priv->hdmi, buf, buf_size);
Simon Glass0139ae62016-01-21 19:45:03 -070077}
78
Simon Glassaad29ae2020-12-03 16:55:21 -070079int rk_hdmi_of_to_plat(struct udevice *dev)
Simon Glass0139ae62016-01-21 19:45:03 -070080{
81 struct rk_hdmi_priv *priv = dev_get_priv(dev);
Jernej Skrabec2ae12ee2017-03-20 23:01:22 +010082 struct dw_hdmi *hdmi = &priv->hdmi;
83
Philipp Tomsich18c64962018-02-23 17:38:51 +010084 hdmi->ioaddr = (ulong)dev_read_addr(dev);
Jernej Skrabec2ae12ee2017-03-20 23:01:22 +010085 hdmi->mpll_cfg = rockchip_mpll_cfg;
86 hdmi->phy_cfg = rockchip_phy_config;
Jernej Skrabec2ae12ee2017-03-20 23:01:22 +010087
Philipp Tomsich66cbacc2017-05-31 17:59:33 +020088 /* hdmi->i2c_clk_{high,low} are set up by the SoC driver */
89
Jernej Skrabec2ae12ee2017-03-20 23:01:22 +010090 hdmi->reg_io_width = 4;
Simon Glass0139ae62016-01-21 19:45:03 -070091
Simon Glass0139ae62016-01-21 19:45:03 -070092 priv->grf = syscon_get_first_range(ROCKCHIP_SYSCON_GRF);
93
Niklas Schulze889ccde2019-07-27 12:07:13 +000094 uclass_get_device_by_phandle(UCLASS_I2C, dev, "ddc-i2c-bus",
95 &hdmi->ddc_bus);
96
Simon Glass0139ae62016-01-21 19:45:03 -070097 return 0;
98}
99
Philipp Tomsich66cbacc2017-05-31 17:59:33 +0200100void rk_hdmi_probe_regulators(struct udevice *dev,
101 const char * const *names, int cnt)
102{
103 rk_vop_probe_regulators(dev, names, cnt);
104}
105
106int rk_hdmi_probe(struct udevice *dev)
Simon Glass0139ae62016-01-21 19:45:03 -0700107{
Simon Glass0139ae62016-01-21 19:45:03 -0700108 struct rk_hdmi_priv *priv = dev_get_priv(dev);
Jernej Skrabec2ae12ee2017-03-20 23:01:22 +0100109 struct dw_hdmi *hdmi = &priv->hdmi;
Simon Glass0139ae62016-01-21 19:45:03 -0700110 int ret;
Simon Glass0139ae62016-01-21 19:45:03 -0700111
Jagan Teki5a4d64e2024-01-17 13:21:38 +0530112 dw_hdmi_init(hdmi);
113 dw_hdmi_phy_init(hdmi);
114
Jagan Teki17d0f552024-01-17 13:21:40 +0530115 ret = dw_hdmi_detect_hpd(hdmi);
116 if (ret < 0)
117 return ret;
Simon Glass0139ae62016-01-21 19:45:03 -0700118
Simon Glass0139ae62016-01-21 19:45:03 -0700119 return 0;
120}