cpuidle-kirkwood.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  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/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. .name = "DDR SR",
  44. .desc = "WFI and DDR Self Refresh",
  45. },
  46. .state_count = KIRKWOOD_MAX_STATES,
  47. };
  48. /* Initialize CPU idle by registering the idle states */
  49. static int kirkwood_cpuidle_probe(struct platform_device *pdev)
  50. {
  51. struct resource *res;
  52. res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  53. ddr_operation_base = devm_ioremap_resource(&pdev->dev, res);
  54. if (IS_ERR(ddr_operation_base))
  55. return PTR_ERR(ddr_operation_base);
  56. return cpuidle_register(&kirkwood_idle_driver, NULL);
  57. }
  58. static int kirkwood_cpuidle_remove(struct platform_device *pdev)
  59. {
  60. cpuidle_unregister(&kirkwood_idle_driver);
  61. return 0;
  62. }
  63. static struct platform_driver kirkwood_cpuidle_driver = {
  64. .probe = kirkwood_cpuidle_probe,
  65. .remove = kirkwood_cpuidle_remove,
  66. .driver = {
  67. .name = "kirkwood_cpuidle",
  68. },
  69. };
  70. module_platform_driver(kirkwood_cpuidle_driver);
  71. MODULE_AUTHOR("Andrew Lunn <andrew@lunn.ch>");
  72. MODULE_DESCRIPTION("Kirkwood cpu idle driver");
  73. MODULE_LICENSE("GPL v2");
  74. MODULE_ALIAS("platform:kirkwood-cpuidle");