cpuidle-kirkwood.c 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * CPU idle Marvell Kirkwood SoCs
  3. *
  4. * This file is licensed under the terms of the GNU General Public
  5. * License version 2. This program is licensed "as is" without any
  6. * warranty of any kind, whether express or implied.
  7. *
  8. * The cpu idle uses wait-for-interrupt and DDR self refresh in order
  9. * to implement two idle states -
  10. * #1 wait-for-interrupt
  11. * #2 wait-for-interrupt and DDR self refresh
  12. *
  13. * Maintainer: Jason Cooper <jason@lakedaemon.net>
  14. * Maintainer: Andrew Lunn <andrew@lunn.ch>
  15. */
  16. #include <linux/kernel.h>
  17. #include <linux/module.h>
  18. #include <linux/init.h>
  19. #include <linux/platform_device.h>
  20. #include <linux/cpuidle.h>
  21. #include <linux/io.h>
  22. #include <linux/export.h>
  23. #include <asm/proc-fns.h>
  24. #include <asm/cpuidle.h>
  25. #define KIRKWOOD_MAX_STATES 2
  26. static void __iomem *ddr_operation_base;
  27. /* Actual code that puts the SoC in different idle states */
  28. static int kirkwood_enter_idle(struct cpuidle_device *dev,
  29. struct cpuidle_driver *drv,
  30. int index)
  31. {
  32. writel(0x7, ddr_operation_base);
  33. cpu_do_idle();
  34. return index;
  35. }
  36. static struct cpuidle_driver kirkwood_idle_driver = {
  37. .name = "kirkwood_idle",
  38. .owner = THIS_MODULE,
  39. .states[0] = ARM_CPUIDLE_WFI_STATE,
  40. .states[1] = {
  41. .enter = kirkwood_enter_idle,
  42. .exit_latency = 10,
  43. .target_residency = 100000,
  44. .flags = CPUIDLE_FLAG_TIME_VALID,
  45. .name = "DDR SR",
  46. .desc = "WFI and DDR Self Refresh",
  47. },
  48. .state_count = KIRKWOOD_MAX_STATES,
  49. };
  50. /* Initialize CPU idle by registering the idle states */
  51. static int kirkwood_cpuidle_probe(struct platform_device *pdev)
  52. {
  53. struct resource *res;
  54. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  55. ddr_operation_base = devm_ioremap_resource(&pdev->dev, res);
  56. if (IS_ERR(ddr_operation_base))
  57. return PTR_ERR(ddr_operation_base);
  58. return cpuidle_register(&kirkwood_idle_driver, NULL);
  59. }
  60. static int kirkwood_cpuidle_remove(struct platform_device *pdev)
  61. {
  62. cpuidle_unregister(&kirkwood_idle_driver);
  63. return 0;
  64. }
  65. static struct platform_driver kirkwood_cpuidle_driver = {
  66. .probe = kirkwood_cpuidle_probe,
  67. .remove = kirkwood_cpuidle_remove,
  68. .driver = {
  69. .name = "kirkwood_cpuidle",
  70. .owner = THIS_MODULE,
  71. },
  72. };
  73. module_platform_driver(kirkwood_cpuidle_driver);
  74. MODULE_AUTHOR("Andrew Lunn <andrew@lunn.ch>");
  75. MODULE_DESCRIPTION("Kirkwood cpu idle driver");
  76. MODULE_LICENSE("GPL v2");
  77. MODULE_ALIAS("platform:kirkwood-cpuidle");