aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/hwmon
diff options
context:
space:
mode:
authorJean Delvare <khali@linux-fr.org>2007-06-09 10:11:15 -0400
committerMark M. Hoffman <mhoffman@lightlink.com>2007-07-19 14:22:11 -0400
commit75819f01af77d6d70abc7777e450a0848a9b898b (patch)
treef61ea83be425f7a3416c2766a867dbfabb8ffbcf /drivers/hwmon
parente4a7167f82130fa95005097797bb1ec9c76201fd (diff)
hwmon/ds1621: Minor cleanups
* Discard comments which do not apply or are redundant. * Remove a few useless instructions. * Rename new_client to just client. Signed-off-by: Jean Delvare <khali@linux-fr.org> Cc: Aurelien Jarno <aurelien@aurel32.net>
Diffstat (limited to 'drivers/hwmon')
-rw-r--r--drivers/hwmon/ds1621.c51
1 files changed, 19 insertions, 32 deletions
diff --git a/drivers/hwmon/ds1621.c b/drivers/hwmon/ds1621.c
index d5ac422d73b2..ccf0fe617e5f 100644
--- a/drivers/hwmon/ds1621.c
+++ b/drivers/hwmon/ds1621.c
@@ -63,10 +63,7 @@ MODULE_PARM_DESC(polarity, "Output's polarity: 0 = active high, 1 = active low")
63#define DS1621_ALARM_TEMP_HIGH 0x40 63#define DS1621_ALARM_TEMP_HIGH 0x40
64#define DS1621_ALARM_TEMP_LOW 0x20 64#define DS1621_ALARM_TEMP_LOW 0x20
65 65
66/* Conversions. Rounding and limit checking is only done on the TO_REG 66/* Conversions */
67 variants. Note that you should be a bit careful with which arguments
68 these macros are called: arguments may be evaluated more than once.
69 Fixing this is just not worth it. */
70#define ALARMS_FROM_REG(val) ((val) & \ 67#define ALARMS_FROM_REG(val) ((val) & \
71 (DS1621_ALARM_TEMP_HIGH | DS1621_ALARM_TEMP_LOW)) 68 (DS1621_ALARM_TEMP_HIGH | DS1621_ALARM_TEMP_LOW))
72 69
@@ -101,7 +98,7 @@ static struct i2c_driver ds1621_driver = {
101 98
102/* All registers are word-sized, except for the configuration register. 99/* All registers are word-sized, except for the configuration register.
103 DS1621 uses a high-byte first convention, which is exactly opposite to 100 DS1621 uses a high-byte first convention, which is exactly opposite to
104 the usual practice. */ 101 the SMBus standard. */
105static int ds1621_read_value(struct i2c_client *client, u8 reg) 102static int ds1621_read_value(struct i2c_client *client, u8 reg)
106{ 103{
107 if (reg == DS1621_REG_CONF) 104 if (reg == DS1621_REG_CONF)
@@ -110,9 +107,6 @@ static int ds1621_read_value(struct i2c_client *client, u8 reg)
110 return swab16(i2c_smbus_read_word_data(client, reg)); 107 return swab16(i2c_smbus_read_word_data(client, reg));
111} 108}
112 109
113/* All registers are word-sized, except for the configuration register.
114 DS1621 uses a high-byte first convention, which is exactly opposite to
115 the usual practice. */
116static int ds1621_write_value(struct i2c_client *client, u8 reg, u16 value) 110static int ds1621_write_value(struct i2c_client *client, u8 reg, u16 value)
117{ 111{
118 if (reg == DS1621_REG_CONF) 112 if (reg == DS1621_REG_CONF)
@@ -204,7 +198,7 @@ static int ds1621_detect(struct i2c_adapter *adapter, int address,
204 int kind) 198 int kind)
205{ 199{
206 int conf, temp; 200 int conf, temp;
207 struct i2c_client *new_client; 201 struct i2c_client *client;
208 struct ds1621_data *data; 202 struct ds1621_data *data;
209 int err = 0; 203 int err = 0;
210 204
@@ -221,55 +215,48 @@ static int ds1621_detect(struct i2c_adapter *adapter, int address,
221 goto exit; 215 goto exit;
222 } 216 }
223 217
224 new_client = &data->client; 218 client = &data->client;
225 i2c_set_clientdata(new_client, data); 219 i2c_set_clientdata(client, data);
226 new_client->addr = address; 220 client->addr = address;
227 new_client->adapter = adapter; 221 client->adapter = adapter;
228 new_client->driver = &ds1621_driver; 222 client->driver = &ds1621_driver;
229 new_client->flags = 0;
230
231 223
232 /* Now, we do the remaining detection. It is lousy. */ 224 /* Now, we do the remaining detection. It is lousy. */
233 if (kind < 0) { 225 if (kind < 0) {
234 /* The NVB bit should be low if no EEPROM write has been 226 /* The NVB bit should be low if no EEPROM write has been
235 requested during the latest 10ms, which is highly 227 requested during the latest 10ms, which is highly
236 improbable in our case. */ 228 improbable in our case. */
237 conf = ds1621_read_value(new_client, DS1621_REG_CONF); 229 conf = ds1621_read_value(client, DS1621_REG_CONF);
238 if (conf & DS1621_REG_CONFIG_NVB) 230 if (conf & DS1621_REG_CONFIG_NVB)
239 goto exit_free; 231 goto exit_free;
240 /* The 7 lowest bits of a temperature should always be 0. */ 232 /* The 7 lowest bits of a temperature should always be 0. */
241 temp = ds1621_read_value(new_client, DS1621_REG_TEMP); 233 temp = ds1621_read_value(client, DS1621_REG_TEMP);
242 if (temp & 0x007f) 234 if (temp & 0x007f)
243 goto exit_free; 235 goto exit_free;
244 temp = ds1621_read_value(new_client, DS1621_REG_TEMP_MIN); 236 temp = ds1621_read_value(client, DS1621_REG_TEMP_MIN);
245 if (temp & 0x007f) 237 if (temp & 0x007f)
246 goto exit_free; 238 goto exit_free;
247 temp = ds1621_read_value(new_client, DS1621_REG_TEMP_MAX); 239 temp = ds1621_read_value(client, DS1621_REG_TEMP_MAX);
248 if (temp & 0x007f) 240 if (temp & 0x007f)
249 goto exit_free; 241 goto exit_free;
250 } 242 }
251 243
252 /* Determine the chip type - only one kind supported! */
253 if (kind <= 0)
254 kind = ds1621;
255
256 /* Fill in remaining client fields and put it into the global list */ 244 /* Fill in remaining client fields and put it into the global list */
257 strlcpy(new_client->name, "ds1621", I2C_NAME_SIZE); 245 strlcpy(client->name, "ds1621", I2C_NAME_SIZE);
258 data->valid = 0;
259 mutex_init(&data->update_lock); 246 mutex_init(&data->update_lock);
260 247
261 /* Tell the I2C layer a new client has arrived */ 248 /* Tell the I2C layer a new client has arrived */
262 if ((err = i2c_attach_client(new_client))) 249 if ((err = i2c_attach_client(client)))
263 goto exit_free; 250 goto exit_free;
264 251
265 /* Initialize the DS1621 chip */ 252 /* Initialize the DS1621 chip */
266 ds1621_init_client(new_client); 253 ds1621_init_client(client);
267 254
268 /* Register sysfs hooks */ 255 /* Register sysfs hooks */
269 if ((err = sysfs_create_group(&new_client->dev.kobj, &ds1621_group))) 256 if ((err = sysfs_create_group(&client->dev.kobj, &ds1621_group)))
270 goto exit_detach; 257 goto exit_detach;
271 258
272 data->class_dev = hwmon_device_register(&new_client->dev); 259 data->class_dev = hwmon_device_register(&client->dev);
273 if (IS_ERR(data->class_dev)) { 260 if (IS_ERR(data->class_dev)) {
274 err = PTR_ERR(data->class_dev); 261 err = PTR_ERR(data->class_dev);
275 goto exit_remove_files; 262 goto exit_remove_files;
@@ -278,9 +265,9 @@ static int ds1621_detect(struct i2c_adapter *adapter, int address,
278 return 0; 265 return 0;
279 266
280 exit_remove_files: 267 exit_remove_files:
281 sysfs_remove_group(&new_client->dev.kobj, &ds1621_group); 268 sysfs_remove_group(&client->dev.kobj, &ds1621_group);
282 exit_detach: 269 exit_detach:
283 i2c_detach_client(new_client); 270 i2c_detach_client(client);
284 exit_free: 271 exit_free:
285 kfree(data); 272 kfree(data);
286 exit: 273 exit: