idle.c 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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 "pasemi.h"
  27. struct sleep_mode {
  28. char *name;
  29. void (*entry)(void);
  30. };
  31. static struct sleep_mode modes[] = {
  32. { .name = "spin", .entry = &idle_spin },
  33. { .name = "doze", .entry = &idle_doze },
  34. };
  35. static int current_mode = 0;
  36. static int pasemi_system_reset_exception(struct pt_regs *regs)
  37. {
  38. /* If we were woken up from power savings, we need to return
  39. * to the calling function, since nip is not saved across
  40. * all modes.
  41. */
  42. if (regs->msr & SRR1_WAKEMASK)
  43. regs->nip = regs->link;
  44. switch (regs->msr & SRR1_WAKEMASK) {
  45. case SRR1_WAKEEE:
  46. do_IRQ(regs);
  47. break;
  48. case SRR1_WAKEDEC:
  49. timer_interrupt(regs);
  50. break;
  51. default:
  52. /* do system reset */
  53. return 0;
  54. }
  55. /* Set higher astate since we come out of power savings at 0 */
  56. restore_astate(hard_smp_processor_id());
  57. /* everything handled */
  58. regs->msr |= MSR_RI;
  59. return 1;
  60. }
  61. void __init pasemi_idle_init(void)
  62. {
  63. #ifndef CONFIG_PPC_PASEMI_CPUFREQ
  64. printk(KERN_WARNING "No cpufreq driver, powersavings modes disabled\n");
  65. current_mode = 0;
  66. #endif
  67. ppc_md.system_reset_exception = pasemi_system_reset_exception;
  68. ppc_md.power_save = modes[current_mode].entry;
  69. printk(KERN_INFO "Using PA6T idle loop (%s)\n", modes[current_mode].name);
  70. }
  71. static int __init idle_param(char *p)
  72. {
  73. int i;
  74. for (i = 0; i < sizeof(modes)/sizeof(struct sleep_mode); i++) {
  75. if (!strcmp(modes[i].name, p)) {
  76. current_mode = i;
  77. break;
  78. }
  79. }
  80. return 0;
  81. }
  82. early_param("idle", idle_param);