Commit ff71c182f461da5ae9d2d65f8a63f5a9193b9be1

Authored by Guenter Roeck
1 parent ddf28352b8

hwmon: (max16065) Fix current calculation

Current calculation is completely wrong. Add missing brackets to fix it.

Signed-off-by: Guenter Roeck <guenter.roeck@ericsson.com>
Acked-by: Jean Delvare <khali@linux-fr.org>
Cc: stable@kernel.org # 3.0+

Showing 1 changed file with 1 additions and 1 deletions Inline Diff

drivers/hwmon/max16065.c
1 /* 1 /*
2 * Driver for 2 * Driver for
3 * Maxim MAX16065/MAX16066 12-Channel/8-Channel, Flash-Configurable 3 * Maxim MAX16065/MAX16066 12-Channel/8-Channel, Flash-Configurable
4 * System Managers with Nonvolatile Fault Registers 4 * System Managers with Nonvolatile Fault Registers
5 * Maxim MAX16067/MAX16068 6-Channel, Flash-Configurable System Managers 5 * Maxim MAX16067/MAX16068 6-Channel, Flash-Configurable System Managers
6 * with Nonvolatile Fault Registers 6 * with Nonvolatile Fault Registers
7 * Maxim MAX16070/MAX16071 12-Channel/8-Channel, Flash-Configurable System 7 * Maxim MAX16070/MAX16071 12-Channel/8-Channel, Flash-Configurable System
8 * Monitors with Nonvolatile Fault Registers 8 * Monitors with Nonvolatile Fault Registers
9 * 9 *
10 * Copyright (C) 2011 Ericsson AB. 10 * Copyright (C) 2011 Ericsson AB.
11 * 11 *
12 * This program is free software; you can redistribute it and/or modify 12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License as published by 13 * it under the terms of the GNU General Public License as published by
14 * the Free Software Foundation; version 2 of the License. 14 * the Free Software Foundation; version 2 of the License.
15 */ 15 */
16 16
17 #include <linux/kernel.h> 17 #include <linux/kernel.h>
18 #include <linux/module.h> 18 #include <linux/module.h>
19 #include <linux/init.h> 19 #include <linux/init.h>
20 #include <linux/err.h> 20 #include <linux/err.h>
21 #include <linux/slab.h> 21 #include <linux/slab.h>
22 #include <linux/i2c.h> 22 #include <linux/i2c.h>
23 #include <linux/hwmon.h> 23 #include <linux/hwmon.h>
24 #include <linux/hwmon-sysfs.h> 24 #include <linux/hwmon-sysfs.h>
25 #include <linux/delay.h> 25 #include <linux/delay.h>
26 #include <linux/jiffies.h> 26 #include <linux/jiffies.h>
27 27
28 enum chips { max16065, max16066, max16067, max16068, max16070, max16071 }; 28 enum chips { max16065, max16066, max16067, max16068, max16070, max16071 };
29 29
30 /* 30 /*
31 * Registers 31 * Registers
32 */ 32 */
33 #define MAX16065_ADC(x) ((x) * 2) 33 #define MAX16065_ADC(x) ((x) * 2)
34 34
35 #define MAX16065_CURR_SENSE 0x18 35 #define MAX16065_CURR_SENSE 0x18
36 #define MAX16065_CSP_ADC 0x19 36 #define MAX16065_CSP_ADC 0x19
37 #define MAX16065_FAULT(x) (0x1b + (x)) 37 #define MAX16065_FAULT(x) (0x1b + (x))
38 #define MAX16065_SCALE(x) (0x43 + (x)) 38 #define MAX16065_SCALE(x) (0x43 + (x))
39 #define MAX16065_CURR_CONTROL 0x47 39 #define MAX16065_CURR_CONTROL 0x47
40 #define MAX16065_LIMIT(l, x) (0x48 + (l) + (x) * 3) /* 40 #define MAX16065_LIMIT(l, x) (0x48 + (l) + (x) * 3) /*
41 * l: limit 41 * l: limit
42 * 0: min/max 42 * 0: min/max
43 * 1: crit 43 * 1: crit
44 * 2: lcrit 44 * 2: lcrit
45 * x: ADC index 45 * x: ADC index
46 */ 46 */
47 47
48 #define MAX16065_SW_ENABLE 0x73 48 #define MAX16065_SW_ENABLE 0x73
49 49
50 #define MAX16065_WARNING_OV (1 << 3) /* Set if secondary threshold is OV 50 #define MAX16065_WARNING_OV (1 << 3) /* Set if secondary threshold is OV
51 warning */ 51 warning */
52 52
53 #define MAX16065_CURR_ENABLE (1 << 0) 53 #define MAX16065_CURR_ENABLE (1 << 0)
54 54
55 #define MAX16065_NUM_LIMIT 3 55 #define MAX16065_NUM_LIMIT 3
56 #define MAX16065_NUM_ADC 12 /* maximum number of ADC channels */ 56 #define MAX16065_NUM_ADC 12 /* maximum number of ADC channels */
57 57
58 static const int max16065_num_adc[] = { 58 static const int max16065_num_adc[] = {
59 [max16065] = 12, 59 [max16065] = 12,
60 [max16066] = 8, 60 [max16066] = 8,
61 [max16067] = 6, 61 [max16067] = 6,
62 [max16068] = 6, 62 [max16068] = 6,
63 [max16070] = 12, 63 [max16070] = 12,
64 [max16071] = 8, 64 [max16071] = 8,
65 }; 65 };
66 66
67 static const bool max16065_have_secondary[] = { 67 static const bool max16065_have_secondary[] = {
68 [max16065] = true, 68 [max16065] = true,
69 [max16066] = true, 69 [max16066] = true,
70 [max16067] = false, 70 [max16067] = false,
71 [max16068] = false, 71 [max16068] = false,
72 [max16070] = true, 72 [max16070] = true,
73 [max16071] = true, 73 [max16071] = true,
74 }; 74 };
75 75
76 static const bool max16065_have_current[] = { 76 static const bool max16065_have_current[] = {
77 [max16065] = true, 77 [max16065] = true,
78 [max16066] = true, 78 [max16066] = true,
79 [max16067] = false, 79 [max16067] = false,
80 [max16068] = false, 80 [max16068] = false,
81 [max16070] = true, 81 [max16070] = true,
82 [max16071] = true, 82 [max16071] = true,
83 }; 83 };
84 84
85 struct max16065_data { 85 struct max16065_data {
86 enum chips type; 86 enum chips type;
87 struct device *hwmon_dev; 87 struct device *hwmon_dev;
88 struct mutex update_lock; 88 struct mutex update_lock;
89 bool valid; 89 bool valid;
90 unsigned long last_updated; /* in jiffies */ 90 unsigned long last_updated; /* in jiffies */
91 int num_adc; 91 int num_adc;
92 bool have_current; 92 bool have_current;
93 int curr_gain; 93 int curr_gain;
94 /* limits are in mV */ 94 /* limits are in mV */
95 int limit[MAX16065_NUM_LIMIT][MAX16065_NUM_ADC]; 95 int limit[MAX16065_NUM_LIMIT][MAX16065_NUM_ADC];
96 int range[MAX16065_NUM_ADC + 1];/* voltage range */ 96 int range[MAX16065_NUM_ADC + 1];/* voltage range */
97 int adc[MAX16065_NUM_ADC + 1]; /* adc values (raw) including csp_adc */ 97 int adc[MAX16065_NUM_ADC + 1]; /* adc values (raw) including csp_adc */
98 int curr_sense; 98 int curr_sense;
99 int fault[2]; 99 int fault[2];
100 }; 100 };
101 101
102 static const int max16065_adc_range[] = { 5560, 2780, 1390, 0 }; 102 static const int max16065_adc_range[] = { 5560, 2780, 1390, 0 };
103 static const int max16065_csp_adc_range[] = { 7000, 14000 }; 103 static const int max16065_csp_adc_range[] = { 7000, 14000 };
104 104
105 /* ADC registers have 10 bit resolution. */ 105 /* ADC registers have 10 bit resolution. */
106 static inline int ADC_TO_MV(int adc, int range) 106 static inline int ADC_TO_MV(int adc, int range)
107 { 107 {
108 return (adc * range) / 1024; 108 return (adc * range) / 1024;
109 } 109 }
110 110
111 /* 111 /*
112 * Limit registers have 8 bit resolution and match upper 8 bits of ADC 112 * Limit registers have 8 bit resolution and match upper 8 bits of ADC
113 * registers. 113 * registers.
114 */ 114 */
115 static inline int LIMIT_TO_MV(int limit, int range) 115 static inline int LIMIT_TO_MV(int limit, int range)
116 { 116 {
117 return limit * range / 256; 117 return limit * range / 256;
118 } 118 }
119 119
120 static inline int MV_TO_LIMIT(int mv, int range) 120 static inline int MV_TO_LIMIT(int mv, int range)
121 { 121 {
122 return SENSORS_LIMIT(DIV_ROUND_CLOSEST(mv * 256, range), 0, 255); 122 return SENSORS_LIMIT(DIV_ROUND_CLOSEST(mv * 256, range), 0, 255);
123 } 123 }
124 124
125 static inline int ADC_TO_CURR(int adc, int gain) 125 static inline int ADC_TO_CURR(int adc, int gain)
126 { 126 {
127 return adc * 1400000 / gain * 255; 127 return adc * 1400000 / (gain * 255);
128 } 128 }
129 129
130 /* 130 /*
131 * max16065_read_adc() 131 * max16065_read_adc()
132 * 132 *
133 * Read 16 bit value from <reg>, <reg+1>. 133 * Read 16 bit value from <reg>, <reg+1>.
134 * Upper 8 bits are in <reg>, lower 2 bits are in bits 7:6 of <reg+1>. 134 * Upper 8 bits are in <reg>, lower 2 bits are in bits 7:6 of <reg+1>.
135 */ 135 */
136 static int max16065_read_adc(struct i2c_client *client, int reg) 136 static int max16065_read_adc(struct i2c_client *client, int reg)
137 { 137 {
138 int rv; 138 int rv;
139 139
140 rv = i2c_smbus_read_word_data(client, reg); 140 rv = i2c_smbus_read_word_data(client, reg);
141 if (unlikely(rv < 0)) 141 if (unlikely(rv < 0))
142 return rv; 142 return rv;
143 return ((rv & 0xff) << 2) | ((rv >> 14) & 0x03); 143 return ((rv & 0xff) << 2) | ((rv >> 14) & 0x03);
144 } 144 }
145 145
146 static struct max16065_data *max16065_update_device(struct device *dev) 146 static struct max16065_data *max16065_update_device(struct device *dev)
147 { 147 {
148 struct i2c_client *client = to_i2c_client(dev); 148 struct i2c_client *client = to_i2c_client(dev);
149 struct max16065_data *data = i2c_get_clientdata(client); 149 struct max16065_data *data = i2c_get_clientdata(client);
150 150
151 mutex_lock(&data->update_lock); 151 mutex_lock(&data->update_lock);
152 if (time_after(jiffies, data->last_updated + HZ) || !data->valid) { 152 if (time_after(jiffies, data->last_updated + HZ) || !data->valid) {
153 int i; 153 int i;
154 154
155 for (i = 0; i < data->num_adc; i++) 155 for (i = 0; i < data->num_adc; i++)
156 data->adc[i] 156 data->adc[i]
157 = max16065_read_adc(client, MAX16065_ADC(i)); 157 = max16065_read_adc(client, MAX16065_ADC(i));
158 158
159 if (data->have_current) { 159 if (data->have_current) {
160 data->adc[MAX16065_NUM_ADC] 160 data->adc[MAX16065_NUM_ADC]
161 = max16065_read_adc(client, MAX16065_CSP_ADC); 161 = max16065_read_adc(client, MAX16065_CSP_ADC);
162 data->curr_sense 162 data->curr_sense
163 = i2c_smbus_read_byte_data(client, 163 = i2c_smbus_read_byte_data(client,
164 MAX16065_CURR_SENSE); 164 MAX16065_CURR_SENSE);
165 } 165 }
166 166
167 for (i = 0; i < DIV_ROUND_UP(data->num_adc, 8); i++) 167 for (i = 0; i < DIV_ROUND_UP(data->num_adc, 8); i++)
168 data->fault[i] 168 data->fault[i]
169 = i2c_smbus_read_byte_data(client, MAX16065_FAULT(i)); 169 = i2c_smbus_read_byte_data(client, MAX16065_FAULT(i));
170 170
171 data->last_updated = jiffies; 171 data->last_updated = jiffies;
172 data->valid = 1; 172 data->valid = 1;
173 } 173 }
174 mutex_unlock(&data->update_lock); 174 mutex_unlock(&data->update_lock);
175 return data; 175 return data;
176 } 176 }
177 177
178 static ssize_t max16065_show_alarm(struct device *dev, 178 static ssize_t max16065_show_alarm(struct device *dev,
179 struct device_attribute *da, char *buf) 179 struct device_attribute *da, char *buf)
180 { 180 {
181 struct sensor_device_attribute_2 *attr2 = to_sensor_dev_attr_2(da); 181 struct sensor_device_attribute_2 *attr2 = to_sensor_dev_attr_2(da);
182 struct max16065_data *data = max16065_update_device(dev); 182 struct max16065_data *data = max16065_update_device(dev);
183 int val = data->fault[attr2->nr]; 183 int val = data->fault[attr2->nr];
184 184
185 if (val < 0) 185 if (val < 0)
186 return val; 186 return val;
187 187
188 val &= (1 << attr2->index); 188 val &= (1 << attr2->index);
189 if (val) 189 if (val)
190 i2c_smbus_write_byte_data(to_i2c_client(dev), 190 i2c_smbus_write_byte_data(to_i2c_client(dev),
191 MAX16065_FAULT(attr2->nr), val); 191 MAX16065_FAULT(attr2->nr), val);
192 192
193 return snprintf(buf, PAGE_SIZE, "%d\n", !!val); 193 return snprintf(buf, PAGE_SIZE, "%d\n", !!val);
194 } 194 }
195 195
196 static ssize_t max16065_show_input(struct device *dev, 196 static ssize_t max16065_show_input(struct device *dev,
197 struct device_attribute *da, char *buf) 197 struct device_attribute *da, char *buf)
198 { 198 {
199 struct sensor_device_attribute *attr = to_sensor_dev_attr(da); 199 struct sensor_device_attribute *attr = to_sensor_dev_attr(da);
200 struct max16065_data *data = max16065_update_device(dev); 200 struct max16065_data *data = max16065_update_device(dev);
201 int adc = data->adc[attr->index]; 201 int adc = data->adc[attr->index];
202 202
203 if (unlikely(adc < 0)) 203 if (unlikely(adc < 0))
204 return adc; 204 return adc;
205 205
206 return snprintf(buf, PAGE_SIZE, "%d\n", 206 return snprintf(buf, PAGE_SIZE, "%d\n",
207 ADC_TO_MV(adc, data->range[attr->index])); 207 ADC_TO_MV(adc, data->range[attr->index]));
208 } 208 }
209 209
210 static ssize_t max16065_show_current(struct device *dev, 210 static ssize_t max16065_show_current(struct device *dev,
211 struct device_attribute *da, char *buf) 211 struct device_attribute *da, char *buf)
212 { 212 {
213 struct max16065_data *data = max16065_update_device(dev); 213 struct max16065_data *data = max16065_update_device(dev);
214 214
215 if (unlikely(data->curr_sense < 0)) 215 if (unlikely(data->curr_sense < 0))
216 return data->curr_sense; 216 return data->curr_sense;
217 217
218 return snprintf(buf, PAGE_SIZE, "%d\n", 218 return snprintf(buf, PAGE_SIZE, "%d\n",
219 ADC_TO_CURR(data->curr_sense, data->curr_gain)); 219 ADC_TO_CURR(data->curr_sense, data->curr_gain));
220 } 220 }
221 221
222 static ssize_t max16065_set_limit(struct device *dev, 222 static ssize_t max16065_set_limit(struct device *dev,
223 struct device_attribute *da, 223 struct device_attribute *da,
224 const char *buf, size_t count) 224 const char *buf, size_t count)
225 { 225 {
226 struct sensor_device_attribute_2 *attr2 = to_sensor_dev_attr_2(da); 226 struct sensor_device_attribute_2 *attr2 = to_sensor_dev_attr_2(da);
227 struct i2c_client *client = to_i2c_client(dev); 227 struct i2c_client *client = to_i2c_client(dev);
228 struct max16065_data *data = i2c_get_clientdata(client); 228 struct max16065_data *data = i2c_get_clientdata(client);
229 unsigned long val; 229 unsigned long val;
230 int err; 230 int err;
231 int limit; 231 int limit;
232 232
233 err = strict_strtoul(buf, 10, &val); 233 err = strict_strtoul(buf, 10, &val);
234 if (unlikely(err < 0)) 234 if (unlikely(err < 0))
235 return err; 235 return err;
236 236
237 limit = MV_TO_LIMIT(val, data->range[attr2->index]); 237 limit = MV_TO_LIMIT(val, data->range[attr2->index]);
238 238
239 mutex_lock(&data->update_lock); 239 mutex_lock(&data->update_lock);
240 data->limit[attr2->nr][attr2->index] 240 data->limit[attr2->nr][attr2->index]
241 = LIMIT_TO_MV(limit, data->range[attr2->index]); 241 = LIMIT_TO_MV(limit, data->range[attr2->index]);
242 i2c_smbus_write_byte_data(client, 242 i2c_smbus_write_byte_data(client,
243 MAX16065_LIMIT(attr2->nr, attr2->index), 243 MAX16065_LIMIT(attr2->nr, attr2->index),
244 limit); 244 limit);
245 mutex_unlock(&data->update_lock); 245 mutex_unlock(&data->update_lock);
246 246
247 return count; 247 return count;
248 } 248 }
249 249
250 static ssize_t max16065_show_limit(struct device *dev, 250 static ssize_t max16065_show_limit(struct device *dev,
251 struct device_attribute *da, char *buf) 251 struct device_attribute *da, char *buf)
252 { 252 {
253 struct sensor_device_attribute_2 *attr2 = to_sensor_dev_attr_2(da); 253 struct sensor_device_attribute_2 *attr2 = to_sensor_dev_attr_2(da);
254 struct i2c_client *client = to_i2c_client(dev); 254 struct i2c_client *client = to_i2c_client(dev);
255 struct max16065_data *data = i2c_get_clientdata(client); 255 struct max16065_data *data = i2c_get_clientdata(client);
256 256
257 return snprintf(buf, PAGE_SIZE, "%d\n", 257 return snprintf(buf, PAGE_SIZE, "%d\n",
258 data->limit[attr2->nr][attr2->index]); 258 data->limit[attr2->nr][attr2->index]);
259 } 259 }
260 260
261 /* Construct a sensor_device_attribute structure for each register */ 261 /* Construct a sensor_device_attribute structure for each register */
262 262
263 /* Input voltages */ 263 /* Input voltages */
264 static SENSOR_DEVICE_ATTR(in0_input, S_IRUGO, max16065_show_input, NULL, 0); 264 static SENSOR_DEVICE_ATTR(in0_input, S_IRUGO, max16065_show_input, NULL, 0);
265 static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, max16065_show_input, NULL, 1); 265 static SENSOR_DEVICE_ATTR(in1_input, S_IRUGO, max16065_show_input, NULL, 1);
266 static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO, max16065_show_input, NULL, 2); 266 static SENSOR_DEVICE_ATTR(in2_input, S_IRUGO, max16065_show_input, NULL, 2);
267 static SENSOR_DEVICE_ATTR(in3_input, S_IRUGO, max16065_show_input, NULL, 3); 267 static SENSOR_DEVICE_ATTR(in3_input, S_IRUGO, max16065_show_input, NULL, 3);
268 static SENSOR_DEVICE_ATTR(in4_input, S_IRUGO, max16065_show_input, NULL, 4); 268 static SENSOR_DEVICE_ATTR(in4_input, S_IRUGO, max16065_show_input, NULL, 4);
269 static SENSOR_DEVICE_ATTR(in5_input, S_IRUGO, max16065_show_input, NULL, 5); 269 static SENSOR_DEVICE_ATTR(in5_input, S_IRUGO, max16065_show_input, NULL, 5);
270 static SENSOR_DEVICE_ATTR(in6_input, S_IRUGO, max16065_show_input, NULL, 6); 270 static SENSOR_DEVICE_ATTR(in6_input, S_IRUGO, max16065_show_input, NULL, 6);
271 static SENSOR_DEVICE_ATTR(in7_input, S_IRUGO, max16065_show_input, NULL, 7); 271 static SENSOR_DEVICE_ATTR(in7_input, S_IRUGO, max16065_show_input, NULL, 7);
272 static SENSOR_DEVICE_ATTR(in8_input, S_IRUGO, max16065_show_input, NULL, 8); 272 static SENSOR_DEVICE_ATTR(in8_input, S_IRUGO, max16065_show_input, NULL, 8);
273 static SENSOR_DEVICE_ATTR(in9_input, S_IRUGO, max16065_show_input, NULL, 9); 273 static SENSOR_DEVICE_ATTR(in9_input, S_IRUGO, max16065_show_input, NULL, 9);
274 static SENSOR_DEVICE_ATTR(in10_input, S_IRUGO, max16065_show_input, NULL, 10); 274 static SENSOR_DEVICE_ATTR(in10_input, S_IRUGO, max16065_show_input, NULL, 10);
275 static SENSOR_DEVICE_ATTR(in11_input, S_IRUGO, max16065_show_input, NULL, 11); 275 static SENSOR_DEVICE_ATTR(in11_input, S_IRUGO, max16065_show_input, NULL, 11);
276 static SENSOR_DEVICE_ATTR(in12_input, S_IRUGO, max16065_show_input, NULL, 12); 276 static SENSOR_DEVICE_ATTR(in12_input, S_IRUGO, max16065_show_input, NULL, 12);
277 277
278 /* Input voltages lcrit */ 278 /* Input voltages lcrit */
279 static SENSOR_DEVICE_ATTR_2(in0_lcrit, S_IWUSR | S_IRUGO, max16065_show_limit, 279 static SENSOR_DEVICE_ATTR_2(in0_lcrit, S_IWUSR | S_IRUGO, max16065_show_limit,
280 max16065_set_limit, 2, 0); 280 max16065_set_limit, 2, 0);
281 static SENSOR_DEVICE_ATTR_2(in1_lcrit, S_IWUSR | S_IRUGO, max16065_show_limit, 281 static SENSOR_DEVICE_ATTR_2(in1_lcrit, S_IWUSR | S_IRUGO, max16065_show_limit,
282 max16065_set_limit, 2, 1); 282 max16065_set_limit, 2, 1);
283 static SENSOR_DEVICE_ATTR_2(in2_lcrit, S_IWUSR | S_IRUGO, max16065_show_limit, 283 static SENSOR_DEVICE_ATTR_2(in2_lcrit, S_IWUSR | S_IRUGO, max16065_show_limit,
284 max16065_set_limit, 2, 2); 284 max16065_set_limit, 2, 2);
285 static SENSOR_DEVICE_ATTR_2(in3_lcrit, S_IWUSR | S_IRUGO, max16065_show_limit, 285 static SENSOR_DEVICE_ATTR_2(in3_lcrit, S_IWUSR | S_IRUGO, max16065_show_limit,
286 max16065_set_limit, 2, 3); 286 max16065_set_limit, 2, 3);
287 static SENSOR_DEVICE_ATTR_2(in4_lcrit, S_IWUSR | S_IRUGO, max16065_show_limit, 287 static SENSOR_DEVICE_ATTR_2(in4_lcrit, S_IWUSR | S_IRUGO, max16065_show_limit,
288 max16065_set_limit, 2, 4); 288 max16065_set_limit, 2, 4);
289 static SENSOR_DEVICE_ATTR_2(in5_lcrit, S_IWUSR | S_IRUGO, max16065_show_limit, 289 static SENSOR_DEVICE_ATTR_2(in5_lcrit, S_IWUSR | S_IRUGO, max16065_show_limit,
290 max16065_set_limit, 2, 5); 290 max16065_set_limit, 2, 5);
291 static SENSOR_DEVICE_ATTR_2(in6_lcrit, S_IWUSR | S_IRUGO, max16065_show_limit, 291 static SENSOR_DEVICE_ATTR_2(in6_lcrit, S_IWUSR | S_IRUGO, max16065_show_limit,
292 max16065_set_limit, 2, 6); 292 max16065_set_limit, 2, 6);
293 static SENSOR_DEVICE_ATTR_2(in7_lcrit, S_IWUSR | S_IRUGO, max16065_show_limit, 293 static SENSOR_DEVICE_ATTR_2(in7_lcrit, S_IWUSR | S_IRUGO, max16065_show_limit,
294 max16065_set_limit, 2, 7); 294 max16065_set_limit, 2, 7);
295 static SENSOR_DEVICE_ATTR_2(in8_lcrit, S_IWUSR | S_IRUGO, max16065_show_limit, 295 static SENSOR_DEVICE_ATTR_2(in8_lcrit, S_IWUSR | S_IRUGO, max16065_show_limit,
296 max16065_set_limit, 2, 8); 296 max16065_set_limit, 2, 8);
297 static SENSOR_DEVICE_ATTR_2(in9_lcrit, S_IWUSR | S_IRUGO, max16065_show_limit, 297 static SENSOR_DEVICE_ATTR_2(in9_lcrit, S_IWUSR | S_IRUGO, max16065_show_limit,
298 max16065_set_limit, 2, 9); 298 max16065_set_limit, 2, 9);
299 static SENSOR_DEVICE_ATTR_2(in10_lcrit, S_IWUSR | S_IRUGO, max16065_show_limit, 299 static SENSOR_DEVICE_ATTR_2(in10_lcrit, S_IWUSR | S_IRUGO, max16065_show_limit,
300 max16065_set_limit, 2, 10); 300 max16065_set_limit, 2, 10);
301 static SENSOR_DEVICE_ATTR_2(in11_lcrit, S_IWUSR | S_IRUGO, max16065_show_limit, 301 static SENSOR_DEVICE_ATTR_2(in11_lcrit, S_IWUSR | S_IRUGO, max16065_show_limit,
302 max16065_set_limit, 2, 11); 302 max16065_set_limit, 2, 11);
303 303
304 /* Input voltages crit */ 304 /* Input voltages crit */
305 static SENSOR_DEVICE_ATTR_2(in0_crit, S_IWUSR | S_IRUGO, max16065_show_limit, 305 static SENSOR_DEVICE_ATTR_2(in0_crit, S_IWUSR | S_IRUGO, max16065_show_limit,
306 max16065_set_limit, 1, 0); 306 max16065_set_limit, 1, 0);
307 static SENSOR_DEVICE_ATTR_2(in1_crit, S_IWUSR | S_IRUGO, max16065_show_limit, 307 static SENSOR_DEVICE_ATTR_2(in1_crit, S_IWUSR | S_IRUGO, max16065_show_limit,
308 max16065_set_limit, 1, 1); 308 max16065_set_limit, 1, 1);
309 static SENSOR_DEVICE_ATTR_2(in2_crit, S_IWUSR | S_IRUGO, max16065_show_limit, 309 static SENSOR_DEVICE_ATTR_2(in2_crit, S_IWUSR | S_IRUGO, max16065_show_limit,
310 max16065_set_limit, 1, 2); 310 max16065_set_limit, 1, 2);
311 static SENSOR_DEVICE_ATTR_2(in3_crit, S_IWUSR | S_IRUGO, max16065_show_limit, 311 static SENSOR_DEVICE_ATTR_2(in3_crit, S_IWUSR | S_IRUGO, max16065_show_limit,
312 max16065_set_limit, 1, 3); 312 max16065_set_limit, 1, 3);
313 static SENSOR_DEVICE_ATTR_2(in4_crit, S_IWUSR | S_IRUGO, max16065_show_limit, 313 static SENSOR_DEVICE_ATTR_2(in4_crit, S_IWUSR | S_IRUGO, max16065_show_limit,
314 max16065_set_limit, 1, 4); 314 max16065_set_limit, 1, 4);
315 static SENSOR_DEVICE_ATTR_2(in5_crit, S_IWUSR | S_IRUGO, max16065_show_limit, 315 static SENSOR_DEVICE_ATTR_2(in5_crit, S_IWUSR | S_IRUGO, max16065_show_limit,
316 max16065_set_limit, 1, 5); 316 max16065_set_limit, 1, 5);
317 static SENSOR_DEVICE_ATTR_2(in6_crit, S_IWUSR | S_IRUGO, max16065_show_limit, 317 static SENSOR_DEVICE_ATTR_2(in6_crit, S_IWUSR | S_IRUGO, max16065_show_limit,
318 max16065_set_limit, 1, 6); 318 max16065_set_limit, 1, 6);
319 static SENSOR_DEVICE_ATTR_2(in7_crit, S_IWUSR | S_IRUGO, max16065_show_limit, 319 static SENSOR_DEVICE_ATTR_2(in7_crit, S_IWUSR | S_IRUGO, max16065_show_limit,
320 max16065_set_limit, 1, 7); 320 max16065_set_limit, 1, 7);
321 static SENSOR_DEVICE_ATTR_2(in8_crit, S_IWUSR | S_IRUGO, max16065_show_limit, 321 static SENSOR_DEVICE_ATTR_2(in8_crit, S_IWUSR | S_IRUGO, max16065_show_limit,
322 max16065_set_limit, 1, 8); 322 max16065_set_limit, 1, 8);
323 static SENSOR_DEVICE_ATTR_2(in9_crit, S_IWUSR | S_IRUGO, max16065_show_limit, 323 static SENSOR_DEVICE_ATTR_2(in9_crit, S_IWUSR | S_IRUGO, max16065_show_limit,
324 max16065_set_limit, 1, 9); 324 max16065_set_limit, 1, 9);
325 static SENSOR_DEVICE_ATTR_2(in10_crit, S_IWUSR | S_IRUGO, max16065_show_limit, 325 static SENSOR_DEVICE_ATTR_2(in10_crit, S_IWUSR | S_IRUGO, max16065_show_limit,
326 max16065_set_limit, 1, 10); 326 max16065_set_limit, 1, 10);
327 static SENSOR_DEVICE_ATTR_2(in11_crit, S_IWUSR | S_IRUGO, max16065_show_limit, 327 static SENSOR_DEVICE_ATTR_2(in11_crit, S_IWUSR | S_IRUGO, max16065_show_limit,
328 max16065_set_limit, 1, 11); 328 max16065_set_limit, 1, 11);
329 329
330 /* Input voltages min */ 330 /* Input voltages min */
331 static SENSOR_DEVICE_ATTR_2(in0_min, S_IWUSR | S_IRUGO, max16065_show_limit, 331 static SENSOR_DEVICE_ATTR_2(in0_min, S_IWUSR | S_IRUGO, max16065_show_limit,
332 max16065_set_limit, 0, 0); 332 max16065_set_limit, 0, 0);
333 static SENSOR_DEVICE_ATTR_2(in1_min, S_IWUSR | S_IRUGO, max16065_show_limit, 333 static SENSOR_DEVICE_ATTR_2(in1_min, S_IWUSR | S_IRUGO, max16065_show_limit,
334 max16065_set_limit, 0, 1); 334 max16065_set_limit, 0, 1);
335 static SENSOR_DEVICE_ATTR_2(in2_min, S_IWUSR | S_IRUGO, max16065_show_limit, 335 static SENSOR_DEVICE_ATTR_2(in2_min, S_IWUSR | S_IRUGO, max16065_show_limit,
336 max16065_set_limit, 0, 2); 336 max16065_set_limit, 0, 2);
337 static SENSOR_DEVICE_ATTR_2(in3_min, S_IWUSR | S_IRUGO, max16065_show_limit, 337 static SENSOR_DEVICE_ATTR_2(in3_min, S_IWUSR | S_IRUGO, max16065_show_limit,
338 max16065_set_limit, 0, 3); 338 max16065_set_limit, 0, 3);
339 static SENSOR_DEVICE_ATTR_2(in4_min, S_IWUSR | S_IRUGO, max16065_show_limit, 339 static SENSOR_DEVICE_ATTR_2(in4_min, S_IWUSR | S_IRUGO, max16065_show_limit,
340 max16065_set_limit, 0, 4); 340 max16065_set_limit, 0, 4);
341 static SENSOR_DEVICE_ATTR_2(in5_min, S_IWUSR | S_IRUGO, max16065_show_limit, 341 static SENSOR_DEVICE_ATTR_2(in5_min, S_IWUSR | S_IRUGO, max16065_show_limit,
342 max16065_set_limit, 0, 5); 342 max16065_set_limit, 0, 5);
343 static SENSOR_DEVICE_ATTR_2(in6_min, S_IWUSR | S_IRUGO, max16065_show_limit, 343 static SENSOR_DEVICE_ATTR_2(in6_min, S_IWUSR | S_IRUGO, max16065_show_limit,
344 max16065_set_limit, 0, 6); 344 max16065_set_limit, 0, 6);
345 static SENSOR_DEVICE_ATTR_2(in7_min, S_IWUSR | S_IRUGO, max16065_show_limit, 345 static SENSOR_DEVICE_ATTR_2(in7_min, S_IWUSR | S_IRUGO, max16065_show_limit,
346 max16065_set_limit, 0, 7); 346 max16065_set_limit, 0, 7);
347 static SENSOR_DEVICE_ATTR_2(in8_min, S_IWUSR | S_IRUGO, max16065_show_limit, 347 static SENSOR_DEVICE_ATTR_2(in8_min, S_IWUSR | S_IRUGO, max16065_show_limit,
348 max16065_set_limit, 0, 8); 348 max16065_set_limit, 0, 8);
349 static SENSOR_DEVICE_ATTR_2(in9_min, S_IWUSR | S_IRUGO, max16065_show_limit, 349 static SENSOR_DEVICE_ATTR_2(in9_min, S_IWUSR | S_IRUGO, max16065_show_limit,
350 max16065_set_limit, 0, 9); 350 max16065_set_limit, 0, 9);
351 static SENSOR_DEVICE_ATTR_2(in10_min, S_IWUSR | S_IRUGO, max16065_show_limit, 351 static SENSOR_DEVICE_ATTR_2(in10_min, S_IWUSR | S_IRUGO, max16065_show_limit,
352 max16065_set_limit, 0, 10); 352 max16065_set_limit, 0, 10);
353 static SENSOR_DEVICE_ATTR_2(in11_min, S_IWUSR | S_IRUGO, max16065_show_limit, 353 static SENSOR_DEVICE_ATTR_2(in11_min, S_IWUSR | S_IRUGO, max16065_show_limit,
354 max16065_set_limit, 0, 11); 354 max16065_set_limit, 0, 11);
355 355
356 /* Input voltages max */ 356 /* Input voltages max */
357 static SENSOR_DEVICE_ATTR_2(in0_max, S_IWUSR | S_IRUGO, max16065_show_limit, 357 static SENSOR_DEVICE_ATTR_2(in0_max, S_IWUSR | S_IRUGO, max16065_show_limit,
358 max16065_set_limit, 0, 0); 358 max16065_set_limit, 0, 0);
359 static SENSOR_DEVICE_ATTR_2(in1_max, S_IWUSR | S_IRUGO, max16065_show_limit, 359 static SENSOR_DEVICE_ATTR_2(in1_max, S_IWUSR | S_IRUGO, max16065_show_limit,
360 max16065_set_limit, 0, 1); 360 max16065_set_limit, 0, 1);
361 static SENSOR_DEVICE_ATTR_2(in2_max, S_IWUSR | S_IRUGO, max16065_show_limit, 361 static SENSOR_DEVICE_ATTR_2(in2_max, S_IWUSR | S_IRUGO, max16065_show_limit,
362 max16065_set_limit, 0, 2); 362 max16065_set_limit, 0, 2);
363 static SENSOR_DEVICE_ATTR_2(in3_max, S_IWUSR | S_IRUGO, max16065_show_limit, 363 static SENSOR_DEVICE_ATTR_2(in3_max, S_IWUSR | S_IRUGO, max16065_show_limit,
364 max16065_set_limit, 0, 3); 364 max16065_set_limit, 0, 3);
365 static SENSOR_DEVICE_ATTR_2(in4_max, S_IWUSR | S_IRUGO, max16065_show_limit, 365 static SENSOR_DEVICE_ATTR_2(in4_max, S_IWUSR | S_IRUGO, max16065_show_limit,
366 max16065_set_limit, 0, 4); 366 max16065_set_limit, 0, 4);
367 static SENSOR_DEVICE_ATTR_2(in5_max, S_IWUSR | S_IRUGO, max16065_show_limit, 367 static SENSOR_DEVICE_ATTR_2(in5_max, S_IWUSR | S_IRUGO, max16065_show_limit,
368 max16065_set_limit, 0, 5); 368 max16065_set_limit, 0, 5);
369 static SENSOR_DEVICE_ATTR_2(in6_max, S_IWUSR | S_IRUGO, max16065_show_limit, 369 static SENSOR_DEVICE_ATTR_2(in6_max, S_IWUSR | S_IRUGO, max16065_show_limit,
370 max16065_set_limit, 0, 6); 370 max16065_set_limit, 0, 6);
371 static SENSOR_DEVICE_ATTR_2(in7_max, S_IWUSR | S_IRUGO, max16065_show_limit, 371 static SENSOR_DEVICE_ATTR_2(in7_max, S_IWUSR | S_IRUGO, max16065_show_limit,
372 max16065_set_limit, 0, 7); 372 max16065_set_limit, 0, 7);
373 static SENSOR_DEVICE_ATTR_2(in8_max, S_IWUSR | S_IRUGO, max16065_show_limit, 373 static SENSOR_DEVICE_ATTR_2(in8_max, S_IWUSR | S_IRUGO, max16065_show_limit,
374 max16065_set_limit, 0, 8); 374 max16065_set_limit, 0, 8);
375 static SENSOR_DEVICE_ATTR_2(in9_max, S_IWUSR | S_IRUGO, max16065_show_limit, 375 static SENSOR_DEVICE_ATTR_2(in9_max, S_IWUSR | S_IRUGO, max16065_show_limit,
376 max16065_set_limit, 0, 9); 376 max16065_set_limit, 0, 9);
377 static SENSOR_DEVICE_ATTR_2(in10_max, S_IWUSR | S_IRUGO, max16065_show_limit, 377 static SENSOR_DEVICE_ATTR_2(in10_max, S_IWUSR | S_IRUGO, max16065_show_limit,
378 max16065_set_limit, 0, 10); 378 max16065_set_limit, 0, 10);
379 static SENSOR_DEVICE_ATTR_2(in11_max, S_IWUSR | S_IRUGO, max16065_show_limit, 379 static SENSOR_DEVICE_ATTR_2(in11_max, S_IWUSR | S_IRUGO, max16065_show_limit,
380 max16065_set_limit, 0, 11); 380 max16065_set_limit, 0, 11);
381 381
382 /* alarms */ 382 /* alarms */
383 static SENSOR_DEVICE_ATTR_2(in0_alarm, S_IRUGO, max16065_show_alarm, NULL, 383 static SENSOR_DEVICE_ATTR_2(in0_alarm, S_IRUGO, max16065_show_alarm, NULL,
384 0, 0); 384 0, 0);
385 static SENSOR_DEVICE_ATTR_2(in1_alarm, S_IRUGO, max16065_show_alarm, NULL, 385 static SENSOR_DEVICE_ATTR_2(in1_alarm, S_IRUGO, max16065_show_alarm, NULL,
386 0, 1); 386 0, 1);
387 static SENSOR_DEVICE_ATTR_2(in2_alarm, S_IRUGO, max16065_show_alarm, NULL, 387 static SENSOR_DEVICE_ATTR_2(in2_alarm, S_IRUGO, max16065_show_alarm, NULL,
388 0, 2); 388 0, 2);
389 static SENSOR_DEVICE_ATTR_2(in3_alarm, S_IRUGO, max16065_show_alarm, NULL, 389 static SENSOR_DEVICE_ATTR_2(in3_alarm, S_IRUGO, max16065_show_alarm, NULL,
390 0, 3); 390 0, 3);
391 static SENSOR_DEVICE_ATTR_2(in4_alarm, S_IRUGO, max16065_show_alarm, NULL, 391 static SENSOR_DEVICE_ATTR_2(in4_alarm, S_IRUGO, max16065_show_alarm, NULL,
392 0, 4); 392 0, 4);
393 static SENSOR_DEVICE_ATTR_2(in5_alarm, S_IRUGO, max16065_show_alarm, NULL, 393 static SENSOR_DEVICE_ATTR_2(in5_alarm, S_IRUGO, max16065_show_alarm, NULL,
394 0, 5); 394 0, 5);
395 static SENSOR_DEVICE_ATTR_2(in6_alarm, S_IRUGO, max16065_show_alarm, NULL, 395 static SENSOR_DEVICE_ATTR_2(in6_alarm, S_IRUGO, max16065_show_alarm, NULL,
396 0, 6); 396 0, 6);
397 static SENSOR_DEVICE_ATTR_2(in7_alarm, S_IRUGO, max16065_show_alarm, NULL, 397 static SENSOR_DEVICE_ATTR_2(in7_alarm, S_IRUGO, max16065_show_alarm, NULL,
398 0, 7); 398 0, 7);
399 static SENSOR_DEVICE_ATTR_2(in8_alarm, S_IRUGO, max16065_show_alarm, NULL, 399 static SENSOR_DEVICE_ATTR_2(in8_alarm, S_IRUGO, max16065_show_alarm, NULL,
400 1, 0); 400 1, 0);
401 static SENSOR_DEVICE_ATTR_2(in9_alarm, S_IRUGO, max16065_show_alarm, NULL, 401 static SENSOR_DEVICE_ATTR_2(in9_alarm, S_IRUGO, max16065_show_alarm, NULL,
402 1, 1); 402 1, 1);
403 static SENSOR_DEVICE_ATTR_2(in10_alarm, S_IRUGO, max16065_show_alarm, NULL, 403 static SENSOR_DEVICE_ATTR_2(in10_alarm, S_IRUGO, max16065_show_alarm, NULL,
404 1, 2); 404 1, 2);
405 static SENSOR_DEVICE_ATTR_2(in11_alarm, S_IRUGO, max16065_show_alarm, NULL, 405 static SENSOR_DEVICE_ATTR_2(in11_alarm, S_IRUGO, max16065_show_alarm, NULL,
406 1, 3); 406 1, 3);
407 407
408 /* Current and alarm */ 408 /* Current and alarm */
409 static SENSOR_DEVICE_ATTR(curr1_input, S_IRUGO, max16065_show_current, NULL, 0); 409 static SENSOR_DEVICE_ATTR(curr1_input, S_IRUGO, max16065_show_current, NULL, 0);
410 static SENSOR_DEVICE_ATTR_2(curr1_alarm, S_IRUGO, max16065_show_alarm, NULL, 410 static SENSOR_DEVICE_ATTR_2(curr1_alarm, S_IRUGO, max16065_show_alarm, NULL,
411 1, 4); 411 1, 4);
412 412
413 /* 413 /*
414 * Finally, construct an array of pointers to members of the above objects, 414 * Finally, construct an array of pointers to members of the above objects,
415 * as required for sysfs_create_group() 415 * as required for sysfs_create_group()
416 */ 416 */
417 static struct attribute *max16065_basic_attributes[] = { 417 static struct attribute *max16065_basic_attributes[] = {
418 &sensor_dev_attr_in0_input.dev_attr.attr, 418 &sensor_dev_attr_in0_input.dev_attr.attr,
419 &sensor_dev_attr_in0_lcrit.dev_attr.attr, 419 &sensor_dev_attr_in0_lcrit.dev_attr.attr,
420 &sensor_dev_attr_in0_crit.dev_attr.attr, 420 &sensor_dev_attr_in0_crit.dev_attr.attr,
421 &sensor_dev_attr_in0_alarm.dev_attr.attr, 421 &sensor_dev_attr_in0_alarm.dev_attr.attr,
422 422
423 &sensor_dev_attr_in1_input.dev_attr.attr, 423 &sensor_dev_attr_in1_input.dev_attr.attr,
424 &sensor_dev_attr_in1_lcrit.dev_attr.attr, 424 &sensor_dev_attr_in1_lcrit.dev_attr.attr,
425 &sensor_dev_attr_in1_crit.dev_attr.attr, 425 &sensor_dev_attr_in1_crit.dev_attr.attr,
426 &sensor_dev_attr_in1_alarm.dev_attr.attr, 426 &sensor_dev_attr_in1_alarm.dev_attr.attr,
427 427
428 &sensor_dev_attr_in2_input.dev_attr.attr, 428 &sensor_dev_attr_in2_input.dev_attr.attr,
429 &sensor_dev_attr_in2_lcrit.dev_attr.attr, 429 &sensor_dev_attr_in2_lcrit.dev_attr.attr,
430 &sensor_dev_attr_in2_crit.dev_attr.attr, 430 &sensor_dev_attr_in2_crit.dev_attr.attr,
431 &sensor_dev_attr_in2_alarm.dev_attr.attr, 431 &sensor_dev_attr_in2_alarm.dev_attr.attr,
432 432
433 &sensor_dev_attr_in3_input.dev_attr.attr, 433 &sensor_dev_attr_in3_input.dev_attr.attr,
434 &sensor_dev_attr_in3_lcrit.dev_attr.attr, 434 &sensor_dev_attr_in3_lcrit.dev_attr.attr,
435 &sensor_dev_attr_in3_crit.dev_attr.attr, 435 &sensor_dev_attr_in3_crit.dev_attr.attr,
436 &sensor_dev_attr_in3_alarm.dev_attr.attr, 436 &sensor_dev_attr_in3_alarm.dev_attr.attr,
437 437
438 &sensor_dev_attr_in4_input.dev_attr.attr, 438 &sensor_dev_attr_in4_input.dev_attr.attr,
439 &sensor_dev_attr_in4_lcrit.dev_attr.attr, 439 &sensor_dev_attr_in4_lcrit.dev_attr.attr,
440 &sensor_dev_attr_in4_crit.dev_attr.attr, 440 &sensor_dev_attr_in4_crit.dev_attr.attr,
441 &sensor_dev_attr_in4_alarm.dev_attr.attr, 441 &sensor_dev_attr_in4_alarm.dev_attr.attr,
442 442
443 &sensor_dev_attr_in5_input.dev_attr.attr, 443 &sensor_dev_attr_in5_input.dev_attr.attr,
444 &sensor_dev_attr_in5_lcrit.dev_attr.attr, 444 &sensor_dev_attr_in5_lcrit.dev_attr.attr,
445 &sensor_dev_attr_in5_crit.dev_attr.attr, 445 &sensor_dev_attr_in5_crit.dev_attr.attr,
446 &sensor_dev_attr_in5_alarm.dev_attr.attr, 446 &sensor_dev_attr_in5_alarm.dev_attr.attr,
447 447
448 &sensor_dev_attr_in6_input.dev_attr.attr, 448 &sensor_dev_attr_in6_input.dev_attr.attr,
449 &sensor_dev_attr_in6_lcrit.dev_attr.attr, 449 &sensor_dev_attr_in6_lcrit.dev_attr.attr,
450 &sensor_dev_attr_in6_crit.dev_attr.attr, 450 &sensor_dev_attr_in6_crit.dev_attr.attr,
451 &sensor_dev_attr_in6_alarm.dev_attr.attr, 451 &sensor_dev_attr_in6_alarm.dev_attr.attr,
452 452
453 &sensor_dev_attr_in7_input.dev_attr.attr, 453 &sensor_dev_attr_in7_input.dev_attr.attr,
454 &sensor_dev_attr_in7_lcrit.dev_attr.attr, 454 &sensor_dev_attr_in7_lcrit.dev_attr.attr,
455 &sensor_dev_attr_in7_crit.dev_attr.attr, 455 &sensor_dev_attr_in7_crit.dev_attr.attr,
456 &sensor_dev_attr_in7_alarm.dev_attr.attr, 456 &sensor_dev_attr_in7_alarm.dev_attr.attr,
457 457
458 &sensor_dev_attr_in8_input.dev_attr.attr, 458 &sensor_dev_attr_in8_input.dev_attr.attr,
459 &sensor_dev_attr_in8_lcrit.dev_attr.attr, 459 &sensor_dev_attr_in8_lcrit.dev_attr.attr,
460 &sensor_dev_attr_in8_crit.dev_attr.attr, 460 &sensor_dev_attr_in8_crit.dev_attr.attr,
461 &sensor_dev_attr_in8_alarm.dev_attr.attr, 461 &sensor_dev_attr_in8_alarm.dev_attr.attr,
462 462
463 &sensor_dev_attr_in9_input.dev_attr.attr, 463 &sensor_dev_attr_in9_input.dev_attr.attr,
464 &sensor_dev_attr_in9_lcrit.dev_attr.attr, 464 &sensor_dev_attr_in9_lcrit.dev_attr.attr,
465 &sensor_dev_attr_in9_crit.dev_attr.attr, 465 &sensor_dev_attr_in9_crit.dev_attr.attr,
466 &sensor_dev_attr_in9_alarm.dev_attr.attr, 466 &sensor_dev_attr_in9_alarm.dev_attr.attr,
467 467
468 &sensor_dev_attr_in10_input.dev_attr.attr, 468 &sensor_dev_attr_in10_input.dev_attr.attr,
469 &sensor_dev_attr_in10_lcrit.dev_attr.attr, 469 &sensor_dev_attr_in10_lcrit.dev_attr.attr,
470 &sensor_dev_attr_in10_crit.dev_attr.attr, 470 &sensor_dev_attr_in10_crit.dev_attr.attr,
471 &sensor_dev_attr_in10_alarm.dev_attr.attr, 471 &sensor_dev_attr_in10_alarm.dev_attr.attr,
472 472
473 &sensor_dev_attr_in11_input.dev_attr.attr, 473 &sensor_dev_attr_in11_input.dev_attr.attr,
474 &sensor_dev_attr_in11_lcrit.dev_attr.attr, 474 &sensor_dev_attr_in11_lcrit.dev_attr.attr,
475 &sensor_dev_attr_in11_crit.dev_attr.attr, 475 &sensor_dev_attr_in11_crit.dev_attr.attr,
476 &sensor_dev_attr_in11_alarm.dev_attr.attr, 476 &sensor_dev_attr_in11_alarm.dev_attr.attr,
477 477
478 NULL 478 NULL
479 }; 479 };
480 480
481 static struct attribute *max16065_current_attributes[] = { 481 static struct attribute *max16065_current_attributes[] = {
482 &sensor_dev_attr_in12_input.dev_attr.attr, 482 &sensor_dev_attr_in12_input.dev_attr.attr,
483 &sensor_dev_attr_curr1_input.dev_attr.attr, 483 &sensor_dev_attr_curr1_input.dev_attr.attr,
484 &sensor_dev_attr_curr1_alarm.dev_attr.attr, 484 &sensor_dev_attr_curr1_alarm.dev_attr.attr,
485 NULL 485 NULL
486 }; 486 };
487 487
488 static struct attribute *max16065_min_attributes[] = { 488 static struct attribute *max16065_min_attributes[] = {
489 &sensor_dev_attr_in0_min.dev_attr.attr, 489 &sensor_dev_attr_in0_min.dev_attr.attr,
490 &sensor_dev_attr_in1_min.dev_attr.attr, 490 &sensor_dev_attr_in1_min.dev_attr.attr,
491 &sensor_dev_attr_in2_min.dev_attr.attr, 491 &sensor_dev_attr_in2_min.dev_attr.attr,
492 &sensor_dev_attr_in3_min.dev_attr.attr, 492 &sensor_dev_attr_in3_min.dev_attr.attr,
493 &sensor_dev_attr_in4_min.dev_attr.attr, 493 &sensor_dev_attr_in4_min.dev_attr.attr,
494 &sensor_dev_attr_in5_min.dev_attr.attr, 494 &sensor_dev_attr_in5_min.dev_attr.attr,
495 &sensor_dev_attr_in6_min.dev_attr.attr, 495 &sensor_dev_attr_in6_min.dev_attr.attr,
496 &sensor_dev_attr_in7_min.dev_attr.attr, 496 &sensor_dev_attr_in7_min.dev_attr.attr,
497 &sensor_dev_attr_in8_min.dev_attr.attr, 497 &sensor_dev_attr_in8_min.dev_attr.attr,
498 &sensor_dev_attr_in9_min.dev_attr.attr, 498 &sensor_dev_attr_in9_min.dev_attr.attr,
499 &sensor_dev_attr_in10_min.dev_attr.attr, 499 &sensor_dev_attr_in10_min.dev_attr.attr,
500 &sensor_dev_attr_in11_min.dev_attr.attr, 500 &sensor_dev_attr_in11_min.dev_attr.attr,
501 NULL 501 NULL
502 }; 502 };
503 503
504 static struct attribute *max16065_max_attributes[] = { 504 static struct attribute *max16065_max_attributes[] = {
505 &sensor_dev_attr_in0_max.dev_attr.attr, 505 &sensor_dev_attr_in0_max.dev_attr.attr,
506 &sensor_dev_attr_in1_max.dev_attr.attr, 506 &sensor_dev_attr_in1_max.dev_attr.attr,
507 &sensor_dev_attr_in2_max.dev_attr.attr, 507 &sensor_dev_attr_in2_max.dev_attr.attr,
508 &sensor_dev_attr_in3_max.dev_attr.attr, 508 &sensor_dev_attr_in3_max.dev_attr.attr,
509 &sensor_dev_attr_in4_max.dev_attr.attr, 509 &sensor_dev_attr_in4_max.dev_attr.attr,
510 &sensor_dev_attr_in5_max.dev_attr.attr, 510 &sensor_dev_attr_in5_max.dev_attr.attr,
511 &sensor_dev_attr_in6_max.dev_attr.attr, 511 &sensor_dev_attr_in6_max.dev_attr.attr,
512 &sensor_dev_attr_in7_max.dev_attr.attr, 512 &sensor_dev_attr_in7_max.dev_attr.attr,
513 &sensor_dev_attr_in8_max.dev_attr.attr, 513 &sensor_dev_attr_in8_max.dev_attr.attr,
514 &sensor_dev_attr_in9_max.dev_attr.attr, 514 &sensor_dev_attr_in9_max.dev_attr.attr,
515 &sensor_dev_attr_in10_max.dev_attr.attr, 515 &sensor_dev_attr_in10_max.dev_attr.attr,
516 &sensor_dev_attr_in11_max.dev_attr.attr, 516 &sensor_dev_attr_in11_max.dev_attr.attr,
517 NULL 517 NULL
518 }; 518 };
519 519
520 static const struct attribute_group max16065_basic_group = { 520 static const struct attribute_group max16065_basic_group = {
521 .attrs = max16065_basic_attributes, 521 .attrs = max16065_basic_attributes,
522 }; 522 };
523 523
524 static const struct attribute_group max16065_current_group = { 524 static const struct attribute_group max16065_current_group = {
525 .attrs = max16065_current_attributes, 525 .attrs = max16065_current_attributes,
526 }; 526 };
527 527
528 static const struct attribute_group max16065_min_group = { 528 static const struct attribute_group max16065_min_group = {
529 .attrs = max16065_min_attributes, 529 .attrs = max16065_min_attributes,
530 }; 530 };
531 531
532 static const struct attribute_group max16065_max_group = { 532 static const struct attribute_group max16065_max_group = {
533 .attrs = max16065_max_attributes, 533 .attrs = max16065_max_attributes,
534 }; 534 };
535 535
536 static void max16065_cleanup(struct i2c_client *client) 536 static void max16065_cleanup(struct i2c_client *client)
537 { 537 {
538 sysfs_remove_group(&client->dev.kobj, &max16065_max_group); 538 sysfs_remove_group(&client->dev.kobj, &max16065_max_group);
539 sysfs_remove_group(&client->dev.kobj, &max16065_min_group); 539 sysfs_remove_group(&client->dev.kobj, &max16065_min_group);
540 sysfs_remove_group(&client->dev.kobj, &max16065_current_group); 540 sysfs_remove_group(&client->dev.kobj, &max16065_current_group);
541 sysfs_remove_group(&client->dev.kobj, &max16065_basic_group); 541 sysfs_remove_group(&client->dev.kobj, &max16065_basic_group);
542 } 542 }
543 543
544 static int max16065_probe(struct i2c_client *client, 544 static int max16065_probe(struct i2c_client *client,
545 const struct i2c_device_id *id) 545 const struct i2c_device_id *id)
546 { 546 {
547 struct i2c_adapter *adapter = client->adapter; 547 struct i2c_adapter *adapter = client->adapter;
548 struct max16065_data *data; 548 struct max16065_data *data;
549 int i, j, val, ret; 549 int i, j, val, ret;
550 bool have_secondary; /* true if chip has secondary limits */ 550 bool have_secondary; /* true if chip has secondary limits */
551 bool secondary_is_max = false; /* secondary limits reflect max */ 551 bool secondary_is_max = false; /* secondary limits reflect max */
552 552
553 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA 553 if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA
554 | I2C_FUNC_SMBUS_READ_WORD_DATA)) 554 | I2C_FUNC_SMBUS_READ_WORD_DATA))
555 return -ENODEV; 555 return -ENODEV;
556 556
557 data = kzalloc(sizeof(*data), GFP_KERNEL); 557 data = kzalloc(sizeof(*data), GFP_KERNEL);
558 if (unlikely(!data)) 558 if (unlikely(!data))
559 return -ENOMEM; 559 return -ENOMEM;
560 560
561 i2c_set_clientdata(client, data); 561 i2c_set_clientdata(client, data);
562 mutex_init(&data->update_lock); 562 mutex_init(&data->update_lock);
563 563
564 data->num_adc = max16065_num_adc[id->driver_data]; 564 data->num_adc = max16065_num_adc[id->driver_data];
565 data->have_current = max16065_have_current[id->driver_data]; 565 data->have_current = max16065_have_current[id->driver_data];
566 have_secondary = max16065_have_secondary[id->driver_data]; 566 have_secondary = max16065_have_secondary[id->driver_data];
567 567
568 if (have_secondary) { 568 if (have_secondary) {
569 val = i2c_smbus_read_byte_data(client, MAX16065_SW_ENABLE); 569 val = i2c_smbus_read_byte_data(client, MAX16065_SW_ENABLE);
570 if (unlikely(val < 0)) { 570 if (unlikely(val < 0)) {
571 ret = val; 571 ret = val;
572 goto out_free; 572 goto out_free;
573 } 573 }
574 secondary_is_max = val & MAX16065_WARNING_OV; 574 secondary_is_max = val & MAX16065_WARNING_OV;
575 } 575 }
576 576
577 /* Read scale registers, convert to range */ 577 /* Read scale registers, convert to range */
578 for (i = 0; i < DIV_ROUND_UP(data->num_adc, 4); i++) { 578 for (i = 0; i < DIV_ROUND_UP(data->num_adc, 4); i++) {
579 val = i2c_smbus_read_byte_data(client, MAX16065_SCALE(i)); 579 val = i2c_smbus_read_byte_data(client, MAX16065_SCALE(i));
580 if (unlikely(val < 0)) { 580 if (unlikely(val < 0)) {
581 ret = val; 581 ret = val;
582 goto out_free; 582 goto out_free;
583 } 583 }
584 for (j = 0; j < 4 && i * 4 + j < data->num_adc; j++) { 584 for (j = 0; j < 4 && i * 4 + j < data->num_adc; j++) {
585 data->range[i * 4 + j] = 585 data->range[i * 4 + j] =
586 max16065_adc_range[(val >> (j * 2)) & 0x3]; 586 max16065_adc_range[(val >> (j * 2)) & 0x3];
587 } 587 }
588 } 588 }
589 589
590 /* Read limits */ 590 /* Read limits */
591 for (i = 0; i < MAX16065_NUM_LIMIT; i++) { 591 for (i = 0; i < MAX16065_NUM_LIMIT; i++) {
592 if (i == 0 && !have_secondary) 592 if (i == 0 && !have_secondary)
593 continue; 593 continue;
594 594
595 for (j = 0; j < data->num_adc; j++) { 595 for (j = 0; j < data->num_adc; j++) {
596 val = i2c_smbus_read_byte_data(client, 596 val = i2c_smbus_read_byte_data(client,
597 MAX16065_LIMIT(i, j)); 597 MAX16065_LIMIT(i, j));
598 if (unlikely(val < 0)) { 598 if (unlikely(val < 0)) {
599 ret = val; 599 ret = val;
600 goto out_free; 600 goto out_free;
601 } 601 }
602 data->limit[i][j] = LIMIT_TO_MV(val, data->range[j]); 602 data->limit[i][j] = LIMIT_TO_MV(val, data->range[j]);
603 } 603 }
604 } 604 }
605 605
606 /* Register sysfs hooks */ 606 /* Register sysfs hooks */
607 for (i = 0; i < data->num_adc * 4; i++) { 607 for (i = 0; i < data->num_adc * 4; i++) {
608 /* Do not create sysfs entry if channel is disabled */ 608 /* Do not create sysfs entry if channel is disabled */
609 if (!data->range[i / 4]) 609 if (!data->range[i / 4])
610 continue; 610 continue;
611 611
612 ret = sysfs_create_file(&client->dev.kobj, 612 ret = sysfs_create_file(&client->dev.kobj,
613 max16065_basic_attributes[i]); 613 max16065_basic_attributes[i]);
614 if (unlikely(ret)) 614 if (unlikely(ret))
615 goto out; 615 goto out;
616 } 616 }
617 617
618 if (have_secondary) { 618 if (have_secondary) {
619 struct attribute **attr = secondary_is_max ? 619 struct attribute **attr = secondary_is_max ?
620 max16065_max_attributes : max16065_min_attributes; 620 max16065_max_attributes : max16065_min_attributes;
621 621
622 for (i = 0; i < data->num_adc; i++) { 622 for (i = 0; i < data->num_adc; i++) {
623 if (!data->range[i]) 623 if (!data->range[i])
624 continue; 624 continue;
625 625
626 ret = sysfs_create_file(&client->dev.kobj, attr[i]); 626 ret = sysfs_create_file(&client->dev.kobj, attr[i]);
627 if (unlikely(ret)) 627 if (unlikely(ret))
628 goto out; 628 goto out;
629 } 629 }
630 } 630 }
631 631
632 if (data->have_current) { 632 if (data->have_current) {
633 val = i2c_smbus_read_byte_data(client, MAX16065_CURR_CONTROL); 633 val = i2c_smbus_read_byte_data(client, MAX16065_CURR_CONTROL);
634 if (unlikely(val < 0)) { 634 if (unlikely(val < 0)) {
635 ret = val; 635 ret = val;
636 goto out; 636 goto out;
637 } 637 }
638 if (val & MAX16065_CURR_ENABLE) { 638 if (val & MAX16065_CURR_ENABLE) {
639 /* 639 /*
640 * Current gain is 6, 12, 24, 48 based on values in 640 * Current gain is 6, 12, 24, 48 based on values in
641 * bit 2,3. 641 * bit 2,3.
642 */ 642 */
643 data->curr_gain = 6 << ((val >> 2) & 0x03); 643 data->curr_gain = 6 << ((val >> 2) & 0x03);
644 data->range[MAX16065_NUM_ADC] 644 data->range[MAX16065_NUM_ADC]
645 = max16065_csp_adc_range[(val >> 1) & 0x01]; 645 = max16065_csp_adc_range[(val >> 1) & 0x01];
646 ret = sysfs_create_group(&client->dev.kobj, 646 ret = sysfs_create_group(&client->dev.kobj,
647 &max16065_current_group); 647 &max16065_current_group);
648 if (unlikely(ret)) 648 if (unlikely(ret))
649 goto out; 649 goto out;
650 } else { 650 } else {
651 data->have_current = false; 651 data->have_current = false;
652 } 652 }
653 } 653 }
654 654
655 data->hwmon_dev = hwmon_device_register(&client->dev); 655 data->hwmon_dev = hwmon_device_register(&client->dev);
656 if (unlikely(IS_ERR(data->hwmon_dev))) { 656 if (unlikely(IS_ERR(data->hwmon_dev))) {
657 ret = PTR_ERR(data->hwmon_dev); 657 ret = PTR_ERR(data->hwmon_dev);
658 goto out; 658 goto out;
659 } 659 }
660 return 0; 660 return 0;
661 661
662 out: 662 out:
663 max16065_cleanup(client); 663 max16065_cleanup(client);
664 out_free: 664 out_free:
665 kfree(data); 665 kfree(data);
666 return ret; 666 return ret;
667 } 667 }
668 668
669 static int max16065_remove(struct i2c_client *client) 669 static int max16065_remove(struct i2c_client *client)
670 { 670 {
671 struct max16065_data *data = i2c_get_clientdata(client); 671 struct max16065_data *data = i2c_get_clientdata(client);
672 672
673 hwmon_device_unregister(data->hwmon_dev); 673 hwmon_device_unregister(data->hwmon_dev);
674 max16065_cleanup(client); 674 max16065_cleanup(client);
675 kfree(data); 675 kfree(data);
676 676
677 return 0; 677 return 0;
678 } 678 }
679 679
680 static const struct i2c_device_id max16065_id[] = { 680 static const struct i2c_device_id max16065_id[] = {
681 { "max16065", max16065 }, 681 { "max16065", max16065 },
682 { "max16066", max16066 }, 682 { "max16066", max16066 },
683 { "max16067", max16067 }, 683 { "max16067", max16067 },
684 { "max16068", max16068 }, 684 { "max16068", max16068 },
685 { "max16070", max16070 }, 685 { "max16070", max16070 },
686 { "max16071", max16071 }, 686 { "max16071", max16071 },
687 { } 687 { }
688 }; 688 };
689 689
690 MODULE_DEVICE_TABLE(i2c, max16065_id); 690 MODULE_DEVICE_TABLE(i2c, max16065_id);
691 691
692 /* This is the driver that will be inserted */ 692 /* This is the driver that will be inserted */
693 static struct i2c_driver max16065_driver = { 693 static struct i2c_driver max16065_driver = {
694 .driver = { 694 .driver = {
695 .name = "max16065", 695 .name = "max16065",
696 }, 696 },
697 .probe = max16065_probe, 697 .probe = max16065_probe,
698 .remove = max16065_remove, 698 .remove = max16065_remove,
699 .id_table = max16065_id, 699 .id_table = max16065_id,
700 }; 700 };
701 701
702 static int __init max16065_init(void) 702 static int __init max16065_init(void)
703 { 703 {
704 return i2c_add_driver(&max16065_driver); 704 return i2c_add_driver(&max16065_driver);
705 } 705 }
706 706
707 static void __exit max16065_exit(void) 707 static void __exit max16065_exit(void)
708 { 708 {
709 i2c_del_driver(&max16065_driver); 709 i2c_del_driver(&max16065_driver);
710 } 710 }
711 711
712 MODULE_AUTHOR("Guenter Roeck <guenter.roeck@ericsson.com>"); 712 MODULE_AUTHOR("Guenter Roeck <guenter.roeck@ericsson.com>");
713 MODULE_DESCRIPTION("MAX16065 driver"); 713 MODULE_DESCRIPTION("MAX16065 driver");
714 MODULE_LICENSE("GPL"); 714 MODULE_LICENSE("GPL");
715 715
716 module_init(max16065_init); 716 module_init(max16065_init);
717 module_exit(max16065_exit); 717 module_exit(max16065_exit);
718 718