xgene-reboot.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. /*
  2. * AppliedMicro X-Gene SoC Reboot Driver
  3. *
  4. * Copyright (c) 2013, Applied Micro Circuits Corporation
  5. * Author: Feng Kan <fkan@apm.com>
  6. * Author: Loc Ho <lho@apm.com>
  7. *
  8. * This program is free software; you can redistribute it and/or
  9. * modify it under the terms of the GNU General Public License as
  10. * published by the Free Software Foundation; either version 2 of
  11. * the License, or (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program; if not, write to the Free Software
  20. * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
  21. * MA 02111-1307 USA
  22. *
  23. * This driver provides system reboot functionality for APM X-Gene SoC.
  24. * For system shutdown, this is board specify. If a board designer
  25. * implements GPIO shutdown, use the gpio-poweroff.c driver.
  26. */
  27. #include <linux/io.h>
  28. #include <linux/of_device.h>
  29. #include <linux/of_address.h>
  30. #include <linux/platform_device.h>
  31. #include <linux/stat.h>
  32. #include <linux/slab.h>
  33. #include <asm/system_misc.h>
  34. struct xgene_reboot_context {
  35. struct platform_device *pdev;
  36. void *csr;
  37. u32 mask;
  38. };
  39. static struct xgene_reboot_context *xgene_restart_ctx;
  40. static void xgene_restart(char str, const char *cmd)
  41. {
  42. struct xgene_reboot_context *ctx = xgene_restart_ctx;
  43. unsigned long timeout;
  44. /* Issue the reboot */
  45. if (ctx)
  46. writel(ctx->mask, ctx->csr);
  47. timeout = jiffies + HZ;
  48. while (time_before(jiffies, timeout))
  49. cpu_relax();
  50. dev_emerg(&ctx->pdev->dev, "Unable to restart system\n");
  51. }
  52. static int xgene_reboot_probe(struct platform_device *pdev)
  53. {
  54. struct xgene_reboot_context *ctx;
  55. ctx = devm_kzalloc(&pdev->dev, sizeof(*ctx), GFP_KERNEL);
  56. if (!ctx) {
  57. dev_err(&pdev->dev, "out of memory for context\n");
  58. return -ENODEV;
  59. }
  60. ctx->csr = of_iomap(pdev->dev.of_node, 0);
  61. if (!ctx->csr) {
  62. devm_kfree(&pdev->dev, ctx);
  63. dev_err(&pdev->dev, "can not map resource\n");
  64. return -ENODEV;
  65. }
  66. if (of_property_read_u32(pdev->dev.of_node, "mask", &ctx->mask))
  67. ctx->mask = 0xFFFFFFFF;
  68. ctx->pdev = pdev;
  69. arm_pm_restart = xgene_restart;
  70. xgene_restart_ctx = ctx;
  71. return 0;
  72. }
  73. static struct of_device_id xgene_reboot_of_match[] = {
  74. { .compatible = "apm,xgene-reboot" },
  75. {}
  76. };
  77. static struct platform_driver xgene_reboot_driver = {
  78. .probe = xgene_reboot_probe,
  79. .driver = {
  80. .name = "xgene-reboot",
  81. .of_match_table = xgene_reboot_of_match,
  82. },
  83. };
  84. static int __init xgene_reboot_init(void)
  85. {
  86. return platform_driver_register(&xgene_reboot_driver);
  87. }
  88. device_initcall(xgene_reboot_init);