cpuidle-kirkwood.c 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  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. .en_core_tk_irqen = 1,
  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. static struct cpuidle_device *device;
  51. static DEFINE_PER_CPU(struct cpuidle_device, kirkwood_cpuidle_device);
  52. /* Initialize CPU idle by registering the idle states */
  53. static int kirkwood_cpuidle_probe(struct platform_device *pdev)
  54. {
  55. struct resource *res;
  56. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  57. if (res == NULL)
  58. return -EINVAL;
  59. ddr_operation_base = devm_request_and_ioremap(&pdev->dev, res);
  60. if (!ddr_operation_base)
  61. return -EADDRNOTAVAIL;
  62. device = &per_cpu(kirkwood_cpuidle_device, smp_processor_id());
  63. device->state_count = KIRKWOOD_MAX_STATES;
  64. cpuidle_register_driver(&kirkwood_idle_driver);
  65. if (cpuidle_register_device(device)) {
  66. pr_err("kirkwood_init_cpuidle: Failed registering\n");
  67. return -EIO;
  68. }
  69. return 0;
  70. }
  71. int kirkwood_cpuidle_remove(struct platform_device *pdev)
  72. {
  73. cpuidle_unregister_device(device);
  74. cpuidle_unregister_driver(&kirkwood_idle_driver);
  75. return 0;
  76. }
  77. static struct platform_driver kirkwood_cpuidle_driver = {
  78. .probe = kirkwood_cpuidle_probe,
  79. .remove = kirkwood_cpuidle_remove,
  80. .driver = {
  81. .name = "kirkwood_cpuidle",
  82. .owner = THIS_MODULE,
  83. },
  84. };
  85. module_platform_driver(kirkwood_cpuidle_driver);
  86. MODULE_AUTHOR("Andrew Lunn <andrew@lunn.ch>");
  87. MODULE_DESCRIPTION("Kirkwood cpu idle driver");
  88. MODULE_LICENSE("GPL v2");
  89. MODULE_ALIAS("platform:kirkwood-cpuidle");