summaryrefslogtreecommitdiffstats
path: root/drivers/hwmon/lm77.c
diff options
context:
space:
mode:
authorGuenter Roeck <linux@roeck-us.net>2014-04-12 11:45:20 -0400
committerGuenter Roeck <linux@roeck-us.net>2014-05-21 19:02:20 -0400
commit9f9edcd4c32bf33255f8db7329c78a99baa94585 (patch)
tree4e172035d675f619c3b26bf8b2cec5a0427d169c /drivers/hwmon/lm77.c
parentd9ee59751e616840e98ef0896efb43486e0f54d1 (diff)
hwmon: (lm77) Rearrange code to no longer require forward declarations
Forward declarations are easy to avoid and unnecessary. Rearrange code to avoid it. No functional change. Acked-by: Jean Delvare <jdelvare@suse.de> Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'drivers/hwmon/lm77.c')
-rw-r--r--drivers/hwmon/lm77.c173
1 files changed, 81 insertions, 92 deletions
diff --git a/drivers/hwmon/lm77.c b/drivers/hwmon/lm77.c
index 642216285814..4cd8a513c47b 100644
--- a/drivers/hwmon/lm77.c
+++ b/drivers/hwmon/lm77.c
@@ -57,36 +57,6 @@ struct lm77_data {
57 u8 alarms; 57 u8 alarms;
58}; 58};
59 59
60static int lm77_probe(struct i2c_client *client,
61 const struct i2c_device_id *id);
62static int lm77_detect(struct i2c_client *client, struct i2c_board_info *info);
63static void lm77_init_client(struct i2c_client *client);
64static int lm77_remove(struct i2c_client *client);
65static u16 lm77_read_value(struct i2c_client *client, u8 reg);
66static int lm77_write_value(struct i2c_client *client, u8 reg, u16 value);
67
68static struct lm77_data *lm77_update_device(struct device *dev);
69
70
71static const struct i2c_device_id lm77_id[] = {
72 { "lm77", 0 },
73 { }
74};
75MODULE_DEVICE_TABLE(i2c, lm77_id);
76
77/* This is the driver that will be inserted */
78static struct i2c_driver lm77_driver = {
79 .class = I2C_CLASS_HWMON,
80 .driver = {
81 .name = "lm77",
82 },
83 .probe = lm77_probe,
84 .remove = lm77_remove,
85 .id_table = lm77_id,
86 .detect = lm77_detect,
87 .address_list = normal_i2c,
88};
89
90/* straight from the datasheet */ 60/* straight from the datasheet */
91#define LM77_TEMP_MIN (-55000) 61#define LM77_TEMP_MIN (-55000)
92#define LM77_TEMP_MAX 125000 62#define LM77_TEMP_MAX 125000
@@ -106,6 +76,62 @@ static inline int LM77_TEMP_FROM_REG(s16 reg)
106 return (reg / 8) * 500; 76 return (reg / 8) * 500;
107} 77}
108 78
79/*
80 * All registers are word-sized, except for the configuration register.
81 * The LM77 uses the high-byte first convention.
82 */
83static u16 lm77_read_value(struct i2c_client *client, u8 reg)
84{
85 if (reg == LM77_REG_CONF)
86 return i2c_smbus_read_byte_data(client, reg);
87 else
88 return i2c_smbus_read_word_swapped(client, reg);
89}
90
91static int lm77_write_value(struct i2c_client *client, u8 reg, u16 value)
92{
93 if (reg == LM77_REG_CONF)
94 return i2c_smbus_write_byte_data(client, reg, value);
95 else
96 return i2c_smbus_write_word_swapped(client, reg, value);
97}
98
99static struct lm77_data *lm77_update_device(struct device *dev)
100{
101 struct i2c_client *client = to_i2c_client(dev);
102 struct lm77_data *data = i2c_get_clientdata(client);
103
104 mutex_lock(&data->update_lock);
105
106 if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
107 || !data->valid) {
108 dev_dbg(&client->dev, "Starting lm77 update\n");
109 data->temp_input =
110 LM77_TEMP_FROM_REG(lm77_read_value(client,
111 LM77_REG_TEMP));
112 data->temp_hyst =
113 LM77_TEMP_FROM_REG(lm77_read_value(client,
114 LM77_REG_TEMP_HYST));
115 data->temp_crit =
116 LM77_TEMP_FROM_REG(lm77_read_value(client,
117 LM77_REG_TEMP_CRIT));
118 data->temp_min =
119 LM77_TEMP_FROM_REG(lm77_read_value(client,
120 LM77_REG_TEMP_MIN));
121 data->temp_max =
122 LM77_TEMP_FROM_REG(lm77_read_value(client,
123 LM77_REG_TEMP_MAX));
124 data->alarms =
125 lm77_read_value(client, LM77_REG_TEMP) & 0x0007;
126 data->last_updated = jiffies;
127 data->valid = 1;
128 }
129
130 mutex_unlock(&data->update_lock);
131
132 return data;
133}
134
109/* sysfs stuff */ 135/* sysfs stuff */
110 136
111/* read routines for temperature limits */ 137/* read routines for temperature limits */
@@ -333,6 +359,14 @@ static int lm77_detect(struct i2c_client *client, struct i2c_board_info *info)
333 return 0; 359 return 0;
334} 360}
335 361
362static void lm77_init_client(struct i2c_client *client)
363{
364 /* Initialize the LM77 chip - turn off shutdown mode */
365 int conf = lm77_read_value(client, LM77_REG_CONF);
366 if (conf & 1)
367 lm77_write_value(client, LM77_REG_CONF, conf & 0xfe);
368}
369
336static int lm77_probe(struct i2c_client *client, const struct i2c_device_id *id) 370static int lm77_probe(struct i2c_client *client, const struct i2c_device_id *id)
337{ 371{
338 struct device *dev = &client->dev; 372 struct device *dev = &client->dev;
@@ -375,69 +409,24 @@ static int lm77_remove(struct i2c_client *client)
375 return 0; 409 return 0;
376} 410}
377 411
378/* 412static const struct i2c_device_id lm77_id[] = {
379 * All registers are word-sized, except for the configuration register. 413 { "lm77", 0 },
380 * The LM77 uses the high-byte first convention. 414 { }
381 */ 415};
382static u16 lm77_read_value(struct i2c_client *client, u8 reg) 416MODULE_DEVICE_TABLE(i2c, lm77_id);
383{
384 if (reg == LM77_REG_CONF)
385 return i2c_smbus_read_byte_data(client, reg);
386 else
387 return i2c_smbus_read_word_swapped(client, reg);
388}
389
390static int lm77_write_value(struct i2c_client *client, u8 reg, u16 value)
391{
392 if (reg == LM77_REG_CONF)
393 return i2c_smbus_write_byte_data(client, reg, value);
394 else
395 return i2c_smbus_write_word_swapped(client, reg, value);
396}
397
398static void lm77_init_client(struct i2c_client *client)
399{
400 /* Initialize the LM77 chip - turn off shutdown mode */
401 int conf = lm77_read_value(client, LM77_REG_CONF);
402 if (conf & 1)
403 lm77_write_value(client, LM77_REG_CONF, conf & 0xfe);
404}
405
406static struct lm77_data *lm77_update_device(struct device *dev)
407{
408 struct i2c_client *client = to_i2c_client(dev);
409 struct lm77_data *data = i2c_get_clientdata(client);
410
411 mutex_lock(&data->update_lock);
412
413 if (time_after(jiffies, data->last_updated + HZ + HZ / 2)
414 || !data->valid) {
415 dev_dbg(&client->dev, "Starting lm77 update\n");
416 data->temp_input =
417 LM77_TEMP_FROM_REG(lm77_read_value(client,
418 LM77_REG_TEMP));
419 data->temp_hyst =
420 LM77_TEMP_FROM_REG(lm77_read_value(client,
421 LM77_REG_TEMP_HYST));
422 data->temp_crit =
423 LM77_TEMP_FROM_REG(lm77_read_value(client,
424 LM77_REG_TEMP_CRIT));
425 data->temp_min =
426 LM77_TEMP_FROM_REG(lm77_read_value(client,
427 LM77_REG_TEMP_MIN));
428 data->temp_max =
429 LM77_TEMP_FROM_REG(lm77_read_value(client,
430 LM77_REG_TEMP_MAX));
431 data->alarms =
432 lm77_read_value(client, LM77_REG_TEMP) & 0x0007;
433 data->last_updated = jiffies;
434 data->valid = 1;
435 }
436
437 mutex_unlock(&data->update_lock);
438 417
439 return data; 418/* This is the driver that will be inserted */
440} 419static struct i2c_driver lm77_driver = {
420 .class = I2C_CLASS_HWMON,
421 .driver = {
422 .name = "lm77",
423 },
424 .probe = lm77_probe,
425 .remove = lm77_remove,
426 .id_table = lm77_id,
427 .detect = lm77_detect,
428 .address_list = normal_i2c,
429};
441 430
442module_i2c_driver(lm77_driver); 431module_i2c_driver(lm77_driver);
443 432