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