axxia-reset.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Reset driver for Axxia devices
  4. *
  5. * Copyright (C) 2014 LSI
  6. */
  7. #include <linux/init.h>
  8. #include <linux/err.h>
  9. #include <linux/io.h>
  10. #include <linux/kernel.h>
  11. #include <linux/mfd/syscon.h>
  12. #include <linux/module.h>
  13. #include <linux/notifier.h>
  14. #include <linux/of.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/reboot.h>
  17. #include <linux/regmap.h>
  18. #define SC_CRIT_WRITE_KEY 0x1000
  19. #define SC_LATCH_ON_RESET 0x1004
  20. #define SC_RESET_CONTROL 0x1008
  21. #define RSTCTL_RST_ZERO (1<<3)
  22. #define RSTCTL_RST_FAB (1<<2)
  23. #define RSTCTL_RST_CHIP (1<<1)
  24. #define RSTCTL_RST_SYS (1<<0)
  25. #define SC_EFUSE_INT_STATUS 0x180c
  26. #define EFUSE_READ_DONE (1<<31)
  27. static int axxia_restart_handler(struct sys_off_data *data)
  28. {
  29. struct regmap *syscon = data->cb_data;
  30. /* Access Key (0xab) */
  31. regmap_write(syscon, SC_CRIT_WRITE_KEY, 0xab);
  32. /* Select internal boot from 0xffff0000 */
  33. regmap_write(syscon, SC_LATCH_ON_RESET, 0x00000040);
  34. /* Assert ResetReadDone (to avoid hanging in boot ROM) */
  35. regmap_write(syscon, SC_EFUSE_INT_STATUS, EFUSE_READ_DONE);
  36. /* Assert chip reset */
  37. regmap_update_bits(syscon, SC_RESET_CONTROL,
  38. RSTCTL_RST_CHIP, RSTCTL_RST_CHIP);
  39. return NOTIFY_DONE;
  40. }
  41. static int axxia_reset_probe(struct platform_device *pdev)
  42. {
  43. struct device *dev = &pdev->dev;
  44. struct regmap *syscon;
  45. int err;
  46. syscon = syscon_regmap_lookup_by_phandle(dev->of_node, "syscon");
  47. if (IS_ERR(syscon)) {
  48. pr_err("%pOFn: syscon lookup failed\n", dev->of_node);
  49. return PTR_ERR(syscon);
  50. }
  51. err = devm_register_sys_off_handler(&pdev->dev, SYS_OFF_MODE_RESTART,
  52. 128, axxia_restart_handler, syscon);
  53. if (err)
  54. dev_err(dev, "cannot register restart handler (err=%d)\n", err);
  55. return err;
  56. }
  57. static const struct of_device_id of_axxia_reset_match[] = {
  58. { .compatible = "lsi,axm55xx-reset", },
  59. {},
  60. };
  61. MODULE_DEVICE_TABLE(of, of_axxia_reset_match);
  62. static struct platform_driver axxia_reset_driver = {
  63. .probe = axxia_reset_probe,
  64. .driver = {
  65. .name = "axxia-reset",
  66. .of_match_table = of_match_ptr(of_axxia_reset_match),
  67. },
  68. };
  69. builtin_platform_driver(axxia_reset_driver);