idle.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * Copyright (C) 2006-2007 PA Semi, Inc
  3. *
  4. * Maintained by: Olof Johansson <olof@lixom.net>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 as
  8. * published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  18. *
  19. */
  20. #undef DEBUG
  21. #include <linux/kernel.h>
  22. #include <linux/string.h>
  23. #include <linux/irq.h>
  24. #include <asm/machdep.h>
  25. #include <asm/reg.h>
  26. #include <asm/smp.h>
  27. #include "pasemi.h"
  28. struct sleep_mode {
  29. char *name;
  30. void (*entry)(void);
  31. };
  32. static struct sleep_mode modes[] = {
  33. { .name = "spin", .entry = &idle_spin },
  34. { .name = "doze", .entry = &idle_doze },
  35. };
  36. static int current_mode = 0;
  37. static int pasemi_system_reset_exception(struct pt_regs *regs)
  38. {
  39. /* If we were woken up from power savings, we need to return
  40. * to the calling function, since nip is not saved across
  41. * all modes.
  42. */
  43. if (regs->msr & SRR1_WAKEMASK)
  44. regs->nip = regs->link;
  45. switch (regs->msr & SRR1_WAKEMASK) {
  46. case SRR1_WAKEDEC:
  47. set_dec(1);
  48. case SRR1_WAKEEE:
  49. /*
  50. * Handle these when interrupts get re-enabled and we take
  51. * them as regular exceptions. We are in an NMI context
  52. * and can't handle these here.
  53. */
  54. break;
  55. default:
  56. /* do system reset */
  57. return 0;
  58. }
  59. /* Set higher astate since we come out of power savings at 0 */
  60. restore_astate(hard_smp_processor_id());
  61. /* everything handled */
  62. regs->msr |= MSR_RI;
  63. return 1;
  64. }
  65. static int __init pasemi_idle_init(void)
  66. {
  67. #ifndef CONFIG_PPC_PASEMI_CPUFREQ
  68. pr_warn("No cpufreq driver, powersavings modes disabled\n");
  69. current_mode = 0;
  70. #endif
  71. ppc_md.system_reset_exception = pasemi_system_reset_exception;
  72. ppc_md.power_save = modes[current_mode].entry;
  73. pr_info("Using PA6T idle loop (%s)\n", modes[current_mode].name);
  74. return 0;
  75. }
  76. machine_late_initcall(pasemi, pasemi_idle_init);
  77. static int __init idle_param(char *p)
  78. {
  79. int i;
  80. for (i = 0; i < ARRAY_SIZE(modes); i++) {
  81. if (!strcmp(modes[i].name, p)) {
  82. current_mode = i;
  83. break;
  84. }
  85. }
  86. return 0;
  87. }
  88. early_param("idle", idle_param);