Skip to content

Commit

Permalink
hwmon (pmbus) use simple i2c probe function
Browse files Browse the repository at this point in the history
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: Stephen Kitt <steve@sk2.org>
Acked-by: Wolfram Sang <wsa@kernel.org>
Link: https://lore.kernel.org/r/20200808210004.30880-1-steve@sk2.org
Signed-off-by: Guenter Roeck <linux@roeck-us.net>
  • Loading branch information
Stephen Kitt authored and Guenter Roeck committed Sep 23, 2020
1 parent e403583 commit dd43193
Show file tree
Hide file tree
Showing 30 changed files with 131 additions and 138 deletions.
3 changes: 1 addition & 2 deletions Documentation/hwmon/pmbus-core.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
7 changes: 3 additions & 4 deletions Documentation/hwmon/pmbus.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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,
};
Expand Down
11 changes: 5 additions & 6 deletions drivers/hwmon/pmbus/adm1275.c
Original file line number Diff line number Diff line change
Expand Up @@ -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];
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
};
Expand Down
11 changes: 6 additions & 5 deletions drivers/hwmon/pmbus/bel-pfe.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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[] = {
Expand All @@ -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,
};
Expand Down
19 changes: 12 additions & 7 deletions drivers/hwmon/pmbus/ibm-cffps.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -473,20 +475,23 @@ 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;
struct dentry *debugfs;
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)
vs = (enum versions)id->driver_data;
} 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;
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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,
};
Expand Down
7 changes: 3 additions & 4 deletions drivers/hwmon/pmbus/inspur-ipsps.c
Original file line number Diff line number Diff line change
Expand Up @@ -190,11 +190,10 @@ static struct pmbus_platform_data ipsps_pdata = {
.flags = PMBUS_SKIP_STATUS_CHECK,
};

static int ipsps_probe(struct i2c_client *client,
const struct i2c_device_id *id)
static int ipsps_probe(struct i2c_client *client)
{
client->dev.platform_data = &ipsps_pdata;
return pmbus_do_probe(client, id, &ipsps_info);
return pmbus_do_probe(client, &ipsps_info);
}

static const struct i2c_device_id ipsps_id[] = {
Expand All @@ -216,7 +215,7 @@ static struct i2c_driver ipsps_driver = {
.name = "inspur-ipsps",
.of_match_table = of_match_ptr(ipsps_of_match),
},
.probe = ipsps_probe,
.probe_new = ipsps_probe,
.remove = pmbus_do_remove,
.id_table = ipsps_id,
};
Expand Down
7 changes: 3 additions & 4 deletions drivers/hwmon/pmbus/ir35221.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,7 @@ static int ir35221_read_word_data(struct i2c_client *client, int page,
return ret;
}

