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