cpuidle-kirkwood.c 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  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. .en_core_tk_irqen = 1,
  40. .states[0] = ARM_CPUIDLE_WFI_STATE,
  41. .states[1] = {
  42. .enter = kirkwood_enter_idle,
  43. .exit_latency = 10,
  44. .target_residency = 100000,
  45. .flags = CPUIDLE_FLAG_TIME_VALID,
  46. .name = "DDR SR",
  47. .desc = "WFI and DDR Self Refresh",
  48. },
  49. .state_count = KIRKWOOD_MAX_STATES,
  50. };
  51. static struct cpuidle_device *device;
  52. static DEFINE_PER_CPU(struct cpuidle_device, kirkwood_cpuidle_device);
  53. /* Initialize CPU idle by registering the idle states */
  54. static int kirkwood_cpuidle_probe(struct platform_device *pdev)
  55. {
  56. struct resource *res;
  57. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  58. if (res == NULL)
  59. return -EINVAL;
  60. ddr_operation_base = devm_ioremap_resource(&pdev->dev, res);
  61. if (IS_ERR(ddr_operation_base))
  62. return PTR_ERR(ddr_operation_base);
  63. device = &per_cpu(kirkwood_cpuidle_device, smp_processor_id());
  64. device->state_count = KIRKWOOD_MAX_STATES;
  65. cpuidle_register_driver(&kirkwood_idle_driver);
  66. if (cpuidle_register_device(device)) {
  67. printk(KERN_ERR "kirkwood_init_cpuidle: Failed registering\n");
  68. return -EIO;
  69. }
  70. return 0;
  71. }
  72. int kirkwood_cpuidle_remove(struct platform_device *pdev)
  73. {
  74. cpuidle_unregister_device(device);
  75. cpuidle_unregister_driver(&kirkwood_idle_driver);
  76. return 0;
  77. }
  78. static struct platform_driver kirkwood_cpuidle_driver = {
  79. .probe = kirkwood_cpuidle_probe,
  80. .remove = kirkwood_cpuidle_remove,
  81. .driver = {
  82. .name = "kirkwood_cpuidle",
  83. .owner = THIS_MODULE,
  84. },
  85. };
  86. module_platform_driver(kirkwood_cpuidle_driver);
  87. MODULE_AUTHOR("Andrew Lunn <andrew@lunn.ch>");
  88. MODULE_DESCRIPTION("Kirkwood cpu idle driver");
  89. MODULE_LICENSE("GPL v2");
  90. MODULE_ALIAS("platform:kirkwood-cpuidle");