1 // SPDX-License-Identifier: GPL-2.0
3 // Spreadtrum clock infrastructure
5 // Copyright (C) 2017 Spreadtrum, Inc.
6 // Author: Chunyan Zhang <chunyan.zhang@spreadtrum.com>
8 #include <linux/mfd/syscon.h>
9 #include <linux/module.h>
10 #include <linux/of_address.h>
11 #include <linux/of_platform.h>
12 #include <linux/regmap.h>
16 static const struct regmap_config sprdclk_regmap_config
= {
20 .max_register
= 0xffff,
24 static void sprd_clk_set_regmap(const struct sprd_clk_desc
*desc
,
25 struct regmap
*regmap
)
28 struct sprd_clk_common
*cclk
;
30 for (i
= 0; i
< desc
->num_clk_clks
; i
++) {
31 cclk
= desc
->clk_clks
[i
];
35 cclk
->regmap
= regmap
;
39 int sprd_clk_regmap_init(struct platform_device
*pdev
,
40 const struct sprd_clk_desc
*desc
)
43 struct device
*dev
= &pdev
->dev
;
44 struct device_node
*node
= dev
->of_node
;
45 struct regmap
*regmap
;
47 if (of_find_property(node
, "sprd,syscon", NULL
)) {
48 regmap
= syscon_regmap_lookup_by_phandle(node
, "sprd,syscon");
50 pr_err("%s: failed to get syscon regmap\n", __func__
);
51 return PTR_ERR(regmap
);
53 } else if (of_device_is_compatible(of_get_parent(dev
->of_node
),
55 regmap
= device_node_to_regmap(of_get_parent(dev
->of_node
));
57 dev_err(dev
, "failed to get regmap from its parent.\n");
58 return PTR_ERR(regmap
);
61 base
= devm_platform_ioremap_resource(pdev
, 0);
65 regmap
= devm_regmap_init_mmio(&pdev
->dev
, base
,
66 &sprdclk_regmap_config
);
68 pr_err("failed to init regmap\n");
69 return PTR_ERR(regmap
);
73 sprd_clk_set_regmap(desc
, regmap
);
77 EXPORT_SYMBOL_GPL(sprd_clk_regmap_init
);
79 int sprd_clk_probe(struct device
*dev
, struct clk_hw_onecell_data
*clkhw
)
84 for (i
= 0; i
< clkhw
->num
; i
++) {
91 name
= hw
->init
->name
;
92 ret
= devm_clk_hw_register(dev
, hw
);
94 dev_err(dev
, "Couldn't register clock %d - %s\n",
100 ret
= devm_of_clk_add_hw_provider(dev
, of_clk_hw_onecell_get
, clkhw
);
102 dev_err(dev
, "Failed to add clock provider\n");
106 EXPORT_SYMBOL_GPL(sprd_clk_probe
);
108 MODULE_LICENSE("GPL v2");