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