kgsl_pwrctrl.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2010-2021, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2022-2024 Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #ifndef __KGSL_PWRCTRL_H
  7. #define __KGSL_PWRCTRL_H
  8. #include <linux/clk.h>
  9. #include <linux/pm_qos.h>
  10. /*****************************************************************************
  11. * power flags
  12. ****************************************************************************/
  13. #define KGSL_MAX_CLKS 18
  14. #define KGSL_MAX_PWRLEVELS 32
  15. #define KGSL_PWRFLAGS_POWER_ON 0
  16. #define KGSL_PWRFLAGS_CLK_ON 1
  17. #define KGSL_PWRFLAGS_AXI_ON 2
  18. #define KGSL_PWRFLAGS_IRQ_ON 3
  19. /* Use to enable all the force power on states at once */
  20. #define KGSL_PWR_ON GENMASK(5, 0)
  21. /* Only two supported levels, min & max */
  22. #define KGSL_CONSTRAINT_PWR_MAXLEVELS 2
  23. #define KGSL_XO_CLK_FREQ 19200000
  24. #define KGSL_ISENSE_CLK_FREQ 200000000
  25. #define KGSL_PWRCTRL_LOG_FREQLIM(device) dev_err_ratelimited(device->dev, \
  26. "GPU req freq %u from prev freq %u unsupported for speed_bin: %d, soc_code: 0x%x\n", \
  27. device->pwrctrl.pwrlevels[device->pwrctrl.active_pwrlevel].gpu_freq, \
  28. device->pwrctrl.pwrlevels[device->pwrctrl.previous_pwrlevel].gpu_freq, \
  29. device->speed_bin, \
  30. device->soc_code)
  31. struct platform_device;
  32. struct icc_path;
  33. struct kgsl_clk_stats {
  34. unsigned int busy;
  35. unsigned int total;
  36. unsigned int busy_old;
  37. unsigned int total_old;
  38. };
  39. struct kgsl_pwr_constraint {
  40. unsigned int type;
  41. unsigned int sub_type;
  42. unsigned long expires;
  43. uint32_t owner_id;
  44. u32 owner_timestamp;
  45. };
  46. /**
  47. * struct kgsl_pwrlevel - Struct holding different pwrlevel info obtained
  48. * from dtsi file
  49. * @gpu_freq: GPU frequency vote in Hz
  50. * @bus_freq: Bus bandwidth vote index
  51. * @bus_min: Min bus index @gpu_freq
  52. * @bus_max: Max bus index @gpu_freq
  53. */
  54. struct kgsl_pwrlevel {
  55. unsigned int gpu_freq;
  56. unsigned int bus_freq;
  57. unsigned int bus_min;
  58. unsigned int bus_max;
  59. unsigned int acd_level;
  60. /** @cx_level: CX vote */
  61. u32 cx_level;
  62. /** @voltage_level: Voltage level used by the GMU to vote RPMh */
  63. u32 voltage_level;
  64. };
  65. /**
  66. * struct kgsl_pwrctrl - Power control settings for a KGSL device
  67. * @interrupt_num - The interrupt number for the device
  68. * @grp_clks - Array of clocks structures that we control
  69. * @power_flags - Control flags for power
  70. * @pwrlevels - List of supported power levels
  71. * @active_pwrlevel - The currently active power level
  72. * @previous_pwrlevel - The power level before transition
  73. * @thermal_pwrlevel - maximum powerlevel constraint from thermal
  74. * @thermal_pwrlevel_floor - minimum powerlevel constraint from thermal
  75. * @default_pwrlevel - device wake up power level
  76. * @max_pwrlevel - maximum allowable powerlevel per the user
  77. * @min_pwrlevel - minimum allowable powerlevel per the user
  78. * @min_render_pwrlevel - minimum allowable powerlevel for rendering
  79. * @num_pwrlevels - number of available power levels
  80. * @throttle_mask - LM throttle mask
  81. * @interval_timeout - timeout to be idle before a power event
  82. * @clock_times - Each GPU frequency's accumulated active time in us
  83. * @clk_stats - structure of clock statistics
  84. * @input_disable - To disable GPU wakeup on touch input event
  85. * @bus_control - true if the bus calculation is independent
  86. * @bus_mod - modifier from the current power level for the bus vote
  87. * @bus_percent_ab - current percent of total possible bus usage
  88. * @bus_width - target specific bus width in number of bytes
  89. * @bus_ab_mbytes - AB vote in Mbytes for current bus usage
  90. * @constraint - currently active power constraint
  91. * @superfast - Boolean flag to indicate that the GPU start should be run in the
  92. * higher priority thread
  93. * isense_clk_indx - index of isense clock, 0 if no isense
  94. * isense_clk_on_level - isense clock rate is XO rate below this level.
  95. */
  96. struct kgsl_pwrctrl {
  97. int interrupt_num;
  98. struct clk *grp_clks[KGSL_MAX_CLKS];
  99. struct clk *gpu_bimc_int_clk;
  100. /** @cx_gdsc: Pointer to the CX domain regulator if applicable */
  101. struct regulator *cx_gdsc;
  102. /** @gx_gdsc: Pointer to the GX domain regulator if applicable */
  103. struct regulator *gx_gdsc;
  104. /** @gx_gdsc: Pointer to the GX domain parent supply */
  105. struct regulator *gx_gdsc_parent;
  106. /** @gx_gdsc_parent_min_corner: Minimum supply voltage for GX parent */
  107. u32 gx_gdsc_parent_min_corner;
  108. /** @cx_gdsc_nb: Notifier block for cx gdsc regulator */
  109. struct notifier_block cx_gdsc_nb;
  110. /** @cx_gdsc_gate: Completion to signal cx gdsc collapse status */
  111. struct completion cx_gdsc_gate;
  112. /** @cx_gdsc_wait: Whether to wait for cx gdsc to turn off */
  113. bool cx_gdsc_wait;
  114. /** @cx_cfg_gdsc_offset: Offset of CX CFG GDSC register */
  115. u32 cx_cfg_gdsc_offset;
  116. int isense_clk_indx;
  117. int isense_clk_on_level;
  118. unsigned long power_flags;
  119. unsigned long ctrl_flags;
  120. struct kgsl_pwrlevel pwrlevels[KGSL_MAX_PWRLEVELS];
  121. unsigned int active_pwrlevel;
  122. unsigned int previous_pwrlevel;
  123. unsigned int thermal_pwrlevel;
  124. unsigned int thermal_pwrlevel_floor;
  125. unsigned int default_pwrlevel;
  126. unsigned int max_pwrlevel;
  127. unsigned int min_pwrlevel;
  128. unsigned int min_render_pwrlevel;
  129. unsigned int num_pwrlevels;
  130. unsigned int throttle_mask;
  131. u32 interval_timeout;
  132. u64 clock_times[KGSL_MAX_PWRLEVELS];
  133. struct kgsl_clk_stats clk_stats;
  134. bool bus_control;
  135. int bus_mod;
  136. unsigned int bus_percent_ab;
  137. unsigned int bus_width;
  138. unsigned long bus_ab_mbytes;
  139. /** @ddr_table: List of the DDR bandwidths in KBps for the target */
  140. u32 *ddr_table;
  141. /** @ddr_table_count: Number of objects in @ddr_table */
  142. int ddr_table_count;
  143. /** cur_buslevel: The last buslevel voted by the driver */
  144. int cur_buslevel;
  145. /** @bus_max: The maximum bandwidth available to the device */
  146. unsigned long bus_max;
  147. struct kgsl_pwr_constraint constraint;
  148. bool superfast;
  149. unsigned int gpu_bimc_int_clk_freq;
  150. bool gpu_bimc_interface_enabled;
  151. /** @icc_path: Interconnect path for the GPU (if applicable) */
  152. struct icc_path *icc_path;
  153. /** cur_ab: The last ab voted by the driver */
  154. u32 cur_ab;
  155. /** @sysfs_thermal_req - PM QoS maximum frequency request from user (via sysfs) */
  156. struct dev_pm_qos_request sysfs_thermal_req;
  157. /** @time_in_pwrlevel: Each pwrlevel active duration in usec */
  158. u64 time_in_pwrlevel[KGSL_MAX_PWRLEVELS];
  159. /** @last_stat_updated: The last time stats were updated */
  160. ktime_t last_stat_updated;
  161. /** @nb_max: Notifier block for DEV_PM_QOS_MAX_FREQUENCY */
  162. struct notifier_block nb_max;
  163. /** @cur_dcvs_buslevel: Current bus level decided by bus DCVS */
  164. u32 cur_dcvs_buslevel;
  165. /** @rt_bus_hint: IB level hint for real time clients i.e. RB-0 */
  166. u32 rt_bus_hint;
  167. /** @rt_bus_hint_active: Boolean flag to indicate if RT bus hint is active */
  168. bool rt_bus_hint_active;
  169. /** @wake_on_touch: If true our last wakeup was due to a touch event */
  170. bool wake_on_touch;
  171. };
  172. int kgsl_pwrctrl_init(struct kgsl_device *device);
  173. void kgsl_pwrctrl_close(struct kgsl_device *device);
  174. void kgsl_timer(struct timer_list *t);
  175. void kgsl_pre_hwaccess(struct kgsl_device *device);
  176. void kgsl_pwrctrl_pwrlevel_change(struct kgsl_device *device,
  177. unsigned int level);
  178. int kgsl_pwrctrl_init_sysfs(struct kgsl_device *device);
  179. int kgsl_pwrctrl_change_state(struct kgsl_device *device, int state);
  180. unsigned int kgsl_pwrctrl_adjust_pwrlevel(struct kgsl_device *device,
  181. unsigned int new_level);
  182. /*
  183. * kgsl_pwrctrl_active_freq - get currently configured frequency
  184. * @pwr: kgsl_pwrctrl structure for the device
  185. *
  186. * Returns the currently configured frequency for the device.
  187. */
  188. static inline unsigned long
  189. kgsl_pwrctrl_active_freq(struct kgsl_pwrctrl *pwr)
  190. {
  191. return pwr->pwrlevels[pwr->active_pwrlevel].gpu_freq;
  192. }
  193. /**
  194. * kgsl_active_count_wait() - Wait for activity to finish.
  195. * @device: Pointer to a KGSL device
  196. * @count: Active count value to wait for
  197. * @wait_jiffies: Jiffies to wait
  198. *
  199. * Block until the active_cnt value hits the desired value
  200. */
  201. int kgsl_active_count_wait(struct kgsl_device *device, int count,
  202. unsigned long wait_jiffies);
  203. void kgsl_pwrctrl_busy_time(struct kgsl_device *device, u64 time, u64 busy);
  204. /**
  205. * kgsl_pwrctrl_set_constraint() - Validate and change enforced constraint
  206. * @device: Pointer to the kgsl_device struct
  207. * @pwrc: Pointer to requested constraint
  208. * @id: Context id which owns the constraint
  209. * @ts: The timestamp for which this constraint is enforced
  210. *
  211. * Accept the new constraint if no previous constraint existed or if the
  212. * new constraint is faster than the previous one. If the new and previous
  213. * constraints are equal, update the timestamp and ownership to make sure
  214. * the constraint expires at the correct time.
  215. */
  216. void kgsl_pwrctrl_set_constraint(struct kgsl_device *device,
  217. struct kgsl_pwr_constraint *pwrc, u32 id, u32 ts);
  218. int kgsl_pwrctrl_set_default_gpu_pwrlevel(struct kgsl_device *device);
  219. /**
  220. * kgsl_pwrctrl_request_state - Request a specific power state
  221. * @device: Pointer to the kgsl device
  222. * @state: Power state requested
  223. */
  224. void kgsl_pwrctrl_request_state(struct kgsl_device *device, u32 state);
  225. /**
  226. * kgsl_pwrctrl_set_state - Set a specific power state
  227. * @device: Pointer to the kgsl device
  228. * @state: Power state requested
  229. */
  230. void kgsl_pwrctrl_set_state(struct kgsl_device *device, u32 state);
  231. /**
  232. * kgsl_pwrctrl_axi - Propagate bus votes during slumber entry and exit
  233. * @device: Pointer to the kgsl device
  234. * @state: Whether we are going to slumber or coming out of slumber
  235. *
  236. * This function will propagate the default bus vote when coming out of
  237. * slumber and set bus bandwidth to 0 when going into slumber
  238. *
  239. * Return: 0 on success or negative error on failure
  240. */
  241. int kgsl_pwrctrl_axi(struct kgsl_device *device, bool state);
  242. /**
  243. * kgsl_idle_check - kgsl idle function
  244. * @work: work item being run by the function
  245. *
  246. * This function is called for work that is queued by the interrupt
  247. * handler or the idle timer. It attempts to transition to a clocks
  248. * off state if the active_cnt is 0 and the hardware is idle.
  249. */
  250. void kgsl_idle_check(struct work_struct *work);
  251. /**
  252. * kgsl_pwrctrl_irq - Enable or disable gpu interrupts
  253. * @device: Handle to the kgsl device
  254. * @state: Variable to decide whether interrupts need to be enabled or disabled
  255. *
  256. */
  257. void kgsl_pwrctrl_irq(struct kgsl_device *device, bool state);
  258. /**
  259. * kgsl_pwrctrl_clear_l3_vote - Relinquish l3 vote
  260. * @device: Handle to the kgsl device
  261. *
  262. * Clear the l3 vote when going into slumber
  263. */
  264. void kgsl_pwrctrl_clear_l3_vote(struct kgsl_device *device);
  265. /**
  266. * kgsl_pwrctrl_enable_cx_gdsc - Enable cx gdsc
  267. * @device: Pointer to the kgsl device
  268. *
  269. * Return: 0 on success or negative error on failure
  270. */
  271. int kgsl_pwrctrl_enable_cx_gdsc(struct kgsl_device *device);
  272. /**
  273. * kgsl_pwrctrl_disable_cx_gdsc - Disable cx gdsc
  274. * @device: Pointer to the kgsl device
  275. */
  276. void kgsl_pwrctrl_disable_cx_gdsc(struct kgsl_device *device);
  277. /**
  278. * kgsl_pwrctrl_probe_regulators - Probe regulators
  279. * @device: Pointer to the kgsl device
  280. * @pdev: Pointer to the platform device
  281. *
  282. * Return: 0 on success or negative error on failure
  283. */
  284. int kgsl_pwrctrl_probe_regulators(struct kgsl_device *device,
  285. struct platform_device *pdev);
  286. /**
  287. * kgsl_pwrctrl_get_acv_perfmode_lvl - Retrieve DDR level for GPU performance mode
  288. * @device: Pointer to the kgsl device
  289. * @ddr_freq: Target specific DDR frequency from where GPU needs to vote for perf mode
  290. *
  291. * Return: DDR vote level from where GPU should vote for performance mode
  292. */
  293. u32 kgsl_pwrctrl_get_acv_perfmode_lvl(struct kgsl_device *device, u32 ddr_freq);
  294. #endif /* __KGSL_PWRCTRL_H */