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