Commit dd431939 authored by Stephen Kitt's avatar Stephen Kitt Committed by Guenter Roeck
Browse files

hwmon (pmbus) use simple i2c probe function



pmbus_do_probe doesn't use the id information provided in its second
argument, so this can be removed, which then allows using the
single-parameter i2c probe function ("probe_new") for probes.

This avoids scanning the identifier tables during probes.

Drivers which didn't use the id are converted as-is; drivers which did
are modified as follows:

* if the information in i2c_client is sufficient, that's used instead
  (client->name);
* configured v. probed comparisons are performed by comparing the
  configured name to the detected name, instead of the ids; this
  involves strcmp but is still cheaper than comparing all the device
  names when scanning the tables;
* anything else is handled by calling i2c_match_id() with the same
  level of error-handling (if any) as before.

Additionally, the mismatch message in the ltc2978 driver is adjusted
so that it no longer assumes that the driver_data is an index into
ltc2978_id.

Signed-off-by: default avatarStephen Kitt <steve@sk2.org>
Acked-by: default avatarWolfram Sang <wsa@kernel.org>
Link: https://lore.kernel.org/r/20200808210004.30880-1-steve@sk2.org


Signed-off-by: default avatarGuenter Roeck <linux@roeck-us.net>
parent e4035839
Loading
Loading
Loading
Loading
+1 −2
Original line number Diff line number Diff line
@@ -270,8 +270,7 @@ obtain the chip status. Therefore, it must _not_ be called from that function.

::

  int pmbus_do_probe(struct i2c_client *client, const struct i2c_device_id *id,
		     struct pmbus_driver_info *info);
  int pmbus_do_probe(struct i2c_client *client, struct pmbus_driver_info *info);

Execute probe function. Similar to standard probe function for other drivers,
with the pointer to struct pmbus_driver_info as additional argument. Calls
+3 −4
Original line number Diff line number Diff line
@@ -143,10 +143,9 @@ Emerson DS1200 power modules might look as follows::
		   | PMBUS_HAVE_FAN12 | PMBUS_HAVE_STATUS_FAN12,
  };

  static int ds1200_probe(struct i2c_client *client,
			  const struct i2c_device_id *id)
  static int ds1200_probe(struct i2c_client *client)
  {
	return pmbus_do_probe(client, id, &ds1200_info);
	return pmbus_do_probe(client, &ds1200_info);
  }

  static int ds1200_remove(struct i2c_client *client)
@@ -166,7 +165,7 @@ Emerson DS1200 power modules might look as follows::
	.driver = {
		   .name = "ds1200",
		   },
	.probe = ds1200_probe,
	.probe_new = ds1200_probe,
	.remove = ds1200_remove,
	.id_table = ds1200_id,
  };
+5 −6
Original line number Diff line number Diff line
@@ -462,8 +462,7 @@ static const struct i2c_device_id adm1275_id[] = {
};
MODULE_DEVICE_TABLE(i2c, adm1275_id);

static int adm1275_probe(struct i2c_client *client,
			 const struct i2c_device_id *id)
static int adm1275_probe(struct i2c_client *client)
{
	s32 (*config_read_fn)(const struct i2c_client *client, u8 reg);
	u8 block_buffer[I2C_SMBUS_BLOCK_MAX + 1];
@@ -506,10 +505,10 @@ static int adm1275_probe(struct i2c_client *client,
		return -ENODEV;
	}

	if (id->driver_data != mid->driver_data)
	if (strcmp(client->name, mid->name) != 0)
		dev_notice(&client->dev,
			   "Device mismatch: Configured %s, detected %s\n",
			   id->name, mid->name);
			   client->name, mid->name);

	if (mid->driver_data == adm1272 || mid->driver_data == adm1278 ||
	    mid->driver_data == adm1293 || mid->driver_data == adm1294)
