diff options
author | Jean Delvare <khali@linux-fr.org> | 2009-03-30 15:46:40 -0400 |
---|---|---|
committer | Jean Delvare <khali@linux-fr.org> | 2009-03-30 15:46:40 -0400 |
commit | 9202add67454c6a6f9508f41e733edce705dc56e (patch) | |
tree | c95085164215c9374e838f1bf3f6051b74d99441 | |
parent | 0d34fb8e93ceba7b6dad0062dbb4a0813bacd75b (diff) |
hwmon: (ds1621) Reorder code statements
Reorder the ds1621 driver code so that we can get rid of forward
function declarations.
Signed-off-by: Jean Delvare <khali@linux-fr.org>
Cc: Aurelien Jarno <aurelien@aurel32.net>
-rw-r--r-- | drivers/hwmon/ds1621.c | 123 |
1 files changed, 57 insertions, 66 deletions
diff --git a/drivers/hwmon/ds1621.c b/drivers/hwmon/ds1621.c index 7415381601c3..e688798e115f 100644 --- a/drivers/hwmon/ds1621.c +++ b/drivers/hwmon/ds1621.c | |||
@@ -81,34 +81,6 @@ struct ds1621_data { | |||
81 | u8 conf; /* Register encoding, combined */ | 81 | u8 conf; /* Register encoding, combined */ |
82 | }; | 82 | }; |
83 | 83 | ||
84 | static int ds1621_probe(struct i2c_client *client, | ||
85 | const struct i2c_device_id *id); | ||
86 | static int ds1621_detect(struct i2c_client *client, int kind, | ||
87 | struct i2c_board_info *info); | ||
88 | static void ds1621_init_client(struct i2c_client *client); | ||
89 | static int ds1621_remove(struct i2c_client *client); | ||
90 | static struct ds1621_data *ds1621_update_client(struct device *dev); | ||
91 | |||
92 | static const struct i2c_device_id ds1621_id[] = { | ||
93 | { "ds1621", ds1621 }, | ||
94 | { "ds1625", ds1621 }, | ||
95 | { } | ||
96 | }; | ||
97 | MODULE_DEVICE_TABLE(i2c, ds1621_id); | ||
98 | |||
99 | /* This is the driver that will be inserted */ | ||
100 | static struct i2c_driver ds1621_driver = { | ||
101 | .class = I2C_CLASS_HWMON, | ||
102 | .driver = { | ||
103 | .name = "ds1621", | ||
104 | }, | ||
105 | .probe = ds1621_probe, | ||
106 | .remove = ds1621_remove, | ||
107 | .id_table = ds1621_id, | ||
108 | .detect = ds1621_detect, | ||
109 | .address_data = &addr_data, | ||
110 | }; | ||
111 | |||
112 | /* All registers are word-sized, except for the configuration register. | 84 | /* All registers are word-sized, except for the configuration register. |
113 | DS1621 uses a high-byte first convention, which is exactly opposite to | 85 | DS1621 uses a high-byte first convention, which is exactly opposite to |
114 | the SMBus standard. */ | 86 | the SMBus standard. */ |
@@ -146,6 +118,45 @@ static void ds1621_init_client(struct i2c_client *client) | |||
146 | i2c_smbus_write_byte(client, DS1621_COM_START); | 118 | i2c_smbus_write_byte(client, DS1621_COM_START); |
147 | } | 119 | } |
148 | 120 | ||
121 | static struct ds1621_data *ds1621_update_client(struct device *dev) | ||
122 | { | ||
123 | struct i2c_client *client = to_i2c_client(dev); | ||
124 | struct ds1621_data *data = i2c_get_clientdata(client); | ||
125 | u8 new_conf; | ||
126 | |||
127 | mutex_lock(&data->update_lock); | ||
128 | |||
129 | if (time_after(jiffies, data->last_updated + HZ + HZ / 2) | ||
130 | || !data->valid) { | ||
131 | int i; | ||
132 | |||
133 | dev_dbg(&client->dev, "Starting ds1621 update\n"); | ||
134 | |||
135 | data->conf = ds1621_read_value(client, DS1621_REG_CONF); | ||
136 | |||
137 | for (i = 0; i < ARRAY_SIZE(data->temp); i++) | ||
138 | data->temp[i] = ds1621_read_value(client, | ||
139 | DS1621_REG_TEMP[i]); | ||
140 | |||
141 | /* reset alarms if necessary */ | ||
142 | new_conf = data->conf; | ||
143 | if (data->temp[0] > data->temp[1]) /* input > min */ | ||
144 | new_conf &= ~DS1621_ALARM_TEMP_LOW; | ||
145 | if (data->temp[0] < data->temp[2]) /* input < max */ | ||
146 | new_conf &= ~DS1621_ALARM_TEMP_HIGH; | ||
147 | if (data->conf != new_conf) | ||
148 | ds1621_write_value(client, DS1621_REG_CONF, | ||
149 | new_conf); | ||
150 | |||
151 | data->last_updated = jiffies; | ||
152 | data->valid = 1; | ||
153 | } | ||
154 | |||
155 | mutex_unlock(&data->update_lock); | ||
156 | |||
157 | return data; | ||
158 | } | ||
159 | |||
149 | static ssize_t show_temp(struct device *dev, struct device_attribute *da, | 160 | static ssize_t show_temp(struct device *dev, struct device_attribute *da, |
150 | char *buf) | 161 | char *buf) |
151 | { | 162 | { |
@@ -294,45 +305,25 @@ static int ds1621_remove(struct i2c_client *client) | |||
294 | return 0; | 305 | return 0; |
295 | } | 306 | } |
296 | 307 | ||
308 | static const struct i2c_device_id ds1621_id[] = { | ||
309 | { "ds1621", ds1621 }, | ||
310 | { "ds1625", ds1621 }, | ||
311 | { } | ||
312 | }; | ||
313 | MODULE_DEVICE_TABLE(i2c, ds1621_id); | ||
297 | 314 | ||
298 | static struct ds1621_data *ds1621_update_client(struct device *dev) | 315 | /* This is the driver that will be inserted */ |
299 | { | 316 | static struct i2c_driver ds1621_driver = { |
300 | struct i2c_client *client = to_i2c_client(dev); | 317 | .class = I2C_CLASS_HWMON, |
301 | struct ds1621_data *data = i2c_get_clientdata(client); | 318 | .driver = { |
302 | u8 new_conf; | 319 | .name = "ds1621", |
303 | 320 | }, | |
304 | mutex_lock(&data->update_lock); | 321 | .probe = ds1621_probe, |
305 | 322 | .remove = ds1621_remove, | |
306 | if (time_after(jiffies, data->last_updated + HZ + HZ / 2) | 323 | .id_table = ds1621_id, |
307 | || !data->valid) { | 324 | .detect = ds1621_detect, |
308 | int i; | 325 | .address_data = &addr_data, |
309 | 326 | }; | |
310 | dev_dbg(&client->dev, "Starting ds1621 update\n"); | ||
311 | |||
312 | data->conf = ds1621_read_value(client, DS1621_REG_CONF); | ||
313 | |||
314 | for (i = 0; i < ARRAY_SIZE(data->temp); i++) | ||
315 | data->temp[i] = ds1621_read_value(client, | ||
316 | DS1621_REG_TEMP[i]); | ||
317 | |||
318 | /* reset alarms if necessary */ | ||
319 | new_conf = data->conf; | ||
320 | if (data->temp[0] > data->temp[1]) /* input > min */ | ||
321 | new_conf &= ~DS1621_ALARM_TEMP_LOW; | ||
322 | if (data->temp[0] < data->temp[2]) /* input < max */ | ||
323 | new_conf &= ~DS1621_ALARM_TEMP_HIGH; | ||
324 | if (data->conf != new_conf) | ||
325 | ds1621_write_value(client, DS1621_REG_CONF, | ||
326 | new_conf); | ||
327 | |||
328 | data->last_updated = jiffies; | ||
329 | data->valid = 1; | ||
330 | } | ||
331 | |||
332 | mutex_unlock(&data->update_lock); | ||
333 | |||
334 | return data; | ||
335 | } | ||
336 | 327 | ||
337 | static int __init ds1621_init(void) | 328 | static int __init ds1621_init(void) |
338 | { | 329 | { |