xgene-reboot.c 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * AppliedMicro X-Gene SoC Reboot Driver
  4. *
  5. * Copyright (c) 2013, Applied Micro Circuits Corporation
  6. * Author: Feng Kan <fkan@apm.com>
  7. * Author: Loc Ho <lho@apm.com>
  8. *
  9. * This driver provides system reboot functionality for APM X-Gene SoC.
  10. * For system shutdown, this is board specify. If a board designer
  11. * implements GPIO shutdown, use the gpio-poweroff.c driver.
  12. */
  13. #include <linux/delay.h>
  14. #include <linux/io.h>
  15. #include <linux/notifier.h>
  16. #include <linux/of_device.h>
  17. #include <linux/of_address.h>
  18. #include <linux/platform_device.h>
  19. #include <linux/reboot.h>
  20. #include <linux/stat.h>
  21. #include <linux/slab.h>
  22. struct xgene_reboot_context {
  23. struct device *dev;
  24. void *csr;
  25. u32 mask;
  26. struct notifier_block restart_handler;
  27. };
  28. static int xgene_restart_handler(struct notifier_block *this,
  29. unsigned long mode, void *cmd)
  30. {
  31. struct xgene_reboot_context *ctx =
  32. container_of(this, struct xgene_reboot_context,
  33. restart_handler);
  34. /* Issue the reboot */
  35. writel(ctx->mask, ctx->csr);
  36. mdelay(1000);
  37. dev_emerg(ctx->dev, "Unable to restart system\n");
  38. return NOTIFY_DONE;
  39. }
  40. static int xgene_reboot_probe(struct platform_device *pdev)
  41. {
  42. struct xgene_reboot_context *ctx;
  43. struct device *dev = &pdev->dev;
  44. int err;
  45. ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL);
  46. if (!ctx)
  47. return -ENOMEM;
  48. ctx->csr = of_iomap(dev->of_node, 0);
  49. if (!ctx->csr) {
  50. dev_err(dev, "can not map resource\n");
  51. return -ENODEV;
  52. }
  53. if (of_property_read_u32(dev->of_node, "mask", &ctx->mask))
  54. ctx->mask = 0xFFFFFFFF;
  55. ctx->dev = dev;
  56. ctx->restart_handler.notifier_call = xgene_restart_handler;
  57. ctx->restart_handler.priority = 128;
  58. err = register_restart_handler(&ctx->restart_handler);
  59. if (err) {
  60. iounmap(ctx->csr);
  61. dev_err(dev, "cannot register restart handler (err=%d)\n", err);
  62. }
  63. return err;
  64. }
  65. static const struct of_device_id xgene_reboot_of_match[] = {
  66. { .compatible = "apm,xgene-reboot" },
  67. {}
  68. };
  69. static struct platform_driver xgene_reboot_driver = {
  70. .probe = xgene_reboot_probe,
  71. .driver = {
  72. .name = "xgene-reboot",
  73. .of_match_table = xgene_reboot_of_match,
  74. },
  75. };
  76. static int __init xgene_reboot_init(void)
  77. {
  78. return platform_driver_register(&xgene_reboot_driver);
  79. }
  80. device_initcall(xgene_reboot_init);