summaryrefslogtreecommitdiff
path: root/drivers/clk/clk_sandbox.c
blob: 367130f8b76b12a662d41086932e165bfb185390 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
/*
 * (C) Copyright 2015 Google, Inc
 *
 * SPDX-License-Identifier:	GPL-2.0
 */

#include <common.h>
#include <clk.h>
#include <dm.h>
#include <errno.h>
#include <asm/test.h>

struct sandbox_clk_priv {
	ulong rate;
	ulong periph_rate[PERIPH_ID_COUNT];
};

static ulong sandbox_clk_get_rate(struct udevice *dev)
{
	struct sandbox_clk_priv *priv = dev_get_priv(dev);

	return priv->rate;
}

static ulong sandbox_clk_set_rate(struct udevice *dev, ulong rate)
{
	struct sandbox_clk_priv *priv = dev_get_priv(dev);

	if (!rate)
		return -EINVAL;
	priv->rate = rate;
	return 0;
}

static ulong sandbox_get_periph_rate(struct udevice *dev, int periph)
{
	struct sandbox_clk_priv *priv = dev_get_priv(dev);

	if (periph < PERIPH_ID_FIRST || periph >= PERIPH_ID_COUNT)
		return -EINVAL;
	return priv->periph_rate[periph];
}

static ulong sandbox_set_periph_rate(struct udevice *dev, int periph,
				     ulong rate)
{
	struct sandbox_clk_priv *priv = dev_get_priv(dev);
	ulong old_rate;

	if (periph < PERIPH_ID_FIRST || periph >= PERIPH_ID_COUNT)
		return -EINVAL;
	old_rate = priv->periph_rate[periph];
	priv->periph_rate[periph] = rate;

	return old_rate;
}

static int sandbox_clk_probe(struct udevice *dev)
{
	struct sandbox_clk_priv *priv = dev_get_priv(dev);

	priv->rate = SANDBOX_CLK_RATE;

	return 0;
}

static struct clk_ops sandbox_clk_ops = {
	.get_rate	= sandbox_clk_get_rate,
	.set_rate	= sandbox_clk_set_rate,
	.get_periph_rate = sandbox_get_periph_rate,
	.set_periph_rate = sandbox_set_periph_rate,
};

static const struct udevice_id sandbox_clk_ids[] = {
	{ .compatible = "sandbox,clk" },
	{ }
};

U_BOOT_DRIVER(clk_sandbox) = {
	.name		= "clk_sandbox",
	.id		= UCLASS_CLK,
	.of_match	= sandbox_clk_ids,
	.ops		= &sandbox_clk_ops,
	.priv_auto_alloc_size = sizeof(struct sandbox_clk_priv),
	.probe		= sandbox_clk_probe,
};