blob: 8d5a5dab955a85c5ef7042d887def12cda1de439 [file] [log] [blame]
Jerome Brunet6682bd42019-02-01 15:53:45 +01001// 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>
Kevin Hilman20425f62020-11-18 11:14:05 -080012#include <linux/module.h>
Jerome Brunet6682bd42019-02-01 15:53:45 +010013
Jerome Brunet6682bd42019-02-01 15:53:45 +010014#include "clk-regmap.h"
15#include "meson-eeclk.h"
16
17int meson_eeclkc_probe(struct platform_device *pdev)
18{
19 const struct meson_eeclkc_data *data;
20 struct device *dev = &pdev->dev;
Jerome Brunet6682bd42019-02-01 15:53:45 +010021 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 map = syscon_node_to_regmap(of_get_parent(dev->of_node));
30 if (IS_ERR(map)) {
31 dev_err(dev,
32 "failed to get HHI regmap\n");
33 return PTR_ERR(map);
34 }
35
Jerome Brunet19a18d42019-05-13 14:31:14 +020036 if (data->init_count)
37 regmap_multi_reg_write(map, data->init_regs, data->init_count);
38
Jerome Brunet6682bd42019-02-01 15:53:45 +010039 /* Populate regmap for the regmap backed clocks */
40 for (i = 0; i < data->regmap_clk_num; i++)
41 data->regmap_clks[i]->map = map;
42
43 for (i = 0; i < data->hw_onecell_data->num; i++) {
44 /* array might be sparse */
45 if (!data->hw_onecell_data->hws[i])
46 continue;
47
48 ret = devm_clk_hw_register(dev, data->hw_onecell_data->hws[i]);
49 if (ret) {
50 dev_err(dev, "Clock registration failed\n");
51 return ret;
52 }
53 }
54
55 return devm_of_clk_add_hw_provider(dev, of_clk_hw_onecell_get,
56 data->hw_onecell_data);
57}
Kevin Hilman20425f62020-11-18 11:14:05 -080058EXPORT_SYMBOL_GPL(meson_eeclkc_probe);
59MODULE_LICENSE("GPL v2");