Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Simon Glass | 0139ae6 | 2016-01-21 19:45:03 -0700 | [diff] [blame] | 2 | /* |
Philipp Tomsich | 66cbacc | 2017-05-31 17:59:33 +0200 | [diff] [blame] | 3 | * Copyright (c) 2017 Theobroma Systems Design und Consulting GmbH |
Simon Glass | 0139ae6 | 2016-01-21 19:45:03 -0700 | [diff] [blame] | 4 | * Copyright (c) 2015 Google, Inc |
| 5 | * Copyright 2014 Rockchip Inc. |
Simon Glass | 0139ae6 | 2016-01-21 19:45:03 -0700 | [diff] [blame] | 6 | */ |
| 7 | |
| 8 | #include <common.h> |
| 9 | #include <clk.h> |
| 10 | #include <display.h> |
| 11 | #include <dm.h> |
Jernej Skrabec | 2ae12ee | 2017-03-20 23:01:22 +0100 | [diff] [blame] | 12 | #include <dw_hdmi.h> |
Simon Glass | 0139ae6 | 2016-01-21 19:45:03 -0700 | [diff] [blame] | 13 | #include <edid.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 14 | #include <log.h> |
Simon Glass | 0139ae6 | 2016-01-21 19:45:03 -0700 | [diff] [blame] | 15 | #include <regmap.h> |
| 16 | #include <syscon.h> |
| 17 | #include <asm/gpio.h> |
Kever Yang | 9fbe17c | 2019-03-28 11:01:23 +0800 | [diff] [blame] | 18 | #include <asm/arch-rockchip/clock.h> |
| 19 | #include <asm/arch-rockchip/hardware.h> |
Philipp Tomsich | 66cbacc | 2017-05-31 17:59:33 +0200 | [diff] [blame] | 20 | #include "rk_hdmi.h" |
| 21 | #include "rk_vop.h" /* for rk_vop_probe_regulators */ |
Simon Glass | 0139ae6 | 2016-01-21 19:45:03 -0700 | [diff] [blame] | 22 | |
Simon Glass | 0139ae6 | 2016-01-21 19:45:03 -0700 | [diff] [blame] | 23 | static const struct hdmi_phy_config rockchip_phy_config[] = { |
| 24 | { |
Nickey Yang Nickey Yang | 5a808a9 | 2016-12-29 14:01:26 +0800 | [diff] [blame] | 25 | .mpixelclock = 74250000, |
Simon Glass | 0139ae6 | 2016-01-21 19:45:03 -0700 | [diff] [blame] | 26 | .sym_ctr = 0x8009, .term = 0x0004, .vlev_ctr = 0x0272, |
| 27 | }, { |
Nickey Yang Nickey Yang | 5a808a9 | 2016-12-29 14:01:26 +0800 | [diff] [blame] | 28 | .mpixelclock = 148500000, |
Simon Glass | 0139ae6 | 2016-01-21 19:45:03 -0700 | [diff] [blame] | 29 | .sym_ctr = 0x802b, .term = 0x0004, .vlev_ctr = 0x028d, |
| 30 | }, { |
Nickey Yang Nickey Yang | 5a808a9 | 2016-12-29 14:01:26 +0800 | [diff] [blame] | 31 | .mpixelclock = 297000000, |
Simon Glass | 0139ae6 | 2016-01-21 19:45:03 -0700 | [diff] [blame] | 32 | .sym_ctr = 0x8039, .term = 0x0005, .vlev_ctr = 0x028d, |
| 33 | }, { |
Philipp Tomsich | a35ccec | 2017-05-31 17:59:32 +0200 | [diff] [blame] | 34 | .mpixelclock = 584000000, |
| 35 | .sym_ctr = 0x8039, .term = 0x0000, .vlev_ctr = 0x019d, |
| 36 | }, { |
Simon Glass | 0139ae6 | 2016-01-21 19:45:03 -0700 | [diff] [blame] | 37 | .mpixelclock = ~0ul, |
| 38 | .sym_ctr = 0x0000, .term = 0x0000, .vlev_ctr = 0x0000, |
| 39 | } |
| 40 | }; |
| 41 | |
| 42 | static const struct hdmi_mpll_config rockchip_mpll_cfg[] = { |
| 43 | { |
Nickey Yang Nickey Yang | 5a808a9 | 2016-12-29 14:01:26 +0800 | [diff] [blame] | 44 | .mpixelclock = 40000000, |
Simon Glass | 0139ae6 | 2016-01-21 19:45:03 -0700 | [diff] [blame] | 45 | .cpce = 0x00b3, .gmp = 0x0000, .curr = 0x0018, |
| 46 | }, { |
Nickey Yang Nickey Yang | 5a808a9 | 2016-12-29 14:01:26 +0800 | [diff] [blame] | 47 | .mpixelclock = 65000000, |
Simon Glass | 0139ae6 | 2016-01-21 19:45:03 -0700 | [diff] [blame] | 48 | .cpce = 0x0072, .gmp = 0x0001, .curr = 0x0028, |
| 49 | }, { |
Nickey Yang Nickey Yang | 5a808a9 | 2016-12-29 14:01:26 +0800 | [diff] [blame] | 50 | .mpixelclock = 66000000, |
Simon Glass | 0139ae6 | 2016-01-21 19:45:03 -0700 | [diff] [blame] | 51 | .cpce = 0x013e, .gmp = 0x0003, .curr = 0x0038, |
| 52 | }, { |
Nickey Yang Nickey Yang | 8b221cf | 2017-02-27 17:04:21 +0800 | [diff] [blame] | 53 | .mpixelclock = 83500000, |
Simon Glass | 0139ae6 | 2016-01-21 19:45:03 -0700 | [diff] [blame] | 54 | .cpce = 0x0072, .gmp = 0x0001, .curr = 0x0028, |
| 55 | }, { |
Nickey Yang Nickey Yang | 5a808a9 | 2016-12-29 14:01:26 +0800 | [diff] [blame] | 56 | .mpixelclock = 146250000, |
Simon Glass | 0139ae6 | 2016-01-21 19:45:03 -0700 | [diff] [blame] | 57 | .cpce = 0x0051, .gmp = 0x0002, .curr = 0x0038, |
| 58 | }, { |
Nickey Yang Nickey Yang | 5a808a9 | 2016-12-29 14:01:26 +0800 | [diff] [blame] | 59 | .mpixelclock = 148500000, |
Simon Glass | 0139ae6 | 2016-01-21 19:45:03 -0700 | [diff] [blame] | 60 | .cpce = 0x0051, .gmp = 0x0003, .curr = 0x0000, |
| 61 | }, { |
Philipp Tomsich | a35ccec | 2017-05-31 17:59:32 +0200 | [diff] [blame] | 62 | .mpixelclock = 272000000, |
| 63 | .cpce = 0x0040, .gmp = 0x0003, .curr = 0x0000, |
| 64 | }, { |
| 65 | .mpixelclock = 340000000, |
| 66 | .cpce = 0x0040, .gmp = 0x0003, .curr = 0x0000, |
| 67 | }, { |
Simon Glass | 0139ae6 | 2016-01-21 19:45:03 -0700 | [diff] [blame] | 68 | .mpixelclock = ~0ul, |
| 69 | .cpce = 0x0051, .gmp = 0x0003, .curr = 0x0000, |
| 70 | } |
| 71 | }; |
| 72 | |
Philipp Tomsich | 66cbacc | 2017-05-31 17:59:33 +0200 | [diff] [blame] | 73 | int rk_hdmi_read_edid(struct udevice *dev, u8 *buf, int buf_size) |
Simon Glass | 0139ae6 | 2016-01-21 19:45:03 -0700 | [diff] [blame] | 74 | { |
| 75 | struct rk_hdmi_priv *priv = dev_get_priv(dev); |
Simon Glass | 0139ae6 | 2016-01-21 19:45:03 -0700 | [diff] [blame] | 76 | |
Jernej Skrabec | 2ae12ee | 2017-03-20 23:01:22 +0100 | [diff] [blame] | 77 | return dw_hdmi_read_edid(&priv->hdmi, buf, buf_size); |
Simon Glass | 0139ae6 | 2016-01-21 19:45:03 -0700 | [diff] [blame] | 78 | } |
| 79 | |
Simon Glass | aad29ae | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 80 | int rk_hdmi_of_to_plat(struct udevice *dev) |
Simon Glass | 0139ae6 | 2016-01-21 19:45:03 -0700 | [diff] [blame] | 81 | { |
| 82 | struct rk_hdmi_priv *priv = dev_get_priv(dev); |
Jernej Skrabec | 2ae12ee | 2017-03-20 23:01:22 +0100 | [diff] [blame] | 83 | struct dw_hdmi *hdmi = &priv->hdmi; |
| 84 | |
Philipp Tomsich | 18c6496 | 2018-02-23 17:38:51 +0100 | [diff] [blame] | 85 | hdmi->ioaddr = (ulong)dev_read_addr(dev); |
Jernej Skrabec | 2ae12ee | 2017-03-20 23:01:22 +0100 | [diff] [blame] | 86 | hdmi->mpll_cfg = rockchip_mpll_cfg; |
| 87 | hdmi->phy_cfg = rockchip_phy_config; |
Jernej Skrabec | 2ae12ee | 2017-03-20 23:01:22 +0100 | [diff] [blame] | 88 | |
Philipp Tomsich | 66cbacc | 2017-05-31 17:59:33 +0200 | [diff] [blame] | 89 | /* hdmi->i2c_clk_{high,low} are set up by the SoC driver */ |
| 90 | |
Jernej Skrabec | 2ae12ee | 2017-03-20 23:01:22 +0100 | [diff] [blame] | 91 | hdmi->reg_io_width = 4; |
| 92 | hdmi->phy_set = dw_hdmi_phy_cfg; |
Simon Glass | 0139ae6 | 2016-01-21 19:45:03 -0700 | [diff] [blame] | 93 | |
Simon Glass | 0139ae6 | 2016-01-21 19:45:03 -0700 | [diff] [blame] | 94 | priv->grf = syscon_get_first_range(ROCKCHIP_SYSCON_GRF); |
| 95 | |
Niklas Schulze | 889ccde | 2019-07-27 12:07:13 +0000 | [diff] [blame] | 96 | uclass_get_device_by_phandle(UCLASS_I2C, dev, "ddc-i2c-bus", |
| 97 | &hdmi->ddc_bus); |
| 98 | |
Simon Glass | 0139ae6 | 2016-01-21 19:45:03 -0700 | [diff] [blame] | 99 | return 0; |
| 100 | } |
| 101 | |
Philipp Tomsich | 66cbacc | 2017-05-31 17:59:33 +0200 | [diff] [blame] | 102 | void rk_hdmi_probe_regulators(struct udevice *dev, |
| 103 | const char * const *names, int cnt) |
| 104 | { |
| 105 | rk_vop_probe_regulators(dev, names, cnt); |
| 106 | } |
| 107 | |
| 108 | int rk_hdmi_probe(struct udevice *dev) |
Simon Glass | 0139ae6 | 2016-01-21 19:45:03 -0700 | [diff] [blame] | 109 | { |
Simon Glass | 0139ae6 | 2016-01-21 19:45:03 -0700 | [diff] [blame] | 110 | struct rk_hdmi_priv *priv = dev_get_priv(dev); |
Jernej Skrabec | 2ae12ee | 2017-03-20 23:01:22 +0100 | [diff] [blame] | 111 | struct dw_hdmi *hdmi = &priv->hdmi; |
Simon Glass | 0139ae6 | 2016-01-21 19:45:03 -0700 | [diff] [blame] | 112 | int ret; |
Simon Glass | 0139ae6 | 2016-01-21 19:45:03 -0700 | [diff] [blame] | 113 | |
Jernej Skrabec | 2ae12ee | 2017-03-20 23:01:22 +0100 | [diff] [blame] | 114 | ret = dw_hdmi_phy_wait_for_hpd(hdmi); |
Simon Glass | 0139ae6 | 2016-01-21 19:45:03 -0700 | [diff] [blame] | 115 | if (ret < 0) { |
| 116 | debug("hdmi can not get hpd signal\n"); |
| 117 | return -1; |
| 118 | } |
| 119 | |
Jernej Skrabec | 2ae12ee | 2017-03-20 23:01:22 +0100 | [diff] [blame] | 120 | dw_hdmi_init(hdmi); |
| 121 | dw_hdmi_phy_init(hdmi); |
Simon Glass | 0139ae6 | 2016-01-21 19:45:03 -0700 | [diff] [blame] | 122 | |
| 123 | return 0; |
| 124 | } |