2 * (C) Copyright 2015 Google, Inc
4 * SPDX-License-Identifier: GPL-2.0
8 #include <clk-uclass.h>
13 struct sandbox_clk_priv
{
14 ulong rate
[SANDBOX_CLK_ID_COUNT
];
15 bool enabled
[SANDBOX_CLK_ID_COUNT
];
18 static ulong
sandbox_clk_get_rate(struct clk
*clk
)
20 struct sandbox_clk_priv
*priv
= dev_get_priv(clk
->dev
);
22 if (clk
->id
>= SANDBOX_CLK_ID_COUNT
)
25 return priv
->rate
[clk
->id
];
28 static ulong
sandbox_clk_set_rate(struct clk
*clk
, ulong rate
)
30 struct sandbox_clk_priv
*priv
= dev_get_priv(clk
->dev
);
33 if (clk
->id
>= SANDBOX_CLK_ID_COUNT
)
39 old_rate
= priv
->rate
[clk
->id
];
40 priv
->rate
[clk
->id
] = rate
;
45 static int sandbox_clk_enable(struct clk
*clk
)
47 struct sandbox_clk_priv
*priv
= dev_get_priv(clk
->dev
);
49 if (clk
->id
>= SANDBOX_CLK_ID_COUNT
)
52 priv
->enabled
[clk
->id
] = true;
57 static int sandbox_clk_disable(struct clk
*clk
)
59 struct sandbox_clk_priv
*priv
= dev_get_priv(clk
->dev
);
61 if (clk
->id
>= SANDBOX_CLK_ID_COUNT
)
64 priv
->enabled
[clk
->id
] = false;
69 static struct clk_ops sandbox_clk_ops
= {
70 .get_rate
= sandbox_clk_get_rate
,
71 .set_rate
= sandbox_clk_set_rate
,
72 .enable
= sandbox_clk_enable
,
73 .disable
= sandbox_clk_disable
,
76 static const struct udevice_id sandbox_clk_ids
[] = {
77 { .compatible
= "sandbox,clk" },
81 U_BOOT_DRIVER(clk_sandbox
) = {
82 .name
= "clk_sandbox",
84 .of_match
= sandbox_clk_ids
,
85 .ops
= &sandbox_clk_ops
,
86 .priv_auto_alloc_size
= sizeof(struct sandbox_clk_priv
),
89 ulong
sandbox_clk_query_rate(struct udevice
*dev
, int id
)
91 struct sandbox_clk_priv
*priv
= dev_get_priv(dev
);
93 if (id
< 0 || id
>= SANDBOX_CLK_ID_COUNT
)
96 return priv
->rate
[id
];
99 int sandbox_clk_query_enable(struct udevice
*dev
, int id
)
101 struct sandbox_clk_priv
*priv
= dev_get_priv(dev
);
103 if (id
< 0 || id
>= SANDBOX_CLK_ID_COUNT
)
106 return priv
->enabled
[id
];