static int ir35221_probe(struct i2c_client *client,
const struct i2c_device_id *id)
static int ir35221_probe(struct i2c_client *client)
{
struct pmbus_driver_info *info;
u8 buf[I2C_SMBUS_BLOCK_MAX];
Expand Down Expand Up @@ -123,7 +122,7 @@ static int ir35221_probe(struct i2c_client *client,
| PMBUS_HAVE_STATUS_INPUT | PMBUS_HAVE_STATUS_TEMP;
info->func[1] = info->func[0];

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

static const struct i2c_device_id ir35221_id[] = {
Expand All @@ -137,7 +136,7 @@ static struct i2c_driver ir35221_driver = {
.driver = {
.name = "ir35221",
},
.probe = ir35221_probe,
.probe_new = ir35221_probe,
.remove = pmbus_do_remove,
.id_table = ir35221_id,
};
Expand Down
7 changes: 3 additions & 4 deletions drivers/hwmon/pmbus/ir38064.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,9 @@ static struct pmbus_driver_info ir38064_info = {
| PMBUS_HAVE_POUT,
};

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

static const struct i2c_device_id ir38064_id[] = {
Expand All @@ -53,7 +52,7 @@ static struct i2c_driver ir38064_driver = {
.driver = {
.name = "ir38064",
},
.probe = ir38064_probe,
.probe_new = ir38064_probe,
.remove = pmbus_do_remove,
.id_table = ir38064_id,
};
Expand Down
7 changes: 3 additions & 4 deletions drivers/hwmon/pmbus/irps5401.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,9 @@ static struct pmbus_driver_info irps5401_info = {
.func[4] = IRPS5401_LDO_FUNC,
};

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

static const struct i2c_device_id irps5401_id[] = {
Expand All @@ -55,7 +54,7 @@ static struct i2c_driver irps5401_driver = {
.driver = {
.name = "irps5401",
},
.probe = irps5401_probe,
.probe_new = irps5401_probe,
.remove = pmbus_do_remove,
.id_table = irps5401_id,
};
Expand Down
11 changes: 6 additions & 5 deletions drivers/hwmon/pmbus/isl68137.c
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,8 @@ enum variants {
raa_dmpvr2_hv,
};

static const struct i2c_device_id raa_dmpvr_id[];

static ssize_t isl68137_avs_enable_show_page(struct i2c_client *client,
int page,
char *buf)
Expand Down Expand Up @@ -218,8 +220,7 @@ static struct pmbus_driver_info raa_dmpvr_info = {
| PMBUS_HAVE_STATUS_IOUT | PMBUS_HAVE_POUT,
};

static int isl68137_probe(struct i2c_client *client,
const struct i2c_device_id *id)
static int isl68137_probe(struct i2c_client *client)
{
struct pmbus_driver_info *info;

Expand All @@ -228,7 +229,7 @@ static int isl68137_probe(struct i2c_client *client,
return -ENOMEM;
memcpy(info, &raa_dmpvr_info, sizeof(*info));

switch (id->driver_data) {
switch (i2c_match_id(raa_dmpvr_id, client)->driver_data) {
case raa_dmpvr1_2rail:
info->pages = 2;
info->R[PSC_VOLTAGE_IN] = 3;
Expand Down Expand Up @@ -267,7 +268,7 @@ static int isl68137_probe(struct i2c_client *client,
return -ENODEV;
}

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

static const struct i2c_device_id raa_dmpvr_id[] = {
Expand Down Expand Up @@ -322,7 +323,7 @@ static struct i2c_driver isl68137_driver = {
.driver = {
.name = "isl68137",
},
.probe = isl68137_probe,
.probe_new = isl68137_probe,
.remove = pmbus_do_remove,
.id_table = raa_dmpvr_id,
};
Expand Down
11 changes: 6 additions & 5 deletions drivers/hwmon/pmbus/lm25066.c
Original file line number Diff line number Diff line change
Expand Up @@ -211,6 +211,8 @@ struct lm25066_data {

#define to_lm25066_data(x) container_of(x, struct lm25066_data, info)

static const struct i2c_device_id lm25066_id[];

static int lm25066_read_word_data(struct i2c_client *client, int page,
int phase, int reg)
{
Expand Down Expand Up @@ -416,8 +418,7 @@ static int lm25066_write_word_data(struct i2c_client *client, int page, int reg,
return ret;
}

static int lm25066_probe(struct i2c_client *client,
const struct i2c_device_id *id)
static int lm25066_probe(struct i2c_client *client)
{
int config;
struct lm25066_data *data;
Expand All @@ -437,7 +438,7 @@ static int lm25066_probe(struct i2c_client *client,
if (config < 0)
return config;

data->id = id->driver_data;
data->id = i2c_match_id(lm25066_id, client)->driver_data;
info = &data->info;

info->pages = 1;
Expand Down Expand Up @@ -487,7 +488,7 @@ static int lm25066_probe(struct i2c_client *client,
info->b[PSC_POWER] = coeff[PSC_POWER].b;
}

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

static const struct i2c_device_id lm25066_id[] = {
Expand All @@ -506,7 +507,7 @@ static struct i2c_driver lm25066_driver = {
.driver = {
.name = "lm25066",
},
.probe = lm25066_probe,
.probe_new = lm25066_probe,
.remove = pmbus_do_remove,
.id_table = lm25066_id,
};
Expand Down
14 changes: 8 additions & 6 deletions drivers/hwmon/pmbus/ltc2978.c
Original file line number Diff line number Diff line change
Expand Up @@ -649,12 +649,12 @@ static int ltc2978_get_id(struct i2c_client *client)
return -ENODEV;
}

static int ltc2978_probe(struct i2c_client *client,
const struct i2c_device_id *id)
static int ltc2978_probe(struct i2c_client *client)
{
int i, chip_id;
struct ltc2978_data *data;
struct pmbus_driver_info *info;
const struct i2c_device_id *id;

if (!i2c_check_functionality(client->adapter,
I2C_FUNC_SMBUS_READ_WORD_DATA))
Expand All @@ -670,11 +670,13 @@ static int ltc2978_probe(struct i2c_client *client,
return chip_id;

data->id = chip_id;
id = i2c_match_id(ltc2978_id, client);
if (data->id != id->driver_data)
dev_warn(&client->dev,
"Device mismatch: Configured %s, detected %s\n",
"Device mismatch: Configured %s (%d), detected %d\n",
id->name,
ltc2978_id[data->id].name);
(int) id->driver_data,
chip_id);

info = &data->info;
info->write_word_data = ltc2978_write_word_data;
Expand Down Expand Up @@ -832,7 +834,7 @@ static int ltc2978_probe(struct i2c_client *client,
}
#endif

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


Expand Down Expand Up @@ -872,7 +874,7 @@ static struct i2c_driver ltc2978_driver = {
.name = "ltc2978",
.of_match_table = of_match_ptr(ltc2978_of_match),
},
.probe = ltc2978_probe,
.probe_new = ltc2978_probe,
.remove = pmbus_do_remove,
.id_table = ltc2978_id,
};
Expand Down
Loading

0 comments on commit dd43193

Please sign in to comment.