cpuidle-kirkwood.c 2.3 KB

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