diff options
author | Guenter Roeck <linux@roeck-us.net> | 2014-04-16 00:28:15 -0400 |
---|---|---|
committer | Guenter Roeck <linux@roeck-us.net> | 2014-05-21 19:02:24 -0400 |
commit | d397276b0c833b0089cb19d94fbc35a43ada58a7 (patch) | |
tree | 20a873ae6c1b15d6046d2a50aa9d022cc12a50bf /drivers/hwmon/jc42.c | |
parent | 51585befb4c3c629980b5b252a0caaeeac3b7d73 (diff) |
hwmon: (jc42) Rearrange code to avoid forward declarations
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'drivers/hwmon/jc42.c')
-rw-r--r-- | drivers/hwmon/jc42.c | 186 |
1 files changed, 89 insertions, 97 deletions
diff --git a/drivers/hwmon/jc42.c b/drivers/hwmon/jc42.c index 6013611e4f21..ba1a3f781fde 100644 --- a/drivers/hwmon/jc42.c +++ b/drivers/hwmon/jc42.c | |||
@@ -176,65 +176,6 @@ struct jc42_data { | |||
176 | u16 temp_max; | 176 | u16 temp_max; |
177 | }; | 177 | }; |
178 | 178 | ||
179 | static int jc42_probe(struct i2c_client *client, | ||
180 | const struct i2c_device_id *id); | ||
181 | static int jc42_detect(struct i2c_client *client, struct i2c_board_info *info); | ||
182 | static int jc42_remove(struct i2c_client *client); | ||
183 | |||
184 | static struct jc42_data *jc42_update_device(struct device *dev); | ||
185 | |||
186 | static const struct i2c_device_id jc42_id[] = { | ||
187 | { "jc42", 0 }, | ||
188 | { } | ||
189 | }; | ||
190 | MODULE_DEVICE_TABLE(i2c, jc42_id); | ||
191 | |||
192 | #ifdef CONFIG_PM | ||
193 | |||
194 | static int jc42_suspend(struct device *dev) | ||
195 | { | ||
196 | struct jc42_data *data = dev_get_drvdata(dev); | ||
197 | |||
198 | data->config |= JC42_CFG_SHUTDOWN; | ||
199 | i2c_smbus_write_word_swapped(data->client, JC42_REG_CONFIG, | ||
200 | data->config); | ||
201 | return 0; | ||
202 | } | ||
203 | |||
204 | static int jc42_resume(struct device *dev) | ||
205 | { | ||
206 | struct jc42_data *data = dev_get_drvdata(dev); | ||
207 | |||
208 | data->config &= ~JC42_CFG_SHUTDOWN; | ||
209 | i2c_smbus_write_word_swapped(data->client, JC42_REG_CONFIG, | ||
210 | data->config); | ||
211 | return 0; | ||
212 | } | ||
213 | |||
214 | static const struct dev_pm_ops jc42_dev_pm_ops = { | ||
215 | .suspend = jc42_suspend, | ||
216 | .resume = jc42_resume, | ||
217 | }; | ||
218 | |||
219 | #define JC42_DEV_PM_OPS (&jc42_dev_pm_ops) | ||
220 | #else | ||
221 | #define JC42_DEV_PM_OPS NULL | ||
222 | #endif /* CONFIG_PM */ | ||
223 | |||
224 | /* This is the driver that will be inserted */ | ||
225 | static struct i2c_driver jc42_driver = { | ||
226 | .class = I2C_CLASS_SPD, | ||
227 | .driver = { | ||
228 | .name = "jc42", | ||
229 | .pm = JC42_DEV_PM_OPS, | ||
230 | }, | ||
231 | .probe = jc42_probe, | ||
232 | .remove = jc42_remove, | ||
233 | .id_table = jc42_id, | ||
234 | .detect = jc42_detect, | ||
235 | .address_list = normal_i2c, | ||
236 | }; | ||
237 | |||
238 | #define JC42_TEMP_MIN_EXTENDED (-40000) | 179 | #define JC42_TEMP_MIN_EXTENDED (-40000) |
239 | #define JC42_TEMP_MIN 0 | 180 | #define JC42_TEMP_MIN 0 |
240 | #define JC42_TEMP_MAX 125000 | 181 | #define JC42_TEMP_MAX 125000 |
@@ -261,6 +202,53 @@ static int jc42_temp_from_reg(s16 reg) | |||
261 | return reg * 125 / 2; | 202 | return reg * 125 / 2; |
262 | } | 203 | } |
263 | 204 | ||
205 | static struct jc42_data *jc42_update_device(struct device *dev) | ||
206 | { | ||
207 | struct jc42_data *data = dev_get_drvdata(dev); | ||
208 | struct i2c_client *client = data->client; | ||
209 | struct jc42_data *ret = data; | ||
210 | int val; | ||
211 | |||
212 | mutex_lock(&data->update_lock); | ||
213 | |||
214 | if (time_after(jiffies, data->last_updated + HZ) || !data->valid) { | ||
215 | val = i2c_smbus_read_word_swapped(client, JC42_REG_TEMP); | ||
216 | if (val < 0) { | ||
217 | ret = ERR_PTR(val); | ||
218 | goto abort; | ||
219 | } | ||
220 | data->temp_input = val; | ||
221 | |||
222 | val = i2c_smbus_read_word_swapped(client, | ||
223 | JC42_REG_TEMP_CRITICAL); | ||
224 | if (val < 0) { | ||
225 | ret = ERR_PTR(val); | ||
226 | goto abort; | ||
227 | } | ||
228 | data->temp_crit = val; | ||
229 | |||
230 | val = i2c_smbus_read_word_swapped(client, JC42_REG_TEMP_LOWER); | ||
231 | if (val < 0) { | ||
232 | ret = ERR_PTR(val); | ||
233 | goto abort; | ||
234 | } | ||
235 | data->temp_min = val; | ||
236 | |||
237 | val = i2c_smbus_read_word_swapped(client, JC42_REG_TEMP_UPPER); | ||
238 | if (val < 0) { | ||
239 | ret = ERR_PTR(val); | ||
240 | goto abort; | ||
241 | } | ||
242 | data->temp_max = val; | ||
243 | |||
244 | data->last_updated = jiffies; | ||
245 | data->valid = true; | ||
246 | } | ||
247 | abort: | ||
248 | mutex_unlock(&data->update_lock); | ||
249 | return ret; | ||
250 | } | ||
251 | |||
264 | /* sysfs stuff */ | 252 | /* sysfs stuff */ |
265 | 253 | ||
266 | /* read routines for temperature limits */ | 254 | /* read routines for temperature limits */ |
@@ -537,52 +525,56 @@ static int jc42_remove(struct i2c_client *client) | |||
537 | return 0; | 525 | return 0; |
538 | } | 526 | } |
539 | 527 | ||
540 | static struct jc42_data *jc42_update_device(struct device *dev) | 528 | #ifdef CONFIG_PM |
529 | |||
530 | static int jc42_suspend(struct device *dev) | ||
541 | { | 531 | { |
542 | struct jc42_data *data = dev_get_drvdata(dev); | 532 | struct jc42_data *data = dev_get_drvdata(dev); |
543 | struct i2c_client *client = data->client; | ||
544 | struct jc42_data *ret = data; | ||
545 | int val; | ||
546 | 533 | ||
547 | mutex_lock(&data->update_lock); | 534 | data->config |= JC42_CFG_SHUTDOWN; |
535 | i2c_smbus_write_word_swapped(data->client, JC42_REG_CONFIG, | ||
536 | data->config); | ||
537 | return 0; | ||
538 | } | ||
548 | 539 | ||
549 | if (time_after(jiffies, data->last_updated + HZ) || !data->valid) { | 540 | static int jc42_resume(struct device *dev) |
550 | val = i2c_smbus_read_word_swapped(client, JC42_REG_TEMP); | 541 | { |
551 | if (val < 0) { | 542 | struct jc42_data *data = dev_get_drvdata(dev); |
552 | ret = ERR_PTR(val); | ||
553 | goto abort; | ||
554 | } | ||
555 | data->temp_input = val; | ||
556 | 543 | ||
557 | val = i2c_smbus_read_word_swapped(client, | 544 | data->config &= ~JC42_CFG_SHUTDOWN; |
558 | JC42_REG_TEMP_CRITICAL); | 545 | i2c_smbus_write_word_swapped(data->client, JC42_REG_CONFIG, |
559 | if (val < 0) { | 546 | data->config); |
560 | ret = ERR_PTR(val); | 547 | return 0; |
561 | goto abort; | 548 | } |
562 | } | ||
563 | data->temp_crit = val; | ||
564 | 549 | ||
565 | val = i2c_smbus_read_word_swapped(client, JC42_REG_TEMP_LOWER); | 550 | static const struct dev_pm_ops jc42_dev_pm_ops = { |
566 | if (val < 0) { | 551 | .suspend = jc42_suspend, |
567 | ret = ERR_PTR(val); | 552 | .resume = jc42_resume, |
568 | goto abort; | 553 | }; |
569 | } | ||
570 | data->temp_min = val; | ||
571 | 554 | ||
572 | val = i2c_smbus_read_word_swapped(client, JC42_REG_TEMP_UPPER); | 555 | #define JC42_DEV_PM_OPS (&jc42_dev_pm_ops) |
573 | if (val < 0) { | 556 | #else |
574 | ret = ERR_PTR(val); | 557 | #define JC42_DEV_PM_OPS NULL |
575 | goto abort; | 558 | #endif /* CONFIG_PM */ |
576 | } | ||
577 | data->temp_max = val; | ||
578 | 559 | ||
579 | data->last_updated = jiffies; | 560 | static const struct i2c_device_id jc42_id[] = { |
580 | data->valid = true; | 561 | { "jc42", 0 }, |
581 | } | 562 | { } |
582 | abort: | 563 | }; |
583 | mutex_unlock(&data->update_lock); | 564 | MODULE_DEVICE_TABLE(i2c, jc42_id); |
584 | return ret; | 565 | |
585 | } | 566 | static struct i2c_driver jc42_driver = { |
567 | .class = I2C_CLASS_SPD, | ||
568 | .driver = { | ||
569 | .name = "jc42", | ||
570 | .pm = JC42_DEV_PM_OPS, | ||
571 | }, | ||
572 | .probe = jc42_probe, | ||
573 | .remove = jc42_remove, | ||
574 | .id_table = jc42_id, | ||
575 | .detect = jc42_detect, | ||
576 | .address_list = normal_i2c, | ||
577 | }; | ||
586 | 578 | ||
587 | module_i2c_driver(jc42_driver); | 579 | module_i2c_driver(jc42_driver); |
588 | 580 | ||