blob: 8dcd4d596456108a00ed3faaa495152339cd7899 [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
8#include <common.h>
9#include <clk.h>
10#include <display.h>
11#include <dm.h>
Jernej Skrabec2ae12ee2017-03-20 23:01:22 +010012#include <dw_hdmi.h>
Simon Glass0139ae62016-01-21 19:45:03 -070013#include <edid.h>
Simon Glass0f2af882020-05-10 11:40:05 -060014#include <log.h>
Simon Glass0139ae62016-01-21 19:45:03 -070015#include <regmap.h>
16#include <syscon.h>
17#include <asm/gpio.h>
18#include <asm/io.h>
Kever Yang9fbe17c2019-03-28 11:01:23 +080019#include <asm/arch-rockchip/clock.h>
20#include <asm/arch-rockchip/hardware.h>
Philipp Tomsich66cbacc2017-05-31 17:59:33 +020021#include "rk_hdmi.h"
22#include "rk_vop.h" /* for rk_vop_probe_regulators */
Simon Glass0139ae62016-01-21 19:45:03 -070023
Simon Glass0139ae62016-01-21 19:45:03 -070024static const struct hdmi_phy_config rockchip_phy_config[] = {
25 {
Nickey Yang Nickey Yang5a808a92016-12-29 14:01:26 +080026 .mpixelclock = 74250000,
Simon Glass0139ae62016-01-21 19:45:03 -070027 .sym_ctr = 0x8009, .term = 0x0004, .vlev_ctr = 0x0272,
28 }, {
Nickey Yang Nickey Yang5a808a92016-12-29 14:01:26 +080029 .mpixelclock = 148500000,
Simon Glass0139ae62016-01-21 19:45:03 -070030 .sym_ctr = 0x802b, .term = 0x0004, .vlev_ctr = 0x028d,
31 }, {
Nickey Yang Nickey Yang5a808a92016-12-29 14:01:26 +080032 .mpixelclock = 297000000,
Simon Glass0139ae62016-01-21 19:45:03 -070033 .sym_ctr = 0x8039, .term = 0x0005, .vlev_ctr = 0x028d,
34 }, {
Philipp Tomsicha35ccec2017-05-31 17:59:32 +020035 .mpixelclock = 584000000,
36 .sym_ctr = 0x8039, .term = 0x0000, .vlev_ctr = 0x019d,
37 }, {
Simon Glass0139ae62016-01-21 19:45:03 -070038 .mpixelclock = ~0ul,
39 .sym_ctr = 0x0000, .term = 0x0000, .vlev_ctr = 0x0000,
40 }
41};
42
43static const struct hdmi_mpll_config rockchip_mpll_cfg[] = {
44 {
Nickey Yang Nickey Yang5a808a92016-12-29 14:01:26 +080045 .mpixelclock = 40000000,
Simon Glass0139ae62016-01-21 19:45:03 -070046 .cpce = 0x00b3, .gmp = 0x0000, .curr = 0x0018,
47 }, {
Nickey Yang Nickey Yang5a808a92016-12-29 14:01:26 +080048 .mpixelclock = 65000000,
Simon Glass0139ae62016-01-21 19:45:03 -070049 .cpce = 0x0072, .gmp = 0x0001, .curr = 0x0028,
50 }, {
Nickey Yang Nickey Yang5a808a92016-12-29 14:01:26 +080051 .mpixelclock = 66000000,
Simon Glass0139ae62016-01-21 19:45:03 -070052 .cpce = 0x013e, .gmp = 0x0003, .curr = 0x0038,
53 }, {
Nickey Yang Nickey Yang8b221cf2017-02-27 17:04:21 +080054 .mpixelclock = 83500000,
Simon Glass0139ae62016-01-21 19:45:03 -070055 .cpce = 0x0072, .gmp = 0x0001, .curr = 0x0028,
56 }, {
Nickey Yang Nickey Yang5a808a92016-12-29 14:01:26 +080057 .mpixelclock = 146250000,
Simon Glass0139ae62016-01-21 19:45:03 -070058 .cpce = 0x0051, .gmp = 0x0002, .curr = 0x0038,
59 }, {
Nickey Yang Nickey Yang5a808a92016-12-29 14:01:26 +080060 .mpixelclock = 148500000,
Simon Glass0139ae62016-01-21 19:45:03 -070061 .cpce = 0x0051, .gmp = 0x0003, .curr = 0x0000,
62 }, {
Philipp Tomsicha35ccec2017-05-31 17:59:32 +020063 .mpixelclock = 272000000,
64 .cpce = 0x0040, .gmp = 0x0003, .curr = 0x0000,
65 }, {
66 .mpixelclock = 340000000,
67 .cpce = 0x0040, .gmp = 0x0003, .curr = 0x0000,
68 }, {
Simon Glass0139ae62016-01-21 19:45:03 -070069 .mpixelclock = ~0ul,
70 .cpce = 0x0051, .gmp = 0x0003, .curr = 0x0000,
71 }
72};
73
Philipp Tomsich66cbacc2017-05-31 17:59:33 +020074int rk_hdmi_read_edid(struct udevice *dev, u8 *buf, int buf_size)
Simon Glass0139ae62016-01-21 19:45:03 -070075{
76 struct rk_hdmi_priv *priv = dev_get_priv(dev);
Simon Glass0139ae62016-01-21 19:45:03 -070077
Jernej Skrabec2ae12ee2017-03-20 23:01:22 +010078 return dw_hdmi_read_edid(&priv->hdmi, buf, buf_size);
Simon Glass0139ae62016-01-21 19:45:03 -070079}
80
Simon Glassaad29ae2020-12-03 16:55:21 -070081int rk_hdmi_of_to_plat(struct udevice *dev)
Simon Glass0139ae62016-01-21 19:45:03 -070082{
83 struct rk_hdmi_priv *priv = dev_get_priv(dev);
Jernej Skrabec2ae12ee2017-03-20 23:01:22 +010084 struct dw_hdmi *hdmi = &priv->hdmi;
85
Philipp Tomsich18c64962018-02-23 17:38:51 +010086 hdmi->ioaddr = (ulong)dev_read_addr(dev);
Jernej Skrabec2ae12ee2017-03-20 23:01:22 +010087 hdmi->mpll_cfg = rockchip_mpll_cfg;
88 hdmi->phy_cfg = rockchip_phy_config;
Jernej Skrabec2ae12ee2017-03-20 23:01:22 +010089
Philipp Tomsich66cbacc2017-05-31 17:59:33 +020090 /* hdmi->i2c_clk_{high,low} are set up by the SoC driver */
91
Jernej Skrabec2ae12ee2017-03-20 23:01:22 +010092 hdmi->reg_io_width = 4;
93 hdmi->phy_set = dw_hdmi_phy_cfg;
Simon Glass0139ae62016-01-21 19:45:03 -070094
Simon Glass0139ae62016-01-21 19:45:03 -070095 priv->grf = syscon_get_first_range(ROCKCHIP_SYSCON_GRF);
96
Niklas Schulze889ccde2019-07-27 12:07:13 +000097 uclass_get_device_by_phandle(UCLASS_I2C, dev, "ddc-i2c-bus",
98 &hdmi->ddc_bus);
99
Simon Glass0139ae62016-01-21 19:45:03 -0700100 return 0;
101}
102
Philipp Tomsich66cbacc2017-05-31 17:59:33 +0200103void rk_hdmi_probe_regulators(struct udevice *dev,
104 const char * const *names, int cnt)
105{
106 rk_vop_probe_regulators(dev, names, cnt);
107}
108
109int rk_hdmi_probe(struct udevice *dev)
Simon Glass0139ae62016-01-21 19:45:03 -0700110{
Simon Glass0139ae62016-01-21 19:45:03 -0700111 struct rk_hdmi_priv *priv = dev_get_priv(dev);
Jernej Skrabec2ae12ee2017-03-20 23:01:22 +0100112 struct dw_hdmi *hdmi = &priv->hdmi;
Simon Glass0139ae62016-01-21 19:45:03 -0700113 int ret;
Simon Glass0139ae62016-01-21 19:45:03 -0700114
Jernej Skrabec2ae12ee2017-03-20 23:01:22 +0100115 ret = dw_hdmi_phy_wait_for_hpd(hdmi);
Simon Glass0139ae62016-01-21 19:45:03 -0700116 if (ret < 0) {
117 debug("hdmi can not get hpd signal\n");
118 return -1;
119 }
120
Jernej Skrabec2ae12ee2017-03-20 23:01:22 +0100121 dw_hdmi_init(hdmi);
122 dw_hdmi_phy_init(hdmi);
Simon Glass0139ae62016-01-21 19:45:03 -0700123
124 return 0;
125}