Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Jernej Skrabec | 8d91b46 | 2017-03-27 19:22:32 +0200 | [diff] [blame] | 2 | /* |
| 3 | * Allwinner DW HDMI bridge |
| 4 | * |
| 5 | * (C) Copyright 2017 Jernej Skrabec <jernej.skrabec@siol.net> |
Jernej Skrabec | 8d91b46 | 2017-03-27 19:22:32 +0200 | [diff] [blame] | 6 | */ |
| 7 | |
Samuel Holland | 65bd46b | 2022-11-28 01:02:27 -0600 | [diff] [blame] | 8 | #include <clk.h> |
Jernej Skrabec | 8d91b46 | 2017-03-27 19:22:32 +0200 | [diff] [blame] | 9 | #include <display.h> |
| 10 | #include <dm.h> |
| 11 | #include <dw_hdmi.h> |
| 12 | #include <edid.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 13 | #include <log.h> |
Samuel Holland | 65bd46b | 2022-11-28 01:02:27 -0600 | [diff] [blame] | 14 | #include <reset.h> |
Simon Glass | 495a5dc | 2019-11-14 12:57:30 -0700 | [diff] [blame] | 15 | #include <time.h> |
Jernej Skrabec | 8d91b46 | 2017-03-27 19:22:32 +0200 | [diff] [blame] | 16 | #include <asm/io.h> |
| 17 | #include <asm/arch/clock.h> |
| 18 | #include <asm/arch/lcdc.h> |
Simon Glass | 4dcacfc | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 19 | #include <linux/bitops.h> |
Simon Glass | dbd7954 | 2020-05-10 11:40:11 -0600 | [diff] [blame] | 20 | #include <linux/delay.h> |
Samuel Holland | 56a730b | 2022-11-28 01:02:28 -0600 | [diff] [blame] | 21 | #include <power/regulator.h> |
Jernej Skrabec | 8d91b46 | 2017-03-27 19:22:32 +0200 | [diff] [blame] | 22 | |
| 23 | struct sunxi_dw_hdmi_priv { |
| 24 | struct dw_hdmi hdmi; |
Samuel Holland | 65bd46b | 2022-11-28 01:02:27 -0600 | [diff] [blame] | 25 | struct reset_ctl_bulk resets; |
| 26 | struct clk_bulk clocks; |
Samuel Holland | 56a730b | 2022-11-28 01:02:28 -0600 | [diff] [blame] | 27 | struct udevice *hvcc; |
Jernej Skrabec | 8d91b46 | 2017-03-27 19:22:32 +0200 | [diff] [blame] | 28 | }; |
| 29 | |
| 30 | struct sunxi_hdmi_phy { |
| 31 | u32 pol; |
| 32 | u32 res1[3]; |
| 33 | u32 read_en; |
| 34 | u32 unscramble; |
| 35 | u32 res2[2]; |
| 36 | u32 ctrl; |
| 37 | u32 unk1; |
| 38 | u32 unk2; |
| 39 | u32 pll; |
| 40 | u32 clk; |
| 41 | u32 unk3; |
| 42 | u32 status; |
| 43 | }; |
| 44 | |
| 45 | #define HDMI_PHY_OFFS 0x10000 |
| 46 | |
| 47 | static int sunxi_dw_hdmi_get_divider(uint clock) |
| 48 | { |
| 49 | /* |
| 50 | * Due to missing documentaion of HDMI PHY, we know correct |
| 51 | * settings only for following four PHY dividers. Select one |
| 52 | * based on clock speed. |
| 53 | */ |
| 54 | if (clock <= 27000000) |
| 55 | return 11; |
| 56 | else if (clock <= 74250000) |
| 57 | return 4; |
| 58 | else if (clock <= 148500000) |
| 59 | return 2; |
| 60 | else |
| 61 | return 1; |
| 62 | } |
| 63 | |
Jernej Skrabec | d04dbf7 | 2022-11-28 01:02:26 -0600 | [diff] [blame] | 64 | static void sunxi_dw_hdmi_phy_init(struct dw_hdmi *hdmi) |
Jernej Skrabec | 8d91b46 | 2017-03-27 19:22:32 +0200 | [diff] [blame] | 65 | { |
| 66 | struct sunxi_hdmi_phy * const phy = |
Jernej Skrabec | d04dbf7 | 2022-11-28 01:02:26 -0600 | [diff] [blame] | 67 | (struct sunxi_hdmi_phy *)(hdmi->ioaddr + HDMI_PHY_OFFS); |
Jernej Skrabec | 8d91b46 | 2017-03-27 19:22:32 +0200 | [diff] [blame] | 68 | unsigned long tmo; |
| 69 | u32 tmp; |
| 70 | |
| 71 | /* |
| 72 | * HDMI PHY settings are taken as-is from Allwinner BSP code. |
| 73 | * There is no documentation. |
| 74 | */ |
| 75 | writel(0, &phy->ctrl); |
| 76 | setbits_le32(&phy->ctrl, BIT(0)); |
| 77 | udelay(5); |
| 78 | setbits_le32(&phy->ctrl, BIT(16)); |
| 79 | setbits_le32(&phy->ctrl, BIT(1)); |
| 80 | udelay(10); |
| 81 | setbits_le32(&phy->ctrl, BIT(2)); |
| 82 | udelay(5); |
| 83 | setbits_le32(&phy->ctrl, BIT(3)); |
| 84 | udelay(40); |
| 85 | setbits_le32(&phy->ctrl, BIT(19)); |
| 86 | udelay(100); |
| 87 | setbits_le32(&phy->ctrl, BIT(18)); |
| 88 | setbits_le32(&phy->ctrl, 7 << 4); |
| 89 | |
| 90 | /* Note that Allwinner code doesn't fail in case of timeout */ |
| 91 | tmo = timer_get_us() + 2000; |
| 92 | while ((readl(&phy->status) & 0x80) == 0) { |
| 93 | if (timer_get_us() > tmo) { |
| 94 | printf("Warning: HDMI PHY init timeout!\n"); |
| 95 | break; |
| 96 | } |
| 97 | } |
| 98 | |
| 99 | setbits_le32(&phy->ctrl, 0xf << 8); |
| 100 | setbits_le32(&phy->ctrl, BIT(7)); |
| 101 | |
| 102 | writel(0x39dc5040, &phy->pll); |
| 103 | writel(0x80084343, &phy->clk); |
| 104 | udelay(10000); |
| 105 | writel(1, &phy->unk3); |
| 106 | setbits_le32(&phy->pll, BIT(25)); |
| 107 | udelay(100000); |
| 108 | tmp = (readl(&phy->status) & 0x1f800) >> 11; |
| 109 | setbits_le32(&phy->pll, BIT(31) | BIT(30)); |
| 110 | setbits_le32(&phy->pll, tmp); |
| 111 | writel(0x01FF0F7F, &phy->ctrl); |
| 112 | writel(0x80639000, &phy->unk1); |
| 113 | writel(0x0F81C405, &phy->unk2); |
| 114 | |
| 115 | /* enable read access to HDMI controller */ |
| 116 | writel(0x54524545, &phy->read_en); |
| 117 | /* descramble register offsets */ |
| 118 | writel(0x42494E47, &phy->unscramble); |
| 119 | } |
| 120 | |
Jernej Skrabec | d04dbf7 | 2022-11-28 01:02:26 -0600 | [diff] [blame] | 121 | static void sunxi_dw_hdmi_phy_set(struct dw_hdmi *hdmi, uint clock, int phy_div) |
Jernej Skrabec | 8d91b46 | 2017-03-27 19:22:32 +0200 | [diff] [blame] | 122 | { |
| 123 | struct sunxi_hdmi_phy * const phy = |
Jernej Skrabec | d04dbf7 | 2022-11-28 01:02:26 -0600 | [diff] [blame] | 124 | (struct sunxi_hdmi_phy *)(hdmi->ioaddr + HDMI_PHY_OFFS); |
Jernej Skrabec | 8d91b46 | 2017-03-27 19:22:32 +0200 | [diff] [blame] | 125 | int div = sunxi_dw_hdmi_get_divider(clock); |
| 126 | u32 tmp; |
| 127 | |
| 128 | /* |
| 129 | * Unfortunately, we don't know much about those magic |
| 130 | * numbers. They are taken from Allwinner BSP driver. |
| 131 | */ |
| 132 | switch (div) { |
| 133 | case 1: |
| 134 | writel(0x30dc5fc0, &phy->pll); |
Jernej Skrabec | 89d1802 | 2019-03-24 19:26:40 +0100 | [diff] [blame] | 135 | writel(0x800863C0 | (phy_div - 1), &phy->clk); |
Jernej Skrabec | 8d91b46 | 2017-03-27 19:22:32 +0200 | [diff] [blame] | 136 | mdelay(10); |
| 137 | writel(0x00000001, &phy->unk3); |
| 138 | setbits_le32(&phy->pll, BIT(25)); |
| 139 | mdelay(200); |
| 140 | tmp = (readl(&phy->status) & 0x1f800) >> 11; |
| 141 | setbits_le32(&phy->pll, BIT(31) | BIT(30)); |
| 142 | if (tmp < 0x3d) |
| 143 | setbits_le32(&phy->pll, tmp + 2); |
| 144 | else |
| 145 | setbits_le32(&phy->pll, 0x3f); |
| 146 | mdelay(100); |
| 147 | writel(0x01FFFF7F, &phy->ctrl); |
| 148 | writel(0x8063b000, &phy->unk1); |
| 149 | writel(0x0F8246B5, &phy->unk2); |
| 150 | break; |
| 151 | case 2: |
| 152 | writel(0x39dc5040, &phy->pll); |
Jernej Skrabec | 89d1802 | 2019-03-24 19:26:40 +0100 | [diff] [blame] | 153 | writel(0x80084380 | (phy_div - 1), &phy->clk); |
Jernej Skrabec | 8d91b46 | 2017-03-27 19:22:32 +0200 | [diff] [blame] | 154 | mdelay(10); |
| 155 | writel(0x00000001, &phy->unk3); |
| 156 | setbits_le32(&phy->pll, BIT(25)); |
| 157 | mdelay(100); |
| 158 | tmp = (readl(&phy->status) & 0x1f800) >> 11; |
| 159 | setbits_le32(&phy->pll, BIT(31) | BIT(30)); |
| 160 | setbits_le32(&phy->pll, tmp); |
| 161 | writel(0x01FFFF7F, &phy->ctrl); |
| 162 | writel(0x8063a800, &phy->unk1); |
| 163 | writel(0x0F81C485, &phy->unk2); |
| 164 | break; |
| 165 | case 4: |
| 166 | writel(0x39dc5040, &phy->pll); |
Jernej Skrabec | 89d1802 | 2019-03-24 19:26:40 +0100 | [diff] [blame] | 167 | writel(0x80084340 | (phy_div - 1), &phy->clk); |
Jernej Skrabec | 8d91b46 | 2017-03-27 19:22:32 +0200 | [diff] [blame] | 168 | mdelay(10); |
| 169 | writel(0x00000001, &phy->unk3); |
| 170 | setbits_le32(&phy->pll, BIT(25)); |
| 171 | mdelay(100); |
| 172 | tmp = (readl(&phy->status) & 0x1f800) >> 11; |
| 173 | setbits_le32(&phy->pll, BIT(31) | BIT(30)); |
| 174 | setbits_le32(&phy->pll, tmp); |
| 175 | writel(0x01FFFF7F, &phy->ctrl); |
| 176 | writel(0x8063b000, &phy->unk1); |
| 177 | writel(0x0F81C405, &phy->unk2); |
| 178 | break; |
| 179 | case 11: |
| 180 | writel(0x39dc5040, &phy->pll); |
Jernej Skrabec | 89d1802 | 2019-03-24 19:26:40 +0100 | [diff] [blame] | 181 | writel(0x80084300 | (phy_div - 1), &phy->clk); |
Jernej Skrabec | 8d91b46 | 2017-03-27 19:22:32 +0200 | [diff] [blame] | 182 | mdelay(10); |
| 183 | writel(0x00000001, &phy->unk3); |
| 184 | setbits_le32(&phy->pll, BIT(25)); |
| 185 | mdelay(100); |
| 186 | tmp = (readl(&phy->status) & 0x1f800) >> 11; |
| 187 | setbits_le32(&phy->pll, BIT(31) | BIT(30)); |
| 188 | setbits_le32(&phy->pll, tmp); |
| 189 | writel(0x01FFFF7F, &phy->ctrl); |
| 190 | writel(0x8063b000, &phy->unk1); |
| 191 | writel(0x0F81C405, &phy->unk2); |
| 192 | break; |
| 193 | } |
| 194 | } |
| 195 | |
Jernej Skrabec | 89d1802 | 2019-03-24 19:26:40 +0100 | [diff] [blame] | 196 | static void sunxi_dw_hdmi_pll_set(uint clk_khz, int *phy_div) |
Jernej Skrabec | 8d91b46 | 2017-03-27 19:22:32 +0200 | [diff] [blame] | 197 | { |
Jernej Skrabec | 89d1802 | 2019-03-24 19:26:40 +0100 | [diff] [blame] | 198 | int value, n, m, div, diff; |
| 199 | int best_n = 0, best_m = 0, best_div = 0, best_diff = 0x0FFFFFFF; |
Jernej Skrabec | 8d91b46 | 2017-03-27 19:22:32 +0200 | [diff] [blame] | 200 | |
| 201 | /* |
| 202 | * Find the lowest divider resulting in a matching clock. If there |
| 203 | * is no match, pick the closest lower clock, as monitors tend to |
| 204 | * not sync to higher frequencies. |
| 205 | */ |
Jernej Skrabec | 89d1802 | 2019-03-24 19:26:40 +0100 | [diff] [blame] | 206 | for (div = 1; div <= 16; div++) { |
| 207 | int target = clk_khz * div; |
| 208 | |
| 209 | if (target < 192000) |
| 210 | continue; |
| 211 | if (target > 912000) |
| 212 | continue; |
Jernej Skrabec | 8d91b46 | 2017-03-27 19:22:32 +0200 | [diff] [blame] | 213 | |
Jernej Skrabec | 89d1802 | 2019-03-24 19:26:40 +0100 | [diff] [blame] | 214 | for (m = 1; m <= 16; m++) { |
| 215 | n = (m * target) / 24000; |
| 216 | |
| 217 | if (n >= 1 && n <= 128) { |
| 218 | value = (24000 * n) / m / div; |
| 219 | diff = clk_khz - value; |
| 220 | if (diff < best_diff) { |
| 221 | best_diff = diff; |
| 222 | best_m = m; |
| 223 | best_n = n; |
| 224 | best_div = div; |
| 225 | } |
Jernej Skrabec | 8d91b46 | 2017-03-27 19:22:32 +0200 | [diff] [blame] | 226 | } |
| 227 | } |
| 228 | } |
| 229 | |
Jernej Skrabec | 89d1802 | 2019-03-24 19:26:40 +0100 | [diff] [blame] | 230 | *phy_div = best_div; |
| 231 | |
Jernej Skrabec | 8d91b46 | 2017-03-27 19:22:32 +0200 | [diff] [blame] | 232 | clock_set_pll3_factors(best_m, best_n); |
| 233 | debug("dotclock: %dkHz = %dkHz: (24MHz * %d) / %d / %d\n", |
Jernej Skrabec | 89d1802 | 2019-03-24 19:26:40 +0100 | [diff] [blame] | 234 | clk_khz, (clock_get_pll3() / 1000) / best_div, |
| 235 | best_n, best_m, best_div); |
Jernej Skrabec | 8d91b46 | 2017-03-27 19:22:32 +0200 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | static void sunxi_dw_hdmi_lcdc_init(int mux, const struct display_timing *edid, |
| 239 | int bpp) |
| 240 | { |
| 241 | struct sunxi_ccm_reg * const ccm = |
| 242 | (struct sunxi_ccm_reg *)SUNXI_CCM_BASE; |
Mark Kettenis | 898c609 | 2019-08-09 22:30:26 +0200 | [diff] [blame] | 243 | int div = DIV_ROUND_UP(clock_get_pll3(), edid->pixelclock.typ); |
Jernej Skrabec | 8d91b46 | 2017-03-27 19:22:32 +0200 | [diff] [blame] | 244 | struct sunxi_lcdc_reg *lcdc; |
| 245 | |
| 246 | if (mux == 0) { |
| 247 | lcdc = (struct sunxi_lcdc_reg *)SUNXI_LCD0_BASE; |
| 248 | |
| 249 | /* Reset off */ |
| 250 | setbits_le32(&ccm->ahb_reset1_cfg, 1 << AHB_RESET_OFFSET_LCD0); |
| 251 | |
| 252 | /* Clock on */ |
| 253 | setbits_le32(&ccm->ahb_gate1, 1 << AHB_GATE_OFFSET_LCD0); |
| 254 | writel(CCM_LCD0_CTRL_GATE | CCM_LCD0_CTRL_M(div), |
| 255 | &ccm->lcd0_clk_cfg); |
| 256 | } else { |
| 257 | lcdc = (struct sunxi_lcdc_reg *)SUNXI_LCD1_BASE; |
| 258 | |
| 259 | /* Reset off */ |
| 260 | setbits_le32(&ccm->ahb_reset1_cfg, 1 << AHB_RESET_OFFSET_LCD1); |
| 261 | |
| 262 | /* Clock on */ |
| 263 | setbits_le32(&ccm->ahb_gate1, 1 << AHB_GATE_OFFSET_LCD1); |
| 264 | writel(CCM_LCD1_CTRL_GATE | CCM_LCD1_CTRL_M(div), |
| 265 | &ccm->lcd1_clk_cfg); |
| 266 | } |
| 267 | |
| 268 | lcdc_init(lcdc); |
| 269 | lcdc_tcon1_mode_set(lcdc, edid, false, false); |
| 270 | lcdc_enable(lcdc, bpp); |
| 271 | } |
| 272 | |
| 273 | static int sunxi_dw_hdmi_phy_cfg(struct dw_hdmi *hdmi, uint mpixelclock) |
| 274 | { |
Jernej Skrabec | 89d1802 | 2019-03-24 19:26:40 +0100 | [diff] [blame] | 275 | int phy_div; |
| 276 | |
| 277 | sunxi_dw_hdmi_pll_set(mpixelclock / 1000, &phy_div); |
Jernej Skrabec | d04dbf7 | 2022-11-28 01:02:26 -0600 | [diff] [blame] | 278 | sunxi_dw_hdmi_phy_set(hdmi, mpixelclock, phy_div); |
Jernej Skrabec | 8d91b46 | 2017-03-27 19:22:32 +0200 | [diff] [blame] | 279 | |
| 280 | return 0; |
| 281 | } |
| 282 | |
| 283 | static int sunxi_dw_hdmi_read_edid(struct udevice *dev, u8 *buf, int buf_size) |
| 284 | { |
| 285 | struct sunxi_dw_hdmi_priv *priv = dev_get_priv(dev); |
| 286 | |
| 287 | return dw_hdmi_read_edid(&priv->hdmi, buf, buf_size); |
| 288 | } |
| 289 | |
Jernej Skrabec | 5b2b0a7 | 2021-04-22 01:14:26 +0100 | [diff] [blame] | 290 | static bool sunxi_dw_hdmi_mode_valid(struct udevice *dev, |
| 291 | const struct display_timing *timing) |
| 292 | { |
| 293 | return timing->pixelclock.typ <= 297000000; |
| 294 | } |
| 295 | |
Jernej Skrabec | 8d91b46 | 2017-03-27 19:22:32 +0200 | [diff] [blame] | 296 | static int sunxi_dw_hdmi_enable(struct udevice *dev, int panel_bpp, |
| 297 | const struct display_timing *edid) |
| 298 | { |
Jernej Skrabec | d04dbf7 | 2022-11-28 01:02:26 -0600 | [diff] [blame] | 299 | struct sunxi_dw_hdmi_priv *priv = dev_get_priv(dev); |
Jernej Skrabec | 8d91b46 | 2017-03-27 19:22:32 +0200 | [diff] [blame] | 300 | struct sunxi_hdmi_phy * const phy = |
Jernej Skrabec | d04dbf7 | 2022-11-28 01:02:26 -0600 | [diff] [blame] | 301 | (struct sunxi_hdmi_phy *)(priv->hdmi.ioaddr + HDMI_PHY_OFFS); |
Jernej Skrabec | 5dd59e5 | 2021-04-22 01:14:33 +0100 | [diff] [blame] | 302 | struct display_plat *uc_plat = dev_get_uclass_plat(dev); |
Jernej Skrabec | 8d91b46 | 2017-03-27 19:22:32 +0200 | [diff] [blame] | 303 | int ret; |
| 304 | |
| 305 | ret = dw_hdmi_enable(&priv->hdmi, edid); |
| 306 | if (ret) |
| 307 | return ret; |
| 308 | |
Jernej Skrabec | 5dd59e5 | 2021-04-22 01:14:33 +0100 | [diff] [blame] | 309 | sunxi_dw_hdmi_lcdc_init(uc_plat->source_id, edid, panel_bpp); |
Jernej Skrabec | 8d91b46 | 2017-03-27 19:22:32 +0200 | [diff] [blame] | 310 | |
Vasily Khoruzhick | efce412 | 2018-05-14 13:49:52 -0700 | [diff] [blame] | 311 | if (edid->flags & DISPLAY_FLAGS_VSYNC_LOW) |
Vasily Khoruzhick | 97d1967 | 2017-11-28 22:33:27 -0800 | [diff] [blame] | 312 | setbits_le32(&phy->pol, 0x200); |
| 313 | |
Vasily Khoruzhick | efce412 | 2018-05-14 13:49:52 -0700 | [diff] [blame] | 314 | if (edid->flags & DISPLAY_FLAGS_HSYNC_LOW) |
Vasily Khoruzhick | 97d1967 | 2017-11-28 22:33:27 -0800 | [diff] [blame] | 315 | setbits_le32(&phy->pol, 0x100); |
Jernej Skrabec | 8d91b46 | 2017-03-27 19:22:32 +0200 | [diff] [blame] | 316 | |
| 317 | setbits_le32(&phy->ctrl, 0xf << 12); |
| 318 | |
| 319 | /* |
| 320 | * This is last hdmi access before boot, so scramble addresses |
| 321 | * again or othwerwise BSP driver won't work. Dummy read is |
| 322 | * needed or otherwise last write doesn't get written correctly. |
| 323 | */ |
Jernej Skrabec | d04dbf7 | 2022-11-28 01:02:26 -0600 | [diff] [blame] | 324 | (void)readb(priv->hdmi.ioaddr); |
Jernej Skrabec | 8d91b46 | 2017-03-27 19:22:32 +0200 | [diff] [blame] | 325 | writel(0, &phy->unscramble); |
| 326 | |
| 327 | return 0; |
| 328 | } |
| 329 | |
| 330 | static int sunxi_dw_hdmi_probe(struct udevice *dev) |
| 331 | { |
Jernej Skrabec | 8d91b46 | 2017-03-27 19:22:32 +0200 | [diff] [blame] | 332 | struct sunxi_dw_hdmi_priv *priv = dev_get_priv(dev); |
| 333 | struct sunxi_ccm_reg * const ccm = |
| 334 | (struct sunxi_ccm_reg *)SUNXI_CCM_BASE; |
| 335 | int ret; |
| 336 | |
Samuel Holland | 56a730b | 2022-11-28 01:02:28 -0600 | [diff] [blame] | 337 | if (priv->hvcc) |
| 338 | regulator_set_enable(priv->hvcc, true); |
| 339 | |
Jernej Skrabec | 8d91b46 | 2017-03-27 19:22:32 +0200 | [diff] [blame] | 340 | /* Set pll3 to 297 MHz */ |
| 341 | clock_set_pll3(297000000); |
| 342 | |
| 343 | /* Set hdmi parent to pll3 */ |
| 344 | clrsetbits_le32(&ccm->hdmi_clk_cfg, CCM_HDMI_CTRL_PLL_MASK, |
| 345 | CCM_HDMI_CTRL_PLL3); |
| 346 | |
Samuel Holland | 65bd46b | 2022-11-28 01:02:27 -0600 | [diff] [blame] | 347 | /* This reset is referenced from the PHY devicetree node. */ |
Jernej Skrabec | 8d91b46 | 2017-03-27 19:22:32 +0200 | [diff] [blame] | 348 | setbits_le32(&ccm->ahb_reset1_cfg, 1 << AHB_RESET_OFFSET_HDMI2); |
Jernej Skrabec | 8d91b46 | 2017-03-27 19:22:32 +0200 | [diff] [blame] | 349 | |
Samuel Holland | 65bd46b | 2022-11-28 01:02:27 -0600 | [diff] [blame] | 350 | ret = reset_deassert_bulk(&priv->resets); |
| 351 | if (ret) |
| 352 | return ret; |
| 353 | |
| 354 | ret = clk_enable_bulk(&priv->clocks); |
| 355 | if (ret) |
| 356 | return ret; |
Jernej Skrabec | 8d91b46 | 2017-03-27 19:22:32 +0200 | [diff] [blame] | 357 | |
Jernej Skrabec | d04dbf7 | 2022-11-28 01:02:26 -0600 | [diff] [blame] | 358 | sunxi_dw_hdmi_phy_init(&priv->hdmi); |
Jernej Skrabec | 8d91b46 | 2017-03-27 19:22:32 +0200 | [diff] [blame] | 359 | |
Jagan Teki | 17d0f55 | 2024-01-17 13:21:40 +0530 | [diff] [blame] | 360 | ret = dw_hdmi_detect_hpd(&priv->hdmi); |
| 361 | if (ret < 0) |
| 362 | return ret; |
Jernej Skrabec | 1cf6619 | 2021-04-22 01:14:30 +0100 | [diff] [blame] | 363 | |
Jernej Skrabec | 8d91b46 | 2017-03-27 19:22:32 +0200 | [diff] [blame] | 364 | dw_hdmi_init(&priv->hdmi); |
| 365 | |
| 366 | return 0; |
| 367 | } |
| 368 | |
Jagan Teki | b3c66b6 | 2024-01-17 13:21:39 +0530 | [diff] [blame] | 369 | static const struct dw_hdmi_phy_ops dw_hdmi_sunxi_phy_ops = { |
| 370 | .phy_set = sunxi_dw_hdmi_phy_cfg, |
| 371 | }; |
| 372 | |
Jernej Skrabec | d04dbf7 | 2022-11-28 01:02:26 -0600 | [diff] [blame] | 373 | static int sunxi_dw_hdmi_of_to_plat(struct udevice *dev) |
| 374 | { |
| 375 | struct sunxi_dw_hdmi_priv *priv = dev_get_priv(dev); |
| 376 | struct dw_hdmi *hdmi = &priv->hdmi; |
Samuel Holland | 65bd46b | 2022-11-28 01:02:27 -0600 | [diff] [blame] | 377 | int ret; |
Jernej Skrabec | d04dbf7 | 2022-11-28 01:02:26 -0600 | [diff] [blame] | 378 | |
| 379 | hdmi->ioaddr = (ulong)dev_read_addr(dev); |
| 380 | hdmi->i2c_clk_high = 0xd8; |
| 381 | hdmi->i2c_clk_low = 0xfe; |
| 382 | hdmi->reg_io_width = 1; |
Jagan Teki | b3c66b6 | 2024-01-17 13:21:39 +0530 | [diff] [blame] | 383 | hdmi->ops = &dw_hdmi_sunxi_phy_ops; |
Jernej Skrabec | d04dbf7 | 2022-11-28 01:02:26 -0600 | [diff] [blame] | 384 | |
Samuel Holland | 65bd46b | 2022-11-28 01:02:27 -0600 | [diff] [blame] | 385 | ret = reset_get_bulk(dev, &priv->resets); |
| 386 | if (ret) |
| 387 | return ret; |
| 388 | |
| 389 | ret = clk_get_bulk(dev, &priv->clocks); |
| 390 | if (ret) |
| 391 | return ret; |
| 392 | |
Samuel Holland | 56a730b | 2022-11-28 01:02:28 -0600 | [diff] [blame] | 393 | ret = device_get_supply_regulator(dev, "hvcc-supply", &priv->hvcc); |
| 394 | if (ret) |
| 395 | priv->hvcc = NULL; |
| 396 | |
Jernej Skrabec | d04dbf7 | 2022-11-28 01:02:26 -0600 | [diff] [blame] | 397 | return 0; |
| 398 | } |
| 399 | |
Jernej Skrabec | 8d91b46 | 2017-03-27 19:22:32 +0200 | [diff] [blame] | 400 | static const struct dm_display_ops sunxi_dw_hdmi_ops = { |
| 401 | .read_edid = sunxi_dw_hdmi_read_edid, |
| 402 | .enable = sunxi_dw_hdmi_enable, |
Jernej Skrabec | 5b2b0a7 | 2021-04-22 01:14:26 +0100 | [diff] [blame] | 403 | .mode_valid = sunxi_dw_hdmi_mode_valid, |
Jernej Skrabec | 8d91b46 | 2017-03-27 19:22:32 +0200 | [diff] [blame] | 404 | }; |
| 405 | |
Jernej Skrabec | 97d10d4 | 2022-11-28 01:02:25 -0600 | [diff] [blame] | 406 | static const struct udevice_id sunxi_dw_hdmi_ids[] = { |
| 407 | { .compatible = "allwinner,sun8i-a83t-dw-hdmi" }, |
| 408 | { } |
Jernej Skrabec | 8d91b46 | 2017-03-27 19:22:32 +0200 | [diff] [blame] | 409 | }; |
| 410 | |
Jernej Skrabec | 97d10d4 | 2022-11-28 01:02:25 -0600 | [diff] [blame] | 411 | U_BOOT_DRIVER(sunxi_dw_hdmi) = { |
| 412 | .name = "sunxi_dw_hdmi", |
| 413 | .id = UCLASS_DISPLAY, |
| 414 | .of_match = sunxi_dw_hdmi_ids, |
| 415 | .probe = sunxi_dw_hdmi_probe, |
Jernej Skrabec | d04dbf7 | 2022-11-28 01:02:26 -0600 | [diff] [blame] | 416 | .of_to_plat = sunxi_dw_hdmi_of_to_plat, |
Jernej Skrabec | 97d10d4 | 2022-11-28 01:02:25 -0600 | [diff] [blame] | 417 | .priv_auto = sizeof(struct sunxi_dw_hdmi_priv), |
| 418 | .ops = &sunxi_dw_hdmi_ops, |
Jernej Skrabec | 8d91b46 | 2017-03-27 19:22:32 +0200 | [diff] [blame] | 419 | }; |