Jagan Teki | 161c67b | 2024-01-17 13:21:49 +0530 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
| 2 | /* |
| 3 | * Copyright (c) 2023 Edgeble AI Technologies Pvt. Ltd. |
| 4 | */ |
| 5 | |
| 6 | #include <clk.h> |
| 7 | #include <display.h> |
| 8 | #include <dm.h> |
| 9 | #include <dw_hdmi.h> |
| 10 | #include <asm/io.h> |
| 11 | #include <asm/arch-rockchip/grf_rk3328.h> |
| 12 | #include "rk_hdmi.h" |
| 13 | |
| 14 | #define RK3328_IO_3V_DOMAIN (7 << (9 + 16)) |
| 15 | #define RK3328_IO_5V_DOMAIN ((7 << 9) | (3 << (9 + 16))) |
| 16 | #define RK3328_IO_DDC_IN_MSK ((3 << 10) | (3 << (10 + 16))) |
| 17 | #define RK3328_IO_CTRL_BY_HDMI ((1 << 13) | (1 << (13 + 16))) |
| 18 | |
| 19 | static int rk3328_hdmi_enable(struct udevice *dev, int panel_bpp, |
| 20 | const struct display_timing *edid) |
| 21 | { |
| 22 | struct rk_hdmi_priv *priv = dev_get_priv(dev); |
| 23 | |
| 24 | return dw_hdmi_enable(&priv->hdmi, edid); |
| 25 | } |
| 26 | |
| 27 | static int rk3328_dw_hdmi_phy_cfg(struct dw_hdmi *hdmi, uint pixclock) |
| 28 | { |
| 29 | struct rk_hdmi_priv *priv = container_of(hdmi, struct rk_hdmi_priv, hdmi); |
| 30 | int ret; |
| 31 | |
| 32 | ret = generic_phy_init(&priv->phy); |
| 33 | if (ret) { |
| 34 | printf("failed to init phy (ret=%d)\n", ret); |
| 35 | return ret; |
| 36 | } |
| 37 | |
| 38 | ret = generic_phy_power_on(&priv->phy); |
| 39 | if (ret) { |
| 40 | printf("failed to power on phy (ret=%d)\n", ret); |
| 41 | return ret; |
| 42 | } |
| 43 | |
| 44 | return 0; |
| 45 | } |
| 46 | |
| 47 | static void rk3328_dw_hdmi_setup_hpd(struct dw_hdmi *hdmi) |
| 48 | { |
| 49 | struct rk_hdmi_priv *priv = container_of(hdmi, struct rk_hdmi_priv, hdmi); |
| 50 | struct rk3328_grf_regs *grf = priv->grf; |
| 51 | |
| 52 | writel(RK3328_IO_DDC_IN_MSK, &grf->soc_con[2]); |
| 53 | writel(RK3328_IO_CTRL_BY_HDMI, &grf->soc_con[3]); |
| 54 | } |
| 55 | |
| 56 | static void rk3328_dw_hdmi_read_hpd(struct dw_hdmi *hdmi, bool hpd_status) |
| 57 | { |
| 58 | struct rk_hdmi_priv *priv = container_of(hdmi, struct rk_hdmi_priv, hdmi); |
| 59 | struct rk3328_grf_regs *grf = priv->grf; |
| 60 | |
| 61 | if (hpd_status) |
| 62 | writel(RK3328_IO_5V_DOMAIN, &grf->soc_con[4]); |
| 63 | else |
| 64 | writel(RK3328_IO_3V_DOMAIN, &grf->soc_con[4]); |
| 65 | } |
| 66 | |
| 67 | static const struct dw_hdmi_phy_ops dw_hdmi_rk3328_phy_ops = { |
| 68 | .phy_set = rk3328_dw_hdmi_phy_cfg, |
| 69 | .setup_hpd = rk3328_dw_hdmi_setup_hpd, |
| 70 | .read_hpd = rk3328_dw_hdmi_read_hpd, |
| 71 | }; |
| 72 | |
| 73 | static int rk3328_hdmi_of_to_plat(struct udevice *dev) |
| 74 | { |
| 75 | struct rk_hdmi_priv *priv = dev_get_priv(dev); |
| 76 | struct dw_hdmi *hdmi = &priv->hdmi; |
| 77 | |
| 78 | hdmi->i2c_clk_high = 0x71; |
| 79 | hdmi->i2c_clk_low = 0x76; |
| 80 | |
| 81 | rk_hdmi_of_to_plat(dev); |
| 82 | |
| 83 | hdmi->ops = &dw_hdmi_rk3328_phy_ops; |
| 84 | |
| 85 | return 0; |
| 86 | } |
| 87 | |
| 88 | static int rk3328_hdmi_probe(struct udevice *dev) |
| 89 | { |
| 90 | struct rk_hdmi_priv *priv = dev_get_priv(dev); |
| 91 | int ret; |
| 92 | |
| 93 | ret = generic_phy_get_by_name(dev, "hdmi", &priv->phy); |
| 94 | if (ret) { |
| 95 | printf("failed to get hdmi phy\n"); |
| 96 | return ret; |
| 97 | }; |
| 98 | |
| 99 | ret = rk_hdmi_probe(dev); |
| 100 | if (ret) { |
| 101 | printf("failed to probe rk hdmi\n"); |
| 102 | return ret; |
| 103 | } |
| 104 | |
| 105 | return 0; |
| 106 | } |
| 107 | |
| 108 | static const struct dm_display_ops rk3328_hdmi_ops = { |
| 109 | .read_edid = rk_hdmi_read_edid, |
| 110 | .enable = rk3328_hdmi_enable, |
| 111 | }; |
| 112 | |
| 113 | static const struct udevice_id rk3328_hdmi_ids[] = { |
| 114 | { .compatible = "rockchip,rk3328-dw-hdmi" }, |
| 115 | { } |
| 116 | }; |
| 117 | |
| 118 | U_BOOT_DRIVER(rk3328_hdmi_rockchip) = { |
| 119 | .name = "rk3328_hdmi_rockchip", |
| 120 | .id = UCLASS_DISPLAY, |
| 121 | .of_match = rk3328_hdmi_ids, |
| 122 | .ops = &rk3328_hdmi_ops, |
| 123 | .of_to_plat = rk3328_hdmi_of_to_plat, |
| 124 | .probe = rk3328_hdmi_probe, |
| 125 | .priv_auto = sizeof(struct rk_hdmi_priv), |
| 126 | }; |