diff options
author | Guenter Roeck <linux@roeck-us.net> | 2014-04-12 13:14:33 -0400 |
---|---|---|
committer | Guenter Roeck <linux@roeck-us.net> | 2014-05-21 19:02:25 -0400 |
commit | 40089a9fe265cae0669e84c5ee6fafa59949c215 (patch) | |
tree | da44ba7eb7695729aca47a060e08671e5b84b608 /drivers/hwmon | |
parent | b09489ecce58d4ac9362124a5a5590cb92c58c49 (diff) |
hwmon: (max1619) Rearrange code to avoid forward declarations
Forward declarations are unnecessary and easy to avoid, so rearrange
code and drop them.
No functional change.
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
Diffstat (limited to 'drivers/hwmon')
-rw-r--r-- | drivers/hwmon/max1619.c | 158 |
1 files changed, 69 insertions, 89 deletions
diff --git a/drivers/hwmon/max1619.c b/drivers/hwmon/max1619.c index 9a8d7ca9b389..c8a729734df5 100644 --- a/drivers/hwmon/max1619.c +++ b/drivers/hwmon/max1619.c | |||
@@ -72,40 +72,6 @@ static int temp_to_reg(int val) | |||
72 | } | 72 | } |
73 | 73 | ||
74 | /* | 74 | /* |
75 | * Functions declaration | ||
76 | */ | ||
77 | |||
78 | static int max1619_probe(struct i2c_client *client, | ||
79 | const struct i2c_device_id *id); | ||
80 | static int max1619_detect(struct i2c_client *client, | ||
81 | struct i2c_board_info *info); | ||
82 | static void max1619_init_client(struct i2c_client *client); | ||
83 | static int max1619_remove(struct i2c_client *client); | ||
84 | static struct max1619_data *max1619_update_device(struct device *dev); | ||
85 | |||
86 | /* | ||
87 | * Driver data (common to all clients) | ||
88 | */ | ||
89 | |||
90 | static const struct i2c_device_id max1619_id[] = { | ||
91 | { "max1619", 0 }, | ||
92 | { } | ||
93 | }; | ||
94 | MODULE_DEVICE_TABLE(i2c, max1619_id); | ||
95 | |||
96 | static struct i2c_driver max1619_driver = { | ||
97 | .class = I2C_CLASS_HWMON, | ||
98 | .driver = { | ||
99 | .name = "max1619", | ||
100 | }, | ||
101 | .probe = max1619_probe, | ||
102 | .remove = max1619_remove, | ||
103 | .id_table = max1619_id, | ||
104 | .detect = max1619_detect, | ||
105 | .address_list = normal_i2c, | ||
106 | }; | ||
107 | |||
108 | /* | ||
109 | * Client data (each client gets its own) | 75 | * Client data (each client gets its own) |
110 | */ | 76 | */ |
111 | 77 | ||
@@ -123,6 +89,44 @@ struct max1619_data { | |||
123 | u8 alarms; | 89 | u8 alarms; |
124 | }; | 90 | }; |
125 | 91 | ||
92 | static struct max1619_data *max1619_update_device(struct device *dev) | ||
93 | { | ||
94 | struct i2c_client *client = to_i2c_client(dev); | ||
95 | struct max1619_data *data = i2c_get_clientdata(client); | ||
96 | int config; | ||
97 | |||
98 | mutex_lock(&data->update_lock); | ||
99 | |||
100 | if (time_after(jiffies, data->last_updated + HZ * 2) || !data->valid) { | ||
101 | dev_dbg(&client->dev, "Updating max1619 data.\n"); | ||
102 | data->temp_input1 = i2c_smbus_read_byte_data(client, | ||
103 | MAX1619_REG_R_LOCAL_TEMP); | ||
104 | data->temp_input2 = i2c_smbus_read_byte_data(client, | ||
105 | MAX1619_REG_R_REMOTE_TEMP); | ||
106 | data->temp_high2 = i2c_smbus_read_byte_data(client, | ||
107 | MAX1619_REG_R_REMOTE_HIGH); | ||
108 | data->temp_low2 = i2c_smbus_read_byte_data(client, | ||
109 | MAX1619_REG_R_REMOTE_LOW); | ||
110 | data->temp_crit2 = i2c_smbus_read_byte_data(client, | ||
111 | MAX1619_REG_R_REMOTE_CRIT); | ||
112 | data->temp_hyst2 = i2c_smbus_read_byte_data(client, | ||
113 | MAX1619_REG_R_TCRIT_HYST); | ||
114 | data->alarms = i2c_smbus_read_byte_data(client, | ||
115 | MAX1619_REG_R_STATUS); | ||
116 | /* If OVERT polarity is low, reverse alarm bit */ | ||
117 | config = i2c_smbus_read_byte_data(client, MAX1619_REG_R_CONFIG); | ||
118 | if (!(config & 0x20)) | ||
119 | data->alarms ^= 0x02; | ||
120 | |||
121 | data->last_updated = jiffies; | ||
122 | data->valid = 1; | ||
123 | } | ||
124 | |||
125 | mutex_unlock(&data->update_lock); | ||
126 | |||
127 | return data; | ||
128 | } | ||
129 | |||
126 | /* | 130 | /* |
127 | * Sysfs stuff | 131 | * Sysfs stuff |
128 | */ | 132 | */ |
@@ -216,10 +220,6 @@ static const struct attribute_group max1619_group = { | |||
216 | .attrs = max1619_attributes, | 220 | .attrs = max1619_attributes, |
217 | }; | 221 | }; |
218 | 222 | ||
219 | /* | ||
220 | * Real code | ||
221 | */ | ||
222 | |||
223 | /* Return 0 if detection is successful, -ENODEV otherwise */ | 223 | /* Return 0 if detection is successful, -ENODEV otherwise */ |
224 | static int max1619_detect(struct i2c_client *client, | 224 | static int max1619_detect(struct i2c_client *client, |
225 | struct i2c_board_info *info) | 225 | struct i2c_board_info *info) |
@@ -256,6 +256,21 @@ static int max1619_detect(struct i2c_client *client, | |||
256 | return 0; | 256 | return 0; |
257 | } | 257 | } |
258 | 258 | ||
259 | static void max1619_init_client(struct i2c_client *client) | ||
260 | { | ||
261 | u8 config; | ||
262 | |||
263 | /* | ||
264 | * Start the conversions. | ||
265 | */ | ||
266 | i2c_smbus_write_byte_data(client, MAX1619_REG_W_CONVRATE, | ||
267 | 5); /* 2 Hz */ | ||
268 | config = i2c_smbus_read_byte_data(client, MAX1619_REG_R_CONFIG); | ||
269 | if (config & 0x40) | ||
270 | i2c_smbus_write_byte_data(client, MAX1619_REG_W_CONFIG, | ||
271 | config & 0xBF); /* run */ | ||
272 | } | ||
273 | |||
259 | static int max1619_probe(struct i2c_client *new_client, | 274 | static int max1619_probe(struct i2c_client *new_client, |
260 | const struct i2c_device_id *id) | 275 | const struct i2c_device_id *id) |
261 | { | 276 | { |
@@ -291,21 +306,6 @@ exit_remove_files: | |||
291 | return err; | 306 | return err; |
292 | } | 307 | } |
293 | 308 | ||
294 | static void max1619_init_client(struct i2c_client *client) | ||
295 | { | ||
296 | u8 config; | ||
297 | |||
298 | /* | ||
299 | * Start the conversions. | ||
300 | */ | ||
301 | i2c_smbus_write_byte_data(client, MAX1619_REG_W_CONVRATE, | ||
302 | 5); /* 2 Hz */ | ||
303 | config = i2c_smbus_read_byte_data(client, MAX1619_REG_R_CONFIG); | ||
304 | if (config & 0x40) | ||
305 | i2c_smbus_write_byte_data(client, MAX1619_REG_W_CONFIG, | ||
306 | config & 0xBF); /* run */ | ||
307 | } | ||
308 | |||
309 | static int max1619_remove(struct i2c_client *client) | 309 | static int max1619_remove(struct i2c_client *client) |
310 | { | 310 | { |
311 | struct max1619_data *data = i2c_get_clientdata(client); | 311 | struct max1619_data *data = i2c_get_clientdata(client); |
@@ -316,43 +316,23 @@ static int max1619_remove(struct i2c_client *client) | |||
316 | return 0; | 316 | return 0; |
317 | } | 317 | } |
318 | 318 | ||
319 | static struct max1619_data *max1619_update_device(struct device *dev) | 319 | static const struct i2c_device_id max1619_id[] = { |
320 | { | 320 | { "max1619", 0 }, |
321 | struct i2c_client *client = to_i2c_client(dev); | 321 | { } |
322 | struct max1619_data *data = i2c_get_clientdata(client); | 322 | }; |
323 | int config; | 323 | MODULE_DEVICE_TABLE(i2c, max1619_id); |
324 | |||
325 | mutex_lock(&data->update_lock); | ||
326 | |||
327 | if (time_after(jiffies, data->last_updated + HZ * 2) || !data->valid) { | ||
328 | dev_dbg(&client->dev, "Updating max1619 data.\n"); | ||
329 | data->temp_input1 = i2c_smbus_read_byte_data(client, | ||
330 | MAX1619_REG_R_LOCAL_TEMP); | ||
331 | data->temp_input2 = i2c_smbus_read_byte_data(client, | ||
332 | MAX1619_REG_R_REMOTE_TEMP); | ||
333 | data->temp_high2 = i2c_smbus_read_byte_data(client, | ||
334 | MAX1619_REG_R_REMOTE_HIGH); | ||
335 | data->temp_low2 = i2c_smbus_read_byte_data(client, | ||
336 | MAX1619_REG_R_REMOTE_LOW); | ||
337 | data->temp_crit2 = i2c_smbus_read_byte_data(client, | ||
338 | MAX1619_REG_R_REMOTE_CRIT); | ||
339 | data->temp_hyst2 = i2c_smbus_read_byte_data(client, | ||
340 | MAX1619_REG_R_TCRIT_HYST); | ||
341 | data->alarms = i2c_smbus_read_byte_data(client, | ||
342 | MAX1619_REG_R_STATUS); | ||
343 | /* If OVERT polarity is low, reverse alarm bit */ | ||
344 | config = i2c_smbus_read_byte_data(client, MAX1619_REG_R_CONFIG); | ||
345 | if (!(config & 0x20)) | ||
346 | data->alarms ^= 0x02; | ||
347 | |||
348 | data->last_updated = jiffies; | ||
349 | data->valid = 1; | ||
350 | } | ||
351 | |||
352 | mutex_unlock(&data->update_lock); | ||
353 | 324 | ||
354 | return data; | 325 | static struct i2c_driver max1619_driver = { |
355 | } | 326 | .class = I2C_CLASS_HWMON, |
327 | .driver = { | ||
328 | .name = "max1619", | ||
329 | }, | ||
330 | .probe = max1619_probe, | ||
331 | .remove = max1619_remove, | ||
332 | .id_table = max1619_id, | ||
333 | .detect = max1619_detect, | ||
334 | .address_list = normal_i2c, | ||
335 | }; | ||
356 | 336 | ||
357 | module_i2c_driver(max1619_driver); | 337 | module_i2c_driver(max1619_driver); |
358 | 338 | ||