fsl_pmc.c 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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/suspend.h>
  17. #include <linux/delay.h>
  18. #include <linux/device.h>
  19. #include <linux/of_platform.h>
  20. struct pmc_regs {
  21. __be32 devdisr;
  22. __be32 devdisr2;
  23. __be32 :32;
  24. __be32 :32;
  25. __be32 pmcsr;
  26. #define PMCSR_SLP (1 << 17)
  27. };
  28. static struct device *pmc_dev;
  29. static struct pmc_regs __iomem *pmc_regs;
  30. static int pmc_suspend_enter(suspend_state_t state)
  31. {
  32. int ret;
  33. setbits32(&pmc_regs->pmcsr, PMCSR_SLP);
  34. /* At this point, the CPU is asleep. */
  35. /* Upon resume, wait for SLP bit to be clear. */
  36. ret = spin_event_timeout((in_be32(&pmc_regs->pmcsr) & PMCSR_SLP) == 0,
  37. 10000, 10) ? 0 : -ETIMEDOUT;
  38. if (ret)
  39. dev_err(pmc_dev, "tired waiting for SLP bit to clear\n");
  40. return ret;
  41. }
  42. static int pmc_suspend_valid(suspend_state_t state)
  43. {
  44. if (state != PM_SUSPEND_STANDBY)
  45. return 0;
  46. return 1;
  47. }
  48. static const struct platform_suspend_ops pmc_suspend_ops = {
  49. .valid = pmc_suspend_valid,
  50. .enter = pmc_suspend_enter,
  51. };
  52. static int pmc_probe(struct platform_device *ofdev)
  53. {
  54. pmc_regs = of_iomap(ofdev->dev.of_node, 0);
  55. if (!pmc_regs)
  56. return -ENOMEM;
  57. pmc_dev = &ofdev->dev;
  58. suspend_set_ops(&pmc_suspend_ops);
  59. return 0;
  60. }
  61. static const struct of_device_id pmc_ids[] = {
  62. { .compatible = "fsl,mpc8548-pmc", },
  63. { .compatible = "fsl,mpc8641d-pmc", },
  64. { },
  65. };
  66. static struct platform_driver pmc_driver = {
  67. .driver = {
  68. .name = "fsl-pmc",
  69. .owner = THIS_MODULE,
  70. .of_match_table = pmc_ids,
  71. },
  72. .probe = pmc_probe,
  73. };
  74. static int __init pmc_init(void)
  75. {
  76. return platform_driver_register(&pmc_driver);
  77. }
  78. device_initcall(pmc_init);