brcmstb-reboot.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  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/of_address.h>
  19. #include <linux/of_irq.h>
  20. #include <linux/of_platform.h>
  21. #include <linux/platform_device.h>
  22. #include <linux/printk.h>
  23. #include <linux/reboot.h>
  24. #include <linux/regmap.h>
  25. #include <linux/smp.h>
  26. #include <linux/mfd/syscon.h>
  27. #include <asm/system_misc.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 void brcmstb_reboot(enum reboot_mode mode, const char *cmd)
  34. {
  35. int rc;
  36. u32 tmp;
  37. rc = regmap_write(regmap, rst_src_en, 1);
  38. if (rc) {
  39. pr_err("failed to write rst_src_en (%d)\n", rc);
  40. return;
  41. }
  42. rc = regmap_read(regmap, rst_src_en, &tmp);
  43. if (rc) {
  44. pr_err("failed to read rst_src_en (%d)\n", rc);
  45. return;
  46. }
  47. rc = regmap_write(regmap, sw_mstr_rst, 1);
  48. if (rc) {
  49. pr_err("failed to write sw_mstr_rst (%d)\n", rc);
  50. return;
  51. }
  52. rc = regmap_read(regmap, sw_mstr_rst, &tmp);
  53. if (rc) {
  54. pr_err("failed to read sw_mstr_rst (%d)\n", rc);
  55. return;
  56. }
  57. while (1)
  58. ;
  59. }
  60. static int brcmstb_reboot_probe(struct platform_device *pdev)
  61. {
  62. int rc;
  63. struct device_node *np = pdev->dev.of_node;
  64. regmap = syscon_regmap_lookup_by_phandle(np, "syscon");
  65. if (IS_ERR(regmap)) {
  66. pr_err("failed to get syscon phandle\n");
  67. return -EINVAL;
  68. }
  69. rc = of_property_read_u32_index(np, "syscon", RESET_SOURCE_ENABLE_REG,
  70. &rst_src_en);
  71. if (rc) {
  72. pr_err("can't get rst_src_en offset (%d)\n", rc);
  73. return -EINVAL;
  74. }
  75. rc = of_property_read_u32_index(np, "syscon", SW_MASTER_RESET_REG,
  76. &sw_mstr_rst);
  77. if (rc) {
  78. pr_err("can't get sw_mstr_rst offset (%d)\n", rc);
  79. return -EINVAL;
  80. }
  81. arm_pm_restart = brcmstb_reboot;
  82. return 0;
  83. }
  84. static const struct of_device_id of_match[] = {
  85. { .compatible = "brcm,brcmstb-reboot", },
  86. {},
  87. };
  88. static struct platform_driver brcmstb_reboot_driver = {
  89. .probe = brcmstb_reboot_probe,
  90. .driver = {
  91. .name = "brcmstb-reboot",
  92. .owner = THIS_MODULE,
  93. .of_match_table = of_match,
  94. },
  95. };
  96. static int __init brcmstb_reboot_init(void)
  97. {
  98. return platform_driver_probe(&brcmstb_reboot_driver,
  99. brcmstb_reboot_probe);
  100. }
  101. subsys_initcall(brcmstb_reboot_init);