18444b75fSSumit Garg // SPDX-License-Identifier: BSD-2-Clause
28444b75fSSumit Garg /*
38444b75fSSumit Garg * Copyright (c) 2025, Linaro Ltd
48444b75fSSumit Garg * Copyright (c) 2026, Qualcomm Technologies, Inc. and/or its subsidiaries.
58444b75fSSumit Garg */
68444b75fSSumit Garg
78444b75fSSumit Garg #include <drivers/clk.h>
88444b75fSSumit Garg #include <drivers/clk_qcom.h>
98444b75fSSumit Garg #include <io.h>
104be57ec2SJorge Ramirez-Ortiz #include <mm/core_mmu.h>
118444b75fSSumit Garg
124be57ec2SJorge Ramirez-Ortiz register_phys_mem(MEM_AREA_IO_NSEC, GCC_BASE, GCC_SIZE);
138444b75fSSumit Garg
14*ed9b177eSJorge Ramirez-Ortiz #define CBCR_BRANCH_ENABLE_BIT BIT(0)
15*ed9b177eSJorge Ramirez-Ortiz #define CBCR_HW_CTL_ENABLE_BIT BIT(1)
16*ed9b177eSJorge Ramirez-Ortiz #define CBCR_BRANCH_OFF_BIT BIT(31)
17594035b1SJorge Ramirez-Ortiz
cbcr_branch_on(uint32_t val)18594035b1SJorge Ramirez-Ortiz static inline bool cbcr_branch_on(uint32_t val)
198444b75fSSumit Garg {
20594035b1SJorge Ramirez-Ortiz return !(val & CBCR_BRANCH_OFF_BIT);
21594035b1SJorge Ramirez-Ortiz }
228444b75fSSumit Garg
qcom_clock_enable_cbc(vaddr_t cbcr)23*ed9b177eSJorge Ramirez-Ortiz TEE_Result qcom_clock_enable_cbc(vaddr_t cbcr)
24594035b1SJorge Ramirez-Ortiz {
25594035b1SJorge Ramirez-Ortiz int ret = 0;
268444b75fSSumit Garg
27594035b1SJorge Ramirez-Ortiz io_setbits32(cbcr, CBCR_BRANCH_ENABLE_BIT);
28594035b1SJorge Ramirez-Ortiz
29594035b1SJorge Ramirez-Ortiz REG_POLL_TIMEOUT(cbcr, 10 * 1000, 10, &ret, cbcr_branch_on);
30594035b1SJorge Ramirez-Ortiz
31*ed9b177eSJorge Ramirez-Ortiz if (ret < 0)
32*ed9b177eSJorge Ramirez-Ortiz return TEE_ERROR_TIMEOUT;
33594035b1SJorge Ramirez-Ortiz
34*ed9b177eSJorge Ramirez-Ortiz return TEE_SUCCESS;
353fff682dSJorge Ramirez-Ortiz }
363fff682dSJorge Ramirez-Ortiz
qcom_clock_enable(enum qcom_clk_group group)378444b75fSSumit Garg TEE_Result qcom_clock_enable(enum qcom_clk_group group)
388444b75fSSumit Garg {
398444b75fSSumit Garg switch (group) {
40594035b1SJorge Ramirez-Ortiz case QCOM_CLKS_TURING:
413fff682dSJorge Ramirez-Ortiz case QCOM_CLKS_LPASS:
42*ed9b177eSJorge Ramirez-Ortiz case QCOM_CLKS_WPSS:
43*ed9b177eSJorge Ramirez-Ortiz return qcom_clock_enable_pas(group);
448444b75fSSumit Garg default:
458444b75fSSumit Garg EMSG("Unsupported clock group %d\n", group);
468444b75fSSumit Garg return TEE_ERROR_BAD_PARAMETERS;
478444b75fSSumit Garg }
488444b75fSSumit Garg
498444b75fSSumit Garg return TEE_SUCCESS;
508444b75fSSumit Garg }
51