xref: /openbmc/u-boot/drivers/clk/clk_bcm6345.c (revision 679590eb)
1 /*
2  * Copyright (C) 2017 Álvaro Fernández Rojas <noltari@gmail.com>
3  *
4  * Derived from linux/arch/mips/bcm63xx/clk.c:
5  *	Copyright (C) 2008 Maxime Bizon <mbizon@freebox.fr>
6  *
7  * SPDX-License-Identifier:	GPL-2.0+
8  */
9 
10 #include <common.h>
11 #include <clk-uclass.h>
12 #include <dm.h>
13 #include <errno.h>
14 #include <asm/io.h>
15 
16 #define MAX_CLKS	32
17 
18 struct bcm6345_clk_priv {
19 	void __iomem *regs;
20 };
21 
22 static int bcm6345_clk_enable(struct clk *clk)
23 {
24 	struct bcm6345_clk_priv *priv = dev_get_priv(clk->dev);
25 
26 	if (clk->id >= MAX_CLKS)
27 		return -EINVAL;
28 
29 	setbits_be32(priv->regs, BIT(clk->id));
30 
31 	return 0;
32 }
33 
34 static int bcm6345_clk_disable(struct clk *clk)
35 {
36 	struct bcm6345_clk_priv *priv = dev_get_priv(clk->dev);
37 
38 	if (clk->id >= MAX_CLKS)
39 		return -EINVAL;
40 
41 	clrbits_be32(priv->regs, BIT(clk->id));
42 
43 	return 0;
44 }
45 
46 static struct clk_ops bcm6345_clk_ops = {
47 	.disable = bcm6345_clk_disable,
48 	.enable = bcm6345_clk_enable,
49 };
50 
51 static const struct udevice_id bcm6345_clk_ids[] = {
52 	{ .compatible = "brcm,bcm6345-clk" },
53 	{ /* sentinel */ }
54 };
55 
56 static int bcm63xx_clk_probe(struct udevice *dev)
57 {
58 	struct bcm6345_clk_priv *priv = dev_get_priv(dev);
59 	fdt_addr_t addr;
60 	fdt_size_t size;
61 
62 	addr = devfdt_get_addr_size_index(dev, 0, &size);
63 	if (addr == FDT_ADDR_T_NONE)
64 		return -EINVAL;
65 
66 	priv->regs = ioremap(addr, size);
67 
68 	return 0;
69 }
70 
71 U_BOOT_DRIVER(clk_bcm6345) = {
72 	.name = "clk_bcm6345",
73 	.id = UCLASS_CLK,
74 	.of_match = bcm6345_clk_ids,
75 	.ops = &bcm6345_clk_ops,
76 	.probe = bcm63xx_clk_probe,
77 	.priv_auto_alloc_size = sizeof(struct bcm6345_clk_priv),
78 };
79