cpuidle.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. /*
  2. * CPU idle for DaVinci SoCs
  3. *
  4. * Copyright (C) 2009 Texas Instruments Incorporated. http://www.ti.com/
  5. *
  6. * Derived from Marvell Kirkwood CPU idle code
  7. * (arch/arm/mach-kirkwood/cpuidle.c)
  8. *
  9. * This program is free software; you can redistribute it and/or modify
  10. * it under the terms of the GNU General Public License version 2 as
  11. * published by the Free Software Foundation.
  12. */
  13. #include <linux/kernel.h>
  14. #include <linux/init.h>
  15. #include <linux/platform_device.h>
  16. #include <linux/cpuidle.h>
  17. #include <linux/io.h>
  18. #include <linux/export.h>
  19. #include <asm/proc-fns.h>
  20. #include <asm/cpuidle.h>
  21. #include <mach/cpuidle.h>
  22. #include <mach/ddr2.h>
  23. #define DAVINCI_CPUIDLE_MAX_STATES 2
  24. static void __iomem *ddr2_reg_base;
  25. static bool ddr2_pdown;
  26. static void davinci_save_ddr_power(int enter, bool pdown)
  27. {
  28. u32 val;
  29. val = __raw_readl(ddr2_reg_base + DDR2_SDRCR_OFFSET);
  30. if (enter) {
  31. if (pdown)
  32. val |= DDR2_SRPD_BIT;
  33. else
  34. val &= ~DDR2_SRPD_BIT;
  35. val |= DDR2_LPMODEN_BIT;
  36. } else {
  37. val &= ~(DDR2_SRPD_BIT | DDR2_LPMODEN_BIT);
  38. }
  39. __raw_writel(val, ddr2_reg_base + DDR2_SDRCR_OFFSET);
  40. }
  41. /* Actual code that puts the SoC in different idle states */
  42. static int davinci_enter_idle(struct cpuidle_device *dev,
  43. struct cpuidle_driver *drv, int index)
  44. {
  45. davinci_save_ddr_power(1, ddr2_pdown);
  46. cpu_do_idle();
  47. davinci_save_ddr_power(0, ddr2_pdown);
  48. return index;
  49. }
  50. static struct cpuidle_driver davinci_idle_driver = {
  51. .name = "cpuidle-davinci",
  52. .owner = THIS_MODULE,
  53. .states[0] = ARM_CPUIDLE_WFI_STATE,
  54. .states[1] = {
  55. .enter = davinci_enter_idle,
  56. .exit_latency = 10,
  57. .target_residency = 100000,
  58. .flags = CPUIDLE_FLAG_TIME_VALID,
  59. .name = "DDR SR",
  60. .desc = "WFI and DDR Self Refresh",
  61. },
  62. .state_count = DAVINCI_CPUIDLE_MAX_STATES,
  63. };
  64. static int __init davinci_cpuidle_probe(struct platform_device *pdev)
  65. {
  66. struct davinci_cpuidle_config *pdata = pdev->dev.platform_data;
  67. if (!pdata) {
  68. dev_err(&pdev->dev, "cannot get platform data\n");
  69. return -ENOENT;
  70. }
  71. ddr2_reg_base = pdata->ddr2_ctlr_base;
  72. ddr2_pdown = pdata->ddr2_pdown;
  73. return cpuidle_register(&davinci_idle_driver, NULL);
  74. }
  75. static struct platform_driver davinci_cpuidle_driver = {
  76. .driver = {
  77. .name = "cpuidle-davinci",
  78. .owner = THIS_MODULE,
  79. },
  80. };
  81. static int __init davinci_cpuidle_init(void)
  82. {
  83. return platform_driver_probe(&davinci_cpuidle_driver,
  84. davinci_cpuidle_probe);
  85. }
  86. device_initcall(davinci_cpuidle_init);