blob: 8c22ed2f43d4a6f46cd04ff12040a4aa5eaa3744 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Álvaro Fernández Rojasc35611c2017-05-07 20:13:01 +02002/*
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>
Álvaro Fernández Rojasc35611c2017-05-07 20:13:01 +02007 */
8
9#include <common.h>
10#include <clk-uclass.h>
11#include <dm.h>
12#include <errno.h>
13#include <asm/io.h>
Simon Glass4dcacfc2020-05-10 11:40:13 -060014#include <linux/bitops.h>
Álvaro Fernández Rojasc35611c2017-05-07 20:13:01 +020015
16#define MAX_CLKS 32
17
18struct bcm6345_clk_priv {
19 void __iomem *regs;
20};
21
22static 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
34static 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
46static struct clk_ops bcm6345_clk_ops = {
47 .disable = bcm6345_clk_disable,
48 .enable = bcm6345_clk_enable,
49};
50
51static const struct udevice_id bcm6345_clk_ids[] = {
52 { .compatible = "brcm,bcm6345-clk" },
53 { /* sentinel */ }
54};
55
56static int bcm63xx_clk_probe(struct udevice *dev)
57{
58 struct bcm6345_clk_priv *priv = dev_get_priv(dev);
Álvaro Fernández Rojasc35611c2017-05-07 20:13:01 +020059
Álvaro Fernández Rojasdf3bf642018-03-22 19:39:30 +010060 priv->regs = dev_remap_addr(dev);
61 if (!priv->regs)
Álvaro Fernández Rojasc35611c2017-05-07 20:13:01 +020062 return -EINVAL;
63
Álvaro Fernández Rojasc35611c2017-05-07 20:13:01 +020064 return 0;
65}
66
67U_BOOT_DRIVER(clk_bcm6345) = {
68 .name = "clk_bcm6345",
69 .id = UCLASS_CLK,
70 .of_match = bcm6345_clk_ids,
71 .ops = &bcm6345_clk_ops,
72 .probe = bcm63xx_clk_probe,
Simon Glass8a2b47f2020-12-03 16:55:17 -070073 .priv_auto = sizeof(struct bcm6345_clk_priv),
Álvaro Fernández Rojasc35611c2017-05-07 20:13:01 +020074};