blob: 753c1108a9605fda275d491ef2f4bc519daabec5 [file] [log] [blame]
Tom Rini83d290c2018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Álvaro Fernández Rojas18393f72017-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 Rojas18393f72017-05-03 15:10:21 +02007 */
8
9#include <common.h>
10#include <dm.h>
11#include <errno.h>
12#include <reset-uclass.h>
13#include <asm/io.h>
14
15#define MAX_RESETS 32
16
17struct bcm6345_reset_priv {
18 void __iomem *regs;
19};
20
21static int bcm6345_reset_assert(struct reset_ctl *rst)
22{
23 struct bcm6345_reset_priv *priv = dev_get_priv(rst->dev);
24
25 clrbits_be32(priv->regs, BIT(rst->id));
26 mdelay(20);
27
28 return 0;
29}
30
31static int bcm6345_reset_deassert(struct reset_ctl *rst)
32{
33 struct bcm6345_reset_priv *priv = dev_get_priv(rst->dev);
34
35 setbits_be32(priv->regs, BIT(rst->id));
36 mdelay(20);
37
38 return 0;
39}
40
41static int bcm6345_reset_free(struct reset_ctl *rst)
42{
43 return 0;
44}
45
46static int bcm6345_reset_request(struct reset_ctl *rst)
47{
48 if (rst->id >= MAX_RESETS)
49 return -EINVAL;
50
51 return bcm6345_reset_assert(rst);
52}
53
54struct reset_ops bcm6345_reset_reset_ops = {
55 .free = bcm6345_reset_free,
56 .request = bcm6345_reset_request,
57 .rst_assert = bcm6345_reset_assert,
58 .rst_deassert = bcm6345_reset_deassert,
59};
60
61static const struct udevice_id bcm6345_reset_ids[] = {
62 { .compatible = "brcm,bcm6345-reset" },
63 { /* sentinel */ }
64};
65
66static int bcm6345_reset_probe(struct udevice *dev)
67{
68 struct bcm6345_reset_priv *priv = dev_get_priv(dev);
Álvaro Fernández Rojas18393f72017-05-03 15:10:21 +020069
Álvaro Fernández Rojas56d4b702018-03-22 19:39:31 +010070 priv->regs = dev_remap_addr(dev);
71 if (!priv->regs)
Álvaro Fernández Rojas18393f72017-05-03 15:10:21 +020072 return -EINVAL;
73
Álvaro Fernández Rojas18393f72017-05-03 15:10:21 +020074 return 0;
75}
76
77U_BOOT_DRIVER(bcm6345_reset) = {
78 .name = "bcm6345-reset",
79 .id = UCLASS_RESET,
80 .of_match = bcm6345_reset_ids,
81 .ops = &bcm6345_reset_reset_ops,
82 .probe = bcm6345_reset_probe,
83 .priv_auto_alloc_size = sizeof(struct bcm6345_reset_priv),
84};