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