ARM: tegra12: set CPU rate to 2.2GHz for sku 0x87
[linux-3.10.git] / arch / arm / mach-tegra / board-pluto-powermon.c
1 /*
2  * arch/arm/mach-tegra/board-pluto-powermon.c
3  *
4  * Copyright (c) 2012-2013, NVIDIA CORPORATION. All rights reserved.
5  *
6  * This program is free software; you can redistribute it and/or modify it
7  * under the terms and conditions of the GNU General Public License,
8  * version 2, as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
13  * more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17  *
18  */
19
20 #include <linux/i2c.h>
21 #include <linux/ina219.h>
22 #include <linux/platform_data/ina230.h>
23 #include <linux/i2c/pca954x.h>
24
25 #include "board.h"
26 #include "board-pluto.h"
27
28 #define PRECISION_MULTIPLIER_PLUTO      1000
29
30 /*
31  * following power_config will be passed from Bootloader
32  * if board is reworked for power measurement
33  */
34 #define PLUTO_POWER_REWORKED_CONFIG     0x10
35
36 #define AVG_SAMPLES (2 << 9) /* 16 samples */
37
38 /* AVG is specified from platform data */
39 #define INA230_CONT_CONFIG      (AVG_SAMPLES | INA230_VBUS_CT | \
40                                 INA230_VSH_CT | INA230_CONT_MODE)
41 #define INA230_TRIG_CONFIG      (AVG_SAMPLES | INA230_VBUS_CT | \
42                                  INA230_VSH_CT | INA230_TRIG_MODE)
43
44 enum {
45         UNUSED_RAIL,
46 };
47
48 enum {
49         VDD_SYS_SUM,
50         VDD_SYS_SMPS123,
51         VDD_SYS_SMPS45,
52         VDD_SYS_SMPS6,
53         VDD_SYS_SMPS7,
54         VDD_SYS_SMPS8,
55         VDD_SYS_BL,
56         VDD_SYS_LDO8,
57         VDD_MMC_LDO9,
58         VDD_5V0_LDOUSB,
59         VDD_1V8_AP,
60         VDD_MMC_LCD,
61         VDDIO_HSIC_BB,
62         AVDD_PLL_BB,
63 };
64
65 enum {
66         AVDD_1V05_LDO1,
67         VDDIO_1V8_BB,
68 };
69
70 static struct ina219_platform_data power_mon_info_0[] = {
71         /* All unused INA219 devices use below data*/
72         [UNUSED_RAIL] = {
73                 .calibration_data = 0x369c,
74                 .power_lsb = 3.051979018 * PRECISION_MULTIPLIER_PLUTO,
75                 .rail_name = "unused_rail",
76                 .divisor = 25,
77                 .precision_multiplier = PRECISION_MULTIPLIER_PLUTO,
78         },
79 };
80
81 static struct ina230_platform_data power_mon_info_1[] = {
82         [VDD_SYS_SUM] = {
83                 .calibration_data  = 0x369c,
84                 .power_lsb = 3.051979018 * PRECISION_MULTIPLIER_PLUTO,
85                 .rail_name = "VDD_SYS_SUM",
86                 .trig_conf = INA230_TRIG_CONFIG,
87                 .cont_conf = INA230_CONT_CONFIG,
88                 .divisor = 25,
89                 .precision_multiplier = PRECISION_MULTIPLIER_PLUTO,
90         },
91
92         [VDD_SYS_SMPS123] = {
93                 .calibration_data  = 0x2bb0,
94                 .power_lsb = 2.288984263 * PRECISION_MULTIPLIER_PLUTO,
95                 .rail_name = "VDD_SYS_SMPS123",
96                 .trig_conf = INA230_TRIG_CONFIG,
97                 .cont_conf = INA230_CONT_CONFIG,
98                 .divisor = 25,
99                 .precision_multiplier = PRECISION_MULTIPLIER_PLUTO,
100         },
101
102         [VDD_SYS_SMPS45] = {
103                 .calibration_data  = 0x4188,
104                 .power_lsb = 1.525989509 * PRECISION_MULTIPLIER_PLUTO,
105                 .rail_name = "VDD_SYS_SMPS45",
106                 .trig_conf = INA230_TRIG_CONFIG,
107                 .cont_conf = INA230_CONT_CONFIG,
108                 .divisor = 25,
109                 .precision_multiplier = PRECISION_MULTIPLIER_PLUTO,
110         },
111
112         [VDD_SYS_SMPS6] = {
113                 .calibration_data  = 0x2bb0,
114                 .power_lsb = 0.381497377 * PRECISION_MULTIPLIER_PLUTO,
115                 .rail_name = "VDD_SYS_SMPS6",
116                 .trig_conf = INA230_TRIG_CONFIG,
117                 .cont_conf = INA230_CONT_CONFIG,
118                 .divisor = 25,
119                 .precision_multiplier = PRECISION_MULTIPLIER_PLUTO,
120         },
121
122         [VDD_SYS_SMPS7] = {
123                 .calibration_data  = 0x2bb0,
124                 .power_lsb = 0.228898426  * PRECISION_MULTIPLIER_PLUTO,
125                 .rail_name = "VDD_SYS_SMPS7",
126                 .trig_conf = INA230_TRIG_CONFIG,
127                 .cont_conf = INA230_CONT_CONFIG,
128                 .resistor = 50,
129                 .divisor = 25,
130                 .precision_multiplier = PRECISION_MULTIPLIER_PLUTO,
131         },
132
133         [VDD_SYS_SMPS8] = {
134                 .calibration_data  = 0x2bb0,
135                 .power_lsb = 0.228898426 * PRECISION_MULTIPLIER_PLUTO,
136                 .rail_name = "VDD_SYS_SMPS8",
137                 .trig_conf = INA230_TRIG_CONFIG,
138                 .cont_conf = INA230_CONT_CONFIG,
139                 .divisor = 25,
140                 .precision_multiplier = PRECISION_MULTIPLIER_PLUTO,
141         },
142
143         [VDD_SYS_BL] = {
144                 .calibration_data  = 0x4188,
145                 .power_lsb = 0.152598951 * PRECISION_MULTIPLIER_PLUTO,
146                 .rail_name = "VDD_SYS_BL",
147                 .trig_conf = INA230_TRIG_CONFIG,
148                 .cont_conf = INA230_CONT_CONFIG,
149                 .divisor = 25,
150                 .precision_multiplier = PRECISION_MULTIPLIER_PLUTO,
151         },
152
153         [VDD_SYS_LDO8] = {
154                 .calibration_data  = 0x2d82,
155                 .power_lsb = 0.054935622 * PRECISION_MULTIPLIER_PLUTO,
156                 .rail_name = "VDD_SYS_LDO8",
157                 .trig_conf = INA230_TRIG_CONFIG,
158                 .cont_conf = INA230_CONT_CONFIG,
159                 .divisor = 25,
160                 .precision_multiplier = PRECISION_MULTIPLIER_PLUTO,
161         },
162
163         [VDD_MMC_LDO9] = {
164                 .calibration_data  = 0x51ea,
165                 .power_lsb = 0.03051979 * PRECISION_MULTIPLIER_PLUTO,
166                 .rail_name = "VDD_MMC_LDO9",
167                 .trig_conf = INA230_TRIG_CONFIG,
168                 .cont_conf = INA230_CONT_CONFIG,
169                 .divisor = 25,
170                 .precision_multiplier = PRECISION_MULTIPLIER_PLUTO,
171         },
172
173         [VDD_5V0_LDOUSB] = {
174                 .calibration_data  = 0x2f7d,
175                 .power_lsb = 0.052644567 * PRECISION_MULTIPLIER_PLUTO,
176                 .rail_name = "VDD_5V0_LDOUSB",
177                 .trig_conf = INA230_TRIG_CONFIG,
178                 .cont_conf = INA230_CONT_CONFIG,
179                 .divisor = 25,
180                 .precision_multiplier = PRECISION_MULTIPLIER_PLUTO,
181         },
182
183         [VDD_1V8_AP] = {
184                 .calibration_data  = 0x4feb,
185                 .power_lsb = 0.125128305 * PRECISION_MULTIPLIER_PLUTO,
186                 .rail_name = "VDD_1V8_AP",
187                 .trig_conf = INA230_TRIG_CONFIG,
188                 .cont_conf = INA230_CONT_CONFIG,
189                 .divisor = 25,
190                 .precision_multiplier = PRECISION_MULTIPLIER_PLUTO,
191         },
192
193         [VDD_MMC_LCD] = {
194                 .calibration_data  = 0x346d,
195                 .power_lsb = 0.047686462 * PRECISION_MULTIPLIER_PLUTO,
196                 .rail_name = "VDD_MMC_LCD",
197                 .trig_conf = INA230_TRIG_CONFIG,
198                 .cont_conf = INA230_CONT_CONFIG,
199                 .divisor = 25,
200                 .precision_multiplier = PRECISION_MULTIPLIER_PLUTO,
201         },
202
203         [VDDIO_HSIC_BB] = {
204                 .calibration_data  = 0x6d39,
205                 .power_lsb = 0.00915561 * PRECISION_MULTIPLIER_PLUTO,
206                 .rail_name = "VDDIO_HSIC_BB",
207                 .trig_conf = INA230_TRIG_CONFIG,
208                 .cont_conf = INA230_CONT_CONFIG,
209                 .divisor = 25,
210                 .precision_multiplier = PRECISION_MULTIPLIER_PLUTO,
211         },
212
213         [AVDD_PLL_BB] = {
214                 .calibration_data  = 0x7fff,
215                 .power_lsb = 0.007812738 * PRECISION_MULTIPLIER_PLUTO,
216                 .rail_name = "AVDD_PLL_BB",
217                 .trig_conf = INA230_TRIG_CONFIG,
218                 .cont_conf = INA230_CONT_CONFIG,
219                 .divisor = 25,
220                 .precision_multiplier = PRECISION_MULTIPLIER_PLUTO,
221         },
222 };
223
224 static struct ina230_platform_data power_mon_info_2[] = {
225         [AVDD_1V05_LDO1] = {
226                 .calibration_data  = 0x7fff,
227                 .power_lsb = 0.195318461 * PRECISION_MULTIPLIER_PLUTO,
228                 .rail_name = "AVDD_1V05_LDO1",
229                 .trig_conf = INA230_TRIG_CONFIG,
230                 .cont_conf = INA230_CONT_CONFIG,
231                 .divisor = 25,
232                 .precision_multiplier = PRECISION_MULTIPLIER_PLUTO,
233         },
234
235         [VDDIO_1V8_BB] = {
236                 .calibration_data  = 0x7fff,
237                 .power_lsb = 0.078127384 * PRECISION_MULTIPLIER_PLUTO,
238                 .rail_name = "VDDIO_1V8_BB",
239                 .trig_conf = INA230_TRIG_CONFIG,
240                 .cont_conf = INA230_CONT_CONFIG,
241                 .divisor = 25,
242                 .precision_multiplier = PRECISION_MULTIPLIER_PLUTO,
243         },
244 };
245
246 enum {
247         INA_I2C_2_0_ADDR_40,
248         INA_I2C_2_0_ADDR_41,
249         INA_I2C_2_0_ADDR_42,
250         INA_I2C_2_0_ADDR_43,
251 };
252
253 enum {
254         INA_I2C_2_1_ADDR_40,
255         INA_I2C_2_1_ADDR_41,
256         INA_I2C_2_1_ADDR_42,
257         INA_I2C_2_1_ADDR_43,
258         INA_I2C_2_1_ADDR_44,
259         INA_I2C_2_1_ADDR_45,
260         INA_I2C_2_1_ADDR_46,
261         INA_I2C_2_1_ADDR_47,
262         INA_I2C_2_1_ADDR_48,
263         INA_I2C_2_1_ADDR_49,
264         INA_I2C_2_1_ADDR_4B,
265         INA_I2C_2_1_ADDR_4C,
266         INA_I2C_2_1_ADDR_4E,
267         INA_I2C_2_1_ADDR_4F,
268 };
269
270 enum {
271         INA_I2C_2_2_ADDR_49,
272         INA_I2C_2_2_ADDR_4C,
273 };
274
275 static struct i2c_board_info pluto_i2c2_0_ina219_board_info[] = {
276         [INA_I2C_2_0_ADDR_40] = {
277                 I2C_BOARD_INFO("ina219", 0x40),
278                 .platform_data = &power_mon_info_0[UNUSED_RAIL],
279                 .irq = -1,
280         },
281
282         [INA_I2C_2_0_ADDR_41] = {
283                 I2C_BOARD_INFO("ina219", 0x41),
284                 .platform_data = &power_mon_info_0[UNUSED_RAIL],
285                 .irq = -1,
286         },
287
288         [INA_I2C_2_0_ADDR_42] = {
289                 I2C_BOARD_INFO("ina219", 0x42),
290                 .platform_data = &power_mon_info_0[UNUSED_RAIL],
291                 .irq = -1,
292         },
293
294         [INA_I2C_2_0_ADDR_43] = {
295                 I2C_BOARD_INFO("ina219", 0x43),
296                 .platform_data = &power_mon_info_0[UNUSED_RAIL],
297                 .irq = -1,
298         },
299 };
300
301 static struct i2c_board_info pluto_i2c2_1_ina230_board_info[] = {
302         [INA_I2C_2_1_ADDR_40] = {
303                 I2C_BOARD_INFO("ina230", 0x40),
304                 .platform_data = &power_mon_info_1[VDD_SYS_SUM],
305                 .irq = -1,
306         },
307
308         [INA_I2C_2_1_ADDR_41] = {
309                 I2C_BOARD_INFO("ina230", 0x41),
310                 .platform_data = &power_mon_info_1[VDD_SYS_SMPS123],
311                 .irq = -1,
312         },
313
314         [INA_I2C_2_1_ADDR_42] = {
315                 I2C_BOARD_INFO("ina230", 0x42),
316                 .platform_data = &power_mon_info_1[VDD_SYS_SMPS45],
317                 .irq = -1,
318         },
319
320         [INA_I2C_2_1_ADDR_43] = {
321                 I2C_BOARD_INFO("ina230", 0x43),
322                 .platform_data = &power_mon_info_1[VDD_SYS_SMPS6],
323                 .irq = -1,
324         },
325
326         [INA_I2C_2_1_ADDR_44] = {
327                 I2C_BOARD_INFO("ina230", 0x44),
328                 .platform_data = &power_mon_info_1[VDD_SYS_SMPS7],
329                 .irq = -1,
330         },
331
332         [INA_I2C_2_1_ADDR_45] = {
333                 I2C_BOARD_INFO("ina230", 0x45),
334                 .platform_data = &power_mon_info_1[VDD_SYS_SMPS8],
335                 .irq = -1,
336         },
337
338         [INA_I2C_2_1_ADDR_46] = {
339                 I2C_BOARD_INFO("ina230", 0x46),
340                 .platform_data = &power_mon_info_1[VDD_SYS_BL],
341                 .irq = -1,
342         },
343
344         [INA_I2C_2_1_ADDR_47] = {
345                 I2C_BOARD_INFO("ina230", 0x47),
346                 .platform_data = &power_mon_info_1[VDD_SYS_LDO8],
347                 .irq = -1,
348         },
349
350         [INA_I2C_2_1_ADDR_48] = {
351                 I2C_BOARD_INFO("ina230", 0x48),
352                 .platform_data = &power_mon_info_1[VDD_MMC_LDO9],
353                 .irq = -1,
354         },
355
356         [INA_I2C_2_1_ADDR_49] = {
357                 I2C_BOARD_INFO("ina230", 0x49),
358                 .platform_data = &power_mon_info_1[VDD_5V0_LDOUSB],
359                 .irq = -1,
360         },
361
362         [INA_I2C_2_1_ADDR_4B] = {
363                 I2C_BOARD_INFO("ina230", 0x4B),
364                 .platform_data = &power_mon_info_1[VDD_1V8_AP],
365                 .irq = -1,
366         },
367
368         [INA_I2C_2_1_ADDR_4C] = {
369                 I2C_BOARD_INFO("ina230", 0x4C),
370                 .platform_data = &power_mon_info_1[VDD_MMC_LCD],
371                 .irq = -1,
372         },
373
374         [INA_I2C_2_1_ADDR_4E] = {
375                 I2C_BOARD_INFO("ina230", 0x4E),
376                 .platform_data = &power_mon_info_1[VDDIO_HSIC_BB],
377                 .irq = -1,
378         },
379
380         [INA_I2C_2_1_ADDR_4F] = {
381                 I2C_BOARD_INFO("ina230", 0x4F),
382                 .platform_data = &power_mon_info_1[AVDD_PLL_BB],
383                 .irq = -1,
384         },
385 };
386
387 static struct i2c_board_info pluto_i2c2_2_ina230_board_info[] = {
388         [INA_I2C_2_2_ADDR_49] = {
389                 I2C_BOARD_INFO("ina230", 0x49),
390                 .platform_data = &power_mon_info_2[AVDD_1V05_LDO1],
391                 .irq = -1,
392         },
393
394         [INA_I2C_2_2_ADDR_4C] = {
395                 I2C_BOARD_INFO("ina230", 0x4C),
396                 .platform_data = &power_mon_info_2[VDDIO_1V8_BB],
397                 .irq = -1,
398         },
399 };
400
401 static struct pca954x_platform_mode pluto_pca954x_modes[] = {
402         { .adap_id = PCA954x_I2C_BUS0, .deselect_on_exit = true, },
403         { .adap_id = PCA954x_I2C_BUS1, .deselect_on_exit = true, },
404         { .adap_id = PCA954x_I2C_BUS2, .deselect_on_exit = true, },
405         { .adap_id = PCA954x_I2C_BUS3, .deselect_on_exit = true, },
406 };
407
408 static struct pca954x_platform_data pluto_pca954x_data = {
409         .modes    = pluto_pca954x_modes,
410         .num_modes      = ARRAY_SIZE(pluto_pca954x_modes),
411 };
412
413 static const struct i2c_board_info pluto_i2c2_board_info[] = {
414         {
415                 I2C_BOARD_INFO("pca9546", 0x71),
416                 .platform_data = &pluto_pca954x_data,
417         },
418 };
419
420 static void modify_reworked_rail_data(void)
421 {
422         power_mon_info_1[VDD_SYS_SUM].calibration_data = 0x426;
423         power_mon_info_1[VDD_SYS_SUM].power_lsb =
424                                 1.20527307 * PRECISION_MULTIPLIER_PLUTO;
425
426         power_mon_info_1[VDD_SYS_SMPS123].calibration_data = 0x2134;
427         power_mon_info_1[VDD_SYS_SMPS123].power_lsb =
428                                 0.301176471 * PRECISION_MULTIPLIER_PLUTO;
429
430         power_mon_info_1[VDD_SYS_SMPS45].calibration_data = 0x2134;
431         power_mon_info_1[VDD_SYS_SMPS45].power_lsb =
432                                 0.301176471 * PRECISION_MULTIPLIER_PLUTO;
433
434         power_mon_info_1[VDD_SYS_SMPS6].calibration_data = 0x3756;
435         power_mon_info_1[VDD_SYS_SMPS6].power_lsb =
436                                 0.180714387 * PRECISION_MULTIPLIER_PLUTO;
437
438         power_mon_info_1[VDD_SYS_SMPS7].calibration_data = 0x84D;
439         power_mon_info_1[VDD_SYS_SMPS7].power_lsb =
440                                 0.120470588 * PRECISION_MULTIPLIER_PLUTO;
441
442         power_mon_info_1[VDD_SYS_SMPS8].calibration_data = 0x14C0;
443         power_mon_info_1[VDD_SYS_SMPS8].power_lsb =
444                                 0.240963855 * PRECISION_MULTIPLIER_PLUTO;
445
446         power_mon_info_1[VDD_SYS_LDO8].calibration_data = 0x18E7;
447         power_mon_info_1[VDD_SYS_LDO8].power_lsb =
448                                 0.040156863 * PRECISION_MULTIPLIER_PLUTO;
449
450         power_mon_info_1[VDD_MMC_LDO9].calibration_data = 0xEAD;
451         power_mon_info_1[VDD_MMC_LDO9].power_lsb =
452                                 0.068139473 * PRECISION_MULTIPLIER_PLUTO;
453
454         power_mon_info_1[VDD_MMC_LCD].calibration_data = 0x1E95;
455         power_mon_info_1[VDD_MMC_LCD].power_lsb =
456                                 0.08174735 * PRECISION_MULTIPLIER_PLUTO;
457 }
458
459 int __init pluto_pmon_init(void)
460 {
461         u8 power_config;
462
463         /*
464          * Get power_config of board and check whether
465          * board is power reworked or not.
466          * In case board is reworked, modify rail data
467          * for which rework was done.
468          */
469         power_config = get_power_config();
470         if (power_config & PLUTO_POWER_REWORKED_CONFIG)
471                 modify_reworked_rail_data();
472
473         i2c_register_board_info(1, pluto_i2c2_board_info,
474                 ARRAY_SIZE(pluto_i2c2_board_info));
475
476         i2c_register_board_info(PCA954x_I2C_BUS0,
477                         pluto_i2c2_0_ina219_board_info,
478                         ARRAY_SIZE(pluto_i2c2_0_ina219_board_info));
479
480         i2c_register_board_info(PCA954x_I2C_BUS1,
481                         pluto_i2c2_1_ina230_board_info,
482                         ARRAY_SIZE(pluto_i2c2_1_ina230_board_info));
483
484         i2c_register_board_info(PCA954x_I2C_BUS2,
485                         pluto_i2c2_2_ina230_board_info,
486                         ARRAY_SIZE(pluto_i2c2_2_ina230_board_info));
487         return 0;
488 }
489