xref: /openbmc/linux/drivers/clk/meson/meson-eeclk.c (revision a2cab953)
1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Copyright (c) 2019 BayLibre, SAS.
4  * Author: Jerome Brunet <jbrunet@baylibre.com>
5  */
6 
7 #include <linux/clk-provider.h>
8 #include <linux/of_device.h>
9 #include <linux/platform_device.h>
10 #include <linux/mfd/syscon.h>
11 #include <linux/regmap.h>
12 #include <linux/module.h>
13 
14 #include "clk-regmap.h"
15 #include "meson-eeclk.h"
16 
17 int meson_eeclkc_probe(struct platform_device *pdev)
18 {
19 	const struct meson_eeclkc_data *data;
20 	struct device *dev = &pdev->dev;
21 	struct device_node *np;
22 	struct regmap *map;
23 	int ret, i;
24 
25 	data = of_device_get_match_data(dev);
26 	if (!data)
27 		return -EINVAL;
28 
29 	/* Get the hhi system controller node */
30 	np = of_get_parent(dev->of_node);
31 	map = syscon_node_to_regmap(np);
32 	of_node_put(np);
33 	if (IS_ERR(map)) {
34 		dev_err(dev,
35 			"failed to get HHI regmap\n");
36 		return PTR_ERR(map);
37 	}
38 
39 	if (data->init_count)
40 		regmap_multi_reg_write(map, data->init_regs, data->init_count);
41 
42 	/* Populate regmap for the regmap backed clocks */
43 	for (i = 0; i < data->regmap_clk_num; i++)
44 		data->regmap_clks[i]->map = map;
45 
46 	for (i = 0; i < data->hw_onecell_data->num; i++) {
47 		/* array might be sparse */
48 		if (!data->hw_onecell_data->hws[i])
49 			continue;
50 
51 		ret = devm_clk_hw_register(dev, data->hw_onecell_data->hws[i]);
52 		if (ret) {
53 			dev_err(dev, "Clock registration failed\n");
54 			return ret;
55 		}
56 	}
57 
58 	return devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get,
59 					   data->hw_onecell_data);
60 }
61 EXPORT_SYMBOL_GPL(meson_eeclkc_probe);
62 MODULE_LICENSE("GPL v2");
63