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