blob: 62b9563ce144b7ea66b0c3a0eb2f2c605efcda9d [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);
69 fdt_addr_t addr;
70 fdt_size_t size;
71
Simon Glassa821c4a2017-05-17 17:18:05 -060072 addr = devfdt_get_addr_size_index(dev, 0, &size);
Álvaro Fernández Rojas18393f72017-05-03 15:10:21 +020073 if (addr == FDT_ADDR_T_NONE)
74 return -EINVAL;
75
76 priv->regs = ioremap(addr, size);
77
78 return 0;
79}
80
81U_BOOT_DRIVER(bcm6345_reset) = {
82 .name = "bcm6345-reset",
83 .id = UCLASS_RESET,
84 .of_match = bcm6345_reset_ids,
85 .ops = &bcm6345_reset_reset_ops,
86 .probe = bcm6345_reset_probe,
87 .priv_auto_alloc_size = sizeof(struct bcm6345_reset_priv),
88};