Tom Rini | 83d290c | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0+ |
Álvaro Fernández Rojas | 5357eb9 | 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 | 5357eb9 | 2017-05-07 20:13:01 +0200 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <common.h> |
| 10 | #include <clk-uclass.h> |
| 11 | #include <dm.h> |
| 12 | #include <errno.h> |
| 13 | #include <asm/io.h> |
Simon Glass | cd93d62 | 2020-05-10 11:40:13 -0600 | [diff] [blame] | 14 | #include <linux/bitops.h> |
Álvaro Fernández Rojas | 5357eb9 | 2017-05-07 20:13:01 +0200 | [diff] [blame] | 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); |
Álvaro Fernández Rojas | 5357eb9 | 2017-05-07 20:13:01 +0200 | [diff] [blame] | 59 | |
Álvaro Fernández Rojas | 2902997 | 2018-03-22 19:39:30 +0100 | [diff] [blame] | 60 | priv->regs = dev_remap_addr(dev); |
| 61 | if (!priv->regs) |
Álvaro Fernández Rojas | 5357eb9 | 2017-05-07 20:13:01 +0200 | [diff] [blame] | 62 | return -EINVAL; |
| 63 | |
Álvaro Fernández Rojas | 5357eb9 | 2017-05-07 20:13:01 +0200 | [diff] [blame] | 64 | return 0; |
| 65 | } |
| 66 | |
| 67 | U_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, |
| 73 | .priv_auto_alloc_size = sizeof(struct bcm6345_clk_priv), |
| 74 | }; |