sde_power_handle.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2016-2020, The Linux Foundation. All rights reserved.
  4. */
  5. #ifndef _SDE_POWER_HANDLE_H_
  6. #define _SDE_POWER_HANDLE_H_
  7. #define MAX_CLIENT_NAME_LEN 128
  8. #define SDE_POWER_HANDLE_ENABLE_BUS_AB_QUOTA 0
  9. #define SDE_POWER_HANDLE_DISABLE_BUS_AB_QUOTA 0
  10. #define SDE_POWER_HANDLE_ENABLE_BUS_IB_QUOTA 400000000
  11. #define SDE_POWER_HANDLE_ENABLE_NRT_BUS_IB_QUOTA 0
  12. #define SDE_POWER_HANDLE_DISABLE_BUS_IB_QUOTA 0
  13. #define SDE_POWER_HANDLE_CONT_SPLASH_BUS_IB_QUOTA 3000000000ULL
  14. #define SDE_POWER_HANDLE_CONT_SPLASH_BUS_AB_QUOTA 3000000000ULL
  15. #include <linux/sde_io_util.h>
  16. #include <linux/interconnect.h>
  17. /* event will be triggered before power handler disable */
  18. #define SDE_POWER_EVENT_PRE_DISABLE 0x1
  19. /* event will be triggered after power handler disable */
  20. #define SDE_POWER_EVENT_POST_DISABLE 0x2
  21. /* event will be triggered before power handler enable */
  22. #define SDE_POWER_EVENT_PRE_ENABLE 0x4
  23. /* event will be triggered after power handler enable */
  24. #define SDE_POWER_EVENT_POST_ENABLE 0x8
  25. #define DATA_BUS_PATH_MAX 0x2
  26. /*
  27. * The AMC bucket denotes constraints that are applied to hardware when
  28. * icc_set_bw() completes, whereas the WAKE and SLEEP constraints are applied
  29. * when the execution environment transitions between active and low power mode.
  30. */
  31. #define QCOM_ICC_BUCKET_AMC 0
  32. #define QCOM_ICC_BUCKET_WAKE 1
  33. #define QCOM_ICC_BUCKET_SLEEP 2
  34. #define QCOM_ICC_NUM_BUCKETS 3
  35. #define QCOM_ICC_TAG_AMC BIT(QCOM_ICC_BUCKET_AMC)
  36. #define QCOM_ICC_TAG_WAKE BIT(QCOM_ICC_BUCKET_WAKE)
  37. #define QCOM_ICC_TAG_SLEEP BIT(QCOM_ICC_BUCKET_SLEEP)
  38. #define QCOM_ICC_TAG_ACTIVE_ONLY (QCOM_ICC_TAG_AMC | QCOM_ICC_TAG_WAKE)
  39. #define QCOM_ICC_TAG_ALWAYS (QCOM_ICC_TAG_AMC | QCOM_ICC_TAG_WAKE |\
  40. QCOM_ICC_TAG_SLEEP)
  41. /**
  42. * mdss_bus_vote_type: register bus vote type
  43. * VOTE_INDEX_DISABLE: removes the client vote
  44. * VOTE_INDEX_LOW: keeps the lowest vote for register bus
  45. * VOTE_INDEX_MEDIUM: keeps medium vote for register bus
  46. * VOTE_INDEX_HIGH: keeps the highest vote for register bus
  47. * VOTE_INDEX_MAX: invalid
  48. */
  49. enum mdss_bus_vote_type {
  50. VOTE_INDEX_DISABLE,
  51. VOTE_INDEX_LOW,
  52. VOTE_INDEX_MEDIUM,
  53. VOTE_INDEX_HIGH,
  54. VOTE_INDEX_MAX,
  55. };
  56. /**
  57. * enum sde_power_handle_data_bus_client - type of axi bus clients
  58. * @SDE_POWER_HANDLE_DATA_BUS_CLIENT_RT: core real-time bus client
  59. * @SDE_POWER_HANDLE_DATA_BUS_CLIENT_NRT: core non-real-time bus client
  60. * @SDE_POWER_HANDLE_DATA_BUS_CLIENT_MAX: maximum number of bus client type
  61. */
  62. enum sde_power_handle_data_bus_client {
  63. SDE_POWER_HANDLE_DATA_BUS_CLIENT_RT,
  64. SDE_POWER_HANDLE_DATA_BUS_CLIENT_NRT,
  65. SDE_POWER_HANDLE_DATA_BUS_CLIENT_MAX
  66. };
  67. /**
  68. * enum SDE_POWER_HANDLE_DBUS_ID - data bus identifier
  69. * @SDE_POWER_HANDLE_DBUS_ID_MNOC: DPU/MNOC data bus
  70. * @SDE_POWER_HANDLE_DBUS_ID_LLCC: MNOC/LLCC data bus
  71. * @SDE_POWER_HANDLE_DBUS_ID_EBI: LLCC/EBI data bus
  72. */
  73. enum SDE_POWER_HANDLE_DBUS_ID {
  74. SDE_POWER_HANDLE_DBUS_ID_MNOC,
  75. SDE_POWER_HANDLE_DBUS_ID_LLCC,
  76. SDE_POWER_HANDLE_DBUS_ID_EBI,
  77. SDE_POWER_HANDLE_DBUS_ID_MAX,
  78. };
  79. /**
  80. * struct sde_power_bus_scaling_data: struct for bus setting
  81. * @ab: average bandwidth in bytes per second
  82. * @ib: peak bandwidth in bytes per second
  83. */
  84. struct sde_power_bus_scaling_data {
  85. uint64_t ab; /* Arbitrated bandwidth */
  86. uint64_t ib; /* Instantaneous bandwidth */
  87. };
  88. /**
  89. * struct sde_power_data_handle: power handle struct for data bus
  90. * @data_bus_hdl: current data bus handle
  91. * @curr_val : save the current bus value
  92. * @data_paths_cnt: number of rt data path ports
  93. */
  94. struct sde_power_data_bus_handle {
  95. struct icc_path *data_bus_hdl[DATA_BUS_PATH_MAX];
  96. struct sde_power_bus_scaling_data curr_val;
  97. u32 data_paths_cnt;
  98. bool bus_active_only;
  99. };
  100. /**
  101. * struct sde_power_reg_bus_handle: power handle struct for reg bus
  102. * @reg_bus_hdl: reg bus interconnect path handle
  103. * @curr_idx : use-case index in to scale_table for the current vote
  104. * @scale_table: bus scaling bandwidth vote table
  105. */
  106. struct sde_power_reg_bus_handle {
  107. struct icc_path *reg_bus_hdl;
  108. enum mdss_bus_vote_type curr_idx;
  109. struct sde_power_bus_scaling_data scale_table[VOTE_INDEX_MAX];
  110. };
  111. /*
  112. * struct sde_power_event - local event registration structure
  113. * @client_name: name of the client registering
  114. * @cb_fnc: pointer to desired callback function
  115. * @usr: user pointer to pass to callback event trigger
  116. * @event: refer to SDE_POWER_HANDLE_EVENT_*
  117. * @list: list to attach event master list
  118. * @active: indicates the state of sde power handle
  119. */
  120. struct sde_power_event {
  121. char client_name[MAX_CLIENT_NAME_LEN];
  122. void (*cb_fnc)(u32 event_type, void *usr);
  123. void *usr;
  124. u32 event_type;
  125. struct list_head list;
  126. bool active;
  127. };
  128. /**
  129. * struct sde_power_handle: power handle main struct
  130. * @mp: module power for clock and regulator
  131. * @phandle_lock: lock to synchronize the enable/disable
  132. * @dev: pointer to device structure
  133. * @reg_bus_handle: context structure for reg bus control
  134. * @data_bus_handle: context structure for data bus control
  135. * @event_list: current power handle event list
  136. * @rsc_client: sde rsc client pointer
  137. * @rsc_client_init: boolean to control rsc client create
  138. */
  139. struct sde_power_handle {
  140. struct dss_module_power mp;
  141. struct mutex phandle_lock;
  142. struct device *dev;
  143. struct sde_power_reg_bus_handle reg_bus_handle;
  144. struct sde_power_data_bus_handle data_bus_handle
  145. [SDE_POWER_HANDLE_DBUS_ID_MAX];
  146. struct list_head event_list;
  147. u32 last_event_handled;
  148. struct sde_rsc_client *rsc_client;
  149. bool rsc_client_init;
  150. };
  151. /**
  152. * sde_power_resource_init() - initializes the sde power handle
  153. * @pdev: platform device to search the power resources
  154. * @pdata: power handle to store the power resources
  155. *
  156. * Return: error code.
  157. */
  158. int sde_power_resource_init(struct platform_device *pdev,
  159. struct sde_power_handle *pdata);
  160. /**
  161. * sde_power_resource_deinit() - release the sde power handle
  162. * @pdev: platform device for power resources
  163. * @pdata: power handle containing the resources
  164. *
  165. * Return: error code.
  166. */
  167. void sde_power_resource_deinit(struct platform_device *pdev,
  168. struct sde_power_handle *pdata);
  169. /**
  170. * sde_power_resource_enable() - enable/disable the power resources
  171. * @pdata: power handle containing the resources
  172. * @enable: boolean request for enable/disable
  173. *
  174. * Return: error code.
  175. */
  176. int sde_power_resource_enable(struct sde_power_handle *pdata, bool enable);
  177. /**
  178. * sde_power_scale_reg_bus() - Scale the registers bus for the specified client
  179. * @phandle: power handle containing the resources
  180. * @usecase_ndx: new use case to scale the reg bus
  181. * @skip_lock: will skip holding the power rsrc mutex during the call, this is
  182. * for internal callers that already hold this required lock.
  183. *
  184. * Return: error code.
  185. */
  186. int sde_power_scale_reg_bus(struct sde_power_handle *phandle,
  187. u32 usecase_ndx, bool skip_lock);
  188. /**
  189. * sde_power_data_bus_state_update() - update data bus state
  190. * @pdata: power handle containing the resources
  191. * @enable: take enable vs disable path
  192. *
  193. * Return: error code.
  194. */
  195. int sde_power_data_bus_state_update(struct sde_power_handle *phandle,
  196. bool enable);
  197. /**
  198. * sde_power_clk_set_rate() - set the clock rate
  199. * @pdata: power handle containing the resources
  200. * @clock_name: clock name which needs rate update.
  201. * @rate: Requested rate.
  202. *
  203. * Return: error code.
  204. */
  205. int sde_power_clk_set_rate(struct sde_power_handle *pdata, char *clock_name,
  206. u64 rate);
  207. /**
  208. * sde_power_clk_get_rate() - get the clock rate
  209. * @pdata: power handle containing the resources
  210. * @clock_name: clock name to get the rate
  211. *
  212. * Return: current clock rate
  213. */
  214. u64 sde_power_clk_get_rate(struct sde_power_handle *pdata, char *clock_name);
  215. /**
  216. * sde_power_clk_get_max_rate() - get the maximum clock rate
  217. * @pdata: power handle containing the resources
  218. * @clock_name: clock name to get the max rate.
  219. *
  220. * Return: maximum clock rate or 0 if not found.
  221. */
  222. u64 sde_power_clk_get_max_rate(struct sde_power_handle *pdata,
  223. char *clock_name);
  224. /**
  225. * sde_power_clk_get_clk() - get the clock
  226. * @pdata: power handle containing the resources
  227. * @clock_name: clock name to get the clk pointer.
  228. *
  229. * Return: Pointer to clock
  230. */
  231. struct clk *sde_power_clk_get_clk(struct sde_power_handle *phandle,
  232. char *clock_name);
  233. /**
  234. * sde_power_data_bus_set_quota() - set data bus quota for power client
  235. * @phandle: power handle containing the resources
  236. * @bus_id: identifier of data bus, see SDE_POWER_HANDLE_DBUS_ID
  237. * @ab_quota: arbitrated bus bandwidth
  238. * @ib_quota: instantaneous bus bandwidth
  239. *
  240. * Return: zero if success, or error code otherwise
  241. */
  242. int sde_power_data_bus_set_quota(struct sde_power_handle *phandle,
  243. u32 bus_id, u64 ab_quota, u64 ib_quota);
  244. /**
  245. * sde_power_data_bus_bandwidth_ctrl() - control data bus bandwidth enable
  246. * @phandle: power handle containing the resources
  247. * @enable: true to enable bandwidth for data base
  248. *
  249. * Return: none
  250. */
  251. void sde_power_data_bus_bandwidth_ctrl(struct sde_power_handle *phandle,
  252. int enable);
  253. /**
  254. * sde_power_handle_register_event - register a callback function for an event.
  255. * Clients can register for multiple events with a single register.
  256. * Any block with access to phandle can register for the event
  257. * notification.
  258. * @phandle: power handle containing the resources
  259. * @event_type: event type to register; refer SDE_POWER_HANDLE_EVENT_*
  260. * @cb_fnc: pointer to desired callback function
  261. * @usr: user pointer to pass to callback on event trigger
  262. *
  263. * Return: event pointer if success, or error code otherwise
  264. */
  265. struct sde_power_event *sde_power_handle_register_event(
  266. struct sde_power_handle *phandle,
  267. u32 event_type, void (*cb_fnc)(u32 event_type, void *usr),
  268. void *usr, char *client_name);
  269. /**
  270. * sde_power_handle_unregister_event - unregister callback for event(s)
  271. * @phandle: power handle containing the resources
  272. * @event: event pointer returned after power handle register
  273. */
  274. void sde_power_handle_unregister_event(struct sde_power_handle *phandle,
  275. struct sde_power_event *event);
  276. /**
  277. * sde_power_handle_get_dbus_name - get name of given data bus identifier
  278. * @bus_id: data bus identifier
  279. * Return: Pointer to name string if success; NULL otherwise
  280. */
  281. const char *sde_power_handle_get_dbus_name(u32 bus_id);
  282. #endif /* _SDE_POWER_HANDLE_H_ */