ep93xx-restart.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Cirrus EP93xx SoC reset driver
  4. *
  5. * Copyright (C) 2021 Nikita Shubin <nikita.shubin@maquefel.me>
  6. */
  7. #include <linux/bits.h>
  8. #include <linux/container_of.h>
  9. #include <linux/delay.h>
  10. #include <linux/errno.h>
  11. #include <linux/mfd/syscon.h>
  12. #include <linux/module.h>
  13. #include <linux/mod_devicetable.h>
  14. #include <linux/notifier.h>
  15. #include <linux/reboot.h>
  16. #include <linux/slab.h>
  17. #include <linux/soc/cirrus/ep93xx.h>
  18. #define EP93XX_SYSCON_DEVCFG 0x80
  19. #define EP93XX_SYSCON_DEVCFG_SWRST BIT(31)
  20. struct ep93xx_restart {
  21. struct ep93xx_regmap_adev *aux_dev;
  22. struct notifier_block restart_handler;
  23. };
  24. static int ep93xx_restart_handle(struct notifier_block *this,
  25. unsigned long mode, void *cmd)
  26. {
  27. struct ep93xx_restart *priv =
  28. container_of(this, struct ep93xx_restart, restart_handler);
  29. struct ep93xx_regmap_adev *aux = priv->aux_dev;
  30. /* Issue the reboot */
  31. aux->update_bits(aux->map, aux->lock, EP93XX_SYSCON_DEVCFG,
  32. EP93XX_SYSCON_DEVCFG_SWRST, EP93XX_SYSCON_DEVCFG_SWRST);
  33. aux->update_bits(aux->map, aux->lock, EP93XX_SYSCON_DEVCFG,
  34. EP93XX_SYSCON_DEVCFG_SWRST, 0);
  35. return NOTIFY_DONE;
  36. }
  37. static int ep93xx_reboot_probe(struct auxiliary_device *adev,
  38. const struct auxiliary_device_id *id)
  39. {
  40. struct ep93xx_regmap_adev *rdev = to_ep93xx_regmap_adev(adev);
  41. struct device *dev = &adev->dev;
  42. struct ep93xx_restart *priv;
  43. int err;
  44. if (!rdev->update_bits)
  45. return -ENODEV;
  46. priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
  47. if (!priv)
  48. return -ENOMEM;
  49. priv->aux_dev = rdev;
  50. priv->restart_handler.notifier_call = ep93xx_restart_handle;
  51. priv->restart_handler.priority = 128;
  52. err = register_restart_handler(&priv->restart_handler);
  53. if (err)
  54. return dev_err_probe(dev, err, "can't register restart notifier\n");
  55. return 0;
  56. }
  57. static const struct auxiliary_device_id ep93xx_reboot_ids[] = {
  58. {
  59. .name = "soc_ep93xx.reset-ep93xx",
  60. },
  61. { /* sentinel */ }
  62. };
  63. MODULE_DEVICE_TABLE(auxiliary, ep93xx_reboot_ids);
  64. static struct auxiliary_driver ep93xx_reboot_driver = {
  65. .probe = ep93xx_reboot_probe,
  66. .id_table = ep93xx_reboot_ids,
  67. };
  68. module_auxiliary_driver(ep93xx_reboot_driver);