blob: 61d489c6e1c8df55245efd1e795259bd50594667 [file] [log] [blame]
Marek Szyprowskib1cddab2020-12-16 08:51:53 +01001// SPDX-License-Identifier: GPL-2.0+
2
Marek Szyprowskib1cddab2020-12-16 08:51:53 +01003#include <log.h>
4#include <asm/io.h>
5#include <clk-uclass.h>
6#include <dm.h>
7#include <regmap.h>
8#include <syscon.h>
9#include <dt-bindings/clock/g12a-aoclkc.h>
10
11#include "clk_meson.h"
12
13struct meson_clk {
14 struct regmap *map;
15};
16
17#define AO_CLK_GATE0 0x4c
18#define AO_SAR_CLK 0x90
19
20static struct meson_gate gates[] = {
21 MESON_GATE(CLKID_AO_SAR_ADC, AO_CLK_GATE0, 8),
22 MESON_GATE(CLKID_AO_SAR_ADC_CLK, AO_SAR_CLK, 8),
23};
24
25static int meson_set_gate(struct clk *clk, bool on)
26{
27 struct meson_clk *priv = dev_get_priv(clk->dev);
28 struct meson_gate *gate;
29
Marek Szyprowskib1cddab2020-12-16 08:51:53 +010030 gate = &gates[clk->id];
31
Marek Szyprowskib1cddab2020-12-16 08:51:53 +010032 regmap_update_bits(priv->map, gate->reg,
33 BIT(gate->bit), on ? BIT(gate->bit) : 0);
34
35 return 0;
36}
37
38static int meson_clk_enable(struct clk *clk)
39{
40 return meson_set_gate(clk, true);
41}
42
43static int meson_clk_disable(struct clk *clk)
44{
45 return meson_set_gate(clk, false);
46}
47
48static int meson_clk_probe(struct udevice *dev)
49{
50 struct meson_clk *priv = dev_get_priv(dev);
51
Tom Rini0542b012021-01-12 15:46:52 -050052 priv->map = syscon_node_to_regmap(dev_ofnode(dev_get_parent(dev)));
Marek Szyprowskib1cddab2020-12-16 08:51:53 +010053 if (IS_ERR(priv->map))
54 return PTR_ERR(priv->map);
55
56 return 0;
57}
58
Vyacheslav Bocharov3fc8aa32022-04-24 11:21:56 +030059static int meson_clk_request(struct clk *clk)
60{
61 if (clk->id >= ARRAY_SIZE(gates))
62 return -ENOENT;
63
64 return 0;
65}
66
Marek Szyprowskib1cddab2020-12-16 08:51:53 +010067static struct clk_ops meson_clk_ops = {
68 .disable = meson_clk_disable,
69 .enable = meson_clk_enable,
Vyacheslav Bocharov3fc8aa32022-04-24 11:21:56 +030070 .request = meson_clk_request,
Marek Szyprowskib1cddab2020-12-16 08:51:53 +010071};
72
73static const struct udevice_id meson_clk_ids[] = {
74 { .compatible = "amlogic,meson-g12a-aoclkc" },
75 { }
76};
77
Vyacheslav Bocharovc95a99b2022-04-24 11:21:55 +030078U_BOOT_DRIVER(meson_clk_g12a_ao) = {
Marek Szyprowskib1cddab2020-12-16 08:51:53 +010079 .name = "meson_clk_g12a_ao",
80 .id = UCLASS_CLK,
81 .of_match = meson_clk_ids,
Tom Rini0542b012021-01-12 15:46:52 -050082 .priv_auto = sizeof(struct meson_clk),
Marek Szyprowskib1cddab2020-12-16 08:51:53 +010083 .ops = &meson_clk_ops,
84 .probe = meson_clk_probe,
85};