blob: 367130f8b76b12a662d41086932e165bfb185390 [file] [log] [blame]
Simon Glass6a1c7ce2015-07-06 12:54:24 -06001/*
2 * (C) Copyright 2015 Google, Inc
3 *
4 * SPDX-License-Identifier: GPL-2.0
5 */
6
7#include <common.h>
8#include <clk.h>
9#include <dm.h>
10#include <errno.h>
11#include <asm/test.h>
12
13struct sandbox_clk_priv {
14 ulong rate;
15 ulong periph_rate[PERIPH_ID_COUNT];
16};
17
18static ulong sandbox_clk_get_rate(struct udevice *dev)
19{
20 struct sandbox_clk_priv *priv = dev_get_priv(dev);
21
22 return priv->rate;
23}
24
25static ulong sandbox_clk_set_rate(struct udevice *dev, ulong rate)
26{
27 struct sandbox_clk_priv *priv = dev_get_priv(dev);
28
29 if (!rate)
30 return -EINVAL;
31 priv->rate = rate;
32 return 0;
33}
34
Masahiro Yamada9e521262016-01-13 13:16:10 +090035static ulong sandbox_get_periph_rate(struct udevice *dev, int periph)
Simon Glass6a1c7ce2015-07-06 12:54:24 -060036{
37 struct sandbox_clk_priv *priv = dev_get_priv(dev);
38
39 if (periph < PERIPH_ID_FIRST || periph >= PERIPH_ID_COUNT)
40 return -EINVAL;
41 return priv->periph_rate[periph];
42}
43
Masahiro Yamada9e521262016-01-13 13:16:10 +090044static ulong sandbox_set_periph_rate(struct udevice *dev, int periph,
45 ulong rate)
Simon Glass6a1c7ce2015-07-06 12:54:24 -060046{
47 struct sandbox_clk_priv *priv = dev_get_priv(dev);
48 ulong old_rate;
49
50 if (periph < PERIPH_ID_FIRST || periph >= PERIPH_ID_COUNT)
51 return -EINVAL;
52 old_rate = priv->periph_rate[periph];
53 priv->periph_rate[periph] = rate;
54
55 return old_rate;
56}
57
58static int sandbox_clk_probe(struct udevice *dev)
59{
60 struct sandbox_clk_priv *priv = dev_get_priv(dev);
61
62 priv->rate = SANDBOX_CLK_RATE;
63
64 return 0;
65}
66
67static struct clk_ops sandbox_clk_ops = {
68 .get_rate = sandbox_clk_get_rate,
69 .set_rate = sandbox_clk_set_rate,
70 .get_periph_rate = sandbox_get_periph_rate,
71 .set_periph_rate = sandbox_set_periph_rate,
72};
73
74static const struct udevice_id sandbox_clk_ids[] = {
75 { .compatible = "sandbox,clk" },
76 { }
77};
78
79U_BOOT_DRIVER(clk_sandbox) = {
80 .name = "clk_sandbox",
81 .id = UCLASS_CLK,
82 .of_match = sandbox_clk_ids,
83 .ops = &sandbox_clk_ops,
84 .priv_auto_alloc_size = sizeof(struct sandbox_clk_priv),
85 .probe = sandbox_clk_probe,
86};