blob: c1f1e7f70bf4fa5aefbb9839f8e153047b31ac0d [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Álvaro Fernández Rojas5161bd32017-05-03 15:10:21 +02002/*
3 * Copyright (C) 2017 Álvaro Fernández Rojas <noltari@gmail.com>
4 *
5 * Derived from linux/arch/mips/bcm63xx/reset.c:
6 * Copyright (C) 2012 Jonas Gorski <jonas.gorski@gmail.com>
Álvaro Fernández Rojas5161bd32017-05-03 15:10:21 +02007 */
8
9#include <common.h>
10#include <dm.h>
11#include <errno.h>
Simon Glass9bc15642020-02-03 07:36:16 -070012#include <malloc.h>
Álvaro Fernández Rojas5161bd32017-05-03 15:10:21 +020013#include <reset-uclass.h>
14#include <asm/io.h>
15
16#define MAX_RESETS 32
17
18struct bcm6345_reset_priv {
19 void __iomem *regs;
20};
21
22static int bcm6345_reset_assert(struct reset_ctl *rst)
23{
24 struct bcm6345_reset_priv *priv = dev_get_priv(rst->dev);
25
26 clrbits_be32(priv->regs, BIT(rst->id));
27 mdelay(20);
28
29 return 0;
30}
31
32static int bcm6345_reset_deassert(struct reset_ctl *rst)
33{
34 struct bcm6345_reset_priv *priv = dev_get_priv(rst->dev);
35
36 setbits_be32(priv->regs, BIT(rst->id));
37 mdelay(20);
38
39 return 0;
40}
41
42static int bcm6345_reset_free(struct reset_ctl *rst)
43{
44 return 0;
45}
46
47static int bcm6345_reset_request(struct reset_ctl *rst)
48{
49 if (rst->id >= MAX_RESETS)
50 return -EINVAL;
51
52 return bcm6345_reset_assert(rst);
53}
54
55struct reset_ops bcm6345_reset_reset_ops = {
Simon Glass1928cd42020-02-03 07:35:52 -070056 .rfree = bcm6345_reset_free,
Álvaro Fernández Rojas5161bd32017-05-03 15:10:21 +020057 .request = bcm6345_reset_request,
58 .rst_assert = bcm6345_reset_assert,
59 .rst_deassert = bcm6345_reset_deassert,
60};
61
62static const struct udevice_id bcm6345_reset_ids[] = {
63 { .compatible = "brcm,bcm6345-reset" },
64 { /* sentinel */ }
65};
66
67static int bcm6345_reset_probe(struct udevice *dev)
68{
69 struct bcm6345_reset_priv *priv = dev_get_priv(dev);
Álvaro Fernández Rojas5161bd32017-05-03 15:10:21 +020070
Álvaro Fernández Rojas15385322018-03-22 19:39:31 +010071 priv->regs = dev_remap_addr(dev);
72 if (!priv->regs)
Álvaro Fernández Rojas5161bd32017-05-03 15:10:21 +020073 return -EINVAL;
74
Álvaro Fernández Rojas5161bd32017-05-03 15:10:21 +020075 return 0;
76}
77
78U_BOOT_DRIVER(bcm6345_reset) = {
79 .name = "bcm6345-reset",
80 .id = UCLASS_RESET,
81 .of_match = bcm6345_reset_ids,
82 .ops = &bcm6345_reset_reset_ops,
83 .probe = bcm6345_reset_probe,
84 .priv_auto_alloc_size = sizeof(struct bcm6345_reset_priv),
85};