Re: [PATCH v2 1/5] iio: accel: bmc150: use regmap to retrieve struct device

From: Srinivas Pandruvada
Date: Mon Apr 18 2016 - 10:59:17 EST


On Sat, 2016-04-16 at 20:20 +0100, Jonathan Cameron wrote:
> On 10/04/16 20:05, Alison Schofield wrote:
> >
> > Driver includes struct regmap and struct device in its global data.
> > Remove the struct device and use regmap API to retrieve device
> > info.
> >
> > Patch created using Coccinelle plus manual edits.
> >
> > Signed-off-by: Alison Schofield <amsfield22@xxxxxxxxx>
Reviewed-by: Srinivas Pandruvada <srinivas.pandruvada@xxxxxxxxxxxxxxx>

> I'm happy with this but please do make sure to cc the maintainer /
> author
> of drivers if possible (often the email addresses are out of date!)
>
> Srinivas, this is one of yours.ÂÂAre you happy with this?
> I've also cc'd Irina who has worked on this driver recently for any
> comments.
>
> If no one comments in the meantime I'll probably pick these up
> sometime
> in the next week.
>
> Jonathan
> >
> > ---
> > Âdrivers/iio/accel/bmc150-accel-core.c | 99 +++++++++++++++++++--
> > --------------
> > Â1 file changed, 54 insertions(+), 45 deletions(-)
> >
> > diff --git a/drivers/iio/accel/bmc150-accel-core.c
> > b/drivers/iio/accel/bmc150-accel-core.c
> > index f3d096f..ad5310b 100644
> > --- a/drivers/iio/accel/bmc150-accel-core.c
> > +++ b/drivers/iio/accel/bmc150-accel-core.c
> > @@ -188,7 +188,6 @@ enum bmc150_accel_trigger_id {
> > Â
> > Âstruct bmc150_accel_data {
> > Â struct regmap *regmap;
> > - struct device *dev;
> > Â int irq;
> > Â struct bmc150_accel_interrupt
> > interrupts[BMC150_ACCEL_INTERRUPTS];
> > Â atomic_t active_intr;
> > @@ -256,6 +255,7 @@ static int bmc150_accel_set_mode(struct
> > bmc150_accel_data *data,
> > Â Âenum bmc150_power_modes mode,
> > Â Âint dur_us)
> > Â{
> > + struct device *dev = regmap_get_device(data->regmap);
> > Â int i;
> > Â int ret;
> > Â u8 lpw_bits;
> > @@ -279,11 +279,11 @@ static int bmc150_accel_set_mode(struct
> > bmc150_accel_data *data,
> > Â lpw_bits = mode << BMC150_ACCEL_PMU_MODE_SHIFT;
> > Â lpw_bits |= (dur_val <<
> > BMC150_ACCEL_PMU_BIT_SLEEP_DUR_SHIFT);
> > Â
> > - dev_dbg(data->dev, "Set Mode bits %x\n", lpw_bits);
> > + dev_dbg(dev, "Set Mode bits %x\n", lpw_bits);
> > Â
> > Â ret = regmap_write(data->regmap, BMC150_ACCEL_REG_PMU_LPW,
> > lpw_bits);
> > Â if (ret < 0) {
> > - dev_err(data->dev, "Error writing reg_pmu_lpw\n");
> > + dev_err(dev, "Error writing reg_pmu_lpw\n");
> > Â return ret;
> > Â }
> > Â
> > @@ -316,23 +316,24 @@ static int bmc150_accel_set_bw(struct
> > bmc150_accel_data *data, int val,
> > Â
> > Âstatic int bmc150_accel_update_slope(struct bmc150_accel_data
> > *data)
> > Â{
> > + struct device *dev = regmap_get_device(data->regmap);
> > Â int ret;
> > Â
> > Â ret = regmap_write(data->regmap, BMC150_ACCEL_REG_INT_6,
> > Â data->slope_thres);
> > Â if (ret < 0) {
> > - dev_err(data->dev, "Error writing reg_int_6\n");
> > + dev_err(dev, "Error writing reg_int_6\n");
> > Â return ret;
> > Â }
> > Â
> > Â ret = regmap_update_bits(data->regmap,
> > BMC150_ACCEL_REG_INT_5,
> > Â ÂBMC150_ACCEL_SLOPE_DUR_MASK,
> > data->slope_dur);
> > Â if (ret < 0) {
> > - dev_err(data->dev, "Error updating reg_int_5\n");
> > + dev_err(dev, "Error updating reg_int_5\n");
> > Â return ret;
> > Â }
> > Â
> > - dev_dbg(data->dev, "%s: %x %x\n", __func__, data-
> > >slope_thres,
> > + dev_dbg(dev, "%s: %x %x\n", __func__, data->slope_thres,
> > Â data->slope_dur);
> > Â
> > Â return ret;
> > @@ -378,20 +379,21 @@ static int
> > bmc150_accel_get_startup_times(struct bmc150_accel_data *data)
> > Â
> > Âstatic int bmc150_accel_set_power_state(struct bmc150_accel_data
> > *data, bool on)
> > Â{
> > + struct device *dev = regmap_get_device(data->regmap);
> > Â int ret;
> > Â
> > Â if (on) {
> > - ret = pm_runtime_get_sync(data->dev);
> > + ret = pm_runtime_get_sync(dev);
> > Â } else {
> > - pm_runtime_mark_last_busy(data->dev);
> > - ret = pm_runtime_put_autosuspend(data->dev);
> > + pm_runtime_mark_last_busy(dev);
> > + ret = pm_runtime_put_autosuspend(dev);
> > Â }
> > Â
> > Â if (ret < 0) {
> > - dev_err(data->dev,
> > + dev_err(dev,
> > Â "Failed: bmc150_accel_set_power_state for
> > %d\n", on);
> > Â if (on)
> > - pm_runtime_put_noidle(data->dev);
> > + pm_runtime_put_noidle(dev);
> > Â
> > Â return ret;
> > Â }
> > @@ -445,6 +447,7 @@ static void
> > bmc150_accel_interrupts_setup(struct iio_dev *indio_dev,
> > Âstatic int bmc150_accel_set_interrupt(struct bmc150_accel_data
> > *data, int i,
> > Â ÂÂÂÂÂÂbool state)
> > Â{
> > + struct device *dev = regmap_get_device(data->regmap);
> > Â struct bmc150_accel_interrupt *intr = &data-
> > >interrupts[i];
> > Â const struct bmc150_accel_interrupt_info *info = intr-
> > >info;
> > Â int ret;
> > @@ -474,7 +477,7 @@ static int bmc150_accel_set_interrupt(struct
> > bmc150_accel_data *data, int i,
> > Â ret = regmap_update_bits(data->regmap, info->map_reg,
> > info->map_bitmask,
> > Â Â(state ? info->map_bitmask : 0));
> > Â if (ret < 0) {
> > - dev_err(data->dev, "Error updating
> > reg_int_map\n");
> > + dev_err(dev, "Error updating reg_int_map\n");
> > Â goto out_fix_power_state;
> > Â }
> > Â
> > @@ -482,7 +485,7 @@ static int bmc150_accel_set_interrupt(struct
> > bmc150_accel_data *data, int i,
> > Â ret = regmap_update_bits(data->regmap, info->en_reg, info-
> > >en_bitmask,
> > Â Â(state ? info->en_bitmask : 0));
> > Â if (ret < 0) {
> > - dev_err(data->dev, "Error updating reg_int_en\n");
> > + dev_err(dev, "Error updating reg_int_en\n");
> > Â goto out_fix_power_state;
> > Â }
> > Â
> > @@ -500,6 +503,7 @@ out_fix_power_state:
> > Â
> > Âstatic int bmc150_accel_set_scale(struct bmc150_accel_data *data,
> > int val)
> > Â{
> > + struct device *dev = regmap_get_device(data->regmap);
> > Â int ret, i;
> > Â
> > Â for (i = 0; i < ARRAY_SIZE(data->chip_info->scale_table);
> > ++i) {
> > @@ -508,8 +512,7 @@ static int bmc150_accel_set_scale(struct
> > bmc150_accel_data *data, int val)
> > Â ÂÂÂÂÂBMC150_ACCEL_REG_PMU_RANGE,
> > Â ÂÂÂÂÂdata->chip_info-
> > >scale_table[i].reg_range);
> > Â if (ret < 0) {
> > - dev_err(data->dev,
> > - "Error writing
> > pmu_range\n");
> > + dev_err(dev, "Error writing
> > pmu_range\n");
> > Â return ret;
> > Â }
> > Â
> > @@ -523,6 +526,7 @@ static int bmc150_accel_set_scale(struct
> > bmc150_accel_data *data, int val)
> > Â
> > Âstatic int bmc150_accel_get_temp(struct bmc150_accel_data *data,
> > int *val)
> > Â{
> > + struct device *dev = regmap_get_device(data->regmap);
> > Â int ret;
> > Â unsigned int value;
> > Â
> > @@ -530,7 +534,7 @@ static int bmc150_accel_get_temp(struct
> > bmc150_accel_data *data, int *val)
> > Â
> > Â ret = regmap_read(data->regmap, BMC150_ACCEL_REG_TEMP,
> > &value);
> > Â if (ret < 0) {
> > - dev_err(data->dev, "Error reading reg_temp\n");
> > + dev_err(dev, "Error reading reg_temp\n");
> > Â mutex_unlock(&data->mutex);
> > Â return ret;
> > Â }
> > @@ -545,6 +549,7 @@ static int bmc150_accel_get_axis(struct
> > bmc150_accel_data *data,
> > Â Âstruct iio_chan_spec const *chan,
> > Â Âint *val)
> > Â{
> > + struct device *dev = regmap_get_device(data->regmap);
> > Â int ret;
> > Â int axis = chan->scan_index;
> > Â unsigned int raw_val;
> > @@ -559,7 +564,7 @@ static int bmc150_accel_get_axis(struct
> > bmc150_accel_data *data,
> > Â ret = regmap_bulk_read(data->regmap,
> > BMC150_ACCEL_AXIS_TO_REG(axis),
> > Â ÂÂÂÂÂÂÂ&raw_val, 2);
> > Â if (ret < 0) {
> > - dev_err(data->dev, "Error reading axis %d\n",
> > axis);
> > + dev_err(dev, "Error reading axis %d\n", axis);
> > Â bmc150_accel_set_power_state(data, false);
> > Â mutex_unlock(&data->mutex);
> > Â return ret;
> > @@ -831,6 +836,7 @@ static int bmc150_accel_set_watermark(struct
> > iio_dev *indio_dev, unsigned val)
> > Âstatic int bmc150_accel_fifo_transfer(struct bmc150_accel_data
> > *data,
> > Â ÂÂÂÂÂÂchar *buffer, int samples)
> > Â{
> > + struct device *dev = regmap_get_device(data->regmap);
> > Â int sample_length = 3 * 2;
> > Â int ret;
> > Â int total_length = samples * sample_length;
> > @@ -854,7 +860,8 @@ static int bmc150_accel_fifo_transfer(struct
> > bmc150_accel_data *data,
> > Â }
> > Â
> > Â if (ret)
> > - dev_err(data->dev, "Error transferring data from
> > fifo in single steps of %zu\n",
> > + dev_err(dev,
> > + "Error transferring data from fifo in
> > single steps of %zu\n",
> > Â step);
> > Â
> > Â return ret;
> > @@ -864,6 +871,7 @@ static int __bmc150_accel_fifo_flush(struct
> > iio_dev *indio_dev,
> > Â ÂÂÂÂÂunsigned samples, bool irq)
> > Â{
> > Â struct bmc150_accel_data *data = iio_priv(indio_dev);
> > + struct device *dev = regmap_get_device(data->regmap);
> > Â int ret, i;
> > Â u8 count;
> > Â u16 buffer[BMC150_ACCEL_FIFO_LENGTH * 3];
> > @@ -873,7 +881,7 @@ static int __bmc150_accel_fifo_flush(struct
> > iio_dev *indio_dev,
> > Â
> > Â ret = regmap_read(data->regmap,
> > BMC150_ACCEL_REG_FIFO_STATUS, &val);
> > Â if (ret < 0) {
> > - dev_err(data->dev, "Error reading
> > reg_fifo_status\n");
> > + dev_err(dev, "Error reading reg_fifo_status\n");
> > Â return ret;
> > Â }
> > Â
> > @@ -1135,6 +1143,7 @@ static int bmc150_accel_trig_try_reen(struct
> > iio_trigger *trig)
> > Â{
> > Â struct bmc150_accel_trigger *t =
> > iio_trigger_get_drvdata(trig);
> > Â struct bmc150_accel_data *data = t->data;
> > + struct device *dev = regmap_get_device(data->regmap);
> > Â int ret;
> > Â
> > Â /* new data interrupts don't need ack */
> > @@ -1148,8 +1157,7 @@ static int bmc150_accel_trig_try_reen(struct
> > iio_trigger *trig)
> > Â ÂÂÂBMC150_ACCEL_INT_MODE_LATCH_RESET);
> > Â mutex_unlock(&data->mutex);
> > Â if (ret < 0) {
> > - dev_err(data->dev,
> > - "Error writing reg_int_rst_latch\n");
> > + dev_err(dev, "Error writing reg_int_rst_latch\n");
> > Â return ret;
> > Â }
> > Â
> > @@ -1200,13 +1208,14 @@ static const struct iio_trigger_ops
> > bmc150_accel_trigger_ops = {
> > Âstatic int bmc150_accel_handle_roc_event(struct iio_dev
> > *indio_dev)
> > Â{
> > Â struct bmc150_accel_data *data = iio_priv(indio_dev);
> > + struct device *dev = regmap_get_device(data->regmap);
> > Â int dir;
> > Â int ret;
> > Â unsigned int val;
> > Â
> > Â ret = regmap_read(data->regmap,
> > BMC150_ACCEL_REG_INT_STATUS_2, &val);
> > Â if (ret < 0) {
> > - dev_err(data->dev, "Error reading
> > reg_int_status_2\n");
> > + dev_err(dev, "Error reading reg_int_status_2\n");
> > Â return ret;
> > Â }
> > Â
> > @@ -1249,6 +1258,7 @@ static irqreturn_t
> > bmc150_accel_irq_thread_handler(int irq, void *private)
> > Â{
> > Â struct iio_dev *indio_dev = private;
> > Â struct bmc150_accel_data *data = iio_priv(indio_dev);
> > + struct device *dev = regmap_get_device(data->regmap);
> > Â bool ack = false;
> > Â int ret;
> > Â
> > @@ -1272,7 +1282,7 @@ static irqreturn_t
> > bmc150_accel_irq_thread_handler(int irq, void *private)
> > Â ÂÂÂBMC150_ACCEL_INT_MODE_LATCH_INT
> > |
> > Â ÂÂÂBMC150_ACCEL_INT_MODE_LATCH_RES
> > ET);
> > Â if (ret)
> > - dev_err(data->dev, "Error writing
> > reg_int_rst_latch\n");
> > + dev_err(dev, "Error writing
> > reg_int_rst_latch\n");
> > Â
> > Â ret = IRQ_HANDLED;
> > Â } else {
> > @@ -1343,13 +1353,14 @@ static void
> > bmc150_accel_unregister_triggers(struct bmc150_accel_data *data,
> > Âstatic int bmc150_accel_triggers_setup(struct iio_dev *indio_dev,
> > Â ÂÂÂÂÂÂÂstruct bmc150_accel_data
> > *data)
> > Â{
> > + struct device *dev = regmap_get_device(data->regmap);
> > Â int i, ret;
> > Â
> > Â for (i = 0; i < BMC150_ACCEL_TRIGGERS; i++) {
> > Â struct bmc150_accel_trigger *t = &data-
> > >triggers[i];
> > Â
> > - t->indio_trig = devm_iio_trigger_alloc(data->dev,
> > - ÂÂÂÂÂÂÂbmc150_accel_trigge
> > rs[i].name,
> > + t->indio_trig = devm_iio_trigger_alloc(dev,
> > + bmc150_accel_triggers[i].n
> > ame,
> > Â ÂÂÂÂÂÂÂindio_dev-
> > >name,
> > Â ÂÂÂÂÂÂÂindio_dev-
> > >id);
> > Â if (!t->indio_trig) {
> > @@ -1357,7 +1368,7 @@ static int bmc150_accel_triggers_setup(struct
> > iio_dev *indio_dev,
> > Â break;
> > Â }
> > Â
> > - t->indio_trig->dev.parent = data->dev;
> > + t->indio_trig->dev.parent = dev;
> > Â t->indio_trig->ops = &bmc150_accel_trigger_ops;
> > Â t->intr = bmc150_accel_triggers[i].intr;
> > Â t->data = data;
> > @@ -1381,12 +1392,13 @@ static int
> > bmc150_accel_triggers_setup(struct iio_dev *indio_dev,
> > Â
> > Âstatic int bmc150_accel_fifo_set_mode(struct bmc150_accel_data
> > *data)
> > Â{
> > + struct device *dev = regmap_get_device(data->regmap);
> > Â u8 reg = BMC150_ACCEL_REG_FIFO_CONFIG1;
> > Â int ret;
> > Â
> > Â ret = regmap_write(data->regmap, reg, data->fifo_mode);
> > Â if (ret < 0) {
> > - dev_err(data->dev, "Error writing
> > reg_fifo_config1\n");
> > + dev_err(dev, "Error writing reg_fifo_config1\n");
> > Â return ret;
> > Â }
> > Â
> > @@ -1396,7 +1408,7 @@ static int bmc150_accel_fifo_set_mode(struct
> > bmc150_accel_data *data)
> > Â ret = regmap_write(data->regmap,
> > BMC150_ACCEL_REG_FIFO_CONFIG0,
> > Â ÂÂÂdata->watermark);
> > Â if (ret < 0)
> > - dev_err(data->dev, "Error writing
> > reg_fifo_config0\n");
> > + dev_err(dev, "Error writing reg_fifo_config0\n");
> > Â
> > Â return ret;
> > Â}
> > @@ -1480,17 +1492,17 @@ static const struct iio_buffer_setup_ops
> > bmc150_accel_buffer_ops = {
> > Â
> > Âstatic int bmc150_accel_chip_init(struct bmc150_accel_data *data)
> > Â{
> > + struct device *dev = regmap_get_device(data->regmap);
> > Â int ret, i;
> > Â unsigned int val;
> > Â
> > Â ret = regmap_read(data->regmap, BMC150_ACCEL_REG_CHIP_ID,
> > &val);
> > Â if (ret < 0) {
> > - dev_err(data->dev,
> > - "Error: Reading chip id\n");
> > + dev_err(dev, "Error: Reading chip id\n");
> > Â return ret;
> > Â }
> > Â
> > - dev_dbg(data->dev, "Chip Id %x\n", val);
> > + dev_dbg(dev, "Chip Id %x\n", val);
> > Â for (i = 0; i < ARRAY_SIZE(bmc150_accel_chip_info_tbl);
> > i++) {
> > Â if (bmc150_accel_chip_info_tbl[i].chip_id == val)
> > {
> > Â data->chip_info =
> > &bmc150_accel_chip_info_tbl[i];
> > @@ -1499,7 +1511,7 @@ static int bmc150_accel_chip_init(struct
> > bmc150_accel_data *data)
> > Â }
> > Â
> > Â if (!data->chip_info) {
> > - dev_err(data->dev, "Invalid chip %x\n", val);
> > + dev_err(dev, "Invalid chip %x\n", val);
> > Â return -ENODEV;
> > Â }
> > Â
> > @@ -1516,8 +1528,7 @@ static int bmc150_accel_chip_init(struct
> > bmc150_accel_data *data)
> > Â ret = regmap_write(data->regmap,
> > BMC150_ACCEL_REG_PMU_RANGE,
> > Â ÂÂÂBMC150_ACCEL_DEF_RANGE_4G);
> > Â if (ret < 0) {
> > - dev_err(data->dev,
> > - "Error writing
> > reg_pmu_range\n");
> > + dev_err(dev, "Error writing reg_pmu_range\n");
> > Â return ret;
> > Â }
> > Â
> > @@ -1535,8 +1546,7 @@ static int bmc150_accel_chip_init(struct
> > bmc150_accel_data *data)
> > Â ÂÂÂBMC150_ACCEL_INT_MODE_LATCH_INT |
> > Â ÂÂÂBMC150_ACCEL_INT_MODE_LATCH_RESET);
> > Â if (ret < 0) {
> > - dev_err(data->dev,
> > - "Error writing reg_int_rst_latch\n");
> > + dev_err(dev, "Error writing reg_int_rst_latch\n");
> > Â return ret;
> > Â }
> > Â
> > @@ -1556,7 +1566,6 @@ int bmc150_accel_core_probe(struct device
> > *dev, struct regmap *regmap, int irq,
> > Â
> > Â data = iio_priv(indio_dev);
> > Â dev_set_drvdata(dev, indio_dev);
> > - data->dev = dev;
> > Â data->irq = irq;
> > Â
> > Â data->regmap = regmap;
> > @@ -1580,13 +1589,13 @@ int bmc150_accel_core_probe(struct device
> > *dev, struct regmap *regmap, int irq,
> > Â Âbmc150_accel_trigger_hand
> > ler,
> > Â Â&bmc150_accel_buffer_ops)
> > ;
> > Â if (ret < 0) {
> > - dev_err(data->dev, "Failed: iio triggered buffer
> > setup\n");
> > + dev_err(dev, "Failed: iio triggered buffer
> > setup\n");
> > Â return ret;
> > Â }
> > Â
> > Â if (data->irq > 0) {
> > Â ret = devm_request_threaded_irq(
> > - data->dev, data-
> > >irq,
> > + dev, data->irq,
> > Â bmc150_accel_irq_h
> > andler,
> > Â bmc150_accel_irq_t
> > hread_handler,
> > Â IRQF_TRIGGER_RISIN
> > G,
> > @@ -1604,7 +1613,7 @@ int bmc150_accel_core_probe(struct device
> > *dev, struct regmap *regmap, int irq,
> > Â ret = regmap_write(data->regmap,
> > BMC150_ACCEL_REG_INT_RST_LATCH,
> > Â ÂÂÂBMC150_ACCEL_INT_MODE_LATCH_RES
> > ET);
> > Â if (ret < 0) {
> > - dev_err(data->dev, "Error writing
> > reg_int_rst_latch\n");
> > + dev_err(dev, "Error writing
> > reg_int_rst_latch\n");
> > Â goto err_buffer_cleanup;
> > Â }
> > Â
> > @@ -1653,9 +1662,9 @@ int bmc150_accel_core_remove(struct device
> > *dev)
> > Â
> > Â iio_device_unregister(indio_dev);
> > Â
> > - pm_runtime_disable(data->dev);
> > - pm_runtime_set_suspended(data->dev);
> > - pm_runtime_put_noidle(data->dev);
> > + pm_runtime_disable(dev);
> > + pm_runtime_set_suspended(dev);
> > + pm_runtime_put_noidle(dev);
> > Â
> > Â bmc150_accel_unregister_triggers(data,
> > BMC150_ACCEL_TRIGGERS - 1);
> > Â
> > @@ -1704,7 +1713,7 @@ static int
> > bmc150_accel_runtime_suspend(struct device *dev)
> > Â struct bmc150_accel_data *data = iio_priv(indio_dev);
> > Â int ret;
> > Â
> > - dev_dbg(data->dev,ÂÂ__func__);
> > + dev_dbg(dev,ÂÂ__func__);
> > Â ret = bmc150_accel_set_mode(data,
> > BMC150_ACCEL_SLEEP_MODE_SUSPEND, 0);
> > Â if (ret < 0)
> > Â return -EAGAIN;
> > @@ -1719,7 +1728,7 @@ static int bmc150_accel_runtime_resume(struct
> > device *dev)
> > Â int ret;
> > Â int sleep_val;
> > Â
> > - dev_dbg(data->dev,ÂÂ__func__);
> > + dev_dbg(dev,ÂÂ__func__);
> > Â
> > Â ret = bmc150_accel_set_mode(data,
> > BMC150_ACCEL_SLEEP_MODE_NORMAL, 0);
> > Â if (ret < 0)
> >