1 // SPDX-License-Identifier: GPL-2.0-only
2 /* Copyright (c) 2010-2015, The Linux Foundation. All rights reserved.
6 #include <linux/qcom_scm.h>
8 #define HDCP_REG_ENABLE 0x01
9 #define HDCP_REG_DISABLE 0x00
10 #define HDCP_PORT_ADDR 0x74
12 #define HDCP_INT_STATUS_MASK ( \
13 HDMI_HDCP_INT_CTRL_AUTH_SUCCESS_INT | \
14 HDMI_HDCP_INT_CTRL_AUTH_FAIL_INT | \
15 HDMI_HDCP_INT_CTRL_AUTH_XFER_REQ_INT | \
16 HDMI_HDCP_INT_CTRL_AUTH_XFER_DONE_INT)
18 #define AUTH_WORK_RETRIES_TIME 100
19 #define AUTH_RETRIES_TIME 30
21 /* QFPROM Registers for HDMI/HDCP */
22 #define QFPROM_RAW_FEAT_CONFIG_ROW0_LSB 0x000000F8
23 #define QFPROM_RAW_FEAT_CONFIG_ROW0_MSB 0x000000FC
24 #define HDCP_KSV_LSB 0x000060D8
25 #define HDCP_KSV_MSB 0x000060DC
27 enum DS_TYPE
{ /* type of downstream device */
33 enum hdmi_hdcp_state
{
36 HDCP_STATE_AUTHENTICATING
,
37 HDCP_STATE_AUTHENTICATED
,
38 HDCP_STATE_AUTH_FAILED
41 struct hdmi_hdcp_reg_data
{
48 struct hdmi_hdcp_ctrl
{
52 enum hdmi_hdcp_state hdcp_state
;
53 struct work_struct hdcp_auth_work
;
54 struct work_struct hdcp_reauth_work
;
56 #define AUTH_ABORT_EV 1
57 #define AUTH_RESULT_RDY_EV 2
58 unsigned long auth_event
;
59 wait_queue_head_t auth_event_queue
;
63 * store aksv from qfprom
74 bool max_cascade_exceeded
;
75 bool max_dev_exceeded
;
78 static int msm_hdmi_ddc_read(struct hdmi
*hdmi
, u16 addr
, u8 offset
,
79 u8
*data
, u16 data_len
)
83 struct i2c_msg msgs
[] = {
97 DBG("Start DDC read");
99 rc
= i2c_transfer(hdmi
->i2c
, msgs
, 2);
109 DBG("End DDC read %d", rc
);
114 #define HDCP_DDC_WRITE_MAX_BYTE_NUM 32
116 static int msm_hdmi_ddc_write(struct hdmi
*hdmi
, u16 addr
, u8 offset
,
117 u8
*data
, u16 data_len
)
121 u8 buf
[HDCP_DDC_WRITE_MAX_BYTE_NUM
];
122 struct i2c_msg msgs
[] = {
130 DBG("Start DDC write");
131 if (data_len
> (HDCP_DDC_WRITE_MAX_BYTE_NUM
- 1)) {
132 pr_err("%s: write size too big\n", __func__
);
137 memcpy(&buf
[1], data
, data_len
);
139 msgs
[0].len
= data_len
+ 1;
141 rc
= i2c_transfer(hdmi
->i2c
, msgs
, 1);
151 DBG("End DDC write %d", rc
);
156 static int msm_hdmi_hdcp_scm_wr(struct hdmi_hdcp_ctrl
*hdcp_ctrl
, u32
*preg
,
157 u32
*pdata
, u32 count
)
159 struct hdmi
*hdmi
= hdcp_ctrl
->hdmi
;
160 struct qcom_scm_hdcp_req scm_buf
[QCOM_SCM_HDCP_MAX_REQ_CNT
];
161 u32 resp
, phy_addr
, idx
= 0;
164 WARN_ON(!pdata
|| !preg
|| (count
== 0));
166 if (hdcp_ctrl
->tz_hdcp
) {
167 phy_addr
= (u32
)hdmi
->mmio_phy_addr
;
170 memset(scm_buf
, 0, sizeof(scm_buf
));
171 for (i
= 0; i
< count
&& i
< QCOM_SCM_HDCP_MAX_REQ_CNT
;
173 scm_buf
[i
].addr
= phy_addr
+ preg
[idx
];
174 scm_buf
[i
].val
= pdata
[idx
];
177 ret
= qcom_scm_hdcp_req(scm_buf
, i
, &resp
);
180 pr_err("%s: error: scm_call ret=%d resp=%u\n",
181 __func__
, ret
, resp
);
189 for (i
= 0; i
< count
; i
++)
190 hdmi_write(hdmi
, preg
[i
], pdata
[i
]);
196 void msm_hdmi_hdcp_irq(struct hdmi_hdcp_ctrl
*hdcp_ctrl
)
198 struct hdmi
*hdmi
= hdcp_ctrl
->hdmi
;
199 u32 reg_val
, hdcp_int_status
;
202 spin_lock_irqsave(&hdmi
->reg_lock
, flags
);
203 reg_val
= hdmi_read(hdmi
, REG_HDMI_HDCP_INT_CTRL
);
204 hdcp_int_status
= reg_val
& HDCP_INT_STATUS_MASK
;
205 if (!hdcp_int_status
) {
206 spin_unlock_irqrestore(&hdmi
->reg_lock
, flags
);
209 /* Clear Interrupts */
210 reg_val
|= hdcp_int_status
<< 1;
211 /* Clear AUTH_FAIL_INFO as well */
212 if (hdcp_int_status
& HDMI_HDCP_INT_CTRL_AUTH_FAIL_INT
)
213 reg_val
|= HDMI_HDCP_INT_CTRL_AUTH_FAIL_INFO_ACK
;
214 hdmi_write(hdmi
, REG_HDMI_HDCP_INT_CTRL
, reg_val
);
215 spin_unlock_irqrestore(&hdmi
->reg_lock
, flags
);
217 DBG("hdcp irq %x", hdcp_int_status
);
219 if (hdcp_int_status
& HDMI_HDCP_INT_CTRL_AUTH_SUCCESS_INT
) {
220 pr_info("%s:AUTH_SUCCESS_INT received\n", __func__
);
221 if (HDCP_STATE_AUTHENTICATING
== hdcp_ctrl
->hdcp_state
) {
222 set_bit(AUTH_RESULT_RDY_EV
, &hdcp_ctrl
->auth_event
);
223 wake_up_all(&hdcp_ctrl
->auth_event_queue
);
227 if (hdcp_int_status
& HDMI_HDCP_INT_CTRL_AUTH_FAIL_INT
) {
228 reg_val
= hdmi_read(hdmi
, REG_HDMI_HDCP_LINK0_STATUS
);
229 pr_info("%s: AUTH_FAIL_INT rcvd, LINK0_STATUS=0x%08x\n",
231 if (HDCP_STATE_AUTHENTICATED
== hdcp_ctrl
->hdcp_state
)
232 queue_work(hdmi
->workq
, &hdcp_ctrl
->hdcp_reauth_work
);
233 else if (HDCP_STATE_AUTHENTICATING
==
234 hdcp_ctrl
->hdcp_state
) {
235 set_bit(AUTH_RESULT_RDY_EV
, &hdcp_ctrl
->auth_event
);
236 wake_up_all(&hdcp_ctrl
->auth_event_queue
);
241 static int msm_hdmi_hdcp_msleep(struct hdmi_hdcp_ctrl
*hdcp_ctrl
, u32 ms
, u32 ev
)
245 rc
= wait_event_timeout(hdcp_ctrl
->auth_event_queue
,
246 !!test_bit(ev
, &hdcp_ctrl
->auth_event
),
247 msecs_to_jiffies(ms
));
249 pr_info("%s: msleep is canceled by event %d\n",
251 clear_bit(ev
, &hdcp_ctrl
->auth_event
);
258 static int msm_hdmi_hdcp_read_validate_aksv(struct hdmi_hdcp_ctrl
*hdcp_ctrl
)
260 struct hdmi
*hdmi
= hdcp_ctrl
->hdmi
;
262 /* Fetch aksv from QFPROM, this info should be public. */
263 hdcp_ctrl
->aksv_lsb
= hdmi_qfprom_read(hdmi
, HDCP_KSV_LSB
);
264 hdcp_ctrl
->aksv_msb
= hdmi_qfprom_read(hdmi
, HDCP_KSV_MSB
);
266 /* check there are 20 ones in AKSV */
267 if ((hweight32(hdcp_ctrl
->aksv_lsb
) + hweight32(hdcp_ctrl
->aksv_msb
))
269 pr_err("%s: AKSV QFPROM doesn't have 20 1's, 20 0's\n",
271 pr_err("%s: QFPROM AKSV chk failed (AKSV=%02x%08x)\n",
272 __func__
, hdcp_ctrl
->aksv_msb
,
273 hdcp_ctrl
->aksv_lsb
);
276 DBG("AKSV=%02x%08x", hdcp_ctrl
->aksv_msb
, hdcp_ctrl
->aksv_lsb
);
281 static int msm_reset_hdcp_ddc_failures(struct hdmi_hdcp_ctrl
*hdcp_ctrl
)
283 struct hdmi
*hdmi
= hdcp_ctrl
->hdmi
;
284 u32 reg_val
, failure
, nack0
;
287 /* Check for any DDC transfer failures */
288 reg_val
= hdmi_read(hdmi
, REG_HDMI_HDCP_DDC_STATUS
);
289 failure
= reg_val
& HDMI_HDCP_DDC_STATUS_FAILED
;
290 nack0
= reg_val
& HDMI_HDCP_DDC_STATUS_NACK0
;
291 DBG("HDCP_DDC_STATUS=0x%x, FAIL=%d, NACK0=%d",
292 reg_val
, failure
, nack0
);
296 * Indicates that the last HDCP HW DDC transfer failed.
297 * This occurs when a transfer is attempted with HDCP DDC
298 * disabled (HDCP_DDC_DISABLE=1) or the number of retries
299 * matches HDCP_DDC_RETRY_CNT.
300 * Failure occurred, let's clear it.
302 DBG("DDC failure detected");
304 /* First, Disable DDC */
305 hdmi_write(hdmi
, REG_HDMI_HDCP_DDC_CTRL_0
,
306 HDMI_HDCP_DDC_CTRL_0_DISABLE
);
308 /* ACK the Failure to Clear it */
309 reg_val
= hdmi_read(hdmi
, REG_HDMI_HDCP_DDC_CTRL_1
);
310 reg_val
|= HDMI_HDCP_DDC_CTRL_1_FAILED_ACK
;
311 hdmi_write(hdmi
, REG_HDMI_HDCP_DDC_CTRL_1
, reg_val
);
313 /* Check if the FAILURE got Cleared */
314 reg_val
= hdmi_read(hdmi
, REG_HDMI_HDCP_DDC_STATUS
);
315 if (reg_val
& HDMI_HDCP_DDC_STATUS_FAILED
)
316 pr_info("%s: Unable to clear HDCP DDC Failure\n",
319 /* Re-Enable HDCP DDC */
320 hdmi_write(hdmi
, REG_HDMI_HDCP_DDC_CTRL_0
, 0);
324 DBG("Before: HDMI_DDC_SW_STATUS=0x%08x",
325 hdmi_read(hdmi
, REG_HDMI_DDC_SW_STATUS
));
326 /* Reset HDMI DDC software status */
327 reg_val
= hdmi_read(hdmi
, REG_HDMI_DDC_CTRL
);
328 reg_val
|= HDMI_DDC_CTRL_SW_STATUS_RESET
;
329 hdmi_write(hdmi
, REG_HDMI_DDC_CTRL
, reg_val
);
331 rc
= msm_hdmi_hdcp_msleep(hdcp_ctrl
, 20, AUTH_ABORT_EV
);
333 reg_val
= hdmi_read(hdmi
, REG_HDMI_DDC_CTRL
);
334 reg_val
&= ~HDMI_DDC_CTRL_SW_STATUS_RESET
;
335 hdmi_write(hdmi
, REG_HDMI_DDC_CTRL
, reg_val
);
337 /* Reset HDMI DDC Controller */
338 reg_val
= hdmi_read(hdmi
, REG_HDMI_DDC_CTRL
);
339 reg_val
|= HDMI_DDC_CTRL_SOFT_RESET
;
340 hdmi_write(hdmi
, REG_HDMI_DDC_CTRL
, reg_val
);
342 /* If previous msleep is aborted, skip this msleep */
344 rc
= msm_hdmi_hdcp_msleep(hdcp_ctrl
, 20, AUTH_ABORT_EV
);
346 reg_val
= hdmi_read(hdmi
, REG_HDMI_DDC_CTRL
);
347 reg_val
&= ~HDMI_DDC_CTRL_SOFT_RESET
;
348 hdmi_write(hdmi
, REG_HDMI_DDC_CTRL
, reg_val
);
349 DBG("After: HDMI_DDC_SW_STATUS=0x%08x",
350 hdmi_read(hdmi
, REG_HDMI_DDC_SW_STATUS
));
356 static int msm_hdmi_hdcp_hw_ddc_clean(struct hdmi_hdcp_ctrl
*hdcp_ctrl
)
359 u32 hdcp_ddc_status
, ddc_hw_status
;
360 u32 xfer_done
, xfer_req
, hw_done
;
363 struct hdmi
*hdmi
= hdcp_ctrl
->hdmi
;
365 if (hdmi_read(hdmi
, REG_HDMI_DDC_HW_STATUS
) == 0)
368 /* Wait to be clean on DDC HW engine */
371 hdcp_ddc_status
= hdmi_read(hdmi
, REG_HDMI_HDCP_DDC_STATUS
);
372 ddc_hw_status
= hdmi_read(hdmi
, REG_HDMI_DDC_HW_STATUS
);
374 xfer_done
= hdcp_ddc_status
& HDMI_HDCP_DDC_STATUS_XFER_DONE
;
375 xfer_req
= hdcp_ddc_status
& HDMI_HDCP_DDC_STATUS_XFER_REQ
;
376 hw_done
= ddc_hw_status
& HDMI_DDC_HW_STATUS_DONE
;
377 hw_not_ready
= !xfer_done
|| xfer_req
|| !hw_done
;
383 if (!timeout_count
) {
384 pr_warn("%s: hw_ddc_clean failed\n", __func__
);
388 rc
= msm_hdmi_hdcp_msleep(hdcp_ctrl
, 20, AUTH_ABORT_EV
);
396 static void msm_hdmi_hdcp_reauth_work(struct work_struct
*work
)
398 struct hdmi_hdcp_ctrl
*hdcp_ctrl
= container_of(work
,
399 struct hdmi_hdcp_ctrl
, hdcp_reauth_work
);
400 struct hdmi
*hdmi
= hdcp_ctrl
->hdmi
;
404 DBG("HDCP REAUTH WORK");
406 * Disable HPD circuitry.
407 * This is needed to reset the HDCP cipher engine so that when we
408 * attempt a re-authentication, HW would clear the AN0_READY and
409 * AN1_READY bits in HDMI_HDCP_LINK0_STATUS register
411 spin_lock_irqsave(&hdmi
->reg_lock
, flags
);
412 reg_val
= hdmi_read(hdmi
, REG_HDMI_HPD_CTRL
);
413 reg_val
&= ~HDMI_HPD_CTRL_ENABLE
;
414 hdmi_write(hdmi
, REG_HDMI_HPD_CTRL
, reg_val
);
416 /* Disable HDCP interrupts */
417 hdmi_write(hdmi
, REG_HDMI_HDCP_INT_CTRL
, 0);
418 spin_unlock_irqrestore(&hdmi
->reg_lock
, flags
);
420 hdmi_write(hdmi
, REG_HDMI_HDCP_RESET
,
421 HDMI_HDCP_RESET_LINK0_DEAUTHENTICATE
);
423 /* Wait to be clean on DDC HW engine */
424 if (msm_hdmi_hdcp_hw_ddc_clean(hdcp_ctrl
)) {
425 pr_info("%s: reauth work aborted\n", __func__
);
429 /* Disable encryption and disable the HDCP block */
430 hdmi_write(hdmi
, REG_HDMI_HDCP_CTRL
, 0);
432 /* Enable HPD circuitry */
433 spin_lock_irqsave(&hdmi
->reg_lock
, flags
);
434 reg_val
= hdmi_read(hdmi
, REG_HDMI_HPD_CTRL
);
435 reg_val
|= HDMI_HPD_CTRL_ENABLE
;
436 hdmi_write(hdmi
, REG_HDMI_HPD_CTRL
, reg_val
);
437 spin_unlock_irqrestore(&hdmi
->reg_lock
, flags
);
440 * Only retry defined times then abort current authenticating process
442 if (++hdcp_ctrl
->auth_retries
== AUTH_RETRIES_TIME
) {
443 hdcp_ctrl
->hdcp_state
= HDCP_STATE_INACTIVE
;
444 hdcp_ctrl
->auth_retries
= 0;
445 pr_info("%s: abort reauthentication!\n", __func__
);
450 DBG("Queue AUTH WORK");
451 hdcp_ctrl
->hdcp_state
= HDCP_STATE_AUTHENTICATING
;
452 queue_work(hdmi
->workq
, &hdcp_ctrl
->hdcp_auth_work
);
455 static int msm_hdmi_hdcp_auth_prepare(struct hdmi_hdcp_ctrl
*hdcp_ctrl
)
457 struct hdmi
*hdmi
= hdcp_ctrl
->hdmi
;
463 if (!hdcp_ctrl
->aksv_valid
) {
464 rc
= msm_hdmi_hdcp_read_validate_aksv(hdcp_ctrl
);
466 pr_err("%s: ASKV validation failed\n", __func__
);
467 hdcp_ctrl
->hdcp_state
= HDCP_STATE_NO_AKSV
;
470 hdcp_ctrl
->aksv_valid
= true;
473 spin_lock_irqsave(&hdmi
->reg_lock
, flags
);
474 /* disable HDMI Encrypt */
475 reg_val
= hdmi_read(hdmi
, REG_HDMI_CTRL
);
476 reg_val
&= ~HDMI_CTRL_ENCRYPTED
;
477 hdmi_write(hdmi
, REG_HDMI_CTRL
, reg_val
);
479 /* Enabling Software DDC */
480 reg_val
= hdmi_read(hdmi
, REG_HDMI_DDC_ARBITRATION
);
481 reg_val
&= ~HDMI_DDC_ARBITRATION_HW_ARBITRATION
;
482 hdmi_write(hdmi
, REG_HDMI_DDC_ARBITRATION
, reg_val
);
483 spin_unlock_irqrestore(&hdmi
->reg_lock
, flags
);
486 * Write AKSV read from QFPROM to the HDCP registers.
487 * This step is needed for HDCP authentication and must be
488 * written before enabling HDCP.
490 hdmi_write(hdmi
, REG_HDMI_HDCP_SW_LOWER_AKSV
, hdcp_ctrl
->aksv_lsb
);
491 hdmi_write(hdmi
, REG_HDMI_HDCP_SW_UPPER_AKSV
, hdcp_ctrl
->aksv_msb
);
494 * HDCP setup prior to enabling HDCP_CTRL.
495 * Setup seed values for random number An.
497 hdmi_write(hdmi
, REG_HDMI_HDCP_ENTROPY_CTRL0
, 0xB1FFB0FF);
498 hdmi_write(hdmi
, REG_HDMI_HDCP_ENTROPY_CTRL1
, 0xF00DFACE);
500 /* Disable the RngCipher state */
501 reg_val
= hdmi_read(hdmi
, REG_HDMI_HDCP_DEBUG_CTRL
);
502 reg_val
&= ~HDMI_HDCP_DEBUG_CTRL_RNG_CIPHER
;
503 hdmi_write(hdmi
, REG_HDMI_HDCP_DEBUG_CTRL
, reg_val
);
504 DBG("HDCP_DEBUG_CTRL=0x%08x",
505 hdmi_read(hdmi
, REG_HDMI_HDCP_DEBUG_CTRL
));
508 * Ensure that all register writes are completed before
509 * enabling HDCP cipher
515 * This needs to be done as early as possible in order for the
516 * hardware to make An available to read
518 hdmi_write(hdmi
, REG_HDMI_HDCP_CTRL
, HDMI_HDCP_CTRL_ENABLE
);
521 * If we had stale values for the An ready bit, it should most
522 * likely be cleared now after enabling HDCP cipher
524 link0_status
= hdmi_read(hdmi
, REG_HDMI_HDCP_LINK0_STATUS
);
525 DBG("After enabling HDCP Link0_Status=0x%08x", link0_status
);
527 (HDMI_HDCP_LINK0_STATUS_AN_0_READY
|
528 HDMI_HDCP_LINK0_STATUS_AN_1_READY
)))
529 DBG("An not ready after enabling HDCP");
531 /* Clear any DDC failures from previous tries before enable HDCP*/
532 rc
= msm_reset_hdcp_ddc_failures(hdcp_ctrl
);
537 static void msm_hdmi_hdcp_auth_fail(struct hdmi_hdcp_ctrl
*hdcp_ctrl
)
539 struct hdmi
*hdmi
= hdcp_ctrl
->hdmi
;
543 DBG("hdcp auth failed, queue reauth work");
544 /* clear HDMI Encrypt */
545 spin_lock_irqsave(&hdmi
->reg_lock
, flags
);
546 reg_val
= hdmi_read(hdmi
, REG_HDMI_CTRL
);
547 reg_val
&= ~HDMI_CTRL_ENCRYPTED
;
548 hdmi_write(hdmi
, REG_HDMI_CTRL
, reg_val
);
549 spin_unlock_irqrestore(&hdmi
->reg_lock
, flags
);
551 hdcp_ctrl
->hdcp_state
= HDCP_STATE_AUTH_FAILED
;
552 queue_work(hdmi
->workq
, &hdcp_ctrl
->hdcp_reauth_work
);
555 static void msm_hdmi_hdcp_auth_done(struct hdmi_hdcp_ctrl
*hdcp_ctrl
)
557 struct hdmi
*hdmi
= hdcp_ctrl
->hdmi
;
562 * Disable software DDC before going into part3 to make sure
563 * there is no Arbitration between software and hardware for DDC
565 spin_lock_irqsave(&hdmi
->reg_lock
, flags
);
566 reg_val
= hdmi_read(hdmi
, REG_HDMI_DDC_ARBITRATION
);
567 reg_val
|= HDMI_DDC_ARBITRATION_HW_ARBITRATION
;
568 hdmi_write(hdmi
, REG_HDMI_DDC_ARBITRATION
, reg_val
);
569 spin_unlock_irqrestore(&hdmi
->reg_lock
, flags
);
571 /* enable HDMI Encrypt */
572 spin_lock_irqsave(&hdmi
->reg_lock
, flags
);
573 reg_val
= hdmi_read(hdmi
, REG_HDMI_CTRL
);
574 reg_val
|= HDMI_CTRL_ENCRYPTED
;
575 hdmi_write(hdmi
, REG_HDMI_CTRL
, reg_val
);
576 spin_unlock_irqrestore(&hdmi
->reg_lock
, flags
);
578 hdcp_ctrl
->hdcp_state
= HDCP_STATE_AUTHENTICATED
;
579 hdcp_ctrl
->auth_retries
= 0;
583 * hdcp authenticating part 1
585 * Read BCAPS from sink
586 * Write BCAPS and AKSV into HDCP engine
587 * Write An and AKSV to sink
588 * Read BKSV from sink and write into HDCP engine
590 static int msm_hdmi_hdcp_wait_key_an_ready(struct hdmi_hdcp_ctrl
*hdcp_ctrl
)
593 struct hdmi
*hdmi
= hdcp_ctrl
->hdmi
;
594 u32 link0_status
, keys_state
;
598 /* Wait for HDCP keys to be checked and validated */
601 link0_status
= hdmi_read(hdmi
, REG_HDMI_HDCP_LINK0_STATUS
);
602 keys_state
= (link0_status
>> 28) & 0x7;
603 if (keys_state
== HDCP_KEYS_STATE_VALID
)
606 DBG("Keys not ready(%d). s=%d, l0=%0x08x",
607 timeout_count
, keys_state
, link0_status
);
610 if (!timeout_count
) {
611 pr_err("%s: Wait key state timedout", __func__
);
615 rc
= msm_hdmi_hdcp_msleep(hdcp_ctrl
, 20, AUTH_ABORT_EV
);
622 link0_status
= hdmi_read(hdmi
, REG_HDMI_HDCP_LINK0_STATUS
);
623 an_ready
= (link0_status
& HDMI_HDCP_LINK0_STATUS_AN_0_READY
)
624 && (link0_status
& HDMI_HDCP_LINK0_STATUS_AN_1_READY
);
628 DBG("An not ready(%d). l0_status=0x%08x",
629 timeout_count
, link0_status
);
632 if (!timeout_count
) {
633 pr_err("%s: Wait An timedout", __func__
);
637 rc
= msm_hdmi_hdcp_msleep(hdcp_ctrl
, 20, AUTH_ABORT_EV
);
645 static int msm_hdmi_hdcp_send_aksv_an(struct hdmi_hdcp_ctrl
*hdcp_ctrl
)
648 struct hdmi
*hdmi
= hdcp_ctrl
->hdmi
;
649 u32 link0_aksv_0
, link0_aksv_1
;
653 /* Read An0 and An1 */
654 link0_an
[0] = hdmi_read(hdmi
, REG_HDMI_HDCP_RCVPORT_DATA5
);
655 link0_an
[1] = hdmi_read(hdmi
, REG_HDMI_HDCP_RCVPORT_DATA6
);
658 link0_aksv_0
= hdmi_read(hdmi
, REG_HDMI_HDCP_RCVPORT_DATA3
);
659 link0_aksv_1
= hdmi_read(hdmi
, REG_HDMI_HDCP_RCVPORT_DATA4
);
661 DBG("Link ASKV=%08x%08x", link0_aksv_0
, link0_aksv_1
);
662 /* Copy An and AKSV to byte arrays for transmission */
663 aksv
[0] = link0_aksv_0
& 0xFF;
664 aksv
[1] = (link0_aksv_0
>> 8) & 0xFF;
665 aksv
[2] = (link0_aksv_0
>> 16) & 0xFF;
666 aksv
[3] = (link0_aksv_0
>> 24) & 0xFF;
667 aksv
[4] = link0_aksv_1
& 0xFF;
669 /* Write An to offset 0x18 */
670 rc
= msm_hdmi_ddc_write(hdmi
, HDCP_PORT_ADDR
, 0x18, (u8
*)link0_an
,
671 (u16
)sizeof(link0_an
));
673 pr_err("%s:An write failed\n", __func__
);
676 DBG("Link0-An=%08x%08x", link0_an
[0], link0_an
[1]);
678 /* Write AKSV to offset 0x10 */
679 rc
= msm_hdmi_ddc_write(hdmi
, HDCP_PORT_ADDR
, 0x10, aksv
, 5);
681 pr_err("%s:AKSV write failed\n", __func__
);
684 DBG("Link0-AKSV=%02x%08x", link0_aksv_1
& 0xFF, link0_aksv_0
);
689 static int msm_hdmi_hdcp_recv_bksv(struct hdmi_hdcp_ctrl
*hdcp_ctrl
)
692 struct hdmi
*hdmi
= hdcp_ctrl
->hdmi
;
696 /* Read BKSV at offset 0x00 */
697 rc
= msm_hdmi_ddc_read(hdmi
, HDCP_PORT_ADDR
, 0x00, bksv
, 5);
699 pr_err("%s:BKSV read failed\n", __func__
);
703 hdcp_ctrl
->bksv_lsb
= bksv
[0] | (bksv
[1] << 8) |
704 (bksv
[2] << 16) | (bksv
[3] << 24);
705 hdcp_ctrl
->bksv_msb
= bksv
[4];
706 DBG(":BKSV=%02x%08x", hdcp_ctrl
->bksv_msb
, hdcp_ctrl
->bksv_lsb
);
708 /* check there are 20 ones in BKSV */
709 if ((hweight32(hdcp_ctrl
->bksv_lsb
) + hweight32(hdcp_ctrl
->bksv_msb
))
711 pr_err(": BKSV doesn't have 20 1's and 20 0's\n");
712 pr_err(": BKSV chk fail. BKSV=%02x%02x%02x%02x%02x\n",
713 bksv
[4], bksv
[3], bksv
[2], bksv
[1], bksv
[0]);
717 /* Write BKSV read from sink to HDCP registers */
718 reg
[0] = REG_HDMI_HDCP_RCVPORT_DATA0
;
719 data
[0] = hdcp_ctrl
->bksv_lsb
;
720 reg
[1] = REG_HDMI_HDCP_RCVPORT_DATA1
;
721 data
[1] = hdcp_ctrl
->bksv_msb
;
722 rc
= msm_hdmi_hdcp_scm_wr(hdcp_ctrl
, reg
, data
, 2);
727 static int msm_hdmi_hdcp_recv_bcaps(struct hdmi_hdcp_ctrl
*hdcp_ctrl
)
730 struct hdmi
*hdmi
= hdcp_ctrl
->hdmi
;
734 rc
= msm_hdmi_ddc_read(hdmi
, HDCP_PORT_ADDR
, 0x40, &bcaps
, 1);
736 pr_err("%s:BCAPS read failed\n", __func__
);
739 DBG("BCAPS=%02x", bcaps
);
741 /* receiver (0), repeater (1) */
742 hdcp_ctrl
->ds_type
= (bcaps
& BIT(6)) ? DS_REPEATER
: DS_RECEIVER
;
744 /* Write BCAPS to the hardware */
745 reg
= REG_HDMI_HDCP_RCVPORT_DATA12
;
747 rc
= msm_hdmi_hdcp_scm_wr(hdcp_ctrl
, ®
, &data
, 1);
752 static int msm_hdmi_hdcp_auth_part1_key_exchange(struct hdmi_hdcp_ctrl
*hdcp_ctrl
)
754 struct hdmi
*hdmi
= hdcp_ctrl
->hdmi
;
758 /* Wait for AKSV key and An ready */
759 rc
= msm_hdmi_hdcp_wait_key_an_ready(hdcp_ctrl
);
761 pr_err("%s: wait key and an ready failed\n", __func__
);
765 /* Read BCAPS and send to HDCP engine */
766 rc
= msm_hdmi_hdcp_recv_bcaps(hdcp_ctrl
);
768 pr_err("%s: read bcaps error, abort\n", __func__
);
773 * 1.1_Features turned off by default.
774 * No need to write AInfo since 1.1_Features is disabled.
776 hdmi_write(hdmi
, REG_HDMI_HDCP_RCVPORT_DATA4
, 0);
778 /* Send AKSV and An to sink */
779 rc
= msm_hdmi_hdcp_send_aksv_an(hdcp_ctrl
);
781 pr_err("%s:An/Aksv write failed\n", __func__
);
785 /* Read BKSV and send to HDCP engine*/
786 rc
= msm_hdmi_hdcp_recv_bksv(hdcp_ctrl
);
788 pr_err("%s:BKSV Process failed\n", __func__
);
792 /* Enable HDCP interrupts and ack/clear any stale interrupts */
793 spin_lock_irqsave(&hdmi
->reg_lock
, flags
);
794 hdmi_write(hdmi
, REG_HDMI_HDCP_INT_CTRL
,
795 HDMI_HDCP_INT_CTRL_AUTH_SUCCESS_ACK
|
796 HDMI_HDCP_INT_CTRL_AUTH_SUCCESS_MASK
|
797 HDMI_HDCP_INT_CTRL_AUTH_FAIL_ACK
|
798 HDMI_HDCP_INT_CTRL_AUTH_FAIL_MASK
|
799 HDMI_HDCP_INT_CTRL_AUTH_FAIL_INFO_ACK
);
800 spin_unlock_irqrestore(&hdmi
->reg_lock
, flags
);
805 /* read R0' from sink and pass it to HDCP engine */
806 static int msm_hdmi_hdcp_auth_part1_recv_r0(struct hdmi_hdcp_ctrl
*hdcp_ctrl
)
808 struct hdmi
*hdmi
= hdcp_ctrl
->hdmi
;
813 * HDCP Compliance Test case 1A-01:
814 * Wait here at least 100ms before reading R0'
816 rc
= msm_hdmi_hdcp_msleep(hdcp_ctrl
, 125, AUTH_ABORT_EV
);
820 /* Read R0' at offset 0x08 */
821 rc
= msm_hdmi_ddc_read(hdmi
, HDCP_PORT_ADDR
, 0x08, buf
, 2);
823 pr_err("%s:R0' read failed\n", __func__
);
826 DBG("R0'=%02x%02x", buf
[1], buf
[0]);
828 /* Write R0' to HDCP registers and check to see if it is a match */
829 hdmi_write(hdmi
, REG_HDMI_HDCP_RCVPORT_DATA2_0
,
830 (((u32
)buf
[1]) << 8) | buf
[0]);
835 /* Wait for authenticating result: R0/R0' are matched or not */
836 static int msm_hdmi_hdcp_auth_part1_verify_r0(struct hdmi_hdcp_ctrl
*hdcp_ctrl
)
838 struct hdmi
*hdmi
= hdcp_ctrl
->hdmi
;
842 /* wait for hdcp irq, 10 sec should be long enough */
843 rc
= msm_hdmi_hdcp_msleep(hdcp_ctrl
, 10000, AUTH_RESULT_RDY_EV
);
845 pr_err("%s: Wait Auth IRQ timeout\n", __func__
);
849 link0_status
= hdmi_read(hdmi
, REG_HDMI_HDCP_LINK0_STATUS
);
850 if (!(link0_status
& HDMI_HDCP_LINK0_STATUS_RI_MATCHES
)) {
851 pr_err("%s: Authentication Part I failed\n", __func__
);
855 /* Enable HDCP Encryption */
856 hdmi_write(hdmi
, REG_HDMI_HDCP_CTRL
,
857 HDMI_HDCP_CTRL_ENABLE
|
858 HDMI_HDCP_CTRL_ENCRYPTION_ENABLE
);
863 static int msm_hdmi_hdcp_recv_check_bstatus(struct hdmi_hdcp_ctrl
*hdcp_ctrl
,
867 struct hdmi
*hdmi
= hdcp_ctrl
->hdmi
;
868 bool max_devs_exceeded
= false, max_cascade_exceeded
= false;
869 u32 repeater_cascade_depth
= 0, down_stream_devices
= 0;
873 /* Read BSTATUS at offset 0x41 */
874 rc
= msm_hdmi_ddc_read(hdmi
, HDCP_PORT_ADDR
, 0x41, buf
, 2);
876 pr_err("%s: BSTATUS read failed\n", __func__
);
879 *pbstatus
= bstatus
= (buf
[1] << 8) | buf
[0];
882 down_stream_devices
= bstatus
& 0x7F;
883 repeater_cascade_depth
= (bstatus
>> 8) & 0x7;
884 max_devs_exceeded
= (bstatus
& BIT(7)) ? true : false;
885 max_cascade_exceeded
= (bstatus
& BIT(11)) ? true : false;
887 if (down_stream_devices
== 0) {
889 * If no downstream devices are attached to the repeater
890 * then part II fails.
891 * todo: The other approach would be to continue PART II.
893 pr_err("%s: No downstream devices\n", __func__
);
899 * HDCP Compliance 1B-05:
900 * Check if no. of devices connected to repeater
901 * exceed max_devices_connected from bit 7 of Bstatus.
903 if (max_devs_exceeded
) {
904 pr_err("%s: no. of devs connected exceeds max allowed",
911 * HDCP Compliance 1B-06:
912 * Check if no. of cascade connected to repeater
913 * exceed max_cascade_connected from bit 11 of Bstatus.
915 if (max_cascade_exceeded
) {
916 pr_err("%s: no. of cascade conn exceeds max allowed",
923 hdcp_ctrl
->dev_count
= down_stream_devices
;
924 hdcp_ctrl
->max_cascade_exceeded
= max_cascade_exceeded
;
925 hdcp_ctrl
->max_dev_exceeded
= max_devs_exceeded
;
926 hdcp_ctrl
->depth
= repeater_cascade_depth
;
930 static int msm_hdmi_hdcp_auth_part2_wait_ksv_fifo_ready(
931 struct hdmi_hdcp_ctrl
*hdcp_ctrl
)
934 struct hdmi
*hdmi
= hdcp_ctrl
->hdmi
;
941 * Wait until READY bit is set in BCAPS, as per HDCP specifications
942 * maximum permitted time to check for READY bit is five seconds.
946 /* Read BCAPS at offset 0x40 */
947 rc
= msm_hdmi_ddc_read(hdmi
, HDCP_PORT_ADDR
, 0x40, &bcaps
, 1);
949 pr_err("%s: BCAPS read failed\n", __func__
);
957 if (!timeout_count
) {
958 pr_err("%s: Wait KSV fifo ready timedout", __func__
);
962 rc
= msm_hdmi_hdcp_msleep(hdcp_ctrl
, 20, AUTH_ABORT_EV
);
967 rc
= msm_hdmi_hdcp_recv_check_bstatus(hdcp_ctrl
, &bstatus
);
969 pr_err("%s: bstatus error\n", __func__
);
973 /* Write BSTATUS and BCAPS to HDCP registers */
974 reg
= REG_HDMI_HDCP_RCVPORT_DATA12
;
975 data
= bcaps
| (bstatus
<< 8);
976 rc
= msm_hdmi_hdcp_scm_wr(hdcp_ctrl
, ®
, &data
, 1);
978 pr_err("%s: BSTATUS write failed\n", __func__
);
986 * hdcp authenticating part 2: 2nd
987 * read ksv fifo from sink
988 * transfer V' from sink to HDCP engine
991 static int msm_hdmi_hdcp_transfer_v_h(struct hdmi_hdcp_ctrl
*hdcp_ctrl
)
993 struct hdmi
*hdmi
= hdcp_ctrl
->hdmi
;
995 struct hdmi_hdcp_reg_data reg_data
[] = {
996 {REG_HDMI_HDCP_RCVPORT_DATA7
, 0x20, "V' H0"},
997 {REG_HDMI_HDCP_RCVPORT_DATA8
, 0x24, "V' H1"},
998 {REG_HDMI_HDCP_RCVPORT_DATA9
, 0x28, "V' H2"},
999 {REG_HDMI_HDCP_RCVPORT_DATA10
, 0x2C, "V' H3"},
1000 {REG_HDMI_HDCP_RCVPORT_DATA11
, 0x30, "V' H4"},
1002 struct hdmi_hdcp_reg_data
*rd
;
1003 u32 size
= ARRAY_SIZE(reg_data
);
1004 u32 reg
[ARRAY_SIZE(reg_data
)];
1005 u32 data
[ARRAY_SIZE(reg_data
)];
1008 for (i
= 0; i
< size
; i
++) {
1010 rc
= msm_hdmi_ddc_read(hdmi
, HDCP_PORT_ADDR
,
1011 rd
->off
, (u8
*)&data
[i
], (u16
)sizeof(data
[i
]));
1013 pr_err("%s: Read %s failed\n", __func__
, rd
->name
);
1017 DBG("%s =%x", rd
->name
, data
[i
]);
1018 reg
[i
] = reg_data
[i
].reg_id
;
1021 rc
= msm_hdmi_hdcp_scm_wr(hdcp_ctrl
, reg
, data
, size
);
1027 static int msm_hdmi_hdcp_recv_ksv_fifo(struct hdmi_hdcp_ctrl
*hdcp_ctrl
)
1030 struct hdmi
*hdmi
= hdcp_ctrl
->hdmi
;
1033 ksv_bytes
= 5 * hdcp_ctrl
->dev_count
;
1035 rc
= msm_hdmi_ddc_read(hdmi
, HDCP_PORT_ADDR
, 0x43,
1036 hdcp_ctrl
->ksv_list
, ksv_bytes
);
1038 pr_err("%s: KSV FIFO read failed\n", __func__
);
1043 static int msm_hdmi_hdcp_reset_sha_engine(struct hdmi_hdcp_ctrl
*hdcp_ctrl
)
1045 u32 reg
[2], data
[2];
1048 reg
[0] = REG_HDMI_HDCP_SHA_CTRL
;
1049 data
[0] = HDCP_REG_ENABLE
;
1050 reg
[1] = REG_HDMI_HDCP_SHA_CTRL
;
1051 data
[1] = HDCP_REG_DISABLE
;
1053 rc
= msm_hdmi_hdcp_scm_wr(hdcp_ctrl
, reg
, data
, 2);
1058 static int msm_hdmi_hdcp_auth_part2_recv_ksv_fifo(
1059 struct hdmi_hdcp_ctrl
*hdcp_ctrl
)
1065 * Read KSV FIFO over DDC
1066 * Key Selection vector FIFO Used to pull downstream KSVs
1067 * from HDCP Repeaters.
1068 * All bytes (DEVICE_COUNT * 5) must be read in a single,
1069 * auto incrementing access.
1070 * All bytes read as 0x00 for HDCP Receivers that are not
1071 * HDCP Repeaters (REPEATER == 0).
1073 timeout_count
= 100;
1075 rc
= msm_hdmi_hdcp_recv_ksv_fifo(hdcp_ctrl
);
1080 if (!timeout_count
) {
1081 pr_err("%s: Recv ksv fifo timedout", __func__
);
1085 rc
= msm_hdmi_hdcp_msleep(hdcp_ctrl
, 25, AUTH_ABORT_EV
);
1090 rc
= msm_hdmi_hdcp_transfer_v_h(hdcp_ctrl
);
1092 pr_err("%s: transfer V failed\n", __func__
);
1096 /* reset SHA engine before write ksv fifo */
1097 rc
= msm_hdmi_hdcp_reset_sha_engine(hdcp_ctrl
);
1099 pr_err("%s: fail to reset sha engine\n", __func__
);
1107 * Write KSV FIFO to HDCP_SHA_DATA.
1108 * This is done 1 byte at time starting with the LSB.
1109 * Once 64 bytes have been written, we need to poll for
1110 * HDCP_SHA_BLOCK_DONE before writing any further
1111 * If the last byte is written, we need to poll for
1112 * HDCP_SHA_COMP_DONE to wait until HW finish
1114 static int msm_hdmi_hdcp_write_ksv_fifo(struct hdmi_hdcp_ctrl
*hdcp_ctrl
)
1117 struct hdmi
*hdmi
= hdcp_ctrl
->hdmi
;
1118 u32 ksv_bytes
, last_byte
= 0;
1119 u8
*ksv_fifo
= NULL
;
1120 u32 reg_val
, data
, reg
;
1123 ksv_bytes
= 5 * hdcp_ctrl
->dev_count
;
1125 /* Check if need to wait for HW completion */
1126 if (hdcp_ctrl
->ksv_fifo_w_index
) {
1127 reg_val
= hdmi_read(hdmi
, REG_HDMI_HDCP_SHA_STATUS
);
1128 DBG("HDCP_SHA_STATUS=%08x", reg_val
);
1129 if (hdcp_ctrl
->ksv_fifo_w_index
== ksv_bytes
) {
1130 /* check COMP_DONE if last write */
1131 if (reg_val
& HDMI_HDCP_SHA_STATUS_COMP_DONE
) {
1138 /* check BLOCK_DONE if not last write */
1139 if (!(reg_val
& HDMI_HDCP_SHA_STATUS_BLOCK_DONE
))
1146 ksv_bytes
-= hdcp_ctrl
->ksv_fifo_w_index
;
1147 if (ksv_bytes
<= 64)
1152 ksv_fifo
= hdcp_ctrl
->ksv_list
;
1153 ksv_fifo
+= hdcp_ctrl
->ksv_fifo_w_index
;
1155 for (i
= 0; i
< ksv_bytes
; i
++) {
1156 /* Write KSV byte and set DONE bit[0] for last byte*/
1157 reg_val
= ksv_fifo
[i
] << 16;
1158 if ((i
== (ksv_bytes
- 1)) && last_byte
)
1159 reg_val
|= HDMI_HDCP_SHA_DATA_DONE
;
1161 reg
= REG_HDMI_HDCP_SHA_DATA
;
1163 rc
= msm_hdmi_hdcp_scm_wr(hdcp_ctrl
, ®
, &data
, 1);
1169 hdcp_ctrl
->ksv_fifo_w_index
+= ksv_bytes
;
1172 *return -EAGAIN to notify caller to wait for COMP_DONE or BLOCK_DONE
1177 /* write ksv fifo into HDCP engine */
1178 static int msm_hdmi_hdcp_auth_part2_write_ksv_fifo(
1179 struct hdmi_hdcp_ctrl
*hdcp_ctrl
)
1184 hdcp_ctrl
->ksv_fifo_w_index
= 0;
1185 timeout_count
= 100;
1187 rc
= msm_hdmi_hdcp_write_ksv_fifo(hdcp_ctrl
);
1195 if (!timeout_count
) {
1196 pr_err("%s: Write KSV fifo timedout", __func__
);
1200 rc
= msm_hdmi_hdcp_msleep(hdcp_ctrl
, 20, AUTH_ABORT_EV
);
1208 static int msm_hdmi_hdcp_auth_part2_check_v_match(struct hdmi_hdcp_ctrl
*hdcp_ctrl
)
1211 struct hdmi
*hdmi
= hdcp_ctrl
->hdmi
;
1213 u32 timeout_count
= 100;
1216 link0_status
= hdmi_read(hdmi
, REG_HDMI_HDCP_LINK0_STATUS
);
1217 if (link0_status
& HDMI_HDCP_LINK0_STATUS_V_MATCHES
)
1221 if (!timeout_count
) {
1222 pr_err("%s: HDCP V Match timedout", __func__
);
1226 rc
= msm_hdmi_hdcp_msleep(hdcp_ctrl
, 20, AUTH_ABORT_EV
);
1234 static void msm_hdmi_hdcp_auth_work(struct work_struct
*work
)
1236 struct hdmi_hdcp_ctrl
*hdcp_ctrl
= container_of(work
,
1237 struct hdmi_hdcp_ctrl
, hdcp_auth_work
);
1240 rc
= msm_hdmi_hdcp_auth_prepare(hdcp_ctrl
);
1242 pr_err("%s: auth prepare failed %d\n", __func__
, rc
);
1247 rc
= msm_hdmi_hdcp_auth_part1_key_exchange(hdcp_ctrl
);
1249 pr_err("%s: key exchange failed %d\n", __func__
, rc
);
1253 rc
= msm_hdmi_hdcp_auth_part1_recv_r0(hdcp_ctrl
);
1255 pr_err("%s: receive r0 failed %d\n", __func__
, rc
);
1259 rc
= msm_hdmi_hdcp_auth_part1_verify_r0(hdcp_ctrl
);
1261 pr_err("%s: verify r0 failed %d\n", __func__
, rc
);
1264 pr_info("%s: Authentication Part I successful\n", __func__
);
1265 if (hdcp_ctrl
->ds_type
== DS_RECEIVER
)
1269 rc
= msm_hdmi_hdcp_auth_part2_wait_ksv_fifo_ready(hdcp_ctrl
);
1271 pr_err("%s: wait ksv fifo ready failed %d\n", __func__
, rc
);
1275 rc
= msm_hdmi_hdcp_auth_part2_recv_ksv_fifo(hdcp_ctrl
);
1277 pr_err("%s: recv ksv fifo failed %d\n", __func__
, rc
);
1281 rc
= msm_hdmi_hdcp_auth_part2_write_ksv_fifo(hdcp_ctrl
);
1283 pr_err("%s: write ksv fifo failed %d\n", __func__
, rc
);
1287 rc
= msm_hdmi_hdcp_auth_part2_check_v_match(hdcp_ctrl
);
1289 pr_err("%s: check v match failed %d\n", __func__
, rc
);
1292 if (rc
== -ECANCELED
) {
1293 pr_info("%s: hdcp authentication canceled\n", __func__
);
1294 } else if (rc
== -ENOTSUPP
) {
1295 pr_info("%s: hdcp is not supported\n", __func__
);
1297 pr_err("%s: hdcp authentication failed\n", __func__
);
1298 msm_hdmi_hdcp_auth_fail(hdcp_ctrl
);
1300 msm_hdmi_hdcp_auth_done(hdcp_ctrl
);
1304 void msm_hdmi_hdcp_on(struct hdmi_hdcp_ctrl
*hdcp_ctrl
)
1306 struct hdmi
*hdmi
= hdcp_ctrl
->hdmi
;
1308 unsigned long flags
;
1310 if ((HDCP_STATE_INACTIVE
!= hdcp_ctrl
->hdcp_state
) ||
1311 (HDCP_STATE_NO_AKSV
== hdcp_ctrl
->hdcp_state
)) {
1312 DBG("still active or activating or no askv. returning");
1316 /* clear HDMI Encrypt */
1317 spin_lock_irqsave(&hdmi
->reg_lock
, flags
);
1318 reg_val
= hdmi_read(hdmi
, REG_HDMI_CTRL
);
1319 reg_val
&= ~HDMI_CTRL_ENCRYPTED
;
1320 hdmi_write(hdmi
, REG_HDMI_CTRL
, reg_val
);
1321 spin_unlock_irqrestore(&hdmi
->reg_lock
, flags
);
1323 hdcp_ctrl
->auth_event
= 0;
1324 hdcp_ctrl
->hdcp_state
= HDCP_STATE_AUTHENTICATING
;
1325 hdcp_ctrl
->auth_retries
= 0;
1326 queue_work(hdmi
->workq
, &hdcp_ctrl
->hdcp_auth_work
);
1329 void msm_hdmi_hdcp_off(struct hdmi_hdcp_ctrl
*hdcp_ctrl
)
1331 struct hdmi
*hdmi
= hdcp_ctrl
->hdmi
;
1332 unsigned long flags
;
1335 if ((HDCP_STATE_INACTIVE
== hdcp_ctrl
->hdcp_state
) ||
1336 (HDCP_STATE_NO_AKSV
== hdcp_ctrl
->hdcp_state
)) {
1337 DBG("hdcp inactive or no aksv. returning");
1342 * Disable HPD circuitry.
1343 * This is needed to reset the HDCP cipher engine so that when we
1344 * attempt a re-authentication, HW would clear the AN0_READY and
1345 * AN1_READY bits in HDMI_HDCP_LINK0_STATUS register
1347 spin_lock_irqsave(&hdmi
->reg_lock
, flags
);
1348 reg_val
= hdmi_read(hdmi
, REG_HDMI_HPD_CTRL
);
1349 reg_val
&= ~HDMI_HPD_CTRL_ENABLE
;
1350 hdmi_write(hdmi
, REG_HDMI_HPD_CTRL
, reg_val
);
1353 * Disable HDCP interrupts.
1354 * Also, need to set the state to inactive here so that any ongoing
1355 * reauth works will know that the HDCP session has been turned off.
1357 hdmi_write(hdmi
, REG_HDMI_HDCP_INT_CTRL
, 0);
1358 spin_unlock_irqrestore(&hdmi
->reg_lock
, flags
);
1361 * Cancel any pending auth/reauth attempts.
1362 * If one is ongoing, this will wait for it to finish.
1363 * No more reauthentication attempts will be scheduled since we
1364 * set the current state to inactive.
1366 set_bit(AUTH_ABORT_EV
, &hdcp_ctrl
->auth_event
);
1367 wake_up_all(&hdcp_ctrl
->auth_event_queue
);
1368 cancel_work_sync(&hdcp_ctrl
->hdcp_auth_work
);
1369 cancel_work_sync(&hdcp_ctrl
->hdcp_reauth_work
);
1371 hdmi_write(hdmi
, REG_HDMI_HDCP_RESET
,
1372 HDMI_HDCP_RESET_LINK0_DEAUTHENTICATE
);
1374 /* Disable encryption and disable the HDCP block */
1375 hdmi_write(hdmi
, REG_HDMI_HDCP_CTRL
, 0);
1377 spin_lock_irqsave(&hdmi
->reg_lock
, flags
);
1378 reg_val
= hdmi_read(hdmi
, REG_HDMI_CTRL
);
1379 reg_val
&= ~HDMI_CTRL_ENCRYPTED
;
1380 hdmi_write(hdmi
, REG_HDMI_CTRL
, reg_val
);
1382 /* Enable HPD circuitry */
1383 reg_val
= hdmi_read(hdmi
, REG_HDMI_HPD_CTRL
);
1384 reg_val
|= HDMI_HPD_CTRL_ENABLE
;
1385 hdmi_write(hdmi
, REG_HDMI_HPD_CTRL
, reg_val
);
1386 spin_unlock_irqrestore(&hdmi
->reg_lock
, flags
);
1388 hdcp_ctrl
->hdcp_state
= HDCP_STATE_INACTIVE
;
1393 struct hdmi_hdcp_ctrl
*msm_hdmi_hdcp_init(struct hdmi
*hdmi
)
1395 struct hdmi_hdcp_ctrl
*hdcp_ctrl
= NULL
;
1397 if (!hdmi
->qfprom_mmio
) {
1398 pr_err("%s: HDCP is not supported without qfprom\n",
1400 return ERR_PTR(-EINVAL
);
1403 hdcp_ctrl
= kzalloc(sizeof(*hdcp_ctrl
), GFP_KERNEL
);
1405 return ERR_PTR(-ENOMEM
);
1407 INIT_WORK(&hdcp_ctrl
->hdcp_auth_work
, msm_hdmi_hdcp_auth_work
);
1408 INIT_WORK(&hdcp_ctrl
->hdcp_reauth_work
, msm_hdmi_hdcp_reauth_work
);
1409 init_waitqueue_head(&hdcp_ctrl
->auth_event_queue
);
1410 hdcp_ctrl
->hdmi
= hdmi
;
1411 hdcp_ctrl
->hdcp_state
= HDCP_STATE_INACTIVE
;
1412 hdcp_ctrl
->aksv_valid
= false;
1414 if (qcom_scm_hdcp_available())
1415 hdcp_ctrl
->tz_hdcp
= true;
1417 hdcp_ctrl
->tz_hdcp
= false;
1422 void msm_hdmi_hdcp_destroy(struct hdmi
*hdmi
)
1425 kfree(hdmi
->hdcp_ctrl
);
1426 hdmi
->hdcp_ctrl
= NULL
;