aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/adm1025.c
diff options
context:
space:
mode:
authorJean Delvare <khali@linux-fr.org>2007-10-10 15:11:01 -0400
committerMark M. Hoffman <mhoffman@lightlink.com>2008-02-07 20:39:41 -0500
commitd8543e7f30fe9306c8d5a16086bf75f71ab79acf (patch)
treea9fe72585338d37f03ee17675cb5f8f6fcc5623d /drivers/hwmon/adm1025.c
parentc7fa373796ea685874ca9525eeb3d0d0951e511b (diff)
hwmon: (adm1025) Use dynamic sysfs callbacks
This lets us get rid of macro-generated functions and shrinks the driver size by about 30%. Signed-off-by: Jean Delvare <khali@linux-fr.org> Signed-off-by: Mark M. Hoffman <mhoffman@lightlink.com>
Diffstat (limited to 'drivers/hwmon/adm1025.c')
-rw-r--r--drivers/hwmon/adm1025.c291
1 files changed, 154 insertions, 137 deletions
diff --git a/drivers/hwmon/adm1025.c b/drivers/hwmon/adm1025.c
index 041ecb0bdf48..f0d833eb1f47 100644
--- a/drivers/hwmon/adm1025.c
+++ b/drivers/hwmon/adm1025.c
@@ -51,6 +51,7 @@
51#include <linux/jiffies.h> 51#include <linux/jiffies.h>
52#include <linux/i2c.h> 52#include <linux/i2c.h>
53#include <linux/hwmon.h> 53#include <linux/hwmon.h>
54#include <linux/hwmon-sysfs.h>
54#include <linux/hwmon-vid.h> 55#include <linux/hwmon-vid.h>
55#include <linux/err.h> 56#include <linux/err.h>
56#include <linux/mutex.h> 57#include <linux/mutex.h>
@@ -153,86 +154,96 @@ struct adm1025_data {
153 * Sysfs stuff 154 * Sysfs stuff
154 */ 155 */
155 156
156#define show_in(offset) \ 157static ssize_t
157static ssize_t show_in##offset(struct device *dev, struct device_attribute *attr, char *buf) \ 158show_in(struct device *dev, struct device_attribute *attr, char *buf)
158{ \ 159{
159 struct adm1025_data *data = adm1025_update_device(dev); \ 160 int index = to_sensor_dev_attr(attr)->index;
160 return sprintf(buf, "%u\n", IN_FROM_REG(data->in[offset], \ 161 struct adm1025_data *data = adm1025_update_device(dev);
161 in_scale[offset])); \ 162 return sprintf(buf, "%u\n", IN_FROM_REG(data->in[index],
162} \ 163 in_scale[index]));
163static ssize_t show_in##offset##_min(struct device *dev, struct device_attribute *attr, char *buf) \ 164}
164{ \ 165
165 struct adm1025_data *data = adm1025_update_device(dev); \ 166static ssize_t
166 return sprintf(buf, "%u\n", IN_FROM_REG(data->in_min[offset], \ 167show_in_min(struct device *dev, struct device_attribute *attr, char *buf)
167 in_scale[offset])); \ 168{
168} \ 169 int index = to_sensor_dev_attr(attr)->index;
169static ssize_t show_in##offset##_max(struct device *dev, struct device_attribute *attr, char *buf) \ 170 struct adm1025_data *data = adm1025_update_device(dev);
170{ \ 171 return sprintf(buf, "%u\n", IN_FROM_REG(data->in_min[index],
171 struct adm1025_data *data = adm1025_update_device(dev); \ 172 in_scale[index]));
172 return sprintf(buf, "%u\n", IN_FROM_REG(data->in_max[offset], \ 173}
173 in_scale[offset])); \ 174
174} \ 175static ssize_t
175static DEVICE_ATTR(in##offset##_input, S_IRUGO, show_in##offset, NULL); 176show_in_max(struct device *dev, struct device_attribute *attr, char *buf)
176show_in(0); 177{
177show_in(1); 178 int index = to_sensor_dev_attr(attr)->index;
178show_in(2); 179 struct adm1025_data *data = adm1025_update_device(dev);
179show_in(3); 180 return sprintf(buf, "%u\n", IN_FROM_REG(data->in_max[index],
180show_in(4); 181 in_scale[index]));
181show_in(5); 182}
182 183
183#define show_temp(offset) \ 184static ssize_t
184static ssize_t show_temp##offset(struct device *dev, struct device_attribute *attr, char *buf) \ 185show_temp(struct device *dev, struct device_attribute *attr, char *buf)
185{ \ 186{
186 struct adm1025_data *data = adm1025_update_device(dev); \ 187 int index = to_sensor_dev_attr(attr)->index;
187 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[offset-1])); \ 188 struct adm1025_data *data = adm1025_update_device(dev);
188} \ 189 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[index]));
189static ssize_t show_temp##offset##_min(struct device *dev, struct device_attribute *attr, char *buf) \ 190}
190{ \ 191
191 struct adm1025_data *data = adm1025_update_device(dev); \ 192static ssize_t
192 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_min[offset-1])); \ 193show_temp_min(struct device *dev, struct device_attribute *attr, char *buf)
193} \ 194{
194static ssize_t show_temp##offset##_max(struct device *dev, struct device_attribute *attr, char *buf) \ 195 int index = to_sensor_dev_attr(attr)->index;
195{ \ 196 struct adm1025_data *data = adm1025_update_device(dev);
196 struct adm1025_data *data = adm1025_update_device(dev); \ 197 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_min[index]));
197 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[offset-1])); \ 198}
198}\ 199
199static DEVICE_ATTR(temp##offset##_input, S_IRUGO, show_temp##offset, NULL); 200static ssize_t
200show_temp(1); 201show_temp_max(struct device *dev, struct device_attribute *attr, char *buf)
201show_temp(2); 202{
203 int index = to_sensor_dev_attr(attr)->index;
204 struct adm1025_data *data = adm1025_update_device(dev);
205 return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[index]));
206}
207
208static ssize_t set_in_min(struct device *dev, struct device_attribute *attr,
209 const char *buf, size_t count)
210{
211 int index = to_sensor_dev_attr(attr)->index;
212 struct i2c_client *client = to_i2c_client(dev);
213 struct adm1025_data *data = i2c_get_clientdata(client);
214 long val = simple_strtol(buf, NULL, 10);
215
216 mutex_lock(&data->update_lock);
217 data->in_min[index] = IN_TO_REG(val, in_scale[index]);
218 i2c_smbus_write_byte_data(client, ADM1025_REG_IN_MIN(index),
219 data->in_min[index]);
220 mutex_unlock(&data->update_lock);
221 return count;
222}
223
224static ssize_t set_in_max(struct device *dev, struct device_attribute *attr,
225 const char *buf, size_t count)
226{
227 int index = to_sensor_dev_attr(attr)->index;
228 struct i2c_client *client = to_i2c_client(dev);
229 struct adm1025_data *data = i2c_get_clientdata(client);
230 long val = simple_strtol(buf, NULL, 10);
231
232 mutex_lock(&data->update_lock);
233 data->in_max[index] = IN_TO_REG(val, in_scale[index]);
234 i2c_smbus_write_byte_data(client, ADM1025_REG_IN_MAX(index),
235 data->in_max[index]);
236 mutex_unlock(&data->update_lock);
237 return count;
238}
202 239
203#define set_in(offset) \ 240#define set_in(offset) \
204static ssize_t set_in##offset##_min(struct device *dev, struct device_attribute *attr, const char *buf, \ 241static SENSOR_DEVICE_ATTR(in##offset##_input, S_IRUGO, \
205 size_t count) \ 242 show_in, NULL, offset); \
206{ \ 243static SENSOR_DEVICE_ATTR(in##offset##_min, S_IWUSR | S_IRUGO, \
207 struct i2c_client *client = to_i2c_client(dev); \ 244 show_in_min, set_in_min, offset); \
208 struct adm1025_data *data = i2c_get_clientdata(client); \ 245static SENSOR_DEVICE_ATTR(in##offset##_max, S_IWUSR | S_IRUGO, \
209 long val = simple_strtol(buf, NULL, 10); \ 246 show_in_max, set_in_max, offset)
210 \
211 mutex_lock(&data->update_lock); \
212 data->in_min[offset] = IN_TO_REG(val, in_scale[offset]); \
213 i2c_smbus_write_byte_data(client, ADM1025_REG_IN_MIN(offset), \
214 data->in_min[offset]); \
215 mutex_unlock(&data->update_lock); \
216 return count; \
217} \
218static ssize_t set_in##offset##_max(struct device *dev, struct device_attribute *attr, const char *buf, \
219 size_t count) \
220{ \
221 struct i2c_client *client = to_i2c_client(dev); \
222 struct adm1025_data *data = i2c_get_clientdata(client); \
223 long val = simple_strtol(buf, NULL, 10); \
224 \
225 mutex_lock(&data->update_lock); \
226 data->in_max[offset] = IN_TO_REG(val, in_scale[offset]); \
227 i2c_smbus_write_byte_data(client, ADM1025_REG_IN_MAX(offset), \
228 data->in_max[offset]); \
229 mutex_unlock(&data->update_lock); \
230 return count; \
231} \
232static DEVICE_ATTR(in##offset##_min, S_IWUSR | S_IRUGO, \
233 show_in##offset##_min, set_in##offset##_min); \
234static DEVICE_ATTR(in##offset##_max, S_IWUSR | S_IRUGO, \
235 show_in##offset##_max, set_in##offset##_max);
236set_in(0); 247set_in(0);
237set_in(1); 248set_in(1);
238set_in(2); 249set_in(2);
@@ -240,39 +251,45 @@ set_in(3);
240set_in(4); 251set_in(4);
241set_in(5); 252set_in(5);
242 253
254static ssize_t set_temp_min(struct device *dev, struct device_attribute *attr,
255 const char *buf, size_t count)
256{
257 int index = to_sensor_dev_attr(attr)->index;
258 struct i2c_client *client = to_i2c_client(dev);
259 struct adm1025_data *data = i2c_get_clientdata(client);
260 long val = simple_strtol(buf, NULL, 10);
261
262 mutex_lock(&data->update_lock);
263 data->temp_min[index] = TEMP_TO_REG(val);
264 i2c_smbus_write_byte_data(client, ADM1025_REG_TEMP_LOW(index),
265 data->temp_min[index]);
266 mutex_unlock(&data->update_lock);
267 return count;
268}
269
270static ssize_t set_temp_max(struct device *dev, struct device_attribute *attr,
271 const char *buf, size_t count)
272{
273 int index = to_sensor_dev_attr(attr)->index;
274 struct i2c_client *client = to_i2c_client(dev);
275 struct adm1025_data *data = i2c_get_clientdata(client);
276 long val = simple_strtol(buf, NULL, 10);
277
278 mutex_lock(&data->update_lock);
279 data->temp_max[index] = TEMP_TO_REG(val);
280 i2c_smbus_write_byte_data(client, ADM1025_REG_TEMP_HIGH(index),
281 data->temp_max[index]);
282 mutex_unlock(&data->update_lock);
283 return count;
284}
285
243#define set_temp(offset) \ 286#define set_temp(offset) \
244static ssize_t set_temp##offset##_min(struct device *dev, struct device_attribute *attr, const char *buf, \ 287static SENSOR_DEVICE_ATTR(temp##offset##_input, S_IRUGO, \
245 size_t count) \ 288 show_temp, NULL, offset - 1); \
246{ \ 289static SENSOR_DEVICE_ATTR(temp##offset##_min, S_IWUSR | S_IRUGO, \
247 struct i2c_client *client = to_i2c_client(dev); \ 290 show_temp_min, set_temp_min, offset - 1); \
248 struct adm1025_data *data = i2c_get_clientdata(client); \ 291static SENSOR_DEVICE_ATTR(temp##offset##_max, S_IWUSR | S_IRUGO, \
249 long val = simple_strtol(buf, NULL, 10); \ 292 show_temp_max, set_temp_max, offset - 1)
250 \
251 mutex_lock(&data->update_lock); \
252 data->temp_min[offset-1] = TEMP_TO_REG(val); \
253 i2c_smbus_write_byte_data(client, ADM1025_REG_TEMP_LOW(offset-1), \
254 data->temp_min[offset-1]); \
255 mutex_unlock(&data->update_lock); \
256 return count; \
257} \
258static ssize_t set_temp##offset##_max(struct device *dev, struct device_attribute *attr, const char *buf, \
259 size_t count) \
260{ \
261 struct i2c_client *client = to_i2c_client(dev); \
262 struct adm1025_data *data = i2c_get_clientdata(client); \
263 long val = simple_strtol(buf, NULL, 10); \
264 \
265 mutex_lock(&data->update_lock); \
266 data->temp_max[offset-1] = TEMP_TO_REG(val); \
267 i2c_smbus_write_byte_data(client, ADM1025_REG_TEMP_HIGH(offset-1), \
268 data->temp_max[offset-1]); \
269 mutex_unlock(&data->update_lock); \
270 return count; \
271} \
272static DEVICE_ATTR(temp##offset##_min, S_IWUSR | S_IRUGO, \
273 show_temp##offset##_min, set_temp##offset##_min); \
274static DEVICE_ATTR(temp##offset##_max, S_IWUSR | S_IRUGO, \
275 show_temp##offset##_max, set_temp##offset##_max);
276set_temp(1); 293set_temp(1);
277set_temp(2); 294set_temp(2);
278 295
@@ -316,27 +333,27 @@ static int adm1025_attach_adapter(struct i2c_adapter *adapter)
316} 333}
317 334
318static struct attribute *adm1025_attributes[] = { 335static struct attribute *adm1025_attributes[] = {
319 &dev_attr_in0_input.attr, 336 &sensor_dev_attr_in0_input.dev_attr.attr,
320 &dev_attr_in1_input.attr, 337 &sensor_dev_attr_in1_input.dev_attr.attr,
321 &dev_attr_in2_input.attr, 338 &sensor_dev_attr_in2_input.dev_attr.attr,
322 &dev_attr_in3_input.attr, 339 &sensor_dev_attr_in3_input.dev_attr.attr,
323 &dev_attr_in5_input.attr, 340 &sensor_dev_attr_in5_input.dev_attr.attr,
324 &dev_attr_in0_min.attr, 341 &sensor_dev_attr_in0_min.dev_attr.attr,
325 &dev_attr_in1_min.attr, 342 &sensor_dev_attr_in1_min.dev_attr.attr,
326 &dev_attr_in2_min.attr, 343 &sensor_dev_attr_in2_min.dev_attr.attr,
327 &dev_attr_in3_min.attr, 344 &sensor_dev_attr_in3_min.dev_attr.attr,
328 &dev_attr_in5_min.attr, 345 &sensor_dev_attr_in5_min.dev_attr.attr,
329 &dev_attr_in0_max.attr, 346 &sensor_dev_attr_in0_max.dev_attr.attr,
330 &dev_attr_in1_max.attr, 347 &sensor_dev_attr_in1_max.dev_attr.attr,
331 &dev_attr_in2_max.attr, 348 &sensor_dev_attr_in2_max.dev_attr.attr,
332 &dev_attr_in3_max.attr, 349 &sensor_dev_attr_in3_max.dev_attr.attr,
333 &dev_attr_in5_max.attr, 350 &sensor_dev_attr_in5_max.dev_attr.attr,
334 &dev_attr_temp1_input.attr, 351 &sensor_dev_attr_temp1_input.dev_attr.attr,
335 &dev_attr_temp2_input.attr, 352 &sensor_dev_attr_temp2_input.dev_attr.attr,
336 &dev_attr_temp1_min.attr, 353 &sensor_dev_attr_temp1_min.dev_attr.attr,
337 &dev_attr_temp2_min.attr, 354 &sensor_dev_attr_temp2_min.dev_attr.attr,
338 &dev_attr_temp1_max.attr, 355 &sensor_dev_attr_temp1_max.dev_attr.attr,
339 &dev_attr_temp2_max.attr, 356 &sensor_dev_attr_temp2_max.dev_attr.attr,
340 &dev_attr_alarms.attr, 357 &dev_attr_alarms.attr,
341 &dev_attr_cpu0_vid.attr, 358 &dev_attr_cpu0_vid.attr,
342 &dev_attr_vrm.attr, 359 &dev_attr_vrm.attr,
@@ -348,9 +365,9 @@ static const struct attribute_group adm1025_group = {
348}; 365};
349 366
350static struct attribute *adm1025_attributes_opt[] = { 367static struct attribute *adm1025_attributes_opt[] = {
351 &dev_attr_in4_input.attr, 368 &sensor_dev_attr_in4_input.dev_attr.attr,
352 &dev_attr_in4_min.attr, 369 &sensor_dev_attr_in4_min.dev_attr.attr,
353 &dev_attr_in4_max.attr, 370 &sensor_dev_attr_in4_max.dev_attr.attr,
354 NULL 371 NULL
355}; 372};
356 373
@@ -464,11 +481,11 @@ static int adm1025_detect(struct i2c_adapter *adapter, int address, int kind)
464 /* Pin 11 is either in4 (+12V) or VID4 */ 481 /* Pin 11 is either in4 (+12V) or VID4 */
465 if (!(config & 0x20)) { 482 if (!(config & 0x20)) {
466 if ((err = device_create_file(&new_client->dev, 483 if ((err = device_create_file(&new_client->dev,
467 &dev_attr_in4_input)) 484 &sensor_dev_attr_in4_input.dev_attr))
468 || (err = device_create_file(&new_client->dev, 485 || (err = device_create_file(&new_client->dev,
469 &dev_attr_in4_min)) 486 &sensor_dev_attr_in4_min.dev_attr))
470 || (err = device_create_file(&new_client->dev, 487 || (err = device_create_file(&new_client->dev,
471 &dev_attr_in4_max))) 488 &sensor_dev_attr_in4_max.dev_attr)))
472 goto exit_remove; 489 goto exit_remove;
473 } 490 }
474 491