blob: 13d07ee304815e16b907edc060d42d616a338e34 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Simon Glassc2539482016-01-21 19:45:03 -07002/*
Philipp Tomsich147fd3a2017-05-31 17:59:33 +02003 * Copyright (c) 2017 Theobroma Systems Design und Consulting GmbH
Simon Glassc2539482016-01-21 19:45:03 -07004 * Copyright (c) 2015 Google, Inc
5 * Copyright 2014 Rockchip Inc.
Simon Glassc2539482016-01-21 19:45:03 -07006 */
7
8#include <common.h>
9#include <clk.h>
10#include <display.h>
11#include <dm.h>
Jernej Skrabeccc232a92017-03-20 23:01:22 +010012#include <dw_hdmi.h>
Simon Glassc2539482016-01-21 19:45:03 -070013#include <edid.h>
14#include <regmap.h>
15#include <syscon.h>
16#include <asm/gpio.h>
Philipp Tomsich12085232017-06-06 09:15:14 +020017#include <asm/hardware.h>
Simon Glassc2539482016-01-21 19:45:03 -070018#include <asm/io.h>
19#include <asm/arch/clock.h>
Philipp Tomsich147fd3a2017-05-31 17:59:33 +020020#include <asm/arch/hardware.h>
21#include "rk_hdmi.h"
22#include "rk_vop.h" /* for rk_vop_probe_regulators */
Simon Glassc2539482016-01-21 19:45:03 -070023
Simon Glassc2539482016-01-21 19:45:03 -070024static const struct hdmi_phy_config rockchip_phy_config[] = {
25 {
Nickey Yang Nickey Yang0fc41e52016-12-29 14:01:26 +080026 .mpixelclock = 74250000,
Simon Glassc2539482016-01-21 19:45:03 -070027 .sym_ctr = 0x8009, .term = 0x0004, .vlev_ctr = 0x0272,
28 }, {
Nickey Yang Nickey Yang0fc41e52016-12-29 14:01:26 +080029 .mpixelclock = 148500000,
Simon Glassc2539482016-01-21 19:45:03 -070030 .sym_ctr = 0x802b, .term = 0x0004, .vlev_ctr = 0x028d,
31 }, {
Nickey Yang Nickey Yang0fc41e52016-12-29 14:01:26 +080032 .mpixelclock = 297000000,
Simon Glassc2539482016-01-21 19:45:03 -070033 .sym_ctr = 0x8039, .term = 0x0005, .vlev_ctr = 0x028d,
34 }, {
Philipp Tomsichf210e552017-05-31 17:59:32 +020035 .mpixelclock = 584000000,
36 .sym_ctr = 0x8039, .term = 0x0000, .vlev_ctr = 0x019d,
37 }, {
Simon Glassc2539482016-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 Yang0fc41e52016-12-29 14:01:26 +080045 .mpixelclock = 40000000,
Simon Glassc2539482016-01-21 19:45:03 -070046 .cpce = 0x00b3, .gmp = 0x0000, .curr = 0x0018,
47 }, {
Nickey Yang Nickey Yang0fc41e52016-12-29 14:01:26 +080048 .mpixelclock = 65000000,
Simon Glassc2539482016-01-21 19:45:03 -070049 .cpce = 0x0072, .gmp = 0x0001, .curr = 0x0028,
50 }, {
Nickey Yang Nickey Yang0fc41e52016-12-29 14:01:26 +080051 .mpixelclock = 66000000,
Simon Glassc2539482016-01-21 19:45:03 -070052 .cpce = 0x013e, .gmp = 0x0003, .curr = 0x0038,
53 }, {
Nickey Yang Nickey Yang94412742017-02-27 17:04:21 +080054 .mpixelclock = 83500000,
Simon Glassc2539482016-01-21 19:45:03 -070055 .cpce = 0x0072, .gmp = 0x0001, .curr = 0x0028,
56 }, {
Nickey Yang Nickey Yang0fc41e52016-12-29 14:01:26 +080057 .mpixelclock = 146250000,
Simon Glassc2539482016-01-21 19:45:03 -070058 .cpce = 0x0051, .gmp = 0x0002, .curr = 0x0038,
59 }, {
Nickey Yang Nickey Yang0fc41e52016-12-29 14:01:26 +080060 .mpixelclock = 148500000,
Simon Glassc2539482016-01-21 19:45:03 -070061 .cpce = 0x0051, .gmp = 0x0003, .curr = 0x0000,
62 }, {
Philipp Tomsichf210e552017-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 Glassc2539482016-01-21 19:45:03 -070069 .mpixelclock = ~0ul,
70 .cpce = 0x0051, .gmp = 0x0003, .curr = 0x0000,
71 }
72};
73
Philipp Tomsich147fd3a2017-05-31 17:59:33 +020074int rk_hdmi_read_edid(struct udevice *dev, u8 *buf, int buf_size)
Simon Glassc2539482016-01-21 19:45:03 -070075{
76 struct rk_hdmi_priv *priv = dev_get_priv(dev);
Simon Glassc2539482016-01-21 19:45:03 -070077
Jernej Skrabeccc232a92017-03-20 23:01:22 +010078 return dw_hdmi_read_edid(&priv->hdmi, buf, buf_size);
Simon Glassc2539482016-01-21 19:45:03 -070079}
80
Philipp Tomsich147fd3a2017-05-31 17:59:33 +020081int rk_hdmi_ofdata_to_platdata(struct udevice *dev)
Simon Glassc2539482016-01-21 19:45:03 -070082{
83 struct rk_hdmi_priv *priv = dev_get_priv(dev);
Jernej Skrabeccc232a92017-03-20 23:01:22 +010084 struct dw_hdmi *hdmi = &priv->hdmi;
Simon Glassc2539482016-01-21 19:45:03 -070085
Philipp Tomsich18e48772018-02-23 17:38:51 +010086 hdmi->ioaddr = (ulong)dev_read_addr(dev);
Jernej Skrabeccc232a92017-03-20 23:01:22 +010087 hdmi->mpll_cfg = rockchip_mpll_cfg;
88 hdmi->phy_cfg = rockchip_phy_config;
Jernej Skrabeccc232a92017-03-20 23:01:22 +010089
Philipp Tomsich147fd3a2017-05-31 17:59:33 +020090 /* hdmi->i2c_clk_{high,low} are set up by the SoC driver */
91
Jernej Skrabeccc232a92017-03-20 23:01:22 +010092 hdmi->reg_io_width = 4;
93 hdmi->phy_set = dw_hdmi_phy_cfg;
94
Simon Glassc2539482016-01-21 19:45:03 -070095 priv->grf = syscon_get_first_range(ROCKCHIP_SYSCON_GRF);
96
97 return 0;
98}
99
Philipp Tomsich147fd3a2017-05-31 17:59:33 +0200100void rk_hdmi_probe_regulators(struct udevice *dev,
101 const char * const *names, int cnt)
Simon Glassc2539482016-01-21 19:45:03 -0700102{
Philipp Tomsich147fd3a2017-05-31 17:59:33 +0200103 rk_vop_probe_regulators(dev, names, cnt);
104}
105
106int rk_hdmi_probe(struct udevice *dev)
107{
Simon Glassc2539482016-01-21 19:45:03 -0700108 struct rk_hdmi_priv *priv = dev_get_priv(dev);
Jernej Skrabeccc232a92017-03-20 23:01:22 +0100109 struct dw_hdmi *hdmi = &priv->hdmi;
Simon Glassc2539482016-01-21 19:45:03 -0700110 int ret;
Simon Glassc2539482016-01-21 19:45:03 -0700111
Jernej Skrabeccc232a92017-03-20 23:01:22 +0100112 ret = dw_hdmi_phy_wait_for_hpd(hdmi);
Simon Glassc2539482016-01-21 19:45:03 -0700113 if (ret < 0) {
114 debug("hdmi can not get hpd signal\n");
115 return -1;
116 }
117
Jernej Skrabeccc232a92017-03-20 23:01:22 +0100118 dw_hdmi_init(hdmi);
119 dw_hdmi_phy_init(hdmi);
Simon Glassc2539482016-01-21 19:45:03 -0700120
121 return 0;
122}