brcm-kona-reset.c 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. // Copyright (C) 2016 Broadcom
  3. #include <linux/io.h>
  4. #include <linux/mod_devicetable.h>
  5. #include <linux/platform_device.h>
  6. #include <linux/reboot.h>
  7. #define RSTMGR_REG_WR_ACCESS_OFFSET 0
  8. #define RSTMGR_REG_CHIP_SOFT_RST_OFFSET 4
  9. #define RSTMGR_WR_PASSWORD 0xa5a5
  10. #define RSTMGR_WR_PASSWORD_SHIFT 8
  11. #define RSTMGR_WR_ACCESS_ENABLE 1
  12. static void __iomem *kona_reset_base;
  13. static int kona_reset_handler(struct sys_off_data *data)
  14. {
  15. /*
  16. * A soft reset is triggered by writing a 0 to bit 0 of the soft reset
  17. * register. To write to that register we must first write the password
  18. * and the enable bit in the write access enable register.
  19. */
  20. writel((RSTMGR_WR_PASSWORD << RSTMGR_WR_PASSWORD_SHIFT) |
  21. RSTMGR_WR_ACCESS_ENABLE,
  22. kona_reset_base + RSTMGR_REG_WR_ACCESS_OFFSET);
  23. writel(0, kona_reset_base + RSTMGR_REG_CHIP_SOFT_RST_OFFSET);
  24. return NOTIFY_DONE;
  25. }
  26. static int kona_reset_probe(struct platform_device *pdev)
  27. {
  28. kona_reset_base = devm_platform_ioremap_resource(pdev, 0);
  29. if (IS_ERR(kona_reset_base))
  30. return PTR_ERR(kona_reset_base);
  31. return devm_register_sys_off_handler(&pdev->dev, SYS_OFF_MODE_RESTART,
  32. 128, kona_reset_handler, NULL);
  33. }
  34. static const struct of_device_id of_match[] = {
  35. { .compatible = "brcm,bcm21664-resetmgr" },
  36. {},
  37. };
  38. static struct platform_driver bcm_kona_reset_driver = {
  39. .probe = kona_reset_probe,
  40. .driver = {
  41. .name = "brcm-kona-reset",
  42. .of_match_table = of_match,
  43. },
  44. };
  45. builtin_platform_driver(bcm_kona_reset_driver);