Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 52df6440 authored by Jean Delvare's avatar Jean Delvare
Browse files

hwmon: Clean up detect functions



As kind is now hard-coded to -1, there is room for code clean-ups.

Signed-off-by: default avatarJean Delvare <khali@linux-fr.org>
Acked-by: default avatarCorentin Labbe <corentin.labbe@geomatys.fr>
Cc: "Mark M. Hoffman" <mhoffman@lightlink.com>
Cc: Juerg Haefliger <juergh@gmail.com>
Cc: Riku Voipio <riku.voipio@iki.fi>
Acked-by: default avatar"Hans J. Koch" <hjk@linutronix.de>
Cc: Rudolf Marek <r.marek@assembler.cz>
parent a1fa4cdc
Loading
Loading
Loading
Loading
+19 −28
Original line number Diff line number Diff line
@@ -1672,35 +1672,26 @@ static int adm1026_detect(struct i2c_client *client, int kind,
		i2c_adapter_id(client->adapter), client->addr,
		company, verstep);

	/* If auto-detecting, Determine the chip type. */
	if (kind <= 0) {
		dev_dbg(&adapter->dev, "Autodetecting device at %d,0x%02x "
			"...\n", i2c_adapter_id(adapter), address);
	/* Determine the chip type. */
	dev_dbg(&adapter->dev, "Autodetecting device at %d,0x%02x...\n",
		i2c_adapter_id(adapter), address);
	if (company == ADM1026_COMPANY_ANALOG_DEV
	    && verstep == ADM1026_VERSTEP_ADM1026) {
			kind = adm1026;
		/* Analog Devices ADM1026 */
	} else if (company == ADM1026_COMPANY_ANALOG_DEV
		&& (verstep & 0xf0) == ADM1026_VERSTEP_GENERIC) {
		dev_err(&adapter->dev, "Unrecognized stepping "
			"0x%02x. Defaulting to ADM1026.\n", verstep);
			kind = adm1026;
	} else if ((verstep & 0xf0) == ADM1026_VERSTEP_GENERIC) {
		dev_err(&adapter->dev, "Found version/stepping "
			"0x%02x. Assuming generic ADM1026.\n",
			verstep);
			kind = any_chip;
	} else {
		dev_dbg(&adapter->dev, "Autodetection failed\n");
		/* Not an ADM1026... */
			if (kind == 0) { /* User used force=x,y */
				dev_err(&adapter->dev, "Generic ADM1026 not "
					"found at %d,0x%02x.  Try "
					"force_adm1026.\n",
					i2c_adapter_id(adapter), address);
			}
		return -ENODEV;
	}
	}

	strlcpy(info->type, "adm1026", I2C_NAME_SIZE);

	return 0;
+16 −39
Original line number Diff line number Diff line
@@ -301,33 +301,17 @@ static int adm1029_detect(struct i2c_client *client, int kind,
			  struct i2c_board_info *info)
{
	struct i2c_adapter *adapter = client->adapter;
	u8 man_id, chip_id, temp_devices_installed, nb_fan_support;

	if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
		return -ENODEV;

	/* Now we do the detection and identification. A negative kind
	 * means that the driver was loaded with no force parameter
	 * (default), so we must both detect and identify the chip
	 * (actually there is only one possible kind of chip for now, adm1029).
	 * A zero kind means that the driver was loaded with the force
	 * parameter, the detection step shall be skipped. A positive kind
	 * means that the driver was loaded with the force parameter and a
	 * given kind of chip is requested, so both the detection and the
	 * identification steps are skipped. */

	/* Default to an adm1029 if forced */
	if (kind == 0)
		kind = adm1029;

	/* ADM1029 doesn't have CHIP ID, check just MAN ID
	 * For better detection we check also ADM1029_TEMP_DEVICES_INSTALLED,
	 * ADM1029_REG_NB_FAN_SUPPORT and compare it with possible values
	 * documented
	 */

