cpuidle-kirkwood.c 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * CPU idle Marvell Kirkwood SoCs
  4. *
  5. * The cpu idle uses wait-for-interrupt and DDR self refresh in order
  6. * to implement two idle states -
  7. * #1 wait-for-interrupt
  8. * #2 wait-for-interrupt and DDR self refresh
  9. *
  10. * Maintainer: Jason Cooper <[email protected]>
  11. * Maintainer: Andrew Lunn <[email protected]>
  12. */
  13. #include <linux/kernel.h>
  14. #include <linux/module.h>
  15. #include <linux/init.h>
  16. #include <linux/platform_device.h>
  17. #include <linux/cpuidle.h>
  18. #include <linux/io.h>
  19. #include <linux/export.h>
  20. #include <asm/cpuidle.h>
  21. #define KIRKWOOD_MAX_STATES 2
  22. static void __iomem *ddr_operation_base;
  23. /* Actual code that puts the SoC in different idle states */
  24. static int kirkwood_enter_idle(struct cpuidle_device *dev,
  25. struct cpuidle_driver *drv,
  26. int index)
  27. {
  28. writel(0x7, ddr_operation_base);
  29. cpu_do_idle();
  30. return index;
  31. }
  32. static struct cpuidle_driver kirkwood_idle_driver = {
  33. .name = "kirkwood_idle",
  34. .owner = THIS_MODULE,
  35. .states[0] = ARM_CPUIDLE_WFI_STATE,
  36. .states[1] = {
  37. .enter = kirkwood_enter_idle,
  38. .exit_latency = 10,
  39. .target_residency = 100000,
  40. .name = "DDR SR",
  41. .desc = "WFI and DDR Self Refresh",
  42. },
  43. .state_count = KIRKWOOD_MAX_STATES,
  44. };
  45. /* Initialize CPU idle by registering the idle states */
  46. static int kirkwood_cpuidle_probe(struct platform_device *pdev)
  47. {
  48. ddr_operation_base = devm_platform_ioremap_resource(pdev, 0);
  49. if (IS_ERR(ddr_operation_base))
  50. return PTR_ERR(ddr_operation_base);
  51. return cpuidle_register(&kirkwood_idle_driver, NULL);
  52. }
  53. static int kirkwood_cpuidle_remove(struct platform_device *pdev)
  54. {
  55. cpuidle_unregister(&kirkwood_idle_driver);
  56. return 0;
  57. }
  58. static struct platform_driver kirkwood_cpuidle_driver = {
  59. .probe = kirkwood_cpuidle_probe,
  60. .remove = kirkwood_cpuidle_remove,
  61. .driver = {
  62. .name = "kirkwood_cpuidle",
  63. },
  64. };
  65. module_platform_driver(kirkwood_cpuidle_driver);
  66. MODULE_AUTHOR("Andrew Lunn <[email protected]>");
  67. MODULE_DESCRIPTION("Kirkwood cpu idle driver");
  68. MODULE_LICENSE("GPL v2");
  69. MODULE_ALIAS("platform:kirkwood-cpuidle");