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