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