sde_power_handle.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2016-2019, 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 3000000000
  14. #define SDE_POWER_HANDLE_CONT_SPLASH_BUS_AB_QUOTA 3000000000
  15. #include <linux/sde_io_util.h>
  16. #include <soc/qcom/cx_ipeak.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. /**
  26. * mdss_bus_vote_type: register bus vote type
  27. * VOTE_INDEX_DISABLE: removes the client vote
  28. * VOTE_INDEX_LOW: keeps the lowest vote for register bus
  29. * VOTE_INDEX_MEDIUM: keeps medium vote for register bus
  30. * VOTE_INDEX_HIGH: keeps the highest vote for register bus
  31. * VOTE_INDEX_MAX: invalid
  32. */
  33. enum mdss_bus_vote_type {
  34. VOTE_INDEX_DISABLE,
  35. VOTE_INDEX_LOW,
  36. VOTE_INDEX_MEDIUM,
  37. VOTE_INDEX_HIGH,
  38. VOTE_INDEX_MAX,
  39. };
  40. /**
  41. * enum sde_power_handle_data_bus_client - type of axi bus clients
  42. * @SDE_POWER_HANDLE_DATA_BUS_CLIENT_RT: core real-time bus client
  43. * @SDE_POWER_HANDLE_DATA_BUS_CLIENT_NRT: core non-real-time bus client
  44. * @SDE_POWER_HANDLE_DATA_BUS_CLIENT_MAX: maximum number of bus client type
  45. */
  46. enum sde_power_handle_data_bus_client {
  47. SDE_POWER_HANDLE_DATA_BUS_CLIENT_RT,
  48. SDE_POWER_HANDLE_DATA_BUS_CLIENT_NRT,
  49. SDE_POWER_HANDLE_DATA_BUS_CLIENT_MAX
  50. };
  51. /**
  52. * enum SDE_POWER_HANDLE_DBUS_ID - data bus identifier
  53. * @SDE_POWER_HANDLE_DBUS_ID_MNOC: DPU/MNOC data bus
  54. * @SDE_POWER_HANDLE_DBUS_ID_LLCC: MNOC/LLCC data bus
  55. * @SDE_POWER_HANDLE_DBUS_ID_EBI: LLCC/EBI data bus
  56. */
  57. enum SDE_POWER_HANDLE_DBUS_ID {
  58. SDE_POWER_HANDLE_DBUS_ID_MNOC,
  59. SDE_POWER_HANDLE_DBUS_ID_LLCC,
  60. SDE_POWER_HANDLE_DBUS_ID_EBI,
  61. SDE_POWER_HANDLE_DBUS_ID_MAX,
  62. };
  63. /**
  64. * struct sde_power_data_handle: power handle struct for data bus
  65. * @data_bus_scale_table: pointer to bus scaling table
  66. * @data_bus_hdl: current data bus handle
  67. * @data_paths_cnt: number of rt data path ports
  68. * @curr_bw_uc_idx: current use case index of data bus
  69. * @ao_bw_uc_idx: active only use case index of data bus
  70. * @ab_rt: realtime ab quota
  71. * @ib_rt: realtime ib quota
  72. * @ab_nrt: non-realtime ab quota
  73. * @ib_nrt: non-realtime ib quota
  74. * @enable: true if bus is enabled
  75. */
  76. struct sde_power_data_bus_handle {
  77. struct msm_bus_scale_pdata *data_bus_scale_table;
  78. u32 data_bus_hdl;
  79. u32 data_paths_cnt;
  80. u32 curr_bw_uc_idx;
  81. u32 ao_bw_uc_idx;
  82. u64 ab_rt;
  83. u64 ib_rt;
  84. u64 ab_nrt;
  85. u64 ib_nrt;
  86. bool enable;
  87. };
  88. /*
  89. * struct sde_power_event - local event registration structure
  90. * @client_name: name of the client registering
  91. * @cb_fnc: pointer to desired callback function
  92. * @usr: user pointer to pass to callback event trigger
  93. * @event: refer to SDE_POWER_HANDLE_EVENT_*
  94. * @list: list to attach event master list
  95. * @active: indicates the state of sde power handle
  96. */
  97. struct sde_power_event {
  98. char client_name[MAX_CLIENT_NAME_LEN];
  99. void (*cb_fnc)(u32 event_type, void *usr);
  100. void *usr;
  101. u32 event_type;
  102. struct list_head list;
  103. bool active;
  104. };
  105. /**
  106. * struct sde_power_handle: power handle main struct
  107. * @mp: module power for clock and regulator
  108. * @phandle_lock: lock to synchronize the enable/disable
  109. * @dev: pointer to device structure
  110. * @usecase_ndx: current usecase index
  111. * @reg_bus_hdl: current register bus handle
  112. * @data_bus_handle: context structure for data bus control
  113. * @event_list: current power handle event list
  114. * @rsc_client: sde rsc client pointer
  115. * @rsc_client_init: boolean to control rsc client create
  116. * @dss_cx_ipeak: client pointer for cx ipeak driver
  117. */
  118. struct sde_power_handle {
  119. struct dss_module_power mp;
  120. struct mutex phandle_lock;
  121. struct device *dev;
  122. u32 current_usecase_ndx;
  123. u32 reg_bus_hdl;
  124. struct sde_power_data_bus_handle data_bus_handle
  125. [SDE_POWER_HANDLE_DBUS_ID_MAX];
  126. struct list_head event_list;
  127. struct sde_rsc_client *rsc_client;
  128. bool rsc_client_init;
  129. struct cx_ipeak_client *dss_cx_ipeak;
  130. };
  131. /**
  132. * sde_power_resource_init() - initializes the sde power handle
  133. * @pdev: platform device to search the power resources
  134. * @pdata: power handle to store the power resources
  135. *
  136. * Return: error code.
  137. */
  138. int sde_power_resource_init(struct platform_device *pdev,
  139. struct sde_power_handle *pdata);
  140. /**
  141. * sde_power_resource_deinit() - release the sde power handle
  142. * @pdev: platform device for power resources
  143. * @pdata: power handle containing the resources
  144. *
  145. * Return: error code.
  146. */
  147. void sde_power_resource_deinit(struct platform_device *pdev,
  148. struct sde_power_handle *pdata);
  149. /**
  150. * sde_power_resource_enable() - enable/disable the power resources
  151. * @pdata: power handle containing the resources
  152. * @enable: boolean request for enable/disable
  153. *
  154. * Return: error code.
  155. */
  156. int sde_power_resource_enable(struct sde_power_handle *pdata, bool enable);
  157. /**
  158. * sde_power_scale_reg_bus() - Scale the registers bus for the specified client
  159. * @phandle: power handle containing the resources
  160. * @usecase_ndx: new use case to scale the reg bus
  161. * @skip_lock: will skip holding the power rsrc mutex during the call, this is
  162. * for internal callers that already hold this required lock.
  163. *
  164. * Return: error code.
  165. */
  166. int sde_power_scale_reg_bus(struct sde_power_handle *phandle,
  167. u32 usecase_ndx, bool skip_lock);
  168. /**
  169. * sde_power_data_bus_state_update() - update data bus state
  170. * @pdata: power handle containing the resources
  171. * @enable: take enable vs disable path
  172. *
  173. * Return: error code.
  174. */
  175. int sde_power_data_bus_state_update(struct sde_power_handle *phandle,
  176. bool enable);
  177. /**
  178. * sde_power_clk_set_rate() - set the clock rate
  179. * @pdata: power handle containing the resources
  180. * @clock_name: clock name which needs rate update.
  181. * @rate: Requested rate.
  182. *
  183. * Return: error code.
  184. */
  185. int sde_power_clk_set_rate(struct sde_power_handle *pdata, char *clock_name,
  186. u64 rate);
  187. /**
  188. * sde_power_clk_get_rate() - get the clock rate
  189. * @pdata: power handle containing the resources
  190. * @clock_name: clock name to get the rate
  191. *
  192. * Return: current clock rate
  193. */
  194. u64 sde_power_clk_get_rate(struct sde_power_handle *pdata, char *clock_name);
  195. /**
  196. * sde_power_clk_get_max_rate() - get the maximum clock rate
  197. * @pdata: power handle containing the resources
  198. * @clock_name: clock name to get the max rate.
  199. *
  200. * Return: maximum clock rate or 0 if not found.
  201. */
  202. u64 sde_power_clk_get_max_rate(struct sde_power_handle *pdata,
  203. char *clock_name);
  204. /**
  205. * sde_power_clk_get_clk() - get the clock
  206. * @pdata: power handle containing the resources
  207. * @clock_name: clock name to get the clk pointer.
  208. *
  209. * Return: Pointer to clock
  210. */
  211. struct clk *sde_power_clk_get_clk(struct sde_power_handle *phandle,
  212. char *clock_name);
  213. /**
  214. * sde_power_clk_set_flags() - set the clock flags
  215. * @pdata: power handle containing the resources
  216. * @clock_name: clock name to get the clk pointer.
  217. * @flags: flags to set
  218. *
  219. * Return: error code.
  220. */
  221. int sde_power_clk_set_flags(struct sde_power_handle *pdata,
  222. char *clock_name, unsigned long flags);
  223. /**
  224. * sde_power_data_bus_set_quota() - set data bus quota for power client
  225. * @phandle: power handle containing the resources
  226. * @bus_id: identifier of data bus, see SDE_POWER_HANDLE_DBUS_ID
  227. * @ab_quota: arbitrated bus bandwidth
  228. * @ib_quota: instantaneous bus bandwidth
  229. *
  230. * Return: zero if success, or error code otherwise
  231. */
  232. int sde_power_data_bus_set_quota(struct sde_power_handle *phandle,
  233. u32 bus_id, u64 ab_quota, u64 ib_quota);
  234. /**
  235. * sde_power_data_bus_bandwidth_ctrl() - control data bus bandwidth enable
  236. * @phandle: power handle containing the resources
  237. * @enable: true to enable bandwidth for data base
  238. *
  239. * Return: none
  240. */
  241. void sde_power_data_bus_bandwidth_ctrl(struct sde_power_handle *phandle,
  242. int enable);
  243. /**
  244. * sde_power_handle_register_event - register a callback function for an event.
  245. * Clients can register for multiple events with a single register.
  246. * Any block with access to phandle can register for the event
  247. * notification.
  248. * @phandle: power handle containing the resources
  249. * @event_type: event type to register; refer SDE_POWER_HANDLE_EVENT_*
  250. * @cb_fnc: pointer to desired callback function
  251. * @usr: user pointer to pass to callback on event trigger
  252. *
  253. * Return: event pointer if success, or error code otherwise
  254. */
  255. struct sde_power_event *sde_power_handle_register_event(
  256. struct sde_power_handle *phandle,
  257. u32 event_type, void (*cb_fnc)(u32 event_type, void *usr),
  258. void *usr, char *client_name);
  259. /**
  260. * sde_power_handle_unregister_event - unregister callback for event(s)
  261. * @phandle: power handle containing the resources
  262. * @event: event pointer returned after power handle register
  263. */
  264. void sde_power_handle_unregister_event(struct sde_power_handle *phandle,
  265. struct sde_power_event *event);
  266. /**
  267. * sde_power_handle_get_dbus_name - get name of given data bus identifier
  268. * @bus_id: data bus identifier
  269. * Return: Pointer to name string if success; NULL otherwise
  270. */
  271. const char *sde_power_handle_get_dbus_name(u32 bus_id);
  272. #endif /* _SDE_POWER_HANDLE_H_ */