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