xref: /linux/drivers/clk/qcom/hfpll.c (revision 619b92b9c8fe5369503ae948ad4e0a9c195c2c4a)
1cb546b79SStephen Boyd // SPDX-License-Identifier: GPL-2.0
2cb546b79SStephen Boyd // Copyright (c) 2018, The Linux Foundation. All rights reserved.
3cb546b79SStephen Boyd 
4cb546b79SStephen Boyd #include <linux/kernel.h>
5cb546b79SStephen Boyd #include <linux/init.h>
6cb546b79SStephen Boyd #include <linux/module.h>
7cb546b79SStephen Boyd #include <linux/platform_device.h>
8cb546b79SStephen Boyd #include <linux/of.h>
934e000c0SAdam Skladowski #include <linux/of_device.h>
10cb546b79SStephen Boyd #include <linux/clk.h>
11cb546b79SStephen Boyd #include <linux/clk-provider.h>
12cb546b79SStephen Boyd #include <linux/regmap.h>
13cb546b79SStephen Boyd 
14cb546b79SStephen Boyd #include "clk-regmap.h"
15cb546b79SStephen Boyd #include "clk-hfpll.h"
16cb546b79SStephen Boyd 
17*3db0f3b9SLuca Weiss static const struct hfpll_data qcs404 = {
18cb546b79SStephen Boyd 	.mode_reg = 0x00,
19cb546b79SStephen Boyd 	.l_reg = 0x04,
20cb546b79SStephen Boyd 	.m_reg = 0x08,
21cb546b79SStephen Boyd 	.n_reg = 0x0c,
22cb546b79SStephen Boyd 	.user_reg = 0x10,
23cb546b79SStephen Boyd 	.config_reg = 0x14,
24cb546b79SStephen Boyd 	.config_val = 0x430405d,
25cb546b79SStephen Boyd 	.status_reg = 0x1c,
26cb546b79SStephen Boyd 	.lock_bit = 16,
27cb546b79SStephen Boyd 
28cb546b79SStephen Boyd 	.user_val = 0x8,
29cb546b79SStephen Boyd 	.user_vco_mask = 0x100000,
30cb546b79SStephen Boyd 	.low_vco_max_rate = 1248000000,
31cb546b79SStephen Boyd 	.min_rate = 537600000UL,
32cb546b79SStephen Boyd 	.max_rate = 2900000000UL,
33cb546b79SStephen Boyd };
34cb546b79SStephen Boyd 
351fa2d1a8SAdam Skladowski static const struct hfpll_data msm8976_a53 = {
361fa2d1a8SAdam Skladowski 	.mode_reg = 0x00,
371fa2d1a8SAdam Skladowski 	.l_reg = 0x04,
381fa2d1a8SAdam Skladowski 	.m_reg = 0x08,
391fa2d1a8SAdam Skladowski 	.n_reg = 0x0c,
401fa2d1a8SAdam Skladowski 	.user_reg = 0x10,
411fa2d1a8SAdam Skladowski 	.config_reg = 0x14,
421fa2d1a8SAdam Skladowski 	.config_val = 0x341600,
431fa2d1a8SAdam Skladowski 	.status_reg = 0x1c,
441fa2d1a8SAdam Skladowski 	.lock_bit = 16,
451fa2d1a8SAdam Skladowski 
461fa2d1a8SAdam Skladowski 	.l_val = 0x35,
471fa2d1a8SAdam Skladowski 	.user_val = 0x109,
481fa2d1a8SAdam Skladowski 	.min_rate = 902400000UL,
491fa2d1a8SAdam Skladowski 	.max_rate = 1478400000UL,
501fa2d1a8SAdam Skladowski };
511fa2d1a8SAdam Skladowski 
521fa2d1a8SAdam Skladowski static const struct hfpll_data msm8976_a72 = {
531fa2d1a8SAdam Skladowski 	.mode_reg = 0x00,
541fa2d1a8SAdam Skladowski 	.l_reg = 0x04,
551fa2d1a8SAdam Skladowski 	.m_reg = 0x08,
561fa2d1a8SAdam Skladowski 	.n_reg = 0x0c,
571fa2d1a8SAdam Skladowski 	.user_reg = 0x10,
581fa2d1a8SAdam Skladowski 	.config_reg = 0x14,
591fa2d1a8SAdam Skladowski 	.config_val = 0x4e0405d,
601fa2d1a8SAdam Skladowski 	.status_reg = 0x1c,
611fa2d1a8SAdam Skladowski 	.lock_bit = 16,
621fa2d1a8SAdam Skladowski 
631fa2d1a8SAdam Skladowski 	.l_val = 0x3e,
641fa2d1a8SAdam Skladowski 	.user_val = 0x100109,
651fa2d1a8SAdam Skladowski 	.min_rate = 940800000UL,
661fa2d1a8SAdam Skladowski 	.max_rate = 2016000000UL,
671fa2d1a8SAdam Skladowski };
681fa2d1a8SAdam Skladowski 
691fa2d1a8SAdam Skladowski static const struct hfpll_data msm8976_cci = {
701fa2d1a8SAdam Skladowski 	.mode_reg = 0x00,
711fa2d1a8SAdam Skladowski 	.l_reg = 0x04,
721fa2d1a8SAdam Skladowski 	.m_reg = 0x08,
731fa2d1a8SAdam Skladowski 	.n_reg = 0x0c,
741fa2d1a8SAdam Skladowski 	.user_reg = 0x10,
751fa2d1a8SAdam Skladowski 	.config_reg = 0x14,
761fa2d1a8SAdam Skladowski 	.config_val = 0x141400,
771fa2d1a8SAdam Skladowski 	.status_reg = 0x1c,
781fa2d1a8SAdam Skladowski 	.lock_bit = 16,
791fa2d1a8SAdam Skladowski 
801fa2d1a8SAdam Skladowski 	.l_val = 0x20,
811fa2d1a8SAdam Skladowski 	.user_val = 0x100109,
821fa2d1a8SAdam Skladowski 	.min_rate = 556800000UL,
831fa2d1a8SAdam Skladowski 	.max_rate = 902400000UL,
841fa2d1a8SAdam Skladowski };
851fa2d1a8SAdam Skladowski 
86cb546b79SStephen Boyd static const struct of_device_id qcom_hfpll_match_table[] = {
871fa2d1a8SAdam Skladowski 	{ .compatible = "qcom,msm8976-hfpll-a53", .data = &msm8976_a53 },
881fa2d1a8SAdam Skladowski 	{ .compatible = "qcom,msm8976-hfpll-a72", .data = &msm8976_a72 },
891fa2d1a8SAdam Skladowski 	{ .compatible = "qcom,msm8976-hfpll-cci", .data = &msm8976_cci },
90*3db0f3b9SLuca Weiss 	{ .compatible = "qcom,qcs404-hfpll", .data = &qcs404 },
91*3db0f3b9SLuca Weiss 	/* Deprecated in bindings */
92*3db0f3b9SLuca Weiss 	{ .compatible = "qcom,hfpll", .data = &qcs404 },
93cb546b79SStephen Boyd 	{ }
94cb546b79SStephen Boyd };
95cb546b79SStephen Boyd MODULE_DEVICE_TABLE(of, qcom_hfpll_match_table);
96cb546b79SStephen Boyd 
97cb546b79SStephen Boyd static const struct regmap_config hfpll_regmap_config = {
98cb546b79SStephen Boyd 	.reg_bits	= 32,
99cb546b79SStephen Boyd 	.reg_stride	= 4,
100cb546b79SStephen Boyd 	.val_bits	= 32,
101cb546b79SStephen Boyd 	.max_register	= 0x30,
102cb546b79SStephen Boyd 	.fast_io	= true,
103cb546b79SStephen Boyd };
104cb546b79SStephen Boyd 
qcom_hfpll_probe(struct platform_device * pdev)105cb546b79SStephen Boyd static int qcom_hfpll_probe(struct platform_device *pdev)
106cb546b79SStephen Boyd {
107cb546b79SStephen Boyd 	struct device *dev = &pdev->dev;
108cb546b79SStephen Boyd 	void __iomem *base;
109cb546b79SStephen Boyd 	struct regmap *regmap;
110cb546b79SStephen Boyd 	struct clk_hfpll *h;
111cb546b79SStephen Boyd 	struct clk_init_data init = {
112cb546b79SStephen Boyd 		.num_parents = 1,
113cb546b79SStephen Boyd 		.ops = &clk_ops_hfpll,
114b455dc35SJorge Ramirez-Ortiz 		/*
115b455dc35SJorge Ramirez-Ortiz 		 * rather than marking the clock critical and forcing the clock
116b455dc35SJorge Ramirez-Ortiz 		 * to be always enabled, we make sure that the clock is not
117b455dc35SJorge Ramirez-Ortiz 		 * disabled: the firmware remains responsible of enabling this
118b455dc35SJorge Ramirez-Ortiz 		 * clock (for more info check the commit log)
119b455dc35SJorge Ramirez-Ortiz 		 */
120b455dc35SJorge Ramirez-Ortiz 		.flags = CLK_IGNORE_UNUSED,
121cb546b79SStephen Boyd 	};
1229e406674SJorge Ramirez-Ortiz 	int ret;
1238a7729abSJorge Ramirez-Ortiz 	struct clk_parent_data pdata = { .index = 0 };
124cb546b79SStephen Boyd 
125cb546b79SStephen Boyd 	h = devm_kzalloc(dev, sizeof(*h), GFP_KERNEL);
126cb546b79SStephen Boyd 	if (!h)
127cb546b79SStephen Boyd 		return -ENOMEM;
128cb546b79SStephen Boyd 
1290c44be06SMinghao Chi 	base = devm_platform_get_and_ioremap_resource(pdev, 0, NULL);
130cb546b79SStephen Boyd 	if (IS_ERR(base))
131cb546b79SStephen Boyd 		return PTR_ERR(base);
132cb546b79SStephen Boyd 
133cb546b79SStephen Boyd 	regmap = devm_regmap_init_mmio(&pdev->dev, base, &hfpll_regmap_config);
134cb546b79SStephen Boyd 	if (IS_ERR(regmap))
135cb546b79SStephen Boyd 		return PTR_ERR(regmap);
136cb546b79SStephen Boyd 
137cb546b79SStephen Boyd 	if (of_property_read_string_index(dev->of_node, "clock-output-names",
138cb546b79SStephen Boyd 					  0, &init.name))
139cb546b79SStephen Boyd 		return -ENODEV;
140cb546b79SStephen Boyd 
1418a7729abSJorge Ramirez-Ortiz 	init.parent_data = &pdata;
1428a7729abSJorge Ramirez-Ortiz 
14334e000c0SAdam Skladowski 	h->d = of_device_get_match_data(&pdev->dev);
144cb546b79SStephen Boyd 	h->clkr.hw.init = &init;
145cb546b79SStephen Boyd 	spin_lock_init(&h->lock);
146cb546b79SStephen Boyd 
1479e406674SJorge Ramirez-Ortiz 	ret = devm_clk_register_regmap(dev, &h->clkr);
1489e406674SJorge Ramirez-Ortiz 	if (ret) {
1499e406674SJorge Ramirez-Ortiz 		dev_err(dev, "failed to register regmap clock: %d\n", ret);
1509e406674SJorge Ramirez-Ortiz 		return ret;
1519e406674SJorge Ramirez-Ortiz 	}
1529e406674SJorge Ramirez-Ortiz 
1539e406674SJorge Ramirez-Ortiz 	return devm_of_clk_add_hw_provider(dev, of_clk_hw_simple_get,
1549e406674SJorge Ramirez-Ortiz 					   &h->clkr.hw);
155cb546b79SStephen Boyd }
156cb546b79SStephen Boyd 
157cb546b79SStephen Boyd static struct platform_driver qcom_hfpll_driver = {
158cb546b79SStephen Boyd 	.probe		= qcom_hfpll_probe,
159cb546b79SStephen Boyd 	.driver		= {
160cb546b79SStephen Boyd 		.name	= "qcom-hfpll",
161cb546b79SStephen Boyd 		.of_match_table = qcom_hfpll_match_table,
162cb546b79SStephen Boyd 	},
163cb546b79SStephen Boyd };
164cb546b79SStephen Boyd module_platform_driver(qcom_hfpll_driver);
165cb546b79SStephen Boyd 
166cb546b79SStephen Boyd MODULE_DESCRIPTION("QCOM HFPLL Clock Driver");
167cb546b79SStephen Boyd MODULE_LICENSE("GPL v2");
168cb546b79SStephen Boyd MODULE_ALIAS("platform:qcom-hfpll");
169