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