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