Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Philipp Tomsich | 66cbacc | 2017-05-31 17:59:33 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2017 Theobroma Systems Design und Consulting GmbH |
Philipp Tomsich | 66cbacc | 2017-05-31 17:59:33 +0200 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #include <common.h> |
| 7 | #include <clk.h> |
| 8 | #include <display.h> |
| 9 | #include <dm.h> |
| 10 | #include <dw_hdmi.h> |
| 11 | #include <edid.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 12 | #include <log.h> |
Simon Glass | 9bc1564 | 2020-02-03 07:36:16 -0700 | [diff] [blame] | 13 | #include <malloc.h> |
Philipp Tomsich | 66cbacc | 2017-05-31 17:59:33 +0200 | [diff] [blame] | 14 | #include <regmap.h> |
| 15 | #include <syscon.h> |
| 16 | #include <asm/gpio.h> |
| 17 | #include <asm/io.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> |
| 20 | #include <asm/arch-rockchip/grf_rk3288.h> |
Philipp Tomsich | 66cbacc | 2017-05-31 17:59:33 +0200 | [diff] [blame] | 21 | #include <power/regulator.h> |
| 22 | #include "rk_hdmi.h" |
| 23 | |
| 24 | static int rk3288_hdmi_enable(struct udevice *dev, int panel_bpp, |
| 25 | const struct display_timing *edid) |
| 26 | { |
| 27 | struct rk_hdmi_priv *priv = dev_get_priv(dev); |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 28 | struct display_plat *uc_plat = dev_get_uclass_plat(dev); |
Philipp Tomsich | 66cbacc | 2017-05-31 17:59:33 +0200 | [diff] [blame] | 29 | int vop_id = uc_plat->source_id; |
| 30 | struct rk3288_grf *grf = priv->grf; |
| 31 | |
| 32 | /* hdmi source select hdmi controller */ |
| 33 | rk_setreg(&grf->soc_con6, 1 << 15); |
| 34 | |
| 35 | /* hdmi data from vop id */ |
| 36 | rk_clrsetreg(&grf->soc_con6, 1 << 4, (vop_id == 1) ? (1 << 4) : 0); |
| 37 | |
Niklas Schulze | 65fdabe | 2019-07-14 10:40:13 +0000 | [diff] [blame] | 38 | return dw_hdmi_enable(&priv->hdmi, edid); |
Philipp Tomsich | 66cbacc | 2017-05-31 17:59:33 +0200 | [diff] [blame] | 39 | } |
| 40 | |
Simon Glass | aad29ae | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 41 | static int rk3288_hdmi_of_to_plat(struct udevice *dev) |
Philipp Tomsich | 66cbacc | 2017-05-31 17:59:33 +0200 | [diff] [blame] | 42 | { |
| 43 | struct rk_hdmi_priv *priv = dev_get_priv(dev); |
| 44 | struct dw_hdmi *hdmi = &priv->hdmi; |
| 45 | |
| 46 | hdmi->i2c_clk_high = 0x7a; |
| 47 | hdmi->i2c_clk_low = 0x8d; |
| 48 | |
| 49 | /* |
| 50 | * TODO(sjg@chromium.org): The above values don't work - these |
| 51 | * ones work better, but generate lots of errors in the data. |
| 52 | */ |
| 53 | hdmi->i2c_clk_high = 0x0d; |
| 54 | hdmi->i2c_clk_low = 0x0d; |
| 55 | |
Simon Glass | aad29ae | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 56 | return rk_hdmi_of_to_plat(dev); |
Philipp Tomsich | 66cbacc | 2017-05-31 17:59:33 +0200 | [diff] [blame] | 57 | } |
| 58 | |
| 59 | static int rk3288_clk_config(struct udevice *dev) |
| 60 | { |
Simon Glass | 71fa5b4 | 2020-12-03 16:55:18 -0700 | [diff] [blame] | 61 | struct display_plat *uc_plat = dev_get_uclass_plat(dev); |
Philipp Tomsich | 66cbacc | 2017-05-31 17:59:33 +0200 | [diff] [blame] | 62 | struct clk clk; |
| 63 | int ret; |
| 64 | |
| 65 | /* |
| 66 | * Configure the maximum clock to permit whatever resolution the |
| 67 | * monitor wants |
| 68 | */ |
| 69 | ret = clk_get_by_index(uc_plat->src_dev, 0, &clk); |
Sean Anderson | d318eb3 | 2023-12-16 14:38:42 -0500 | [diff] [blame] | 70 | if (ret >= 0) |
Philipp Tomsich | 66cbacc | 2017-05-31 17:59:33 +0200 | [diff] [blame] | 71 | ret = clk_set_rate(&clk, 384000000); |
Philipp Tomsich | 66cbacc | 2017-05-31 17:59:33 +0200 | [diff] [blame] | 72 | if (ret < 0) { |
| 73 | debug("%s: Failed to set clock in source device '%s': ret=%d\n", |
| 74 | __func__, uc_plat->src_dev->name, ret); |
| 75 | return ret; |
| 76 | } |
| 77 | |
| 78 | return 0; |
| 79 | } |
| 80 | |
| 81 | static const char * const rk3288_regulator_names[] = { |
| 82 | "vcc50_hdmi" |
| 83 | }; |
| 84 | |
| 85 | static int rk3288_hdmi_probe(struct udevice *dev) |
| 86 | { |
| 87 | /* Enable VOP clock for RK3288 */ |
| 88 | rk3288_clk_config(dev); |
| 89 | |
| 90 | /* Enable regulators required for HDMI */ |
| 91 | rk_hdmi_probe_regulators(dev, rk3288_regulator_names, |
| 92 | ARRAY_SIZE(rk3288_regulator_names)); |
| 93 | |
| 94 | return rk_hdmi_probe(dev); |
| 95 | } |
| 96 | |
| 97 | static const struct dm_display_ops rk3288_hdmi_ops = { |
| 98 | .read_edid = rk_hdmi_read_edid, |
| 99 | .enable = rk3288_hdmi_enable, |
| 100 | }; |
| 101 | |
| 102 | static const struct udevice_id rk3288_hdmi_ids[] = { |
| 103 | { .compatible = "rockchip,rk3288-dw-hdmi" }, |
| 104 | { } |
| 105 | }; |
| 106 | |
| 107 | U_BOOT_DRIVER(rk3288_hdmi_rockchip) = { |
| 108 | .name = "rk3288_hdmi_rockchip", |
| 109 | .id = UCLASS_DISPLAY, |
| 110 | .of_match = rk3288_hdmi_ids, |
| 111 | .ops = &rk3288_hdmi_ops, |
Simon Glass | aad29ae | 2020-12-03 16:55:21 -0700 | [diff] [blame] | 112 | .of_to_plat = rk3288_hdmi_of_to_plat, |
Philipp Tomsich | 66cbacc | 2017-05-31 17:59:33 +0200 | [diff] [blame] | 113 | .probe = rk3288_hdmi_probe, |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 114 | .priv_auto = sizeof(struct rk_hdmi_priv), |
Philipp Tomsich | 66cbacc | 2017-05-31 17:59:33 +0200 | [diff] [blame] | 115 | }; |