Merge tag 'trace-printf-v6.13' of git://git.kernel.org/pub/scm/linux/kernel/git/trace...
[drm/drm-misc.git] / drivers / clk / actions / owl-common.c
blobc62024b7c7374f64367ce4a9d37f7ee382f0fe6e
1 // SPDX-License-Identifier: GPL-2.0+
2 //
3 // OWL common clock driver
4 //
5 // Copyright (c) 2014 Actions Semi Inc.
6 // Author: David Liu <liuwei@actions-semi.com>
7 //
8 // Copyright (c) 2018 Linaro Ltd.
9 // Author: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
11 #include <linux/platform_device.h>
12 #include <linux/regmap.h>
14 #include "owl-common.h"
16 static const struct regmap_config owl_regmap_config = {
17 .reg_bits = 32,
18 .reg_stride = 4,
19 .val_bits = 32,
20 .max_register = 0x00cc,
21 .fast_io = true,
24 static void owl_clk_set_regmap(const struct owl_clk_desc *desc,
25 struct regmap *regmap)
27 int i;
28 struct owl_clk_common *clks;
30 for (i = 0; i < desc->num_clks; i++) {
31 clks = desc->clks[i];
32 if (!clks)
33 continue;
35 clks->regmap = regmap;
39 int owl_clk_regmap_init(struct platform_device *pdev,
40 struct owl_clk_desc *desc)
42 void __iomem *base;
43 struct regmap *regmap;
45 base = devm_platform_ioremap_resource(pdev, 0);
46 if (IS_ERR(base))
47 return PTR_ERR(base);
49 regmap = devm_regmap_init_mmio(&pdev->dev, base, &owl_regmap_config);
50 if (IS_ERR(regmap)) {
51 pr_err("failed to init regmap\n");
52 return PTR_ERR(regmap);
55 owl_clk_set_regmap(desc, regmap);
56 desc->regmap = regmap;
58 return 0;
61 int owl_clk_probe(struct device *dev, struct clk_hw_onecell_data *hw_clks)
63 int i, ret;
64 struct clk_hw *hw;
66 for (i = 0; i < hw_clks->num; i++) {
67 const char *name;
69 hw = hw_clks->hws[i];
70 if (IS_ERR_OR_NULL(hw))
71 continue;
73 name = hw->init->name;
74 ret = devm_clk_hw_register(dev, hw);
75 if (ret) {
76 dev_err(dev, "Couldn't register clock %d - %s\n",
77 i, name);
78 return ret;
82 ret = devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get, hw_clks);
83 if (ret)
84 dev_err(dev, "Failed to add clock provider\n");
86 return ret;