arm: tegra: power: Update dynamic CPU EDP model
[linux-3.10.git] / arch / arm / mach-tegra / edp.c
1 /*
2  * arch/arm/mach-tegra/edp.c
3  *
4  * Copyright (C) 2011-2012, NVIDIA CORPORATION. All Rights Reserved.
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
18  * 02111-1307, USA
19  */
20
21 #include <linux/kernel.h>
22 #include <linux/init.h>
23 #include <linux/seq_file.h>
24 #include <linux/slab.h>
25 #include <linux/module.h>
26 #include <linux/uaccess.h>
27 #include <mach/edp.h>
28
29 #include "fuse.h"
30 #include "dvfs.h"
31 #include "clock.h"
32 #include "cpu-tegra.h"
33
34 #define FREQ_STEP 10000000
35 #define TEMP_LUT_MAX 68
36 #define EDP_CALCULATED_LIMITS_SIZE TEMP_LUT_MAX
37
38 static struct tegra_edp_limits *edp_limits;
39 static int edp_limits_size;
40 static unsigned int regulator_cur;
41 /* Value to subtract from regulator current limit */
42 static unsigned int edp_reg_override_mA = 0;
43
44 static const unsigned int *system_edp_limits;
45
46 /*
47  * Temperature step size cannot be less than 4C because of hysteresis
48  * delta
49  * Code assumes different temperatures for the same speedo_id /
50  * regulator_cur are adjacent in the table, and higest regulator_cur
51  * comes first
52  */
53 static char __initdata tegra_edp_map[] = {
54         0x00, 0x2f, 0x17, 0x7d, 0x73, 0x73, 0x73, 0x00,
55         0x2f, 0x2d, 0x82, 0x78, 0x78, 0x78, 0x00, 0x2f,
56         0x3c, 0x82, 0x78, 0x78, 0x78, 0x00, 0x2f, 0x4b,
57         0x82, 0x78, 0x78, 0x78, 0x00, 0x2f, 0x55, 0x82,
58         0x78, 0x78, 0x78, 0x00, 0x28, 0x17, 0x7d, 0x73,
59         0x73, 0x73, 0x00, 0x28, 0x2d, 0x82, 0x78, 0x78,
60         0x78, 0x00, 0x28, 0x3c, 0x82, 0x78, 0x78, 0x78,
61         0x00, 0x28, 0x4b, 0x82, 0x78, 0x78, 0x73, 0x00,
62         0x28, 0x55, 0x82, 0x78, 0x78, 0x69, 0x00, 0x23,
63         0x17, 0x7d, 0x73, 0x73, 0x73, 0x00, 0x23, 0x2d,
64         0x82, 0x78, 0x78, 0x78, 0x00, 0x23, 0x3c, 0x82,
65         0x78, 0x78, 0x6e, 0x00, 0x23, 0x4b, 0x82, 0x78,
66         0x78, 0x64, 0x00, 0x23, 0x55, 0x82, 0x78, 0x6e,
67         0x5a, 0x00, 0x1e, 0x17, 0x7d, 0x73, 0x73, 0x64,
68         0x00, 0x1e, 0x2d, 0x82, 0x78, 0x78, 0x69, 0x00,
69         0x1e, 0x3c, 0x82, 0x78, 0x78, 0x64, 0x00, 0x1e,
70         0x4b, 0x82, 0x78, 0x6e, 0x5a, 0x00, 0x1e, 0x55,
71         0x82, 0x78, 0x64, 0x50, 0x00, 0x19, 0x17, 0x7d,
72         0x73, 0x69, 0x55, 0x00, 0x19, 0x2d, 0x82, 0x78,
73         0x6e, 0x5a, 0x00, 0x19, 0x3c, 0x82, 0x78, 0x69,
74         0x55, 0x00, 0x19, 0x4b, 0x82, 0x78, 0x5f, 0x4b,
75         0x00, 0x19, 0x55, 0x82, 0x73, 0x55, 0x3c, 0x01,
76         0x2f, 0x17, 0x7d, 0x73, 0x73, 0x73, 0x01, 0x2f,
77         0x2d, 0x82, 0x78, 0x78, 0x78, 0x01, 0x2f, 0x3c,
78         0x82, 0x78, 0x78, 0x78, 0x01, 0x2f, 0x4b, 0x82,
79         0x78, 0x78, 0x78, 0x01, 0x2f, 0x55, 0x82, 0x78,
80         0x78, 0x78, 0x01, 0x28, 0x17, 0x7d, 0x73, 0x73,
81         0x73, 0x01, 0x28, 0x2d, 0x82, 0x78, 0x78, 0x78,
82         0x01, 0x28, 0x3c, 0x82, 0x78, 0x78, 0x78, 0x01,
83         0x28, 0x4b, 0x82, 0x78, 0x78, 0x73, 0x01, 0x28,
84         0x55, 0x82, 0x78, 0x78, 0x69, 0x01, 0x23, 0x17,
85         0x7d, 0x73, 0x73, 0x73, 0x01, 0x23, 0x2d, 0x82,
86         0x78, 0x78, 0x78, 0x01, 0x23, 0x3c, 0x82, 0x78,
87         0x78, 0x6e, 0x01, 0x23, 0x4b, 0x82, 0x78, 0x78,
88         0x64, 0x01, 0x23, 0x55, 0x82, 0x78, 0x6e, 0x5a,
89         0x01, 0x1e, 0x17, 0x7d, 0x73, 0x73, 0x64, 0x01,
90         0x1e, 0x2d, 0x82, 0x78, 0x78, 0x69, 0x01, 0x1e,
91         0x3c, 0x82, 0x78, 0x78, 0x64, 0x01, 0x1e, 0x4b,
92         0x82, 0x78, 0x6e, 0x5a, 0x01, 0x1e, 0x55, 0x82,
93         0x78, 0x64, 0x50, 0x01, 0x19, 0x17, 0x7d, 0x73,
94         0x69, 0x55, 0x01, 0x19, 0x2d, 0x82, 0x78, 0x6e,
95         0x5a, 0x01, 0x19, 0x3c, 0x82, 0x78, 0x69, 0x55,
96         0x01, 0x19, 0x4b, 0x82, 0x78, 0x5f, 0x4b, 0x01,
97         0x19, 0x55, 0x82, 0x73, 0x55, 0x3c, 0x02, 0x3d,
98         0x17, 0x87, 0x7d, 0x7d, 0x7d, 0x02, 0x3d, 0x2d,
99         0x8c, 0x82, 0x82, 0x82, 0x02, 0x3d, 0x3c, 0x8c,
100         0x82, 0x82, 0x82, 0x02, 0x3d, 0x4b, 0x8c, 0x82,
101         0x82, 0x82, 0x02, 0x3d, 0x55, 0x8c, 0x82, 0x82,
102         0x82, 0x02, 0x32, 0x17, 0x87, 0x7d, 0x7d, 0x7d,
103         0x02, 0x32, 0x2d, 0x8c, 0x82, 0x82, 0x82, 0x02,
104         0x32, 0x3c, 0x8c, 0x82, 0x82, 0x82, 0x02, 0x32,
105         0x4b, 0x8c, 0x82, 0x82, 0x78, 0x02, 0x32, 0x55,
106         0x8c, 0x82, 0x82, 0x6e, 0x02, 0x28, 0x17, 0x87,
107         0x7d, 0x7d, 0x73, 0x02, 0x28, 0x2d, 0x8c, 0x82,
108         0x82, 0x78, 0x02, 0x28, 0x3c, 0x8c, 0x82, 0x82,
109         0x73, 0x02, 0x28, 0x4b, 0x8c, 0x82, 0x78, 0x69,
110         0x02, 0x28, 0x55, 0x8c, 0x82, 0x6e, 0x5a, 0x02,
111         0x23, 0x17, 0x87, 0x7d, 0x7d, 0x69, 0x02, 0x23,
112         0x2d, 0x8c, 0x82, 0x82, 0x6e, 0x02, 0x23, 0x3c,
113         0x8c, 0x82, 0x78, 0x69, 0x02, 0x23, 0x4b, 0x8c,
114         0x82, 0x6e, 0x5a, 0x02, 0x23, 0x55, 0x8c, 0x82,
115         0x64, 0x50, 0x03, 0x3d, 0x17, 0x87, 0x7d, 0x7d,
116         0x7d, 0x03, 0x3d, 0x2d, 0x8c, 0x82, 0x82, 0x82,
117         0x03, 0x3d, 0x3c, 0x8c, 0x82, 0x82, 0x82, 0x03,
118         0x3d, 0x4b, 0x8c, 0x82, 0x82, 0x82, 0x03, 0x3d,
119         0x55, 0x8c, 0x82, 0x82, 0x82, 0x03, 0x32, 0x17,
120         0x87, 0x7d, 0x7d, 0x7d, 0x03, 0x32, 0x2d, 0x8c,
121         0x82, 0x82, 0x82, 0x03, 0x32, 0x3c, 0x8c, 0x82,
122         0x82, 0x82, 0x03, 0x32, 0x4b, 0x8c, 0x82, 0x82,
123         0x78, 0x03, 0x32, 0x55, 0x8c, 0x82, 0x82, 0x6e,
124         0x03, 0x28, 0x17, 0x87, 0x7d, 0x7d, 0x73, 0x03,
125         0x28, 0x2d, 0x8c, 0x82, 0x82, 0x78, 0x03, 0x28,
126         0x3c, 0x8c, 0x82, 0x82, 0x73, 0x03, 0x28, 0x4b,
127         0x8c, 0x82, 0x78, 0x69, 0x03, 0x28, 0x55, 0x8c,
128         0x82, 0x6e, 0x5a, 0x03, 0x23, 0x17, 0x87, 0x7d,
129         0x7d, 0x69, 0x03, 0x23, 0x2d, 0x8c, 0x82, 0x82,
130         0x6e, 0x03, 0x23, 0x3c, 0x8c, 0x82, 0x78, 0x69,
131         0x03, 0x23, 0x4b, 0x8c, 0x82, 0x6e, 0x5a, 0x03,
132         0x23, 0x55, 0x8c, 0x82, 0x64, 0x50, 0x04, 0x32,
133         0x17, 0x91, 0x87, 0x87, 0x87, 0x04, 0x32, 0x2d,
134         0x96, 0x8c, 0x8c, 0x8c, 0x04, 0x32, 0x3c, 0x96,
135         0x8c, 0x8c, 0x8c, 0x04, 0x32, 0x46, 0x96, 0x8c,
136         0x8c, 0x8c, 0x04, 0x32, 0x4b, 0x82, 0x78, 0x78,
137         0x78, 0x04, 0x32, 0x55, 0x82, 0x78, 0x78, 0x78,
138         0x04, 0x2f, 0x17, 0x91, 0x87, 0x87, 0x87, 0x04,
139         0x2f, 0x2d, 0x96, 0x8c, 0x8c, 0x8c, 0x04, 0x2f,
140         0x3c, 0x96, 0x8c, 0x8c, 0x8c, 0x04, 0x2f, 0x46,
141         0x96, 0x8c, 0x8c, 0x82, 0x04, 0x2f, 0x4b, 0x82,
142         0x78, 0x78, 0x78, 0x04, 0x2f, 0x55, 0x82, 0x78,
143         0x78, 0x78, 0x04, 0x28, 0x17, 0x91, 0x87, 0x87,
144         0x87, 0x04, 0x28, 0x2d, 0x96, 0x8c, 0x8c, 0x82,
145         0x04, 0x28, 0x3c, 0x96, 0x8c, 0x8c, 0x82, 0x04,
146         0x28, 0x46, 0x96, 0x8c, 0x8c, 0x78, 0x04, 0x28,
147         0x4b, 0x82, 0x78, 0x78, 0x78, 0x04, 0x28, 0x55,
148         0x82, 0x78, 0x78, 0x6e, 0x04, 0x23, 0x17, 0x91,
149         0x87, 0x87, 0x73, 0x04, 0x23, 0x2d, 0x96, 0x8c,
150         0x8c, 0x78, 0x04, 0x23, 0x3c, 0x96, 0x8c, 0x82,
151         0x78, 0x04, 0x23, 0x46, 0x96, 0x8c, 0x82, 0x6e,
152         0x04, 0x23, 0x4b, 0x82, 0x78, 0x78, 0x6e, 0x04,
153         0x23, 0x55, 0x82, 0x78, 0x78, 0x64, 0x04, 0x1e,
154         0x17, 0x91, 0x87, 0x7d, 0x69, 0x04, 0x1e, 0x2d,
155         0x96, 0x8c, 0x82, 0x6e, 0x04, 0x1e, 0x3c, 0x96,
156         0x8c, 0x78, 0x64, 0x04, 0x1e, 0x46, 0x96, 0x8c,
157         0x78, 0x5a, 0x04, 0x1e, 0x4b, 0x82, 0x78, 0x78,
158         0x5a, 0x04, 0x1e, 0x55, 0x82, 0x78, 0x64, 0x50,
159         0x04, 0x19, 0x17, 0x91, 0x87, 0x69, 0x55, 0x04,
160         0x19, 0x2d, 0x96, 0x8c, 0x6e, 0x5a, 0x04, 0x19,
161         0x3c, 0x96, 0x82, 0x6e, 0x55, 0x04, 0x19, 0x46,
162         0x96, 0x82, 0x64, 0x50, 0x04, 0x19, 0x4b, 0x82,
163         0x78, 0x64, 0x50, 0x04, 0x19, 0x55, 0x82, 0x78,
164         0x55, 0x3c, 0x05, 0x64, 0x17, 0xa5, 0x9b, 0x9b,
165         0x9b, 0x05, 0x64, 0x2d, 0xaa, 0xa0, 0xa0, 0xa0,
166         0x05, 0x64, 0x3c, 0xaa, 0xa0, 0xa0, 0xa0, 0x05,
167         0x64, 0x46, 0xaa, 0xa0, 0xa0, 0xa0, 0x05, 0x64,
168         0x4b, 0x8c, 0x82, 0x82, 0x82, 0x05, 0x64, 0x55,
169         0x8c, 0x82, 0x82, 0x82, 0x05, 0x50, 0x17, 0xa5,
170         0x9b, 0x9b, 0x9b, 0x05, 0x50, 0x2d, 0xaa, 0xa0,
171         0xa0, 0xa0, 0x05, 0x50, 0x3c, 0xaa, 0xa0, 0xa0,
172         0x96, 0x05, 0x50, 0x46, 0xaa, 0xa0, 0xa0, 0x96,
173         0x05, 0x50, 0x4b, 0x8c, 0x82, 0x82, 0x82, 0x05,
174         0x50, 0x55, 0x8c, 0x82, 0x82, 0x82, 0x05, 0x3c,
175         0x17, 0xa5, 0x9b, 0x9b, 0x87, 0x05, 0x3c, 0x2d,
176         0xaa, 0xa0, 0xa0, 0x8c, 0x05, 0x3c, 0x3c, 0xaa,
177         0xa0, 0x96, 0x82, 0x05, 0x3c, 0x46, 0xaa, 0xa0,
178         0x96, 0x78, 0x05, 0x3c, 0x4b, 0x8c, 0x82, 0x82,
179         0x78, 0x05, 0x3c, 0x55, 0x8c, 0x82, 0x82, 0x6e,
180         0x05, 0x28, 0x17, 0xa5, 0x91, 0x7d, 0x69, 0x05,
181         0x28, 0x2d, 0xaa, 0x96, 0x82, 0x6e, 0x05, 0x28,
182         0x3c, 0xaa, 0x96, 0x78, 0x64, 0x05, 0x28, 0x46,
183         0xaa, 0x8c, 0x6e, 0x5a, 0x05, 0x28, 0x4b, 0x8c,
184         0x82, 0x6e, 0x5a, 0x05, 0x28, 0x55, 0x8c, 0x82,
185         0x64, 0x50, 0x06, 0x3d, 0x17, 0xa5, 0x9b, 0x7d,
186         0x7d, 0x06, 0x3d, 0x2d, 0xaa, 0xa0, 0x82, 0x82,
187         0x06, 0x3d, 0x3c, 0xaa, 0xa0, 0x82, 0x82, 0x06,
188         0x3d, 0x46, 0xaa, 0xa0, 0x82, 0x82, 0x06, 0x3d,
189         0x4b, 0x8c, 0x82, 0x82, 0x82, 0x06, 0x3d, 0x55,
190         0x8c, 0x82, 0x82, 0x82, 0x06, 0x32, 0x17, 0xa5,
191         0x9b, 0x7d, 0x7d, 0x06, 0x32, 0x2d, 0xaa, 0xa0,
192         0x82, 0x82, 0x06, 0x32, 0x3c, 0xaa, 0xa0, 0x82,
193         0x82, 0x06, 0x32, 0x46, 0xaa, 0xa0, 0x82, 0x78,
194         0x06, 0x32, 0x4b, 0x8c, 0x82, 0x82, 0x78, 0x06,
195         0x32, 0x55, 0x8c, 0x82, 0x82, 0x6e, 0x06, 0x28,
196         0x17, 0xa5, 0x9b, 0x7d, 0x73, 0x06, 0x28, 0x2d,
197         0xaa, 0xa0, 0x82, 0x78, 0x06, 0x28, 0x3c, 0xaa,
198         0x96, 0x82, 0x73, 0x06, 0x28, 0x46, 0xaa, 0x96,
199         0x78, 0x69, 0x06, 0x28, 0x4b, 0x8c, 0x82, 0x78,
200         0x69, 0x06, 0x28, 0x55, 0x8c, 0x82, 0x6e, 0x5a,
201         0x06, 0x23, 0x17, 0xa5, 0x91, 0x7d, 0x69, 0x06,
202         0x23, 0x2d, 0xaa, 0x96, 0x82, 0x6e, 0x06, 0x23,
203         0x3c, 0xaa, 0x96, 0x78, 0x69, 0x06, 0x23, 0x46,
204         0xaa, 0x8c, 0x6e, 0x5a, 0x06, 0x23, 0x4b, 0x8c,
205         0x82, 0x6e, 0x5a, 0x06, 0x23, 0x55, 0x8c, 0x82,
206         0x64, 0x50, 0x07, 0x3b, 0x17, 0x7d, 0x73, 0x73,
207         0x73, 0x07, 0x3b, 0x2d, 0x82, 0x78, 0x78, 0x78,
208         0x07, 0x3b, 0x3c, 0x82, 0x78, 0x78, 0x78, 0x07,
209         0x3b, 0x4b, 0x82, 0x78, 0x78, 0x78, 0x07, 0x3b,
210         0x5a, 0x82, 0x78, 0x78, 0x78, 0x07, 0x32, 0x17,
211         0x7d, 0x73, 0x73, 0x73, 0x07, 0x32, 0x2d, 0x82,
212         0x78, 0x78, 0x78, 0x07, 0x32, 0x3c, 0x82, 0x78,
213         0x78, 0x78, 0x07, 0x32, 0x4b, 0x82, 0x78, 0x78,
214         0x78, 0x07, 0x32, 0x5a, 0x82, 0x78, 0x6e, 0x64,
215         0x07, 0x28, 0x17, 0x7d, 0x73, 0x73, 0x69, 0x07,
216         0x28, 0x2d, 0x82, 0x78, 0x78, 0x6e, 0x07, 0x28,
217         0x3c, 0x82, 0x78, 0x78, 0x64, 0x07, 0x28, 0x4b,
218         0x82, 0x78, 0x78, 0x64, 0x07, 0x28, 0x5a, 0x82,
219         0x78, 0x64, 0x50, 0x07, 0x23, 0x17, 0x7d, 0x73,
220         0x73, 0x5f, 0x07, 0x23, 0x2d, 0x82, 0x78, 0x78,
221         0x64, 0x07, 0x23, 0x3c, 0x82, 0x78, 0x78, 0x64,
222         0x07, 0x23, 0x4b, 0x82, 0x78, 0x64, 0x50, 0x07,
223         0x23, 0x5a, 0x82, 0x78, 0x5a, 0x46, 0x08, 0x3b,
224         0x17, 0x7d, 0x73, 0x73, 0x73, 0x08, 0x3b, 0x2d,
225         0x82, 0x78, 0x78, 0x78, 0x08, 0x3b, 0x3c, 0x82,
226         0x78, 0x78, 0x78, 0x08, 0x3b, 0x4b, 0x82, 0x78,
227         0x78, 0x78, 0x08, 0x3b, 0x5a, 0x82, 0x78, 0x78,
228         0x78, 0x08, 0x32, 0x17, 0x7d, 0x73, 0x73, 0x73,
229         0x08, 0x32, 0x2d, 0x82, 0x78, 0x78, 0x78, 0x08,
230         0x32, 0x3c, 0x82, 0x78, 0x78, 0x78, 0x08, 0x32,
231         0x4b, 0x82, 0x78, 0x78, 0x78, 0x08, 0x32, 0x5a,
232         0x82, 0x78, 0x6e, 0x64, 0x08, 0x28, 0x17, 0x7d,
233         0x73, 0x73, 0x69, 0x08, 0x28, 0x2d, 0x82, 0x78,
234         0x78, 0x6e, 0x08, 0x28, 0x3c, 0x82, 0x78, 0x78,
235         0x64, 0x08, 0x28, 0x4b, 0x82, 0x78, 0x78, 0x64,
236         0x08, 0x28, 0x5a, 0x82, 0x78, 0x64, 0x50, 0x08,
237         0x23, 0x17, 0x7d, 0x73, 0x73, 0x5f, 0x08, 0x23,
238         0x2d, 0x82, 0x78, 0x78, 0x64, 0x08, 0x23, 0x3c,
239         0x82, 0x78, 0x78, 0x64, 0x08, 0x23, 0x4b, 0x82,
240         0x78, 0x64, 0x50, 0x08, 0x23, 0x5a, 0x82, 0x78,
241         0x5a, 0x46, 0x0c, 0x52, 0x17, 0xa5, 0x9b, 0x9b,
242         0x9b, 0x0c, 0x52, 0x2d, 0xaa, 0xa0, 0xa0, 0xa0,
243         0x0c, 0x52, 0x3c, 0xaa, 0xa0, 0xa0, 0xa0, 0x0c,
244         0x52, 0x46, 0xaa, 0xa0, 0xa0, 0xa0, 0x0c, 0x52,
245         0x4b, 0x8c, 0x82, 0x82, 0x82, 0x0c, 0x52, 0x55,
246         0x8c, 0x82, 0x82, 0x82, 0x0c, 0x42, 0x17, 0xa5,
247         0x9b, 0x9b, 0x91, 0x0c, 0x42, 0x2d, 0xaa, 0xa0,
248         0xa0, 0x96, 0x0c, 0x42, 0x3c, 0xaa, 0xa0, 0xa0,
249         0x96, 0x0c, 0x42, 0x46, 0xaa, 0xa0, 0xa0, 0x96,
250         0x0c, 0x42, 0x4b, 0x8c, 0x82, 0x82, 0x82, 0x0c,
251         0x42, 0x55, 0x8c, 0x82, 0x82, 0x82, 0x0c, 0x3d,
252         0x17, 0xa5, 0x9b, 0x9b, 0x91, 0x0c, 0x3d, 0x2d,
253         0xaa, 0xa0, 0xa0, 0x96, 0x0c, 0x3d, 0x3c, 0xaa,
254         0xa0, 0xa0, 0x8c, 0x0c, 0x3d, 0x46, 0xaa, 0xa0,
255         0x96, 0x8c, 0x0c, 0x3d, 0x4b, 0x8c, 0x82, 0x82,
256         0x82, 0x0c, 0x3d, 0x55, 0x8c, 0x82, 0x82, 0x82,
257         0x0c, 0x32, 0x17, 0xa5, 0x9b, 0x91, 0x87, 0x0c,
258         0x32, 0x2d, 0xaa, 0xa0, 0x96, 0x8c, 0x0c, 0x32,
259         0x3c, 0xaa, 0xa0, 0x96, 0x82, 0x0c, 0x32, 0x46,
260         0xaa, 0xa0, 0x8c, 0x78, 0x0c, 0x32, 0x4b, 0x8c,
261         0x82, 0x82, 0x78, 0x0c, 0x32, 0x55, 0x8c, 0x82,
262         0x82, 0x6e, 0x0c, 0x28, 0x17, 0xa5, 0x9b, 0x87,
263         0x73, 0x0c, 0x28, 0x2d, 0xaa, 0xa0, 0x8c, 0x78,
264         0x0c, 0x28, 0x3c, 0xaa, 0x96, 0x82, 0x73, 0x0c,
265         0x28, 0x46, 0xaa, 0x96, 0x78, 0x69, 0x0c, 0x28,
266         0x4b, 0x8c, 0x82, 0x78, 0x69, 0x0c, 0x28, 0x55,
267         0x8c, 0x82, 0x6e, 0x5a, 0x0c, 0x23, 0x17, 0xa5,
268         0x91, 0x7d, 0x69, 0x0c, 0x23, 0x2d, 0xaa, 0x96,
269         0x82, 0x6e, 0x0c, 0x23, 0x3c, 0xaa, 0x96, 0x78,
270         0x69, 0x0c, 0x23, 0x46, 0xaa, 0x8c, 0x6e, 0x5a,
271         0x0c, 0x23, 0x4b, 0x8c, 0x82, 0x6e, 0x5a, 0x0c,
272         0x23, 0x55, 0x8c, 0x82, 0x64, 0x50, 0x0d, 0x64,
273         0x17, 0xa5, 0x9b, 0x9b, 0x9b, 0x0d, 0x64, 0x2d,
274         0xaa, 0xa0, 0xa0, 0xa0, 0x0d, 0x64, 0x3c, 0xaa,
275         0xa0, 0xa0, 0xa0, 0x0d, 0x64, 0x46, 0xaa, 0xa0,
276         0xa0, 0xa0, 0x0d, 0x64, 0x4b, 0x8c, 0x82, 0x82,
277         0x82, 0x0d, 0x64, 0x55, 0x8c, 0x82, 0x82, 0x82,
278         0x0d, 0x50, 0x17, 0xa5, 0x9b, 0x9b, 0x9b, 0x0d,
279         0x50, 0x2d, 0xaa, 0xa0, 0xa0, 0xa0, 0x0d, 0x50,
280         0x3c, 0xaa, 0xa0, 0xa0, 0x96, 0x0d, 0x50, 0x46,
281         0xaa, 0xa0, 0xa0, 0x96, 0x0d, 0x50, 0x4b, 0x8c,
282         0x82, 0x82, 0x82, 0x0d, 0x50, 0x55, 0x8c, 0x82,
283         0x82, 0x82, 0x0d, 0x3c, 0x17, 0xa5, 0x9b, 0x9b,
284         0x87, 0x0d, 0x3c, 0x2d, 0xaa, 0xa0, 0xa0, 0x8c,
285         0x0d, 0x3c, 0x3c, 0xaa, 0xa0, 0x96, 0x82, 0x0d,
286         0x3c, 0x46, 0xaa, 0xa0, 0x96, 0x78, 0x0d, 0x3c,
287         0x4b, 0x8c, 0x82, 0x82, 0x78, 0x0d, 0x3c, 0x55,
288         0x8c, 0x82, 0x82, 0x6e, 0x0d, 0x28, 0x17, 0xa5,
289         0x91, 0x7d, 0x69, 0x0d, 0x28, 0x2d, 0xaa, 0x96,
290         0x82, 0x6e, 0x0d, 0x28, 0x3c, 0xaa, 0x96, 0x78,
291         0x64, 0x0d, 0x28, 0x46, 0xaa, 0x8c, 0x6e, 0x5a,
292         0x0d, 0x28, 0x4b, 0x8c, 0x82, 0x6e, 0x5a, 0x0d,
293         0x28, 0x55, 0x8c, 0x82, 0x64, 0x50,
294 };
295
296
297 static struct system_edp_entry __initdata tegra_system_edp_map[] = {
298
299 /* {SKU, power-limit (in 100mW), {freq limits (in 10Mhz)} } */
300
301         {  1,  49, {130, 120, 120, 120} },
302         {  1,  44, {130, 120, 120, 110} },
303         {  1,  37, {130, 120, 110, 100} },
304         {  1,  35, {130, 120, 110,  90} },
305         {  1,  29, {130, 120, 100,  80} },
306         {  1,  27, {130, 120,  90,  80} },
307         {  1,  25, {130, 110,  80,  60} },
308         {  1,  21, {130, 100,  80,  40} },
309
310         {  4,  49, {130, 120, 120, 120} },
311         {  4,  44, {130, 120, 120, 110} },
312         {  4,  37, {130, 120, 110, 100} },
313         {  4,  35, {130, 120, 110,  90} },
314         {  4,  29, {130, 120, 100,  80} },
315         {  4,  27, {130, 120,  90,  80} },
316         {  4,  25, {130, 110,  80,  60} },
317         {  4,  21, {130, 100,  80,  40} },
318 };
319
320 /*
321  * "Safe entry" to be used when no match for speedo_id /
322  * regulator_cur is found; must be the last one
323  */
324 static struct tegra_edp_limits edp_default_limits[] = {
325         {85, {1000000, 1000000, 1000000, 1000000} },
326 };
327
328 /*
329  * Constants for EDP calculations
330  */
331 int temps_lut[TEMP_LUT_MAX] = {
332         23, 24, 25, 26, 27, 28, 29,
333         30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
334         40, 41, 42, 43, 44, 45, 46, 47, 48, 49,
335         50, 51, 52, 53, 54, 55, 56, 57, 58, 59,
336         60, 61, 62, 63, 64, 65, 66, 67, 68, 69,
337         70, 71, 72, 73, 74, 75, 76, 77, 78, 79,
338         80, 81, 82, 83, 84, 85, 86, 87, 88, 89,
339         90,
340 };
341
342 /* TODO: This struct will get large for 13 speedo IDs... relocate. */
343 struct edp_constants_lut_t {
344         int cpu_speedo_id;
345         /* All constants are pre-multiplied by 1,000,000 */
346         int leakage_consts_ijk[64];
347         int leakage_consts_n[NR_CPUS];
348         int dyn_consts_n[NR_CPUS];
349 } edp_constants_lut[] = {
350         {
351                 .cpu_speedo_id = -1,
352                 .leakage_consts_n = {
353                         641026,
354                         757576,
355                         878500,
356                         1000000
357                 },
358                 /* Constants order: C(i,j,k), i,j,k = {0,1,2,3}, with k
359                  * being the least significant index and i being the most
360                  * significant index */
361                 .leakage_consts_ijk =  {
362                         0,
363                         -21481846,
364                         519650,
365                         -3254,
366                         0,
367                         65678948,
368                         -1572498,
369                         9850,
370                         0,
371                         -65988168,
372                         1565063,
373                         -9808,
374                         0,
375                         22109316,
376                         -522158,
377                         3281,
378                         0,
379                         24840561,
380                         -565618,
381                         5196,
382                         0,
383                         -65603470,
384                         1592186,
385                         -13823,
386                         0,
387                         56585242,
388                         -1488977,
389                         12944,
390                         0,
391                         -14740016,
392                         470284,
393                         -3670,
394                         0,
395                         -7050232,
396                         244771,
397                         -1779,
398                         0,
399                         20985919,
400                         -701848,
401                         5008,
402                         0,
403                         -20478304,
404                         677782,
405                         -4766,
406                         0,
407                         7093793,
408                         -218579,
409                         1454,
410                         0,
411                         942881,
412                         -29599,
413                         203,
414                         0,
415                         -2750253,
416                         84116,
417                         -569,
418                         0,
419                         2643026,
420                         -80080,
421                         536,
422                         0,
423                         -868855,
424                         25062,
425                         -161,
426                 }, /* consts_ijk */
427                 .dyn_consts_n = {
428                         1560207,
429                         2378136,
430                         3196066,
431                         4013995
432                 }
433         }
434 };
435
436 struct freq_voltage_lut_t {
437         unsigned int freq;
438         int voltage_mV;
439 } *freq_voltage_lut = 0;
440 unsigned int freq_voltage_lut_size;
441
442 static s64 edp_pwr(s64 val, int pwr)
443 {
444         int i;
445         s64 retval = 1;
446
447         for (i = 0; i < pwr; i++)
448                 retval *= val;
449
450         return retval;
451 }
452
453 /*
454  * Find the maximum frequency that results in dynamic and leakage current that
455  * is less than the regulator current limit.
456  */
457 unsigned int edp_calculate_maxf(struct edp_constants_lut_t  *edp_constants,
458                                 int temp_C,
459                                 int iddq_mA,
460                                 int n_cores_idx)
461 {
462         unsigned int voltage_mV, freq_MHz;
463         unsigned int regulator_cur_effective = regulator_cur - edp_reg_override_mA;
464         int f_v_pair, i, j, k, leakage_const_n, dyn_const_n;
465         int *leakage_consts_ijk;
466         s64 leakage_mA, dyn_mA, leakage_calc_step;
467         /* WAR for GCC 4.4.3 bug 43949 - compiler throws an array bounds warning
468          * if these arrays are dereferenced in the calling function*/
469         leakage_consts_ijk = edp_constants->leakage_consts_ijk;
470         dyn_const_n = edp_constants->dyn_consts_n[n_cores_idx];
471         leakage_const_n = edp_constants->leakage_consts_n[n_cores_idx];
472
473         for (f_v_pair = freq_voltage_lut_size - 1; f_v_pair  >= 0; f_v_pair--) {
474                 freq_MHz = freq_voltage_lut[f_v_pair].freq / 1000000;
475                 voltage_mV = freq_voltage_lut[f_v_pair].voltage_mV;
476
477                 /*
478                  * Calculate leakage current
479                  */
480                 leakage_mA = 0;
481                 for (i = 0; i <= 3; i++)
482                         for (j = 0; j <= 3; j++)
483                                 for (k = 0; k <= 3; k++) {
484                                         leakage_calc_step =
485                                              leakage_consts_ijk[i*16 + j*4 + k]
486                                                 * edp_pwr(iddq_mA, i);
487                                         /* Convert (mA)^i to (A)^i */
488                                         leakage_calc_step =
489                                                 div64_s64(leakage_calc_step,
490                                                           edp_pwr(1000, i));
491                                         leakage_calc_step *=
492                                                 edp_pwr(voltage_mV, j);
493                                         /* Convert (mV)^i to (V)^i */
494                                         leakage_calc_step =
495                                                 div64_s64(leakage_calc_step,
496                                                           edp_pwr(1000, j));
497                                         leakage_calc_step *=
498                                                 edp_pwr(temp_C, k);
499                                         /* const_ijk was X 1,000,000 */
500                                         leakage_calc_step =
501                                                 div64_s64(leakage_calc_step,
502                                                           1000000);
503                                         leakage_mA += leakage_calc_step;
504                                 }
505                 leakage_mA *= leakage_const_n;
506                 /* leakage_const_n was pre-multiplied by 1,000,000 */
507                 leakage_mA = div64_s64(leakage_mA, 1000000);
508
509                 /*
510                  * Calculate dynamic current
511                  */
512                 dyn_mA = voltage_mV * freq_MHz;
513                 /* Convert mV to V */
514                 dyn_mA = div64_s64(dyn_mA, 1000);
515                 dyn_mA *= dyn_const_n;
516                 /* dyn_const_n was pre-multiplied by 1,000,000 */
517                 dyn_mA = div64_s64(dyn_mA, 1000000);
518
519                 if ((leakage_mA + dyn_mA) <= regulator_cur_effective)
520                         return freq_MHz * 1000;
521         }
522         return 0;
523 }
524
525 static int edp_relate_freq_voltage(struct clk *clk_cpu_g,
526                                 unsigned int cpu_speedo_idx)
527 {
528         unsigned int i, j, freq;
529         int voltage_mV;
530
531         for (i = 0, j = 0, freq = clk_get_min_rate(clk_cpu_g);
532                  i < freq_voltage_lut_size;
533                  i++, freq += FREQ_STEP) {
534
535                 /* Predict voltages */
536                 voltage_mV = tegra_dvfs_predict_millivolts(clk_cpu_g, freq);
537                 if (voltage_mV < 0) {
538                         pr_err("%s: couldn't predict voltage for freq %u, err %d",
539                                __func__, freq, voltage_mV);
540                         return -EINVAL;
541                 }
542
543                 /* Cache frequency / voltage / voltage constant relationship */
544                 freq_voltage_lut[i].freq = freq;
545                 freq_voltage_lut[i].voltage_mV = voltage_mV;
546         }
547
548         return 0;
549 }
550
551 int edp_find_speedo_idx(int cpu_speedo_id, unsigned int *cpu_speedo_idx)
552 {
553         int i;
554
555         for (i = 0; i < ARRAY_SIZE(edp_constants_lut); i++)
556                 if (cpu_speedo_id == edp_constants_lut[i].cpu_speedo_id) {
557                         *cpu_speedo_idx = i;
558                         return 0;
559                 }
560
561         pr_err("%s: couldn't find cpu speedo id %d in freq/voltage LUT\n",
562                __func__, cpu_speedo_id);
563         return -EINVAL;
564 }
565 int init_cpu_edp_limits_calculated(int cpu_speedo_id)
566 {
567         unsigned int temp_idx, n_cores_idx;
568         unsigned int cpu_g_minf, cpu_g_maxf;
569         unsigned int iddq_mA;
570         unsigned int cpu_speedo_idx;
571         struct tegra_edp_limits *edp_calculated_limits;
572         struct edp_constants_lut_t *edp_constants;
573         int ret;
574         struct clk *clk_cpu_g = tegra_get_clock_by_name("cpu_g");
575
576         /* Determine all inputs to EDP formula */
577         tegra_fuse_get_cpu_iddq_mA(&iddq_mA);
578
579         ret = edp_find_speedo_idx(cpu_speedo_id, &cpu_speedo_idx);
580         if (ret)
581                 return ret;
582
583         edp_constants = &edp_constants_lut[cpu_speedo_idx];
584
585         edp_calculated_limits =
586                 kmalloc(sizeof(struct tegra_edp_limits) * EDP_CALCULATED_LIMITS_SIZE,
587                                 GFP_KERNEL);
588         BUG_ON(!edp_calculated_limits);
589
590         cpu_g_minf = clk_get_min_rate(clk_cpu_g);
591         cpu_g_maxf = clk_get_max_rate(clk_cpu_g);
592         freq_voltage_lut_size = (cpu_g_maxf - cpu_g_minf) / FREQ_STEP + 1;
593         freq_voltage_lut =
594                 kmalloc(sizeof(struct freq_voltage_lut_t)*freq_voltage_lut_size,
595                                 GFP_KERNEL);
596         if (!freq_voltage_lut) {
597                 pr_err("%s: failed alloc mem for freq/voltage LUT\n", __func__);
598                 return -ENOMEM;
599         }
600
601         ret = edp_relate_freq_voltage(clk_cpu_g, cpu_speedo_idx);
602         if (ret) {
603                 kfree(freq_voltage_lut);
604                 return ret;
605         }
606
607         /* Calculate EDP table */
608         for (temp_idx = 0; temp_idx < ARRAY_SIZE(temps_lut); temp_idx++) {
609                 edp_calculated_limits[temp_idx].temperature = temps_lut[temp_idx];
610
611                 for (n_cores_idx = 0; n_cores_idx < NR_CPUS; n_cores_idx++)
612                         edp_calculated_limits[temp_idx].
613                                 freq_limits[n_cores_idx] =
614                                 edp_calculate_maxf(edp_constants,
615                                                 temps_lut[temp_idx],
616                                                 iddq_mA,
617                                                 n_cores_idx);
618         }
619
620         /*
621          * If this is an EDP table update, need to overwrite old table.
622          * The old table's address must remain valid.
623          */
624         if (edp_limits != edp_default_limits) {
625                 memcpy(edp_limits, edp_calculated_limits,
626                         sizeof(struct tegra_edp_limits) * EDP_CALCULATED_LIMITS_SIZE);
627                 kfree(edp_calculated_limits);
628         }
629         else {
630                 edp_limits = edp_calculated_limits;
631                 edp_limits_size = EDP_CALCULATED_LIMITS_SIZE;
632         }
633
634         kfree(freq_voltage_lut);
635         return 0;
636 }
637
638 int __init init_cpu_edp_limits_lookup(int cpu_speedo_id)
639 {
640         int i, j;
641         struct tegra_edp_limits *e;
642         struct tegra_edp_entry *t = (struct tegra_edp_entry *)tegra_edp_map;
643         int tsize = sizeof(tegra_edp_map)/sizeof(struct tegra_edp_entry);
644
645         for (i = 0; i < tsize; i++) {
646                 if (t[i].speedo_id == cpu_speedo_id &&
647                     t[i].regulator_100mA <= regulator_cur / 100)
648                         break;
649         }
650
651         /* No entry found in tegra_edp_map */
652         if (i >= tsize)
653                 return -EINVAL;
654
655         /* Find all rows for this entry */
656         for (j = i + 1; j < tsize; j++) {
657                 if (t[i].speedo_id != t[j].speedo_id ||
658                     t[i].regulator_100mA != t[j].regulator_100mA)
659                         break;
660         }
661
662         edp_limits_size = j - i;
663         e = kmalloc(sizeof(struct tegra_edp_limits) * edp_limits_size,
664                     GFP_KERNEL);
665         BUG_ON(!e);
666
667         for (j = 0; j < edp_limits_size; j++) {
668                 e[j].temperature = (int)t[i+j].temperature;
669                 e[j].freq_limits[0] = (unsigned int)t[i+j].freq_limits[0]*10000;
670                 e[j].freq_limits[1] = (unsigned int)t[i+j].freq_limits[1]*10000;
671                 e[j].freq_limits[2] = (unsigned int)t[i+j].freq_limits[2]*10000;
672                 e[j].freq_limits[3] = (unsigned int)t[i+j].freq_limits[3]*10000;
673         }
674
675         if (edp_limits != edp_default_limits)
676                 kfree(edp_limits);
677
678         edp_limits = e;
679         return 0;
680 }
681
682 /*
683  * Specify regulator current in mA, e.g. 5000mA
684  * Use 0 for default
685  */
686 void __init tegra_init_cpu_edp_limits(unsigned int regulator_mA)
687 {
688         int cpu_speedo_id = tegra_cpu_speedo_id();
689
690         if (!regulator_mA) {
691                 edp_limits = edp_default_limits;
692                 edp_limits_size = ARRAY_SIZE(edp_default_limits);
693                 return;
694         }
695         regulator_cur = regulator_mA;
696
697         if (init_cpu_edp_limits_lookup(cpu_speedo_id) == 0)
698                 return;
699
700         if (init_cpu_edp_limits_calculated(cpu_speedo_id) == 0)
701                 return;
702
703         edp_limits = edp_default_limits;
704         edp_limits_size = ARRAY_SIZE(edp_default_limits);
705 }
706
707 void __init tegra_init_system_edp_limits(unsigned int power_limit_mW)
708 {
709         int cpu_speedo_id = tegra_cpu_speedo_id();
710         int i;
711         unsigned int *e;
712         struct system_edp_entry *t =
713                 (struct system_edp_entry *)tegra_system_edp_map;
714         int tsize = sizeof(tegra_system_edp_map) /
715                 sizeof(struct system_edp_entry);
716
717         if (!power_limit_mW) {
718                 e = NULL;
719                 goto out;
720         }
721
722         for (i = 0; i < tsize; i++)
723                 if (t[i].speedo_id == cpu_speedo_id)
724                         break;
725
726         if (i >= tsize) {
727                 e = NULL;
728                 goto out;
729         }
730
731         do {
732                 if (t[i].power_limit_100mW <= power_limit_mW / 100)
733                         break;
734                 i++;
735         } while (i < tsize && t[i].speedo_id == cpu_speedo_id);
736
737         if (i >= tsize || t[i].speedo_id != cpu_speedo_id)
738                 i--; /* No low enough entry in the table, use best possible */
739
740         e = kmalloc(sizeof(unsigned int) * 4, GFP_KERNEL);
741         BUG_ON(!e);
742
743         e[0] = (unsigned int)t[i].freq_limits[0] * 10000;
744         e[1] = (unsigned int)t[i].freq_limits[1] * 10000;
745         e[2] = (unsigned int)t[i].freq_limits[2] * 10000;
746         e[3] = (unsigned int)t[i].freq_limits[3] * 10000;
747
748 out:
749         kfree(system_edp_limits);
750
751         system_edp_limits = e;
752 }
753
754
755 void tegra_get_cpu_edp_limits(const struct tegra_edp_limits **limits, int *size)
756 {
757         *limits = edp_limits;
758         *size = edp_limits_size;
759 }
760
761 void tegra_get_system_edp_limits(const unsigned int **limits)
762 {
763         *limits = system_edp_limits;
764 }
765
766 #ifdef CONFIG_EDP_FRAMEWORK
767
768 static struct edp_manager battery_edp_manager = {
769         .name = "battery"
770 };
771
772 void __init tegra_battery_edp_init(unsigned int cap)
773 {
774         struct edp_governor *g;
775         int r;
776
777         battery_edp_manager.imax = cap;
778         r = edp_register_manager(&battery_edp_manager);
779         if (r)
780                 goto err_ret;
781
782         /* start with priority governor */
783         g = edp_get_governor("priority");
784         if (!g) {
785                 r = -EFAULT;
786                 goto err_ret;
787         }
788
789         r = edp_set_governor(&battery_edp_manager, g);
790         if (r)
791                 goto err_ret;
792
793         return;
794
795 err_ret:
796         pr_err("Battery EDP init failed with error %d\n", r);
797         WARN_ON(1);
798 }
799
800 #endif
801
802 #ifdef CONFIG_DEBUG_FS
803
804 static int edp_limit_debugfs_show(struct seq_file *s, void *data)
805 {
806         seq_printf(s, "%u\n", tegra_get_edp_limit());
807         return 0;
808 }
809
810 static int edp_debugfs_show(struct seq_file *s, void *data)
811 {
812         int i;
813
814         seq_printf(s, "-- VDD_CPU %sEDP table (%umA) --\n",
815                    edp_limits == edp_default_limits ? "default " : "",
816                    regulator_cur);
817         seq_printf(s, "%6s %10s %10s %10s %10s\n",
818                    " Temp.", "1-core", "2-cores", "3-cores", "4-cores");
819         for (i = 0; i < edp_limits_size; i++) {
820                 seq_printf(s, "%4dC: %10u %10u %10u %10u\n",
821                            edp_limits[i].temperature,
822                            edp_limits[i].freq_limits[0],
823                            edp_limits[i].freq_limits[1],
824                            edp_limits[i].freq_limits[2],
825                            edp_limits[i].freq_limits[3]);
826         }
827
828         if (system_edp_limits) {
829                 seq_printf(s, "\n-- System EDP table --\n");
830                 seq_printf(s, "%10u %10u %10u %10u\n",
831                            system_edp_limits[0],
832                            system_edp_limits[1],
833                            system_edp_limits[2],
834                            system_edp_limits[3]);
835         }
836
837         return 0;
838 }
839
840 static int edp_reg_override_show(struct seq_file *s, void *data)
841 {
842         seq_printf(s, "Regulator limit override: %u mA. Effective regulator limit: %u mA\n",
843                    edp_reg_override_mA, regulator_cur - edp_reg_override_mA);
844         return 0;
845 }
846
847 static int edp_reg_override_write(struct file *file,
848         const char __user *userbuf, size_t count, loff_t *ppos)
849 {
850         char buf[32], *end;
851         unsigned int edp_reg_override_mA_temp;
852         unsigned int edp_reg_override_mA_prev = edp_reg_override_mA;
853         int cpu_speedo_id;
854
855         if (sizeof(buf) <= count)
856                 goto override_err;
857
858         if (copy_from_user(buf, userbuf, count))
859                 goto override_err;
860
861         /* terminate buffer and trim - white spaces may be appended
862          *  at the end when invoked from shell command line */
863         buf[count]='\0';
864         strim(buf);
865
866         edp_reg_override_mA_temp = simple_strtoul(buf, &end, 10);
867         if (*end != '\0')
868                 goto override_err;
869
870         if (edp_reg_override_mA_temp >= regulator_cur)
871                 goto override_err;
872
873         edp_reg_override_mA = edp_reg_override_mA_temp;
874         cpu_speedo_id = tegra_cpu_speedo_id();
875         if(init_cpu_edp_limits_calculated(cpu_speedo_id)) {
876                 /* Revert to previous override value if new value fails */
877                 edp_reg_override_mA = edp_reg_override_mA_prev;
878                 goto override_err;
879         }
880
881         if (tegra_cpu_set_speed_cap(NULL)) {
882                 pr_err("Failed to apply CPU freq cap using new VDD_CPU EDP table.\n");
883                 goto override_out;
884         }
885
886         pr_info("Reinitialized VDD_CPU EDP table with regulator current limit"
887                         " %u mA\n", regulator_cur - edp_reg_override_mA);
888
889         return count;
890
891 override_err:
892         pr_err("Failed to reinitialized VDD_CPU EDP table with override \"%s\"",
893                buf);
894 override_out:
895         return -EINVAL;
896
897 }
898
899 static int edp_debugfs_open(struct inode *inode, struct file *file)
900 {
901         return single_open(file, edp_debugfs_show, inode->i_private);
902 }
903
904 static int edp_limit_debugfs_open(struct inode *inode, struct file *file)
905 {
906         return single_open(file, edp_limit_debugfs_show, inode->i_private);
907 }
908
909 static int edp_reg_override_open(struct inode *inode, struct file *file)
910 {
911         return single_open(file, edp_reg_override_show, inode->i_private);
912 }
913
914 static const struct file_operations edp_debugfs_fops = {
915         .open           = edp_debugfs_open,
916         .read           = seq_read,
917         .llseek         = seq_lseek,
918         .release        = single_release,
919 };
920
921 static const struct file_operations edp_limit_debugfs_fops = {
922         .open           = edp_limit_debugfs_open,
923         .read           = seq_read,
924         .llseek         = seq_lseek,
925         .release        = single_release,
926 };
927
928 static const struct file_operations edp_reg_override_debugfs_fops = {
929         .open           = edp_reg_override_open,
930         .read           = seq_read,
931         .write          = edp_reg_override_write,
932         .llseek         = seq_lseek,
933         .release        = single_release,
934 };
935
936 static int __init tegra_edp_debugfs_init(void)
937 {
938         struct dentry *d_edp;
939         struct dentry *d_edp_limit;
940         struct dentry *d_edp_reg_override;
941         struct dentry *edp_dir;
942         struct dentry *vdd_cpu_dir;
943
944         edp_dir = debugfs_create_dir("edp", NULL);
945
946         if (!edp_dir)
947                 goto edp_dir_err;
948
949         vdd_cpu_dir = debugfs_create_dir("vdd_cpu", edp_dir);
950
951         if (!vdd_cpu_dir)
952                 goto vdd_cpu_dir_err;
953
954         d_edp = debugfs_create_file("edp", S_IRUGO, vdd_cpu_dir, NULL,
955                                 &edp_debugfs_fops);
956
957         if (!d_edp)
958                 goto edp_err;
959
960         d_edp_limit = debugfs_create_file("edp_limit", S_IRUGO, vdd_cpu_dir,
961                                 NULL, &edp_limit_debugfs_fops);
962
963         if (!d_edp_limit)
964                 goto edp_limit_err;
965
966         d_edp_reg_override = debugfs_create_file("edp_reg_override",
967                                 S_IRUGO | S_IWUSR, vdd_cpu_dir, NULL,
968                                 &edp_reg_override_debugfs_fops);
969
970         if (!d_edp_reg_override)
971                 goto edp_reg_override_err;
972
973         return 0;
974
975 edp_reg_override_err:
976         debugfs_remove(d_edp_limit);
977 edp_limit_err:
978         debugfs_remove(d_edp);
979 edp_err:
980         debugfs_remove(vdd_cpu_dir);
981 vdd_cpu_dir_err:
982         debugfs_remove(edp_dir);
983 edp_dir_err:
984         return -ENOMEM;
985 }
986
987 late_initcall(tegra_edp_debugfs_init);
988 #endif /* CONFIG_DEBUG_FS */