hwmon: (lm77) Clean up detect function
PATCH 1/1 hwmon: (lm77) Clean up detect function
As kind is now hard-coded to -1, there is room for code clean-ups.
Signed-off-by Jean Delvare <[email protected]>
---
The patch looks large, but most of it is really only removing one depth of indentation.
drivers/hwmon/lm77.c | 78 ++++++++++++++++++++++++-------------------------- 1 file changed, 38 insertions(+), 40 deletions(-)
drivers/hwmon/lm77.c +38 -40
@@ -249,6 +249,7 @@ static int lm77_detect(struct i2c_client struct i2c_board_info *info) {struct i2c_adapter *adapter = new_client->adapter; +int i, cur, conf, hyst, crit, min, max;if (!i2c_check_functionality (adapter,I2C_FUNC_SMBUS_BYTE_DATA |I2C_FUNC_SMBUS_WORD_DATA ))
@@ -265,51 +266,48 @@ static int lm77_detect(struct i2c_client4. registers cycling over 8-address boundaries Word-sized registers are high-byte first. */ -if (kind <0 ) { -int i, cur, conf, hyst, crit, min, max; -/* addresses cycling */ - cur =i2c_smbus_read_word_data (new_client,0 ); - conf =i2c_smbus_read_byte_data (new_client,1 ); - hyst =i2c_smbus_read_word_data (new_client,2 ); - crit =i2c_smbus_read_word_data (new_client,3 ); - min =i2c_smbus_read_word_data (new_client,4 ); - max =i2c_smbus_read_word_data (new_client,5 ); -for (i =8 ; i <=0xff ; i +=8 ) -if (i2c_smbus_read_byte_data (new_client, i +1 ) != conf - ||i2c_smbus_read_word_data (new_client, i +2 ) != hyst - ||i2c_smbus_read_word_data (new_client, i +3 ) != crit - ||i2c_smbus_read_word_data (new_client, i +4 ) != min - ||i2c_smbus_read_word_data (new_client, i +5 ) != max) -return -ENODEV ; - -/* sign bits */ -if (((cur &0x00f0 ) !=0xf0 && (cur &0x00f0 ) !=0x0 ) - || ((hyst &0x00f0 ) !=0xf0 && (hyst &0x00f0 ) !=0x0 ) - || ((crit &0x00f0 ) !=0xf0 && (crit &0x00f0 ) !=0x0 ) - || ((min &0x00f0 ) !=0xf0 && (min &0x00f0 ) !=0x0 ) - || ((max &0x00f0 ) !=0xf0 && (max &0x00f0 ) !=0x0 )) +/* addresses cycling */ + cur =i2c_smbus_read_word_data (new_client,0 ); + conf =i2c_smbus_read_byte_data (new_client,1 ); + hyst =i2c_smbus_read_word_data (new_client,2 ); + crit =i2c_smbus_read_word_data (new_client,3 ); + min =i2c_smbus_read_word_data (new_client,4 ); + max =i2c_smbus_read_word_data (new_client,5 ); +for (i =8 ; i <=0xff ; i +=8 ) { +if (i2c_smbus_read_byte_data (new_client, i +1 ) != conf + ||i2c_smbus_read_word_data (new_client, i +2 ) != hyst + ||i2c_smbus_read_word_data (new_client, i +3 ) != crit + ||i2c_smbus_read_word_data (new_client, i +4 ) != min + ||i2c_smbus_read_word_data (new_client, i +5 ) != max)return -ENODEV ; + } -/* unused bits */ -if (conf &0xe0 ) -return -ENODEV ; +/* sign bits */ +if (((cur &0x00f0 ) !=0xf0 && (cur &0x00f0 ) !=0x0 ) + || ((hyst &0x00f0 ) !=0xf0 && (hyst &0x00f0 ) !=0x0 ) + || ((crit &0x00f0 ) !=0xf0 && (crit &0x00f0 ) !=0x0 ) + || ((min &0x00f0 ) !=0xf0 && (min &0x00f0 ) !=0x0 ) + || ((max &0x00f0 ) !=0xf0 && (max &0x00f0 ) !=0x0 )) +return -ENODEV ; -/* 0x06 and 0x07 return the last read value */ - cur =i2c_smbus_read_word_data (new_client,0 ); -if (i2c_smbus_read_word_data (new_client,6 ) != cur - ||i2c_smbus_read_word_data (new_client,7 ) != cur) -return -ENODEV ; - hyst =i2c_smbus_read_word_data (new_client,2 ); -if (i2c_smbus_read_word_data (new_client,6 ) != hyst - ||i2c_smbus_read_word_data (new_client,7 ) != hyst) -return -ENODEV ; - min =i2c_smbus_read_word_data (new_client,4 ); -if (i2c_smbus_read_word_data (new_client,6 ) != min - ||i2c_smbus_read_word_data (new_client,7 ) != min) -return -ENODEV ; +/* unused bits */ +if (conf &0xe0 ) +return -ENODEV ; - } +/* 0x06 and 0x07 return the last read value */ + cur =i2c_smbus_read_word_data (new_client,0 ); +if (i2c_smbus_read_word_data (new_client,6 ) != cur + ||i2c_smbus_read_word_data (new_client,7 ) != cur) +return -ENODEV ; + hyst =i2c_smbus_read_word_data (new_client,2 ); +if (i2c_smbus_read_word_data (new_client,6 ) != hyst + ||i2c_smbus_read_word_data (new_client,7 ) != hyst) +return -ENODEV ; + min =i2c_smbus_read_word_data (new_client,4 ); +if (i2c_smbus_read_word_data (new_client,6 ) != min + ||i2c_smbus_read_word_data (new_client,7 ) != min) +return -ENODEV ;strlcpy (info->type,"lm77" ,I2C_NAME_SIZE );
Signature · 6 lines
Jean Delvare _______________________________________________ lm-sensors mailing list [email protected] http://lists.lm-sensors.org/mailman/listinfo/lm-sensors