blob: 71a0fdd4b614d73cab391318708af04b262b06ee [file] [log] [blame]
Steve Kondikf7652b32013-11-26 15:20:51 -08001/* Copyright (c) 2010-2013, The Linux Foundation. All rights reserved.
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
30struct platform_device;
31
32struct kgsl_clk_stats {
33 unsigned int old_clock_time[KGSL_MAX_PWRLEVELS];
34 unsigned int clock_time[KGSL_MAX_PWRLEVELS];
35 unsigned int on_time_old;
36 ktime_t start;
37 ktime_t stop;
38 unsigned int no_nap_cnt;
39 unsigned int elapsed;
40 unsigned int elapsed_old;
41};
42
43/**
44 * struct kgsl_pwrctrl - Power control settings for a KGSL device
45 * @interrupt_num - The interrupt number for the device
46 * @ebi1_clk - Pointer to the EBI clock structure
47 * @grp_clks - Array of clocks structures that we control
48 * @power_flags - Control flags for power
49 * @pwrlevels - List of supported power levels
50 * @active_pwrlevel - The currently active power level
51 * @thermal_pwrlevel - maximum powerlevel constraint from thermal
52 * @default_pwrlevel - device wake up power level
53 * @init_pwrlevel - device inital power level
54 * @max_pwrlevel - maximum allowable powerlevel per the user
55 * @min_pwrlevel - minimum allowable powerlevel per the user
56 * @num_pwrlevels - number of available power levels
57 * @interval_timeout - timeout in jiffies to be idle before a power event
58 * @strtstp_sleepwake - true if the device supports low latency GPU start/stop
59 * @gpu_reg - pointer to the regulator structure for gpu_reg
60 * @gpu_cx - pointer to the regulator structure for gpu_cx
61 * @pcl - bus scale identifier
62 * @idle_needed - true if the device needs a idle before clock change
63 * @irq_name - resource name for the IRQ
64 * @clk_stats - structure of clock statistics
65 * @pm_qos_req_dma - the power management quality of service structure
66 * @pm_qos_latency - allowed CPU latency in microseconds
67 * @step_mul - multiplier for moving between power levels
68 */
69
70struct kgsl_pwrctrl {
71 int interrupt_num;
72 struct clk *ebi1_clk;
73 struct clk *grp_clks[KGSL_MAX_CLKS];
74 unsigned long power_flags;
75 unsigned long ctrl_flags;
76 struct kgsl_pwrlevel pwrlevels[KGSL_MAX_PWRLEVELS];
77 unsigned int active_pwrlevel;
78 int thermal_pwrlevel;
79 unsigned int default_pwrlevel;
80 unsigned int init_pwrlevel;
81 unsigned int max_pwrlevel;
82 unsigned int min_pwrlevel;
83 unsigned int num_pwrlevels;
84 unsigned int interval_timeout;
85 bool strtstp_sleepwake;
86 struct regulator *gpu_reg;
87 struct regulator *gpu_cx;
88 uint32_t pcl;
89 unsigned int idle_needed;
90 const char *irq_name;
91 s64 time;
92 struct kgsl_clk_stats clk_stats;
93 struct pm_qos_request pm_qos_req_dma;
94 unsigned int pm_qos_latency;
95 unsigned int step_mul;
96 unsigned int irq_last;
97};
98
99void kgsl_pwrctrl_irq(struct kgsl_device *device, int state);
100int kgsl_pwrctrl_init(struct kgsl_device *device);
101void kgsl_pwrctrl_close(struct kgsl_device *device);
102void kgsl_timer(unsigned long data);
103void kgsl_idle_check(struct work_struct *work);
104void kgsl_pre_hwaccess(struct kgsl_device *device);
105int kgsl_pwrctrl_sleep(struct kgsl_device *device);
106int kgsl_pwrctrl_wake(struct kgsl_device *device);
107void kgsl_pwrctrl_pwrlevel_change(struct kgsl_device *device,
108 unsigned int level);
109int kgsl_pwrctrl_init_sysfs(struct kgsl_device *device);
110void kgsl_pwrctrl_uninit_sysfs(struct kgsl_device *device);
111void kgsl_pwrctrl_enable(struct kgsl_device *device);
112void kgsl_pwrctrl_disable(struct kgsl_device *device);
113bool kgsl_pwrctrl_isenabled(struct kgsl_device *device);
114
115static inline unsigned long kgsl_get_clkrate(struct clk *clk)
116{
117 return (clk != NULL) ? clk_get_rate(clk) : 0;
118}
119
120void kgsl_pwrctrl_set_state(struct kgsl_device *device, unsigned int state);
121void kgsl_pwrctrl_request_state(struct kgsl_device *device, unsigned int state);
122
123int kgsl_active_count_get(struct kgsl_device *device);
124int kgsl_active_count_get_light(struct kgsl_device *device);
125void kgsl_active_count_put(struct kgsl_device *device);
126int kgsl_active_count_wait(struct kgsl_device *device, int count);
127
128#endif /* __KGSL_PWRCTRL_H */