diff options
author | Hans de Goede <hdegoede@redhat.com> | 2009-01-07 10:37:27 -0500 |
---|---|---|
committer | Jean Delvare <khali@linux-fr.org> | 2009-01-07 10:37:27 -0500 |
commit | c13548c531ff40501aee1c1dd6f474c3c6adfcd5 (patch) | |
tree | 9f8b907d1b4cc7efb211e99cbdde9b4141c77aca /drivers/hwmon | |
parent | 9ab796ebe185257013f0ac505ecbe7abf068a608 (diff) |
hwmon: (f71882fg) Style cleanups and put some repeating code into functions
Various small cleanups as preparation for adding f71862fg support to the
f71882fg driver.
Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Diffstat (limited to 'drivers/hwmon')
-rw-r--r-- | drivers/hwmon/f71882fg.c | 89 |
1 files changed, 41 insertions, 48 deletions
diff --git a/drivers/hwmon/f71882fg.c b/drivers/hwmon/f71882fg.c index c04108735f3f..593ed2a0555c 100644 --- a/drivers/hwmon/f71882fg.c +++ b/drivers/hwmon/f71882fg.c | |||
@@ -1,6 +1,6 @@ | |||
1 | /*************************************************************************** | 1 | /*************************************************************************** |
2 | * Copyright (C) 2006 by Hans Edgington <hans@edgington.nl> * | 2 | * Copyright (C) 2006 by Hans Edgington <hans@edgington.nl> * |
3 | * Copyright (C) 2007 by Hans de Goede <j.w.r.degoede@hhs.nl> * | 3 | * Copyright (C) 2007,2008 by Hans de Goede <hdegoede@redhat.com> * |
4 | * * | 4 | * * |
5 | * This program is free software; you can redistribute it and/or modify * | 5 | * This program is free software; you can redistribute it and/or modify * |
6 | * it under the terms of the GNU General Public License as published by * | 6 | * it under the terms of the GNU General Public License as published by * |
@@ -228,11 +228,7 @@ static ssize_t show_name(struct device *dev, struct device_attribute *devattr, | |||
228 | char *buf); | 228 | char *buf); |
229 | 229 | ||
230 | static int __devinit f71882fg_probe(struct platform_device * pdev); | 230 | static int __devinit f71882fg_probe(struct platform_device * pdev); |
231 | static int __devexit f71882fg_remove(struct platform_device *pdev); | 231 | static int f71882fg_remove(struct platform_device *pdev); |
232 | static int __init f71882fg_init(void); | ||
233 | static int __init f71882fg_find(int sioaddr, unsigned short *address); | ||
234 | static int __init f71882fg_device_add(unsigned short address); | ||
235 | static void __exit f71882fg_exit(void); | ||
236 | 232 | ||
237 | static struct platform_driver f71882fg_driver = { | 233 | static struct platform_driver f71882fg_driver = { |
238 | .driver = { | 234 | .driver = { |
@@ -243,10 +239,7 @@ static struct platform_driver f71882fg_driver = { | |||
243 | .remove = __devexit_p(f71882fg_remove), | 239 | .remove = __devexit_p(f71882fg_remove), |
244 | }; | 240 | }; |
245 | 241 | ||
246 | static struct device_attribute f71882fg_dev_attr[] = | 242 | static DEVICE_ATTR(name, S_IRUGO, show_name, NULL); |
247 | { | ||
248 | __ATTR( name, S_IRUGO, show_name, NULL ), | ||
249 | }; | ||
250 | 243 | ||
251 | static struct sensor_device_attribute_2 f71882fg_in_temp_attr[] = { | 244 | static struct sensor_device_attribute_2 f71882fg_in_temp_attr[] = { |
252 | SENSOR_ATTR_2(in0_input, S_IRUGO, show_in, NULL, 0, 0), | 245 | SENSOR_ATTR_2(in0_input, S_IRUGO, show_in, NULL, 0, 0), |
@@ -1396,14 +1389,27 @@ static ssize_t show_name(struct device *dev, struct device_attribute *devattr, | |||
1396 | return sprintf(buf, DRVNAME "\n"); | 1389 | return sprintf(buf, DRVNAME "\n"); |
1397 | } | 1390 | } |
1398 | 1391 | ||
1392 | static int __devinit f71882fg_create_sysfs_files(struct platform_device *pdev, | ||
1393 | struct sensor_device_attribute_2 *attr, int count) | ||
1394 | { | ||
1395 | int err, i; | ||
1396 | |||
1397 | for (i = 0; i < count; i++) { | ||
1398 | err = device_create_file(&pdev->dev, &attr[i].dev_attr); | ||
1399 | if (err) | ||
1400 | return err; | ||
1401 | } | ||
1402 | return 0; | ||
1403 | } | ||
1399 | 1404 | ||
1400 | static int __devinit f71882fg_probe(struct platform_device * pdev) | 1405 | static int __devinit f71882fg_probe(struct platform_device *pdev) |
1401 | { | 1406 | { |
1402 | struct f71882fg_data *data; | 1407 | struct f71882fg_data *data; |
1403 | int err, i; | 1408 | int err; |
1404 | u8 start_reg; | 1409 | u8 start_reg; |
1405 | 1410 | ||
1406 | if (!(data = kzalloc(sizeof(struct f71882fg_data), GFP_KERNEL))) | 1411 | data = kzalloc(sizeof(struct f71882fg_data), GFP_KERNEL); |
1412 | if (!data) | ||
1407 | return -ENOMEM; | 1413 | return -ENOMEM; |
1408 | 1414 | ||
1409 | data->addr = platform_get_resource(pdev, IORESOURCE_IO, 0)->start; | 1415 | data->addr = platform_get_resource(pdev, IORESOURCE_IO, 0)->start; |
@@ -1411,65 +1417,50 @@ static int __devinit f71882fg_probe(struct platform_device * pdev) | |||
1411 | platform_set_drvdata(pdev, data); | 1417 | platform_set_drvdata(pdev, data); |
1412 | 1418 | ||
1413 | /* Register sysfs interface files */ | 1419 | /* Register sysfs interface files */ |
1414 | for (i = 0; i < ARRAY_SIZE(f71882fg_dev_attr); i++) { | 1420 | err = device_create_file(&pdev->dev, &dev_attr_name); |
1415 | err = device_create_file(&pdev->dev, &f71882fg_dev_attr[i]); | 1421 | if (err) |
1416 | if (err) | 1422 | goto exit_unregister_sysfs; |
1417 | goto exit_unregister_sysfs; | ||
1418 | } | ||
1419 | 1423 | ||
1420 | start_reg = f71882fg_read8(data, F71882FG_REG_START); | 1424 | start_reg = f71882fg_read8(data, F71882FG_REG_START); |
1421 | if (start_reg & 0x01) { | 1425 | if (start_reg & 0x01) { |
1422 | for (i = 0; i < ARRAY_SIZE(f71882fg_in_temp_attr); i++) { | 1426 | err = f71882fg_create_sysfs_files(pdev, f71882fg_in_temp_attr, |
1423 | err = device_create_file(&pdev->dev, | 1427 | ARRAY_SIZE(f71882fg_in_temp_attr)); |
1424 | &f71882fg_in_temp_attr[i].dev_attr); | 1428 | if (err) |
1425 | if (err) | 1429 | goto exit_unregister_sysfs; |
1426 | goto exit_unregister_sysfs; | ||
1427 | } | ||
1428 | } | 1430 | } |
1429 | 1431 | ||
1430 | if (start_reg & 0x02) { | 1432 | if (start_reg & 0x02) { |
1431 | for (i = 0; i < ARRAY_SIZE(f71882fg_fan_attr); i++) { | 1433 | err = f71882fg_create_sysfs_files(pdev, f71882fg_fan_attr, |
1432 | err = device_create_file(&pdev->dev, | 1434 | ARRAY_SIZE(f71882fg_fan_attr)); |
1433 | &f71882fg_fan_attr[i].dev_attr); | 1435 | if (err) |
1434 | if (err) | 1436 | goto exit_unregister_sysfs; |
1435 | goto exit_unregister_sysfs; | ||
1436 | } | ||
1437 | } | 1437 | } |
1438 | 1438 | ||
1439 | data->hwmon_dev = hwmon_device_register(&pdev->dev); | 1439 | data->hwmon_dev = hwmon_device_register(&pdev->dev); |
1440 | if (IS_ERR(data->hwmon_dev)) { | 1440 | if (IS_ERR(data->hwmon_dev)) { |
1441 | err = PTR_ERR(data->hwmon_dev); | 1441 | err = PTR_ERR(data->hwmon_dev); |
1442 | data->hwmon_dev = NULL; | ||
1442 | goto exit_unregister_sysfs; | 1443 | goto exit_unregister_sysfs; |
1443 | } | 1444 | } |
1444 | 1445 | ||
1445 | return 0; | 1446 | return 0; |
1446 | 1447 | ||
1447 | exit_unregister_sysfs: | 1448 | exit_unregister_sysfs: |
1448 | for (i = 0; i < ARRAY_SIZE(f71882fg_dev_attr); i++) | 1449 | f71882fg_remove(pdev); /* Will unregister the sysfs files for us */ |
1449 | device_remove_file(&pdev->dev, &f71882fg_dev_attr[i]); | ||
1450 | |||
1451 | for (i = 0; i < ARRAY_SIZE(f71882fg_in_temp_attr); i++) | ||
1452 | device_remove_file(&pdev->dev, | ||
1453 | &f71882fg_in_temp_attr[i].dev_attr); | ||
1454 | |||
1455 | for (i = 0; i < ARRAY_SIZE(f71882fg_fan_attr); i++) | ||
1456 | device_remove_file(&pdev->dev, &f71882fg_fan_attr[i].dev_attr); | ||
1457 | |||
1458 | kfree(data); | ||
1459 | 1450 | ||
1460 | return err; | 1451 | return err; |
1461 | } | 1452 | } |
1462 | 1453 | ||
1463 | static int __devexit f71882fg_remove(struct platform_device *pdev) | 1454 | static int f71882fg_remove(struct platform_device *pdev) |
1464 | { | 1455 | { |
1465 | int i; | 1456 | int i; |
1466 | struct f71882fg_data *data = platform_get_drvdata(pdev); | 1457 | struct f71882fg_data *data = platform_get_drvdata(pdev); |
1467 | 1458 | ||
1468 | platform_set_drvdata(pdev, NULL); | 1459 | platform_set_drvdata(pdev, NULL); |
1469 | hwmon_device_unregister(data->hwmon_dev); | 1460 | if (data->hwmon_dev) |
1461 | hwmon_device_unregister(data->hwmon_dev); | ||
1470 | 1462 | ||
1471 | for (i = 0; i < ARRAY_SIZE(f71882fg_dev_attr); i++) | 1463 | device_remove_file(&pdev->dev, &dev_attr_name); |
1472 | device_remove_file(&pdev->dev, &f71882fg_dev_attr[i]); | ||
1473 | 1464 | ||
1474 | for (i = 0; i < ARRAY_SIZE(f71882fg_in_temp_attr); i++) | 1465 | for (i = 0; i < ARRAY_SIZE(f71882fg_in_temp_attr); i++) |
1475 | device_remove_file(&pdev->dev, | 1466 | device_remove_file(&pdev->dev, |
@@ -1577,10 +1568,12 @@ static int __init f71882fg_init(void) | |||
1577 | if (f71882fg_find(0x2e, &address) && f71882fg_find(0x4e, &address)) | 1568 | if (f71882fg_find(0x2e, &address) && f71882fg_find(0x4e, &address)) |
1578 | goto exit; | 1569 | goto exit; |
1579 | 1570 | ||
1580 | if ((err = platform_driver_register(&f71882fg_driver))) | 1571 | err = platform_driver_register(&f71882fg_driver); |
1572 | if (err) | ||
1581 | goto exit; | 1573 | goto exit; |
1582 | 1574 | ||
1583 | if ((err = f71882fg_device_add(address))) | 1575 | err = f71882fg_device_add(address); |
1576 | if (err) | ||
1584 | goto exit_driver; | 1577 | goto exit_driver; |
1585 | 1578 | ||
1586 | return 0; | 1579 | return 0; |
@@ -1598,7 +1591,7 @@ static void __exit f71882fg_exit(void) | |||
1598 | } | 1591 | } |
1599 | 1592 | ||
1600 | MODULE_DESCRIPTION("F71882FG Hardware Monitoring Driver"); | 1593 | MODULE_DESCRIPTION("F71882FG Hardware Monitoring Driver"); |
1601 | MODULE_AUTHOR("Hans Edgington (hans@edgington.nl)"); | 1594 | MODULE_AUTHOR("Hans Edgington, Hans de Goede (hdegoede@redhat.com)"); |
1602 | MODULE_LICENSE("GPL"); | 1595 | MODULE_LICENSE("GPL"); |
1603 | 1596 | ||
1604 | module_init(f71882fg_init); | 1597 | module_init(f71882fg_init); |