arm: tegra: roth: change board sensors for roth
[linux-2.6.git] / arch / arm / mach-tegra / board-roth-sensors.c
1 /*
2  * arch/arm/mach-tegra/board-roth-sensors.c
3  *
4  * Copyright (c) 2012 NVIDIA CORPORATION, All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions are
8  * met:
9  *
10  * Redistributions of source code must retain the above copyright notice,
11  * this list of conditions and the following disclaimer.
12  *
13  * Redistributions in binary form must reproduce the above copyright
14  * notice, this list of conditions and the following disclaimer in the
15  * documentation and/or other materials provided with the distribution.
16  *
17  * Neither the name of NVIDIA CORPORATION nor the names of its contributors
18  * may be used to endorse or promote products derived from this software
19  * without specific prior written permission.
20  *
21  * This software is licensed under the terms of the GNU General Public
22  * License version 2, as published by the Free Software Foundation, and
23  * may be copied, distributed, and modified under those terms.
24  *
25  * This program is distributed in the hope that it will be useful,
26  * but WITHOUT ANY WARRANTY; without even the implied warranty of
27  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28  * GNU General Public License for more details.
29  */
30
31 #include <linux/i2c.h>
32 #include <linux/delay.h>
33 #include <linux/mpu.h>
34 #include <linux/gpio.h>
35 #include <linux/therm_est.h>
36 #include <linux/nct1008.h>
37 #include <mach/edp.h>
38 #include <mach/gpio-tegra.h>
39 #include <mach/pinmux-t11.h>
40 #include <mach/pinmux.h>
41 #include <generated/mach-types.h>
42
43 #include "gpio-names.h"
44 #include "board.h"
45 #include "board-roth.h"
46 #include "cpu-tegra.h"
47 #include "devices.h"
48 #include "tegra-board-id.h"
49
50 static struct board_info board_info;
51
52 static struct balanced_throttle tj_throttle = {
53         .throt_tab_size = 10,
54         .throt_tab = {
55                 {      0, 1000 },
56                 { 640000, 1000 },
57                 { 640000, 1000 },
58                 { 640000, 1000 },
59                 { 640000, 1000 },
60                 { 640000, 1000 },
61                 { 760000, 1000 },
62                 { 760000, 1050 },
63                 {1000000, 1050 },
64                 {1000000, 1100 },
65         },
66 };
67
68 static struct nct1008_platform_data roth_nct1008_pdata = {
69         .supported_hwrev = true,
70         .ext_range = true,
71         .conv_rate = 0x08,
72         .offset = 80, /* 4 * 20C. Bug 844025 - 1C for device accuracies */
73         .shutdown_ext_limit = 90, /* C */
74         .shutdown_local_limit = 120, /* C */
75
76         /* Thermal Throttling */
77         .passive = {
78                 .create_cdev = (struct thermal_cooling_device *(*)(void *))
79                                 balanced_throttle_register,
80                 .cdev_data = &tj_throttle,
81                 .trip_temp = 80000,
82                 .tc1 = 0,
83                 .tc2 = 1,
84                 .passive_delay = 2000,
85         }
86 };
87
88 static struct i2c_board_info roth_i2c4_nct1008_board_info[] = {
89         {
90                 I2C_BOARD_INFO("nct1008", 0x4C),
91                 .platform_data = &roth_nct1008_pdata,
92                 .irq = -1,
93         }
94 };
95
96 #define VI_PINMUX(_pingroup, _mux, _pupd, _tri, _io, _lock, _ioreset) \
97         {                                                       \
98                 .pingroup       = TEGRA_PINGROUP_##_pingroup,   \
99                 .func           = TEGRA_MUX_##_mux,             \
100                 .pupd           = TEGRA_PUPD_##_pupd,           \
101                 .tristate       = TEGRA_TRI_##_tri,             \
102                 .io             = TEGRA_PIN_##_io,              \
103                 .lock           = TEGRA_PIN_LOCK_##_lock,       \
104                 .od             = TEGRA_PIN_OD_DEFAULT,         \
105                 .ioreset        = TEGRA_PIN_IO_RESET_##_ioreset \
106         }
107
108 /* MPU board file definition    */
109 static struct mpu_platform_data mpu9150_gyro_data = {
110         .int_config     = 0x10,
111         .level_shifter  = 0,
112         /* Located in board_[platformname].h */
113         .orientation    = MPU_GYRO_ORIENTATION,
114         .sec_slave_type = SECONDARY_SLAVE_TYPE_NONE,
115         .key            = {0x4E, 0xCC, 0x7E, 0xEB, 0xF6, 0x1E, 0x35, 0x22,
116                            0x00, 0x34, 0x0D, 0x65, 0x32, 0xE9, 0x94, 0x89},
117 };
118
119 static struct i2c_board_info __initdata inv_mpu9150_i2c2_board_info[] = {
120         {
121                 I2C_BOARD_INFO(MPU_GYRO_NAME, MPU_GYRO_ADDR),
122                 .platform_data = &mpu9150_gyro_data,
123         },
124 };
125
126 static void mpuirq_init(void)
127 {
128         int ret = 0;
129         unsigned gyro_irq_gpio = MPU_GYRO_IRQ_GPIO;
130         unsigned gyro_bus_num = MPU_GYRO_BUS_NUM;
131         char *gyro_name = MPU_GYRO_NAME;
132
133         pr_info("*** MPU START *** mpuirq_init...\n");
134
135         ret = gpio_request(gyro_irq_gpio, gyro_name);
136
137         if (ret < 0) {
138                 pr_err("%s: gpio_request failed %d\n", __func__, ret);
139                 return;
140         }
141
142         ret = gpio_direction_input(gyro_irq_gpio);
143         if (ret < 0) {
144                 pr_err("%s: gpio_direction_input failed %d\n", __func__, ret);
145                 gpio_free(gyro_irq_gpio);
146                 return;
147         }
148         pr_info("*** MPU END *** mpuirq_init...\n");
149
150         inv_mpu9150_i2c2_board_info[0].irq = gpio_to_irq(MPU_GYRO_IRQ_GPIO);
151         i2c_register_board_info(gyro_bus_num, inv_mpu9150_i2c2_board_info,
152                 ARRAY_SIZE(inv_mpu9150_i2c2_board_info));
153 }
154
155 static int roth_nct1008_init(void)
156 {
157         int nct1008_port = -1;
158         int ret = 0;
159
160 #if defined(CONFIG_ARCH_TEGRA_11x_SOC)
161         if ((board_info.board_id == BOARD_E1611) ||
162             (board_info.board_id == BOARD_E1612) ||
163             (board_info.board_id == BOARD_E1641) ||
164             (board_info.board_id == BOARD_E1613) ||
165             (board_info.board_id == BOARD_P2454))
166         {
167                 /* per email from Matt 9/10/2012 */
168                 nct1008_port = TEGRA_GPIO_PX6;
169         } else {
170                 nct1008_port = TEGRA_GPIO_PX6;
171                 pr_err("Warning: nct alert_port assumed TEGRA_GPIO_PX6"
172                        " for unknown roth board id E%d\n",
173                        board_info.board_id);
174         }
175 #else
176         /* roth + AP30 interposer has SPI2_CS0 gpio */
177         nct1008_port = TEGRA_GPIO_PX3;
178 #endif
179
180         if (nct1008_port >= 0) {
181 #ifdef CONFIG_TEGRA_EDP_LIMITS
182                 const struct tegra_edp_limits *cpu_edp_limits;
183                 int cpu_edp_limits_size;
184                 int i;
185
186                 /* edp capping */
187                 tegra_get_cpu_edp_limits(&cpu_edp_limits, &cpu_edp_limits_size);
188
189                 if (cpu_edp_limits_size > MAX_THROT_TABLE_SIZE)
190                         BUG();
191
192                 for (i = 0; i < cpu_edp_limits_size-1; i++) {
193                         roth_nct1008_pdata.active[i].create_cdev =
194                                 (struct thermal_cooling_device *(*)(void *))
195                                         edp_cooling_device_create;
196                         roth_nct1008_pdata.active[i].cdev_data = (void *)i;
197                         roth_nct1008_pdata.active[i].trip_temp =
198                                 cpu_edp_limits[i].temperature * 1000;
199                         roth_nct1008_pdata.active[i].hysteresis = 1000;
200                 }
201                 roth_nct1008_pdata.active[i].create_cdev = NULL;
202 #endif
203
204                 roth_i2c4_nct1008_board_info[0].irq = gpio_to_irq(nct1008_port);
205                 pr_info("%s: roth nct1008 irq %d", __func__, roth_i2c4_nct1008_board_info[0].irq);
206
207                 ret = gpio_request(nct1008_port, "temp_alert");
208                 if (ret < 0)
209                         return ret;
210
211                 ret = gpio_direction_input(nct1008_port);
212                 if (ret < 0) {
213                         pr_info("%s: calling gpio_free(nct1008_port)", __func__);
214                         gpio_free(nct1008_port);
215                 }
216         }
217
218         /* roth has thermal sensor on GEN1-I2C i.e. instance 0 */
219         i2c_register_board_info(0, roth_i2c4_nct1008_board_info,
220                 ARRAY_SIZE(roth_i2c4_nct1008_board_info));
221
222         return ret;
223 }
224
225 static struct i2c_board_info __initdata bq20z45_pdata[] = {
226         {
227                 I2C_BOARD_INFO("sbs-battery", 0x0B),
228         },
229 };
230
231 #ifdef CONFIG_TEGRA_SKIN_THROTTLE
232 static int tegra_skin_match(struct thermal_zone_device *thz, void *data)
233 {
234         return strcmp((char *)data, thz->type) == 0;
235 }
236
237 static int tegra_skin_get_temp(void *data, long *temp)
238 {
239         struct thermal_zone_device *thz;
240
241         thz = thermal_zone_device_find(data, tegra_skin_match);
242
243         if (!thz || thz->ops->get_temp(thz, temp))
244                 *temp = 25000;
245
246         return 0;
247 }
248
249 static struct therm_est_data skin_data = {
250         .toffset = 9793,
251         .polling_period = 1100,
252         .ndevs = 2,
253         .devs = {
254                         {
255                                 .dev_data = "nct_ext",
256                                 .get_temp = tegra_skin_get_temp,
257                                 .coeffs = {
258                                         2, 1, 1, 1,
259                                         1, 1, 1, 1,
260                                         1, 1, 1, 0,
261                                         1, 1, 0, 0,
262                                         0, 0, -1, -7
263                                 },
264                         },
265                         {
266                                 .dev_data = "nct_int",
267                                 .get_temp = tegra_skin_get_temp,
268                                 .coeffs = {
269                                         -11, -7, -5, -3,
270                                         -3, -2, -1, 0,
271                                         0, 0, 1, 1,
272                                         1, 2, 2, 3,
273                                         4, 6, 11, 18
274                                 },
275                         },
276         },
277         .trip_temp = 43000,
278         .tc1 = 1,
279         .tc2 = 15,
280         .passive_delay = 15000,
281 };
282
283 static struct balanced_throttle skin_throttle = {
284         .throt_tab_size = 6,
285         .throt_tab = {
286                 { 640000, 1200 },
287                 { 640000, 1200 },
288                 { 760000, 1200 },
289                 { 760000, 1200 },
290                 {1000000, 1200 },
291                 {1000000, 1200 },
292         },
293 };
294
295 static int __init roth_skin_init(void)
296 {
297         struct thermal_cooling_device *skin_cdev;
298
299         skin_cdev = balanced_throttle_register(&skin_throttle);
300
301         skin_data.cdev = skin_cdev;
302         tegra_skin_therm_est_device.dev.platform_data = &skin_data;
303         platform_device_register(&tegra_skin_therm_est_device);
304
305         return 0;
306 }
307 late_initcall(roth_skin_init);
308 #endif
309
310 int __init roth_sensors_init(void)
311 {
312         int err;
313
314         tegra_get_board_info(&board_info);
315
316         err = roth_nct1008_init();
317         if (err)
318                 return err;
319
320         mpuirq_init();
321
322         i2c_register_board_info(0, bq20z45_pdata,
323                 ARRAY_SIZE(bq20z45_pdata));
324
325         return 0;
326 }