cpuidle-light.c 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Copyright (C) 2021 Alibaba Group Holding Limited.
  4. * CPU idle support for Thead LIGHT SoC
  5. */
  6. #include <linux/kernel.h>
  7. #include <linux/init.h>
  8. #include <linux/platform_device.h>
  9. #include <linux/cpuidle.h>
  10. #include <linux/io.h>
  11. #include <linux/export.h>
  12. #include <asm/cpuidle.h>
  13. #define LIGHT_MAX_STATES 1
  14. extern void arch_cpu_idle(void);
  15. /* Actual code that puts the SoC in different idle states */
  16. static int light_enter_idle(struct cpuidle_device *dev,
  17. struct cpuidle_driver *drv,
  18. int index)
  19. {
  20. arch_cpu_idle();
  21. return index;
  22. }
  23. static struct cpuidle_driver light_idle_driver = {
  24. .name = "light_idle",
  25. .owner = THIS_MODULE,
  26. .states[0] = {
  27. .enter = light_enter_idle,
  28. .exit_latency = 1,
  29. .power_usage = UINT_MAX,
  30. .target_residency = 1,
  31. .name = "WFI",
  32. .desc = "RISC-V WFI",
  33. },
  34. .state_count = LIGHT_MAX_STATES,
  35. };
  36. /* Initialize CPU idle by registering the idle states */
  37. static int light_cpuidle_probe(struct platform_device *dev)
  38. {
  39. return cpuidle_register(&light_idle_driver, NULL);
  40. }
  41. static struct platform_driver light_cpuidle_driver = {
  42. .driver = {
  43. .name = "cpuidle-light",
  44. },
  45. .probe = light_cpuidle_probe,
  46. };
  47. static int __init light_cpuidle_init(void)
  48. {
  49. int ret;
  50. struct platform_device *pdev;
  51. ret = platform_driver_register(&light_cpuidle_driver);
  52. if (ret)
  53. return ret;
  54. pdev = platform_device_register_simple("cpuidle-light",
  55. -1, NULL, 0);
  56. if (IS_ERR(pdev)) {
  57. platform_driver_unregister(&light_cpuidle_driver);
  58. return PTR_ERR(pdev);
  59. }
  60. return 0;
  61. }
  62. device_initcall(light_cpuidle_init);