diff options
author | Axel Lin <axel.lin@ingics.com> | 2014-07-02 21:46:51 -0400 |
---|---|---|
committer | Guenter Roeck <linux@roeck-us.net> | 2014-08-04 10:01:36 -0400 |
commit | d4a972a33932f039fe9dce0cfb2337fee1150f5a (patch) | |
tree | 8db65c0d2f5ae59258f2a952ba05749bcbdc9df4 /drivers/hwmon/gl518sm.c | |
parent | 6579d589eaa0f86a902504f76b4f973e2978d951 (diff) |
hwmon: (gl518sm) Avoid forward declaration
Reorder functions to avoid forward declaration.
Signed-off-by: Axel Lin <axel.lin@ingics.com>
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'drivers/hwmon/gl518sm.c')
-rw-r--r-- | drivers/hwmon/gl518sm.c | 263 |
1 files changed, 126 insertions, 137 deletions
diff --git a/drivers/hwmon/gl518sm.c b/drivers/hwmon/gl518sm.c index 1e9830513045..0307d8218f87 100644 --- a/drivers/hwmon/gl518sm.c +++ b/drivers/hwmon/gl518sm.c | |||
@@ -137,33 +137,98 @@ struct gl518_data { | |||
137 | u8 beep_enable; /* Boolean */ | 137 | u8 beep_enable; /* Boolean */ |
138 | }; | 138 | }; |
139 | 139 | ||
140 | static int gl518_probe(struct i2c_client *client, | 140 | /* |
141 | const struct i2c_device_id *id); | 141 | * Registers 0x07 to 0x0c are word-sized, others are byte-sized |
142 | static int gl518_detect(struct i2c_client *client, struct i2c_board_info *info); | 142 | * GL518 uses a high-byte first convention, which is exactly opposite to |
143 | static void gl518_init_client(struct i2c_client *client); | 143 | * the SMBus standard. |
144 | static int gl518_remove(struct i2c_client *client); | 144 | */ |
145 | static int gl518_read_value(struct i2c_client *client, u8 reg); | 145 | static int gl518_read_value(struct i2c_client *client, u8 reg) |
146 | static int gl518_write_value(struct i2c_client *client, u8 reg, u16 value); | 146 | { |
147 | static struct gl518_data *gl518_update_device(struct device *dev); | 147 | if ((reg >= 0x07) && (reg <= 0x0c)) |
148 | return i2c_smbus_read_word_swapped(client, reg); | ||
149 | else | ||
150 | return i2c_smbus_read_byte_data(client, reg); | ||
151 | } | ||
148 | 152 | ||
149 | static const struct i2c_device_id gl518_id[] = { | 153 | static int gl518_write_value(struct i2c_client *client, u8 reg, u16 value) |
150 | { "gl518sm", 0 }, | 154 | { |
151 | { } | 155 | if ((reg >= 0x07) && (reg <= 0x0c)) |
152 | }; | 156 | return i2c_smbus_write_word_swapped(client, reg, value); |
153 | MODULE_DEVICE_TABLE(i2c, gl518_id); | 157 | else |
158 | return i2c_smbus_write_byte_data(client, reg, value); | ||
159 | } | ||
154 | 160 | ||
155 | /* This is the driver that will be inserted */ | 161 | static struct gl518_data *gl518_update_device(struct device *dev) |
156 | static struct i2c_driver gl518_driver = { | 162 | { |
157 | .class = I2C_CLASS_HWMON, | 163 | struct i2c_client *client = to_i2c_client(dev); |
158 | .driver = { | 164 | struct gl518_data *data = i2c_get_clientdata(client); |
159 | .name = "gl518sm", | 165 | int val; |
160 | }, | 166 | |
161 | .probe = gl518_probe, | 167 | mutex_lock(&data->update_lock); |
162 | .remove = gl518_remove, | 168 | |
163 | .id_table = gl518_id, | 169 | if (time_after(jiffies, data->last_updated + HZ + HZ / 2) |
164 | .detect = gl518_detect, | 170 | || !data->valid) { |
165 | .address_list = normal_i2c, | 171 | dev_dbg(&client->dev, "Starting gl518 update\n"); |
166 | }; | 172 | |
173 | data->alarms = gl518_read_value(client, GL518_REG_INT); | ||
174 | data->beep_mask = gl518_read_value(client, GL518_REG_ALARM); | ||
175 | |||
176 | val = gl518_read_value(client, GL518_REG_VDD_LIMIT); | ||
177 | data->voltage_min[0] = val & 0xff; | ||
178 | data->voltage_max[0] = (val >> 8) & 0xff; | ||
179 | val = gl518_read_value(client, GL518_REG_VIN1_LIMIT); | ||
180 | data->voltage_min[1] = val & 0xff; | ||
181 | data->voltage_max[1] = (val >> 8) & 0xff; | ||
182 | val = gl518_read_value(client, GL518_REG_VIN2_LIMIT); | ||
183 | data->voltage_min[2] = val & 0xff; | ||
184 | data->voltage_max[2] = (val >> 8) & 0xff; | ||
185 | val = gl518_read_value(client, GL518_REG_VIN3_LIMIT); | ||
186 | data->voltage_min[3] = val & 0xff; | ||
187 | data->voltage_max[3] = (val >> 8) & 0xff; | ||
188 | |||
189 | val = gl518_read_value(client, GL518_REG_FAN_COUNT); | ||
190 | data->fan_in[0] = (val >> 8) & 0xff; | ||
191 | data->fan_in[1] = val & 0xff; | ||
192 | |||
193 | val = gl518_read_value(client, GL518_REG_FAN_LIMIT); | ||
194 | data->fan_min[0] = (val >> 8) & 0xff; | ||
195 | data->fan_min[1] = val & 0xff; | ||
196 | |||
197 | data->temp_in = gl518_read_value(client, GL518_REG_TEMP_IN); | ||
198 | data->temp_max = | ||
199 | gl518_read_value(client, GL518_REG_TEMP_MAX); | ||
200 | data->temp_hyst = | ||
201 | gl518_read_value(client, GL518_REG_TEMP_HYST); | ||
202 | |||
203 | val = gl518_read_value(client, GL518_REG_MISC); | ||
204 | data->fan_div[0] = (val >> 6) & 0x03; | ||
205 | data->fan_div[1] = (val >> 4) & 0x03; | ||
206 | data->fan_auto1 = (val >> 3) & 0x01; | ||
207 | |||
208 | data->alarms &= data->alarm_mask; | ||
209 | |||
210 | val = gl518_read_value(client, GL518_REG_CONF); | ||
211 | data->beep_enable = (val >> 2) & 1; | ||
212 | |||
213 | if (data->type != gl518sm_r00) { | ||
214 | data->voltage_in[0] = | ||
215 | gl518_read_value(client, GL518_REG_VDD); | ||
216 | data->voltage_in[1] = | ||
217 | gl518_read_value(client, GL518_REG_VIN1); | ||
218 | data->voltage_in[2] = | ||
219 | gl518_read_value(client, GL518_REG_VIN2); | ||
220 | } | ||
221 | data->voltage_in[3] = | ||
222 | gl518_read_value(client, GL518_REG_VIN3); | ||
223 | |||
224 | data->last_updated = jiffies; | ||
225 | data->valid = 1; | ||
226 | } | ||
227 | |||
228 | mutex_unlock(&data->update_lock); | ||
229 | |||
230 | return data; | ||
231 | } | ||
167 | 232 | ||
168 | /* | 233 | /* |
169 | * Sysfs stuff | 234 | * Sysfs stuff |
@@ -539,6 +604,26 @@ static int gl518_detect(struct i2c_client *client, struct i2c_board_info *info) | |||
539 | return 0; | 604 | return 0; |
540 | } | 605 | } |
541 | 606 | ||
607 | /* | ||
608 | * Called when we have found a new GL518SM. | ||
609 | * Note that we preserve D4:NoFan2 and D2:beep_enable. | ||
610 | */ | ||
611 | static void gl518_init_client(struct i2c_client *client) | ||
612 | { | ||
613 | /* Make sure we leave D7:Reset untouched */ | ||
614 | u8 regvalue = gl518_read_value(client, GL518_REG_CONF) & 0x7f; | ||
615 | |||
616 | /* Comparator mode (D3=0), standby mode (D6=0) */ | ||
617 | gl518_write_value(client, GL518_REG_CONF, (regvalue &= 0x37)); | ||
618 | |||
619 | /* Never interrupts */ | ||
620 | gl518_write_value(client, GL518_REG_MASK, 0x00); | ||
621 | |||
622 | /* Clear status register (D5=1), start (D6=1) */ | ||
623 | gl518_write_value(client, GL518_REG_CONF, 0x20 | regvalue); | ||
624 | gl518_write_value(client, GL518_REG_CONF, 0x40 | regvalue); | ||
625 | } | ||
626 | |||
542 | static int gl518_probe(struct i2c_client *client, | 627 | static int gl518_probe(struct i2c_client *client, |
543 | const struct i2c_device_id *id) | 628 | const struct i2c_device_id *id) |
544 | { | 629 | { |
@@ -584,27 +669,6 @@ exit_remove_files: | |||
584 | return err; | 669 | return err; |
585 | } | 670 | } |
586 | 671 | ||
587 | |||
588 | /* | ||
589 | * Called when we have found a new GL518SM. | ||
590 | * Note that we preserve D4:NoFan2 and D2:beep_enable. | ||
591 | */ | ||
592 | static void gl518_init_client(struct i2c_client *client) | ||
593 | { | ||
594 | /* Make sure we leave D7:Reset untouched */ | ||
595 | u8 regvalue = gl518_read_value(client, GL518_REG_CONF) & 0x7f; | ||
596 | |||
597 | /* Comparator mode (D3=0), standby mode (D6=0) */ | ||
598 | gl518_write_value(client, GL518_REG_CONF, (regvalue &= 0x37)); | ||
599 | |||
600 | /* Never interrupts */ | ||
601 | gl518_write_value(client, GL518_REG_MASK, 0x00); | ||
602 | |||
603 | /* Clear status register (D5=1), start (D6=1) */ | ||
604 | gl518_write_value(client, GL518_REG_CONF, 0x20 | regvalue); | ||
605 | gl518_write_value(client, GL518_REG_CONF, 0x40 | regvalue); | ||
606 | } | ||
607 | |||
608 | static int gl518_remove(struct i2c_client *client) | 672 | static int gl518_remove(struct i2c_client *client) |
609 | { | 673 | { |
610 | struct gl518_data *data = i2c_get_clientdata(client); | 674 | struct gl518_data *data = i2c_get_clientdata(client); |
@@ -617,98 +681,23 @@ static int gl518_remove(struct i2c_client *client) | |||
617 | return 0; | 681 | return 0; |
618 | } | 682 | } |
619 | 683 | ||
620 | /* | 684 | static const struct i2c_device_id gl518_id[] = { |
621 | * Registers 0x07 to 0x0c are word-sized, others are byte-sized | 685 | { "gl518sm", 0 }, |
622 | * GL518 uses a high-byte first convention, which is exactly opposite to | 686 | { } |
623 | * the SMBus standard. | 687 | }; |
624 | */ | 688 | MODULE_DEVICE_TABLE(i2c, gl518_id); |
625 | static int gl518_read_value(struct i2c_client *client, u8 reg) | ||
626 | { | ||
627 | if ((reg >= 0x07) && (reg <= 0x0c)) | ||
628 | return i2c_smbus_read_word_swapped(client, reg); | ||
629 | else | ||
630 | return i2c_smbus_read_byte_data(client, reg); | ||
631 | } | ||
632 | |||
633 | static int gl518_write_value(struct i2c_client *client, u8 reg, u16 value) | ||
634 | { | ||
635 | if ((reg >= 0x07) && (reg <= 0x0c)) | ||
636 | return i2c_smbus_write_word_swapped(client, reg, value); | ||
637 | else | ||
638 | return i2c_smbus_write_byte_data(client, reg, value); | ||
639 | } | ||
640 | |||
641 | static struct gl518_data *gl518_update_device(struct device *dev) | ||
642 | { | ||
643 | struct i2c_client *client = to_i2c_client(dev); | ||
644 | struct gl518_data *data = i2c_get_clientdata(client); | ||
645 | int val; | ||
646 | |||
647 | mutex_lock(&data->update_lock); | ||
648 | |||
649 | if (time_after(jiffies, data->last_updated + HZ + HZ / 2) | ||
650 | || !data->valid) { | ||
651 | dev_dbg(&client->dev, "Starting gl518 update\n"); | ||
652 | |||
653 | data->alarms = gl518_read_value(client, GL518_REG_INT); | ||
654 | data->beep_mask = gl518_read_value(client, GL518_REG_ALARM); | ||
655 | |||
656 | val = gl518_read_value(client, GL518_REG_VDD_LIMIT); | ||
657 | data->voltage_min[0] = val & 0xff; | ||
658 | data->voltage_max[0] = (val >> 8) & 0xff; | ||
659 | val = gl518_read_value(client, GL518_REG_VIN1_LIMIT); | ||
660 | data->voltage_min[1] = val & 0xff; | ||
661 | data->voltage_max[1] = (val >> 8) & 0xff; | ||
662 | val = gl518_read_value(client, GL518_REG_VIN2_LIMIT); | ||
663 | data->voltage_min[2] = val & 0xff; | ||
664 | data->voltage_max[2] = (val >> 8) & 0xff; | ||
665 | val = gl518_read_value(client, GL518_REG_VIN3_LIMIT); | ||
666 | data->voltage_min[3] = val & 0xff; | ||
667 | data->voltage_max[3] = (val >> 8) & 0xff; | ||
668 | |||
669 | val = gl518_read_value(client, GL518_REG_FAN_COUNT); | ||
670 | data->fan_in[0] = (val >> 8) & 0xff; | ||
671 | data->fan_in[1] = val & 0xff; | ||
672 | |||
673 | val = gl518_read_value(client, GL518_REG_FAN_LIMIT); | ||
674 | data->fan_min[0] = (val >> 8) & 0xff; | ||
675 | data->fan_min[1] = val & 0xff; | ||
676 | |||
677 | data->temp_in = gl518_read_value(client, GL518_REG_TEMP_IN); | ||
678 | data->temp_max = | ||
679 | gl518_read_value(client, GL518_REG_TEMP_MAX); | ||
680 | data->temp_hyst = | ||
681 | gl518_read_value(client, GL518_REG_TEMP_HYST); | ||
682 | |||
683 | val = gl518_read_value(client, GL518_REG_MISC); | ||
684 | data->fan_div[0] = (val >> 6) & 0x03; | ||
685 | data->fan_div[1] = (val >> 4) & 0x03; | ||
686 | data->fan_auto1 = (val >> 3) & 0x01; | ||
687 | |||
688 | data->alarms &= data->alarm_mask; | ||
689 | |||
690 | val = gl518_read_value(client, GL518_REG_CONF); | ||
691 | data->beep_enable = (val >> 2) & 1; | ||
692 | |||
693 | if (data->type != gl518sm_r00) { | ||
694 | data->voltage_in[0] = | ||
695 | gl518_read_value(client, GL518_REG_VDD); | ||
696 | data->voltage_in[1] = | ||
697 | gl518_read_value(client, GL518_REG_VIN1); | ||
698 | data->voltage_in[2] = | ||
699 | gl518_read_value(client, GL518_REG_VIN2); | ||
700 | } | ||
701 | data->voltage_in[3] = | ||
702 | gl518_read_value(client, GL518_REG_VIN3); | ||
703 | |||
704 | data->last_updated = jiffies; | ||
705 | data->valid = 1; | ||
706 | } | ||
707 | |||
708 | mutex_unlock(&data->update_lock); | ||
709 | 689 | ||
710 | return data; | 690 | static struct i2c_driver gl518_driver = { |
711 | } | 691 | .class = I2C_CLASS_HWMON, |
692 | .driver = { | ||
693 | .name = "gl518sm", | ||
694 | }, | ||
695 | .probe = gl518_probe, | ||
696 | .remove = gl518_remove, | ||
697 | .id_table = gl518_id, | ||
698 | .detect = gl518_detect, | ||
699 | .address_list = normal_i2c, | ||
700 | }; | ||
712 | 701 | ||
713 | module_i2c_driver(gl518_driver); | 702 | module_i2c_driver(gl518_driver); |
714 | 703 | ||