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