Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Álvaro Fernández Rojas | c35611c | 2017-05-07 20:13:01 +0200 | [diff] [blame] | 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> |
Álvaro Fernández Rojas | c35611c | 2017-05-07 20:13:01 +0200 | [diff] [blame] | 7 | */ |
| 8 | |
Álvaro Fernández Rojas | c35611c | 2017-05-07 20:13:01 +0200 | [diff] [blame] | 9 | #include <clk-uclass.h> |
| 10 | #include <dm.h> |
| 11 | #include <errno.h> |
| 12 | #include <asm/io.h> |
Simon Glass | 4dcacfc | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 13 | #include <linux/bitops.h> |
Álvaro Fernández Rojas | c35611c | 2017-05-07 20:13:01 +0200 | [diff] [blame] | 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); |
Álvaro Fernández Rojas | c35611c | 2017-05-07 20:13:01 +0200 | [diff] [blame] | 58 | |
Álvaro Fernández Rojas | df3bf64 | 2018-03-22 19:39:30 +0100 | [diff] [blame] | 59 | priv->regs = dev_remap_addr(dev); |
| 60 | if (!priv->regs) |
Álvaro Fernández Rojas | c35611c | 2017-05-07 20:13:01 +0200 | [diff] [blame] | 61 | return -EINVAL; |
| 62 | |
Álvaro Fernández Rojas | c35611c | 2017-05-07 20:13:01 +0200 | [diff] [blame] | 63 | return 0; |
| 64 | } |
| 65 | |
| 66 | U_BOOT_DRIVER(clk_bcm6345) = { |
| 67 | .name = "clk_bcm6345", |
| 68 | .id = UCLASS_CLK, |
| 69 | .of_match = bcm6345_clk_ids, |
| 70 | .ops = &bcm6345_clk_ops, |
| 71 | .probe = bcm63xx_clk_probe, |
Simon Glass | 8a2b47f | 2020-12-03 16:55:17 -0700 | [diff] [blame] | 72 | .priv_auto = sizeof(struct bcm6345_clk_priv), |
Álvaro Fernández Rojas | c35611c | 2017-05-07 20:13:01 +0200 | [diff] [blame] | 73 | }; |