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 153ddc3564SStephen Boyd static const char *aux_parents[] = { 163ddc3564SStephen Boyd "pll8_vote", 173ddc3564SStephen Boyd "pxo", 183ddc3564SStephen Boyd }; 193ddc3564SStephen Boyd 20*eac03cb0SJonathan 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 323ddc3564SStephen Boyd static int kpss_xcc_driver_probe(struct platform_device *pdev) 333ddc3564SStephen Boyd { 343ddc3564SStephen Boyd const struct of_device_id *id; 353ddc3564SStephen Boyd struct clk *clk; 363ddc3564SStephen Boyd void __iomem *base; 373ddc3564SStephen Boyd const char *name; 383ddc3564SStephen Boyd 393ddc3564SStephen Boyd id = of_match_device(kpss_xcc_match_table, &pdev->dev); 403ddc3564SStephen Boyd if (!id) 413ddc3564SStephen Boyd return -ENODEV; 423ddc3564SStephen Boyd 4317c774abSCai Huoqing base = devm_platform_ioremap_resource(pdev, 0); 443ddc3564SStephen Boyd if (IS_ERR(base)) 453ddc3564SStephen Boyd return PTR_ERR(base); 463ddc3564SStephen Boyd 473ddc3564SStephen Boyd if (id->data) { 483ddc3564SStephen Boyd if (of_property_read_string_index(pdev->dev.of_node, 493ddc3564SStephen Boyd "clock-output-names", 503ddc3564SStephen Boyd 0, &name)) 513ddc3564SStephen Boyd return -ENODEV; 523ddc3564SStephen Boyd base += 0x14; 533ddc3564SStephen Boyd } else { 543ddc3564SStephen Boyd name = "acpu_l2_aux"; 553ddc3564SStephen Boyd base += 0x28; 563ddc3564SStephen Boyd } 573ddc3564SStephen Boyd 583ddc3564SStephen Boyd clk = clk_register_mux_table(&pdev->dev, name, aux_parents, 593ddc3564SStephen Boyd ARRAY_SIZE(aux_parents), 0, base, 0, 0x3, 603ddc3564SStephen Boyd 0, aux_parent_map, NULL); 613ddc3564SStephen Boyd 623ddc3564SStephen Boyd platform_set_drvdata(pdev, clk); 633ddc3564SStephen Boyd 643ddc3564SStephen Boyd return PTR_ERR_OR_ZERO(clk); 653ddc3564SStephen Boyd } 663ddc3564SStephen Boyd 673ddc3564SStephen Boyd static int kpss_xcc_driver_remove(struct platform_device *pdev) 683ddc3564SStephen Boyd { 693ddc3564SStephen Boyd clk_unregister_mux(platform_get_drvdata(pdev)); 703ddc3564SStephen Boyd return 0; 713ddc3564SStephen Boyd } 723ddc3564SStephen Boyd 733ddc3564SStephen Boyd static struct platform_driver kpss_xcc_driver = { 743ddc3564SStephen Boyd .probe = kpss_xcc_driver_probe, 753ddc3564SStephen Boyd .remove = kpss_xcc_driver_remove, 763ddc3564SStephen Boyd .driver = { 773ddc3564SStephen Boyd .name = "kpss-xcc", 783ddc3564SStephen Boyd .of_match_table = kpss_xcc_match_table, 793ddc3564SStephen Boyd }, 803ddc3564SStephen Boyd }; 813ddc3564SStephen Boyd module_platform_driver(kpss_xcc_driver); 823ddc3564SStephen Boyd 833ddc3564SStephen Boyd MODULE_DESCRIPTION("Krait Processor Sub System (KPSS) Clock Driver"); 843ddc3564SStephen Boyd MODULE_LICENSE("GPL v2"); 853ddc3564SStephen Boyd MODULE_ALIAS("platform:kpss-xcc"); 86