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