hwmon: (lm83) Clean up detect function
As kind is now hard-coded to -1, there is room for code clean-ups. Signed-off-by: Jean Delvare <khali@linux-fr.org>
This commit is contained in:
@@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* lm83.c - Part of lm_sensors, Linux kernel modules for hardware
|
* lm83.c - Part of lm_sensors, Linux kernel modules for hardware
|
||||||
* monitoring
|
* monitoring
|
||||||
* Copyright (C) 2003-2008 Jean Delvare <khali@linux-fr.org>
|
* Copyright (C) 2003-2009 Jean Delvare <khali@linux-fr.org>
|
||||||
*
|
*
|
||||||
* Heavily inspired from the lm78, lm75 and adm1021 drivers. The LM83 is
|
* Heavily inspired from the lm78, lm75 and adm1021 drivers. The LM83 is
|
||||||
* a sensor chip made by National Semiconductor. It reports up to four
|
* a sensor chip made by National Semiconductor. It reports up to four
|
||||||
@@ -295,69 +295,40 @@ static int lm83_detect(struct i2c_client *new_client, int kind,
|
|||||||
struct i2c_board_info *info)
|
struct i2c_board_info *info)
|
||||||
{
|
{
|
||||||
struct i2c_adapter *adapter = new_client->adapter;
|
struct i2c_adapter *adapter = new_client->adapter;
|
||||||
const char *name = "";
|
const char *name;
|
||||||
|
u8 man_id, chip_id;
|
||||||
|
|
||||||
if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
|
if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
|
||||||
return -ENODEV;
|
return -ENODEV;
|
||||||
|
|
||||||
/* Now we do the detection and identification. A negative kind
|
/* Detection */
|
||||||
* means that the driver was loaded with no force parameter
|
if ((i2c_smbus_read_byte_data(new_client, LM83_REG_R_STATUS1) & 0xA8) ||
|
||||||
* (default), so we must both detect and identify the chip
|
(i2c_smbus_read_byte_data(new_client, LM83_REG_R_STATUS2) & 0x48) ||
|
||||||
* (actually there is only one possible kind of chip for now, LM83).
|
(i2c_smbus_read_byte_data(new_client, LM83_REG_R_CONFIG) & 0x41)) {
|
||||||
* A zero kind means that the driver was loaded with the force
|
dev_dbg(&adapter->dev, "LM83 detection failed at 0x%02x\n",
|
||||||
* parameter, the detection step shall be skipped. A positive kind
|
new_client->addr);
|
||||||
* means that the driver was loaded with the force parameter and a
|
return -ENODEV;
|
||||||
* given kind of chip is requested, so both the detection and the
|
|
||||||
* identification steps are skipped. */
|
|
||||||
|
|
||||||
/* Default to an LM83 if forced */
|
|
||||||
if (kind == 0)
|
|
||||||
kind = lm83;
|
|
||||||
|
|
||||||
if (kind < 0) { /* detection */
|
|
||||||
if (((i2c_smbus_read_byte_data(new_client, LM83_REG_R_STATUS1)
|
|
||||||
& 0xA8) != 0x00) ||
|
|
||||||
((i2c_smbus_read_byte_data(new_client, LM83_REG_R_STATUS2)
|
|
||||||
& 0x48) != 0x00) ||
|
|
||||||
((i2c_smbus_read_byte_data(new_client, LM83_REG_R_CONFIG)
|
|
||||||
& 0x41) != 0x00)) {
|
|
||||||
dev_dbg(&adapter->dev,
|
|
||||||
"LM83 detection failed at 0x%02x.\n",
|
|
||||||
new_client->addr);
|
|
||||||
return -ENODEV;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (kind <= 0) { /* identification */
|
/* Identification */
|
||||||
u8 man_id, chip_id;
|
man_id = i2c_smbus_read_byte_data(new_client, LM83_REG_R_MAN_ID);
|
||||||
|
if (man_id != 0x01) /* National Semiconductor */
|
||||||
|
return -ENODEV;
|
||||||
|
|
||||||
man_id = i2c_smbus_read_byte_data(new_client,
|
chip_id = i2c_smbus_read_byte_data(new_client, LM83_REG_R_CHIP_ID);
|
||||||
LM83_REG_R_MAN_ID);
|
switch (chip_id) {
|
||||||
chip_id = i2c_smbus_read_byte_data(new_client,
|
case 0x03:
|
||||||
LM83_REG_R_CHIP_ID);
|
|
||||||
|
|
||||||
if (man_id == 0x01) { /* National Semiconductor */
|
|
||||||
if (chip_id == 0x03) {
|
|
||||||
kind = lm83;
|
|
||||||
} else
|
|
||||||
if (chip_id == 0x01) {
|
|
||||||
kind = lm82;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (kind <= 0) { /* identification failed */
|
|
||||||
dev_info(&adapter->dev,
|
|
||||||
"Unsupported chip (man_id=0x%02X, "
|
|
||||||
"chip_id=0x%02X).\n", man_id, chip_id);
|
|
||||||
return -ENODEV;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (kind == lm83) {
|
|
||||||
name = "lm83";
|
name = "lm83";
|
||||||
} else
|
break;
|
||||||
if (kind == lm82) {
|
case 0x01:
|
||||||
name = "lm82";
|
name = "lm82";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
/* identification failed */
|
||||||
|
dev_info(&adapter->dev,
|
||||||
|
"Unsupported chip (man_id=0x%02X, chip_id=0x%02X)\n",
|
||||||
|
man_id, chip_id);
|
||||||
|
return -ENODEV;
|
||||||
}
|
}
|
||||||
|
|
||||||
strlcpy(info->type, name, I2C_NAME_SIZE);
|
strlcpy(info->type, name, I2C_NAME_SIZE);
|
||||||
|
Reference in New Issue
Block a user