This patch series aims to add match data improvements for mcp4725 driver.
This patch series is only compile tested.
v2->v3:
* Added struct mcp4725_chip_info with chan_spec and chip_id variable and
used that as OF/ID table match data.
* Added variables use_ext_ref_voltage and dac_reg_offset to struct
mcp4725_chip_info to handle hw differences between mcp4725 and
mcp4726.
v1->v2:
* Update commit description with reason for change.
Biju Das (4):
iio: dac: mcp4725: Replace variable 'id' from struct mcp4725_data
iio: dac: mcp4725: Use i2c_get_match_data()
iio: dac: mcp4725: Add use_ext_ref_voltage to struct mcp4725_chip_info
iio: dac: mcp4725: Add dac_reg_offset to struct mcp4725_chip_info
drivers/iio/dac/mcp4725.c | 42 ++++++++++++++++++++++++++-------------
1 file changed, 28 insertions(+), 14 deletions(-)
--
2.25.1
Replace the variable 'id' from struct mcp4725_data with local variable
chip_id in probe() as the id variable is not used elsewhere in the
driver.
Signed-off-by: Biju Das <[email protected]>
---
v2->v3:
* No change.
v1->v2:
* Update commit description with reason for change.
---
drivers/iio/dac/mcp4725.c | 16 ++++++++--------
1 file changed, 8 insertions(+), 8 deletions(-)
diff --git a/drivers/iio/dac/mcp4725.c b/drivers/iio/dac/mcp4725.c
index f4a3124d29f2..33a61f65bc25 100644
--- a/drivers/iio/dac/mcp4725.c
+++ b/drivers/iio/dac/mcp4725.c
@@ -32,7 +32,6 @@
struct mcp4725_data {
struct i2c_client *client;
- int id;
unsigned ref_mode;
bool vref_buffered;
u16 dac_value;
@@ -387,6 +386,7 @@ static int mcp4725_probe(struct i2c_client *client)
struct mcp4725_data *data;
struct iio_dev *indio_dev;
struct mcp4725_platform_data *pdata, pdata_dt;
+ int chip_id;
u8 inbuf[4];
u8 pd;
u8 ref;
@@ -399,9 +399,9 @@ static int mcp4725_probe(struct i2c_client *client)
i2c_set_clientdata(client, indio_dev);
data->client = client;
if (dev_fwnode(&client->dev))
- data->id = (uintptr_t)device_get_match_data(&client->dev);
+ chip_id = (uintptr_t)device_get_match_data(&client->dev);
else
- data->id = id->driver_data;
+ chip_id = id->driver_data;
pdata = dev_get_platdata(&client->dev);
if (!pdata) {
@@ -414,7 +414,7 @@ static int mcp4725_probe(struct i2c_client *client)
pdata = &pdata_dt;
}
- if (data->id == MCP4725 && pdata->use_vref) {
+ if (chip_id == MCP4725 && pdata->use_vref) {
dev_err(&client->dev,
"external reference is unavailable on MCP4725");
return -EINVAL;
@@ -455,12 +455,12 @@ static int mcp4725_probe(struct i2c_client *client)
indio_dev->name = id->name;
indio_dev->info = &mcp4725_info;
- indio_dev->channels = &mcp472x_channel[id->driver_data];
+ indio_dev->channels = &mcp472x_channel[chip_id];
indio_dev->num_channels = 1;
indio_dev->modes = INDIO_DIRECT_MODE;
/* read current DAC value and settings */
- err = i2c_master_recv(client, inbuf, data->id == MCP4725 ? 3 : 4);
+ err = i2c_master_recv(client, inbuf, chip_id == MCP4725 ? 3 : 4);
if (err < 0) {
dev_err(&client->dev, "failed to read DAC value");
@@ -470,10 +470,10 @@ static int mcp4725_probe(struct i2c_client *client)
data->powerdown = pd > 0;
data->powerdown_mode = pd ? pd - 1 : 2; /* largest resistor to gnd */
data->dac_value = (inbuf[1] << 4) | (inbuf[2] >> 4);
- if (data->id == MCP4726)
+ if (chip_id == MCP4726)
ref = (inbuf[3] >> 3) & 0x3;
- if (data->id == MCP4726 && ref != data->ref_mode) {
+ if (chip_id == MCP4726 && ref != data->ref_mode) {
dev_info(&client->dev,
"voltage reference mode differs (conf: %u, eeprom: %u), setting %u",
data->ref_mode, ref, data->ref_mode);
--
2.25.1