aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/fscher.c
diff options
context:
space:
mode:
Diffstat (limited to 'drivers/hwmon/fscher.c')
-rw-r--r--drivers/hwmon/fscher.c106
1 files changed, 47 insertions, 59 deletions
diff --git a/drivers/hwmon/fscher.c b/drivers/hwmon/fscher.c
index 6bc76b407636..19717752cfca 100644
--- a/drivers/hwmon/fscher.c
+++ b/drivers/hwmon/fscher.c
@@ -34,6 +34,7 @@
34#include <linux/hwmon.h> 34#include <linux/hwmon.h>
35#include <linux/err.h> 35#include <linux/err.h>
36#include <linux/mutex.h> 36#include <linux/mutex.h>
37#include <linux/sysfs.h>
37 38
38/* 39/*
39 * Addresses to scan 40 * Addresses to scan
@@ -240,47 +241,45 @@ sysfs_alarms(FSCHER_REG_EVENTS)
240sysfs_control(FSCHER_REG_CONTROL) 241sysfs_control(FSCHER_REG_CONTROL)
241sysfs_watchdog(FSCHER_REG_WDOG_CONTROL, FSCHER_REG_WDOG_STATE, FSCHER_REG_WDOG_PRESET) 242sysfs_watchdog(FSCHER_REG_WDOG_CONTROL, FSCHER_REG_WDOG_STATE, FSCHER_REG_WDOG_PRESET)
242 243
243#define device_create_file_fan(client, offset) \ 244static struct attribute *fscher_attributes[] = {
244do { \ 245 &dev_attr_revision.attr,
245 device_create_file(&client->dev, &dev_attr_fan##offset##_status); \ 246 &dev_attr_alarms.attr,
246 device_create_file(&client->dev, &dev_attr_pwm##offset); \ 247 &dev_attr_control.attr,
247 device_create_file(&client->dev, &dev_attr_fan##offset##_div); \ 248
248 device_create_file(&client->dev, &dev_attr_fan##offset##_input); \ 249 &dev_attr_watchdog_status.attr,
249} while (0) 250 &dev_attr_watchdog_control.attr,
250 251 &dev_attr_watchdog_preset.attr,
251#define device_create_file_temp(client, offset) \ 252
252do { \ 253 &dev_attr_in0_input.attr,
253 device_create_file(&client->dev, &dev_attr_temp##offset##_status); \ 254 &dev_attr_in1_input.attr,
254 device_create_file(&client->dev, &dev_attr_temp##offset##_input); \ 255 &dev_attr_in2_input.attr,
255} while (0) 256
256 257 &dev_attr_fan1_status.attr,
257#define device_create_file_in(client, offset) \ 258 &dev_attr_fan1_div.attr,
258do { \ 259 &dev_attr_fan1_input.attr,
259 device_create_file(&client->dev, &dev_attr_in##offset##_input); \ 260 &dev_attr_pwm1.attr,
260} while (0) 261 &dev_attr_fan2_status.attr,
261 262 &dev_attr_fan2_div.attr,
262#define device_create_file_revision(client) \ 263 &dev_attr_fan2_input.attr,
263do { \ 264 &dev_attr_pwm2.attr,
264 device_create_file(&client->dev, &dev_attr_revision); \ 265 &dev_attr_fan3_status.attr,
265} while (0) 266 &dev_attr_fan3_div.attr,
266 267 &dev_attr_fan3_input.attr,
267#define device_create_file_alarms(client) \ 268 &dev_attr_pwm3.attr,
268do { \ 269
269 device_create_file(&client->dev, &dev_attr_alarms); \ 270 &dev_attr_temp1_status.attr,
270} while (0) 271 &dev_attr_temp1_input.attr,
271 272 &dev_attr_temp2_status.attr,
272#define device_create_file_control(client) \ 273 &dev_attr_temp2_input.attr,
273do { \ 274 &dev_attr_temp3_status.attr,
274 device_create_file(&client->dev, &dev_attr_control); \ 275 &dev_attr_temp3_input.attr,
275} while (0) 276 NULL
276 277};
277#define device_create_file_watchdog(client) \ 278
278do { \ 279static const struct attribute_group fscher_group = {
279 device_create_file(&client->dev, &dev_attr_watchdog_status); \ 280 .attrs = fscher_attributes,
280 device_create_file(&client->dev, &dev_attr_watchdog_control); \ 281};
281 device_create_file(&client->dev, &dev_attr_watchdog_preset); \ 282
282} while (0)
283
284/* 283/*
285 * Real code 284 * Real code
286 */ 285 */
@@ -342,31 +341,19 @@ static int fscher_detect(struct i2c_adapter *adapter, int address, int kind)
342 fscher_init_client(new_client); 341 fscher_init_client(new_client);
343 342
344 /* Register sysfs hooks */ 343 /* Register sysfs hooks */
344 if ((err = sysfs_create_group(&new_client->dev.kobj, &fscher_group)))
345 goto exit_detach;
346
345 data->class_dev = hwmon_device_register(&new_client->dev); 347 data->class_dev = hwmon_device_register(&new_client->dev);
346 if (IS_ERR(data->class_dev)) { 348 if (IS_ERR(data->class_dev)) {
347 err = PTR_ERR(data->class_dev); 349 err = PTR_ERR(data->class_dev);
348 goto exit_detach; 350 goto exit_remove_files;
349 } 351 }
350 352
351 device_create_file_revision(new_client);
352 device_create_file_alarms(new_client);
353 device_create_file_control(new_client);
354 device_create_file_watchdog(new_client);
355
356 device_create_file_in(new_client, 0);
357 device_create_file_in(new_client, 1);
358 device_create_file_in(new_client, 2);
359
360 device_create_file_fan(new_client, 1);
361 device_create_file_fan(new_client, 2);
362 device_create_file_fan(new_client, 3);
363
364 device_create_file_temp(new_client, 1);
365 device_create_file_temp(new_client, 2);
366 device_create_file_temp(new_client, 3);
367
368 return 0; 353 return 0;
369 354
355exit_remove_files:
356 sysfs_remove_group(&new_client->dev.kobj, &fscher_group);
370exit_detach: 357exit_detach:
371 i2c_detach_client(new_client); 358 i2c_detach_client(new_client);
372exit_free: 359exit_free:
@@ -381,6 +368,7 @@ static int fscher_detach_client(struct i2c_client *client)
381 int err; 368 int err;
382 369
383 hwmon_device_unregister(data->class_dev); 370 hwmon_device_unregister(data->class_dev);
371 sysfs_remove_group(&client->dev.kobj, &fscher_group);
384 372
385 if ((err = i2c_detach_client(client))) 373 if ((err = i2c_detach_client(client)))
386 return err; 374 return err;