	if (kind <= 0) {	/* identification */
		u8 man_id, chip_id, temp_devices_installed, nb_fan_support;

	man_id = i2c_smbus_read_byte_data(client, ADM1029_REG_MAN_ID);
	chip_id = i2c_smbus_read_byte_data(client, ADM1029_REG_CHIP_ID);
	temp_devices_installed = i2c_smbus_read_byte_data(client,
@@ -335,25 +319,18 @@ static int adm1029_detect(struct i2c_client *client, int kind,
	nb_fan_support = i2c_smbus_read_byte_data(client,
						ADM1029_REG_NB_FAN_SUPPORT);
	/* 0x41 is Analog Devices */
		if (man_id == 0x41 && (temp_devices_installed & 0xf9) == 0x01
		    && nb_fan_support == 0x03) {
			if ((chip_id & 0xF0) == 0x00) {
				kind = adm1029;
			} else {
	if (man_id != 0x41 || (temp_devices_installed & 0xf9) != 0x01
	    || nb_fan_support != 0x03)
		return -ENODEV;

	if ((chip_id & 0xF0) != 0x00) {
		/* There are no "official" CHIP ID, so actually
		 * we use Major/Minor revision for that */
				printk(KERN_INFO
				       "adm1029: Unknown major revision %x, "
		pr_info("adm1029: Unknown major revision %x, "
			"please let us know\n", chip_id);
			}
		}

		if (kind <= 0) {	/* identification failed */
			pr_debug("adm1029: Unsupported chip (man_id=0x%02X, "
				 "chip_id=0x%02X)\n", man_id, chip_id);
		return -ENODEV;
	}
	}

	strlcpy(info->type, "adm1029", I2C_NAME_SIZE);

	return 0;
+7 −19
Original line number Diff line number Diff line
@@ -817,31 +817,19 @@ static int adm1031_detect(struct i2c_client *client, int kind,
			  struct i2c_board_info *info)
{
	struct i2c_adapter *adapter = client->adapter;
	const char *name = "";
	const char *name;
	int id, co;

	if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
		return -ENODEV;

	if (kind < 0) {
		int id, co;
	id = i2c_smbus_read_byte_data(client, 0x3d);
	co = i2c_smbus_read_byte_data(client, 0x3e);

	if (!((id == 0x31 || id == 0x30) && co == 0x41))
		return -ENODEV;
		kind = (id == 0x30) ? adm1030 : adm1031;
	}
	name = (id == 0x30) ? "adm1030" : "adm1031";

	if (kind <= 0)
		kind = adm1031;

	/* Given the detected chip type, set the chip name and the
	 * auto fan control helper table. */
	if (kind == adm1030) {
		name = "adm1030";
	} else if (kind == adm1031) {
		name = "adm1031";
	}
	strlcpy(info->type, name, I2C_NAME_SIZE);

	return 0;
+22 −39
Original line number Diff line number Diff line
@@ -556,51 +556,34 @@ static int adm9240_detect(struct i2c_client *new_client, int kind,
	if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_BYTE_DATA))
		return -ENODEV;

	if (kind == 0) {
		kind = adm9240;
	}

	if (kind < 0) {

	/* verify chip: reg address should match i2c address */
	if (i2c_smbus_read_byte_data(new_client, ADM9240_REG_I2C_ADDR)
			!= address) {
			dev_err(&adapter->dev, "detect fail: address match, "
					"0x%02x\n", address);
		dev_err(&adapter->dev, "detect fail: address match, 0x%02x\n",
			address);
		return -ENODEV;
	}

	/* check known chip manufacturer */
		man_id = i2c_smbus_read_byte_data(new_client,
				ADM9240_REG_MAN_ID);
	man_id = i2c_smbus_read_byte_data(new_client, ADM9240_REG_MAN_ID);
	if (man_id == 0x23) {
			kind = adm9240;
		name = "adm9240";
	} else if (man_id == 0xda) {
			kind = ds1780;
		name = "ds1780";
	} else if (man_id == 0x01) {
			kind = lm81;
		name = "lm81";
	} else {
			dev_err(&adapter->dev, "detect fail: unknown manuf, "
					"0x%02x\n", man_id);
		dev_err(&adapter->dev, "detect fail: unknown manuf, 0x%02x\n",
			man_id);
		return -ENODEV;
	}

	/* successful detect, print chip info */
		die_rev = i2c_smbus_read_byte_data(new_client,
				ADM9240_REG_DIE_REV);
	die_rev = i2c_smbus_read_byte_data(new_client, ADM9240_REG_DIE_REV);
	dev_info(&adapter->dev, "found %s revision %u\n",
		 man_id == 0x23 ? "ADM9240" :
		 man_id == 0xda ? "DS1780" : "LM81", die_rev);
	}

	/* either forced or detected chip kind */
	if (kind == adm9240) {
		name = "adm9240";
	} else if (kind == ds1780) {
		name = "ds1780";
	} else if (kind == lm81) {
		name = "lm81";
	}
	strlcpy(info->type, name, I2C_NAME_SIZE);

	return 0;
+10 −12
Original line number Diff line number Diff line
@@ -191,6 +191,7 @@ static int ads7828_detect(struct i2c_client *client, int kind,
			  struct i2c_board_info *info)
{
	struct i2c_adapter *adapter = client->adapter;
	int ch;

	/* Check we have a valid client */
	if (!i2c_check_functionality(adapter, I2C_FUNC_SMBUS_READ_WORD_DATA))
@@ -202,20 +203,17 @@ static int ads7828_detect(struct i2c_client *client, int kind,
	- Read from the 8 channel addresses
	- Check the top 4 bits of each result are not set (12 data bits)
	*/
	if (kind < 0) {
		int ch;
	for (ch = 0; ch < ADS7828_NCH; ch++) {
		u16 in_data;
		u8 cmd = channel_cmd_byte(ch);
		in_data = ads7828_read_value(client, cmd);
		if (in_data & 0xF000) {
				printk(KERN_DEBUG
				"%s : Doesn't look like an ads7828 device\n",
			pr_debug("%s : Doesn't look like an ads7828 device\n",
				 __func__);
			return -ENODEV;
		}
	}
	}

	strlcpy(info->type, "ads7828", I2C_NAME_SIZE);

	return 0;
Loading