fsl_pmc.c 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Suspend/resume support
  4. *
  5. * Copyright 2009 MontaVista Software, Inc.
  6. *
  7. * Author: Anton Vorontsov <[email protected]>
  8. */
  9. #include <linux/init.h>
  10. #include <linux/types.h>
  11. #include <linux/errno.h>
  12. #include <linux/export.h>
  13. #include <linux/suspend.h>
  14. #include <linux/delay.h>
  15. #include <linux/device.h>
  16. #include <linux/of_address.h>
  17. #include <linux/of_platform.h>
  18. struct pmc_regs {
  19. __be32 devdisr;
  20. __be32 devdisr2;
  21. __be32 :32;
  22. __be32 :32;
  23. __be32 pmcsr;
  24. #define PMCSR_SLP (1 << 17)
  25. };
  26. static struct device *pmc_dev;
  27. static struct pmc_regs __iomem *pmc_regs;
  28. static int pmc_suspend_enter(suspend_state_t state)
  29. {
  30. int ret;
  31. setbits32(&pmc_regs->pmcsr, PMCSR_SLP);
  32. /* At this point, the CPU is asleep. */
  33. /* Upon resume, wait for SLP bit to be clear. */
  34. ret = spin_event_timeout((in_be32(&pmc_regs->pmcsr) & PMCSR_SLP) == 0,
  35. 10000, 10) ? 0 : -ETIMEDOUT;
  36. if (ret)
  37. dev_err(pmc_dev, "tired waiting for SLP bit to clear\n");
  38. return ret;
  39. }
  40. static int pmc_suspend_valid(suspend_state_t state)
  41. {
  42. if (state != PM_SUSPEND_STANDBY)
  43. return 0;
  44. return 1;
  45. }
  46. static const struct platform_suspend_ops pmc_suspend_ops = {
  47. .valid = pmc_suspend_valid,
  48. .enter = pmc_suspend_enter,
  49. };
  50. static int pmc_probe(struct platform_device *ofdev)
  51. {
  52. pmc_regs = of_iomap(ofdev->dev.of_node, 0);
  53. if (!pmc_regs)
  54. return -ENOMEM;
  55. pmc_dev = &ofdev->dev;
  56. suspend_set_ops(&pmc_suspend_ops);
  57. return 0;
  58. }
  59. static const struct of_device_id pmc_ids[] = {
  60. { .compatible = "fsl,mpc8548-pmc", },
  61. { .compatible = "fsl,mpc8641d-pmc", },
  62. { },
  63. };
  64. static struct platform_driver pmc_driver = {
  65. .driver = {
  66. .name = "fsl-pmc",
  67. .of_match_table = pmc_ids,
  68. },
  69. .probe = pmc_probe,
  70. };
  71. builtin_platform_driver(pmc_driver);