13ddc3564SStephen Boyd // SPDX-License-Identifier: GPL-2.0
23ddc3564SStephen Boyd // Copyright (c) 2018, The Linux Foundation. All rights reserved.
33ddc3564SStephen Boyd
43ddc3564SStephen Boyd #include <linux/kernel.h>
53ddc3564SStephen Boyd #include <linux/init.h>
63ddc3564SStephen Boyd #include <linux/module.h>
73ddc3564SStephen Boyd #include <linux/platform_device.h>
83ddc3564SStephen Boyd #include <linux/err.h>
93ddc3564SStephen Boyd #include <linux/io.h>
103ddc3564SStephen Boyd #include <linux/of.h>
113ddc3564SStephen Boyd #include <linux/of_device.h>
123ddc3564SStephen Boyd #include <linux/clk.h>
133ddc3564SStephen Boyd #include <linux/clk-provider.h>
143ddc3564SStephen Boyd
15c3db5128SChristian Marangi static const struct clk_parent_data aux_parents[] = {
16c3db5128SChristian Marangi { .fw_name = "pll8_vote", .name = "pll8_vote" },
17c3db5128SChristian Marangi { .fw_name = "pxo", .name = "pxo_board" },
183ddc3564SStephen Boyd };
193ddc3564SStephen Boyd
20eac03cb0SJonathan Neuschäfer static const u32 aux_parent_map[] = {
213ddc3564SStephen Boyd 3,
223ddc3564SStephen Boyd 0,
233ddc3564SStephen Boyd };
243ddc3564SStephen Boyd
253ddc3564SStephen Boyd static const struct of_device_id kpss_xcc_match_table[] = {
263ddc3564SStephen Boyd { .compatible = "qcom,kpss-acc-v1", .data = (void *)1UL },
273ddc3564SStephen Boyd { .compatible = "qcom,kpss-gcc" },
283ddc3564SStephen Boyd {}
293ddc3564SStephen Boyd };
303ddc3564SStephen Boyd MODULE_DEVICE_TABLE(of, kpss_xcc_match_table);
313ddc3564SStephen Boyd
kpss_xcc_driver_probe(struct platform_device * pdev)323ddc3564SStephen Boyd static int kpss_xcc_driver_probe(struct platform_device *pdev)
333ddc3564SStephen Boyd {
3409be1a39SChristian Marangi struct device *dev = &pdev->dev;
353ddc3564SStephen Boyd const struct of_device_id *id;
363ddc3564SStephen Boyd void __iomem *base;
37c3db5128SChristian Marangi struct clk_hw *hw;
383ddc3564SStephen Boyd const char *name;
393ddc3564SStephen Boyd
4009be1a39SChristian Marangi id = of_match_device(kpss_xcc_match_table, dev);
413ddc3564SStephen Boyd if (!id)
423ddc3564SStephen Boyd return -ENODEV;
433ddc3564SStephen Boyd
4417c774abSCai Huoqing base = devm_platform_ioremap_resource(pdev, 0);
453ddc3564SStephen Boyd if (IS_ERR(base))
463ddc3564SStephen Boyd return PTR_ERR(base);
473ddc3564SStephen Boyd
483ddc3564SStephen Boyd if (id->data) {
4909be1a39SChristian Marangi if (of_property_read_string_index(dev->of_node,
503ddc3564SStephen Boyd "clock-output-names",
513ddc3564SStephen Boyd 0, &name))
523ddc3564SStephen Boyd return -ENODEV;
533ddc3564SStephen Boyd base += 0x14;
543ddc3564SStephen Boyd } else {
553ddc3564SStephen Boyd name = "acpu_l2_aux";
563ddc3564SStephen Boyd base += 0x28;
573ddc3564SStephen Boyd }
583ddc3564SStephen Boyd
5909be1a39SChristian Marangi hw = devm_clk_hw_register_mux_parent_data_table(dev, name, aux_parents,
60c3db5128SChristian Marangi ARRAY_SIZE(aux_parents), 0,
61c3db5128SChristian Marangi base, 0, 0x3,
623ddc3564SStephen Boyd 0, aux_parent_map, NULL);
6309be1a39SChristian Marangi if (IS_ERR(hw))
6409be1a39SChristian Marangi return PTR_ERR(hw);
653ddc3564SStephen Boyd
66*7e8e9d3dSChen Ni return of_clk_add_hw_provider(dev->of_node, of_clk_hw_simple_get, hw);
673ddc3564SStephen Boyd }
683ddc3564SStephen Boyd
693ddc3564SStephen Boyd static struct platform_driver kpss_xcc_driver = {
703ddc3564SStephen Boyd .probe = kpss_xcc_driver_probe,
713ddc3564SStephen Boyd .driver = {
723ddc3564SStephen Boyd .name = "kpss-xcc",
733ddc3564SStephen Boyd .of_match_table = kpss_xcc_match_table,
743ddc3564SStephen Boyd },
753ddc3564SStephen Boyd };
763ddc3564SStephen Boyd module_platform_driver(kpss_xcc_driver);
773ddc3564SStephen Boyd
783ddc3564SStephen Boyd MODULE_DESCRIPTION("Krait Processor Sub System (KPSS) Clock Driver");
793ddc3564SStephen Boyd MODULE_LICENSE("GPL v2");
803ddc3564SStephen Boyd MODULE_ALIAS("platform:kpss-xcc");
81