cpuidle.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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/cpuidle.h>
  20. #include "cpuidle.h"
  21. #include "ddr2.h"
  22. #define DAVINCI_CPUIDLE_MAX_STATES 2
  23. static void __iomem *ddr2_reg_base;
  24. static bool ddr2_pdown;
  25. static void davinci_save_ddr_power(int enter, bool pdown)
  26. {
  27. u32 val;
  28. val = __raw_readl(ddr2_reg_base + DDR2_SDRCR_OFFSET);
  29. if (enter) {
  30. if (pdown)
  31. val |= DDR2_SRPD_BIT;
  32. else
  33. val &= ~DDR2_SRPD_BIT;
  34. val |= DDR2_LPMODEN_BIT;
  35. } else {
  36. val &= ~(DDR2_SRPD_BIT | DDR2_LPMODEN_BIT);
  37. }
  38. __raw_writel(val, ddr2_reg_base + DDR2_SDRCR_OFFSET);
  39. }
  40. /* Actual code that puts the SoC in different idle states */
  41. static int davinci_enter_idle(struct cpuidle_device *dev,
  42. struct cpuidle_driver *drv, int index)
  43. {
  44. davinci_save_ddr_power(1, ddr2_pdown);
  45. cpu_do_idle();
  46. davinci_save_ddr_power(0, ddr2_pdown);
  47. return index;
  48. }
  49. static struct cpuidle_driver davinci_idle_driver = {
  50. .name = "cpuidle-davinci",
  51. .owner = THIS_MODULE,
  52. .states[0] = ARM_CPUIDLE_WFI_STATE,
  53. .states[1] = {
  54. .enter = davinci_enter_idle,
  55. .exit_latency = 10,
  56. .target_residency = 10000,
  57. .name = "DDR SR",
  58. .desc = "WFI and DDR Self Refresh",
  59. },
  60. .state_count = DAVINCI_CPUIDLE_MAX_STATES,
  61. };
  62. static int __init davinci_cpuidle_probe(struct platform_device *pdev)
  63. {
  64. struct davinci_cpuidle_config *pdata = pdev->dev.platform_data;
  65. if (!pdata) {
  66. dev_err(&pdev->dev, "cannot get platform data\n");
  67. return -ENOENT;
  68. }
  69. ddr2_reg_base = pdata->ddr2_ctlr_base;
  70. ddr2_pdown = pdata->ddr2_pdown;
  71. return cpuidle_register(&davinci_idle_driver, NULL);
  72. }
  73. static struct platform_driver davinci_cpuidle_driver = {
  74. .driver = {
  75. .name = "cpuidle-davinci",
  76. },
  77. };
  78. static int __init davinci_cpuidle_init(void)
  79. {
  80. return platform_driver_probe(&davinci_cpuidle_driver,
  81. davinci_cpuidle_probe);
  82. }
  83. device_initcall(davinci_cpuidle_init);