sde_power_handle.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2016-2021, 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. /* event will be triggered during MMRM callback */
  26. #define SDE_POWER_EVENT_MMRM_CALLBACK 0x10
  27. #define DATA_BUS_PATH_MAX 0x2
  28. /*
  29. * The AMC bucket denotes constraints that are applied to hardware when
  30. * icc_set_bw() completes, whereas the WAKE and SLEEP constraints are applied
  31. * when the execution environment transitions between active and low power mode.
  32. */
  33. #define QCOM_ICC_BUCKET_AMC 0
  34. #define QCOM_ICC_BUCKET_WAKE 1
  35. #define QCOM_ICC_BUCKET_SLEEP 2
  36. #define QCOM_ICC_NUM_BUCKETS 3
  37. #define QCOM_ICC_TAG_AMC BIT(QCOM_ICC_BUCKET_AMC)
  38. #define QCOM_ICC_TAG_WAKE BIT(QCOM_ICC_BUCKET_WAKE)
  39. #define QCOM_ICC_TAG_SLEEP BIT(QCOM_ICC_BUCKET_SLEEP)
  40. #define QCOM_ICC_TAG_ACTIVE_ONLY (QCOM_ICC_TAG_AMC | QCOM_ICC_TAG_WAKE)
  41. #define QCOM_ICC_TAG_ALWAYS (QCOM_ICC_TAG_AMC | QCOM_ICC_TAG_WAKE |\
  42. QCOM_ICC_TAG_SLEEP)
  43. /**
  44. * mdss_bus_vote_type: register bus vote type
  45. * VOTE_INDEX_DISABLE: removes the client vote
  46. * VOTE_INDEX_LOW: keeps the lowest vote for register bus
  47. * VOTE_INDEX_MEDIUM: keeps medium vote for register bus
  48. * VOTE_INDEX_HIGH: keeps the highest vote for register bus
  49. * VOTE_INDEX_MAX: invalid
  50. */
  51. enum mdss_bus_vote_type {
  52. VOTE_INDEX_DISABLE,
  53. VOTE_INDEX_LOW,
  54. VOTE_INDEX_MEDIUM,
  55. VOTE_INDEX_HIGH,
  56. VOTE_INDEX_MAX,
  57. };
  58. /**
  59. * enum sde_power_handle_data_bus_client - type of axi bus clients
  60. * @SDE_POWER_HANDLE_DATA_BUS_CLIENT_RT: core real-time bus client
  61. * @SDE_POWER_HANDLE_DATA_BUS_CLIENT_NRT: core non-real-time bus client
  62. * @SDE_POWER_HANDLE_DATA_BUS_CLIENT_MAX: maximum number of bus client type
  63. */
  64. enum sde_power_handle_data_bus_client {
  65. SDE_POWER_HANDLE_DATA_BUS_CLIENT_RT,
  66. SDE_POWER_HANDLE_DATA_BUS_CLIENT_NRT,
  67. SDE_POWER_HANDLE_DATA_BUS_CLIENT_MAX
  68. };
  69. /**
  70. * enum SDE_POWER_HANDLE_DBUS_ID - data bus identifier
  71. * @SDE_POWER_HANDLE_DBUS_ID_MNOC: DPU/MNOC data bus
  72. * @SDE_POWER_HANDLE_DBUS_ID_LLCC: MNOC/LLCC data bus
  73. * @SDE_POWER_HANDLE_DBUS_ID_EBI: LLCC/EBI data bus
  74. */
  75. enum SDE_POWER_HANDLE_DBUS_ID {
  76. SDE_POWER_HANDLE_DBUS_ID_MNOC,
  77. SDE_POWER_HANDLE_DBUS_ID_LLCC,
  78. SDE_POWER_HANDLE_DBUS_ID_EBI,
  79. SDE_POWER_HANDLE_DBUS_ID_MAX,
  80. };
  81. /**
  82. * struct sde_power_bus_scaling_data: struct for bus setting
  83. * @ab: average bandwidth in bytes per second
  84. * @ib: peak bandwidth in bytes per second
  85. */
  86. struct sde_power_bus_scaling_data {
  87. uint64_t ab; /* Arbitrated bandwidth */
  88. uint64_t ib; /* Instantaneous bandwidth */
  89. };
  90. /**
  91. * struct sde_power_data_handle: power handle struct for data bus
  92. * @data_bus_hdl: current data bus handle
  93. * @curr_val : save the current bus value
  94. * @data_paths_cnt: number of rt data path ports
  95. */
  96. struct sde_power_data_bus_handle {
  97. struct icc_path *data_bus_hdl[DATA_BUS_PATH_MAX];
  98. struct sde_power_bus_scaling_data curr_val;
  99. u32 data_paths_cnt;
  100. bool bus_active_only;
  101. };
  102. /**
  103. * struct sde_power_reg_bus_handle: power handle struct for reg bus
  104. * @reg_bus_hdl: reg bus interconnect path handle
  105. * @curr_idx : use-case index in to scale_table for the current vote
  106. * @scale_table: bus scaling bandwidth vote table
  107. */
  108. struct sde_power_reg_bus_handle {
  109. struct icc_path *reg_bus_hdl;
  110. enum mdss_bus_vote_type curr_idx;
  111. struct sde_power_bus_scaling_data scale_table[VOTE_INDEX_MAX];
  112. };
  113. /*
  114. * struct sde_power_event - local event registration structure
  115. * @client_name: name of the client registering
  116. * @cb_fnc: pointer to desired callback function
  117. * @usr: user pointer to pass to callback event trigger
  118. * @event: refer to SDE_POWER_HANDLE_EVENT_*
  119. * @list: list to attach event master list
  120. * @active: indicates the state of sde power handle
  121. */
  122. struct sde_power_event {
  123. char client_name[MAX_CLIENT_NAME_LEN];
  124. void (*cb_fnc)(u32 event_type, void *usr);
  125. void *usr;
  126. u32 event_type;
  127. struct list_head list;
  128. bool active;
  129. };
  130. /*
  131. * struct sde_power_mmrm_reserve - mmrm resource reservation for clk and bw
  132. * @clk_name: name of resource reservation clock
  133. * @clk_rate: resource reservation clock rate
  134. */
  135. struct sde_power_mmrm_reserve {
  136. char clk_name[32];
  137. u64 clk_rate;
  138. };
  139. /**
  140. * struct sde_power_handle: power handle main struct
  141. * @mp: module power for clock and regulator
  142. * @phandle_lock: lock to synchronize the enable/disable
  143. * @dev: pointer to device structure
  144. * @reg_bus_handle: context structure for reg bus control
  145. * @data_bus_handle: context structure for data bus control
  146. * @event_list: current power handle event list
  147. * @rsc_client: sde rsc client pointer
  148. * @rsc_client_init: boolean to control rsc client create
  149. * @mmrm_enable: boolean to indicate if mmrm is enabled
  150. * @ib_quota: ib quota of the given bus
  151. * @mmrm_reserve: mmrm resource reservation
  152. */
  153. struct sde_power_handle {
  154. struct dss_module_power mp;
  155. struct mutex phandle_lock;
  156. struct device *dev;
  157. struct sde_power_reg_bus_handle reg_bus_handle;
  158. struct sde_power_data_bus_handle data_bus_handle
  159. [SDE_POWER_HANDLE_DBUS_ID_MAX];
  160. struct list_head event_list;
  161. u32 last_event_handled;
  162. struct sde_rsc_client *rsc_client;
  163. bool rsc_client_init;
  164. bool mmrm_enable;
  165. u64 ib_quota[SDE_POWER_HANDLE_DBUS_ID_MAX];
  166. struct sde_power_mmrm_reserve mmrm_reserve;
  167. };
  168. /**
  169. * sde_power_resource_init() - initializes the sde power handle
  170. * @pdev: platform device to search the power resources
  171. * @pdata: power handle to store the power resources
  172. *
  173. * Return: error code.
  174. */
  175. int sde_power_resource_init(struct platform_device *pdev,
  176. struct sde_power_handle *pdata);
  177. /**
  178. * sde_power_resource_deinit() - release the sde power handle
  179. * @pdev: platform device for power resources
  180. * @pdata: power handle containing the resources
  181. *
  182. * Return: error code.
  183. */
  184. void sde_power_resource_deinit(struct platform_device *pdev,
  185. struct sde_power_handle *pdata);
  186. /**
  187. * sde_power_resource_enable() - enable/disable the power resources
  188. * @pdata: power handle containing the resources
  189. * @enable: boolean request for enable/disable
  190. *
  191. * Return: error code.
  192. */
  193. int sde_power_resource_enable(struct sde_power_handle *pdata, bool enable);
  194. /**
  195. * sde_power_scale_reg_bus() - Scale the registers bus for the specified client
  196. * @phandle: power handle containing the resources
  197. * @usecase_ndx: new use case to scale the reg bus
  198. * @skip_lock: will skip holding the power rsrc mutex during the call, this is
  199. * for internal callers that already hold this required lock.
  200. *
  201. * Return: error code.
  202. */
  203. int sde_power_scale_reg_bus(struct sde_power_handle *phandle,
  204. u32 usecase_ndx, bool skip_lock);
  205. /**
  206. * sde_power_data_bus_state_update() - update data bus state
  207. * @pdata: power handle containing the resources
  208. * @enable: take enable vs disable path
  209. *
  210. * Return: error code.
  211. */
  212. int sde_power_data_bus_state_update(struct sde_power_handle *phandle,
  213. bool enable);
  214. /**
  215. * sde_power_clk_reserve_rate() - reserve the clock rate with mmrm
  216. * @pdata: power handle containing the resources
  217. * @clock_name: clock name which needs rate update.
  218. * @rate: Requested rate.
  219. *
  220. * Return: error code.
  221. */
  222. int sde_power_clk_reserve_rate(struct sde_power_handle *pdata, char *clock_name, u64 rate);
  223. /**
  224. * sde_power_clk_set_rate() - set the clock rate
  225. * @pdata: power handle containing the resources
  226. * @clock_name: clock name which needs rate update.
  227. * @rate: Requested rate.
  228. * @flags: Flags to be set for this clk
  229. *
  230. * Return: error code.
  231. */
  232. int sde_power_clk_set_rate(struct sde_power_handle *pdata, char *clock_name,
  233. u64 rate, u32 flags);
  234. /**
  235. * sde_power_mmrm_set_clk_limit() - sets a limit for mdp core clk
  236. * @clk: pointer to the mdp core clk
  237. * @phandle: power handle containing the resources
  238. * @requested_clk: limit requested for the core clk
  239. *
  240. * This function must be called in a thread different than the
  241. * commit-thread, otherwise it will always fail, since this function
  242. * sends a notification to user-space to reduce the clk, and then it
  243. * waits for the next commit after this call to reduce the clk rate.
  244. * Hence, if the commit-thread is blocked (by this function waiting)
  245. * or if user-space does not send another commit to reduce the clk,
  246. * this function will timeout after some time and fail.
  247. *
  248. * Return: 0 upon succeeding setting the clk to a value lower or
  249. * equal than the 'requested_clk', otherwise it returns an
  250. * error code.
  251. */
  252. int sde_power_mmrm_set_clk_limit(struct dss_clk *clk,
  253. struct sde_power_handle *phandle, unsigned long requested_clk);
  254. /**
  255. * sde_power_mmrm_get_requested_clk() - get clk rate requested by mmrm
  256. * @pdata: power handle containing the resources
  257. * @clock_name: clock name to get the rate requested by mmrm driver
  258. * to decrease
  259. *
  260. * Return: clock rate requested by mmrm driver, if 0,
  261. * then no active request by mmrm driver
  262. */
  263. u64 sde_power_mmrm_get_requested_clk(struct sde_power_handle *pdata,
  264. char *clock_name);
  265. /**
  266. * sde_power_clk_get_rate() - get the clock rate
  267. * @pdata: power handle containing the resources
  268. * @clock_name: clock name to get the rate
  269. *
  270. * Return: current clock rate
  271. */
  272. u64 sde_power_clk_get_rate(struct sde_power_handle *pdata, char *clock_name);
  273. /**
  274. * sde_power_clk_get_max_rate() - get the maximum clock rate
  275. * @pdata: power handle containing the resources
  276. * @clock_name: clock name to get the max rate.
  277. *
  278. * Return: maximum clock rate or 0 if not found.
  279. */
  280. u64 sde_power_clk_get_max_rate(struct sde_power_handle *pdata,
  281. char *clock_name);
  282. /**
  283. * sde_power_clk_get_clk() - get the clock
  284. * @pdata: power handle containing the resources
  285. * @clock_name: clock name to get the clk pointer.
  286. *
  287. * Return: Pointer to clock
  288. */
  289. struct clk *sde_power_clk_get_clk(struct sde_power_handle *phandle,
  290. char *clock_name);
  291. /**
  292. * sde_power_data_bus_set_quota() - set data bus quota for power client
  293. * @phandle: power handle containing the resources
  294. * @bus_id: identifier of data bus, see SDE_POWER_HANDLE_DBUS_ID
  295. * @ab_quota: arbitrated bus bandwidth
  296. * @ib_quota: instantaneous bus bandwidth
  297. *
  298. * Return: zero if success, or error code otherwise
  299. */
  300. int sde_power_data_bus_set_quota(struct sde_power_handle *phandle,
  301. u32 bus_id, u64 ab_quota, u64 ib_quota);
  302. /**
  303. * sde_power_data_bus_bandwidth_ctrl() - control data bus bandwidth enable
  304. * @phandle: power handle containing the resources
  305. * @enable: true to enable bandwidth for data base
  306. *
  307. * Return: none
  308. */
  309. void sde_power_data_bus_bandwidth_ctrl(struct sde_power_handle *phandle,
  310. int enable);
  311. /**
  312. * sde_power_handle_register_event - register a callback function for an event.
  313. * Clients can register for multiple events with a single register.
  314. * Any block with access to phandle can register for the event
  315. * notification.
  316. * @phandle: power handle containing the resources
  317. * @event_type: event type to register; refer SDE_POWER_HANDLE_EVENT_*
  318. * @cb_fnc: pointer to desired callback function
  319. * @usr: user pointer to pass to callback on event trigger
  320. *
  321. * Return: event pointer if success, or error code otherwise
  322. */
  323. struct sde_power_event *sde_power_handle_register_event(
  324. struct sde_power_handle *phandle,
  325. u32 event_type, void (*cb_fnc)(u32 event_type, void *usr),
  326. void *usr, char *client_name);
  327. /**
  328. * sde_power_handle_unregister_event - unregister callback for event(s)
  329. * @phandle: power handle containing the resources
  330. * @event: event pointer returned after power handle register
  331. */
  332. void sde_power_handle_unregister_event(struct sde_power_handle *phandle,
  333. struct sde_power_event *event);
  334. /**
  335. * sde_power_handle_get_dbus_name - get name of given data bus identifier
  336. * @bus_id: data bus identifier
  337. * Return: Pointer to name string if success; NULL otherwise
  338. */
  339. const char *sde_power_handle_get_dbus_name(u32 bus_id);
  340. #endif /* _SDE_POWER_HANDLE_H_ */