16cdef273SGovind Singh // SPDX-License-Identifier: GPL-2.0
26cdef273SGovind Singh /*
36cdef273SGovind Singh * Copyright (c) 2018, The Linux Foundation. All rights reserved.
46cdef273SGovind Singh */
56cdef273SGovind Singh
66cdef273SGovind Singh #include <linux/bitops.h>
7737a2267SVinod Koul #include <linux/clk-provider.h>
86cdef273SGovind Singh #include <linux/err.h>
96cdef273SGovind Singh #include <linux/module.h>
106cdef273SGovind Singh #include <linux/platform_device.h>
116cdef273SGovind Singh #include <linux/pm_clock.h>
126cdef273SGovind Singh #include <linux/pm_runtime.h>
136cdef273SGovind Singh #include <linux/regmap.h>
146cdef273SGovind Singh
156cdef273SGovind Singh #include <dt-bindings/clock/qcom,q6sstopcc-qcs404.h>
166cdef273SGovind Singh
176cdef273SGovind Singh #include "clk-regmap.h"
186cdef273SGovind Singh #include "clk-branch.h"
196cdef273SGovind Singh #include "common.h"
206cdef273SGovind Singh #include "reset.h"
216cdef273SGovind Singh
226cdef273SGovind Singh static struct clk_branch lcc_ahbfabric_cbc_clk = {
236cdef273SGovind Singh .halt_reg = 0x1b004,
246cdef273SGovind Singh .halt_check = BRANCH_HALT,
256cdef273SGovind Singh .clkr = {
266cdef273SGovind Singh .enable_reg = 0x1b004,
276cdef273SGovind Singh .enable_mask = BIT(0),
286cdef273SGovind Singh .hw.init = &(struct clk_init_data){
296cdef273SGovind Singh .name = "lcc_ahbfabric_cbc_clk",
306cdef273SGovind Singh .ops = &clk_branch2_ops,
316cdef273SGovind Singh },
326cdef273SGovind Singh },
336cdef273SGovind Singh };
346cdef273SGovind Singh
356cdef273SGovind Singh static struct clk_branch lcc_q6ss_ahbs_cbc_clk = {
366cdef273SGovind Singh .halt_reg = 0x22000,
376cdef273SGovind Singh .halt_check = BRANCH_VOTED,
386cdef273SGovind Singh .clkr = {
396cdef273SGovind Singh .enable_reg = 0x22000,
406cdef273SGovind Singh .enable_mask = BIT(0),
416cdef273SGovind Singh .hw.init = &(struct clk_init_data){
426cdef273SGovind Singh .name = "lcc_q6ss_ahbs_cbc_clk",
436cdef273SGovind Singh .ops = &clk_branch2_ops,
446cdef273SGovind Singh },
456cdef273SGovind Singh },
466cdef273SGovind Singh };
476cdef273SGovind Singh
486cdef273SGovind Singh static struct clk_branch lcc_q6ss_tcm_slave_cbc_clk = {
496cdef273SGovind Singh .halt_reg = 0x1c000,
506cdef273SGovind Singh .halt_check = BRANCH_VOTED,
516cdef273SGovind Singh .clkr = {
526cdef273SGovind Singh .enable_reg = 0x1c000,
536cdef273SGovind Singh .enable_mask = BIT(0),
546cdef273SGovind Singh .hw.init = &(struct clk_init_data){
556cdef273SGovind Singh .name = "lcc_q6ss_tcm_slave_cbc_clk",
566cdef273SGovind Singh .ops = &clk_branch2_ops,
576cdef273SGovind Singh },
586cdef273SGovind Singh },
596cdef273SGovind Singh };
606cdef273SGovind Singh
616cdef273SGovind Singh static struct clk_branch lcc_q6ss_ahbm_cbc_clk = {
626cdef273SGovind Singh .halt_reg = 0x22004,
636cdef273SGovind Singh .halt_check = BRANCH_VOTED,
646cdef273SGovind Singh .clkr = {
656cdef273SGovind Singh .enable_reg = 0x22004,
666cdef273SGovind Singh .enable_mask = BIT(0),
676cdef273SGovind Singh .hw.init = &(struct clk_init_data){
686cdef273SGovind Singh .name = "lcc_q6ss_ahbm_cbc_clk",
696cdef273SGovind Singh .ops = &clk_branch2_ops,
706cdef273SGovind Singh },
716cdef273SGovind Singh },
726cdef273SGovind Singh };
736cdef273SGovind Singh
746cdef273SGovind Singh static struct clk_branch lcc_q6ss_axim_cbc_clk = {
756cdef273SGovind Singh .halt_reg = 0x1c004,
766cdef273SGovind Singh .halt_check = BRANCH_VOTED,
776cdef273SGovind Singh .clkr = {
786cdef273SGovind Singh .enable_reg = 0x1c004,
796cdef273SGovind Singh .enable_mask = BIT(0),
806cdef273SGovind Singh .hw.init = &(struct clk_init_data){
816cdef273SGovind Singh .name = "lcc_q6ss_axim_cbc_clk",
826cdef273SGovind Singh .ops = &clk_branch2_ops,
836cdef273SGovind Singh },
846cdef273SGovind Singh },
856cdef273SGovind Singh };
866cdef273SGovind Singh
876cdef273SGovind Singh static struct clk_branch lcc_q6ss_bcr_sleep_clk = {
886cdef273SGovind Singh .halt_reg = 0x6004,
896cdef273SGovind Singh .halt_check = BRANCH_VOTED,
906cdef273SGovind Singh .clkr = {
916cdef273SGovind Singh .enable_reg = 0x6004,
926cdef273SGovind Singh .enable_mask = BIT(0),
936cdef273SGovind Singh .hw.init = &(struct clk_init_data){
946cdef273SGovind Singh .name = "lcc_q6ss_bcr_sleep_clk",
956cdef273SGovind Singh .ops = &clk_branch2_ops,
966cdef273SGovind Singh },
976cdef273SGovind Singh },
986cdef273SGovind Singh };
996cdef273SGovind Singh
1006cdef273SGovind Singh /* TCSR clock */
1016cdef273SGovind Singh static struct clk_branch tcsr_lcc_csr_cbcr_clk = {
1026cdef273SGovind Singh .halt_reg = 0x8008,
1036cdef273SGovind Singh .halt_check = BRANCH_VOTED,
1046cdef273SGovind Singh .clkr = {
1056cdef273SGovind Singh .enable_reg = 0x8008,
1066cdef273SGovind Singh .enable_mask = BIT(0),
1076cdef273SGovind Singh .hw.init = &(struct clk_init_data){
1086cdef273SGovind Singh .name = "tcsr_lcc_csr_cbcr_clk",
1096cdef273SGovind Singh .ops = &clk_branch2_ops,
1106cdef273SGovind Singh },
1116cdef273SGovind Singh },
1126cdef273SGovind Singh };
1136cdef273SGovind Singh
1146cdef273SGovind Singh static struct regmap_config q6sstop_regmap_config = {
1156cdef273SGovind Singh .reg_bits = 32,
1166cdef273SGovind Singh .reg_stride = 4,
1176cdef273SGovind Singh .val_bits = 32,
1186cdef273SGovind Singh .fast_io = true,
1196cdef273SGovind Singh };
1206cdef273SGovind Singh
1216cdef273SGovind Singh static struct clk_regmap *q6sstop_qcs404_clocks[] = {
1226cdef273SGovind Singh [LCC_AHBFABRIC_CBC_CLK] = &lcc_ahbfabric_cbc_clk.clkr,
1236cdef273SGovind Singh [LCC_Q6SS_AHBS_CBC_CLK] = &lcc_q6ss_ahbs_cbc_clk.clkr,
1246cdef273SGovind Singh [LCC_Q6SS_TCM_SLAVE_CBC_CLK] = &lcc_q6ss_tcm_slave_cbc_clk.clkr,
1256cdef273SGovind Singh [LCC_Q6SS_AHBM_CBC_CLK] = &lcc_q6ss_ahbm_cbc_clk.clkr,
1266cdef273SGovind Singh [LCC_Q6SS_AXIM_CBC_CLK] = &lcc_q6ss_axim_cbc_clk.clkr,
1276cdef273SGovind Singh [LCC_Q6SS_BCR_SLEEP_CLK] = &lcc_q6ss_bcr_sleep_clk.clkr,
1286cdef273SGovind Singh };
1296cdef273SGovind Singh
1306cdef273SGovind Singh static const struct qcom_reset_map q6sstop_qcs404_resets[] = {
1316cdef273SGovind Singh [Q6SSTOP_BCR_RESET] = { 0x6000 },
1326cdef273SGovind Singh };
1336cdef273SGovind Singh
1346cdef273SGovind Singh static const struct qcom_cc_desc q6sstop_qcs404_desc = {
1356cdef273SGovind Singh .config = &q6sstop_regmap_config,
1366cdef273SGovind Singh .clks = q6sstop_qcs404_clocks,
1376cdef273SGovind Singh .num_clks = ARRAY_SIZE(q6sstop_qcs404_clocks),
1386cdef273SGovind Singh .resets = q6sstop_qcs404_resets,
1396cdef273SGovind Singh .num_resets = ARRAY_SIZE(q6sstop_qcs404_resets),
1406cdef273SGovind Singh };
1416cdef273SGovind Singh
1426cdef273SGovind Singh static struct clk_regmap *tcsr_qcs404_clocks[] = {
1436cdef273SGovind Singh [TCSR_Q6SS_LCC_CBCR_CLK] = &tcsr_lcc_csr_cbcr_clk.clkr,
1446cdef273SGovind Singh };
1456cdef273SGovind Singh
1466cdef273SGovind Singh static const struct qcom_cc_desc tcsr_qcs404_desc = {
1476cdef273SGovind Singh .config = &q6sstop_regmap_config,
1486cdef273SGovind Singh .clks = tcsr_qcs404_clocks,
1496cdef273SGovind Singh .num_clks = ARRAY_SIZE(tcsr_qcs404_clocks),
1506cdef273SGovind Singh };
1516cdef273SGovind Singh
1526cdef273SGovind Singh static const struct of_device_id q6sstopcc_qcs404_match_table[] = {
1536cdef273SGovind Singh { .compatible = "qcom,qcs404-q6sstopcc" },
1546cdef273SGovind Singh { }
1556cdef273SGovind Singh };
1566cdef273SGovind Singh MODULE_DEVICE_TABLE(of, q6sstopcc_qcs404_match_table);
1576cdef273SGovind Singh
q6sstopcc_qcs404_probe(struct platform_device * pdev)1586cdef273SGovind Singh static int q6sstopcc_qcs404_probe(struct platform_device *pdev)
1596cdef273SGovind Singh {
1606cdef273SGovind Singh const struct qcom_cc_desc *desc;
1616cdef273SGovind Singh int ret;
1626cdef273SGovind Singh
16372cfc73fSDmitry Baryshkov ret = devm_pm_runtime_enable(&pdev->dev);
1646cdef273SGovind Singh if (ret)
16572cfc73fSDmitry Baryshkov return ret;
16672cfc73fSDmitry Baryshkov
16772cfc73fSDmitry Baryshkov ret = devm_pm_clk_create(&pdev->dev);
16872cfc73fSDmitry Baryshkov if (ret)
16972cfc73fSDmitry Baryshkov return ret;
1706cdef273SGovind Singh
1716cdef273SGovind Singh ret = pm_clk_add(&pdev->dev, NULL);
1726cdef273SGovind Singh if (ret < 0) {
1736cdef273SGovind Singh dev_err(&pdev->dev, "failed to acquire iface clock\n");
17472cfc73fSDmitry Baryshkov return ret;
1756cdef273SGovind Singh }
1766cdef273SGovind Singh
177*97112c83SJohan Hovold ret = pm_runtime_resume_and_get(&pdev->dev);
178*97112c83SJohan Hovold if (ret)
179*97112c83SJohan Hovold return ret;
180*97112c83SJohan Hovold
1816cdef273SGovind Singh q6sstop_regmap_config.name = "q6sstop_tcsr";
1826cdef273SGovind Singh desc = &tcsr_qcs404_desc;
1836cdef273SGovind Singh
1846cdef273SGovind Singh ret = qcom_cc_probe_by_index(pdev, 1, desc);
1856cdef273SGovind Singh if (ret)
186*97112c83SJohan Hovold goto err_put_rpm;
1876cdef273SGovind Singh
1886cdef273SGovind Singh q6sstop_regmap_config.name = "q6sstop_cc";
1896cdef273SGovind Singh desc = &q6sstop_qcs404_desc;
1906cdef273SGovind Singh
1916cdef273SGovind Singh ret = qcom_cc_probe_by_index(pdev, 0, desc);
1926cdef273SGovind Singh if (ret)
193*97112c83SJohan Hovold goto err_put_rpm;
194*97112c83SJohan Hovold
195*97112c83SJohan Hovold pm_runtime_put(&pdev->dev);
1966cdef273SGovind Singh
1976cdef273SGovind Singh return 0;
198*97112c83SJohan Hovold
199*97112c83SJohan Hovold err_put_rpm:
200*97112c83SJohan Hovold pm_runtime_put_sync(&pdev->dev);
201*97112c83SJohan Hovold
202*97112c83SJohan Hovold return ret;
2036cdef273SGovind Singh }
2046cdef273SGovind Singh
2056cdef273SGovind Singh static const struct dev_pm_ops q6sstopcc_pm_ops = {
2066cdef273SGovind Singh SET_RUNTIME_PM_OPS(pm_clk_suspend, pm_clk_resume, NULL)
2076cdef273SGovind Singh };
2086cdef273SGovind Singh
2096cdef273SGovind Singh static struct platform_driver q6sstopcc_qcs404_driver = {
2106cdef273SGovind Singh .probe = q6sstopcc_qcs404_probe,
2116cdef273SGovind Singh .driver = {
2126cdef273SGovind Singh .name = "qcs404-q6sstopcc",
2136cdef273SGovind Singh .of_match_table = q6sstopcc_qcs404_match_table,
2146cdef273SGovind Singh .pm = &q6sstopcc_pm_ops,
2156cdef273SGovind Singh },
2166cdef273SGovind Singh };
2176cdef273SGovind Singh
2186cdef273SGovind Singh module_platform_driver(q6sstopcc_qcs404_driver);
2196cdef273SGovind Singh
2206cdef273SGovind Singh MODULE_DESCRIPTION("QTI QCS404 Q6SSTOP Clock Controller Driver");
2216cdef273SGovind Singh MODULE_LICENSE("GPL v2");
222