2 * Socfpga Reset Controller Driver
4 * Copyright 2014 Steffen Trumtrar <s.trumtrar@pengutronix.de>
7 * Allwinner SoCs Reset Controller driver
9 * Copyright 2013 Maxime Ripard
11 * Maxime Ripard <maxime.ripard@free-electrons.com>
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License as published by
15 * the Free Software Foundation; either version 2 of the License, or
16 * (at your option) any later version.
19 #include <linux/err.h>
21 #include <linux/init.h>
23 #include <linux/platform_device.h>
24 #include <linux/reset-controller.h>
25 #include <linux/spinlock.h>
26 #include <linux/types.h>
30 struct socfpga_reset_data
{
32 void __iomem
*membase
;
33 struct reset_controller_dev rcdev
;
36 static int socfpga_reset_assert(struct reset_controller_dev
*rcdev
,
39 struct socfpga_reset_data
*data
= container_of(rcdev
,
40 struct socfpga_reset_data
,
42 int bank
= id
/ BITS_PER_LONG
;
43 int offset
= id
% BITS_PER_LONG
;
47 spin_lock_irqsave(&data
->lock
, flags
);
49 reg
= readl(data
->membase
+ (bank
* NR_BANKS
));
50 writel(reg
| BIT(offset
), data
->membase
+ (bank
* NR_BANKS
));
51 spin_unlock_irqrestore(&data
->lock
, flags
);
56 static int socfpga_reset_deassert(struct reset_controller_dev
*rcdev
,
59 struct socfpga_reset_data
*data
= container_of(rcdev
,
60 struct socfpga_reset_data
,
63 int bank
= id
/ BITS_PER_LONG
;
64 int offset
= id
% BITS_PER_LONG
;
68 spin_lock_irqsave(&data
->lock
, flags
);
70 reg
= readl(data
->membase
+ (bank
* NR_BANKS
));
71 writel(reg
& ~BIT(offset
), data
->membase
+ (bank
* NR_BANKS
));
73 spin_unlock_irqrestore(&data
->lock
, flags
);
78 static int socfpga_reset_status(struct reset_controller_dev
*rcdev
,
81 struct socfpga_reset_data
*data
= container_of(rcdev
,
82 struct socfpga_reset_data
, rcdev
);
83 int bank
= id
/ BITS_PER_LONG
;
84 int offset
= id
% BITS_PER_LONG
;
87 reg
= readl(data
->membase
+ (bank
* NR_BANKS
));
89 return !(reg
& BIT(offset
));
92 static const struct reset_control_ops socfpga_reset_ops
= {
93 .assert = socfpga_reset_assert
,
94 .deassert
= socfpga_reset_deassert
,
95 .status
= socfpga_reset_status
,
98 static int socfpga_reset_probe(struct platform_device
*pdev
)
100 struct socfpga_reset_data
*data
;
101 struct resource
*res
;
102 struct device
*dev
= &pdev
->dev
;
103 struct device_node
*np
= dev
->of_node
;
107 * The binding was mainlined without the required property.
108 * Do not continue, when we encounter an old DT.
110 if (!of_find_property(pdev
->dev
.of_node
, "#reset-cells", NULL
)) {
111 dev_err(&pdev
->dev
, "%s missing #reset-cells property\n",
112 pdev
->dev
.of_node
->full_name
);
116 data
= devm_kzalloc(&pdev
->dev
, sizeof(*data
), GFP_KERNEL
);
120 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
121 data
->membase
= devm_ioremap_resource(&pdev
->dev
, res
);
122 if (IS_ERR(data
->membase
))
123 return PTR_ERR(data
->membase
);
125 if (of_property_read_u32(np
, "altr,modrst-offset", &modrst_offset
)) {
126 dev_warn(dev
, "missing altr,modrst-offset property, assuming 0x10!\n");
127 modrst_offset
= 0x10;
129 data
->membase
+= modrst_offset
;
131 spin_lock_init(&data
->lock
);
133 data
->rcdev
.owner
= THIS_MODULE
;
134 data
->rcdev
.nr_resets
= NR_BANKS
* BITS_PER_LONG
;
135 data
->rcdev
.ops
= &socfpga_reset_ops
;
136 data
->rcdev
.of_node
= pdev
->dev
.of_node
;
138 return devm_reset_controller_register(dev
, &data
->rcdev
);
141 static const struct of_device_id socfpga_reset_dt_ids
[] = {
142 { .compatible
= "altr,rst-mgr", },
146 static struct platform_driver socfpga_reset_driver
= {
147 .probe
= socfpga_reset_probe
,
149 .name
= "socfpga-reset",
150 .of_match_table
= socfpga_reset_dt_ids
,
153 builtin_platform_driver(socfpga_reset_driver
);