summaryrefslogtreecommitdiffstats
path: root/drivers/clk/bcm/clk-bcm2835-aux.c
blob: b4636b850e83cd292543569d26bf325eec1b34ce (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
// SPDX-License-Identifier: GPL-2.0+
/*
 * Copyright (C) 2015 Broadcom
 */

#include <linux/clk.h>
#include <io.h>
#include <of_address.h>
#include <driver.h>
#include <init.h>
#include <dt-bindings/clock/bcm2835-aux.h>

#define BCM2835_AUXIRQ		0x00
#define BCM2835_AUXENB		0x04

static int bcm2835_aux_clk_probe(struct device_d *dev)
{
	struct clk_hw_onecell_data *onecell;
	const char *parent;
	struct clk *parent_clk;
	void __iomem *reg, *gate;

	parent_clk = clk_get(dev, NULL);
	if (IS_ERR(parent_clk))
		return PTR_ERR(parent_clk);
	parent = __clk_get_name(parent_clk);

	reg = of_iomap(dev->of_node, 0);
	if (!reg)
		return -ENOMEM;

	onecell = kmalloc(struct_size(onecell, hws, BCM2835_AUX_CLOCK_COUNT),
			  GFP_KERNEL);
	if (!onecell)
		return -ENOMEM;
	onecell->num = BCM2835_AUX_CLOCK_COUNT;

	gate = reg + BCM2835_AUXENB;
	onecell->hws[BCM2835_AUX_CLOCK_UART] =
		clk_hw_register_gate(dev, "aux_uart", parent, 0, gate, 0, 0, NULL);

	onecell->hws[BCM2835_AUX_CLOCK_SPI1] =
		clk_hw_register_gate(dev, "aux_spi1", parent, 0, gate, 1, 0, NULL);

	onecell->hws[BCM2835_AUX_CLOCK_SPI2] =
		clk_hw_register_gate(dev, "aux_spi2", parent, 0, gate, 2, 0, NULL);

	return of_clk_add_hw_provider(dev->of_node, of_clk_hw_onecell_get,
				      onecell);
}

static const struct of_device_id bcm2835_aux_clk_of_match[] = {
	{ .compatible = "brcm,bcm2835-aux", },
	{},
};

static struct driver_d bcm2835_aux_clk_driver = {
	.name = "bcm2835-aux-clk",
	.of_compatible = bcm2835_aux_clk_of_match,
	.probe          = bcm2835_aux_clk_probe,
};
core_platform_driver(bcm2835_aux_clk_driver);

MODULE_AUTHOR("Eric Anholt <eric@anholt.net>");
MODULE_DESCRIPTION("BCM2835 auxiliary peripheral clock driver");
MODULE_LICENSE("GPL");