1*3ddc3564SStephen Boyd // SPDX-License-Identifier: GPL-2.0 2*3ddc3564SStephen Boyd // Copyright (c) 2018, The Linux Foundation. All rights reserved. 3*3ddc3564SStephen Boyd 4*3ddc3564SStephen Boyd #include <linux/kernel.h> 5*3ddc3564SStephen Boyd #include <linux/init.h> 6*3ddc3564SStephen Boyd #include <linux/module.h> 7*3ddc3564SStephen Boyd #include <linux/platform_device.h> 8*3ddc3564SStephen Boyd #include <linux/err.h> 9*3ddc3564SStephen Boyd #include <linux/io.h> 10*3ddc3564SStephen Boyd #include <linux/of.h> 11*3ddc3564SStephen Boyd #include <linux/of_device.h> 12*3ddc3564SStephen Boyd #include <linux/clk.h> 13*3ddc3564SStephen Boyd #include <linux/clk-provider.h> 14*3ddc3564SStephen Boyd 15*3ddc3564SStephen Boyd static const char *aux_parents[] = { 16*3ddc3564SStephen Boyd "pll8_vote", 17*3ddc3564SStephen Boyd "pxo", 18*3ddc3564SStephen Boyd }; 19*3ddc3564SStephen Boyd 20*3ddc3564SStephen Boyd static unsigned int aux_parent_map[] = { 21*3ddc3564SStephen Boyd 3, 22*3ddc3564SStephen Boyd 0, 23*3ddc3564SStephen Boyd }; 24*3ddc3564SStephen Boyd 25*3ddc3564SStephen Boyd static const struct of_device_id kpss_xcc_match_table[] = { 26*3ddc3564SStephen Boyd { .compatible = "qcom,kpss-acc-v1", .data = (void *)1UL }, 27*3ddc3564SStephen Boyd { .compatible = "qcom,kpss-gcc" }, 28*3ddc3564SStephen Boyd {} 29*3ddc3564SStephen Boyd }; 30*3ddc3564SStephen Boyd MODULE_DEVICE_TABLE(of, kpss_xcc_match_table); 31*3ddc3564SStephen Boyd 32*3ddc3564SStephen Boyd static int kpss_xcc_driver_probe(struct platform_device *pdev) 33*3ddc3564SStephen Boyd { 34*3ddc3564SStephen Boyd const struct of_device_id *id; 35*3ddc3564SStephen Boyd struct clk *clk; 36*3ddc3564SStephen Boyd struct resource *res; 37*3ddc3564SStephen Boyd void __iomem *base; 38*3ddc3564SStephen Boyd const char *name; 39*3ddc3564SStephen Boyd 40*3ddc3564SStephen Boyd id = of_match_device(kpss_xcc_match_table, &pdev->dev); 41*3ddc3564SStephen Boyd if (!id) 42*3ddc3564SStephen Boyd return -ENODEV; 43*3ddc3564SStephen Boyd 44*3ddc3564SStephen Boyd res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 45*3ddc3564SStephen Boyd base = devm_ioremap_resource(&pdev->dev, res); 46*3ddc3564SStephen Boyd if (IS_ERR(base)) 47*3ddc3564SStephen Boyd return PTR_ERR(base); 48*3ddc3564SStephen Boyd 49*3ddc3564SStephen Boyd if (id->data) { 50*3ddc3564SStephen Boyd if (of_property_read_string_index(pdev->dev.of_node, 51*3ddc3564SStephen Boyd "clock-output-names", 52*3ddc3564SStephen Boyd 0, &name)) 53*3ddc3564SStephen Boyd return -ENODEV; 54*3ddc3564SStephen Boyd base += 0x14; 55*3ddc3564SStephen Boyd } else { 56*3ddc3564SStephen Boyd name = "acpu_l2_aux"; 57*3ddc3564SStephen Boyd base += 0x28; 58*3ddc3564SStephen Boyd } 59*3ddc3564SStephen Boyd 60*3ddc3564SStephen Boyd clk = clk_register_mux_table(&pdev->dev, name, aux_parents, 61*3ddc3564SStephen Boyd ARRAY_SIZE(aux_parents), 0, base, 0, 0x3, 62*3ddc3564SStephen Boyd 0, aux_parent_map, NULL); 63*3ddc3564SStephen Boyd 64*3ddc3564SStephen Boyd platform_set_drvdata(pdev, clk); 65*3ddc3564SStephen Boyd 66*3ddc3564SStephen Boyd return PTR_ERR_OR_ZERO(clk); 67*3ddc3564SStephen Boyd } 68*3ddc3564SStephen Boyd 69*3ddc3564SStephen Boyd static int kpss_xcc_driver_remove(struct platform_device *pdev) 70*3ddc3564SStephen Boyd { 71*3ddc3564SStephen Boyd clk_unregister_mux(platform_get_drvdata(pdev)); 72*3ddc3564SStephen Boyd return 0; 73*3ddc3564SStephen Boyd } 74*3ddc3564SStephen Boyd 75*3ddc3564SStephen Boyd static struct platform_driver kpss_xcc_driver = { 76*3ddc3564SStephen Boyd .probe = kpss_xcc_driver_probe, 77*3ddc3564SStephen Boyd .remove = kpss_xcc_driver_remove, 78*3ddc3564SStephen Boyd .driver = { 79*3ddc3564SStephen Boyd .name = "kpss-xcc", 80*3ddc3564SStephen Boyd .of_match_table = kpss_xcc_match_table, 81*3ddc3564SStephen Boyd }, 82*3ddc3564SStephen Boyd }; 83*3ddc3564SStephen Boyd module_platform_driver(kpss_xcc_driver); 84*3ddc3564SStephen Boyd 85*3ddc3564SStephen Boyd MODULE_DESCRIPTION("Krait Processor Sub System (KPSS) Clock Driver"); 86*3ddc3564SStephen Boyd MODULE_LICENSE("GPL v2"); 87*3ddc3564SStephen Boyd MODULE_ALIAS("platform:kpss-xcc"); 88