brcmstb-reboot.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. * Copyright (C) 2013 Broadcom Corporation
  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/device.h>
  14. #include <linux/errno.h>
  15. #include <linux/init.h>
  16. #include <linux/io.h>
  17. #include <linux/jiffies.h>
  18. #include <linux/notifier.h>
  19. #include <linux/of_address.h>
  20. #include <linux/of_irq.h>
  21. #include <linux/of_platform.h>
  22. #include <linux/platform_device.h>
  23. #include <linux/printk.h>
  24. #include <linux/reboot.h>
  25. #include <linux/regmap.h>
  26. #include <linux/smp.h>
  27. #include <linux/mfd/syscon.h>
  28. #define RESET_SOURCE_ENABLE_REG 1
  29. #define SW_MASTER_RESET_REG 2
  30. static struct regmap *regmap;
  31. static u32 rst_src_en;
  32. static u32 sw_mstr_rst;
  33. static int brcmstb_restart_handler(struct notifier_block *this,
  34. unsigned long mode, void *cmd)
  35. {
  36. int rc;
  37. u32 tmp;
  38. rc = regmap_write(regmap, rst_src_en, 1);
  39. if (rc) {
  40. pr_err("failed to write rst_src_en (%d)\n", rc);
  41. return NOTIFY_DONE;
  42. }
  43. rc = regmap_read(regmap, rst_src_en, &tmp);
  44. if (rc) {
  45. pr_err("failed to read rst_src_en (%d)\n", rc);
  46. return NOTIFY_DONE;
  47. }
  48. rc = regmap_write(regmap, sw_mstr_rst, 1);
  49. if (rc) {
  50. pr_err("failed to write sw_mstr_rst (%d)\n", rc);
  51. return NOTIFY_DONE;
  52. }
  53. rc = regmap_read(regmap, sw_mstr_rst, &tmp);
  54. if (rc) {
  55. pr_err("failed to read sw_mstr_rst (%d)\n", rc);
  56. return NOTIFY_DONE;
  57. }
  58. while (1)
  59. ;
  60. return NOTIFY_DONE;
  61. }
  62. static struct notifier_block brcmstb_restart_nb = {
  63. .notifier_call = brcmstb_restart_handler,
  64. .priority = 128,
  65. };
  66. static int brcmstb_reboot_probe(struct platform_device *pdev)
  67. {
  68. int rc;
  69. struct device_node *np = pdev->dev.of_node;
  70. regmap = syscon_regmap_lookup_by_phandle(np, "syscon");
  71. if (IS_ERR(regmap)) {
  72. pr_err("failed to get syscon phandle\n");
  73. return -EINVAL;
  74. }
  75. rc = of_property_read_u32_index(np, "syscon", RESET_SOURCE_ENABLE_REG,
  76. &rst_src_en);
  77. if (rc) {
  78. pr_err("can't get rst_src_en offset (%d)\n", rc);
  79. return -EINVAL;
  80. }
  81. rc = of_property_read_u32_index(np, "syscon", SW_MASTER_RESET_REG,
  82. &sw_mstr_rst);
  83. if (rc) {
  84. pr_err("can't get sw_mstr_rst offset (%d)\n", rc);
  85. return -EINVAL;
  86. }
  87. rc = register_restart_handler(&brcmstb_restart_nb);
  88. if (rc)
  89. dev_err(&pdev->dev,
  90. "cannot register restart handler (err=%d)\n", rc);
  91. return rc;
  92. }
  93. static const struct of_device_id of_match[] = {
  94. { .compatible = "brcm,brcmstb-reboot", },
  95. {},
  96. };
  97. static struct platform_driver brcmstb_reboot_driver = {
  98. .probe = brcmstb_reboot_probe,
  99. .driver = {
  100. .name = "brcmstb-reboot",
  101. .of_match_table = of_match,
  102. },
  103. };
  104. static int __init brcmstb_reboot_init(void)
  105. {
  106. return platform_driver_probe(&brcmstb_reboot_driver,
  107. brcmstb_reboot_probe);
  108. }
  109. subsys_initcall(brcmstb_reboot_init);