blob: a9c8fba7e45d5f9fde9f48961b21b3d310c71787 [file] [log] [blame]
Simon Glassc2539482016-01-21 19:45:03 -07001/*
Philipp Tomsich147fd3a2017-05-31 17:59:33 +02002 * Copyright (c) 2017 Theobroma Systems Design und Consulting GmbH
Simon Glassc2539482016-01-21 19:45:03 -07003 * Copyright (c) 2015 Google, Inc
4 * Copyright 2014 Rockchip Inc.
5 *
6 * SPDX-License-Identifier: GPL-2.0+
7 */
8
9#include <common.h>
10#include <clk.h>
11#include <display.h>
12#include <dm.h>
Jernej Skrabeccc232a92017-03-20 23:01:22 +010013#include <dw_hdmi.h>
Simon Glassc2539482016-01-21 19:45:03 -070014#include <edid.h>
15#include <regmap.h>
16#include <syscon.h>
17#include <asm/gpio.h>
Philipp Tomsich12085232017-06-06 09:15:14 +020018#include <asm/hardware.h>
Simon Glassc2539482016-01-21 19:45:03 -070019#include <asm/io.h>
20#include <asm/arch/clock.h>
Philipp Tomsich147fd3a2017-05-31 17:59:33 +020021#include <asm/arch/hardware.h>
22#include "rk_hdmi.h"
23#include "rk_vop.h" /* for rk_vop_probe_regulators */
Simon Glassc2539482016-01-21 19:45:03 -070024
Simon Glassc2539482016-01-21 19:45:03 -070025static const struct hdmi_phy_config rockchip_phy_config[] = {
26 {
Nickey Yang Nickey Yang0fc41e52016-12-29 14:01:26 +080027 .mpixelclock = 74250000,
Simon Glassc2539482016-01-21 19:45:03 -070028 .sym_ctr = 0x8009, .term = 0x0004, .vlev_ctr = 0x0272,
29 }, {
Nickey Yang Nickey Yang0fc41e52016-12-29 14:01:26 +080030 .mpixelclock = 148500000,
Simon Glassc2539482016-01-21 19:45:03 -070031 .sym_ctr = 0x802b, .term = 0x0004, .vlev_ctr = 0x028d,
32 }, {
Nickey Yang Nickey Yang0fc41e52016-12-29 14:01:26 +080033 .mpixelclock = 297000000,
Simon Glassc2539482016-01-21 19:45:03 -070034 .sym_ctr = 0x8039, .term = 0x0005, .vlev_ctr = 0x028d,
35 }, {
Philipp Tomsichf210e552017-05-31 17:59:32 +020036 .mpixelclock = 584000000,
37 .sym_ctr = 0x8039, .term = 0x0000, .vlev_ctr = 0x019d,
38 }, {
Simon Glassc2539482016-01-21 19:45:03 -070039 .mpixelclock = ~0ul,
40 .sym_ctr = 0x0000, .term = 0x0000, .vlev_ctr = 0x0000,
41 }
42};
43
44static const struct hdmi_mpll_config rockchip_mpll_cfg[] = {
45 {
Nickey Yang Nickey Yang0fc41e52016-12-29 14:01:26 +080046 .mpixelclock = 40000000,
Simon Glassc2539482016-01-21 19:45:03 -070047 .cpce = 0x00b3, .gmp = 0x0000, .curr = 0x0018,
48 }, {
Nickey Yang Nickey Yang0fc41e52016-12-29 14:01:26 +080049 .mpixelclock = 65000000,
Simon Glassc2539482016-01-21 19:45:03 -070050 .cpce = 0x0072, .gmp = 0x0001, .curr = 0x0028,
51 }, {
Nickey Yang Nickey Yang0fc41e52016-12-29 14:01:26 +080052 .mpixelclock = 66000000,
Simon Glassc2539482016-01-21 19:45:03 -070053 .cpce = 0x013e, .gmp = 0x0003, .curr = 0x0038,
54 }, {
Nickey Yang Nickey Yang94412742017-02-27 17:04:21 +080055 .mpixelclock = 83500000,
Simon Glassc2539482016-01-21 19:45:03 -070056 .cpce = 0x0072, .gmp = 0x0001, .curr = 0x0028,
57 }, {
Nickey Yang Nickey Yang0fc41e52016-12-29 14:01:26 +080058 .mpixelclock = 146250000,
Simon Glassc2539482016-01-21 19:45:03 -070059 .cpce = 0x0051, .gmp = 0x0002, .curr = 0x0038,
60 }, {
Nickey Yang Nickey Yang0fc41e52016-12-29 14:01:26 +080061 .mpixelclock = 148500000,
Simon Glassc2539482016-01-21 19:45:03 -070062 .cpce = 0x0051, .gmp = 0x0003, .curr = 0x0000,
63 }, {
Philipp Tomsichf210e552017-05-31 17:59:32 +020064 .mpixelclock = 272000000,
65 .cpce = 0x0040, .gmp = 0x0003, .curr = 0x0000,
66 }, {
67 .mpixelclock = 340000000,
68 .cpce = 0x0040, .gmp = 0x0003, .curr = 0x0000,
69 }, {
Simon Glassc2539482016-01-21 19:45:03 -070070 .mpixelclock = ~0ul,
71 .cpce = 0x0051, .gmp = 0x0003, .curr = 0x0000,
72 }
73};
74
Philipp Tomsich147fd3a2017-05-31 17:59:33 +020075int rk_hdmi_read_edid(struct udevice *dev, u8 *buf, int buf_size)
Simon Glassc2539482016-01-21 19:45:03 -070076{
77 struct rk_hdmi_priv *priv = dev_get_priv(dev);
Simon Glassc2539482016-01-21 19:45:03 -070078
Jernej Skrabeccc232a92017-03-20 23:01:22 +010079 return dw_hdmi_read_edid(&priv->hdmi, buf, buf_size);
Simon Glassc2539482016-01-21 19:45:03 -070080}
81
Philipp Tomsich147fd3a2017-05-31 17:59:33 +020082int rk_hdmi_ofdata_to_platdata(struct udevice *dev)
Simon Glassc2539482016-01-21 19:45:03 -070083{
84 struct rk_hdmi_priv *priv = dev_get_priv(dev);
Jernej Skrabeccc232a92017-03-20 23:01:22 +010085 struct dw_hdmi *hdmi = &priv->hdmi;
Simon Glassc2539482016-01-21 19:45:03 -070086
Simon Glassa821c4a2017-05-17 17:18:05 -060087 hdmi->ioaddr = (ulong)devfdt_get_addr(dev);
Jernej Skrabeccc232a92017-03-20 23:01:22 +010088 hdmi->mpll_cfg = rockchip_mpll_cfg;
89 hdmi->phy_cfg = rockchip_phy_config;
Jernej Skrabeccc232a92017-03-20 23:01:22 +010090
Philipp Tomsich147fd3a2017-05-31 17:59:33 +020091 /* hdmi->i2c_clk_{high,low} are set up by the SoC driver */
92
Jernej Skrabeccc232a92017-03-20 23:01:22 +010093 hdmi->reg_io_width = 4;
94 hdmi->phy_set = dw_hdmi_phy_cfg;
95
Simon Glassc2539482016-01-21 19:45:03 -070096 priv->grf = syscon_get_first_range(ROCKCHIP_SYSCON_GRF);
97
98 return 0;
99}
100
Philipp Tomsich147fd3a2017-05-31 17:59:33 +0200101void rk_hdmi_probe_regulators(struct udevice *dev,
102 const char * const *names, int cnt)
Simon Glassc2539482016-01-21 19:45:03 -0700103{
Philipp Tomsich147fd3a2017-05-31 17:59:33 +0200104 rk_vop_probe_regulators(dev, names, cnt);
105}
106
107int rk_hdmi_probe(struct udevice *dev)
108{
Simon Glassc2539482016-01-21 19:45:03 -0700109 struct rk_hdmi_priv *priv = dev_get_priv(dev);
Jernej Skrabeccc232a92017-03-20 23:01:22 +0100110 struct dw_hdmi *hdmi = &priv->hdmi;
Simon Glassc2539482016-01-21 19:45:03 -0700111 int ret;
Simon Glassc2539482016-01-21 19:45:03 -0700112
Jernej Skrabeccc232a92017-03-20 23:01:22 +0100113 ret = dw_hdmi_phy_wait_for_hpd(hdmi);
Simon Glassc2539482016-01-21 19:45:03 -0700114 if (ret < 0) {
115 debug("hdmi can not get hpd signal\n");
116 return -1;
117 }
118
Jernej Skrabeccc232a92017-03-20 23:01:22 +0100119 dw_hdmi_init(hdmi);
120 dw_hdmi_phy_init(hdmi);
Simon Glassc2539482016-01-21 19:45:03 -0700121
122 return 0;
123}