blob: 9805b6cae8ac193aed4f77a704aa270c675fed2c [file] [log] [blame]
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001/* 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 Raoa2c27672011-08-30 17:19:39 -070018#define CEC_MSG_PRINT
19/* #define CEC_COMPLIANCE_TESTING */
20
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070021#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 Moskovchenko164fe8a2011-08-05 18:10:54 -070028#include <mach/socinfo.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070029
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
52struct workqueue_struct *hdmi_work_queue;
53struct hdmi_msm_state_type *hdmi_msm_state;
54
Manoj Raoa2c27672011-08-30 17:19:39 -070055DEFINE_MUTEX(hdmi_msm_state_mutex);
56EXPORT_SYMBOL(hdmi_msm_state_mutex);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070057static DEFINE_MUTEX(hdcp_auth_state_mutex);
58
59#ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT
60static void hdmi_msm_hdcp_enable(void);
61#else
62static inline void hdmi_msm_hdcp_enable(void) {}
63#endif
64
Manoj Raoa2c27672011-08-30 17:19:39 -070065static void hdmi_msm_turn_on(void);
66static int hdmi_msm_audio_off(void);
67static int hdmi_msm_read_edid(void);
68static 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
111void 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
164void 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
172void 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
188void 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
256void 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
504void 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 Huntsman3f2bc4d2011-08-16 17:27:22 -0700537uint32 hdmi_msm_get_io_base(void)
538{
539 return (uint32)MSM_HDMI_BASE;
540}
541EXPORT_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 */
545static 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
567const 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
669void 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
679uint32 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
688static void hdmi_msm_turn_on(void);
689static int hdmi_msm_audio_off(void);
690static int hdmi_msm_read_edid(void);
691static void hdmi_msm_hpd_off(void);
692
693static 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 Raob91fa712011-06-29 09:07:55 -0700713 DEV_DBG("%s:Got interrupt\n", __func__);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700714 /* 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 Rao09ab5652011-10-10 17:36:15 -0700755 /* 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 Huntsman3f2bc4d2011-08-16 17:27:22 -0700761 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 Huntsman3f2bc4d2011-08-16 17:27:22 -0700767 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 Kharbandad5315bd2011-08-10 19:45:53 -0700772#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 Huntsman3f2bc4d2011-08-16 17:27:22 -0700780 } 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
813static void hdcp_deauthenticate(void);
814static 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
848static 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
872static irqreturn_t hdmi_msm_isr(int irq, void *dev_id)
873{
874 uint32 hpd_int_status;
875 uint32 hpd_int_ctrl;
Manoj Raoa2c27672011-08-30 17:19:39 -0700876#ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_CEC_SUPPORT
877 uint32 cec_intr_status;
878#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700879 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 Raof74d2edd2011-07-18 14:25:38 -0700913 /* 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 Huntsman3f2bc4d2011-08-16 17:27:22 -0700918
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 Raoa2c27672011-08-30 17:19:39 -07001083#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 Huntsman3f2bc4d2011-08-16 17:27:22 -07001130 DEV_DBG("%s: HPD<Ctrl=%04x, State=%04x>, ddc_int_ctrl=%04x, "
Manoj Raoa2c27672011-08-30 17:19:39 -07001131 "aud_int=%04x, cec_intr_status=%04x\n", __func__, hpd_int_ctrl,
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001132 hpd_int_status, ddc_int_ctrl, audio_int_val,
1133 HDMI_INP_ND(0x029C));
1134
1135 return IRQ_HANDLED;
1136}
1137
1138static 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
1160static 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
1166static 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. */
1179static 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 Kalyanam49a83b22011-07-20 15:28:44 -07001185void hdmi_msm_set_mode(boolean power_on)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001186{
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 Raob91fa712011-06-29 09:07:55 -07001194 if (external_common_state->present_hdcp)
1195 /* HDMI Encryption */
1196 reg_val |= 0x00000004;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001197 /* HDMI_CTRL */
1198 HDMI_OUTP(0x0000, reg_val);
1199 /* HDMI_DVI_SEL */
1200 reg_val &= ~0x00000002;
Manoj Raob91fa712011-06-29 09:07:55 -07001201 } else {
1202 if (external_common_state->present_hdcp)
1203 /* HDMI_Encryption_ON */
1204 reg_val |= 0x00000006;
1205 else
1206 reg_val |= 0x00000002;
1207 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001208 } 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
1216static 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 Kharbandadee95102011-09-19 14:08:33 -07001234 /*
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 Huntsman3f2bc4d2011-08-16 17:27:22 -07001240
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
1252static 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
1282static 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
1295again:
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
1474error:
1475 return status;
1476}
1477#endif /* CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT */
1478
1479static 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
1494again:
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
1703error:
1704 return status;
1705}
1706
1707static 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
1723again:
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
1964error:
1965 return status;
1966}
1967
1968
1969static 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
1986static 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
2015static 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
2033error:
2034 return status;
2035}
2036
2037#ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT
2038static 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
2072static 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
2104static 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
2113static 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
2132static 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;
2412error:
2413 DEV_ERR("[%s]: HDCP Reauthentication\n", __func__);
2414 is_part1_done = FALSE;
2415 return ret;
2416 } else {
2417 return 1;
2418 }
2419}
2420
2421static 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
2501static 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
2677hdcp_error:
2678error:
2679 return ret;
2680}
2681
2682static 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
2705error:
2706 return ret;
2707}
2708
2709static 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
2790error:
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
2810static 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
2876struct hdmi_msm_audio_acr {
2877 uint32 n; /* N parameter for clock regeneration */
2878 uint32 cts; /* CTS parameter for clock regeneration */
2879};
2880
2881struct 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 */
2890static 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
2913static 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
3029static 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
3046static 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
3062int 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
3091 return 0;
3092}
3093EXPORT_SYMBOL(hdmi_audio_enable);
3094
3095static void hdmi_msm_audio_info_setup(boolean enabled, int num_of_channels,
3096 int level_shift, boolean down_mix)
3097{
3098 uint32 channel_allocation = 0; /* Default to FR,FL */
3099 uint32 channel_count = 1; /* Default to 2 channels
3100 -> See Table 17 in CEA-D spec */
3101 uint32 check_sum, audio_info_0_reg, audio_info_1_reg;
3102 uint32 audio_info_ctrl_reg;
3103
3104 /* Please see table 20 Audio InfoFrame in HDMI spec
3105 FL = front left
3106 FC = front Center
3107 FR = front right
3108 FLC = front left center
3109 FRC = front right center
3110 RL = rear left
3111 RC = rear center
3112 RR = rear right
3113 RLC = rear left center
3114 RRC = rear right center
3115 LFE = low frequency effect
3116 */
3117
3118 /* Read first then write because it is bundled with other controls */
3119 /* HDMI_INFOFRAME_CTRL0[0x002C] */
3120 audio_info_ctrl_reg = HDMI_INP(0x002C);
3121
3122 if (enabled) {
3123 switch (num_of_channels) {
3124 case MSM_HDMI_AUDIO_CHANNEL_2:
3125 break;
3126 case MSM_HDMI_AUDIO_CHANNEL_4:
3127 channel_count = 3;
3128 /* FC,LFE,FR,FL */
3129 channel_allocation = 0x3;
3130 break;
3131 case MSM_HDMI_AUDIO_CHANNEL_6:
3132 channel_count = 5;
3133 /* RR,RL,FC,LFE,FR,FL */
3134 channel_allocation = 0xB;
3135 break;
3136 case MSM_HDMI_AUDIO_CHANNEL_8:
3137 channel_count = 7;
3138 /* FRC,FLC,RR,RL,FC,LFE,FR,FL */
3139 channel_allocation = 0x1f;
3140 break;
3141 default:
3142 break;
3143 }
3144
3145 /* Program the Channel-Speaker allocation */
3146 audio_info_1_reg = 0;
3147 /* CA(channel_allocation) */
3148 audio_info_1_reg |= channel_allocation & 0xff;
3149 /* Program the Level shifter */
3150 /* LSV(level_shift) */
3151 audio_info_1_reg |= (level_shift << 11) & 0x00007800;
3152 /* Program the Down-mix Inhibit Flag */
3153 /* DM_INH(down_mix) */
3154 audio_info_1_reg |= (down_mix << 15) & 0x00008000;
3155
3156 /* HDMI_AUDIO_INFO1[0x00E8] */
3157 HDMI_OUTP(0x00E8, audio_info_1_reg);
3158
3159 /* Calculate CheckSum
3160 Sum of all the bytes in the Audio Info Packet bytes
3161 (See table 8.4 in HDMI spec) */
3162 check_sum = 0;
3163 /* HDMI_AUDIO_INFO_FRAME_PACKET_HEADER_TYPE[0x84] */
3164 check_sum += 0x84;
3165 /* HDMI_AUDIO_INFO_FRAME_PACKET_HEADER_VERSION[0x01] */
3166 check_sum += 1;
3167 /* HDMI_AUDIO_INFO_FRAME_PACKET_LENGTH[0x0A] */
3168 check_sum += 0x0A;
3169 check_sum += channel_count;
3170 check_sum += channel_allocation;
3171 /* See Table 8.5 in HDMI spec */
3172 check_sum += (level_shift & 0xF) << 3 | (down_mix & 0x1) << 7;
3173 check_sum &= 0xFF;
3174 check_sum = (uint8) (256 - check_sum);
3175
3176 audio_info_0_reg = 0;
3177 /* CHECKSUM(check_sum) */
3178 audio_info_0_reg |= check_sum & 0xff;
3179 /* CC(channel_count) */
3180 audio_info_0_reg |= (channel_count << 8) & 0x00000700;
3181
3182 /* HDMI_AUDIO_INFO0[0x00E4] */
3183 HDMI_OUTP(0x00E4, audio_info_0_reg);
3184
3185 /* Set these flags */
3186 /* AUDIO_INFO_UPDATE | AUDIO_INFO_SOURCE | AUDIO_INFO_CONT
3187 | AUDIO_INFO_SEND */
3188 audio_info_ctrl_reg |= 0x000000F0;
3189 } else {
3190 /* Clear these flags */
3191 /* ~(AUDIO_INFO_UPDATE | AUDIO_INFO_SOURCE | AUDIO_INFO_CONT
3192 | AUDIO_INFO_SEND) */
3193 audio_info_ctrl_reg &= ~0x000000F0;
3194 }
3195 /* HDMI_INFOFRAME_CTRL0[0x002C] */
3196 HDMI_OUTP(0x002C, audio_info_ctrl_reg);
3197}
3198
3199static void hdmi_msm_audio_ctrl_setup(boolean enabled, int delay)
3200{
3201 uint32 audio_pkt_ctrl_reg = 0;
3202
3203 /* Enable Packet Transmission */
3204 audio_pkt_ctrl_reg |= enabled ? 0x00000001 : 0;
3205 audio_pkt_ctrl_reg |= (delay << 4);
3206
3207 /* HDMI_AUDIO_PKT_CTRL1[0x0020] */
3208 HDMI_OUTP(0x0020, audio_pkt_ctrl_reg);
3209}
3210
3211static void hdmi_msm_en_gc_packet(boolean av_mute_is_requested)
3212{
3213 /* HDMI_GC[0x0040] */
3214 HDMI_OUTP(0x0040, av_mute_is_requested ? 1 : 0);
3215
3216 /* GC packet enable (every frame) */
3217 /* HDMI_VBI_PKT_CTRL[0x0028] */
3218 hdmi_msm_rmw32or(0x0028, 3 << 4);
3219}
3220
Manoj Raoc2f19592011-08-05 17:54:25 -07003221#ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_ISRC_ACP_SUPPORT
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003222static void hdmi_msm_en_isrc_packet(boolean isrc_is_continued)
3223{
3224 static const char isrc_psuedo_data[] =
3225 "ISRC1:0123456789isrc2=ABCDEFGHIJ";
3226 const uint32 * isrc_data = (const uint32 *) isrc_psuedo_data;
3227
3228 /* ISRC_STATUS =0b010 | ISRC_CONTINUE | ISRC_VALID */
3229 /* HDMI_ISRC1_0[0x00048] */
3230 HDMI_OUTP(0x00048, 2 | (isrc_is_continued ? 1 : 0) << 6 | 0 << 7);
3231
3232 /* HDMI_ISRC1_1[0x004C] */
3233 HDMI_OUTP(0x004C, *isrc_data++);
3234 /* HDMI_ISRC1_2[0x0050] */
3235 HDMI_OUTP(0x0050, *isrc_data++);
3236 /* HDMI_ISRC1_3[0x0054] */
3237 HDMI_OUTP(0x0054, *isrc_data++);
3238 /* HDMI_ISRC1_4[0x0058] */
3239 HDMI_OUTP(0x0058, *isrc_data++);
3240
3241 /* HDMI_ISRC2_0[0x005C] */
3242 HDMI_OUTP(0x005C, *isrc_data++);
3243 /* HDMI_ISRC2_1[0x0060] */
3244 HDMI_OUTP(0x0060, *isrc_data++);
3245 /* HDMI_ISRC2_2[0x0064] */
3246 HDMI_OUTP(0x0064, *isrc_data++);
3247 /* HDMI_ISRC2_3[0x0068] */
3248 HDMI_OUTP(0x0068, *isrc_data);
3249
3250 /* HDMI_VBI_PKT_CTRL[0x0028] */
3251 /* ISRC Send + Continuous */
3252 hdmi_msm_rmw32or(0x0028, 3 << 8);
3253}
Manoj Raoc2f19592011-08-05 17:54:25 -07003254#else
3255static void hdmi_msm_en_isrc_packet(boolean isrc_is_continued)
3256{
3257 /*
3258 * Until end-to-end support for various audio packets
3259 */
3260}
3261#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003262
Manoj Raoc2f19592011-08-05 17:54:25 -07003263#ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_ISRC_ACP_SUPPORT
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003264static void hdmi_msm_en_acp_packet(uint32 byte1)
3265{
3266 /* HDMI_ACP[0x003C] */
3267 HDMI_OUTP(0x003C, 2 | 1 << 8 | byte1 << 16);
3268
3269 /* HDMI_VBI_PKT_CTRL[0x0028] */
3270 /* ACP send, s/w source */
3271 hdmi_msm_rmw32or(0x0028, 3 << 12);
3272}
Manoj Raoc2f19592011-08-05 17:54:25 -07003273#else
3274static void hdmi_msm_en_acp_packet(uint32 byte1)
3275{
3276 /*
3277 * Until end-to-end support for various audio packets
3278 */
3279}
3280#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003281
3282static void hdmi_msm_audio_setup(void)
3283{
3284 const int channels = MSM_HDMI_AUDIO_CHANNEL_2;
3285
3286 /* (0) for clr_avmute, (1) for set_avmute */
3287 hdmi_msm_en_gc_packet(0);
3288 /* (0) for isrc1 only, (1) for isrc1 and isrc2 */
3289 hdmi_msm_en_isrc_packet(1);
3290 /* arbitrary bit pattern for byte1 */
3291 hdmi_msm_en_acp_packet(0x5a);
Manoj Raoc2f19592011-08-05 17:54:25 -07003292 DEV_DBG("Not setting ACP, ISRC1, ISRC2 packets\n");
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003293 hdmi_msm_audio_acr_setup(TRUE,
3294 external_common_state->video_resolution,
3295 MSM_HDMI_SAMPLE_RATE_48KHZ, channels);
3296 hdmi_msm_audio_info_setup(TRUE, channels, 0, FALSE);
3297 hdmi_msm_audio_ctrl_setup(TRUE, 1);
3298
3299 /* Turn on Audio FIFO and SAM DROP ISR */
3300 HDMI_OUTP(0x02CC, HDMI_INP(0x02CC) | BIT(1) | BIT(3));
3301 DEV_INFO("HDMI Audio: Enabled\n");
3302}
3303
3304static int hdmi_msm_audio_off(void)
3305{
3306 uint32 audio_pkt_ctrl, audio_cfg;
3307 /* Number of wait iterations */
3308 int i = 10;
3309 audio_pkt_ctrl = HDMI_INP_ND(0x0020);
3310 audio_cfg = HDMI_INP_ND(0x01D0);
3311
3312 /* Checking BIT[0] of AUDIO PACKET CONTROL and */
3313 /* AUDIO CONFIGURATION register */
3314 while (((audio_pkt_ctrl & 0x00000001) || (audio_cfg & 0x00000001))
3315 && (i--)) {
3316 audio_pkt_ctrl = HDMI_INP_ND(0x0020);
3317 audio_cfg = HDMI_INP_ND(0x01D0);
3318 DEV_DBG("%d times :: HDMI AUDIO PACKET is %08x and "
3319 "AUDIO CFG is %08x", i, audio_pkt_ctrl, audio_cfg);
3320 msleep(100);
3321 if (!i) {
3322 DEV_ERR("%s:failed to set BIT[0] AUDIO PACKET"
3323 "CONTROL or AUDIO CONFIGURATION REGISTER\n",
3324 __func__);
3325 return -ETIMEDOUT;
3326 }
3327 }
3328 hdmi_msm_audio_info_setup(FALSE, 0, 0, FALSE);
3329 hdmi_msm_audio_ctrl_setup(FALSE, 0);
3330 hdmi_msm_audio_acr_setup(FALSE, 0, 0, 0);
3331 DEV_INFO("HDMI Audio: Disabled\n");
3332 return 0;
3333}
3334
3335
Manoj Raobbf9a472011-06-14 21:05:18 -07003336static uint8 hdmi_msm_avi_iframe_lut[][15] = {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003337/* 480p60 480i60 576p50 576i50 720p60 720p50 1080p60 1080i60 1080p50
Manoj Raobbf9a472011-06-14 21:05:18 -07003338 1080i50 1080p24 1080p30 1080p25 640x480p 480p60_16_9*/
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003339 {0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
Manoj Raobbf9a472011-06-14 21:05:18 -07003340 0x10, 0x10, 0x10, 0x10, 0x10, 0x10}, /*00*/
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003341 {0x18, 0x18, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28,
Manoj Raobbf9a472011-06-14 21:05:18 -07003342 0x28, 0x28, 0x28, 0x28, 0x18, 0x28}, /*01*/
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003343 {0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
Manoj Raobbf9a472011-06-14 21:05:18 -07003344 0x04, 0x04, 0x04, 0x04, 0x88, 0x04}, /*02*/
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003345 {0x02, 0x06, 0x11, 0x15, 0x04, 0x13, 0x10, 0x05, 0x1F,
Manoj Raobbf9a472011-06-14 21:05:18 -07003346 0x14, 0x20, 0x22, 0x21, 0x01, 0x03}, /*03*/
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003347 {0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
Manoj Raobbf9a472011-06-14 21:05:18 -07003348 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*04*/
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003349 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Manoj Raobbf9a472011-06-14 21:05:18 -07003350 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*05*/
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003351 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Manoj Raobbf9a472011-06-14 21:05:18 -07003352 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*06*/
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003353 {0xE1, 0xE1, 0x41, 0x41, 0xD1, 0xd1, 0x39, 0x39, 0x39,
Manoj Raobbf9a472011-06-14 21:05:18 -07003354 0x39, 0x39, 0x39, 0x39, 0xe1, 0xE1}, /*07*/
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003355 {0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x04, 0x04, 0x04,
Manoj Raobbf9a472011-06-14 21:05:18 -07003356 0x04, 0x04, 0x04, 0x04, 0x01, 0x01}, /*08*/
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003357 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Manoj Raobbf9a472011-06-14 21:05:18 -07003358 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*09*/
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003359 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Manoj Raobbf9a472011-06-14 21:05:18 -07003360 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*10*/
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003361 {0xD1, 0xD1, 0xD1, 0xD1, 0x01, 0x01, 0x81, 0x81, 0x81,
Manoj Raobbf9a472011-06-14 21:05:18 -07003362 0x81, 0x81, 0x81, 0x81, 0x81, 0xD1}, /*11*/
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003363 {0x02, 0x02, 0x02, 0x02, 0x05, 0x05, 0x07, 0x07, 0x07,
Manoj Raobbf9a472011-06-14 21:05:18 -07003364 0x07, 0x07, 0x07, 0x07, 0x02, 0x02} /*12*/
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003365};
3366
3367static void hdmi_msm_avi_info_frame(void)
3368{
3369 /* two header + length + 13 data */
3370 uint8 aviInfoFrame[16];
3371 uint8 checksum;
3372 uint32 sum;
3373 uint32 regVal;
3374 int i;
3375 int mode = 0;
3376
3377 switch (external_common_state->video_resolution) {
Manoj Raobbf9a472011-06-14 21:05:18 -07003378 case HDMI_VFRMT_720x480p60_4_3:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003379 mode = 0;
3380 break;
3381 case HDMI_VFRMT_720x480i60_16_9:
3382 mode = 1;
3383 break;
3384 case HDMI_VFRMT_720x576p50_16_9:
3385 mode = 2;
3386 break;
3387 case HDMI_VFRMT_720x576i50_16_9:
3388 mode = 3;
3389 break;
3390 case HDMI_VFRMT_1280x720p60_16_9:
3391 mode = 4;
3392 break;
3393 case HDMI_VFRMT_1280x720p50_16_9:
3394 mode = 5;
3395 break;
3396 case HDMI_VFRMT_1920x1080p60_16_9:
3397 mode = 6;
3398 break;
3399 case HDMI_VFRMT_1920x1080i60_16_9:
3400 mode = 7;
3401 break;
3402 case HDMI_VFRMT_1920x1080p50_16_9:
3403 mode = 8;
3404 break;
3405 case HDMI_VFRMT_1920x1080i50_16_9:
3406 mode = 9;
3407 break;
3408 case HDMI_VFRMT_1920x1080p24_16_9:
3409 mode = 10;
3410 break;
3411 case HDMI_VFRMT_1920x1080p30_16_9:
3412 mode = 11;
3413 break;
3414 case HDMI_VFRMT_1920x1080p25_16_9:
3415 mode = 12;
3416 break;
3417 case HDMI_VFRMT_640x480p60_4_3:
3418 mode = 13;
3419 break;
Manoj Raobbf9a472011-06-14 21:05:18 -07003420 case HDMI_VFRMT_720x480p60_16_9:
3421 mode = 14;
3422 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003423 default:
3424 DEV_INFO("%s: mode %d not supported\n", __func__,
3425 external_common_state->video_resolution);
3426 return;
3427 }
3428
3429 /* InfoFrame Type = 82 */
3430 aviInfoFrame[0] = 0x82;
3431 /* Version = 2 */
3432 aviInfoFrame[1] = 2;
3433 /* Length of AVI InfoFrame = 13 */
3434 aviInfoFrame[2] = 13;
3435
3436 /* Data Byte 01: 0 Y1 Y0 A0 B1 B0 S1 S0 */
3437 aviInfoFrame[3] = hdmi_msm_avi_iframe_lut[0][mode];
3438 /* Data Byte 02: C1 C0 M1 M0 R3 R2 R1 R0 */
3439 aviInfoFrame[4] = hdmi_msm_avi_iframe_lut[1][mode];
3440 /* Data Byte 03: ITC EC2 EC1 EC0 Q1 Q0 SC1 SC0 */
3441 aviInfoFrame[5] = hdmi_msm_avi_iframe_lut[2][mode];
3442 /* Data Byte 04: 0 VIC6 VIC5 VIC4 VIC3 VIC2 VIC1 VIC0 */
3443 aviInfoFrame[6] = hdmi_msm_avi_iframe_lut[3][mode];
3444 /* Data Byte 05: 0 0 0 0 PR3 PR2 PR1 PR0 */
3445 aviInfoFrame[7] = hdmi_msm_avi_iframe_lut[4][mode];
3446 /* Data Byte 06: LSB Line No of End of Top Bar */
3447 aviInfoFrame[8] = hdmi_msm_avi_iframe_lut[5][mode];
3448 /* Data Byte 07: MSB Line No of End of Top Bar */
3449 aviInfoFrame[9] = hdmi_msm_avi_iframe_lut[6][mode];
3450 /* Data Byte 08: LSB Line No of Start of Bottom Bar */
3451 aviInfoFrame[10] = hdmi_msm_avi_iframe_lut[7][mode];
3452 /* Data Byte 09: MSB Line No of Start of Bottom Bar */
3453 aviInfoFrame[11] = hdmi_msm_avi_iframe_lut[8][mode];
3454 /* Data Byte 10: LSB Pixel Number of End of Left Bar */
3455 aviInfoFrame[12] = hdmi_msm_avi_iframe_lut[9][mode];
3456 /* Data Byte 11: MSB Pixel Number of End of Left Bar */
3457 aviInfoFrame[13] = hdmi_msm_avi_iframe_lut[10][mode];
3458 /* Data Byte 12: LSB Pixel Number of Start of Right Bar */
3459 aviInfoFrame[14] = hdmi_msm_avi_iframe_lut[11][mode];
3460 /* Data Byte 13: MSB Pixel Number of Start of Right Bar */
3461 aviInfoFrame[15] = hdmi_msm_avi_iframe_lut[12][mode];
3462
3463 sum = 0;
3464 for (i = 0; i < 16; i++)
3465 sum += aviInfoFrame[i];
3466 sum &= 0xFF;
3467 sum = 256 - sum;
3468 checksum = (uint8) sum;
3469
3470 regVal = aviInfoFrame[5];
3471 regVal = regVal << 8 | aviInfoFrame[4];
3472 regVal = regVal << 8 | aviInfoFrame[3];
3473 regVal = regVal << 8 | checksum;
3474 HDMI_OUTP(0x006C, regVal);
3475
3476 regVal = aviInfoFrame[9];
3477 regVal = regVal << 8 | aviInfoFrame[8];
3478 regVal = regVal << 8 | aviInfoFrame[7];
3479 regVal = regVal << 8 | aviInfoFrame[6];
3480 HDMI_OUTP(0x0070, regVal);
3481
3482 regVal = aviInfoFrame[13];
3483 regVal = regVal << 8 | aviInfoFrame[12];
3484 regVal = regVal << 8 | aviInfoFrame[11];
3485 regVal = regVal << 8 | aviInfoFrame[10];
3486 HDMI_OUTP(0x0074, regVal);
3487
3488 regVal = aviInfoFrame[1];
3489 regVal = regVal << 16 | aviInfoFrame[15];
3490 regVal = regVal << 8 | aviInfoFrame[14];
3491 HDMI_OUTP(0x0078, regVal);
3492
3493 /* INFOFRAME_CTRL0[0x002C] */
3494 /* 0x3 for AVI InfFrame enable (every frame) */
3495 HDMI_OUTP(0x002C, HDMI_INP(0x002C) | 0x00000003L);
3496}
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003497
3498#ifdef CONFIG_FB_MSM_HDMI_3D
3499static void hdmi_msm_vendor_infoframe_packetsetup(void)
3500{
3501 uint32 packet_header = 0;
3502 uint32 check_sum = 0;
3503 uint32 packet_payload = 0;
3504
3505 if (!external_common_state->format_3d) {
3506 HDMI_OUTP(0x0034, 0);
3507 return;
3508 }
3509
3510 /* 0x0084 GENERIC0_HDR
3511 * HB0 7:0 NUM
3512 * HB1 15:8 NUM
3513 * HB2 23:16 NUM */
3514 /* Setup Packet header and payload */
3515 /* 0x81 VS_INFO_FRAME_ID
3516 0x01 VS_INFO_FRAME_VERSION
3517 0x1B VS_INFO_FRAME_PAYLOAD_LENGTH */
3518 packet_header = 0x81 | (0x01 << 8) | (0x1B << 16);
3519 HDMI_OUTP(0x0084, packet_header);
3520
3521 check_sum = packet_header & 0xff;
3522 check_sum += (packet_header >> 8) & 0xff;
3523 check_sum += (packet_header >> 16) & 0xff;
3524
3525 /* 0x008C GENERIC0_1
3526 * BYTE4 7:0 NUM
3527 * BYTE5 15:8 NUM
3528 * BYTE6 23:16 NUM
3529 * BYTE7 31:24 NUM */
3530 /* 0x02 VS_INFO_FRAME_3D_PRESENT */
3531 packet_payload = 0x02 << 5;
3532 switch (external_common_state->format_3d) {
3533 case 1:
3534 /* 0b1000 VIDEO_3D_FORMAT_SIDE_BY_SIDE_HALF */
3535 packet_payload |= (0x08 << 8) << 4;
3536 break;
3537 case 2:
3538 /* 0b0110 VIDEO_3D_FORMAT_TOP_AND_BOTTOM_HALF */
3539 packet_payload |= (0x06 << 8) << 4;
3540 break;
3541 }
3542 HDMI_OUTP(0x008C, packet_payload);
3543
3544 check_sum += packet_payload & 0xff;
3545 check_sum += (packet_payload >> 8) & 0xff;
3546
3547 #define IEEE_REGISTRATION_ID 0xC03
3548 /* Next 3 bytes are IEEE Registration Identifcation */
3549 /* 0x0088 GENERIC0_0
3550 * BYTE0 7:0 NUM (checksum)
3551 * BYTE1 15:8 NUM
3552 * BYTE2 23:16 NUM
3553 * BYTE3 31:24 NUM */
3554 check_sum += IEEE_REGISTRATION_ID & 0xff;
3555 check_sum += (IEEE_REGISTRATION_ID >> 8) & 0xff;
3556 check_sum += (IEEE_REGISTRATION_ID >> 16) & 0xff;
3557
3558 HDMI_OUTP(0x0088, (0x100 - (0xff & check_sum))
3559 | ((IEEE_REGISTRATION_ID & 0xff) << 8)
3560 | (((IEEE_REGISTRATION_ID >> 8) & 0xff) << 16)
3561 | (((IEEE_REGISTRATION_ID >> 16) & 0xff) << 24));
3562
3563 /* 0x0034 GEN_PKT_CTRL
3564 * GENERIC0_SEND 0 0 = Disable Generic0 Packet Transmission
3565 * 1 = Enable Generic0 Packet Transmission
3566 * GENERIC0_CONT 1 0 = Send Generic0 Packet on next frame only
3567 * 1 = Send Generic0 Packet on every frame
3568 * GENERIC0_UPDATE 2 NUM
3569 * GENERIC1_SEND 4 0 = Disable Generic1 Packet Transmission
3570 * 1 = Enable Generic1 Packet Transmission
3571 * GENERIC1_CONT 5 0 = Send Generic1 Packet on next frame only
3572 * 1 = Send Generic1 Packet on every frame
3573 * GENERIC0_LINE 21:16 NUM
3574 * GENERIC1_LINE 29:24 NUM
3575 */
3576 /* GENERIC0_LINE | GENERIC0_UPDATE | GENERIC0_CONT | GENERIC0_SEND
3577 * Setup HDMI TX generic packet control
3578 * Enable this packet to transmit every frame
3579 * Enable this packet to transmit every frame
3580 * Enable HDMI TX engine to transmit Generic packet 0 */
3581 HDMI_OUTP(0x0034, (1 << 16) | (1 << 2) | BIT(1) | BIT(0));
3582}
3583
3584static void hdmi_msm_switch_3d(boolean on)
3585{
3586 mutex_lock(&external_common_state_hpd_mutex);
3587 if (external_common_state->hpd_state)
3588 hdmi_msm_vendor_infoframe_packetsetup();
3589 mutex_unlock(&external_common_state_hpd_mutex);
3590}
3591#endif
3592
Ravishangar Kalyanam49a83b22011-07-20 15:28:44 -07003593int hdmi_msm_clk(int on)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003594{
3595 int rc;
3596
3597 DEV_DBG("HDMI Clk: %s\n", on ? "Enable" : "Disable");
3598 if (on) {
3599 rc = clk_enable(hdmi_msm_state->hdmi_app_clk);
3600 if (rc) {
3601 DEV_ERR("'hdmi_app_clk' clock enable failed, rc=%d\n",
3602 rc);
3603 return rc;
3604 }
3605
3606 rc = clk_enable(hdmi_msm_state->hdmi_m_pclk);
3607 if (rc) {
3608 DEV_ERR("'hdmi_m_pclk' clock enable failed, rc=%d\n",
3609 rc);
3610 return rc;
3611 }
3612
3613 rc = clk_enable(hdmi_msm_state->hdmi_s_pclk);
3614 if (rc) {
3615 DEV_ERR("'hdmi_s_pclk' clock enable failed, rc=%d\n",
3616 rc);
3617 return rc;
3618 }
3619 } else {
3620 clk_disable(hdmi_msm_state->hdmi_app_clk);
3621 clk_disable(hdmi_msm_state->hdmi_m_pclk);
3622 clk_disable(hdmi_msm_state->hdmi_s_pclk);
3623 }
3624
3625 return 0;
3626}
3627
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003628static void hdmi_msm_turn_on(void)
3629{
3630 uint32 hpd_ctrl;
3631
3632 hdmi_msm_reset_core();
3633 hdmi_msm_init_phy(external_common_state->video_resolution);
3634 /* HDMI_USEC_REFTIMER[0x0208] */
3635 HDMI_OUTP(0x0208, 0x0001001B);
3636
3637 hdmi_msm_video_setup(external_common_state->video_resolution);
3638 if (!hdmi_msm_is_dvi_mode())
3639 hdmi_msm_audio_setup();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003640 hdmi_msm_avi_info_frame();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003641#ifdef CONFIG_FB_MSM_HDMI_3D
3642 hdmi_msm_vendor_infoframe_packetsetup();
3643#endif
3644
3645 /* set timeout to 4.1ms (max) for hardware debounce */
3646 hpd_ctrl = (HDMI_INP(0x0258) & ~0xFFF) | 0xFFF;
3647
3648 /* Toggle HPD circuit to trigger HPD sense */
3649 HDMI_OUTP(0x0258, ~(1 << 28) & hpd_ctrl);
3650 HDMI_OUTP(0x0258, (1 << 28) | hpd_ctrl);
3651
3652 hdmi_msm_set_mode(TRUE);
3653
3654 /* Setup HPD IRQ */
3655 HDMI_OUTP(0x0254, 4 | (external_common_state->hpd_state ? 0 : 2));
3656
3657#ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT
3658 if (hdmi_msm_state->reauth) {
3659 hdmi_msm_hdcp_enable();
3660 hdmi_msm_state->reauth = FALSE ;
3661 }
3662#endif /* CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT */
Manoj Raoa2c27672011-08-30 17:19:39 -07003663
3664#ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_CEC_SUPPORT
3665 /* re-initialize CEC if enabled */
3666 mutex_lock(&hdmi_msm_state_mutex);
3667 if (hdmi_msm_state->cec_enabled == true) {
3668 hdmi_msm_cec_init();
3669 hdmi_msm_cec_write_logical_addr(
3670 hdmi_msm_state->cec_logical_addr);
3671 }
3672 mutex_unlock(&hdmi_msm_state_mutex);
3673#endif /* CONFIG_FB_MSM_HDMI_MSM_PANEL_CEC_SUPPORT */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003674 DEV_INFO("HDMI Core: Initialized\n");
3675}
3676
3677static void hdmi_msm_hpd_state_timer(unsigned long data)
3678{
3679 queue_work(hdmi_work_queue, &hdmi_msm_state->hpd_state_work);
3680}
3681
3682#ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT
3683static void hdmi_msm_hdcp_timer(unsigned long data)
3684{
3685 queue_work(hdmi_work_queue, &hdmi_msm_state->hdcp_work);
3686}
3687#endif
3688
3689static void hdmi_msm_hpd_read_work(struct work_struct *work)
3690{
3691 uint32 hpd_ctrl;
3692
3693 clk_enable(hdmi_msm_state->hdmi_app_clk);
3694 hdmi_msm_state->pd->core_power(1, 1);
3695 hdmi_msm_state->pd->enable_5v(1);
3696 hdmi_msm_set_mode(FALSE);
3697 hdmi_msm_init_phy(external_common_state->video_resolution);
3698 /* HDMI_USEC_REFTIMER[0x0208] */
3699 HDMI_OUTP(0x0208, 0x0001001B);
3700 hpd_ctrl = (HDMI_INP(0x0258) & ~0xFFF) | 0xFFF;
3701
3702 /* Toggle HPD circuit to trigger HPD sense */
3703 HDMI_OUTP(0x0258, ~(1 << 28) & hpd_ctrl);
3704 HDMI_OUTP(0x0258, (1 << 28) | hpd_ctrl);
3705
3706 hdmi_msm_set_mode(TRUE);
3707 msleep(1000);
3708 external_common_state->hpd_state = (HDMI_INP(0x0250) & 0x2) >> 1;
3709 if (external_common_state->hpd_state) {
3710 hdmi_msm_read_edid();
3711 DEV_DBG("%s: sense CONNECTED: send ONLINE\n", __func__);
3712 kobject_uevent(external_common_state->uevent_kobj,
3713 KOBJ_ONLINE);
3714 }
3715 hdmi_msm_hpd_off();
3716 hdmi_msm_set_mode(FALSE);
3717 hdmi_msm_state->pd->core_power(0, 1);
3718 hdmi_msm_state->pd->enable_5v(0);
3719 clk_disable(hdmi_msm_state->hdmi_app_clk);
3720}
3721
3722static void hdmi_msm_hpd_off(void)
3723{
3724 DEV_DBG("%s: (timer, clk, 5V, core, IRQ off)\n", __func__);
3725 del_timer(&hdmi_msm_state->hpd_state_timer);
3726 disable_irq(hdmi_msm_state->irq);
3727
3728 hdmi_msm_set_mode(FALSE);
3729 HDMI_OUTP_ND(0x0308, 0x7F); /*0b01111111*/
3730 hdmi_msm_state->hpd_initialized = FALSE;
Manoj Raoa2c27672011-08-30 17:19:39 -07003731 hdmi_msm_state->pd->cec_power(0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003732 hdmi_msm_state->pd->enable_5v(0);
3733 hdmi_msm_state->pd->core_power(0, 1);
3734 hdmi_msm_clk(0);
3735 hdmi_msm_state->hpd_initialized = FALSE;
3736}
3737
Manoj Rao668d6d52011-08-16 19:12:31 -07003738static void hdmi_msm_dump_regs(const char *prefix)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003739{
3740#ifdef REG_DUMP
3741 print_hex_dump(KERN_INFO, prefix, DUMP_PREFIX_OFFSET, 32, 4,
3742 (void *)MSM_HDMI_BASE, 0x0334, false);
3743#endif
3744}
3745
3746static int hdmi_msm_hpd_on(bool trigger_handler)
3747{
3748 static int phy_reset_done;
3749
3750 hdmi_msm_clk(1);
3751 hdmi_msm_state->pd->core_power(1, 1);
3752 hdmi_msm_state->pd->enable_5v(1);
Manoj Raoa2c27672011-08-30 17:19:39 -07003753 hdmi_msm_state->pd->cec_power(1);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003754 hdmi_msm_dump_regs("HDMI-INIT: ");
3755 hdmi_msm_set_mode(FALSE);
3756
3757 if (!phy_reset_done) {
3758 hdmi_phy_reset();
3759 phy_reset_done = 1;
3760 }
3761
3762 hdmi_msm_init_phy(external_common_state->video_resolution);
3763 /* HDMI_USEC_REFTIMER[0x0208] */
3764 HDMI_OUTP(0x0208, 0x0001001B);
3765
3766 /* Check HPD State */
3767 if (!hdmi_msm_state->hpd_initialized) {
3768 uint32 hpd_ctrl;
3769 enable_irq(hdmi_msm_state->irq);
3770
3771 /* set timeout to 4.1ms (max) for hardware debounce */
3772 hpd_ctrl = (HDMI_INP(0x0258) & ~0xFFF) | 0xFFF;
3773
3774 /* Toggle HPD circuit to trigger HPD sense */
3775 HDMI_OUTP(0x0258, ~(1 << 28) & hpd_ctrl);
3776 HDMI_OUTP(0x0258, (1 << 28) | hpd_ctrl);
3777
3778 DEV_DBG("%s: (clk, 5V, core, IRQ on) <trigger:%s>\n", __func__,
3779 trigger_handler ? "true" : "false");
3780
3781 if (trigger_handler) {
3782 /* Set HPD state machine: ensure at least 2 readouts */
3783 mutex_lock(&hdmi_msm_state_mutex);
3784 hdmi_msm_state->hpd_stable = 0;
3785 hdmi_msm_state->hpd_prev_state = TRUE;
3786 mutex_lock(&external_common_state_hpd_mutex);
3787 external_common_state->hpd_state = FALSE;
3788 mutex_unlock(&external_common_state_hpd_mutex);
3789 hdmi_msm_state->hpd_cable_chg_detected = TRUE;
3790 mutex_unlock(&hdmi_msm_state_mutex);
3791 mod_timer(&hdmi_msm_state->hpd_state_timer,
3792 jiffies + HZ/2);
3793 }
3794
3795 hdmi_msm_state->hpd_initialized = TRUE;
3796 }
3797 hdmi_msm_set_mode(TRUE);
3798
3799 return 0;
3800}
3801
3802static int hdmi_msm_power_on(struct platform_device *pdev)
3803{
3804 struct msm_fb_data_type *mfd = platform_get_drvdata(pdev);
3805 bool changed;
3806
3807 if (!hdmi_msm_state || !hdmi_msm_state->hdmi_app_clk || !MSM_HDMI_BASE)
3808 return -ENODEV;
3809#ifdef CONFIG_SUSPEND
3810 mutex_lock(&hdmi_msm_state_mutex);
3811 if (hdmi_msm_state->pm_suspended) {
3812 mutex_unlock(&hdmi_msm_state_mutex);
3813 DEV_WARN("%s: ignored, pm_suspended\n", __func__);
3814 return -ENODEV;
3815 }
3816 mutex_unlock(&hdmi_msm_state_mutex);
3817#endif
3818
3819 DEV_INFO("power: ON (%dx%d %d)\n", mfd->var_xres, mfd->var_yres,
3820 mfd->var_pixclock);
3821
3822#ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT
3823 mutex_lock(&hdmi_msm_state_mutex);
3824 if (hdmi_msm_state->hdcp_activating) {
3825 hdmi_msm_state->panel_power_on = TRUE;
3826 DEV_INFO("HDCP: activating, returning\n");
3827 }
3828 mutex_unlock(&hdmi_msm_state_mutex);
3829#endif /* CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT */
3830
3831 changed = hdmi_common_get_video_format_from_drv_data(mfd);
3832 if (!external_common_state->hpd_feature_on) {
3833 int rc = hdmi_msm_hpd_on(true);
3834 DEV_INFO("HPD: panel power without 'hpd' feature on\n");
3835 if (rc) {
3836 DEV_WARN("HPD: activation failed: rc=%d\n", rc);
3837 return rc;
3838 }
3839 }
3840 hdmi_msm_audio_info_setup(TRUE, 0, 0, FALSE);
3841
3842 mutex_lock(&external_common_state_hpd_mutex);
3843 hdmi_msm_state->panel_power_on = TRUE;
3844 if ((external_common_state->hpd_state && !hdmi_msm_is_power_on())
3845 || changed) {
3846 mutex_unlock(&external_common_state_hpd_mutex);
3847 hdmi_msm_turn_on();
3848 } else
3849 mutex_unlock(&external_common_state_hpd_mutex);
3850
3851 hdmi_msm_dump_regs("HDMI-ON: ");
3852
3853 DEV_INFO("power=%s DVI= %s\n",
3854 hdmi_msm_is_power_on() ? "ON" : "OFF" ,
3855 hdmi_msm_is_dvi_mode() ? "ON" : "OFF");
3856 return 0;
3857}
3858
3859/* Note that power-off will also be called when the cable-remove event is
3860 * processed on the user-space and as a result the framebuffer is powered
3861 * down. However, we are still required to be able to detect a cable-insert
3862 * event; so for now leave the HDMI engine running; so that the HPD IRQ is
3863 * still being processed.
3864 */
3865static int hdmi_msm_power_off(struct platform_device *pdev)
3866{
3867 if (!hdmi_msm_state->hdmi_app_clk)
3868 return -ENODEV;
3869#ifdef CONFIG_SUSPEND
3870 mutex_lock(&hdmi_msm_state_mutex);
3871 if (hdmi_msm_state->pm_suspended) {
3872 mutex_unlock(&hdmi_msm_state_mutex);
3873 DEV_WARN("%s: ignored, pm_suspended\n", __func__);
3874 return -ENODEV;
3875 }
3876 mutex_unlock(&hdmi_msm_state_mutex);
3877#endif
3878
3879#ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT
3880 mutex_lock(&hdmi_msm_state_mutex);
3881 if (hdmi_msm_state->hdcp_activating) {
3882 hdmi_msm_state->panel_power_on = FALSE;
3883 mutex_unlock(&hdmi_msm_state_mutex);
3884 DEV_INFO("HDCP: activating, returning\n");
3885 return 0;
3886 }
3887 mutex_unlock(&hdmi_msm_state_mutex);
3888#endif /* CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT */
3889
3890 DEV_INFO("power: OFF (audio off, Reset Core)\n");
3891 hdmi_msm_audio_off();
3892#ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT
3893 hdcp_deauthenticate();
3894#endif
3895 hdmi_msm_hpd_off();
3896 hdmi_msm_powerdown_phy();
3897 hdmi_msm_dump_regs("HDMI-OFF: ");
Manoj Rao53ac99d2011-10-10 17:32:28 -07003898 hdmi_msm_hpd_on(true);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003899
3900 mutex_lock(&external_common_state_hpd_mutex);
3901 if (!external_common_state->hpd_feature_on)
3902 hdmi_msm_hpd_off();
3903 mutex_unlock(&external_common_state_hpd_mutex);
3904
3905 hdmi_msm_state->panel_power_on = FALSE;
3906 return 0;
3907}
3908
3909static int __devinit hdmi_msm_probe(struct platform_device *pdev)
3910{
3911 int rc;
3912 struct platform_device *fb_dev;
3913
Stepan Moskovchenko164fe8a2011-08-05 18:10:54 -07003914 if (cpu_is_apq8064())
3915 return -ENODEV;
3916
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003917 if (!hdmi_msm_state) {
3918 pr_err("%s: hdmi_msm_state is NULL\n", __func__);
3919 return -ENOMEM;
3920 }
3921
3922 external_common_state->dev = &pdev->dev;
3923 DEV_DBG("probe\n");
3924 if (pdev->id == 0) {
3925 struct resource *res;
3926
3927 #define GET_RES(name, mode) do { \
3928 res = platform_get_resource_byname(pdev, mode, name); \
3929 if (!res) { \
3930 DEV_ERR("'" name "' resource not found\n"); \
3931 rc = -ENODEV; \
3932 goto error; \
3933 } \
3934 } while (0)
3935
3936 #define IO_REMAP(var, name) do { \
3937 GET_RES(name, IORESOURCE_MEM); \
3938 var = ioremap(res->start, resource_size(res)); \
3939 if (!var) { \
3940 DEV_ERR("'" name "' ioremap failed\n"); \
3941 rc = -ENOMEM; \
3942 goto error; \
3943 } \
3944 } while (0)
3945
3946 #define GET_IRQ(var, name) do { \
3947 GET_RES(name, IORESOURCE_IRQ); \
3948 var = res->start; \
3949 } while (0)
3950
3951 IO_REMAP(hdmi_msm_state->qfprom_io, "hdmi_msm_qfprom_addr");
3952 hdmi_msm_state->hdmi_io = MSM_HDMI_BASE;
3953 GET_IRQ(hdmi_msm_state->irq, "hdmi_msm_irq");
3954
3955 hdmi_msm_state->pd = pdev->dev.platform_data;
3956
3957 #undef GET_RES
3958 #undef IO_REMAP
3959 #undef GET_IRQ
3960 return 0;
3961 }
3962
Matt Wagantall5a4f1ba2011-08-18 18:13:03 -07003963 hdmi_msm_state->hdmi_app_clk = clk_get(&pdev->dev, "core_clk");
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003964 if (IS_ERR(hdmi_msm_state->hdmi_app_clk)) {
Matt Wagantall5a4f1ba2011-08-18 18:13:03 -07003965 DEV_ERR("'core_clk' clk not found\n");
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003966 rc = IS_ERR(hdmi_msm_state->hdmi_app_clk);
3967 goto error;
3968 }
3969
Matt Wagantall5a4f1ba2011-08-18 18:13:03 -07003970 hdmi_msm_state->hdmi_m_pclk = clk_get(&pdev->dev, "master_iface_clk");
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003971 if (IS_ERR(hdmi_msm_state->hdmi_m_pclk)) {
Matt Wagantall5a4f1ba2011-08-18 18:13:03 -07003972 DEV_ERR("'master_iface_clk' clk not found\n");
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003973 rc = IS_ERR(hdmi_msm_state->hdmi_m_pclk);
3974 goto error;
3975 }
3976
Matt Wagantall5a4f1ba2011-08-18 18:13:03 -07003977 hdmi_msm_state->hdmi_s_pclk = clk_get(&pdev->dev, "slave_iface_clk");
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003978 if (IS_ERR(hdmi_msm_state->hdmi_s_pclk)) {
Matt Wagantall5a4f1ba2011-08-18 18:13:03 -07003979 DEV_ERR("'slave_iface_clk' clk not found\n");
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003980 rc = IS_ERR(hdmi_msm_state->hdmi_s_pclk);
3981 goto error;
3982 }
3983
3984 rc = check_hdmi_features();
3985 if (rc) {
3986 DEV_ERR("Init FAILED: check_hdmi_features rc=%d\n", rc);
3987 goto error;
3988 }
3989
3990 if (!hdmi_msm_state->pd->core_power) {
3991 DEV_ERR("Init FAILED: core_power function missing\n");
3992 rc = -ENODEV;
3993 goto error;
3994 }
3995 if (!hdmi_msm_state->pd->enable_5v) {
3996 DEV_ERR("Init FAILED: enable_5v function missing\n");
3997 rc = -ENODEV;
3998 goto error;
3999 }
4000
Manoj Raoa2c27672011-08-30 17:19:39 -07004001 if (!hdmi_msm_state->pd->cec_power) {
4002 DEV_ERR("Init FAILED: cec_power function missing\n");
4003 rc = -ENODEV;
4004 goto error;
4005 }
4006
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004007 rc = request_threaded_irq(hdmi_msm_state->irq, NULL, &hdmi_msm_isr,
4008 IRQF_TRIGGER_HIGH | IRQF_ONESHOT, "hdmi_msm_isr", NULL);
4009 if (rc) {
4010 DEV_ERR("Init FAILED: IRQ request, rc=%d\n", rc);
4011 goto error;
4012 }
4013 disable_irq(hdmi_msm_state->irq);
4014
4015 init_timer(&hdmi_msm_state->hpd_state_timer);
4016 hdmi_msm_state->hpd_state_timer.function =
4017 hdmi_msm_hpd_state_timer;
4018 hdmi_msm_state->hpd_state_timer.data = (uint32)NULL;
4019
4020 hdmi_msm_state->hpd_state_timer.expires = 0xffffffffL;
4021 add_timer(&hdmi_msm_state->hpd_state_timer);
4022
4023#ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT
4024 init_timer(&hdmi_msm_state->hdcp_timer);
4025 hdmi_msm_state->hdcp_timer.function =
4026 hdmi_msm_hdcp_timer;
4027 hdmi_msm_state->hdcp_timer.data = (uint32)NULL;
4028
4029 hdmi_msm_state->hdcp_timer.expires = 0xffffffffL;
4030 add_timer(&hdmi_msm_state->hdcp_timer);
4031#endif /* CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT */
4032
4033 fb_dev = msm_fb_add_device(pdev);
4034 if (fb_dev) {
4035 rc = external_common_state_create(fb_dev);
4036 if (rc) {
4037 DEV_ERR("Init FAILED: hdmi_msm_state_create, rc=%d\n",
4038 rc);
4039 goto error;
4040 }
4041 } else
4042 DEV_ERR("Init FAILED: failed to add fb device\n");
4043
4044 DEV_INFO("HDMI HPD: ON\n");
4045
4046 rc = hdmi_msm_hpd_on(true);
4047 if (rc)
4048 goto error;
4049
4050 if (hdmi_msm_has_hdcp())
4051 external_common_state->present_hdcp = TRUE;
4052 else {
4053 external_common_state->present_hdcp = FALSE;
4054#ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT
4055 /*
4056 * If the device is not hdcp capable do
4057 * not start hdcp timer.
4058 */
4059 del_timer(&hdmi_msm_state->hdcp_timer);
4060#endif
4061 }
4062
4063 queue_work(hdmi_work_queue, &hdmi_msm_state->hpd_read_work);
4064 return 0;
4065
4066error:
4067 if (hdmi_msm_state->qfprom_io)
4068 iounmap(hdmi_msm_state->qfprom_io);
4069 hdmi_msm_state->qfprom_io = NULL;
4070
4071 if (hdmi_msm_state->hdmi_io)
4072 iounmap(hdmi_msm_state->hdmi_io);
4073 hdmi_msm_state->hdmi_io = NULL;
4074
4075 external_common_state_remove();
4076
4077 if (hdmi_msm_state->hdmi_app_clk)
4078 clk_put(hdmi_msm_state->hdmi_app_clk);
4079 if (hdmi_msm_state->hdmi_m_pclk)
4080 clk_put(hdmi_msm_state->hdmi_m_pclk);
4081 if (hdmi_msm_state->hdmi_s_pclk)
4082 clk_put(hdmi_msm_state->hdmi_s_pclk);
4083
4084 hdmi_msm_state->hdmi_app_clk = NULL;
4085 hdmi_msm_state->hdmi_m_pclk = NULL;
4086 hdmi_msm_state->hdmi_s_pclk = NULL;
4087
4088 return rc;
4089}
4090
4091static int __devexit hdmi_msm_remove(struct platform_device *pdev)
4092{
4093 DEV_INFO("HDMI device: remove\n");
4094
4095 DEV_INFO("HDMI HPD: OFF\n");
4096 hdmi_msm_hpd_off();
4097 free_irq(hdmi_msm_state->irq, NULL);
4098
4099 if (hdmi_msm_state->qfprom_io)
4100 iounmap(hdmi_msm_state->qfprom_io);
4101 hdmi_msm_state->qfprom_io = NULL;
4102
4103 if (hdmi_msm_state->hdmi_io)
4104 iounmap(hdmi_msm_state->hdmi_io);
4105 hdmi_msm_state->hdmi_io = NULL;
4106
4107 external_common_state_remove();
4108
4109 if (hdmi_msm_state->hdmi_app_clk)
4110 clk_put(hdmi_msm_state->hdmi_app_clk);
4111 if (hdmi_msm_state->hdmi_m_pclk)
4112 clk_put(hdmi_msm_state->hdmi_m_pclk);
4113 if (hdmi_msm_state->hdmi_s_pclk)
4114 clk_put(hdmi_msm_state->hdmi_s_pclk);
4115
4116 hdmi_msm_state->hdmi_app_clk = NULL;
4117 hdmi_msm_state->hdmi_m_pclk = NULL;
4118 hdmi_msm_state->hdmi_s_pclk = NULL;
4119
4120 kfree(hdmi_msm_state);
4121 hdmi_msm_state = NULL;
4122
4123 return 0;
4124}
4125
4126static int hdmi_msm_hpd_feature(int on)
4127{
4128 int rc = 0;
4129
4130 DEV_INFO("%s: %d\n", __func__, on);
4131 if (on)
4132 rc = hdmi_msm_hpd_on(true);
4133 else
4134 hdmi_msm_hpd_off();
4135
4136 return rc;
4137}
4138
4139
4140#ifdef CONFIG_SUSPEND
4141static int hdmi_msm_device_pm_suspend(struct device *dev)
4142{
4143 mutex_lock(&hdmi_msm_state_mutex);
4144 if (hdmi_msm_state->pm_suspended) {
4145 mutex_unlock(&hdmi_msm_state_mutex);
4146 return 0;
4147 }
4148
4149 DEV_DBG("pm_suspend\n");
4150
4151 del_timer(&hdmi_msm_state->hpd_state_timer);
4152#ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT
4153 del_timer(&hdmi_msm_state->hdcp_timer);
4154#endif /* CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT */
4155
4156 disable_irq(hdmi_msm_state->irq);
Ravishangar Kalyanam18337542011-08-12 10:26:35 -07004157 if (external_common_state->hpd_feature_on)
4158 hdmi_msm_clk(0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004159
4160 hdmi_msm_state->pm_suspended = TRUE;
4161 mutex_unlock(&hdmi_msm_state_mutex);
4162
4163 hdmi_msm_powerdown_phy();
4164 hdmi_msm_state->pd->enable_5v(0);
4165 hdmi_msm_state->pd->core_power(0, 1);
4166 return 0;
4167}
4168
4169static int hdmi_msm_device_pm_resume(struct device *dev)
4170{
4171 mutex_lock(&hdmi_msm_state_mutex);
4172 if (!hdmi_msm_state->pm_suspended) {
4173 mutex_unlock(&hdmi_msm_state_mutex);
4174 return 0;
4175 }
4176
4177 DEV_DBG("pm_resume\n");
4178
4179 hdmi_msm_state->pd->core_power(1, 1);
4180 hdmi_msm_state->pd->enable_5v(1);
Ravishangar Kalyanam18337542011-08-12 10:26:35 -07004181 if (external_common_state->hpd_feature_on)
4182 hdmi_msm_clk(1);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004183
4184 hdmi_msm_state->pm_suspended = FALSE;
4185 mutex_unlock(&hdmi_msm_state_mutex);
4186 enable_irq(hdmi_msm_state->irq);
4187 return 0;
4188}
4189#else
4190#define hdmi_msm_device_pm_suspend NULL
4191#define hdmi_msm_device_pm_resume NULL
4192#endif
4193
4194static const struct dev_pm_ops hdmi_msm_device_pm_ops = {
4195 .suspend = hdmi_msm_device_pm_suspend,
4196 .resume = hdmi_msm_device_pm_resume,
4197};
4198
4199static struct platform_driver this_driver = {
4200 .probe = hdmi_msm_probe,
4201 .remove = hdmi_msm_remove,
4202 .driver.name = "hdmi_msm",
4203 .driver.pm = &hdmi_msm_device_pm_ops,
4204};
4205
4206static struct msm_fb_panel_data hdmi_msm_panel_data = {
4207 .on = hdmi_msm_power_on,
4208 .off = hdmi_msm_power_off,
4209};
4210
4211static struct platform_device this_device = {
4212 .name = "hdmi_msm",
4213 .id = 1,
4214 .dev.platform_data = &hdmi_msm_panel_data,
4215};
4216
4217static int __init hdmi_msm_init(void)
4218{
4219 int rc;
4220
Ravishangar Kalyanamc719c542011-07-28 16:49:25 -07004221 if (msm_fb_detect_client("hdmi_msm"))
4222 return 0;
4223
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004224 hdmi_msm_setup_video_mode_lut();
4225 hdmi_msm_state = kzalloc(sizeof(*hdmi_msm_state), GFP_KERNEL);
4226 if (!hdmi_msm_state) {
4227 pr_err("hdmi_msm_init FAILED: out of memory\n");
4228 rc = -ENOMEM;
4229 goto init_exit;
4230 }
4231
4232 external_common_state = &hdmi_msm_state->common;
4233 external_common_state->video_resolution = HDMI_VFRMT_1920x1080p60_16_9;
4234#ifdef CONFIG_FB_MSM_HDMI_3D
4235 external_common_state->switch_3d = hdmi_msm_switch_3d;
4236#endif
4237
Manoj Raoa2c27672011-08-30 17:19:39 -07004238#ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_CEC_SUPPORT
4239 hdmi_msm_state->cec_queue_start =
4240 kzalloc(sizeof(struct hdmi_msm_cec_msg)*CEC_QUEUE_SIZE,
4241 GFP_KERNEL);
4242 if (!hdmi_msm_state->cec_queue_start) {
4243 pr_err("hdmi_msm_init FAILED: CEC queue out of memory\n");
4244 rc = -ENOMEM;
4245 goto init_exit;
4246 }
4247
4248 hdmi_msm_state->cec_queue_wr = hdmi_msm_state->cec_queue_start;
4249 hdmi_msm_state->cec_queue_rd = hdmi_msm_state->cec_queue_start;
4250 hdmi_msm_state->cec_queue_full = false;
4251#endif
4252
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004253 /*
4254 * Create your work queue
4255 * allocs and returns ptr
4256 */
4257 hdmi_work_queue = create_workqueue("hdmi_hdcp");
4258 external_common_state->hpd_feature = hdmi_msm_hpd_feature;
4259
4260 rc = platform_driver_register(&this_driver);
4261 if (rc) {
4262 pr_err("hdmi_msm_init FAILED: platform_driver_register rc=%d\n",
4263 rc);
4264 goto init_exit;
4265 }
4266
4267 hdmi_common_init_panel_info(&hdmi_msm_panel_data.panel_info);
4268 init_completion(&hdmi_msm_state->ddc_sw_done);
4269 INIT_WORK(&hdmi_msm_state->hpd_state_work, hdmi_msm_hpd_state_work);
4270 INIT_WORK(&hdmi_msm_state->hpd_read_work, hdmi_msm_hpd_read_work);
4271#ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT
4272 init_completion(&hdmi_msm_state->hdcp_success_done);
4273 INIT_WORK(&hdmi_msm_state->hdcp_reauth_work, hdmi_msm_hdcp_reauth_work);
4274 INIT_WORK(&hdmi_msm_state->hdcp_work, hdmi_msm_hdcp_work);
4275#endif /* CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT */
4276
Manoj Raoa2c27672011-08-30 17:19:39 -07004277#ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_CEC_SUPPORT
4278 init_completion(&hdmi_msm_state->cec_frame_wr_done);
4279#endif
4280
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004281 rc = platform_device_register(&this_device);
4282 if (rc) {
4283 pr_err("hdmi_msm_init FAILED: platform_device_register rc=%d\n",
4284 rc);
4285 platform_driver_unregister(&this_driver);
4286 goto init_exit;
4287 }
4288
4289 pr_debug("%s: success:"
4290#ifdef DEBUG
4291 " DEBUG"
4292#else
4293 " RELEASE"
4294#endif
4295 " AUDIO EDID HPD HDCP"
4296#ifndef CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT
4297 ":0"
4298#endif /* CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT */
4299 " DVI"
4300#ifndef CONFIG_FB_MSM_HDMI_MSM_PANEL_DVI_SUPPORT
4301 ":0"
4302#endif /* CONFIG_FB_MSM_HDMI_MSM_PANEL_DVI_SUPPORT */
4303 "\n", __func__);
4304
4305 return 0;
4306
4307init_exit:
4308 kfree(hdmi_msm_state);
4309 hdmi_msm_state = NULL;
4310
4311 return rc;
4312}
4313
4314static void __exit hdmi_msm_exit(void)
4315{
4316 platform_device_unregister(&this_device);
4317 platform_driver_unregister(&this_driver);
4318}
4319
4320module_init(hdmi_msm_init);
4321module_exit(hdmi_msm_exit);
4322
4323MODULE_LICENSE("GPL v2");
4324MODULE_VERSION("0.3");
4325MODULE_AUTHOR("Qualcomm Innovation Center, Inc.");
4326MODULE_DESCRIPTION("HDMI MSM TX driver");