blob: 6f140574216d4a59a7b836b5ea7baa4f92498df6 [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
Álvaro Fernández Rojas5161bd32017-05-03 15:10:21 +02009#include <dm.h>
10#include <errno.h>
Simon Glass0f2af882020-05-10 11:40:05 -060011#include <log.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>
Simon Glass4dcacfc2020-05-10 11:40:13 -060015#include <linux/bitops.h>
Simon Glassdbd79542020-05-10 11:40:11 -060016#include <linux/delay.h>
Álvaro Fernández Rojas5161bd32017-05-03 15:10:21 +020017
18#define MAX_RESETS 32
19
20struct bcm6345_reset_priv {
21 void __iomem *regs;
22};
23
24static int bcm6345_reset_assert(struct reset_ctl *rst)
25{
26 struct bcm6345_reset_priv *priv = dev_get_priv(rst->dev);
27
28 clrbits_be32(priv->regs, BIT(rst->id));
29 mdelay(20);
30
31 return 0;
32}
33
34static int bcm6345_reset_deassert(struct reset_ctl *rst)
35{
36 struct bcm6345_reset_priv *priv = dev_get_priv(rst->dev);
37
38 setbits_be32(priv->regs, BIT(rst->id));
39 mdelay(20);
40
41 return 0;
42}
43
Álvaro Fernández Rojas5161bd32017-05-03 15:10:21 +020044static int bcm6345_reset_request(struct reset_ctl *rst)
45{
46 if (rst->id >= MAX_RESETS)
47 return -EINVAL;
48
49 return bcm6345_reset_assert(rst);
50}
51
52struct reset_ops bcm6345_reset_reset_ops = {
Álvaro Fernández Rojas5161bd32017-05-03 15:10:21 +020053 .request = bcm6345_reset_request,
54 .rst_assert = bcm6345_reset_assert,
55 .rst_deassert = bcm6345_reset_deassert,
56};
57
58static const struct udevice_id bcm6345_reset_ids[] = {
59 { .compatible = "brcm,bcm6345-reset" },
60 { /* sentinel */ }
61};
62
63static int bcm6345_reset_probe(struct udevice *dev)
64{
65 struct bcm6345_reset_priv *priv = dev_get_priv(dev);
Álvaro Fernández Rojas5161bd32017-05-03 15:10:21 +020066
Álvaro Fernández Rojas15385322018-03-22 19:39:31 +010067 priv->regs = dev_remap_addr(dev);
68 if (!priv->regs)
Álvaro Fernández Rojas5161bd32017-05-03 15:10:21 +020069 return -EINVAL;
70
Álvaro Fernández Rojas5161bd32017-05-03 15:10:21 +020071 return 0;
72}
73
74U_BOOT_DRIVER(bcm6345_reset) = {
75 .name = "bcm6345-reset",
76 .id = UCLASS_RESET,
77 .of_match = bcm6345_reset_ids,
78 .ops = &bcm6345_reset_reset_ops,
79 .probe = bcm6345_reset_probe,
Simon Glass8a2b47f2020-12-03 16:55:17 -070080 .priv_auto = sizeof(struct bcm6345_reset_priv),
Álvaro Fernández Rojas5161bd32017-05-03 15:10:21 +020081};