• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0+
2 /*
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>
7  */
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 
17 struct bcm6345_reset_priv {
18 	void __iomem *regs;
19 };
20 
bcm6345_reset_assert(struct reset_ctl * rst)21 static 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 
bcm6345_reset_deassert(struct reset_ctl * rst)31 static 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 
bcm6345_reset_free(struct reset_ctl * rst)41 static int bcm6345_reset_free(struct reset_ctl *rst)
42 {
43 	return 0;
44 }
45 
bcm6345_reset_request(struct reset_ctl * rst)46 static 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 
54 struct 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 
61 static const struct udevice_id bcm6345_reset_ids[] = {
62 	{ .compatible = "brcm,bcm6345-reset" },
63 	{ /* sentinel */ }
64 };
65 
bcm6345_reset_probe(struct udevice * dev)66 static int bcm6345_reset_probe(struct udevice *dev)
67 {
68 	struct bcm6345_reset_priv *priv = dev_get_priv(dev);
69 
70 	priv->regs = dev_remap_addr(dev);
71 	if (!priv->regs)
72 		return -EINVAL;
73 
74 	return 0;
75 }
76 
77 U_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 };
85