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