]> git.sur5r.net Git - u-boot/blob - drivers/clk/clk_sandbox.c
Merge branch 'master' of git://git.denx.de/u-boot-net
[u-boot] / drivers / clk / clk_sandbox.c
1 /*
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
13 struct sandbox_clk_priv {
14         ulong rate;
15         ulong periph_rate[PERIPH_ID_COUNT];
16 };
17
18 static 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
25 static 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
35 static ulong sandbox_get_periph_rate(struct udevice *dev, int periph)
36 {
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
44 static ulong sandbox_set_periph_rate(struct udevice *dev, int periph,
45                                      ulong rate)
46 {
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
58 static 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
67 static 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
74 static const struct udevice_id sandbox_clk_ids[] = {
75         { .compatible = "sandbox,clk" },
76         { }
77 };
78
79 U_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 };