0ddc7129176c08679b327af2e7b8e79fa12ac793
[linux-2.6.git] / arch / arm / mach-tegra / board-macallan-powermon.c
1 /*
2  * arch/arm/mach-tegra/board-macallan-powermon.c
3  *
4  * Copyright (c) 2013, 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 as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  *
19  */
20
21 #include <linux/i2c.h>
22 #include <linux/ina219.h>
23 #include <linux/platform_data/ina230.h>
24
25 #include "board.h"
26 #include "board-macallan.h"
27
28 #define PRECISION_MULTIPLIER_MACALLAN 1000
29
30 enum {
31         VD_CPU,
32         VD_SOC,
33         VS_DDR0,
34         VS_DDR1,
35         VS_LCD_BL,
36         VD_LCD_HV,
37         VS_SYS_1V8,
38         VD_AP_1V8,
39         VD_AP_RTC,
40         VS_AUD_SYS,
41         VD_DDR0,
42         VD_DDR1,
43         VD_AP_VBUS,
44         VS_SYS_2V9,
45         VA_PLLX,
46         VA_AP_1V2,
47 };
48
49 static struct ina219_platform_data power_mon_ina219_info[] = {
50         [VD_CPU] = {
51                 .calibration_data  = 0x7CD2,
52                 .power_lsb = 2.563685298 * PRECISION_MULTIPLIER_MACALLAN,
53                 .rail_name = "VD_CPU",
54                 .divisor = 20,
55                 .precision_multiplier = PRECISION_MULTIPLIER_MACALLAN,
56                 .cont_conf = 0x3FFF,
57                 .trig_conf = 0x1DB,
58                 .shunt_resistor = 1,
59         },
60
61         [VD_SOC] = {
62                 .calibration_data  = 0x7CD2,
63                 .power_lsb = 2.563685298 * PRECISION_MULTIPLIER_MACALLAN,
64                 .rail_name = "VD_SOC",
65                 .divisor = 20,
66                 .precision_multiplier = PRECISION_MULTIPLIER_MACALLAN,
67                 .cont_conf = 0x3FFF,
68                 .trig_conf = 0x1DB,
69                 .shunt_resistor = 1,
70         },
71
72         [VS_DDR0] = {
73                 .calibration_data  = 0xfffe,
74                 .power_lsb = 1.2500381481 * PRECISION_MULTIPLIER_MACALLAN,
75                 .rail_name = "VS_DDR0",
76                 .divisor = 20,
77                 .precision_multiplier = PRECISION_MULTIPLIER_MACALLAN,
78                 .cont_conf = 0x3FFF,
79                 .trig_conf = 0x1DB,
80                 .shunt_resistor = 10,
81         },
82
83         [VS_DDR1] = {
84                 .calibration_data  = 0xfffe,
85                 .power_lsb = 1.2500381481 * PRECISION_MULTIPLIER_MACALLAN,
86                 .rail_name = "VS_DDR1",
87                 .divisor = 20,
88                 .precision_multiplier = PRECISION_MULTIPLIER_MACALLAN,
89                 .cont_conf = 0x3FFF,
90                 .trig_conf = 0x1DB,
91                 .shunt_resistor = 10,
92         },
93
94         [VS_LCD_BL] = {
95                 .calibration_data  = 0xfffe,
96                 .power_lsb = 1.2500381481 * PRECISION_MULTIPLIER_MACALLAN,
97                 .rail_name = "VS_LCD_BL",
98                 .divisor = 20,
99                 .precision_multiplier = PRECISION_MULTIPLIER_MACALLAN,
100                 .cont_conf = 0x3FFF,
101                 .trig_conf = 0x1DB,
102                 .shunt_resistor = 10,
103         },
104
105         [VD_LCD_HV] = {
106                 .calibration_data  = 0xfffe,
107                 .power_lsb = 1.2500381481 * PRECISION_MULTIPLIER_MACALLAN,
108                 .rail_name = "VD_LCD_HV",
109                 .divisor = 20,
110                 .precision_multiplier = PRECISION_MULTIPLIER_MACALLAN,
111                 .cont_conf = 0x3FFF,
112                 .trig_conf = 0x1DB,
113                 .shunt_resistor = 10,
114         },
115
116         [VS_SYS_1V8] = {
117                 .calibration_data  = 0x7CD2,
118                 .power_lsb = 2.563685298 * PRECISION_MULTIPLIER_MACALLAN,
119                 .rail_name = "VS_SYS_1V8",
120                 .divisor = 20,
121                 .precision_multiplier = PRECISION_MULTIPLIER_MACALLAN,
122                 .cont_conf = 0x3FFF,
123                 .trig_conf = 0x1DB,
124                 .shunt_resistor = 10,
125         },
126
127         [VD_AP_1V8] = {
128                 .calibration_data  = 0xfffe,
129                 .power_lsb = 1.2500381481 * PRECISION_MULTIPLIER_MACALLAN,
130                 .rail_name = "VD_AP_1V8",
131                 .divisor = 20,
132                 .precision_multiplier = PRECISION_MULTIPLIER_MACALLAN,
133                 .cont_conf = 0x3FFF,
134                 .trig_conf = 0x1DB,
135                 .shunt_resistor = 10,
136         },
137
138         [VD_AP_RTC] = {
139                 .calibration_data  = 0xfffe,
140                 .power_lsb = 1.2500381481 * PRECISION_MULTIPLIER_MACALLAN,
141                 .rail_name = "VD_AP_RTC",
142                 .divisor = 20,
143                 .precision_multiplier = PRECISION_MULTIPLIER_MACALLAN,
144                 .cont_conf = 0x3FFF,
145                 .trig_conf = 0x1DB,
146                 .shunt_resistor = 10,
147         },
148
149         [VS_AUD_SYS] = {
150                 .calibration_data  = 0xfffe,
151                 .power_lsb = 1.2500381481 * PRECISION_MULTIPLIER_MACALLAN,
152                 .rail_name = "VS_AUD_SYS",
153                 .divisor = 20,
154                 .precision_multiplier = PRECISION_MULTIPLIER_MACALLAN,
155                 .cont_conf = 0x3FFF,
156                 .trig_conf = 0x1DB,
157                 .shunt_resistor = 10,
158         },
159
160         [VD_DDR0] = {
161                 .calibration_data  = 0xaec0,
162                 .power_lsb = 1.8311874106 * PRECISION_MULTIPLIER_MACALLAN,
163                 .rail_name = "VD_DDR0",
164                 .divisor = 20,
165                 .precision_multiplier = PRECISION_MULTIPLIER_MACALLAN,
166                 .cont_conf = 0x3FFF,
167                 .trig_conf = 0x1DB,
168                 .shunt_resistor = 10,
169         },
170
171         [VD_DDR1] = {
172                 .calibration_data  = 0xaec0,
173                 .power_lsb = 1.8311874106 * PRECISION_MULTIPLIER_MACALLAN,
174                 .rail_name = "VD_DDR1",
175                 .divisor = 20,
176                 .precision_multiplier = PRECISION_MULTIPLIER_MACALLAN,
177                 .cont_conf = 0x3FFF,
178                 .trig_conf = 0x1DB,
179                 .shunt_resistor = 10,
180         },
181
182         [VD_AP_VBUS] = {
183                 .calibration_data  = 0xfffe,
184                 .power_lsb = 1.2500381481 * PRECISION_MULTIPLIER_MACALLAN,
185                 .rail_name = "VD_AP_VBUS",
186                 .divisor = 20,
187                 .precision_multiplier = PRECISION_MULTIPLIER_MACALLAN,
188                 .cont_conf = 0x3FFF,
189                 .trig_conf = 0x1DB,
190                 .shunt_resistor = 200,
191         },
192
193         [VS_SYS_2V9] = {
194                 .calibration_data  = 0xfffe,
195                 .power_lsb = 1.2500381481 * PRECISION_MULTIPLIER_MACALLAN,
196                 .rail_name = "VS_SYS_2V9",
197                 .divisor = 20,
198                 .precision_multiplier = PRECISION_MULTIPLIER_MACALLAN,
199                 .cont_conf = 0x3FFF,
200                 .trig_conf = 0x1DB,
201                 .shunt_resistor = 10,
202         },
203
204         [VA_PLLX] = {
205                 .calibration_data  = 0xfffe,
206                 .power_lsb = 1.2500381481 * PRECISION_MULTIPLIER_MACALLAN,
207                 .rail_name = "VA_PLLX",
208                 .divisor = 20,
209                 .precision_multiplier = PRECISION_MULTIPLIER_MACALLAN,
210                 .cont_conf = 0x3FFF,
211                 .trig_conf = 0x1DB,
212                 .shunt_resistor = 10,
213         },
214
215         [VA_AP_1V2] = {
216                 .calibration_data  = 0xfffe,
217                 .power_lsb = 1.2500381481 * PRECISION_MULTIPLIER_MACALLAN,
218                 .rail_name = "VA_AP_1V2",
219                 .divisor = 20,
220                 .precision_multiplier = PRECISION_MULTIPLIER_MACALLAN,
221                 .cont_conf = 0x3FFF,
222                 .trig_conf = 0x1DB,
223                 .shunt_resistor = 10,
224         },
225 };
226
227 enum {
228         VDD_CELL
229 };
230
231 static struct ina230_platform_data power_mon_ina230_info[] = {
232         [VDD_CELL] = {
233                 .calibration_data  = 0x20c4,
234                 .power_lsb = 3.051757813 * PRECISION_MULTIPLIER_MACALLAN,
235                 .rail_name = "VDD_CELL",
236                 .resistor = -5,
237                 .divisor = 25,
238                 .precision_multiplier = PRECISION_MULTIPLIER_MACALLAN,
239                 .shunt_polarity_inverted = 1,
240         }
241 };
242
243 enum {
244         INA_I2C_ADDR_40,
245         INA_I2C_ADDR_41,
246         INA_I2C_ADDR_42,
247         INA_I2C_ADDR_43,
248         INA_I2C_ADDR_44,
249         INA_I2C_ADDR_45,
250         INA_I2C_ADDR_46,
251         INA_I2C_ADDR_47,
252         INA_I2C_ADDR_48,
253         INA_I2C_ADDR_49,
254         INA_I2C_ADDR_4A,
255         INA_I2C_ADDR_4B,
256         INA_I2C_ADDR_4C,
257         INA_I2C_ADDR_4D,
258         INA_I2C_ADDR_4E,
259         INA_I2C_ADDR_4F,
260 };
261
262 static struct i2c_board_info macallan_i2c1_ina_board_info[] = {
263         [INA_I2C_ADDR_40] = {
264                 I2C_BOARD_INFO("ina219", 0x40),
265                 .platform_data = &power_mon_ina219_info[VD_CPU],
266                 .irq = -1,
267         },
268
269         [INA_I2C_ADDR_41] = {
270                 I2C_BOARD_INFO("ina219", 0x41),
271                 .platform_data = &power_mon_ina219_info[VD_SOC],
272                 .irq = -1,
273         },
274
275         [INA_I2C_ADDR_42] = {
276                 I2C_BOARD_INFO("ina219", 0x42),
277                 .platform_data = &power_mon_ina219_info[VS_DDR0],
278                 .irq = -1,
279         },
280
281         [INA_I2C_ADDR_43] = {
282                 I2C_BOARD_INFO("ina219", 0x43),
283                 .platform_data = &power_mon_ina219_info[VS_DDR1],
284                 .irq = -1,
285         },
286
287         [INA_I2C_ADDR_44] = {
288                 I2C_BOARD_INFO("ina230", 0x44),
289                 .platform_data = &power_mon_ina230_info[VDD_CELL],
290                 .irq = -1,
291         },
292
293         [INA_I2C_ADDR_45] = {
294                 I2C_BOARD_INFO("ina219", 0x45),
295                 .platform_data = &power_mon_ina219_info[VD_LCD_HV],
296                 .irq = -1,
297         },
298
299         [INA_I2C_ADDR_46] = {
300                 I2C_BOARD_INFO("ina219", 0x46),
301                 .platform_data = &power_mon_ina219_info[VS_SYS_1V8],
302                 .irq = -1,
303         },
304
305         [INA_I2C_ADDR_47] = {
306                 I2C_BOARD_INFO("ina219", 0x47),
307                 .platform_data = &power_mon_ina219_info[VD_AP_1V8],
308                 .irq = -1,
309         },
310
311         [INA_I2C_ADDR_48] = {
312                 I2C_BOARD_INFO("ina219", 0x48),
313                 .platform_data = &power_mon_ina219_info[VD_AP_RTC],
314                 .irq = -1,
315         },
316
317         [INA_I2C_ADDR_49] = {
318                 I2C_BOARD_INFO("ina219", 0x49),
319                 .platform_data = &power_mon_ina219_info[VS_AUD_SYS],
320                 .irq = -1,
321         },
322
323         [INA_I2C_ADDR_4A] = {
324                 I2C_BOARD_INFO("ina219", 0x4A),
325                 .platform_data = &power_mon_ina219_info[VD_DDR0],
326                 .irq = -1,
327         },
328
329         [INA_I2C_ADDR_4B] = {
330                 I2C_BOARD_INFO("ina219", 0x4B),
331                 .platform_data = &power_mon_ina219_info[VD_DDR1],
332                 .irq = -1,
333         },
334
335         [INA_I2C_ADDR_4C] = {
336                 I2C_BOARD_INFO("ina219", 0x4C),
337                 .platform_data = &power_mon_ina219_info[VD_AP_VBUS],
338                 .irq = -1,
339         },
340
341         [INA_I2C_ADDR_4D] = {
342                 I2C_BOARD_INFO("ina219", 0x4D),
343                 .platform_data = &power_mon_ina219_info[VS_SYS_2V9],
344                 .irq = -1,
345         },
346
347         [INA_I2C_ADDR_4E] = {
348                 I2C_BOARD_INFO("ina219", 0x4E),
349                 .platform_data = &power_mon_ina219_info[VA_PLLX],
350                 .irq = -1,
351         },
352
353         [INA_I2C_ADDR_4F] = {
354                 I2C_BOARD_INFO("ina219", 0x4F),
355                 .platform_data = &power_mon_ina219_info[VA_AP_1V2],
356                 .irq = -1,
357         },
358 };
359
360 int __init macallan_pmon_init(void)
361 {
362         i2c_register_board_info(1, macallan_i2c1_ina_board_info,
363                 ARRAY_SIZE(macallan_i2c1_ina_board_info));
364
365         return 0;
366 }
367
368