Re: [PATCH v2 5/5] iio: gyro: bmg160: use regmap to retrieve struct device
From: Srinivas Pandruvada
Date: Mon Apr 18 2016 - 11:03:47 EST
On Sat, 2016-04-16 at 20:24 +0100, Jonathan Cameron wrote:
> On 10/04/16 20:08, 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>
> Cc'd Srinivas
>
> Actually I'm curious as to why linux-arm-kernel and linux-samsung-soc
> are cc'd?
> Not terribly relevant lists...
> >
> > ---
> > Âdrivers/iio/gyro/bmg160_core.c | 86 +++++++++++++++++++++---------
> > ------------
> > Â1 file changed, 44 insertions(+), 42 deletions(-)
> >
> > diff --git a/drivers/iio/gyro/bmg160_core.c
> > b/drivers/iio/gyro/bmg160_core.c
> > index 2493bb1..b2b1071 100644
> > --- a/drivers/iio/gyro/bmg160_core.c
> > +++ b/drivers/iio/gyro/bmg160_core.c
> > @@ -95,7 +95,6 @@
> > Â#define BMG160_AUTO_SUSPEND_DELAY_MS 2000
> > Â
> > Âstruct bmg160_data {
> > - struct device *dev;
> > Â struct regmap *regmap;
> > Â struct iio_trigger *dready_trig;
> > Â struct iio_trigger *motion_trig;
> > @@ -137,11 +136,12 @@ static const struct {
> > Â
> > Âstatic int bmg160_set_mode(struct bmg160_data *data, u8 mode)
> > Â{
> > + struct device *dev = regmap_get_device(data->regmap);
> > Â int ret;
> > Â
> > Â ret = regmap_write(data->regmap, BMG160_REG_PMU_LPW,
> > mode);
> > Â if (ret < 0) {
> > - dev_err(data->dev, "Error writing reg_pmu_lpw\n");
> > + dev_err(dev, "Error writing reg_pmu_lpw\n");
> > Â return ret;
> > Â }
> > Â
> > @@ -162,6 +162,7 @@ static int bmg160_convert_freq_to_bit(int val)
> > Â
> > Âstatic int bmg160_set_bw(struct bmg160_data *data, int val)
> > Â{
> > + struct device *dev = regmap_get_device(data->regmap);
> > Â int ret;
> > Â int bw_bits;
> > Â
> > @@ -171,7 +172,7 @@ static int bmg160_set_bw(struct bmg160_data
> > *data, int val)
> > Â
> > Â ret = regmap_write(data->regmap, BMG160_REG_PMU_BW,
> > bw_bits);
> > Â if (ret < 0) {
> > - dev_err(data->dev, "Error writing reg_pmu_bw\n");
> > + dev_err(dev, "Error writing reg_pmu_bw\n");
> > Â return ret;
> > Â }
> > Â
> > @@ -182,18 +183,19 @@ static int bmg160_set_bw(struct bmg160_data
> > *data, int val)
> > Â
> > Âstatic int bmg160_chip_init(struct bmg160_data *data)
> > Â{
> > + struct device *dev = regmap_get_device(data->regmap);
> > Â int ret;
> > Â unsigned int val;
> > Â
> > Â ret = regmap_read(data->regmap, BMG160_REG_CHIP_ID, &val);
> > Â if (ret < 0) {
> > - dev_err(data->dev, "Error reading reg_chip_id\n");
> > + dev_err(dev, "Error reading reg_chip_id\n");
> > Â return ret;
> > Â }
> > Â
> > - dev_dbg(data->dev, "Chip Id %x\n", val);
> > + dev_dbg(dev, "Chip Id %x\n", val);
> > Â if (val != BMG160_CHIP_ID_VAL) {
> > - dev_err(data->dev, "invalid chip %x\n", val);
> > + dev_err(dev, "invalid chip %x\n", val);
> > Â return -ENODEV;
> > Â }
> > Â
> > @@ -212,14 +214,14 @@ static int bmg160_chip_init(struct
> > bmg160_data *data)
> > Â /* Set Default Range */
> > Â ret = regmap_write(data->regmap, BMG160_REG_RANGE,
> > BMG160_RANGE_500DPS);
> > Â if (ret < 0) {
> > - dev_err(data->dev, "Error writing reg_range\n");
> > + dev_err(dev, "Error writing reg_range\n");
> > Â return ret;
> > Â }
> > Â data->dps_range = BMG160_RANGE_500DPS;
> > Â
> > Â ret = regmap_read(data->regmap, BMG160_REG_SLOPE_THRES,
> > &val);
> > Â if (ret < 0) {
> > - dev_err(data->dev, "Error reading
> > reg_slope_thres\n");
> > + dev_err(dev, "Error reading reg_slope_thres\n");
> > Â return ret;
> > Â }
> > Â data->slope_thres = val;
> > @@ -228,7 +230,7 @@ static int bmg160_chip_init(struct bmg160_data
> > *data)
> > Â ret = regmap_update_bits(data->regmap,
> > BMG160_REG_INT_EN_1,
> > Â ÂBMG160_INT1_BIT_OD, 0);
> > Â if (ret < 0) {
> > - dev_err(data->dev, "Error updating bits in
> > reg_int_en_1\n");
> > + dev_err(dev, "Error updating bits in
> > reg_int_en_1\n");
> > Â return ret;
> > Â }
> > Â
> > @@ -236,7 +238,7 @@ static int bmg160_chip_init(struct bmg160_data
> > *data)
> > Â ÂÂÂBMG160_INT_MODE_LATCH_INT |
> > Â ÂÂÂBMG160_INT_MODE_LATCH_RESET);
> > Â if (ret < 0) {
> > - dev_err(data->dev,
> > + dev_err(dev,
> > Â "Error writing reg_motion_intr\n");
> > Â return ret;
> > Â }
> > @@ -247,20 +249,21 @@ static int bmg160_chip_init(struct
> > bmg160_data *data)
> > Âstatic int bmg160_set_power_state(struct bmg160_data *data, bool
> > on)
> > Â{
> > Â#ifdef CONFIG_PM
> > + 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,
> > - "Failed: bmg160_set_power_state for %d\n",
> > on);
> > + dev_err(dev, "Failed: bmg160_set_power_state for
> > %d\n", on);
> > +
> > Â if (on)
> > - pm_runtime_put_noidle(data->dev);
> > + pm_runtime_put_noidle(dev);
> > Â
> > Â return ret;
> > Â }
> > @@ -272,6 +275,7 @@ static int bmg160_set_power_state(struct
> > bmg160_data *data, bool on)
> > Âstatic int bmg160_setup_any_motion_interrupt(struct bmg160_data
> > *data,
> > Â ÂÂÂÂÂbool status)
> > Â{
> > + struct device *dev = regmap_get_device(data->regmap);
> > Â int ret;
> > Â
> > Â /* Enable/Disable INT_MAP0 mapping */
> > @@ -279,7 +283,7 @@ static int
> > bmg160_setup_any_motion_interrupt(struct bmg160_data *data,
> > Â ÂBMG160_INT_MAP_0_BIT_ANY,
> > Â Â(status ?
> > BMG160_INT_MAP_0_BIT_ANY : 0));
> > Â if (ret < 0) {
> > - dev_err(data->dev, "Error updating bits
> > reg_int_map0\n");
> > + dev_err(dev, "Error updating bits
> > reg_int_map0\n");
> > Â return ret;
> > Â }
> > Â
> > @@ -289,8 +293,7 @@ static int
> > bmg160_setup_any_motion_interrupt(struct bmg160_data *data,
> > Â ret = regmap_write(data->regmap,
> > BMG160_REG_SLOPE_THRES,
> > Â ÂÂÂdata->slope_thres);
> > Â if (ret < 0) {
> > - dev_err(data->dev,
> > - "Error writing
> > reg_slope_thres\n");
> > + dev_err(dev, "Error writing
> > reg_slope_thres\n");
> > Â return ret;
> > Â }
> > Â
> > @@ -298,8 +301,7 @@ static int
> > bmg160_setup_any_motion_interrupt(struct bmg160_data *data,
> > Â ÂÂÂBMG160_INT_MOTION_X |
> > BMG160_INT_MOTION_Y |
> > Â ÂÂÂBMG160_INT_MOTION_Z);
> > Â if (ret < 0) {
> > - dev_err(data->dev,
> > - "Error writing
> > reg_motion_intr\n");
> > + dev_err(dev, "Error writing
> > reg_motion_intr\n");
> > Â return ret;
> > Â }
> > Â
> > @@ -314,8 +316,7 @@ static int
> > bmg160_setup_any_motion_interrupt(struct bmg160_data *data,
> > Â ÂÂÂBMG160_INT_MODE_LATCH_I
> > NT |
> > Â ÂÂÂBMG160_INT_MODE_LATCH_R
> > ESET);
> > Â if (ret < 0) {
> > - dev_err(data->dev,
> > - "Error writing
> > reg_rst_latch\n");
> > + dev_err(dev, "Error writing
> > reg_rst_latch\n");
> > Â return ret;
> > Â }
> > Â }
> > @@ -328,7 +329,7 @@ static int
> > bmg160_setup_any_motion_interrupt(struct bmg160_data *data,
> > Â }
> > Â
> > Â if (ret < 0) {
> > - dev_err(data->dev, "Error writing reg_int_en0\n");
> > + dev_err(dev, "Error writing reg_int_en0\n");
> > Â return ret;
> > Â }
> > Â
> > @@ -338,6 +339,7 @@ static int
> > bmg160_setup_any_motion_interrupt(struct bmg160_data *data,
> > Âstatic int bmg160_setup_new_data_interrupt(struct bmg160_data
> > *data,
> > Â ÂÂÂbool status)
> > Â{
> > + struct device *dev = regmap_get_device(data->regmap);
> > Â int ret;
> > Â
> > Â /* Enable/Disable INT_MAP1 mapping */
> > @@ -345,7 +347,7 @@ static int
> > bmg160_setup_new_data_interrupt(struct bmg160_data *data,
> > Â ÂBMG160_INT_MAP_1_BIT_NEW_DATA,
> > Â Â(status ?
> > BMG160_INT_MAP_1_BIT_NEW_DATA : 0));
> > Â if (ret < 0) {
> > - dev_err(data->dev, "Error updating bits in
> > reg_int_map1\n");
> > + dev_err(dev, "Error updating bits in
> > reg_int_map1\n");
> > Â return ret;
> > Â }
> > Â
> > @@ -354,9 +356,8 @@ static int
> > bmg160_setup_new_data_interrupt(struct bmg160_data *data,
> > Â ÂÂÂBMG160_INT_MODE_NON_LATCH_INT |
> > Â ÂÂÂBMG160_INT_MODE_LATCH_RESET);
> > Â if (ret < 0) {
> > - dev_err(data->dev,
> > - "Error writing reg_rst_latch\n");
> > - return ret;
> > + dev_err(dev, "Error writing
> > reg_rst_latch\n");
> > + return ret;
> > Â }
> > Â
> > Â ret = regmap_write(data->regmap,
> > BMG160_REG_INT_EN_0,
> > @@ -368,16 +369,15 @@ static int
> > bmg160_setup_new_data_interrupt(struct bmg160_data *data,
> > Â ÂÂÂBMG160_INT_MODE_LATCH_INT |
> > Â ÂÂÂBMG160_INT_MODE_LATCH_RESET);
> > Â if (ret < 0) {
> > - dev_err(data->dev,
> > - "Error writing reg_rst_latch\n");
> > - return ret;
> > + dev_err(dev, "Error writing
> > reg_rst_latch\n");
> > + return ret;
> > Â }
> > Â
> > Â ret = regmap_write(data->regmap,
> > BMG160_REG_INT_EN_0, 0);
> > Â }
> > Â
> > Â if (ret < 0) {
> > - dev_err(data->dev, "Error writing reg_int_en0\n");
> > + dev_err(dev, "Error writing reg_int_en0\n");
> > Â return ret;
> > Â }
> > Â
> > @@ -400,6 +400,7 @@ static int bmg160_get_bw(struct bmg160_data
> > *data, int *val)
> > Â
> > Âstatic int bmg160_set_scale(struct bmg160_data *data, int val)
> > Â{
> > + struct device *dev = regmap_get_device(data->regmap);
> > Â int ret, i;
> > Â
> > Â for (i = 0; i < ARRAY_SIZE(bmg160_scale_table); ++i) {
> > @@ -407,8 +408,7 @@ static int bmg160_set_scale(struct bmg160_data
> > *data, int val)
> > Â ret = regmap_write(data->regmap,
> > BMG160_REG_RANGE,
> > Â ÂÂÂbmg160_scale_table[i].d
> > ps_range);
> > Â if (ret < 0) {
> > - dev_err(data->dev,
> > - "Error writing
> > reg_range\n");
> > + dev_err(dev, "Error writing
> > reg_range\n");
> > Â return ret;
> > Â }
> > Â data->dps_range =
> > bmg160_scale_table[i].dps_range;
> > @@ -421,6 +421,7 @@ static int bmg160_set_scale(struct bmg160_data
> > *data, int val)
> > Â
> > Âstatic int bmg160_get_temp(struct bmg160_data *data, int *val)
> > Â{
> > + struct device *dev = regmap_get_device(data->regmap);
> > Â int ret;
> > Â unsigned int raw_val;
> > Â
> > @@ -433,7 +434,7 @@ static int bmg160_get_temp(struct bmg160_data
> > *data, int *val)
> > Â
> > Â ret = regmap_read(data->regmap, BMG160_REG_TEMP,
> > &raw_val);
> > Â if (ret < 0) {
> > - dev_err(data->dev, "Error reading reg_temp\n");
> > + dev_err(dev, "Error reading reg_temp\n");
> > Â bmg160_set_power_state(data, false);
> > Â mutex_unlock(&data->mutex);
> > Â return ret;
> > @@ -450,6 +451,7 @@ static int bmg160_get_temp(struct bmg160_data
> > *data, int *val)
> > Â
> > Âstatic int bmg160_get_axis(struct bmg160_data *data, int axis, int
> > *val)
> > Â{
> > + struct device *dev = regmap_get_device(data->regmap);
> > Â int ret;
> > Â unsigned int raw_val;
> > Â
> > @@ -463,7 +465,7 @@ static int bmg160_get_axis(struct bmg160_data
> > *data, int axis, int *val)
> > Â ret = regmap_bulk_read(data->regmap,
> > BMG160_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);
> > Â bmg160_set_power_state(data, false);
> > Â mutex_unlock(&data->mutex);
> > Â return ret;
> > @@ -793,6 +795,7 @@ static int bmg160_trig_try_reen(struct
> > iio_trigger *trig)
> > Â{
> > Â struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig);
> > Â struct bmg160_data *data = iio_priv(indio_dev);
> > + struct device *dev = regmap_get_device(data->regmap);
> > Â int ret;
> > Â
> > Â /* new data interrupts don't need ack */
> > @@ -804,7 +807,7 @@ static int bmg160_trig_try_reen(struct
> > iio_trigger *trig)
> > Â ÂÂÂBMG160_INT_MODE_LATCH_INT |
> > Â ÂÂÂBMG160_INT_MODE_LATCH_RESET);
> > Â if (ret < 0) {
> > - dev_err(data->dev, "Error writing
> > reg_rst_latch\n");
> > + dev_err(dev, "Error writing reg_rst_latch\n");
> > Â return ret;
> > Â }
> > Â
> > @@ -864,13 +867,14 @@ static irqreturn_t bmg160_event_handler(int
> > irq, void *private)
> > Â{
> > Â struct iio_dev *indio_dev = private;
> > Â struct bmg160_data *data = iio_priv(indio_dev);
> > + struct device *dev = regmap_get_device(data->regmap);
> > Â int ret;
> > Â int dir;
> > Â unsigned int val;
> > Â
> > Â ret = regmap_read(data->regmap, BMG160_REG_INT_STATUS_2,
> > &val);
> > Â if (ret < 0) {
> > - dev_err(data->dev, "Error reading
> > reg_int_status2\n");
> > + dev_err(dev, "Error reading reg_int_status2\n");
> > Â goto ack_intr_status;
> > Â }
> > Â
> > @@ -907,8 +911,7 @@ ack_intr_status:
> > Â ÂÂÂBMG160_INT_MODE_LATCH_INT |
> > Â ÂÂÂBMG160_INT_MODE_LATCH_RESET);
> > Â if (ret < 0)
> > - dev_err(data->dev,
> > - "Error writing reg_rst_latch\n");
> > + dev_err(dev, "Error writing
> > reg_rst_latch\n");
> > Â }
> > Â
> > Â return IRQ_HANDLED;
> > @@ -976,7 +979,6 @@ int bmg160_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;
> > Â
> > @@ -1139,7 +1141,7 @@ static int bmg160_runtime_suspend(struct
> > device *dev)
> > Â
> > Â ret = bmg160_set_mode(data, BMG160_MODE_SUSPEND);
> > Â if (ret < 0) {
> > - dev_err(data->dev, "set mode failed\n");
> > + dev_err(dev, "set mode failed\n");
> > Â return -EAGAIN;
> > Â }
> > Â
> >