@@ -790,14 +789,14 @@ static int adm1275_probe(struct i2c_client *client,
		info->R[PSC_TEMPERATURE] = coefficients[tindex].R;
	}

	return pmbus_do_probe(client, id, info);
	return pmbus_do_probe(client, info);
}

static struct i2c_driver adm1275_driver = {
	.driver = {
		   .name = "adm1275",
		   },
	.probe = adm1275_probe,
	.probe_new = adm1275_probe,
	.remove = pmbus_do_remove,
	.id_table = adm1275_id,
};
+6 −5
Original line number Diff line number Diff line
@@ -87,12 +87,13 @@ static struct pmbus_driver_info pfe_driver_info[] = {
	},
};

static int pfe_pmbus_probe(struct i2c_client *client,
			   const struct i2c_device_id *id)
static const struct i2c_device_id pfe_device_id[];

static int pfe_pmbus_probe(struct i2c_client *client)
{
	int model;

	model = (int)id->driver_data;
	model = (int)i2c_match_id(pfe_device_id, client)->driver_data;

	/*
	 * PFE3000-12-069RA devices may not stay in page 0 during device
@@ -104,7 +105,7 @@ static int pfe_pmbus_probe(struct i2c_client *client,
		i2c_smbus_write_byte_data(client, PMBUS_PAGE, 0);
	}

	return pmbus_do_probe(client, id, &pfe_driver_info[model]);
	return pmbus_do_probe(client, &pfe_driver_info[model]);
}

static const struct i2c_device_id pfe_device_id[] = {
@@ -119,7 +120,7 @@ static struct i2c_driver pfe_pmbus_driver = {
	.driver = {
		   .name = "bel-pfe",
	},
	.probe = pfe_pmbus_probe,
	.probe_new = pfe_pmbus_probe,
	.remove = pmbus_do_remove,
	.id_table = pfe_device_id,
};
+12 −7
Original line number Diff line number Diff line
@@ -91,6 +91,8 @@ struct ibm_cffps {
	struct led_classdev led;
};

static const struct i2c_device_id ibm_cffps_id[];

#define to_psu(x, y) container_of((x), struct ibm_cffps, debugfs_entries[(y)])

static ssize_t ibm_cffps_read_input_history(struct ibm_cffps *psu,
@@ -473,8 +475,7 @@ static struct pmbus_platform_data ibm_cffps_pdata = {
	.flags = PMBUS_SKIP_STATUS_CHECK,
};

static int ibm_cffps_probe(struct i2c_client *client,
			   const struct i2c_device_id *id)
static int ibm_cffps_probe(struct i2c_client *client)
{
	int i, rc;
	enum versions vs = cffps_unknown;
@@ -482,11 +483,15 @@ static int ibm_cffps_probe(struct i2c_client *client,
	struct dentry *ibm_cffps_dir;
	struct ibm_cffps *psu;
	const void *md = of_device_get_match_data(&client->dev);
	const struct i2c_device_id *id;

	if (md)
	if (md) {
		vs = (enum versions)md;
	else if (id)
	} else {
		id = i2c_match_id(ibm_cffps_id, client);
		if (id)
			vs = (enum versions)id->driver_data;
	}

	if (vs == cffps_unknown) {
		u16 ccin_revision = 0;
@@ -519,7 +524,7 @@ static int ibm_cffps_probe(struct i2c_client *client,
	}

	client->dev.platform_data = &ibm_cffps_pdata;
	rc = pmbus_do_probe(client, id, &ibm_cffps_info[vs]);
	rc = pmbus_do_probe(client, &ibm_cffps_info[vs]);
	if (rc)
		return rc;

@@ -611,7 +616,7 @@ static struct i2c_driver ibm_cffps_driver = {
		.name = "ibm-cffps",
		.of_match_table = ibm_cffps_of_match,
	},
	.probe = ibm_cffps_probe,
	.probe_new = ibm_cffps_probe,
	.remove = pmbus_do_remove,
	.id_table = ibm_cffps_id,
};
Loading