pm.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. * PXA250/210 Power Management Routines
  3. *
  4. * Original code for the SA11x0:
  5. * Copyright (c) 2001 Cliff Brake <cbrake@accelent.com>
  6. *
  7. * Modified for the PXA250 by Nicolas Pitre:
  8. * Copyright (c) 2002 Monta Vista Software, Inc.
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License.
  12. */
  13. #include <linux/init.h>
  14. #include <linux/module.h>
  15. #include <linux/suspend.h>
  16. #include <linux/errno.h>
  17. #include <linux/slab.h>
  18. #include <mach/pm.h>
  19. struct pxa_cpu_pm_fns *pxa_cpu_pm_fns;
  20. static unsigned long *sleep_save;
  21. int pxa_pm_enter(suspend_state_t state)
  22. {
  23. unsigned long sleep_save_checksum = 0, checksum = 0;
  24. int i;
  25. #ifdef CONFIG_IWMMXT
  26. /* force any iWMMXt context to ram **/
  27. if (elf_hwcap & HWCAP_IWMMXT)
  28. iwmmxt_task_disable(NULL);
  29. #endif
  30. /* skip registers saving for standby */
  31. if (state != PM_SUSPEND_STANDBY) {
  32. pxa_cpu_pm_fns->save(sleep_save);
  33. /* before sleeping, calculate and save a checksum */
  34. for (i = 0; i < pxa_cpu_pm_fns->save_count - 1; i++)
  35. sleep_save_checksum += sleep_save[i];
  36. }
  37. /* *** go zzz *** */
  38. pxa_cpu_pm_fns->enter(state);
  39. cpu_init();
  40. if (state != PM_SUSPEND_STANDBY) {
  41. /* after sleeping, validate the checksum */
  42. for (i = 0; i < pxa_cpu_pm_fns->save_count - 1; i++)
  43. checksum += sleep_save[i];
  44. /* if invalid, display message and wait for a hardware reset */
  45. if (checksum != sleep_save_checksum) {
  46. lubbock_set_hexled(0xbadbadc5);
  47. while (1)
  48. pxa_cpu_pm_fns->enter(state);
  49. }
  50. pxa_cpu_pm_fns->restore(sleep_save);
  51. }
  52. pr_debug("*** made it back from resume\n");
  53. return 0;
  54. }
  55. EXPORT_SYMBOL_GPL(pxa_pm_enter);
  56. unsigned long sleep_phys_sp(void *sp)
  57. {
  58. return virt_to_phys(sp);
  59. }
  60. static int pxa_pm_valid(suspend_state_t state)
  61. {
  62. if (pxa_cpu_pm_fns)
  63. return pxa_cpu_pm_fns->valid(state);
  64. return -EINVAL;
  65. }
  66. int pxa_pm_prepare(void)
  67. {
  68. int ret = 0;
  69. if (pxa_cpu_pm_fns && pxa_cpu_pm_fns->prepare)
  70. ret = pxa_cpu_pm_fns->prepare();
  71. return ret;
  72. }
  73. void pxa_pm_finish(void)
  74. {
  75. if (pxa_cpu_pm_fns && pxa_cpu_pm_fns->finish)
  76. pxa_cpu_pm_fns->finish();
  77. }
  78. static const struct platform_suspend_ops pxa_pm_ops = {
  79. .valid = pxa_pm_valid,
  80. .enter = pxa_pm_enter,
  81. .prepare = pxa_pm_prepare,
  82. .finish = pxa_pm_finish,
  83. };
  84. static int __init pxa_pm_init(void)
  85. {
  86. if (!pxa_cpu_pm_fns) {
  87. printk(KERN_ERR "no valid pxa_cpu_pm_fns defined\n");
  88. return -EINVAL;
  89. }
  90. sleep_save = kmalloc(pxa_cpu_pm_fns->save_count * sizeof(unsigned long),
  91. GFP_KERNEL);
  92. if (!sleep_save) {
  93. printk(KERN_ERR "failed to alloc memory for pm save\n");
  94. return -ENOMEM;
  95. }
  96. suspend_set_ops(&pxa_pm_ops);
  97. return 0;
  98. }
  99. device_initcall(pxa_pm_init);