Ethan Chen | 7b18590 | 2014-11-16 16:48:31 -0800 | [diff] [blame^] | 1 | /* Copyright (c) 2010-2014, The Linux Foundation. All rights reserved. |
Steve Kondik | f7652b3 | 2013-11-26 15:20:51 -0800 | [diff] [blame] | 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | * |
| 12 | */ |
| 13 | #ifndef __KGSL_PWRCTRL_H |
| 14 | #define __KGSL_PWRCTRL_H |
| 15 | |
| 16 | /***************************************************************************** |
| 17 | ** power flags |
| 18 | *****************************************************************************/ |
| 19 | #define KGSL_PWRFLAGS_ON 1 |
| 20 | #define KGSL_PWRFLAGS_OFF 0 |
| 21 | |
| 22 | #define KGSL_PWRLEVEL_TURBO 0 |
| 23 | #define KGSL_PWRLEVEL_NOMINAL 1 |
| 24 | #define KGSL_PWRLEVEL_LAST_OFFSET 2 |
| 25 | |
| 26 | #define KGSL_PWR_ON 0xFFFF |
| 27 | |
| 28 | #define KGSL_MAX_CLKS 6 |
| 29 | |
Ethan Chen | 7b18590 | 2014-11-16 16:48:31 -0800 | [diff] [blame^] | 30 | /* Only two supported levels, min & max */ |
| 31 | #define KGSL_CONSTRAINT_PWR_MAXLEVELS 2 |
| 32 | |
| 33 | /* Symbolic table for the constraint type */ |
| 34 | #define KGSL_CONSTRAINT_TYPES \ |
| 35 | { KGSL_CONSTRAINT_NONE, "None" }, \ |
| 36 | { KGSL_CONSTRAINT_PWRLEVEL, "Pwrlevel" } |
| 37 | /* Symbolic table for the constraint sub type */ |
| 38 | #define KGSL_CONSTRAINT_PWRLEVEL_SUBTYPES \ |
| 39 | { KGSL_CONSTRAINT_PWR_MIN, "Min" }, \ |
| 40 | { KGSL_CONSTRAINT_PWR_MAX, "Max" } |
| 41 | |
Steve Kondik | f7652b3 | 2013-11-26 15:20:51 -0800 | [diff] [blame] | 42 | struct platform_device; |
| 43 | |
| 44 | struct kgsl_clk_stats { |
| 45 | unsigned int old_clock_time[KGSL_MAX_PWRLEVELS]; |
| 46 | unsigned int clock_time[KGSL_MAX_PWRLEVELS]; |
| 47 | unsigned int on_time_old; |
| 48 | ktime_t start; |
| 49 | ktime_t stop; |
| 50 | unsigned int no_nap_cnt; |
| 51 | unsigned int elapsed; |
| 52 | unsigned int elapsed_old; |
| 53 | }; |
| 54 | |
Ethan Chen | 7b18590 | 2014-11-16 16:48:31 -0800 | [diff] [blame^] | 55 | struct kgsl_pwr_constraint { |
| 56 | unsigned int type; |
| 57 | unsigned int sub_type; |
| 58 | union { |
| 59 | struct { |
| 60 | unsigned int level; |
| 61 | } pwrlevel; |
| 62 | } hint; |
| 63 | unsigned long expires; |
| 64 | uint32_t owner_id; |
| 65 | }; |
| 66 | |
Steve Kondik | f7652b3 | 2013-11-26 15:20:51 -0800 | [diff] [blame] | 67 | /** |
| 68 | * struct kgsl_pwrctrl - Power control settings for a KGSL device |
| 69 | * @interrupt_num - The interrupt number for the device |
| 70 | * @ebi1_clk - Pointer to the EBI clock structure |
| 71 | * @grp_clks - Array of clocks structures that we control |
| 72 | * @power_flags - Control flags for power |
| 73 | * @pwrlevels - List of supported power levels |
| 74 | * @active_pwrlevel - The currently active power level |
| 75 | * @thermal_pwrlevel - maximum powerlevel constraint from thermal |
| 76 | * @default_pwrlevel - device wake up power level |
| 77 | * @init_pwrlevel - device inital power level |
| 78 | * @max_pwrlevel - maximum allowable powerlevel per the user |
| 79 | * @min_pwrlevel - minimum allowable powerlevel per the user |
| 80 | * @num_pwrlevels - number of available power levels |
| 81 | * @interval_timeout - timeout in jiffies to be idle before a power event |
| 82 | * @strtstp_sleepwake - true if the device supports low latency GPU start/stop |
| 83 | * @gpu_reg - pointer to the regulator structure for gpu_reg |
| 84 | * @gpu_cx - pointer to the regulator structure for gpu_cx |
| 85 | * @pcl - bus scale identifier |
| 86 | * @idle_needed - true if the device needs a idle before clock change |
| 87 | * @irq_name - resource name for the IRQ |
| 88 | * @clk_stats - structure of clock statistics |
| 89 | * @pm_qos_req_dma - the power management quality of service structure |
| 90 | * @pm_qos_latency - allowed CPU latency in microseconds |
| 91 | * @step_mul - multiplier for moving between power levels |
Ethan Chen | 7b18590 | 2014-11-16 16:48:31 -0800 | [diff] [blame^] | 92 | * @constraint - currently active power constraint |
Steve Kondik | f7652b3 | 2013-11-26 15:20:51 -0800 | [diff] [blame] | 93 | */ |
| 94 | |
| 95 | struct kgsl_pwrctrl { |
| 96 | int interrupt_num; |
| 97 | struct clk *ebi1_clk; |
| 98 | struct clk *grp_clks[KGSL_MAX_CLKS]; |
| 99 | unsigned long power_flags; |
| 100 | unsigned long ctrl_flags; |
| 101 | struct kgsl_pwrlevel pwrlevels[KGSL_MAX_PWRLEVELS]; |
| 102 | unsigned int active_pwrlevel; |
| 103 | int thermal_pwrlevel; |
| 104 | unsigned int default_pwrlevel; |
| 105 | unsigned int init_pwrlevel; |
| 106 | unsigned int max_pwrlevel; |
| 107 | unsigned int min_pwrlevel; |
| 108 | unsigned int num_pwrlevels; |
| 109 | unsigned int interval_timeout; |
| 110 | bool strtstp_sleepwake; |
| 111 | struct regulator *gpu_reg; |
| 112 | struct regulator *gpu_cx; |
| 113 | uint32_t pcl; |
| 114 | unsigned int idle_needed; |
| 115 | const char *irq_name; |
| 116 | s64 time; |
| 117 | struct kgsl_clk_stats clk_stats; |
| 118 | struct pm_qos_request pm_qos_req_dma; |
| 119 | unsigned int pm_qos_latency; |
| 120 | unsigned int step_mul; |
| 121 | unsigned int irq_last; |
Ethan Chen | 7b18590 | 2014-11-16 16:48:31 -0800 | [diff] [blame^] | 122 | struct kgsl_pwr_constraint constraint; |
Steve Kondik | f7652b3 | 2013-11-26 15:20:51 -0800 | [diff] [blame] | 123 | }; |
| 124 | |
| 125 | void kgsl_pwrctrl_irq(struct kgsl_device *device, int state); |
| 126 | int kgsl_pwrctrl_init(struct kgsl_device *device); |
| 127 | void kgsl_pwrctrl_close(struct kgsl_device *device); |
| 128 | void kgsl_timer(unsigned long data); |
| 129 | void kgsl_idle_check(struct work_struct *work); |
| 130 | void kgsl_pre_hwaccess(struct kgsl_device *device); |
| 131 | int kgsl_pwrctrl_sleep(struct kgsl_device *device); |
| 132 | int kgsl_pwrctrl_wake(struct kgsl_device *device); |
| 133 | void kgsl_pwrctrl_pwrlevel_change(struct kgsl_device *device, |
| 134 | unsigned int level); |
| 135 | int kgsl_pwrctrl_init_sysfs(struct kgsl_device *device); |
| 136 | void kgsl_pwrctrl_uninit_sysfs(struct kgsl_device *device); |
| 137 | void kgsl_pwrctrl_enable(struct kgsl_device *device); |
| 138 | void kgsl_pwrctrl_disable(struct kgsl_device *device); |
| 139 | bool kgsl_pwrctrl_isenabled(struct kgsl_device *device); |
| 140 | |
| 141 | static inline unsigned long kgsl_get_clkrate(struct clk *clk) |
| 142 | { |
| 143 | return (clk != NULL) ? clk_get_rate(clk) : 0; |
| 144 | } |
| 145 | |
| 146 | void kgsl_pwrctrl_set_state(struct kgsl_device *device, unsigned int state); |
| 147 | void kgsl_pwrctrl_request_state(struct kgsl_device *device, unsigned int state); |
| 148 | |
Steve Kondik | 2deaf4b | 2014-03-20 22:29:09 -0700 | [diff] [blame] | 149 | int __must_check kgsl_active_count_get(struct kgsl_device *device); |
| 150 | int __must_check kgsl_active_count_get_light(struct kgsl_device *device); |
Steve Kondik | f7652b3 | 2013-11-26 15:20:51 -0800 | [diff] [blame] | 151 | void kgsl_active_count_put(struct kgsl_device *device); |
| 152 | int kgsl_active_count_wait(struct kgsl_device *device, int count); |
| 153 | |
| 154 | #endif /* __KGSL_PWRCTRL_H */ |