cpuidle.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. /* linux/arch/arm/mach-s3c64xx/cpuidle.c
  2. *
  3. * Copyright (c) 2011 Wolfson Microelectronics, plc
  4. * Copyright (c) 2011 Samsung Electronics Co., Ltd.
  5. * http://www.samsung.com
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License version 2 as
  9. * published by the Free Software Foundation.
  10. */
  11. #include <linux/kernel.h>
  12. #include <linux/init.h>
  13. #include <linux/cpuidle.h>
  14. #include <linux/io.h>
  15. #include <linux/export.h>
  16. #include <linux/time.h>
  17. #include <asm/proc-fns.h>
  18. #include <mach/map.h>
  19. #include <mach/regs-sys.h>
  20. #include <mach/regs-syscon-power.h>
  21. static int s3c64xx_enter_idle(struct cpuidle_device *dev,
  22. struct cpuidle_driver *drv,
  23. int index)
  24. {
  25. struct timeval before, after;
  26. unsigned long tmp;
  27. int idle_time;
  28. local_irq_disable();
  29. do_gettimeofday(&before);
  30. /* Setup PWRCFG to enter idle mode */
  31. tmp = __raw_readl(S3C64XX_PWR_CFG);
  32. tmp &= ~S3C64XX_PWRCFG_CFG_WFI_MASK;
  33. tmp |= S3C64XX_PWRCFG_CFG_WFI_IDLE;
  34. __raw_writel(tmp, S3C64XX_PWR_CFG);
  35. cpu_do_idle();
  36. do_gettimeofday(&after);
  37. local_irq_enable();
  38. idle_time = (after.tv_sec - before.tv_sec) * USEC_PER_SEC +
  39. (after.tv_usec - before.tv_usec);
  40. dev->last_residency = idle_time;
  41. return index;
  42. }
  43. static struct cpuidle_state s3c64xx_cpuidle_set[] = {
  44. [0] = {
  45. .enter = s3c64xx_enter_idle,
  46. .exit_latency = 1,
  47. .target_residency = 1,
  48. .flags = CPUIDLE_FLAG_TIME_VALID,
  49. .name = "IDLE",
  50. .desc = "System active, ARM gated",
  51. },
  52. };
  53. static struct cpuidle_driver s3c64xx_cpuidle_driver = {
  54. .name = "s3c64xx_cpuidle",
  55. .owner = THIS_MODULE,
  56. .state_count = ARRAY_SIZE(s3c64xx_cpuidle_set),
  57. };
  58. static struct cpuidle_device s3c64xx_cpuidle_device = {
  59. .state_count = ARRAY_SIZE(s3c64xx_cpuidle_set),
  60. };
  61. static int __init s3c64xx_init_cpuidle(void)
  62. {
  63. int ret;
  64. memcpy(s3c64xx_cpuidle_driver.states, s3c64xx_cpuidle_set,
  65. sizeof(s3c64xx_cpuidle_set));
  66. cpuidle_register_driver(&s3c64xx_cpuidle_driver);
  67. ret = cpuidle_register_device(&s3c64xx_cpuidle_device);
  68. if (ret) {
  69. pr_err("Failed to register cpuidle device: %d\n", ret);
  70. return ret;
  71. }
  72. return 0;
  73. }
  74. device_initcall(s3c64xx_init_cpuidle);