diff options
| author | Joshua Crofts <joshua.crofts1@gmail.com> | 2026-06-14 15:19:04 +0200 |
|---|---|---|
| committer | Jonathan Cameron <jic23@kernel.org> | 2026-06-30 00:15:54 +0100 |
| commit | c9439c1de88fd7fba1e95fc4c756b2384beba423 (patch) | |
| tree | 6790c9445ebf05e9b2556cc4eca1d10459f820d3 | |
| parent | a3ed4362d3d902f0adf4e187eed15ccbe230fc7a (diff) | |
| download | linux-stable-c9439c1de88fd7fba1e95fc4c756b2384beba423.tar.gz linux-stable-c9439c1de88fd7fba1e95fc4c756b2384beba423.zip | |
iio: light: opt3001: use local struct device and i2c_client variables
Switch the driver to use local variables for struct device and struct
i2c_client and remove struct device member from struct opt3001, as the
former can be derived from struct client.
No functional change.
Suggested-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com>
Signed-off-by: Joshua Crofts <joshua.crofts1@gmail.com>
Signed-off-by: Jonathan Cameron <jic23@kernel.org>
| -rw-r--r-- | drivers/iio/light/opt3001.c | 139 |
1 files changed, 73 insertions, 66 deletions
diff --git a/drivers/iio/light/opt3001.c b/drivers/iio/light/opt3001.c index 0423c6de5321..16cc9b4bdef1 100644 --- a/drivers/iio/light/opt3001.c +++ b/drivers/iio/light/opt3001.c @@ -101,7 +101,6 @@ struct opt3001_chip_info { struct opt3001 { struct i2c_client *client; - struct device *dev; struct mutex lock; bool ok_to_ignore_lock; @@ -313,6 +312,8 @@ static const struct iio_chan_spec opt3002_channels[] = { static int opt3001_get_processed(struct opt3001 *opt, int *val, int *val2) { + struct i2c_client *client = opt->client; + struct device *dev = &client->dev; int ret; u16 mantissa; u16 reg; @@ -326,12 +327,12 @@ static int opt3001_get_processed(struct opt3001 *opt, int *val, int *val2) * doing so will overwrite the low-level limit value however we * will restore this value later on. */ - ret = i2c_smbus_write_word_swapped(opt->client, - OPT3001_LOW_LIMIT, - OPT3001_LOW_LIMIT_EOC_ENABLE); + ret = i2c_smbus_write_word_swapped(client, + OPT3001_LOW_LIMIT, + OPT3001_LOW_LIMIT_EOC_ENABLE); if (ret < 0) { - dev_err(opt->dev, "failed to write register %02x\n", - OPT3001_LOW_LIMIT); + dev_err(dev, "failed to write register %02x\n", + OPT3001_LOW_LIMIT); return ret; } @@ -343,21 +344,20 @@ static int opt3001_get_processed(struct opt3001 *opt, int *val, int *val2) opt->result_ready = false; /* Configure for single-conversion mode and start a new conversion */ - ret = i2c_smbus_read_word_swapped(opt->client, OPT3001_CONFIGURATION); + ret = i2c_smbus_read_word_swapped(client, OPT3001_CONFIGURATION); if (ret < 0) { - dev_err(opt->dev, "failed to read register %02x\n", - OPT3001_CONFIGURATION); + dev_err(dev, "failed to read register %02x\n", + OPT3001_CONFIGURATION); goto err; } reg = ret; opt3001_set_mode(opt, ®, OPT3001_CONFIGURATION_M_SINGLE); - ret = i2c_smbus_write_word_swapped(opt->client, OPT3001_CONFIGURATION, - reg); + ret = i2c_smbus_write_word_swapped(client, OPT3001_CONFIGURATION, reg); if (ret < 0) { - dev_err(opt->dev, "failed to write register %02x\n", - OPT3001_CONFIGURATION); + dev_err(dev, "failed to write register %02x\n", + OPT3001_CONFIGURATION); goto err; } @@ -377,10 +377,9 @@ static int opt3001_get_processed(struct opt3001 *opt, int *val, int *val2) msleep(timeout); /* Check result ready flag */ - ret = i2c_smbus_read_word_swapped(opt->client, - OPT3001_CONFIGURATION); + ret = i2c_smbus_read_word_swapped(client, OPT3001_CONFIGURATION); if (ret < 0) { - dev_err(opt->dev, "failed to read register %02x\n", + dev_err(dev, "failed to read register %02x\n", OPT3001_CONFIGURATION); goto err; } @@ -391,9 +390,9 @@ static int opt3001_get_processed(struct opt3001 *opt, int *val, int *val2) } /* Obtain value */ - ret = i2c_smbus_read_word_swapped(opt->client, OPT3001_RESULT); + ret = i2c_smbus_read_word_swapped(client, OPT3001_RESULT); if (ret < 0) { - dev_err(opt->dev, "failed to read register %02x\n", + dev_err(dev, "failed to read register %02x\n", OPT3001_RESULT); goto err; } @@ -418,12 +417,12 @@ err: * bit-overlap and therefore can't be done. */ value = (opt->low_thresh_exp << 12) | opt->low_thresh_mantissa; - ret = i2c_smbus_write_word_swapped(opt->client, + ret = i2c_smbus_write_word_swapped(client, OPT3001_LOW_LIMIT, value); if (ret < 0) { - dev_err(opt->dev, "failed to write register %02x\n", - OPT3001_LOW_LIMIT); + dev_err(dev, "failed to write register %02x\n", + OPT3001_LOW_LIMIT); return ret; } } @@ -446,13 +445,15 @@ static int opt3001_get_int_time(struct opt3001 *opt, int *val, int *val2) static int opt3001_set_int_time(struct opt3001 *opt, int time) { + struct i2c_client *client = opt->client; + struct device *dev = &client->dev; int ret; u16 reg; - ret = i2c_smbus_read_word_swapped(opt->client, OPT3001_CONFIGURATION); + ret = i2c_smbus_read_word_swapped(client, OPT3001_CONFIGURATION); if (ret < 0) { - dev_err(opt->dev, "failed to read register %02x\n", - OPT3001_CONFIGURATION); + dev_err(dev, "failed to read register %02x\n", + OPT3001_CONFIGURATION); return ret; } @@ -471,8 +472,7 @@ static int opt3001_set_int_time(struct opt3001 *opt, int time) return -EINVAL; } - return i2c_smbus_write_word_swapped(opt->client, OPT3001_CONFIGURATION, - reg); + return i2c_smbus_write_word_swapped(client, OPT3001_CONFIGURATION, reg); } static int opt3001_read_raw(struct iio_dev *iio, @@ -567,6 +567,8 @@ static int opt3001_write_event_value(struct iio_dev *iio, int val, int val2) { struct opt3001 *opt = iio_priv(iio); + struct i2c_client *client = opt->client; + struct device *dev = &client->dev; int ret; int whole; int integer; @@ -585,7 +587,7 @@ static int opt3001_write_event_value(struct iio_dev *iio, ret = opt3001_find_scale(opt, val, val2, &exponent); if (ret < 0) { - dev_err(opt->dev, "can't find scale for %d.%06u\n", val, val2); + dev_err(dev, "can't find scale for %d.%06u\n", val, val2); goto err; } @@ -613,9 +615,9 @@ static int opt3001_write_event_value(struct iio_dev *iio, goto err; } - ret = i2c_smbus_write_word_swapped(opt->client, reg, value); + ret = i2c_smbus_write_word_swapped(client, reg, value); if (ret < 0) { - dev_err(opt->dev, "failed to write register %02x\n", reg); + dev_err(dev, "failed to write register %02x\n", reg); goto err; } @@ -639,6 +641,8 @@ static int opt3001_write_event_config(struct iio_dev *iio, enum iio_event_direction dir, bool state) { struct opt3001 *opt = iio_priv(iio); + struct i2c_client *client = opt->client; + struct device *dev = &client->dev; int ret; u16 mode; u16 reg; @@ -654,21 +658,20 @@ static int opt3001_write_event_config(struct iio_dev *iio, mode = state ? OPT3001_CONFIGURATION_M_CONTINUOUS : OPT3001_CONFIGURATION_M_SHUTDOWN; - ret = i2c_smbus_read_word_swapped(opt->client, OPT3001_CONFIGURATION); + ret = i2c_smbus_read_word_swapped(client, OPT3001_CONFIGURATION); if (ret < 0) { - dev_err(opt->dev, "failed to read register %02x\n", - OPT3001_CONFIGURATION); + dev_err(dev, "failed to read register %02x\n", + OPT3001_CONFIGURATION); goto err; } reg = ret; opt3001_set_mode(opt, ®, mode); - ret = i2c_smbus_write_word_swapped(opt->client, OPT3001_CONFIGURATION, - reg); + ret = i2c_smbus_write_word_swapped(client, OPT3001_CONFIGURATION, reg); if (ret < 0) { - dev_err(opt->dev, "failed to write register %02x\n", - OPT3001_CONFIGURATION); + dev_err(dev, "failed to write register %02x\n", + OPT3001_CONFIGURATION); goto err; } @@ -690,13 +693,15 @@ static const struct iio_info opt3001_info = { static int opt3001_read_id(struct opt3001 *opt) { + struct i2c_client *client = opt->client; + struct device *dev = &client->dev; char manufacturer[2]; u16 device_id; int ret; - ret = i2c_smbus_read_word_swapped(opt->client, OPT3001_MANUFACTURER_ID); + ret = i2c_smbus_read_word_swapped(client, OPT3001_MANUFACTURER_ID); if (ret < 0) { - dev_err(opt->dev, "failed to read register %02x\n", + dev_err(dev, "failed to read register %02x\n", OPT3001_MANUFACTURER_ID); return ret; } @@ -704,29 +709,31 @@ static int opt3001_read_id(struct opt3001 *opt) manufacturer[0] = ret >> 8; manufacturer[1] = ret & 0xff; - ret = i2c_smbus_read_word_swapped(opt->client, OPT3001_DEVICE_ID); + ret = i2c_smbus_read_word_swapped(client, OPT3001_DEVICE_ID); if (ret < 0) { - dev_err(opt->dev, "failed to read register %02x\n", + dev_err(dev, "failed to read register %02x\n", OPT3001_DEVICE_ID); return ret; } device_id = ret; - dev_info(opt->dev, "Found %c%c OPT%04x\n", manufacturer[0], - manufacturer[1], device_id); + dev_info(dev, "Found %c%c OPT%04x\n", manufacturer[0], manufacturer[1], + device_id); return 0; } static int opt3001_configure(struct opt3001 *opt) { + struct i2c_client *client = opt->client; + struct device *dev = &client->dev; int ret; u16 reg; - ret = i2c_smbus_read_word_swapped(opt->client, OPT3001_CONFIGURATION); + ret = i2c_smbus_read_word_swapped(client, OPT3001_CONFIGURATION); if (ret < 0) { - dev_err(opt->dev, "failed to read register %02x\n", + dev_err(dev, "failed to read register %02x\n", OPT3001_CONFIGURATION); return ret; } @@ -752,17 +759,16 @@ static int opt3001_configure(struct opt3001 *opt) reg &= ~OPT3001_CONFIGURATION_ME; reg &= ~OPT3001_CONFIGURATION_FC_MASK; - ret = i2c_smbus_write_word_swapped(opt->client, OPT3001_CONFIGURATION, - reg); + ret = i2c_smbus_write_word_swapped(client, OPT3001_CONFIGURATION, reg); if (ret < 0) { - dev_err(opt->dev, "failed to write register %02x\n", + dev_err(dev, "failed to write register %02x\n", OPT3001_CONFIGURATION); return ret; } - ret = i2c_smbus_read_word_swapped(opt->client, OPT3001_LOW_LIMIT); + ret = i2c_smbus_read_word_swapped(client, OPT3001_LOW_LIMIT); if (ret < 0) { - dev_err(opt->dev, "failed to read register %02x\n", + dev_err(dev, "failed to read register %02x\n", OPT3001_LOW_LIMIT); return ret; } @@ -770,9 +776,9 @@ static int opt3001_configure(struct opt3001 *opt) opt->low_thresh_mantissa = OPT3001_REG_MANTISSA(ret); opt->low_thresh_exp = OPT3001_REG_EXPONENT(ret); - ret = i2c_smbus_read_word_swapped(opt->client, OPT3001_HIGH_LIMIT); + ret = i2c_smbus_read_word_swapped(client, OPT3001_HIGH_LIMIT); if (ret < 0) { - dev_err(opt->dev, "failed to read register %02x\n", + dev_err(dev, "failed to read register %02x\n", OPT3001_HIGH_LIMIT); return ret; } @@ -787,6 +793,8 @@ static irqreturn_t opt3001_irq(int irq, void *_iio) { struct iio_dev *iio = _iio; struct opt3001 *opt = iio_priv(iio); + struct i2c_client *client = opt->client; + struct device *dev = &client->dev; int ret; bool wake_result_ready_queue = false; enum iio_chan_type chan_type = opt->chip_info->chan_type; @@ -795,10 +803,10 @@ static irqreturn_t opt3001_irq(int irq, void *_iio) if (!ok_to_ignore_lock) mutex_lock(&opt->lock); - ret = i2c_smbus_read_word_swapped(opt->client, OPT3001_CONFIGURATION); + ret = i2c_smbus_read_word_swapped(client, OPT3001_CONFIGURATION); if (ret < 0) { - dev_err(opt->dev, "failed to read register %02x\n", - OPT3001_CONFIGURATION); + dev_err(dev, "failed to read register %02x\n", + OPT3001_CONFIGURATION); goto out; } @@ -817,10 +825,10 @@ static irqreturn_t opt3001_irq(int irq, void *_iio) IIO_EV_DIR_FALLING), iio_get_time_ns(iio)); } else if (ret & OPT3001_CONFIGURATION_CRF) { - ret = i2c_smbus_read_word_swapped(opt->client, OPT3001_RESULT); + ret = i2c_smbus_read_word_swapped(client, OPT3001_RESULT); if (ret < 0) { - dev_err(opt->dev, "failed to read register %02x\n", - OPT3001_RESULT); + dev_err(dev, "failed to read register %02x\n", + OPT3001_RESULT); goto out; } opt->result = ret; @@ -853,7 +861,6 @@ static int opt3001_probe(struct i2c_client *client) opt = iio_priv(iio); opt->client = client; - opt->dev = dev; opt->chip_info = i2c_get_match_data(client); mutex_init(&opt->lock); @@ -887,7 +894,7 @@ static int opt3001_probe(struct i2c_client *client) } opt->use_irq = true; } else { - dev_dbg(opt->dev, "enabling interrupt-less operation\n"); + dev_dbg(dev, "enabling interrupt-less operation\n"); } ret = iio_device_register(iio); @@ -907,6 +914,7 @@ static void opt3001_remove(struct i2c_client *client) { struct iio_dev *iio = i2c_get_clientdata(client); struct opt3001 *opt = iio_priv(iio); + struct device *dev = &client->dev; int ret; u16 reg; @@ -915,21 +923,20 @@ static void opt3001_remove(struct i2c_client *client) if (opt->use_irq) free_irq(client->irq, iio); - ret = i2c_smbus_read_word_swapped(opt->client, OPT3001_CONFIGURATION); + ret = i2c_smbus_read_word_swapped(client, OPT3001_CONFIGURATION); if (ret < 0) { - dev_err(opt->dev, "failed to read register %02x\n", - OPT3001_CONFIGURATION); + dev_err(dev, "failed to read register %02x\n", + OPT3001_CONFIGURATION); return; } reg = ret; opt3001_set_mode(opt, ®, OPT3001_CONFIGURATION_M_SHUTDOWN); - ret = i2c_smbus_write_word_swapped(opt->client, OPT3001_CONFIGURATION, - reg); + ret = i2c_smbus_write_word_swapped(client, OPT3001_CONFIGURATION, reg); if (ret < 0) { - dev_err(opt->dev, "failed to write register %02x\n", - OPT3001_CONFIGURATION); + dev_err(dev, "failed to write register %02x\n", + OPT3001_CONFIGURATION); } } |
