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