xgene-reboot.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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.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 __iomem *csr;
  25. u32 mask;
  26. };
  27. static int xgene_restart_handler(struct sys_off_data *data)
  28. {
  29. struct xgene_reboot_context *ctx = data->cb_data;
  30. /* Issue the reboot */
  31. writel(ctx->mask, ctx->csr);
  32. mdelay(1000);
  33. dev_emerg(ctx->dev, "Unable to restart system\n");
  34. return NOTIFY_DONE;
  35. }
  36. static int xgene_reboot_probe(struct platform_device *pdev)
  37. {
  38. struct xgene_reboot_context *ctx;
  39. struct device *dev = &pdev->dev;
  40. int err;
  41. ctx = devm_kzalloc(dev, sizeof(*ctx), GFP_KERNEL);
  42. if (!ctx)
  43. return -ENOMEM;
  44. ctx->csr = devm_platform_ioremap_resource(pdev, 0);
  45. if (IS_ERR(ctx->csr)) {
  46. dev_err(dev, "can not map resource\n");
  47. return PTR_ERR(ctx->csr);
  48. }
  49. if (of_property_read_u32(dev->of_node, "mask", &ctx->mask))
  50. ctx->mask = 0xFFFFFFFF;
  51. ctx->dev = dev;
  52. err = devm_register_sys_off_handler(dev, SYS_OFF_MODE_RESTART, 128,
  53. xgene_restart_handler, ctx);
  54. if (err)
  55. dev_err(dev, "cannot register restart handler (err=%d)\n", err);
  56. return err;
  57. }
  58. static const struct of_device_id xgene_reboot_of_match[] = {
  59. { .compatible = "apm,xgene-reboot" },
  60. {}
  61. };
  62. static struct platform_driver xgene_reboot_driver = {
  63. .probe = xgene_reboot_probe,
  64. .driver = {
  65. .name = "xgene-reboot",
  66. .of_match_table = xgene_reboot_of_match,
  67. },
  68. };
  69. builtin_platform_driver(xgene_reboot_driver);