| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 1 | /* Copyright (c) 2010-2011, Code Aurora Forum. All rights reserved. |
| 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | /* #define DEBUG */ |
| 15 | #define DEV_DBG_PREFIX "HDMI: " |
| 16 | /* #define REG_DUMP */ |
| 17 | |
| 18 | #include <linux/types.h> |
| 19 | #include <linux/bitops.h> |
| 20 | #include <linux/clk.h> |
| 21 | #include <linux/mutex.h> |
| 22 | #include <mach/msm_hdmi_audio.h> |
| 23 | #include <mach/clk.h> |
| 24 | #include <mach/msm_iomap.h> |
| Stepan Moskovchenko | 164fe8a | 2011-08-05 18:10:54 -0700 | [diff] [blame] | 25 | #include <mach/socinfo.h> |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 26 | |
| 27 | #include "msm_fb.h" |
| 28 | #include "hdmi_msm.h" |
| 29 | |
| 30 | /* Supported HDMI Audio channels */ |
| 31 | #define MSM_HDMI_AUDIO_CHANNEL_2 0 |
| 32 | #define MSM_HDMI_AUDIO_CHANNEL_4 1 |
| 33 | #define MSM_HDMI_AUDIO_CHANNEL_6 2 |
| 34 | #define MSM_HDMI_AUDIO_CHANNEL_8 3 |
| 35 | #define MSM_HDMI_AUDIO_CHANNEL_MAX 4 |
| 36 | #define MSM_HDMI_AUDIO_CHANNEL_FORCE_32BIT 0x7FFFFFFF |
| 37 | |
| 38 | /* Supported HDMI Audio sample rates */ |
| 39 | #define MSM_HDMI_SAMPLE_RATE_32KHZ 0 |
| 40 | #define MSM_HDMI_SAMPLE_RATE_44_1KHZ 1 |
| 41 | #define MSM_HDMI_SAMPLE_RATE_48KHZ 2 |
| 42 | #define MSM_HDMI_SAMPLE_RATE_88_2KHZ 3 |
| 43 | #define MSM_HDMI_SAMPLE_RATE_96KHZ 4 |
| 44 | #define MSM_HDMI_SAMPLE_RATE_176_4KHZ 5 |
| 45 | #define MSM_HDMI_SAMPLE_RATE_192KHZ 6 |
| 46 | #define MSM_HDMI_SAMPLE_RATE_MAX 7 |
| 47 | #define MSM_HDMI_SAMPLE_RATE_FORCE_32BIT 0x7FFFFFFF |
| 48 | |
| 49 | struct workqueue_struct *hdmi_work_queue; |
| 50 | struct hdmi_msm_state_type *hdmi_msm_state; |
| 51 | |
| 52 | static DEFINE_MUTEX(hdmi_msm_state_mutex); |
| 53 | static DEFINE_MUTEX(hdcp_auth_state_mutex); |
| 54 | |
| 55 | #ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT |
| 56 | static void hdmi_msm_hdcp_enable(void); |
| 57 | #else |
| 58 | static inline void hdmi_msm_hdcp_enable(void) {} |
| 59 | #endif |
| 60 | |
| 61 | uint32 hdmi_msm_get_io_base(void) |
| 62 | { |
| 63 | return (uint32)MSM_HDMI_BASE; |
| 64 | } |
| 65 | EXPORT_SYMBOL(hdmi_msm_get_io_base); |
| 66 | |
| 67 | /* Table indicating the video format supported by the HDMI TX Core v1.0 */ |
| 68 | /* Valid Pixel-Clock rates: 25.2MHz, 27MHz, 27.03MHz, 74.25MHz, 148.5MHz */ |
| 69 | static void hdmi_msm_setup_video_mode_lut(void) |
| 70 | { |
| 71 | HDMI_SETUP_LUT(640x480p60_4_3); |
| 72 | HDMI_SETUP_LUT(720x480p60_4_3); |
| 73 | HDMI_SETUP_LUT(720x480p60_16_9); |
| 74 | HDMI_SETUP_LUT(1280x720p60_16_9); |
| 75 | HDMI_SETUP_LUT(1920x1080i60_16_9); |
| 76 | HDMI_SETUP_LUT(1440x480i60_4_3); |
| 77 | HDMI_SETUP_LUT(1440x480i60_16_9); |
| 78 | HDMI_SETUP_LUT(1920x1080p60_16_9); |
| 79 | HDMI_SETUP_LUT(720x576p50_4_3); |
| 80 | HDMI_SETUP_LUT(720x576p50_16_9); |
| 81 | HDMI_SETUP_LUT(1280x720p50_16_9); |
| 82 | HDMI_SETUP_LUT(1440x576i50_4_3); |
| 83 | HDMI_SETUP_LUT(1440x576i50_16_9); |
| 84 | HDMI_SETUP_LUT(1920x1080p50_16_9); |
| 85 | HDMI_SETUP_LUT(1920x1080p24_16_9); |
| 86 | HDMI_SETUP_LUT(1920x1080p25_16_9); |
| 87 | HDMI_SETUP_LUT(1920x1080p30_16_9); |
| 88 | } |
| 89 | |
| 90 | #ifdef PORT_DEBUG |
| 91 | const char *hdmi_msm_name(uint32 offset) |
| 92 | { |
| 93 | switch (offset) { |
| 94 | case 0x0000: return "CTRL"; |
| 95 | case 0x0020: return "AUDIO_PKT_CTRL1"; |
| 96 | case 0x0024: return "ACR_PKT_CTRL"; |
| 97 | case 0x0028: return "VBI_PKT_CTRL"; |
| 98 | case 0x002C: return "INFOFRAME_CTRL0"; |
| 99 | #ifdef CONFIG_FB_MSM_HDMI_3D |
| 100 | case 0x0034: return "GEN_PKT_CTRL"; |
| 101 | #endif |
| 102 | case 0x003C: return "ACP"; |
| 103 | case 0x0040: return "GC"; |
| 104 | case 0x0044: return "AUDIO_PKT_CTRL2"; |
| 105 | case 0x0048: return "ISRC1_0"; |
| 106 | case 0x004C: return "ISRC1_1"; |
| 107 | case 0x0050: return "ISRC1_2"; |
| 108 | case 0x0054: return "ISRC1_3"; |
| 109 | case 0x0058: return "ISRC1_4"; |
| 110 | case 0x005C: return "ISRC2_0"; |
| 111 | case 0x0060: return "ISRC2_1"; |
| 112 | case 0x0064: return "ISRC2_2"; |
| 113 | case 0x0068: return "ISRC2_3"; |
| 114 | case 0x006C: return "AVI_INFO0"; |
| 115 | case 0x0070: return "AVI_INFO1"; |
| 116 | case 0x0074: return "AVI_INFO2"; |
| 117 | case 0x0078: return "AVI_INFO3"; |
| 118 | #ifdef CONFIG_FB_MSM_HDMI_3D |
| 119 | case 0x0084: return "GENERIC0_HDR"; |
| 120 | case 0x0088: return "GENERIC0_0"; |
| 121 | case 0x008C: return "GENERIC0_1"; |
| 122 | #endif |
| 123 | case 0x00C4: return "ACR_32_0"; |
| 124 | case 0x00C8: return "ACR_32_1"; |
| 125 | case 0x00CC: return "ACR_44_0"; |
| 126 | case 0x00D0: return "ACR_44_1"; |
| 127 | case 0x00D4: return "ACR_48_0"; |
| 128 | case 0x00D8: return "ACR_48_1"; |
| 129 | case 0x00E4: return "AUDIO_INFO0"; |
| 130 | case 0x00E8: return "AUDIO_INFO1"; |
| 131 | #ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT |
| 132 | case 0x0110: return "HDCP_CTRL"; |
| 133 | case 0x0114: return "HDCP_DEBUG_CTRL"; |
| 134 | case 0x0118: return "HDCP_INT_CTRL"; |
| 135 | case 0x011C: return "HDCP_LINK0_STATUS"; |
| 136 | case 0x012C: return "HDCP_ENTROPY_CTRL0"; |
| 137 | case 0x0130: return "HDCP_RESET"; |
| 138 | case 0x0134: return "HDCP_RCVPORT_DATA0"; |
| 139 | case 0x0138: return "HDCP_RCVPORT_DATA1"; |
| 140 | case 0x013C: return "HDCP_RCVPORT_DATA2"; |
| 141 | case 0x0144: return "HDCP_RCVPORT_DATA3"; |
| 142 | case 0x0148: return "HDCP_RCVPORT_DATA4"; |
| 143 | case 0x014C: return "HDCP_RCVPORT_DATA5"; |
| 144 | case 0x0150: return "HDCP_RCVPORT_DATA6"; |
| 145 | case 0x0168: return "HDCP_RCVPORT_DATA12"; |
| 146 | #endif /* CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT */ |
| 147 | case 0x01D0: return "AUDIO_CFG"; |
| 148 | case 0x0208: return "USEC_REFTIMER"; |
| 149 | case 0x020C: return "DDC_CTRL"; |
| 150 | case 0x0214: return "DDC_INT_CTRL"; |
| 151 | case 0x0218: return "DDC_SW_STATUS"; |
| 152 | case 0x021C: return "DDC_HW_STATUS"; |
| 153 | case 0x0220: return "DDC_SPEED"; |
| 154 | case 0x0224: return "DDC_SETUP"; |
| 155 | case 0x0228: return "DDC_TRANS0"; |
| 156 | case 0x022C: return "DDC_TRANS1"; |
| 157 | case 0x0238: return "DDC_DATA"; |
| 158 | case 0x0250: return "HPD_INT_STATUS"; |
| 159 | case 0x0254: return "HPD_INT_CTRL"; |
| 160 | case 0x0258: return "HPD_CTRL"; |
| 161 | #ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT |
| 162 | case 0x025C: return "HDCP_ENTROPY_CTRL1"; |
| 163 | #endif /* CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT */ |
| 164 | case 0x027C: return "DDC_REF"; |
| 165 | #ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT |
| 166 | case 0x0284: return "HDCP_SW_UPPER_AKSV"; |
| 167 | case 0x0288: return "HDCP_SW_LOWER_AKSV"; |
| 168 | #endif /* CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT */ |
| 169 | case 0x02B4: return "ACTIVE_H"; |
| 170 | case 0x02B8: return "ACTIVE_V"; |
| 171 | case 0x02BC: return "ACTIVE_V_F2"; |
| 172 | case 0x02C0: return "TOTAL"; |
| 173 | case 0x02C4: return "V_TOTAL_F2"; |
| 174 | case 0x02C8: return "FRAME_CTRL"; |
| 175 | case 0x02CC: return "AUD_INT"; |
| 176 | case 0x0300: return "PHY_REG0"; |
| 177 | case 0x0304: return "PHY_REG1"; |
| 178 | case 0x0308: return "PHY_REG2"; |
| 179 | case 0x030C: return "PHY_REG3"; |
| 180 | case 0x0310: return "PHY_REG4"; |
| 181 | case 0x0314: return "PHY_REG5"; |
| 182 | case 0x0318: return "PHY_REG6"; |
| 183 | case 0x031C: return "PHY_REG7"; |
| 184 | case 0x0320: return "PHY_REG8"; |
| 185 | case 0x0324: return "PHY_REG9"; |
| 186 | case 0x0328: return "PHY_REG10"; |
| 187 | case 0x032C: return "PHY_REG11"; |
| 188 | case 0x0330: return "PHY_REG12"; |
| 189 | default: return "???"; |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | void hdmi_outp(uint32 offset, uint32 value) |
| 194 | { |
| 195 | uint32 in_val; |
| 196 | |
| 197 | outpdw(MSM_HDMI_BASE+offset, value); |
| 198 | in_val = inpdw(MSM_HDMI_BASE+offset); |
| 199 | DEV_DBG("HDMI[%04x] => %08x [%08x] %s\n", |
| 200 | offset, value, in_val, hdmi_msm_name(offset)); |
| 201 | } |
| 202 | |
| 203 | uint32 hdmi_inp(uint32 offset) |
| 204 | { |
| 205 | uint32 value = inpdw(MSM_HDMI_BASE+offset); |
| 206 | DEV_DBG("HDMI[%04x] <= %08x %s\n", |
| 207 | offset, value, hdmi_msm_name(offset)); |
| 208 | return value; |
| 209 | } |
| 210 | #endif /* DEBUG */ |
| 211 | |
| 212 | static void hdmi_msm_turn_on(void); |
| 213 | static int hdmi_msm_audio_off(void); |
| 214 | static int hdmi_msm_read_edid(void); |
| 215 | static void hdmi_msm_hpd_off(void); |
| 216 | |
| 217 | static void hdmi_msm_hpd_state_work(struct work_struct *work) |
| 218 | { |
| 219 | boolean hpd_state; |
| 220 | char *envp[2]; |
| 221 | |
| 222 | if (!hdmi_msm_state || !hdmi_msm_state->hpd_initialized || |
| 223 | !MSM_HDMI_BASE) { |
| 224 | DEV_DBG("%s: ignored, probe failed\n", __func__); |
| 225 | return; |
| 226 | } |
| 227 | #ifdef CONFIG_SUSPEND |
| 228 | mutex_lock(&hdmi_msm_state_mutex); |
| 229 | if (hdmi_msm_state->pm_suspended) { |
| 230 | mutex_unlock(&hdmi_msm_state_mutex); |
| 231 | DEV_WARN("%s: ignored, pm_suspended\n", __func__); |
| 232 | return; |
| 233 | } |
| 234 | mutex_unlock(&hdmi_msm_state_mutex); |
| 235 | #endif |
| 236 | |
| Manoj Rao | b91fa71 | 2011-06-29 09:07:55 -0700 | [diff] [blame] | 237 | DEV_DBG("%s:Got interrupt\n", __func__); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 238 | /* HPD_INT_STATUS[0x0250] */ |
| 239 | hpd_state = (HDMI_INP(0x0250) & 0x2) >> 1; |
| 240 | mutex_lock(&external_common_state_hpd_mutex); |
| 241 | mutex_lock(&hdmi_msm_state_mutex); |
| 242 | if ((external_common_state->hpd_state != hpd_state) || (hdmi_msm_state-> |
| 243 | hpd_prev_state != external_common_state->hpd_state)) { |
| 244 | external_common_state->hpd_state = hpd_state; |
| 245 | hdmi_msm_state->hpd_prev_state = |
| 246 | external_common_state->hpd_state; |
| 247 | DEV_DBG("%s: state not stable yet, wait again (%d|%d|%d)\n", |
| 248 | __func__, hdmi_msm_state->hpd_prev_state, |
| 249 | external_common_state->hpd_state, hpd_state); |
| 250 | mutex_unlock(&external_common_state_hpd_mutex); |
| 251 | hdmi_msm_state->hpd_stable = 0; |
| 252 | mutex_unlock(&hdmi_msm_state_mutex); |
| 253 | mod_timer(&hdmi_msm_state->hpd_state_timer, jiffies + HZ/2); |
| 254 | return; |
| 255 | } |
| 256 | mutex_unlock(&external_common_state_hpd_mutex); |
| 257 | |
| 258 | if (hdmi_msm_state->hpd_stable++) { |
| 259 | mutex_unlock(&hdmi_msm_state_mutex); |
| 260 | DEV_DBG("%s: no more timer, depending for IRQ now\n", |
| 261 | __func__); |
| 262 | return; |
| 263 | } |
| 264 | |
| 265 | hdmi_msm_state->hpd_stable = 1; |
| 266 | DEV_INFO("HDMI HPD: event detected\n"); |
| 267 | |
| 268 | if (!hdmi_msm_state->hpd_cable_chg_detected) { |
| 269 | mutex_unlock(&hdmi_msm_state_mutex); |
| 270 | if (hpd_state) { |
| 271 | if (!external_common_state-> |
| 272 | disp_mode_list.num_of_elements) |
| 273 | hdmi_msm_read_edid(); |
| 274 | hdmi_msm_turn_on(); |
| 275 | } |
| 276 | } else { |
| 277 | hdmi_msm_state->hpd_cable_chg_detected = FALSE; |
| 278 | mutex_unlock(&hdmi_msm_state_mutex); |
| 279 | if (hpd_state) { |
| 280 | hdmi_msm_read_edid(); |
| 281 | #ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT |
| 282 | hdmi_msm_state->reauth = FALSE ; |
| 283 | #endif |
| 284 | /* Build EDID table */ |
| 285 | envp[0] = "HDCP_STATE=FAIL"; |
| 286 | envp[1] = NULL; |
| 287 | DEV_INFO("HDMI HPD: QDSP OFF\n"); |
| 288 | kobject_uevent_env(external_common_state->uevent_kobj, |
| 289 | KOBJ_CHANGE, envp); |
| 290 | hdmi_msm_turn_on(); |
| 291 | DEV_INFO("HDMI HPD: sense CONNECTED: send ONLINE\n"); |
| 292 | kobject_uevent(external_common_state->uevent_kobj, |
| 293 | KOBJ_ONLINE); |
| 294 | hdmi_msm_hdcp_enable(); |
| Abhishek Kharbanda | d5315bd | 2011-08-10 19:45:53 -0700 | [diff] [blame] | 295 | #ifndef CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT |
| 296 | /* Send Audio for HDMI Compliance Cases*/ |
| 297 | envp[0] = "HDCP_STATE=PASS"; |
| 298 | envp[1] = NULL; |
| 299 | DEV_INFO("HDMI HPD: sense : send HDCP_PASS\n"); |
| 300 | kobject_uevent_env(external_common_state->uevent_kobj, |
| 301 | KOBJ_CHANGE, envp); |
| 302 | #endif |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 303 | } else { |
| 304 | DEV_INFO("HDMI HPD: sense DISCONNECTED: send OFFLINE\n" |
| 305 | ); |
| 306 | kobject_uevent(external_common_state->uevent_kobj, |
| 307 | KOBJ_OFFLINE); |
| 308 | } |
| 309 | } |
| 310 | |
| 311 | /* HPD_INT_CTRL[0x0254] |
| 312 | * 31:10 Reserved |
| 313 | * 9 RCV_PLUGIN_DET_MASK receiver plug in interrupt mask. |
| 314 | * When programmed to 1, |
| 315 | * RCV_PLUGIN_DET_INT will toggle |
| 316 | * the interrupt line |
| 317 | * 8:6 Reserved |
| 318 | * 5 RX_INT_EN Panel RX interrupt enable |
| 319 | * 0: Disable |
| 320 | * 1: Enable |
| 321 | * 4 RX_INT_ACK WRITE ONLY. Panel RX interrupt |
| 322 | * ack |
| 323 | * 3 Reserved |
| 324 | * 2 INT_EN Panel interrupt control |
| 325 | * 0: Disable |
| 326 | * 1: Enable |
| 327 | * 1 INT_POLARITY Panel interrupt polarity |
| 328 | * 0: generate interrupt on disconnect |
| 329 | * 1: generate interrupt on connect |
| 330 | * 0 INT_ACK WRITE ONLY. Panel interrupt ack */ |
| 331 | /* Set IRQ for HPD */ |
| 332 | HDMI_OUTP(0x0254, 4 | (hpd_state ? 0 : 2)); |
| 333 | } |
| 334 | |
| 335 | #ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT |
| 336 | static void hdcp_deauthenticate(void); |
| 337 | static void hdmi_msm_hdcp_reauth_work(struct work_struct *work) |
| 338 | { |
| 339 | #ifdef CONFIG_SUSPEND |
| 340 | mutex_lock(&hdmi_msm_state_mutex); |
| 341 | if (hdmi_msm_state->pm_suspended) { |
| 342 | mutex_unlock(&hdmi_msm_state_mutex); |
| 343 | DEV_WARN("HDCP: deauthenticating skipped, pm_suspended\n"); |
| 344 | return; |
| 345 | } |
| 346 | mutex_unlock(&hdmi_msm_state_mutex); |
| 347 | #endif |
| 348 | |
| 349 | /* Don't process recursive actions */ |
| 350 | mutex_lock(&hdmi_msm_state_mutex); |
| 351 | if (hdmi_msm_state->hdcp_activating) { |
| 352 | mutex_unlock(&hdmi_msm_state_mutex); |
| 353 | return; |
| 354 | } |
| 355 | mutex_unlock(&hdmi_msm_state_mutex); |
| 356 | |
| 357 | /* |
| 358 | * Reauth=>deauth, hdcp_auth |
| 359 | * hdcp_auth=>turn_on() which calls |
| 360 | * HDMI Core reset without informing the Audio QDSP |
| 361 | * this can do bad things to video playback on the HDTV |
| 362 | * Therefore, as surprising as it may sound do reauth |
| 363 | * only if the device is HDCP-capable |
| 364 | */ |
| 365 | if (external_common_state->present_hdcp) { |
| 366 | hdcp_deauthenticate(); |
| 367 | mod_timer(&hdmi_msm_state->hdcp_timer, jiffies + HZ/2); |
| 368 | } |
| 369 | } |
| 370 | |
| 371 | static void hdmi_msm_hdcp_work(struct work_struct *work) |
| 372 | { |
| 373 | #ifdef CONFIG_SUSPEND |
| 374 | mutex_lock(&hdmi_msm_state_mutex); |
| 375 | if (hdmi_msm_state->pm_suspended) { |
| 376 | mutex_unlock(&hdmi_msm_state_mutex); |
| 377 | DEV_WARN("HDCP: Re-enable skipped, pm_suspended\n"); |
| 378 | return; |
| 379 | } |
| 380 | mutex_unlock(&hdmi_msm_state_mutex); |
| 381 | #endif |
| 382 | |
| 383 | /* Only re-enable if cable still connected */ |
| 384 | mutex_lock(&external_common_state_hpd_mutex); |
| 385 | if (external_common_state->hpd_state && |
| 386 | !(hdmi_msm_state->full_auth_done)) { |
| 387 | mutex_unlock(&external_common_state_hpd_mutex); |
| 388 | hdmi_msm_state->reauth = TRUE; |
| 389 | hdmi_msm_turn_on(); |
| 390 | } else |
| 391 | mutex_unlock(&external_common_state_hpd_mutex); |
| 392 | } |
| 393 | #endif /* CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT */ |
| 394 | |
| 395 | static irqreturn_t hdmi_msm_isr(int irq, void *dev_id) |
| 396 | { |
| 397 | uint32 hpd_int_status; |
| 398 | uint32 hpd_int_ctrl; |
| 399 | uint32 ddc_int_ctrl; |
| 400 | uint32 audio_int_val; |
| 401 | #ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT |
| 402 | uint32 hdcp_int_val; |
| 403 | char *envp[2]; |
| 404 | #endif /* CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT */ |
| 405 | static uint32 fifo_urun_int_occurred; |
| 406 | static uint32 sample_drop_int_occurred; |
| 407 | const uint32 occurrence_limit = 5; |
| 408 | |
| 409 | if (!hdmi_msm_state || !hdmi_msm_state->hpd_initialized || |
| 410 | !MSM_HDMI_BASE) { |
| 411 | DEV_DBG("ISR ignored, probe failed\n"); |
| 412 | return IRQ_HANDLED; |
| 413 | } |
| 414 | #ifdef CONFIG_SUSPEND |
| 415 | mutex_lock(&hdmi_msm_state_mutex); |
| 416 | if (hdmi_msm_state->pm_suspended) { |
| 417 | mutex_unlock(&hdmi_msm_state_mutex); |
| 418 | DEV_WARN("ISR ignored, pm_suspended\n"); |
| 419 | return IRQ_HANDLED; |
| 420 | } |
| 421 | mutex_unlock(&hdmi_msm_state_mutex); |
| 422 | #endif |
| 423 | |
| 424 | /* Process HPD Interrupt */ |
| 425 | /* HDMI_HPD_INT_STATUS[0x0250] */ |
| 426 | hpd_int_status = HDMI_INP_ND(0x0250); |
| 427 | /* HDMI_HPD_INT_CTRL[0x0254] */ |
| 428 | hpd_int_ctrl = HDMI_INP_ND(0x0254); |
| 429 | if ((hpd_int_ctrl & (1 << 2)) && (hpd_int_status & (1 << 0))) { |
| 430 | boolean cable_detected = (hpd_int_status & 2) >> 1; |
| 431 | |
| 432 | /* HDMI_HPD_INT_CTRL[0x0254] */ |
| Manoj Rao | f74d2edd | 2011-07-18 14:25:38 -0700 | [diff] [blame] | 433 | /* Clear all interrupts, timer will turn IRQ back on |
| 434 | * Leaving the bit[2] on, else core goes off |
| 435 | * on getting HPD during power off |
| 436 | */ |
| 437 | HDMI_OUTP(0x0254, (1 << 2) | (1 << 0)); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 438 | |
| 439 | DEV_DBG("%s: HPD IRQ, Ctrl=%04x, State=%04x\n", __func__, |
| 440 | hpd_int_ctrl, hpd_int_status); |
| 441 | mutex_lock(&hdmi_msm_state_mutex); |
| 442 | hdmi_msm_state->hpd_cable_chg_detected = TRUE; |
| 443 | |
| 444 | /* ensure 2 readouts */ |
| 445 | hdmi_msm_state->hpd_prev_state = cable_detected ? 0 : 1; |
| 446 | external_common_state->hpd_state = cable_detected ? 1 : 0; |
| 447 | hdmi_msm_state->hpd_stable = 0; |
| 448 | mod_timer(&hdmi_msm_state->hpd_state_timer, jiffies + HZ/2); |
| 449 | mutex_unlock(&hdmi_msm_state_mutex); |
| 450 | /* |
| 451 | * HDCP Compliance 1A-01: |
| 452 | * The Quantum Data Box 882 triggers two consecutive |
| 453 | * HPD events very close to each other as a part of this |
| 454 | * test which can trigger two parallel HDCP auth threads |
| 455 | * if HDCP authentication is going on and we get ISR |
| 456 | * then stop the authentication , rather than |
| 457 | * reauthenticating it again |
| 458 | */ |
| 459 | if (!(hdmi_msm_state->full_auth_done)) { |
| 460 | DEV_DBG("%s getting hpd while authenticating\n",\ |
| 461 | __func__); |
| 462 | mutex_lock(&hdcp_auth_state_mutex); |
| 463 | hdmi_msm_state->hpd_during_auth = TRUE; |
| 464 | mutex_unlock(&hdcp_auth_state_mutex); |
| 465 | } |
| 466 | return IRQ_HANDLED; |
| 467 | } |
| 468 | |
| 469 | /* Process DDC Interrupts */ |
| 470 | /* HDMI_DDC_INT_CTRL[0x0214] */ |
| 471 | ddc_int_ctrl = HDMI_INP_ND(0x0214); |
| 472 | if ((ddc_int_ctrl & (1 << 2)) && (ddc_int_ctrl & (1 << 0))) { |
| 473 | /* SW_DONE INT occured, clr it */ |
| 474 | HDMI_OUTP_ND(0x0214, ddc_int_ctrl | (1 << 1)); |
| 475 | complete(&hdmi_msm_state->ddc_sw_done); |
| 476 | return IRQ_HANDLED; |
| 477 | } |
| 478 | |
| 479 | /* FIFO Underrun Int is enabled */ |
| 480 | /* HDMI_AUD_INT[0x02CC] |
| 481 | * [3] AUD_SAM_DROP_MASK [R/W] |
| 482 | * [2] AUD_SAM_DROP_ACK [W], AUD_SAM_DROP_INT [R] |
| 483 | * [1] AUD_FIFO_URUN_MASK [R/W] |
| 484 | * [0] AUD_FIFO_URUN_ACK [W], AUD_FIFO_URUN_INT [R] */ |
| 485 | audio_int_val = HDMI_INP_ND(0x02CC); |
| 486 | if ((audio_int_val & (1 << 1)) && (audio_int_val & (1 << 0))) { |
| 487 | /* FIFO Underrun occured, clr it */ |
| 488 | HDMI_OUTP(0x02CC, audio_int_val | (1 << 0)); |
| 489 | |
| 490 | ++fifo_urun_int_occurred; |
| 491 | DEV_INFO("HDMI AUD_FIFO_URUN: %d\n", fifo_urun_int_occurred); |
| 492 | |
| 493 | if (fifo_urun_int_occurred >= occurrence_limit) { |
| 494 | HDMI_OUTP(0x02CC, HDMI_INP(0x02CC) & ~(1 << 1)); |
| 495 | DEV_INFO("HDMI AUD_FIFO_URUN: INT has been disabled " |
| 496 | "by the ISR after %d occurences...\n", |
| 497 | fifo_urun_int_occurred); |
| 498 | } |
| 499 | return IRQ_HANDLED; |
| 500 | } |
| 501 | |
| 502 | /* Audio Sample Drop int is enabled */ |
| 503 | if ((audio_int_val & (1 << 3)) && (audio_int_val & (1 << 2))) { |
| 504 | /* Audio Sample Drop occured, clr it */ |
| 505 | HDMI_OUTP(0x02CC, audio_int_val | (1 << 2)); |
| 506 | DEV_DBG("%s: AUD_SAM_DROP", __func__); |
| 507 | |
| 508 | ++sample_drop_int_occurred; |
| 509 | if (sample_drop_int_occurred >= occurrence_limit) { |
| 510 | HDMI_OUTP(0x02CC, HDMI_INP(0x02CC) & ~(1 << 3)); |
| 511 | DEV_INFO("HDMI AUD_SAM_DROP: INT has been disabled " |
| 512 | "by the ISR after %d occurences...\n", |
| 513 | sample_drop_int_occurred); |
| 514 | } |
| 515 | return IRQ_HANDLED; |
| 516 | } |
| 517 | |
| 518 | #ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT |
| 519 | /* HDCP_INT_CTRL[0x0118] |
| 520 | * [0] AUTH_SUCCESS_INT [R] HDCP Authentication Success |
| 521 | * interrupt status |
| 522 | * [1] AUTH_SUCCESS_ACK [W] Acknowledge bit for HDCP |
| 523 | * Authentication Success bit - write 1 to clear |
| 524 | * [2] AUTH_SUCCESS_MASK [R/W] Mask bit for HDCP Authentication |
| 525 | * Success interrupt - set to 1 to enable interrupt */ |
| 526 | hdcp_int_val = HDMI_INP_ND(0x0118); |
| 527 | if ((hdcp_int_val & (1 << 2)) && (hdcp_int_val & (1 << 0))) { |
| 528 | /* AUTH_SUCCESS_INT */ |
| 529 | HDMI_OUTP(0x0118, (hdcp_int_val | (1 << 1)) & ~(1 << 0)); |
| 530 | DEV_INFO("HDCP: AUTH_SUCCESS_INT received\n"); |
| 531 | complete_all(&hdmi_msm_state->hdcp_success_done); |
| 532 | return IRQ_HANDLED; |
| 533 | } |
| 534 | /* [4] AUTH_FAIL_INT [R] HDCP Authentication Lost |
| 535 | * interrupt Status |
| 536 | * [5] AUTH_FAIL_ACK [W] Acknowledge bit for HDCP |
| 537 | * Authentication Lost bit - write 1 to clear |
| 538 | * [6] AUTH_FAIL_MASK [R/W] Mask bit fo HDCP Authentication |
| 539 | * Lost interrupt set to 1 to enable interrupt |
| 540 | * [7] AUTH_FAIL_INFO_ACK [W] Acknowledge bit for HDCP |
| 541 | * Authentication Failure Info field - write 1 to clear */ |
| 542 | if ((hdcp_int_val & (1 << 6)) && (hdcp_int_val & (1 << 4))) { |
| 543 | /* AUTH_FAIL_INT */ |
| 544 | /* Clear and Disable */ |
| 545 | HDMI_OUTP(0x0118, (hdcp_int_val | (1 << 5)) |
| 546 | & ~((1 << 6) | (1 << 4))); |
| 547 | DEV_INFO("HDCP: AUTH_FAIL_INT received, LINK0_STATUS=0x%08x\n", |
| 548 | HDMI_INP_ND(0x011C)); |
| 549 | if (hdmi_msm_state->full_auth_done) { |
| 550 | envp[0] = "HDCP_STATE=FAIL"; |
| 551 | envp[1] = NULL; |
| 552 | DEV_INFO("HDMI HPD:QDSP OFF\n"); |
| 553 | kobject_uevent_env(external_common_state->uevent_kobj, |
| 554 | KOBJ_CHANGE, envp); |
| 555 | mutex_lock(&hdcp_auth_state_mutex); |
| 556 | hdmi_msm_state->full_auth_done = FALSE; |
| 557 | mutex_unlock(&hdcp_auth_state_mutex); |
| 558 | /* Calling reauth only when authentication |
| 559 | * is sucessful or else we always go into |
| 560 | * the reauth loop |
| 561 | */ |
| 562 | queue_work(hdmi_work_queue, |
| 563 | &hdmi_msm_state->hdcp_reauth_work); |
| 564 | } |
| 565 | mutex_lock(&hdcp_auth_state_mutex); |
| 566 | /* This flag prevents other threads from re-authenticating |
| 567 | * after we've just authenticated (i.e., finished part3) |
| 568 | */ |
| 569 | hdmi_msm_state->full_auth_done = FALSE; |
| 570 | |
| 571 | mutex_unlock(&hdcp_auth_state_mutex); |
| 572 | DEV_DBG("calling reauthenticate from %s HDCP FAIL INT ", |
| 573 | __func__); |
| 574 | |
| 575 | return IRQ_HANDLED; |
| 576 | } |
| 577 | /* [8] DDC_XFER_REQ_INT [R] HDCP DDC Transfer Request |
| 578 | * interrupt status |
| 579 | * [9] DDC_XFER_REQ_ACK [W] Acknowledge bit for HDCP DDC |
| 580 | * Transfer Request bit - write 1 to clear |
| 581 | * [10] DDC_XFER_REQ_MASK [R/W] Mask bit for HDCP DDC Transfer |
| 582 | * Request interrupt - set to 1 to enable interrupt */ |
| 583 | if ((hdcp_int_val & (1 << 10)) && (hdcp_int_val & (1 << 8))) { |
| 584 | /* DDC_XFER_REQ_INT */ |
| 585 | HDMI_OUTP_ND(0x0118, (hdcp_int_val | (1 << 9)) & ~(1 << 8)); |
| 586 | if (!(hdcp_int_val & (1 << 12))) |
| 587 | return IRQ_HANDLED; |
| 588 | } |
| 589 | /* [12] DDC_XFER_DONE_INT [R] HDCP DDC Transfer done interrupt |
| 590 | * status |
| 591 | * [13] DDC_XFER_DONE_ACK [W] Acknowledge bit for HDCP DDC |
| 592 | * Transfer done bit - write 1 to clear |
| 593 | * [14] DDC_XFER_DONE_MASK [R/W] Mask bit for HDCP DDC Transfer |
| 594 | * done interrupt - set to 1 to enable interrupt */ |
| 595 | if ((hdcp_int_val & (1 << 14)) && (hdcp_int_val & (1 << 12))) { |
| 596 | /* DDC_XFER_DONE_INT */ |
| 597 | HDMI_OUTP_ND(0x0118, (hdcp_int_val | (1 << 13)) & ~(1 << 12)); |
| 598 | DEV_INFO("HDCP: DDC_XFER_DONE received\n"); |
| 599 | return IRQ_HANDLED; |
| 600 | } |
| 601 | #endif /* CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT */ |
| 602 | |
| 603 | DEV_DBG("%s: HPD<Ctrl=%04x, State=%04x>, ddc_int_ctrl=%04x, " |
| 604 | "aud_int=%04x, cec_int=%04x\n", __func__, hpd_int_ctrl, |
| 605 | hpd_int_status, ddc_int_ctrl, audio_int_val, |
| 606 | HDMI_INP_ND(0x029C)); |
| 607 | |
| 608 | return IRQ_HANDLED; |
| 609 | } |
| 610 | |
| 611 | static int check_hdmi_features(void) |
| 612 | { |
| 613 | /* RAW_FEAT_CONFIG_ROW0_LSB */ |
| 614 | uint32 val = inpdw(QFPROM_BASE + 0x0238); |
| 615 | /* HDMI_DISABLE */ |
| 616 | boolean hdmi_disabled = (val & 0x00200000) >> 21; |
| 617 | /* HDCP_DISABLE */ |
| 618 | boolean hdcp_disabled = (val & 0x00400000) >> 22; |
| 619 | |
| 620 | DEV_DBG("Features <val:0x%08x, HDMI:%s, HDCP:%s>\n", val, |
| 621 | hdmi_disabled ? "OFF" : "ON", hdcp_disabled ? "OFF" : "ON"); |
| 622 | if (hdmi_disabled) { |
| 623 | DEV_ERR("ERROR: HDMI disabled\n"); |
| 624 | return -ENODEV; |
| 625 | } |
| 626 | |
| 627 | if (hdcp_disabled) |
| 628 | DEV_WARN("WARNING: HDCP disabled\n"); |
| 629 | |
| 630 | return 0; |
| 631 | } |
| 632 | |
| 633 | static boolean hdmi_msm_has_hdcp(void) |
| 634 | { |
| 635 | /* RAW_FEAT_CONFIG_ROW0_LSB, HDCP_DISABLE */ |
| 636 | return (inpdw(QFPROM_BASE + 0x0238) & 0x00400000) ? FALSE : TRUE; |
| 637 | } |
| 638 | |
| 639 | static boolean hdmi_msm_is_power_on(void) |
| 640 | { |
| 641 | /* HDMI_CTRL, ENABLE */ |
| 642 | return (HDMI_INP_ND(0x0000) & 0x00000001) ? TRUE : FALSE; |
| 643 | } |
| 644 | |
| 645 | /* 1.2.1.2.1 DVI Operation |
| 646 | * HDMI compliance requires the HDMI core to support DVI as well. The |
| 647 | * HDMI core also supports DVI. In DVI operation there are no preambles |
| 648 | * and guardbands transmitted. THe TMDS encoding of video data remains |
| 649 | * the same as HDMI. There are no VBI or audio packets transmitted. In |
| 650 | * order to enable DVI mode in HDMI core, HDMI_DVI_SEL field of |
| 651 | * HDMI_CTRL register needs to be programmed to 0. */ |
| 652 | static boolean hdmi_msm_is_dvi_mode(void) |
| 653 | { |
| 654 | /* HDMI_CTRL, HDMI_DVI_SEL */ |
| 655 | return (HDMI_INP_ND(0x0000) & 0x00000002) ? FALSE : TRUE; |
| 656 | } |
| 657 | |
| Ravishangar Kalyanam | 49a83b2 | 2011-07-20 15:28:44 -0700 | [diff] [blame] | 658 | void hdmi_msm_set_mode(boolean power_on) |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 659 | { |
| 660 | uint32 reg_val = 0; |
| 661 | if (power_on) { |
| 662 | /* ENABLE */ |
| 663 | reg_val |= 0x00000001; /* Enable the block */ |
| 664 | if (external_common_state->hdmi_sink == 0) { |
| 665 | /* HDMI_DVI_SEL */ |
| 666 | reg_val |= 0x00000002; |
| Manoj Rao | b91fa71 | 2011-06-29 09:07:55 -0700 | [diff] [blame] | 667 | if (external_common_state->present_hdcp) |
| 668 | /* HDMI Encryption */ |
| 669 | reg_val |= 0x00000004; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 670 | /* HDMI_CTRL */ |
| 671 | HDMI_OUTP(0x0000, reg_val); |
| 672 | /* HDMI_DVI_SEL */ |
| 673 | reg_val &= ~0x00000002; |
| Manoj Rao | b91fa71 | 2011-06-29 09:07:55 -0700 | [diff] [blame] | 674 | } else { |
| 675 | if (external_common_state->present_hdcp) |
| 676 | /* HDMI_Encryption_ON */ |
| 677 | reg_val |= 0x00000006; |
| 678 | else |
| 679 | reg_val |= 0x00000002; |
| 680 | } |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 681 | } else |
| 682 | reg_val = 0x00000002; |
| 683 | |
| 684 | /* HDMI_CTRL */ |
| 685 | HDMI_OUTP(0x0000, reg_val); |
| 686 | DEV_DBG("HDMI Core: %s\n", power_on ? "Enable" : "Disable"); |
| 687 | } |
| 688 | |
| 689 | static void msm_hdmi_init_ddc(void) |
| 690 | { |
| 691 | /* 0x0220 HDMI_DDC_SPEED |
| 692 | [31:16] PRESCALE prescale = (m * xtal_frequency) / |
| 693 | (desired_i2c_speed), where m is multiply |
| 694 | factor, default: m = 1 |
| 695 | [1:0] THRESHOLD Select threshold to use to determine whether value |
| 696 | sampled on SDA is a 1 or 0. Specified in terms of the ratio |
| 697 | between the number of sampled ones and the total number of times |
| 698 | SDA is sampled. |
| 699 | * 0x0: >0 |
| 700 | * 0x1: 1/4 of total samples |
| 701 | * 0x2: 1/2 of total samples |
| 702 | * 0x3: 3/4 of total samples */ |
| 703 | /* Configure the Pre-Scale multiplier |
| 704 | * Configure the Threshold */ |
| 705 | HDMI_OUTP_ND(0x0220, (10 << 16) | (2 << 0)); |
| 706 | |
| 707 | /* 0x0224 HDMI_DDC_SETUP */ |
| 708 | HDMI_OUTP_ND(0x0224, 0); |
| 709 | |
| 710 | /* 0x027C HDMI_DDC_REF |
| 711 | [6] REFTIMER_ENABLE Enable the timer |
| 712 | * 0: Disable |
| 713 | * 1: Enable |
| 714 | [15:0] REFTIMER Value to set the register in order to generate |
| 715 | DDC strobe. This register counts on HDCP application clock */ |
| 716 | /* Enable reference timer |
| 717 | * 27 micro-seconds */ |
| 718 | HDMI_OUTP_ND(0x027C, (1 << 16) | (27 << 0)); |
| 719 | } |
| 720 | |
| 721 | static int hdmi_msm_ddc_clear_irq(const char *what) |
| 722 | { |
| 723 | const uint32 time_out = 0xFFFF; |
| 724 | uint32 time_out_count, reg_val; |
| 725 | |
| 726 | /* clear pending and enable interrupt */ |
| 727 | time_out_count = time_out; |
| 728 | do { |
| 729 | --time_out_count; |
| 730 | /* HDMI_DDC_INT_CTRL[0x0214] |
| 731 | [2] SW_DONE_MK Mask bit for SW_DONE_INT. Set to 1 to enable |
| 732 | interrupt. |
| 733 | [1] SW_DONE_ACK WRITE ONLY. Acknowledge bit for SW_DONE_INT. |
| 734 | Write 1 to clear interrupt. |
| 735 | [0] SW_DONE_INT READ ONLY. SW_DONE interrupt status */ |
| 736 | /* Clear and Enable DDC interrupt */ |
| 737 | /* Write */ |
| 738 | HDMI_OUTP_ND(0x0214, (1 << 2) | (1 << 1)); |
| 739 | /* Read back */ |
| 740 | reg_val = HDMI_INP_ND(0x0214); |
| 741 | } while ((reg_val & 0x1) && time_out_count); |
| 742 | if (!time_out_count) { |
| 743 | DEV_ERR("%s[%s]: timedout\n", __func__, what); |
| 744 | return -ETIMEDOUT; |
| 745 | } |
| 746 | |
| 747 | return 0; |
| 748 | } |
| 749 | |
| 750 | #ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT |
| 751 | static int hdmi_msm_ddc_write(uint32 dev_addr, uint32 offset, |
| 752 | const uint8 *data_buf, uint32 data_len, const char *what) |
| 753 | { |
| 754 | uint32 reg_val, ndx; |
| 755 | int status = 0, retry = 10; |
| 756 | uint32 time_out_count; |
| 757 | |
| 758 | if (NULL == data_buf) { |
| 759 | status = -EINVAL; |
| 760 | DEV_ERR("%s[%s]: invalid input paramter\n", __func__, what); |
| 761 | goto error; |
| 762 | } |
| 763 | |
| 764 | again: |
| 765 | status = hdmi_msm_ddc_clear_irq(what); |
| 766 | if (status) |
| 767 | goto error; |
| 768 | |
| 769 | /* Ensure Device Address has LSB set to 0 to indicate Slave addr read */ |
| 770 | dev_addr &= 0xFE; |
| 771 | |
| 772 | /* 0x0238 HDMI_DDC_DATA |
| 773 | [31] INDEX_WRITE WRITE ONLY. To write index field, set this bit to |
| 774 | 1 while writing HDMI_DDC_DATA. |
| 775 | [23:16] INDEX Use to set index into DDC buffer for next read or |
| 776 | current write, or to read index of current read or next write. |
| 777 | Writable only when INDEX_WRITE=1. |
| 778 | [15:8] DATA Use to fill or read the DDC buffer |
| 779 | [0] DATA_RW Select whether buffer access will be a read or write. |
| 780 | For writes, address auto-increments on write to HDMI_DDC_DATA. |
| 781 | For reads, address autoincrements on reads to HDMI_DDC_DATA. |
| 782 | * 0: Write |
| 783 | * 1: Read */ |
| 784 | |
| 785 | /* 1. Write to HDMI_I2C_DATA with the following fields set in order to |
| 786 | * handle portion #1 |
| 787 | * DATA_RW = 0x1 (write) |
| 788 | * DATA = linkAddress (primary link address and writing) |
| 789 | * INDEX = 0x0 (initial offset into buffer) |
| 790 | * INDEX_WRITE = 0x1 (setting initial offset) */ |
| 791 | HDMI_OUTP_ND(0x0238, (0x1UL << 31) | (dev_addr << 8)); |
| 792 | |
| 793 | /* 2. Write to HDMI_I2C_DATA with the following fields set in order to |
| 794 | * handle portion #2 |
| 795 | * DATA_RW = 0x0 (write) |
| 796 | * DATA = offsetAddress |
| 797 | * INDEX = 0x0 |
| 798 | * INDEX_WRITE = 0x0 (auto-increment by hardware) */ |
| 799 | HDMI_OUTP_ND(0x0238, offset << 8); |
| 800 | |
| 801 | /* 3. Write to HDMI_I2C_DATA with the following fields set in order to |
| 802 | * handle portion #3 |
| 803 | * DATA_RW = 0x0 (write) |
| 804 | * DATA = data_buf[ndx] |
| 805 | * INDEX = 0x0 |
| 806 | * INDEX_WRITE = 0x0 (auto-increment by hardware) */ |
| 807 | for (ndx = 0; ndx < data_len; ++ndx) |
| 808 | HDMI_OUTP_ND(0x0238, ((uint32)data_buf[ndx]) << 8); |
| 809 | |
| 810 | /* Data setup is complete, now setup the transaction characteristics */ |
| 811 | |
| 812 | /* 0x0228 HDMI_DDC_TRANS0 |
| 813 | [23:16] CNT0 Byte count for first transaction (excluding the first |
| 814 | byte, which is usually the address). |
| 815 | [13] STOP0 Determines whether a stop bit will be sent after the first |
| 816 | transaction |
| 817 | * 0: NO STOP |
| 818 | * 1: STOP |
| 819 | [12] START0 Determines whether a start bit will be sent before the |
| 820 | first transaction |
| 821 | * 0: NO START |
| 822 | * 1: START |
| 823 | [8] STOP_ON_NACK0 Determines whether the current transfer will stop |
| 824 | if a NACK is received during the first transaction (current |
| 825 | transaction always stops). |
| 826 | * 0: STOP CURRENT TRANSACTION, GO TO NEXT TRANSACTION |
| 827 | * 1: STOP ALL TRANSACTIONS, SEND STOP BIT |
| 828 | [0] RW0 Read/write indicator for first transaction - set to 0 for |
| 829 | write, 1 for read. This bit only controls HDMI_DDC behaviour - |
| 830 | the R/W bit in the transaction is programmed into the DDC buffer |
| 831 | as the LSB of the address byte. |
| 832 | * 0: WRITE |
| 833 | * 1: READ */ |
| 834 | |
| 835 | /* 4. Write to HDMI_I2C_TRANSACTION0 with the following fields set in |
| 836 | order to handle characteristics of portion #1 and portion #2 |
| 837 | * RW0 = 0x0 (write) |
| 838 | * START0 = 0x1 (insert START bit) |
| 839 | * STOP0 = 0x0 (do NOT insert STOP bit) |
| 840 | * CNT0 = 0x1 (single byte transaction excluding address) */ |
| 841 | HDMI_OUTP_ND(0x0228, (1 << 12) | (1 << 16)); |
| 842 | |
| 843 | /* 0x022C HDMI_DDC_TRANS1 |
| 844 | [23:16] CNT1 Byte count for second transaction (excluding the first |
| 845 | byte, which is usually the address). |
| 846 | [13] STOP1 Determines whether a stop bit will be sent after the second |
| 847 | transaction |
| 848 | * 0: NO STOP |
| 849 | * 1: STOP |
| 850 | [12] START1 Determines whether a start bit will be sent before the |
| 851 | second transaction |
| 852 | * 0: NO START |
| 853 | * 1: START |
| 854 | [8] STOP_ON_NACK1 Determines whether the current transfer will stop if |
| 855 | a NACK is received during the second transaction (current |
| 856 | transaction always stops). |
| 857 | * 0: STOP CURRENT TRANSACTION, GO TO NEXT TRANSACTION |
| 858 | * 1: STOP ALL TRANSACTIONS, SEND STOP BIT |
| 859 | [0] RW1 Read/write indicator for second transaction - set to 0 for |
| 860 | write, 1 for read. This bit only controls HDMI_DDC behaviour - |
| 861 | the R/W bit in the transaction is programmed into the DDC buffer |
| 862 | as the LSB of the address byte. |
| 863 | * 0: WRITE |
| 864 | * 1: READ */ |
| 865 | |
| 866 | /* 5. Write to HDMI_I2C_TRANSACTION1 with the following fields set in |
| 867 | order to handle characteristics of portion #3 |
| 868 | * RW1 = 0x1 (read) |
| 869 | * START1 = 0x1 (insert START bit) |
| 870 | * STOP1 = 0x1 (insert STOP bit) |
| 871 | * CNT1 = data_len (0xN (write N bytes of data)) |
| 872 | * Byte count for second transition (excluding the first |
| 873 | * Byte which is usually the address) */ |
| 874 | HDMI_OUTP_ND(0x022C, (1 << 13) | ((data_len-1) << 16)); |
| 875 | |
| 876 | /* Trigger the I2C transfer */ |
| 877 | /* 0x020C HDMI_DDC_CTRL |
| 878 | [21:20] TRANSACTION_CNT |
| 879 | Number of transactions to be done in current transfer. |
| 880 | * 0x0: transaction0 only |
| 881 | * 0x1: transaction0, transaction1 |
| 882 | * 0x2: transaction0, transaction1, transaction2 |
| 883 | * 0x3: transaction0, transaction1, transaction2, transaction3 |
| 884 | [3] SW_STATUS_RESET |
| 885 | Write 1 to reset HDMI_DDC_SW_STATUS flags, will reset SW_DONE, |
| 886 | ABORTED, TIMEOUT, SW_INTERRUPTED, BUFFER_OVERFLOW, |
| 887 | STOPPED_ON_NACK, NACK0, NACK1, NACK2, NACK3 |
| 888 | [2] SEND_RESET Set to 1 to send reset sequence (9 clocks with no |
| 889 | data) at start of transfer. This sequence is sent after GO is |
| 890 | written to 1, before the first transaction only. |
| 891 | [1] SOFT_RESET Write 1 to reset DDC controller |
| 892 | [0] GO WRITE ONLY. Write 1 to start DDC transfer. */ |
| 893 | |
| 894 | /* 6. Write to HDMI_I2C_CONTROL to kick off the hardware. |
| 895 | * Note that NOTHING has been transmitted on the DDC lines up to this |
| 896 | * point. |
| 897 | * TRANSACTION_CNT = 0x1 (execute transaction0 followed by |
| 898 | * transaction1) |
| 899 | * GO = 0x1 (kicks off hardware) */ |
| 900 | INIT_COMPLETION(hdmi_msm_state->ddc_sw_done); |
| 901 | HDMI_OUTP_ND(0x020C, (1 << 0) | (1 << 20)); |
| 902 | |
| 903 | time_out_count = wait_for_completion_interruptible_timeout( |
| 904 | &hdmi_msm_state->ddc_sw_done, HZ/2); |
| 905 | HDMI_OUTP_ND(0x0214, 0x2); |
| 906 | if (!time_out_count) { |
| 907 | if (retry-- > 0) { |
| 908 | DEV_INFO("%s[%s]: failed timout, retry=%d\n", __func__, |
| 909 | what, retry); |
| 910 | goto again; |
| 911 | } |
| 912 | status = -ETIMEDOUT; |
| 913 | DEV_ERR("%s[%s]: timedout, DDC SW Status=%08x, HW " |
| 914 | "Status=%08x, Int Ctrl=%08x\n", __func__, what, |
| 915 | HDMI_INP_ND(0x0218), HDMI_INP_ND(0x021C), |
| 916 | HDMI_INP_ND(0x0214)); |
| 917 | goto error; |
| 918 | } |
| 919 | |
| 920 | /* Read DDC status */ |
| 921 | reg_val = HDMI_INP_ND(0x0218); |
| 922 | reg_val &= 0x00001000 | 0x00002000 | 0x00004000 | 0x00008000; |
| 923 | |
| 924 | /* Check if any NACK occurred */ |
| 925 | if (reg_val) { |
| 926 | if (retry > 1) |
| 927 | HDMI_OUTP_ND(0x020C, BIT(3)); /* SW_STATUS_RESET */ |
| 928 | else |
| 929 | HDMI_OUTP_ND(0x020C, BIT(1)); /* SOFT_RESET */ |
| 930 | if (retry-- > 0) { |
| 931 | DEV_DBG("%s[%s]: failed NACK=%08x, retry=%d\n", |
| 932 | __func__, what, reg_val, retry); |
| 933 | msleep(100); |
| 934 | goto again; |
| 935 | } |
| 936 | status = -EIO; |
| 937 | DEV_ERR("%s[%s]: failed NACK: %08x\n", __func__, what, reg_val); |
| 938 | goto error; |
| 939 | } |
| 940 | |
| 941 | DEV_DBG("%s[%s] success\n", __func__, what); |
| 942 | |
| 943 | error: |
| 944 | return status; |
| 945 | } |
| 946 | #endif /* CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT */ |
| 947 | |
| 948 | static int hdmi_msm_ddc_read_retry(uint32 dev_addr, uint32 offset, |
| 949 | uint8 *data_buf, uint32 data_len, uint32 request_len, int retry, |
| 950 | const char *what) |
| 951 | { |
| 952 | uint32 reg_val, ndx; |
| 953 | int status = 0; |
| 954 | uint32 time_out_count; |
| 955 | int log_retry_fail = retry != 1; |
| 956 | |
| 957 | if (NULL == data_buf) { |
| 958 | status = -EINVAL; |
| 959 | DEV_ERR("%s: invalid input paramter\n", __func__); |
| 960 | goto error; |
| 961 | } |
| 962 | |
| 963 | again: |
| 964 | status = hdmi_msm_ddc_clear_irq(what); |
| 965 | if (status) |
| 966 | goto error; |
| 967 | |
| 968 | /* Ensure Device Address has LSB set to 0 to indicate Slave addr read */ |
| 969 | dev_addr &= 0xFE; |
| 970 | |
| 971 | /* 0x0238 HDMI_DDC_DATA |
| 972 | [31] INDEX_WRITE WRITE ONLY. To write index field, set this bit to |
| 973 | 1 while writing HDMI_DDC_DATA. |
| 974 | [23:16] INDEX Use to set index into DDC buffer for next read or |
| 975 | current write, or to read index of current read or next write. |
| 976 | Writable only when INDEX_WRITE=1. |
| 977 | [15:8] DATA Use to fill or read the DDC buffer |
| 978 | [0] DATA_RW Select whether buffer access will be a read or write. |
| 979 | For writes, address auto-increments on write to HDMI_DDC_DATA. |
| 980 | For reads, address autoincrements on reads to HDMI_DDC_DATA. |
| 981 | * 0: Write |
| 982 | * 1: Read */ |
| 983 | |
| 984 | /* 1. Write to HDMI_I2C_DATA with the following fields set in order to |
| 985 | * handle portion #1 |
| 986 | * DATA_RW = 0x0 (write) |
| 987 | * DATA = linkAddress (primary link address and writing) |
| 988 | * INDEX = 0x0 (initial offset into buffer) |
| 989 | * INDEX_WRITE = 0x1 (setting initial offset) */ |
| 990 | HDMI_OUTP_ND(0x0238, (0x1UL << 31) | (dev_addr << 8)); |
| 991 | |
| 992 | /* 2. Write to HDMI_I2C_DATA with the following fields set in order to |
| 993 | * handle portion #2 |
| 994 | * DATA_RW = 0x0 (write) |
| 995 | * DATA = offsetAddress |
| 996 | * INDEX = 0x0 |
| 997 | * INDEX_WRITE = 0x0 (auto-increment by hardware) */ |
| 998 | HDMI_OUTP_ND(0x0238, offset << 8); |
| 999 | |
| 1000 | /* 3. Write to HDMI_I2C_DATA with the following fields set in order to |
| 1001 | * handle portion #3 |
| 1002 | * DATA_RW = 0x0 (write) |
| 1003 | * DATA = linkAddress + 1 (primary link address 0x74 and reading) |
| 1004 | * INDEX = 0x0 |
| 1005 | * INDEX_WRITE = 0x0 (auto-increment by hardware) */ |
| 1006 | HDMI_OUTP_ND(0x0238, (dev_addr | 1) << 8); |
| 1007 | |
| 1008 | /* Data setup is complete, now setup the transaction characteristics */ |
| 1009 | |
| 1010 | /* 0x0228 HDMI_DDC_TRANS0 |
| 1011 | [23:16] CNT0 Byte count for first transaction (excluding the first |
| 1012 | byte, which is usually the address). |
| 1013 | [13] STOP0 Determines whether a stop bit will be sent after the first |
| 1014 | transaction |
| 1015 | * 0: NO STOP |
| 1016 | * 1: STOP |
| 1017 | [12] START0 Determines whether a start bit will be sent before the |
| 1018 | first transaction |
| 1019 | * 0: NO START |
| 1020 | * 1: START |
| 1021 | [8] STOP_ON_NACK0 Determines whether the current transfer will stop |
| 1022 | if a NACK is received during the first transaction (current |
| 1023 | transaction always stops). |
| 1024 | * 0: STOP CURRENT TRANSACTION, GO TO NEXT TRANSACTION |
| 1025 | * 1: STOP ALL TRANSACTIONS, SEND STOP BIT |
| 1026 | [0] RW0 Read/write indicator for first transaction - set to 0 for |
| 1027 | write, 1 for read. This bit only controls HDMI_DDC behaviour - |
| 1028 | the R/W bit in the transaction is programmed into the DDC buffer |
| 1029 | as the LSB of the address byte. |
| 1030 | * 0: WRITE |
| 1031 | * 1: READ */ |
| 1032 | |
| 1033 | /* 4. Write to HDMI_I2C_TRANSACTION0 with the following fields set in |
| 1034 | order to handle characteristics of portion #1 and portion #2 |
| 1035 | * RW0 = 0x0 (write) |
| 1036 | * START0 = 0x1 (insert START bit) |
| 1037 | * STOP0 = 0x0 (do NOT insert STOP bit) |
| 1038 | * CNT0 = 0x1 (single byte transaction excluding address) */ |
| 1039 | HDMI_OUTP_ND(0x0228, (1 << 12) | (1 << 16)); |
| 1040 | |
| 1041 | /* 0x022C HDMI_DDC_TRANS1 |
| 1042 | [23:16] CNT1 Byte count for second transaction (excluding the first |
| 1043 | byte, which is usually the address). |
| 1044 | [13] STOP1 Determines whether a stop bit will be sent after the second |
| 1045 | transaction |
| 1046 | * 0: NO STOP |
| 1047 | * 1: STOP |
| 1048 | [12] START1 Determines whether a start bit will be sent before the |
| 1049 | second transaction |
| 1050 | * 0: NO START |
| 1051 | * 1: START |
| 1052 | [8] STOP_ON_NACK1 Determines whether the current transfer will stop if |
| 1053 | a NACK is received during the second transaction (current |
| 1054 | transaction always stops). |
| 1055 | * 0: STOP CURRENT TRANSACTION, GO TO NEXT TRANSACTION |
| 1056 | * 1: STOP ALL TRANSACTIONS, SEND STOP BIT |
| 1057 | [0] RW1 Read/write indicator for second transaction - set to 0 for |
| 1058 | write, 1 for read. This bit only controls HDMI_DDC behaviour - |
| 1059 | the R/W bit in the transaction is programmed into the DDC buffer |
| 1060 | as the LSB of the address byte. |
| 1061 | * 0: WRITE |
| 1062 | * 1: READ */ |
| 1063 | |
| 1064 | /* 5. Write to HDMI_I2C_TRANSACTION1 with the following fields set in |
| 1065 | order to handle characteristics of portion #3 |
| 1066 | * RW1 = 0x1 (read) |
| 1067 | * START1 = 0x1 (insert START bit) |
| 1068 | * STOP1 = 0x1 (insert STOP bit) |
| 1069 | * CNT1 = data_len (it's 128 (0x80) for a blk read) */ |
| 1070 | HDMI_OUTP_ND(0x022C, 1 | (1 << 12) | (1 << 13) | (request_len << 16)); |
| 1071 | |
| 1072 | /* Trigger the I2C transfer */ |
| 1073 | /* 0x020C HDMI_DDC_CTRL |
| 1074 | [21:20] TRANSACTION_CNT |
| 1075 | Number of transactions to be done in current transfer. |
| 1076 | * 0x0: transaction0 only |
| 1077 | * 0x1: transaction0, transaction1 |
| 1078 | * 0x2: transaction0, transaction1, transaction2 |
| 1079 | * 0x3: transaction0, transaction1, transaction2, transaction3 |
| 1080 | [3] SW_STATUS_RESET |
| 1081 | Write 1 to reset HDMI_DDC_SW_STATUS flags, will reset SW_DONE, |
| 1082 | ABORTED, TIMEOUT, SW_INTERRUPTED, BUFFER_OVERFLOW, |
| 1083 | STOPPED_ON_NACK, NACK0, NACK1, NACK2, NACK3 |
| 1084 | [2] SEND_RESET Set to 1 to send reset sequence (9 clocks with no |
| 1085 | data) at start of transfer. This sequence is sent after GO is |
| 1086 | written to 1, before the first transaction only. |
| 1087 | [1] SOFT_RESET Write 1 to reset DDC controller |
| 1088 | [0] GO WRITE ONLY. Write 1 to start DDC transfer. */ |
| 1089 | |
| 1090 | /* 6. Write to HDMI_I2C_CONTROL to kick off the hardware. |
| 1091 | * Note that NOTHING has been transmitted on the DDC lines up to this |
| 1092 | * point. |
| 1093 | * TRANSACTION_CNT = 0x1 (execute transaction0 followed by |
| 1094 | * transaction1) |
| 1095 | * SEND_RESET = Set to 1 to send reset sequence |
| 1096 | * GO = 0x1 (kicks off hardware) */ |
| 1097 | INIT_COMPLETION(hdmi_msm_state->ddc_sw_done); |
| 1098 | HDMI_OUTP_ND(0x020C, (1 << 0) | (1 << 20)); |
| 1099 | |
| 1100 | time_out_count = wait_for_completion_interruptible_timeout( |
| 1101 | &hdmi_msm_state->ddc_sw_done, HZ/2); |
| 1102 | HDMI_OUTP_ND(0x0214, 0x2); |
| 1103 | if (!time_out_count) { |
| 1104 | if (retry-- > 0) { |
| 1105 | DEV_INFO("%s: failed timout, retry=%d\n", __func__, |
| 1106 | retry); |
| 1107 | goto again; |
| 1108 | } |
| 1109 | status = -ETIMEDOUT; |
| 1110 | DEV_ERR("%s: timedout(7), DDC SW Status=%08x, HW " |
| 1111 | "Status=%08x, Int Ctrl=%08x\n", __func__, |
| 1112 | HDMI_INP(0x0218), HDMI_INP(0x021C), HDMI_INP(0x0214)); |
| 1113 | goto error; |
| 1114 | } |
| 1115 | |
| 1116 | /* Read DDC status */ |
| 1117 | reg_val = HDMI_INP_ND(0x0218); |
| 1118 | reg_val &= 0x00001000 | 0x00002000 | 0x00004000 | 0x00008000; |
| 1119 | |
| 1120 | /* Check if any NACK occurred */ |
| 1121 | if (reg_val) { |
| 1122 | HDMI_OUTP_ND(0x020C, BIT(3)); /* SW_STATUS_RESET */ |
| 1123 | if (retry == 1) |
| 1124 | HDMI_OUTP_ND(0x020C, BIT(1)); /* SOFT_RESET */ |
| 1125 | if (retry-- > 0) { |
| 1126 | DEV_DBG("%s(%s): failed NACK=0x%08x, retry=%d, " |
| 1127 | "dev-addr=0x%02x, offset=0x%02x, " |
| 1128 | "length=%d\n", __func__, what, |
| 1129 | reg_val, retry, dev_addr, |
| 1130 | offset, data_len); |
| 1131 | goto again; |
| 1132 | } |
| 1133 | status = -EIO; |
| 1134 | if (log_retry_fail) |
| 1135 | DEV_ERR("%s(%s): failed NACK=0x%08x, dev-addr=0x%02x, " |
| 1136 | "offset=0x%02x, length=%d\n", __func__, what, |
| 1137 | reg_val, dev_addr, offset, data_len); |
| 1138 | goto error; |
| 1139 | } |
| 1140 | |
| 1141 | /* 0x0238 HDMI_DDC_DATA |
| 1142 | [31] INDEX_WRITE WRITE ONLY. To write index field, set this bit to 1 |
| 1143 | while writing HDMI_DDC_DATA. |
| 1144 | [23:16] INDEX Use to set index into DDC buffer for next read or |
| 1145 | current write, or to read index of current read or next write. |
| 1146 | Writable only when INDEX_WRITE=1. |
| 1147 | [15:8] DATA Use to fill or read the DDC buffer |
| 1148 | [0] DATA_RW Select whether buffer access will be a read or write. |
| 1149 | For writes, address auto-increments on write to HDMI_DDC_DATA. |
| 1150 | For reads, address autoincrements on reads to HDMI_DDC_DATA. |
| 1151 | * 0: Write |
| 1152 | * 1: Read */ |
| 1153 | |
| 1154 | /* 8. ALL data is now available and waiting in the DDC buffer. |
| 1155 | * Read HDMI_I2C_DATA with the following fields set |
| 1156 | * RW = 0x1 (read) |
| 1157 | * DATA = BCAPS (this is field where data is pulled from) |
| 1158 | * INDEX = 0x3 (where the data has been placed in buffer by hardware) |
| 1159 | * INDEX_WRITE = 0x1 (explicitly define offset) */ |
| 1160 | /* Write this data to DDC buffer */ |
| 1161 | HDMI_OUTP_ND(0x0238, 0x1 | (3 << 16) | (1 << 31)); |
| 1162 | |
| 1163 | /* Discard first byte */ |
| 1164 | HDMI_INP_ND(0x0238); |
| 1165 | for (ndx = 0; ndx < data_len; ++ndx) { |
| 1166 | reg_val = HDMI_INP_ND(0x0238); |
| 1167 | data_buf[ndx] = (uint8) ((reg_val & 0x0000FF00) >> 8); |
| 1168 | } |
| 1169 | |
| 1170 | DEV_DBG("%s[%s] success\n", __func__, what); |
| 1171 | |
| 1172 | error: |
| 1173 | return status; |
| 1174 | } |
| 1175 | |
| 1176 | static int hdmi_msm_ddc_read_edid_seg(uint32 dev_addr, uint32 offset, |
| 1177 | uint8 *data_buf, uint32 data_len, uint32 request_len, int retry, |
| 1178 | const char *what) |
| 1179 | { |
| 1180 | uint32 reg_val, ndx; |
| 1181 | int status = 0; |
| 1182 | uint32 time_out_count; |
| 1183 | int log_retry_fail = retry != 1; |
| 1184 | int seg_addr = 0x60, seg_num = 0x01; |
| 1185 | |
| 1186 | if (NULL == data_buf) { |
| 1187 | status = -EINVAL; |
| 1188 | DEV_ERR("%s: invalid input paramter\n", __func__); |
| 1189 | goto error; |
| 1190 | } |
| 1191 | |
| 1192 | again: |
| 1193 | status = hdmi_msm_ddc_clear_irq(what); |
| 1194 | if (status) |
| 1195 | goto error; |
| 1196 | |
| 1197 | /* Ensure Device Address has LSB set to 0 to indicate Slave addr read */ |
| 1198 | dev_addr &= 0xFE; |
| 1199 | |
| 1200 | /* 0x0238 HDMI_DDC_DATA |
| 1201 | [31] INDEX_WRITE WRITE ONLY. To write index field, set this bit to |
| 1202 | 1 while writing HDMI_DDC_DATA. |
| 1203 | [23:16] INDEX Use to set index into DDC buffer for next read or |
| 1204 | current write, or to read index of current read or next write. |
| 1205 | Writable only when INDEX_WRITE=1. |
| 1206 | [15:8] DATA Use to fill or read the DDC buffer |
| 1207 | [0] DATA_RW Select whether buffer access will be a read or write. |
| 1208 | For writes, address auto-increments on write to HDMI_DDC_DATA. |
| 1209 | For reads, address autoincrements on reads to HDMI_DDC_DATA. |
| 1210 | * 0: Write |
| 1211 | * 1: Read */ |
| 1212 | |
| 1213 | /* 1. Write to HDMI_I2C_DATA with the following fields set in order to |
| 1214 | * handle portion #1 |
| 1215 | * DATA_RW = 0x0 (write) |
| 1216 | * DATA = linkAddress (primary link address and writing) |
| 1217 | * INDEX = 0x0 (initial offset into buffer) |
| 1218 | * INDEX_WRITE = 0x1 (setting initial offset) */ |
| 1219 | HDMI_OUTP_ND(0x0238, (0x1UL << 31) | (seg_addr << 8)); |
| 1220 | |
| 1221 | /* 2. Write to HDMI_I2C_DATA with the following fields set in order to |
| 1222 | * handle portion #2 |
| 1223 | * DATA_RW = 0x0 (write) |
| 1224 | * DATA = offsetAddress |
| 1225 | * INDEX = 0x0 |
| 1226 | * INDEX_WRITE = 0x0 (auto-increment by hardware) */ |
| 1227 | HDMI_OUTP_ND(0x0238, seg_num << 8); |
| 1228 | |
| 1229 | /* 3. Write to HDMI_I2C_DATA with the following fields set in order to |
| 1230 | * handle portion #3 |
| 1231 | * DATA_RW = 0x0 (write) |
| 1232 | * DATA = linkAddress + 1 (primary link address 0x74 and reading) |
| 1233 | * INDEX = 0x0 |
| 1234 | * INDEX_WRITE = 0x0 (auto-increment by hardware) */ |
| 1235 | HDMI_OUTP_ND(0x0238, dev_addr << 8); |
| 1236 | HDMI_OUTP_ND(0x0238, offset << 8); |
| 1237 | HDMI_OUTP_ND(0x0238, (dev_addr | 1) << 8); |
| 1238 | |
| 1239 | /* Data setup is complete, now setup the transaction characteristics */ |
| 1240 | |
| 1241 | /* 0x0228 HDMI_DDC_TRANS0 |
| 1242 | [23:16] CNT0 Byte count for first transaction (excluding the first |
| 1243 | byte, which is usually the address). |
| 1244 | [13] STOP0 Determines whether a stop bit will be sent after the first |
| 1245 | transaction |
| 1246 | * 0: NO STOP |
| 1247 | * 1: STOP |
| 1248 | [12] START0 Determines whether a start bit will be sent before the |
| 1249 | first transaction |
| 1250 | * 0: NO START |
| 1251 | * 1: START |
| 1252 | [8] STOP_ON_NACK0 Determines whether the current transfer will stop |
| 1253 | if a NACK is received during the first transaction (current |
| 1254 | transaction always stops). |
| 1255 | * 0: STOP CURRENT TRANSACTION, GO TO NEXT TRANSACTION |
| 1256 | * 1: STOP ALL TRANSACTIONS, SEND STOP BIT |
| 1257 | [0] RW0 Read/write indicator for first transaction - set to 0 for |
| 1258 | write, 1 for read. This bit only controls HDMI_DDC behaviour - |
| 1259 | the R/W bit in the transaction is programmed into the DDC buffer |
| 1260 | as the LSB of the address byte. |
| 1261 | * 0: WRITE |
| 1262 | * 1: READ */ |
| 1263 | |
| 1264 | /* 4. Write to HDMI_I2C_TRANSACTION0 with the following fields set in |
| 1265 | order to handle characteristics of portion #1 and portion #2 |
| 1266 | * RW0 = 0x0 (write) |
| 1267 | * START0 = 0x1 (insert START bit) |
| 1268 | * STOP0 = 0x0 (do NOT insert STOP bit) |
| 1269 | * CNT0 = 0x1 (single byte transaction excluding address) */ |
| 1270 | HDMI_OUTP_ND(0x0228, (1 << 12) | (1 << 16)); |
| 1271 | |
| 1272 | /* 0x022C HDMI_DDC_TRANS1 |
| 1273 | [23:16] CNT1 Byte count for second transaction (excluding the first |
| 1274 | byte, which is usually the address). |
| 1275 | [13] STOP1 Determines whether a stop bit will be sent after the second |
| 1276 | transaction |
| 1277 | * 0: NO STOP |
| 1278 | * 1: STOP |
| 1279 | [12] START1 Determines whether a start bit will be sent before the |
| 1280 | second transaction |
| 1281 | * 0: NO START |
| 1282 | * 1: START |
| 1283 | [8] STOP_ON_NACK1 Determines whether the current transfer will stop if |
| 1284 | a NACK is received during the second transaction (current |
| 1285 | transaction always stops). |
| 1286 | * 0: STOP CURRENT TRANSACTION, GO TO NEXT TRANSACTION |
| 1287 | * 1: STOP ALL TRANSACTIONS, SEND STOP BIT |
| 1288 | [0] RW1 Read/write indicator for second transaction - set to 0 for |
| 1289 | write, 1 for read. This bit only controls HDMI_DDC behaviour - |
| 1290 | the R/W bit in the transaction is programmed into the DDC buffer |
| 1291 | as the LSB of the address byte. |
| 1292 | * 0: WRITE |
| 1293 | * 1: READ */ |
| 1294 | |
| 1295 | /* 5. Write to HDMI_I2C_TRANSACTION1 with the following fields set in |
| 1296 | order to handle characteristics of portion #3 |
| 1297 | * RW1 = 0x1 (read) |
| 1298 | * START1 = 0x1 (insert START bit) |
| 1299 | * STOP1 = 0x1 (insert STOP bit) |
| 1300 | * CNT1 = data_len (it's 128 (0x80) for a blk read) */ |
| 1301 | HDMI_OUTP_ND(0x022C, (1 << 12) | (1 << 16)); |
| 1302 | |
| 1303 | /* 0x022C HDMI_DDC_TRANS2 |
| 1304 | [23:16] CNT1 Byte count for second transaction (excluding the first |
| 1305 | byte, which is usually the address). |
| 1306 | [13] STOP1 Determines whether a stop bit will be sent after the second |
| 1307 | transaction |
| 1308 | * 0: NO STOP |
| 1309 | * 1: STOP |
| 1310 | [12] START1 Determines whether a start bit will be sent before the |
| 1311 | second transaction |
| 1312 | * 0: NO START |
| 1313 | * 1: START |
| 1314 | [8] STOP_ON_NACK1 Determines whether the current transfer will stop if |
| 1315 | a NACK is received during the second transaction (current |
| 1316 | transaction always stops). |
| 1317 | * 0: STOP CURRENT TRANSACTION, GO TO NEXT TRANSACTION |
| 1318 | * 1: STOP ALL TRANSACTIONS, SEND STOP BIT |
| 1319 | [0] RW1 Read/write indicator for second transaction - set to 0 for |
| 1320 | write, 1 for read. This bit only controls HDMI_DDC behaviour - |
| 1321 | the R/W bit in the transaction is programmed into the DDC buffer |
| 1322 | as the LSB of the address byte. |
| 1323 | * 0: WRITE |
| 1324 | * 1: READ */ |
| 1325 | |
| 1326 | /* 5. Write to HDMI_I2C_TRANSACTION1 with the following fields set in |
| 1327 | order to handle characteristics of portion #3 |
| 1328 | * RW1 = 0x1 (read) |
| 1329 | * START1 = 0x1 (insert START bit) |
| 1330 | * STOP1 = 0x1 (insert STOP bit) |
| 1331 | * CNT1 = data_len (it's 128 (0x80) for a blk read) */ |
| 1332 | HDMI_OUTP_ND(0x0230, 1 | (1 << 12) | (1 << 13) | (request_len << 16)); |
| 1333 | |
| 1334 | /* Trigger the I2C transfer */ |
| 1335 | /* 0x020C HDMI_DDC_CTRL |
| 1336 | [21:20] TRANSACTION_CNT |
| 1337 | Number of transactions to be done in current transfer. |
| 1338 | * 0x0: transaction0 only |
| 1339 | * 0x1: transaction0, transaction1 |
| 1340 | * 0x2: transaction0, transaction1, transaction2 |
| 1341 | * 0x3: transaction0, transaction1, transaction2, transaction3 |
| 1342 | [3] SW_STATUS_RESET |
| 1343 | Write 1 to reset HDMI_DDC_SW_STATUS flags, will reset SW_DONE, |
| 1344 | ABORTED, TIMEOUT, SW_INTERRUPTED, BUFFER_OVERFLOW, |
| 1345 | STOPPED_ON_NACK, NACK0, NACK1, NACK2, NACK3 |
| 1346 | [2] SEND_RESET Set to 1 to send reset sequence (9 clocks with no |
| 1347 | data) at start of transfer. This sequence is sent after GO is |
| 1348 | written to 1, before the first transaction only. |
| 1349 | [1] SOFT_RESET Write 1 to reset DDC controller |
| 1350 | [0] GO WRITE ONLY. Write 1 to start DDC transfer. */ |
| 1351 | |
| 1352 | /* 6. Write to HDMI_I2C_CONTROL to kick off the hardware. |
| 1353 | * Note that NOTHING has been transmitted on the DDC lines up to this |
| 1354 | * point. |
| 1355 | * TRANSACTION_CNT = 0x2 (execute transaction0 followed by |
| 1356 | * transaction1) |
| 1357 | * GO = 0x1 (kicks off hardware) */ |
| 1358 | INIT_COMPLETION(hdmi_msm_state->ddc_sw_done); |
| 1359 | HDMI_OUTP_ND(0x020C, (1 << 0) | (2 << 20)); |
| 1360 | |
| 1361 | time_out_count = wait_for_completion_interruptible_timeout( |
| 1362 | &hdmi_msm_state->ddc_sw_done, HZ/2); |
| 1363 | HDMI_OUTP_ND(0x0214, 0x2); |
| 1364 | if (!time_out_count) { |
| 1365 | if (retry-- > 0) { |
| 1366 | DEV_INFO("%s: failed timout, retry=%d\n", __func__, |
| 1367 | retry); |
| 1368 | goto again; |
| 1369 | } |
| 1370 | status = -ETIMEDOUT; |
| 1371 | DEV_ERR("%s: timedout(7), DDC SW Status=%08x, HW " |
| 1372 | "Status=%08x, Int Ctrl=%08x\n", __func__, |
| 1373 | HDMI_INP(0x0218), HDMI_INP(0x021C), HDMI_INP(0x0214)); |
| 1374 | goto error; |
| 1375 | } |
| 1376 | |
| 1377 | /* Read DDC status */ |
| 1378 | reg_val = HDMI_INP_ND(0x0218); |
| 1379 | reg_val &= 0x00001000 | 0x00002000 | 0x00004000 | 0x00008000; |
| 1380 | |
| 1381 | /* Check if any NACK occurred */ |
| 1382 | if (reg_val) { |
| 1383 | HDMI_OUTP_ND(0x020C, BIT(3)); /* SW_STATUS_RESET */ |
| 1384 | if (retry == 1) |
| 1385 | HDMI_OUTP_ND(0x020C, BIT(1)); /* SOFT_RESET */ |
| 1386 | if (retry-- > 0) { |
| 1387 | DEV_DBG("%s(%s): failed NACK=0x%08x, retry=%d, " |
| 1388 | "dev-addr=0x%02x, offset=0x%02x, " |
| 1389 | "length=%d\n", __func__, what, |
| 1390 | reg_val, retry, dev_addr, |
| 1391 | offset, data_len); |
| 1392 | goto again; |
| 1393 | } |
| 1394 | status = -EIO; |
| 1395 | if (log_retry_fail) |
| 1396 | DEV_ERR("%s(%s): failed NACK=0x%08x, dev-addr=0x%02x, " |
| 1397 | "offset=0x%02x, length=%d\n", __func__, what, |
| 1398 | reg_val, dev_addr, offset, data_len); |
| 1399 | goto error; |
| 1400 | } |
| 1401 | |
| 1402 | /* 0x0238 HDMI_DDC_DATA |
| 1403 | [31] INDEX_WRITE WRITE ONLY. To write index field, set this bit to 1 |
| 1404 | while writing HDMI_DDC_DATA. |
| 1405 | [23:16] INDEX Use to set index into DDC buffer for next read or |
| 1406 | current write, or to read index of current read or next write. |
| 1407 | Writable only when INDEX_WRITE=1. |
| 1408 | [15:8] DATA Use to fill or read the DDC buffer |
| 1409 | [0] DATA_RW Select whether buffer access will be a read or write. |
| 1410 | For writes, address auto-increments on write to HDMI_DDC_DATA. |
| 1411 | For reads, address autoincrements on reads to HDMI_DDC_DATA. |
| 1412 | * 0: Write |
| 1413 | * 1: Read */ |
| 1414 | |
| 1415 | /* 8. ALL data is now available and waiting in the DDC buffer. |
| 1416 | * Read HDMI_I2C_DATA with the following fields set |
| 1417 | * RW = 0x1 (read) |
| 1418 | * DATA = BCAPS (this is field where data is pulled from) |
| 1419 | * INDEX = 0x3 (where the data has been placed in buffer by hardware) |
| 1420 | * INDEX_WRITE = 0x1 (explicitly define offset) */ |
| 1421 | /* Write this data to DDC buffer */ |
| 1422 | HDMI_OUTP_ND(0x0238, 0x1 | (3 << 16) | (1 << 31)); |
| 1423 | |
| 1424 | /* Discard first byte */ |
| 1425 | HDMI_INP_ND(0x0238); |
| 1426 | for (ndx = 0; ndx < data_len; ++ndx) { |
| 1427 | reg_val = HDMI_INP_ND(0x0238); |
| 1428 | data_buf[ndx] = (uint8) ((reg_val & 0x0000FF00) >> 8); |
| 1429 | } |
| 1430 | |
| 1431 | DEV_DBG("%s[%s] success\n", __func__, what); |
| 1432 | |
| 1433 | error: |
| 1434 | return status; |
| 1435 | } |
| 1436 | |
| 1437 | |
| 1438 | static int hdmi_msm_ddc_read(uint32 dev_addr, uint32 offset, uint8 *data_buf, |
| 1439 | uint32 data_len, int retry, const char *what, boolean no_align) |
| 1440 | { |
| 1441 | int ret = hdmi_msm_ddc_read_retry(dev_addr, offset, data_buf, data_len, |
| 1442 | data_len, retry, what); |
| 1443 | if (!ret) |
| 1444 | return 0; |
| 1445 | if (no_align) { |
| 1446 | return hdmi_msm_ddc_read_retry(dev_addr, offset, data_buf, |
| 1447 | data_len, data_len, retry, what); |
| 1448 | } else { |
| 1449 | return hdmi_msm_ddc_read_retry(dev_addr, offset, data_buf, |
| 1450 | data_len, 32 * ((data_len + 31) / 32), retry, what); |
| 1451 | } |
| 1452 | } |
| 1453 | |
| 1454 | |
| 1455 | static int hdmi_msm_read_edid_block(int block, uint8 *edid_buf) |
| 1456 | { |
| 1457 | int i, rc = 0; |
| 1458 | int block_size = 0x80; |
| 1459 | |
| 1460 | do { |
| 1461 | DEV_DBG("EDID: reading block(%d) with block-size=%d\n", |
| 1462 | block, block_size); |
| 1463 | for (i = 0; i < 0x80; i += block_size) { |
| 1464 | /*Read EDID twice with 32bit alighnment too */ |
| 1465 | if (block < 2) { |
| 1466 | rc = hdmi_msm_ddc_read(0xA0, block*0x80 + i, |
| 1467 | edid_buf+i, block_size, 1, |
| 1468 | "EDID", FALSE); |
| 1469 | } else { |
| 1470 | rc = hdmi_msm_ddc_read_edid_seg(0xA0, |
| 1471 | block*0x80 + i, edid_buf+i, block_size, |
| 1472 | block_size, 1, "EDID"); |
| 1473 | } |
| 1474 | if (rc) |
| 1475 | break; |
| 1476 | } |
| 1477 | |
| 1478 | block_size /= 2; |
| 1479 | } while (rc && (block_size >= 16)); |
| 1480 | |
| 1481 | return rc; |
| 1482 | } |
| 1483 | |
| 1484 | static int hdmi_msm_read_edid(void) |
| 1485 | { |
| 1486 | int status; |
| 1487 | |
| 1488 | msm_hdmi_init_ddc(); |
| 1489 | /* Looks like we need to turn on HDMI engine before any |
| 1490 | * DDC transaction */ |
| 1491 | if (!hdmi_msm_is_power_on()) { |
| 1492 | DEV_ERR("%s: failed: HDMI power is off", __func__); |
| 1493 | status = -ENXIO; |
| 1494 | goto error; |
| 1495 | } |
| 1496 | |
| 1497 | external_common_state->read_edid_block = hdmi_msm_read_edid_block; |
| 1498 | status = hdmi_common_read_edid(); |
| 1499 | if (!status) |
| 1500 | DEV_DBG("EDID: successfully read\n"); |
| 1501 | |
| 1502 | error: |
| 1503 | return status; |
| 1504 | } |
| 1505 | |
| 1506 | #ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT |
| 1507 | static void hdcp_auth_info(uint32 auth_info) |
| 1508 | { |
| 1509 | switch (auth_info) { |
| 1510 | case 0: |
| 1511 | DEV_INFO("%s: None", __func__); |
| 1512 | break; |
| 1513 | case 1: |
| 1514 | DEV_INFO("%s: Software Disabled Authentication", __func__); |
| 1515 | break; |
| 1516 | case 2: |
| 1517 | DEV_INFO("%s: An Written", __func__); |
| 1518 | break; |
| 1519 | case 3: |
| 1520 | DEV_INFO("%s: Invalid Aksv", __func__); |
| 1521 | break; |
| 1522 | case 4: |
| 1523 | DEV_INFO("%s: Invalid Bksv", __func__); |
| 1524 | break; |
| 1525 | case 5: |
| 1526 | DEV_INFO("%s: RI Mismatch (including RO)", __func__); |
| 1527 | break; |
| 1528 | case 6: |
| 1529 | DEV_INFO("%s: consecutive Pj Mismatches", __func__); |
| 1530 | break; |
| 1531 | case 7: |
| 1532 | DEV_INFO("%s: HPD Disconnect", __func__); |
| 1533 | break; |
| 1534 | case 8: |
| 1535 | default: |
| 1536 | DEV_INFO("%s: Reserved", __func__); |
| 1537 | break; |
| 1538 | } |
| 1539 | } |
| 1540 | |
| 1541 | static void hdcp_key_state(uint32 key_state) |
| 1542 | { |
| 1543 | switch (key_state) { |
| 1544 | case 0: |
| 1545 | DEV_WARN("%s: No HDCP Keys", __func__); |
| 1546 | break; |
| 1547 | case 1: |
| 1548 | DEV_WARN("%s: Not Checked", __func__); |
| 1549 | break; |
| 1550 | case 2: |
| 1551 | DEV_DBG("%s: Checking", __func__); |
| 1552 | break; |
| 1553 | case 3: |
| 1554 | DEV_DBG("%s: HDCP Keys Valid", __func__); |
| 1555 | break; |
| 1556 | case 4: |
| 1557 | DEV_WARN("%s: AKSV not valid", __func__); |
| 1558 | break; |
| 1559 | case 5: |
| 1560 | DEV_WARN("%s: Checksum Mismatch", __func__); |
| 1561 | break; |
| 1562 | case 6: |
| 1563 | DEV_DBG("%s: Production AKSV" |
| 1564 | "with ENABLE_USER_DEFINED_AN=1", __func__); |
| 1565 | break; |
| 1566 | case 7: |
| 1567 | default: |
| 1568 | DEV_INFO("%s: Reserved", __func__); |
| 1569 | break; |
| 1570 | } |
| 1571 | } |
| 1572 | |
| 1573 | static int hdmi_msm_count_one(uint8 *array, uint8 len) |
| 1574 | { |
| 1575 | int i, j, count = 0; |
| 1576 | for (i = 0; i < len; i++) |
| 1577 | for (j = 0; j < 8; j++) |
| 1578 | count += (((array[i] >> j) & 0x1) ? 1 : 0); |
| 1579 | return count; |
| 1580 | } |
| 1581 | |
| 1582 | static void hdcp_deauthenticate(void) |
| 1583 | { |
| 1584 | int hdcp_link_status = HDMI_INP(0x011C); |
| 1585 | |
| 1586 | external_common_state->hdcp_active = FALSE; |
| 1587 | /* 0x0130 HDCP_RESET |
| 1588 | [0] LINK0_DEAUTHENTICATE */ |
| 1589 | HDMI_OUTP(0x0130, 0x1); |
| 1590 | |
| 1591 | /* 0x0110 HDCP_CTRL |
| 1592 | [8] ENCRYPTION_ENABLE |
| 1593 | [0] ENABLE */ |
| 1594 | /* encryption_enable = 0 | hdcp block enable = 1 */ |
| 1595 | HDMI_OUTP(0x0110, 0x0); |
| 1596 | |
| 1597 | if (hdcp_link_status & 0x00000004) |
| 1598 | hdcp_auth_info((hdcp_link_status & 0x000000F0) >> 4); |
| 1599 | } |
| 1600 | |
| 1601 | static int hdcp_authentication_part1(void) |
| 1602 | { |
| 1603 | int ret = 0; |
| 1604 | boolean is_match; |
| 1605 | boolean is_part1_done = FALSE; |
| 1606 | uint32 timeout_count; |
| 1607 | uint8 bcaps; |
| 1608 | uint8 aksv[5]; |
| 1609 | uint32 qfprom_aksv_0, qfprom_aksv_1, link0_aksv_0, link0_aksv_1; |
| 1610 | uint8 bksv[5]; |
| 1611 | uint32 link0_bksv_0, link0_bksv_1; |
| 1612 | uint8 an[8]; |
| 1613 | uint32 link0_an_0, link0_an_1; |
| 1614 | uint32 hpd_int_status, hpd_int_ctrl; |
| 1615 | |
| 1616 | |
| 1617 | static uint8 buf[0xFF]; |
| 1618 | memset(buf, 0, sizeof(buf)); |
| 1619 | |
| 1620 | if (!is_part1_done) { |
| 1621 | is_part1_done = TRUE; |
| 1622 | |
| 1623 | /* Fetch aksv from QFprom, this info should be public. */ |
| 1624 | qfprom_aksv_0 = inpdw(QFPROM_BASE + 0x000060D8); |
| 1625 | qfprom_aksv_1 = inpdw(QFPROM_BASE + 0x000060DC); |
| 1626 | |
| 1627 | /* copy an and aksv to byte arrays for transmission */ |
| 1628 | aksv[0] = qfprom_aksv_0 & 0xFF; |
| 1629 | aksv[1] = (qfprom_aksv_0 >> 8) & 0xFF; |
| 1630 | aksv[2] = (qfprom_aksv_0 >> 16) & 0xFF; |
| 1631 | aksv[3] = (qfprom_aksv_0 >> 24) & 0xFF; |
| 1632 | aksv[4] = qfprom_aksv_1 & 0xFF; |
| 1633 | /* check there are 20 ones in AKSV */ |
| 1634 | if (hdmi_msm_count_one(aksv, 5) != 20) { |
| 1635 | DEV_ERR("HDCP: AKSV read from QFPROM doesn't have\ |
| 1636 | 20 1's and 20 0's, FAIL (AKSV=%02x%08x)\n", |
| 1637 | qfprom_aksv_1, qfprom_aksv_0); |
| 1638 | ret = -EINVAL; |
| 1639 | goto error; |
| 1640 | } |
| 1641 | DEV_DBG("HDCP: AKSV=%02x%08x\n", qfprom_aksv_1, qfprom_aksv_0); |
| 1642 | |
| 1643 | /* 0x0288 HDCP_SW_LOWER_AKSV |
| 1644 | [31:0] LOWER_AKSV */ |
| 1645 | /* 0x0284 HDCP_SW_UPPER_AKSV |
| 1646 | [7:0] UPPER_AKSV */ |
| 1647 | |
| 1648 | /* This is the lower 32 bits of the SW |
| 1649 | * injected AKSV value(AKSV[31:0]) read |
| 1650 | * from the EFUSE. It is needed for HDCP |
| 1651 | * authentication and must be written |
| 1652 | * before enabling HDCP. */ |
| 1653 | HDMI_OUTP(0x0288, qfprom_aksv_0); |
| 1654 | HDMI_OUTP(0x0284, qfprom_aksv_1); |
| 1655 | |
| 1656 | msm_hdmi_init_ddc(); |
| 1657 | |
| 1658 | /* Read Bksv 5 bytes at 0x00 in HDCP port */ |
| 1659 | ret = hdmi_msm_ddc_read(0x74, 0x00, bksv, 5, 5, "Bksv", TRUE); |
| 1660 | if (ret) { |
| 1661 | DEV_ERR("%s(%d): Read BKSV failed", __func__, __LINE__); |
| 1662 | goto error; |
| 1663 | } |
| 1664 | /* check there are 20 ones in BKSV */ |
| 1665 | if (hdmi_msm_count_one(bksv, 5) != 20) { |
| 1666 | DEV_ERR("HDCP: BKSV read from Sink doesn't have\ |
| 1667 | 20 1's and 20 0's, FAIL (BKSV=\ |
| 1668 | %02x%02x%02x%02x%02x)\n", |
| 1669 | bksv[4], bksv[3], bksv[2], bksv[1], bksv[0]); |
| 1670 | ret = -EINVAL; |
| 1671 | goto error; |
| 1672 | } |
| 1673 | |
| 1674 | link0_bksv_0 = bksv[3]; |
| 1675 | link0_bksv_0 = (link0_bksv_0 << 8) | bksv[2]; |
| 1676 | link0_bksv_0 = (link0_bksv_0 << 8) | bksv[1]; |
| 1677 | link0_bksv_0 = (link0_bksv_0 << 8) | bksv[0]; |
| 1678 | link0_bksv_1 = bksv[4]; |
| 1679 | DEV_DBG("HDCP: BKSV=%02x%08x\n", link0_bksv_1, link0_bksv_0); |
| 1680 | |
| 1681 | /* read Bcaps at 0x40 in HDCP Port */ |
| 1682 | ret = hdmi_msm_ddc_read(0x74, 0x40, &bcaps, 1, 5, "Bcaps", |
| 1683 | TRUE); |
| 1684 | if (ret) { |
| 1685 | DEV_ERR("%s(%d): Read Bcaps failed", __func__, |
| 1686 | __LINE__); |
| 1687 | goto error; |
| 1688 | } |
| 1689 | DEV_DBG("HDCP: Bcaps=%02x\n", bcaps); |
| 1690 | |
| 1691 | /* HDCP setup prior to HDCP enabled */ |
| 1692 | |
| 1693 | /* 0x0148 HDCP_RCVPORT_DATA4 |
| 1694 | [15:8] LINK0_AINFO |
| 1695 | [7:0] LINK0_AKSV_1 */ |
| 1696 | /* LINK0_AINFO = 0x2 FEATURE 1.1 on. |
| 1697 | * = 0x0 FEATURE 1.1 off*/ |
| 1698 | HDMI_OUTP(0x0148, 0x2 << 8); |
| 1699 | |
| 1700 | /* 0x012C HDCP_ENTROPY_CTRL0 |
| 1701 | [31:0] BITS_OF_INFLUENCE_0 */ |
| 1702 | /* 0x025C HDCP_ENTROPY_CTRL1 |
| 1703 | [31:0] BITS_OF_INFLUENCE_1 */ |
| 1704 | HDMI_OUTP(0x012C, 0xB1FFB0FF); |
| 1705 | HDMI_OUTP(0x025C, 0xF00DFACE); |
| 1706 | |
| 1707 | /* 0x0114 HDCP_DEBUG_CTRL |
| 1708 | [2] DEBUG_RNG_CIPHER |
| 1709 | else default 0 */ |
| 1710 | HDMI_OUTP(0x0114, HDMI_INP(0x0114) & 0xFFFFFFFB); |
| 1711 | |
| 1712 | /* 0x0110 HDCP_CTRL |
| 1713 | [8] ENCRYPTION_ENABLE |
| 1714 | [0] ENABLE */ |
| 1715 | /* encryption_enable | enable */ |
| 1716 | HDMI_OUTP(0x0110, (1 << 8) | (1 << 0)); |
| 1717 | |
| 1718 | /* 0x0118 HDCP_INT_CTRL |
| 1719 | * [2] AUTH_SUCCESS_MASK [R/W] Mask bit for\ |
| 1720 | * HDCP Authentication |
| 1721 | * Success interrupt - set to 1 to enable interrupt |
| 1722 | * |
| 1723 | * [6] AUTH_FAIL_MASK [R/W] Mask bit for HDCP |
| 1724 | * Authentication |
| 1725 | * Lost interrupt set to 1 to enable interrupt |
| 1726 | * |
| 1727 | * [7] AUTH_FAIL_INFO_ACK [W] Acknwledge bit for HDCP |
| 1728 | * Auth Failure Info field - write 1 to clear |
| 1729 | * |
| 1730 | * [10] DDC_XFER_REQ_MASK [R/W] Mask bit for HDCP\ |
| 1731 | * DDC Transfer |
| 1732 | * Request interrupt - set to 1 to enable interrupt |
| 1733 | * |
| 1734 | * [14] DDC_XFER_DONE_MASK [R/W] Mask bit for HDCP\ |
| 1735 | * DDC Transfer |
| 1736 | * done interrupt - set to 1 to enable interrupt */ |
| 1737 | /* enable all HDCP ints */ |
| 1738 | HDMI_OUTP(0x0118, (1 << 2) | (1 << 6) | (1 << 7)); |
| 1739 | |
| 1740 | /* 0x011C HDCP_LINK0_STATUS |
| 1741 | [8] AN_0_READY |
| 1742 | [9] AN_1_READY */ |
| 1743 | /* wait for an0 and an1 ready bits to be set in LINK0_STATUS */ |
| 1744 | timeout_count = 100; |
| 1745 | while (((HDMI_INP_ND(0x011C) & (0x3 << 8)) != (0x3 << 8)) |
| 1746 | && timeout_count--) |
| 1747 | msleep(20); |
| 1748 | if (!timeout_count) { |
| 1749 | ret = -ETIMEDOUT; |
| 1750 | DEV_ERR("%s(%d): timedout, An0=%d, An1=%d\n", |
| 1751 | __func__, __LINE__, |
| 1752 | (HDMI_INP_ND(0x011C) & BIT(8)) >> 8, |
| 1753 | (HDMI_INP_ND(0x011C) & BIT(9)) >> 9); |
| 1754 | goto error; |
| 1755 | } |
| 1756 | |
| 1757 | /* 0x0168 HDCP_RCVPORT_DATA12 |
| 1758 | [23:8] BSTATUS |
| 1759 | [7:0] BCAPS */ |
| 1760 | HDMI_OUTP(0x0168, bcaps); |
| 1761 | |
| 1762 | /* 0x014C HDCP_RCVPORT_DATA5 |
| 1763 | [31:0] LINK0_AN_0 */ |
| 1764 | /* read an0 calculation */ |
| 1765 | link0_an_0 = HDMI_INP(0x014C); |
| 1766 | |
| 1767 | /* 0x0150 HDCP_RCVPORT_DATA6 |
| 1768 | [31:0] LINK0_AN_1 */ |
| 1769 | /* read an1 calculation */ |
| 1770 | link0_an_1 = HDMI_INP(0x0150); |
| 1771 | |
| 1772 | /* three bits 28..30 */ |
| 1773 | hdcp_key_state((HDMI_INP(0x011C) >> 28) & 0x7); |
| 1774 | |
| 1775 | /* 0x0144 HDCP_RCVPORT_DATA3 |
| 1776 | [31:0] LINK0_AKSV_0 public key |
| 1777 | 0x0148 HDCP_RCVPORT_DATA4 |
| 1778 | [15:8] LINK0_AINFO |
| 1779 | [7:0] LINK0_AKSV_1 public key */ |
| 1780 | link0_aksv_0 = HDMI_INP(0x0144); |
| 1781 | link0_aksv_1 = HDMI_INP(0x0148); |
| 1782 | |
| 1783 | /* copy an and aksv to byte arrays for transmission */ |
| 1784 | aksv[0] = link0_aksv_0 & 0xFF; |
| 1785 | aksv[1] = (link0_aksv_0 >> 8) & 0xFF; |
| 1786 | aksv[2] = (link0_aksv_0 >> 16) & 0xFF; |
| 1787 | aksv[3] = (link0_aksv_0 >> 24) & 0xFF; |
| 1788 | aksv[4] = link0_aksv_1 & 0xFF; |
| 1789 | |
| 1790 | an[0] = link0_an_0 & 0xFF; |
| 1791 | an[1] = (link0_an_0 >> 8) & 0xFF; |
| 1792 | an[2] = (link0_an_0 >> 16) & 0xFF; |
| 1793 | an[3] = (link0_an_0 >> 24) & 0xFF; |
| 1794 | an[4] = link0_an_1 & 0xFF; |
| 1795 | an[5] = (link0_an_1 >> 8) & 0xFF; |
| 1796 | an[6] = (link0_an_1 >> 16) & 0xFF; |
| 1797 | an[7] = (link0_an_1 >> 24) & 0xFF; |
| 1798 | |
| 1799 | /* Write An 8 bytes to offset 0x18 */ |
| 1800 | ret = hdmi_msm_ddc_write(0x74, 0x18, an, 8, "An"); |
| 1801 | if (ret) { |
| 1802 | DEV_ERR("%s(%d): Write An failed", __func__, __LINE__); |
| 1803 | goto error; |
| 1804 | } |
| 1805 | |
| 1806 | /* Write Aksv 5 bytes to offset 0x10 */ |
| 1807 | ret = hdmi_msm_ddc_write(0x74, 0x10, aksv, 5, "Aksv"); |
| 1808 | if (ret) { |
| 1809 | DEV_ERR("%s(%d): Write Aksv failed", __func__, |
| 1810 | __LINE__); |
| 1811 | goto error; |
| 1812 | } |
| 1813 | DEV_DBG("HDCP: Link0-AKSV=%02x%08x\n", |
| 1814 | link0_aksv_1 & 0xFF, link0_aksv_0); |
| 1815 | |
| 1816 | /* 0x0134 HDCP_RCVPORT_DATA0 |
| 1817 | [31:0] LINK0_BKSV_0 */ |
| 1818 | HDMI_OUTP(0x0134, link0_bksv_0); |
| 1819 | /* 0x0138 HDCP_RCVPORT_DATA1 |
| 1820 | [31:0] LINK0_BKSV_1 */ |
| 1821 | HDMI_OUTP(0x0138, link0_bksv_1); |
| 1822 | DEV_DBG("HDCP: Link0-BKSV=%02x%08x\n", link0_bksv_1, |
| 1823 | link0_bksv_0); |
| 1824 | |
| 1825 | /* HDMI_HPD_INT_STATUS[0x0250] */ |
| 1826 | hpd_int_status = HDMI_INP_ND(0x0250); |
| 1827 | /* HDMI_HPD_INT_CTRL[0x0254] */ |
| 1828 | hpd_int_ctrl = HDMI_INP_ND(0x0254); |
| 1829 | DEV_DBG("[SR-DEUG]: HPD_INTR_CTRL=[%u] HPD_INTR_STATUS=[%u]\ |
| 1830 | before reading R0'\n", hpd_int_ctrl, hpd_int_status); |
| 1831 | |
| 1832 | /* |
| 1833 | * HDCP Compliace Test case 1B-01: |
| 1834 | * Wait here until all the ksv bytes have been |
| 1835 | * read from the KSV FIFO register. |
| 1836 | */ |
| 1837 | msleep(125); |
| 1838 | |
| 1839 | /* Reading R0' 2 bytes at offset 0x08 */ |
| 1840 | ret = hdmi_msm_ddc_read(0x74, 0x08, buf, 2, 5, "RO'", TRUE); |
| 1841 | if (ret) { |
| 1842 | DEV_ERR("%s(%d): Read RO's failed", __func__, |
| 1843 | __LINE__); |
| 1844 | goto error; |
| 1845 | } |
| 1846 | |
| 1847 | /* 0x013C HDCP_RCVPORT_DATA2_0 |
| 1848 | [15:0] LINK0_RI */ |
| 1849 | HDMI_OUTP(0x013C, (((uint32)buf[1]) << 8) | buf[0]); |
| 1850 | DEV_DBG("HDCP: R0'=%02x%02x\n", buf[1], buf[0]); |
| 1851 | |
| 1852 | INIT_COMPLETION(hdmi_msm_state->hdcp_success_done); |
| 1853 | timeout_count = wait_for_completion_interruptible_timeout( |
| 1854 | &hdmi_msm_state->hdcp_success_done, HZ*2); |
| 1855 | |
| 1856 | if (!timeout_count) { |
| 1857 | ret = -ETIMEDOUT; |
| 1858 | is_match = HDMI_INP(0x011C) & BIT(12); |
| 1859 | DEV_ERR("%s(%d): timedout, Link0=<%s>\n", __func__, |
| 1860 | __LINE__, |
| 1861 | is_match ? "RI_MATCH" : "No RI Match INTR in time"); |
| 1862 | if (!is_match) |
| 1863 | goto error; |
| 1864 | } |
| 1865 | |
| 1866 | /* 0x011C HDCP_LINK0_STATUS |
| 1867 | [12] RI_MATCHES [0] MISMATCH, [1] MATCH |
| 1868 | [0] AUTH_SUCCESS */ |
| 1869 | /* Checking for RI, R0 Match */ |
| 1870 | /* RI_MATCHES */ |
| 1871 | if ((HDMI_INP(0x011C) & BIT(12)) != BIT(12)) { |
| 1872 | ret = -EINVAL; |
| 1873 | DEV_ERR("%s: HDCP_LINK0_STATUS[RI_MATCHES]: MISMATCH\n", |
| 1874 | __func__); |
| 1875 | goto error; |
| 1876 | } |
| 1877 | |
| 1878 | DEV_INFO("HDCP: authentication part I, successful\n"); |
| 1879 | is_part1_done = FALSE; |
| 1880 | return 0; |
| 1881 | error: |
| 1882 | DEV_ERR("[%s]: HDCP Reauthentication\n", __func__); |
| 1883 | is_part1_done = FALSE; |
| 1884 | return ret; |
| 1885 | } else { |
| 1886 | return 1; |
| 1887 | } |
| 1888 | } |
| 1889 | |
| 1890 | static int hdmi_msm_transfer_v_h(void) |
| 1891 | { |
| 1892 | /* Read V'.HO 4 Byte at offset 0x20 */ |
| 1893 | char what[20]; |
| 1894 | int ret; |
| 1895 | uint8 buf[4]; |
| 1896 | |
| 1897 | snprintf(what, sizeof(what), "V' H0"); |
| 1898 | ret = hdmi_msm_ddc_read(0x74, 0x20, buf, 4, 5, what, TRUE); |
| 1899 | if (ret) { |
| 1900 | DEV_ERR("%s: Read %s failed", __func__, what); |
| 1901 | return ret; |
| 1902 | } |
| 1903 | DEV_DBG("buf[0]= %x , buf[1] = %x , buf[2] = %x , buf[3] = %x\n ", |
| 1904 | buf[0] , buf[1] , buf[2] , buf[3]); |
| 1905 | |
| 1906 | /* 0x0154 HDCP_RCVPORT_DATA7 |
| 1907 | [31:0] V_HO */ |
| 1908 | HDMI_OUTP(0x0154 , |
| 1909 | (buf[3] << 24 | buf[2] << 16 | buf[1] << 8 | buf[0])); |
| 1910 | |
| 1911 | snprintf(what, sizeof(what), "V' H1"); |
| 1912 | ret = hdmi_msm_ddc_read(0x74, 0x24, buf, 4, 5, what, TRUE); |
| 1913 | if (ret) { |
| 1914 | DEV_ERR("%s: Read %s failed", __func__, what); |
| 1915 | return ret; |
| 1916 | } |
| 1917 | DEV_DBG("buf[0]= %x , buf[1] = %x , buf[2] = %x , buf[3] = %x\n ", |
| 1918 | buf[0] , buf[1] , buf[2] , buf[3]); |
| 1919 | |
| 1920 | /* 0x0158 HDCP_RCVPORT_ DATA8 |
| 1921 | [31:0] V_H1 */ |
| 1922 | HDMI_OUTP(0x0158, |
| 1923 | (buf[3] << 24 | buf[2] << 16 | buf[1] << 8 | buf[0])); |
| 1924 | |
| 1925 | |
| 1926 | snprintf(what, sizeof(what), "V' H2"); |
| 1927 | ret = hdmi_msm_ddc_read(0x74, 0x28, buf, 4, 5, what, TRUE); |
| 1928 | if (ret) { |
| 1929 | DEV_ERR("%s: Read %s failed", __func__, what); |
| 1930 | return ret; |
| 1931 | } |
| 1932 | DEV_DBG("buf[0]= %x , buf[1] = %x , buf[2] = %x , buf[3] = %x\n ", |
| 1933 | buf[0] , buf[1] , buf[2] , buf[3]); |
| 1934 | |
| 1935 | /* 0x015c HDCP_RCVPORT_DATA9 |
| 1936 | [31:0] V_H2 */ |
| 1937 | HDMI_OUTP(0x015c , |
| 1938 | (buf[3] << 24 | buf[2] << 16 | buf[1] << 8 | buf[0])); |
| 1939 | |
| 1940 | snprintf(what, sizeof(what), "V' H3"); |
| 1941 | ret = hdmi_msm_ddc_read(0x74, 0x2c, buf, 4, 5, what, TRUE); |
| 1942 | if (ret) { |
| 1943 | DEV_ERR("%s: Read %s failed", __func__, what); |
| 1944 | return ret; |
| 1945 | } |
| 1946 | DEV_DBG("buf[0]= %x , buf[1] = %x , buf[2] = %x , buf[3] = %x\n ", |
| 1947 | buf[0] , buf[1] , buf[2] , buf[3]); |
| 1948 | |
| 1949 | /* 0x0160 HDCP_RCVPORT_DATA10 |
| 1950 | [31:0] V_H3 */ |
| 1951 | HDMI_OUTP(0x0160, |
| 1952 | (buf[3] << 24 | buf[2] << 16 | buf[1] << 8 | buf[0])); |
| 1953 | |
| 1954 | snprintf(what, sizeof(what), "V' H4"); |
| 1955 | ret = hdmi_msm_ddc_read(0x74, 0x30, buf, 4, 5, what, TRUE); |
| 1956 | if (ret) { |
| 1957 | DEV_ERR("%s: Read %s failed", __func__, what); |
| 1958 | return ret; |
| 1959 | } |
| 1960 | DEV_DBG("buf[0]= %x , buf[1] = %x , buf[2] = %x , buf[3] = %x\n ", |
| 1961 | buf[0] , buf[1] , buf[2] , buf[3]); |
| 1962 | /* 0x0164 HDCP_RCVPORT_DATA11 |
| 1963 | [31:0] V_H4 */ |
| 1964 | HDMI_OUTP(0x0164, |
| 1965 | (buf[3] << 24 | buf[2] << 16 | buf[1] << 8 | buf[0])); |
| 1966 | |
| 1967 | return 0; |
| 1968 | } |
| 1969 | |
| 1970 | static int hdcp_authentication_part2(void) |
| 1971 | { |
| 1972 | int ret = 0; |
| 1973 | uint32 timeout_count; |
| 1974 | int i = 0; |
| 1975 | int cnt = 0; |
| 1976 | uint bstatus; |
| 1977 | uint8 bcaps; |
| 1978 | uint32 down_stream_devices; |
| 1979 | uint32 ksv_bytes; |
| 1980 | |
| 1981 | static uint8 buf[0xFF]; |
| 1982 | static uint8 kvs_fifo[5 * 127]; |
| 1983 | |
| 1984 | boolean max_devs_exceeded = 0; |
| 1985 | boolean max_cascade_exceeded = 0; |
| 1986 | |
| 1987 | boolean ksv_done = FALSE; |
| 1988 | |
| 1989 | memset(buf, 0, sizeof(buf)); |
| 1990 | memset(kvs_fifo, 0, sizeof(kvs_fifo)); |
| 1991 | |
| 1992 | /* wait until READY bit is set in bcaps */ |
| 1993 | timeout_count = 50; |
| 1994 | do { |
| 1995 | timeout_count--; |
| 1996 | /* read bcaps 1 Byte at offset 0x40 */ |
| 1997 | ret = hdmi_msm_ddc_read(0x74, 0x40, &bcaps, 1, 1, |
| 1998 | "Bcaps", FALSE); |
| 1999 | if (ret) { |
| 2000 | DEV_ERR("%s(%d): Read Bcaps failed", __func__, |
| 2001 | __LINE__); |
| 2002 | goto error; |
| 2003 | } |
| 2004 | msleep(100); |
| 2005 | } while ((0 == (bcaps & 0x20)) && timeout_count); /* READY (Bit 5) */ |
| 2006 | if (!timeout_count) { |
| 2007 | ret = -ETIMEDOUT; |
| 2008 | DEV_ERR("%s:timedout(1)", __func__); |
| 2009 | goto error; |
| 2010 | } |
| 2011 | |
| 2012 | /* read bstatus 2 bytes at offset 0x41 */ |
| 2013 | |
| 2014 | ret = hdmi_msm_ddc_read(0x74, 0x41, buf, 2, 5, "Bstatus", FALSE); |
| 2015 | if (ret) { |
| 2016 | DEV_ERR("%s(%d): Read Bstatus failed", __func__, __LINE__); |
| 2017 | goto error; |
| 2018 | } |
| 2019 | bstatus = buf[1]; |
| 2020 | bstatus = (bstatus << 8) | buf[0]; |
| 2021 | /* 0x0168 DCP_RCVPORT_DATA12 |
| 2022 | [7:0] BCAPS |
| 2023 | [23:8 BSTATUS */ |
| 2024 | HDMI_OUTP(0x0168, bcaps | (bstatus << 8)); |
| 2025 | /* BSTATUS [6:0] DEVICE_COUNT Number of HDMI device attached to repeater |
| 2026 | * - see HDCP spec */ |
| 2027 | down_stream_devices = bstatus & 0x7F; |
| 2028 | |
| 2029 | if (down_stream_devices == 0x0) { |
| 2030 | /* There isn't any devices attaced to the Repeater */ |
| 2031 | DEV_ERR("%s: there isn't any devices attached to the " |
| 2032 | "Repeater\n", __func__); |
| 2033 | ret = -EINVAL; |
| 2034 | goto error; |
| 2035 | } |
| 2036 | |
| 2037 | /* |
| 2038 | * HDCP Compliance 1B-05: |
| 2039 | * Check if no. of devices connected to repeater |
| 2040 | * exceed max_devices_connected from bit 7 of Bstatus. |
| 2041 | */ |
| 2042 | max_devs_exceeded = (bstatus & 0x80) >> 7; |
| 2043 | if (max_devs_exceeded == 0x01) { |
| 2044 | DEV_ERR("%s: Number of devs connected to repeater " |
| 2045 | "exceeds max_devs\n", __func__); |
| 2046 | ret = -EINVAL; |
| 2047 | goto hdcp_error; |
| 2048 | } |
| 2049 | |
| 2050 | /* |
| 2051 | * HDCP Compliance 1B-06: |
| 2052 | * Check if no. of cascade connected to repeater |
| 2053 | * exceed max_cascade_connected from bit 11 of Bstatus. |
| 2054 | */ |
| 2055 | max_cascade_exceeded = (bstatus & 0x800) >> 11; |
| 2056 | if (max_cascade_exceeded == 0x01) { |
| 2057 | DEV_ERR("%s: Number of cascade connected to repeater " |
| 2058 | "exceeds max_cascade\n", __func__); |
| 2059 | ret = -EINVAL; |
| 2060 | goto hdcp_error; |
| 2061 | } |
| 2062 | |
| 2063 | /* Read KSV FIFO over DDC |
| 2064 | * Key Slection vector FIFO |
| 2065 | * Used to pull downstream KSVs from HDCP Repeaters. |
| 2066 | * All bytes (DEVICE_COUNT * 5) must be read in a single, |
| 2067 | * auto incrementing access. |
| 2068 | * All bytes read as 0x00 for HDCP Receivers that are not |
| 2069 | * HDCP Repeaters (REPEATER == 0). */ |
| 2070 | ksv_bytes = 5 * down_stream_devices; |
| 2071 | /* Reading KSV FIFO / KSV FIFO */ |
| 2072 | ksv_done = FALSE; |
| 2073 | |
| 2074 | ret = hdmi_msm_ddc_read(0x74, 0x43, kvs_fifo, ksv_bytes, 5, |
| 2075 | "KSV FIFO", TRUE); |
| 2076 | do { |
| 2077 | if (ret) { |
| 2078 | DEV_ERR("%s(%d): Read KSV FIFO failed", |
| 2079 | __func__, __LINE__); |
| 2080 | /* |
| 2081 | * HDCP Compliace Test case 1B-01: |
| 2082 | * Wait here until all the ksv bytes have been |
| 2083 | * read from the KSV FIFO register. |
| 2084 | */ |
| 2085 | msleep(25); |
| 2086 | } else { |
| 2087 | ksv_done = TRUE; |
| 2088 | } |
| 2089 | cnt++; |
| 2090 | } while (!ksv_done && cnt != 20); |
| 2091 | |
| 2092 | if (ksv_done == FALSE) |
| 2093 | goto error; |
| 2094 | |
| 2095 | ret = hdmi_msm_transfer_v_h(); |
| 2096 | if (ret) |
| 2097 | goto error; |
| 2098 | |
| 2099 | /* Next: Write KSV FIFO to HDCP_SHA_DATA. |
| 2100 | * This is done 1 byte at time starting with the LSB. |
| 2101 | * On the very last byte write, |
| 2102 | * the HDCP_SHA_DATA_DONE bit[0] |
| 2103 | */ |
| 2104 | |
| 2105 | /* 0x023C HDCP_SHA_CTRL |
| 2106 | [0] RESET [0] Enable, [1] Reset |
| 2107 | [4] SELECT [0] DIGA_HDCP, [1] DIGB_HDCP */ |
| 2108 | /* reset SHA engine */ |
| 2109 | HDMI_OUTP(0x023C, 1); |
| 2110 | /* enable SHA engine, SEL=DIGA_HDCP */ |
| 2111 | HDMI_OUTP(0x023C, 0); |
| 2112 | |
| 2113 | for (i = 0; i < ksv_bytes - 1; i++) { |
| 2114 | /* Write KSV byte and do not set DONE bit[0] */ |
| 2115 | HDMI_OUTP_ND(0x0244, kvs_fifo[i] << 16); |
| 2116 | } |
| 2117 | /* Write l to DONE bit[0] */ |
| 2118 | HDMI_OUTP_ND(0x0244, (kvs_fifo[ksv_bytes - 1] << 16) | 0x1); |
| 2119 | |
| 2120 | /* 0x0240 HDCP_SHA_STATUS |
| 2121 | [4] COMP_DONE */ |
| 2122 | /* Now wait for HDCP_SHA_COMP_DONE */ |
| 2123 | timeout_count = 100; |
| 2124 | while ((0x10 != (HDMI_INP_ND(0x0240) & 0x10)) && timeout_count--) |
| 2125 | msleep(20); |
| 2126 | if (!timeout_count) { |
| 2127 | ret = -ETIMEDOUT; |
| 2128 | DEV_ERR("%s(%d): timedout", __func__, __LINE__); |
| 2129 | goto error; |
| 2130 | } |
| 2131 | |
| 2132 | /* 0x011C HDCP_LINK0_STATUS |
| 2133 | [20] V_MATCHES */ |
| 2134 | timeout_count = 100; |
| 2135 | while (((HDMI_INP_ND(0x011C) & (1 << 20)) != (1 << 20)) |
| 2136 | && timeout_count--) |
| 2137 | msleep(20); |
| 2138 | if (!timeout_count) { |
| 2139 | ret = -ETIMEDOUT; |
| 2140 | DEV_ERR("%s(%d): timedout", __func__, __LINE__); |
| 2141 | goto error; |
| 2142 | } |
| 2143 | |
| 2144 | DEV_INFO("HDCP: authentication part II, successful\n"); |
| 2145 | |
| 2146 | hdcp_error: |
| 2147 | error: |
| 2148 | return ret; |
| 2149 | } |
| 2150 | |
| 2151 | static int hdcp_authentication_part3(uint32 found_repeater) |
| 2152 | { |
| 2153 | int ret = 0; |
| 2154 | int poll = 3000; |
| 2155 | while (poll) { |
| 2156 | /* 0x011C HDCP_LINK0_STATUS |
| 2157 | [30:28] KEYS_STATE = 3 = "Valid" |
| 2158 | [24] RO_COMPUTATION_DONE [0] Not Done, [1] Done |
| 2159 | [20] V_MATCHES [0] Mismtach, [1] Match |
| 2160 | [12] RI_MATCHES [0] Mismatch, [1] Match |
| 2161 | [0] AUTH_SUCCESS */ |
| 2162 | if (HDMI_INP_ND(0x011C) != (0x31001001 | |
| 2163 | (found_repeater << 20))) { |
| 2164 | DEV_ERR("HDCP: autentication part III, FAILED, " |
| 2165 | "Link Status=%08x\n", HDMI_INP(0x011C)); |
| 2166 | ret = -EINVAL; |
| 2167 | goto error; |
| 2168 | } |
| 2169 | poll--; |
| 2170 | } |
| 2171 | |
| 2172 | DEV_INFO("HDCP: authentication part III, successful\n"); |
| 2173 | |
| 2174 | error: |
| 2175 | return ret; |
| 2176 | } |
| 2177 | |
| 2178 | static void hdmi_msm_hdcp_enable(void) |
| 2179 | { |
| 2180 | int ret = 0; |
| 2181 | uint8 bcaps; |
| 2182 | uint32 found_repeater = 0x0; |
| 2183 | char *envp[2]; |
| 2184 | |
| 2185 | if (!hdmi_msm_has_hdcp()) |
| 2186 | return; |
| 2187 | |
| 2188 | mutex_lock(&hdmi_msm_state_mutex); |
| 2189 | hdmi_msm_state->hdcp_activating = TRUE; |
| 2190 | mutex_unlock(&hdmi_msm_state_mutex); |
| 2191 | |
| 2192 | fill_black_screen(); |
| 2193 | |
| 2194 | mutex_lock(&hdcp_auth_state_mutex); |
| 2195 | /* |
| 2196 | * Initialize this to zero here to make |
| 2197 | * sure HPD has not happened yet |
| 2198 | */ |
| 2199 | hdmi_msm_state->hpd_during_auth = FALSE; |
| 2200 | /* This flag prevents other threads from re-authenticating |
| 2201 | * after we've just authenticated (i.e., finished part3) |
| 2202 | * We probably need to protect this in a mutex lock */ |
| 2203 | hdmi_msm_state->full_auth_done = FALSE; |
| 2204 | mutex_unlock(&hdcp_auth_state_mutex); |
| 2205 | |
| 2206 | /* PART I Authentication*/ |
| 2207 | ret = hdcp_authentication_part1(); |
| 2208 | if (ret) |
| 2209 | goto error; |
| 2210 | |
| 2211 | /* PART II Authentication*/ |
| 2212 | /* read Bcaps at 0x40 in HDCP Port */ |
| 2213 | ret = hdmi_msm_ddc_read(0x74, 0x40, &bcaps, 1, 5, "Bcaps", FALSE); |
| 2214 | if (ret) { |
| 2215 | DEV_ERR("%s(%d): Read Bcaps failed\n", __func__, __LINE__); |
| 2216 | goto error; |
| 2217 | } |
| 2218 | DEV_DBG("HDCP: Bcaps=0x%02x (%s)\n", bcaps, |
| 2219 | (bcaps & BIT(6)) ? "repeater" : "no repeater"); |
| 2220 | |
| 2221 | /* if REPEATER (Bit 6), perform Part2 Authentication */ |
| 2222 | if (bcaps & BIT(6)) { |
| 2223 | found_repeater = 0x1; |
| 2224 | ret = hdcp_authentication_part2(); |
| 2225 | if (ret) |
| 2226 | goto error; |
| 2227 | } else |
| 2228 | DEV_INFO("HDCP: authentication part II skipped, no repeater\n"); |
| 2229 | |
| 2230 | /* PART III Authentication*/ |
| 2231 | ret = hdcp_authentication_part3(found_repeater); |
| 2232 | if (ret) |
| 2233 | goto error; |
| 2234 | |
| 2235 | unfill_black_screen(); |
| 2236 | |
| 2237 | external_common_state->hdcp_active = TRUE; |
| 2238 | mutex_lock(&hdmi_msm_state_mutex); |
| 2239 | hdmi_msm_state->hdcp_activating = FALSE; |
| 2240 | mutex_unlock(&hdmi_msm_state_mutex); |
| 2241 | |
| 2242 | mutex_lock(&hdcp_auth_state_mutex); |
| 2243 | /* |
| 2244 | * This flag prevents other threads from re-authenticating |
| 2245 | * after we've just authenticated (i.e., finished part3) |
| 2246 | */ |
| 2247 | hdmi_msm_state->full_auth_done = TRUE; |
| 2248 | mutex_unlock(&hdcp_auth_state_mutex); |
| 2249 | |
| 2250 | if (!hdmi_msm_is_dvi_mode()) { |
| 2251 | DEV_INFO("HDMI HPD: sense : send HDCP_PASS\n"); |
| 2252 | envp[0] = "HDCP_STATE=PASS"; |
| 2253 | envp[1] = NULL; |
| 2254 | kobject_uevent_env(external_common_state->uevent_kobj, |
| 2255 | KOBJ_CHANGE, envp); |
| 2256 | } |
| 2257 | return; |
| 2258 | |
| 2259 | error: |
| 2260 | mutex_lock(&hdmi_msm_state_mutex); |
| 2261 | hdmi_msm_state->hdcp_activating = FALSE; |
| 2262 | mutex_unlock(&hdmi_msm_state_mutex); |
| 2263 | if (hdmi_msm_state->hpd_during_auth) { |
| 2264 | DEV_WARN("Calling Deauthentication: HPD occured during\ |
| 2265 | authentication from [%s]\n", __func__); |
| 2266 | hdcp_deauthenticate(); |
| 2267 | mutex_lock(&hdcp_auth_state_mutex); |
| 2268 | hdmi_msm_state->hpd_during_auth = FALSE; |
| 2269 | mutex_unlock(&hdcp_auth_state_mutex); |
| 2270 | } else { |
| 2271 | DEV_WARN("[DEV_DBG]: Calling reauth from [%s]\n", __func__); |
| 2272 | if (hdmi_msm_state->panel_power_on) |
| 2273 | queue_work(hdmi_work_queue, |
| 2274 | &hdmi_msm_state->hdcp_reauth_work); |
| 2275 | } |
| 2276 | } |
| 2277 | #endif /* CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT */ |
| 2278 | |
| 2279 | static void hdmi_msm_video_setup(int video_format) |
| 2280 | { |
| 2281 | uint32 total_v = 0; |
| 2282 | uint32 total_h = 0; |
| 2283 | uint32 start_h = 0; |
| 2284 | uint32 end_h = 0; |
| 2285 | uint32 start_v = 0; |
| 2286 | uint32 end_v = 0; |
| 2287 | const struct hdmi_disp_mode_timing_type *timing = |
| 2288 | hdmi_common_get_supported_mode(video_format); |
| 2289 | |
| 2290 | /* timing register setup */ |
| 2291 | if (timing == NULL) { |
| 2292 | DEV_ERR("video format not supported: %d\n", video_format); |
| 2293 | return; |
| 2294 | } |
| 2295 | |
| 2296 | /* Hsync Total and Vsync Total */ |
| 2297 | total_h = timing->active_h + timing->front_porch_h |
| 2298 | + timing->back_porch_h + timing->pulse_width_h - 1; |
| 2299 | total_v = timing->active_v + timing->front_porch_v |
| 2300 | + timing->back_porch_v + timing->pulse_width_v - 1; |
| 2301 | /* 0x02C0 HDMI_TOTAL |
| 2302 | [27:16] V_TOTAL Vertical Total |
| 2303 | [11:0] H_TOTAL Horizontal Total */ |
| 2304 | HDMI_OUTP(0x02C0, ((total_v << 16) & 0x0FFF0000) |
| 2305 | | ((total_h << 0) & 0x00000FFF)); |
| 2306 | |
| 2307 | /* Hsync Start and Hsync End */ |
| 2308 | start_h = timing->back_porch_h + timing->pulse_width_h; |
| 2309 | end_h = (total_h + 1) - timing->front_porch_h; |
| 2310 | /* 0x02B4 HDMI_ACTIVE_H |
| 2311 | [27:16] END Horizontal end |
| 2312 | [11:0] START Horizontal start */ |
| 2313 | HDMI_OUTP(0x02B4, ((end_h << 16) & 0x0FFF0000) |
| 2314 | | ((start_h << 0) & 0x00000FFF)); |
| 2315 | |
| 2316 | start_v = timing->back_porch_v + timing->pulse_width_v - 1; |
| 2317 | end_v = total_v - timing->front_porch_v; |
| 2318 | /* 0x02B8 HDMI_ACTIVE_V |
| 2319 | [27:16] END Vertical end |
| 2320 | [11:0] START Vertical start */ |
| 2321 | HDMI_OUTP(0x02B8, ((end_v << 16) & 0x0FFF0000) |
| 2322 | | ((start_v << 0) & 0x00000FFF)); |
| 2323 | |
| 2324 | if (timing->interlaced) { |
| 2325 | /* 0x02C4 HDMI_V_TOTAL_F2 |
| 2326 | [11:0] V_TOTAL_F2 Vertical total for field2 */ |
| 2327 | HDMI_OUTP(0x02C4, ((total_v + 1) << 0) & 0x00000FFF); |
| 2328 | |
| 2329 | /* 0x02BC HDMI_ACTIVE_V_F2 |
| 2330 | [27:16] END_F2 Vertical end for field2 |
| 2331 | [11:0] START_F2 Vertical start for Field2 */ |
| 2332 | HDMI_OUTP(0x02BC, |
| 2333 | (((start_v + 1) << 0) & 0x00000FFF) |
| 2334 | | (((end_v + 1) << 16) & 0x0FFF0000)); |
| 2335 | } else { |
| 2336 | /* HDMI_V_TOTAL_F2 */ |
| 2337 | HDMI_OUTP(0x02C4, 0); |
| 2338 | /* HDMI_ACTIVE_V_F2 */ |
| 2339 | HDMI_OUTP(0x02BC, 0); |
| 2340 | } |
| 2341 | |
| 2342 | hdmi_frame_ctrl_cfg(timing); |
| 2343 | } |
| 2344 | |
| 2345 | struct hdmi_msm_audio_acr { |
| 2346 | uint32 n; /* N parameter for clock regeneration */ |
| 2347 | uint32 cts; /* CTS parameter for clock regeneration */ |
| 2348 | }; |
| 2349 | |
| 2350 | struct hdmi_msm_audio_arcs { |
| 2351 | uint32 pclk; |
| 2352 | struct hdmi_msm_audio_acr lut[MSM_HDMI_SAMPLE_RATE_MAX]; |
| 2353 | }; |
| 2354 | |
| 2355 | #define HDMI_MSM_AUDIO_ARCS(pclk, ...) { pclk, __VA_ARGS__ } |
| 2356 | |
| 2357 | /* Audio constants lookup table for hdmi_msm_audio_acr_setup */ |
| 2358 | /* Valid Pixel-Clock rates: 25.2MHz, 27MHz, 27.03MHz, 74.25MHz, 148.5MHz */ |
| 2359 | static const struct hdmi_msm_audio_arcs hdmi_msm_audio_acr_lut[] = { |
| 2360 | /* 25.200MHz */ |
| 2361 | HDMI_MSM_AUDIO_ARCS(25200, { |
| 2362 | {4096, 25200}, {6272, 28000}, {6144, 25200}, {12544, 28000}, |
| 2363 | {12288, 25200}, {25088, 28000}, {24576, 25200} }), |
| 2364 | /* 27.000MHz */ |
| 2365 | HDMI_MSM_AUDIO_ARCS(27000, { |
| 2366 | {4096, 27000}, {6272, 30000}, {6144, 27000}, {12544, 30000}, |
| 2367 | {12288, 27000}, {25088, 30000}, {24576, 27000} }), |
| 2368 | /* 27.030MHz */ |
| 2369 | HDMI_MSM_AUDIO_ARCS(27030, { |
| 2370 | {4096, 27030}, {6272, 30030}, {6144, 27030}, {12544, 30030}, |
| 2371 | {12288, 27030}, {25088, 30030}, {24576, 27030} }), |
| 2372 | /* 74.250MHz */ |
| 2373 | HDMI_MSM_AUDIO_ARCS(74250, { |
| 2374 | {4096, 74250}, {6272, 82500}, {6144, 74250}, {12544, 82500}, |
| 2375 | {12288, 74250}, {25088, 82500}, {24576, 74250} }), |
| 2376 | /* 148.500MHz */ |
| 2377 | HDMI_MSM_AUDIO_ARCS(148500, { |
| 2378 | {4096, 148500}, {6272, 165000}, {6144, 148500}, {12544, 165000}, |
| 2379 | {12288, 148500}, {25088, 165000}, {24576, 148500} }), |
| 2380 | }; |
| 2381 | |
| 2382 | static void hdmi_msm_audio_acr_setup(boolean enabled, int video_format, |
| 2383 | int audio_sample_rate, int num_of_channels) |
| 2384 | { |
| 2385 | /* Read first before writing */ |
| 2386 | /* HDMI_ACR_PKT_CTRL[0x0024] */ |
| 2387 | uint32 acr_pck_ctrl_reg = HDMI_INP(0x0024); |
| 2388 | |
| 2389 | if (enabled) { |
| 2390 | const struct hdmi_disp_mode_timing_type *timing = |
| 2391 | hdmi_common_get_supported_mode(video_format); |
| 2392 | const struct hdmi_msm_audio_arcs *audio_arc = |
| 2393 | &hdmi_msm_audio_acr_lut[0]; |
| 2394 | const int lut_size = sizeof(hdmi_msm_audio_acr_lut) |
| 2395 | /sizeof(*hdmi_msm_audio_acr_lut); |
| 2396 | uint32 i, n, cts, layout, multiplier, aud_pck_ctrl_2_reg; |
| 2397 | |
| 2398 | if (timing == NULL) { |
| 2399 | DEV_WARN("%s: video format %d not supported\n", |
| 2400 | __func__, video_format); |
| 2401 | return; |
| 2402 | } |
| 2403 | |
| 2404 | for (i = 0; i < lut_size; |
| 2405 | audio_arc = &hdmi_msm_audio_acr_lut[++i]) { |
| 2406 | if (audio_arc->pclk == timing->pixel_freq) |
| 2407 | break; |
| 2408 | } |
| 2409 | if (i >= lut_size) { |
| 2410 | DEV_WARN("%s: pixel clock %d not supported\n", __func__, |
| 2411 | timing->pixel_freq); |
| 2412 | return; |
| 2413 | } |
| 2414 | |
| 2415 | n = audio_arc->lut[audio_sample_rate].n; |
| 2416 | cts = audio_arc->lut[audio_sample_rate].cts; |
| 2417 | layout = (MSM_HDMI_AUDIO_CHANNEL_2 == num_of_channels) ? 0 : 1; |
| 2418 | |
| 2419 | if ((MSM_HDMI_SAMPLE_RATE_192KHZ == audio_sample_rate) || |
| 2420 | (MSM_HDMI_SAMPLE_RATE_176_4KHZ == audio_sample_rate)) { |
| 2421 | multiplier = 4; |
| 2422 | n >>= 2; /* divide N by 4 and use multiplier */ |
| 2423 | } else if ((MSM_HDMI_SAMPLE_RATE_96KHZ == audio_sample_rate) || |
| 2424 | (MSM_HDMI_SAMPLE_RATE_88_2KHZ == audio_sample_rate)) { |
| 2425 | multiplier = 2; |
| 2426 | n >>= 1; /* divide N by 2 and use multiplier */ |
| 2427 | } else { |
| 2428 | multiplier = 1; |
| 2429 | } |
| 2430 | DEV_DBG("%s: n=%u, cts=%u, layout=%u\n", __func__, n, cts, |
| 2431 | layout); |
| 2432 | |
| 2433 | /* AUDIO_PRIORITY | SOURCE */ |
| 2434 | acr_pck_ctrl_reg |= 0x80000100; |
| 2435 | /* N_MULTIPLE(multiplier) */ |
| 2436 | acr_pck_ctrl_reg |= (multiplier & 7) << 16; |
| 2437 | |
| 2438 | if ((MSM_HDMI_SAMPLE_RATE_48KHZ == audio_sample_rate) || |
| 2439 | (MSM_HDMI_SAMPLE_RATE_96KHZ == audio_sample_rate) || |
| 2440 | (MSM_HDMI_SAMPLE_RATE_192KHZ == audio_sample_rate)) { |
| 2441 | /* SELECT(3) */ |
| 2442 | acr_pck_ctrl_reg |= 3 << 4; |
| 2443 | /* CTS_48 */ |
| 2444 | cts <<= 12; |
| 2445 | |
| 2446 | /* CTS: need to determine how many fractional bits */ |
| 2447 | /* HDMI_ACR_48_0 */ |
| 2448 | HDMI_OUTP(0x00D4, cts); |
| 2449 | /* N */ |
| 2450 | /* HDMI_ACR_48_1 */ |
| 2451 | HDMI_OUTP(0x00D8, n); |
| 2452 | } else if ((MSM_HDMI_SAMPLE_RATE_44_1KHZ == audio_sample_rate) |
| 2453 | || (MSM_HDMI_SAMPLE_RATE_88_2KHZ == |
| 2454 | audio_sample_rate) |
| 2455 | || (MSM_HDMI_SAMPLE_RATE_176_4KHZ == |
| 2456 | audio_sample_rate)) { |
| 2457 | /* SELECT(2) */ |
| 2458 | acr_pck_ctrl_reg |= 2 << 4; |
| 2459 | /* CTS_44 */ |
| 2460 | cts <<= 12; |
| 2461 | |
| 2462 | /* CTS: need to determine how many fractional bits */ |
| 2463 | /* HDMI_ACR_44_0 */ |
| 2464 | HDMI_OUTP(0x00CC, cts); |
| 2465 | /* N */ |
| 2466 | /* HDMI_ACR_44_1 */ |
| 2467 | HDMI_OUTP(0x00D0, n); |
| 2468 | } else { /* default to 32k */ |
| 2469 | /* SELECT(1) */ |
| 2470 | acr_pck_ctrl_reg |= 1 << 4; |
| 2471 | /* CTS_32 */ |
| 2472 | cts <<= 12; |
| 2473 | |
| 2474 | /* CTS: need to determine how many fractional bits */ |
| 2475 | /* HDMI_ACR_32_0 */ |
| 2476 | HDMI_OUTP(0x00C4, cts); |
| 2477 | /* N */ |
| 2478 | /* HDMI_ACR_32_1 */ |
| 2479 | HDMI_OUTP(0x00C8, n); |
| 2480 | } |
| 2481 | /* Payload layout depends on number of audio channels */ |
| 2482 | /* LAYOUT_SEL(layout) */ |
| 2483 | aud_pck_ctrl_2_reg = 1 | (layout << 1); |
| 2484 | /* override | layout */ |
| 2485 | /* HDMI_AUDIO_PKT_CTRL2[0x00044] */ |
| 2486 | HDMI_OUTP(0x00044, aud_pck_ctrl_2_reg); |
| 2487 | |
| 2488 | /* SEND | CONT */ |
| 2489 | acr_pck_ctrl_reg |= 0x00000003; |
| 2490 | } else { |
| 2491 | /* ~(SEND | CONT) */ |
| 2492 | acr_pck_ctrl_reg &= ~0x00000003; |
| 2493 | } |
| 2494 | /* HDMI_ACR_PKT_CTRL[0x0024] */ |
| 2495 | HDMI_OUTP(0x0024, acr_pck_ctrl_reg); |
| 2496 | } |
| 2497 | |
| 2498 | static void hdmi_msm_outpdw_chk(uint32 offset, uint32 data) |
| 2499 | { |
| 2500 | uint32 check, i = 0; |
| 2501 | |
| 2502 | #ifdef DEBUG |
| 2503 | HDMI_OUTP(offset, data); |
| 2504 | #endif |
| 2505 | do { |
| 2506 | outpdw(MSM_HDMI_BASE+offset, data); |
| 2507 | check = inpdw(MSM_HDMI_BASE+offset); |
| 2508 | } while (check != data && i++ < 10); |
| 2509 | |
| 2510 | if (check != data) |
| 2511 | DEV_ERR("%s: failed addr=%08x, data=%x, check=%x", |
| 2512 | __func__, offset, data, check); |
| 2513 | } |
| 2514 | |
| 2515 | static void hdmi_msm_rmw32or(uint32 offset, uint32 data) |
| 2516 | { |
| 2517 | uint32 reg_data; |
| 2518 | reg_data = inpdw(MSM_HDMI_BASE+offset); |
| 2519 | reg_data = inpdw(MSM_HDMI_BASE+offset); |
| 2520 | hdmi_msm_outpdw_chk(offset, reg_data | data); |
| 2521 | } |
| 2522 | |
| 2523 | |
| 2524 | #define HDMI_AUDIO_CFG 0x01D0 |
| 2525 | #define HDMI_AUDIO_ENGINE_ENABLE 1 |
| 2526 | #define HDMI_AUDIO_FIFO_MASK 0x000000F0 |
| 2527 | #define HDMI_AUDIO_FIFO_WATERMARK_SHIFT 4 |
| 2528 | #define HDMI_AUDIO_FIFO_MAX_WATER_MARK 8 |
| 2529 | |
| 2530 | |
| 2531 | int hdmi_audio_enable(bool on , u32 fifo_water_mark) |
| 2532 | { |
| 2533 | u32 hdmi_audio_config; |
| 2534 | |
| 2535 | hdmi_audio_config = HDMI_INP(HDMI_AUDIO_CFG); |
| 2536 | |
| 2537 | if (on) { |
| 2538 | |
| 2539 | if (fifo_water_mark > HDMI_AUDIO_FIFO_MAX_WATER_MARK) { |
| 2540 | pr_err("%s : HDMI audio fifo water mark can not be more" |
| 2541 | " than %u\n", __func__, |
| 2542 | HDMI_AUDIO_FIFO_MAX_WATER_MARK); |
| 2543 | return -EINVAL; |
| 2544 | } |
| 2545 | |
| 2546 | /* |
| 2547 | * Enable HDMI Audio engine. |
| 2548 | * MUST be enabled after Audio DMA is enabled. |
| 2549 | */ |
| 2550 | hdmi_audio_config &= ~(HDMI_AUDIO_FIFO_MASK); |
| 2551 | |
| 2552 | hdmi_audio_config |= (HDMI_AUDIO_ENGINE_ENABLE | |
| 2553 | (fifo_water_mark << HDMI_AUDIO_FIFO_WATERMARK_SHIFT)); |
| 2554 | |
| 2555 | } else |
| 2556 | hdmi_audio_config &= ~(HDMI_AUDIO_ENGINE_ENABLE); |
| 2557 | |
| 2558 | HDMI_OUTP(HDMI_AUDIO_CFG, hdmi_audio_config); |
| 2559 | |
| 2560 | return 0; |
| 2561 | } |
| 2562 | EXPORT_SYMBOL(hdmi_audio_enable); |
| 2563 | |
| 2564 | static void hdmi_msm_audio_info_setup(boolean enabled, int num_of_channels, |
| 2565 | int level_shift, boolean down_mix) |
| 2566 | { |
| 2567 | uint32 channel_allocation = 0; /* Default to FR,FL */ |
| 2568 | uint32 channel_count = 1; /* Default to 2 channels |
| 2569 | -> See Table 17 in CEA-D spec */ |
| 2570 | uint32 check_sum, audio_info_0_reg, audio_info_1_reg; |
| 2571 | uint32 audio_info_ctrl_reg; |
| 2572 | |
| 2573 | /* Please see table 20 Audio InfoFrame in HDMI spec |
| 2574 | FL = front left |
| 2575 | FC = front Center |
| 2576 | FR = front right |
| 2577 | FLC = front left center |
| 2578 | FRC = front right center |
| 2579 | RL = rear left |
| 2580 | RC = rear center |
| 2581 | RR = rear right |
| 2582 | RLC = rear left center |
| 2583 | RRC = rear right center |
| 2584 | LFE = low frequency effect |
| 2585 | */ |
| 2586 | |
| 2587 | /* Read first then write because it is bundled with other controls */ |
| 2588 | /* HDMI_INFOFRAME_CTRL0[0x002C] */ |
| 2589 | audio_info_ctrl_reg = HDMI_INP(0x002C); |
| 2590 | |
| 2591 | if (enabled) { |
| 2592 | switch (num_of_channels) { |
| 2593 | case MSM_HDMI_AUDIO_CHANNEL_2: |
| 2594 | break; |
| 2595 | case MSM_HDMI_AUDIO_CHANNEL_4: |
| 2596 | channel_count = 3; |
| 2597 | /* FC,LFE,FR,FL */ |
| 2598 | channel_allocation = 0x3; |
| 2599 | break; |
| 2600 | case MSM_HDMI_AUDIO_CHANNEL_6: |
| 2601 | channel_count = 5; |
| 2602 | /* RR,RL,FC,LFE,FR,FL */ |
| 2603 | channel_allocation = 0xB; |
| 2604 | break; |
| 2605 | case MSM_HDMI_AUDIO_CHANNEL_8: |
| 2606 | channel_count = 7; |
| 2607 | /* FRC,FLC,RR,RL,FC,LFE,FR,FL */ |
| 2608 | channel_allocation = 0x1f; |
| 2609 | break; |
| 2610 | default: |
| 2611 | break; |
| 2612 | } |
| 2613 | |
| 2614 | /* Program the Channel-Speaker allocation */ |
| 2615 | audio_info_1_reg = 0; |
| 2616 | /* CA(channel_allocation) */ |
| 2617 | audio_info_1_reg |= channel_allocation & 0xff; |
| 2618 | /* Program the Level shifter */ |
| 2619 | /* LSV(level_shift) */ |
| 2620 | audio_info_1_reg |= (level_shift << 11) & 0x00007800; |
| 2621 | /* Program the Down-mix Inhibit Flag */ |
| 2622 | /* DM_INH(down_mix) */ |
| 2623 | audio_info_1_reg |= (down_mix << 15) & 0x00008000; |
| 2624 | |
| 2625 | /* HDMI_AUDIO_INFO1[0x00E8] */ |
| 2626 | HDMI_OUTP(0x00E8, audio_info_1_reg); |
| 2627 | |
| 2628 | /* Calculate CheckSum |
| 2629 | Sum of all the bytes in the Audio Info Packet bytes |
| 2630 | (See table 8.4 in HDMI spec) */ |
| 2631 | check_sum = 0; |
| 2632 | /* HDMI_AUDIO_INFO_FRAME_PACKET_HEADER_TYPE[0x84] */ |
| 2633 | check_sum += 0x84; |
| 2634 | /* HDMI_AUDIO_INFO_FRAME_PACKET_HEADER_VERSION[0x01] */ |
| 2635 | check_sum += 1; |
| 2636 | /* HDMI_AUDIO_INFO_FRAME_PACKET_LENGTH[0x0A] */ |
| 2637 | check_sum += 0x0A; |
| 2638 | check_sum += channel_count; |
| 2639 | check_sum += channel_allocation; |
| 2640 | /* See Table 8.5 in HDMI spec */ |
| 2641 | check_sum += (level_shift & 0xF) << 3 | (down_mix & 0x1) << 7; |
| 2642 | check_sum &= 0xFF; |
| 2643 | check_sum = (uint8) (256 - check_sum); |
| 2644 | |
| 2645 | audio_info_0_reg = 0; |
| 2646 | /* CHECKSUM(check_sum) */ |
| 2647 | audio_info_0_reg |= check_sum & 0xff; |
| 2648 | /* CC(channel_count) */ |
| 2649 | audio_info_0_reg |= (channel_count << 8) & 0x00000700; |
| 2650 | |
| 2651 | /* HDMI_AUDIO_INFO0[0x00E4] */ |
| 2652 | HDMI_OUTP(0x00E4, audio_info_0_reg); |
| 2653 | |
| 2654 | /* Set these flags */ |
| 2655 | /* AUDIO_INFO_UPDATE | AUDIO_INFO_SOURCE | AUDIO_INFO_CONT |
| 2656 | | AUDIO_INFO_SEND */ |
| 2657 | audio_info_ctrl_reg |= 0x000000F0; |
| 2658 | } else { |
| 2659 | /* Clear these flags */ |
| 2660 | /* ~(AUDIO_INFO_UPDATE | AUDIO_INFO_SOURCE | AUDIO_INFO_CONT |
| 2661 | | AUDIO_INFO_SEND) */ |
| 2662 | audio_info_ctrl_reg &= ~0x000000F0; |
| 2663 | } |
| 2664 | /* HDMI_INFOFRAME_CTRL0[0x002C] */ |
| 2665 | HDMI_OUTP(0x002C, audio_info_ctrl_reg); |
| 2666 | } |
| 2667 | |
| 2668 | static void hdmi_msm_audio_ctrl_setup(boolean enabled, int delay) |
| 2669 | { |
| 2670 | uint32 audio_pkt_ctrl_reg = 0; |
| 2671 | |
| 2672 | /* Enable Packet Transmission */ |
| 2673 | audio_pkt_ctrl_reg |= enabled ? 0x00000001 : 0; |
| 2674 | audio_pkt_ctrl_reg |= (delay << 4); |
| 2675 | |
| 2676 | /* HDMI_AUDIO_PKT_CTRL1[0x0020] */ |
| 2677 | HDMI_OUTP(0x0020, audio_pkt_ctrl_reg); |
| 2678 | } |
| 2679 | |
| 2680 | static void hdmi_msm_en_gc_packet(boolean av_mute_is_requested) |
| 2681 | { |
| 2682 | /* HDMI_GC[0x0040] */ |
| 2683 | HDMI_OUTP(0x0040, av_mute_is_requested ? 1 : 0); |
| 2684 | |
| 2685 | /* GC packet enable (every frame) */ |
| 2686 | /* HDMI_VBI_PKT_CTRL[0x0028] */ |
| 2687 | hdmi_msm_rmw32or(0x0028, 3 << 4); |
| 2688 | } |
| 2689 | |
| 2690 | static void hdmi_msm_en_isrc_packet(boolean isrc_is_continued) |
| 2691 | { |
| 2692 | static const char isrc_psuedo_data[] = |
| 2693 | "ISRC1:0123456789isrc2=ABCDEFGHIJ"; |
| 2694 | const uint32 * isrc_data = (const uint32 *) isrc_psuedo_data; |
| 2695 | |
| 2696 | /* ISRC_STATUS =0b010 | ISRC_CONTINUE | ISRC_VALID */ |
| 2697 | /* HDMI_ISRC1_0[0x00048] */ |
| 2698 | HDMI_OUTP(0x00048, 2 | (isrc_is_continued ? 1 : 0) << 6 | 0 << 7); |
| 2699 | |
| 2700 | /* HDMI_ISRC1_1[0x004C] */ |
| 2701 | HDMI_OUTP(0x004C, *isrc_data++); |
| 2702 | /* HDMI_ISRC1_2[0x0050] */ |
| 2703 | HDMI_OUTP(0x0050, *isrc_data++); |
| 2704 | /* HDMI_ISRC1_3[0x0054] */ |
| 2705 | HDMI_OUTP(0x0054, *isrc_data++); |
| 2706 | /* HDMI_ISRC1_4[0x0058] */ |
| 2707 | HDMI_OUTP(0x0058, *isrc_data++); |
| 2708 | |
| 2709 | /* HDMI_ISRC2_0[0x005C] */ |
| 2710 | HDMI_OUTP(0x005C, *isrc_data++); |
| 2711 | /* HDMI_ISRC2_1[0x0060] */ |
| 2712 | HDMI_OUTP(0x0060, *isrc_data++); |
| 2713 | /* HDMI_ISRC2_2[0x0064] */ |
| 2714 | HDMI_OUTP(0x0064, *isrc_data++); |
| 2715 | /* HDMI_ISRC2_3[0x0068] */ |
| 2716 | HDMI_OUTP(0x0068, *isrc_data); |
| 2717 | |
| 2718 | /* HDMI_VBI_PKT_CTRL[0x0028] */ |
| 2719 | /* ISRC Send + Continuous */ |
| 2720 | hdmi_msm_rmw32or(0x0028, 3 << 8); |
| 2721 | } |
| 2722 | |
| 2723 | static void hdmi_msm_en_acp_packet(uint32 byte1) |
| 2724 | { |
| 2725 | /* HDMI_ACP[0x003C] */ |
| 2726 | HDMI_OUTP(0x003C, 2 | 1 << 8 | byte1 << 16); |
| 2727 | |
| 2728 | /* HDMI_VBI_PKT_CTRL[0x0028] */ |
| 2729 | /* ACP send, s/w source */ |
| 2730 | hdmi_msm_rmw32or(0x0028, 3 << 12); |
| 2731 | } |
| 2732 | |
| 2733 | static void hdmi_msm_audio_setup(void) |
| 2734 | { |
| 2735 | const int channels = MSM_HDMI_AUDIO_CHANNEL_2; |
| 2736 | |
| 2737 | /* (0) for clr_avmute, (1) for set_avmute */ |
| 2738 | hdmi_msm_en_gc_packet(0); |
| 2739 | /* (0) for isrc1 only, (1) for isrc1 and isrc2 */ |
| 2740 | hdmi_msm_en_isrc_packet(1); |
| 2741 | /* arbitrary bit pattern for byte1 */ |
| 2742 | hdmi_msm_en_acp_packet(0x5a); |
| 2743 | |
| 2744 | hdmi_msm_audio_acr_setup(TRUE, |
| 2745 | external_common_state->video_resolution, |
| 2746 | MSM_HDMI_SAMPLE_RATE_48KHZ, channels); |
| 2747 | hdmi_msm_audio_info_setup(TRUE, channels, 0, FALSE); |
| 2748 | hdmi_msm_audio_ctrl_setup(TRUE, 1); |
| 2749 | |
| 2750 | /* Turn on Audio FIFO and SAM DROP ISR */ |
| 2751 | HDMI_OUTP(0x02CC, HDMI_INP(0x02CC) | BIT(1) | BIT(3)); |
| 2752 | DEV_INFO("HDMI Audio: Enabled\n"); |
| 2753 | } |
| 2754 | |
| 2755 | static int hdmi_msm_audio_off(void) |
| 2756 | { |
| 2757 | uint32 audio_pkt_ctrl, audio_cfg; |
| 2758 | /* Number of wait iterations */ |
| 2759 | int i = 10; |
| 2760 | audio_pkt_ctrl = HDMI_INP_ND(0x0020); |
| 2761 | audio_cfg = HDMI_INP_ND(0x01D0); |
| 2762 | |
| 2763 | /* Checking BIT[0] of AUDIO PACKET CONTROL and */ |
| 2764 | /* AUDIO CONFIGURATION register */ |
| 2765 | while (((audio_pkt_ctrl & 0x00000001) || (audio_cfg & 0x00000001)) |
| 2766 | && (i--)) { |
| 2767 | audio_pkt_ctrl = HDMI_INP_ND(0x0020); |
| 2768 | audio_cfg = HDMI_INP_ND(0x01D0); |
| 2769 | DEV_DBG("%d times :: HDMI AUDIO PACKET is %08x and " |
| 2770 | "AUDIO CFG is %08x", i, audio_pkt_ctrl, audio_cfg); |
| 2771 | msleep(100); |
| 2772 | if (!i) { |
| 2773 | DEV_ERR("%s:failed to set BIT[0] AUDIO PACKET" |
| 2774 | "CONTROL or AUDIO CONFIGURATION REGISTER\n", |
| 2775 | __func__); |
| 2776 | return -ETIMEDOUT; |
| 2777 | } |
| 2778 | } |
| 2779 | hdmi_msm_audio_info_setup(FALSE, 0, 0, FALSE); |
| 2780 | hdmi_msm_audio_ctrl_setup(FALSE, 0); |
| 2781 | hdmi_msm_audio_acr_setup(FALSE, 0, 0, 0); |
| 2782 | DEV_INFO("HDMI Audio: Disabled\n"); |
| 2783 | return 0; |
| 2784 | } |
| 2785 | |
| 2786 | |
| 2787 | #ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT |
| Manoj Rao | bbf9a47 | 2011-06-14 21:05:18 -0700 | [diff] [blame^] | 2788 | static uint8 hdmi_msm_avi_iframe_lut[][15] = { |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2789 | /* 480p60 480i60 576p50 576i50 720p60 720p50 1080p60 1080i60 1080p50 |
| Manoj Rao | bbf9a47 | 2011-06-14 21:05:18 -0700 | [diff] [blame^] | 2790 | 1080i50 1080p24 1080p30 1080p25 640x480p 480p60_16_9*/ |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2791 | {0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, |
| Manoj Rao | bbf9a47 | 2011-06-14 21:05:18 -0700 | [diff] [blame^] | 2792 | 0x10, 0x10, 0x10, 0x10, 0x10, 0x10}, /*00*/ |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2793 | {0x18, 0x18, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, |
| Manoj Rao | bbf9a47 | 2011-06-14 21:05:18 -0700 | [diff] [blame^] | 2794 | 0x28, 0x28, 0x28, 0x28, 0x18, 0x28}, /*01*/ |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2795 | {0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, |
| Manoj Rao | bbf9a47 | 2011-06-14 21:05:18 -0700 | [diff] [blame^] | 2796 | 0x04, 0x04, 0x04, 0x04, 0x88, 0x04}, /*02*/ |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2797 | {0x02, 0x06, 0x11, 0x15, 0x04, 0x13, 0x10, 0x05, 0x1F, |
| Manoj Rao | bbf9a47 | 2011-06-14 21:05:18 -0700 | [diff] [blame^] | 2798 | 0x14, 0x20, 0x22, 0x21, 0x01, 0x03}, /*03*/ |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2799 | {0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, |
| Manoj Rao | bbf9a47 | 2011-06-14 21:05:18 -0700 | [diff] [blame^] | 2800 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*04*/ |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2801 | {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| Manoj Rao | bbf9a47 | 2011-06-14 21:05:18 -0700 | [diff] [blame^] | 2802 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*05*/ |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2803 | {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| Manoj Rao | bbf9a47 | 2011-06-14 21:05:18 -0700 | [diff] [blame^] | 2804 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*06*/ |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2805 | {0xE1, 0xE1, 0x41, 0x41, 0xD1, 0xd1, 0x39, 0x39, 0x39, |
| Manoj Rao | bbf9a47 | 2011-06-14 21:05:18 -0700 | [diff] [blame^] | 2806 | 0x39, 0x39, 0x39, 0x39, 0xe1, 0xE1}, /*07*/ |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2807 | {0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x04, 0x04, 0x04, |
| Manoj Rao | bbf9a47 | 2011-06-14 21:05:18 -0700 | [diff] [blame^] | 2808 | 0x04, 0x04, 0x04, 0x04, 0x01, 0x01}, /*08*/ |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2809 | {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| Manoj Rao | bbf9a47 | 2011-06-14 21:05:18 -0700 | [diff] [blame^] | 2810 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*09*/ |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2811 | {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, |
| Manoj Rao | bbf9a47 | 2011-06-14 21:05:18 -0700 | [diff] [blame^] | 2812 | 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*10*/ |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2813 | {0xD1, 0xD1, 0xD1, 0xD1, 0x01, 0x01, 0x81, 0x81, 0x81, |
| Manoj Rao | bbf9a47 | 2011-06-14 21:05:18 -0700 | [diff] [blame^] | 2814 | 0x81, 0x81, 0x81, 0x81, 0x81, 0xD1}, /*11*/ |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2815 | {0x02, 0x02, 0x02, 0x02, 0x05, 0x05, 0x07, 0x07, 0x07, |
| Manoj Rao | bbf9a47 | 2011-06-14 21:05:18 -0700 | [diff] [blame^] | 2816 | 0x07, 0x07, 0x07, 0x07, 0x02, 0x02} /*12*/ |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2817 | }; |
| 2818 | |
| 2819 | static void hdmi_msm_avi_info_frame(void) |
| 2820 | { |
| 2821 | /* two header + length + 13 data */ |
| 2822 | uint8 aviInfoFrame[16]; |
| 2823 | uint8 checksum; |
| 2824 | uint32 sum; |
| 2825 | uint32 regVal; |
| 2826 | int i; |
| 2827 | int mode = 0; |
| 2828 | |
| 2829 | switch (external_common_state->video_resolution) { |
| Manoj Rao | bbf9a47 | 2011-06-14 21:05:18 -0700 | [diff] [blame^] | 2830 | case HDMI_VFRMT_720x480p60_4_3: |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2831 | mode = 0; |
| 2832 | break; |
| 2833 | case HDMI_VFRMT_720x480i60_16_9: |
| 2834 | mode = 1; |
| 2835 | break; |
| 2836 | case HDMI_VFRMT_720x576p50_16_9: |
| 2837 | mode = 2; |
| 2838 | break; |
| 2839 | case HDMI_VFRMT_720x576i50_16_9: |
| 2840 | mode = 3; |
| 2841 | break; |
| 2842 | case HDMI_VFRMT_1280x720p60_16_9: |
| 2843 | mode = 4; |
| 2844 | break; |
| 2845 | case HDMI_VFRMT_1280x720p50_16_9: |
| 2846 | mode = 5; |
| 2847 | break; |
| 2848 | case HDMI_VFRMT_1920x1080p60_16_9: |
| 2849 | mode = 6; |
| 2850 | break; |
| 2851 | case HDMI_VFRMT_1920x1080i60_16_9: |
| 2852 | mode = 7; |
| 2853 | break; |
| 2854 | case HDMI_VFRMT_1920x1080p50_16_9: |
| 2855 | mode = 8; |
| 2856 | break; |
| 2857 | case HDMI_VFRMT_1920x1080i50_16_9: |
| 2858 | mode = 9; |
| 2859 | break; |
| 2860 | case HDMI_VFRMT_1920x1080p24_16_9: |
| 2861 | mode = 10; |
| 2862 | break; |
| 2863 | case HDMI_VFRMT_1920x1080p30_16_9: |
| 2864 | mode = 11; |
| 2865 | break; |
| 2866 | case HDMI_VFRMT_1920x1080p25_16_9: |
| 2867 | mode = 12; |
| 2868 | break; |
| 2869 | case HDMI_VFRMT_640x480p60_4_3: |
| 2870 | mode = 13; |
| 2871 | break; |
| Manoj Rao | bbf9a47 | 2011-06-14 21:05:18 -0700 | [diff] [blame^] | 2872 | case HDMI_VFRMT_720x480p60_16_9: |
| 2873 | mode = 14; |
| 2874 | break; |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 2875 | default: |
| 2876 | DEV_INFO("%s: mode %d not supported\n", __func__, |
| 2877 | external_common_state->video_resolution); |
| 2878 | return; |
| 2879 | } |
| 2880 | |
| 2881 | /* InfoFrame Type = 82 */ |
| 2882 | aviInfoFrame[0] = 0x82; |
| 2883 | /* Version = 2 */ |
| 2884 | aviInfoFrame[1] = 2; |
| 2885 | /* Length of AVI InfoFrame = 13 */ |
| 2886 | aviInfoFrame[2] = 13; |
| 2887 | |
| 2888 | /* Data Byte 01: 0 Y1 Y0 A0 B1 B0 S1 S0 */ |
| 2889 | aviInfoFrame[3] = hdmi_msm_avi_iframe_lut[0][mode]; |
| 2890 | /* Data Byte 02: C1 C0 M1 M0 R3 R2 R1 R0 */ |
| 2891 | aviInfoFrame[4] = hdmi_msm_avi_iframe_lut[1][mode]; |
| 2892 | /* Data Byte 03: ITC EC2 EC1 EC0 Q1 Q0 SC1 SC0 */ |
| 2893 | aviInfoFrame[5] = hdmi_msm_avi_iframe_lut[2][mode]; |
| 2894 | /* Data Byte 04: 0 VIC6 VIC5 VIC4 VIC3 VIC2 VIC1 VIC0 */ |
| 2895 | aviInfoFrame[6] = hdmi_msm_avi_iframe_lut[3][mode]; |
| 2896 | /* Data Byte 05: 0 0 0 0 PR3 PR2 PR1 PR0 */ |
| 2897 | aviInfoFrame[7] = hdmi_msm_avi_iframe_lut[4][mode]; |
| 2898 | /* Data Byte 06: LSB Line No of End of Top Bar */ |
| 2899 | aviInfoFrame[8] = hdmi_msm_avi_iframe_lut[5][mode]; |
| 2900 | /* Data Byte 07: MSB Line No of End of Top Bar */ |
| 2901 | aviInfoFrame[9] = hdmi_msm_avi_iframe_lut[6][mode]; |
| 2902 | /* Data Byte 08: LSB Line No of Start of Bottom Bar */ |
| 2903 | aviInfoFrame[10] = hdmi_msm_avi_iframe_lut[7][mode]; |
| 2904 | /* Data Byte 09: MSB Line No of Start of Bottom Bar */ |
| 2905 | aviInfoFrame[11] = hdmi_msm_avi_iframe_lut[8][mode]; |
| 2906 | /* Data Byte 10: LSB Pixel Number of End of Left Bar */ |
| 2907 | aviInfoFrame[12] = hdmi_msm_avi_iframe_lut[9][mode]; |
| 2908 | /* Data Byte 11: MSB Pixel Number of End of Left Bar */ |
| 2909 | aviInfoFrame[13] = hdmi_msm_avi_iframe_lut[10][mode]; |
| 2910 | /* Data Byte 12: LSB Pixel Number of Start of Right Bar */ |
| 2911 | aviInfoFrame[14] = hdmi_msm_avi_iframe_lut[11][mode]; |
| 2912 | /* Data Byte 13: MSB Pixel Number of Start of Right Bar */ |
| 2913 | aviInfoFrame[15] = hdmi_msm_avi_iframe_lut[12][mode]; |
| 2914 | |
| 2915 | sum = 0; |
| 2916 | for (i = 0; i < 16; i++) |
| 2917 | sum += aviInfoFrame[i]; |
| 2918 | sum &= 0xFF; |
| 2919 | sum = 256 - sum; |
| 2920 | checksum = (uint8) sum; |
| 2921 | |
| 2922 | regVal = aviInfoFrame[5]; |
| 2923 | regVal = regVal << 8 | aviInfoFrame[4]; |
| 2924 | regVal = regVal << 8 | aviInfoFrame[3]; |
| 2925 | regVal = regVal << 8 | checksum; |
| 2926 | HDMI_OUTP(0x006C, regVal); |
| 2927 | |
| 2928 | regVal = aviInfoFrame[9]; |
| 2929 | regVal = regVal << 8 | aviInfoFrame[8]; |
| 2930 | regVal = regVal << 8 | aviInfoFrame[7]; |
| 2931 | regVal = regVal << 8 | aviInfoFrame[6]; |
| 2932 | HDMI_OUTP(0x0070, regVal); |
| 2933 | |
| 2934 | regVal = aviInfoFrame[13]; |
| 2935 | regVal = regVal << 8 | aviInfoFrame[12]; |
| 2936 | regVal = regVal << 8 | aviInfoFrame[11]; |
| 2937 | regVal = regVal << 8 | aviInfoFrame[10]; |
| 2938 | HDMI_OUTP(0x0074, regVal); |
| 2939 | |
| 2940 | regVal = aviInfoFrame[1]; |
| 2941 | regVal = regVal << 16 | aviInfoFrame[15]; |
| 2942 | regVal = regVal << 8 | aviInfoFrame[14]; |
| 2943 | HDMI_OUTP(0x0078, regVal); |
| 2944 | |
| 2945 | /* INFOFRAME_CTRL0[0x002C] */ |
| 2946 | /* 0x3 for AVI InfFrame enable (every frame) */ |
| 2947 | HDMI_OUTP(0x002C, HDMI_INP(0x002C) | 0x00000003L); |
| 2948 | } |
| 2949 | #endif |
| 2950 | |
| 2951 | #ifdef CONFIG_FB_MSM_HDMI_3D |
| 2952 | static void hdmi_msm_vendor_infoframe_packetsetup(void) |
| 2953 | { |
| 2954 | uint32 packet_header = 0; |
| 2955 | uint32 check_sum = 0; |
| 2956 | uint32 packet_payload = 0; |
| 2957 | |
| 2958 | if (!external_common_state->format_3d) { |
| 2959 | HDMI_OUTP(0x0034, 0); |
| 2960 | return; |
| 2961 | } |
| 2962 | |
| 2963 | /* 0x0084 GENERIC0_HDR |
| 2964 | * HB0 7:0 NUM |
| 2965 | * HB1 15:8 NUM |
| 2966 | * HB2 23:16 NUM */ |
| 2967 | /* Setup Packet header and payload */ |
| 2968 | /* 0x81 VS_INFO_FRAME_ID |
| 2969 | 0x01 VS_INFO_FRAME_VERSION |
| 2970 | 0x1B VS_INFO_FRAME_PAYLOAD_LENGTH */ |
| 2971 | packet_header = 0x81 | (0x01 << 8) | (0x1B << 16); |
| 2972 | HDMI_OUTP(0x0084, packet_header); |
| 2973 | |
| 2974 | check_sum = packet_header & 0xff; |
| 2975 | check_sum += (packet_header >> 8) & 0xff; |
| 2976 | check_sum += (packet_header >> 16) & 0xff; |
| 2977 | |
| 2978 | /* 0x008C GENERIC0_1 |
| 2979 | * BYTE4 7:0 NUM |
| 2980 | * BYTE5 15:8 NUM |
| 2981 | * BYTE6 23:16 NUM |
| 2982 | * BYTE7 31:24 NUM */ |
| 2983 | /* 0x02 VS_INFO_FRAME_3D_PRESENT */ |
| 2984 | packet_payload = 0x02 << 5; |
| 2985 | switch (external_common_state->format_3d) { |
| 2986 | case 1: |
| 2987 | /* 0b1000 VIDEO_3D_FORMAT_SIDE_BY_SIDE_HALF */ |
| 2988 | packet_payload |= (0x08 << 8) << 4; |
| 2989 | break; |
| 2990 | case 2: |
| 2991 | /* 0b0110 VIDEO_3D_FORMAT_TOP_AND_BOTTOM_HALF */ |
| 2992 | packet_payload |= (0x06 << 8) << 4; |
| 2993 | break; |
| 2994 | } |
| 2995 | HDMI_OUTP(0x008C, packet_payload); |
| 2996 | |
| 2997 | check_sum += packet_payload & 0xff; |
| 2998 | check_sum += (packet_payload >> 8) & 0xff; |
| 2999 | |
| 3000 | #define IEEE_REGISTRATION_ID 0xC03 |
| 3001 | /* Next 3 bytes are IEEE Registration Identifcation */ |
| 3002 | /* 0x0088 GENERIC0_0 |
| 3003 | * BYTE0 7:0 NUM (checksum) |
| 3004 | * BYTE1 15:8 NUM |
| 3005 | * BYTE2 23:16 NUM |
| 3006 | * BYTE3 31:24 NUM */ |
| 3007 | check_sum += IEEE_REGISTRATION_ID & 0xff; |
| 3008 | check_sum += (IEEE_REGISTRATION_ID >> 8) & 0xff; |
| 3009 | check_sum += (IEEE_REGISTRATION_ID >> 16) & 0xff; |
| 3010 | |
| 3011 | HDMI_OUTP(0x0088, (0x100 - (0xff & check_sum)) |
| 3012 | | ((IEEE_REGISTRATION_ID & 0xff) << 8) |
| 3013 | | (((IEEE_REGISTRATION_ID >> 8) & 0xff) << 16) |
| 3014 | | (((IEEE_REGISTRATION_ID >> 16) & 0xff) << 24)); |
| 3015 | |
| 3016 | /* 0x0034 GEN_PKT_CTRL |
| 3017 | * GENERIC0_SEND 0 0 = Disable Generic0 Packet Transmission |
| 3018 | * 1 = Enable Generic0 Packet Transmission |
| 3019 | * GENERIC0_CONT 1 0 = Send Generic0 Packet on next frame only |
| 3020 | * 1 = Send Generic0 Packet on every frame |
| 3021 | * GENERIC0_UPDATE 2 NUM |
| 3022 | * GENERIC1_SEND 4 0 = Disable Generic1 Packet Transmission |
| 3023 | * 1 = Enable Generic1 Packet Transmission |
| 3024 | * GENERIC1_CONT 5 0 = Send Generic1 Packet on next frame only |
| 3025 | * 1 = Send Generic1 Packet on every frame |
| 3026 | * GENERIC0_LINE 21:16 NUM |
| 3027 | * GENERIC1_LINE 29:24 NUM |
| 3028 | */ |
| 3029 | /* GENERIC0_LINE | GENERIC0_UPDATE | GENERIC0_CONT | GENERIC0_SEND |
| 3030 | * Setup HDMI TX generic packet control |
| 3031 | * Enable this packet to transmit every frame |
| 3032 | * Enable this packet to transmit every frame |
| 3033 | * Enable HDMI TX engine to transmit Generic packet 0 */ |
| 3034 | HDMI_OUTP(0x0034, (1 << 16) | (1 << 2) | BIT(1) | BIT(0)); |
| 3035 | } |
| 3036 | |
| 3037 | static void hdmi_msm_switch_3d(boolean on) |
| 3038 | { |
| 3039 | mutex_lock(&external_common_state_hpd_mutex); |
| 3040 | if (external_common_state->hpd_state) |
| 3041 | hdmi_msm_vendor_infoframe_packetsetup(); |
| 3042 | mutex_unlock(&external_common_state_hpd_mutex); |
| 3043 | } |
| 3044 | #endif |
| 3045 | |
| Ravishangar Kalyanam | 49a83b2 | 2011-07-20 15:28:44 -0700 | [diff] [blame] | 3046 | int hdmi_msm_clk(int on) |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3047 | { |
| 3048 | int rc; |
| 3049 | |
| 3050 | DEV_DBG("HDMI Clk: %s\n", on ? "Enable" : "Disable"); |
| 3051 | if (on) { |
| 3052 | rc = clk_enable(hdmi_msm_state->hdmi_app_clk); |
| 3053 | if (rc) { |
| 3054 | DEV_ERR("'hdmi_app_clk' clock enable failed, rc=%d\n", |
| 3055 | rc); |
| 3056 | return rc; |
| 3057 | } |
| 3058 | |
| 3059 | rc = clk_enable(hdmi_msm_state->hdmi_m_pclk); |
| 3060 | if (rc) { |
| 3061 | DEV_ERR("'hdmi_m_pclk' clock enable failed, rc=%d\n", |
| 3062 | rc); |
| 3063 | return rc; |
| 3064 | } |
| 3065 | |
| 3066 | rc = clk_enable(hdmi_msm_state->hdmi_s_pclk); |
| 3067 | if (rc) { |
| 3068 | DEV_ERR("'hdmi_s_pclk' clock enable failed, rc=%d\n", |
| 3069 | rc); |
| 3070 | return rc; |
| 3071 | } |
| 3072 | } else { |
| 3073 | clk_disable(hdmi_msm_state->hdmi_app_clk); |
| 3074 | clk_disable(hdmi_msm_state->hdmi_m_pclk); |
| 3075 | clk_disable(hdmi_msm_state->hdmi_s_pclk); |
| 3076 | } |
| 3077 | |
| 3078 | return 0; |
| 3079 | } |
| 3080 | |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3081 | static void hdmi_msm_turn_on(void) |
| 3082 | { |
| 3083 | uint32 hpd_ctrl; |
| 3084 | |
| 3085 | hdmi_msm_reset_core(); |
| 3086 | hdmi_msm_init_phy(external_common_state->video_resolution); |
| 3087 | /* HDMI_USEC_REFTIMER[0x0208] */ |
| 3088 | HDMI_OUTP(0x0208, 0x0001001B); |
| 3089 | |
| 3090 | hdmi_msm_video_setup(external_common_state->video_resolution); |
| 3091 | if (!hdmi_msm_is_dvi_mode()) |
| 3092 | hdmi_msm_audio_setup(); |
| 3093 | #ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT |
| 3094 | hdmi_msm_avi_info_frame(); |
| 3095 | #endif /* CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT */ |
| 3096 | #ifdef CONFIG_FB_MSM_HDMI_3D |
| 3097 | hdmi_msm_vendor_infoframe_packetsetup(); |
| 3098 | #endif |
| 3099 | |
| 3100 | /* set timeout to 4.1ms (max) for hardware debounce */ |
| 3101 | hpd_ctrl = (HDMI_INP(0x0258) & ~0xFFF) | 0xFFF; |
| 3102 | |
| 3103 | /* Toggle HPD circuit to trigger HPD sense */ |
| 3104 | HDMI_OUTP(0x0258, ~(1 << 28) & hpd_ctrl); |
| 3105 | HDMI_OUTP(0x0258, (1 << 28) | hpd_ctrl); |
| 3106 | |
| 3107 | hdmi_msm_set_mode(TRUE); |
| 3108 | |
| 3109 | /* Setup HPD IRQ */ |
| 3110 | HDMI_OUTP(0x0254, 4 | (external_common_state->hpd_state ? 0 : 2)); |
| 3111 | |
| 3112 | #ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT |
| 3113 | if (hdmi_msm_state->reauth) { |
| 3114 | hdmi_msm_hdcp_enable(); |
| 3115 | hdmi_msm_state->reauth = FALSE ; |
| 3116 | } |
| 3117 | #endif /* CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT */ |
| 3118 | DEV_INFO("HDMI Core: Initialized\n"); |
| 3119 | } |
| 3120 | |
| 3121 | static void hdmi_msm_hpd_state_timer(unsigned long data) |
| 3122 | { |
| 3123 | queue_work(hdmi_work_queue, &hdmi_msm_state->hpd_state_work); |
| 3124 | } |
| 3125 | |
| 3126 | #ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT |
| 3127 | static void hdmi_msm_hdcp_timer(unsigned long data) |
| 3128 | { |
| 3129 | queue_work(hdmi_work_queue, &hdmi_msm_state->hdcp_work); |
| 3130 | } |
| 3131 | #endif |
| 3132 | |
| 3133 | static void hdmi_msm_hpd_read_work(struct work_struct *work) |
| 3134 | { |
| 3135 | uint32 hpd_ctrl; |
| 3136 | |
| 3137 | clk_enable(hdmi_msm_state->hdmi_app_clk); |
| 3138 | hdmi_msm_state->pd->core_power(1, 1); |
| 3139 | hdmi_msm_state->pd->enable_5v(1); |
| 3140 | hdmi_msm_set_mode(FALSE); |
| 3141 | hdmi_msm_init_phy(external_common_state->video_resolution); |
| 3142 | /* HDMI_USEC_REFTIMER[0x0208] */ |
| 3143 | HDMI_OUTP(0x0208, 0x0001001B); |
| 3144 | hpd_ctrl = (HDMI_INP(0x0258) & ~0xFFF) | 0xFFF; |
| 3145 | |
| 3146 | /* Toggle HPD circuit to trigger HPD sense */ |
| 3147 | HDMI_OUTP(0x0258, ~(1 << 28) & hpd_ctrl); |
| 3148 | HDMI_OUTP(0x0258, (1 << 28) | hpd_ctrl); |
| 3149 | |
| 3150 | hdmi_msm_set_mode(TRUE); |
| 3151 | msleep(1000); |
| 3152 | external_common_state->hpd_state = (HDMI_INP(0x0250) & 0x2) >> 1; |
| 3153 | if (external_common_state->hpd_state) { |
| 3154 | hdmi_msm_read_edid(); |
| 3155 | DEV_DBG("%s: sense CONNECTED: send ONLINE\n", __func__); |
| 3156 | kobject_uevent(external_common_state->uevent_kobj, |
| 3157 | KOBJ_ONLINE); |
| 3158 | } |
| 3159 | hdmi_msm_hpd_off(); |
| 3160 | hdmi_msm_set_mode(FALSE); |
| 3161 | hdmi_msm_state->pd->core_power(0, 1); |
| 3162 | hdmi_msm_state->pd->enable_5v(0); |
| 3163 | clk_disable(hdmi_msm_state->hdmi_app_clk); |
| 3164 | } |
| 3165 | |
| 3166 | static void hdmi_msm_hpd_off(void) |
| 3167 | { |
| 3168 | DEV_DBG("%s: (timer, clk, 5V, core, IRQ off)\n", __func__); |
| 3169 | del_timer(&hdmi_msm_state->hpd_state_timer); |
| 3170 | disable_irq(hdmi_msm_state->irq); |
| 3171 | |
| 3172 | hdmi_msm_set_mode(FALSE); |
| 3173 | HDMI_OUTP_ND(0x0308, 0x7F); /*0b01111111*/ |
| 3174 | hdmi_msm_state->hpd_initialized = FALSE; |
| 3175 | hdmi_msm_state->pd->enable_5v(0); |
| 3176 | hdmi_msm_state->pd->core_power(0, 1); |
| 3177 | hdmi_msm_clk(0); |
| 3178 | hdmi_msm_state->hpd_initialized = FALSE; |
| 3179 | } |
| 3180 | |
| Manoj Rao | 668d6d5 | 2011-08-16 19:12:31 -0700 | [diff] [blame] | 3181 | static void hdmi_msm_dump_regs(const char *prefix) |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3182 | { |
| 3183 | #ifdef REG_DUMP |
| 3184 | print_hex_dump(KERN_INFO, prefix, DUMP_PREFIX_OFFSET, 32, 4, |
| 3185 | (void *)MSM_HDMI_BASE, 0x0334, false); |
| 3186 | #endif |
| 3187 | } |
| 3188 | |
| 3189 | static int hdmi_msm_hpd_on(bool trigger_handler) |
| 3190 | { |
| 3191 | static int phy_reset_done; |
| 3192 | |
| 3193 | hdmi_msm_clk(1); |
| 3194 | hdmi_msm_state->pd->core_power(1, 1); |
| 3195 | hdmi_msm_state->pd->enable_5v(1); |
| 3196 | hdmi_msm_dump_regs("HDMI-INIT: "); |
| 3197 | hdmi_msm_set_mode(FALSE); |
| 3198 | |
| 3199 | if (!phy_reset_done) { |
| 3200 | hdmi_phy_reset(); |
| 3201 | phy_reset_done = 1; |
| 3202 | } |
| 3203 | |
| 3204 | hdmi_msm_init_phy(external_common_state->video_resolution); |
| 3205 | /* HDMI_USEC_REFTIMER[0x0208] */ |
| 3206 | HDMI_OUTP(0x0208, 0x0001001B); |
| 3207 | |
| 3208 | /* Check HPD State */ |
| 3209 | if (!hdmi_msm_state->hpd_initialized) { |
| 3210 | uint32 hpd_ctrl; |
| 3211 | enable_irq(hdmi_msm_state->irq); |
| 3212 | |
| 3213 | /* set timeout to 4.1ms (max) for hardware debounce */ |
| 3214 | hpd_ctrl = (HDMI_INP(0x0258) & ~0xFFF) | 0xFFF; |
| 3215 | |
| 3216 | /* Toggle HPD circuit to trigger HPD sense */ |
| 3217 | HDMI_OUTP(0x0258, ~(1 << 28) & hpd_ctrl); |
| 3218 | HDMI_OUTP(0x0258, (1 << 28) | hpd_ctrl); |
| 3219 | |
| 3220 | DEV_DBG("%s: (clk, 5V, core, IRQ on) <trigger:%s>\n", __func__, |
| 3221 | trigger_handler ? "true" : "false"); |
| 3222 | |
| 3223 | if (trigger_handler) { |
| 3224 | /* Set HPD state machine: ensure at least 2 readouts */ |
| 3225 | mutex_lock(&hdmi_msm_state_mutex); |
| 3226 | hdmi_msm_state->hpd_stable = 0; |
| 3227 | hdmi_msm_state->hpd_prev_state = TRUE; |
| 3228 | mutex_lock(&external_common_state_hpd_mutex); |
| 3229 | external_common_state->hpd_state = FALSE; |
| 3230 | mutex_unlock(&external_common_state_hpd_mutex); |
| 3231 | hdmi_msm_state->hpd_cable_chg_detected = TRUE; |
| 3232 | mutex_unlock(&hdmi_msm_state_mutex); |
| 3233 | mod_timer(&hdmi_msm_state->hpd_state_timer, |
| 3234 | jiffies + HZ/2); |
| 3235 | } |
| 3236 | |
| 3237 | hdmi_msm_state->hpd_initialized = TRUE; |
| 3238 | } |
| 3239 | hdmi_msm_set_mode(TRUE); |
| 3240 | |
| 3241 | return 0; |
| 3242 | } |
| 3243 | |
| 3244 | static int hdmi_msm_power_on(struct platform_device *pdev) |
| 3245 | { |
| 3246 | struct msm_fb_data_type *mfd = platform_get_drvdata(pdev); |
| 3247 | bool changed; |
| 3248 | |
| 3249 | if (!hdmi_msm_state || !hdmi_msm_state->hdmi_app_clk || !MSM_HDMI_BASE) |
| 3250 | return -ENODEV; |
| 3251 | #ifdef CONFIG_SUSPEND |
| 3252 | mutex_lock(&hdmi_msm_state_mutex); |
| 3253 | if (hdmi_msm_state->pm_suspended) { |
| 3254 | mutex_unlock(&hdmi_msm_state_mutex); |
| 3255 | DEV_WARN("%s: ignored, pm_suspended\n", __func__); |
| 3256 | return -ENODEV; |
| 3257 | } |
| 3258 | mutex_unlock(&hdmi_msm_state_mutex); |
| 3259 | #endif |
| 3260 | |
| 3261 | DEV_INFO("power: ON (%dx%d %d)\n", mfd->var_xres, mfd->var_yres, |
| 3262 | mfd->var_pixclock); |
| 3263 | |
| 3264 | #ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT |
| 3265 | mutex_lock(&hdmi_msm_state_mutex); |
| 3266 | if (hdmi_msm_state->hdcp_activating) { |
| 3267 | hdmi_msm_state->panel_power_on = TRUE; |
| 3268 | DEV_INFO("HDCP: activating, returning\n"); |
| 3269 | } |
| 3270 | mutex_unlock(&hdmi_msm_state_mutex); |
| 3271 | #endif /* CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT */ |
| 3272 | |
| 3273 | changed = hdmi_common_get_video_format_from_drv_data(mfd); |
| 3274 | if (!external_common_state->hpd_feature_on) { |
| 3275 | int rc = hdmi_msm_hpd_on(true); |
| 3276 | DEV_INFO("HPD: panel power without 'hpd' feature on\n"); |
| 3277 | if (rc) { |
| 3278 | DEV_WARN("HPD: activation failed: rc=%d\n", rc); |
| 3279 | return rc; |
| 3280 | } |
| 3281 | } |
| 3282 | hdmi_msm_audio_info_setup(TRUE, 0, 0, FALSE); |
| 3283 | |
| 3284 | mutex_lock(&external_common_state_hpd_mutex); |
| 3285 | hdmi_msm_state->panel_power_on = TRUE; |
| 3286 | if ((external_common_state->hpd_state && !hdmi_msm_is_power_on()) |
| 3287 | || changed) { |
| 3288 | mutex_unlock(&external_common_state_hpd_mutex); |
| 3289 | hdmi_msm_turn_on(); |
| 3290 | } else |
| 3291 | mutex_unlock(&external_common_state_hpd_mutex); |
| 3292 | |
| 3293 | hdmi_msm_dump_regs("HDMI-ON: "); |
| 3294 | |
| 3295 | DEV_INFO("power=%s DVI= %s\n", |
| 3296 | hdmi_msm_is_power_on() ? "ON" : "OFF" , |
| 3297 | hdmi_msm_is_dvi_mode() ? "ON" : "OFF"); |
| 3298 | return 0; |
| 3299 | } |
| 3300 | |
| 3301 | /* Note that power-off will also be called when the cable-remove event is |
| 3302 | * processed on the user-space and as a result the framebuffer is powered |
| 3303 | * down. However, we are still required to be able to detect a cable-insert |
| 3304 | * event; so for now leave the HDMI engine running; so that the HPD IRQ is |
| 3305 | * still being processed. |
| 3306 | */ |
| 3307 | static int hdmi_msm_power_off(struct platform_device *pdev) |
| 3308 | { |
| 3309 | if (!hdmi_msm_state->hdmi_app_clk) |
| 3310 | return -ENODEV; |
| 3311 | #ifdef CONFIG_SUSPEND |
| 3312 | mutex_lock(&hdmi_msm_state_mutex); |
| 3313 | if (hdmi_msm_state->pm_suspended) { |
| 3314 | mutex_unlock(&hdmi_msm_state_mutex); |
| 3315 | DEV_WARN("%s: ignored, pm_suspended\n", __func__); |
| 3316 | return -ENODEV; |
| 3317 | } |
| 3318 | mutex_unlock(&hdmi_msm_state_mutex); |
| 3319 | #endif |
| 3320 | |
| 3321 | #ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT |
| 3322 | mutex_lock(&hdmi_msm_state_mutex); |
| 3323 | if (hdmi_msm_state->hdcp_activating) { |
| 3324 | hdmi_msm_state->panel_power_on = FALSE; |
| 3325 | mutex_unlock(&hdmi_msm_state_mutex); |
| 3326 | DEV_INFO("HDCP: activating, returning\n"); |
| 3327 | return 0; |
| 3328 | } |
| 3329 | mutex_unlock(&hdmi_msm_state_mutex); |
| 3330 | #endif /* CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT */ |
| 3331 | |
| 3332 | DEV_INFO("power: OFF (audio off, Reset Core)\n"); |
| 3333 | hdmi_msm_audio_off(); |
| 3334 | #ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT |
| 3335 | hdcp_deauthenticate(); |
| 3336 | #endif |
| 3337 | hdmi_msm_hpd_off(); |
| 3338 | hdmi_msm_powerdown_phy(); |
| 3339 | hdmi_msm_dump_regs("HDMI-OFF: "); |
| 3340 | hdmi_msm_hpd_on(false); |
| 3341 | |
| 3342 | mutex_lock(&external_common_state_hpd_mutex); |
| 3343 | if (!external_common_state->hpd_feature_on) |
| 3344 | hdmi_msm_hpd_off(); |
| 3345 | mutex_unlock(&external_common_state_hpd_mutex); |
| 3346 | |
| 3347 | hdmi_msm_state->panel_power_on = FALSE; |
| 3348 | return 0; |
| 3349 | } |
| 3350 | |
| 3351 | static int __devinit hdmi_msm_probe(struct platform_device *pdev) |
| 3352 | { |
| 3353 | int rc; |
| 3354 | struct platform_device *fb_dev; |
| 3355 | |
| Stepan Moskovchenko | 164fe8a | 2011-08-05 18:10:54 -0700 | [diff] [blame] | 3356 | if (cpu_is_apq8064()) |
| 3357 | return -ENODEV; |
| 3358 | |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3359 | if (!hdmi_msm_state) { |
| 3360 | pr_err("%s: hdmi_msm_state is NULL\n", __func__); |
| 3361 | return -ENOMEM; |
| 3362 | } |
| 3363 | |
| 3364 | external_common_state->dev = &pdev->dev; |
| 3365 | DEV_DBG("probe\n"); |
| 3366 | if (pdev->id == 0) { |
| 3367 | struct resource *res; |
| 3368 | |
| 3369 | #define GET_RES(name, mode) do { \ |
| 3370 | res = platform_get_resource_byname(pdev, mode, name); \ |
| 3371 | if (!res) { \ |
| 3372 | DEV_ERR("'" name "' resource not found\n"); \ |
| 3373 | rc = -ENODEV; \ |
| 3374 | goto error; \ |
| 3375 | } \ |
| 3376 | } while (0) |
| 3377 | |
| 3378 | #define IO_REMAP(var, name) do { \ |
| 3379 | GET_RES(name, IORESOURCE_MEM); \ |
| 3380 | var = ioremap(res->start, resource_size(res)); \ |
| 3381 | if (!var) { \ |
| 3382 | DEV_ERR("'" name "' ioremap failed\n"); \ |
| 3383 | rc = -ENOMEM; \ |
| 3384 | goto error; \ |
| 3385 | } \ |
| 3386 | } while (0) |
| 3387 | |
| 3388 | #define GET_IRQ(var, name) do { \ |
| 3389 | GET_RES(name, IORESOURCE_IRQ); \ |
| 3390 | var = res->start; \ |
| 3391 | } while (0) |
| 3392 | |
| 3393 | IO_REMAP(hdmi_msm_state->qfprom_io, "hdmi_msm_qfprom_addr"); |
| 3394 | hdmi_msm_state->hdmi_io = MSM_HDMI_BASE; |
| 3395 | GET_IRQ(hdmi_msm_state->irq, "hdmi_msm_irq"); |
| 3396 | |
| 3397 | hdmi_msm_state->pd = pdev->dev.platform_data; |
| 3398 | |
| 3399 | #undef GET_RES |
| 3400 | #undef IO_REMAP |
| 3401 | #undef GET_IRQ |
| 3402 | return 0; |
| 3403 | } |
| 3404 | |
| 3405 | hdmi_msm_state->hdmi_app_clk = clk_get(NULL, "hdmi_app_clk"); |
| 3406 | if (IS_ERR(hdmi_msm_state->hdmi_app_clk)) { |
| 3407 | DEV_ERR("'hdmi_app_clk' clk not found\n"); |
| 3408 | rc = IS_ERR(hdmi_msm_state->hdmi_app_clk); |
| 3409 | goto error; |
| 3410 | } |
| 3411 | |
| 3412 | hdmi_msm_state->hdmi_m_pclk = clk_get(NULL, "hdmi_m_pclk"); |
| 3413 | if (IS_ERR(hdmi_msm_state->hdmi_m_pclk)) { |
| 3414 | DEV_ERR("'hdmi_m_pclk' clk not found\n"); |
| 3415 | rc = IS_ERR(hdmi_msm_state->hdmi_m_pclk); |
| 3416 | goto error; |
| 3417 | } |
| 3418 | |
| 3419 | hdmi_msm_state->hdmi_s_pclk = clk_get(NULL, "hdmi_s_pclk"); |
| 3420 | if (IS_ERR(hdmi_msm_state->hdmi_s_pclk)) { |
| 3421 | DEV_ERR("'hdmi_s_pclk' clk not found\n"); |
| 3422 | rc = IS_ERR(hdmi_msm_state->hdmi_s_pclk); |
| 3423 | goto error; |
| 3424 | } |
| 3425 | |
| 3426 | rc = check_hdmi_features(); |
| 3427 | if (rc) { |
| 3428 | DEV_ERR("Init FAILED: check_hdmi_features rc=%d\n", rc); |
| 3429 | goto error; |
| 3430 | } |
| 3431 | |
| 3432 | if (!hdmi_msm_state->pd->core_power) { |
| 3433 | DEV_ERR("Init FAILED: core_power function missing\n"); |
| 3434 | rc = -ENODEV; |
| 3435 | goto error; |
| 3436 | } |
| 3437 | if (!hdmi_msm_state->pd->enable_5v) { |
| 3438 | DEV_ERR("Init FAILED: enable_5v function missing\n"); |
| 3439 | rc = -ENODEV; |
| 3440 | goto error; |
| 3441 | } |
| 3442 | |
| 3443 | rc = request_threaded_irq(hdmi_msm_state->irq, NULL, &hdmi_msm_isr, |
| 3444 | IRQF_TRIGGER_HIGH | IRQF_ONESHOT, "hdmi_msm_isr", NULL); |
| 3445 | if (rc) { |
| 3446 | DEV_ERR("Init FAILED: IRQ request, rc=%d\n", rc); |
| 3447 | goto error; |
| 3448 | } |
| 3449 | disable_irq(hdmi_msm_state->irq); |
| 3450 | |
| 3451 | init_timer(&hdmi_msm_state->hpd_state_timer); |
| 3452 | hdmi_msm_state->hpd_state_timer.function = |
| 3453 | hdmi_msm_hpd_state_timer; |
| 3454 | hdmi_msm_state->hpd_state_timer.data = (uint32)NULL; |
| 3455 | |
| 3456 | hdmi_msm_state->hpd_state_timer.expires = 0xffffffffL; |
| 3457 | add_timer(&hdmi_msm_state->hpd_state_timer); |
| 3458 | |
| 3459 | #ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT |
| 3460 | init_timer(&hdmi_msm_state->hdcp_timer); |
| 3461 | hdmi_msm_state->hdcp_timer.function = |
| 3462 | hdmi_msm_hdcp_timer; |
| 3463 | hdmi_msm_state->hdcp_timer.data = (uint32)NULL; |
| 3464 | |
| 3465 | hdmi_msm_state->hdcp_timer.expires = 0xffffffffL; |
| 3466 | add_timer(&hdmi_msm_state->hdcp_timer); |
| 3467 | #endif /* CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT */ |
| 3468 | |
| 3469 | fb_dev = msm_fb_add_device(pdev); |
| 3470 | if (fb_dev) { |
| 3471 | rc = external_common_state_create(fb_dev); |
| 3472 | if (rc) { |
| 3473 | DEV_ERR("Init FAILED: hdmi_msm_state_create, rc=%d\n", |
| 3474 | rc); |
| 3475 | goto error; |
| 3476 | } |
| 3477 | } else |
| 3478 | DEV_ERR("Init FAILED: failed to add fb device\n"); |
| 3479 | |
| 3480 | DEV_INFO("HDMI HPD: ON\n"); |
| 3481 | |
| 3482 | rc = hdmi_msm_hpd_on(true); |
| 3483 | if (rc) |
| 3484 | goto error; |
| 3485 | |
| 3486 | if (hdmi_msm_has_hdcp()) |
| 3487 | external_common_state->present_hdcp = TRUE; |
| 3488 | else { |
| 3489 | external_common_state->present_hdcp = FALSE; |
| 3490 | #ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT |
| 3491 | /* |
| 3492 | * If the device is not hdcp capable do |
| 3493 | * not start hdcp timer. |
| 3494 | */ |
| 3495 | del_timer(&hdmi_msm_state->hdcp_timer); |
| 3496 | #endif |
| 3497 | } |
| 3498 | |
| 3499 | queue_work(hdmi_work_queue, &hdmi_msm_state->hpd_read_work); |
| 3500 | return 0; |
| 3501 | |
| 3502 | error: |
| 3503 | if (hdmi_msm_state->qfprom_io) |
| 3504 | iounmap(hdmi_msm_state->qfprom_io); |
| 3505 | hdmi_msm_state->qfprom_io = NULL; |
| 3506 | |
| 3507 | if (hdmi_msm_state->hdmi_io) |
| 3508 | iounmap(hdmi_msm_state->hdmi_io); |
| 3509 | hdmi_msm_state->hdmi_io = NULL; |
| 3510 | |
| 3511 | external_common_state_remove(); |
| 3512 | |
| 3513 | if (hdmi_msm_state->hdmi_app_clk) |
| 3514 | clk_put(hdmi_msm_state->hdmi_app_clk); |
| 3515 | if (hdmi_msm_state->hdmi_m_pclk) |
| 3516 | clk_put(hdmi_msm_state->hdmi_m_pclk); |
| 3517 | if (hdmi_msm_state->hdmi_s_pclk) |
| 3518 | clk_put(hdmi_msm_state->hdmi_s_pclk); |
| 3519 | |
| 3520 | hdmi_msm_state->hdmi_app_clk = NULL; |
| 3521 | hdmi_msm_state->hdmi_m_pclk = NULL; |
| 3522 | hdmi_msm_state->hdmi_s_pclk = NULL; |
| 3523 | |
| 3524 | return rc; |
| 3525 | } |
| 3526 | |
| 3527 | static int __devexit hdmi_msm_remove(struct platform_device *pdev) |
| 3528 | { |
| 3529 | DEV_INFO("HDMI device: remove\n"); |
| 3530 | |
| 3531 | DEV_INFO("HDMI HPD: OFF\n"); |
| 3532 | hdmi_msm_hpd_off(); |
| 3533 | free_irq(hdmi_msm_state->irq, NULL); |
| 3534 | |
| 3535 | if (hdmi_msm_state->qfprom_io) |
| 3536 | iounmap(hdmi_msm_state->qfprom_io); |
| 3537 | hdmi_msm_state->qfprom_io = NULL; |
| 3538 | |
| 3539 | if (hdmi_msm_state->hdmi_io) |
| 3540 | iounmap(hdmi_msm_state->hdmi_io); |
| 3541 | hdmi_msm_state->hdmi_io = NULL; |
| 3542 | |
| 3543 | external_common_state_remove(); |
| 3544 | |
| 3545 | if (hdmi_msm_state->hdmi_app_clk) |
| 3546 | clk_put(hdmi_msm_state->hdmi_app_clk); |
| 3547 | if (hdmi_msm_state->hdmi_m_pclk) |
| 3548 | clk_put(hdmi_msm_state->hdmi_m_pclk); |
| 3549 | if (hdmi_msm_state->hdmi_s_pclk) |
| 3550 | clk_put(hdmi_msm_state->hdmi_s_pclk); |
| 3551 | |
| 3552 | hdmi_msm_state->hdmi_app_clk = NULL; |
| 3553 | hdmi_msm_state->hdmi_m_pclk = NULL; |
| 3554 | hdmi_msm_state->hdmi_s_pclk = NULL; |
| 3555 | |
| 3556 | kfree(hdmi_msm_state); |
| 3557 | hdmi_msm_state = NULL; |
| 3558 | |
| 3559 | return 0; |
| 3560 | } |
| 3561 | |
| 3562 | static int hdmi_msm_hpd_feature(int on) |
| 3563 | { |
| 3564 | int rc = 0; |
| 3565 | |
| 3566 | DEV_INFO("%s: %d\n", __func__, on); |
| 3567 | if (on) |
| 3568 | rc = hdmi_msm_hpd_on(true); |
| 3569 | else |
| 3570 | hdmi_msm_hpd_off(); |
| 3571 | |
| 3572 | return rc; |
| 3573 | } |
| 3574 | |
| 3575 | |
| 3576 | #ifdef CONFIG_SUSPEND |
| 3577 | static int hdmi_msm_device_pm_suspend(struct device *dev) |
| 3578 | { |
| 3579 | mutex_lock(&hdmi_msm_state_mutex); |
| 3580 | if (hdmi_msm_state->pm_suspended) { |
| 3581 | mutex_unlock(&hdmi_msm_state_mutex); |
| 3582 | return 0; |
| 3583 | } |
| 3584 | |
| 3585 | DEV_DBG("pm_suspend\n"); |
| 3586 | |
| 3587 | del_timer(&hdmi_msm_state->hpd_state_timer); |
| 3588 | #ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT |
| 3589 | del_timer(&hdmi_msm_state->hdcp_timer); |
| 3590 | #endif /* CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT */ |
| 3591 | |
| 3592 | disable_irq(hdmi_msm_state->irq); |
| Ravishangar Kalyanam | 1833754 | 2011-08-12 10:26:35 -0700 | [diff] [blame] | 3593 | if (external_common_state->hpd_feature_on) |
| 3594 | hdmi_msm_clk(0); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3595 | |
| 3596 | hdmi_msm_state->pm_suspended = TRUE; |
| 3597 | mutex_unlock(&hdmi_msm_state_mutex); |
| 3598 | |
| 3599 | hdmi_msm_powerdown_phy(); |
| 3600 | hdmi_msm_state->pd->enable_5v(0); |
| 3601 | hdmi_msm_state->pd->core_power(0, 1); |
| 3602 | return 0; |
| 3603 | } |
| 3604 | |
| 3605 | static int hdmi_msm_device_pm_resume(struct device *dev) |
| 3606 | { |
| 3607 | mutex_lock(&hdmi_msm_state_mutex); |
| 3608 | if (!hdmi_msm_state->pm_suspended) { |
| 3609 | mutex_unlock(&hdmi_msm_state_mutex); |
| 3610 | return 0; |
| 3611 | } |
| 3612 | |
| 3613 | DEV_DBG("pm_resume\n"); |
| 3614 | |
| 3615 | hdmi_msm_state->pd->core_power(1, 1); |
| 3616 | hdmi_msm_state->pd->enable_5v(1); |
| Ravishangar Kalyanam | 1833754 | 2011-08-12 10:26:35 -0700 | [diff] [blame] | 3617 | if (external_common_state->hpd_feature_on) |
| 3618 | hdmi_msm_clk(1); |
| Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 3619 | |
| 3620 | hdmi_msm_state->pm_suspended = FALSE; |
| 3621 | mutex_unlock(&hdmi_msm_state_mutex); |
| 3622 | enable_irq(hdmi_msm_state->irq); |
| 3623 | return 0; |
| 3624 | } |
| 3625 | #else |
| 3626 | #define hdmi_msm_device_pm_suspend NULL |
| 3627 | #define hdmi_msm_device_pm_resume NULL |
| 3628 | #endif |
| 3629 | |
| 3630 | static const struct dev_pm_ops hdmi_msm_device_pm_ops = { |
| 3631 | .suspend = hdmi_msm_device_pm_suspend, |
| 3632 | .resume = hdmi_msm_device_pm_resume, |
| 3633 | }; |
| 3634 | |
| 3635 | static struct platform_driver this_driver = { |
| 3636 | .probe = hdmi_msm_probe, |
| 3637 | .remove = hdmi_msm_remove, |
| 3638 | .driver.name = "hdmi_msm", |
| 3639 | .driver.pm = &hdmi_msm_device_pm_ops, |
| 3640 | }; |
| 3641 | |
| 3642 | static struct msm_fb_panel_data hdmi_msm_panel_data = { |
| 3643 | .on = hdmi_msm_power_on, |
| 3644 | .off = hdmi_msm_power_off, |
| 3645 | }; |
| 3646 | |
| 3647 | static struct platform_device this_device = { |
| 3648 | .name = "hdmi_msm", |
| 3649 | .id = 1, |
| 3650 | .dev.platform_data = &hdmi_msm_panel_data, |
| 3651 | }; |
| 3652 | |
| 3653 | static int __init hdmi_msm_init(void) |
| 3654 | { |
| 3655 | int rc; |
| 3656 | |
| 3657 | hdmi_msm_setup_video_mode_lut(); |
| 3658 | hdmi_msm_state = kzalloc(sizeof(*hdmi_msm_state), GFP_KERNEL); |
| 3659 | if (!hdmi_msm_state) { |
| 3660 | pr_err("hdmi_msm_init FAILED: out of memory\n"); |
| 3661 | rc = -ENOMEM; |
| 3662 | goto init_exit; |
| 3663 | } |
| 3664 | |
| 3665 | external_common_state = &hdmi_msm_state->common; |
| 3666 | external_common_state->video_resolution = HDMI_VFRMT_1920x1080p60_16_9; |
| 3667 | #ifdef CONFIG_FB_MSM_HDMI_3D |
| 3668 | external_common_state->switch_3d = hdmi_msm_switch_3d; |
| 3669 | #endif |
| 3670 | |
| 3671 | /* |
| 3672 | * Create your work queue |
| 3673 | * allocs and returns ptr |
| 3674 | */ |
| 3675 | hdmi_work_queue = create_workqueue("hdmi_hdcp"); |
| 3676 | external_common_state->hpd_feature = hdmi_msm_hpd_feature; |
| 3677 | |
| 3678 | rc = platform_driver_register(&this_driver); |
| 3679 | if (rc) { |
| 3680 | pr_err("hdmi_msm_init FAILED: platform_driver_register rc=%d\n", |
| 3681 | rc); |
| 3682 | goto init_exit; |
| 3683 | } |
| 3684 | |
| 3685 | hdmi_common_init_panel_info(&hdmi_msm_panel_data.panel_info); |
| 3686 | init_completion(&hdmi_msm_state->ddc_sw_done); |
| 3687 | INIT_WORK(&hdmi_msm_state->hpd_state_work, hdmi_msm_hpd_state_work); |
| 3688 | INIT_WORK(&hdmi_msm_state->hpd_read_work, hdmi_msm_hpd_read_work); |
| 3689 | #ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT |
| 3690 | init_completion(&hdmi_msm_state->hdcp_success_done); |
| 3691 | INIT_WORK(&hdmi_msm_state->hdcp_reauth_work, hdmi_msm_hdcp_reauth_work); |
| 3692 | INIT_WORK(&hdmi_msm_state->hdcp_work, hdmi_msm_hdcp_work); |
| 3693 | #endif /* CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT */ |
| 3694 | |
| 3695 | rc = platform_device_register(&this_device); |
| 3696 | if (rc) { |
| 3697 | pr_err("hdmi_msm_init FAILED: platform_device_register rc=%d\n", |
| 3698 | rc); |
| 3699 | platform_driver_unregister(&this_driver); |
| 3700 | goto init_exit; |
| 3701 | } |
| 3702 | |
| 3703 | pr_debug("%s: success:" |
| 3704 | #ifdef DEBUG |
| 3705 | " DEBUG" |
| 3706 | #else |
| 3707 | " RELEASE" |
| 3708 | #endif |
| 3709 | " AUDIO EDID HPD HDCP" |
| 3710 | #ifndef CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT |
| 3711 | ":0" |
| 3712 | #endif /* CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT */ |
| 3713 | " DVI" |
| 3714 | #ifndef CONFIG_FB_MSM_HDMI_MSM_PANEL_DVI_SUPPORT |
| 3715 | ":0" |
| 3716 | #endif /* CONFIG_FB_MSM_HDMI_MSM_PANEL_DVI_SUPPORT */ |
| 3717 | "\n", __func__); |
| 3718 | |
| 3719 | return 0; |
| 3720 | |
| 3721 | init_exit: |
| 3722 | kfree(hdmi_msm_state); |
| 3723 | hdmi_msm_state = NULL; |
| 3724 | |
| 3725 | return rc; |
| 3726 | } |
| 3727 | |
| 3728 | static void __exit hdmi_msm_exit(void) |
| 3729 | { |
| 3730 | platform_device_unregister(&this_device); |
| 3731 | platform_driver_unregister(&this_driver); |
| 3732 | } |
| 3733 | |
| 3734 | module_init(hdmi_msm_init); |
| 3735 | module_exit(hdmi_msm_exit); |
| 3736 | |
| 3737 | MODULE_LICENSE("GPL v2"); |
| 3738 | MODULE_VERSION("0.3"); |
| 3739 | MODULE_AUTHOR("Qualcomm Innovation Center, Inc."); |
| 3740 | MODULE_DESCRIPTION("HDMI MSM TX driver"); |