• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
meson_eeclkc_probe(struct platform_device * pdev)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 device_node *np;
21 	struct regmap *map;
22 	int ret, i;
23 
24 	data = of_device_get_match_data(dev);
25 	if (!data)
26 		return -EINVAL;
27 
28 	/* Get the hhi system controller node */
29 	np = of_get_parent(dev->of_node);
30 	map = syscon_node_to_regmap(np);
31 	of_node_put(np);
32 	if (IS_ERR(map)) {
33 		dev_err(dev,
34 			"failed to get HHI regmap\n");
35 		return PTR_ERR(map);
36 	}
37 
38 	if (data->init_count)
39 		regmap_multi_reg_write(map, data->init_regs, data->init_count);
40 
41 	/* Populate regmap for the regmap backed clocks */
42 	for (i = 0; i < data->regmap_clk_num; i++)
43 		data->regmap_clks[i]->map = map;
44 
45 	for (i = 0; i < data->hw_onecell_data->num; i++) {
46 		/* array might be sparse */
47 		if (!data->hw_onecell_data->hws[i])
48 			continue;
49 
50 		ret = devm_clk_hw_register(dev, data->hw_onecell_data->hws[i]);
51 		if (ret) {
52 			dev_err(dev, "Clock registration failed\n");
53 			return ret;
54 		}
55 	}
56 
57 	return devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get,
58 					   data->hw_onecell_data);
59 }
60