aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/max6650.c
diff options
context:
space:
mode:
authorGuenter Roeck <linux@roeck-us.net>2014-02-12 01:26:12 -0500
committerGuenter Roeck <linux@roeck-us.net>2014-03-03 11:01:05 -0500
commit1577f94bcefb0ef88d4fb15313076a45b8bea8a1 (patch)
tree31de357a5d160859eb39969ad36f248d36e6bfa6 /drivers/hwmon/max6650.c
parent6c588b45b0d4005814cd3188f47db621b929c922 (diff)
hwmon: (max6650) Rearrange code to no longer require forward declarations
Cleanup only; no functional change. Reviewed-by: Jean Delvare <jdelvare@suse.de> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'drivers/hwmon/max6650.c')
-rw-r--r--drivers/hwmon/max6650.c228
1 files changed, 109 insertions, 119 deletions
diff --git a/drivers/hwmon/max6650.c b/drivers/hwmon/max6650.c
index 0cafc390db4d..26b24f772f5c 100644
--- a/drivers/hwmon/max6650.c
+++ b/drivers/hwmon/max6650.c
@@ -105,32 +105,6 @@ module_param(clock, int, S_IRUGO);
105 105
106#define DIV_FROM_REG(reg) (1 << (reg & 7)) 106#define DIV_FROM_REG(reg) (1 << (reg & 7))
107 107
108static int max6650_probe(struct i2c_client *client,
109 const struct i2c_device_id *id);
110static int max6650_init_client(struct i2c_client *client);
111static int max6650_remove(struct i2c_client *client);
112static struct max6650_data *max6650_update_device(struct device *dev);
113
114/*
115 * Driver data (common to all clients)
116 */
117
118static const struct i2c_device_id max6650_id[] = {
119 { "max6650", 1 },
120 { "max6651", 4 },
121 { }
122};
123MODULE_DEVICE_TABLE(i2c, max6650_id);
124
125static struct i2c_driver max6650_driver = {
126 .driver = {
127 .name = "max6650",
128 },
129 .probe = max6650_probe,
130 .remove = max6650_remove,
131 .id_table = max6650_id,
132};
133
134/* 108/*
135 * Client data (each client gets its own) 109 * Client data (each client gets its own)
136 */ 110 */
@@ -151,6 +125,51 @@ struct max6650_data {
151 u8 alarm; 125 u8 alarm;
152}; 126};
153 127
128static const u8 tach_reg[] = {
129 MAX6650_REG_TACH0,
130 MAX6650_REG_TACH1,
131 MAX6650_REG_TACH2,
132 MAX6650_REG_TACH3,
133};
134
135static struct max6650_data *max6650_update_device(struct device *dev)
136{
137 int i;
138 struct i2c_client *client = to_i2c_client(dev);
139 struct max6650_data *data = i2c_get_clientdata(client);
140
141 mutex_lock(&data->update_lock);
142
143 if (time_after(jiffies, data->last_updated + HZ) || !data->valid) {
144 data->speed = i2c_smbus_read_byte_data(client,
145 MAX6650_REG_SPEED);
146 data->config = i2c_smbus_read_byte_data(client,
147 MAX6650_REG_CONFIG);
148 for (i = 0; i < data->nr_fans; i++) {
149 data->tach[i] = i2c_smbus_read_byte_data(client,
150 tach_reg[i]);
151 }
152 data->count = i2c_smbus_read_byte_data(client,
153 MAX6650_REG_COUNT);
154 data->dac = i2c_smbus_read_byte_data(client, MAX6650_REG_DAC);
155
156 /*
157 * Alarms are cleared on read in case the condition that
158 * caused the alarm is removed. Keep the value latched here
159 * for providing the register through different alarm files.
160 */
161 data->alarm |= i2c_smbus_read_byte_data(client,
162 MAX6650_REG_ALARM);
163
164 data->last_updated = jiffies;
165 data->valid = 1;
166 }
167
168 mutex_unlock(&data->update_lock);
169
170 return data;
171}
172
154static ssize_t get_fan(struct device *dev, struct device_attribute *devattr, 173static ssize_t get_fan(struct device *dev, struct device_attribute *devattr,
155 char *buf) 174 char *buf)
156{ 175{
@@ -539,64 +558,6 @@ static const struct attribute_group max6651_attr_grp = {
539 * Real code 558 * Real code
540 */ 559 */
541 560
542static int max6650_probe(struct i2c_client *client,
543 const struct i2c_device_id *id)
544{
545 struct max6650_data *data;
546 int err;
547
548 data = devm_kzalloc(&client->dev, sizeof(struct max6650_data),
549 GFP_KERNEL);
550 if (!data) {
551 dev_err(&client->dev, "out of memory.\n");
552 return -ENOMEM;
553 }
554
555 i2c_set_clientdata(client, data);
556 mutex_init(&data->update_lock);
557 data->nr_fans = id->driver_data;
558
559 /*
560 * Initialize the max6650 chip
561 */
562 err = max6650_init_client(client);
563 if (err)
564 return err;
565
566 err = sysfs_create_group(&client->dev.kobj, &max6650_attr_grp);
567 if (err)
568 return err;
569 /* 3 additional fan inputs for the MAX6651 */
570 if (data->nr_fans == 4) {
571 err = sysfs_create_group(&client->dev.kobj, &max6651_attr_grp);
572 if (err)
573 goto err_remove;
574 }
575
576 data->hwmon_dev = hwmon_device_register(&client->dev);
577 if (!IS_ERR(data->hwmon_dev))
578 return 0;
579
580 err = PTR_ERR(data->hwmon_dev);
581 dev_err(&client->dev, "error registering hwmon device.\n");
582 if (data->nr_fans == 4)
583 sysfs_remove_group(&client->dev.kobj, &max6651_attr_grp);
584err_remove:
585 sysfs_remove_group(&client->dev.kobj, &max6650_attr_grp);
586 return err;
587}
588
589static int max6650_remove(struct i2c_client *client)
590{
591 struct max6650_data *data = i2c_get_clientdata(client);
592
593 hwmon_device_unregister(data->hwmon_dev);
594 if (data->nr_fans == 4)
595 sysfs_remove_group(&client->dev.kobj, &max6651_attr_grp);
596 sysfs_remove_group(&client->dev.kobj, &max6650_attr_grp);
597 return 0;
598}
599
600static int max6650_init_client(struct i2c_client *client) 561static int max6650_init_client(struct i2c_client *client)
601{ 562{
602 struct max6650_data *data = i2c_get_clientdata(client); 563 struct max6650_data *data = i2c_get_clientdata(client);
@@ -684,51 +645,80 @@ static int max6650_init_client(struct i2c_client *client)
684 return 0; 645 return 0;
685} 646}
686 647
687static const u8 tach_reg[] = { 648static int max6650_probe(struct i2c_client *client,
688 MAX6650_REG_TACH0, 649 const struct i2c_device_id *id)
689 MAX6650_REG_TACH1,
690 MAX6650_REG_TACH2,
691 MAX6650_REG_TACH3,
692};
693
694static struct max6650_data *max6650_update_device(struct device *dev)
695{ 650{
696 int i; 651 struct max6650_data *data;
697 struct i2c_client *client = to_i2c_client(dev); 652 int err;
698 struct max6650_data *data = i2c_get_clientdata(client);
699 653
700 mutex_lock(&data->update_lock); 654 data = devm_kzalloc(&client->dev, sizeof(struct max6650_data),
655 GFP_KERNEL);
656 if (!data) {
657 dev_err(&client->dev, "out of memory.\n");
658 return -ENOMEM;
659 }
701 660
702 if (time_after(jiffies, data->last_updated + HZ) || !data->valid) { 661 i2c_set_clientdata(client, data);
703 data->speed = i2c_smbus_read_byte_data(client, 662 mutex_init(&data->update_lock);
704 MAX6650_REG_SPEED); 663 data->nr_fans = id->driver_data;
705 data->config = i2c_smbus_read_byte_data(client,
706 MAX6650_REG_CONFIG);
707 for (i = 0; i < data->nr_fans; i++) {
708 data->tach[i] = i2c_smbus_read_byte_data(client,
709 tach_reg[i]);
710 }
711 data->count = i2c_smbus_read_byte_data(client,
712 MAX6650_REG_COUNT);
713 data->dac = i2c_smbus_read_byte_data(client, MAX6650_REG_DAC);
714 664
715 /* 665 /*
716 * Alarms are cleared on read in case the condition that 666 * Initialize the max6650 chip
717 * caused the alarm is removed. Keep the value latched here 667 */
718 * for providing the register through different alarm files. 668 err = max6650_init_client(client);
719 */ 669 if (err)
720 data->alarm |= i2c_smbus_read_byte_data(client, 670 return err;
721 MAX6650_REG_ALARM);
722 671
723 data->last_updated = jiffies; 672 err = sysfs_create_group(&client->dev.kobj, &max6650_attr_grp);
724 data->valid = 1; 673 if (err)
674 return err;
675 /* 3 additional fan inputs for the MAX6651 */
676 if (data->nr_fans == 4) {
677 err = sysfs_create_group(&client->dev.kobj, &max6651_attr_grp);
678 if (err)
679 goto err_remove;
725 } 680 }
726 681
727 mutex_unlock(&data->update_lock); 682 data->hwmon_dev = hwmon_device_register(&client->dev);
683 if (!IS_ERR(data->hwmon_dev))
684 return 0;
728 685
729 return data; 686 err = PTR_ERR(data->hwmon_dev);
687 dev_err(&client->dev, "error registering hwmon device.\n");
688 if (data->nr_fans == 4)
689 sysfs_remove_group(&client->dev.kobj, &max6651_attr_grp);
690err_remove:
691 sysfs_remove_group(&client->dev.kobj, &max6650_attr_grp);
692 return err;
730} 693}
731 694
695static int max6650_remove(struct i2c_client *client)
696{
697 struct max6650_data *data = i2c_get_clientdata(client);
698
699 hwmon_device_unregister(data->hwmon_dev);
700 if (data->nr_fans == 4)
701 sysfs_remove_group(&client->dev.kobj, &max6651_attr_grp);
702 sysfs_remove_group(&client->dev.kobj, &max6650_attr_grp);
703 return 0;
704}
705
706static const struct i2c_device_id max6650_id[] = {
707 { "max6650", 1 },
708 { "max6651", 4 },
709 { }
710};
711MODULE_DEVICE_TABLE(i2c, max6650_id);
712
713static struct i2c_driver max6650_driver = {
714 .driver = {
715 .name = "max6650",
716 },
717 .probe = max6650_probe,
718 .remove = max6650_remove,
719 .id_table = max6650_id,
720};
721
732module_i2c_driver(max6650_driver); 722module_i2c_driver(max6650_driver);
733 723
734MODULE_AUTHOR("Hans J. Koch"); 724MODULE_AUTHOR("Hans J. Koch");