clk: qcom: Add IPQ8064 PLL required for USB
[linux-2.6-block.git] / drivers / clk / qcom / common.c
CommitLineData
49fc825f
SB
1/*
2 * Copyright (c) 2013-2014, The Linux Foundation. All rights reserved.
3 *
4 * This software is licensed under the terms of the GNU General Public
5 * License version 2, as published by the Free Software Foundation, and
6 * may be copied, distributed, and modified under those terms.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 */
13
14#include <linux/export.h>
15#include <linux/regmap.h>
16#include <linux/platform_device.h>
17#include <linux/clk-provider.h>
18#include <linux/reset-controller.h>
19
20#include "common.h"
21#include "clk-regmap.h"
22#include "reset.h"
23
24struct qcom_cc {
25 struct qcom_reset_controller reset;
26 struct clk_onecell_data data;
27 struct clk *clks[];
28};
29
5b6b7490
SB
30struct regmap *
31qcom_cc_map(struct platform_device *pdev, const struct qcom_cc_desc *desc)
49fc825f
SB
32{
33 void __iomem *base;
34 struct resource *res;
5b6b7490
SB
35 struct device *dev = &pdev->dev;
36
37 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
38 base = devm_ioremap_resource(dev, res);
39 if (IS_ERR(base))
40 return ERR_CAST(base);
41
42 return devm_regmap_init_mmio(dev, base, desc->config);
43}
44EXPORT_SYMBOL_GPL(qcom_cc_map);
45
46int qcom_cc_really_probe(struct platform_device *pdev,
47 const struct qcom_cc_desc *desc, struct regmap *regmap)
48{
49fc825f
SB
49 int i, ret;
50 struct device *dev = &pdev->dev;
51 struct clk *clk;
52 struct clk_onecell_data *data;
53 struct clk **clks;
49fc825f
SB
54 struct qcom_reset_controller *reset;
55 struct qcom_cc *cc;
56 size_t num_clks = desc->num_clks;
57 struct clk_regmap **rclks = desc->clks;
58
49fc825f
SB
59 cc = devm_kzalloc(dev, sizeof(*cc) + sizeof(*clks) * num_clks,
60 GFP_KERNEL);
61 if (!cc)
62 return -ENOMEM;
63
64 clks = cc->clks;
65 data = &cc->data;
66 data->clks = clks;
67 data->clk_num = num_clks;
68
69 for (i = 0; i < num_clks; i++) {
9ec2749b
SB
70 if (!rclks[i]) {
71 clks[i] = ERR_PTR(-ENOENT);
49fc825f 72 continue;
9ec2749b 73 }
49fc825f
SB
74 clk = devm_clk_register_regmap(dev, rclks[i]);
75 if (IS_ERR(clk))
76 return PTR_ERR(clk);
77 clks[i] = clk;
78 }
79
80 ret = of_clk_add_provider(dev->of_node, of_clk_src_onecell_get, data);
81 if (ret)
82 return ret;
83
84 reset = &cc->reset;
85 reset->rcdev.of_node = dev->of_node;
86 reset->rcdev.ops = &qcom_reset_ops;
87 reset->rcdev.owner = dev->driver->owner;
88 reset->rcdev.nr_resets = desc->num_resets;
89 reset->regmap = regmap;
90 reset->reset_map = desc->resets;
91 platform_set_drvdata(pdev, &reset->rcdev);
92
93 ret = reset_controller_register(&reset->rcdev);
94 if (ret)
95 of_clk_del_provider(dev->of_node);
96
97 return ret;
98}
5b6b7490
SB
99EXPORT_SYMBOL_GPL(qcom_cc_really_probe);
100
101int qcom_cc_probe(struct platform_device *pdev, const struct qcom_cc_desc *desc)
102{
103 struct regmap *regmap;
104
105 regmap = qcom_cc_map(pdev, desc);
106 if (IS_ERR(regmap))
107 return PTR_ERR(regmap);
108
109 return qcom_cc_really_probe(pdev, desc, regmap);
110}
49fc825f
SB
111EXPORT_SYMBOL_GPL(qcom_cc_probe);
112
113void qcom_cc_remove(struct platform_device *pdev)
114{
115 of_clk_del_provider(pdev->dev.of_node);
116 reset_controller_unregister(platform_get_drvdata(pdev));
117}
118EXPORT_SYMBOL_GPL(qcom_cc_remove);