xref: /openbmc/linux/drivers/clk/meson/meson-eeclk.c (revision e72e8bf1)
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 
13 #include "clk-regmap.h"
14 #include "meson-eeclk.h"
15 
16 int meson_eeclkc_probe(struct platform_device *pdev)
17 {
18 	const struct meson_eeclkc_data *data;
19 	struct device *dev = &pdev->dev;
20 	struct regmap *map;
21 	int ret, i;
22 
23 	data = of_device_get_match_data(dev);
24 	if (!data)
25 		return -EINVAL;
26 
27 	/* Get the hhi system controller node */
28 	map = syscon_node_to_regmap(of_get_parent(dev->of_node));
29 	if (IS_ERR(map)) {
30 		dev_err(dev,
31 			"failed to get HHI regmap\n");
32 		return PTR_ERR(map);
33 	}
34 
35 	if (data->init_count)
36 		regmap_multi_reg_write(map, data->init_regs, data->init_count);
37 
38 	/* Populate regmap for the regmap backed clocks */
39 	for (i = 0; i < data->regmap_clk_num; i++)
40 		data->regmap_clks[i]->map = map;
41 
42 	for (i = 0; i < data->hw_onecell_data->num; i++) {
43 		/* array might be sparse */
44 		if (!data->hw_onecell_data->hws[i])
45 			continue;
46 
47 		ret = devm_clk_hw_register(dev, data->hw_onecell_data->hws[i]);
48 		if (ret) {
49 			dev_err(dev, "Clock registration failed\n");
50 			return ret;
51 		}
52 	}
53 
54 	return devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get,
55 					   data->hw_onecell_data);
56 }
57