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