Neil Armstrong | add986c | 2018-07-24 17:45:28 +0200 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
| 2 | /* |
| 3 | * Copyright (C) 2018 BayLibre, SAS |
| 4 | * Author: Jorge Ramirez-Ortiz <jramirez@baylibre.com> |
| 5 | */ |
| 6 | |
| 7 | #include <common.h> |
| 8 | #include <display.h> |
| 9 | #include <dm.h> |
| 10 | #include <edid.h> |
Simon Glass | 0f2af88 | 2020-05-10 11:40:05 -0600 | [diff] [blame] | 11 | #include <log.h> |
Neil Armstrong | add986c | 2018-07-24 17:45:28 +0200 | [diff] [blame] | 12 | #include <asm/io.h> |
| 13 | #include <dw_hdmi.h> |
| 14 | #include <dm/device-internal.h> |
| 15 | #include <dm/uclass-internal.h> |
Simon Glass | 4dcacfc | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 16 | #include <linux/bitops.h> |
Simon Glass | bdd5f81 | 2023-09-14 18:21:46 -0600 | [diff] [blame] | 17 | #include <linux/printk.h> |
Neil Armstrong | add986c | 2018-07-24 17:45:28 +0200 | [diff] [blame] | 18 | #include <power/regulator.h> |
| 19 | #include <clk.h> |
| 20 | #include <linux/delay.h> |
| 21 | #include <reset.h> |
| 22 | #include <media_bus_format.h> |
| 23 | #include "meson_dw_hdmi.h" |
| 24 | #include "meson_vpu.h" |
| 25 | |
| 26 | /* TOP Block Communication Channel */ |
| 27 | #define HDMITX_TOP_ADDR_REG 0x0 |
| 28 | #define HDMITX_TOP_DATA_REG 0x4 |
| 29 | #define HDMITX_TOP_CTRL_REG 0x8 |
Neil Armstrong | 57d6dfe | 2019-08-30 14:09:24 +0200 | [diff] [blame] | 30 | #define HDMITX_TOP_G12A_OFFSET 0x8000 |
Neil Armstrong | add986c | 2018-07-24 17:45:28 +0200 | [diff] [blame] | 31 | |
| 32 | /* Controller Communication Channel */ |
| 33 | #define HDMITX_DWC_ADDR_REG 0x10 |
| 34 | #define HDMITX_DWC_DATA_REG 0x14 |
| 35 | #define HDMITX_DWC_CTRL_REG 0x18 |
| 36 | |
| 37 | /* HHI Registers */ |
| 38 | #define HHI_MEM_PD_REG0 0x100 /* 0x40 */ |
| 39 | #define HHI_HDMI_CLK_CNTL 0x1cc /* 0x73 */ |
| 40 | #define HHI_HDMI_PHY_CNTL0 0x3a0 /* 0xe8 */ |
| 41 | #define HHI_HDMI_PHY_CNTL1 0x3a4 /* 0xe9 */ |
| 42 | #define HHI_HDMI_PHY_CNTL2 0x3a8 /* 0xea */ |
| 43 | #define HHI_HDMI_PHY_CNTL3 0x3ac /* 0xeb */ |
Neil Armstrong | 57d6dfe | 2019-08-30 14:09:24 +0200 | [diff] [blame] | 44 | #define HHI_HDMI_PHY_CNTL4 0x3b0 /* 0xec */ |
| 45 | #define HHI_HDMI_PHY_CNTL5 0x3b4 /* 0xed */ |
Neil Armstrong | add986c | 2018-07-24 17:45:28 +0200 | [diff] [blame] | 46 | |
| 47 | struct meson_dw_hdmi { |
| 48 | struct udevice *dev; |
| 49 | struct dw_hdmi hdmi; |
| 50 | void __iomem *hhi_base; |
| 51 | }; |
| 52 | |
| 53 | enum hdmi_compatible { |
| 54 | HDMI_COMPATIBLE_GXBB = 0, |
| 55 | HDMI_COMPATIBLE_GXL = 1, |
| 56 | HDMI_COMPATIBLE_GXM = 2, |
Neil Armstrong | 57d6dfe | 2019-08-30 14:09:24 +0200 | [diff] [blame] | 57 | HDMI_COMPATIBLE_G12A = 3, |
Neil Armstrong | add986c | 2018-07-24 17:45:28 +0200 | [diff] [blame] | 58 | }; |
| 59 | |
| 60 | static inline bool meson_hdmi_is_compatible(struct meson_dw_hdmi *priv, |
| 61 | enum hdmi_compatible family) |
| 62 | { |
| 63 | enum hdmi_compatible compat = dev_get_driver_data(priv->dev); |
| 64 | |
| 65 | return compat == family; |
| 66 | } |
| 67 | |
| 68 | static unsigned int dw_hdmi_top_read(struct dw_hdmi *hdmi, unsigned int addr) |
| 69 | { |
Neil Armstrong | 57d6dfe | 2019-08-30 14:09:24 +0200 | [diff] [blame] | 70 | struct meson_dw_hdmi *priv = container_of(hdmi, struct meson_dw_hdmi, |
| 71 | hdmi); |
Neil Armstrong | add986c | 2018-07-24 17:45:28 +0200 | [diff] [blame] | 72 | unsigned int data; |
| 73 | |
Neil Armstrong | 57d6dfe | 2019-08-30 14:09:24 +0200 | [diff] [blame] | 74 | if (meson_hdmi_is_compatible(priv, HDMI_COMPATIBLE_G12A)) |
| 75 | return readl(hdmi->ioaddr + |
| 76 | HDMITX_TOP_G12A_OFFSET + (addr << 2)); |
| 77 | |
Neil Armstrong | add986c | 2018-07-24 17:45:28 +0200 | [diff] [blame] | 78 | /* ADDR must be written twice */ |
| 79 | writel(addr & 0xffff, hdmi->ioaddr + HDMITX_TOP_ADDR_REG); |
| 80 | writel(addr & 0xffff, hdmi->ioaddr + HDMITX_TOP_ADDR_REG); |
| 81 | |
| 82 | /* Read needs a second DATA read */ |
| 83 | data = readl(hdmi->ioaddr + HDMITX_TOP_DATA_REG); |
| 84 | data = readl(hdmi->ioaddr + HDMITX_TOP_DATA_REG); |
| 85 | |
| 86 | return data; |
| 87 | } |
| 88 | |
| 89 | static inline void dw_hdmi_top_write(struct dw_hdmi *hdmi, |
| 90 | unsigned int addr, unsigned int data) |
| 91 | { |
Neil Armstrong | 57d6dfe | 2019-08-30 14:09:24 +0200 | [diff] [blame] | 92 | struct meson_dw_hdmi *priv = container_of(hdmi, struct meson_dw_hdmi, |
| 93 | hdmi); |
| 94 | |
| 95 | if (meson_hdmi_is_compatible(priv, HDMI_COMPATIBLE_G12A)) { |
| 96 | writel(data, hdmi->ioaddr + |
| 97 | HDMITX_TOP_G12A_OFFSET + (addr << 2)); |
| 98 | return; |
| 99 | } |
| 100 | |
Neil Armstrong | add986c | 2018-07-24 17:45:28 +0200 | [diff] [blame] | 101 | /* ADDR must be written twice */ |
| 102 | writel(addr & 0xffff, hdmi->ioaddr + HDMITX_TOP_ADDR_REG); |
| 103 | writel(addr & 0xffff, hdmi->ioaddr + HDMITX_TOP_ADDR_REG); |
| 104 | |
| 105 | /* Write needs single DATA write */ |
| 106 | writel(data, hdmi->ioaddr + HDMITX_TOP_DATA_REG); |
| 107 | } |
| 108 | |
| 109 | static inline void dw_hdmi_top_write_bits(struct dw_hdmi *hdmi, |
| 110 | unsigned int addr, |
| 111 | unsigned int mask, |
| 112 | unsigned int val) |
| 113 | { |
| 114 | unsigned int data = dw_hdmi_top_read(hdmi, addr); |
| 115 | |
| 116 | data &= ~mask; |
| 117 | data |= val; |
| 118 | dw_hdmi_top_write(hdmi, addr, data); |
| 119 | } |
| 120 | |
| 121 | static u8 dw_hdmi_dwc_read(struct dw_hdmi *hdmi, int addr) |
| 122 | { |
| 123 | unsigned int data; |
| 124 | |
| 125 | /* ADDR must be written twice */ |
| 126 | writel(addr & 0xffff, hdmi->ioaddr + HDMITX_DWC_ADDR_REG); |
| 127 | writel(addr & 0xffff, hdmi->ioaddr + HDMITX_DWC_ADDR_REG); |
| 128 | |
| 129 | /* Read needs a second DATA read */ |
| 130 | data = readl(hdmi->ioaddr + HDMITX_DWC_DATA_REG); |
| 131 | data = readl(hdmi->ioaddr + HDMITX_DWC_DATA_REG); |
| 132 | |
| 133 | return data; |
| 134 | } |
| 135 | |
| 136 | static inline void dw_hdmi_dwc_write(struct dw_hdmi *hdmi, u8 data, int addr) |
| 137 | { |
| 138 | /* ADDR must be written twice */ |
| 139 | writel(addr & 0xffff, hdmi->ioaddr + HDMITX_DWC_ADDR_REG); |
| 140 | writel(addr & 0xffff, hdmi->ioaddr + HDMITX_DWC_ADDR_REG); |
| 141 | |
| 142 | /* Write needs single DATA write */ |
| 143 | writel(data, hdmi->ioaddr + HDMITX_DWC_DATA_REG); |
| 144 | } |
| 145 | |
| 146 | static inline void dw_hdmi_dwc_write_bits(struct dw_hdmi *hdmi, |
| 147 | unsigned int addr, |
| 148 | unsigned int mask, |
| 149 | unsigned int val) |
| 150 | { |
| 151 | u8 data = dw_hdmi_dwc_read(hdmi, addr); |
| 152 | |
| 153 | data &= ~mask; |
| 154 | data |= val; |
| 155 | |
| 156 | dw_hdmi_dwc_write(hdmi, data, addr); |
| 157 | } |
| 158 | |
| 159 | static inline void dw_hdmi_hhi_write(struct meson_dw_hdmi *priv, |
| 160 | unsigned int addr, unsigned int data) |
| 161 | { |
| 162 | hhi_write(addr, data); |
| 163 | } |
| 164 | |
| 165 | __attribute__((unused)) |
| 166 | static unsigned int dw_hdmi_hhi_read(struct meson_dw_hdmi *priv, |
| 167 | unsigned int addr) |
| 168 | { |
| 169 | return hhi_read(addr); |
| 170 | } |
| 171 | |
| 172 | static inline void dw_hdmi_hhi_update_bits(struct meson_dw_hdmi *priv, |
| 173 | unsigned int addr, |
| 174 | unsigned int mask, |
| 175 | unsigned int val) |
| 176 | { |
| 177 | hhi_update_bits(addr, mask, val); |
| 178 | } |
| 179 | |
| 180 | static int meson_dw_hdmi_read_edid(struct udevice *dev, u8 *buf, int buf_size) |
| 181 | { |
| 182 | #if defined DEBUG |
| 183 | struct display_timing timing; |
| 184 | int panel_bits_per_colour; |
| 185 | #endif |
| 186 | struct meson_dw_hdmi *priv = dev_get_priv(dev); |
| 187 | int ret; |
| 188 | |
| 189 | ret = dw_hdmi_read_edid(&priv->hdmi, buf, buf_size); |
| 190 | |
| 191 | #if defined DEBUG |
| 192 | if (!ret) |
| 193 | return ret; |
| 194 | |
| 195 | edid_print_info((struct edid1_info *)buf); |
| 196 | edid_get_timing(buf, ret, &timing, &panel_bits_per_colour); |
| 197 | debug("Display timing:\n"); |
| 198 | debug(" hactive %04d, hfrontp %04d, hbackp %04d hsync %04d\n" |
| 199 | " vactive %04d, vfrontp %04d, vbackp %04d vsync %04d\n", |
| 200 | timing.hactive.typ, timing.hfront_porch.typ, |
| 201 | timing.hback_porch.typ, timing.hsync_len.typ, |
| 202 | timing.vactive.typ, timing.vfront_porch.typ, |
| 203 | timing.vback_porch.typ, timing.vsync_len.typ); |
| 204 | debug(" flags: "); |
| 205 | if (timing.flags & DISPLAY_FLAGS_INTERLACED) |
| 206 | debug("interlaced "); |
| 207 | if (timing.flags & DISPLAY_FLAGS_DOUBLESCAN) |
| 208 | debug("doublescan "); |
| 209 | if (timing.flags & DISPLAY_FLAGS_DOUBLECLK) |
| 210 | debug("doubleclk "); |
| 211 | if (timing.flags & DISPLAY_FLAGS_HSYNC_LOW) |
| 212 | debug("hsync_low "); |
| 213 | if (timing.flags & DISPLAY_FLAGS_HSYNC_HIGH) |
| 214 | debug("hsync_high "); |
| 215 | if (timing.flags & DISPLAY_FLAGS_VSYNC_LOW) |
| 216 | debug("vsync_low "); |
| 217 | if (timing.flags & DISPLAY_FLAGS_VSYNC_HIGH) |
| 218 | debug("vsync_high "); |
| 219 | debug("\n"); |
| 220 | #endif |
| 221 | |
| 222 | return ret; |
| 223 | } |
| 224 | |
| 225 | static inline void meson_dw_hdmi_phy_reset(struct meson_dw_hdmi *priv) |
| 226 | { |
| 227 | /* Enable and software reset */ |
| 228 | dw_hdmi_hhi_update_bits(priv, HHI_HDMI_PHY_CNTL1, 0xf, 0xf); |
| 229 | |
| 230 | mdelay(2); |
| 231 | |
| 232 | /* Enable and unreset */ |
| 233 | dw_hdmi_hhi_update_bits(priv, HHI_HDMI_PHY_CNTL1, 0xf, 0xe); |
| 234 | |
| 235 | mdelay(2); |
| 236 | } |
| 237 | |
| 238 | static void meson_dw_hdmi_phy_setup_mode(struct meson_dw_hdmi *priv, |
| 239 | uint pixel_clock) |
| 240 | { |
| 241 | pixel_clock = pixel_clock / 1000; |
| 242 | |
| 243 | if (meson_hdmi_is_compatible(priv, HDMI_COMPATIBLE_GXL) || |
| 244 | meson_hdmi_is_compatible(priv, HDMI_COMPATIBLE_GXM)) { |
| 245 | if (pixel_clock >= 371250) { |
| 246 | /* 5.94Gbps, 3.7125Gbps */ |
| 247 | hhi_write(HHI_HDMI_PHY_CNTL0, 0x333d3282); |
| 248 | hhi_write(HHI_HDMI_PHY_CNTL3, 0x2136315b); |
| 249 | } else if (pixel_clock >= 297000) { |
| 250 | /* 2.97Gbps */ |
| 251 | hhi_write(HHI_HDMI_PHY_CNTL0, 0x33303382); |
| 252 | hhi_write(HHI_HDMI_PHY_CNTL3, 0x2036315b); |
| 253 | } else if (pixel_clock >= 148500) { |
| 254 | /* 1.485Gbps */ |
| 255 | hhi_write(HHI_HDMI_PHY_CNTL0, 0x33303362); |
| 256 | hhi_write(HHI_HDMI_PHY_CNTL3, 0x2016315b); |
| 257 | } else { |
| 258 | /* 742.5Mbps, and below */ |
| 259 | hhi_write(HHI_HDMI_PHY_CNTL0, 0x33604142); |
| 260 | hhi_write(HHI_HDMI_PHY_CNTL3, 0x0016315b); |
| 261 | } |
Neil Armstrong | 57d6dfe | 2019-08-30 14:09:24 +0200 | [diff] [blame] | 262 | } else if (meson_hdmi_is_compatible(priv, HDMI_COMPATIBLE_GXBB)) { |
Neil Armstrong | add986c | 2018-07-24 17:45:28 +0200 | [diff] [blame] | 263 | if (pixel_clock >= 371250) { |
| 264 | /* 5.94Gbps, 3.7125Gbps */ |
| 265 | hhi_write(HHI_HDMI_PHY_CNTL0, 0x33353245); |
| 266 | hhi_write(HHI_HDMI_PHY_CNTL3, 0x2100115b); |
| 267 | } else if (pixel_clock >= 297000) { |
| 268 | /* 2.97Gbps */ |
| 269 | hhi_write(HHI_HDMI_PHY_CNTL0, 0x33634283); |
| 270 | hhi_write(HHI_HDMI_PHY_CNTL3, 0xb000115b); |
| 271 | } else { |
| 272 | /* 1.485Gbps, and below */ |
| 273 | hhi_write(HHI_HDMI_PHY_CNTL0, 0x33632122); |
| 274 | hhi_write(HHI_HDMI_PHY_CNTL3, 0x2000115b); |
| 275 | } |
Neil Armstrong | 57d6dfe | 2019-08-30 14:09:24 +0200 | [diff] [blame] | 276 | } else if (meson_hdmi_is_compatible(priv, HDMI_COMPATIBLE_G12A)) { |
| 277 | if (pixel_clock >= 371250) { |
| 278 | /* 5.94Gbps, 3.7125Gbps */ |
| 279 | hhi_write(HHI_HDMI_PHY_CNTL0, 0x37eb65c4); |
| 280 | hhi_write(HHI_HDMI_PHY_CNTL3, 0x2ab0ff3b); |
| 281 | hhi_write(HHI_HDMI_PHY_CNTL5, 0x0000080b); |
| 282 | } else if (pixel_clock >= 297000) { |
| 283 | /* 2.97Gbps */ |
| 284 | hhi_write(HHI_HDMI_PHY_CNTL0, 0x33eb6262); |
| 285 | hhi_write(HHI_HDMI_PHY_CNTL3, 0x2ab0ff3b); |
| 286 | hhi_write(HHI_HDMI_PHY_CNTL5, 0x00000003); |
| 287 | } else { |
| 288 | /* 1.485Gbps, and below */ |
| 289 | hhi_write(HHI_HDMI_PHY_CNTL0, 0x33eb4242); |
| 290 | hhi_write(HHI_HDMI_PHY_CNTL3, 0x2ab0ff3b); |
| 291 | hhi_write(HHI_HDMI_PHY_CNTL5, 0x00000003); |
| 292 | } |
Neil Armstrong | add986c | 2018-07-24 17:45:28 +0200 | [diff] [blame] | 293 | } |
| 294 | } |
| 295 | |
| 296 | static int meson_dw_hdmi_phy_init(struct dw_hdmi *hdmi, uint pixel_clock) |
| 297 | { |
| 298 | struct meson_dw_hdmi *priv = container_of(hdmi, struct meson_dw_hdmi, |
| 299 | hdmi); |
| 300 | /* Enable clocks */ |
| 301 | dw_hdmi_hhi_update_bits(priv, HHI_HDMI_CLK_CNTL, 0xffff, 0x100); |
| 302 | |
| 303 | /* Bring HDMITX MEM output of power down */ |
| 304 | dw_hdmi_hhi_update_bits(priv, HHI_MEM_PD_REG0, 0xff << 8, 0); |
| 305 | |
| 306 | /* Bring out of reset */ |
| 307 | dw_hdmi_top_write(hdmi, HDMITX_TOP_SW_RESET, 0); |
| 308 | |
| 309 | /* Enable internal pixclk, tmds_clk, spdif_clk, i2s_clk, cecclk */ |
| 310 | dw_hdmi_top_write_bits(hdmi, HDMITX_TOP_CLK_CNTL, 0x3, 0x3); |
| 311 | dw_hdmi_top_write_bits(hdmi, HDMITX_TOP_CLK_CNTL, 0x3 << 4, 0x3 << 4); |
| 312 | |
| 313 | /* Enable normal output to PHY */ |
| 314 | dw_hdmi_top_write(hdmi, HDMITX_TOP_BIST_CNTL, BIT(12)); |
| 315 | |
| 316 | /* TMDS pattern setup (TOFIX pattern for 4k2k scrambling) */ |
| 317 | dw_hdmi_top_write(hdmi, HDMITX_TOP_TMDS_CLK_PTTN_01, 0x001f001f); |
| 318 | dw_hdmi_top_write(hdmi, HDMITX_TOP_TMDS_CLK_PTTN_23, 0x001f001f); |
| 319 | |
| 320 | /* Load TMDS pattern */ |
| 321 | dw_hdmi_top_write(hdmi, HDMITX_TOP_TMDS_CLK_PTTN_CNTL, 0x1); |
| 322 | mdelay(20); |
| 323 | dw_hdmi_top_write(hdmi, HDMITX_TOP_TMDS_CLK_PTTN_CNTL, 0x2); |
| 324 | |
| 325 | /* Setup PHY parameters */ |
| 326 | meson_dw_hdmi_phy_setup_mode(priv, pixel_clock); |
| 327 | |
| 328 | /* Setup PHY */ |
| 329 | dw_hdmi_hhi_update_bits(priv, HHI_HDMI_PHY_CNTL1, |
| 330 | 0xffff << 16, 0x0390 << 16); |
| 331 | |
| 332 | /* BIT_INVERT */ |
| 333 | if (meson_hdmi_is_compatible(priv, HDMI_COMPATIBLE_GXL) || |
Neil Armstrong | 57d6dfe | 2019-08-30 14:09:24 +0200 | [diff] [blame] | 334 | meson_hdmi_is_compatible(priv, HDMI_COMPATIBLE_GXM) || |
| 335 | meson_hdmi_is_compatible(priv, HDMI_COMPATIBLE_G12A)) |
Neil Armstrong | add986c | 2018-07-24 17:45:28 +0200 | [diff] [blame] | 336 | dw_hdmi_hhi_update_bits(priv, HHI_HDMI_PHY_CNTL1, BIT(17), 0); |
| 337 | else |
| 338 | dw_hdmi_hhi_update_bits(priv, HHI_HDMI_PHY_CNTL1, |
| 339 | BIT(17), BIT(17)); |
| 340 | |
| 341 | /* Disable clock, fifo, fifo_wr */ |
| 342 | dw_hdmi_hhi_update_bits(priv, HHI_HDMI_PHY_CNTL1, 0xf, 0); |
| 343 | |
| 344 | mdelay(100); |
| 345 | |
| 346 | /* Reset PHY 3 times in a row */ |
| 347 | meson_dw_hdmi_phy_reset(priv); |
| 348 | meson_dw_hdmi_phy_reset(priv); |
| 349 | meson_dw_hdmi_phy_reset(priv); |
| 350 | |
| 351 | return 0; |
| 352 | } |
| 353 | |
| 354 | static int meson_dw_hdmi_enable(struct udevice *dev, int panel_bpp, |
| 355 | const struct display_timing *edid) |
| 356 | { |
| 357 | struct meson_dw_hdmi *priv = dev_get_priv(dev); |
| 358 | |
| 359 | /* will back into meson_dw_hdmi_phy_init */ |
| 360 | return dw_hdmi_enable(&priv->hdmi, edid); |
| 361 | } |
| 362 | |
| 363 | static int meson_dw_hdmi_wait_hpd(struct dw_hdmi *hdmi) |
| 364 | { |
| 365 | int i; |
| 366 | |
| 367 | /* Poll 1 second for HPD signal */ |
| 368 | for (i = 0; i < 10; ++i) { |
| 369 | if (dw_hdmi_top_read(hdmi, HDMITX_TOP_STAT0)) |
| 370 | return 0; |
| 371 | |
| 372 | mdelay(100); |
| 373 | } |
| 374 | |
| 375 | return -ETIMEDOUT; |
| 376 | } |
| 377 | |
| 378 | static int meson_dw_hdmi_probe(struct udevice *dev) |
| 379 | { |
| 380 | struct meson_dw_hdmi *priv = dev_get_priv(dev); |
| 381 | struct reset_ctl_bulk resets; |
| 382 | struct clk_bulk clocks; |
Jaehoon Chung | 91c79ac | 2020-11-06 14:57:48 +0900 | [diff] [blame] | 383 | #if CONFIG_IS_ENABLED(DM_REGULATOR) |
Neil Armstrong | add986c | 2018-07-24 17:45:28 +0200 | [diff] [blame] | 384 | struct udevice *supply; |
Jaehoon Chung | 91c79ac | 2020-11-06 14:57:48 +0900 | [diff] [blame] | 385 | #endif |
Neil Armstrong | add986c | 2018-07-24 17:45:28 +0200 | [diff] [blame] | 386 | int ret; |
| 387 | |
| 388 | priv->dev = dev; |
| 389 | |
| 390 | priv->hdmi.ioaddr = (ulong)dev_remap_addr_index(dev, 0); |
| 391 | if (!priv->hdmi.ioaddr) |
| 392 | return -EINVAL; |
| 393 | |
| 394 | priv->hhi_base = dev_remap_addr_index(dev, 1); |
| 395 | if (!priv->hhi_base) |
| 396 | return -EINVAL; |
| 397 | |
| 398 | priv->hdmi.hdmi_data.enc_out_bus_format = MEDIA_BUS_FMT_RGB888_1X24; |
| 399 | priv->hdmi.hdmi_data.enc_in_bus_format = MEDIA_BUS_FMT_YUV8_1X24; |
| 400 | priv->hdmi.phy_set = meson_dw_hdmi_phy_init; |
Neil Armstrong | 57d6dfe | 2019-08-30 14:09:24 +0200 | [diff] [blame] | 401 | if (meson_hdmi_is_compatible(priv, HDMI_COMPATIBLE_G12A)) |
| 402 | priv->hdmi.reg_io_width = 1; |
| 403 | else { |
| 404 | priv->hdmi.write_reg = dw_hdmi_dwc_write; |
| 405 | priv->hdmi.read_reg = dw_hdmi_dwc_read; |
| 406 | } |
Neil Armstrong | add986c | 2018-07-24 17:45:28 +0200 | [diff] [blame] | 407 | priv->hdmi.i2c_clk_high = 0x67; |
| 408 | priv->hdmi.i2c_clk_low = 0x78; |
| 409 | |
Maxime Jourdan | e27c5bc | 2019-06-04 22:26:19 +0200 | [diff] [blame] | 410 | #if CONFIG_IS_ENABLED(DM_REGULATOR) |
Neil Armstrong | add986c | 2018-07-24 17:45:28 +0200 | [diff] [blame] | 411 | ret = device_get_supply_regulator(dev, "hdmi-supply", &supply); |
Maxime Jourdan | e27c5bc | 2019-06-04 22:26:19 +0200 | [diff] [blame] | 412 | if (ret && ret != -ENOENT) { |
| 413 | pr_err("Failed to get HDMI regulator\n"); |
Neil Armstrong | add986c | 2018-07-24 17:45:28 +0200 | [diff] [blame] | 414 | return ret; |
Maxime Jourdan | e27c5bc | 2019-06-04 22:26:19 +0200 | [diff] [blame] | 415 | } |
Neil Armstrong | add986c | 2018-07-24 17:45:28 +0200 | [diff] [blame] | 416 | |
Maxime Jourdan | e27c5bc | 2019-06-04 22:26:19 +0200 | [diff] [blame] | 417 | if (!ret) { |
| 418 | ret = regulator_set_enable(supply, true); |
| 419 | if (ret) |
| 420 | return ret; |
| 421 | } |
| 422 | #endif |
Neil Armstrong | add986c | 2018-07-24 17:45:28 +0200 | [diff] [blame] | 423 | |
Niklas Schulze | 889ccde | 2019-07-27 12:07:13 +0000 | [diff] [blame] | 424 | uclass_get_device_by_phandle(UCLASS_I2C, dev, "ddc-i2c-bus", |
| 425 | &priv->hdmi.ddc_bus); |
| 426 | |
Neil Armstrong | add986c | 2018-07-24 17:45:28 +0200 | [diff] [blame] | 427 | ret = reset_get_bulk(dev, &resets); |
| 428 | if (ret) |
| 429 | return ret; |
| 430 | |
| 431 | ret = clk_get_bulk(dev, &clocks); |
| 432 | if (ret) |
| 433 | return ret; |
| 434 | |
| 435 | ret = clk_enable_bulk(&clocks); |
| 436 | if (ret) |
| 437 | return ret; |
| 438 | |
| 439 | /* Enable clocks */ |
| 440 | dw_hdmi_hhi_update_bits(priv, HHI_HDMI_CLK_CNTL, 0xffff, 0x100); |
| 441 | |
| 442 | /* Bring HDMITX MEM output of power down */ |
| 443 | dw_hdmi_hhi_update_bits(priv, HHI_MEM_PD_REG0, 0xff << 8, 0); |
| 444 | |
| 445 | /* Reset HDMITX APB & TX & PHY: cycle needed for EDID */ |
| 446 | ret = reset_deassert_bulk(&resets); |
| 447 | if (ret) |
| 448 | return ret; |
| 449 | |
| 450 | ret = reset_assert_bulk(&resets); |
| 451 | if (ret) |
| 452 | return ret; |
| 453 | |
| 454 | ret = reset_deassert_bulk(&resets); |
| 455 | if (ret) |
| 456 | return ret; |
| 457 | |
Neil Armstrong | 57d6dfe | 2019-08-30 14:09:24 +0200 | [diff] [blame] | 458 | if (!meson_hdmi_is_compatible(priv, HDMI_COMPATIBLE_G12A)) { |
| 459 | /* Enable APB3 fail on error */ |
| 460 | writel_bits(BIT(15), BIT(15), |
| 461 | priv->hdmi.ioaddr + HDMITX_TOP_CTRL_REG); |
| 462 | writel_bits(BIT(15), BIT(15), |
| 463 | priv->hdmi.ioaddr + HDMITX_DWC_CTRL_REG); |
| 464 | } |
Neil Armstrong | add986c | 2018-07-24 17:45:28 +0200 | [diff] [blame] | 465 | |
| 466 | /* Bring out of reset */ |
| 467 | dw_hdmi_top_write(&priv->hdmi, HDMITX_TOP_SW_RESET, 0); |
| 468 | mdelay(20); |
| 469 | dw_hdmi_top_write(&priv->hdmi, HDMITX_TOP_CLK_CNTL, 0xff); |
| 470 | |
| 471 | dw_hdmi_init(&priv->hdmi); |
| 472 | dw_hdmi_phy_init(&priv->hdmi); |
| 473 | |
| 474 | /* wait for connector */ |
| 475 | ret = meson_dw_hdmi_wait_hpd(&priv->hdmi); |
| 476 | if (ret) |
| 477 | debug("hdmi can not get hpd signal\n"); |
| 478 | |
| 479 | return ret; |
| 480 | } |
| 481 | |
Neil Armstrong | 9345e6d | 2019-07-04 15:52:08 +0200 | [diff] [blame] | 482 | static bool meson_dw_hdmi_mode_valid(struct udevice *dev, |
| 483 | const struct display_timing *timing) |
| 484 | { |
| 485 | return meson_venc_hdmi_supported_mode(timing); |
| 486 | } |
| 487 | |
Neil Armstrong | add986c | 2018-07-24 17:45:28 +0200 | [diff] [blame] | 488 | static const struct dm_display_ops meson_dw_hdmi_ops = { |
| 489 | .read_edid = meson_dw_hdmi_read_edid, |
| 490 | .enable = meson_dw_hdmi_enable, |
Neil Armstrong | 9345e6d | 2019-07-04 15:52:08 +0200 | [diff] [blame] | 491 | .mode_valid = meson_dw_hdmi_mode_valid, |
Neil Armstrong | add986c | 2018-07-24 17:45:28 +0200 | [diff] [blame] | 492 | }; |
| 493 | |
| 494 | static const struct udevice_id meson_dw_hdmi_ids[] = { |
| 495 | { .compatible = "amlogic,meson-gxbb-dw-hdmi", |
| 496 | .data = HDMI_COMPATIBLE_GXBB }, |
| 497 | { .compatible = "amlogic,meson-gxl-dw-hdmi", |
| 498 | .data = HDMI_COMPATIBLE_GXL }, |
| 499 | { .compatible = "amlogic,meson-gxm-dw-hdmi", |
| 500 | .data = HDMI_COMPATIBLE_GXM }, |
Neil Armstrong | 57d6dfe | 2019-08-30 14:09:24 +0200 | [diff] [blame] | 501 | { .compatible = "amlogic,meson-g12a-dw-hdmi", |
| 502 | .data = HDMI_COMPATIBLE_G12A }, |
Neil Armstrong | add986c | 2018-07-24 17:45:28 +0200 | [diff] [blame] | 503 | { } |
| 504 | }; |
| 505 | |
| 506 | U_BOOT_DRIVER(meson_dw_hdmi) = { |
| 507 | .name = "meson_dw_hdmi", |
| 508 | .id = UCLASS_DISPLAY, |
| 509 | .of_match = meson_dw_hdmi_ids, |
| 510 | .ops = &meson_dw_hdmi_ops, |
| 511 | .probe = meson_dw_hdmi_probe, |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 512 | .priv_auto = sizeof(struct meson_dw_hdmi), |
Neil Armstrong | add986c | 2018-07-24 17:45:28 +0200 | [diff] [blame] | 513 | }; |