blob: ece58fafa3212b18498c20df3d3c49e42ed20ef0 [file] [log] [blame]
Ethan Chen7b185902014-11-16 16:48:31 -08001/* Copyright (c) 2010-2014, The Linux Foundation. All rights reserved.
Steve Kondikf7652b32013-11-26 15:20:51 -08002 *
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 Chen7b185902014-11-16 16:48:31 -080030/* 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 Kondikf7652b32013-11-26 15:20:51 -080042struct platform_device;
43
44struct 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 Chen7b185902014-11-16 16:48:31 -080055struct 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 Kondikf7652b32013-11-26 15:20:51 -080067/**
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 Chen7b185902014-11-16 16:48:31 -080092 * @constraint - currently active power constraint
Steve Kondikf7652b32013-11-26 15:20:51 -080093 */
94
95struct 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 Chen7b185902014-11-16 16:48:31 -0800122 struct kgsl_pwr_constraint constraint;
Steve Kondikf7652b32013-11-26 15:20:51 -0800123};
124
125void kgsl_pwrctrl_irq(struct kgsl_device *device, int state);
126int kgsl_pwrctrl_init(struct kgsl_device *device);
127void kgsl_pwrctrl_close(struct kgsl_device *device);
128void kgsl_timer(unsigned long data);
129void kgsl_idle_check(struct work_struct *work);
130void kgsl_pre_hwaccess(struct kgsl_device *device);
131int kgsl_pwrctrl_sleep(struct kgsl_device *device);
132int kgsl_pwrctrl_wake(struct kgsl_device *device);
133void kgsl_pwrctrl_pwrlevel_change(struct kgsl_device *device,
134 unsigned int level);
135int kgsl_pwrctrl_init_sysfs(struct kgsl_device *device);
136void kgsl_pwrctrl_uninit_sysfs(struct kgsl_device *device);
137void kgsl_pwrctrl_enable(struct kgsl_device *device);
138void kgsl_pwrctrl_disable(struct kgsl_device *device);
139bool kgsl_pwrctrl_isenabled(struct kgsl_device *device);
140
141static inline unsigned long kgsl_get_clkrate(struct clk *clk)
142{
143 return (clk != NULL) ? clk_get_rate(clk) : 0;
144}
145
146void kgsl_pwrctrl_set_state(struct kgsl_device *device, unsigned int state);
147void kgsl_pwrctrl_request_state(struct kgsl_device *device, unsigned int state);
148
Steve Kondik2deaf4b2014-03-20 22:29:09 -0700149int __must_check kgsl_active_count_get(struct kgsl_device *device);
150int __must_check kgsl_active_count_get_light(struct kgsl_device *device);
Steve Kondikf7652b32013-11-26 15:20:51 -0800151void kgsl_active_count_put(struct kgsl_device *device);
152int kgsl_active_count_wait(struct kgsl_device *device, int count);
153
154#endif /* __KGSL_PWRCTRL_H */