blob: 63c97292f62a88c5a61ef446b0b8cbe521de2bcd [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
Aravind Venkateswaran954620c2011-11-30 14:50:48 -08002317 /*
2318 * A small delay is needed here to avoid device crash observed
2319 * during reauthentication in MSM8960
2320 */
2321 msleep(20);
2322
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002323 /* 0x0168 HDCP_RCVPORT_DATA12
2324 [23:8] BSTATUS
2325 [7:0] BCAPS */
2326 HDMI_OUTP(0x0168, bcaps);
2327
2328 /* 0x014C HDCP_RCVPORT_DATA5
2329 [31:0] LINK0_AN_0 */
2330 /* read an0 calculation */
2331 link0_an_0 = HDMI_INP(0x014C);
2332
2333 /* 0x0150 HDCP_RCVPORT_DATA6
2334 [31:0] LINK0_AN_1 */
2335 /* read an1 calculation */
2336 link0_an_1 = HDMI_INP(0x0150);
2337
2338 /* three bits 28..30 */
2339 hdcp_key_state((HDMI_INP(0x011C) >> 28) & 0x7);
2340
2341 /* 0x0144 HDCP_RCVPORT_DATA3
2342 [31:0] LINK0_AKSV_0 public key
2343 0x0148 HDCP_RCVPORT_DATA4
2344 [15:8] LINK0_AINFO
2345 [7:0] LINK0_AKSV_1 public key */
2346 link0_aksv_0 = HDMI_INP(0x0144);
2347 link0_aksv_1 = HDMI_INP(0x0148);
2348
2349 /* copy an and aksv to byte arrays for transmission */
2350 aksv[0] = link0_aksv_0 & 0xFF;
2351 aksv[1] = (link0_aksv_0 >> 8) & 0xFF;
2352 aksv[2] = (link0_aksv_0 >> 16) & 0xFF;
2353 aksv[3] = (link0_aksv_0 >> 24) & 0xFF;
2354 aksv[4] = link0_aksv_1 & 0xFF;
2355
2356 an[0] = link0_an_0 & 0xFF;
2357 an[1] = (link0_an_0 >> 8) & 0xFF;
2358 an[2] = (link0_an_0 >> 16) & 0xFF;
2359 an[3] = (link0_an_0 >> 24) & 0xFF;
2360 an[4] = link0_an_1 & 0xFF;
2361 an[5] = (link0_an_1 >> 8) & 0xFF;
2362 an[6] = (link0_an_1 >> 16) & 0xFF;
2363 an[7] = (link0_an_1 >> 24) & 0xFF;
2364
2365 /* Write An 8 bytes to offset 0x18 */
2366 ret = hdmi_msm_ddc_write(0x74, 0x18, an, 8, "An");
2367 if (ret) {
2368 DEV_ERR("%s(%d): Write An failed", __func__, __LINE__);
2369 goto error;
2370 }
2371
2372 /* Write Aksv 5 bytes to offset 0x10 */
2373 ret = hdmi_msm_ddc_write(0x74, 0x10, aksv, 5, "Aksv");
2374 if (ret) {
2375 DEV_ERR("%s(%d): Write Aksv failed", __func__,
2376 __LINE__);
2377 goto error;
2378 }
2379 DEV_DBG("HDCP: Link0-AKSV=%02x%08x\n",
2380 link0_aksv_1 & 0xFF, link0_aksv_0);
2381
2382 /* 0x0134 HDCP_RCVPORT_DATA0
2383 [31:0] LINK0_BKSV_0 */
2384 HDMI_OUTP(0x0134, link0_bksv_0);
2385 /* 0x0138 HDCP_RCVPORT_DATA1
2386 [31:0] LINK0_BKSV_1 */
2387 HDMI_OUTP(0x0138, link0_bksv_1);
2388 DEV_DBG("HDCP: Link0-BKSV=%02x%08x\n", link0_bksv_1,
2389 link0_bksv_0);
2390
2391 /* HDMI_HPD_INT_STATUS[0x0250] */
2392 hpd_int_status = HDMI_INP_ND(0x0250);
2393 /* HDMI_HPD_INT_CTRL[0x0254] */
2394 hpd_int_ctrl = HDMI_INP_ND(0x0254);
2395 DEV_DBG("[SR-DEUG]: HPD_INTR_CTRL=[%u] HPD_INTR_STATUS=[%u]\
2396 before reading R0'\n", hpd_int_ctrl, hpd_int_status);
2397
2398 /*
2399 * HDCP Compliace Test case 1B-01:
2400 * Wait here until all the ksv bytes have been
2401 * read from the KSV FIFO register.
2402 */
2403 msleep(125);
2404
2405 /* Reading R0' 2 bytes at offset 0x08 */
2406 ret = hdmi_msm_ddc_read(0x74, 0x08, buf, 2, 5, "RO'", TRUE);
2407 if (ret) {
2408 DEV_ERR("%s(%d): Read RO's failed", __func__,
2409 __LINE__);
2410 goto error;
2411 }
2412
2413 /* 0x013C HDCP_RCVPORT_DATA2_0
2414 [15:0] LINK0_RI */
2415 HDMI_OUTP(0x013C, (((uint32)buf[1]) << 8) | buf[0]);
2416 DEV_DBG("HDCP: R0'=%02x%02x\n", buf[1], buf[0]);
2417
2418 INIT_COMPLETION(hdmi_msm_state->hdcp_success_done);
2419 timeout_count = wait_for_completion_interruptible_timeout(
2420 &hdmi_msm_state->hdcp_success_done, HZ*2);
2421
2422 if (!timeout_count) {
2423 ret = -ETIMEDOUT;
2424 is_match = HDMI_INP(0x011C) & BIT(12);
2425 DEV_ERR("%s(%d): timedout, Link0=<%s>\n", __func__,
2426 __LINE__,
2427 is_match ? "RI_MATCH" : "No RI Match INTR in time");
2428 if (!is_match)
2429 goto error;
2430 }
2431
2432 /* 0x011C HDCP_LINK0_STATUS
2433 [12] RI_MATCHES [0] MISMATCH, [1] MATCH
2434 [0] AUTH_SUCCESS */
2435 /* Checking for RI, R0 Match */
2436 /* RI_MATCHES */
2437 if ((HDMI_INP(0x011C) & BIT(12)) != BIT(12)) {
2438 ret = -EINVAL;
2439 DEV_ERR("%s: HDCP_LINK0_STATUS[RI_MATCHES]: MISMATCH\n",
2440 __func__);
2441 goto error;
2442 }
2443
2444 DEV_INFO("HDCP: authentication part I, successful\n");
2445 is_part1_done = FALSE;
2446 return 0;
2447error:
2448 DEV_ERR("[%s]: HDCP Reauthentication\n", __func__);
2449 is_part1_done = FALSE;
2450 return ret;
2451 } else {
2452 return 1;
2453 }
2454}
2455
2456static int hdmi_msm_transfer_v_h(void)
2457{
2458 /* Read V'.HO 4 Byte at offset 0x20 */
2459 char what[20];
2460 int ret;
2461 uint8 buf[4];
2462
2463 snprintf(what, sizeof(what), "V' H0");
2464 ret = hdmi_msm_ddc_read(0x74, 0x20, buf, 4, 5, what, TRUE);
2465 if (ret) {
2466 DEV_ERR("%s: Read %s failed", __func__, what);
2467 return ret;
2468 }
2469 DEV_DBG("buf[0]= %x , buf[1] = %x , buf[2] = %x , buf[3] = %x\n ",
2470 buf[0] , buf[1] , buf[2] , buf[3]);
2471
2472 /* 0x0154 HDCP_RCVPORT_DATA7
2473 [31:0] V_HO */
2474 HDMI_OUTP(0x0154 ,
2475 (buf[3] << 24 | buf[2] << 16 | buf[1] << 8 | buf[0]));
2476
2477 snprintf(what, sizeof(what), "V' H1");
2478 ret = hdmi_msm_ddc_read(0x74, 0x24, buf, 4, 5, what, TRUE);
2479 if (ret) {
2480 DEV_ERR("%s: Read %s failed", __func__, what);
2481 return ret;
2482 }
2483 DEV_DBG("buf[0]= %x , buf[1] = %x , buf[2] = %x , buf[3] = %x\n ",
2484 buf[0] , buf[1] , buf[2] , buf[3]);
2485
2486 /* 0x0158 HDCP_RCVPORT_ DATA8
2487 [31:0] V_H1 */
2488 HDMI_OUTP(0x0158,
2489 (buf[3] << 24 | buf[2] << 16 | buf[1] << 8 | buf[0]));
2490
2491
2492 snprintf(what, sizeof(what), "V' H2");
2493 ret = hdmi_msm_ddc_read(0x74, 0x28, buf, 4, 5, what, TRUE);
2494 if (ret) {
2495 DEV_ERR("%s: Read %s failed", __func__, what);
2496 return ret;
2497 }
2498 DEV_DBG("buf[0]= %x , buf[1] = %x , buf[2] = %x , buf[3] = %x\n ",
2499 buf[0] , buf[1] , buf[2] , buf[3]);
2500
2501 /* 0x015c HDCP_RCVPORT_DATA9
2502 [31:0] V_H2 */
2503 HDMI_OUTP(0x015c ,
2504 (buf[3] << 24 | buf[2] << 16 | buf[1] << 8 | buf[0]));
2505
2506 snprintf(what, sizeof(what), "V' H3");
2507 ret = hdmi_msm_ddc_read(0x74, 0x2c, buf, 4, 5, what, TRUE);
2508 if (ret) {
2509 DEV_ERR("%s: Read %s failed", __func__, what);
2510 return ret;
2511 }
2512 DEV_DBG("buf[0]= %x , buf[1] = %x , buf[2] = %x , buf[3] = %x\n ",
2513 buf[0] , buf[1] , buf[2] , buf[3]);
2514
2515 /* 0x0160 HDCP_RCVPORT_DATA10
2516 [31:0] V_H3 */
2517 HDMI_OUTP(0x0160,
2518 (buf[3] << 24 | buf[2] << 16 | buf[1] << 8 | buf[0]));
2519
2520 snprintf(what, sizeof(what), "V' H4");
2521 ret = hdmi_msm_ddc_read(0x74, 0x30, buf, 4, 5, what, TRUE);
2522 if (ret) {
2523 DEV_ERR("%s: Read %s failed", __func__, what);
2524 return ret;
2525 }
2526 DEV_DBG("buf[0]= %x , buf[1] = %x , buf[2] = %x , buf[3] = %x\n ",
2527 buf[0] , buf[1] , buf[2] , buf[3]);
2528 /* 0x0164 HDCP_RCVPORT_DATA11
2529 [31:0] V_H4 */
2530 HDMI_OUTP(0x0164,
2531 (buf[3] << 24 | buf[2] << 16 | buf[1] << 8 | buf[0]));
2532
2533 return 0;
2534}
2535
2536static int hdcp_authentication_part2(void)
2537{
2538 int ret = 0;
2539 uint32 timeout_count;
2540 int i = 0;
2541 int cnt = 0;
2542 uint bstatus;
2543 uint8 bcaps;
2544 uint32 down_stream_devices;
2545 uint32 ksv_bytes;
2546
2547 static uint8 buf[0xFF];
2548 static uint8 kvs_fifo[5 * 127];
2549
2550 boolean max_devs_exceeded = 0;
2551 boolean max_cascade_exceeded = 0;
2552
2553 boolean ksv_done = FALSE;
2554
2555 memset(buf, 0, sizeof(buf));
2556 memset(kvs_fifo, 0, sizeof(kvs_fifo));
2557
2558 /* wait until READY bit is set in bcaps */
2559 timeout_count = 50;
2560 do {
2561 timeout_count--;
2562 /* read bcaps 1 Byte at offset 0x40 */
2563 ret = hdmi_msm_ddc_read(0x74, 0x40, &bcaps, 1, 1,
2564 "Bcaps", FALSE);
2565 if (ret) {
2566 DEV_ERR("%s(%d): Read Bcaps failed", __func__,
2567 __LINE__);
2568 goto error;
2569 }
2570 msleep(100);
2571 } while ((0 == (bcaps & 0x20)) && timeout_count); /* READY (Bit 5) */
2572 if (!timeout_count) {
2573 ret = -ETIMEDOUT;
2574 DEV_ERR("%s:timedout(1)", __func__);
2575 goto error;
2576 }
2577
2578 /* read bstatus 2 bytes at offset 0x41 */
2579
2580 ret = hdmi_msm_ddc_read(0x74, 0x41, buf, 2, 5, "Bstatus", FALSE);
2581 if (ret) {
2582 DEV_ERR("%s(%d): Read Bstatus failed", __func__, __LINE__);
2583 goto error;
2584 }
2585 bstatus = buf[1];
2586 bstatus = (bstatus << 8) | buf[0];
2587 /* 0x0168 DCP_RCVPORT_DATA12
2588 [7:0] BCAPS
2589 [23:8 BSTATUS */
2590 HDMI_OUTP(0x0168, bcaps | (bstatus << 8));
2591 /* BSTATUS [6:0] DEVICE_COUNT Number of HDMI device attached to repeater
2592 * - see HDCP spec */
2593 down_stream_devices = bstatus & 0x7F;
2594
2595 if (down_stream_devices == 0x0) {
2596 /* There isn't any devices attaced to the Repeater */
2597 DEV_ERR("%s: there isn't any devices attached to the "
2598 "Repeater\n", __func__);
2599 ret = -EINVAL;
2600 goto error;
2601 }
2602
2603 /*
2604 * HDCP Compliance 1B-05:
2605 * Check if no. of devices connected to repeater
2606 * exceed max_devices_connected from bit 7 of Bstatus.
2607 */
2608 max_devs_exceeded = (bstatus & 0x80) >> 7;
2609 if (max_devs_exceeded == 0x01) {
2610 DEV_ERR("%s: Number of devs connected to repeater "
2611 "exceeds max_devs\n", __func__);
2612 ret = -EINVAL;
2613 goto hdcp_error;
2614 }
2615
2616 /*
2617 * HDCP Compliance 1B-06:
2618 * Check if no. of cascade connected to repeater
2619 * exceed max_cascade_connected from bit 11 of Bstatus.
2620 */
2621 max_cascade_exceeded = (bstatus & 0x800) >> 11;
2622 if (max_cascade_exceeded == 0x01) {
2623 DEV_ERR("%s: Number of cascade connected to repeater "
2624 "exceeds max_cascade\n", __func__);
2625 ret = -EINVAL;
2626 goto hdcp_error;
2627 }
2628
2629 /* Read KSV FIFO over DDC
2630 * Key Slection vector FIFO
2631 * Used to pull downstream KSVs from HDCP Repeaters.
2632 * All bytes (DEVICE_COUNT * 5) must be read in a single,
2633 * auto incrementing access.
2634 * All bytes read as 0x00 for HDCP Receivers that are not
2635 * HDCP Repeaters (REPEATER == 0). */
2636 ksv_bytes = 5 * down_stream_devices;
2637 /* Reading KSV FIFO / KSV FIFO */
2638 ksv_done = FALSE;
2639
2640 ret = hdmi_msm_ddc_read(0x74, 0x43, kvs_fifo, ksv_bytes, 5,
2641 "KSV FIFO", TRUE);
2642 do {
2643 if (ret) {
2644 DEV_ERR("%s(%d): Read KSV FIFO failed",
2645 __func__, __LINE__);
2646 /*
2647 * HDCP Compliace Test case 1B-01:
2648 * Wait here until all the ksv bytes have been
2649 * read from the KSV FIFO register.
2650 */
2651 msleep(25);
2652 } else {
2653 ksv_done = TRUE;
2654 }
2655 cnt++;
2656 } while (!ksv_done && cnt != 20);
2657
2658 if (ksv_done == FALSE)
2659 goto error;
2660
2661 ret = hdmi_msm_transfer_v_h();
2662 if (ret)
2663 goto error;
2664
2665 /* Next: Write KSV FIFO to HDCP_SHA_DATA.
2666 * This is done 1 byte at time starting with the LSB.
2667 * On the very last byte write,
2668 * the HDCP_SHA_DATA_DONE bit[0]
2669 */
2670
2671 /* 0x023C HDCP_SHA_CTRL
2672 [0] RESET [0] Enable, [1] Reset
2673 [4] SELECT [0] DIGA_HDCP, [1] DIGB_HDCP */
2674 /* reset SHA engine */
2675 HDMI_OUTP(0x023C, 1);
2676 /* enable SHA engine, SEL=DIGA_HDCP */
2677 HDMI_OUTP(0x023C, 0);
2678
2679 for (i = 0; i < ksv_bytes - 1; i++) {
2680 /* Write KSV byte and do not set DONE bit[0] */
2681 HDMI_OUTP_ND(0x0244, kvs_fifo[i] << 16);
Aravind Venkateswaranfa14cb02011-10-19 13:00:16 -07002682
2683 /* Once 64 bytes have been written, we need to poll for
2684 * HDCP_SHA_BLOCK_DONE before writing any further
2685 */
2686 if (i && !((i+1)%64)) {
2687 timeout_count = 100;
2688 while (!(HDMI_INP_ND(0x0240) & 0x1)
2689 && (--timeout_count)) {
2690 DEV_DBG("HDCP Auth Part II: Waiting for the "
2691 "computation of the current 64 byte to "
2692 "complete. HDCP_SHA_STATUS=%08x. "
2693 "timeout_count=%d\n",
2694 HDMI_INP_ND(0x0240), timeout_count);
2695 msleep(20);
2696 }
2697 if (!timeout_count) {
2698 ret = -ETIMEDOUT;
2699 DEV_ERR("%s(%d): timedout", __func__, __LINE__);
2700 goto error;
2701 }
2702 }
2703
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002704 }
Aravind Venkateswaranfa14cb02011-10-19 13:00:16 -07002705
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002706 /* Write l to DONE bit[0] */
2707 HDMI_OUTP_ND(0x0244, (kvs_fifo[ksv_bytes - 1] << 16) | 0x1);
2708
2709 /* 0x0240 HDCP_SHA_STATUS
2710 [4] COMP_DONE */
2711 /* Now wait for HDCP_SHA_COMP_DONE */
2712 timeout_count = 100;
Aravind Venkateswaranfa14cb02011-10-19 13:00:16 -07002713 while ((0x10 != (HDMI_INP_ND(0x0240) & 0xFFFFFF10)) && --timeout_count)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002714 msleep(20);
Aravind Venkateswaranfa14cb02011-10-19 13:00:16 -07002715
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002716 if (!timeout_count) {
2717 ret = -ETIMEDOUT;
2718 DEV_ERR("%s(%d): timedout", __func__, __LINE__);
2719 goto error;
2720 }
2721
2722 /* 0x011C HDCP_LINK0_STATUS
2723 [20] V_MATCHES */
2724 timeout_count = 100;
2725 while (((HDMI_INP_ND(0x011C) & (1 << 20)) != (1 << 20))
Aravind Venkateswaranfa14cb02011-10-19 13:00:16 -07002726 && --timeout_count) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002727 msleep(20);
Aravind Venkateswaranfa14cb02011-10-19 13:00:16 -07002728 }
2729
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002730 if (!timeout_count) {
2731 ret = -ETIMEDOUT;
2732 DEV_ERR("%s(%d): timedout", __func__, __LINE__);
2733 goto error;
2734 }
2735
2736 DEV_INFO("HDCP: authentication part II, successful\n");
2737
2738hdcp_error:
2739error:
2740 return ret;
2741}
2742
2743static int hdcp_authentication_part3(uint32 found_repeater)
2744{
2745 int ret = 0;
2746 int poll = 3000;
2747 while (poll) {
2748 /* 0x011C HDCP_LINK0_STATUS
2749 [30:28] KEYS_STATE = 3 = "Valid"
2750 [24] RO_COMPUTATION_DONE [0] Not Done, [1] Done
2751 [20] V_MATCHES [0] Mismtach, [1] Match
2752 [12] RI_MATCHES [0] Mismatch, [1] Match
2753 [0] AUTH_SUCCESS */
2754 if (HDMI_INP_ND(0x011C) != (0x31001001 |
2755 (found_repeater << 20))) {
2756 DEV_ERR("HDCP: autentication part III, FAILED, "
2757 "Link Status=%08x\n", HDMI_INP(0x011C));
2758 ret = -EINVAL;
2759 goto error;
2760 }
2761 poll--;
2762 }
2763
2764 DEV_INFO("HDCP: authentication part III, successful\n");
2765
2766error:
2767 return ret;
2768}
2769
2770static void hdmi_msm_hdcp_enable(void)
2771{
2772 int ret = 0;
2773 uint8 bcaps;
2774 uint32 found_repeater = 0x0;
2775 char *envp[2];
2776
2777 if (!hdmi_msm_has_hdcp())
2778 return;
2779
2780 mutex_lock(&hdmi_msm_state_mutex);
2781 hdmi_msm_state->hdcp_activating = TRUE;
2782 mutex_unlock(&hdmi_msm_state_mutex);
2783
2784 fill_black_screen();
2785
2786 mutex_lock(&hdcp_auth_state_mutex);
2787 /*
2788 * Initialize this to zero here to make
2789 * sure HPD has not happened yet
2790 */
2791 hdmi_msm_state->hpd_during_auth = FALSE;
2792 /* This flag prevents other threads from re-authenticating
2793 * after we've just authenticated (i.e., finished part3)
2794 * We probably need to protect this in a mutex lock */
2795 hdmi_msm_state->full_auth_done = FALSE;
2796 mutex_unlock(&hdcp_auth_state_mutex);
2797
2798 /* PART I Authentication*/
2799 ret = hdcp_authentication_part1();
2800 if (ret)
2801 goto error;
2802
2803 /* PART II Authentication*/
2804 /* read Bcaps at 0x40 in HDCP Port */
2805 ret = hdmi_msm_ddc_read(0x74, 0x40, &bcaps, 1, 5, "Bcaps", FALSE);
2806 if (ret) {
2807 DEV_ERR("%s(%d): Read Bcaps failed\n", __func__, __LINE__);
2808 goto error;
2809 }
2810 DEV_DBG("HDCP: Bcaps=0x%02x (%s)\n", bcaps,
2811 (bcaps & BIT(6)) ? "repeater" : "no repeater");
2812
2813 /* if REPEATER (Bit 6), perform Part2 Authentication */
2814 if (bcaps & BIT(6)) {
2815 found_repeater = 0x1;
2816 ret = hdcp_authentication_part2();
2817 if (ret)
2818 goto error;
2819 } else
2820 DEV_INFO("HDCP: authentication part II skipped, no repeater\n");
2821
2822 /* PART III Authentication*/
2823 ret = hdcp_authentication_part3(found_repeater);
2824 if (ret)
2825 goto error;
2826
2827 unfill_black_screen();
2828
2829 external_common_state->hdcp_active = TRUE;
2830 mutex_lock(&hdmi_msm_state_mutex);
2831 hdmi_msm_state->hdcp_activating = FALSE;
2832 mutex_unlock(&hdmi_msm_state_mutex);
2833
2834 mutex_lock(&hdcp_auth_state_mutex);
2835 /*
2836 * This flag prevents other threads from re-authenticating
2837 * after we've just authenticated (i.e., finished part3)
2838 */
2839 hdmi_msm_state->full_auth_done = TRUE;
2840 mutex_unlock(&hdcp_auth_state_mutex);
2841
2842 if (!hdmi_msm_is_dvi_mode()) {
2843 DEV_INFO("HDMI HPD: sense : send HDCP_PASS\n");
2844 envp[0] = "HDCP_STATE=PASS";
2845 envp[1] = NULL;
2846 kobject_uevent_env(external_common_state->uevent_kobj,
2847 KOBJ_CHANGE, envp);
2848 }
2849 return;
2850
2851error:
2852 mutex_lock(&hdmi_msm_state_mutex);
2853 hdmi_msm_state->hdcp_activating = FALSE;
2854 mutex_unlock(&hdmi_msm_state_mutex);
2855 if (hdmi_msm_state->hpd_during_auth) {
2856 DEV_WARN("Calling Deauthentication: HPD occured during\
2857 authentication from [%s]\n", __func__);
2858 hdcp_deauthenticate();
2859 mutex_lock(&hdcp_auth_state_mutex);
2860 hdmi_msm_state->hpd_during_auth = FALSE;
2861 mutex_unlock(&hdcp_auth_state_mutex);
2862 } else {
2863 DEV_WARN("[DEV_DBG]: Calling reauth from [%s]\n", __func__);
2864 if (hdmi_msm_state->panel_power_on)
2865 queue_work(hdmi_work_queue,
2866 &hdmi_msm_state->hdcp_reauth_work);
2867 }
2868}
2869#endif /* CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT */
2870
2871static void hdmi_msm_video_setup(int video_format)
2872{
2873 uint32 total_v = 0;
2874 uint32 total_h = 0;
2875 uint32 start_h = 0;
2876 uint32 end_h = 0;
2877 uint32 start_v = 0;
2878 uint32 end_v = 0;
2879 const struct hdmi_disp_mode_timing_type *timing =
2880 hdmi_common_get_supported_mode(video_format);
2881
2882 /* timing register setup */
2883 if (timing == NULL) {
2884 DEV_ERR("video format not supported: %d\n", video_format);
2885 return;
2886 }
2887
2888 /* Hsync Total and Vsync Total */
2889 total_h = timing->active_h + timing->front_porch_h
2890 + timing->back_porch_h + timing->pulse_width_h - 1;
2891 total_v = timing->active_v + timing->front_porch_v
2892 + timing->back_porch_v + timing->pulse_width_v - 1;
2893 /* 0x02C0 HDMI_TOTAL
2894 [27:16] V_TOTAL Vertical Total
2895 [11:0] H_TOTAL Horizontal Total */
2896 HDMI_OUTP(0x02C0, ((total_v << 16) & 0x0FFF0000)
2897 | ((total_h << 0) & 0x00000FFF));
2898
2899 /* Hsync Start and Hsync End */
2900 start_h = timing->back_porch_h + timing->pulse_width_h;
2901 end_h = (total_h + 1) - timing->front_porch_h;
2902 /* 0x02B4 HDMI_ACTIVE_H
2903 [27:16] END Horizontal end
2904 [11:0] START Horizontal start */
2905 HDMI_OUTP(0x02B4, ((end_h << 16) & 0x0FFF0000)
2906 | ((start_h << 0) & 0x00000FFF));
2907
2908 start_v = timing->back_porch_v + timing->pulse_width_v - 1;
2909 end_v = total_v - timing->front_porch_v;
2910 /* 0x02B8 HDMI_ACTIVE_V
2911 [27:16] END Vertical end
2912 [11:0] START Vertical start */
2913 HDMI_OUTP(0x02B8, ((end_v << 16) & 0x0FFF0000)
2914 | ((start_v << 0) & 0x00000FFF));
2915
2916 if (timing->interlaced) {
2917 /* 0x02C4 HDMI_V_TOTAL_F2
2918 [11:0] V_TOTAL_F2 Vertical total for field2 */
2919 HDMI_OUTP(0x02C4, ((total_v + 1) << 0) & 0x00000FFF);
2920
2921 /* 0x02BC HDMI_ACTIVE_V_F2
2922 [27:16] END_F2 Vertical end for field2
2923 [11:0] START_F2 Vertical start for Field2 */
2924 HDMI_OUTP(0x02BC,
2925 (((start_v + 1) << 0) & 0x00000FFF)
2926 | (((end_v + 1) << 16) & 0x0FFF0000));
2927 } else {
2928 /* HDMI_V_TOTAL_F2 */
2929 HDMI_OUTP(0x02C4, 0);
2930 /* HDMI_ACTIVE_V_F2 */
2931 HDMI_OUTP(0x02BC, 0);
2932 }
2933
2934 hdmi_frame_ctrl_cfg(timing);
2935}
2936
2937struct hdmi_msm_audio_acr {
2938 uint32 n; /* N parameter for clock regeneration */
2939 uint32 cts; /* CTS parameter for clock regeneration */
2940};
2941
2942struct hdmi_msm_audio_arcs {
2943 uint32 pclk;
2944 struct hdmi_msm_audio_acr lut[MSM_HDMI_SAMPLE_RATE_MAX];
2945};
2946
2947#define HDMI_MSM_AUDIO_ARCS(pclk, ...) { pclk, __VA_ARGS__ }
2948
2949/* Audio constants lookup table for hdmi_msm_audio_acr_setup */
2950/* Valid Pixel-Clock rates: 25.2MHz, 27MHz, 27.03MHz, 74.25MHz, 148.5MHz */
2951static const struct hdmi_msm_audio_arcs hdmi_msm_audio_acr_lut[] = {
2952 /* 25.200MHz */
2953 HDMI_MSM_AUDIO_ARCS(25200, {
2954 {4096, 25200}, {6272, 28000}, {6144, 25200}, {12544, 28000},
2955 {12288, 25200}, {25088, 28000}, {24576, 25200} }),
2956 /* 27.000MHz */
2957 HDMI_MSM_AUDIO_ARCS(27000, {
2958 {4096, 27000}, {6272, 30000}, {6144, 27000}, {12544, 30000},
2959 {12288, 27000}, {25088, 30000}, {24576, 27000} }),
2960 /* 27.030MHz */
2961 HDMI_MSM_AUDIO_ARCS(27030, {
2962 {4096, 27030}, {6272, 30030}, {6144, 27030}, {12544, 30030},
2963 {12288, 27030}, {25088, 30030}, {24576, 27030} }),
2964 /* 74.250MHz */
2965 HDMI_MSM_AUDIO_ARCS(74250, {
2966 {4096, 74250}, {6272, 82500}, {6144, 74250}, {12544, 82500},
2967 {12288, 74250}, {25088, 82500}, {24576, 74250} }),
2968 /* 148.500MHz */
2969 HDMI_MSM_AUDIO_ARCS(148500, {
2970 {4096, 148500}, {6272, 165000}, {6144, 148500}, {12544, 165000},
2971 {12288, 148500}, {25088, 165000}, {24576, 148500} }),
2972};
2973
2974static void hdmi_msm_audio_acr_setup(boolean enabled, int video_format,
2975 int audio_sample_rate, int num_of_channels)
2976{
2977 /* Read first before writing */
2978 /* HDMI_ACR_PKT_CTRL[0x0024] */
2979 uint32 acr_pck_ctrl_reg = HDMI_INP(0x0024);
2980
2981 if (enabled) {
2982 const struct hdmi_disp_mode_timing_type *timing =
2983 hdmi_common_get_supported_mode(video_format);
2984 const struct hdmi_msm_audio_arcs *audio_arc =
2985 &hdmi_msm_audio_acr_lut[0];
2986 const int lut_size = sizeof(hdmi_msm_audio_acr_lut)
2987 /sizeof(*hdmi_msm_audio_acr_lut);
2988 uint32 i, n, cts, layout, multiplier, aud_pck_ctrl_2_reg;
2989
2990 if (timing == NULL) {
2991 DEV_WARN("%s: video format %d not supported\n",
2992 __func__, video_format);
2993 return;
2994 }
2995
2996 for (i = 0; i < lut_size;
2997 audio_arc = &hdmi_msm_audio_acr_lut[++i]) {
2998 if (audio_arc->pclk == timing->pixel_freq)
2999 break;
3000 }
3001 if (i >= lut_size) {
3002 DEV_WARN("%s: pixel clock %d not supported\n", __func__,
3003 timing->pixel_freq);
3004 return;
3005 }
3006
3007 n = audio_arc->lut[audio_sample_rate].n;
3008 cts = audio_arc->lut[audio_sample_rate].cts;
3009 layout = (MSM_HDMI_AUDIO_CHANNEL_2 == num_of_channels) ? 0 : 1;
3010
3011 if ((MSM_HDMI_SAMPLE_RATE_192KHZ == audio_sample_rate) ||
3012 (MSM_HDMI_SAMPLE_RATE_176_4KHZ == audio_sample_rate)) {
3013 multiplier = 4;
3014 n >>= 2; /* divide N by 4 and use multiplier */
3015 } else if ((MSM_HDMI_SAMPLE_RATE_96KHZ == audio_sample_rate) ||
3016 (MSM_HDMI_SAMPLE_RATE_88_2KHZ == audio_sample_rate)) {
3017 multiplier = 2;
3018 n >>= 1; /* divide N by 2 and use multiplier */
3019 } else {
3020 multiplier = 1;
3021 }
3022 DEV_DBG("%s: n=%u, cts=%u, layout=%u\n", __func__, n, cts,
3023 layout);
3024
3025 /* AUDIO_PRIORITY | SOURCE */
3026 acr_pck_ctrl_reg |= 0x80000100;
3027 /* N_MULTIPLE(multiplier) */
3028 acr_pck_ctrl_reg |= (multiplier & 7) << 16;
3029
3030 if ((MSM_HDMI_SAMPLE_RATE_48KHZ == audio_sample_rate) ||
3031 (MSM_HDMI_SAMPLE_RATE_96KHZ == audio_sample_rate) ||
3032 (MSM_HDMI_SAMPLE_RATE_192KHZ == audio_sample_rate)) {
3033 /* SELECT(3) */
3034 acr_pck_ctrl_reg |= 3 << 4;
3035 /* CTS_48 */
3036 cts <<= 12;
3037
3038 /* CTS: need to determine how many fractional bits */
3039 /* HDMI_ACR_48_0 */
3040 HDMI_OUTP(0x00D4, cts);
3041 /* N */
3042 /* HDMI_ACR_48_1 */
3043 HDMI_OUTP(0x00D8, n);
3044 } else if ((MSM_HDMI_SAMPLE_RATE_44_1KHZ == audio_sample_rate)
3045 || (MSM_HDMI_SAMPLE_RATE_88_2KHZ ==
3046 audio_sample_rate)
3047 || (MSM_HDMI_SAMPLE_RATE_176_4KHZ ==
3048 audio_sample_rate)) {
3049 /* SELECT(2) */
3050 acr_pck_ctrl_reg |= 2 << 4;
3051 /* CTS_44 */
3052 cts <<= 12;
3053
3054 /* CTS: need to determine how many fractional bits */
3055 /* HDMI_ACR_44_0 */
3056 HDMI_OUTP(0x00CC, cts);
3057 /* N */
3058 /* HDMI_ACR_44_1 */
3059 HDMI_OUTP(0x00D0, n);
3060 } else { /* default to 32k */
3061 /* SELECT(1) */
3062 acr_pck_ctrl_reg |= 1 << 4;
3063 /* CTS_32 */
3064 cts <<= 12;
3065
3066 /* CTS: need to determine how many fractional bits */
3067 /* HDMI_ACR_32_0 */
3068 HDMI_OUTP(0x00C4, cts);
3069 /* N */
3070 /* HDMI_ACR_32_1 */
3071 HDMI_OUTP(0x00C8, n);
3072 }
3073 /* Payload layout depends on number of audio channels */
3074 /* LAYOUT_SEL(layout) */
3075 aud_pck_ctrl_2_reg = 1 | (layout << 1);
3076 /* override | layout */
3077 /* HDMI_AUDIO_PKT_CTRL2[0x00044] */
3078 HDMI_OUTP(0x00044, aud_pck_ctrl_2_reg);
3079
3080 /* SEND | CONT */
3081 acr_pck_ctrl_reg |= 0x00000003;
3082 } else {
3083 /* ~(SEND | CONT) */
3084 acr_pck_ctrl_reg &= ~0x00000003;
3085 }
3086 /* HDMI_ACR_PKT_CTRL[0x0024] */
3087 HDMI_OUTP(0x0024, acr_pck_ctrl_reg);
3088}
3089
3090static void hdmi_msm_outpdw_chk(uint32 offset, uint32 data)
3091{
3092 uint32 check, i = 0;
3093
3094#ifdef DEBUG
3095 HDMI_OUTP(offset, data);
3096#endif
3097 do {
3098 outpdw(MSM_HDMI_BASE+offset, data);
3099 check = inpdw(MSM_HDMI_BASE+offset);
3100 } while (check != data && i++ < 10);
3101
3102 if (check != data)
3103 DEV_ERR("%s: failed addr=%08x, data=%x, check=%x",
3104 __func__, offset, data, check);
3105}
3106
3107static void hdmi_msm_rmw32or(uint32 offset, uint32 data)
3108{
3109 uint32 reg_data;
3110 reg_data = inpdw(MSM_HDMI_BASE+offset);
3111 reg_data = inpdw(MSM_HDMI_BASE+offset);
3112 hdmi_msm_outpdw_chk(offset, reg_data | data);
3113}
3114
3115
3116#define HDMI_AUDIO_CFG 0x01D0
3117#define HDMI_AUDIO_ENGINE_ENABLE 1
3118#define HDMI_AUDIO_FIFO_MASK 0x000000F0
3119#define HDMI_AUDIO_FIFO_WATERMARK_SHIFT 4
3120#define HDMI_AUDIO_FIFO_MAX_WATER_MARK 8
3121
3122
3123int hdmi_audio_enable(bool on , u32 fifo_water_mark)
3124{
3125 u32 hdmi_audio_config;
3126
3127 hdmi_audio_config = HDMI_INP(HDMI_AUDIO_CFG);
3128
3129 if (on) {
3130
3131 if (fifo_water_mark > HDMI_AUDIO_FIFO_MAX_WATER_MARK) {
3132 pr_err("%s : HDMI audio fifo water mark can not be more"
3133 " than %u\n", __func__,
3134 HDMI_AUDIO_FIFO_MAX_WATER_MARK);
3135 return -EINVAL;
3136 }
3137
3138 /*
3139 * Enable HDMI Audio engine.
3140 * MUST be enabled after Audio DMA is enabled.
3141 */
3142 hdmi_audio_config &= ~(HDMI_AUDIO_FIFO_MASK);
3143
3144 hdmi_audio_config |= (HDMI_AUDIO_ENGINE_ENABLE |
3145 (fifo_water_mark << HDMI_AUDIO_FIFO_WATERMARK_SHIFT));
3146
3147 } else
3148 hdmi_audio_config &= ~(HDMI_AUDIO_ENGINE_ENABLE);
3149
3150 HDMI_OUTP(HDMI_AUDIO_CFG, hdmi_audio_config);
3151
Deepa Madiregama6a3a01a2011-10-28 06:34:17 +05303152 mb();
3153 pr_info("%s :HDMI_AUDIO_CFG 0x%08x\n", __func__,
3154 HDMI_INP(HDMI_AUDIO_CFG));
3155
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003156 return 0;
3157}
3158EXPORT_SYMBOL(hdmi_audio_enable);
3159
Deepa Madiregama6a3a01a2011-10-28 06:34:17 +05303160#define HDMI_AUDIO_PKT_CTRL 0x0020
3161#define HDMI_AUDIO_SAMPLE_SEND_ENABLE 1
3162
3163int hdmi_audio_packet_enable(bool on)
3164{
3165 u32 hdmi_audio_pkt_ctrl;
3166 hdmi_audio_pkt_ctrl = HDMI_INP(HDMI_AUDIO_PKT_CTRL);
3167
3168 if (on)
3169 hdmi_audio_pkt_ctrl |= HDMI_AUDIO_SAMPLE_SEND_ENABLE;
3170 else
3171 hdmi_audio_pkt_ctrl &= ~(HDMI_AUDIO_SAMPLE_SEND_ENABLE);
3172
3173 HDMI_OUTP(HDMI_AUDIO_PKT_CTRL, hdmi_audio_pkt_ctrl);
3174
3175 mb();
3176 pr_info("%s : HDMI_AUDIO_PKT_CTRL 0x%08x\n", __func__,
3177 HDMI_INP(HDMI_AUDIO_PKT_CTRL));
3178 return 0;
3179}
3180EXPORT_SYMBOL(hdmi_audio_packet_enable);
3181
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003182static void hdmi_msm_audio_info_setup(boolean enabled, int num_of_channels,
3183 int level_shift, boolean down_mix)
3184{
3185 uint32 channel_allocation = 0; /* Default to FR,FL */
3186 uint32 channel_count = 1; /* Default to 2 channels
3187 -> See Table 17 in CEA-D spec */
3188 uint32 check_sum, audio_info_0_reg, audio_info_1_reg;
3189 uint32 audio_info_ctrl_reg;
3190
3191 /* Please see table 20 Audio InfoFrame in HDMI spec
3192 FL = front left
3193 FC = front Center
3194 FR = front right
3195 FLC = front left center
3196 FRC = front right center
3197 RL = rear left
3198 RC = rear center
3199 RR = rear right
3200 RLC = rear left center
3201 RRC = rear right center
3202 LFE = low frequency effect
3203 */
3204
3205 /* Read first then write because it is bundled with other controls */
3206 /* HDMI_INFOFRAME_CTRL0[0x002C] */
3207 audio_info_ctrl_reg = HDMI_INP(0x002C);
3208
3209 if (enabled) {
3210 switch (num_of_channels) {
3211 case MSM_HDMI_AUDIO_CHANNEL_2:
3212 break;
3213 case MSM_HDMI_AUDIO_CHANNEL_4:
3214 channel_count = 3;
3215 /* FC,LFE,FR,FL */
3216 channel_allocation = 0x3;
3217 break;
3218 case MSM_HDMI_AUDIO_CHANNEL_6:
3219 channel_count = 5;
3220 /* RR,RL,FC,LFE,FR,FL */
3221 channel_allocation = 0xB;
3222 break;
3223 case MSM_HDMI_AUDIO_CHANNEL_8:
3224 channel_count = 7;
3225 /* FRC,FLC,RR,RL,FC,LFE,FR,FL */
3226 channel_allocation = 0x1f;
3227 break;
3228 default:
3229 break;
3230 }
3231
3232 /* Program the Channel-Speaker allocation */
3233 audio_info_1_reg = 0;
3234 /* CA(channel_allocation) */
3235 audio_info_1_reg |= channel_allocation & 0xff;
3236 /* Program the Level shifter */
3237 /* LSV(level_shift) */
3238 audio_info_1_reg |= (level_shift << 11) & 0x00007800;
3239 /* Program the Down-mix Inhibit Flag */
3240 /* DM_INH(down_mix) */
3241 audio_info_1_reg |= (down_mix << 15) & 0x00008000;
3242
3243 /* HDMI_AUDIO_INFO1[0x00E8] */
3244 HDMI_OUTP(0x00E8, audio_info_1_reg);
3245
3246 /* Calculate CheckSum
3247 Sum of all the bytes in the Audio Info Packet bytes
3248 (See table 8.4 in HDMI spec) */
3249 check_sum = 0;
3250 /* HDMI_AUDIO_INFO_FRAME_PACKET_HEADER_TYPE[0x84] */
3251 check_sum += 0x84;
3252 /* HDMI_AUDIO_INFO_FRAME_PACKET_HEADER_VERSION[0x01] */
3253 check_sum += 1;
3254 /* HDMI_AUDIO_INFO_FRAME_PACKET_LENGTH[0x0A] */
3255 check_sum += 0x0A;
3256 check_sum += channel_count;
3257 check_sum += channel_allocation;
3258 /* See Table 8.5 in HDMI spec */
3259 check_sum += (level_shift & 0xF) << 3 | (down_mix & 0x1) << 7;
3260 check_sum &= 0xFF;
3261 check_sum = (uint8) (256 - check_sum);
3262
3263 audio_info_0_reg = 0;
3264 /* CHECKSUM(check_sum) */
3265 audio_info_0_reg |= check_sum & 0xff;
3266 /* CC(channel_count) */
3267 audio_info_0_reg |= (channel_count << 8) & 0x00000700;
3268
3269 /* HDMI_AUDIO_INFO0[0x00E4] */
3270 HDMI_OUTP(0x00E4, audio_info_0_reg);
3271
3272 /* Set these flags */
3273 /* AUDIO_INFO_UPDATE | AUDIO_INFO_SOURCE | AUDIO_INFO_CONT
3274 | AUDIO_INFO_SEND */
3275 audio_info_ctrl_reg |= 0x000000F0;
3276 } else {
3277 /* Clear these flags */
3278 /* ~(AUDIO_INFO_UPDATE | AUDIO_INFO_SOURCE | AUDIO_INFO_CONT
3279 | AUDIO_INFO_SEND) */
3280 audio_info_ctrl_reg &= ~0x000000F0;
3281 }
3282 /* HDMI_INFOFRAME_CTRL0[0x002C] */
3283 HDMI_OUTP(0x002C, audio_info_ctrl_reg);
3284}
3285
3286static void hdmi_msm_audio_ctrl_setup(boolean enabled, int delay)
3287{
3288 uint32 audio_pkt_ctrl_reg = 0;
3289
3290 /* Enable Packet Transmission */
3291 audio_pkt_ctrl_reg |= enabled ? 0x00000001 : 0;
3292 audio_pkt_ctrl_reg |= (delay << 4);
3293
3294 /* HDMI_AUDIO_PKT_CTRL1[0x0020] */
3295 HDMI_OUTP(0x0020, audio_pkt_ctrl_reg);
3296}
3297
3298static void hdmi_msm_en_gc_packet(boolean av_mute_is_requested)
3299{
3300 /* HDMI_GC[0x0040] */
3301 HDMI_OUTP(0x0040, av_mute_is_requested ? 1 : 0);
3302
3303 /* GC packet enable (every frame) */
3304 /* HDMI_VBI_PKT_CTRL[0x0028] */
3305 hdmi_msm_rmw32or(0x0028, 3 << 4);
3306}
3307
Manoj Raoc2f19592011-08-05 17:54:25 -07003308#ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_ISRC_ACP_SUPPORT
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003309static void hdmi_msm_en_isrc_packet(boolean isrc_is_continued)
3310{
3311 static const char isrc_psuedo_data[] =
3312 "ISRC1:0123456789isrc2=ABCDEFGHIJ";
3313 const uint32 * isrc_data = (const uint32 *) isrc_psuedo_data;
3314
3315 /* ISRC_STATUS =0b010 | ISRC_CONTINUE | ISRC_VALID */
3316 /* HDMI_ISRC1_0[0x00048] */
3317 HDMI_OUTP(0x00048, 2 | (isrc_is_continued ? 1 : 0) << 6 | 0 << 7);
3318
3319 /* HDMI_ISRC1_1[0x004C] */
3320 HDMI_OUTP(0x004C, *isrc_data++);
3321 /* HDMI_ISRC1_2[0x0050] */
3322 HDMI_OUTP(0x0050, *isrc_data++);
3323 /* HDMI_ISRC1_3[0x0054] */
3324 HDMI_OUTP(0x0054, *isrc_data++);
3325 /* HDMI_ISRC1_4[0x0058] */
3326 HDMI_OUTP(0x0058, *isrc_data++);
3327
3328 /* HDMI_ISRC2_0[0x005C] */
3329 HDMI_OUTP(0x005C, *isrc_data++);
3330 /* HDMI_ISRC2_1[0x0060] */
3331 HDMI_OUTP(0x0060, *isrc_data++);
3332 /* HDMI_ISRC2_2[0x0064] */
3333 HDMI_OUTP(0x0064, *isrc_data++);
3334 /* HDMI_ISRC2_3[0x0068] */
3335 HDMI_OUTP(0x0068, *isrc_data);
3336
3337 /* HDMI_VBI_PKT_CTRL[0x0028] */
3338 /* ISRC Send + Continuous */
3339 hdmi_msm_rmw32or(0x0028, 3 << 8);
3340}
Manoj Raoc2f19592011-08-05 17:54:25 -07003341#else
3342static void hdmi_msm_en_isrc_packet(boolean isrc_is_continued)
3343{
3344 /*
3345 * Until end-to-end support for various audio packets
3346 */
3347}
3348#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003349
Manoj Raoc2f19592011-08-05 17:54:25 -07003350#ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_ISRC_ACP_SUPPORT
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003351static void hdmi_msm_en_acp_packet(uint32 byte1)
3352{
3353 /* HDMI_ACP[0x003C] */
3354 HDMI_OUTP(0x003C, 2 | 1 << 8 | byte1 << 16);
3355
3356 /* HDMI_VBI_PKT_CTRL[0x0028] */
3357 /* ACP send, s/w source */
3358 hdmi_msm_rmw32or(0x0028, 3 << 12);
3359}
Manoj Raoc2f19592011-08-05 17:54:25 -07003360#else
3361static void hdmi_msm_en_acp_packet(uint32 byte1)
3362{
3363 /*
3364 * Until end-to-end support for various audio packets
3365 */
3366}
3367#endif
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003368
Ajay Singh Parmar0fc5d362011-11-16 05:48:33 +05303369int hdmi_msm_audio_get_sample_rate(void)
3370{
3371 return msm_hdmi_sample_rate;
3372}
3373EXPORT_SYMBOL(hdmi_msm_audio_get_sample_rate);
3374
3375void hdmi_msm_audio_sample_rate_reset(int rate)
3376{
3377 msm_hdmi_sample_rate = rate;
Ajay Singh Parmar8863118c2011-11-28 23:55:53 +05303378
3379 if (hdmi_msm_has_hdcp())
3380 hdcp_deauthenticate();
3381 else
3382 hdmi_msm_turn_on();
Ajay Singh Parmar0fc5d362011-11-16 05:48:33 +05303383}
3384EXPORT_SYMBOL(hdmi_msm_audio_sample_rate_reset);
3385
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003386static void hdmi_msm_audio_setup(void)
3387{
3388 const int channels = MSM_HDMI_AUDIO_CHANNEL_2;
3389
3390 /* (0) for clr_avmute, (1) for set_avmute */
3391 hdmi_msm_en_gc_packet(0);
3392 /* (0) for isrc1 only, (1) for isrc1 and isrc2 */
3393 hdmi_msm_en_isrc_packet(1);
3394 /* arbitrary bit pattern for byte1 */
3395 hdmi_msm_en_acp_packet(0x5a);
Manoj Raoc2f19592011-08-05 17:54:25 -07003396 DEV_DBG("Not setting ACP, ISRC1, ISRC2 packets\n");
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003397 hdmi_msm_audio_acr_setup(TRUE,
3398 external_common_state->video_resolution,
Ajay Singh Parmar0fc5d362011-11-16 05:48:33 +05303399 msm_hdmi_sample_rate, channels);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003400 hdmi_msm_audio_info_setup(TRUE, channels, 0, FALSE);
Deepa Madiregama6a3a01a2011-10-28 06:34:17 +05303401
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003402 /* Turn on Audio FIFO and SAM DROP ISR */
3403 HDMI_OUTP(0x02CC, HDMI_INP(0x02CC) | BIT(1) | BIT(3));
3404 DEV_INFO("HDMI Audio: Enabled\n");
3405}
3406
3407static int hdmi_msm_audio_off(void)
3408{
3409 uint32 audio_pkt_ctrl, audio_cfg;
3410 /* Number of wait iterations */
3411 int i = 10;
3412 audio_pkt_ctrl = HDMI_INP_ND(0x0020);
3413 audio_cfg = HDMI_INP_ND(0x01D0);
3414
3415 /* Checking BIT[0] of AUDIO PACKET CONTROL and */
3416 /* AUDIO CONFIGURATION register */
3417 while (((audio_pkt_ctrl & 0x00000001) || (audio_cfg & 0x00000001))
3418 && (i--)) {
3419 audio_pkt_ctrl = HDMI_INP_ND(0x0020);
3420 audio_cfg = HDMI_INP_ND(0x01D0);
3421 DEV_DBG("%d times :: HDMI AUDIO PACKET is %08x and "
3422 "AUDIO CFG is %08x", i, audio_pkt_ctrl, audio_cfg);
3423 msleep(100);
3424 if (!i) {
3425 DEV_ERR("%s:failed to set BIT[0] AUDIO PACKET"
3426 "CONTROL or AUDIO CONFIGURATION REGISTER\n",
3427 __func__);
3428 return -ETIMEDOUT;
3429 }
3430 }
3431 hdmi_msm_audio_info_setup(FALSE, 0, 0, FALSE);
3432 hdmi_msm_audio_ctrl_setup(FALSE, 0);
3433 hdmi_msm_audio_acr_setup(FALSE, 0, 0, 0);
3434 DEV_INFO("HDMI Audio: Disabled\n");
3435 return 0;
3436}
3437
3438
Aravind Venkateswaran38753792011-11-18 13:14:08 -08003439static uint8 hdmi_msm_avi_iframe_lut[][16] = {
3440/* 480p60 480i60 576p50 576i50 720p60 720p50 1080p60 1080i60 1080p50
3441 1080i50 1080p24 1080p30 1080p25 640x480p 480p60_16_9 576p50_4_3 */
3442 {0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
3443 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10}, /*00*/
3444 {0x18, 0x18, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28, 0x28,
3445 0x28, 0x28, 0x28, 0x28, 0x18, 0x28, 0x18}, /*01*/
3446 {0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04,
3447 0x04, 0x04, 0x04, 0x04, 0x88, 0x04, 0x04}, /*02*/
3448 {0x02, 0x06, 0x11, 0x15, 0x04, 0x13, 0x10, 0x05, 0x1F,
3449 0x14, 0x20, 0x22, 0x21, 0x01, 0x03, 0x11}, /*03*/
3450 {0x00, 0x01, 0x00, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00,
3451 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*04*/
3452 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3453 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*05*/
3454 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3455 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*06*/
3456 {0xE1, 0xE1, 0x41, 0x41, 0xD1, 0xd1, 0x39, 0x39, 0x39,
3457 0x39, 0x39, 0x39, 0x39, 0xe1, 0xE1, 0x41}, /*07*/
3458 {0x01, 0x01, 0x02, 0x02, 0x02, 0x02, 0x04, 0x04, 0x04,
3459 0x04, 0x04, 0x04, 0x04, 0x01, 0x01, 0x02}, /*08*/
3460 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3461 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*09*/
3462 {0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
3463 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*10*/
3464 {0xD1, 0xD1, 0xD1, 0xD1, 0x01, 0x01, 0x81, 0x81, 0x81,
3465 0x81, 0x81, 0x81, 0x81, 0x81, 0xD1, 0xD1}, /*11*/
3466 {0x02, 0x02, 0x02, 0x02, 0x05, 0x05, 0x07, 0x07, 0x07,
3467 0x07, 0x07, 0x07, 0x07, 0x02, 0x02, 0x02} /*12*/
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003468};
3469
3470static void hdmi_msm_avi_info_frame(void)
3471{
3472 /* two header + length + 13 data */
3473 uint8 aviInfoFrame[16];
3474 uint8 checksum;
3475 uint32 sum;
3476 uint32 regVal;
3477 int i;
3478 int mode = 0;
3479
3480 switch (external_common_state->video_resolution) {
Manoj Raobbf9a472011-06-14 21:05:18 -07003481 case HDMI_VFRMT_720x480p60_4_3:
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003482 mode = 0;
3483 break;
3484 case HDMI_VFRMT_720x480i60_16_9:
3485 mode = 1;
3486 break;
3487 case HDMI_VFRMT_720x576p50_16_9:
3488 mode = 2;
3489 break;
3490 case HDMI_VFRMT_720x576i50_16_9:
3491 mode = 3;
3492 break;
3493 case HDMI_VFRMT_1280x720p60_16_9:
3494 mode = 4;
3495 break;
3496 case HDMI_VFRMT_1280x720p50_16_9:
3497 mode = 5;
3498 break;
3499 case HDMI_VFRMT_1920x1080p60_16_9:
3500 mode = 6;
3501 break;
3502 case HDMI_VFRMT_1920x1080i60_16_9:
3503 mode = 7;
3504 break;
3505 case HDMI_VFRMT_1920x1080p50_16_9:
3506 mode = 8;
3507 break;
3508 case HDMI_VFRMT_1920x1080i50_16_9:
3509 mode = 9;
3510 break;
3511 case HDMI_VFRMT_1920x1080p24_16_9:
3512 mode = 10;
3513 break;
3514 case HDMI_VFRMT_1920x1080p30_16_9:
3515 mode = 11;
3516 break;
3517 case HDMI_VFRMT_1920x1080p25_16_9:
3518 mode = 12;
3519 break;
3520 case HDMI_VFRMT_640x480p60_4_3:
3521 mode = 13;
3522 break;
Manoj Raobbf9a472011-06-14 21:05:18 -07003523 case HDMI_VFRMT_720x480p60_16_9:
3524 mode = 14;
3525 break;
Aravind Venkateswaran38753792011-11-18 13:14:08 -08003526 case HDMI_VFRMT_720x576p50_4_3:
3527 mode = 15;
3528 break;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003529 default:
3530 DEV_INFO("%s: mode %d not supported\n", __func__,
3531 external_common_state->video_resolution);
3532 return;
3533 }
3534
3535 /* InfoFrame Type = 82 */
3536 aviInfoFrame[0] = 0x82;
3537 /* Version = 2 */
3538 aviInfoFrame[1] = 2;
3539 /* Length of AVI InfoFrame = 13 */
3540 aviInfoFrame[2] = 13;
3541
3542 /* Data Byte 01: 0 Y1 Y0 A0 B1 B0 S1 S0 */
3543 aviInfoFrame[3] = hdmi_msm_avi_iframe_lut[0][mode];
3544 /* Data Byte 02: C1 C0 M1 M0 R3 R2 R1 R0 */
3545 aviInfoFrame[4] = hdmi_msm_avi_iframe_lut[1][mode];
3546 /* Data Byte 03: ITC EC2 EC1 EC0 Q1 Q0 SC1 SC0 */
3547 aviInfoFrame[5] = hdmi_msm_avi_iframe_lut[2][mode];
3548 /* Data Byte 04: 0 VIC6 VIC5 VIC4 VIC3 VIC2 VIC1 VIC0 */
3549 aviInfoFrame[6] = hdmi_msm_avi_iframe_lut[3][mode];
3550 /* Data Byte 05: 0 0 0 0 PR3 PR2 PR1 PR0 */
3551 aviInfoFrame[7] = hdmi_msm_avi_iframe_lut[4][mode];
3552 /* Data Byte 06: LSB Line No of End of Top Bar */
3553 aviInfoFrame[8] = hdmi_msm_avi_iframe_lut[5][mode];
3554 /* Data Byte 07: MSB Line No of End of Top Bar */
3555 aviInfoFrame[9] = hdmi_msm_avi_iframe_lut[6][mode];
3556 /* Data Byte 08: LSB Line No of Start of Bottom Bar */
3557 aviInfoFrame[10] = hdmi_msm_avi_iframe_lut[7][mode];
3558 /* Data Byte 09: MSB Line No of Start of Bottom Bar */
3559 aviInfoFrame[11] = hdmi_msm_avi_iframe_lut[8][mode];
3560 /* Data Byte 10: LSB Pixel Number of End of Left Bar */
3561 aviInfoFrame[12] = hdmi_msm_avi_iframe_lut[9][mode];
3562 /* Data Byte 11: MSB Pixel Number of End of Left Bar */
3563 aviInfoFrame[13] = hdmi_msm_avi_iframe_lut[10][mode];
3564 /* Data Byte 12: LSB Pixel Number of Start of Right Bar */
3565 aviInfoFrame[14] = hdmi_msm_avi_iframe_lut[11][mode];
3566 /* Data Byte 13: MSB Pixel Number of Start of Right Bar */
3567 aviInfoFrame[15] = hdmi_msm_avi_iframe_lut[12][mode];
3568
3569 sum = 0;
3570 for (i = 0; i < 16; i++)
3571 sum += aviInfoFrame[i];
3572 sum &= 0xFF;
3573 sum = 256 - sum;
3574 checksum = (uint8) sum;
3575
3576 regVal = aviInfoFrame[5];
3577 regVal = regVal << 8 | aviInfoFrame[4];
3578 regVal = regVal << 8 | aviInfoFrame[3];
3579 regVal = regVal << 8 | checksum;
3580 HDMI_OUTP(0x006C, regVal);
3581
3582 regVal = aviInfoFrame[9];
3583 regVal = regVal << 8 | aviInfoFrame[8];
3584 regVal = regVal << 8 | aviInfoFrame[7];
3585 regVal = regVal << 8 | aviInfoFrame[6];
3586 HDMI_OUTP(0x0070, regVal);
3587
3588 regVal = aviInfoFrame[13];
3589 regVal = regVal << 8 | aviInfoFrame[12];
3590 regVal = regVal << 8 | aviInfoFrame[11];
3591 regVal = regVal << 8 | aviInfoFrame[10];
3592 HDMI_OUTP(0x0074, regVal);
3593
3594 regVal = aviInfoFrame[1];
3595 regVal = regVal << 16 | aviInfoFrame[15];
3596 regVal = regVal << 8 | aviInfoFrame[14];
3597 HDMI_OUTP(0x0078, regVal);
3598
3599 /* INFOFRAME_CTRL0[0x002C] */
3600 /* 0x3 for AVI InfFrame enable (every frame) */
3601 HDMI_OUTP(0x002C, HDMI_INP(0x002C) | 0x00000003L);
3602}
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003603
3604#ifdef CONFIG_FB_MSM_HDMI_3D
3605static void hdmi_msm_vendor_infoframe_packetsetup(void)
3606{
3607 uint32 packet_header = 0;
3608 uint32 check_sum = 0;
3609 uint32 packet_payload = 0;
3610
3611 if (!external_common_state->format_3d) {
3612 HDMI_OUTP(0x0034, 0);
3613 return;
3614 }
3615
3616 /* 0x0084 GENERIC0_HDR
3617 * HB0 7:0 NUM
3618 * HB1 15:8 NUM
3619 * HB2 23:16 NUM */
3620 /* Setup Packet header and payload */
3621 /* 0x81 VS_INFO_FRAME_ID
3622 0x01 VS_INFO_FRAME_VERSION
3623 0x1B VS_INFO_FRAME_PAYLOAD_LENGTH */
3624 packet_header = 0x81 | (0x01 << 8) | (0x1B << 16);
3625 HDMI_OUTP(0x0084, packet_header);
3626
3627 check_sum = packet_header & 0xff;
3628 check_sum += (packet_header >> 8) & 0xff;
3629 check_sum += (packet_header >> 16) & 0xff;
3630
3631 /* 0x008C GENERIC0_1
3632 * BYTE4 7:0 NUM
3633 * BYTE5 15:8 NUM
3634 * BYTE6 23:16 NUM
3635 * BYTE7 31:24 NUM */
3636 /* 0x02 VS_INFO_FRAME_3D_PRESENT */
3637 packet_payload = 0x02 << 5;
3638 switch (external_common_state->format_3d) {
3639 case 1:
3640 /* 0b1000 VIDEO_3D_FORMAT_SIDE_BY_SIDE_HALF */
3641 packet_payload |= (0x08 << 8) << 4;
3642 break;
3643 case 2:
3644 /* 0b0110 VIDEO_3D_FORMAT_TOP_AND_BOTTOM_HALF */
3645 packet_payload |= (0x06 << 8) << 4;
3646 break;
3647 }
3648 HDMI_OUTP(0x008C, packet_payload);
3649
3650 check_sum += packet_payload & 0xff;
3651 check_sum += (packet_payload >> 8) & 0xff;
3652
3653 #define IEEE_REGISTRATION_ID 0xC03
3654 /* Next 3 bytes are IEEE Registration Identifcation */
3655 /* 0x0088 GENERIC0_0
3656 * BYTE0 7:0 NUM (checksum)
3657 * BYTE1 15:8 NUM
3658 * BYTE2 23:16 NUM
3659 * BYTE3 31:24 NUM */
3660 check_sum += IEEE_REGISTRATION_ID & 0xff;
3661 check_sum += (IEEE_REGISTRATION_ID >> 8) & 0xff;
3662 check_sum += (IEEE_REGISTRATION_ID >> 16) & 0xff;
3663
3664 HDMI_OUTP(0x0088, (0x100 - (0xff & check_sum))
3665 | ((IEEE_REGISTRATION_ID & 0xff) << 8)
3666 | (((IEEE_REGISTRATION_ID >> 8) & 0xff) << 16)
3667 | (((IEEE_REGISTRATION_ID >> 16) & 0xff) << 24));
3668
3669 /* 0x0034 GEN_PKT_CTRL
3670 * GENERIC0_SEND 0 0 = Disable Generic0 Packet Transmission
3671 * 1 = Enable Generic0 Packet Transmission
3672 * GENERIC0_CONT 1 0 = Send Generic0 Packet on next frame only
3673 * 1 = Send Generic0 Packet on every frame
3674 * GENERIC0_UPDATE 2 NUM
3675 * GENERIC1_SEND 4 0 = Disable Generic1 Packet Transmission
3676 * 1 = Enable Generic1 Packet Transmission
3677 * GENERIC1_CONT 5 0 = Send Generic1 Packet on next frame only
3678 * 1 = Send Generic1 Packet on every frame
3679 * GENERIC0_LINE 21:16 NUM
3680 * GENERIC1_LINE 29:24 NUM
3681 */
3682 /* GENERIC0_LINE | GENERIC0_UPDATE | GENERIC0_CONT | GENERIC0_SEND
3683 * Setup HDMI TX generic packet control
3684 * Enable this packet to transmit every frame
3685 * Enable this packet to transmit every frame
3686 * Enable HDMI TX engine to transmit Generic packet 0 */
3687 HDMI_OUTP(0x0034, (1 << 16) | (1 << 2) | BIT(1) | BIT(0));
3688}
3689
3690static void hdmi_msm_switch_3d(boolean on)
3691{
3692 mutex_lock(&external_common_state_hpd_mutex);
3693 if (external_common_state->hpd_state)
3694 hdmi_msm_vendor_infoframe_packetsetup();
3695 mutex_unlock(&external_common_state_hpd_mutex);
3696}
3697#endif
3698
Ravishangar Kalyanam49a83b22011-07-20 15:28:44 -07003699int hdmi_msm_clk(int on)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003700{
3701 int rc;
3702
3703 DEV_DBG("HDMI Clk: %s\n", on ? "Enable" : "Disable");
3704 if (on) {
3705 rc = clk_enable(hdmi_msm_state->hdmi_app_clk);
3706 if (rc) {
3707 DEV_ERR("'hdmi_app_clk' clock enable failed, rc=%d\n",
3708 rc);
3709 return rc;
3710 }
3711
3712 rc = clk_enable(hdmi_msm_state->hdmi_m_pclk);
3713 if (rc) {
3714 DEV_ERR("'hdmi_m_pclk' clock enable failed, rc=%d\n",
3715 rc);
3716 return rc;
3717 }
3718
3719 rc = clk_enable(hdmi_msm_state->hdmi_s_pclk);
3720 if (rc) {
3721 DEV_ERR("'hdmi_s_pclk' clock enable failed, rc=%d\n",
3722 rc);
3723 return rc;
3724 }
3725 } else {
3726 clk_disable(hdmi_msm_state->hdmi_app_clk);
3727 clk_disable(hdmi_msm_state->hdmi_m_pclk);
3728 clk_disable(hdmi_msm_state->hdmi_s_pclk);
3729 }
3730
3731 return 0;
3732}
3733
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003734static void hdmi_msm_turn_on(void)
3735{
3736 uint32 hpd_ctrl;
Abhishek Kharbandaa077d002011-11-04 14:25:48 -07003737 uint32 audio_pkt_ctrl, audio_cfg;
3738 /*
3739 * Number of wait iterations for QDSP to disable Audio Engine
3740 * before resetting HDMI core
3741 */
3742 int i = 10;
3743 audio_pkt_ctrl = HDMI_INP_ND(0x0020);
3744 audio_cfg = HDMI_INP_ND(0x01D0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003745
Abhishek Kharbandaa077d002011-11-04 14:25:48 -07003746 /*
3747 * Checking BIT[0] of AUDIO PACKET CONTROL and
3748 * AUDIO CONFIGURATION register
3749 */
3750 while (((audio_pkt_ctrl & 0x00000001) || (audio_cfg & 0x00000001))
3751 && (i--)) {
3752 audio_pkt_ctrl = HDMI_INP_ND(0x0020);
3753 audio_cfg = HDMI_INP_ND(0x01D0);
3754 DEV_DBG("%d times :: HDMI AUDIO PACKET is %08x and "
3755 "AUDIO CFG is %08x", i, audio_pkt_ctrl, audio_cfg);
3756 msleep(20);
3757 }
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003758 hdmi_msm_reset_core();
3759 hdmi_msm_init_phy(external_common_state->video_resolution);
3760 /* HDMI_USEC_REFTIMER[0x0208] */
3761 HDMI_OUTP(0x0208, 0x0001001B);
3762
3763 hdmi_msm_video_setup(external_common_state->video_resolution);
3764 if (!hdmi_msm_is_dvi_mode())
3765 hdmi_msm_audio_setup();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003766 hdmi_msm_avi_info_frame();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003767#ifdef CONFIG_FB_MSM_HDMI_3D
3768 hdmi_msm_vendor_infoframe_packetsetup();
3769#endif
3770
3771 /* set timeout to 4.1ms (max) for hardware debounce */
3772 hpd_ctrl = (HDMI_INP(0x0258) & ~0xFFF) | 0xFFF;
3773
3774 /* Toggle HPD circuit to trigger HPD sense */
3775 HDMI_OUTP(0x0258, ~(1 << 28) & hpd_ctrl);
3776 HDMI_OUTP(0x0258, (1 << 28) | hpd_ctrl);
3777
3778 hdmi_msm_set_mode(TRUE);
3779
3780 /* Setup HPD IRQ */
3781 HDMI_OUTP(0x0254, 4 | (external_common_state->hpd_state ? 0 : 2));
3782
3783#ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT
3784 if (hdmi_msm_state->reauth) {
3785 hdmi_msm_hdcp_enable();
3786 hdmi_msm_state->reauth = FALSE ;
3787 }
3788#endif /* CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT */
Manoj Raoa2c27672011-08-30 17:19:39 -07003789
3790#ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_CEC_SUPPORT
3791 /* re-initialize CEC if enabled */
3792 mutex_lock(&hdmi_msm_state_mutex);
3793 if (hdmi_msm_state->cec_enabled == true) {
3794 hdmi_msm_cec_init();
3795 hdmi_msm_cec_write_logical_addr(
3796 hdmi_msm_state->cec_logical_addr);
3797 }
3798 mutex_unlock(&hdmi_msm_state_mutex);
3799#endif /* CONFIG_FB_MSM_HDMI_MSM_PANEL_CEC_SUPPORT */
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003800 DEV_INFO("HDMI Core: Initialized\n");
3801}
3802
3803static void hdmi_msm_hpd_state_timer(unsigned long data)
3804{
3805 queue_work(hdmi_work_queue, &hdmi_msm_state->hpd_state_work);
3806}
3807
3808#ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT
3809static void hdmi_msm_hdcp_timer(unsigned long data)
3810{
3811 queue_work(hdmi_work_queue, &hdmi_msm_state->hdcp_work);
3812}
3813#endif
3814
3815static void hdmi_msm_hpd_read_work(struct work_struct *work)
3816{
3817 uint32 hpd_ctrl;
3818
3819 clk_enable(hdmi_msm_state->hdmi_app_clk);
3820 hdmi_msm_state->pd->core_power(1, 1);
3821 hdmi_msm_state->pd->enable_5v(1);
3822 hdmi_msm_set_mode(FALSE);
3823 hdmi_msm_init_phy(external_common_state->video_resolution);
3824 /* HDMI_USEC_REFTIMER[0x0208] */
3825 HDMI_OUTP(0x0208, 0x0001001B);
3826 hpd_ctrl = (HDMI_INP(0x0258) & ~0xFFF) | 0xFFF;
3827
3828 /* Toggle HPD circuit to trigger HPD sense */
3829 HDMI_OUTP(0x0258, ~(1 << 28) & hpd_ctrl);
3830 HDMI_OUTP(0x0258, (1 << 28) | hpd_ctrl);
3831
3832 hdmi_msm_set_mode(TRUE);
3833 msleep(1000);
3834 external_common_state->hpd_state = (HDMI_INP(0x0250) & 0x2) >> 1;
3835 if (external_common_state->hpd_state) {
3836 hdmi_msm_read_edid();
3837 DEV_DBG("%s: sense CONNECTED: send ONLINE\n", __func__);
3838 kobject_uevent(external_common_state->uevent_kobj,
3839 KOBJ_ONLINE);
3840 }
3841 hdmi_msm_hpd_off();
3842 hdmi_msm_set_mode(FALSE);
3843 hdmi_msm_state->pd->core_power(0, 1);
3844 hdmi_msm_state->pd->enable_5v(0);
3845 clk_disable(hdmi_msm_state->hdmi_app_clk);
3846}
3847
3848static void hdmi_msm_hpd_off(void)
3849{
3850 DEV_DBG("%s: (timer, clk, 5V, core, IRQ off)\n", __func__);
3851 del_timer(&hdmi_msm_state->hpd_state_timer);
3852 disable_irq(hdmi_msm_state->irq);
3853
3854 hdmi_msm_set_mode(FALSE);
3855 HDMI_OUTP_ND(0x0308, 0x7F); /*0b01111111*/
3856 hdmi_msm_state->hpd_initialized = FALSE;
Manoj Raoa2c27672011-08-30 17:19:39 -07003857 hdmi_msm_state->pd->cec_power(0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003858 hdmi_msm_state->pd->enable_5v(0);
3859 hdmi_msm_state->pd->core_power(0, 1);
3860 hdmi_msm_clk(0);
3861 hdmi_msm_state->hpd_initialized = FALSE;
3862}
3863
Manoj Rao668d6d52011-08-16 19:12:31 -07003864static void hdmi_msm_dump_regs(const char *prefix)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003865{
3866#ifdef REG_DUMP
3867 print_hex_dump(KERN_INFO, prefix, DUMP_PREFIX_OFFSET, 32, 4,
3868 (void *)MSM_HDMI_BASE, 0x0334, false);
3869#endif
3870}
3871
3872static int hdmi_msm_hpd_on(bool trigger_handler)
3873{
3874 static int phy_reset_done;
3875
3876 hdmi_msm_clk(1);
3877 hdmi_msm_state->pd->core_power(1, 1);
3878 hdmi_msm_state->pd->enable_5v(1);
Manoj Raoa2c27672011-08-30 17:19:39 -07003879 hdmi_msm_state->pd->cec_power(1);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07003880 hdmi_msm_dump_regs("HDMI-INIT: ");
3881 hdmi_msm_set_mode(FALSE);
3882
3883 if (!phy_reset_done) {
3884 hdmi_phy_reset();
3885 phy_reset_done = 1;
3886 }
3887
3888 hdmi_msm_init_phy(external_common_state->video_resolution);
3889 /* HDMI_USEC_REFTIMER[0x0208] */
3890 HDMI_OUTP(0x0208, 0x0001001B);
3891
3892 /* Check HPD State */
3893 if (!hdmi_msm_state->hpd_initialized) {
3894 uint32 hpd_ctrl;
3895 enable_irq(hdmi_msm_state->irq);
3896
3897 /* set timeout to 4.1ms (max) for hardware debounce */
3898 hpd_ctrl = (HDMI_INP(0x0258) & ~0xFFF) | 0xFFF;
3899
3900 /* Toggle HPD circuit to trigger HPD sense */
3901 HDMI_OUTP(0x0258, ~(1 << 28) & hpd_ctrl);
3902 HDMI_OUTP(0x0258, (1 << 28) | hpd_ctrl);
3903
3904 DEV_DBG("%s: (clk, 5V, core, IRQ on) <trigger:%s>\n", __func__,
3905 trigger_handler ? "true" : "false");
3906
3907 if (trigger_handler) {
3908 /* Set HPD state machine: ensure at least 2 readouts */
3909 mutex_lock(&hdmi_msm_state_mutex);
3910 hdmi_msm_state->hpd_stable = 0;
3911 hdmi_msm_state->hpd_prev_state = TRUE;
3912 mutex_lock(&external_common_state_hpd_mutex);
3913 external_common_state->hpd_state = FALSE;
3914 mutex_unlock(&external_common_state_hpd_mutex);
3915 hdmi_msm_state->hpd_cable_chg_detected = TRUE;
3916 mutex_unlock(&hdmi_msm_state_mutex);
3917 mod_timer(&hdmi_msm_state->hpd_state_timer,
3918 jiffies + HZ/2);
3919 }
3920
3921 hdmi_msm_state->hpd_initialized = TRUE;
3922 }
3923 hdmi_msm_set_mode(TRUE);
3924
3925 return 0;
3926}
3927
3928static int hdmi_msm_power_on(struct platform_device *pdev)
3929{
3930 struct msm_fb_data_type *mfd = platform_get_drvdata(pdev);
3931 bool changed;
3932
3933 if (!hdmi_msm_state || !hdmi_msm_state->hdmi_app_clk || !MSM_HDMI_BASE)
3934 return -ENODEV;
3935#ifdef CONFIG_SUSPEND
3936 mutex_lock(&hdmi_msm_state_mutex);
3937 if (hdmi_msm_state->pm_suspended) {
3938 mutex_unlock(&hdmi_msm_state_mutex);
3939 DEV_WARN("%s: ignored, pm_suspended\n", __func__);
3940 return -ENODEV;
3941 }
3942 mutex_unlock(&hdmi_msm_state_mutex);
3943#endif
3944
3945 DEV_INFO("power: ON (%dx%d %d)\n", mfd->var_xres, mfd->var_yres,
3946 mfd->var_pixclock);
3947
3948#ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT
3949 mutex_lock(&hdmi_msm_state_mutex);
3950 if (hdmi_msm_state->hdcp_activating) {
3951 hdmi_msm_state->panel_power_on = TRUE;
3952 DEV_INFO("HDCP: activating, returning\n");
3953 }
3954 mutex_unlock(&hdmi_msm_state_mutex);
3955#endif /* CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT */
3956
3957 changed = hdmi_common_get_video_format_from_drv_data(mfd);
3958 if (!external_common_state->hpd_feature_on) {
3959 int rc = hdmi_msm_hpd_on(true);
3960 DEV_INFO("HPD: panel power without 'hpd' feature on\n");
3961 if (rc) {
3962 DEV_WARN("HPD: activation failed: rc=%d\n", rc);
3963 return rc;
3964 }
3965 }
3966 hdmi_msm_audio_info_setup(TRUE, 0, 0, FALSE);
3967
3968 mutex_lock(&external_common_state_hpd_mutex);
3969 hdmi_msm_state->panel_power_on = TRUE;
3970 if ((external_common_state->hpd_state && !hdmi_msm_is_power_on())
3971 || changed) {
3972 mutex_unlock(&external_common_state_hpd_mutex);
3973 hdmi_msm_turn_on();
3974 } else
3975 mutex_unlock(&external_common_state_hpd_mutex);
3976
3977 hdmi_msm_dump_regs("HDMI-ON: ");
3978
3979 DEV_INFO("power=%s DVI= %s\n",
3980 hdmi_msm_is_power_on() ? "ON" : "OFF" ,
3981 hdmi_msm_is_dvi_mode() ? "ON" : "OFF");
3982 return 0;
3983}
3984
3985/* Note that power-off will also be called when the cable-remove event is
3986 * processed on the user-space and as a result the framebuffer is powered
3987 * down. However, we are still required to be able to detect a cable-insert
3988 * event; so for now leave the HDMI engine running; so that the HPD IRQ is
3989 * still being processed.
3990 */
3991static int hdmi_msm_power_off(struct platform_device *pdev)
3992{
3993 if (!hdmi_msm_state->hdmi_app_clk)
3994 return -ENODEV;
3995#ifdef CONFIG_SUSPEND
3996 mutex_lock(&hdmi_msm_state_mutex);
3997 if (hdmi_msm_state->pm_suspended) {
3998 mutex_unlock(&hdmi_msm_state_mutex);
3999 DEV_WARN("%s: ignored, pm_suspended\n", __func__);
4000 return -ENODEV;
4001 }
4002 mutex_unlock(&hdmi_msm_state_mutex);
4003#endif
4004
4005#ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT
4006 mutex_lock(&hdmi_msm_state_mutex);
4007 if (hdmi_msm_state->hdcp_activating) {
4008 hdmi_msm_state->panel_power_on = FALSE;
4009 mutex_unlock(&hdmi_msm_state_mutex);
4010 DEV_INFO("HDCP: activating, returning\n");
4011 return 0;
4012 }
4013 mutex_unlock(&hdmi_msm_state_mutex);
4014#endif /* CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT */
4015
4016 DEV_INFO("power: OFF (audio off, Reset Core)\n");
4017 hdmi_msm_audio_off();
4018#ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT
4019 hdcp_deauthenticate();
4020#endif
4021 hdmi_msm_hpd_off();
4022 hdmi_msm_powerdown_phy();
4023 hdmi_msm_dump_regs("HDMI-OFF: ");
Manoj Rao53ac99d2011-10-10 17:32:28 -07004024 hdmi_msm_hpd_on(true);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004025
4026 mutex_lock(&external_common_state_hpd_mutex);
4027 if (!external_common_state->hpd_feature_on)
4028 hdmi_msm_hpd_off();
4029 mutex_unlock(&external_common_state_hpd_mutex);
4030
4031 hdmi_msm_state->panel_power_on = FALSE;
4032 return 0;
4033}
4034
4035static int __devinit hdmi_msm_probe(struct platform_device *pdev)
4036{
4037 int rc;
4038 struct platform_device *fb_dev;
4039
Stepan Moskovchenko164fe8a2011-08-05 18:10:54 -07004040 if (cpu_is_apq8064())
4041 return -ENODEV;
4042
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004043 if (!hdmi_msm_state) {
4044 pr_err("%s: hdmi_msm_state is NULL\n", __func__);
4045 return -ENOMEM;
4046 }
4047
4048 external_common_state->dev = &pdev->dev;
4049 DEV_DBG("probe\n");
4050 if (pdev->id == 0) {
4051 struct resource *res;
4052
4053 #define GET_RES(name, mode) do { \
4054 res = platform_get_resource_byname(pdev, mode, name); \
4055 if (!res) { \
4056 DEV_ERR("'" name "' resource not found\n"); \
4057 rc = -ENODEV; \
4058 goto error; \
4059 } \
4060 } while (0)
4061
4062 #define IO_REMAP(var, name) do { \
4063 GET_RES(name, IORESOURCE_MEM); \
4064 var = ioremap(res->start, resource_size(res)); \
4065 if (!var) { \
4066 DEV_ERR("'" name "' ioremap failed\n"); \
4067 rc = -ENOMEM; \
4068 goto error; \
4069 } \
4070 } while (0)
4071
4072 #define GET_IRQ(var, name) do { \
4073 GET_RES(name, IORESOURCE_IRQ); \
4074 var = res->start; \
4075 } while (0)
4076
4077 IO_REMAP(hdmi_msm_state->qfprom_io, "hdmi_msm_qfprom_addr");
4078 hdmi_msm_state->hdmi_io = MSM_HDMI_BASE;
4079 GET_IRQ(hdmi_msm_state->irq, "hdmi_msm_irq");
4080
4081 hdmi_msm_state->pd = pdev->dev.platform_data;
4082
4083 #undef GET_RES
4084 #undef IO_REMAP
4085 #undef GET_IRQ
4086 return 0;
4087 }
4088
Matt Wagantall5a4f1ba2011-08-18 18:13:03 -07004089 hdmi_msm_state->hdmi_app_clk = clk_get(&pdev->dev, "core_clk");
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004090 if (IS_ERR(hdmi_msm_state->hdmi_app_clk)) {
Matt Wagantall5a4f1ba2011-08-18 18:13:03 -07004091 DEV_ERR("'core_clk' clk not found\n");
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004092 rc = IS_ERR(hdmi_msm_state->hdmi_app_clk);
4093 goto error;
4094 }
4095
Matt Wagantall5a4f1ba2011-08-18 18:13:03 -07004096 hdmi_msm_state->hdmi_m_pclk = clk_get(&pdev->dev, "master_iface_clk");
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004097 if (IS_ERR(hdmi_msm_state->hdmi_m_pclk)) {
Matt Wagantall5a4f1ba2011-08-18 18:13:03 -07004098 DEV_ERR("'master_iface_clk' clk not found\n");
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004099 rc = IS_ERR(hdmi_msm_state->hdmi_m_pclk);
4100 goto error;
4101 }
4102
Matt Wagantall5a4f1ba2011-08-18 18:13:03 -07004103 hdmi_msm_state->hdmi_s_pclk = clk_get(&pdev->dev, "slave_iface_clk");
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004104 if (IS_ERR(hdmi_msm_state->hdmi_s_pclk)) {
Matt Wagantall5a4f1ba2011-08-18 18:13:03 -07004105 DEV_ERR("'slave_iface_clk' clk not found\n");
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004106 rc = IS_ERR(hdmi_msm_state->hdmi_s_pclk);
4107 goto error;
4108 }
4109
4110 rc = check_hdmi_features();
4111 if (rc) {
4112 DEV_ERR("Init FAILED: check_hdmi_features rc=%d\n", rc);
4113 goto error;
4114 }
4115
4116 if (!hdmi_msm_state->pd->core_power) {
4117 DEV_ERR("Init FAILED: core_power function missing\n");
4118 rc = -ENODEV;
4119 goto error;
4120 }
4121 if (!hdmi_msm_state->pd->enable_5v) {
4122 DEV_ERR("Init FAILED: enable_5v function missing\n");
4123 rc = -ENODEV;
4124 goto error;
4125 }
4126
Manoj Raoa2c27672011-08-30 17:19:39 -07004127 if (!hdmi_msm_state->pd->cec_power) {
4128 DEV_ERR("Init FAILED: cec_power function missing\n");
4129 rc = -ENODEV;
4130 goto error;
4131 }
4132
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004133 rc = request_threaded_irq(hdmi_msm_state->irq, NULL, &hdmi_msm_isr,
4134 IRQF_TRIGGER_HIGH | IRQF_ONESHOT, "hdmi_msm_isr", NULL);
4135 if (rc) {
4136 DEV_ERR("Init FAILED: IRQ request, rc=%d\n", rc);
4137 goto error;
4138 }
4139 disable_irq(hdmi_msm_state->irq);
4140
4141 init_timer(&hdmi_msm_state->hpd_state_timer);
4142 hdmi_msm_state->hpd_state_timer.function =
4143 hdmi_msm_hpd_state_timer;
4144 hdmi_msm_state->hpd_state_timer.data = (uint32)NULL;
4145
4146 hdmi_msm_state->hpd_state_timer.expires = 0xffffffffL;
4147 add_timer(&hdmi_msm_state->hpd_state_timer);
4148
4149#ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT
4150 init_timer(&hdmi_msm_state->hdcp_timer);
4151 hdmi_msm_state->hdcp_timer.function =
4152 hdmi_msm_hdcp_timer;
4153 hdmi_msm_state->hdcp_timer.data = (uint32)NULL;
4154
4155 hdmi_msm_state->hdcp_timer.expires = 0xffffffffL;
4156 add_timer(&hdmi_msm_state->hdcp_timer);
4157#endif /* CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT */
4158
4159 fb_dev = msm_fb_add_device(pdev);
4160 if (fb_dev) {
4161 rc = external_common_state_create(fb_dev);
4162 if (rc) {
4163 DEV_ERR("Init FAILED: hdmi_msm_state_create, rc=%d\n",
4164 rc);
4165 goto error;
4166 }
4167 } else
4168 DEV_ERR("Init FAILED: failed to add fb device\n");
4169
4170 DEV_INFO("HDMI HPD: ON\n");
4171
4172 rc = hdmi_msm_hpd_on(true);
4173 if (rc)
4174 goto error;
4175
4176 if (hdmi_msm_has_hdcp())
4177 external_common_state->present_hdcp = TRUE;
4178 else {
4179 external_common_state->present_hdcp = FALSE;
4180#ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT
4181 /*
4182 * If the device is not hdcp capable do
4183 * not start hdcp timer.
4184 */
4185 del_timer(&hdmi_msm_state->hdcp_timer);
4186#endif
4187 }
4188
4189 queue_work(hdmi_work_queue, &hdmi_msm_state->hpd_read_work);
4190 return 0;
4191
4192error:
4193 if (hdmi_msm_state->qfprom_io)
4194 iounmap(hdmi_msm_state->qfprom_io);
4195 hdmi_msm_state->qfprom_io = NULL;
4196
4197 if (hdmi_msm_state->hdmi_io)
4198 iounmap(hdmi_msm_state->hdmi_io);
4199 hdmi_msm_state->hdmi_io = NULL;
4200
4201 external_common_state_remove();
4202
4203 if (hdmi_msm_state->hdmi_app_clk)
4204 clk_put(hdmi_msm_state->hdmi_app_clk);
4205 if (hdmi_msm_state->hdmi_m_pclk)
4206 clk_put(hdmi_msm_state->hdmi_m_pclk);
4207 if (hdmi_msm_state->hdmi_s_pclk)
4208 clk_put(hdmi_msm_state->hdmi_s_pclk);
4209
4210 hdmi_msm_state->hdmi_app_clk = NULL;
4211 hdmi_msm_state->hdmi_m_pclk = NULL;
4212 hdmi_msm_state->hdmi_s_pclk = NULL;
4213
4214 return rc;
4215}
4216
4217static int __devexit hdmi_msm_remove(struct platform_device *pdev)
4218{
4219 DEV_INFO("HDMI device: remove\n");
4220
4221 DEV_INFO("HDMI HPD: OFF\n");
4222 hdmi_msm_hpd_off();
4223 free_irq(hdmi_msm_state->irq, NULL);
4224
4225 if (hdmi_msm_state->qfprom_io)
4226 iounmap(hdmi_msm_state->qfprom_io);
4227 hdmi_msm_state->qfprom_io = NULL;
4228
4229 if (hdmi_msm_state->hdmi_io)
4230 iounmap(hdmi_msm_state->hdmi_io);
4231 hdmi_msm_state->hdmi_io = NULL;
4232
4233 external_common_state_remove();
4234
4235 if (hdmi_msm_state->hdmi_app_clk)
4236 clk_put(hdmi_msm_state->hdmi_app_clk);
4237 if (hdmi_msm_state->hdmi_m_pclk)
4238 clk_put(hdmi_msm_state->hdmi_m_pclk);
4239 if (hdmi_msm_state->hdmi_s_pclk)
4240 clk_put(hdmi_msm_state->hdmi_s_pclk);
4241
4242 hdmi_msm_state->hdmi_app_clk = NULL;
4243 hdmi_msm_state->hdmi_m_pclk = NULL;
4244 hdmi_msm_state->hdmi_s_pclk = NULL;
4245
4246 kfree(hdmi_msm_state);
4247 hdmi_msm_state = NULL;
4248
4249 return 0;
4250}
4251
4252static int hdmi_msm_hpd_feature(int on)
4253{
4254 int rc = 0;
4255
4256 DEV_INFO("%s: %d\n", __func__, on);
4257 if (on)
4258 rc = hdmi_msm_hpd_on(true);
4259 else
4260 hdmi_msm_hpd_off();
4261
4262 return rc;
4263}
4264
4265
4266#ifdef CONFIG_SUSPEND
4267static int hdmi_msm_device_pm_suspend(struct device *dev)
4268{
4269 mutex_lock(&hdmi_msm_state_mutex);
4270 if (hdmi_msm_state->pm_suspended) {
4271 mutex_unlock(&hdmi_msm_state_mutex);
4272 return 0;
4273 }
4274
4275 DEV_DBG("pm_suspend\n");
4276
4277 del_timer(&hdmi_msm_state->hpd_state_timer);
4278#ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT
4279 del_timer(&hdmi_msm_state->hdcp_timer);
4280#endif /* CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT */
4281
4282 disable_irq(hdmi_msm_state->irq);
Ravishangar Kalyanam18337542011-08-12 10:26:35 -07004283 if (external_common_state->hpd_feature_on)
4284 hdmi_msm_clk(0);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004285
4286 hdmi_msm_state->pm_suspended = TRUE;
4287 mutex_unlock(&hdmi_msm_state_mutex);
4288
4289 hdmi_msm_powerdown_phy();
4290 hdmi_msm_state->pd->enable_5v(0);
4291 hdmi_msm_state->pd->core_power(0, 1);
4292 return 0;
4293}
4294
4295static int hdmi_msm_device_pm_resume(struct device *dev)
4296{
4297 mutex_lock(&hdmi_msm_state_mutex);
4298 if (!hdmi_msm_state->pm_suspended) {
4299 mutex_unlock(&hdmi_msm_state_mutex);
4300 return 0;
4301 }
4302
4303 DEV_DBG("pm_resume\n");
4304
4305 hdmi_msm_state->pd->core_power(1, 1);
4306 hdmi_msm_state->pd->enable_5v(1);
Ravishangar Kalyanam18337542011-08-12 10:26:35 -07004307 if (external_common_state->hpd_feature_on)
4308 hdmi_msm_clk(1);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004309
4310 hdmi_msm_state->pm_suspended = FALSE;
4311 mutex_unlock(&hdmi_msm_state_mutex);
4312 enable_irq(hdmi_msm_state->irq);
4313 return 0;
4314}
4315#else
4316#define hdmi_msm_device_pm_suspend NULL
4317#define hdmi_msm_device_pm_resume NULL
4318#endif
4319
4320static const struct dev_pm_ops hdmi_msm_device_pm_ops = {
4321 .suspend = hdmi_msm_device_pm_suspend,
4322 .resume = hdmi_msm_device_pm_resume,
4323};
4324
4325static struct platform_driver this_driver = {
4326 .probe = hdmi_msm_probe,
4327 .remove = hdmi_msm_remove,
4328 .driver.name = "hdmi_msm",
4329 .driver.pm = &hdmi_msm_device_pm_ops,
4330};
4331
4332static struct msm_fb_panel_data hdmi_msm_panel_data = {
4333 .on = hdmi_msm_power_on,
4334 .off = hdmi_msm_power_off,
4335};
4336
4337static struct platform_device this_device = {
4338 .name = "hdmi_msm",
4339 .id = 1,
4340 .dev.platform_data = &hdmi_msm_panel_data,
4341};
4342
4343static int __init hdmi_msm_init(void)
4344{
4345 int rc;
4346
Ajay Singh Parmar2aab6fd2011-12-07 07:23:34 +05304347 if (cpu_is_msm8627())
4348 return 0;
4349
Ravishangar Kalyanamc719c542011-07-28 16:49:25 -07004350 if (msm_fb_detect_client("hdmi_msm"))
4351 return 0;
4352
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004353 hdmi_msm_setup_video_mode_lut();
4354 hdmi_msm_state = kzalloc(sizeof(*hdmi_msm_state), GFP_KERNEL);
4355 if (!hdmi_msm_state) {
4356 pr_err("hdmi_msm_init FAILED: out of memory\n");
4357 rc = -ENOMEM;
4358 goto init_exit;
4359 }
4360
4361 external_common_state = &hdmi_msm_state->common;
4362 external_common_state->video_resolution = HDMI_VFRMT_1920x1080p60_16_9;
4363#ifdef CONFIG_FB_MSM_HDMI_3D
4364 external_common_state->switch_3d = hdmi_msm_switch_3d;
4365#endif
4366
Manoj Raoa2c27672011-08-30 17:19:39 -07004367#ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_CEC_SUPPORT
4368 hdmi_msm_state->cec_queue_start =
4369 kzalloc(sizeof(struct hdmi_msm_cec_msg)*CEC_QUEUE_SIZE,
4370 GFP_KERNEL);
4371 if (!hdmi_msm_state->cec_queue_start) {
4372 pr_err("hdmi_msm_init FAILED: CEC queue out of memory\n");
4373 rc = -ENOMEM;
4374 goto init_exit;
4375 }
4376
4377 hdmi_msm_state->cec_queue_wr = hdmi_msm_state->cec_queue_start;
4378 hdmi_msm_state->cec_queue_rd = hdmi_msm_state->cec_queue_start;
4379 hdmi_msm_state->cec_queue_full = false;
4380#endif
4381
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004382 /*
4383 * Create your work queue
4384 * allocs and returns ptr
4385 */
4386 hdmi_work_queue = create_workqueue("hdmi_hdcp");
4387 external_common_state->hpd_feature = hdmi_msm_hpd_feature;
4388
4389 rc = platform_driver_register(&this_driver);
4390 if (rc) {
4391 pr_err("hdmi_msm_init FAILED: platform_driver_register rc=%d\n",
4392 rc);
4393 goto init_exit;
4394 }
4395
4396 hdmi_common_init_panel_info(&hdmi_msm_panel_data.panel_info);
4397 init_completion(&hdmi_msm_state->ddc_sw_done);
4398 INIT_WORK(&hdmi_msm_state->hpd_state_work, hdmi_msm_hpd_state_work);
4399 INIT_WORK(&hdmi_msm_state->hpd_read_work, hdmi_msm_hpd_read_work);
4400#ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT
4401 init_completion(&hdmi_msm_state->hdcp_success_done);
4402 INIT_WORK(&hdmi_msm_state->hdcp_reauth_work, hdmi_msm_hdcp_reauth_work);
4403 INIT_WORK(&hdmi_msm_state->hdcp_work, hdmi_msm_hdcp_work);
4404#endif /* CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT */
4405
Manoj Raoa2c27672011-08-30 17:19:39 -07004406#ifdef CONFIG_FB_MSM_HDMI_MSM_PANEL_CEC_SUPPORT
4407 init_completion(&hdmi_msm_state->cec_frame_wr_done);
4408#endif
4409
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004410 rc = platform_device_register(&this_device);
4411 if (rc) {
4412 pr_err("hdmi_msm_init FAILED: platform_device_register rc=%d\n",
4413 rc);
4414 platform_driver_unregister(&this_driver);
4415 goto init_exit;
4416 }
4417
4418 pr_debug("%s: success:"
4419#ifdef DEBUG
4420 " DEBUG"
4421#else
4422 " RELEASE"
4423#endif
4424 " AUDIO EDID HPD HDCP"
4425#ifndef CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT
4426 ":0"
4427#endif /* CONFIG_FB_MSM_HDMI_MSM_PANEL_HDCP_SUPPORT */
4428 " DVI"
4429#ifndef CONFIG_FB_MSM_HDMI_MSM_PANEL_DVI_SUPPORT
4430 ":0"
4431#endif /* CONFIG_FB_MSM_HDMI_MSM_PANEL_DVI_SUPPORT */
4432 "\n", __func__);
4433
4434 return 0;
4435
4436init_exit:
4437 kfree(hdmi_msm_state);
4438 hdmi_msm_state = NULL;
4439
4440 return rc;
4441}
4442
4443static void __exit hdmi_msm_exit(void)
4444{
4445 platform_device_unregister(&this_device);
4446 platform_driver_unregister(&this_driver);
4447}
4448
4449module_init(hdmi_msm_init);
4450module_exit(hdmi_msm_exit);
4451
4452MODULE_LICENSE("GPL v2");
4453MODULE_VERSION("0.3");
4454MODULE_AUTHOR("Qualcomm Innovation Center, Inc.");
4455MODULE_DESCRIPTION("HDMI MSM TX driver");