blob: 63c21474d7d42da0215e9af26427cfefaf6f9d86 [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
1234 /* 0x0224 HDMI_DDC_SETUP */
1235 HDMI_OUTP_ND(0x0224, 0);
1236
1237 /* 0x027C HDMI_DDC_REF
1238 [6] REFTIMER_ENABLE Enable the timer
1239 * 0: Disable
1240 * 1: Enable
1241 [15:0] REFTIMER Value to set the register in order to generate
1242 DDC strobe. This register counts on HDCP application clock */
1243 /* Enable reference timer
1244 * 27 micro-seconds */
1245 HDMI_OUTP_ND(0x027C, (1 << 16) | (27 << 0));
1246}
1247
1248static int hdmi_msm_ddc_clear_irq(const char *what)
1249{
1250 const uint32 time_out = 0xFFFF;
1251 uint32 time_out_count, reg_val;
1252
1253 /* clear pending and enable interrupt */
1254 time_out_count = time_out;
1255 do {
1256 --time_out_count;
1257 /* HDMI_DDC_INT_CTRL[0x0214]
1258 [2] SW_DONE_MK Mask bit for SW_DONE_INT. Set to 1 to enable
1259 interrupt.
1260 [1] SW_DONE_ACK WRITE ONLY. Acknowledge bit for SW_DONE_INT.
1261 Write 1 to clear interrupt.
1262 [0] SW_DONE_INT READ ONLY. SW_DONE interrupt status */
1263 /* Clear and Enable DDC interrupt */
1264 /* Write */
1265 HDMI_OUTP_ND(0x0214, (1 << 2) | (1 << 1));
1266 /* Read back */
1267 reg_val = HDMI_INP_ND(0x0214);
1268 } while ((reg_val & 0x1) && time_out_count);
1269 if (!time_out_count) {
1270 DEV_ERR("%s[%s]: timedout\n", __func__, what);
1271 return -ETIMEDOUT;
1272 }
1273
1274 return 0;
1275}
1276
1277#ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT
1278static int hdmi_msm_ddc_write(uint32 dev_addr, uint32 offset,
1279 const uint8 *data_buf, uint32 data_len, const char *what)
1280{
1281 uint32 reg_val, ndx;
1282 int status = 0, retry = 10;
1283 uint32 time_out_count;
1284
1285 if (NULL == data_buf) {
1286 status = -EINVAL;
1287 DEV_ERR("%s[%s]: invalid input paramter\n", __func__, what);
1288 goto error;
1289 }
1290
1291again:
1292 status = hdmi_msm_ddc_clear_irq(what);
1293 if (status)
1294 goto error;
1295
1296 /* Ensure Device Address has LSB set to 0 to indicate Slave addr read */
1297 dev_addr &= 0xFE;
1298
1299 /* 0x0238 HDMI_DDC_DATA
1300 [31] INDEX_WRITE WRITE ONLY. To write index field, set this bit to
1301 1 while writing HDMI_DDC_DATA.
1302 [23:16] INDEX Use to set index into DDC buffer for next read or
1303 current write, or to read index of current read or next write.
1304 Writable only when INDEX_WRITE=1.
1305 [15:8] DATA Use to fill or read the DDC buffer
1306 [0] DATA_RW Select whether buffer access will be a read or write.
1307 For writes, address auto-increments on write to HDMI_DDC_DATA.
1308 For reads, address autoincrements on reads to HDMI_DDC_DATA.
1309 * 0: Write
1310 * 1: Read */
1311
1312 /* 1. Write to HDMI_I2C_DATA with the following fields set in order to
1313 * handle portion #1
1314 * DATA_RW = 0x1 (write)
1315 * DATA = linkAddress (primary link address and writing)
1316 * INDEX = 0x0 (initial offset into buffer)
1317 * INDEX_WRITE = 0x1 (setting initial offset) */
1318 HDMI_OUTP_ND(0x0238, (0x1UL << 31) | (dev_addr << 8));
1319
1320 /* 2. Write to HDMI_I2C_DATA with the following fields set in order to
1321 * handle portion #2
1322 * DATA_RW = 0x0 (write)
1323 * DATA = offsetAddress
1324 * INDEX = 0x0
1325 * INDEX_WRITE = 0x0 (auto-increment by hardware) */
1326 HDMI_OUTP_ND(0x0238, offset << 8);
1327
1328 /* 3. Write to HDMI_I2C_DATA with the following fields set in order to
1329 * handle portion #3
1330 * DATA_RW = 0x0 (write)
1331 * DATA = data_buf[ndx]
1332 * INDEX = 0x0
1333 * INDEX_WRITE = 0x0 (auto-increment by hardware) */
1334 for (ndx = 0; ndx < data_len; ++ndx)
1335 HDMI_OUTP_ND(0x0238, ((uint32)data_buf[ndx]) << 8);
1336
1337 /* Data setup is complete, now setup the transaction characteristics */
1338
1339 /* 0x0228 HDMI_DDC_TRANS0
1340 [23:16] CNT0 Byte count for first transaction (excluding the first
1341 byte, which is usually the address).
1342 [13] STOP0 Determines whether a stop bit will be sent after the first
1343 transaction
1344 * 0: NO STOP
1345 * 1: STOP
1346 [12] START0 Determines whether a start bit will be sent before the
1347 first transaction
1348 * 0: NO START
1349 * 1: START
1350 [8] STOP_ON_NACK0 Determines whether the current transfer will stop
1351 if a NACK is received during the first transaction (current
1352 transaction always stops).
1353 * 0: STOP CURRENT TRANSACTION, GO TO NEXT TRANSACTION
1354 * 1: STOP ALL TRANSACTIONS, SEND STOP BIT
1355 [0] RW0 Read/write indicator for first transaction - set to 0 for
1356 write, 1 for read. This bit only controls HDMI_DDC behaviour -
1357 the R/W bit in the transaction is programmed into the DDC buffer
1358 as the LSB of the address byte.
1359 * 0: WRITE
1360 * 1: READ */
1361
1362 /* 4. Write to HDMI_I2C_TRANSACTION0 with the following fields set in
1363 order to handle characteristics of portion #1 and portion #2
1364 * RW0 = 0x0 (write)
1365 * START0 = 0x1 (insert START bit)
1366 * STOP0 = 0x0 (do NOT insert STOP bit)
1367 * CNT0 = 0x1 (single byte transaction excluding address) */
1368 HDMI_OUTP_ND(0x0228, (1 << 12) | (1 << 16));
1369
1370 /* 0x022C HDMI_DDC_TRANS1
1371 [23:16] CNT1 Byte count for second transaction (excluding the first
1372 byte, which is usually the address).
1373 [13] STOP1 Determines whether a stop bit will be sent after the second
1374 transaction
1375 * 0: NO STOP
1376 * 1: STOP
1377 [12] START1 Determines whether a start bit will be sent before the
1378 second transaction
1379 * 0: NO START
1380 * 1: START
1381 [8] STOP_ON_NACK1 Determines whether the current transfer will stop if
1382 a NACK is received during the second transaction (current
1383 transaction always stops).
1384 * 0: STOP CURRENT TRANSACTION, GO TO NEXT TRANSACTION
1385 * 1: STOP ALL TRANSACTIONS, SEND STOP BIT
1386 [0] RW1 Read/write indicator for second transaction - set to 0 for
1387 write, 1 for read. This bit only controls HDMI_DDC behaviour -
1388 the R/W bit in the transaction is programmed into the DDC buffer
1389 as the LSB of the address byte.
1390 * 0: WRITE
1391 * 1: READ */
1392
1393 /* 5. Write to HDMI_I2C_TRANSACTION1 with the following fields set in
1394 order to handle characteristics of portion #3
1395 * RW1 = 0x1 (read)
1396 * START1 = 0x1 (insert START bit)
1397 * STOP1 = 0x1 (insert STOP bit)
1398 * CNT1 = data_len (0xN (write N bytes of data))
1399 * Byte count for second transition (excluding the first
1400 * Byte which is usually the address) */
1401 HDMI_OUTP_ND(0x022C, (1 << 13) | ((data_len-1) << 16));
1402
1403 /* Trigger the I2C transfer */
1404 /* 0x020C HDMI_DDC_CTRL
1405 [21:20] TRANSACTION_CNT
1406 Number of transactions to be done in current transfer.
1407 * 0x0: transaction0 only
1408 * 0x1: transaction0, transaction1
1409 * 0x2: transaction0, transaction1, transaction2
1410 * 0x3: transaction0, transaction1, transaction2, transaction3
1411 [3] SW_STATUS_RESET
1412 Write 1 to reset HDMI_DDC_SW_STATUS flags, will reset SW_DONE,
1413 ABORTED, TIMEOUT, SW_INTERRUPTED, BUFFER_OVERFLOW,
1414 STOPPED_ON_NACK, NACK0, NACK1, NACK2, NACK3
1415 [2] SEND_RESET Set to 1 to send reset sequence (9 clocks with no
1416 data) at start of transfer. This sequence is sent after GO is
1417 written to 1, before the first transaction only.
1418 [1] SOFT_RESET Write 1 to reset DDC controller
1419 [0] GO WRITE ONLY. Write 1 to start DDC transfer. */
1420
1421 /* 6. Write to HDMI_I2C_CONTROL to kick off the hardware.
1422 * Note that NOTHING has been transmitted on the DDC lines up to this
1423 * point.
1424 * TRANSACTION_CNT = 0x1 (execute transaction0 followed by
1425 * transaction1)
1426 * GO = 0x1 (kicks off hardware) */
1427 INIT_COMPLETION(hdmi_msm_state->ddc_sw_done);
1428 HDMI_OUTP_ND(0x020C, (1 << 0) | (1 << 20));
1429
1430 time_out_count = wait_for_completion_interruptible_timeout(
1431 &hdmi_msm_state->ddc_sw_done, HZ/2);
1432 HDMI_OUTP_ND(0x0214, 0x2);
1433 if (!time_out_count) {
1434 if (retry-- > 0) {
1435 DEV_INFO("%s[%s]: failed timout, retry=%d\n", __func__,
1436 what, retry);
1437 goto again;
1438 }
1439 status = -ETIMEDOUT;
1440 DEV_ERR("%s[%s]: timedout, DDC SW Status=%08x, HW "
1441 "Status=%08x, Int Ctrl=%08x\n", __func__, what,
1442 HDMI_INP_ND(0x0218), HDMI_INP_ND(0x021C),
1443 HDMI_INP_ND(0x0214));
1444 goto error;
1445 }
1446
1447 /* Read DDC status */
1448 reg_val = HDMI_INP_ND(0x0218);
1449 reg_val &= 0x00001000 | 0x00002000 | 0x00004000 | 0x00008000;
1450
1451 /* Check if any NACK occurred */
1452 if (reg_val) {
1453 if (retry > 1)
1454 HDMI_OUTP_ND(0x020C, BIT(3)); /* SW_STATUS_RESET */
1455 else
1456 HDMI_OUTP_ND(0x020C, BIT(1)); /* SOFT_RESET */
1457 if (retry-- > 0) {
1458 DEV_DBG("%s[%s]: failed NACK=%08x, retry=%d\n",
1459 __func__, what, reg_val, retry);
1460 msleep(100);
1461 goto again;
1462 }
1463 status = -EIO;
1464 DEV_ERR("%s[%s]: failed NACK: %08x\n", __func__, what, reg_val);
1465 goto error;
1466 }
1467
1468 DEV_DBG("%s[%s] success\n", __func__, what);
1469
1470error:
1471 return status;
1472}
1473#endif /* CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT */
1474
1475static int hdmi_msm_ddc_read_retry(uint32 dev_addr, uint32 offset,
1476 uint8 *data_buf, uint32 data_len, uint32 request_len, int retry,
1477 const char *what)
1478{
1479 uint32 reg_val, ndx;
1480 int status = 0;
1481 uint32 time_out_count;
1482 int log_retry_fail = retry != 1;
1483
1484 if (NULL == data_buf) {
1485 status = -EINVAL;
1486 DEV_ERR("%s: invalid input paramter\n", __func__);
1487 goto error;
1488 }
1489
1490again:
1491 status = hdmi_msm_ddc_clear_irq(what);
1492 if (status)
1493 goto error;
1494
1495 /* Ensure Device Address has LSB set to 0 to indicate Slave addr read */
1496 dev_addr &= 0xFE;
1497
1498 /* 0x0238 HDMI_DDC_DATA
1499 [31] INDEX_WRITE WRITE ONLY. To write index field, set this bit to
1500 1 while writing HDMI_DDC_DATA.
1501 [23:16] INDEX Use to set index into DDC buffer for next read or
1502 current write, or to read index of current read or next write.
1503 Writable only when INDEX_WRITE=1.
1504 [15:8] DATA Use to fill or read the DDC buffer
1505 [0] DATA_RW Select whether buffer access will be a read or write.
1506 For writes, address auto-increments on write to HDMI_DDC_DATA.
1507 For reads, address autoincrements on reads to HDMI_DDC_DATA.
1508 * 0: Write
1509 * 1: Read */
1510
1511 /* 1. Write to HDMI_I2C_DATA with the following fields set in order to
1512 * handle portion #1
1513 * DATA_RW = 0x0 (write)
1514 * DATA = linkAddress (primary link address and writing)
1515 * INDEX = 0x0 (initial offset into buffer)
1516 * INDEX_WRITE = 0x1 (setting initial offset) */
1517 HDMI_OUTP_ND(0x0238, (0x1UL << 31) | (dev_addr << 8));
1518
1519 /* 2. Write to HDMI_I2C_DATA with the following fields set in order to
1520 * handle portion #2
1521 * DATA_RW = 0x0 (write)
1522 * DATA = offsetAddress
1523 * INDEX = 0x0
1524 * INDEX_WRITE = 0x0 (auto-increment by hardware) */
1525 HDMI_OUTP_ND(0x0238, offset << 8);
1526
1527 /* 3. Write to HDMI_I2C_DATA with the following fields set in order to
1528 * handle portion #3
1529 * DATA_RW = 0x0 (write)
1530 * DATA = linkAddress + 1 (primary link address 0x74 and reading)
1531 * INDEX = 0x0
1532 * INDEX_WRITE = 0x0 (auto-increment by hardware) */
1533 HDMI_OUTP_ND(0x0238, (dev_addr | 1) << 8);
1534
1535 /* Data setup is complete, now setup the transaction characteristics */
1536
1537 /* 0x0228 HDMI_DDC_TRANS0
1538 [23:16] CNT0 Byte count for first transaction (excluding the first
1539 byte, which is usually the address).
1540 [13] STOP0 Determines whether a stop bit will be sent after the first
1541 transaction
1542 * 0: NO STOP
1543 * 1: STOP
1544 [12] START0 Determines whether a start bit will be sent before the
1545 first transaction
1546 * 0: NO START
1547 * 1: START
1548 [8] STOP_ON_NACK0 Determines whether the current transfer will stop
1549 if a NACK is received during the first transaction (current
1550 transaction always stops).
1551 * 0: STOP CURRENT TRANSACTION, GO TO NEXT TRANSACTION
1552 * 1: STOP ALL TRANSACTIONS, SEND STOP BIT
1553 [0] RW0 Read/write indicator for first transaction - set to 0 for
1554 write, 1 for read. This bit only controls HDMI_DDC behaviour -
1555 the R/W bit in the transaction is programmed into the DDC buffer
1556 as the LSB of the address byte.
1557 * 0: WRITE
1558 * 1: READ */
1559
1560 /* 4. Write to HDMI_I2C_TRANSACTION0 with the following fields set in
1561 order to handle characteristics of portion #1 and portion #2
1562 * RW0 = 0x0 (write)
1563 * START0 = 0x1 (insert START bit)
1564 * STOP0 = 0x0 (do NOT insert STOP bit)
1565 * CNT0 = 0x1 (single byte transaction excluding address) */
1566 HDMI_OUTP_ND(0x0228, (1 << 12) | (1 << 16));
1567
1568 /* 0x022C HDMI_DDC_TRANS1
1569 [23:16] CNT1 Byte count for second transaction (excluding the first
1570 byte, which is usually the address).
1571 [13] STOP1 Determines whether a stop bit will be sent after the second
1572 transaction
1573 * 0: NO STOP
1574 * 1: STOP
1575 [12] START1 Determines whether a start bit will be sent before the
1576 second transaction
1577 * 0: NO START
1578 * 1: START
1579 [8] STOP_ON_NACK1 Determines whether the current transfer will stop if
1580 a NACK is received during the second transaction (current
1581 transaction always stops).
1582 * 0: STOP CURRENT TRANSACTION, GO TO NEXT TRANSACTION
1583 * 1: STOP ALL TRANSACTIONS, SEND STOP BIT
1584 [0] RW1 Read/write indicator for second transaction - set to 0 for
1585 write, 1 for read. This bit only controls HDMI_DDC behaviour -
1586 the R/W bit in the transaction is programmed into the DDC buffer
1587 as the LSB of the address byte.
1588 * 0: WRITE
1589 * 1: READ */
1590
1591 /* 5. Write to HDMI_I2C_TRANSACTION1 with the following fields set in
1592 order to handle characteristics of portion #3
1593 * RW1 = 0x1 (read)
1594 * START1 = 0x1 (insert START bit)
1595 * STOP1 = 0x1 (insert STOP bit)
1596 * CNT1 = data_len (it's 128 (0x80) for a blk read) */
1597 HDMI_OUTP_ND(0x022C, 1 | (1 << 12) | (1 << 13) | (request_len << 16));
1598
1599 /* Trigger the I2C transfer */
1600 /* 0x020C HDMI_DDC_CTRL
1601 [21:20] TRANSACTION_CNT
1602 Number of transactions to be done in current transfer.
1603 * 0x0: transaction0 only
1604 * 0x1: transaction0, transaction1
1605 * 0x2: transaction0, transaction1, transaction2
1606 * 0x3: transaction0, transaction1, transaction2, transaction3
1607 [3] SW_STATUS_RESET
1608 Write 1 to reset HDMI_DDC_SW_STATUS flags, will reset SW_DONE,
1609 ABORTED, TIMEOUT, SW_INTERRUPTED, BUFFER_OVERFLOW,
1610 STOPPED_ON_NACK, NACK0, NACK1, NACK2, NACK3
1611 [2] SEND_RESET Set to 1 to send reset sequence (9 clocks with no
1612 data) at start of transfer. This sequence is sent after GO is
1613 written to 1, before the first transaction only.
1614 [1] SOFT_RESET Write 1 to reset DDC controller
1615 [0] GO WRITE ONLY. Write 1 to start DDC transfer. */
1616
1617 /* 6. Write to HDMI_I2C_CONTROL to kick off the hardware.
1618 * Note that NOTHING has been transmitted on the DDC lines up to this
1619 * point.
1620 * TRANSACTION_CNT = 0x1 (execute transaction0 followed by
1621 * transaction1)
1622 * SEND_RESET = Set to 1 to send reset sequence
1623 * GO = 0x1 (kicks off hardware) */
1624 INIT_COMPLETION(hdmi_msm_state->ddc_sw_done);
1625 HDMI_OUTP_ND(0x020C, (1 << 0) | (1 << 20));
1626
1627 time_out_count = wait_for_completion_interruptible_timeout(
1628 &hdmi_msm_state->ddc_sw_done, HZ/2);
1629 HDMI_OUTP_ND(0x0214, 0x2);
1630 if (!time_out_count) {
1631 if (retry-- > 0) {
1632 DEV_INFO("%s: failed timout, retry=%d\n", __func__,
1633 retry);
1634 goto again;
1635 }
1636 status = -ETIMEDOUT;
1637 DEV_ERR("%s: timedout(7), DDC SW Status=%08x, HW "
1638 "Status=%08x, Int Ctrl=%08x\n", __func__,
1639 HDMI_INP(0x0218), HDMI_INP(0x021C), HDMI_INP(0x0214));
1640 goto error;
1641 }
1642
1643 /* Read DDC status */
1644 reg_val = HDMI_INP_ND(0x0218);
1645 reg_val &= 0x00001000 | 0x00002000 | 0x00004000 | 0x00008000;
1646
1647 /* Check if any NACK occurred */
1648 if (reg_val) {
1649 HDMI_OUTP_ND(0x020C, BIT(3)); /* SW_STATUS_RESET */
1650 if (retry == 1)
1651 HDMI_OUTP_ND(0x020C, BIT(1)); /* SOFT_RESET */
1652 if (retry-- > 0) {
1653 DEV_DBG("%s(%s): failed NACK=0x%08x, retry=%d, "
1654 "dev-addr=0x%02x, offset=0x%02x, "
1655 "length=%d\n", __func__, what,
1656 reg_val, retry, dev_addr,
1657 offset, data_len);
1658 goto again;
1659 }
1660 status = -EIO;
1661 if (log_retry_fail)
1662 DEV_ERR("%s(%s): failed NACK=0x%08x, dev-addr=0x%02x, "
1663 "offset=0x%02x, length=%d\n", __func__, what,
1664 reg_val, dev_addr, offset, data_len);
1665 goto error;
1666 }
1667
1668 /* 0x0238 HDMI_DDC_DATA
1669 [31] INDEX_WRITE WRITE ONLY. To write index field, set this bit to 1
1670 while writing HDMI_DDC_DATA.
1671 [23:16] INDEX Use to set index into DDC buffer for next read or
1672 current write, or to read index of current read or next write.
1673 Writable only when INDEX_WRITE=1.
1674 [15:8] DATA Use to fill or read the DDC buffer
1675 [0] DATA_RW Select whether buffer access will be a read or write.
1676 For writes, address auto-increments on write to HDMI_DDC_DATA.
1677 For reads, address autoincrements on reads to HDMI_DDC_DATA.
1678 * 0: Write
1679 * 1: Read */
1680
1681 /* 8. ALL data is now available and waiting in the DDC buffer.
1682 * Read HDMI_I2C_DATA with the following fields set
1683 * RW = 0x1 (read)
1684 * DATA = BCAPS (this is field where data is pulled from)
1685 * INDEX = 0x3 (where the data has been placed in buffer by hardware)
1686 * INDEX_WRITE = 0x1 (explicitly define offset) */
1687 /* Write this data to DDC buffer */
1688 HDMI_OUTP_ND(0x0238, 0x1 | (3 << 16) | (1 << 31));
1689
1690 /* Discard first byte */
1691 HDMI_INP_ND(0x0238);
1692 for (ndx = 0; ndx < data_len; ++ndx) {
1693 reg_val = HDMI_INP_ND(0x0238);
1694 data_buf[ndx] = (uint8) ((reg_val & 0x0000FF00) >> 8);
1695 }
1696
1697 DEV_DBG("%s[%s] success\n", __func__, what);
1698
1699error:
1700 return status;
1701}
1702
1703static int hdmi_msm_ddc_read_edid_seg(uint32 dev_addr, uint32 offset,
1704 uint8 *data_buf, uint32 data_len, uint32 request_len, int retry,
1705 const char *what)
1706{
1707 uint32 reg_val, ndx;
1708 int status = 0;
1709 uint32 time_out_count;
1710 int log_retry_fail = retry != 1;
1711 int seg_addr = 0x60, seg_num = 0x01;
1712
1713 if (NULL == data_buf) {
1714 status = -EINVAL;
1715 DEV_ERR("%s: invalid input paramter\n", __func__);
1716 goto error;
1717 }
1718
1719again:
1720 status = hdmi_msm_ddc_clear_irq(what);
1721 if (status)
1722 goto error;
1723
1724 /* Ensure Device Address has LSB set to 0 to indicate Slave addr read */
1725 dev_addr &= 0xFE;
1726
1727 /* 0x0238 HDMI_DDC_DATA
1728 [31] INDEX_WRITE WRITE ONLY. To write index field, set this bit to
1729 1 while writing HDMI_DDC_DATA.
1730 [23:16] INDEX Use to set index into DDC buffer for next read or
1731 current write, or to read index of current read or next write.
1732 Writable only when INDEX_WRITE=1.
1733 [15:8] DATA Use to fill or read the DDC buffer
1734 [0] DATA_RW Select whether buffer access will be a read or write.
1735 For writes, address auto-increments on write to HDMI_DDC_DATA.
1736 For reads, address autoincrements on reads to HDMI_DDC_DATA.
1737 * 0: Write
1738 * 1: Read */
1739
1740 /* 1. Write to HDMI_I2C_DATA with the following fields set in order to
1741 * handle portion #1
1742 * DATA_RW = 0x0 (write)
1743 * DATA = linkAddress (primary link address and writing)
1744 * INDEX = 0x0 (initial offset into buffer)
1745 * INDEX_WRITE = 0x1 (setting initial offset) */
1746 HDMI_OUTP_ND(0x0238, (0x1UL << 31) | (seg_addr << 8));
1747
1748 /* 2. Write to HDMI_I2C_DATA with the following fields set in order to
1749 * handle portion #2
1750 * DATA_RW = 0x0 (write)
1751 * DATA = offsetAddress
1752 * INDEX = 0x0
1753 * INDEX_WRITE = 0x0 (auto-increment by hardware) */
1754 HDMI_OUTP_ND(0x0238, seg_num << 8);
1755
1756 /* 3. Write to HDMI_I2C_DATA with the following fields set in order to
1757 * handle portion #3
1758 * DATA_RW = 0x0 (write)
1759 * DATA = linkAddress + 1 (primary link address 0x74 and reading)
1760 * INDEX = 0x0
1761 * INDEX_WRITE = 0x0 (auto-increment by hardware) */
1762 HDMI_OUTP_ND(0x0238, dev_addr << 8);
1763 HDMI_OUTP_ND(0x0238, offset << 8);
1764 HDMI_OUTP_ND(0x0238, (dev_addr | 1) << 8);
1765
1766 /* Data setup is complete, now setup the transaction characteristics */
1767
1768 /* 0x0228 HDMI_DDC_TRANS0
1769 [23:16] CNT0 Byte count for first transaction (excluding the first
1770 byte, which is usually the address).
1771 [13] STOP0 Determines whether a stop bit will be sent after the first
1772 transaction
1773 * 0: NO STOP
1774 * 1: STOP
1775 [12] START0 Determines whether a start bit will be sent before the
1776 first transaction
1777 * 0: NO START
1778 * 1: START
1779 [8] STOP_ON_NACK0 Determines whether the current transfer will stop
1780 if a NACK is received during the first transaction (current
1781 transaction always stops).
1782 * 0: STOP CURRENT TRANSACTION, GO TO NEXT TRANSACTION
1783 * 1: STOP ALL TRANSACTIONS, SEND STOP BIT
1784 [0] RW0 Read/write indicator for first transaction - set to 0 for
1785 write, 1 for read. This bit only controls HDMI_DDC behaviour -
1786 the R/W bit in the transaction is programmed into the DDC buffer
1787 as the LSB of the address byte.
1788 * 0: WRITE
1789 * 1: READ */
1790
1791 /* 4. Write to HDMI_I2C_TRANSACTION0 with the following fields set in
1792 order to handle characteristics of portion #1 and portion #2
1793 * RW0 = 0x0 (write)
1794 * START0 = 0x1 (insert START bit)
1795 * STOP0 = 0x0 (do NOT insert STOP bit)
1796 * CNT0 = 0x1 (single byte transaction excluding address) */
1797 HDMI_OUTP_ND(0x0228, (1 << 12) | (1 << 16));
1798
1799 /* 0x022C HDMI_DDC_TRANS1
1800 [23:16] CNT1 Byte count for second transaction (excluding the first
1801 byte, which is usually the address).
1802 [13] STOP1 Determines whether a stop bit will be sent after the second
1803 transaction
1804 * 0: NO STOP
1805 * 1: STOP
1806 [12] START1 Determines whether a start bit will be sent before the
1807 second transaction
1808 * 0: NO START
1809 * 1: START
1810 [8] STOP_ON_NACK1 Determines whether the current transfer will stop if
1811 a NACK is received during the second transaction (current
1812 transaction always stops).
1813 * 0: STOP CURRENT TRANSACTION, GO TO NEXT TRANSACTION
1814 * 1: STOP ALL TRANSACTIONS, SEND STOP BIT
1815 [0] RW1 Read/write indicator for second transaction - set to 0 for
1816 write, 1 for read. This bit only controls HDMI_DDC behaviour -
1817 the R/W bit in the transaction is programmed into the DDC buffer
1818 as the LSB of the address byte.
1819 * 0: WRITE
1820 * 1: READ */
1821
1822 /* 5. Write to HDMI_I2C_TRANSACTION1 with the following fields set in
1823 order to handle characteristics of portion #3
1824 * RW1 = 0x1 (read)
1825 * START1 = 0x1 (insert START bit)
1826 * STOP1 = 0x1 (insert STOP bit)
1827 * CNT1 = data_len (it's 128 (0x80) for a blk read) */
1828 HDMI_OUTP_ND(0x022C, (1 << 12) | (1 << 16));
1829
1830 /* 0x022C HDMI_DDC_TRANS2
1831 [23:16] CNT1 Byte count for second transaction (excluding the first
1832 byte, which is usually the address).
1833 [13] STOP1 Determines whether a stop bit will be sent after the second
1834 transaction
1835 * 0: NO STOP
1836 * 1: STOP
1837 [12] START1 Determines whether a start bit will be sent before the
1838 second transaction
1839 * 0: NO START
1840 * 1: START
1841 [8] STOP_ON_NACK1 Determines whether the current transfer will stop if
1842 a NACK is received during the second transaction (current
1843 transaction always stops).
1844 * 0: STOP CURRENT TRANSACTION, GO TO NEXT TRANSACTION
1845 * 1: STOP ALL TRANSACTIONS, SEND STOP BIT
1846 [0] RW1 Read/write indicator for second transaction - set to 0 for
1847 write, 1 for read. This bit only controls HDMI_DDC behaviour -
1848 the R/W bit in the transaction is programmed into the DDC buffer
1849 as the LSB of the address byte.
1850 * 0: WRITE
1851 * 1: READ */
1852
1853 /* 5. Write to HDMI_I2C_TRANSACTION1 with the following fields set in
1854 order to handle characteristics of portion #3
1855 * RW1 = 0x1 (read)
1856 * START1 = 0x1 (insert START bit)
1857 * STOP1 = 0x1 (insert STOP bit)
1858 * CNT1 = data_len (it's 128 (0x80) for a blk read) */
1859 HDMI_OUTP_ND(0x0230, 1 | (1 << 12) | (1 << 13) | (request_len << 16));
1860
1861 /* Trigger the I2C transfer */
1862 /* 0x020C HDMI_DDC_CTRL
1863 [21:20] TRANSACTION_CNT
1864 Number of transactions to be done in current transfer.
1865 * 0x0: transaction0 only
1866 * 0x1: transaction0, transaction1
1867 * 0x2: transaction0, transaction1, transaction2
1868 * 0x3: transaction0, transaction1, transaction2, transaction3
1869 [3] SW_STATUS_RESET
1870 Write 1 to reset HDMI_DDC_SW_STATUS flags, will reset SW_DONE,
1871 ABORTED, TIMEOUT, SW_INTERRUPTED, BUFFER_OVERFLOW,
1872 STOPPED_ON_NACK, NACK0, NACK1, NACK2, NACK3
1873 [2] SEND_RESET Set to 1 to send reset sequence (9 clocks with no
1874 data) at start of transfer. This sequence is sent after GO is
1875 written to 1, before the first transaction only.
1876 [1] SOFT_RESET Write 1 to reset DDC controller
1877 [0] GO WRITE ONLY. Write 1 to start DDC transfer. */
1878
1879 /* 6. Write to HDMI_I2C_CONTROL to kick off the hardware.
1880 * Note that NOTHING has been transmitted on the DDC lines up to this
1881 * point.
1882 * TRANSACTION_CNT = 0x2 (execute transaction0 followed by
1883 * transaction1)
1884 * GO = 0x1 (kicks off hardware) */
1885 INIT_COMPLETION(hdmi_msm_state->ddc_sw_done);
1886 HDMI_OUTP_ND(0x020C, (1 << 0) | (2 << 20));
1887
1888 time_out_count = wait_for_completion_interruptible_timeout(
1889 &hdmi_msm_state->ddc_sw_done, HZ/2);
1890 HDMI_OUTP_ND(0x0214, 0x2);
1891 if (!time_out_count) {
1892 if (retry-- > 0) {
1893 DEV_INFO("%s: failed timout, retry=%d\n", __func__,
1894 retry);
1895 goto again;
1896 }
1897 status = -ETIMEDOUT;
1898 DEV_ERR("%s: timedout(7), DDC SW Status=%08x, HW "
1899 "Status=%08x, Int Ctrl=%08x\n", __func__,
1900 HDMI_INP(0x0218), HDMI_INP(0x021C), HDMI_INP(0x0214));
1901 goto error;
1902 }
1903
1904 /* Read DDC status */
1905 reg_val = HDMI_INP_ND(0x0218);
1906 reg_val &= 0x00001000 | 0x00002000 | 0x00004000 | 0x00008000;
1907
1908 /* Check if any NACK occurred */
1909 if (reg_val) {
1910 HDMI_OUTP_ND(0x020C, BIT(3)); /* SW_STATUS_RESET */
1911 if (retry == 1)
1912 HDMI_OUTP_ND(0x020C, BIT(1)); /* SOFT_RESET */
1913 if (retry-- > 0) {
1914 DEV_DBG("%s(%s): failed NACK=0x%08x, retry=%d, "
1915 "dev-addr=0x%02x, offset=0x%02x, "
1916 "length=%d\n", __func__, what,
1917 reg_val, retry, dev_addr,
1918 offset, data_len);
1919 goto again;
1920 }
1921 status = -EIO;
1922 if (log_retry_fail)
1923 DEV_ERR("%s(%s): failed NACK=0x%08x, dev-addr=0x%02x, "
1924 "offset=0x%02x, length=%d\n", __func__, what,
1925 reg_val, dev_addr, offset, data_len);
1926 goto error;
1927 }
1928
1929 /* 0x0238 HDMI_DDC_DATA
1930 [31] INDEX_WRITE WRITE ONLY. To write index field, set this bit to 1
1931 while writing HDMI_DDC_DATA.
1932 [23:16] INDEX Use to set index into DDC buffer for next read or
1933 current write, or to read index of current read or next write.
1934 Writable only when INDEX_WRITE=1.
1935 [15:8] DATA Use to fill or read the DDC buffer
1936 [0] DATA_RW Select whether buffer access will be a read or write.
1937 For writes, address auto-increments on write to HDMI_DDC_DATA.
1938 For reads, address autoincrements on reads to HDMI_DDC_DATA.
1939 * 0: Write
1940 * 1: Read */
1941
1942 /* 8. ALL data is now available and waiting in the DDC buffer.
1943 * Read HDMI_I2C_DATA with the following fields set
1944 * RW = 0x1 (read)
1945 * DATA = BCAPS (this is field where data is pulled from)
1946 * INDEX = 0x3 (where the data has been placed in buffer by hardware)
1947 * INDEX_WRITE = 0x1 (explicitly define offset) */
1948 /* Write this data to DDC buffer */
1949 HDMI_OUTP_ND(0x0238, 0x1 | (3 << 16) | (1 << 31));
1950
1951 /* Discard first byte */
1952 HDMI_INP_ND(0x0238);
1953 for (ndx = 0; ndx < data_len; ++ndx) {
1954 reg_val = HDMI_INP_ND(0x0238);
1955 data_buf[ndx] = (uint8) ((reg_val & 0x0000FF00) >> 8);
1956 }
1957
1958 DEV_DBG("%s[%s] success\n", __func__, what);
1959
1960error:
1961 return status;
1962}
1963
1964
1965static int hdmi_msm_ddc_read(uint32 dev_addr, uint32 offset, uint8 *data_buf,
1966 uint32 data_len, int retry, const char *what, boolean no_align)
1967{
1968 int ret = hdmi_msm_ddc_read_retry(dev_addr, offset, data_buf, data_len,
1969 data_len, retry, what);
1970 if (!ret)
1971 return 0;
1972 if (no_align) {
1973 return hdmi_msm_ddc_read_retry(dev_addr, offset, data_buf,
1974 data_len, data_len, retry, what);
1975 } else {
1976 return hdmi_msm_ddc_read_retry(dev_addr, offset, data_buf,
1977 data_len, 32 * ((data_len + 31) / 32), retry, what);
1978 }
1979}
1980
1981
1982static int hdmi_msm_read_edid_block(int block, uint8 *edid_buf)
1983{
1984 int i, rc = 0;
1985 int block_size = 0x80;
1986
1987 do {
1988 DEV_DBG("EDID: reading block(%d) with block-size=%d\n",
1989 block, block_size);
1990 for (i = 0; i < 0x80; i += block_size) {
1991 /*Read EDID twice with 32bit alighnment too */
1992 if (block < 2) {
1993 rc = hdmi_msm_ddc_read(0xA0, block*0x80 + i,
1994 edid_buf+i, block_size, 1,
1995 "EDID", FALSE);
1996 } else {
1997 rc = hdmi_msm_ddc_read_edid_seg(0xA0,
1998 block*0x80 + i, edid_buf+i, block_size,
1999 block_size, 1, "EDID");
2000 }
2001 if (rc)
2002 break;
2003 }
2004
2005 block_size /= 2;
2006 } while (rc && (block_size >= 16));
2007
2008 return rc;
2009}
2010
2011static int hdmi_msm_read_edid(void)
2012{
2013 int status;
2014
2015 msm_hdmi_init_ddc();
2016 /* Looks like we need to turn on HDMI engine before any
2017 * DDC transaction */
2018 if (!hdmi_msm_is_power_on()) {
2019 DEV_ERR("%s: failed: HDMI power is off", __func__);
2020 status = -ENXIO;
2021 goto error;
2022 }
2023
2024 external_common_state->read_edid_block = hdmi_msm_read_edid_block;
2025 status = hdmi_common_read_edid();
2026 if (!status)
2027 DEV_DBG("EDID: successfully read\n");
2028
2029error:
2030 return status;
2031}
2032
2033#ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT
2034static void hdcp_auth_info(uint32 auth_info)
2035{
2036 switch (auth_info) {
2037 case 0:
2038 DEV_INFO("%s: None", __func__);
2039 break;
2040 case 1:
2041 DEV_INFO("%s: Software Disabled Authentication", __func__);
2042 break;
2043 case 2:
2044 DEV_INFO("%s: An Written", __func__);
2045 break;
2046 case 3:
2047 DEV_INFO("%s: Invalid Aksv", __func__);
2048 break;
2049 case 4:
2050 DEV_INFO("%s: Invalid Bksv", __func__);
2051 break;
2052 case 5:
2053 DEV_INFO("%s: RI Mismatch (including RO)", __func__);
2054 break;
2055 case 6:
2056 DEV_INFO("%s: consecutive Pj Mismatches", __func__);
2057 break;
2058 case 7:
2059 DEV_INFO("%s: HPD Disconnect", __func__);
2060 break;
2061 case 8:
2062 default:
2063 DEV_INFO("%s: Reserved", __func__);
2064 break;
2065 }
2066}
2067
2068static void hdcp_key_state(uint32 key_state)
2069{
2070 switch (key_state) {
2071 case 0:
2072 DEV_WARN("%s: No HDCP Keys", __func__);
2073 break;
2074 case 1:
2075 DEV_WARN("%s: Not Checked", __func__);
2076 break;
2077 case 2:
2078 DEV_DBG("%s: Checking", __func__);
2079 break;
2080 case 3:
2081 DEV_DBG("%s: HDCP Keys Valid", __func__);
2082 break;
2083 case 4:
2084 DEV_WARN("%s: AKSV not valid", __func__);
2085 break;
2086 case 5:
2087 DEV_WARN("%s: Checksum Mismatch", __func__);
2088 break;
2089 case 6:
2090 DEV_DBG("%s: Production AKSV"
2091 "with ENABLE_USER_DEFINED_AN=1", __func__);
2092 break;
2093 case 7:
2094 default:
2095 DEV_INFO("%s: Reserved", __func__);
2096 break;
2097 }
2098}
2099
2100static int hdmi_msm_count_one(uint8 *array, uint8 len)
2101{
2102 int i, j, count = 0;
2103 for (i = 0; i < len; i++)
2104 for (j = 0; j < 8; j++)
2105 count += (((array[i] >> j) & 0x1) ? 1 : 0);
2106 return count;
2107}
2108
2109static void hdcp_deauthenticate(void)
2110{
2111 int hdcp_link_status = HDMI_INP(0x011C);
2112
2113 external_common_state->hdcp_active = FALSE;
2114 /* 0x0130 HDCP_RESET
2115 [0] LINK0_DEAUTHENTICATE */
2116 HDMI_OUTP(0x0130, 0x1);
2117
2118 /* 0x0110 HDCP_CTRL
2119 [8] ENCRYPTION_ENABLE
2120 [0] ENABLE */
2121 /* encryption_enable = 0 | hdcp block enable = 1 */
2122 HDMI_OUTP(0x0110, 0x0);
2123
2124 if (hdcp_link_status & 0x00000004)
2125 hdcp_auth_info((hdcp_link_status & 0x000000F0) >> 4);
2126}
2127
2128static int hdcp_authentication_part1(void)
2129{
2130 int ret = 0;
2131 boolean is_match;
2132 boolean is_part1_done = FALSE;
2133 uint32 timeout_count;
2134 uint8 bcaps;
2135 uint8 aksv[5];
2136 uint32 qfprom_aksv_0, qfprom_aksv_1, link0_aksv_0, link0_aksv_1;
2137 uint8 bksv[5];
2138 uint32 link0_bksv_0, link0_bksv_1;
2139 uint8 an[8];
2140 uint32 link0_an_0, link0_an_1;
2141 uint32 hpd_int_status, hpd_int_ctrl;
2142
2143
2144 static uint8 buf[0xFF];
2145 memset(buf, 0, sizeof(buf));
2146
2147 if (!is_part1_done) {
2148 is_part1_done = TRUE;
2149
2150 /* Fetch aksv from QFprom, this info should be public. */
2151 qfprom_aksv_0 = inpdw(QFPROM_BASE + 0x000060D8);
2152 qfprom_aksv_1 = inpdw(QFPROM_BASE + 0x000060DC);
2153
2154 /* copy an and aksv to byte arrays for transmission */
2155 aksv[0] = qfprom_aksv_0 & 0xFF;
2156 aksv[1] = (qfprom_aksv_0 >> 8) & 0xFF;
2157 aksv[2] = (qfprom_aksv_0 >> 16) & 0xFF;
2158 aksv[3] = (qfprom_aksv_0 >> 24) & 0xFF;
2159 aksv[4] = qfprom_aksv_1 & 0xFF;
2160 /* check there are 20 ones in AKSV */
2161 if (hdmi_msm_count_one(aksv, 5) != 20) {
2162 DEV_ERR("HDCP: AKSV read from QFPROM doesn't have\
2163 20 1's and 20 0's, FAIL (AKSV=%02x%08x)\n",
2164 qfprom_aksv_1, qfprom_aksv_0);
2165 ret = -EINVAL;
2166 goto error;
2167 }
2168 DEV_DBG("HDCP: AKSV=%02x%08x\n", qfprom_aksv_1, qfprom_aksv_0);
2169
2170 /* 0x0288 HDCP_SW_LOWER_AKSV
2171 [31:0] LOWER_AKSV */
2172 /* 0x0284 HDCP_SW_UPPER_AKSV
2173 [7:0] UPPER_AKSV */
2174
2175 /* This is the lower 32 bits of the SW
2176 * injected AKSV value(AKSV[31:0]) read
2177 * from the EFUSE. It is needed for HDCP
2178 * authentication and must be written
2179 * before enabling HDCP. */
2180 HDMI_OUTP(0x0288, qfprom_aksv_0);
2181 HDMI_OUTP(0x0284, qfprom_aksv_1);
2182
2183 msm_hdmi_init_ddc();
2184
2185 /* Read Bksv 5 bytes at 0x00 in HDCP port */
2186 ret = hdmi_msm_ddc_read(0x74, 0x00, bksv, 5, 5, "Bksv", TRUE);
2187 if (ret) {
2188 DEV_ERR("%s(%d): Read BKSV failed", __func__, __LINE__);
2189 goto error;
2190 }
2191 /* check there are 20 ones in BKSV */
2192 if (hdmi_msm_count_one(bksv, 5) != 20) {
2193 DEV_ERR("HDCP: BKSV read from Sink doesn't have\
2194 20 1's and 20 0's, FAIL (BKSV=\
2195 %02x%02x%02x%02x%02x)\n",
2196 bksv[4], bksv[3], bksv[2], bksv[1], bksv[0]);
2197 ret = -EINVAL;
2198 goto error;
2199 }
2200
2201 link0_bksv_0 = bksv[3];
2202 link0_bksv_0 = (link0_bksv_0 << 8) | bksv[2];
2203 link0_bksv_0 = (link0_bksv_0 << 8) | bksv[1];
2204 link0_bksv_0 = (link0_bksv_0 << 8) | bksv[0];
2205 link0_bksv_1 = bksv[4];
2206 DEV_DBG("HDCP: BKSV=%02x%08x\n", link0_bksv_1, link0_bksv_0);
2207
2208 /* read Bcaps at 0x40 in HDCP Port */
2209 ret = hdmi_msm_ddc_read(0x74, 0x40, &bcaps, 1, 5, "Bcaps",
2210 TRUE);
2211 if (ret) {
2212 DEV_ERR("%s(%d): Read Bcaps failed", __func__,
2213 __LINE__);
2214 goto error;
2215 }
2216 DEV_DBG("HDCP: Bcaps=%02x\n", bcaps);
2217
2218 /* HDCP setup prior to HDCP enabled */
2219
2220 /* 0x0148 HDCP_RCVPORT_DATA4
2221 [15:8] LINK0_AINFO
2222 [7:0] LINK0_AKSV_1 */
2223 /* LINK0_AINFO = 0x2 FEATURE 1.1 on.
2224 * = 0x0 FEATURE 1.1 off*/
2225 HDMI_OUTP(0x0148, 0x2 << 8);
2226
2227 /* 0x012C HDCP_ENTROPY_CTRL0
2228 [31:0] BITS_OF_INFLUENCE_0 */
2229 /* 0x025C HDCP_ENTROPY_CTRL1
2230 [31:0] BITS_OF_INFLUENCE_1 */
2231 HDMI_OUTP(0x012C, 0xB1FFB0FF);
2232 HDMI_OUTP(0x025C, 0xF00DFACE);
2233
2234 /* 0x0114 HDCP_DEBUG_CTRL
2235 [2] DEBUG_RNG_CIPHER
2236 else default 0 */
2237 HDMI_OUTP(0x0114, HDMI_INP(0x0114) & 0xFFFFFFFB);
2238
2239 /* 0x0110 HDCP_CTRL
2240 [8] ENCRYPTION_ENABLE
2241 [0] ENABLE */
2242 /* encryption_enable | enable */
2243 HDMI_OUTP(0x0110, (1 << 8) | (1 << 0));
2244
2245 /* 0x0118 HDCP_INT_CTRL
2246 * [2] AUTH_SUCCESS_MASK [R/W] Mask bit for\
2247 * HDCP Authentication
2248 * Success interrupt - set to 1 to enable interrupt
2249 *
2250 * [6] AUTH_FAIL_MASK [R/W] Mask bit for HDCP
2251 * Authentication
2252 * Lost interrupt set to 1 to enable interrupt
2253 *
2254 * [7] AUTH_FAIL_INFO_ACK [W] Acknwledge bit for HDCP
2255 * Auth Failure Info field - write 1 to clear
2256 *
2257 * [10] DDC_XFER_REQ_MASK [R/W] Mask bit for HDCP\
2258 * DDC Transfer
2259 * Request interrupt - set to 1 to enable interrupt
2260 *
2261 * [14] DDC_XFER_DONE_MASK [R/W] Mask bit for HDCP\
2262 * DDC Transfer
2263 * done interrupt - set to 1 to enable interrupt */
2264 /* enable all HDCP ints */
2265 HDMI_OUTP(0x0118, (1 << 2) | (1 << 6) | (1 << 7));
2266
2267 /* 0x011C HDCP_LINK0_STATUS
2268 [8] AN_0_READY
2269 [9] AN_1_READY */
2270 /* wait for an0 and an1 ready bits to be set in LINK0_STATUS */
2271 timeout_count = 100;
2272 while (((HDMI_INP_ND(0x011C) & (0x3 << 8)) != (0x3 << 8))
2273 && timeout_count--)
2274 msleep(20);
2275 if (!timeout_count) {
2276 ret = -ETIMEDOUT;
2277 DEV_ERR("%s(%d): timedout, An0=%d, An1=%d\n",
2278 __func__, __LINE__,
2279 (HDMI_INP_ND(0x011C) & BIT(8)) >> 8,
2280 (HDMI_INP_ND(0x011C) & BIT(9)) >> 9);
2281 goto error;
2282 }
2283
2284 /* 0x0168 HDCP_RCVPORT_DATA12
2285 [23:8] BSTATUS
2286 [7:0] BCAPS */
2287 HDMI_OUTP(0x0168, bcaps);
2288
2289 /* 0x014C HDCP_RCVPORT_DATA5
2290 [31:0] LINK0_AN_0 */
2291 /* read an0 calculation */
2292 link0_an_0 = HDMI_INP(0x014C);
2293
2294 /* 0x0150 HDCP_RCVPORT_DATA6
2295 [31:0] LINK0_AN_1 */
2296 /* read an1 calculation */
2297 link0_an_1 = HDMI_INP(0x0150);
2298
2299 /* three bits 28..30 */
2300 hdcp_key_state((HDMI_INP(0x011C) >> 28) & 0x7);
2301
2302 /* 0x0144 HDCP_RCVPORT_DATA3
2303 [31:0] LINK0_AKSV_0 public key
2304 0x0148 HDCP_RCVPORT_DATA4
2305 [15:8] LINK0_AINFO
2306 [7:0] LINK0_AKSV_1 public key */
2307 link0_aksv_0 = HDMI_INP(0x0144);
2308 link0_aksv_1 = HDMI_INP(0x0148);
2309
2310 /* copy an and aksv to byte arrays for transmission */
2311 aksv[0] = link0_aksv_0 & 0xFF;
2312 aksv[1] = (link0_aksv_0 >> 8) & 0xFF;
2313 aksv[2] = (link0_aksv_0 >> 16) & 0xFF;
2314 aksv[3] = (link0_aksv_0 >> 24) & 0xFF;
2315 aksv[4] = link0_aksv_1 & 0xFF;
2316
2317 an[0] = link0_an_0 & 0xFF;
2318 an[1] = (link0_an_0 >> 8) & 0xFF;
2319 an[2] = (link0_an_0 >> 16) & 0xFF;
2320 an[3] = (link0_an_0 >> 24) & 0xFF;
2321 an[4] = link0_an_1 & 0xFF;
2322 an[5] = (link0_an_1 >> 8) & 0xFF;
2323 an[6] = (link0_an_1 >> 16) & 0xFF;
2324 an[7] = (link0_an_1 >> 24) & 0xFF;
2325
2326 /* Write An 8 bytes to offset 0x18 */
2327 ret = hdmi_msm_ddc_write(0x74, 0x18, an, 8, "An");
2328 if (ret) {
2329 DEV_ERR("%s(%d): Write An failed", __func__, __LINE__);
2330 goto error;
2331 }
2332
2333 /* Write Aksv 5 bytes to offset 0x10 */
2334 ret = hdmi_msm_ddc_write(0x74, 0x10, aksv, 5, "Aksv");
2335 if (ret) {
2336 DEV_ERR("%s(%d): Write Aksv failed", __func__,
2337 __LINE__);
2338 goto error;
2339 }
2340 DEV_DBG("HDCP: Link0-AKSV=%02x%08x\n",
2341 link0_aksv_1 & 0xFF, link0_aksv_0);
2342
2343 /* 0x0134 HDCP_RCVPORT_DATA0
2344 [31:0] LINK0_BKSV_0 */
2345 HDMI_OUTP(0x0134, link0_bksv_0);
2346 /* 0x0138 HDCP_RCVPORT_DATA1
2347 [31:0] LINK0_BKSV_1 */
2348 HDMI_OUTP(0x0138, link0_bksv_1);
2349 DEV_DBG("HDCP: Link0-BKSV=%02x%08x\n", link0_bksv_1,
2350 link0_bksv_0);
2351
2352 /* HDMI_HPD_INT_STATUS[0x0250] */
2353 hpd_int_status = HDMI_INP_ND(0x0250);
2354 /* HDMI_HPD_INT_CTRL[0x0254] */
2355 hpd_int_ctrl = HDMI_INP_ND(0x0254);
2356 DEV_DBG("[SR-DEUG]: HPD_INTR_CTRL=[%u] HPD_INTR_STATUS=[%u]\
2357 before reading R0'\n", hpd_int_ctrl, hpd_int_status);
2358
2359 /*
2360 * HDCP Compliace Test case 1B-01:
2361 * Wait here until all the ksv bytes have been
2362 * read from the KSV FIFO register.
2363 */
2364 msleep(125);
2365
2366 /* Reading R0' 2 bytes at offset 0x08 */
2367 ret = hdmi_msm_ddc_read(0x74, 0x08, buf, 2, 5, "RO'", TRUE);
2368 if (ret) {
2369 DEV_ERR("%s(%d): Read RO's failed", __func__,
2370 __LINE__);
2371 goto error;
2372 }
2373
2374 /* 0x013C HDCP_RCVPORT_DATA2_0
2375 [15:0] LINK0_RI */
2376 HDMI_OUTP(0x013C, (((uint32)buf[1]) << 8) | buf[0]);
2377 DEV_DBG("HDCP: R0'=%02x%02x\n", buf[1], buf[0]);
2378
2379 INIT_COMPLETION(hdmi_msm_state->hdcp_success_done);
2380 timeout_count = wait_for_completion_interruptible_timeout(
2381 &hdmi_msm_state->hdcp_success_done, HZ*2);
2382
2383 if (!timeout_count) {
2384 ret = -ETIMEDOUT;
2385 is_match = HDMI_INP(0x011C) & BIT(12);
2386 DEV_ERR("%s(%d): timedout, Link0=<%s>\n", __func__,
2387 __LINE__,
2388 is_match ? "RI_MATCH" : "No RI Match INTR in time");
2389 if (!is_match)
2390 goto error;
2391 }
2392
2393 /* 0x011C HDCP_LINK0_STATUS
2394 [12] RI_MATCHES [0] MISMATCH, [1] MATCH
2395 [0] AUTH_SUCCESS */
2396 /* Checking for RI, R0 Match */
2397 /* RI_MATCHES */
2398 if ((HDMI_INP(0x011C) & BIT(12)) != BIT(12)) {
2399 ret = -EINVAL;
2400 DEV_ERR("%s: HDCP_LINK0_STATUS[RI_MATCHES]: MISMATCH\n",
2401 __func__);
2402 goto error;
2403 }
2404
2405 DEV_INFO("HDCP: authentication part I, successful\n");
2406 is_part1_done = FALSE;
2407 return 0;
2408error:
2409 DEV_ERR("[%s]: HDCP Reauthentication\n", __func__);
2410 is_part1_done = FALSE;
2411 return ret;
2412 } else {
2413 return 1;
2414 }
2415}
2416
2417static int hdmi_msm_transfer_v_h(void)
2418{
2419 /* Read V'.HO 4 Byte at offset 0x20 */
2420 char what[20];
2421 int ret;
2422 uint8 buf[4];
2423
2424 snprintf(what, sizeof(what), "V' H0");
2425 ret = hdmi_msm_ddc_read(0x74, 0x20, buf, 4, 5, what, TRUE);
2426 if (ret) {
2427 DEV_ERR("%s: Read %s failed", __func__, what);
2428 return ret;
2429 }
2430 DEV_DBG("buf[0]= %x , buf[1] = %x , buf[2] = %x , buf[3] = %x\n ",
2431 buf[0] , buf[1] , buf[2] , buf[3]);
2432
2433 /* 0x0154 HDCP_RCVPORT_DATA7
2434 [31:0] V_HO */
2435 HDMI_OUTP(0x0154 ,
2436 (buf[3] << 24 | buf[2] << 16 | buf[1] << 8 | buf[0]));
2437
2438 snprintf(what, sizeof(what), "V' H1");
2439 ret = hdmi_msm_ddc_read(0x74, 0x24, buf, 4, 5, what, TRUE);
2440 if (ret) {
2441 DEV_ERR("%s: Read %s failed", __func__, what);
2442 return ret;
2443 }
2444 DEV_DBG("buf[0]= %x , buf[1] = %x , buf[2] = %x , buf[3] = %x\n ",
2445 buf[0] , buf[1] , buf[2] , buf[3]);
2446
2447 /* 0x0158 HDCP_RCVPORT_ DATA8
2448 [31:0] V_H1 */
2449 HDMI_OUTP(0x0158,
2450 (buf[3] << 24 | buf[2] << 16 | buf[1] << 8 | buf[0]));
2451
2452
2453 snprintf(what, sizeof(what), "V' H2");
2454 ret = hdmi_msm_ddc_read(0x74, 0x28, buf, 4, 5, what, TRUE);
2455 if (ret) {
2456 DEV_ERR("%s: Read %s failed", __func__, what);
2457 return ret;
2458 }
2459 DEV_DBG("buf[0]= %x , buf[1] = %x , buf[2] = %x , buf[3] = %x\n ",
2460 buf[0] , buf[1] , buf[2] , buf[3]);
2461
2462 /* 0x015c HDCP_RCVPORT_DATA9
2463 [31:0] V_H2 */
2464 HDMI_OUTP(0x015c ,
2465 (buf[3] << 24 | buf[2] << 16 | buf[1] << 8 | buf[0]));
2466
2467 snprintf(what, sizeof(what), "V' H3");
2468 ret = hdmi_msm_ddc_read(0x74, 0x2c, buf, 4, 5, what, TRUE);
2469 if (ret) {
2470 DEV_ERR("%s: Read %s failed", __func__, what);
2471 return ret;
2472 }
2473 DEV_DBG("buf[0]= %x , buf[1] = %x , buf[2] = %x , buf[3] = %x\n ",
2474 buf[0] , buf[1] , buf[2] , buf[3]);
2475
2476 /* 0x0160 HDCP_RCVPORT_DATA10
2477 [31:0] V_H3 */
2478 HDMI_OUTP(0x0160,
2479 (buf[3] << 24 | buf[2] << 16 | buf[1] << 8 | buf[0]));
2480
2481 snprintf(what, sizeof(what), "V' H4");
2482 ret = hdmi_msm_ddc_read(0x74, 0x30, buf, 4, 5, what, TRUE);
2483 if (ret) {
2484 DEV_ERR("%s: Read %s failed", __func__, what);
2485 return ret;
2486 }
2487 DEV_DBG("buf[0]= %x , buf[1] = %x , buf[2] = %x , buf[3] = %x\n ",
2488 buf[0] , buf[1] , buf[2] , buf[3]);
2489 /* 0x0164 HDCP_RCVPORT_DATA11
2490 [31:0] V_H4 */
2491 HDMI_OUTP(0x0164,
2492 (buf[3] << 24 | buf[2] << 16 | buf[1] << 8 | buf[0]));
2493
2494 return 0;
2495}
2496
2497static int hdcp_authentication_part2(void)
2498{
2499 int ret = 0;
2500 uint32 timeout_count;
2501 int i = 0;
2502 int cnt = 0;
2503 uint bstatus;
2504 uint8 bcaps;
2505 uint32 down_stream_devices;
2506 uint32 ksv_bytes;
2507
2508 static uint8 buf[0xFF];
2509 static uint8 kvs_fifo[5 * 127];
2510
2511 boolean max_devs_exceeded = 0;
2512 boolean max_cascade_exceeded = 0;
2513
2514 boolean ksv_done = FALSE;
2515
2516 memset(buf, 0, sizeof(buf));
2517 memset(kvs_fifo, 0, sizeof(kvs_fifo));
2518
2519 /* wait until READY bit is set in bcaps */
2520 timeout_count = 50;
2521 do {
2522 timeout_count--;
2523 /* read bcaps 1 Byte at offset 0x40 */
2524 ret = hdmi_msm_ddc_read(0x74, 0x40, &bcaps, 1, 1,
2525 "Bcaps", FALSE);
2526 if (ret) {
2527 DEV_ERR("%s(%d): Read Bcaps failed", __func__,
2528 __LINE__);
2529 goto error;
2530 }
2531 msleep(100);
2532 } while ((0 == (bcaps & 0x20)) && timeout_count); /* READY (Bit 5) */
2533 if (!timeout_count) {
2534 ret = -ETIMEDOUT;
2535 DEV_ERR("%s:timedout(1)", __func__);
2536 goto error;
2537 }
2538
2539 /* read bstatus 2 bytes at offset 0x41 */
2540
2541 ret = hdmi_msm_ddc_read(0x74, 0x41, buf, 2, 5, "Bstatus", FALSE);
2542 if (ret) {
2543 DEV_ERR("%s(%d): Read Bstatus failed", __func__, __LINE__);
2544 goto error;
2545 }
2546 bstatus = buf[1];
2547 bstatus = (bstatus << 8) | buf[0];
2548 /* 0x0168 DCP_RCVPORT_DATA12
2549 [7:0] BCAPS
2550 [23:8 BSTATUS */
2551 HDMI_OUTP(0x0168, bcaps | (bstatus << 8));
2552 /* BSTATUS [6:0] DEVICE_COUNT Number of HDMI device attached to repeater
2553 * - see HDCP spec */
2554 down_stream_devices = bstatus & 0x7F;
2555
2556 if (down_stream_devices == 0x0) {
2557 /* There isn't any devices attaced to the Repeater */
2558 DEV_ERR("%s: there isn't any devices attached to the "
2559 "Repeater\n", __func__);
2560 ret = -EINVAL;
2561 goto error;
2562 }
2563
2564 /*
2565 * HDCP Compliance 1B-05:
2566 * Check if no. of devices connected to repeater
2567 * exceed max_devices_connected from bit 7 of Bstatus.
2568 */
2569 max_devs_exceeded = (bstatus & 0x80) >> 7;
2570 if (max_devs_exceeded == 0x01) {
2571 DEV_ERR("%s: Number of devs connected to repeater "
2572 "exceeds max_devs\n", __func__);
2573 ret = -EINVAL;
2574 goto hdcp_error;
2575 }
2576
2577 /*
2578 * HDCP Compliance 1B-06:
2579 * Check if no. of cascade connected to repeater
2580 * exceed max_cascade_connected from bit 11 of Bstatus.
2581 */
2582 max_cascade_exceeded = (bstatus & 0x800) >> 11;
2583 if (max_cascade_exceeded == 0x01) {
2584 DEV_ERR("%s: Number of cascade connected to repeater "
2585 "exceeds max_cascade\n", __func__);
2586 ret = -EINVAL;
2587 goto hdcp_error;
2588 }
2589
2590 /* Read KSV FIFO over DDC
2591 * Key Slection vector FIFO
2592 * Used to pull downstream KSVs from HDCP Repeaters.
2593 * All bytes (DEVICE_COUNT * 5) must be read in a single,
2594 * auto incrementing access.
2595 * All bytes read as 0x00 for HDCP Receivers that are not
2596 * HDCP Repeaters (REPEATER == 0). */
2597 ksv_bytes = 5 * down_stream_devices;
2598 /* Reading KSV FIFO / KSV FIFO */
2599 ksv_done = FALSE;
2600
2601 ret = hdmi_msm_ddc_read(0x74, 0x43, kvs_fifo, ksv_bytes, 5,
2602 "KSV FIFO", TRUE);
2603 do {
2604 if (ret) {
2605 DEV_ERR("%s(%d): Read KSV FIFO failed",
2606 __func__, __LINE__);
2607 /*
2608 * HDCP Compliace Test case 1B-01:
2609 * Wait here until all the ksv bytes have been
2610 * read from the KSV FIFO register.
2611 */
2612 msleep(25);
2613 } else {
2614 ksv_done = TRUE;
2615 }
2616 cnt++;
2617 } while (!ksv_done && cnt != 20);
2618
2619 if (ksv_done == FALSE)
2620 goto error;
2621
2622 ret = hdmi_msm_transfer_v_h();
2623 if (ret)
2624 goto error;
2625
2626 /* Next: Write KSV FIFO to HDCP_SHA_DATA.
2627 * This is done 1 byte at time starting with the LSB.
2628 * On the very last byte write,
2629 * the HDCP_SHA_DATA_DONE bit[0]
2630 */
2631
2632 /* 0x023C HDCP_SHA_CTRL
2633 [0] RESET [0] Enable, [1] Reset
2634 [4] SELECT [0] DIGA_HDCP, [1] DIGB_HDCP */
2635 /* reset SHA engine */
2636 HDMI_OUTP(0x023C, 1);
2637 /* enable SHA engine, SEL=DIGA_HDCP */
2638 HDMI_OUTP(0x023C, 0);
2639
2640 for (i = 0; i < ksv_bytes - 1; i++) {
2641 /* Write KSV byte and do not set DONE bit[0] */
2642 HDMI_OUTP_ND(0x0244, kvs_fifo[i] << 16);
2643 }
2644 /* Write l to DONE bit[0] */
2645 HDMI_OUTP_ND(0x0244, (kvs_fifo[ksv_bytes - 1] << 16) | 0x1);
2646
2647 /* 0x0240 HDCP_SHA_STATUS
2648 [4] COMP_DONE */
2649 /* Now wait for HDCP_SHA_COMP_DONE */
2650 timeout_count = 100;
2651 while ((0x10 != (HDMI_INP_ND(0x0240) & 0x10)) && timeout_count--)
2652 msleep(20);
2653 if (!timeout_count) {
2654 ret = -ETIMEDOUT;
2655 DEV_ERR("%s(%d): timedout", __func__, __LINE__);
2656 goto error;
2657 }
2658
2659 /* 0x011C HDCP_LINK0_STATUS
2660 [20] V_MATCHES */
2661 timeout_count = 100;
2662 while (((HDMI_INP_ND(0x011C) & (1 << 20)) != (1 << 20))
2663 && timeout_count--)
2664 msleep(20);
2665 if (!timeout_count) {
2666 ret = -ETIMEDOUT;
2667 DEV_ERR("%s(%d): timedout", __func__, __LINE__);
2668 goto error;
2669 }
2670
2671 DEV_INFO("HDCP: authentication part II, successful\n");
2672
2673hdcp_error:
2674error:
2675 return ret;
2676}
2677
2678static int hdcp_authentication_part3(uint32 found_repeater)
2679{
2680 int ret = 0;
2681 int poll = 3000;
2682 while (poll) {
2683 /* 0x011C HDCP_LINK0_STATUS
2684 [30:28] KEYS_STATE = 3 = "Valid"
2685 [24] RO_COMPUTATION_DONE [0] Not Done, [1] Done
2686 [20] V_MATCHES [0] Mismtach, [1] Match
2687 [12] RI_MATCHES [0] Mismatch, [1] Match
2688 [0] AUTH_SUCCESS */
2689 if (HDMI_INP_ND(0x011C) != (0x31001001 |
2690 (found_repeater << 20))) {
2691 DEV_ERR("HDCP: autentication part III, FAILED, "
2692 "Link Status=%08x\n", HDMI_INP(0x011C));
2693 ret = -EINVAL;
2694 goto error;
2695 }
2696 poll--;
2697 }
2698
2699 DEV_INFO("HDCP: authentication part III, successful\n");
2700
2701error:
2702 return ret;
2703}
2704
2705static void hdmi_msm_hdcp_enable(void)
2706{
2707 int ret = 0;
2708 uint8 bcaps;
2709 uint32 found_repeater = 0x0;
2710 char *envp[2];
2711
2712 if (!hdmi_msm_has_hdcp())
2713 return;
2714
2715 mutex_lock(&hdmi_msm_state_mutex);
2716 hdmi_msm_state->hdcp_activating = TRUE;
2717 mutex_unlock(&hdmi_msm_state_mutex);
2718
2719 fill_black_screen();
2720
2721 mutex_lock(&hdcp_auth_state_mutex);
2722 /*
2723 * Initialize this to zero here to make
2724 * sure HPD has not happened yet
2725 */
2726 hdmi_msm_state->hpd_during_auth = FALSE;
2727 /* This flag prevents other threads from re-authenticating
2728 * after we've just authenticated (i.e., finished part3)
2729 * We probably need to protect this in a mutex lock */
2730 hdmi_msm_state->full_auth_done = FALSE;
2731 mutex_unlock(&hdcp_auth_state_mutex);
2732
2733 /* PART I Authentication*/
2734 ret = hdcp_authentication_part1();
2735 if (ret)
2736 goto error;
2737
2738 /* PART II Authentication*/
2739 /* read Bcaps at 0x40 in HDCP Port */
2740 ret = hdmi_msm_ddc_read(0x74, 0x40, &bcaps, 1, 5, "Bcaps", FALSE);
2741 if (ret) {
2742 DEV_ERR("%s(%d): Read Bcaps failed\n", __func__, __LINE__);
2743 goto error;
2744 }
2745 DEV_DBG("HDCP: Bcaps=0x%02x (%s)\n", bcaps,
2746 (bcaps & BIT(6)) ? "repeater" : "no repeater");
2747
2748 /* if REPEATER (Bit 6), perform Part2 Authentication */
2749 if (bcaps & BIT(6)) {
2750 found_repeater = 0x1;
2751 ret = hdcp_authentication_part2();
2752 if (ret)
2753 goto error;
2754 } else
2755 DEV_INFO("HDCP: authentication part II skipped, no repeater\n");
2756
2757 /* PART III Authentication*/
2758 ret = hdcp_authentication_part3(found_repeater);
2759 if (ret)
2760 goto error;
2761
2762 unfill_black_screen();
2763
2764 external_common_state->hdcp_active = TRUE;
2765 mutex_lock(&hdmi_msm_state_mutex);
2766 hdmi_msm_state->hdcp_activating = FALSE;
2767 mutex_unlock(&hdmi_msm_state_mutex);
2768
2769 mutex_lock(&hdcp_auth_state_mutex);
2770 /*
2771 * This flag prevents other threads from re-authenticating
2772 * after we've just authenticated (i.e., finished part3)
2773 */
2774 hdmi_msm_state->full_auth_done = TRUE;
2775 mutex_unlock(&hdcp_auth_state_mutex);
2776
2777 if (!hdmi_msm_is_dvi_mode()) {
2778 DEV_INFO("HDMI HPD: sense : send HDCP_PASS\n");
2779 envp[0] = "HDCP_STATE=PASS";
2780 envp[1] = NULL;
2781 kobject_uevent_env(external_common_state->uevent_kobj,
2782 KOBJ_CHANGE, envp);
2783 }
2784 return;
2785
2786error:
2787 mutex_lock(&hdmi_msm_state_mutex);
2788 hdmi_msm_state->hdcp_activating = FALSE;
2789 mutex_unlock(&hdmi_msm_state_mutex);
2790 if (hdmi_msm_state->hpd_during_auth) {
2791 DEV_WARN("Calling Deauthentication: HPD occured during\
2792 authentication from [%s]\n", __func__);
2793 hdcp_deauthenticate();
2794 mutex_lock(&hdcp_auth_state_mutex);
2795 hdmi_msm_state->hpd_during_auth = FALSE;
2796 mutex_unlock(&hdcp_auth_state_mutex);
2797 } else {
2798 DEV_WARN("[DEV_DBG]: Calling reauth from [%s]\n", __func__);
2799 if (hdmi_msm_state->panel_power_on)
2800 queue_work(hdmi_work_queue,
2801 &hdmi_msm_state->hdcp_reauth_work);
2802 }
2803}
2804#endif /* CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT */
2805
2806static void hdmi_msm_video_setup(int video_format)
2807{
2808 uint32 total_v = 0;
2809 uint32 total_h = 0;
2810 uint32 start_h = 0;
2811 uint32 end_h = 0;
2812 uint32 start_v = 0;
2813 uint32 end_v = 0;
2814 const struct hdmi_disp_mode_timing_type *timing =
2815 hdmi_common_get_supported_mode(video_format);
2816
2817 /* timing register setup */
2818 if (timing == NULL) {
2819 DEV_ERR("video format not supported: %d\n", video_format);
2820 return;
2821 }
2822
2823 /* Hsync Total and Vsync Total */
2824 total_h = timing->active_h + timing->front_porch_h
2825 + timing->back_porch_h + timing->pulse_width_h - 1;
2826 total_v = timing->active_v + timing->front_porch_v
2827 + timing->back_porch_v + timing->pulse_width_v - 1;
2828 /* 0x02C0 HDMI_TOTAL
2829 [27:16] V_TOTAL Vertical Total
2830 [11:0] H_TOTAL Horizontal Total */
2831 HDMI_OUTP(0x02C0, ((total_v << 16) & 0x0FFF0000)
2832 | ((total_h << 0) & 0x00000FFF));
2833
2834 /* Hsync Start and Hsync End */
2835 start_h = timing->back_porch_h + timing->pulse_width_h;
2836 end_h = (total_h + 1) - timing->front_porch_h;
2837 /* 0x02B4 HDMI_ACTIVE_H
2838 [27:16] END Horizontal end
2839 [11:0] START Horizontal start */
2840 HDMI_OUTP(0x02B4, ((end_h << 16) & 0x0FFF0000)
2841 | ((start_h << 0) & 0x00000FFF));
2842
2843 start_v = timing->back_porch_v + timing->pulse_width_v - 1;
2844 end_v = total_v - timing->front_porch_v;
2845 /* 0x02B8 HDMI_ACTIVE_V
2846 [27:16] END Vertical end
2847 [11:0] START Vertical start */
2848 HDMI_OUTP(0x02B8, ((end_v << 16) & 0x0FFF0000)
2849 | ((start_v << 0) & 0x00000FFF));
2850
2851 if (timing->interlaced) {
2852 /* 0x02C4 HDMI_V_TOTAL_F2
2853 [11:0] V_TOTAL_F2 Vertical total for field2 */
2854 HDMI_OUTP(0x02C4, ((total_v + 1) << 0) & 0x00000FFF);
2855
2856 /* 0x02BC HDMI_ACTIVE_V_F2
2857 [27:16] END_F2 Vertical end for field2
2858 [11:0] START_F2 Vertical start for Field2 */
2859 HDMI_OUTP(0x02BC,
2860 (((start_v + 1) << 0) & 0x00000FFF)
2861 | (((end_v + 1) << 16) & 0x0FFF0000));
2862 } else {
2863 /* HDMI_V_TOTAL_F2 */
2864 HDMI_OUTP(0x02C4, 0);
2865 /* HDMI_ACTIVE_V_F2 */
2866 HDMI_OUTP(0x02BC, 0);
2867 }
2868
2869 hdmi_frame_ctrl_cfg(timing);
2870}
2871
2872struct hdmi_msm_audio_acr {
2873 uint32 n; /* N parameter for clock regeneration */
2874 uint32 cts; /* CTS parameter for clock regeneration */
2875};
2876
2877struct hdmi_msm_audio_arcs {
2878 uint32 pclk;
2879 struct hdmi_msm_audio_acr lut[MSM_HDMI_SAMPLE_RATE_MAX];
2880};
2881
2882#define HDMI_MSM_AUDIO_ARCS(pclk, ...) { pclk, __VA_ARGS__ }
2883
2884/* Audio constants lookup table for hdmi_msm_audio_acr_setup */
2885/* Valid Pixel-Clock rates: 25.2MHz, 27MHz, 27.03MHz, 74.25MHz, 148.5MHz */
2886static const struct hdmi_msm_audio_arcs hdmi_msm_audio_acr_lut[] = {
2887 /* 25.200MHz */
2888 HDMI_MSM_AUDIO_ARCS(25200, {
2889 {4096, 25200}, {6272, 28000}, {6144, 25200}, {12544, 28000},
2890 {12288, 25200}, {25088, 28000}, {24576, 25200} }),
2891 /* 27.000MHz */
2892 HDMI_MSM_AUDIO_ARCS(27000, {
2893 {4096, 27000}, {6272, 30000}, {6144, 27000}, {12544, 30000},
2894 {12288, 27000}, {25088, 30000}, {24576, 27000} }),
2895 /* 27.030MHz */
2896 HDMI_MSM_AUDIO_ARCS(27030, {
2897 {4096, 27030}, {6272, 30030}, {6144, 27030}, {12544, 30030},
2898 {12288, 27030}, {25088, 30030}, {24576, 27030} }),
2899 /* 74.250MHz */
2900 HDMI_MSM_AUDIO_ARCS(74250, {
2901 {4096, 74250}, {6272, 82500}, {6144, 74250}, {12544, 82500},
2902 {12288, 74250}, {25088, 82500}, {24576, 74250} }),
2903 /* 148.500MHz */
2904 HDMI_MSM_AUDIO_ARCS(148500, {
2905 {4096, 148500}, {6272, 165000}, {6144, 148500}, {12544, 165000},
2906 {12288, 148500}, {25088, 165000}, {24576, 148500} }),
2907};
2908
2909static void hdmi_msm_audio_acr_setup(boolean enabled, int video_format,
2910 int audio_sample_rate, int num_of_channels)
2911{
2912 /* Read first before writing */
2913 /* HDMI_ACR_PKT_CTRL[0x0024] */
2914 uint32 acr_pck_ctrl_reg = HDMI_INP(0x0024);
2915
2916 if (enabled) {
2917 const struct hdmi_disp_mode_timing_type *timing =
2918 hdmi_common_get_supported_mode(video_format);
2919 const struct hdmi_msm_audio_arcs *audio_arc =
2920 &hdmi_msm_audio_acr_lut[0];
2921 const int lut_size = sizeof(hdmi_msm_audio_acr_lut)
2922 /sizeof(*hdmi_msm_audio_acr_lut);
2923 uint32 i, n, cts, layout, multiplier, aud_pck_ctrl_2_reg;
2924
2925 if (timing == NULL) {
2926 DEV_WARN("%s: video format %d not supported\n",
2927 __func__, video_format);
2928 return;
2929 }
2930
2931 for (i = 0; i < lut_size;
2932 audio_arc = &hdmi_msm_audio_acr_lut[++i]) {
2933 if (audio_arc->pclk == timing->pixel_freq)
2934 break;
2935 }
2936 if (i >= lut_size) {
2937 DEV_WARN("%s: pixel clock %d not supported\n", __func__,
2938 timing->pixel_freq);
2939 return;
2940 }
2941
2942 n = audio_arc->lut[audio_sample_rate].n;
2943 cts = audio_arc->lut[audio_sample_rate].cts;
2944 layout = (MSM_HDMI_AUDIO_CHANNEL_2 == num_of_channels) ? 0 : 1;
2945
2946 if ((MSM_HDMI_SAMPLE_RATE_192KHZ == audio_sample_rate) ||
2947 (MSM_HDMI_SAMPLE_RATE_176_4KHZ == audio_sample_rate)) {
2948 multiplier = 4;
2949 n >>= 2; /* divide N by 4 and use multiplier */
2950 } else if ((MSM_HDMI_SAMPLE_RATE_96KHZ == audio_sample_rate) ||
2951 (MSM_HDMI_SAMPLE_RATE_88_2KHZ == audio_sample_rate)) {
2952 multiplier = 2;
2953 n >>= 1; /* divide N by 2 and use multiplier */
2954 } else {
2955 multiplier = 1;
2956 }
2957 DEV_DBG("%s: n=%u, cts=%u, layout=%u\n", __func__, n, cts,
2958 layout);
2959
2960 /* AUDIO_PRIORITY | SOURCE */
2961 acr_pck_ctrl_reg |= 0x80000100;
2962 /* N_MULTIPLE(multiplier) */
2963 acr_pck_ctrl_reg |= (multiplier & 7) << 16;
2964
2965 if ((MSM_HDMI_SAMPLE_RATE_48KHZ == audio_sample_rate) ||
2966 (MSM_HDMI_SAMPLE_RATE_96KHZ == audio_sample_rate) ||
2967 (MSM_HDMI_SAMPLE_RATE_192KHZ == audio_sample_rate)) {
2968 /* SELECT(3) */
2969 acr_pck_ctrl_reg |= 3 << 4;
2970 /* CTS_48 */
2971 cts <<= 12;
2972
2973 /* CTS: need to determine how many fractional bits */
2974 /* HDMI_ACR_48_0 */
2975 HDMI_OUTP(0x00D4, cts);
2976 /* N */
2977 /* HDMI_ACR_48_1 */
2978 HDMI_OUTP(0x00D8, n);
2979 } else if ((MSM_HDMI_SAMPLE_RATE_44_1KHZ == audio_sample_rate)
2980 || (MSM_HDMI_SAMPLE_RATE_88_2KHZ ==
2981 audio_sample_rate)
2982 || (MSM_HDMI_SAMPLE_RATE_176_4KHZ ==
2983 audio_sample_rate)) {
2984 /* SELECT(2) */
2985 acr_pck_ctrl_reg |= 2 << 4;
2986 /* CTS_44 */
2987 cts <<= 12;
2988
2989 /* CTS: need to determine how many fractional bits */
2990 /* HDMI_ACR_44_0 */
2991 HDMI_OUTP(0x00CC, cts);
2992 /* N */
2993 /* HDMI_ACR_44_1 */
2994 HDMI_OUTP(0x00D0, n);
2995 } else { /* default to 32k */
2996 /* SELECT(1) */
2997 acr_pck_ctrl_reg |= 1 << 4;
2998 /* CTS_32 */
2999 cts <<= 12;
3000
3001 /* CTS: need to determine how many fractional bits */
3002 /* HDMI_ACR_32_0 */
3003 HDMI_OUTP(0x00C4, cts);
3004 /* N */
3005 /* HDMI_ACR_32_1 */
3006 HDMI_OUTP(0x00C8, n);
3007 }
3008 /* Payload layout depends on number of audio channels */
3009 /* LAYOUT_SEL(layout) */
3010 aud_pck_ctrl_2_reg = 1 | (layout << 1);
3011 /* override | layout */
3012 /* HDMI_AUDIO_PKT_CTRL2[0x00044] */
3013 HDMI_OUTP(0x00044, aud_pck_ctrl_2_reg);
3014
3015 /* SEND | CONT */
3016 acr_pck_ctrl_reg |= 0x00000003;
3017 } else {
3018 /* ~(SEND | CONT) */
3019 acr_pck_ctrl_reg &= ~0x00000003;
3020 }
3021 /* HDMI_ACR_PKT_CTRL[0x0024] */
3022 HDMI_OUTP(0x0024, acr_pck_ctrl_reg);
3023}
3024
3025static void hdmi_msm_outpdw_chk(uint32 offset, uint32 data)
3026{
3027 uint32 check, i = 0;
3028
3029#ifdef DEBUG
3030 HDMI_OUTP(offset, data);
3031#endif
3032 do {
3033 outpdw(MSM_HDMI_BASE+offset, data);
3034 check = inpdw(MSM_HDMI_BASE+offset);
3035 } while (check != data && i++ < 10);
3036
3037 if (check != data)
3038 DEV_ERR("%s: failed addr=%08x, data=%x, check=%x",
3039 __func__, offset, data, check);
3040}
3041
3042static void hdmi_msm_rmw32or(uint32 offset, uint32 data)
3043{
3044 uint32 reg_data;
3045 reg_data = inpdw(MSM_HDMI_BASE+offset);
3046 reg_data = inpdw(MSM_HDMI_BASE+offset);
3047 hdmi_msm_outpdw_chk(offset, reg_data | data);
3048}
3049
3050
3051#define HDMI_AUDIO_CFG 0x01D0
3052#define HDMI_AUDIO_ENGINE_ENABLE 1
3053#define HDMI_AUDIO_FIFO_MASK 0x000000F0
3054#define HDMI_AUDIO_FIFO_WATERMARK_SHIFT 4
3055#define HDMI_AUDIO_FIFO_MAX_WATER_MARK 8
3056
3057
3058int hdmi_audio_enable(bool on , u32 fifo_water_mark)
3059{
3060 u32 hdmi_audio_config;
3061
3062 hdmi_audio_config = HDMI_INP(HDMI_AUDIO_CFG);
3063
3064 if (on) {
3065
3066 if (fifo_water_mark > HDMI_AUDIO_FIFO_MAX_WATER_MARK) {
3067 pr_err("%s : HDMI audio fifo water mark can not be more"
3068 " than %u\n", __func__,
3069 HDMI_AUDIO_FIFO_MAX_WATER_MARK);
3070 return -EINVAL;
3071 }
3072
3073 /*
3074 * Enable HDMI Audio engine.
3075 * MUST be enabled after Audio DMA is enabled.
3076 */
3077 hdmi_audio_config &= ~(HDMI_AUDIO_FIFO_MASK);
3078
3079 hdmi_audio_config |= (HDMI_AUDIO_ENGINE_ENABLE |
3080 (fifo_water_mark << HDMI_AUDIO_FIFO_WATERMARK_SHIFT));
3081
3082 } else
3083 hdmi_audio_config &= ~(HDMI_AUDIO_ENGINE_ENABLE);
3084
3085 HDMI_OUTP(HDMI_AUDIO_CFG, hdmi_audio_config);
3086
3087 return 0;
3088}
3089EXPORT_SYMBOL(hdmi_audio_enable);
3090
3091static void hdmi_msm_audio_info_setup(boolean enabled, int num_of_channels,
3092 int level_shift, boolean down_mix)
3093{
3094 uint32 channel_allocation = 0; /* Default to FR,FL */
3095 uint32 channel_count = 1; /* Default to 2 channels
3096 -> See Table 17 in CEA-D spec */
3097 uint32 check_sum, audio_info_0_reg, audio_info_1_reg;
3098 uint32 audio_info_ctrl_reg;
3099
3100 /* Please see table 20 Audio InfoFrame in HDMI spec
3101 FL = front left
3102 FC = front Center
3103 FR = front right
3104 FLC = front left center
3105 FRC = front right center
3106 RL = rear left
3107 RC = rear center
3108 RR = rear right
3109 RLC = rear left center
3110 RRC = rear right center
3111 LFE = low frequency effect
3112 */
3113
3114 /* Read first then write because it is bundled with other controls */
3115 /* HDMI_INFOFRAME_CTRL0[0x002C] */
3116 audio_info_ctrl_reg = HDMI_INP(0x002C);
3117
3118 if (enabled) {
3119 switch (num_of_channels) {
3120 case MSM_HDMI_AUDIO_CHANNEL_2:
3121 break;
3122 case MSM_HDMI_AUDIO_CHANNEL_4:
3123 channel_count = 3;
3124 /* FC,LFE,FR,FL */
3125 channel_allocation = 0x3;
3126 break;
3127 case MSM_HDMI_AUDIO_CHANNEL_6:
3128 channel_count = 5;
3129 /* RR,RL,FC,LFE,FR,FL */
3130 channel_allocation = 0xB;
3131 break;
3132 case MSM_HDMI_AUDIO_CHANNEL_8:
3133 channel_count = 7;
3134 /* FRC,FLC,RR,RL,FC,LFE,FR,FL */
3135 channel_allocation = 0x1f;
3136 break;
3137 default:
3138 break;
3139 }
3140
3141 /* Program the Channel-Speaker allocation */
3142 audio_info_1_reg = 0;
3143 /* CA(channel_allocation) */
3144 audio_info_1_reg |= channel_allocation & 0xff;
3145 /* Program the Level shifter */
3146 /* LSV(level_shift) */
3147 audio_info_1_reg |= (level_shift << 11) & 0x00007800;
3148 /* Program the Down-mix Inhibit Flag */
3149 /* DM_INH(down_mix) */
3150 audio_info_1_reg |= (down_mix << 15) & 0x00008000;
3151
3152 /* HDMI_AUDIO_INFO1[0x00E8] */
3153 HDMI_OUTP(0x00E8, audio_info_1_reg);
3154
3155 /* Calculate CheckSum
3156 Sum of all the bytes in the Audio Info Packet bytes
3157 (See table 8.4 in HDMI spec) */
3158 check_sum = 0;
3159 /* HDMI_AUDIO_INFO_FRAME_PACKET_HEADER_TYPE[0x84] */
3160 check_sum += 0x84;
3161 /* HDMI_AUDIO_INFO_FRAME_PACKET_HEADER_VERSION[0x01] */
3162 check_sum += 1;
3163 /* HDMI_AUDIO_INFO_FRAME_PACKET_LENGTH[0x0A] */
3164 check_sum += 0x0A;
3165 check_sum += channel_count;
3166 check_sum += channel_allocation;
3167 /* See Table 8.5 in HDMI spec */
3168 check_sum += (level_shift & 0xF) << 3 | (down_mix & 0x1) << 7;
3169 check_sum &= 0xFF;
3170 check_sum = (uint8) (256 - check_sum);
3171
3172 audio_info_0_reg = 0;
3173 /* CHECKSUM(check_sum) */
3174 audio_info_0_reg |= check_sum & 0xff;
3175 /* CC(channel_count) */
3176 audio_info_0_reg |= (channel_count << 8) & 0x00000700;
3177
3178 /* HDMI_AUDIO_INFO0[0x00E4] */
3179 HDMI_OUTP(0x00E4, audio_info_0_reg);
3180
3181 /* Set these flags */
3182 /* AUDIO_INFO_UPDATE | AUDIO_INFO_SOURCE | AUDIO_INFO_CONT
3183 | AUDIO_INFO_SEND */
3184 audio_info_ctrl_reg |= 0x000000F0;
3185 } else {
3186 /* Clear these flags */
3187 /* ~(AUDIO_INFO_UPDATE | AUDIO_INFO_SOURCE | AUDIO_INFO_CONT
3188 | AUDIO_INFO_SEND) */
3189 audio_info_ctrl_reg &= ~0x000000F0;
3190 }
3191 /* HDMI_INFOFRAME_CTRL0[0x002C] */
3192 HDMI_OUTP(0x002C, audio_info_ctrl_reg);
3193}
3194
3195static void hdmi_msm_audio_ctrl_setup(boolean enabled, int delay)
3196{
3197 uint32 audio_pkt_ctrl_reg = 0;
3198
3199 /* Enable Packet Transmission */
3200 audio_pkt_ctrl_reg |= enabled ? 0x00000001 : 0;
3201 audio_pkt_ctrl_reg |= (delay << 4);
3202
3203 /* HDMI_AUDIO_PKT_CTRL1[0x0020] */
3204 HDMI_OUTP(0x0020, audio_pkt_ctrl_reg);
3205}
3206
3207static void hdmi_msm_en_gc_packet(boolean av_mute_is_requested)
3208{
3209 /* HDMI_GC[0x0040] */
3210 HDMI_OUTP(0x0040, av_mute_is_requested ? 1 : 0);
3211
3212 /* GC packet enable (every frame) */
3213 /* HDMI_VBI_PKT_CTRL[0x0028] */
3214 hdmi_msm_rmw32or(0x0028, 3 << 4);
3215}
3216
Manoj Raoc2f19592011-08-05 17:54:25 -07003217#ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_ISRC_ACP_SUPPORT
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003218static void hdmi_msm_en_isrc_packet(boolean isrc_is_continued)
3219{
3220 static const char isrc_psuedo_data[] =
3221 "ISRC1:0123456789isrc2=ABCDEFGHIJ";
3222 const uint32 * isrc_data = (const uint32 *) isrc_psuedo_data;
3223
3224 /* ISRC_STATUS =0b010 | ISRC_CONTINUE | ISRC_VALID */
3225 /* HDMI_ISRC1_0[0x00048] */
3226 HDMI_OUTP(0x00048, 2 | (isrc_is_continued ? 1 : 0) << 6 | 0 << 7);
3227
3228 /* HDMI_ISRC1_1[0x004C] */
3229 HDMI_OUTP(0x004C, *isrc_data++);
3230 /* HDMI_ISRC1_2[0x0050] */
3231 HDMI_OUTP(0x0050, *isrc_data++);
3232 /* HDMI_ISRC1_3[0x0054] */
3233 HDMI_OUTP(0x0054, *isrc_data++);
3234 /* HDMI_ISRC1_4[0x0058] */
3235 HDMI_OUTP(0x0058, *isrc_data++);
3236
3237 /* HDMI_ISRC2_0[0x005C] */
3238 HDMI_OUTP(0x005C, *isrc_data++);
3239 /* HDMI_ISRC2_1[0x0060] */
3240 HDMI_OUTP(0x0060, *isrc_data++);
3241 /* HDMI_ISRC2_2[0x0064] */
3242 HDMI_OUTP(0x0064, *isrc_data++);
3243 /* HDMI_ISRC2_3[0x0068] */
3244 HDMI_OUTP(0x0068, *isrc_data);
3245
3246 /* HDMI_VBI_PKT_CTRL[0x0028] */
3247 /* ISRC Send + Continuous */
3248 hdmi_msm_rmw32or(0x0028, 3 << 8);
3249}
Manoj Raoc2f19592011-08-05 17:54:25 -07003250#else
3251static void hdmi_msm_en_isrc_packet(boolean isrc_is_continued)
3252{
3253 /*
3254 * Until end-to-end support for various audio packets
3255 */
3256}
3257#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003258
Manoj Raoc2f19592011-08-05 17:54:25 -07003259#ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_ISRC_ACP_SUPPORT
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003260static void hdmi_msm_en_acp_packet(uint32 byte1)
3261{
3262 /* HDMI_ACP[0x003C] */
3263 HDMI_OUTP(0x003C, 2 | 1 << 8 | byte1 << 16);
3264
3265 /* HDMI_VBI_PKT_CTRL[0x0028] */
3266 /* ACP send, s/w source */
3267 hdmi_msm_rmw32or(0x0028, 3 << 12);
3268}
Manoj Raoc2f19592011-08-05 17:54:25 -07003269#else
3270static void hdmi_msm_en_acp_packet(uint32 byte1)
3271{
3272 /*
3273 * Until end-to-end support for various audio packets
3274 */
3275}
3276#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003277
3278static void hdmi_msm_audio_setup(void)
3279{
3280 const int channels = MSM_HDMI_AUDIO_CHANNEL_2;
3281
3282 /* (0) for clr_avmute, (1) for set_avmute */
3283 hdmi_msm_en_gc_packet(0);
3284 /* (0) for isrc1 only, (1) for isrc1 and isrc2 */
3285 hdmi_msm_en_isrc_packet(1);
3286 /* arbitrary bit pattern for byte1 */
3287 hdmi_msm_en_acp_packet(0x5a);
Manoj Raoc2f19592011-08-05 17:54:25 -07003288 DEV_DBG("Not setting ACP, ISRC1, ISRC2 packets\n");
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003289 hdmi_msm_audio_acr_setup(TRUE,
3290 external_common_state->video_resolution,
3291 MSM_HDMI_SAMPLE_RATE_48KHZ, channels);
3292 hdmi_msm_audio_info_setup(TRUE, channels, 0, FALSE);
3293 hdmi_msm_audio_ctrl_setup(TRUE, 1);
3294
3295 /* Turn on Audio FIFO and SAM DROP ISR */
3296 HDMI_OUTP(0x02CC, HDMI_INP(0x02CC) | BIT(1) | BIT(3));
3297 DEV_INFO("HDMI Audio: Enabled\n");
3298}
3299
3300static int hdmi_msm_audio_off(void)
3301{
3302 uint32 audio_pkt_ctrl, audio_cfg;
3303 /* Number of wait iterations */
3304 int i = 10;
3305 audio_pkt_ctrl = HDMI_INP_ND(0x0020);
3306 audio_cfg = HDMI_INP_ND(0x01D0);
3307
3308 /* Checking BIT[0] of AUDIO PACKET CONTROL and */
3309 /* AUDIO CONFIGURATION register */
3310 while (((audio_pkt_ctrl & 0x00000001) || (audio_cfg & 0x00000001))
3311 && (i--)) {
3312 audio_pkt_ctrl = HDMI_INP_ND(0x0020);
3313 audio_cfg = HDMI_INP_ND(0x01D0);
3314 DEV_DBG("%d times :: HDMI AUDIO PACKET is %08x and "
3315 "AUDIO CFG is %08x", i, audio_pkt_ctrl, audio_cfg);
3316 msleep(100);
3317 if (!i) {
3318 DEV_ERR("%s:failed to set BIT[0] AUDIO PACKET"
3319 "CONTROL or AUDIO CONFIGURATION REGISTER\n",
3320 __func__);
3321 return -ETIMEDOUT;
3322 }
3323 }
3324 hdmi_msm_audio_info_setup(FALSE, 0, 0, FALSE);
3325 hdmi_msm_audio_ctrl_setup(FALSE, 0);
3326 hdmi_msm_audio_acr_setup(FALSE, 0, 0, 0);
3327 DEV_INFO("HDMI Audio: Disabled\n");
3328 return 0;
3329}
3330
3331
Manoj Raobbf9a472011-06-14 21:05:18 -07003332static uint8 hdmi_msm_avi_iframe_lut[][15] = {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003333/* 480p60 480i60 576p50 576i50 720p60 720p50 1080p60 1080i60 1080p50
Manoj Raobbf9a472011-06-14 21:05:18 -07003334 1080i50 1080p24 1080p30 1080p25 640x480p 480p60_16_9*/
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003335 {0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
Manoj Raobbf9a472011-06-14 21:05:18 -07003336 0x10, 0x10, 0x10, 0x10, 0x10, 0x10}, /*00*/
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003337 {0x18, 0x18, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28,
Manoj Raobbf9a472011-06-14 21:05:18 -07003338 0x28, 0x28, 0x28, 0x28, 0x18, 0x28}, /*01*/
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003339 {0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
Manoj Raobbf9a472011-06-14 21:05:18 -07003340 0x04, 0x04, 0x04, 0x04, 0x88, 0x04}, /*02*/
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003341 {0x02, 0x06, 0x11, 0x15, 0x04, 0x13, 0x10, 0x05, 0x1F,
Manoj Raobbf9a472011-06-14 21:05:18 -07003342 0x14, 0x20, 0x22, 0x21, 0x01, 0x03}, /*03*/
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003343 {0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
Manoj Raobbf9a472011-06-14 21:05:18 -07003344 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*04*/
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003345 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Manoj Raobbf9a472011-06-14 21:05:18 -07003346 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*05*/
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003347 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Manoj Raobbf9a472011-06-14 21:05:18 -07003348 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*06*/
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003349 {0xE1, 0xE1, 0x41, 0x41, 0xD1, 0xd1, 0x39, 0x39, 0x39,
Manoj Raobbf9a472011-06-14 21:05:18 -07003350 0x39, 0x39, 0x39, 0x39, 0xe1, 0xE1}, /*07*/
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003351 {0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x04, 0x04, 0x04,
Manoj Raobbf9a472011-06-14 21:05:18 -07003352 0x04, 0x04, 0x04, 0x04, 0x01, 0x01}, /*08*/
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003353 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Manoj Raobbf9a472011-06-14 21:05:18 -07003354 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*09*/
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003355 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
Manoj Raobbf9a472011-06-14 21:05:18 -07003356 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*10*/
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003357 {0xD1, 0xD1, 0xD1, 0xD1, 0x01, 0x01, 0x81, 0x81, 0x81,
Manoj Raobbf9a472011-06-14 21:05:18 -07003358 0x81, 0x81, 0x81, 0x81, 0x81, 0xD1}, /*11*/
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003359 {0x02, 0x02, 0x02, 0x02, 0x05, 0x05, 0x07, 0x07, 0x07,
Manoj Raobbf9a472011-06-14 21:05:18 -07003360 0x07, 0x07, 0x07, 0x07, 0x02, 0x02} /*12*/
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003361};
3362
3363static void hdmi_msm_avi_info_frame(void)
3364{
3365 /* two header + length + 13 data */
3366 uint8 aviInfoFrame[16];
3367 uint8 checksum;
3368 uint32 sum;
3369 uint32 regVal;
3370 int i;
3371 int mode = 0;
3372
3373 switch (external_common_state->video_resolution) {
Manoj Raobbf9a472011-06-14 21:05:18 -07003374 case HDMI_VFRMT_720x480p60_4_3:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003375 mode = 0;
3376 break;
3377 case HDMI_VFRMT_720x480i60_16_9:
3378 mode = 1;
3379 break;
3380 case HDMI_VFRMT_720x576p50_16_9:
3381 mode = 2;
3382 break;
3383 case HDMI_VFRMT_720x576i50_16_9:
3384 mode = 3;
3385 break;
3386 case HDMI_VFRMT_1280x720p60_16_9:
3387 mode = 4;
3388 break;
3389 case HDMI_VFRMT_1280x720p50_16_9:
3390 mode = 5;
3391 break;
3392 case HDMI_VFRMT_1920x1080p60_16_9:
3393 mode = 6;
3394 break;
3395 case HDMI_VFRMT_1920x1080i60_16_9:
3396 mode = 7;
3397 break;
3398 case HDMI_VFRMT_1920x1080p50_16_9:
3399 mode = 8;
3400 break;
3401 case HDMI_VFRMT_1920x1080i50_16_9:
3402 mode = 9;
3403 break;
3404 case HDMI_VFRMT_1920x1080p24_16_9:
3405 mode = 10;
3406 break;
3407 case HDMI_VFRMT_1920x1080p30_16_9:
3408 mode = 11;
3409 break;
3410 case HDMI_VFRMT_1920x1080p25_16_9:
3411 mode = 12;
3412 break;
3413 case HDMI_VFRMT_640x480p60_4_3:
3414 mode = 13;
3415 break;
Manoj Raobbf9a472011-06-14 21:05:18 -07003416 case HDMI_VFRMT_720x480p60_16_9:
3417 mode = 14;
3418 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003419 default:
3420 DEV_INFO("%s: mode %d not supported\n", __func__,
3421 external_common_state->video_resolution);
3422 return;
3423 }
3424
3425 /* InfoFrame Type = 82 */
3426 aviInfoFrame[0] = 0x82;
3427 /* Version = 2 */
3428 aviInfoFrame[1] = 2;
3429 /* Length of AVI InfoFrame = 13 */
3430 aviInfoFrame[2] = 13;
3431
3432 /* Data Byte 01: 0 Y1 Y0 A0 B1 B0 S1 S0 */
3433 aviInfoFrame[3] = hdmi_msm_avi_iframe_lut[0][mode];
3434 /* Data Byte 02: C1 C0 M1 M0 R3 R2 R1 R0 */
3435 aviInfoFrame[4] = hdmi_msm_avi_iframe_lut[1][mode];
3436 /* Data Byte 03: ITC EC2 EC1 EC0 Q1 Q0 SC1 SC0 */
3437 aviInfoFrame[5] = hdmi_msm_avi_iframe_lut[2][mode];
3438 /* Data Byte 04: 0 VIC6 VIC5 VIC4 VIC3 VIC2 VIC1 VIC0 */
3439 aviInfoFrame[6] = hdmi_msm_avi_iframe_lut[3][mode];
3440 /* Data Byte 05: 0 0 0 0 PR3 PR2 PR1 PR0 */
3441 aviInfoFrame[7] = hdmi_msm_avi_iframe_lut[4][mode];
3442 /* Data Byte 06: LSB Line No of End of Top Bar */
3443 aviInfoFrame[8] = hdmi_msm_avi_iframe_lut[5][mode];
3444 /* Data Byte 07: MSB Line No of End of Top Bar */
3445 aviInfoFrame[9] = hdmi_msm_avi_iframe_lut[6][mode];
3446 /* Data Byte 08: LSB Line No of Start of Bottom Bar */
3447 aviInfoFrame[10] = hdmi_msm_avi_iframe_lut[7][mode];
3448 /* Data Byte 09: MSB Line No of Start of Bottom Bar */
3449 aviInfoFrame[11] = hdmi_msm_avi_iframe_lut[8][mode];
3450 /* Data Byte 10: LSB Pixel Number of End of Left Bar */
3451 aviInfoFrame[12] = hdmi_msm_avi_iframe_lut[9][mode];
3452 /* Data Byte 11: MSB Pixel Number of End of Left Bar */
3453 aviInfoFrame[13] = hdmi_msm_avi_iframe_lut[10][mode];
3454 /* Data Byte 12: LSB Pixel Number of Start of Right Bar */
3455 aviInfoFrame[14] = hdmi_msm_avi_iframe_lut[11][mode];
3456 /* Data Byte 13: MSB Pixel Number of Start of Right Bar */
3457 aviInfoFrame[15] = hdmi_msm_avi_iframe_lut[12][mode];
3458
3459 sum = 0;
3460 for (i = 0; i < 16; i++)
3461 sum += aviInfoFrame[i];
3462 sum &= 0xFF;
3463 sum = 256 - sum;
3464 checksum = (uint8) sum;
3465
3466 regVal = aviInfoFrame[5];
3467 regVal = regVal << 8 | aviInfoFrame[4];
3468 regVal = regVal << 8 | aviInfoFrame[3];
3469 regVal = regVal << 8 | checksum;
3470 HDMI_OUTP(0x006C, regVal);
3471
3472 regVal = aviInfoFrame[9];
3473 regVal = regVal << 8 | aviInfoFrame[8];
3474 regVal = regVal << 8 | aviInfoFrame[7];
3475 regVal = regVal << 8 | aviInfoFrame[6];
3476 HDMI_OUTP(0x0070, regVal);
3477
3478 regVal = aviInfoFrame[13];
3479 regVal = regVal << 8 | aviInfoFrame[12];
3480 regVal = regVal << 8 | aviInfoFrame[11];
3481 regVal = regVal << 8 | aviInfoFrame[10];
3482 HDMI_OUTP(0x0074, regVal);
3483
3484 regVal = aviInfoFrame[1];
3485 regVal = regVal << 16 | aviInfoFrame[15];
3486 regVal = regVal << 8 | aviInfoFrame[14];
3487 HDMI_OUTP(0x0078, regVal);
3488
3489 /* INFOFRAME_CTRL0[0x002C] */
3490 /* 0x3 for AVI InfFrame enable (every frame) */
3491 HDMI_OUTP(0x002C, HDMI_INP(0x002C) | 0x00000003L);
3492}
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003493
3494#ifdef CONFIG_FB_MSM_HDMI_3D
3495static void hdmi_msm_vendor_infoframe_packetsetup(void)
3496{
3497 uint32 packet_header = 0;
3498 uint32 check_sum = 0;
3499 uint32 packet_payload = 0;
3500
3501 if (!external_common_state->format_3d) {
3502 HDMI_OUTP(0x0034, 0);
3503 return;
3504 }
3505
3506 /* 0x0084 GENERIC0_HDR
3507 * HB0 7:0 NUM
3508 * HB1 15:8 NUM
3509 * HB2 23:16 NUM */
3510 /* Setup Packet header and payload */
3511 /* 0x81 VS_INFO_FRAME_ID
3512 0x01 VS_INFO_FRAME_VERSION
3513 0x1B VS_INFO_FRAME_PAYLOAD_LENGTH */
3514 packet_header = 0x81 | (0x01 << 8) | (0x1B << 16);
3515 HDMI_OUTP(0x0084, packet_header);
3516
3517 check_sum = packet_header & 0xff;
3518 check_sum += (packet_header >> 8) & 0xff;
3519 check_sum += (packet_header >> 16) & 0xff;
3520
3521 /* 0x008C GENERIC0_1
3522 * BYTE4 7:0 NUM
3523 * BYTE5 15:8 NUM
3524 * BYTE6 23:16 NUM
3525 * BYTE7 31:24 NUM */
3526 /* 0x02 VS_INFO_FRAME_3D_PRESENT */
3527 packet_payload = 0x02 << 5;
3528 switch (external_common_state->format_3d) {
3529 case 1:
3530 /* 0b1000 VIDEO_3D_FORMAT_SIDE_BY_SIDE_HALF */
3531 packet_payload |= (0x08 << 8) << 4;
3532 break;
3533 case 2:
3534 /* 0b0110 VIDEO_3D_FORMAT_TOP_AND_BOTTOM_HALF */
3535 packet_payload |= (0x06 << 8) << 4;
3536 break;
3537 }
3538 HDMI_OUTP(0x008C, packet_payload);
3539
3540 check_sum += packet_payload & 0xff;
3541 check_sum += (packet_payload >> 8) & 0xff;
3542
3543 #define IEEE_REGISTRATION_ID 0xC03
3544 /* Next 3 bytes are IEEE Registration Identifcation */
3545 /* 0x0088 GENERIC0_0
3546 * BYTE0 7:0 NUM (checksum)
3547 * BYTE1 15:8 NUM
3548 * BYTE2 23:16 NUM
3549 * BYTE3 31:24 NUM */
3550 check_sum += IEEE_REGISTRATION_ID & 0xff;
3551 check_sum += (IEEE_REGISTRATION_ID >> 8) & 0xff;
3552 check_sum += (IEEE_REGISTRATION_ID >> 16) & 0xff;
3553
3554 HDMI_OUTP(0x0088, (0x100 - (0xff & check_sum))
3555 | ((IEEE_REGISTRATION_ID & 0xff) << 8)
3556 | (((IEEE_REGISTRATION_ID >> 8) & 0xff) << 16)
3557 | (((IEEE_REGISTRATION_ID >> 16) & 0xff) << 24));
3558
3559 /* 0x0034 GEN_PKT_CTRL
3560 * GENERIC0_SEND 0 0 = Disable Generic0 Packet Transmission
3561 * 1 = Enable Generic0 Packet Transmission
3562 * GENERIC0_CONT 1 0 = Send Generic0 Packet on next frame only
3563 * 1 = Send Generic0 Packet on every frame
3564 * GENERIC0_UPDATE 2 NUM
3565 * GENERIC1_SEND 4 0 = Disable Generic1 Packet Transmission
3566 * 1 = Enable Generic1 Packet Transmission
3567 * GENERIC1_CONT 5 0 = Send Generic1 Packet on next frame only
3568 * 1 = Send Generic1 Packet on every frame
3569 * GENERIC0_LINE 21:16 NUM
3570 * GENERIC1_LINE 29:24 NUM
3571 */
3572 /* GENERIC0_LINE | GENERIC0_UPDATE | GENERIC0_CONT | GENERIC0_SEND
3573 * Setup HDMI TX generic packet control
3574 * Enable this packet to transmit every frame
3575 * Enable this packet to transmit every frame
3576 * Enable HDMI TX engine to transmit Generic packet 0 */
3577 HDMI_OUTP(0x0034, (1 << 16) | (1 << 2) | BIT(1) | BIT(0));
3578}
3579
3580static void hdmi_msm_switch_3d(boolean on)
3581{
3582 mutex_lock(&external_common_state_hpd_mutex);
3583 if (external_common_state->hpd_state)
3584 hdmi_msm_vendor_infoframe_packetsetup();
3585 mutex_unlock(&external_common_state_hpd_mutex);
3586}
3587#endif
3588
Ravishangar Kalyanam49a83b22011-07-20 15:28:44 -07003589int hdmi_msm_clk(int on)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003590{
3591 int rc;
3592
3593 DEV_DBG("HDMI Clk: %s\n", on ? "Enable" : "Disable");
3594 if (on) {
3595 rc = clk_enable(hdmi_msm_state->hdmi_app_clk);
3596 if (rc) {
3597 DEV_ERR("'hdmi_app_clk' clock enable failed, rc=%d\n",
3598 rc);
3599 return rc;
3600 }
3601
3602 rc = clk_enable(hdmi_msm_state->hdmi_m_pclk);
3603 if (rc) {
3604 DEV_ERR("'hdmi_m_pclk' clock enable failed, rc=%d\n",
3605 rc);
3606 return rc;
3607 }
3608
3609 rc = clk_enable(hdmi_msm_state->hdmi_s_pclk);
3610 if (rc) {
3611 DEV_ERR("'hdmi_s_pclk' clock enable failed, rc=%d\n",
3612 rc);
3613 return rc;
3614 }
3615 } else {
3616 clk_disable(hdmi_msm_state->hdmi_app_clk);
3617 clk_disable(hdmi_msm_state->hdmi_m_pclk);
3618 clk_disable(hdmi_msm_state->hdmi_s_pclk);
3619 }
3620
3621 return 0;
3622}
3623
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003624static void hdmi_msm_turn_on(void)
3625{
3626 uint32 hpd_ctrl;
3627
3628 hdmi_msm_reset_core();
3629 hdmi_msm_init_phy(external_common_state->video_resolution);
3630 /* HDMI_USEC_REFTIMER[0x0208] */
3631 HDMI_OUTP(0x0208, 0x0001001B);
3632
3633 hdmi_msm_video_setup(external_common_state->video_resolution);
3634 if (!hdmi_msm_is_dvi_mode())
3635 hdmi_msm_audio_setup();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003636 hdmi_msm_avi_info_frame();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003637#ifdef CONFIG_FB_MSM_HDMI_3D
3638 hdmi_msm_vendor_infoframe_packetsetup();
3639#endif
3640
3641 /* set timeout to 4.1ms (max) for hardware debounce */
3642 hpd_ctrl = (HDMI_INP(0x0258) & ~0xFFF) | 0xFFF;
3643
3644 /* Toggle HPD circuit to trigger HPD sense */
3645 HDMI_OUTP(0x0258, ~(1 << 28) & hpd_ctrl);
3646 HDMI_OUTP(0x0258, (1 << 28) | hpd_ctrl);
3647
3648 hdmi_msm_set_mode(TRUE);
3649
3650 /* Setup HPD IRQ */
3651 HDMI_OUTP(0x0254, 4 | (external_common_state->hpd_state ? 0 : 2));
3652
3653#ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT
3654 if (hdmi_msm_state->reauth) {
3655 hdmi_msm_hdcp_enable();
3656 hdmi_msm_state->reauth = FALSE ;
3657 }
3658#endif /* CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT */
Manoj Raoa2c27672011-08-30 17:19:39 -07003659
3660#ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_CEC_SUPPORT
3661 /* re-initialize CEC if enabled */
3662 mutex_lock(&hdmi_msm_state_mutex);
3663 if (hdmi_msm_state->cec_enabled == true) {
3664 hdmi_msm_cec_init();
3665 hdmi_msm_cec_write_logical_addr(
3666 hdmi_msm_state->cec_logical_addr);
3667 }
3668 mutex_unlock(&hdmi_msm_state_mutex);
3669#endif /* CONFIG_FB_MSM_HDMI_MSM_PANEL_CEC_SUPPORT */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003670 DEV_INFO("HDMI Core: Initialized\n");
3671}
3672
3673static void hdmi_msm_hpd_state_timer(unsigned long data)
3674{
3675 queue_work(hdmi_work_queue, &hdmi_msm_state->hpd_state_work);
3676}
3677
3678#ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT
3679static void hdmi_msm_hdcp_timer(unsigned long data)
3680{
3681 queue_work(hdmi_work_queue, &hdmi_msm_state->hdcp_work);
3682}
3683#endif
3684
3685static void hdmi_msm_hpd_read_work(struct work_struct *work)
3686{
3687 uint32 hpd_ctrl;
3688
3689 clk_enable(hdmi_msm_state->hdmi_app_clk);
3690 hdmi_msm_state->pd->core_power(1, 1);
3691 hdmi_msm_state->pd->enable_5v(1);
3692 hdmi_msm_set_mode(FALSE);
3693 hdmi_msm_init_phy(external_common_state->video_resolution);
3694 /* HDMI_USEC_REFTIMER[0x0208] */
3695 HDMI_OUTP(0x0208, 0x0001001B);
3696 hpd_ctrl = (HDMI_INP(0x0258) & ~0xFFF) | 0xFFF;
3697
3698 /* Toggle HPD circuit to trigger HPD sense */
3699 HDMI_OUTP(0x0258, ~(1 << 28) & hpd_ctrl);
3700 HDMI_OUTP(0x0258, (1 << 28) | hpd_ctrl);
3701
3702 hdmi_msm_set_mode(TRUE);
3703 msleep(1000);
3704 external_common_state->hpd_state = (HDMI_INP(0x0250) & 0x2) >> 1;
3705 if (external_common_state->hpd_state) {
3706 hdmi_msm_read_edid();
3707 DEV_DBG("%s: sense CONNECTED: send ONLINE\n", __func__);
3708 kobject_uevent(external_common_state->uevent_kobj,
3709 KOBJ_ONLINE);
3710 }
3711 hdmi_msm_hpd_off();
3712 hdmi_msm_set_mode(FALSE);
3713 hdmi_msm_state->pd->core_power(0, 1);
3714 hdmi_msm_state->pd->enable_5v(0);
3715 clk_disable(hdmi_msm_state->hdmi_app_clk);
3716}
3717
3718static void hdmi_msm_hpd_off(void)
3719{
3720 DEV_DBG("%s: (timer, clk, 5V, core, IRQ off)\n", __func__);
3721 del_timer(&hdmi_msm_state->hpd_state_timer);
3722 disable_irq(hdmi_msm_state->irq);
3723
3724 hdmi_msm_set_mode(FALSE);
3725 HDMI_OUTP_ND(0x0308, 0x7F); /*0b01111111*/
3726 hdmi_msm_state->hpd_initialized = FALSE;
Manoj Raoa2c27672011-08-30 17:19:39 -07003727 hdmi_msm_state->pd->cec_power(0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003728 hdmi_msm_state->pd->enable_5v(0);
3729 hdmi_msm_state->pd->core_power(0, 1);
3730 hdmi_msm_clk(0);
3731 hdmi_msm_state->hpd_initialized = FALSE;
3732}
3733
Manoj Rao668d6d52011-08-16 19:12:31 -07003734static void hdmi_msm_dump_regs(const char *prefix)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003735{
3736#ifdef REG_DUMP
3737 print_hex_dump(KERN_INFO, prefix, DUMP_PREFIX_OFFSET, 32, 4,
3738 (void *)MSM_HDMI_BASE, 0x0334, false);
3739#endif
3740}
3741
3742static int hdmi_msm_hpd_on(bool trigger_handler)
3743{
3744 static int phy_reset_done;
3745
3746 hdmi_msm_clk(1);
3747 hdmi_msm_state->pd->core_power(1, 1);
3748 hdmi_msm_state->pd->enable_5v(1);
Manoj Raoa2c27672011-08-30 17:19:39 -07003749 hdmi_msm_state->pd->cec_power(1);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003750 hdmi_msm_dump_regs("HDMI-INIT: ");
3751 hdmi_msm_set_mode(FALSE);
3752
3753 if (!phy_reset_done) {
3754 hdmi_phy_reset();
3755 phy_reset_done = 1;
3756 }
3757
3758 hdmi_msm_init_phy(external_common_state->video_resolution);
3759 /* HDMI_USEC_REFTIMER[0x0208] */
3760 HDMI_OUTP(0x0208, 0x0001001B);
3761
3762 /* Check HPD State */
3763 if (!hdmi_msm_state->hpd_initialized) {
3764 uint32 hpd_ctrl;
3765 enable_irq(hdmi_msm_state->irq);
3766
3767 /* set timeout to 4.1ms (max) for hardware debounce */
3768 hpd_ctrl = (HDMI_INP(0x0258) & ~0xFFF) | 0xFFF;
3769
3770 /* Toggle HPD circuit to trigger HPD sense */
3771 HDMI_OUTP(0x0258, ~(1 << 28) & hpd_ctrl);
3772 HDMI_OUTP(0x0258, (1 << 28) | hpd_ctrl);
3773
3774 DEV_DBG("%s: (clk, 5V, core, IRQ on) <trigger:%s>\n", __func__,
3775 trigger_handler ? "true" : "false");
3776
3777 if (trigger_handler) {
3778 /* Set HPD state machine: ensure at least 2 readouts */
3779 mutex_lock(&hdmi_msm_state_mutex);
3780 hdmi_msm_state->hpd_stable = 0;
3781 hdmi_msm_state->hpd_prev_state = TRUE;
3782 mutex_lock(&external_common_state_hpd_mutex);
3783 external_common_state->hpd_state = FALSE;
3784 mutex_unlock(&external_common_state_hpd_mutex);
3785 hdmi_msm_state->hpd_cable_chg_detected = TRUE;
3786 mutex_unlock(&hdmi_msm_state_mutex);
3787 mod_timer(&hdmi_msm_state->hpd_state_timer,
3788 jiffies + HZ/2);
3789 }
3790
3791 hdmi_msm_state->hpd_initialized = TRUE;
3792 }
3793 hdmi_msm_set_mode(TRUE);
3794
3795 return 0;
3796}
3797
3798static int hdmi_msm_power_on(struct platform_device *pdev)
3799{
3800 struct msm_fb_data_type *mfd = platform_get_drvdata(pdev);
3801 bool changed;
3802
3803 if (!hdmi_msm_state || !hdmi_msm_state->hdmi_app_clk || !MSM_HDMI_BASE)
3804 return -ENODEV;
3805#ifdef CONFIG_SUSPEND
3806 mutex_lock(&hdmi_msm_state_mutex);
3807 if (hdmi_msm_state->pm_suspended) {
3808 mutex_unlock(&hdmi_msm_state_mutex);
3809 DEV_WARN("%s: ignored, pm_suspended\n", __func__);
3810 return -ENODEV;
3811 }
3812 mutex_unlock(&hdmi_msm_state_mutex);
3813#endif
3814
3815 DEV_INFO("power: ON (%dx%d %d)\n", mfd->var_xres, mfd->var_yres,
3816 mfd->var_pixclock);
3817
3818#ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT
3819 mutex_lock(&hdmi_msm_state_mutex);
3820 if (hdmi_msm_state->hdcp_activating) {
3821 hdmi_msm_state->panel_power_on = TRUE;
3822 DEV_INFO("HDCP: activating, returning\n");
3823 }
3824 mutex_unlock(&hdmi_msm_state_mutex);
3825#endif /* CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT */
3826
3827 changed = hdmi_common_get_video_format_from_drv_data(mfd);
3828 if (!external_common_state->hpd_feature_on) {
3829 int rc = hdmi_msm_hpd_on(true);
3830 DEV_INFO("HPD: panel power without 'hpd' feature on\n");
3831 if (rc) {
3832 DEV_WARN("HPD: activation failed: rc=%d\n", rc);
3833 return rc;
3834 }
3835 }
3836 hdmi_msm_audio_info_setup(TRUE, 0, 0, FALSE);
3837
3838 mutex_lock(&external_common_state_hpd_mutex);
3839 hdmi_msm_state->panel_power_on = TRUE;
3840 if ((external_common_state->hpd_state && !hdmi_msm_is_power_on())
3841 || changed) {
3842 mutex_unlock(&external_common_state_hpd_mutex);
3843 hdmi_msm_turn_on();
3844 } else
3845 mutex_unlock(&external_common_state_hpd_mutex);
3846
3847 hdmi_msm_dump_regs("HDMI-ON: ");
3848
3849 DEV_INFO("power=%s DVI= %s\n",
3850 hdmi_msm_is_power_on() ? "ON" : "OFF" ,
3851 hdmi_msm_is_dvi_mode() ? "ON" : "OFF");
3852 return 0;
3853}
3854
3855/* Note that power-off will also be called when the cable-remove event is
3856 * processed on the user-space and as a result the framebuffer is powered
3857 * down. However, we are still required to be able to detect a cable-insert
3858 * event; so for now leave the HDMI engine running; so that the HPD IRQ is
3859 * still being processed.
3860 */
3861static int hdmi_msm_power_off(struct platform_device *pdev)
3862{
3863 if (!hdmi_msm_state->hdmi_app_clk)
3864 return -ENODEV;
3865#ifdef CONFIG_SUSPEND
3866 mutex_lock(&hdmi_msm_state_mutex);
3867 if (hdmi_msm_state->pm_suspended) {
3868 mutex_unlock(&hdmi_msm_state_mutex);
3869 DEV_WARN("%s: ignored, pm_suspended\n", __func__);
3870 return -ENODEV;
3871 }
3872 mutex_unlock(&hdmi_msm_state_mutex);
3873#endif
3874
3875#ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT
3876 mutex_lock(&hdmi_msm_state_mutex);
3877 if (hdmi_msm_state->hdcp_activating) {
3878 hdmi_msm_state->panel_power_on = FALSE;
3879 mutex_unlock(&hdmi_msm_state_mutex);
3880 DEV_INFO("HDCP: activating, returning\n");
3881 return 0;
3882 }
3883 mutex_unlock(&hdmi_msm_state_mutex);
3884#endif /* CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT */
3885
3886 DEV_INFO("power: OFF (audio off, Reset Core)\n");
3887 hdmi_msm_audio_off();
3888#ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT
3889 hdcp_deauthenticate();
3890#endif
3891 hdmi_msm_hpd_off();
3892 hdmi_msm_powerdown_phy();
3893 hdmi_msm_dump_regs("HDMI-OFF: ");
Manoj Rao53ac99d2011-10-10 17:32:28 -07003894 hdmi_msm_hpd_on(true);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003895
3896 mutex_lock(&external_common_state_hpd_mutex);
3897 if (!external_common_state->hpd_feature_on)
3898 hdmi_msm_hpd_off();
3899 mutex_unlock(&external_common_state_hpd_mutex);
3900
3901 hdmi_msm_state->panel_power_on = FALSE;
3902 return 0;
3903}
3904
3905static int __devinit hdmi_msm_probe(struct platform_device *pdev)
3906{
3907 int rc;
3908 struct platform_device *fb_dev;
3909
Stepan Moskovchenko164fe8a2011-08-05 18:10:54 -07003910 if (cpu_is_apq8064())
3911 return -ENODEV;
3912
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003913 if (!hdmi_msm_state) {
3914 pr_err("%s: hdmi_msm_state is NULL\n", __func__);
3915 return -ENOMEM;
3916 }
3917
3918 external_common_state->dev = &pdev->dev;
3919 DEV_DBG("probe\n");
3920 if (pdev->id == 0) {
3921 struct resource *res;
3922
3923 #define GET_RES(name, mode) do { \
3924 res = platform_get_resource_byname(pdev, mode, name); \
3925 if (!res) { \
3926 DEV_ERR("'" name "' resource not found\n"); \
3927 rc = -ENODEV; \
3928 goto error; \
3929 } \
3930 } while (0)
3931
3932 #define IO_REMAP(var, name) do { \
3933 GET_RES(name, IORESOURCE_MEM); \
3934 var = ioremap(res->start, resource_size(res)); \
3935 if (!var) { \
3936 DEV_ERR("'" name "' ioremap failed\n"); \
3937 rc = -ENOMEM; \
3938 goto error; \
3939 } \
3940 } while (0)
3941
3942 #define GET_IRQ(var, name) do { \
3943 GET_RES(name, IORESOURCE_IRQ); \
3944 var = res->start; \
3945 } while (0)
3946
3947 IO_REMAP(hdmi_msm_state->qfprom_io, "hdmi_msm_qfprom_addr");
3948 hdmi_msm_state->hdmi_io = MSM_HDMI_BASE;
3949 GET_IRQ(hdmi_msm_state->irq, "hdmi_msm_irq");
3950
3951 hdmi_msm_state->pd = pdev->dev.platform_data;
3952
3953 #undef GET_RES
3954 #undef IO_REMAP
3955 #undef GET_IRQ
3956 return 0;
3957 }
3958
Matt Wagantall5a4f1ba2011-08-18 18:13:03 -07003959 hdmi_msm_state->hdmi_app_clk = clk_get(&pdev->dev, "core_clk");
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003960 if (IS_ERR(hdmi_msm_state->hdmi_app_clk)) {
Matt Wagantall5a4f1ba2011-08-18 18:13:03 -07003961 DEV_ERR("'core_clk' clk not found\n");
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003962 rc = IS_ERR(hdmi_msm_state->hdmi_app_clk);
3963 goto error;
3964 }
3965
Matt Wagantall5a4f1ba2011-08-18 18:13:03 -07003966 hdmi_msm_state->hdmi_m_pclk = clk_get(&pdev->dev, "master_iface_clk");
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003967 if (IS_ERR(hdmi_msm_state->hdmi_m_pclk)) {
Matt Wagantall5a4f1ba2011-08-18 18:13:03 -07003968 DEV_ERR("'master_iface_clk' clk not found\n");
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003969 rc = IS_ERR(hdmi_msm_state->hdmi_m_pclk);
3970 goto error;
3971 }
3972
Matt Wagantall5a4f1ba2011-08-18 18:13:03 -07003973 hdmi_msm_state->hdmi_s_pclk = clk_get(&pdev->dev, "slave_iface_clk");
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003974 if (IS_ERR(hdmi_msm_state->hdmi_s_pclk)) {
Matt Wagantall5a4f1ba2011-08-18 18:13:03 -07003975 DEV_ERR("'slave_iface_clk' clk not found\n");
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003976 rc = IS_ERR(hdmi_msm_state->hdmi_s_pclk);
3977 goto error;
3978 }
3979
3980 rc = check_hdmi_features();
3981 if (rc) {
3982 DEV_ERR("Init FAILED: check_hdmi_features rc=%d\n", rc);
3983 goto error;
3984 }
3985
3986 if (!hdmi_msm_state->pd->core_power) {
3987 DEV_ERR("Init FAILED: core_power function missing\n");
3988 rc = -ENODEV;
3989 goto error;
3990 }
3991 if (!hdmi_msm_state->pd->enable_5v) {
3992 DEV_ERR("Init FAILED: enable_5v function missing\n");
3993 rc = -ENODEV;
3994 goto error;
3995 }
3996
Manoj Raoa2c27672011-08-30 17:19:39 -07003997 if (!hdmi_msm_state->pd->cec_power) {
3998 DEV_ERR("Init FAILED: cec_power function missing\n");
3999 rc = -ENODEV;
4000 goto error;
4001 }
4002
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004003 rc = request_threaded_irq(hdmi_msm_state->irq, NULL, &hdmi_msm_isr,
4004 IRQF_TRIGGER_HIGH | IRQF_ONESHOT, "hdmi_msm_isr", NULL);
4005 if (rc) {
4006 DEV_ERR("Init FAILED: IRQ request, rc=%d\n", rc);
4007 goto error;
4008 }
4009 disable_irq(hdmi_msm_state->irq);
4010
4011 init_timer(&hdmi_msm_state->hpd_state_timer);
4012 hdmi_msm_state->hpd_state_timer.function =
4013 hdmi_msm_hpd_state_timer;
4014 hdmi_msm_state->hpd_state_timer.data = (uint32)NULL;
4015
4016 hdmi_msm_state->hpd_state_timer.expires = 0xffffffffL;
4017 add_timer(&hdmi_msm_state->hpd_state_timer);
4018
4019#ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT
4020 init_timer(&hdmi_msm_state->hdcp_timer);
4021 hdmi_msm_state->hdcp_timer.function =
4022 hdmi_msm_hdcp_timer;
4023 hdmi_msm_state->hdcp_timer.data = (uint32)NULL;
4024
4025 hdmi_msm_state->hdcp_timer.expires = 0xffffffffL;
4026 add_timer(&hdmi_msm_state->hdcp_timer);
4027#endif /* CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT */
4028
4029 fb_dev = msm_fb_add_device(pdev);
4030 if (fb_dev) {
4031 rc = external_common_state_create(fb_dev);
4032 if (rc) {
4033 DEV_ERR("Init FAILED: hdmi_msm_state_create, rc=%d\n",
4034 rc);
4035 goto error;
4036 }
4037 } else
4038 DEV_ERR("Init FAILED: failed to add fb device\n");
4039
4040 DEV_INFO("HDMI HPD: ON\n");
4041
4042 rc = hdmi_msm_hpd_on(true);
4043 if (rc)
4044 goto error;
4045
4046 if (hdmi_msm_has_hdcp())
4047 external_common_state->present_hdcp = TRUE;
4048 else {
4049 external_common_state->present_hdcp = FALSE;
4050#ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT
4051 /*
4052 * If the device is not hdcp capable do
4053 * not start hdcp timer.
4054 */
4055 del_timer(&hdmi_msm_state->hdcp_timer);
4056#endif
4057 }
4058
4059 queue_work(hdmi_work_queue, &hdmi_msm_state->hpd_read_work);
4060 return 0;
4061
4062error:
4063 if (hdmi_msm_state->qfprom_io)
4064 iounmap(hdmi_msm_state->qfprom_io);
4065 hdmi_msm_state->qfprom_io = NULL;
4066
4067 if (hdmi_msm_state->hdmi_io)
4068 iounmap(hdmi_msm_state->hdmi_io);
4069 hdmi_msm_state->hdmi_io = NULL;
4070
4071 external_common_state_remove();
4072
4073 if (hdmi_msm_state->hdmi_app_clk)
4074 clk_put(hdmi_msm_state->hdmi_app_clk);
4075 if (hdmi_msm_state->hdmi_m_pclk)
4076 clk_put(hdmi_msm_state->hdmi_m_pclk);
4077 if (hdmi_msm_state->hdmi_s_pclk)
4078 clk_put(hdmi_msm_state->hdmi_s_pclk);
4079
4080 hdmi_msm_state->hdmi_app_clk = NULL;
4081 hdmi_msm_state->hdmi_m_pclk = NULL;
4082 hdmi_msm_state->hdmi_s_pclk = NULL;
4083
4084 return rc;
4085}
4086
4087static int __devexit hdmi_msm_remove(struct platform_device *pdev)
4088{
4089 DEV_INFO("HDMI device: remove\n");
4090
4091 DEV_INFO("HDMI HPD: OFF\n");
4092 hdmi_msm_hpd_off();
4093 free_irq(hdmi_msm_state->irq, NULL);
4094
4095 if (hdmi_msm_state->qfprom_io)
4096 iounmap(hdmi_msm_state->qfprom_io);
4097 hdmi_msm_state->qfprom_io = NULL;
4098
4099 if (hdmi_msm_state->hdmi_io)
4100 iounmap(hdmi_msm_state->hdmi_io);
4101 hdmi_msm_state->hdmi_io = NULL;
4102
4103 external_common_state_remove();
4104
4105 if (hdmi_msm_state->hdmi_app_clk)
4106 clk_put(hdmi_msm_state->hdmi_app_clk);
4107 if (hdmi_msm_state->hdmi_m_pclk)
4108 clk_put(hdmi_msm_state->hdmi_m_pclk);
4109 if (hdmi_msm_state->hdmi_s_pclk)
4110 clk_put(hdmi_msm_state->hdmi_s_pclk);
4111
4112 hdmi_msm_state->hdmi_app_clk = NULL;
4113 hdmi_msm_state->hdmi_m_pclk = NULL;
4114 hdmi_msm_state->hdmi_s_pclk = NULL;
4115
4116 kfree(hdmi_msm_state);
4117 hdmi_msm_state = NULL;
4118
4119 return 0;
4120}
4121
4122static int hdmi_msm_hpd_feature(int on)
4123{
4124 int rc = 0;
4125
4126 DEV_INFO("%s: %d\n", __func__, on);
4127 if (on)
4128 rc = hdmi_msm_hpd_on(true);
4129 else
4130 hdmi_msm_hpd_off();
4131
4132 return rc;
4133}
4134
4135
4136#ifdef CONFIG_SUSPEND
4137static int hdmi_msm_device_pm_suspend(struct device *dev)
4138{
4139 mutex_lock(&hdmi_msm_state_mutex);
4140 if (hdmi_msm_state->pm_suspended) {
4141 mutex_unlock(&hdmi_msm_state_mutex);
4142 return 0;
4143 }
4144
4145 DEV_DBG("pm_suspend\n");
4146
4147 del_timer(&hdmi_msm_state->hpd_state_timer);
4148#ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT
4149 del_timer(&hdmi_msm_state->hdcp_timer);
4150#endif /* CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT */
4151
4152 disable_irq(hdmi_msm_state->irq);
Ravishangar Kalyanam18337542011-08-12 10:26:35 -07004153 if (external_common_state->hpd_feature_on)
4154 hdmi_msm_clk(0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004155
4156 hdmi_msm_state->pm_suspended = TRUE;
4157 mutex_unlock(&hdmi_msm_state_mutex);
4158
4159 hdmi_msm_powerdown_phy();
4160 hdmi_msm_state->pd->enable_5v(0);
4161 hdmi_msm_state->pd->core_power(0, 1);
4162 return 0;
4163}
4164
4165static int hdmi_msm_device_pm_resume(struct device *dev)
4166{
4167 mutex_lock(&hdmi_msm_state_mutex);
4168 if (!hdmi_msm_state->pm_suspended) {
4169 mutex_unlock(&hdmi_msm_state_mutex);
4170 return 0;
4171 }
4172
4173 DEV_DBG("pm_resume\n");
4174
4175 hdmi_msm_state->pd->core_power(1, 1);
4176 hdmi_msm_state->pd->enable_5v(1);
Ravishangar Kalyanam18337542011-08-12 10:26:35 -07004177 if (external_common_state->hpd_feature_on)
4178 hdmi_msm_clk(1);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004179
4180 hdmi_msm_state->pm_suspended = FALSE;
4181 mutex_unlock(&hdmi_msm_state_mutex);
4182 enable_irq(hdmi_msm_state->irq);
4183 return 0;
4184}
4185#else
4186#define hdmi_msm_device_pm_suspend NULL
4187#define hdmi_msm_device_pm_resume NULL
4188#endif
4189
4190static const struct dev_pm_ops hdmi_msm_device_pm_ops = {
4191 .suspend = hdmi_msm_device_pm_suspend,
4192 .resume = hdmi_msm_device_pm_resume,
4193};
4194
4195static struct platform_driver this_driver = {
4196 .probe = hdmi_msm_probe,
4197 .remove = hdmi_msm_remove,
4198 .driver.name = "hdmi_msm",
4199 .driver.pm = &hdmi_msm_device_pm_ops,
4200};
4201
4202static struct msm_fb_panel_data hdmi_msm_panel_data = {
4203 .on = hdmi_msm_power_on,
4204 .off = hdmi_msm_power_off,
4205};
4206
4207static struct platform_device this_device = {
4208 .name = "hdmi_msm",
4209 .id = 1,
4210 .dev.platform_data = &hdmi_msm_panel_data,
4211};
4212
4213static int __init hdmi_msm_init(void)
4214{
4215 int rc;
4216
Ravishangar Kalyanamc719c542011-07-28 16:49:25 -07004217 if (msm_fb_detect_client("hdmi_msm"))
4218 return 0;
4219
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004220 hdmi_msm_setup_video_mode_lut();
4221 hdmi_msm_state = kzalloc(sizeof(*hdmi_msm_state), GFP_KERNEL);
4222 if (!hdmi_msm_state) {
4223 pr_err("hdmi_msm_init FAILED: out of memory\n");
4224 rc = -ENOMEM;
4225 goto init_exit;
4226 }
4227
4228 external_common_state = &hdmi_msm_state->common;
4229 external_common_state->video_resolution = HDMI_VFRMT_1920x1080p60_16_9;
4230#ifdef CONFIG_FB_MSM_HDMI_3D
4231 external_common_state->switch_3d = hdmi_msm_switch_3d;
4232#endif
4233
Manoj Raoa2c27672011-08-30 17:19:39 -07004234#ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_CEC_SUPPORT
4235 hdmi_msm_state->cec_queue_start =
4236 kzalloc(sizeof(struct hdmi_msm_cec_msg)*CEC_QUEUE_SIZE,
4237 GFP_KERNEL);
4238 if (!hdmi_msm_state->cec_queue_start) {
4239 pr_err("hdmi_msm_init FAILED: CEC queue out of memory\n");
4240 rc = -ENOMEM;
4241 goto init_exit;
4242 }
4243
4244 hdmi_msm_state->cec_queue_wr = hdmi_msm_state->cec_queue_start;
4245 hdmi_msm_state->cec_queue_rd = hdmi_msm_state->cec_queue_start;
4246 hdmi_msm_state->cec_queue_full = false;
4247#endif
4248
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004249 /*
4250 * Create your work queue
4251 * allocs and returns ptr
4252 */
4253 hdmi_work_queue = create_workqueue("hdmi_hdcp");
4254 external_common_state->hpd_feature = hdmi_msm_hpd_feature;
4255
4256 rc = platform_driver_register(&this_driver);
4257 if (rc) {
4258 pr_err("hdmi_msm_init FAILED: platform_driver_register rc=%d\n",
4259 rc);
4260 goto init_exit;
4261 }
4262
4263 hdmi_common_init_panel_info(&hdmi_msm_panel_data.panel_info);
4264 init_completion(&hdmi_msm_state->ddc_sw_done);
4265 INIT_WORK(&hdmi_msm_state->hpd_state_work, hdmi_msm_hpd_state_work);
4266 INIT_WORK(&hdmi_msm_state->hpd_read_work, hdmi_msm_hpd_read_work);
4267#ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT
4268 init_completion(&hdmi_msm_state->hdcp_success_done);
4269 INIT_WORK(&hdmi_msm_state->hdcp_reauth_work, hdmi_msm_hdcp_reauth_work);
4270 INIT_WORK(&hdmi_msm_state->hdcp_work, hdmi_msm_hdcp_work);
4271#endif /* CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT */
4272
Manoj Raoa2c27672011-08-30 17:19:39 -07004273#ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_CEC_SUPPORT
4274 init_completion(&hdmi_msm_state->cec_frame_wr_done);
4275#endif
4276
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004277 rc = platform_device_register(&this_device);
4278 if (rc) {
4279 pr_err("hdmi_msm_init FAILED: platform_device_register rc=%d\n",
4280 rc);
4281 platform_driver_unregister(&this_driver);
4282 goto init_exit;
4283 }
4284
4285 pr_debug("%s: success:"
4286#ifdef DEBUG
4287 " DEBUG"
4288#else
4289 " RELEASE"
4290#endif
4291 " AUDIO EDID HPD HDCP"
4292#ifndef CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT
4293 ":0"
4294#endif /* CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT */
4295 " DVI"
4296#ifndef CONFIG_FB_MSM_HDMI_MSM_PANEL_DVI_SUPPORT
4297 ":0"
4298#endif /* CONFIG_FB_MSM_HDMI_MSM_PANEL_DVI_SUPPORT */
4299 "\n", __func__);
4300
4301 return 0;
4302
4303init_exit:
4304 kfree(hdmi_msm_state);
4305 hdmi_msm_state = NULL;
4306
4307 return rc;
4308}
4309
4310static void __exit hdmi_msm_exit(void)
4311{
4312 platform_device_unregister(&this_device);
4313 platform_driver_unregister(&this_driver);
4314}
4315
4316module_init(hdmi_msm_init);
4317module_exit(hdmi_msm_exit);
4318
4319MODULE_LICENSE("GPL v2");
4320MODULE_VERSION("0.3");
4321MODULE_AUTHOR("Qualcomm Innovation Center, Inc.");
4322MODULE_DESCRIPTION("HDMI MSM TX driver");