misc: nct1008: sysfs interface for THERM setting
[linux-2.6.git] / arch / arm / mach-tegra / board-cardhu-sensors.c
1 /*
2  * arch/arm/mach-tegra/board-cardhu-sensors.c
3  *
4  * Copyright (c) 2011, NVIDIA, 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/i2c/pca954x.h>
23 #include <linux/i2c/pca953x.h>
24
25 #include <linux/nct1008.h>
26 #include "board.h"
27 #include "board-cardhu.h"
28 #include "gpio-names.h"
29
30 #ifdef CONFIG_I2C_MUX_PCA954x
31 static struct pca954x_platform_mode cardhu_pca954x_modes[] = {
32         { .adap_id = PCA954x_I2C_BUS0, },
33         { .adap_id = PCA954x_I2C_BUS1, },
34         { .adap_id = PCA954x_I2C_BUS2, },
35         { .adap_id = PCA954x_I2C_BUS3, },
36 };
37
38 static struct pca954x_platform_data cardhu_pca954x_data = {
39         .modes    = cardhu_pca954x_modes,
40         .num_modes      = ARRAY_SIZE(cardhu_pca954x_modes),
41 };
42
43 #endif
44
45 static const struct i2c_board_info cardhu_i2c3_board_info[] = {
46 #ifdef CONFIG_I2C_MUX_PCA954x
47         {
48                 I2C_BOARD_INFO("pca9546", 0x70),
49                 .platform_data = &cardhu_pca954x_data,
50         },
51 #endif
52 };
53
54 static struct nct1008_platform_data cardhu_nct1008_pdata = {
55         .supported_hwrev = true,
56         .ext_range = false,
57         .conv_rate = 0x08,
58         .offset = 0,
59         .hysteresis = 5,
60         .shutdown_ext_limit = 75,
61         .shutdown_local_limit = 75,
62         .throttling_ext_limit = 60,
63         .alarm_fn = NULL,
64 };
65
66 static struct i2c_board_info cardhu_i2c4_board_info[] = {
67         {
68                 I2C_BOARD_INFO("nct1008", 0x4C),
69                 .platform_data = &cardhu_nct1008_pdata,
70                 .irq = -1,
71         }
72 };
73
74 static int cardhu_nct1008_init(void)
75 {
76         int nct1008_port = -1;
77         struct board_info BoardInfo;
78         int ret;
79
80         tegra_get_board_info(&BoardInfo);
81         if ((BoardInfo.board_id == BOARD_E1198) ||
82                 (BoardInfo.board_id == BOARD_E1291)) {
83                 nct1008_port = TEGRA_GPIO_PCC2;
84         } else if ((BoardInfo.board_id == BOARD_E1186) ||
85                 (BoardInfo.board_id == BOARD_E1187)) {
86                 /* FIXME: seems to be conflicting with usb3 vbus on E1186 */
87                 /* nct1008_port = TEGRA_GPIO_PH7; */
88         }
89
90         if (nct1008_port >= 0) {
91                 /* FIXME: enable irq when throttling is supported */
92                 /* cardhu_i2c4_board_info[0].irq = */
93                 /* TEGRA_GPIO_TO_IRQ(nct1008_port); */
94
95                 ret = gpio_request(nct1008_port, "temp_alert");
96                 if (ret < 0)
97                         return ret;
98
99                 ret = gpio_direction_input(nct1008_port);
100                 if (ret < 0)
101                         gpio_free(nct1008_port);
102                 else
103                         tegra_gpio_enable(nct1008_port);
104
105         }
106         return ret;
107 }
108
109 #if defined(CONFIG_GPIO_PCA953X)
110 static struct pca953x_platform_data cardhu_pmu_tca6416_data = {
111         .gpio_base      = PMU_TCA6416_GPIO_BASE,
112 };
113
114 static const struct i2c_board_info cardhu_i2c4_board_info_tca6416[] = {
115         {
116                 I2C_BOARD_INFO("tca6416", 0x20),
117                 .platform_data = &cardhu_pmu_tca6416_data,
118         },
119 };
120
121 static int __init pmu_tca6416_init(void)
122 {
123         struct board_info board_info;
124         tegra_get_board_info(&board_info);
125         if ((board_info.board_id == BOARD_E1198) ||
126                         (board_info.board_id == BOARD_E1291))
127                 return 0;
128
129         pr_info("Registering pmu pca6416\n");
130         i2c_register_board_info(4, cardhu_i2c4_board_info_tca6416,
131                 ARRAY_SIZE(cardhu_i2c4_board_info_tca6416));
132         return 0;
133 }
134 #else
135 static int __init pmu_tca6416_init(void)
136 {
137         return 0;
138 }
139 #endif
140
141 int __init cardhu_sensors_init(void)
142 {
143         int err;
144
145         if (ARRAY_SIZE(cardhu_i2c3_board_info))
146                 i2c_register_board_info(3, cardhu_i2c3_board_info,
147                         ARRAY_SIZE(cardhu_i2c3_board_info));
148
149         pmu_tca6416_init();
150
151         i2c_register_board_info(4, cardhu_i2c4_board_info,
152                 ARRAY_SIZE(cardhu_i2c4_board_info));
153
154         err = cardhu_nct1008_init();
155         if (err)
156                 return err;
157
158         return 0;
159 }