brcm-kona-reset.c 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /*
  2. * Copyright (C) 2016 Broadcom
  3. *
  4. * This program is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU General Public License as
  6. * published by the Free Software Foundation version 2.
  7. *
  8. * This program is distributed "as is" WITHOUT ANY WARRANTY of any
  9. * kind, whether express or implied; without even the implied warranty
  10. * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. * GNU General Public License for more details.
  12. */
  13. #include <linux/io.h>
  14. #include <linux/of_address.h>
  15. #include <linux/of_platform.h>
  16. #include <linux/reboot.h>
  17. #define RSTMGR_REG_WR_ACCESS_OFFSET 0
  18. #define RSTMGR_REG_CHIP_SOFT_RST_OFFSET 4
  19. #define RSTMGR_WR_PASSWORD 0xa5a5
  20. #define RSTMGR_WR_PASSWORD_SHIFT 8
  21. #define RSTMGR_WR_ACCESS_ENABLE 1
  22. static void __iomem *kona_reset_base;
  23. static int kona_reset_handler(struct notifier_block *this,
  24. unsigned long mode, void *cmd)
  25. {
  26. /*
  27. * A soft reset is triggered by writing a 0 to bit 0 of the soft reset
  28. * register. To write to that register we must first write the password
  29. * and the enable bit in the write access enable register.
  30. */
  31. writel((RSTMGR_WR_PASSWORD << RSTMGR_WR_PASSWORD_SHIFT) |
  32. RSTMGR_WR_ACCESS_ENABLE,
  33. kona_reset_base + RSTMGR_REG_WR_ACCESS_OFFSET);
  34. writel(0, kona_reset_base + RSTMGR_REG_CHIP_SOFT_RST_OFFSET);
  35. return NOTIFY_DONE;
  36. }
  37. static struct notifier_block kona_reset_nb = {
  38. .notifier_call = kona_reset_handler,
  39. .priority = 128,
  40. };
  41. static int kona_reset_probe(struct platform_device *pdev)
  42. {
  43. struct resource *res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  44. kona_reset_base = devm_ioremap_resource(&pdev->dev, res);
  45. if (IS_ERR(kona_reset_base))
  46. return PTR_ERR(kona_reset_base);
  47. return register_restart_handler(&kona_reset_nb);
  48. }
  49. static const struct of_device_id of_match[] = {
  50. { .compatible = "brcm,bcm21664-resetmgr" },
  51. {},
  52. };
  53. static struct platform_driver bcm_kona_reset_driver = {
  54. .probe = kona_reset_probe,
  55. .driver = {
  56. .name = "brcm-kona-reset",
  57. .of_match_table = of_match,
  58. },
  59. };
  60. builtin_platform_driver(bcm_kona_reset_driver);