fsl_pmc.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. /*
  2. * Suspend/resume support
  3. *
  4. * Copyright 2009 MontaVista Software, Inc.
  5. *
  6. * Author: Anton Vorontsov <avorontsov@ru.mvista.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. */
  13. #include <linux/init.h>
  14. #include <linux/types.h>
  15. #include <linux/errno.h>
  16. #include <linux/export.h>
  17. #include <linux/suspend.h>
  18. #include <linux/delay.h>
  19. #include <linux/device.h>
  20. #include <linux/of_platform.h>
  21. struct pmc_regs {
  22. __be32 devdisr;
  23. __be32 devdisr2;
  24. __be32 :32;
  25. __be32 :32;
  26. __be32 pmcsr;
  27. #define PMCSR_SLP (1 << 17)
  28. };
  29. static struct device *pmc_dev;
  30. static struct pmc_regs __iomem *pmc_regs;
  31. static int pmc_suspend_enter(suspend_state_t state)
  32. {
  33. int ret;
  34. setbits32(&pmc_regs->pmcsr, PMCSR_SLP);
  35. /* At this point, the CPU is asleep. */
  36. /* Upon resume, wait for SLP bit to be clear. */
  37. ret = spin_event_timeout((in_be32(&pmc_regs->pmcsr) & PMCSR_SLP) == 0,
  38. 10000, 10) ? 0 : -ETIMEDOUT;
  39. if (ret)
  40. dev_err(pmc_dev, "tired waiting for SLP bit to clear\n");
  41. return ret;
  42. }
  43. static int pmc_suspend_valid(suspend_state_t state)
  44. {
  45. if (state != PM_SUSPEND_STANDBY)
  46. return 0;
  47. return 1;
  48. }
  49. static const struct platform_suspend_ops pmc_suspend_ops = {
  50. .valid = pmc_suspend_valid,
  51. .enter = pmc_suspend_enter,
  52. };
  53. static int pmc_probe(struct platform_device *ofdev)
  54. {
  55. pmc_regs = of_iomap(ofdev->dev.of_node, 0);
  56. if (!pmc_regs)
  57. return -ENOMEM;
  58. pmc_dev = &ofdev->dev;
  59. suspend_set_ops(&pmc_suspend_ops);
  60. return 0;
  61. }
  62. static const struct of_device_id pmc_ids[] = {
  63. { .compatible = "fsl,mpc8548-pmc", },
  64. { .compatible = "fsl,mpc8641d-pmc", },
  65. { },
  66. };
  67. static struct platform_driver pmc_driver = {
  68. .driver = {
  69. .name = "fsl-pmc",
  70. .owner = THIS_MODULE,
  71. .of_match_table = pmc_ids,
  72. },
  73. .probe = pmc_probe,
  74. };
  75. static int __init pmc_init(void)
  76. {
  77. return platform_driver_register(&pmc_driver);
  78. }
  79. device_initcall(pmc_init);