]>
Commit | Line | Data |
---|---|---|
83d290c5 | 1 | // SPDX-License-Identifier: GPL-2.0+ |
18393f70 ÁFR |
2 | /* |
3 | * Copyright (C) 2017 Álvaro Fernández Rojas <[email protected]> | |
4 | * | |
5 | * Derived from linux/arch/mips/bcm63xx/reset.c: | |
6 | * Copyright (C) 2012 Jonas Gorski <[email protected]> | |
18393f70 ÁFR |
7 | */ |
8 | ||
9 | #include <common.h> | |
10 | #include <dm.h> | |
11 | #include <errno.h> | |
f7ae49fc | 12 | #include <log.h> |
336d4615 | 13 | #include <malloc.h> |
18393f70 ÁFR |
14 | #include <reset-uclass.h> |
15 | #include <asm/io.h> | |
cd93d625 | 16 | #include <linux/bitops.h> |
c05ed00a | 17 | #include <linux/delay.h> |
18393f70 ÁFR |
18 | |
19 | #define MAX_RESETS 32 | |
20 | ||
21 | struct bcm6345_reset_priv { | |
22 | void __iomem *regs; | |
23 | }; | |
24 | ||
25 | static int bcm6345_reset_assert(struct reset_ctl *rst) | |
26 | { | |
27 | struct bcm6345_reset_priv *priv = dev_get_priv(rst->dev); | |
28 | ||
29 | clrbits_be32(priv->regs, BIT(rst->id)); | |
30 | mdelay(20); | |
31 | ||
32 | return 0; | |
33 | } | |
34 | ||
35 | static int bcm6345_reset_deassert(struct reset_ctl *rst) | |
36 | { | |
37 | struct bcm6345_reset_priv *priv = dev_get_priv(rst->dev); | |
38 | ||
39 | setbits_be32(priv->regs, BIT(rst->id)); | |
40 | mdelay(20); | |
41 | ||
42 | return 0; | |
43 | } | |
44 | ||
45 | static int bcm6345_reset_free(struct reset_ctl *rst) | |
46 | { | |
47 | return 0; | |
48 | } | |
49 | ||
50 | static int bcm6345_reset_request(struct reset_ctl *rst) | |
51 | { | |
52 | if (rst->id >= MAX_RESETS) | |
53 | return -EINVAL; | |
54 | ||
55 | return bcm6345_reset_assert(rst); | |
56 | } | |
57 | ||
58 | struct reset_ops bcm6345_reset_reset_ops = { | |
94474b25 | 59 | .rfree = bcm6345_reset_free, |
18393f70 ÁFR |
60 | .request = bcm6345_reset_request, |
61 | .rst_assert = bcm6345_reset_assert, | |
62 | .rst_deassert = bcm6345_reset_deassert, | |
63 | }; | |
64 | ||
65 | static const struct udevice_id bcm6345_reset_ids[] = { | |
66 | { .compatible = "brcm,bcm6345-reset" }, | |
67 | { /* sentinel */ } | |
68 | }; | |
69 | ||
70 | static int bcm6345_reset_probe(struct udevice *dev) | |
71 | { | |
72 | struct bcm6345_reset_priv *priv = dev_get_priv(dev); | |
18393f70 | 73 | |
56d4b706 ÁFR |
74 | priv->regs = dev_remap_addr(dev); |
75 | if (!priv->regs) | |
18393f70 ÁFR |
76 | return -EINVAL; |
77 | ||
18393f70 ÁFR |
78 | return 0; |
79 | } | |
80 | ||
81 | U_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 | }; |