crm.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2022-2023, Qualcomm Innovation Center, Inc. All rights reserved.
  4. */
  5. #ifndef __SOC_QCOM_CRM_H__
  6. #define __SOC_QCOM_CRM_H__
  7. #include <linux/platform_device.h>
  8. /**
  9. * enum crm_hw_drv_state: Progressive higher power states for the HW DRV request
  10. *
  11. * @CRM_PWR_STATE0: Power State0
  12. * @CRM_PWR_STATE1: Power State1
  13. * @CRM_PWR_STATE2: Power State2
  14. * @CRM_PWR_STATE3: Power State3
  15. * @CRM_PWR_STATE4: Power State4
  16. */
  17. enum crm_hw_drv_state {
  18. CRM_PWR_STATE0,
  19. CRM_PWR_STATE1,
  20. CRM_PWR_STATE2,
  21. CRM_PWR_STATE3,
  22. CRM_PWR_STATE4,
  23. };
  24. /**
  25. * enum crm_sw_drv_state: Power states for the SW DRV request
  26. *
  27. * @CRM_ACTIVE_STATE: Active or AMC mode requests. Resource state
  28. * is aggregated immediately.
  29. * @CRM_SLEEP_STATE: State of the resource when the subsystem is
  30. * powered down. There is no client using the
  31. * resource actively.
  32. * @CRM_WAKE_STATE: Resume resource state to the value previously
  33. * requested before the subsystem was powered down.
  34. */
  35. enum crm_sw_drv_state {
  36. CRM_ACTIVE_STATE,
  37. CRM_SLEEP_STATE,
  38. CRM_WAKE_STATE,
  39. };
  40. union power_state {
  41. enum crm_hw_drv_state hw;
  42. enum crm_sw_drv_state sw;
  43. };
  44. /**
  45. * enum crm_drv_type: CRM DRV type
  46. *
  47. * @CRM_HW_DRV: DRV is HW (HW Client)
  48. * @CRM_SW_DRV: DRV is SW (SW Client)
  49. */
  50. enum crm_drv_type {
  51. CRM_HW_DRV,
  52. CRM_SW_DRV,
  53. };
  54. /**
  55. * struct crm_cmd: The message to be sent to CRM
  56. *
  57. * @pwr_state: The pwr_state for HW/SW DRV
  58. * @resource_idx: The index of the VCD OR ND to apply data
  59. * @data: The Clock Plan index for the VCDs voted by PERF_OL.
  60. * BW vote for the VCDs voted by BW.
  61. * @wait: Set by the client want if want to wait for the vote completion IRQ.
  62. * Applicable for only SW DRV client.
  63. * Don't care for HW DRV client.
  64. */
  65. struct crm_cmd {
  66. union power_state pwr_state;
  67. u32 resource_idx;
  68. u32 data;
  69. bool wait;
  70. };
  71. #if IS_ENABLED(CONFIG_QCOM_CRM)
  72. int crm_write_perf_ol(const struct device *dev, enum crm_drv_type drv,
  73. u32 drv_id, const struct crm_cmd *cmd);
  74. int crm_write_bw_vote(const struct device *dev, enum crm_drv_type drv,
  75. u32 drv_id, const struct crm_cmd *cmd);
  76. int crm_write_pwr_states(const struct device *dev, u32 drv_id);
  77. int crm_dump_drv_regs(const char *name, u32 drv_id);
  78. int crm_dump_regs(const char *name);
  79. int crm_read_curr_perf_ol(const char *name, int vcd_idx, u32 *data);
  80. const struct device *crm_get_device(const char *name);
  81. #else
  82. static inline int crm_write_perf_ol(const struct device *dev,
  83. enum crm_drv_type drv,
  84. u32 drv_id,
  85. const struct crm_cmd *cmd)
  86. { return -ENODEV; }
  87. static inline int crm_write_bw_vote(const struct device *dev,
  88. enum crm_drv_type drv,
  89. u32 drv_id,
  90. const struct crm_cmd *cmd)
  91. { return -ENODEV; }
  92. static inline int crm_write_pwr_states(const struct device *dev, u32 drv_id)
  93. { return -ENODEV; }
  94. static inline int crm_dump_drv_regs(const char *name, u32 drv_id)
  95. { return -ENODEV; }
  96. static inline int crm_dump_regs(const char *name)
  97. { return -ENODEV; }
  98. static inline int crm_read_curr_perf_ol(const char *name, int vcd_idx, u32 *data)
  99. { return -ENODEV; }
  100. static inline const struct device *crm_get_device(const char *name)
  101. { return ERR_PTR(-ENODEV); }
  102. #endif /* CONFIG_QCOM_CRM */
  103. #endif /* __SOC_QCOM_CRM_H__ */