1 // SPDX-License-Identifier: GPL-2.0+
3 * Cirrus EP93xx SoC reset driver
8 #include <linux/bits.h>
9 #include <linux/container_of.h>
10 #include <linux/delay.h>
11 #include <linux/errno.h>
12 #include <linux/mfd/syscon.h>
13 #include <linux/module.h>
14 #include <linux/mod_devicetable.h>
15 #include <linux/notifier.h>
16 #include <linux/reboot.h>
17 #include <linux/slab.h>
19 #include <linux/soc/cirrus/ep93xx.h>
21 #define EP93XX_SYSCON_DEVCFG 0x80
22 #define EP93XX_SYSCON_DEVCFG_SWRST BIT(31)
24 struct ep93xx_restart {
25 struct ep93xx_regmap_adev *aux_dev;
26 struct notifier_block restart_handler;
29 static int ep93xx_restart_handle(struct notifier_block *this,
30 unsigned long mode, void *cmd)
32 struct ep93xx_restart *priv =
33 container_of(this, struct ep93xx_restart, restart_handler);
34 struct ep93xx_regmap_adev *aux = priv->aux_dev;
36 /* Issue the reboot */
37 aux->update_bits(aux->map, aux->lock, EP93XX_SYSCON_DEVCFG,
38 EP93XX_SYSCON_DEVCFG_SWRST, EP93XX_SYSCON_DEVCFG_SWRST);
39 aux->update_bits(aux->map, aux->lock, EP93XX_SYSCON_DEVCFG,
40 EP93XX_SYSCON_DEVCFG_SWRST, 0);
45 static int ep93xx_reboot_probe(struct auxiliary_device *adev,
46 const struct auxiliary_device_id *id)
48 struct ep93xx_regmap_adev *rdev = to_ep93xx_regmap_adev(adev);
49 struct device *dev = &adev->dev;
50 struct ep93xx_restart *priv;
53 if (!rdev->update_bits)
56 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
62 priv->restart_handler.notifier_call = ep93xx_restart_handle;
63 priv->restart_handler.priority = 128;
65 err = register_restart_handler(&priv->restart_handler);
67 return dev_err_probe(dev, err, "can't register restart notifier\n");
72 static const struct auxiliary_device_id ep93xx_reboot_ids[] = {
74 .name = "soc_ep93xx.reset-ep93xx",
78 MODULE_DEVICE_TABLE(auxiliary, ep93xx_reboot_ids);
80 static struct auxiliary_driver ep93xx_reboot_driver = {
81 .probe = ep93xx_reboot_probe,
82 .id_table = ep93xx_reboot_ids,
84 module_auxiliary_driver(ep93xx_reboot_driver);