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>
28 #define BANK_INCREMENT 4
31 struct socfpga_reset_data
{
33 void __iomem
*membase
;
34 struct reset_controller_dev rcdev
;
37 static int socfpga_reset_assert(struct reset_controller_dev
*rcdev
,
40 struct socfpga_reset_data
*data
= container_of(rcdev
,
41 struct socfpga_reset_data
,
43 int bank
= id
/ BITS_PER_LONG
;
44 int offset
= id
% BITS_PER_LONG
;
48 spin_lock_irqsave(&data
->lock
, flags
);
50 reg
= readl(data
->membase
+ (bank
* BANK_INCREMENT
));
51 writel(reg
| BIT(offset
), data
->membase
+ (bank
* BANK_INCREMENT
));
52 spin_unlock_irqrestore(&data
->lock
, flags
);
57 static int socfpga_reset_deassert(struct reset_controller_dev
*rcdev
,
60 struct socfpga_reset_data
*data
= container_of(rcdev
,
61 struct socfpga_reset_data
,
64 int bank
= id
/ BITS_PER_LONG
;
65 int offset
= id
% BITS_PER_LONG
;
69 spin_lock_irqsave(&data
->lock
, flags
);
71 reg
= readl(data
->membase
+ (bank
* BANK_INCREMENT
));
72 writel(reg
& ~BIT(offset
), data
->membase
+ (bank
* BANK_INCREMENT
));
74 spin_unlock_irqrestore(&data
->lock
, flags
);
79 static int socfpga_reset_status(struct reset_controller_dev
*rcdev
,
82 struct socfpga_reset_data
*data
= container_of(rcdev
,
83 struct socfpga_reset_data
, rcdev
);
84 int bank
= id
/ BITS_PER_LONG
;
85 int offset
= id
% BITS_PER_LONG
;
88 reg
= readl(data
->membase
+ (bank
* BANK_INCREMENT
));
90 return !(reg
& BIT(offset
));
93 static const struct reset_control_ops socfpga_reset_ops
= {
94 .assert = socfpga_reset_assert
,
95 .deassert
= socfpga_reset_deassert
,
96 .status
= socfpga_reset_status
,
99 static int socfpga_reset_probe(struct platform_device
*pdev
)
101 struct socfpga_reset_data
*data
;
102 struct resource
*res
;
103 struct device
*dev
= &pdev
->dev
;
104 struct device_node
*np
= dev
->of_node
;
108 * The binding was mainlined without the required property.
109 * Do not continue, when we encounter an old DT.
111 if (!of_find_property(pdev
->dev
.of_node
, "#reset-cells", NULL
)) {
112 dev_err(&pdev
->dev
, "%pOF missing #reset-cells property\n",
117 data
= devm_kzalloc(&pdev
->dev
, sizeof(*data
), GFP_KERNEL
);
121 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
122 data
->membase
= devm_ioremap_resource(&pdev
->dev
, res
);
123 if (IS_ERR(data
->membase
))
124 return PTR_ERR(data
->membase
);
126 if (of_property_read_u32(np
, "altr,modrst-offset", &modrst_offset
)) {
127 dev_warn(dev
, "missing altr,modrst-offset property, assuming 0x10!\n");
128 modrst_offset
= 0x10;
130 data
->membase
+= modrst_offset
;
132 spin_lock_init(&data
->lock
);
134 data
->rcdev
.owner
= THIS_MODULE
;
135 data
->rcdev
.nr_resets
= NR_BANKS
* BITS_PER_LONG
;
136 data
->rcdev
.ops
= &socfpga_reset_ops
;
137 data
->rcdev
.of_node
= pdev
->dev
.of_node
;
139 return devm_reset_controller_register(dev
, &data
->rcdev
);
142 static const struct of_device_id socfpga_reset_dt_ids
[] = {
143 { .compatible
= "altr,rst-mgr", },
147 static struct platform_driver socfpga_reset_driver
= {
148 .probe
= socfpga_reset_probe
,
150 .name
= "socfpga-reset",
151 .of_match_table
= socfpga_reset_dt_ids
,
154 builtin_platform_driver(socfpga_reset_driver
);