Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1 | /* |
Vladimir Zapolskiy | 3efc2fa | 2016-08-24 08:46:37 +0300 | [diff] [blame] | 2 | * DesignWare High-Definition Multimedia Interface (HDMI) driver |
| 3 | * |
| 4 | * Copyright (C) 2013-2015 Mentor Graphics Inc. |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 5 | * Copyright (C) 2011-2013 Freescale Semiconductor, Inc. |
Vladimir Zapolskiy | 3efc2fa | 2016-08-24 08:46:37 +0300 | [diff] [blame] | 6 | * Copyright (C) 2010, Guennadi Liakhovetski <g.liakhovetski@gmx.de> |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 13 | */ |
Andy Yan | b21f4b6 | 2014-12-05 14:26:31 +0800 | [diff] [blame] | 14 | #include <linux/module.h> |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 15 | #include <linux/irq.h> |
| 16 | #include <linux/delay.h> |
| 17 | #include <linux/err.h> |
| 18 | #include <linux/clk.h> |
Sachin Kamat | 5a819ed | 2014-01-28 10:33:16 +0530 | [diff] [blame] | 19 | #include <linux/hdmi.h> |
Russell King | 6bcf495 | 2015-02-02 11:01:08 +0000 | [diff] [blame] | 20 | #include <linux/mutex.h> |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 21 | #include <linux/of_device.h> |
Russell King | b90120a | 2015-03-27 12:59:58 +0000 | [diff] [blame] | 22 | #include <linux/spinlock.h> |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 23 | |
Andy Yan | 3d1b35a | 2014-12-05 14:25:05 +0800 | [diff] [blame] | 24 | #include <drm/drm_of.h> |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 25 | #include <drm/drmP.h> |
Mark Yao | 2c5b2cc | 2015-11-30 18:33:40 +0800 | [diff] [blame] | 26 | #include <drm/drm_atomic_helper.h> |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 27 | #include <drm/drm_crtc_helper.h> |
| 28 | #include <drm/drm_edid.h> |
| 29 | #include <drm/drm_encoder_slave.h> |
Andy Yan | b21f4b6 | 2014-12-05 14:26:31 +0800 | [diff] [blame] | 30 | #include <drm/bridge/dw_hdmi.h> |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 31 | |
Thierry Reding | 248a86f | 2015-11-24 17:52:58 +0100 | [diff] [blame] | 32 | #include "dw-hdmi.h" |
| 33 | #include "dw-hdmi-audio.h" |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 34 | |
| 35 | #define HDMI_EDID_LEN 512 |
| 36 | |
| 37 | #define RGB 0 |
| 38 | #define YCBCR444 1 |
| 39 | #define YCBCR422_16BITS 2 |
| 40 | #define YCBCR422_8BITS 3 |
| 41 | #define XVYCC444 4 |
| 42 | |
| 43 | enum hdmi_datamap { |
| 44 | RGB444_8B = 0x01, |
| 45 | RGB444_10B = 0x03, |
| 46 | RGB444_12B = 0x05, |
| 47 | RGB444_16B = 0x07, |
| 48 | YCbCr444_8B = 0x09, |
| 49 | YCbCr444_10B = 0x0B, |
| 50 | YCbCr444_12B = 0x0D, |
| 51 | YCbCr444_16B = 0x0F, |
| 52 | YCbCr422_8B = 0x16, |
| 53 | YCbCr422_10B = 0x14, |
| 54 | YCbCr422_12B = 0x12, |
| 55 | }; |
| 56 | |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 57 | static const u16 csc_coeff_default[3][4] = { |
| 58 | { 0x2000, 0x0000, 0x0000, 0x0000 }, |
| 59 | { 0x0000, 0x2000, 0x0000, 0x0000 }, |
| 60 | { 0x0000, 0x0000, 0x2000, 0x0000 } |
| 61 | }; |
| 62 | |
| 63 | static const u16 csc_coeff_rgb_out_eitu601[3][4] = { |
| 64 | { 0x2000, 0x6926, 0x74fd, 0x010e }, |
| 65 | { 0x2000, 0x2cdd, 0x0000, 0x7e9a }, |
| 66 | { 0x2000, 0x0000, 0x38b4, 0x7e3b } |
| 67 | }; |
| 68 | |
| 69 | static const u16 csc_coeff_rgb_out_eitu709[3][4] = { |
| 70 | { 0x2000, 0x7106, 0x7a02, 0x00a7 }, |
| 71 | { 0x2000, 0x3264, 0x0000, 0x7e6d }, |
| 72 | { 0x2000, 0x0000, 0x3b61, 0x7e25 } |
| 73 | }; |
| 74 | |
| 75 | static const u16 csc_coeff_rgb_in_eitu601[3][4] = { |
| 76 | { 0x2591, 0x1322, 0x074b, 0x0000 }, |
| 77 | { 0x6535, 0x2000, 0x7acc, 0x0200 }, |
| 78 | { 0x6acd, 0x7534, 0x2000, 0x0200 } |
| 79 | }; |
| 80 | |
| 81 | static const u16 csc_coeff_rgb_in_eitu709[3][4] = { |
| 82 | { 0x2dc5, 0x0d9b, 0x049e, 0x0000 }, |
| 83 | { 0x62f0, 0x2000, 0x7d11, 0x0200 }, |
| 84 | { 0x6756, 0x78ab, 0x2000, 0x0200 } |
| 85 | }; |
| 86 | |
| 87 | struct hdmi_vmode { |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 88 | bool mdataenablepolarity; |
| 89 | |
| 90 | unsigned int mpixelclock; |
| 91 | unsigned int mpixelrepetitioninput; |
| 92 | unsigned int mpixelrepetitionoutput; |
| 93 | }; |
| 94 | |
| 95 | struct hdmi_data_info { |
| 96 | unsigned int enc_in_format; |
| 97 | unsigned int enc_out_format; |
| 98 | unsigned int enc_color_depth; |
| 99 | unsigned int colorimetry; |
| 100 | unsigned int pix_repet_factor; |
| 101 | unsigned int hdcp_enable; |
| 102 | struct hdmi_vmode video_mode; |
| 103 | }; |
| 104 | |
Vladimir Zapolskiy | 3efc2fa | 2016-08-24 08:46:37 +0300 | [diff] [blame] | 105 | struct dw_hdmi_i2c { |
| 106 | struct i2c_adapter adap; |
| 107 | |
| 108 | struct mutex lock; /* used to serialize data transfers */ |
| 109 | struct completion cmp; |
| 110 | u8 stat; |
| 111 | |
| 112 | u8 slave_reg; |
| 113 | bool is_regaddr; |
| 114 | }; |
| 115 | |
Laurent Pinchart | faba6c3 | 2017-01-17 10:29:06 +0200 | [diff] [blame] | 116 | struct dw_hdmi_phy_data { |
| 117 | enum dw_hdmi_phy_type type; |
| 118 | const char *name; |
Laurent Pinchart | b0e583e | 2017-03-06 01:35:39 +0200 | [diff] [blame^] | 119 | unsigned int gen; |
Laurent Pinchart | faba6c3 | 2017-01-17 10:29:06 +0200 | [diff] [blame] | 120 | bool has_svsret; |
| 121 | }; |
| 122 | |
Andy Yan | b21f4b6 | 2014-12-05 14:26:31 +0800 | [diff] [blame] | 123 | struct dw_hdmi { |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 124 | struct drm_connector connector; |
Laurent Pinchart | 70c963e | 2017-01-17 10:28:54 +0200 | [diff] [blame] | 125 | struct drm_bridge bridge; |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 126 | |
Andy Yan | b21f4b6 | 2014-12-05 14:26:31 +0800 | [diff] [blame] | 127 | enum dw_hdmi_devtype dev_type; |
Laurent Pinchart | be41fc5 | 2017-01-17 10:29:05 +0200 | [diff] [blame] | 128 | unsigned int version; |
| 129 | |
| 130 | struct platform_device *audio; |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 131 | struct device *dev; |
| 132 | struct clk *isfr_clk; |
| 133 | struct clk *iahb_clk; |
Vladimir Zapolskiy | 3efc2fa | 2016-08-24 08:46:37 +0300 | [diff] [blame] | 134 | struct dw_hdmi_i2c *i2c; |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 135 | |
| 136 | struct hdmi_data_info hdmi_data; |
Andy Yan | b21f4b6 | 2014-12-05 14:26:31 +0800 | [diff] [blame] | 137 | const struct dw_hdmi_plat_data *plat_data; |
| 138 | |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 139 | int vic; |
| 140 | |
| 141 | u8 edid[HDMI_EDID_LEN]; |
| 142 | bool cable_plugin; |
| 143 | |
Laurent Pinchart | faba6c3 | 2017-01-17 10:29:06 +0200 | [diff] [blame] | 144 | const struct dw_hdmi_phy_data *phy; |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 145 | bool phy_enabled; |
Laurent Pinchart | faba6c3 | 2017-01-17 10:29:06 +0200 | [diff] [blame] | 146 | |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 147 | struct drm_display_mode previous_mode; |
| 148 | |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 149 | struct i2c_adapter *ddc; |
| 150 | void __iomem *regs; |
Russell King | 05b1342 | 2015-07-21 15:35:52 +0100 | [diff] [blame] | 151 | bool sink_is_hdmi; |
Russell King | f709ec0 | 2015-07-21 16:09:39 +0100 | [diff] [blame] | 152 | bool sink_has_audio; |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 153 | |
Russell King | b872a8e | 2015-06-05 12:22:46 +0100 | [diff] [blame] | 154 | struct mutex mutex; /* for state below and previous_mode */ |
Russell King | 381f05a | 2015-06-05 15:25:08 +0100 | [diff] [blame] | 155 | enum drm_connector_force force; /* mutex-protected force state */ |
Russell King | b872a8e | 2015-06-05 12:22:46 +0100 | [diff] [blame] | 156 | bool disabled; /* DRM has disabled our bridge */ |
Russell King | 381f05a | 2015-06-05 15:25:08 +0100 | [diff] [blame] | 157 | bool bridge_is_on; /* indicates the bridge is on */ |
Russell King | aeac23b | 2015-06-05 13:46:22 +0100 | [diff] [blame] | 158 | bool rxsense; /* rxsense state */ |
| 159 | u8 phy_mask; /* desired phy int mask settings */ |
Russell King | b872a8e | 2015-06-05 12:22:46 +0100 | [diff] [blame] | 160 | |
Russell King | b90120a | 2015-03-27 12:59:58 +0000 | [diff] [blame] | 161 | spinlock_t audio_lock; |
Russell King | 6bcf495 | 2015-02-02 11:01:08 +0000 | [diff] [blame] | 162 | struct mutex audio_mutex; |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 163 | unsigned int sample_rate; |
Russell King | b90120a | 2015-03-27 12:59:58 +0000 | [diff] [blame] | 164 | unsigned int audio_cts; |
| 165 | unsigned int audio_n; |
| 166 | bool audio_enable; |
Andy Yan | 0cd9d14 | 2014-12-05 14:28:24 +0800 | [diff] [blame] | 167 | |
| 168 | void (*write)(struct dw_hdmi *hdmi, u8 val, int offset); |
| 169 | u8 (*read)(struct dw_hdmi *hdmi, int offset); |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 170 | }; |
| 171 | |
Russell King | aeac23b | 2015-06-05 13:46:22 +0100 | [diff] [blame] | 172 | #define HDMI_IH_PHY_STAT0_RX_SENSE \ |
| 173 | (HDMI_IH_PHY_STAT0_RX_SENSE0 | HDMI_IH_PHY_STAT0_RX_SENSE1 | \ |
| 174 | HDMI_IH_PHY_STAT0_RX_SENSE2 | HDMI_IH_PHY_STAT0_RX_SENSE3) |
| 175 | |
| 176 | #define HDMI_PHY_RX_SENSE \ |
| 177 | (HDMI_PHY_RX_SENSE0 | HDMI_PHY_RX_SENSE1 | \ |
| 178 | HDMI_PHY_RX_SENSE2 | HDMI_PHY_RX_SENSE3) |
| 179 | |
Andy Yan | 0cd9d14 | 2014-12-05 14:28:24 +0800 | [diff] [blame] | 180 | static void dw_hdmi_writel(struct dw_hdmi *hdmi, u8 val, int offset) |
| 181 | { |
| 182 | writel(val, hdmi->regs + (offset << 2)); |
| 183 | } |
| 184 | |
| 185 | static u8 dw_hdmi_readl(struct dw_hdmi *hdmi, int offset) |
| 186 | { |
| 187 | return readl(hdmi->regs + (offset << 2)); |
| 188 | } |
| 189 | |
| 190 | static void dw_hdmi_writeb(struct dw_hdmi *hdmi, u8 val, int offset) |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 191 | { |
| 192 | writeb(val, hdmi->regs + offset); |
| 193 | } |
| 194 | |
Andy Yan | 0cd9d14 | 2014-12-05 14:28:24 +0800 | [diff] [blame] | 195 | static u8 dw_hdmi_readb(struct dw_hdmi *hdmi, int offset) |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 196 | { |
| 197 | return readb(hdmi->regs + offset); |
| 198 | } |
| 199 | |
Andy Yan | 0cd9d14 | 2014-12-05 14:28:24 +0800 | [diff] [blame] | 200 | static inline void hdmi_writeb(struct dw_hdmi *hdmi, u8 val, int offset) |
| 201 | { |
| 202 | hdmi->write(hdmi, val, offset); |
| 203 | } |
| 204 | |
| 205 | static inline u8 hdmi_readb(struct dw_hdmi *hdmi, int offset) |
| 206 | { |
| 207 | return hdmi->read(hdmi, offset); |
| 208 | } |
| 209 | |
Andy Yan | b21f4b6 | 2014-12-05 14:26:31 +0800 | [diff] [blame] | 210 | static void hdmi_modb(struct dw_hdmi *hdmi, u8 data, u8 mask, unsigned reg) |
Russell King | 812bc61 | 2013-11-04 12:42:02 +0000 | [diff] [blame] | 211 | { |
| 212 | u8 val = hdmi_readb(hdmi, reg) & ~mask; |
Fabio Estevam | b44ab1b | 2014-04-28 08:01:07 -0300 | [diff] [blame] | 213 | |
Russell King | 812bc61 | 2013-11-04 12:42:02 +0000 | [diff] [blame] | 214 | val |= data & mask; |
| 215 | hdmi_writeb(hdmi, val, reg); |
| 216 | } |
| 217 | |
Andy Yan | b21f4b6 | 2014-12-05 14:26:31 +0800 | [diff] [blame] | 218 | static void hdmi_mask_writeb(struct dw_hdmi *hdmi, u8 data, unsigned int reg, |
Andy Yan | b587833 | 2014-12-05 14:23:52 +0800 | [diff] [blame] | 219 | u8 shift, u8 mask) |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 220 | { |
Russell King | 812bc61 | 2013-11-04 12:42:02 +0000 | [diff] [blame] | 221 | hdmi_modb(hdmi, data << shift, mask, reg); |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 222 | } |
| 223 | |
Vladimir Zapolskiy | 3efc2fa | 2016-08-24 08:46:37 +0300 | [diff] [blame] | 224 | static void dw_hdmi_i2c_init(struct dw_hdmi *hdmi) |
| 225 | { |
| 226 | /* Software reset */ |
| 227 | hdmi_writeb(hdmi, 0x00, HDMI_I2CM_SOFTRSTZ); |
| 228 | |
| 229 | /* Set Standard Mode speed (determined to be 100KHz on iMX6) */ |
| 230 | hdmi_writeb(hdmi, 0x00, HDMI_I2CM_DIV); |
| 231 | |
| 232 | /* Set done, not acknowledged and arbitration interrupt polarities */ |
| 233 | hdmi_writeb(hdmi, HDMI_I2CM_INT_DONE_POL, HDMI_I2CM_INT); |
| 234 | hdmi_writeb(hdmi, HDMI_I2CM_CTLINT_NAC_POL | HDMI_I2CM_CTLINT_ARB_POL, |
| 235 | HDMI_I2CM_CTLINT); |
| 236 | |
| 237 | /* Clear DONE and ERROR interrupts */ |
| 238 | hdmi_writeb(hdmi, HDMI_IH_I2CM_STAT0_ERROR | HDMI_IH_I2CM_STAT0_DONE, |
| 239 | HDMI_IH_I2CM_STAT0); |
| 240 | |
| 241 | /* Mute DONE and ERROR interrupts */ |
| 242 | hdmi_writeb(hdmi, HDMI_IH_I2CM_STAT0_ERROR | HDMI_IH_I2CM_STAT0_DONE, |
| 243 | HDMI_IH_MUTE_I2CM_STAT0); |
| 244 | } |
| 245 | |
| 246 | static int dw_hdmi_i2c_read(struct dw_hdmi *hdmi, |
| 247 | unsigned char *buf, unsigned int length) |
| 248 | { |
| 249 | struct dw_hdmi_i2c *i2c = hdmi->i2c; |
| 250 | int stat; |
| 251 | |
| 252 | if (!i2c->is_regaddr) { |
| 253 | dev_dbg(hdmi->dev, "set read register address to 0\n"); |
| 254 | i2c->slave_reg = 0x00; |
| 255 | i2c->is_regaddr = true; |
| 256 | } |
| 257 | |
| 258 | while (length--) { |
| 259 | reinit_completion(&i2c->cmp); |
| 260 | |
| 261 | hdmi_writeb(hdmi, i2c->slave_reg++, HDMI_I2CM_ADDRESS); |
| 262 | hdmi_writeb(hdmi, HDMI_I2CM_OPERATION_READ, |
| 263 | HDMI_I2CM_OPERATION); |
| 264 | |
| 265 | stat = wait_for_completion_timeout(&i2c->cmp, HZ / 10); |
| 266 | if (!stat) |
| 267 | return -EAGAIN; |
| 268 | |
| 269 | /* Check for error condition on the bus */ |
| 270 | if (i2c->stat & HDMI_IH_I2CM_STAT0_ERROR) |
| 271 | return -EIO; |
| 272 | |
| 273 | *buf++ = hdmi_readb(hdmi, HDMI_I2CM_DATAI); |
| 274 | } |
| 275 | |
| 276 | return 0; |
| 277 | } |
| 278 | |
| 279 | static int dw_hdmi_i2c_write(struct dw_hdmi *hdmi, |
| 280 | unsigned char *buf, unsigned int length) |
| 281 | { |
| 282 | struct dw_hdmi_i2c *i2c = hdmi->i2c; |
| 283 | int stat; |
| 284 | |
| 285 | if (!i2c->is_regaddr) { |
| 286 | /* Use the first write byte as register address */ |
| 287 | i2c->slave_reg = buf[0]; |
| 288 | length--; |
| 289 | buf++; |
| 290 | i2c->is_regaddr = true; |
| 291 | } |
| 292 | |
| 293 | while (length--) { |
| 294 | reinit_completion(&i2c->cmp); |
| 295 | |
| 296 | hdmi_writeb(hdmi, *buf++, HDMI_I2CM_DATAO); |
| 297 | hdmi_writeb(hdmi, i2c->slave_reg++, HDMI_I2CM_ADDRESS); |
| 298 | hdmi_writeb(hdmi, HDMI_I2CM_OPERATION_WRITE, |
| 299 | HDMI_I2CM_OPERATION); |
| 300 | |
| 301 | stat = wait_for_completion_timeout(&i2c->cmp, HZ / 10); |
| 302 | if (!stat) |
| 303 | return -EAGAIN; |
| 304 | |
| 305 | /* Check for error condition on the bus */ |
| 306 | if (i2c->stat & HDMI_IH_I2CM_STAT0_ERROR) |
| 307 | return -EIO; |
| 308 | } |
| 309 | |
| 310 | return 0; |
| 311 | } |
| 312 | |
| 313 | static int dw_hdmi_i2c_xfer(struct i2c_adapter *adap, |
| 314 | struct i2c_msg *msgs, int num) |
| 315 | { |
| 316 | struct dw_hdmi *hdmi = i2c_get_adapdata(adap); |
| 317 | struct dw_hdmi_i2c *i2c = hdmi->i2c; |
| 318 | u8 addr = msgs[0].addr; |
| 319 | int i, ret = 0; |
| 320 | |
| 321 | dev_dbg(hdmi->dev, "xfer: num: %d, addr: %#x\n", num, addr); |
| 322 | |
| 323 | for (i = 0; i < num; i++) { |
| 324 | if (msgs[i].addr != addr) { |
| 325 | dev_warn(hdmi->dev, |
| 326 | "unsupported transfer, changed slave address\n"); |
| 327 | return -EOPNOTSUPP; |
| 328 | } |
| 329 | |
| 330 | if (msgs[i].len == 0) { |
| 331 | dev_dbg(hdmi->dev, |
| 332 | "unsupported transfer %d/%d, no data\n", |
| 333 | i + 1, num); |
| 334 | return -EOPNOTSUPP; |
| 335 | } |
| 336 | } |
| 337 | |
| 338 | mutex_lock(&i2c->lock); |
| 339 | |
| 340 | /* Unmute DONE and ERROR interrupts */ |
| 341 | hdmi_writeb(hdmi, 0x00, HDMI_IH_MUTE_I2CM_STAT0); |
| 342 | |
| 343 | /* Set slave device address taken from the first I2C message */ |
| 344 | hdmi_writeb(hdmi, addr, HDMI_I2CM_SLAVE); |
| 345 | |
| 346 | /* Set slave device register address on transfer */ |
| 347 | i2c->is_regaddr = false; |
| 348 | |
| 349 | for (i = 0; i < num; i++) { |
| 350 | dev_dbg(hdmi->dev, "xfer: num: %d/%d, len: %d, flags: %#x\n", |
| 351 | i + 1, num, msgs[i].len, msgs[i].flags); |
| 352 | |
| 353 | if (msgs[i].flags & I2C_M_RD) |
| 354 | ret = dw_hdmi_i2c_read(hdmi, msgs[i].buf, msgs[i].len); |
| 355 | else |
| 356 | ret = dw_hdmi_i2c_write(hdmi, msgs[i].buf, msgs[i].len); |
| 357 | |
| 358 | if (ret < 0) |
| 359 | break; |
| 360 | } |
| 361 | |
| 362 | if (!ret) |
| 363 | ret = num; |
| 364 | |
| 365 | /* Mute DONE and ERROR interrupts */ |
| 366 | hdmi_writeb(hdmi, HDMI_IH_I2CM_STAT0_ERROR | HDMI_IH_I2CM_STAT0_DONE, |
| 367 | HDMI_IH_MUTE_I2CM_STAT0); |
| 368 | |
| 369 | mutex_unlock(&i2c->lock); |
| 370 | |
| 371 | return ret; |
| 372 | } |
| 373 | |
| 374 | static u32 dw_hdmi_i2c_func(struct i2c_adapter *adapter) |
| 375 | { |
| 376 | return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; |
| 377 | } |
| 378 | |
| 379 | static const struct i2c_algorithm dw_hdmi_algorithm = { |
| 380 | .master_xfer = dw_hdmi_i2c_xfer, |
| 381 | .functionality = dw_hdmi_i2c_func, |
| 382 | }; |
| 383 | |
| 384 | static struct i2c_adapter *dw_hdmi_i2c_adapter(struct dw_hdmi *hdmi) |
| 385 | { |
| 386 | struct i2c_adapter *adap; |
| 387 | struct dw_hdmi_i2c *i2c; |
| 388 | int ret; |
| 389 | |
| 390 | i2c = devm_kzalloc(hdmi->dev, sizeof(*i2c), GFP_KERNEL); |
| 391 | if (!i2c) |
| 392 | return ERR_PTR(-ENOMEM); |
| 393 | |
| 394 | mutex_init(&i2c->lock); |
| 395 | init_completion(&i2c->cmp); |
| 396 | |
| 397 | adap = &i2c->adap; |
| 398 | adap->class = I2C_CLASS_DDC; |
| 399 | adap->owner = THIS_MODULE; |
| 400 | adap->dev.parent = hdmi->dev; |
| 401 | adap->algo = &dw_hdmi_algorithm; |
| 402 | strlcpy(adap->name, "DesignWare HDMI", sizeof(adap->name)); |
| 403 | i2c_set_adapdata(adap, hdmi); |
| 404 | |
| 405 | ret = i2c_add_adapter(adap); |
| 406 | if (ret) { |
| 407 | dev_warn(hdmi->dev, "cannot add %s I2C adapter\n", adap->name); |
| 408 | devm_kfree(hdmi->dev, i2c); |
| 409 | return ERR_PTR(ret); |
| 410 | } |
| 411 | |
| 412 | hdmi->i2c = i2c; |
| 413 | |
| 414 | dev_info(hdmi->dev, "registered %s I2C bus driver\n", adap->name); |
| 415 | |
| 416 | return adap; |
| 417 | } |
| 418 | |
Russell King | 351e135 | 2015-01-31 14:50:23 +0000 | [diff] [blame] | 419 | static void hdmi_set_cts_n(struct dw_hdmi *hdmi, unsigned int cts, |
| 420 | unsigned int n) |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 421 | { |
Russell King | 622494a | 2015-02-02 10:55:38 +0000 | [diff] [blame] | 422 | /* Must be set/cleared first */ |
| 423 | hdmi_modb(hdmi, 0, HDMI_AUD_CTS3_CTS_MANUAL, HDMI_AUD_CTS3); |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 424 | |
| 425 | /* nshift factor = 0 */ |
Russell King | 812bc61 | 2013-11-04 12:42:02 +0000 | [diff] [blame] | 426 | hdmi_modb(hdmi, 0, HDMI_AUD_CTS3_N_SHIFT_MASK, HDMI_AUD_CTS3); |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 427 | |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 428 | hdmi_writeb(hdmi, ((cts >> 16) & HDMI_AUD_CTS3_AUDCTS19_16_MASK) | |
| 429 | HDMI_AUD_CTS3_CTS_MANUAL, HDMI_AUD_CTS3); |
Russell King | 622494a | 2015-02-02 10:55:38 +0000 | [diff] [blame] | 430 | hdmi_writeb(hdmi, (cts >> 8) & 0xff, HDMI_AUD_CTS2); |
| 431 | hdmi_writeb(hdmi, cts & 0xff, HDMI_AUD_CTS1); |
| 432 | |
| 433 | hdmi_writeb(hdmi, (n >> 16) & 0x0f, HDMI_AUD_N3); |
| 434 | hdmi_writeb(hdmi, (n >> 8) & 0xff, HDMI_AUD_N2); |
| 435 | hdmi_writeb(hdmi, n & 0xff, HDMI_AUD_N1); |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 436 | } |
| 437 | |
Russell King | b195fbd | 2015-07-22 11:28:16 +0100 | [diff] [blame] | 438 | static unsigned int hdmi_compute_n(unsigned int freq, unsigned long pixel_clk) |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 439 | { |
| 440 | unsigned int n = (128 * freq) / 1000; |
Russell King | d0c96d1 | 2015-07-22 10:35:41 +0100 | [diff] [blame] | 441 | unsigned int mult = 1; |
| 442 | |
| 443 | while (freq > 48000) { |
| 444 | mult *= 2; |
| 445 | freq /= 2; |
| 446 | } |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 447 | |
| 448 | switch (freq) { |
| 449 | case 32000: |
Russell King | 426701d | 2015-07-22 10:39:27 +0100 | [diff] [blame] | 450 | if (pixel_clk == 25175000) |
Russell King | b195fbd | 2015-07-22 11:28:16 +0100 | [diff] [blame] | 451 | n = 4576; |
Russell King | 426701d | 2015-07-22 10:39:27 +0100 | [diff] [blame] | 452 | else if (pixel_clk == 27027000) |
Russell King | b195fbd | 2015-07-22 11:28:16 +0100 | [diff] [blame] | 453 | n = 4096; |
Russell King | 426701d | 2015-07-22 10:39:27 +0100 | [diff] [blame] | 454 | else if (pixel_clk == 74176000 || pixel_clk == 148352000) |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 455 | n = 11648; |
| 456 | else |
| 457 | n = 4096; |
Russell King | d0c96d1 | 2015-07-22 10:35:41 +0100 | [diff] [blame] | 458 | n *= mult; |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 459 | break; |
| 460 | |
| 461 | case 44100: |
Russell King | 426701d | 2015-07-22 10:39:27 +0100 | [diff] [blame] | 462 | if (pixel_clk == 25175000) |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 463 | n = 7007; |
Russell King | 426701d | 2015-07-22 10:39:27 +0100 | [diff] [blame] | 464 | else if (pixel_clk == 74176000) |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 465 | n = 17836; |
Russell King | 426701d | 2015-07-22 10:39:27 +0100 | [diff] [blame] | 466 | else if (pixel_clk == 148352000) |
Russell King | b195fbd | 2015-07-22 11:28:16 +0100 | [diff] [blame] | 467 | n = 8918; |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 468 | else |
| 469 | n = 6272; |
Russell King | d0c96d1 | 2015-07-22 10:35:41 +0100 | [diff] [blame] | 470 | n *= mult; |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 471 | break; |
| 472 | |
| 473 | case 48000: |
Russell King | 426701d | 2015-07-22 10:39:27 +0100 | [diff] [blame] | 474 | if (pixel_clk == 25175000) |
Russell King | b195fbd | 2015-07-22 11:28:16 +0100 | [diff] [blame] | 475 | n = 6864; |
Russell King | 426701d | 2015-07-22 10:39:27 +0100 | [diff] [blame] | 476 | else if (pixel_clk == 27027000) |
Russell King | b195fbd | 2015-07-22 11:28:16 +0100 | [diff] [blame] | 477 | n = 6144; |
Russell King | 426701d | 2015-07-22 10:39:27 +0100 | [diff] [blame] | 478 | else if (pixel_clk == 74176000) |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 479 | n = 11648; |
Russell King | 426701d | 2015-07-22 10:39:27 +0100 | [diff] [blame] | 480 | else if (pixel_clk == 148352000) |
Russell King | b195fbd | 2015-07-22 11:28:16 +0100 | [diff] [blame] | 481 | n = 5824; |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 482 | else |
| 483 | n = 6144; |
Russell King | d0c96d1 | 2015-07-22 10:35:41 +0100 | [diff] [blame] | 484 | n *= mult; |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 485 | break; |
| 486 | |
| 487 | default: |
| 488 | break; |
| 489 | } |
| 490 | |
| 491 | return n; |
| 492 | } |
| 493 | |
Andy Yan | b21f4b6 | 2014-12-05 14:26:31 +0800 | [diff] [blame] | 494 | static void hdmi_set_clk_regenerator(struct dw_hdmi *hdmi, |
Russell King | b195fbd | 2015-07-22 11:28:16 +0100 | [diff] [blame] | 495 | unsigned long pixel_clk, unsigned int sample_rate) |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 496 | { |
Russell King | dfbdaf5 | 2015-07-22 16:54:37 +0100 | [diff] [blame] | 497 | unsigned long ftdms = pixel_clk; |
Russell King | f879b38 | 2015-03-27 12:53:29 +0000 | [diff] [blame] | 498 | unsigned int n, cts; |
Russell King | dfbdaf5 | 2015-07-22 16:54:37 +0100 | [diff] [blame] | 499 | u64 tmp; |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 500 | |
Russell King | b195fbd | 2015-07-22 11:28:16 +0100 | [diff] [blame] | 501 | n = hdmi_compute_n(sample_rate, pixel_clk); |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 502 | |
Russell King | dfbdaf5 | 2015-07-22 16:54:37 +0100 | [diff] [blame] | 503 | /* |
| 504 | * Compute the CTS value from the N value. Note that CTS and N |
| 505 | * can be up to 20 bits in total, so we need 64-bit math. Also |
| 506 | * note that our TDMS clock is not fully accurate; it is accurate |
| 507 | * to kHz. This can introduce an unnecessary remainder in the |
| 508 | * calculation below, so we don't try to warn about that. |
| 509 | */ |
| 510 | tmp = (u64)ftdms * n; |
| 511 | do_div(tmp, 128 * sample_rate); |
| 512 | cts = tmp; |
| 513 | |
| 514 | dev_dbg(hdmi->dev, "%s: fs=%uHz ftdms=%lu.%03luMHz N=%d cts=%d\n", |
| 515 | __func__, sample_rate, ftdms / 1000000, (ftdms / 1000) % 1000, |
| 516 | n, cts); |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 517 | |
Russell King | b90120a | 2015-03-27 12:59:58 +0000 | [diff] [blame] | 518 | spin_lock_irq(&hdmi->audio_lock); |
| 519 | hdmi->audio_n = n; |
| 520 | hdmi->audio_cts = cts; |
| 521 | hdmi_set_cts_n(hdmi, cts, hdmi->audio_enable ? n : 0); |
| 522 | spin_unlock_irq(&hdmi->audio_lock); |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 523 | } |
| 524 | |
Andy Yan | b21f4b6 | 2014-12-05 14:26:31 +0800 | [diff] [blame] | 525 | static void hdmi_init_clk_regenerator(struct dw_hdmi *hdmi) |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 526 | { |
Russell King | 6bcf495 | 2015-02-02 11:01:08 +0000 | [diff] [blame] | 527 | mutex_lock(&hdmi->audio_mutex); |
Russell King | b195fbd | 2015-07-22 11:28:16 +0100 | [diff] [blame] | 528 | hdmi_set_clk_regenerator(hdmi, 74250000, hdmi->sample_rate); |
Russell King | 6bcf495 | 2015-02-02 11:01:08 +0000 | [diff] [blame] | 529 | mutex_unlock(&hdmi->audio_mutex); |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 530 | } |
| 531 | |
Andy Yan | b21f4b6 | 2014-12-05 14:26:31 +0800 | [diff] [blame] | 532 | static void hdmi_clk_regenerator_update_pixel_clock(struct dw_hdmi *hdmi) |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 533 | { |
Russell King | 6bcf495 | 2015-02-02 11:01:08 +0000 | [diff] [blame] | 534 | mutex_lock(&hdmi->audio_mutex); |
Russell King | f879b38 | 2015-03-27 12:53:29 +0000 | [diff] [blame] | 535 | hdmi_set_clk_regenerator(hdmi, hdmi->hdmi_data.video_mode.mpixelclock, |
Russell King | b195fbd | 2015-07-22 11:28:16 +0100 | [diff] [blame] | 536 | hdmi->sample_rate); |
Russell King | 6bcf495 | 2015-02-02 11:01:08 +0000 | [diff] [blame] | 537 | mutex_unlock(&hdmi->audio_mutex); |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 538 | } |
| 539 | |
Russell King | b5814ff | 2015-03-27 12:50:58 +0000 | [diff] [blame] | 540 | void dw_hdmi_set_sample_rate(struct dw_hdmi *hdmi, unsigned int rate) |
| 541 | { |
| 542 | mutex_lock(&hdmi->audio_mutex); |
| 543 | hdmi->sample_rate = rate; |
| 544 | hdmi_set_clk_regenerator(hdmi, hdmi->hdmi_data.video_mode.mpixelclock, |
Russell King | b195fbd | 2015-07-22 11:28:16 +0100 | [diff] [blame] | 545 | hdmi->sample_rate); |
Russell King | b5814ff | 2015-03-27 12:50:58 +0000 | [diff] [blame] | 546 | mutex_unlock(&hdmi->audio_mutex); |
| 547 | } |
| 548 | EXPORT_SYMBOL_GPL(dw_hdmi_set_sample_rate); |
| 549 | |
Russell King | b90120a | 2015-03-27 12:59:58 +0000 | [diff] [blame] | 550 | void dw_hdmi_audio_enable(struct dw_hdmi *hdmi) |
| 551 | { |
| 552 | unsigned long flags; |
| 553 | |
| 554 | spin_lock_irqsave(&hdmi->audio_lock, flags); |
| 555 | hdmi->audio_enable = true; |
| 556 | hdmi_set_cts_n(hdmi, hdmi->audio_cts, hdmi->audio_n); |
| 557 | spin_unlock_irqrestore(&hdmi->audio_lock, flags); |
| 558 | } |
| 559 | EXPORT_SYMBOL_GPL(dw_hdmi_audio_enable); |
| 560 | |
| 561 | void dw_hdmi_audio_disable(struct dw_hdmi *hdmi) |
| 562 | { |
| 563 | unsigned long flags; |
| 564 | |
| 565 | spin_lock_irqsave(&hdmi->audio_lock, flags); |
| 566 | hdmi->audio_enable = false; |
| 567 | hdmi_set_cts_n(hdmi, hdmi->audio_cts, 0); |
| 568 | spin_unlock_irqrestore(&hdmi->audio_lock, flags); |
| 569 | } |
| 570 | EXPORT_SYMBOL_GPL(dw_hdmi_audio_disable); |
| 571 | |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 572 | /* |
| 573 | * this submodule is responsible for the video data synchronization. |
| 574 | * for example, for RGB 4:4:4 input, the data map is defined as |
| 575 | * pin{47~40} <==> R[7:0] |
| 576 | * pin{31~24} <==> G[7:0] |
| 577 | * pin{15~8} <==> B[7:0] |
| 578 | */ |
Andy Yan | b21f4b6 | 2014-12-05 14:26:31 +0800 | [diff] [blame] | 579 | static void hdmi_video_sample(struct dw_hdmi *hdmi) |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 580 | { |
| 581 | int color_format = 0; |
| 582 | u8 val; |
| 583 | |
| 584 | if (hdmi->hdmi_data.enc_in_format == RGB) { |
| 585 | if (hdmi->hdmi_data.enc_color_depth == 8) |
| 586 | color_format = 0x01; |
| 587 | else if (hdmi->hdmi_data.enc_color_depth == 10) |
| 588 | color_format = 0x03; |
| 589 | else if (hdmi->hdmi_data.enc_color_depth == 12) |
| 590 | color_format = 0x05; |
| 591 | else if (hdmi->hdmi_data.enc_color_depth == 16) |
| 592 | color_format = 0x07; |
| 593 | else |
| 594 | return; |
| 595 | } else if (hdmi->hdmi_data.enc_in_format == YCBCR444) { |
| 596 | if (hdmi->hdmi_data.enc_color_depth == 8) |
| 597 | color_format = 0x09; |
| 598 | else if (hdmi->hdmi_data.enc_color_depth == 10) |
| 599 | color_format = 0x0B; |
| 600 | else if (hdmi->hdmi_data.enc_color_depth == 12) |
| 601 | color_format = 0x0D; |
| 602 | else if (hdmi->hdmi_data.enc_color_depth == 16) |
| 603 | color_format = 0x0F; |
| 604 | else |
| 605 | return; |
| 606 | } else if (hdmi->hdmi_data.enc_in_format == YCBCR422_8BITS) { |
| 607 | if (hdmi->hdmi_data.enc_color_depth == 8) |
| 608 | color_format = 0x16; |
| 609 | else if (hdmi->hdmi_data.enc_color_depth == 10) |
| 610 | color_format = 0x14; |
| 611 | else if (hdmi->hdmi_data.enc_color_depth == 12) |
| 612 | color_format = 0x12; |
| 613 | else |
| 614 | return; |
| 615 | } |
| 616 | |
| 617 | val = HDMI_TX_INVID0_INTERNAL_DE_GENERATOR_DISABLE | |
| 618 | ((color_format << HDMI_TX_INVID0_VIDEO_MAPPING_OFFSET) & |
| 619 | HDMI_TX_INVID0_VIDEO_MAPPING_MASK); |
| 620 | hdmi_writeb(hdmi, val, HDMI_TX_INVID0); |
| 621 | |
| 622 | /* Enable TX stuffing: When DE is inactive, fix the output data to 0 */ |
| 623 | val = HDMI_TX_INSTUFFING_BDBDATA_STUFFING_ENABLE | |
| 624 | HDMI_TX_INSTUFFING_RCRDATA_STUFFING_ENABLE | |
| 625 | HDMI_TX_INSTUFFING_GYDATA_STUFFING_ENABLE; |
| 626 | hdmi_writeb(hdmi, val, HDMI_TX_INSTUFFING); |
| 627 | hdmi_writeb(hdmi, 0x0, HDMI_TX_GYDATA0); |
| 628 | hdmi_writeb(hdmi, 0x0, HDMI_TX_GYDATA1); |
| 629 | hdmi_writeb(hdmi, 0x0, HDMI_TX_RCRDATA0); |
| 630 | hdmi_writeb(hdmi, 0x0, HDMI_TX_RCRDATA1); |
| 631 | hdmi_writeb(hdmi, 0x0, HDMI_TX_BCBDATA0); |
| 632 | hdmi_writeb(hdmi, 0x0, HDMI_TX_BCBDATA1); |
| 633 | } |
| 634 | |
Andy Yan | b21f4b6 | 2014-12-05 14:26:31 +0800 | [diff] [blame] | 635 | static int is_color_space_conversion(struct dw_hdmi *hdmi) |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 636 | { |
Fabio Estevam | ba92b22 | 2014-02-06 10:12:03 -0200 | [diff] [blame] | 637 | return hdmi->hdmi_data.enc_in_format != hdmi->hdmi_data.enc_out_format; |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 638 | } |
| 639 | |
Andy Yan | b21f4b6 | 2014-12-05 14:26:31 +0800 | [diff] [blame] | 640 | static int is_color_space_decimation(struct dw_hdmi *hdmi) |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 641 | { |
Fabio Estevam | ba92b22 | 2014-02-06 10:12:03 -0200 | [diff] [blame] | 642 | if (hdmi->hdmi_data.enc_out_format != YCBCR422_8BITS) |
| 643 | return 0; |
| 644 | if (hdmi->hdmi_data.enc_in_format == RGB || |
| 645 | hdmi->hdmi_data.enc_in_format == YCBCR444) |
| 646 | return 1; |
| 647 | return 0; |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 648 | } |
| 649 | |
Andy Yan | b21f4b6 | 2014-12-05 14:26:31 +0800 | [diff] [blame] | 650 | static int is_color_space_interpolation(struct dw_hdmi *hdmi) |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 651 | { |
Fabio Estevam | ba92b22 | 2014-02-06 10:12:03 -0200 | [diff] [blame] | 652 | if (hdmi->hdmi_data.enc_in_format != YCBCR422_8BITS) |
| 653 | return 0; |
| 654 | if (hdmi->hdmi_data.enc_out_format == RGB || |
| 655 | hdmi->hdmi_data.enc_out_format == YCBCR444) |
| 656 | return 1; |
| 657 | return 0; |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 658 | } |
| 659 | |
Andy Yan | b21f4b6 | 2014-12-05 14:26:31 +0800 | [diff] [blame] | 660 | static void dw_hdmi_update_csc_coeffs(struct dw_hdmi *hdmi) |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 661 | { |
| 662 | const u16 (*csc_coeff)[3][4] = &csc_coeff_default; |
Russell King | c082f9d | 2013-11-04 12:10:40 +0000 | [diff] [blame] | 663 | unsigned i; |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 664 | u32 csc_scale = 1; |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 665 | |
| 666 | if (is_color_space_conversion(hdmi)) { |
| 667 | if (hdmi->hdmi_data.enc_out_format == RGB) { |
Gulsah Kose | 256a38b | 2014-03-09 20:11:07 +0200 | [diff] [blame] | 668 | if (hdmi->hdmi_data.colorimetry == |
| 669 | HDMI_COLORIMETRY_ITU_601) |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 670 | csc_coeff = &csc_coeff_rgb_out_eitu601; |
| 671 | else |
| 672 | csc_coeff = &csc_coeff_rgb_out_eitu709; |
| 673 | } else if (hdmi->hdmi_data.enc_in_format == RGB) { |
Gulsah Kose | 256a38b | 2014-03-09 20:11:07 +0200 | [diff] [blame] | 674 | if (hdmi->hdmi_data.colorimetry == |
| 675 | HDMI_COLORIMETRY_ITU_601) |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 676 | csc_coeff = &csc_coeff_rgb_in_eitu601; |
| 677 | else |
| 678 | csc_coeff = &csc_coeff_rgb_in_eitu709; |
| 679 | csc_scale = 0; |
| 680 | } |
| 681 | } |
| 682 | |
Russell King | c082f9d | 2013-11-04 12:10:40 +0000 | [diff] [blame] | 683 | /* The CSC registers are sequential, alternating MSB then LSB */ |
| 684 | for (i = 0; i < ARRAY_SIZE(csc_coeff_default[0]); i++) { |
| 685 | u16 coeff_a = (*csc_coeff)[0][i]; |
| 686 | u16 coeff_b = (*csc_coeff)[1][i]; |
| 687 | u16 coeff_c = (*csc_coeff)[2][i]; |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 688 | |
Andy Yan | b587833 | 2014-12-05 14:23:52 +0800 | [diff] [blame] | 689 | hdmi_writeb(hdmi, coeff_a & 0xff, HDMI_CSC_COEF_A1_LSB + i * 2); |
Russell King | c082f9d | 2013-11-04 12:10:40 +0000 | [diff] [blame] | 690 | hdmi_writeb(hdmi, coeff_a >> 8, HDMI_CSC_COEF_A1_MSB + i * 2); |
| 691 | hdmi_writeb(hdmi, coeff_b & 0xff, HDMI_CSC_COEF_B1_LSB + i * 2); |
| 692 | hdmi_writeb(hdmi, coeff_b >> 8, HDMI_CSC_COEF_B1_MSB + i * 2); |
Andy Yan | b587833 | 2014-12-05 14:23:52 +0800 | [diff] [blame] | 693 | hdmi_writeb(hdmi, coeff_c & 0xff, HDMI_CSC_COEF_C1_LSB + i * 2); |
Russell King | c082f9d | 2013-11-04 12:10:40 +0000 | [diff] [blame] | 694 | hdmi_writeb(hdmi, coeff_c >> 8, HDMI_CSC_COEF_C1_MSB + i * 2); |
| 695 | } |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 696 | |
Russell King | 812bc61 | 2013-11-04 12:42:02 +0000 | [diff] [blame] | 697 | hdmi_modb(hdmi, csc_scale, HDMI_CSC_SCALE_CSCSCALE_MASK, |
| 698 | HDMI_CSC_SCALE); |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 699 | } |
| 700 | |
Andy Yan | b21f4b6 | 2014-12-05 14:26:31 +0800 | [diff] [blame] | 701 | static void hdmi_video_csc(struct dw_hdmi *hdmi) |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 702 | { |
| 703 | int color_depth = 0; |
| 704 | int interpolation = HDMI_CSC_CFG_INTMODE_DISABLE; |
| 705 | int decimation = 0; |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 706 | |
| 707 | /* YCC422 interpolation to 444 mode */ |
| 708 | if (is_color_space_interpolation(hdmi)) |
| 709 | interpolation = HDMI_CSC_CFG_INTMODE_CHROMA_INT_FORMULA1; |
| 710 | else if (is_color_space_decimation(hdmi)) |
| 711 | decimation = HDMI_CSC_CFG_DECMODE_CHROMA_INT_FORMULA3; |
| 712 | |
| 713 | if (hdmi->hdmi_data.enc_color_depth == 8) |
| 714 | color_depth = HDMI_CSC_SCALE_CSC_COLORDE_PTH_24BPP; |
| 715 | else if (hdmi->hdmi_data.enc_color_depth == 10) |
| 716 | color_depth = HDMI_CSC_SCALE_CSC_COLORDE_PTH_30BPP; |
| 717 | else if (hdmi->hdmi_data.enc_color_depth == 12) |
| 718 | color_depth = HDMI_CSC_SCALE_CSC_COLORDE_PTH_36BPP; |
| 719 | else if (hdmi->hdmi_data.enc_color_depth == 16) |
| 720 | color_depth = HDMI_CSC_SCALE_CSC_COLORDE_PTH_48BPP; |
| 721 | else |
| 722 | return; |
| 723 | |
| 724 | /* Configure the CSC registers */ |
| 725 | hdmi_writeb(hdmi, interpolation | decimation, HDMI_CSC_CFG); |
Russell King | 812bc61 | 2013-11-04 12:42:02 +0000 | [diff] [blame] | 726 | hdmi_modb(hdmi, color_depth, HDMI_CSC_SCALE_CSC_COLORDE_PTH_MASK, |
| 727 | HDMI_CSC_SCALE); |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 728 | |
Andy Yan | b21f4b6 | 2014-12-05 14:26:31 +0800 | [diff] [blame] | 729 | dw_hdmi_update_csc_coeffs(hdmi); |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 730 | } |
| 731 | |
| 732 | /* |
| 733 | * HDMI video packetizer is used to packetize the data. |
| 734 | * for example, if input is YCC422 mode or repeater is used, |
| 735 | * data should be repacked this module can be bypassed. |
| 736 | */ |
Andy Yan | b21f4b6 | 2014-12-05 14:26:31 +0800 | [diff] [blame] | 737 | static void hdmi_video_packetize(struct dw_hdmi *hdmi) |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 738 | { |
| 739 | unsigned int color_depth = 0; |
| 740 | unsigned int remap_size = HDMI_VP_REMAP_YCC422_16bit; |
| 741 | unsigned int output_select = HDMI_VP_CONF_OUTPUT_SELECTOR_PP; |
| 742 | struct hdmi_data_info *hdmi_data = &hdmi->hdmi_data; |
Russell King | bebdf66 | 2013-11-04 12:55:30 +0000 | [diff] [blame] | 743 | u8 val, vp_conf; |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 744 | |
Andy Yan | b587833 | 2014-12-05 14:23:52 +0800 | [diff] [blame] | 745 | if (hdmi_data->enc_out_format == RGB || |
| 746 | hdmi_data->enc_out_format == YCBCR444) { |
| 747 | if (!hdmi_data->enc_color_depth) { |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 748 | output_select = HDMI_VP_CONF_OUTPUT_SELECTOR_BYPASS; |
Andy Yan | b587833 | 2014-12-05 14:23:52 +0800 | [diff] [blame] | 749 | } else if (hdmi_data->enc_color_depth == 8) { |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 750 | color_depth = 4; |
| 751 | output_select = HDMI_VP_CONF_OUTPUT_SELECTOR_BYPASS; |
Andy Yan | b587833 | 2014-12-05 14:23:52 +0800 | [diff] [blame] | 752 | } else if (hdmi_data->enc_color_depth == 10) { |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 753 | color_depth = 5; |
Andy Yan | b587833 | 2014-12-05 14:23:52 +0800 | [diff] [blame] | 754 | } else if (hdmi_data->enc_color_depth == 12) { |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 755 | color_depth = 6; |
Andy Yan | b587833 | 2014-12-05 14:23:52 +0800 | [diff] [blame] | 756 | } else if (hdmi_data->enc_color_depth == 16) { |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 757 | color_depth = 7; |
Andy Yan | b587833 | 2014-12-05 14:23:52 +0800 | [diff] [blame] | 758 | } else { |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 759 | return; |
Andy Yan | b587833 | 2014-12-05 14:23:52 +0800 | [diff] [blame] | 760 | } |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 761 | } else if (hdmi_data->enc_out_format == YCBCR422_8BITS) { |
| 762 | if (!hdmi_data->enc_color_depth || |
| 763 | hdmi_data->enc_color_depth == 8) |
| 764 | remap_size = HDMI_VP_REMAP_YCC422_16bit; |
| 765 | else if (hdmi_data->enc_color_depth == 10) |
| 766 | remap_size = HDMI_VP_REMAP_YCC422_20bit; |
| 767 | else if (hdmi_data->enc_color_depth == 12) |
| 768 | remap_size = HDMI_VP_REMAP_YCC422_24bit; |
| 769 | else |
| 770 | return; |
| 771 | output_select = HDMI_VP_CONF_OUTPUT_SELECTOR_YCC422; |
Andy Yan | b587833 | 2014-12-05 14:23:52 +0800 | [diff] [blame] | 772 | } else { |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 773 | return; |
Andy Yan | b587833 | 2014-12-05 14:23:52 +0800 | [diff] [blame] | 774 | } |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 775 | |
| 776 | /* set the packetizer registers */ |
| 777 | val = ((color_depth << HDMI_VP_PR_CD_COLOR_DEPTH_OFFSET) & |
| 778 | HDMI_VP_PR_CD_COLOR_DEPTH_MASK) | |
| 779 | ((hdmi_data->pix_repet_factor << |
| 780 | HDMI_VP_PR_CD_DESIRED_PR_FACTOR_OFFSET) & |
| 781 | HDMI_VP_PR_CD_DESIRED_PR_FACTOR_MASK); |
| 782 | hdmi_writeb(hdmi, val, HDMI_VP_PR_CD); |
| 783 | |
Russell King | 812bc61 | 2013-11-04 12:42:02 +0000 | [diff] [blame] | 784 | hdmi_modb(hdmi, HDMI_VP_STUFF_PR_STUFFING_STUFFING_MODE, |
| 785 | HDMI_VP_STUFF_PR_STUFFING_MASK, HDMI_VP_STUFF); |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 786 | |
| 787 | /* Data from pixel repeater block */ |
| 788 | if (hdmi_data->pix_repet_factor > 1) { |
Russell King | bebdf66 | 2013-11-04 12:55:30 +0000 | [diff] [blame] | 789 | vp_conf = HDMI_VP_CONF_PR_EN_ENABLE | |
| 790 | HDMI_VP_CONF_BYPASS_SELECT_PIX_REPEATER; |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 791 | } else { /* data from packetizer block */ |
Russell King | bebdf66 | 2013-11-04 12:55:30 +0000 | [diff] [blame] | 792 | vp_conf = HDMI_VP_CONF_PR_EN_DISABLE | |
| 793 | HDMI_VP_CONF_BYPASS_SELECT_VID_PACKETIZER; |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 794 | } |
| 795 | |
Russell King | bebdf66 | 2013-11-04 12:55:30 +0000 | [diff] [blame] | 796 | hdmi_modb(hdmi, vp_conf, |
| 797 | HDMI_VP_CONF_PR_EN_MASK | |
| 798 | HDMI_VP_CONF_BYPASS_SELECT_MASK, HDMI_VP_CONF); |
| 799 | |
Russell King | 812bc61 | 2013-11-04 12:42:02 +0000 | [diff] [blame] | 800 | hdmi_modb(hdmi, 1 << HDMI_VP_STUFF_IDEFAULT_PHASE_OFFSET, |
| 801 | HDMI_VP_STUFF_IDEFAULT_PHASE_MASK, HDMI_VP_STUFF); |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 802 | |
| 803 | hdmi_writeb(hdmi, remap_size, HDMI_VP_REMAP); |
| 804 | |
| 805 | if (output_select == HDMI_VP_CONF_OUTPUT_SELECTOR_PP) { |
Russell King | bebdf66 | 2013-11-04 12:55:30 +0000 | [diff] [blame] | 806 | vp_conf = HDMI_VP_CONF_BYPASS_EN_DISABLE | |
| 807 | HDMI_VP_CONF_PP_EN_ENABLE | |
| 808 | HDMI_VP_CONF_YCC422_EN_DISABLE; |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 809 | } else if (output_select == HDMI_VP_CONF_OUTPUT_SELECTOR_YCC422) { |
Russell King | bebdf66 | 2013-11-04 12:55:30 +0000 | [diff] [blame] | 810 | vp_conf = HDMI_VP_CONF_BYPASS_EN_DISABLE | |
| 811 | HDMI_VP_CONF_PP_EN_DISABLE | |
| 812 | HDMI_VP_CONF_YCC422_EN_ENABLE; |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 813 | } else if (output_select == HDMI_VP_CONF_OUTPUT_SELECTOR_BYPASS) { |
Russell King | bebdf66 | 2013-11-04 12:55:30 +0000 | [diff] [blame] | 814 | vp_conf = HDMI_VP_CONF_BYPASS_EN_ENABLE | |
| 815 | HDMI_VP_CONF_PP_EN_DISABLE | |
| 816 | HDMI_VP_CONF_YCC422_EN_DISABLE; |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 817 | } else { |
| 818 | return; |
| 819 | } |
| 820 | |
Russell King | bebdf66 | 2013-11-04 12:55:30 +0000 | [diff] [blame] | 821 | hdmi_modb(hdmi, vp_conf, |
| 822 | HDMI_VP_CONF_BYPASS_EN_MASK | HDMI_VP_CONF_PP_EN_ENMASK | |
| 823 | HDMI_VP_CONF_YCC422_EN_MASK, HDMI_VP_CONF); |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 824 | |
Russell King | 812bc61 | 2013-11-04 12:42:02 +0000 | [diff] [blame] | 825 | hdmi_modb(hdmi, HDMI_VP_STUFF_PP_STUFFING_STUFFING_MODE | |
| 826 | HDMI_VP_STUFF_YCC422_STUFFING_STUFFING_MODE, |
| 827 | HDMI_VP_STUFF_PP_STUFFING_MASK | |
| 828 | HDMI_VP_STUFF_YCC422_STUFFING_MASK, HDMI_VP_STUFF); |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 829 | |
Russell King | 812bc61 | 2013-11-04 12:42:02 +0000 | [diff] [blame] | 830 | hdmi_modb(hdmi, output_select, HDMI_VP_CONF_OUTPUT_SELECTOR_MASK, |
| 831 | HDMI_VP_CONF); |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 832 | } |
| 833 | |
Andy Yan | b21f4b6 | 2014-12-05 14:26:31 +0800 | [diff] [blame] | 834 | static inline void hdmi_phy_test_clear(struct dw_hdmi *hdmi, |
Andy Yan | b587833 | 2014-12-05 14:23:52 +0800 | [diff] [blame] | 835 | unsigned char bit) |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 836 | { |
Russell King | 812bc61 | 2013-11-04 12:42:02 +0000 | [diff] [blame] | 837 | hdmi_modb(hdmi, bit << HDMI_PHY_TST0_TSTCLR_OFFSET, |
| 838 | HDMI_PHY_TST0_TSTCLR_MASK, HDMI_PHY_TST0); |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 839 | } |
| 840 | |
Andy Yan | b21f4b6 | 2014-12-05 14:26:31 +0800 | [diff] [blame] | 841 | static bool hdmi_phy_wait_i2c_done(struct dw_hdmi *hdmi, int msec) |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 842 | { |
Andy Yan | a4d3b8b | 2014-12-05 14:31:09 +0800 | [diff] [blame] | 843 | u32 val; |
| 844 | |
| 845 | while ((val = hdmi_readb(hdmi, HDMI_IH_I2CMPHY_STAT0) & 0x3) == 0) { |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 846 | if (msec-- == 0) |
| 847 | return false; |
Emil Renner Berthing | 0e6bcf3 | 2014-03-30 00:21:21 +0100 | [diff] [blame] | 848 | udelay(1000); |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 849 | } |
Andy Yan | a4d3b8b | 2014-12-05 14:31:09 +0800 | [diff] [blame] | 850 | hdmi_writeb(hdmi, val, HDMI_IH_I2CMPHY_STAT0); |
| 851 | |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 852 | return true; |
| 853 | } |
| 854 | |
Laurent Pinchart | cc7e962 | 2017-01-17 10:28:51 +0200 | [diff] [blame] | 855 | static void hdmi_phy_i2c_write(struct dw_hdmi *hdmi, unsigned short data, |
Andy Yan | b587833 | 2014-12-05 14:23:52 +0800 | [diff] [blame] | 856 | unsigned char addr) |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 857 | { |
| 858 | hdmi_writeb(hdmi, 0xFF, HDMI_IH_I2CMPHY_STAT0); |
| 859 | hdmi_writeb(hdmi, addr, HDMI_PHY_I2CM_ADDRESS_ADDR); |
| 860 | hdmi_writeb(hdmi, (unsigned char)(data >> 8), |
Andy Yan | b587833 | 2014-12-05 14:23:52 +0800 | [diff] [blame] | 861 | HDMI_PHY_I2CM_DATAO_1_ADDR); |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 862 | hdmi_writeb(hdmi, (unsigned char)(data >> 0), |
Andy Yan | b587833 | 2014-12-05 14:23:52 +0800 | [diff] [blame] | 863 | HDMI_PHY_I2CM_DATAO_0_ADDR); |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 864 | hdmi_writeb(hdmi, HDMI_PHY_I2CM_OPERATION_ADDR_WRITE, |
Andy Yan | b587833 | 2014-12-05 14:23:52 +0800 | [diff] [blame] | 865 | HDMI_PHY_I2CM_OPERATION_ADDR); |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 866 | hdmi_phy_wait_i2c_done(hdmi, 1000); |
| 867 | } |
| 868 | |
Russell King | 2fada10 | 2015-07-28 12:21:34 +0100 | [diff] [blame] | 869 | static void dw_hdmi_phy_enable_powerdown(struct dw_hdmi *hdmi, bool enable) |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 870 | { |
Russell King | 2fada10 | 2015-07-28 12:21:34 +0100 | [diff] [blame] | 871 | hdmi_mask_writeb(hdmi, !enable, HDMI_PHY_CONF0, |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 872 | HDMI_PHY_CONF0_PDZ_OFFSET, |
| 873 | HDMI_PHY_CONF0_PDZ_MASK); |
| 874 | } |
| 875 | |
Andy Yan | b21f4b6 | 2014-12-05 14:26:31 +0800 | [diff] [blame] | 876 | static void dw_hdmi_phy_enable_tmds(struct dw_hdmi *hdmi, u8 enable) |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 877 | { |
| 878 | hdmi_mask_writeb(hdmi, enable, HDMI_PHY_CONF0, |
| 879 | HDMI_PHY_CONF0_ENTMDS_OFFSET, |
| 880 | HDMI_PHY_CONF0_ENTMDS_MASK); |
| 881 | } |
| 882 | |
Laurent Pinchart | f4104e8 | 2017-01-17 10:29:02 +0200 | [diff] [blame] | 883 | static void dw_hdmi_phy_enable_svsret(struct dw_hdmi *hdmi, u8 enable) |
Andy Yan | d346c14 | 2014-12-05 14:31:53 +0800 | [diff] [blame] | 884 | { |
| 885 | hdmi_mask_writeb(hdmi, enable, HDMI_PHY_CONF0, |
Laurent Pinchart | f4104e8 | 2017-01-17 10:29:02 +0200 | [diff] [blame] | 886 | HDMI_PHY_CONF0_SVSRET_OFFSET, |
| 887 | HDMI_PHY_CONF0_SVSRET_MASK); |
Andy Yan | d346c14 | 2014-12-05 14:31:53 +0800 | [diff] [blame] | 888 | } |
| 889 | |
Andy Yan | b21f4b6 | 2014-12-05 14:26:31 +0800 | [diff] [blame] | 890 | static void dw_hdmi_phy_gen2_pddq(struct dw_hdmi *hdmi, u8 enable) |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 891 | { |
| 892 | hdmi_mask_writeb(hdmi, enable, HDMI_PHY_CONF0, |
| 893 | HDMI_PHY_CONF0_GEN2_PDDQ_OFFSET, |
| 894 | HDMI_PHY_CONF0_GEN2_PDDQ_MASK); |
| 895 | } |
| 896 | |
Andy Yan | b21f4b6 | 2014-12-05 14:26:31 +0800 | [diff] [blame] | 897 | static void dw_hdmi_phy_gen2_txpwron(struct dw_hdmi *hdmi, u8 enable) |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 898 | { |
| 899 | hdmi_mask_writeb(hdmi, enable, HDMI_PHY_CONF0, |
| 900 | HDMI_PHY_CONF0_GEN2_TXPWRON_OFFSET, |
| 901 | HDMI_PHY_CONF0_GEN2_TXPWRON_MASK); |
| 902 | } |
| 903 | |
Andy Yan | b21f4b6 | 2014-12-05 14:26:31 +0800 | [diff] [blame] | 904 | static void dw_hdmi_phy_sel_data_en_pol(struct dw_hdmi *hdmi, u8 enable) |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 905 | { |
| 906 | hdmi_mask_writeb(hdmi, enable, HDMI_PHY_CONF0, |
| 907 | HDMI_PHY_CONF0_SELDATAENPOL_OFFSET, |
| 908 | HDMI_PHY_CONF0_SELDATAENPOL_MASK); |
| 909 | } |
| 910 | |
Andy Yan | b21f4b6 | 2014-12-05 14:26:31 +0800 | [diff] [blame] | 911 | static void dw_hdmi_phy_sel_interface_control(struct dw_hdmi *hdmi, u8 enable) |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 912 | { |
| 913 | hdmi_mask_writeb(hdmi, enable, HDMI_PHY_CONF0, |
| 914 | HDMI_PHY_CONF0_SELDIPIF_OFFSET, |
| 915 | HDMI_PHY_CONF0_SELDIPIF_MASK); |
| 916 | } |
| 917 | |
Laurent Pinchart | b0e583e | 2017-03-06 01:35:39 +0200 | [diff] [blame^] | 918 | static void dw_hdmi_phy_power_off(struct dw_hdmi *hdmi) |
| 919 | { |
| 920 | const struct dw_hdmi_phy_data *phy = hdmi->phy; |
| 921 | unsigned int i; |
| 922 | u16 val; |
| 923 | |
| 924 | if (phy->gen == 1) { |
| 925 | dw_hdmi_phy_enable_tmds(hdmi, 0); |
| 926 | dw_hdmi_phy_enable_powerdown(hdmi, true); |
| 927 | return; |
| 928 | } |
| 929 | |
| 930 | dw_hdmi_phy_gen2_txpwron(hdmi, 0); |
| 931 | |
| 932 | /* |
| 933 | * Wait for TX_PHY_LOCK to be deasserted to indicate that the PHY went |
| 934 | * to low power mode. |
| 935 | */ |
| 936 | for (i = 0; i < 5; ++i) { |
| 937 | val = hdmi_readb(hdmi, HDMI_PHY_STAT0); |
| 938 | if (!(val & HDMI_PHY_TX_PHY_LOCK)) |
| 939 | break; |
| 940 | |
| 941 | usleep_range(1000, 2000); |
| 942 | } |
| 943 | |
| 944 | if (val & HDMI_PHY_TX_PHY_LOCK) |
| 945 | dev_warn(hdmi->dev, "PHY failed to power down\n"); |
| 946 | else |
| 947 | dev_dbg(hdmi->dev, "PHY powered down in %u iterations\n", i); |
| 948 | |
| 949 | dw_hdmi_phy_gen2_pddq(hdmi, 1); |
| 950 | } |
| 951 | |
Laurent Pinchart | 8b9e1c0 | 2017-03-03 19:19:59 +0200 | [diff] [blame] | 952 | static int hdmi_phy_configure(struct dw_hdmi *hdmi) |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 953 | { |
| 954 | u8 val, msec; |
Russell King | 39cc153 | 2015-03-31 18:34:11 +0100 | [diff] [blame] | 955 | const struct dw_hdmi_plat_data *pdata = hdmi->plat_data; |
| 956 | const struct dw_hdmi_mpll_config *mpll_config = pdata->mpll_cfg; |
| 957 | const struct dw_hdmi_curr_ctrl *curr_ctrl = pdata->cur_ctr; |
| 958 | const struct dw_hdmi_phy_config *phy_config = pdata->phy_config; |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 959 | |
Russell King | 39cc153 | 2015-03-31 18:34:11 +0100 | [diff] [blame] | 960 | /* PLL/MPLL Cfg - always match on final entry */ |
| 961 | for (; mpll_config->mpixelclock != ~0UL; mpll_config++) |
| 962 | if (hdmi->hdmi_data.video_mode.mpixelclock <= |
| 963 | mpll_config->mpixelclock) |
| 964 | break; |
| 965 | |
| 966 | for (; curr_ctrl->mpixelclock != ~0UL; curr_ctrl++) |
| 967 | if (hdmi->hdmi_data.video_mode.mpixelclock <= |
| 968 | curr_ctrl->mpixelclock) |
| 969 | break; |
| 970 | |
| 971 | for (; phy_config->mpixelclock != ~0UL; phy_config++) |
| 972 | if (hdmi->hdmi_data.video_mode.mpixelclock <= |
| 973 | phy_config->mpixelclock) |
| 974 | break; |
| 975 | |
| 976 | if (mpll_config->mpixelclock == ~0UL || |
| 977 | curr_ctrl->mpixelclock == ~0UL || |
| 978 | phy_config->mpixelclock == ~0UL) { |
| 979 | dev_err(hdmi->dev, "Pixel clock %d - unsupported by HDMI\n", |
| 980 | hdmi->hdmi_data.video_mode.mpixelclock); |
| 981 | return -EINVAL; |
| 982 | } |
| 983 | |
Laurent Pinchart | b0e583e | 2017-03-06 01:35:39 +0200 | [diff] [blame^] | 984 | dw_hdmi_phy_power_off(hdmi); |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 985 | |
Laurent Pinchart | 2668db3 | 2017-01-17 10:29:09 +0200 | [diff] [blame] | 986 | /* Leave low power consumption mode by asserting SVSRET. */ |
| 987 | if (hdmi->phy->has_svsret) |
| 988 | dw_hdmi_phy_enable_svsret(hdmi, 1); |
| 989 | |
Laurent Pinchart | 54d7273 | 2017-01-17 10:29:08 +0200 | [diff] [blame] | 990 | /* PHY reset. The reset signal is active high on Gen2 PHYs. */ |
| 991 | hdmi_writeb(hdmi, HDMI_MC_PHYRSTZ_PHYRSTZ, HDMI_MC_PHYRSTZ); |
| 992 | hdmi_writeb(hdmi, 0, HDMI_MC_PHYRSTZ); |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 993 | |
| 994 | hdmi_writeb(hdmi, HDMI_MC_HEACPHY_RST_ASSERT, HDMI_MC_HEACPHY_RST); |
| 995 | |
| 996 | hdmi_phy_test_clear(hdmi, 1); |
| 997 | hdmi_writeb(hdmi, HDMI_PHY_I2CM_SLAVE_ADDR_PHY_GEN2, |
Andy Yan | b587833 | 2014-12-05 14:23:52 +0800 | [diff] [blame] | 998 | HDMI_PHY_I2CM_SLAVE_ADDR); |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 999 | hdmi_phy_test_clear(hdmi, 0); |
| 1000 | |
Laurent Pinchart | f0e7f2f | 2017-01-17 10:29:07 +0200 | [diff] [blame] | 1001 | hdmi_phy_i2c_write(hdmi, mpll_config->res[0].cpce, |
| 1002 | HDMI_3D_TX_PHY_CPCE_CTRL); |
| 1003 | hdmi_phy_i2c_write(hdmi, mpll_config->res[0].gmp, |
| 1004 | HDMI_3D_TX_PHY_GMPCTRL); |
| 1005 | hdmi_phy_i2c_write(hdmi, curr_ctrl->curr[0], |
| 1006 | HDMI_3D_TX_PHY_CURRCTRL); |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1007 | |
Laurent Pinchart | f0e7f2f | 2017-01-17 10:29:07 +0200 | [diff] [blame] | 1008 | hdmi_phy_i2c_write(hdmi, 0, HDMI_3D_TX_PHY_PLLPHBYCTRL); |
| 1009 | hdmi_phy_i2c_write(hdmi, HDMI_3D_TX_PHY_MSM_CTRL_CKO_SEL_FB_CLK, |
| 1010 | HDMI_3D_TX_PHY_MSM_CTRL); |
Russell King | 3e46f15 | 2013-11-04 11:24:00 +0000 | [diff] [blame] | 1011 | |
Laurent Pinchart | f0e7f2f | 2017-01-17 10:29:07 +0200 | [diff] [blame] | 1012 | hdmi_phy_i2c_write(hdmi, phy_config->term, HDMI_3D_TX_PHY_TXTERM); |
| 1013 | hdmi_phy_i2c_write(hdmi, phy_config->sym_ctr, |
| 1014 | HDMI_3D_TX_PHY_CKSYMTXCTRL); |
| 1015 | hdmi_phy_i2c_write(hdmi, phy_config->vlev_ctr, |
| 1016 | HDMI_3D_TX_PHY_VLEVCTRL); |
Andy Yan | aaa757a | 2014-12-05 14:25:50 +0800 | [diff] [blame] | 1017 | |
Laurent Pinchart | f0e7f2f | 2017-01-17 10:29:07 +0200 | [diff] [blame] | 1018 | /* Override and disable clock termination. */ |
| 1019 | hdmi_phy_i2c_write(hdmi, HDMI_3D_TX_PHY_CKCALCTRL_OVERRIDE, |
| 1020 | HDMI_3D_TX_PHY_CKCALCTRL); |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1021 | |
Russell King | 2fada10 | 2015-07-28 12:21:34 +0100 | [diff] [blame] | 1022 | dw_hdmi_phy_enable_powerdown(hdmi, false); |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1023 | |
| 1024 | /* toggle TMDS enable */ |
Andy Yan | b21f4b6 | 2014-12-05 14:26:31 +0800 | [diff] [blame] | 1025 | dw_hdmi_phy_enable_tmds(hdmi, 0); |
| 1026 | dw_hdmi_phy_enable_tmds(hdmi, 1); |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1027 | |
| 1028 | /* gen2 tx power on */ |
Andy Yan | b21f4b6 | 2014-12-05 14:26:31 +0800 | [diff] [blame] | 1029 | dw_hdmi_phy_gen2_txpwron(hdmi, 1); |
| 1030 | dw_hdmi_phy_gen2_pddq(hdmi, 0); |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1031 | |
Laurent Pinchart | 2668db3 | 2017-01-17 10:29:09 +0200 | [diff] [blame] | 1032 | /* Wait for PHY PLL lock */ |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1033 | msec = 5; |
| 1034 | do { |
| 1035 | val = hdmi_readb(hdmi, HDMI_PHY_STAT0) & HDMI_PHY_TX_PHY_LOCK; |
| 1036 | if (!val) |
| 1037 | break; |
| 1038 | |
| 1039 | if (msec == 0) { |
| 1040 | dev_err(hdmi->dev, "PHY PLL not locked\n"); |
| 1041 | return -ETIMEDOUT; |
| 1042 | } |
| 1043 | |
| 1044 | udelay(1000); |
| 1045 | msec--; |
| 1046 | } while (1); |
| 1047 | |
| 1048 | return 0; |
| 1049 | } |
| 1050 | |
Andy Yan | b21f4b6 | 2014-12-05 14:26:31 +0800 | [diff] [blame] | 1051 | static int dw_hdmi_phy_init(struct dw_hdmi *hdmi) |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1052 | { |
| 1053 | int i, ret; |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1054 | |
| 1055 | /* HDMI Phy spec says to do the phy initialization sequence twice */ |
| 1056 | for (i = 0; i < 2; i++) { |
Andy Yan | b21f4b6 | 2014-12-05 14:26:31 +0800 | [diff] [blame] | 1057 | dw_hdmi_phy_sel_data_en_pol(hdmi, 1); |
| 1058 | dw_hdmi_phy_sel_interface_control(hdmi, 0); |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1059 | |
Laurent Pinchart | 8b9e1c0 | 2017-03-03 19:19:59 +0200 | [diff] [blame] | 1060 | ret = hdmi_phy_configure(hdmi); |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1061 | if (ret) |
| 1062 | return ret; |
| 1063 | } |
| 1064 | |
| 1065 | hdmi->phy_enabled = true; |
| 1066 | return 0; |
| 1067 | } |
| 1068 | |
Andy Yan | b21f4b6 | 2014-12-05 14:26:31 +0800 | [diff] [blame] | 1069 | static void hdmi_tx_hdcp_config(struct dw_hdmi *hdmi) |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1070 | { |
Russell King | 812bc61 | 2013-11-04 12:42:02 +0000 | [diff] [blame] | 1071 | u8 de; |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1072 | |
| 1073 | if (hdmi->hdmi_data.video_mode.mdataenablepolarity) |
| 1074 | de = HDMI_A_VIDPOLCFG_DATAENPOL_ACTIVE_HIGH; |
| 1075 | else |
| 1076 | de = HDMI_A_VIDPOLCFG_DATAENPOL_ACTIVE_LOW; |
| 1077 | |
| 1078 | /* disable rx detect */ |
Russell King | 812bc61 | 2013-11-04 12:42:02 +0000 | [diff] [blame] | 1079 | hdmi_modb(hdmi, HDMI_A_HDCPCFG0_RXDETECT_DISABLE, |
| 1080 | HDMI_A_HDCPCFG0_RXDETECT_MASK, HDMI_A_HDCPCFG0); |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1081 | |
Russell King | 812bc61 | 2013-11-04 12:42:02 +0000 | [diff] [blame] | 1082 | hdmi_modb(hdmi, de, HDMI_A_VIDPOLCFG_DATAENPOL_MASK, HDMI_A_VIDPOLCFG); |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1083 | |
Russell King | 812bc61 | 2013-11-04 12:42:02 +0000 | [diff] [blame] | 1084 | hdmi_modb(hdmi, HDMI_A_HDCPCFG1_ENCRYPTIONDISABLE_DISABLE, |
| 1085 | HDMI_A_HDCPCFG1_ENCRYPTIONDISABLE_MASK, HDMI_A_HDCPCFG1); |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1086 | } |
| 1087 | |
Russell King | d4ac4cb | 2015-03-27 20:06:50 +0000 | [diff] [blame] | 1088 | static void hdmi_config_AVI(struct dw_hdmi *hdmi, struct drm_display_mode *mode) |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1089 | { |
Russell King | d4ac4cb | 2015-03-27 20:06:50 +0000 | [diff] [blame] | 1090 | struct hdmi_avi_infoframe frame; |
| 1091 | u8 val; |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1092 | |
Russell King | d4ac4cb | 2015-03-27 20:06:50 +0000 | [diff] [blame] | 1093 | /* Initialise info frame from DRM mode */ |
| 1094 | drm_hdmi_avi_infoframe_from_display_mode(&frame, mode); |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1095 | |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1096 | if (hdmi->hdmi_data.enc_out_format == YCBCR444) |
Russell King | d4ac4cb | 2015-03-27 20:06:50 +0000 | [diff] [blame] | 1097 | frame.colorspace = HDMI_COLORSPACE_YUV444; |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1098 | else if (hdmi->hdmi_data.enc_out_format == YCBCR422_8BITS) |
Russell King | d4ac4cb | 2015-03-27 20:06:50 +0000 | [diff] [blame] | 1099 | frame.colorspace = HDMI_COLORSPACE_YUV422; |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1100 | else |
Russell King | d4ac4cb | 2015-03-27 20:06:50 +0000 | [diff] [blame] | 1101 | frame.colorspace = HDMI_COLORSPACE_RGB; |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1102 | |
| 1103 | /* Set up colorimetry */ |
| 1104 | if (hdmi->hdmi_data.enc_out_format == XVYCC444) { |
Russell King | d4ac4cb | 2015-03-27 20:06:50 +0000 | [diff] [blame] | 1105 | frame.colorimetry = HDMI_COLORIMETRY_EXTENDED; |
Sachin Kamat | 5a819ed | 2014-01-28 10:33:16 +0530 | [diff] [blame] | 1106 | if (hdmi->hdmi_data.colorimetry == HDMI_COLORIMETRY_ITU_601) |
Russell King | d4ac4cb | 2015-03-27 20:06:50 +0000 | [diff] [blame] | 1107 | frame.extended_colorimetry = |
| 1108 | HDMI_EXTENDED_COLORIMETRY_XV_YCC_601; |
Sachin Kamat | 5a819ed | 2014-01-28 10:33:16 +0530 | [diff] [blame] | 1109 | else /*hdmi->hdmi_data.colorimetry == HDMI_COLORIMETRY_ITU_709*/ |
Russell King | d4ac4cb | 2015-03-27 20:06:50 +0000 | [diff] [blame] | 1110 | frame.extended_colorimetry = |
| 1111 | HDMI_EXTENDED_COLORIMETRY_XV_YCC_709; |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1112 | } else if (hdmi->hdmi_data.enc_out_format != RGB) { |
Russell King | d083c31 | 2015-03-27 23:14:16 +0000 | [diff] [blame] | 1113 | frame.colorimetry = hdmi->hdmi_data.colorimetry; |
Russell King | d4ac4cb | 2015-03-27 20:06:50 +0000 | [diff] [blame] | 1114 | frame.extended_colorimetry = HDMI_EXTENDED_COLORIMETRY_XV_YCC_601; |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1115 | } else { /* Carries no data */ |
Russell King | d4ac4cb | 2015-03-27 20:06:50 +0000 | [diff] [blame] | 1116 | frame.colorimetry = HDMI_COLORIMETRY_NONE; |
| 1117 | frame.extended_colorimetry = HDMI_EXTENDED_COLORIMETRY_XV_YCC_601; |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1118 | } |
| 1119 | |
Russell King | d4ac4cb | 2015-03-27 20:06:50 +0000 | [diff] [blame] | 1120 | frame.scan_mode = HDMI_SCAN_MODE_NONE; |
| 1121 | |
| 1122 | /* |
| 1123 | * The Designware IP uses a different byte format from standard |
| 1124 | * AVI info frames, though generally the bits are in the correct |
| 1125 | * bytes. |
| 1126 | */ |
| 1127 | |
| 1128 | /* |
Jose Abreu | b0118e7 | 2016-08-29 10:30:51 +0100 | [diff] [blame] | 1129 | * AVI data byte 1 differences: Colorspace in bits 0,1 rather than 5,6, |
| 1130 | * scan info in bits 4,5 rather than 0,1 and active aspect present in |
| 1131 | * bit 6 rather than 4. |
Russell King | d4ac4cb | 2015-03-27 20:06:50 +0000 | [diff] [blame] | 1132 | */ |
Jose Abreu | b0118e7 | 2016-08-29 10:30:51 +0100 | [diff] [blame] | 1133 | val = (frame.scan_mode & 3) << 4 | (frame.colorspace & 3); |
Russell King | d4ac4cb | 2015-03-27 20:06:50 +0000 | [diff] [blame] | 1134 | if (frame.active_aspect & 15) |
| 1135 | val |= HDMI_FC_AVICONF0_ACTIVE_FMT_INFO_PRESENT; |
| 1136 | if (frame.top_bar || frame.bottom_bar) |
| 1137 | val |= HDMI_FC_AVICONF0_BAR_DATA_HORIZ_BAR; |
| 1138 | if (frame.left_bar || frame.right_bar) |
| 1139 | val |= HDMI_FC_AVICONF0_BAR_DATA_VERT_BAR; |
| 1140 | hdmi_writeb(hdmi, val, HDMI_FC_AVICONF0); |
| 1141 | |
| 1142 | /* AVI data byte 2 differences: none */ |
| 1143 | val = ((frame.colorimetry & 0x3) << 6) | |
| 1144 | ((frame.picture_aspect & 0x3) << 4) | |
| 1145 | (frame.active_aspect & 0xf); |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1146 | hdmi_writeb(hdmi, val, HDMI_FC_AVICONF1); |
| 1147 | |
Russell King | d4ac4cb | 2015-03-27 20:06:50 +0000 | [diff] [blame] | 1148 | /* AVI data byte 3 differences: none */ |
| 1149 | val = ((frame.extended_colorimetry & 0x7) << 4) | |
| 1150 | ((frame.quantization_range & 0x3) << 2) | |
| 1151 | (frame.nups & 0x3); |
| 1152 | if (frame.itc) |
| 1153 | val |= HDMI_FC_AVICONF2_IT_CONTENT_VALID; |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1154 | hdmi_writeb(hdmi, val, HDMI_FC_AVICONF2); |
| 1155 | |
Russell King | d4ac4cb | 2015-03-27 20:06:50 +0000 | [diff] [blame] | 1156 | /* AVI data byte 4 differences: none */ |
| 1157 | val = frame.video_code & 0x7f; |
| 1158 | hdmi_writeb(hdmi, val, HDMI_FC_AVIVID); |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1159 | |
| 1160 | /* AVI Data Byte 5- set up input and output pixel repetition */ |
| 1161 | val = (((hdmi->hdmi_data.video_mode.mpixelrepetitioninput + 1) << |
| 1162 | HDMI_FC_PRCONF_INCOMING_PR_FACTOR_OFFSET) & |
| 1163 | HDMI_FC_PRCONF_INCOMING_PR_FACTOR_MASK) | |
| 1164 | ((hdmi->hdmi_data.video_mode.mpixelrepetitionoutput << |
| 1165 | HDMI_FC_PRCONF_OUTPUT_PR_FACTOR_OFFSET) & |
| 1166 | HDMI_FC_PRCONF_OUTPUT_PR_FACTOR_MASK); |
| 1167 | hdmi_writeb(hdmi, val, HDMI_FC_PRCONF); |
| 1168 | |
Russell King | d4ac4cb | 2015-03-27 20:06:50 +0000 | [diff] [blame] | 1169 | /* |
| 1170 | * AVI data byte 5 differences: content type in 0,1 rather than 4,5, |
| 1171 | * ycc range in bits 2,3 rather than 6,7 |
| 1172 | */ |
| 1173 | val = ((frame.ycc_quantization_range & 0x3) << 2) | |
| 1174 | (frame.content_type & 0x3); |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1175 | hdmi_writeb(hdmi, val, HDMI_FC_AVICONF3); |
| 1176 | |
| 1177 | /* AVI Data Bytes 6-13 */ |
Russell King | d4ac4cb | 2015-03-27 20:06:50 +0000 | [diff] [blame] | 1178 | hdmi_writeb(hdmi, frame.top_bar & 0xff, HDMI_FC_AVIETB0); |
| 1179 | hdmi_writeb(hdmi, (frame.top_bar >> 8) & 0xff, HDMI_FC_AVIETB1); |
| 1180 | hdmi_writeb(hdmi, frame.bottom_bar & 0xff, HDMI_FC_AVISBB0); |
| 1181 | hdmi_writeb(hdmi, (frame.bottom_bar >> 8) & 0xff, HDMI_FC_AVISBB1); |
| 1182 | hdmi_writeb(hdmi, frame.left_bar & 0xff, HDMI_FC_AVIELB0); |
| 1183 | hdmi_writeb(hdmi, (frame.left_bar >> 8) & 0xff, HDMI_FC_AVIELB1); |
| 1184 | hdmi_writeb(hdmi, frame.right_bar & 0xff, HDMI_FC_AVISRB0); |
| 1185 | hdmi_writeb(hdmi, (frame.right_bar >> 8) & 0xff, HDMI_FC_AVISRB1); |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1186 | } |
| 1187 | |
Andy Yan | b21f4b6 | 2014-12-05 14:26:31 +0800 | [diff] [blame] | 1188 | static void hdmi_av_composer(struct dw_hdmi *hdmi, |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1189 | const struct drm_display_mode *mode) |
| 1190 | { |
| 1191 | u8 inv_val; |
| 1192 | struct hdmi_vmode *vmode = &hdmi->hdmi_data.video_mode; |
| 1193 | int hblank, vblank, h_de_hs, v_de_vs, hsync_len, vsync_len; |
Russell King | e80b9f4 | 2015-07-21 11:08:25 +0100 | [diff] [blame] | 1194 | unsigned int vdisplay; |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1195 | |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1196 | vmode->mpixelclock = mode->clock * 1000; |
| 1197 | |
| 1198 | dev_dbg(hdmi->dev, "final pixclk = %d\n", vmode->mpixelclock); |
| 1199 | |
| 1200 | /* Set up HDMI_FC_INVIDCONF */ |
| 1201 | inv_val = (hdmi->hdmi_data.hdcp_enable ? |
| 1202 | HDMI_FC_INVIDCONF_HDCP_KEEPOUT_ACTIVE : |
| 1203 | HDMI_FC_INVIDCONF_HDCP_KEEPOUT_INACTIVE); |
| 1204 | |
Russell King | b91eee8 | 2015-03-27 23:27:17 +0000 | [diff] [blame] | 1205 | inv_val |= mode->flags & DRM_MODE_FLAG_PVSYNC ? |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1206 | HDMI_FC_INVIDCONF_VSYNC_IN_POLARITY_ACTIVE_HIGH : |
Russell King | b91eee8 | 2015-03-27 23:27:17 +0000 | [diff] [blame] | 1207 | HDMI_FC_INVIDCONF_VSYNC_IN_POLARITY_ACTIVE_LOW; |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1208 | |
Russell King | b91eee8 | 2015-03-27 23:27:17 +0000 | [diff] [blame] | 1209 | inv_val |= mode->flags & DRM_MODE_FLAG_PHSYNC ? |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1210 | HDMI_FC_INVIDCONF_HSYNC_IN_POLARITY_ACTIVE_HIGH : |
Russell King | b91eee8 | 2015-03-27 23:27:17 +0000 | [diff] [blame] | 1211 | HDMI_FC_INVIDCONF_HSYNC_IN_POLARITY_ACTIVE_LOW; |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1212 | |
| 1213 | inv_val |= (vmode->mdataenablepolarity ? |
| 1214 | HDMI_FC_INVIDCONF_DE_IN_POLARITY_ACTIVE_HIGH : |
| 1215 | HDMI_FC_INVIDCONF_DE_IN_POLARITY_ACTIVE_LOW); |
| 1216 | |
| 1217 | if (hdmi->vic == 39) |
| 1218 | inv_val |= HDMI_FC_INVIDCONF_R_V_BLANK_IN_OSC_ACTIVE_HIGH; |
| 1219 | else |
Russell King | b91eee8 | 2015-03-27 23:27:17 +0000 | [diff] [blame] | 1220 | inv_val |= mode->flags & DRM_MODE_FLAG_INTERLACE ? |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1221 | HDMI_FC_INVIDCONF_R_V_BLANK_IN_OSC_ACTIVE_HIGH : |
Russell King | b91eee8 | 2015-03-27 23:27:17 +0000 | [diff] [blame] | 1222 | HDMI_FC_INVIDCONF_R_V_BLANK_IN_OSC_ACTIVE_LOW; |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1223 | |
Russell King | b91eee8 | 2015-03-27 23:27:17 +0000 | [diff] [blame] | 1224 | inv_val |= mode->flags & DRM_MODE_FLAG_INTERLACE ? |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1225 | HDMI_FC_INVIDCONF_IN_I_P_INTERLACED : |
Russell King | b91eee8 | 2015-03-27 23:27:17 +0000 | [diff] [blame] | 1226 | HDMI_FC_INVIDCONF_IN_I_P_PROGRESSIVE; |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1227 | |
Russell King | 05b1342 | 2015-07-21 15:35:52 +0100 | [diff] [blame] | 1228 | inv_val |= hdmi->sink_is_hdmi ? |
| 1229 | HDMI_FC_INVIDCONF_DVI_MODEZ_HDMI_MODE : |
| 1230 | HDMI_FC_INVIDCONF_DVI_MODEZ_DVI_MODE; |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1231 | |
| 1232 | hdmi_writeb(hdmi, inv_val, HDMI_FC_INVIDCONF); |
| 1233 | |
Russell King | e80b9f4 | 2015-07-21 11:08:25 +0100 | [diff] [blame] | 1234 | vdisplay = mode->vdisplay; |
| 1235 | vblank = mode->vtotal - mode->vdisplay; |
| 1236 | v_de_vs = mode->vsync_start - mode->vdisplay; |
| 1237 | vsync_len = mode->vsync_end - mode->vsync_start; |
| 1238 | |
| 1239 | /* |
| 1240 | * When we're setting an interlaced mode, we need |
| 1241 | * to adjust the vertical timing to suit. |
| 1242 | */ |
| 1243 | if (mode->flags & DRM_MODE_FLAG_INTERLACE) { |
| 1244 | vdisplay /= 2; |
| 1245 | vblank /= 2; |
| 1246 | v_de_vs /= 2; |
| 1247 | vsync_len /= 2; |
| 1248 | } |
| 1249 | |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1250 | /* Set up horizontal active pixel width */ |
| 1251 | hdmi_writeb(hdmi, mode->hdisplay >> 8, HDMI_FC_INHACTV1); |
| 1252 | hdmi_writeb(hdmi, mode->hdisplay, HDMI_FC_INHACTV0); |
| 1253 | |
| 1254 | /* Set up vertical active lines */ |
Russell King | e80b9f4 | 2015-07-21 11:08:25 +0100 | [diff] [blame] | 1255 | hdmi_writeb(hdmi, vdisplay >> 8, HDMI_FC_INVACTV1); |
| 1256 | hdmi_writeb(hdmi, vdisplay, HDMI_FC_INVACTV0); |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1257 | |
| 1258 | /* Set up horizontal blanking pixel region width */ |
| 1259 | hblank = mode->htotal - mode->hdisplay; |
| 1260 | hdmi_writeb(hdmi, hblank >> 8, HDMI_FC_INHBLANK1); |
| 1261 | hdmi_writeb(hdmi, hblank, HDMI_FC_INHBLANK0); |
| 1262 | |
| 1263 | /* Set up vertical blanking pixel region width */ |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1264 | hdmi_writeb(hdmi, vblank, HDMI_FC_INVBLANK); |
| 1265 | |
| 1266 | /* Set up HSYNC active edge delay width (in pixel clks) */ |
| 1267 | h_de_hs = mode->hsync_start - mode->hdisplay; |
| 1268 | hdmi_writeb(hdmi, h_de_hs >> 8, HDMI_FC_HSYNCINDELAY1); |
| 1269 | hdmi_writeb(hdmi, h_de_hs, HDMI_FC_HSYNCINDELAY0); |
| 1270 | |
| 1271 | /* Set up VSYNC active edge delay (in lines) */ |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1272 | hdmi_writeb(hdmi, v_de_vs, HDMI_FC_VSYNCINDELAY); |
| 1273 | |
| 1274 | /* Set up HSYNC active pulse width (in pixel clks) */ |
| 1275 | hsync_len = mode->hsync_end - mode->hsync_start; |
| 1276 | hdmi_writeb(hdmi, hsync_len >> 8, HDMI_FC_HSYNCINWIDTH1); |
| 1277 | hdmi_writeb(hdmi, hsync_len, HDMI_FC_HSYNCINWIDTH0); |
| 1278 | |
| 1279 | /* Set up VSYNC active edge delay (in lines) */ |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1280 | hdmi_writeb(hdmi, vsync_len, HDMI_FC_VSYNCINWIDTH); |
| 1281 | } |
| 1282 | |
Andy Yan | b21f4b6 | 2014-12-05 14:26:31 +0800 | [diff] [blame] | 1283 | static void dw_hdmi_phy_disable(struct dw_hdmi *hdmi) |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1284 | { |
| 1285 | if (!hdmi->phy_enabled) |
| 1286 | return; |
| 1287 | |
Laurent Pinchart | b0e583e | 2017-03-06 01:35:39 +0200 | [diff] [blame^] | 1288 | dw_hdmi_phy_power_off(hdmi); |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1289 | |
| 1290 | hdmi->phy_enabled = false; |
| 1291 | } |
| 1292 | |
| 1293 | /* HDMI Initialization Step B.4 */ |
Andy Yan | b21f4b6 | 2014-12-05 14:26:31 +0800 | [diff] [blame] | 1294 | static void dw_hdmi_enable_video_path(struct dw_hdmi *hdmi) |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1295 | { |
| 1296 | u8 clkdis; |
| 1297 | |
| 1298 | /* control period minimum duration */ |
| 1299 | hdmi_writeb(hdmi, 12, HDMI_FC_CTRLDUR); |
| 1300 | hdmi_writeb(hdmi, 32, HDMI_FC_EXCTRLDUR); |
| 1301 | hdmi_writeb(hdmi, 1, HDMI_FC_EXCTRLSPAC); |
| 1302 | |
| 1303 | /* Set to fill TMDS data channels */ |
| 1304 | hdmi_writeb(hdmi, 0x0B, HDMI_FC_CH0PREAM); |
| 1305 | hdmi_writeb(hdmi, 0x16, HDMI_FC_CH1PREAM); |
| 1306 | hdmi_writeb(hdmi, 0x21, HDMI_FC_CH2PREAM); |
| 1307 | |
| 1308 | /* Enable pixel clock and tmds data path */ |
| 1309 | clkdis = 0x7F; |
| 1310 | clkdis &= ~HDMI_MC_CLKDIS_PIXELCLK_DISABLE; |
| 1311 | hdmi_writeb(hdmi, clkdis, HDMI_MC_CLKDIS); |
| 1312 | |
| 1313 | clkdis &= ~HDMI_MC_CLKDIS_TMDSCLK_DISABLE; |
| 1314 | hdmi_writeb(hdmi, clkdis, HDMI_MC_CLKDIS); |
| 1315 | |
| 1316 | /* Enable csc path */ |
| 1317 | if (is_color_space_conversion(hdmi)) { |
| 1318 | clkdis &= ~HDMI_MC_CLKDIS_CSCCLK_DISABLE; |
| 1319 | hdmi_writeb(hdmi, clkdis, HDMI_MC_CLKDIS); |
| 1320 | } |
Laurent Pinchart | 8b9e1c0 | 2017-03-03 19:19:59 +0200 | [diff] [blame] | 1321 | |
Neil Armstrong | 14247d7 | 2017-03-03 19:20:00 +0200 | [diff] [blame] | 1322 | /* Enable color space conversion if needed */ |
| 1323 | if (is_color_space_conversion(hdmi)) |
Laurent Pinchart | 8b9e1c0 | 2017-03-03 19:19:59 +0200 | [diff] [blame] | 1324 | hdmi_writeb(hdmi, HDMI_MC_FLOWCTRL_FEED_THROUGH_OFF_CSC_IN_PATH, |
| 1325 | HDMI_MC_FLOWCTRL); |
| 1326 | else |
| 1327 | hdmi_writeb(hdmi, HDMI_MC_FLOWCTRL_FEED_THROUGH_OFF_CSC_BYPASS, |
| 1328 | HDMI_MC_FLOWCTRL); |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1329 | } |
| 1330 | |
Andy Yan | b21f4b6 | 2014-12-05 14:26:31 +0800 | [diff] [blame] | 1331 | static void hdmi_enable_audio_clk(struct dw_hdmi *hdmi) |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1332 | { |
Russell King | 812bc61 | 2013-11-04 12:42:02 +0000 | [diff] [blame] | 1333 | hdmi_modb(hdmi, 0, HDMI_MC_CLKDIS_AUDCLK_DISABLE, HDMI_MC_CLKDIS); |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1334 | } |
| 1335 | |
| 1336 | /* Workaround to clear the overflow condition */ |
Andy Yan | b21f4b6 | 2014-12-05 14:26:31 +0800 | [diff] [blame] | 1337 | static void dw_hdmi_clear_overflow(struct dw_hdmi *hdmi) |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1338 | { |
Laurent Pinchart | be41fc5 | 2017-01-17 10:29:05 +0200 | [diff] [blame] | 1339 | unsigned int count; |
| 1340 | unsigned int i; |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1341 | u8 val; |
| 1342 | |
Laurent Pinchart | be41fc5 | 2017-01-17 10:29:05 +0200 | [diff] [blame] | 1343 | /* |
| 1344 | * Under some circumstances the Frame Composer arithmetic unit can miss |
| 1345 | * an FC register write due to being busy processing the previous one. |
| 1346 | * The issue can be worked around by issuing a TMDS software reset and |
| 1347 | * then write one of the FC registers several times. |
| 1348 | * |
| 1349 | * The number of iterations matters and depends on the HDMI TX revision |
| 1350 | * (and possibly on the platform). So far only i.MX6Q (v1.30a) and |
| 1351 | * i.MX6DL (v1.31a) have been identified as needing the workaround, with |
| 1352 | * 4 and 1 iterations respectively. |
| 1353 | */ |
| 1354 | |
| 1355 | switch (hdmi->version) { |
| 1356 | case 0x130a: |
| 1357 | count = 4; |
| 1358 | break; |
| 1359 | case 0x131a: |
| 1360 | count = 1; |
| 1361 | break; |
| 1362 | default: |
| 1363 | return; |
| 1364 | } |
| 1365 | |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1366 | /* TMDS software reset */ |
| 1367 | hdmi_writeb(hdmi, (u8)~HDMI_MC_SWRSTZ_TMDSSWRST_REQ, HDMI_MC_SWRSTZ); |
| 1368 | |
| 1369 | val = hdmi_readb(hdmi, HDMI_FC_INVIDCONF); |
Laurent Pinchart | be41fc5 | 2017-01-17 10:29:05 +0200 | [diff] [blame] | 1370 | for (i = 0; i < count; i++) |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1371 | hdmi_writeb(hdmi, val, HDMI_FC_INVIDCONF); |
| 1372 | } |
| 1373 | |
Andy Yan | b21f4b6 | 2014-12-05 14:26:31 +0800 | [diff] [blame] | 1374 | static void hdmi_enable_overflow_interrupts(struct dw_hdmi *hdmi) |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1375 | { |
| 1376 | hdmi_writeb(hdmi, 0, HDMI_FC_MASK2); |
| 1377 | hdmi_writeb(hdmi, 0, HDMI_IH_MUTE_FC_STAT2); |
| 1378 | } |
| 1379 | |
Andy Yan | b21f4b6 | 2014-12-05 14:26:31 +0800 | [diff] [blame] | 1380 | static void hdmi_disable_overflow_interrupts(struct dw_hdmi *hdmi) |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1381 | { |
| 1382 | hdmi_writeb(hdmi, HDMI_IH_MUTE_FC_STAT2_OVERFLOW_MASK, |
| 1383 | HDMI_IH_MUTE_FC_STAT2); |
| 1384 | } |
| 1385 | |
Andy Yan | b21f4b6 | 2014-12-05 14:26:31 +0800 | [diff] [blame] | 1386 | static int dw_hdmi_setup(struct dw_hdmi *hdmi, struct drm_display_mode *mode) |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1387 | { |
| 1388 | int ret; |
| 1389 | |
| 1390 | hdmi_disable_overflow_interrupts(hdmi); |
| 1391 | |
| 1392 | hdmi->vic = drm_match_cea_mode(mode); |
| 1393 | |
| 1394 | if (!hdmi->vic) { |
| 1395 | dev_dbg(hdmi->dev, "Non-CEA mode used in HDMI\n"); |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1396 | } else { |
| 1397 | dev_dbg(hdmi->dev, "CEA mode used vic=%d\n", hdmi->vic); |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1398 | } |
| 1399 | |
| 1400 | if ((hdmi->vic == 6) || (hdmi->vic == 7) || |
Andy Yan | b587833 | 2014-12-05 14:23:52 +0800 | [diff] [blame] | 1401 | (hdmi->vic == 21) || (hdmi->vic == 22) || |
| 1402 | (hdmi->vic == 2) || (hdmi->vic == 3) || |
| 1403 | (hdmi->vic == 17) || (hdmi->vic == 18)) |
Sachin Kamat | 5a819ed | 2014-01-28 10:33:16 +0530 | [diff] [blame] | 1404 | hdmi->hdmi_data.colorimetry = HDMI_COLORIMETRY_ITU_601; |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1405 | else |
Sachin Kamat | 5a819ed | 2014-01-28 10:33:16 +0530 | [diff] [blame] | 1406 | hdmi->hdmi_data.colorimetry = HDMI_COLORIMETRY_ITU_709; |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1407 | |
Russell King | d10ca82 | 2015-07-21 11:25:00 +0100 | [diff] [blame] | 1408 | hdmi->hdmi_data.video_mode.mpixelrepetitionoutput = 0; |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1409 | hdmi->hdmi_data.video_mode.mpixelrepetitioninput = 0; |
| 1410 | |
| 1411 | /* TODO: Get input format from IPU (via FB driver interface) */ |
| 1412 | hdmi->hdmi_data.enc_in_format = RGB; |
| 1413 | |
| 1414 | hdmi->hdmi_data.enc_out_format = RGB; |
| 1415 | |
| 1416 | hdmi->hdmi_data.enc_color_depth = 8; |
| 1417 | hdmi->hdmi_data.pix_repet_factor = 0; |
| 1418 | hdmi->hdmi_data.hdcp_enable = 0; |
| 1419 | hdmi->hdmi_data.video_mode.mdataenablepolarity = true; |
| 1420 | |
| 1421 | /* HDMI Initialization Step B.1 */ |
| 1422 | hdmi_av_composer(hdmi, mode); |
| 1423 | |
| 1424 | /* HDMI Initializateion Step B.2 */ |
Andy Yan | b21f4b6 | 2014-12-05 14:26:31 +0800 | [diff] [blame] | 1425 | ret = dw_hdmi_phy_init(hdmi); |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1426 | if (ret) |
| 1427 | return ret; |
| 1428 | |
| 1429 | /* HDMI Initialization Step B.3 */ |
Andy Yan | b21f4b6 | 2014-12-05 14:26:31 +0800 | [diff] [blame] | 1430 | dw_hdmi_enable_video_path(hdmi); |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1431 | |
Russell King | f709ec0 | 2015-07-21 16:09:39 +0100 | [diff] [blame] | 1432 | if (hdmi->sink_has_audio) { |
| 1433 | dev_dbg(hdmi->dev, "sink has audio support\n"); |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1434 | |
| 1435 | /* HDMI Initialization Step E - Configure audio */ |
| 1436 | hdmi_clk_regenerator_update_pixel_clock(hdmi); |
| 1437 | hdmi_enable_audio_clk(hdmi); |
Russell King | f709ec0 | 2015-07-21 16:09:39 +0100 | [diff] [blame] | 1438 | } |
| 1439 | |
| 1440 | /* not for DVI mode */ |
| 1441 | if (hdmi->sink_is_hdmi) { |
| 1442 | dev_dbg(hdmi->dev, "%s HDMI mode\n", __func__); |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1443 | |
| 1444 | /* HDMI Initialization Step F - Configure AVI InfoFrame */ |
Russell King | d4ac4cb | 2015-03-27 20:06:50 +0000 | [diff] [blame] | 1445 | hdmi_config_AVI(hdmi, mode); |
Russell King | 05b1342 | 2015-07-21 15:35:52 +0100 | [diff] [blame] | 1446 | } else { |
| 1447 | dev_dbg(hdmi->dev, "%s DVI mode\n", __func__); |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1448 | } |
| 1449 | |
| 1450 | hdmi_video_packetize(hdmi); |
| 1451 | hdmi_video_csc(hdmi); |
| 1452 | hdmi_video_sample(hdmi); |
| 1453 | hdmi_tx_hdcp_config(hdmi); |
| 1454 | |
Andy Yan | b21f4b6 | 2014-12-05 14:26:31 +0800 | [diff] [blame] | 1455 | dw_hdmi_clear_overflow(hdmi); |
Russell King | 05b1342 | 2015-07-21 15:35:52 +0100 | [diff] [blame] | 1456 | if (hdmi->cable_plugin && hdmi->sink_is_hdmi) |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1457 | hdmi_enable_overflow_interrupts(hdmi); |
| 1458 | |
| 1459 | return 0; |
| 1460 | } |
| 1461 | |
| 1462 | /* Wait until we are registered to enable interrupts */ |
Andy Yan | b21f4b6 | 2014-12-05 14:26:31 +0800 | [diff] [blame] | 1463 | static int dw_hdmi_fb_registered(struct dw_hdmi *hdmi) |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1464 | { |
| 1465 | hdmi_writeb(hdmi, HDMI_PHY_I2CM_INT_ADDR_DONE_POL, |
| 1466 | HDMI_PHY_I2CM_INT_ADDR); |
| 1467 | |
| 1468 | hdmi_writeb(hdmi, HDMI_PHY_I2CM_CTLINT_ADDR_NAC_POL | |
| 1469 | HDMI_PHY_I2CM_CTLINT_ADDR_ARBITRATION_POL, |
| 1470 | HDMI_PHY_I2CM_CTLINT_ADDR); |
| 1471 | |
| 1472 | /* enable cable hot plug irq */ |
Russell King | aeac23b | 2015-06-05 13:46:22 +0100 | [diff] [blame] | 1473 | hdmi_writeb(hdmi, hdmi->phy_mask, HDMI_PHY_MASK0); |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1474 | |
| 1475 | /* Clear Hotplug interrupts */ |
Russell King | aeac23b | 2015-06-05 13:46:22 +0100 | [diff] [blame] | 1476 | hdmi_writeb(hdmi, HDMI_IH_PHY_STAT0_HPD | HDMI_IH_PHY_STAT0_RX_SENSE, |
| 1477 | HDMI_IH_PHY_STAT0); |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1478 | |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1479 | return 0; |
| 1480 | } |
| 1481 | |
Andy Yan | b21f4b6 | 2014-12-05 14:26:31 +0800 | [diff] [blame] | 1482 | static void initialize_hdmi_ih_mutes(struct dw_hdmi *hdmi) |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1483 | { |
| 1484 | u8 ih_mute; |
| 1485 | |
| 1486 | /* |
| 1487 | * Boot up defaults are: |
| 1488 | * HDMI_IH_MUTE = 0x03 (disabled) |
| 1489 | * HDMI_IH_MUTE_* = 0x00 (enabled) |
| 1490 | * |
| 1491 | * Disable top level interrupt bits in HDMI block |
| 1492 | */ |
| 1493 | ih_mute = hdmi_readb(hdmi, HDMI_IH_MUTE) | |
| 1494 | HDMI_IH_MUTE_MUTE_WAKEUP_INTERRUPT | |
| 1495 | HDMI_IH_MUTE_MUTE_ALL_INTERRUPT; |
| 1496 | |
| 1497 | hdmi_writeb(hdmi, ih_mute, HDMI_IH_MUTE); |
| 1498 | |
| 1499 | /* by default mask all interrupts */ |
| 1500 | hdmi_writeb(hdmi, 0xff, HDMI_VP_MASK); |
| 1501 | hdmi_writeb(hdmi, 0xff, HDMI_FC_MASK0); |
| 1502 | hdmi_writeb(hdmi, 0xff, HDMI_FC_MASK1); |
| 1503 | hdmi_writeb(hdmi, 0xff, HDMI_FC_MASK2); |
| 1504 | hdmi_writeb(hdmi, 0xff, HDMI_PHY_MASK0); |
| 1505 | hdmi_writeb(hdmi, 0xff, HDMI_PHY_I2CM_INT_ADDR); |
| 1506 | hdmi_writeb(hdmi, 0xff, HDMI_PHY_I2CM_CTLINT_ADDR); |
| 1507 | hdmi_writeb(hdmi, 0xff, HDMI_AUD_INT); |
| 1508 | hdmi_writeb(hdmi, 0xff, HDMI_AUD_SPDIFINT); |
| 1509 | hdmi_writeb(hdmi, 0xff, HDMI_AUD_HBR_MASK); |
| 1510 | hdmi_writeb(hdmi, 0xff, HDMI_GP_MASK); |
| 1511 | hdmi_writeb(hdmi, 0xff, HDMI_A_APIINTMSK); |
| 1512 | hdmi_writeb(hdmi, 0xff, HDMI_CEC_MASK); |
| 1513 | hdmi_writeb(hdmi, 0xff, HDMI_I2CM_INT); |
| 1514 | hdmi_writeb(hdmi, 0xff, HDMI_I2CM_CTLINT); |
| 1515 | |
| 1516 | /* Disable interrupts in the IH_MUTE_* registers */ |
| 1517 | hdmi_writeb(hdmi, 0xff, HDMI_IH_MUTE_FC_STAT0); |
| 1518 | hdmi_writeb(hdmi, 0xff, HDMI_IH_MUTE_FC_STAT1); |
| 1519 | hdmi_writeb(hdmi, 0xff, HDMI_IH_MUTE_FC_STAT2); |
| 1520 | hdmi_writeb(hdmi, 0xff, HDMI_IH_MUTE_AS_STAT0); |
| 1521 | hdmi_writeb(hdmi, 0xff, HDMI_IH_MUTE_PHY_STAT0); |
| 1522 | hdmi_writeb(hdmi, 0xff, HDMI_IH_MUTE_I2CM_STAT0); |
| 1523 | hdmi_writeb(hdmi, 0xff, HDMI_IH_MUTE_CEC_STAT0); |
| 1524 | hdmi_writeb(hdmi, 0xff, HDMI_IH_MUTE_VP_STAT0); |
| 1525 | hdmi_writeb(hdmi, 0xff, HDMI_IH_MUTE_I2CMPHY_STAT0); |
| 1526 | hdmi_writeb(hdmi, 0xff, HDMI_IH_MUTE_AHBDMAAUD_STAT0); |
| 1527 | |
| 1528 | /* Enable top level interrupt bits in HDMI block */ |
| 1529 | ih_mute &= ~(HDMI_IH_MUTE_MUTE_WAKEUP_INTERRUPT | |
| 1530 | HDMI_IH_MUTE_MUTE_ALL_INTERRUPT); |
| 1531 | hdmi_writeb(hdmi, ih_mute, HDMI_IH_MUTE); |
| 1532 | } |
| 1533 | |
Andy Yan | b21f4b6 | 2014-12-05 14:26:31 +0800 | [diff] [blame] | 1534 | static void dw_hdmi_poweron(struct dw_hdmi *hdmi) |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1535 | { |
Russell King | 381f05a | 2015-06-05 15:25:08 +0100 | [diff] [blame] | 1536 | hdmi->bridge_is_on = true; |
Andy Yan | b21f4b6 | 2014-12-05 14:26:31 +0800 | [diff] [blame] | 1537 | dw_hdmi_setup(hdmi, &hdmi->previous_mode); |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1538 | } |
| 1539 | |
Andy Yan | b21f4b6 | 2014-12-05 14:26:31 +0800 | [diff] [blame] | 1540 | static void dw_hdmi_poweroff(struct dw_hdmi *hdmi) |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1541 | { |
Andy Yan | b21f4b6 | 2014-12-05 14:26:31 +0800 | [diff] [blame] | 1542 | dw_hdmi_phy_disable(hdmi); |
Russell King | 381f05a | 2015-06-05 15:25:08 +0100 | [diff] [blame] | 1543 | hdmi->bridge_is_on = false; |
| 1544 | } |
| 1545 | |
| 1546 | static void dw_hdmi_update_power(struct dw_hdmi *hdmi) |
| 1547 | { |
| 1548 | int force = hdmi->force; |
| 1549 | |
| 1550 | if (hdmi->disabled) { |
| 1551 | force = DRM_FORCE_OFF; |
| 1552 | } else if (force == DRM_FORCE_UNSPECIFIED) { |
Russell King | aeac23b | 2015-06-05 13:46:22 +0100 | [diff] [blame] | 1553 | if (hdmi->rxsense) |
Russell King | 381f05a | 2015-06-05 15:25:08 +0100 | [diff] [blame] | 1554 | force = DRM_FORCE_ON; |
| 1555 | else |
| 1556 | force = DRM_FORCE_OFF; |
| 1557 | } |
| 1558 | |
| 1559 | if (force == DRM_FORCE_OFF) { |
| 1560 | if (hdmi->bridge_is_on) |
| 1561 | dw_hdmi_poweroff(hdmi); |
| 1562 | } else { |
| 1563 | if (!hdmi->bridge_is_on) |
| 1564 | dw_hdmi_poweron(hdmi); |
| 1565 | } |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1566 | } |
| 1567 | |
Russell King | aeac23b | 2015-06-05 13:46:22 +0100 | [diff] [blame] | 1568 | /* |
| 1569 | * Adjust the detection of RXSENSE according to whether we have a forced |
| 1570 | * connection mode enabled, or whether we have been disabled. There is |
| 1571 | * no point processing RXSENSE interrupts if we have a forced connection |
| 1572 | * state, or DRM has us disabled. |
| 1573 | * |
| 1574 | * We also disable rxsense interrupts when we think we're disconnected |
| 1575 | * to avoid floating TDMS signals giving false rxsense interrupts. |
| 1576 | * |
| 1577 | * Note: we still need to listen for HPD interrupts even when DRM has us |
| 1578 | * disabled so that we can detect a connect event. |
| 1579 | */ |
| 1580 | static void dw_hdmi_update_phy_mask(struct dw_hdmi *hdmi) |
| 1581 | { |
| 1582 | u8 old_mask = hdmi->phy_mask; |
| 1583 | |
| 1584 | if (hdmi->force || hdmi->disabled || !hdmi->rxsense) |
| 1585 | hdmi->phy_mask |= HDMI_PHY_RX_SENSE; |
| 1586 | else |
| 1587 | hdmi->phy_mask &= ~HDMI_PHY_RX_SENSE; |
| 1588 | |
| 1589 | if (old_mask != hdmi->phy_mask) |
| 1590 | hdmi_writeb(hdmi, hdmi->phy_mask, HDMI_PHY_MASK0); |
| 1591 | } |
| 1592 | |
Andy Yan | b21f4b6 | 2014-12-05 14:26:31 +0800 | [diff] [blame] | 1593 | static enum drm_connector_status |
| 1594 | dw_hdmi_connector_detect(struct drm_connector *connector, bool force) |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1595 | { |
Andy Yan | b21f4b6 | 2014-12-05 14:26:31 +0800 | [diff] [blame] | 1596 | struct dw_hdmi *hdmi = container_of(connector, struct dw_hdmi, |
Russell King | d94905e | 2013-11-03 22:23:24 +0000 | [diff] [blame] | 1597 | connector); |
Russell King | 98dbead | 2014-04-18 10:46:45 +0100 | [diff] [blame] | 1598 | |
Russell King | 381f05a | 2015-06-05 15:25:08 +0100 | [diff] [blame] | 1599 | mutex_lock(&hdmi->mutex); |
| 1600 | hdmi->force = DRM_FORCE_UNSPECIFIED; |
| 1601 | dw_hdmi_update_power(hdmi); |
Russell King | aeac23b | 2015-06-05 13:46:22 +0100 | [diff] [blame] | 1602 | dw_hdmi_update_phy_mask(hdmi); |
Russell King | 381f05a | 2015-06-05 15:25:08 +0100 | [diff] [blame] | 1603 | mutex_unlock(&hdmi->mutex); |
| 1604 | |
Russell King | 98dbead | 2014-04-18 10:46:45 +0100 | [diff] [blame] | 1605 | return hdmi_readb(hdmi, HDMI_PHY_STAT0) & HDMI_PHY_HPD ? |
| 1606 | connector_status_connected : connector_status_disconnected; |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1607 | } |
| 1608 | |
Andy Yan | b21f4b6 | 2014-12-05 14:26:31 +0800 | [diff] [blame] | 1609 | static int dw_hdmi_connector_get_modes(struct drm_connector *connector) |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1610 | { |
Andy Yan | b21f4b6 | 2014-12-05 14:26:31 +0800 | [diff] [blame] | 1611 | struct dw_hdmi *hdmi = container_of(connector, struct dw_hdmi, |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1612 | connector); |
| 1613 | struct edid *edid; |
Doug Anderson | 6c7e66e | 2015-06-04 11:04:36 -0700 | [diff] [blame] | 1614 | int ret = 0; |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1615 | |
| 1616 | if (!hdmi->ddc) |
| 1617 | return 0; |
| 1618 | |
| 1619 | edid = drm_get_edid(connector, hdmi->ddc); |
| 1620 | if (edid) { |
| 1621 | dev_dbg(hdmi->dev, "got edid: width[%d] x height[%d]\n", |
| 1622 | edid->width_cm, edid->height_cm); |
| 1623 | |
Russell King | 05b1342 | 2015-07-21 15:35:52 +0100 | [diff] [blame] | 1624 | hdmi->sink_is_hdmi = drm_detect_hdmi_monitor(edid); |
Russell King | f709ec0 | 2015-07-21 16:09:39 +0100 | [diff] [blame] | 1625 | hdmi->sink_has_audio = drm_detect_monitor_audio(edid); |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1626 | drm_mode_connector_update_edid_property(connector, edid); |
| 1627 | ret = drm_add_edid_modes(connector, edid); |
Russell King | f5ce405 | 2013-11-07 16:06:01 +0000 | [diff] [blame] | 1628 | /* Store the ELD */ |
| 1629 | drm_edid_to_eld(connector, edid); |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1630 | kfree(edid); |
| 1631 | } else { |
| 1632 | dev_dbg(hdmi->dev, "failed to get edid\n"); |
| 1633 | } |
| 1634 | |
Doug Anderson | 6c7e66e | 2015-06-04 11:04:36 -0700 | [diff] [blame] | 1635 | return ret; |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1636 | } |
| 1637 | |
Andy Yan | 632d035 | 2014-12-05 14:30:21 +0800 | [diff] [blame] | 1638 | static enum drm_mode_status |
| 1639 | dw_hdmi_connector_mode_valid(struct drm_connector *connector, |
| 1640 | struct drm_display_mode *mode) |
| 1641 | { |
| 1642 | struct dw_hdmi *hdmi = container_of(connector, |
| 1643 | struct dw_hdmi, connector); |
| 1644 | enum drm_mode_status mode_status = MODE_OK; |
| 1645 | |
Russell King | 8add419 | 2015-07-22 11:14:00 +0100 | [diff] [blame] | 1646 | /* We don't support double-clocked modes */ |
| 1647 | if (mode->flags & DRM_MODE_FLAG_DBLCLK) |
| 1648 | return MODE_BAD; |
| 1649 | |
Andy Yan | 632d035 | 2014-12-05 14:30:21 +0800 | [diff] [blame] | 1650 | if (hdmi->plat_data->mode_valid) |
| 1651 | mode_status = hdmi->plat_data->mode_valid(connector, mode); |
| 1652 | |
| 1653 | return mode_status; |
| 1654 | } |
| 1655 | |
Russell King | 381f05a | 2015-06-05 15:25:08 +0100 | [diff] [blame] | 1656 | static void dw_hdmi_connector_force(struct drm_connector *connector) |
| 1657 | { |
| 1658 | struct dw_hdmi *hdmi = container_of(connector, struct dw_hdmi, |
| 1659 | connector); |
| 1660 | |
| 1661 | mutex_lock(&hdmi->mutex); |
| 1662 | hdmi->force = connector->force; |
| 1663 | dw_hdmi_update_power(hdmi); |
Russell King | aeac23b | 2015-06-05 13:46:22 +0100 | [diff] [blame] | 1664 | dw_hdmi_update_phy_mask(hdmi); |
Russell King | 381f05a | 2015-06-05 15:25:08 +0100 | [diff] [blame] | 1665 | mutex_unlock(&hdmi->mutex); |
| 1666 | } |
| 1667 | |
Ville Syrjälä | dae91e4 | 2015-12-15 12:21:02 +0100 | [diff] [blame] | 1668 | static const struct drm_connector_funcs dw_hdmi_connector_funcs = { |
Mark Yao | 2c5b2cc | 2015-11-30 18:33:40 +0800 | [diff] [blame] | 1669 | .dpms = drm_atomic_helper_connector_dpms, |
| 1670 | .fill_modes = drm_helper_probe_single_connector_modes, |
| 1671 | .detect = dw_hdmi_connector_detect, |
Marek Vasut | fdd8326 | 2016-10-05 16:31:33 +0200 | [diff] [blame] | 1672 | .destroy = drm_connector_cleanup, |
Mark Yao | 2c5b2cc | 2015-11-30 18:33:40 +0800 | [diff] [blame] | 1673 | .force = dw_hdmi_connector_force, |
| 1674 | .reset = drm_atomic_helper_connector_reset, |
| 1675 | .atomic_duplicate_state = drm_atomic_helper_connector_duplicate_state, |
| 1676 | .atomic_destroy_state = drm_atomic_helper_connector_destroy_state, |
| 1677 | }; |
| 1678 | |
Ville Syrjälä | dae91e4 | 2015-12-15 12:21:02 +0100 | [diff] [blame] | 1679 | static const struct drm_connector_helper_funcs dw_hdmi_connector_helper_funcs = { |
Andy Yan | b21f4b6 | 2014-12-05 14:26:31 +0800 | [diff] [blame] | 1680 | .get_modes = dw_hdmi_connector_get_modes, |
Andy Yan | 632d035 | 2014-12-05 14:30:21 +0800 | [diff] [blame] | 1681 | .mode_valid = dw_hdmi_connector_mode_valid, |
Boris Brezillon | c2a441f | 2016-06-07 13:48:15 +0200 | [diff] [blame] | 1682 | .best_encoder = drm_atomic_helper_best_encoder, |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1683 | }; |
| 1684 | |
Laurent Pinchart | d2ae94a | 2017-01-17 10:28:59 +0200 | [diff] [blame] | 1685 | static int dw_hdmi_bridge_attach(struct drm_bridge *bridge) |
| 1686 | { |
| 1687 | struct dw_hdmi *hdmi = bridge->driver_private; |
| 1688 | struct drm_encoder *encoder = bridge->encoder; |
| 1689 | struct drm_connector *connector = &hdmi->connector; |
| 1690 | |
| 1691 | connector->interlace_allowed = 1; |
| 1692 | connector->polled = DRM_CONNECTOR_POLL_HPD; |
| 1693 | |
| 1694 | drm_connector_helper_add(connector, &dw_hdmi_connector_helper_funcs); |
| 1695 | |
| 1696 | drm_connector_init(bridge->dev, connector, &dw_hdmi_connector_funcs, |
| 1697 | DRM_MODE_CONNECTOR_HDMIA); |
| 1698 | |
| 1699 | drm_mode_connector_attach_encoder(connector, encoder); |
| 1700 | |
| 1701 | return 0; |
| 1702 | } |
| 1703 | |
Laurent Pinchart | fd30b38 | 2017-01-17 10:28:58 +0200 | [diff] [blame] | 1704 | static void dw_hdmi_bridge_mode_set(struct drm_bridge *bridge, |
| 1705 | struct drm_display_mode *orig_mode, |
| 1706 | struct drm_display_mode *mode) |
| 1707 | { |
| 1708 | struct dw_hdmi *hdmi = bridge->driver_private; |
| 1709 | |
| 1710 | mutex_lock(&hdmi->mutex); |
| 1711 | |
| 1712 | /* Store the display mode for plugin/DKMS poweron events */ |
| 1713 | memcpy(&hdmi->previous_mode, mode, sizeof(hdmi->previous_mode)); |
| 1714 | |
| 1715 | mutex_unlock(&hdmi->mutex); |
| 1716 | } |
| 1717 | |
| 1718 | static void dw_hdmi_bridge_disable(struct drm_bridge *bridge) |
| 1719 | { |
| 1720 | struct dw_hdmi *hdmi = bridge->driver_private; |
| 1721 | |
| 1722 | mutex_lock(&hdmi->mutex); |
| 1723 | hdmi->disabled = true; |
| 1724 | dw_hdmi_update_power(hdmi); |
| 1725 | dw_hdmi_update_phy_mask(hdmi); |
| 1726 | mutex_unlock(&hdmi->mutex); |
| 1727 | } |
| 1728 | |
| 1729 | static void dw_hdmi_bridge_enable(struct drm_bridge *bridge) |
| 1730 | { |
| 1731 | struct dw_hdmi *hdmi = bridge->driver_private; |
| 1732 | |
| 1733 | mutex_lock(&hdmi->mutex); |
| 1734 | hdmi->disabled = false; |
| 1735 | dw_hdmi_update_power(hdmi); |
| 1736 | dw_hdmi_update_phy_mask(hdmi); |
| 1737 | mutex_unlock(&hdmi->mutex); |
| 1738 | } |
| 1739 | |
Ville Syrjälä | dae91e4 | 2015-12-15 12:21:02 +0100 | [diff] [blame] | 1740 | static const struct drm_bridge_funcs dw_hdmi_bridge_funcs = { |
Laurent Pinchart | d2ae94a | 2017-01-17 10:28:59 +0200 | [diff] [blame] | 1741 | .attach = dw_hdmi_bridge_attach, |
Andy Yan | b21f4b6 | 2014-12-05 14:26:31 +0800 | [diff] [blame] | 1742 | .enable = dw_hdmi_bridge_enable, |
| 1743 | .disable = dw_hdmi_bridge_disable, |
Andy Yan | b21f4b6 | 2014-12-05 14:26:31 +0800 | [diff] [blame] | 1744 | .mode_set = dw_hdmi_bridge_mode_set, |
Andy Yan | 3d1b35a | 2014-12-05 14:25:05 +0800 | [diff] [blame] | 1745 | }; |
| 1746 | |
Vladimir Zapolskiy | 3efc2fa | 2016-08-24 08:46:37 +0300 | [diff] [blame] | 1747 | static irqreturn_t dw_hdmi_i2c_irq(struct dw_hdmi *hdmi) |
| 1748 | { |
| 1749 | struct dw_hdmi_i2c *i2c = hdmi->i2c; |
| 1750 | unsigned int stat; |
| 1751 | |
| 1752 | stat = hdmi_readb(hdmi, HDMI_IH_I2CM_STAT0); |
| 1753 | if (!stat) |
| 1754 | return IRQ_NONE; |
| 1755 | |
| 1756 | hdmi_writeb(hdmi, stat, HDMI_IH_I2CM_STAT0); |
| 1757 | |
| 1758 | i2c->stat = stat; |
| 1759 | |
| 1760 | complete(&i2c->cmp); |
| 1761 | |
| 1762 | return IRQ_HANDLED; |
| 1763 | } |
| 1764 | |
Andy Yan | b21f4b6 | 2014-12-05 14:26:31 +0800 | [diff] [blame] | 1765 | static irqreturn_t dw_hdmi_hardirq(int irq, void *dev_id) |
Russell King | d94905e | 2013-11-03 22:23:24 +0000 | [diff] [blame] | 1766 | { |
Andy Yan | b21f4b6 | 2014-12-05 14:26:31 +0800 | [diff] [blame] | 1767 | struct dw_hdmi *hdmi = dev_id; |
Russell King | d94905e | 2013-11-03 22:23:24 +0000 | [diff] [blame] | 1768 | u8 intr_stat; |
Vladimir Zapolskiy | 3efc2fa | 2016-08-24 08:46:37 +0300 | [diff] [blame] | 1769 | irqreturn_t ret = IRQ_NONE; |
| 1770 | |
| 1771 | if (hdmi->i2c) |
| 1772 | ret = dw_hdmi_i2c_irq(hdmi); |
Russell King | d94905e | 2013-11-03 22:23:24 +0000 | [diff] [blame] | 1773 | |
| 1774 | intr_stat = hdmi_readb(hdmi, HDMI_IH_PHY_STAT0); |
Vladimir Zapolskiy | 3efc2fa | 2016-08-24 08:46:37 +0300 | [diff] [blame] | 1775 | if (intr_stat) { |
Russell King | d94905e | 2013-11-03 22:23:24 +0000 | [diff] [blame] | 1776 | hdmi_writeb(hdmi, ~0, HDMI_IH_MUTE_PHY_STAT0); |
Vladimir Zapolskiy | 3efc2fa | 2016-08-24 08:46:37 +0300 | [diff] [blame] | 1777 | return IRQ_WAKE_THREAD; |
| 1778 | } |
Russell King | d94905e | 2013-11-03 22:23:24 +0000 | [diff] [blame] | 1779 | |
Vladimir Zapolskiy | 3efc2fa | 2016-08-24 08:46:37 +0300 | [diff] [blame] | 1780 | return ret; |
Russell King | d94905e | 2013-11-03 22:23:24 +0000 | [diff] [blame] | 1781 | } |
| 1782 | |
Andy Yan | b21f4b6 | 2014-12-05 14:26:31 +0800 | [diff] [blame] | 1783 | static irqreturn_t dw_hdmi_irq(int irq, void *dev_id) |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1784 | { |
Andy Yan | b21f4b6 | 2014-12-05 14:26:31 +0800 | [diff] [blame] | 1785 | struct dw_hdmi *hdmi = dev_id; |
Russell King | aeac23b | 2015-06-05 13:46:22 +0100 | [diff] [blame] | 1786 | u8 intr_stat, phy_int_pol, phy_pol_mask, phy_stat; |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1787 | |
| 1788 | intr_stat = hdmi_readb(hdmi, HDMI_IH_PHY_STAT0); |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1789 | phy_int_pol = hdmi_readb(hdmi, HDMI_PHY_POL0); |
Russell King | aeac23b | 2015-06-05 13:46:22 +0100 | [diff] [blame] | 1790 | phy_stat = hdmi_readb(hdmi, HDMI_PHY_STAT0); |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1791 | |
Russell King | aeac23b | 2015-06-05 13:46:22 +0100 | [diff] [blame] | 1792 | phy_pol_mask = 0; |
| 1793 | if (intr_stat & HDMI_IH_PHY_STAT0_HPD) |
| 1794 | phy_pol_mask |= HDMI_PHY_HPD; |
| 1795 | if (intr_stat & HDMI_IH_PHY_STAT0_RX_SENSE0) |
| 1796 | phy_pol_mask |= HDMI_PHY_RX_SENSE0; |
| 1797 | if (intr_stat & HDMI_IH_PHY_STAT0_RX_SENSE1) |
| 1798 | phy_pol_mask |= HDMI_PHY_RX_SENSE1; |
| 1799 | if (intr_stat & HDMI_IH_PHY_STAT0_RX_SENSE2) |
| 1800 | phy_pol_mask |= HDMI_PHY_RX_SENSE2; |
| 1801 | if (intr_stat & HDMI_IH_PHY_STAT0_RX_SENSE3) |
| 1802 | phy_pol_mask |= HDMI_PHY_RX_SENSE3; |
| 1803 | |
| 1804 | if (phy_pol_mask) |
| 1805 | hdmi_modb(hdmi, ~phy_int_pol, phy_pol_mask, HDMI_PHY_POL0); |
| 1806 | |
| 1807 | /* |
| 1808 | * RX sense tells us whether the TDMS transmitters are detecting |
| 1809 | * load - in other words, there's something listening on the |
| 1810 | * other end of the link. Use this to decide whether we should |
| 1811 | * power on the phy as HPD may be toggled by the sink to merely |
| 1812 | * ask the source to re-read the EDID. |
| 1813 | */ |
| 1814 | if (intr_stat & |
| 1815 | (HDMI_IH_PHY_STAT0_RX_SENSE | HDMI_IH_PHY_STAT0_HPD)) { |
Russell King | b872a8e | 2015-06-05 12:22:46 +0100 | [diff] [blame] | 1816 | mutex_lock(&hdmi->mutex); |
Russell King | aeac23b | 2015-06-05 13:46:22 +0100 | [diff] [blame] | 1817 | if (!hdmi->disabled && !hdmi->force) { |
| 1818 | /* |
| 1819 | * If the RX sense status indicates we're disconnected, |
| 1820 | * clear the software rxsense status. |
| 1821 | */ |
| 1822 | if (!(phy_stat & HDMI_PHY_RX_SENSE)) |
| 1823 | hdmi->rxsense = false; |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1824 | |
Russell King | aeac23b | 2015-06-05 13:46:22 +0100 | [diff] [blame] | 1825 | /* |
| 1826 | * Only set the software rxsense status when both |
| 1827 | * rxsense and hpd indicates we're connected. |
| 1828 | * This avoids what seems to be bad behaviour in |
| 1829 | * at least iMX6S versions of the phy. |
| 1830 | */ |
| 1831 | if (phy_stat & HDMI_PHY_HPD) |
| 1832 | hdmi->rxsense = true; |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1833 | |
Russell King | aeac23b | 2015-06-05 13:46:22 +0100 | [diff] [blame] | 1834 | dw_hdmi_update_power(hdmi); |
| 1835 | dw_hdmi_update_phy_mask(hdmi); |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1836 | } |
Russell King | b872a8e | 2015-06-05 12:22:46 +0100 | [diff] [blame] | 1837 | mutex_unlock(&hdmi->mutex); |
Russell King | aeac23b | 2015-06-05 13:46:22 +0100 | [diff] [blame] | 1838 | } |
| 1839 | |
| 1840 | if (intr_stat & HDMI_IH_PHY_STAT0_HPD) { |
| 1841 | dev_dbg(hdmi->dev, "EVENT=%s\n", |
| 1842 | phy_int_pol & HDMI_PHY_HPD ? "plugin" : "plugout"); |
Laurent Pinchart | ba5d7e6 | 2017-01-17 10:28:56 +0200 | [diff] [blame] | 1843 | if (hdmi->bridge.dev) |
| 1844 | drm_helper_hpd_irq_event(hdmi->bridge.dev); |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1845 | } |
| 1846 | |
| 1847 | hdmi_writeb(hdmi, intr_stat, HDMI_IH_PHY_STAT0); |
Russell King | aeac23b | 2015-06-05 13:46:22 +0100 | [diff] [blame] | 1848 | hdmi_writeb(hdmi, ~(HDMI_IH_PHY_STAT0_HPD | HDMI_IH_PHY_STAT0_RX_SENSE), |
| 1849 | HDMI_IH_MUTE_PHY_STAT0); |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1850 | |
| 1851 | return IRQ_HANDLED; |
| 1852 | } |
| 1853 | |
Laurent Pinchart | faba6c3 | 2017-01-17 10:29:06 +0200 | [diff] [blame] | 1854 | static const struct dw_hdmi_phy_data dw_hdmi_phys[] = { |
| 1855 | { |
| 1856 | .type = DW_HDMI_PHY_DWC_HDMI_TX_PHY, |
| 1857 | .name = "DWC HDMI TX PHY", |
Laurent Pinchart | b0e583e | 2017-03-06 01:35:39 +0200 | [diff] [blame^] | 1858 | .gen = 1, |
Laurent Pinchart | faba6c3 | 2017-01-17 10:29:06 +0200 | [diff] [blame] | 1859 | }, { |
| 1860 | .type = DW_HDMI_PHY_DWC_MHL_PHY_HEAC, |
| 1861 | .name = "DWC MHL PHY + HEAC PHY", |
Laurent Pinchart | b0e583e | 2017-03-06 01:35:39 +0200 | [diff] [blame^] | 1862 | .gen = 2, |
Laurent Pinchart | faba6c3 | 2017-01-17 10:29:06 +0200 | [diff] [blame] | 1863 | .has_svsret = true, |
| 1864 | }, { |
| 1865 | .type = DW_HDMI_PHY_DWC_MHL_PHY, |
| 1866 | .name = "DWC MHL PHY", |
Laurent Pinchart | b0e583e | 2017-03-06 01:35:39 +0200 | [diff] [blame^] | 1867 | .gen = 2, |
Laurent Pinchart | faba6c3 | 2017-01-17 10:29:06 +0200 | [diff] [blame] | 1868 | .has_svsret = true, |
| 1869 | }, { |
| 1870 | .type = DW_HDMI_PHY_DWC_HDMI_3D_TX_PHY_HEAC, |
| 1871 | .name = "DWC HDMI 3D TX PHY + HEAC PHY", |
Laurent Pinchart | b0e583e | 2017-03-06 01:35:39 +0200 | [diff] [blame^] | 1872 | .gen = 2, |
Laurent Pinchart | faba6c3 | 2017-01-17 10:29:06 +0200 | [diff] [blame] | 1873 | }, { |
| 1874 | .type = DW_HDMI_PHY_DWC_HDMI_3D_TX_PHY, |
| 1875 | .name = "DWC HDMI 3D TX PHY", |
Laurent Pinchart | b0e583e | 2017-03-06 01:35:39 +0200 | [diff] [blame^] | 1876 | .gen = 2, |
Laurent Pinchart | faba6c3 | 2017-01-17 10:29:06 +0200 | [diff] [blame] | 1877 | }, { |
| 1878 | .type = DW_HDMI_PHY_DWC_HDMI20_TX_PHY, |
| 1879 | .name = "DWC HDMI 2.0 TX PHY", |
Laurent Pinchart | b0e583e | 2017-03-06 01:35:39 +0200 | [diff] [blame^] | 1880 | .gen = 2, |
Laurent Pinchart | faba6c3 | 2017-01-17 10:29:06 +0200 | [diff] [blame] | 1881 | .has_svsret = true, |
| 1882 | } |
| 1883 | }; |
| 1884 | |
| 1885 | static int dw_hdmi_detect_phy(struct dw_hdmi *hdmi) |
| 1886 | { |
| 1887 | unsigned int i; |
| 1888 | u8 phy_type; |
| 1889 | |
| 1890 | phy_type = hdmi_readb(hdmi, HDMI_CONFIG2_ID); |
| 1891 | |
| 1892 | for (i = 0; i < ARRAY_SIZE(dw_hdmi_phys); ++i) { |
| 1893 | if (dw_hdmi_phys[i].type == phy_type) { |
| 1894 | hdmi->phy = &dw_hdmi_phys[i]; |
| 1895 | return 0; |
| 1896 | } |
| 1897 | } |
| 1898 | |
| 1899 | if (phy_type == DW_HDMI_PHY_VENDOR_PHY) |
| 1900 | dev_err(hdmi->dev, "Unsupported vendor HDMI PHY\n"); |
| 1901 | else |
| 1902 | dev_err(hdmi->dev, "Unsupported HDMI PHY type (%02x)\n", |
| 1903 | phy_type); |
| 1904 | |
| 1905 | return -ENODEV; |
| 1906 | } |
| 1907 | |
Laurent Pinchart | 69497eb | 2017-01-17 10:29:00 +0200 | [diff] [blame] | 1908 | static struct dw_hdmi * |
| 1909 | __dw_hdmi_probe(struct platform_device *pdev, |
| 1910 | const struct dw_hdmi_plat_data *plat_data) |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1911 | { |
Laurent Pinchart | c608119 | 2017-01-17 10:28:57 +0200 | [diff] [blame] | 1912 | struct device *dev = &pdev->dev; |
Russell King | 17b5001 | 2013-11-03 11:23:34 +0000 | [diff] [blame] | 1913 | struct device_node *np = dev->of_node; |
Russell King | 7ed6c66 | 2013-11-07 16:01:45 +0000 | [diff] [blame] | 1914 | struct platform_device_info pdevinfo; |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1915 | struct device_node *ddc_node; |
Andy Yan | b21f4b6 | 2014-12-05 14:26:31 +0800 | [diff] [blame] | 1916 | struct dw_hdmi *hdmi; |
Laurent Pinchart | c608119 | 2017-01-17 10:28:57 +0200 | [diff] [blame] | 1917 | struct resource *iores; |
| 1918 | int irq; |
Andy Yan | 3d1b35a | 2014-12-05 14:25:05 +0800 | [diff] [blame] | 1919 | int ret; |
Andy Yan | 0cd9d14 | 2014-12-05 14:28:24 +0800 | [diff] [blame] | 1920 | u32 val = 1; |
Laurent Pinchart | 0527e12 | 2017-01-17 10:29:03 +0200 | [diff] [blame] | 1921 | u8 prod_id0; |
| 1922 | u8 prod_id1; |
Kuninori Morimoto | 2761ba6 | 2016-11-08 01:00:57 +0000 | [diff] [blame] | 1923 | u8 config0; |
Laurent Pinchart | 0c67494 | 2017-01-17 10:29:04 +0200 | [diff] [blame] | 1924 | u8 config3; |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1925 | |
Russell King | 17b5001 | 2013-11-03 11:23:34 +0000 | [diff] [blame] | 1926 | hdmi = devm_kzalloc(dev, sizeof(*hdmi), GFP_KERNEL); |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1927 | if (!hdmi) |
Laurent Pinchart | 69497eb | 2017-01-17 10:29:00 +0200 | [diff] [blame] | 1928 | return ERR_PTR(-ENOMEM); |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1929 | |
Andy Yan | 3d1b35a | 2014-12-05 14:25:05 +0800 | [diff] [blame] | 1930 | hdmi->plat_data = plat_data; |
Russell King | 17b5001 | 2013-11-03 11:23:34 +0000 | [diff] [blame] | 1931 | hdmi->dev = dev; |
Andy Yan | 3d1b35a | 2014-12-05 14:25:05 +0800 | [diff] [blame] | 1932 | hdmi->dev_type = plat_data->dev_type; |
Russell King | 4067838 | 2013-11-07 15:35:06 +0000 | [diff] [blame] | 1933 | hdmi->sample_rate = 48000; |
Russell King | b872a8e | 2015-06-05 12:22:46 +0100 | [diff] [blame] | 1934 | hdmi->disabled = true; |
Russell King | aeac23b | 2015-06-05 13:46:22 +0100 | [diff] [blame] | 1935 | hdmi->rxsense = true; |
| 1936 | hdmi->phy_mask = (u8)~(HDMI_PHY_HPD | HDMI_PHY_RX_SENSE); |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1937 | |
Russell King | b872a8e | 2015-06-05 12:22:46 +0100 | [diff] [blame] | 1938 | mutex_init(&hdmi->mutex); |
Russell King | 6bcf495 | 2015-02-02 11:01:08 +0000 | [diff] [blame] | 1939 | mutex_init(&hdmi->audio_mutex); |
Russell King | b90120a | 2015-03-27 12:59:58 +0000 | [diff] [blame] | 1940 | spin_lock_init(&hdmi->audio_lock); |
Russell King | 6bcf495 | 2015-02-02 11:01:08 +0000 | [diff] [blame] | 1941 | |
Andy Yan | 0cd9d14 | 2014-12-05 14:28:24 +0800 | [diff] [blame] | 1942 | of_property_read_u32(np, "reg-io-width", &val); |
| 1943 | |
| 1944 | switch (val) { |
| 1945 | case 4: |
| 1946 | hdmi->write = dw_hdmi_writel; |
| 1947 | hdmi->read = dw_hdmi_readl; |
| 1948 | break; |
| 1949 | case 1: |
| 1950 | hdmi->write = dw_hdmi_writeb; |
| 1951 | hdmi->read = dw_hdmi_readb; |
| 1952 | break; |
| 1953 | default: |
| 1954 | dev_err(dev, "reg-io-width must be 1 or 4\n"); |
Laurent Pinchart | 69497eb | 2017-01-17 10:29:00 +0200 | [diff] [blame] | 1955 | return ERR_PTR(-EINVAL); |
Andy Yan | 0cd9d14 | 2014-12-05 14:28:24 +0800 | [diff] [blame] | 1956 | } |
| 1957 | |
Philipp Zabel | b5d4590 | 2014-03-05 10:20:56 +0100 | [diff] [blame] | 1958 | ddc_node = of_parse_phandle(np, "ddc-i2c-bus", 0); |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1959 | if (ddc_node) { |
Vladimir Zapolskiy | 9f04a1f | 2016-08-16 23:26:43 +0300 | [diff] [blame] | 1960 | hdmi->ddc = of_get_i2c_adapter_by_node(ddc_node); |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1961 | of_node_put(ddc_node); |
Andy Yan | c2c3848 | 2014-12-05 14:24:28 +0800 | [diff] [blame] | 1962 | if (!hdmi->ddc) { |
| 1963 | dev_dbg(hdmi->dev, "failed to read ddc node\n"); |
Laurent Pinchart | 69497eb | 2017-01-17 10:29:00 +0200 | [diff] [blame] | 1964 | return ERR_PTR(-EPROBE_DEFER); |
Andy Yan | c2c3848 | 2014-12-05 14:24:28 +0800 | [diff] [blame] | 1965 | } |
| 1966 | |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1967 | } else { |
| 1968 | dev_dbg(hdmi->dev, "no ddc property found\n"); |
| 1969 | } |
| 1970 | |
Laurent Pinchart | c608119 | 2017-01-17 10:28:57 +0200 | [diff] [blame] | 1971 | iores = platform_get_resource(pdev, IORESOURCE_MEM, 0); |
Russell King | 17b5001 | 2013-11-03 11:23:34 +0000 | [diff] [blame] | 1972 | hdmi->regs = devm_ioremap_resource(dev, iores); |
Vladimir Zapolskiy | 9f04a1f | 2016-08-16 23:26:43 +0300 | [diff] [blame] | 1973 | if (IS_ERR(hdmi->regs)) { |
| 1974 | ret = PTR_ERR(hdmi->regs); |
| 1975 | goto err_res; |
| 1976 | } |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1977 | |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1978 | hdmi->isfr_clk = devm_clk_get(hdmi->dev, "isfr"); |
| 1979 | if (IS_ERR(hdmi->isfr_clk)) { |
| 1980 | ret = PTR_ERR(hdmi->isfr_clk); |
Andy Yan | b587833 | 2014-12-05 14:23:52 +0800 | [diff] [blame] | 1981 | dev_err(hdmi->dev, "Unable to get HDMI isfr clk: %d\n", ret); |
Vladimir Zapolskiy | 9f04a1f | 2016-08-16 23:26:43 +0300 | [diff] [blame] | 1982 | goto err_res; |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1983 | } |
| 1984 | |
| 1985 | ret = clk_prepare_enable(hdmi->isfr_clk); |
| 1986 | if (ret) { |
Andy Yan | b587833 | 2014-12-05 14:23:52 +0800 | [diff] [blame] | 1987 | dev_err(hdmi->dev, "Cannot enable HDMI isfr clock: %d\n", ret); |
Vladimir Zapolskiy | 9f04a1f | 2016-08-16 23:26:43 +0300 | [diff] [blame] | 1988 | goto err_res; |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1989 | } |
| 1990 | |
| 1991 | hdmi->iahb_clk = devm_clk_get(hdmi->dev, "iahb"); |
| 1992 | if (IS_ERR(hdmi->iahb_clk)) { |
| 1993 | ret = PTR_ERR(hdmi->iahb_clk); |
Andy Yan | b587833 | 2014-12-05 14:23:52 +0800 | [diff] [blame] | 1994 | dev_err(hdmi->dev, "Unable to get HDMI iahb clk: %d\n", ret); |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 1995 | goto err_isfr; |
| 1996 | } |
| 1997 | |
| 1998 | ret = clk_prepare_enable(hdmi->iahb_clk); |
| 1999 | if (ret) { |
Andy Yan | b587833 | 2014-12-05 14:23:52 +0800 | [diff] [blame] | 2000 | dev_err(hdmi->dev, "Cannot enable HDMI iahb clock: %d\n", ret); |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 2001 | goto err_isfr; |
| 2002 | } |
| 2003 | |
| 2004 | /* Product and revision IDs */ |
Laurent Pinchart | be41fc5 | 2017-01-17 10:29:05 +0200 | [diff] [blame] | 2005 | hdmi->version = (hdmi_readb(hdmi, HDMI_DESIGN_ID) << 8) |
| 2006 | | (hdmi_readb(hdmi, HDMI_REVISION_ID) << 0); |
Laurent Pinchart | 0527e12 | 2017-01-17 10:29:03 +0200 | [diff] [blame] | 2007 | prod_id0 = hdmi_readb(hdmi, HDMI_PRODUCT_ID0); |
| 2008 | prod_id1 = hdmi_readb(hdmi, HDMI_PRODUCT_ID1); |
| 2009 | |
| 2010 | if (prod_id0 != HDMI_PRODUCT_ID0_HDMI_TX || |
| 2011 | (prod_id1 & ~HDMI_PRODUCT_ID1_HDCP) != HDMI_PRODUCT_ID1_HDMI_TX) { |
| 2012 | dev_err(dev, "Unsupported HDMI controller (%04x:%02x:%02x)\n", |
Laurent Pinchart | be41fc5 | 2017-01-17 10:29:05 +0200 | [diff] [blame] | 2013 | hdmi->version, prod_id0, prod_id1); |
Laurent Pinchart | 0527e12 | 2017-01-17 10:29:03 +0200 | [diff] [blame] | 2014 | ret = -ENODEV; |
| 2015 | goto err_iahb; |
| 2016 | } |
| 2017 | |
Laurent Pinchart | faba6c3 | 2017-01-17 10:29:06 +0200 | [diff] [blame] | 2018 | ret = dw_hdmi_detect_phy(hdmi); |
| 2019 | if (ret < 0) |
| 2020 | goto err_iahb; |
| 2021 | |
| 2022 | dev_info(dev, "Detected HDMI TX controller v%x.%03x %s HDCP (%s)\n", |
Laurent Pinchart | be41fc5 | 2017-01-17 10:29:05 +0200 | [diff] [blame] | 2023 | hdmi->version >> 12, hdmi->version & 0xfff, |
Laurent Pinchart | faba6c3 | 2017-01-17 10:29:06 +0200 | [diff] [blame] | 2024 | prod_id1 & HDMI_PRODUCT_ID1_HDCP ? "with" : "without", |
| 2025 | hdmi->phy->name); |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 2026 | |
| 2027 | initialize_hdmi_ih_mutes(hdmi); |
| 2028 | |
Laurent Pinchart | c608119 | 2017-01-17 10:28:57 +0200 | [diff] [blame] | 2029 | irq = platform_get_irq(pdev, 0); |
Laurent Pinchart | 69497eb | 2017-01-17 10:29:00 +0200 | [diff] [blame] | 2030 | if (irq < 0) { |
| 2031 | ret = irq; |
Laurent Pinchart | c608119 | 2017-01-17 10:28:57 +0200 | [diff] [blame] | 2032 | goto err_iahb; |
Laurent Pinchart | 69497eb | 2017-01-17 10:29:00 +0200 | [diff] [blame] | 2033 | } |
Laurent Pinchart | c608119 | 2017-01-17 10:28:57 +0200 | [diff] [blame] | 2034 | |
Philipp Zabel | 639a202 | 2015-01-07 13:43:50 +0100 | [diff] [blame] | 2035 | ret = devm_request_threaded_irq(dev, irq, dw_hdmi_hardirq, |
| 2036 | dw_hdmi_irq, IRQF_SHARED, |
| 2037 | dev_name(dev), hdmi); |
| 2038 | if (ret) |
Fabio Estevam | b33ef61 | 2015-01-27 10:54:12 -0200 | [diff] [blame] | 2039 | goto err_iahb; |
Philipp Zabel | 639a202 | 2015-01-07 13:43:50 +0100 | [diff] [blame] | 2040 | |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 2041 | /* |
| 2042 | * To prevent overflows in HDMI_IH_FC_STAT2, set the clk regenerator |
| 2043 | * N and cts values before enabling phy |
| 2044 | */ |
| 2045 | hdmi_init_clk_regenerator(hdmi); |
| 2046 | |
Vladimir Zapolskiy | 3efc2fa | 2016-08-24 08:46:37 +0300 | [diff] [blame] | 2047 | /* If DDC bus is not specified, try to register HDMI I2C bus */ |
| 2048 | if (!hdmi->ddc) { |
| 2049 | hdmi->ddc = dw_hdmi_i2c_adapter(hdmi); |
| 2050 | if (IS_ERR(hdmi->ddc)) |
| 2051 | hdmi->ddc = NULL; |
| 2052 | } |
| 2053 | |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 2054 | /* |
| 2055 | * Configure registers related to HDMI interrupt |
| 2056 | * generation before registering IRQ. |
| 2057 | */ |
Russell King | aeac23b | 2015-06-05 13:46:22 +0100 | [diff] [blame] | 2058 | hdmi_writeb(hdmi, HDMI_PHY_HPD | HDMI_PHY_RX_SENSE, HDMI_PHY_POL0); |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 2059 | |
| 2060 | /* Clear Hotplug interrupts */ |
Russell King | aeac23b | 2015-06-05 13:46:22 +0100 | [diff] [blame] | 2061 | hdmi_writeb(hdmi, HDMI_IH_PHY_STAT0_HPD | HDMI_IH_PHY_STAT0_RX_SENSE, |
| 2062 | HDMI_IH_PHY_STAT0); |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 2063 | |
Laurent Pinchart | 69497eb | 2017-01-17 10:29:00 +0200 | [diff] [blame] | 2064 | hdmi->bridge.driver_private = hdmi; |
| 2065 | hdmi->bridge.funcs = &dw_hdmi_bridge_funcs; |
Arnd Bergmann | d5ad784 | 2017-01-23 13:20:38 +0100 | [diff] [blame] | 2066 | #ifdef CONFIG_OF |
Laurent Pinchart | 69497eb | 2017-01-17 10:29:00 +0200 | [diff] [blame] | 2067 | hdmi->bridge.of_node = pdev->dev.of_node; |
Arnd Bergmann | d5ad784 | 2017-01-23 13:20:38 +0100 | [diff] [blame] | 2068 | #endif |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 2069 | |
Laurent Pinchart | 69497eb | 2017-01-17 10:29:00 +0200 | [diff] [blame] | 2070 | ret = dw_hdmi_fb_registered(hdmi); |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 2071 | if (ret) |
| 2072 | goto err_iahb; |
| 2073 | |
Russell King | d94905e | 2013-11-03 22:23:24 +0000 | [diff] [blame] | 2074 | /* Unmute interrupts */ |
Russell King | aeac23b | 2015-06-05 13:46:22 +0100 | [diff] [blame] | 2075 | hdmi_writeb(hdmi, ~(HDMI_IH_PHY_STAT0_HPD | HDMI_IH_PHY_STAT0_RX_SENSE), |
| 2076 | HDMI_IH_MUTE_PHY_STAT0); |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 2077 | |
Russell King | 7ed6c66 | 2013-11-07 16:01:45 +0000 | [diff] [blame] | 2078 | memset(&pdevinfo, 0, sizeof(pdevinfo)); |
| 2079 | pdevinfo.parent = dev; |
| 2080 | pdevinfo.id = PLATFORM_DEVID_AUTO; |
| 2081 | |
Kuninori Morimoto | 2761ba6 | 2016-11-08 01:00:57 +0000 | [diff] [blame] | 2082 | config0 = hdmi_readb(hdmi, HDMI_CONFIG0_ID); |
Laurent Pinchart | 0c67494 | 2017-01-17 10:29:04 +0200 | [diff] [blame] | 2083 | config3 = hdmi_readb(hdmi, HDMI_CONFIG3_ID); |
Kuninori Morimoto | 2761ba6 | 2016-11-08 01:00:57 +0000 | [diff] [blame] | 2084 | |
Laurent Pinchart | 0c67494 | 2017-01-17 10:29:04 +0200 | [diff] [blame] | 2085 | if (config3 & HDMI_CONFIG3_AHBAUDDMA) { |
Kuninori Morimoto | 2761ba6 | 2016-11-08 01:00:57 +0000 | [diff] [blame] | 2086 | struct dw_hdmi_audio_data audio; |
| 2087 | |
Russell King | 7ed6c66 | 2013-11-07 16:01:45 +0000 | [diff] [blame] | 2088 | audio.phys = iores->start; |
| 2089 | audio.base = hdmi->regs; |
| 2090 | audio.irq = irq; |
| 2091 | audio.hdmi = hdmi; |
Russell King | f5ce405 | 2013-11-07 16:06:01 +0000 | [diff] [blame] | 2092 | audio.eld = hdmi->connector.eld; |
Russell King | 7ed6c66 | 2013-11-07 16:01:45 +0000 | [diff] [blame] | 2093 | |
| 2094 | pdevinfo.name = "dw-hdmi-ahb-audio"; |
| 2095 | pdevinfo.data = &audio; |
| 2096 | pdevinfo.size_data = sizeof(audio); |
| 2097 | pdevinfo.dma_mask = DMA_BIT_MASK(32); |
| 2098 | hdmi->audio = platform_device_register_full(&pdevinfo); |
Kuninori Morimoto | 2761ba6 | 2016-11-08 01:00:57 +0000 | [diff] [blame] | 2099 | } else if (config0 & HDMI_CONFIG0_I2S) { |
| 2100 | struct dw_hdmi_i2s_audio_data audio; |
| 2101 | |
| 2102 | audio.hdmi = hdmi; |
| 2103 | audio.write = hdmi_writeb; |
| 2104 | audio.read = hdmi_readb; |
| 2105 | |
| 2106 | pdevinfo.name = "dw-hdmi-i2s-audio"; |
| 2107 | pdevinfo.data = &audio; |
| 2108 | pdevinfo.size_data = sizeof(audio); |
| 2109 | pdevinfo.dma_mask = DMA_BIT_MASK(32); |
| 2110 | hdmi->audio = platform_device_register_full(&pdevinfo); |
Russell King | 7ed6c66 | 2013-11-07 16:01:45 +0000 | [diff] [blame] | 2111 | } |
| 2112 | |
Vladimir Zapolskiy | 3efc2fa | 2016-08-24 08:46:37 +0300 | [diff] [blame] | 2113 | /* Reset HDMI DDC I2C master controller and mute I2CM interrupts */ |
| 2114 | if (hdmi->i2c) |
| 2115 | dw_hdmi_i2c_init(hdmi); |
| 2116 | |
Laurent Pinchart | c608119 | 2017-01-17 10:28:57 +0200 | [diff] [blame] | 2117 | platform_set_drvdata(pdev, hdmi); |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 2118 | |
Laurent Pinchart | 69497eb | 2017-01-17 10:29:00 +0200 | [diff] [blame] | 2119 | return hdmi; |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 2120 | |
| 2121 | err_iahb: |
Vladimir Zapolskiy | 3efc2fa | 2016-08-24 08:46:37 +0300 | [diff] [blame] | 2122 | if (hdmi->i2c) { |
| 2123 | i2c_del_adapter(&hdmi->i2c->adap); |
| 2124 | hdmi->ddc = NULL; |
| 2125 | } |
| 2126 | |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 2127 | clk_disable_unprepare(hdmi->iahb_clk); |
| 2128 | err_isfr: |
| 2129 | clk_disable_unprepare(hdmi->isfr_clk); |
Vladimir Zapolskiy | 9f04a1f | 2016-08-16 23:26:43 +0300 | [diff] [blame] | 2130 | err_res: |
| 2131 | i2c_put_adapter(hdmi->ddc); |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 2132 | |
Laurent Pinchart | 69497eb | 2017-01-17 10:29:00 +0200 | [diff] [blame] | 2133 | return ERR_PTR(ret); |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 2134 | } |
| 2135 | |
Laurent Pinchart | 69497eb | 2017-01-17 10:29:00 +0200 | [diff] [blame] | 2136 | static void __dw_hdmi_remove(struct dw_hdmi *hdmi) |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 2137 | { |
Russell King | 7ed6c66 | 2013-11-07 16:01:45 +0000 | [diff] [blame] | 2138 | if (hdmi->audio && !IS_ERR(hdmi->audio)) |
| 2139 | platform_device_unregister(hdmi->audio); |
| 2140 | |
Russell King | d94905e | 2013-11-03 22:23:24 +0000 | [diff] [blame] | 2141 | /* Disable all interrupts */ |
| 2142 | hdmi_writeb(hdmi, ~0, HDMI_IH_MUTE_PHY_STAT0); |
| 2143 | |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 2144 | clk_disable_unprepare(hdmi->iahb_clk); |
| 2145 | clk_disable_unprepare(hdmi->isfr_clk); |
Vladimir Zapolskiy | 3efc2fa | 2016-08-24 08:46:37 +0300 | [diff] [blame] | 2146 | |
| 2147 | if (hdmi->i2c) |
| 2148 | i2c_del_adapter(&hdmi->i2c->adap); |
| 2149 | else |
| 2150 | i2c_put_adapter(hdmi->ddc); |
Russell King | 17b5001 | 2013-11-03 11:23:34 +0000 | [diff] [blame] | 2151 | } |
Laurent Pinchart | 69497eb | 2017-01-17 10:29:00 +0200 | [diff] [blame] | 2152 | |
| 2153 | /* ----------------------------------------------------------------------------- |
| 2154 | * Probe/remove API, used from platforms based on the DRM bridge API. |
| 2155 | */ |
| 2156 | int dw_hdmi_probe(struct platform_device *pdev, |
| 2157 | const struct dw_hdmi_plat_data *plat_data) |
| 2158 | { |
| 2159 | struct dw_hdmi *hdmi; |
| 2160 | int ret; |
| 2161 | |
| 2162 | hdmi = __dw_hdmi_probe(pdev, plat_data); |
| 2163 | if (IS_ERR(hdmi)) |
| 2164 | return PTR_ERR(hdmi); |
| 2165 | |
| 2166 | ret = drm_bridge_add(&hdmi->bridge); |
| 2167 | if (ret < 0) { |
| 2168 | __dw_hdmi_remove(hdmi); |
| 2169 | return ret; |
| 2170 | } |
| 2171 | |
| 2172 | return 0; |
| 2173 | } |
| 2174 | EXPORT_SYMBOL_GPL(dw_hdmi_probe); |
| 2175 | |
| 2176 | void dw_hdmi_remove(struct platform_device *pdev) |
| 2177 | { |
| 2178 | struct dw_hdmi *hdmi = platform_get_drvdata(pdev); |
| 2179 | |
| 2180 | drm_bridge_remove(&hdmi->bridge); |
| 2181 | |
| 2182 | __dw_hdmi_remove(hdmi); |
| 2183 | } |
| 2184 | EXPORT_SYMBOL_GPL(dw_hdmi_remove); |
| 2185 | |
| 2186 | /* ----------------------------------------------------------------------------- |
| 2187 | * Bind/unbind API, used from platforms based on the component framework. |
| 2188 | */ |
| 2189 | int dw_hdmi_bind(struct platform_device *pdev, struct drm_encoder *encoder, |
| 2190 | const struct dw_hdmi_plat_data *plat_data) |
| 2191 | { |
| 2192 | struct dw_hdmi *hdmi; |
| 2193 | int ret; |
| 2194 | |
| 2195 | hdmi = __dw_hdmi_probe(pdev, plat_data); |
| 2196 | if (IS_ERR(hdmi)) |
| 2197 | return PTR_ERR(hdmi); |
| 2198 | |
| 2199 | ret = drm_bridge_attach(encoder, &hdmi->bridge, NULL); |
| 2200 | if (ret) { |
| 2201 | dw_hdmi_remove(pdev); |
| 2202 | DRM_ERROR("Failed to initialize bridge with drm\n"); |
| 2203 | return ret; |
| 2204 | } |
| 2205 | |
| 2206 | return 0; |
| 2207 | } |
| 2208 | EXPORT_SYMBOL_GPL(dw_hdmi_bind); |
| 2209 | |
| 2210 | void dw_hdmi_unbind(struct device *dev) |
| 2211 | { |
| 2212 | struct dw_hdmi *hdmi = dev_get_drvdata(dev); |
| 2213 | |
| 2214 | __dw_hdmi_remove(hdmi); |
| 2215 | } |
Andy Yan | b21f4b6 | 2014-12-05 14:26:31 +0800 | [diff] [blame] | 2216 | EXPORT_SYMBOL_GPL(dw_hdmi_unbind); |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 2217 | |
| 2218 | MODULE_AUTHOR("Sascha Hauer <s.hauer@pengutronix.de>"); |
Andy Yan | 3d1b35a | 2014-12-05 14:25:05 +0800 | [diff] [blame] | 2219 | MODULE_AUTHOR("Andy Yan <andy.yan@rock-chips.com>"); |
| 2220 | MODULE_AUTHOR("Yakir Yang <ykk@rock-chips.com>"); |
Vladimir Zapolskiy | 3efc2fa | 2016-08-24 08:46:37 +0300 | [diff] [blame] | 2221 | MODULE_AUTHOR("Vladimir Zapolskiy <vladimir_zapolskiy@mentor.com>"); |
Andy Yan | b21f4b6 | 2014-12-05 14:26:31 +0800 | [diff] [blame] | 2222 | MODULE_DESCRIPTION("DW HDMI transmitter driver"); |
Fabio Estevam | 9aaf880 | 2013-11-29 08:46:32 -0200 | [diff] [blame] | 2223 | MODULE_LICENSE("GPL"); |
Andy Yan | b21f4b6 | 2014-12-05 14:26:31 +0800 | [diff] [blame] | 2224 | MODULE_ALIAS("platform:dw-hdmi"); |