2016-04-06 05:15:39

by Alison Schofield

[permalink] [raw]
Subject: [PATCH 0/9] iio: use regmap to retrieve struct device

These drivers include both struct regmap and struct device in their
global data. Remove the redundant copy by deleting struct device
from the drivers global data and using regmap API to retrieve when
needed.

This patchset removes all such redundancies in drivers/iio/.

Patches created using Coccinelle plus hand edits for whitespace and
one local var naming collision.

Alison Schofield (9):
iio: adc: exynos_adc: use regmap to retrieve struct device
iio: adc: qcom-spmi-iadc: use regmap to retrieve struct device
iio: adc: qcom-spmi-vadc: use regmap to retrieve struct device
iio: accel: bmc150: use regmap to retrieve struct device
iio: accel: mma7455: use regmap to retrieve struct device
iio: accel: mxc4005: use regmap to retrieve struct device
iio: health: afe4403: use regmap to retrieve struct device
iio: health: afe4404: use regmap to retrieve struct device
iio: gyro: bmg160_core: use regmap to retrieve struct device

drivers/iio/accel/bmc150-accel-core.c | 99 +++++++++++++++++++----------------
drivers/iio/accel/mma7455_core.c | 5 +-
drivers/iio/accel/mxc4005.c | 26 +++++----
drivers/iio/adc/exynos_adc.c | 18 +++----
drivers/iio/adc/qcom-spmi-iadc.c | 32 +++++------
drivers/iio/adc/qcom-spmi-vadc.c | 37 +++++++------
drivers/iio/gyro/bmg160_core.c | 86 +++++++++++++++---------------
drivers/iio/health/afe4403.c | 36 ++++++-------
drivers/iio/health/afe4404.c | 38 +++++++-------
9 files changed, 197 insertions(+), 180 deletions(-)

--
2.1.4


2016-04-06 05:16:00

by Alison Schofield

[permalink] [raw]
Subject: [PATCH 1/9] iio: adc: exynos_adc: use regmap to retrieve struct device

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 <[email protected]>
---
drivers/iio/adc/exynos_adc.c | 18 +++++++++---------
1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/iio/adc/exynos_adc.c b/drivers/iio/adc/exynos_adc.c
index c15756d..0313e0f 100644
--- a/drivers/iio/adc/exynos_adc.c
+++ b/drivers/iio/adc/exynos_adc.c
@@ -130,7 +130,6 @@

struct exynos_adc {
struct exynos_adc_data *data;
- struct device *dev;
struct input_dev *input;
void __iomem *regs;
struct regmap *pmu_map;
@@ -173,11 +172,12 @@ static void exynos_adc_unprepare_clk(struct exynos_adc *info)

static int exynos_adc_prepare_clk(struct exynos_adc *info)
{
+ struct device *dev = regmap_get_device(info->pmu_map);
int ret;

ret = clk_prepare(info->clk);
if (ret) {
- dev_err(info->dev, "failed preparing adc clock: %d\n", ret);
+ dev_err(dev, "failed preparing adc clock: %d\n", ret);
return ret;
}

@@ -185,7 +185,7 @@ static int exynos_adc_prepare_clk(struct exynos_adc *info)
ret = clk_prepare(info->sclk);
if (ret) {
clk_unprepare(info->clk);
- dev_err(info->dev,
+ dev_err(dev,
"failed preparing sclk_adc clock: %d\n", ret);
return ret;
}
@@ -203,11 +203,12 @@ static void exynos_adc_disable_clk(struct exynos_adc *info)

static int exynos_adc_enable_clk(struct exynos_adc *info)
{
+ struct device *dev = regmap_get_device(info->pmu_map);
int ret;

ret = clk_enable(info->clk);
if (ret) {
- dev_err(info->dev, "failed enabling adc clock: %d\n", ret);
+ dev_err(dev, "failed enabling adc clock: %d\n", ret);
return ret;
}

@@ -215,7 +216,7 @@ static int exynos_adc_enable_clk(struct exynos_adc *info)
ret = clk_enable(info->sclk);
if (ret) {
clk_disable(info->clk);
- dev_err(info->dev,
+ dev_err(dev,
"failed enabling sclk_adc clock: %d\n", ret);
return ret;
}
@@ -610,13 +611,14 @@ static irqreturn_t exynos_adc_isr(int irq, void *dev_id)
static irqreturn_t exynos_ts_isr(int irq, void *dev_id)
{
struct exynos_adc *info = dev_id;
- struct iio_dev *dev = dev_get_drvdata(info->dev);
+ struct device *dev = regmap_get_device(info->pmu_map);
+ struct iio_dev *indio_dev = dev_get_drvdata(dev);
u32 x, y;
bool pressed;
int ret;

while (info->input->users) {
- ret = exynos_read_s3c64xx_ts(dev, &x, &y);
+ ret = exynos_read_s3c64xx_ts(indio_dev, &x, &y);
if (ret == -ETIMEDOUT)
break;

@@ -800,8 +802,6 @@ static int exynos_adc_probe(struct platform_device *pdev)

info->tsirq = irq;

- info->dev = &pdev->dev;
-
init_completion(&info->completion);

info->clk = devm_clk_get(&pdev->dev, "adc");
--
2.1.4

2016-04-06 05:16:48

by Alison Schofield

[permalink] [raw]
Subject: [PATCH 2/9] iio: adc: qcom-spmi-iadc: use regmap to retrieve struct device

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 <[email protected]>
---
drivers/iio/adc/qcom-spmi-iadc.c | 32 +++++++++++++++++---------------
1 file changed, 17 insertions(+), 15 deletions(-)

diff --git a/drivers/iio/adc/qcom-spmi-iadc.c b/drivers/iio/adc/qcom-spmi-iadc.c
index fabd24e..f69a057 100644
--- a/drivers/iio/adc/qcom-spmi-iadc.c
+++ b/drivers/iio/adc/qcom-spmi-iadc.c
@@ -102,7 +102,6 @@
/**
* struct iadc_chip - IADC Current ADC device structure.
* @regmap: regmap for register read/write.
- * @dev: This device pointer.
* @base: base offset for the ADC peripheral.
* @rsense: Values of the internal and external sense resister in micro Ohms.
* @poll_eoc: Poll for end of conversion instead of waiting for IRQ.
@@ -113,7 +112,6 @@
*/
struct iadc_chip {
struct regmap *regmap;
- struct device *dev;
u16 base;
bool poll_eoc;
u32 rsense[2];
@@ -170,6 +168,7 @@ static int iadc_set_state(struct iadc_chip *iadc, bool state)

static void iadc_status_show(struct iadc_chip *iadc)
{
+ struct device *dev = regmap_get_device(iadc->regmap);
u8 mode, sta1, chan, dig, en, req;
int ret;

@@ -197,7 +196,7 @@ static void iadc_status_show(struct iadc_chip *iadc)
if (ret < 0)
return;

- dev_err(iadc->dev,
+ dev_err(dev,
"mode:%02x en:%02x chan:%02x dig:%02x req:%02x sta1:%02x\n",
mode, en, chan, dig, req, sta1);
}
@@ -284,6 +283,7 @@ static int iadc_read_result(struct iadc_chip *iadc, u16 *data)

static int iadc_do_conversion(struct iadc_chip *iadc, int chan, u16 *data)
{
+ struct device *dev = regmap_get_device(iadc->regmap);
unsigned int wait;
int ret;

@@ -310,7 +310,7 @@ static int iadc_do_conversion(struct iadc_chip *iadc, int chan, u16 *data)
exit:
iadc_set_state(iadc, false);
if (ret < 0)
- dev_err(iadc->dev, "conversion failed\n");
+ dev_err(dev, "conversion failed\n");

return ret;
}
@@ -320,6 +320,7 @@ static int iadc_read_raw(struct iio_dev *indio_dev,
int *val, int *val2, long mask)
{
struct iadc_chip *iadc = iio_priv(indio_dev);
+ struct device *dev = regmap_get_device(iadc->regmap);
s32 isense_ua, vsense_uv;
u16 adc_raw, vsense_raw;
int ret;
@@ -339,7 +340,7 @@ static int iadc_read_raw(struct iio_dev *indio_dev,

isense_ua = vsense_uv / iadc->rsense[chan->channel];

- dev_dbg(iadc->dev, "off %d gain %d adc %d %duV I %duA\n",
+ dev_dbg(dev, "off %d gain %d adc %d %duV I %duA\n",
iadc->offset[chan->channel], iadc->gain,
adc_raw, vsense_uv, isense_ua);

@@ -370,6 +371,7 @@ static irqreturn_t iadc_isr(int irq, void *dev_id)

static int iadc_update_offset(struct iadc_chip *iadc)
{
+ struct device *dev = regmap_get_device(iadc->regmap);
int ret;

ret = iadc_do_conversion(iadc, IADC_GAIN_17P857MV, &iadc->gain);
@@ -382,7 +384,7 @@ static int iadc_update_offset(struct iadc_chip *iadc)
return ret;

if (iadc->gain == iadc->offset[IADC_INT_RSENSE]) {
- dev_err(iadc->dev, "error: internal offset == gain %d\n",
+ dev_err(dev, "error: internal offset == gain %d\n",
iadc->gain);
return -EINVAL;
}
@@ -393,8 +395,7 @@ static int iadc_update_offset(struct iadc_chip *iadc)
return ret;

if (iadc->gain == iadc->offset[IADC_EXT_RSENSE]) {
- dev_err(iadc->dev, "error: external offset == gain %d\n",
- iadc->gain);
+ dev_err(dev, "error: external offset == gain %d\n", iadc->gain);
return -EINVAL;
}

@@ -403,6 +404,7 @@ static int iadc_update_offset(struct iadc_chip *iadc)

static int iadc_version_check(struct iadc_chip *iadc)
{
+ struct device *dev = regmap_get_device(iadc->regmap);
u8 val;
int ret;

@@ -411,7 +413,7 @@ static int iadc_version_check(struct iadc_chip *iadc)
return ret;

if (val < IADC_PERPH_TYPE_ADC) {
- dev_err(iadc->dev, "%d is not ADC\n", val);
+ dev_err(dev, "%d is not ADC\n", val);
return -EINVAL;
}

@@ -420,7 +422,7 @@ static int iadc_version_check(struct iadc_chip *iadc)
return ret;

if (val < IADC_PERPH_SUBTYPE_IADC) {
- dev_err(iadc->dev, "%d is not IADC\n", val);
+ dev_err(dev, "%d is not IADC\n", val);
return -EINVAL;
}

@@ -429,7 +431,7 @@ static int iadc_version_check(struct iadc_chip *iadc)
return ret;

if (val < IADC_REVISION2_SUPPORTED_IADC) {
- dev_err(iadc->dev, "revision %d not supported\n", val);
+ dev_err(dev, "revision %d not supported\n", val);
return -EINVAL;
}

@@ -438,6 +440,7 @@ static int iadc_version_check(struct iadc_chip *iadc)

static int iadc_rsense_read(struct iadc_chip *iadc, struct device_node *node)
{
+ struct device *dev = regmap_get_device(iadc->regmap);
int ret, sign, int_sense;
u8 deviation;

@@ -447,7 +450,7 @@ static int iadc_rsense_read(struct iadc_chip *iadc, struct device_node *node)
iadc->rsense[IADC_EXT_RSENSE] = IADC_INT_RSENSE_IDEAL_VALUE;

if (!iadc->rsense[IADC_EXT_RSENSE]) {
- dev_err(iadc->dev, "external resistor can't be zero Ohms");
+ dev_err(dev, "external resistor can't be zero Ohms");
return -EINVAL;
}

@@ -505,7 +508,6 @@ static int iadc_probe(struct platform_device *pdev)
return -ENOMEM;

iadc = iio_priv(indio_dev);
- iadc->dev = dev;

iadc->regmap = dev_get_regmap(dev->parent, NULL);
if (!iadc->regmap)
@@ -528,7 +530,7 @@ static int iadc_probe(struct platform_device *pdev)
if (ret < 0)
return -ENODEV;

- dev_dbg(iadc->dev, "sense resistors %d and %d micro Ohm\n",
+ dev_dbg(&pdev->dev, "sense resistors %d and %d micro Ohm\n",
iadc->rsense[IADC_INT_RSENSE],
iadc->rsense[IADC_EXT_RSENSE]);

@@ -553,7 +555,7 @@ static int iadc_probe(struct platform_device *pdev)
else
return ret;
} else {
- device_init_wakeup(iadc->dev, 1);
+ device_init_wakeup(&pdev->dev, 1);
}

ret = iadc_update_offset(iadc);
--
2.1.4

2016-04-06 05:17:35

by Alison Schofield

[permalink] [raw]
Subject: [PATCH 3/9] iio: adc: qcom-spmi-vadc: use regmap to retrieve struct device

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 <[email protected]>
---
drivers/iio/adc/qcom-spmi-vadc.c | 37 ++++++++++++++++++++-----------------
1 file changed, 20 insertions(+), 17 deletions(-)

diff --git a/drivers/iio/adc/qcom-spmi-vadc.c b/drivers/iio/adc/qcom-spmi-vadc.c
index c2babe5..9e7aeca 100644
--- a/drivers/iio/adc/qcom-spmi-vadc.c
+++ b/drivers/iio/adc/qcom-spmi-vadc.c
@@ -161,7 +161,6 @@ struct vadc_channel_prop {
/**
* struct vadc_priv - VADC private structure.
* @regmap: pointer to struct regmap.
- * @dev: pointer to struct device.
* @base: base address for the ADC peripheral.
* @nchannels: number of VADC channels.
* @chan_props: array of VADC channel properties.
@@ -174,7 +173,6 @@ struct vadc_channel_prop {
*/
struct vadc_priv {
struct regmap *regmap;
- struct device *dev;
u16 base;
unsigned int nchannels;
struct vadc_channel_prop *chan_props;
@@ -236,6 +234,7 @@ static int vadc_set_state(struct vadc_priv *vadc, bool state)

static void vadc_show_status(struct vadc_priv *vadc)
{
+ struct device *dev = regmap_get_device(vadc->regmap);
u8 mode, sta1, chan, dig, en, req;
int ret;

@@ -263,7 +262,7 @@ static void vadc_show_status(struct vadc_priv *vadc)
if (ret)
return;

- dev_err(vadc->dev,
+ dev_err(dev,
"mode:%02x en:%02x chan:%02x dig:%02x req:%02x sta1:%02x\n",
mode, en, chan, dig, req, sta1);
}
@@ -350,13 +349,14 @@ static int vadc_read_result(struct vadc_priv *vadc, u16 *data)
static struct vadc_channel_prop *vadc_get_channel(struct vadc_priv *vadc,
unsigned int num)
{
+ struct device *dev = regmap_get_device(vadc->regmap);
unsigned int i;

for (i = 0; i < vadc->nchannels; i++)
if (vadc->chan_props[i].channel == num)
return &vadc->chan_props[i];

- dev_dbg(vadc->dev, "no such channel %02x\n", num);
+ dev_dbg(dev, "no such channel %02x\n", num);

return NULL;
}
@@ -364,6 +364,7 @@ static struct vadc_channel_prop *vadc_get_channel(struct vadc_priv *vadc,
static int vadc_do_conversion(struct vadc_priv *vadc,
struct vadc_channel_prop *prop, u16 *data)
{
+ struct device *dev = regmap_get_device(vadc->regmap);
unsigned int timeout;
int ret;

@@ -406,7 +407,7 @@ static int vadc_do_conversion(struct vadc_priv *vadc,
err_disable:
vadc_set_state(vadc, false);
if (ret)
- dev_err(vadc->dev, "conversion failed\n");
+ dev_err(dev, "conversion failed\n");
unlock:
mutex_unlock(&vadc->lock);
return ret;
@@ -414,6 +415,7 @@ unlock:

static int vadc_measure_ref_points(struct vadc_priv *vadc)
{
+ struct device *dev = regmap_get_device(vadc->regmap);
struct vadc_channel_prop *prop;
u16 read_1, read_2;
int ret;
@@ -463,7 +465,7 @@ static int vadc_measure_ref_points(struct vadc_priv *vadc)
vadc->graph[VADC_CALIB_RATIOMETRIC].gnd = read_2;
err:
if (ret)
- dev_err(vadc->dev, "measure reference points failed\n");
+ dev_err(dev, "measure reference points failed\n");

return ret;
}
@@ -814,6 +816,7 @@ static int vadc_get_dt_channel_data(struct device *dev,

static int vadc_get_dt_data(struct vadc_priv *vadc, struct device_node *node)
{
+ struct device *dev = regmap_get_device(vadc->regmap);
const struct vadc_channels *vadc_chan;
struct iio_chan_spec *iio_chan;
struct vadc_channel_prop prop;
@@ -825,12 +828,12 @@ static int vadc_get_dt_data(struct vadc_priv *vadc, struct device_node *node)
if (!vadc->nchannels)
return -EINVAL;

- vadc->iio_chans = devm_kcalloc(vadc->dev, vadc->nchannels,
+ vadc->iio_chans = devm_kcalloc(dev, vadc->nchannels,
sizeof(*vadc->iio_chans), GFP_KERNEL);
if (!vadc->iio_chans)
return -ENOMEM;

- vadc->chan_props = devm_kcalloc(vadc->dev, vadc->nchannels,
+ vadc->chan_props = devm_kcalloc(dev, vadc->nchannels,
sizeof(*vadc->chan_props), GFP_KERNEL);
if (!vadc->chan_props)
return -ENOMEM;
@@ -838,7 +841,7 @@ static int vadc_get_dt_data(struct vadc_priv *vadc, struct device_node *node)
iio_chan = vadc->iio_chans;

for_each_available_child_of_node(node, child) {
- ret = vadc_get_dt_channel_data(vadc->dev, &prop, child);
+ ret = vadc_get_dt_channel_data(dev, &prop, child);
if (ret) {
of_node_put(child);
return ret;
@@ -860,22 +863,22 @@ static int vadc_get_dt_data(struct vadc_priv *vadc, struct device_node *node)

/* These channels are mandatory, they are used as reference points */
if (!vadc_get_channel(vadc, VADC_REF_1250MV)) {
- dev_err(vadc->dev, "Please define 1.25V channel\n");
+ dev_err(dev, "Please define 1.25V channel\n");
return -ENODEV;
}

if (!vadc_get_channel(vadc, VADC_REF_625MV)) {
- dev_err(vadc->dev, "Please define 0.625V channel\n");
+ dev_err(dev, "Please define 0.625V channel\n");
return -ENODEV;
}

if (!vadc_get_channel(vadc, VADC_VDD_VADC)) {
- dev_err(vadc->dev, "Please define VDD channel\n");
+ dev_err(dev, "Please define VDD channel\n");
return -ENODEV;
}

if (!vadc_get_channel(vadc, VADC_GND_REF)) {
- dev_err(vadc->dev, "Please define GND channel\n");
+ dev_err(dev, "Please define GND channel\n");
return -ENODEV;
}

@@ -893,6 +896,7 @@ static irqreturn_t vadc_isr(int irq, void *dev_id)

static int vadc_check_revision(struct vadc_priv *vadc)
{
+ struct device *dev = regmap_get_device(vadc->regmap);
u8 val;
int ret;

@@ -901,7 +905,7 @@ static int vadc_check_revision(struct vadc_priv *vadc)
return ret;

if (val < VADC_PERPH_TYPE_ADC) {
- dev_err(vadc->dev, "%d is not ADC\n", val);
+ dev_err(dev, "%d is not ADC\n", val);
return -ENODEV;
}

@@ -910,7 +914,7 @@ static int vadc_check_revision(struct vadc_priv *vadc)
return ret;

if (val < VADC_PERPH_SUBTYPE_VADC) {
- dev_err(vadc->dev, "%d is not VADC\n", val);
+ dev_err(dev, "%d is not VADC\n", val);
return -ENODEV;
}

@@ -919,7 +923,7 @@ static int vadc_check_revision(struct vadc_priv *vadc)
return ret;

if (val < VADC_REVISION2_SUPPORTED_VADC) {
- dev_err(vadc->dev, "revision %d not supported\n", val);
+ dev_err(dev, "revision %d not supported\n", val);
return -ENODEV;
}

@@ -950,7 +954,6 @@ static int vadc_probe(struct platform_device *pdev)

vadc = iio_priv(indio_dev);
vadc->regmap = regmap;
- vadc->dev = dev;
vadc->base = reg;
vadc->are_ref_measured = false;
init_completion(&vadc->complete);
--
2.1.4

2016-04-06 05:18:16

by Alison Schofield

[permalink] [raw]
Subject: [PATCH 4/9] iio: accel: bmc150: use regmap to retrieve struct device

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 <[email protected]>
---
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_RESET);
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_triggers[i].name,
+ t->indio_trig = devm_iio_trigger_alloc(dev,
+ bmc150_accel_triggers[i].name,
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_handler,
&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_handler,
bmc150_accel_irq_thread_handler,
IRQF_TRIGGER_RISING,
@@ -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_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");
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)
--
2.1.4

2016-04-06 05:18:49

by Alison Schofield

[permalink] [raw]
Subject: [PATCH 5/9] iio: accel: mma7455: use regmap to retrieve struct device

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 <[email protected]>
---
drivers/iio/accel/mma7455_core.c | 5 ++---
1 file changed, 2 insertions(+), 3 deletions(-)

diff --git a/drivers/iio/accel/mma7455_core.c b/drivers/iio/accel/mma7455_core.c
index c633cc2..c902f54 100644
--- a/drivers/iio/accel/mma7455_core.c
+++ b/drivers/iio/accel/mma7455_core.c
@@ -55,11 +55,11 @@

struct mma7455_data {
struct regmap *regmap;
- struct device *dev;
};

static int mma7455_drdy(struct mma7455_data *mma7455)
{
+ struct device *dev = regmap_get_device(mma7455->regmap);
unsigned int reg;
int tries = 3;
int ret;
@@ -75,7 +75,7 @@ static int mma7455_drdy(struct mma7455_data *mma7455)
msleep(20);
}

- dev_warn(mma7455->dev, "data not ready\n");
+ dev_warn(dev, "data not ready\n");

return -EIO;
}
@@ -260,7 +260,6 @@ int mma7455_core_probe(struct device *dev, struct regmap *regmap,
dev_set_drvdata(dev, indio_dev);
mma7455 = iio_priv(indio_dev);
mma7455->regmap = regmap;
- mma7455->dev = dev;

indio_dev->info = &mma7455_info;
indio_dev->name = name;
--
2.1.4

2016-04-06 05:19:30

by Alison Schofield

[permalink] [raw]
Subject: [PATCH 6/9] iio: accel: mxc4005: use regmap to retrieve struct device

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 <[email protected]>
---
drivers/iio/accel/mxc4005.c | 26 +++++++++++++++-----------
1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/drivers/iio/accel/mxc4005.c b/drivers/iio/accel/mxc4005.c
index c23f47a..013d511 100644
--- a/drivers/iio/accel/mxc4005.c
+++ b/drivers/iio/accel/mxc4005.c
@@ -60,7 +60,6 @@ enum mxc4005_range {
};

struct mxc4005_data {
- struct device *dev;
struct mutex mutex;
struct regmap *regmap;
struct iio_trigger *dready_trig;
@@ -140,12 +139,13 @@ static const struct regmap_config mxc4005_regmap_config = {

static int mxc4005_read_xyz(struct mxc4005_data *data)
{
+ struct device *dev = regmap_get_device(data->regmap);
int ret;

ret = regmap_bulk_read(data->regmap, MXC4005_REG_XOUT_UPPER,
(u8 *) data->buffer, sizeof(data->buffer));
if (ret < 0) {
- dev_err(data->dev, "failed to read axes\n");
+ dev_err(dev, "failed to read axes\n");
return ret;
}

@@ -155,12 +155,13 @@ static int mxc4005_read_xyz(struct mxc4005_data *data)
static int mxc4005_read_axis(struct mxc4005_data *data,
unsigned int addr)
{
+ struct device *dev = regmap_get_device(data->regmap);
__be16 reg;
int ret;

ret = regmap_bulk_read(data->regmap, addr, (u8 *) &reg, sizeof(reg));
if (ret < 0) {
- dev_err(data->dev, "failed to read reg %02x\n", addr);
+ dev_err(dev, "failed to read reg %02x\n", addr);
return ret;
}

@@ -169,13 +170,14 @@ static int mxc4005_read_axis(struct mxc4005_data *data,

static int mxc4005_read_scale(struct mxc4005_data *data)
{
+ struct device *dev = regmap_get_device(data->regmap);
unsigned int reg;
int ret;
int i;

ret = regmap_read(data->regmap, MXC4005_REG_CONTROL, &reg);
if (ret < 0) {
- dev_err(data->dev, "failed to read reg_control\n");
+ dev_err(dev, "failed to read reg_control\n");
return ret;
}

@@ -189,6 +191,7 @@ static int mxc4005_read_scale(struct mxc4005_data *data)

static int mxc4005_set_scale(struct mxc4005_data *data, int val)
{
+ struct device *dev = regmap_get_device(data->regmap);
unsigned int reg;
int i;
int ret;
@@ -201,8 +204,7 @@ static int mxc4005_set_scale(struct mxc4005_data *data, int val)
MXC4005_REG_CONTROL_MASK_FSR,
reg);
if (ret < 0)
- dev_err(data->dev,
- "failed to write reg_control\n");
+ dev_err(dev, "failed to write reg_control\n");
return ret;
}
}
@@ -321,13 +323,14 @@ err:

static int mxc4005_clr_intr(struct mxc4005_data *data)
{
+ struct device *dev = regmap_get_device(data->regmap);
int ret;

/* clear interrupt */
ret = regmap_write(data->regmap, MXC4005_REG_INT_CLR1,
MXC4005_REG_INT_CLR1_BIT_DRDYC);
if (ret < 0) {
- dev_err(data->dev, "failed to write to reg_int_clr1\n");
+ dev_err(dev, "failed to write to reg_int_clr1\n");
return ret;
}

@@ -339,6 +342,7 @@ static int mxc4005_set_trigger_state(struct iio_trigger *trig,
{
struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig);
struct mxc4005_data *data = iio_priv(indio_dev);
+ struct device *dev = regmap_get_device(data->regmap);
int ret;

mutex_lock(&data->mutex);
@@ -352,7 +356,7 @@ static int mxc4005_set_trigger_state(struct iio_trigger *trig,

if (ret < 0) {
mutex_unlock(&data->mutex);
- dev_err(data->dev, "failed to update reg_int_mask1");
+ dev_err(dev, "failed to update reg_int_mask1");
return ret;
}

@@ -381,16 +385,17 @@ static const struct iio_trigger_ops mxc4005_trigger_ops = {

static int mxc4005_chip_init(struct mxc4005_data *data)
{
+ struct device *dev = regmap_get_device(data->regmap);
int ret;
unsigned int reg;

ret = regmap_read(data->regmap, MXC4005_REG_DEVICE_ID, &reg);
if (ret < 0) {
- dev_err(data->dev, "failed to read chip id\n");
+ dev_err(dev, "failed to read chip id\n");
return ret;
}

- dev_dbg(data->dev, "MXC4005 chip id %02x\n", reg);
+ dev_dbg(dev, "MXC4005 chip id %02x\n", reg);

return 0;
}
@@ -415,7 +420,6 @@ static int mxc4005_probe(struct i2c_client *client,

data = iio_priv(indio_dev);
i2c_set_clientdata(client, indio_dev);
- data->dev = &client->dev;
data->regmap = regmap;

ret = mxc4005_chip_init(data);
--
2.1.4

2016-04-06 05:20:06

by Alison Schofield

[permalink] [raw]
Subject: [PATCH 7/9] iio: health: afe4403: use regmap to retrieve struct device

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 <[email protected]>
---
drivers/iio/health/afe4403.c | 36 +++++++++++++++++-------------------
1 file changed, 17 insertions(+), 19 deletions(-)

diff --git a/drivers/iio/health/afe4403.c b/drivers/iio/health/afe4403.c
index 88e43f8..71b8f70 100644
--- a/drivers/iio/health/afe4403.c
+++ b/drivers/iio/health/afe4403.c
@@ -104,7 +104,6 @@

/**
* struct afe4403_data
- * @dev - Device structure
* @spi - SPI device handle
* @regmap - Register map of the device
* @regulator - Pointer to the regulator for the IC
@@ -112,7 +111,6 @@
* @irq - ADC_RDY line interrupt number
*/
struct afe4403_data {
- struct device *dev;
struct spi_device *spi;
struct regmap *regmap;
struct regulator *regulator;
@@ -562,55 +560,54 @@ static int afe4403_probe(struct spi_device *spi)
afe = iio_priv(indio_dev);
spi_set_drvdata(spi, indio_dev);

- afe->dev = &spi->dev;
afe->spi = spi;
afe->irq = spi->irq;

afe->regmap = devm_regmap_init_spi(spi, &afe4403_regmap_config);
if (IS_ERR(afe->regmap)) {
- dev_err(afe->dev, "Unable to allocate register map\n");
+ dev_err(&spi->dev, "Unable to allocate register map\n");
return PTR_ERR(afe->regmap);
}

- afe->regulator = devm_regulator_get(afe->dev, "tx_sup");
+ afe->regulator = devm_regulator_get(&spi->dev, "tx_sup");
if (IS_ERR(afe->regulator)) {
- dev_err(afe->dev, "Unable to get regulator\n");
+ dev_err(&spi->dev, "Unable to get regulator\n");
return PTR_ERR(afe->regulator);
}
ret = regulator_enable(afe->regulator);
if (ret) {
- dev_err(afe->dev, "Unable to enable regulator\n");
+ dev_err(&spi->dev, "Unable to enable regulator\n");
return ret;
}

ret = regmap_write(afe->regmap, AFE440X_CONTROL0,
AFE440X_CONTROL0_SW_RESET);
if (ret) {
- dev_err(afe->dev, "Unable to reset device\n");
+ dev_err(&spi->dev, "Unable to reset device\n");
goto err_disable_reg;
}

ret = regmap_multi_reg_write(afe->regmap, afe4403_reg_sequences,
ARRAY_SIZE(afe4403_reg_sequences));
if (ret) {
- dev_err(afe->dev, "Unable to set register defaults\n");
+ dev_err(&spi->dev, "Unable to set register defaults\n");
goto err_disable_reg;
}

indio_dev->modes = INDIO_DIRECT_MODE;
- indio_dev->dev.parent = afe->dev;
+ indio_dev->dev.parent = &spi->dev;
indio_dev->channels = afe4403_channels;
indio_dev->num_channels = ARRAY_SIZE(afe4403_channels);
indio_dev->name = AFE4403_DRIVER_NAME;
indio_dev->info = &afe4403_iio_info;

if (afe->irq > 0) {
- afe->trig = devm_iio_trigger_alloc(afe->dev,
+ afe->trig = devm_iio_trigger_alloc(&spi->dev,
"%s-dev%d",
indio_dev->name,
indio_dev->id);
if (!afe->trig) {
- dev_err(afe->dev, "Unable to allocate IIO trigger\n");
+ dev_err(&spi->dev, "Unable to allocate IIO trigger\n");
ret = -ENOMEM;
goto err_disable_reg;
}
@@ -618,21 +615,21 @@ static int afe4403_probe(struct spi_device *spi)
iio_trigger_set_drvdata(afe->trig, indio_dev);

afe->trig->ops = &afe4403_trigger_ops;
- afe->trig->dev.parent = afe->dev;
+ afe->trig->dev.parent = &spi->dev;

ret = iio_trigger_register(afe->trig);
if (ret) {
- dev_err(afe->dev, "Unable to register IIO trigger\n");
+ dev_err(&spi->dev, "Unable to register IIO trigger\n");
goto err_disable_reg;
}

- ret = devm_request_threaded_irq(afe->dev, afe->irq,
+ ret = devm_request_threaded_irq(&spi->dev, afe->irq,
iio_trigger_generic_data_rdy_poll,
NULL, IRQF_ONESHOT,
AFE4403_DRIVER_NAME,
afe->trig);
if (ret) {
- dev_err(afe->dev, "Unable to request IRQ\n");
+ dev_err(&spi->dev, "Unable to request IRQ\n");
goto err_trig;
}
}
@@ -640,13 +637,13 @@ static int afe4403_probe(struct spi_device *spi)
ret = iio_triggered_buffer_setup(indio_dev, &iio_pollfunc_store_time,
afe4403_trigger_handler, NULL);
if (ret) {
- dev_err(afe->dev, "Unable to setup buffer\n");
+ dev_err(&spi->dev, "Unable to setup buffer\n");
goto err_trig;
}

ret = iio_device_register(indio_dev);
if (ret) {
- dev_err(afe->dev, "Unable to register IIO device\n");
+ dev_err(&spi->dev, "Unable to register IIO device\n");
goto err_buff;
}

@@ -667,6 +664,7 @@ static int afe4403_remove(struct spi_device *spi)
{
struct iio_dev *indio_dev = spi_get_drvdata(spi);
struct afe4403_data *afe = iio_priv(indio_dev);
+ struct device *dev = regmap_get_device(afe->regmap);
int ret;

iio_device_unregister(indio_dev);
@@ -678,7 +676,7 @@ static int afe4403_remove(struct spi_device *spi)

ret = regulator_disable(afe->regulator);
if (ret) {
- dev_err(afe->dev, "Unable to disable regulator\n");
+ dev_err(dev, "Unable to disable regulator\n");
return ret;
}

--
2.1.4

2016-04-06 05:20:58

by Alison Schofield

[permalink] [raw]
Subject: [PATCH 8/9] iio: health: afe4404: use regmap to retrieve struct device

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 <[email protected]>
---
drivers/iio/health/afe4404.c | 38 +++++++++++++++++++-------------------
1 file changed, 19 insertions(+), 19 deletions(-)

diff --git a/drivers/iio/health/afe4404.c b/drivers/iio/health/afe4404.c
index 5096a46..9cd8590 100644
--- a/drivers/iio/health/afe4404.c
+++ b/drivers/iio/health/afe4404.c
@@ -107,14 +107,12 @@

/**
* struct afe4404_data
- * @dev - Device structure
* @regmap - Register map of the device
* @regulator - Pointer to the regulator for the IC
* @trig - IIO trigger for this device
* @irq - ADC_RDY line interrupt number
*/
struct afe4404_data {
- struct device *dev;
struct regmap *regmap;
struct regulator *regulator;
struct iio_trigger *trig;
@@ -534,54 +532,54 @@ static int afe4404_probe(struct i2c_client *client,
afe = iio_priv(indio_dev);
i2c_set_clientdata(client, indio_dev);

- afe->dev = &client->dev;
afe->irq = client->irq;

afe->regmap = devm_regmap_init_i2c(client, &afe4404_regmap_config);
if (IS_ERR(afe->regmap)) {
- dev_err(afe->dev, "Unable to allocate register map\n");
+ dev_err(&client->dev, "Unable to allocate register map\n");
return PTR_ERR(afe->regmap);
}

- afe->regulator = devm_regulator_get(afe->dev, "tx_sup");
+ afe->regulator = devm_regulator_get(&client->dev, "tx_sup");
if (IS_ERR(afe->regulator)) {
- dev_err(afe->dev, "Unable to get regulator\n");
+ dev_err(&client->dev, "Unable to get regulator\n");
return PTR_ERR(afe->regulator);
}
ret = regulator_enable(afe->regulator);
if (ret) {
- dev_err(afe->dev, "Unable to enable regulator\n");
+ dev_err(&client->dev, "Unable to enable regulator\n");
return ret;
}

ret = regmap_write(afe->regmap, AFE440X_CONTROL0,
AFE440X_CONTROL0_SW_RESET);
if (ret) {
- dev_err(afe->dev, "Unable to reset device\n");
+ dev_err(&client->dev, "Unable to reset device\n");
goto disable_reg;
}

ret = regmap_multi_reg_write(afe->regmap, afe4404_reg_sequences,
ARRAY_SIZE(afe4404_reg_sequences));
if (ret) {
- dev_err(afe->dev, "Unable to set register defaults\n");
+ dev_err(&client->dev, "Unable to set register defaults\n");
goto disable_reg;
}

indio_dev->modes = INDIO_DIRECT_MODE;
- indio_dev->dev.parent = afe->dev;
+ indio_dev->dev.parent = &client->dev;
indio_dev->channels = afe4404_channels;
indio_dev->num_channels = ARRAY_SIZE(afe4404_channels);
indio_dev->name = AFE4404_DRIVER_NAME;
indio_dev->info = &afe4404_iio_info;

if (afe->irq > 0) {
- afe->trig = devm_iio_trigger_alloc(afe->dev,
+ afe->trig = devm_iio_trigger_alloc(&client->dev,
"%s-dev%d",
indio_dev->name,
indio_dev->id);
if (!afe->trig) {
- dev_err(afe->dev, "Unable to allocate IIO trigger\n");
+ dev_err(&client->dev,
+ "Unable to allocate IIO trigger\n");
ret = -ENOMEM;
goto disable_reg;
}
@@ -589,21 +587,22 @@ static int afe4404_probe(struct i2c_client *client,
iio_trigger_set_drvdata(afe->trig, indio_dev);

afe->trig->ops = &afe4404_trigger_ops;
- afe->trig->dev.parent = afe->dev;
+ afe->trig->dev.parent = &client->dev;

ret = iio_trigger_register(afe->trig);
if (ret) {
- dev_err(afe->dev, "Unable to register IIO trigger\n");
+ dev_err(&client->dev,
+ "Unable to register IIO trigger\n");
goto disable_reg;
}

- ret = devm_request_threaded_irq(afe->dev, afe->irq,
+ ret = devm_request_threaded_irq(&client->dev, afe->irq,
iio_trigger_generic_data_rdy_poll,
NULL, IRQF_ONESHOT,
AFE4404_DRIVER_NAME,
afe->trig);
if (ret) {
- dev_err(afe->dev, "Unable to request IRQ\n");
+ dev_err(&client->dev, "Unable to request IRQ\n");
goto disable_reg;
}
}
@@ -611,13 +610,13 @@ static int afe4404_probe(struct i2c_client *client,
ret = iio_triggered_buffer_setup(indio_dev, &iio_pollfunc_store_time,
afe4404_trigger_handler, NULL);
if (ret) {
- dev_err(afe->dev, "Unable to setup buffer\n");
+ dev_err(&client->dev, "Unable to setup buffer\n");
goto unregister_trigger;
}

ret = iio_device_register(indio_dev);
if (ret) {
- dev_err(afe->dev, "Unable to register IIO device\n");
+ dev_err(&client->dev, "Unable to register IIO device\n");
goto unregister_triggered_buffer;
}

@@ -638,6 +637,7 @@ static int afe4404_remove(struct i2c_client *client)
{
struct iio_dev *indio_dev = i2c_get_clientdata(client);
struct afe4404_data *afe = iio_priv(indio_dev);
+ struct device *dev = regmap_get_device(afe->regmap);
int ret;

iio_device_unregister(indio_dev);
@@ -649,7 +649,7 @@ static int afe4404_remove(struct i2c_client *client)

ret = regulator_disable(afe->regulator);
if (ret) {
- dev_err(afe->dev, "Unable to disable regulator\n");
+ dev_err(dev, "Unable to disable regulator\n");
return ret;
}

--
2.1.4

2016-04-06 05:21:36

by Alison Schofield

[permalink] [raw]
Subject: [PATCH 9/9] iio: gyro: bmg160_core: use regmap to retrieve struct device

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 <[email protected]>
---
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_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;
}
}
@@ -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].dps_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;
}

--
2.1.4

2016-04-06 07:03:09

by Marek Szyprowski

[permalink] [raw]
Subject: Re: [PATCH 1/9] iio: adc: exynos_adc: use regmap to retrieve struct device

Hello,

On 2016-04-06 07:15, 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 <[email protected]>

This patch changes the struct device which is used by the driver to
report errors. The driver used correctly the struct device associated
with its device tree node, while after the patch it will use device
which is associated with PMU regmap, which is a different device. PMU
regmap is there only to enable/disable the ADC block and it is not the
regmap used to access registers of the ADC device.

I would prefer to drop this patch.

> ---
> drivers/iio/adc/exynos_adc.c | 18 +++++++++---------
> 1 file changed, 9 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/iio/adc/exynos_adc.c b/drivers/iio/adc/exynos_adc.c
> index c15756d..0313e0f 100644
> --- a/drivers/iio/adc/exynos_adc.c
> +++ b/drivers/iio/adc/exynos_adc.c
> @@ -130,7 +130,6 @@
>
> struct exynos_adc {
> struct exynos_adc_data *data;
> - struct device *dev;
> struct input_dev *input;
> void __iomem *regs;
> struct regmap *pmu_map;
> @@ -173,11 +172,12 @@ static void exynos_adc_unprepare_clk(struct exynos_adc *info)
>
> static int exynos_adc_prepare_clk(struct exynos_adc *info)
> {
> + struct device *dev = regmap_get_device(info->pmu_map);
> int ret;
>
> ret = clk_prepare(info->clk);
> if (ret) {
> - dev_err(info->dev, "failed preparing adc clock: %d\n", ret);
> + dev_err(dev, "failed preparing adc clock: %d\n", ret);
> return ret;
> }
>
> @@ -185,7 +185,7 @@ static int exynos_adc_prepare_clk(struct exynos_adc *info)
> ret = clk_prepare(info->sclk);
> if (ret) {
> clk_unprepare(info->clk);
> - dev_err(info->dev,
> + dev_err(dev,
> "failed preparing sclk_adc clock: %d\n", ret);
> return ret;
> }
> @@ -203,11 +203,12 @@ static void exynos_adc_disable_clk(struct exynos_adc *info)
>
> static int exynos_adc_enable_clk(struct exynos_adc *info)
> {
> + struct device *dev = regmap_get_device(info->pmu_map);
> int ret;
>
> ret = clk_enable(info->clk);
> if (ret) {
> - dev_err(info->dev, "failed enabling adc clock: %d\n", ret);
> + dev_err(dev, "failed enabling adc clock: %d\n", ret);
> return ret;
> }
>
> @@ -215,7 +216,7 @@ static int exynos_adc_enable_clk(struct exynos_adc *info)
> ret = clk_enable(info->sclk);
> if (ret) {
> clk_disable(info->clk);
> - dev_err(info->dev,
> + dev_err(dev,
> "failed enabling sclk_adc clock: %d\n", ret);
> return ret;
> }
> @@ -610,13 +611,14 @@ static irqreturn_t exynos_adc_isr(int irq, void *dev_id)
> static irqreturn_t exynos_ts_isr(int irq, void *dev_id)
> {
> struct exynos_adc *info = dev_id;
> - struct iio_dev *dev = dev_get_drvdata(info->dev);
> + struct device *dev = regmap_get_device(info->pmu_map);
> + struct iio_dev *indio_dev = dev_get_drvdata(dev);
> u32 x, y;
> bool pressed;
> int ret;
>
> while (info->input->users) {
> - ret = exynos_read_s3c64xx_ts(dev, &x, &y);
> + ret = exynos_read_s3c64xx_ts(indio_dev, &x, &y);
> if (ret == -ETIMEDOUT)
> break;
>
> @@ -800,8 +802,6 @@ static int exynos_adc_probe(struct platform_device *pdev)
>
> info->tsirq = irq;
>
> - info->dev = &pdev->dev;
> -
> init_completion(&info->completion);
>
> info->clk = devm_clk_get(&pdev->dev, "adc");

Best regards
--
Marek Szyprowski, PhD
Samsung R&D Institute Poland

2016-04-06 07:35:52

by Joachim Eastwood

[permalink] [raw]
Subject: Re: [PATCH 5/9] iio: accel: mma7455: use regmap to retrieve struct device

Hi Alison,

On 6 April 2016 at 07:18, Alison Schofield <[email protected]> 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 <[email protected]>
> ---
> drivers/iio/accel/mma7455_core.c | 5 ++---
> 1 file changed, 2 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/iio/accel/mma7455_core.c b/drivers/iio/accel/mma7455_core.c
> index c633cc2..c902f54 100644
> --- a/drivers/iio/accel/mma7455_core.c
> +++ b/drivers/iio/accel/mma7455_core.c
> @@ -55,11 +55,11 @@
>
> struct mma7455_data {
> struct regmap *regmap;
> - struct device *dev;
> };
>
> static int mma7455_drdy(struct mma7455_data *mma7455)
> {
> + struct device *dev = regmap_get_device(mma7455->regmap);

ah, nice!

Acked-by: Joachim Eastwood <[email protected]>


regards,
Joachim Eastwood

2016-04-06 20:33:15

by Alison Schofield

[permalink] [raw]
Subject: Re: [PATCH 1/9] iio: adc: exynos_adc: use regmap to retrieve struct device

On Wed, Apr 06, 2016 at 09:03:00AM +0200, Marek Szyprowski wrote:
> Hello,
>
> On 2016-04-06 07:15, 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 <[email protected]>
>
> This patch changes the struct device which is used by the driver to report
> errors. The driver used correctly the struct device associated with its
> device tree node, while after the patch it will use device which is
> associated with PMU regmap, which is a different device. PMU regmap is there
> only to enable/disable the ADC block and it is not the regmap used to access
> registers of the ADC device.
>
> I would prefer to drop this patch.
>

Thanks Marek! Please check my understanding. Driver is not carrying
a duplicate struct device. The regmap in exynos_adc is *not* this
devices regmap. It belongs to the PMU, (power mgmt unit?)

It seemed excessive to carry around a struct device just for the
dev_err messages, but, we need that struct to extract the correct
iio_dev struct. Without a regmap belonging to this actual device,
no efficiencies can be gained in exynos, and the patch will be
dropped from set v2.

Now I need to be able to recognize such cases elsewhere. I'm going
back though other patches in this set looking for that, but I'm not
so sure I would recognize it.

Jonathan & all, Any hints on the rule of regmap?

Thanks,
alisons



> >---
> > drivers/iio/adc/exynos_adc.c | 18 +++++++++---------
> > 1 file changed, 9 insertions(+), 9 deletions(-)
> >
> >diff --git a/drivers/iio/adc/exynos_adc.c b/drivers/iio/adc/exynos_adc.c
> >index c15756d..0313e0f 100644
> >--- a/drivers/iio/adc/exynos_adc.c
> >+++ b/drivers/iio/adc/exynos_adc.c
> >@@ -130,7 +130,6 @@
> > struct exynos_adc {
> > struct exynos_adc_data *data;
> >- struct device *dev;
> > struct input_dev *input;
> > void __iomem *regs;
> > struct regmap *pmu_map;
> >@@ -173,11 +172,12 @@ static void exynos_adc_unprepare_clk(struct exynos_adc *info)
> > static int exynos_adc_prepare_clk(struct exynos_adc *info)
> > {
> >+ struct device *dev = regmap_get_device(info->pmu_map);
> > int ret;
> > ret = clk_prepare(info->clk);
> > if (ret) {
> >- dev_err(info->dev, "failed preparing adc clock: %d\n", ret);
> >+ dev_err(dev, "failed preparing adc clock: %d\n", ret);
> > return ret;
> > }
> >@@ -185,7 +185,7 @@ static int exynos_adc_prepare_clk(struct exynos_adc *info)
> > ret = clk_prepare(info->sclk);
> > if (ret) {
> > clk_unprepare(info->clk);
> >- dev_err(info->dev,
> >+ dev_err(dev,
> > "failed preparing sclk_adc clock: %d\n", ret);
> > return ret;
> > }
> >@@ -203,11 +203,12 @@ static void exynos_adc_disable_clk(struct exynos_adc *info)
> > static int exynos_adc_enable_clk(struct exynos_adc *info)
> > {
> >+ struct device *dev = regmap_get_device(info->pmu_map);
> > int ret;
> > ret = clk_enable(info->clk);
> > if (ret) {
> >- dev_err(info->dev, "failed enabling adc clock: %d\n", ret);
> >+ dev_err(dev, "failed enabling adc clock: %d\n", ret);
> > return ret;
> > }
> >@@ -215,7 +216,7 @@ static int exynos_adc_enable_clk(struct exynos_adc *info)
> > ret = clk_enable(info->sclk);
> > if (ret) {
> > clk_disable(info->clk);
> >- dev_err(info->dev,
> >+ dev_err(dev,
> > "failed enabling sclk_adc clock: %d\n", ret);
> > return ret;
> > }
> >@@ -610,13 +611,14 @@ static irqreturn_t exynos_adc_isr(int irq, void *dev_id)
> > static irqreturn_t exynos_ts_isr(int irq, void *dev_id)
> > {
> > struct exynos_adc *info = dev_id;
> >- struct iio_dev *dev = dev_get_drvdata(info->dev);
> >+ struct device *dev = regmap_get_device(info->pmu_map);
> >+ struct iio_dev *indio_dev = dev_get_drvdata(dev);
> > u32 x, y;
> > bool pressed;
> > int ret;
> > while (info->input->users) {
> >- ret = exynos_read_s3c64xx_ts(dev, &x, &y);
> >+ ret = exynos_read_s3c64xx_ts(indio_dev, &x, &y);
> > if (ret == -ETIMEDOUT)
> > break;
> >@@ -800,8 +802,6 @@ static int exynos_adc_probe(struct platform_device *pdev)
> > info->tsirq = irq;
> >- info->dev = &pdev->dev;
> >-
> > init_completion(&info->completion);
> > info->clk = devm_clk_get(&pdev->dev, "adc");
>
> Best regards
> --
> Marek Szyprowski, PhD
> Samsung R&D Institute Poland
>

2016-04-07 05:33:44

by Marek Szyprowski

[permalink] [raw]
Subject: Re: [PATCH 1/9] iio: adc: exynos_adc: use regmap to retrieve struct device

Hello,

On 2016-04-06 22:33, Alison Schofield wrote:
> On Wed, Apr 06, 2016 at 09:03:00AM +0200, Marek Szyprowski wrote:
>> Hello,
>>
>> On 2016-04-06 07:15, 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 <[email protected]>
>> This patch changes the struct device which is used by the driver to report
>> errors. The driver used correctly the struct device associated with its
>> device tree node, while after the patch it will use device which is
>> associated with PMU regmap, which is a different device. PMU regmap is there
>> only to enable/disable the ADC block and it is not the regmap used to access
>> registers of the ADC device.
>>
>> I would prefer to drop this patch.
> Thanks Marek! Please check my understanding. Driver is not carrying
> a duplicate struct device. The regmap in exynos_adc is *not* this
> devices regmap. It belongs to the PMU, (power mgmt unit?)

Exactly.

> It seemed excessive to carry around a struct device just for the
> dev_err messages, but, we need that struct to extract the correct
> iio_dev struct. Without a regmap belonging to this actual device,
> no efficiencies can be gained in exynos, and the patch will be
> dropped from set v2.

Thanks.

> Now I need to be able to recognize such cases elsewhere. I'm going
> back though other patches in this set looking for that, but I'm not
> so sure I would recognize it.
>
> Jonathan & all, Any hints on the rule of regmap?

You may check how the regmap is initialized. When it is retrieved by
phandle from device tree, then you might be almost sure that it refers
to the different device.

Best regards
--
Marek Szyprowski, PhD
Samsung R&D Institute Poland

2016-04-10 13:45:09

by Jonathan Cameron

[permalink] [raw]
Subject: Re: [PATCH 1/9] iio: adc: exynos_adc: use regmap to retrieve struct device

On 07/04/16 06:33, Marek Szyprowski wrote:
> Hello,
>
> On 2016-04-06 22:33, Alison Schofield wrote:
>> On Wed, Apr 06, 2016 at 09:03:00AM +0200, Marek Szyprowski wrote:
>>> Hello,
>>>
>>> On 2016-04-06 07:15, 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 <[email protected]>
>>> This patch changes the struct device which is used by the driver to report
>>> errors. The driver used correctly the struct device associated with its
>>> device tree node, while after the patch it will use device which is
>>> associated with PMU regmap, which is a different device. PMU regmap is there
>>> only to enable/disable the ADC block and it is not the regmap used to access
>>> registers of the ADC device.
>>>
>>> I would prefer to drop this patch.
>> Thanks Marek! Please check my understanding. Driver is not carrying
>> a duplicate struct device. The regmap in exynos_adc is *not* this
>> devices regmap. It belongs to the PMU, (power mgmt unit?)
>
> Exactly.
>
>> It seemed excessive to carry around a struct device just for the
>> dev_err messages, but, we need that struct to extract the correct
>> iio_dev struct. Without a regmap belonging to this actual device,
>> no efficiencies can be gained in exynos, and the patch will be
>> dropped from set v2.
>
> Thanks.
>
>> Now I need to be able to recognize such cases elsewhere. I'm going
>> back though other patches in this set looking for that, but I'm not
>> so sure I would recognize it.
>>
>> Jonathan & all, Any hints on the rule of regmap?
>
> You may check how the regmap is initialized. When it is retrieved by
> phandle from device tree, then you might be almost sure that it refers
> to the different device.
True enough. Most simple devices that stand alone should be fine for
this sort of cleanup as the regmap is typically initiated directly for them.

Jonathan
>
> Best regards

2016-04-10 13:51:41

by Jonathan Cameron

[permalink] [raw]
Subject: Re: [PATCH 5/9] iio: accel: mma7455: use regmap to retrieve struct device

On 06/04/16 08:35, Joachim Eastwood wrote:
> Hi Alison,
>
> On 6 April 2016 at 07:18, Alison Schofield <[email protected]> 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 <[email protected]>
>> ---
>> drivers/iio/accel/mma7455_core.c | 5 ++---
>> 1 file changed, 2 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/iio/accel/mma7455_core.c b/drivers/iio/accel/mma7455_core.c
>> index c633cc2..c902f54 100644
>> --- a/drivers/iio/accel/mma7455_core.c
>> +++ b/drivers/iio/accel/mma7455_core.c
>> @@ -55,11 +55,11 @@
>>
>> struct mma7455_data {
>> struct regmap *regmap;
>> - struct device *dev;
>> };
>>
>> static int mma7455_drdy(struct mma7455_data *mma7455)
>> {
>> + struct device *dev = regmap_get_device(mma7455->regmap);
>
> ah, nice!
>
> Acked-by: Joachim Eastwood <[email protected]>
Applied to the togreg branch of iio.git - initially pushed out as testing
for the autobuilders to play with it.

This one is a fairly standard case and can be easily chased through to
see that the device pointer is the same one either way.

I'm going to let the rest sit a little longer to see if we get more
feedback on them

Jonathan
>
>
> regards,
> Joachim Eastwood
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>

2016-04-10 13:54:51

by Jonathan Cameron

[permalink] [raw]
Subject: Re: [PATCH 2/9] iio: adc: qcom-spmi-iadc: use regmap to retrieve struct device

On 06/04/16 06:16, 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 <[email protected]>
This has the same issue as the exynos driver - in that the regmap belongs
to the parent, not this device.
> ---
> drivers/iio/adc/qcom-spmi-iadc.c | 32 +++++++++++++++++---------------
> 1 file changed, 17 insertions(+), 15 deletions(-)
>
> diff --git a/drivers/iio/adc/qcom-spmi-iadc.c b/drivers/iio/adc/qcom-spmi-iadc.c
> index fabd24e..f69a057 100644
> --- a/drivers/iio/adc/qcom-spmi-iadc.c
> +++ b/drivers/iio/adc/qcom-spmi-iadc.c
> @@ -102,7 +102,6 @@
> /**
> * struct iadc_chip - IADC Current ADC device structure.
> * @regmap: regmap for register read/write.
> - * @dev: This device pointer.
> * @base: base offset for the ADC peripheral.
> * @rsense: Values of the internal and external sense resister in micro Ohms.
> * @poll_eoc: Poll for end of conversion instead of waiting for IRQ.
> @@ -113,7 +112,6 @@
> */
> struct iadc_chip {
> struct regmap *regmap;
> - struct device *dev;
> u16 base;
> bool poll_eoc;
> u32 rsense[2];
> @@ -170,6 +168,7 @@ static int iadc_set_state(struct iadc_chip *iadc, bool state)
>
> static void iadc_status_show(struct iadc_chip *iadc)
> {
> + struct device *dev = regmap_get_device(iadc->regmap);
> u8 mode, sta1, chan, dig, en, req;
> int ret;
>
> @@ -197,7 +196,7 @@ static void iadc_status_show(struct iadc_chip *iadc)
> if (ret < 0)
> return;
>
> - dev_err(iadc->dev,
> + dev_err(dev,
> "mode:%02x en:%02x chan:%02x dig:%02x req:%02x sta1:%02x\n",
> mode, en, chan, dig, req, sta1);
> }
> @@ -284,6 +283,7 @@ static int iadc_read_result(struct iadc_chip *iadc, u16 *data)
>
> static int iadc_do_conversion(struct iadc_chip *iadc, int chan, u16 *data)
> {
> + struct device *dev = regmap_get_device(iadc->regmap);
> unsigned int wait;
> int ret;
>
> @@ -310,7 +310,7 @@ static int iadc_do_conversion(struct iadc_chip *iadc, int chan, u16 *data)
> exit:
> iadc_set_state(iadc, false);
> if (ret < 0)
> - dev_err(iadc->dev, "conversion failed\n");
> + dev_err(dev, "conversion failed\n");
>
> return ret;
> }
> @@ -320,6 +320,7 @@ static int iadc_read_raw(struct iio_dev *indio_dev,
> int *val, int *val2, long mask)
> {
> struct iadc_chip *iadc = iio_priv(indio_dev);
> + struct device *dev = regmap_get_device(iadc->regmap);
> s32 isense_ua, vsense_uv;
> u16 adc_raw, vsense_raw;
> int ret;
> @@ -339,7 +340,7 @@ static int iadc_read_raw(struct iio_dev *indio_dev,
>
> isense_ua = vsense_uv / iadc->rsense[chan->channel];
>
> - dev_dbg(iadc->dev, "off %d gain %d adc %d %duV I %duA\n",
> + dev_dbg(dev, "off %d gain %d adc %d %duV I %duA\n",
> iadc->offset[chan->channel], iadc->gain,
> adc_raw, vsense_uv, isense_ua);
>
> @@ -370,6 +371,7 @@ static irqreturn_t iadc_isr(int irq, void *dev_id)
>
> static int iadc_update_offset(struct iadc_chip *iadc)
> {
> + struct device *dev = regmap_get_device(iadc->regmap);
> int ret;
>
> ret = iadc_do_conversion(iadc, IADC_GAIN_17P857MV, &iadc->gain);
> @@ -382,7 +384,7 @@ static int iadc_update_offset(struct iadc_chip *iadc)
> return ret;
>
> if (iadc->gain == iadc->offset[IADC_INT_RSENSE]) {
> - dev_err(iadc->dev, "error: internal offset == gain %d\n",
> + dev_err(dev, "error: internal offset == gain %d\n",
> iadc->gain);
> return -EINVAL;
> }
> @@ -393,8 +395,7 @@ static int iadc_update_offset(struct iadc_chip *iadc)
> return ret;
>
> if (iadc->gain == iadc->offset[IADC_EXT_RSENSE]) {
> - dev_err(iadc->dev, "error: external offset == gain %d\n",
> - iadc->gain);
> + dev_err(dev, "error: external offset == gain %d\n", iadc->gain);
> return -EINVAL;
> }
>
> @@ -403,6 +404,7 @@ static int iadc_update_offset(struct iadc_chip *iadc)
>
> static int iadc_version_check(struct iadc_chip *iadc)
> {
> + struct device *dev = regmap_get_device(iadc->regmap);
> u8 val;
> int ret;
>
> @@ -411,7 +413,7 @@ static int iadc_version_check(struct iadc_chip *iadc)
> return ret;
>
> if (val < IADC_PERPH_TYPE_ADC) {
> - dev_err(iadc->dev, "%d is not ADC\n", val);
> + dev_err(dev, "%d is not ADC\n", val);
> return -EINVAL;
> }
>
> @@ -420,7 +422,7 @@ static int iadc_version_check(struct iadc_chip *iadc)
> return ret;
>
> if (val < IADC_PERPH_SUBTYPE_IADC) {
> - dev_err(iadc->dev, "%d is not IADC\n", val);
> + dev_err(dev, "%d is not IADC\n", val);
> return -EINVAL;
> }
>
> @@ -429,7 +431,7 @@ static int iadc_version_check(struct iadc_chip *iadc)
> return ret;
>
> if (val < IADC_REVISION2_SUPPORTED_IADC) {
> - dev_err(iadc->dev, "revision %d not supported\n", val);
> + dev_err(dev, "revision %d not supported\n", val);
> return -EINVAL;
> }
>
> @@ -438,6 +440,7 @@ static int iadc_version_check(struct iadc_chip *iadc)
>
> static int iadc_rsense_read(struct iadc_chip *iadc, struct device_node *node)
> {
> + struct device *dev = regmap_get_device(iadc->regmap);
> int ret, sign, int_sense;
> u8 deviation;
>
> @@ -447,7 +450,7 @@ static int iadc_rsense_read(struct iadc_chip *iadc, struct device_node *node)
> iadc->rsense[IADC_EXT_RSENSE] = IADC_INT_RSENSE_IDEAL_VALUE;
>
> if (!iadc->rsense[IADC_EXT_RSENSE]) {
> - dev_err(iadc->dev, "external resistor can't be zero Ohms");
> + dev_err(dev, "external resistor can't be zero Ohms");
> return -EINVAL;
> }
>
> @@ -505,7 +508,6 @@ static int iadc_probe(struct platform_device *pdev)
> return -ENOMEM;
>
> iadc = iio_priv(indio_dev);
> - iadc->dev = dev;
>
> iadc->regmap = dev_get_regmap(dev->parent, NULL);
> if (!iadc->regmap)
> @@ -528,7 +530,7 @@ static int iadc_probe(struct platform_device *pdev)
> if (ret < 0)
> return -ENODEV;
>
> - dev_dbg(iadc->dev, "sense resistors %d and %d micro Ohm\n",
> + dev_dbg(&pdev->dev, "sense resistors %d and %d micro Ohm\n",
> iadc->rsense[IADC_INT_RSENSE],
> iadc->rsense[IADC_EXT_RSENSE]);
>
> @@ -553,7 +555,7 @@ static int iadc_probe(struct platform_device *pdev)
> else
> return ret;
> } else {
> - device_init_wakeup(iadc->dev, 1);
> + device_init_wakeup(&pdev->dev, 1);
> }
>
> ret = iadc_update_offset(iadc);
>

2016-04-10 13:55:44

by Jonathan Cameron

[permalink] [raw]
Subject: Re: [PATCH 3/9] iio: adc: qcom-spmi-vadc: use regmap to retrieve struct device

On 06/04/16 06:17, 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 <[email protected]>
Another one where the regmap belongs to the wrong device... (parent)
> ---
> drivers/iio/adc/qcom-spmi-vadc.c | 37 ++++++++++++++++++++-----------------
> 1 file changed, 20 insertions(+), 17 deletions(-)
>
> diff --git a/drivers/iio/adc/qcom-spmi-vadc.c b/drivers/iio/adc/qcom-spmi-vadc.c
> index c2babe5..9e7aeca 100644
> --- a/drivers/iio/adc/qcom-spmi-vadc.c
> +++ b/drivers/iio/adc/qcom-spmi-vadc.c
> @@ -161,7 +161,6 @@ struct vadc_channel_prop {
> /**
> * struct vadc_priv - VADC private structure.
> * @regmap: pointer to struct regmap.
> - * @dev: pointer to struct device.
> * @base: base address for the ADC peripheral.
> * @nchannels: number of VADC channels.
> * @chan_props: array of VADC channel properties.
> @@ -174,7 +173,6 @@ struct vadc_channel_prop {
> */
> struct vadc_priv {
> struct regmap *regmap;
> - struct device *dev;
> u16 base;
> unsigned int nchannels;
> struct vadc_channel_prop *chan_props;
> @@ -236,6 +234,7 @@ static int vadc_set_state(struct vadc_priv *vadc, bool state)
>
> static void vadc_show_status(struct vadc_priv *vadc)
> {
> + struct device *dev = regmap_get_device(vadc->regmap);
> u8 mode, sta1, chan, dig, en, req;
> int ret;
>
> @@ -263,7 +262,7 @@ static void vadc_show_status(struct vadc_priv *vadc)
> if (ret)
> return;
>
> - dev_err(vadc->dev,
> + dev_err(dev,
> "mode:%02x en:%02x chan:%02x dig:%02x req:%02x sta1:%02x\n",
> mode, en, chan, dig, req, sta1);
> }
> @@ -350,13 +349,14 @@ static int vadc_read_result(struct vadc_priv *vadc, u16 *data)
> static struct vadc_channel_prop *vadc_get_channel(struct vadc_priv *vadc,
> unsigned int num)
> {
> + struct device *dev = regmap_get_device(vadc->regmap);
> unsigned int i;
>
> for (i = 0; i < vadc->nchannels; i++)
> if (vadc->chan_props[i].channel == num)
> return &vadc->chan_props[i];
>
> - dev_dbg(vadc->dev, "no such channel %02x\n", num);
> + dev_dbg(dev, "no such channel %02x\n", num);
>
> return NULL;
> }
> @@ -364,6 +364,7 @@ static struct vadc_channel_prop *vadc_get_channel(struct vadc_priv *vadc,
> static int vadc_do_conversion(struct vadc_priv *vadc,
> struct vadc_channel_prop *prop, u16 *data)
> {
> + struct device *dev = regmap_get_device(vadc->regmap);
> unsigned int timeout;
> int ret;
>
> @@ -406,7 +407,7 @@ static int vadc_do_conversion(struct vadc_priv *vadc,
> err_disable:
> vadc_set_state(vadc, false);
> if (ret)
> - dev_err(vadc->dev, "conversion failed\n");
> + dev_err(dev, "conversion failed\n");
> unlock:
> mutex_unlock(&vadc->lock);
> return ret;
> @@ -414,6 +415,7 @@ unlock:
>
> static int vadc_measure_ref_points(struct vadc_priv *vadc)
> {
> + struct device *dev = regmap_get_device(vadc->regmap);
> struct vadc_channel_prop *prop;
> u16 read_1, read_2;
> int ret;
> @@ -463,7 +465,7 @@ static int vadc_measure_ref_points(struct vadc_priv *vadc)
> vadc->graph[VADC_CALIB_RATIOMETRIC].gnd = read_2;
> err:
> if (ret)
> - dev_err(vadc->dev, "measure reference points failed\n");
> + dev_err(dev, "measure reference points failed\n");
>
> return ret;
> }
> @@ -814,6 +816,7 @@ static int vadc_get_dt_channel_data(struct device *dev,
>
> static int vadc_get_dt_data(struct vadc_priv *vadc, struct device_node *node)
> {
> + struct device *dev = regmap_get_device(vadc->regmap);
> const struct vadc_channels *vadc_chan;
> struct iio_chan_spec *iio_chan;
> struct vadc_channel_prop prop;
> @@ -825,12 +828,12 @@ static int vadc_get_dt_data(struct vadc_priv *vadc, struct device_node *node)
> if (!vadc->nchannels)
> return -EINVAL;
>
> - vadc->iio_chans = devm_kcalloc(vadc->dev, vadc->nchannels,
> + vadc->iio_chans = devm_kcalloc(dev, vadc->nchannels,
> sizeof(*vadc->iio_chans), GFP_KERNEL);
> if (!vadc->iio_chans)
> return -ENOMEM;
>
> - vadc->chan_props = devm_kcalloc(vadc->dev, vadc->nchannels,
> + vadc->chan_props = devm_kcalloc(dev, vadc->nchannels,
> sizeof(*vadc->chan_props), GFP_KERNEL);
> if (!vadc->chan_props)
> return -ENOMEM;
> @@ -838,7 +841,7 @@ static int vadc_get_dt_data(struct vadc_priv *vadc, struct device_node *node)
> iio_chan = vadc->iio_chans;
>
> for_each_available_child_of_node(node, child) {
> - ret = vadc_get_dt_channel_data(vadc->dev, &prop, child);
> + ret = vadc_get_dt_channel_data(dev, &prop, child);
> if (ret) {
> of_node_put(child);
> return ret;
> @@ -860,22 +863,22 @@ static int vadc_get_dt_data(struct vadc_priv *vadc, struct device_node *node)
>
> /* These channels are mandatory, they are used as reference points */
> if (!vadc_get_channel(vadc, VADC_REF_1250MV)) {
> - dev_err(vadc->dev, "Please define 1.25V channel\n");
> + dev_err(dev, "Please define 1.25V channel\n");
> return -ENODEV;
> }
>
> if (!vadc_get_channel(vadc, VADC_REF_625MV)) {
> - dev_err(vadc->dev, "Please define 0.625V channel\n");
> + dev_err(dev, "Please define 0.625V channel\n");
> return -ENODEV;
> }
>
> if (!vadc_get_channel(vadc, VADC_VDD_VADC)) {
> - dev_err(vadc->dev, "Please define VDD channel\n");
> + dev_err(dev, "Please define VDD channel\n");
> return -ENODEV;
> }
>
> if (!vadc_get_channel(vadc, VADC_GND_REF)) {
> - dev_err(vadc->dev, "Please define GND channel\n");
> + dev_err(dev, "Please define GND channel\n");
> return -ENODEV;
> }
>
> @@ -893,6 +896,7 @@ static irqreturn_t vadc_isr(int irq, void *dev_id)
>
> static int vadc_check_revision(struct vadc_priv *vadc)
> {
> + struct device *dev = regmap_get_device(vadc->regmap);
> u8 val;
> int ret;
>
> @@ -901,7 +905,7 @@ static int vadc_check_revision(struct vadc_priv *vadc)
> return ret;
>
> if (val < VADC_PERPH_TYPE_ADC) {
> - dev_err(vadc->dev, "%d is not ADC\n", val);
> + dev_err(dev, "%d is not ADC\n", val);
> return -ENODEV;
> }
>
> @@ -910,7 +914,7 @@ static int vadc_check_revision(struct vadc_priv *vadc)
> return ret;
>
> if (val < VADC_PERPH_SUBTYPE_VADC) {
> - dev_err(vadc->dev, "%d is not VADC\n", val);
> + dev_err(dev, "%d is not VADC\n", val);
> return -ENODEV;
> }
>
> @@ -919,7 +923,7 @@ static int vadc_check_revision(struct vadc_priv *vadc)
> return ret;
>
> if (val < VADC_REVISION2_SUPPORTED_VADC) {
> - dev_err(vadc->dev, "revision %d not supported\n", val);
> + dev_err(dev, "revision %d not supported\n", val);
> return -ENODEV;
> }
>
> @@ -950,7 +954,6 @@ static int vadc_probe(struct platform_device *pdev)
>
> vadc = iio_priv(indio_dev);
> vadc->regmap = regmap;
> - vadc->dev = dev;
> vadc->base = reg;
> vadc->are_ref_measured = false;
> init_completion(&vadc->complete);
>

2016-04-10 19:04:17

by Alison Schofield

[permalink] [raw]
Subject: [PATCH v2 0/5] iio: use regmap to retrieve struct device

These drivers include both struct regmap and struct device in their
global data. Remove the redundant copy by deleting struct device
from the drivers global data and using regmap API to retrieve when
needed.

This patchset removes all such redundancies in drivers/iio/.

Patches created using Coccinelle plus hand edits for whitespace.

Changes v1->v2:
This set is updated following reviews teaching me that not
all regmaps in global data will be of that device. Discards
and keepers are noted below. No actual code changes just a
remake of the patchset.

Jonathan - I saw you want to let it simmer, just want to
let it simmer cleaner ;)

accel: mma7455
Removing: Joachim ack'd, Jonathan took v1

adc: exynos_adc
Discard: regmap is of PMU parent

adc: qcom-spmi-iadc
adc: qcom-spmi-vadc
Discard: first line of _probe gets regmap from parent

accel: bmc150
gyro: bmg160
Keep: regmap passed into _probe from i2c,spi_probe where
it was initialized for this device

accel: mxc4005
health: afe4403
health: afe4404
Keep: regmap initialized in _probe for this device


Alison Schofield (5):
iio: accel: bmc150: use regmap to retrieve struct device
iio: accel: mxc4005: use regmap to retrieve struct device
iio: health: afe4403: use regmap to retrieve struct device
iio: health: afe4404: use regmap to retrieve struct device
iio: gyro: bmg160: use regmap to retrieve struct device

drivers/iio/accel/bmc150-accel-core.c | 99 +++++++++++++++++++----------------
drivers/iio/accel/mxc4005.c | 26 +++++----
drivers/iio/gyro/bmg160_core.c | 86 +++++++++++++++---------------
drivers/iio/health/afe4403.c | 36 ++++++-------
drivers/iio/health/afe4404.c | 38 +++++++-------
5 files changed, 149 insertions(+), 136 deletions(-)

--
2.1.4

2016-04-10 19:05:31

by Alison Schofield

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

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 <[email protected]>
---
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_RESET);
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_triggers[i].name,
+ t->indio_trig = devm_iio_trigger_alloc(dev,
+ bmc150_accel_triggers[i].name,
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_handler,
&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_handler,
bmc150_accel_irq_thread_handler,
IRQF_TRIGGER_RISING,
@@ -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_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");
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)
--
2.1.4

2016-04-10 19:07:01

by Alison Schofield

[permalink] [raw]
Subject: [PATCH v2 2/5] iio: accel: mxc4005: use regmap to retrieve struct device

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 <[email protected]>
---
drivers/iio/accel/mxc4005.c | 26 +++++++++++++++-----------
1 file changed, 15 insertions(+), 11 deletions(-)

diff --git a/drivers/iio/accel/mxc4005.c b/drivers/iio/accel/mxc4005.c
index c23f47a..013d511 100644
--- a/drivers/iio/accel/mxc4005.c
+++ b/drivers/iio/accel/mxc4005.c
@@ -60,7 +60,6 @@ enum mxc4005_range {
};

struct mxc4005_data {
- struct device *dev;
struct mutex mutex;
struct regmap *regmap;
struct iio_trigger *dready_trig;
@@ -140,12 +139,13 @@ static const struct regmap_config mxc4005_regmap_config = {

static int mxc4005_read_xyz(struct mxc4005_data *data)
{
+ struct device *dev = regmap_get_device(data->regmap);
int ret;

ret = regmap_bulk_read(data->regmap, MXC4005_REG_XOUT_UPPER,
(u8 *) data->buffer, sizeof(data->buffer));
if (ret < 0) {
- dev_err(data->dev, "failed to read axes\n");
+ dev_err(dev, "failed to read axes\n");
return ret;
}

@@ -155,12 +155,13 @@ static int mxc4005_read_xyz(struct mxc4005_data *data)
static int mxc4005_read_axis(struct mxc4005_data *data,
unsigned int addr)
{
+ struct device *dev = regmap_get_device(data->regmap);
__be16 reg;
int ret;

ret = regmap_bulk_read(data->regmap, addr, (u8 *) &reg, sizeof(reg));
if (ret < 0) {
- dev_err(data->dev, "failed to read reg %02x\n", addr);
+ dev_err(dev, "failed to read reg %02x\n", addr);
return ret;
}

@@ -169,13 +170,14 @@ static int mxc4005_read_axis(struct mxc4005_data *data,

static int mxc4005_read_scale(struct mxc4005_data *data)
{
+ struct device *dev = regmap_get_device(data->regmap);
unsigned int reg;
int ret;
int i;

ret = regmap_read(data->regmap, MXC4005_REG_CONTROL, &reg);
if (ret < 0) {
- dev_err(data->dev, "failed to read reg_control\n");
+ dev_err(dev, "failed to read reg_control\n");
return ret;
}

@@ -189,6 +191,7 @@ static int mxc4005_read_scale(struct mxc4005_data *data)

static int mxc4005_set_scale(struct mxc4005_data *data, int val)
{
+ struct device *dev = regmap_get_device(data->regmap);
unsigned int reg;
int i;
int ret;
@@ -201,8 +204,7 @@ static int mxc4005_set_scale(struct mxc4005_data *data, int val)
MXC4005_REG_CONTROL_MASK_FSR,
reg);
if (ret < 0)
- dev_err(data->dev,
- "failed to write reg_control\n");
+ dev_err(dev, "failed to write reg_control\n");
return ret;
}
}
@@ -321,13 +323,14 @@ err:

static int mxc4005_clr_intr(struct mxc4005_data *data)
{
+ struct device *dev = regmap_get_device(data->regmap);
int ret;

/* clear interrupt */
ret = regmap_write(data->regmap, MXC4005_REG_INT_CLR1,
MXC4005_REG_INT_CLR1_BIT_DRDYC);
if (ret < 0) {
- dev_err(data->dev, "failed to write to reg_int_clr1\n");
+ dev_err(dev, "failed to write to reg_int_clr1\n");
return ret;
}

@@ -339,6 +342,7 @@ static int mxc4005_set_trigger_state(struct iio_trigger *trig,
{
struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig);
struct mxc4005_data *data = iio_priv(indio_dev);
+ struct device *dev = regmap_get_device(data->regmap);
int ret;

mutex_lock(&data->mutex);
@@ -352,7 +356,7 @@ static int mxc4005_set_trigger_state(struct iio_trigger *trig,

if (ret < 0) {
mutex_unlock(&data->mutex);
- dev_err(data->dev, "failed to update reg_int_mask1");
+ dev_err(dev, "failed to update reg_int_mask1");
return ret;
}

@@ -381,16 +385,17 @@ static const struct iio_trigger_ops mxc4005_trigger_ops = {

static int mxc4005_chip_init(struct mxc4005_data *data)
{
+ struct device *dev = regmap_get_device(data->regmap);
int ret;
unsigned int reg;

ret = regmap_read(data->regmap, MXC4005_REG_DEVICE_ID, &reg);
if (ret < 0) {
- dev_err(data->dev, "failed to read chip id\n");
+ dev_err(dev, "failed to read chip id\n");
return ret;
}

- dev_dbg(data->dev, "MXC4005 chip id %02x\n", reg);
+ dev_dbg(dev, "MXC4005 chip id %02x\n", reg);

return 0;
}
@@ -415,7 +420,6 @@ static int mxc4005_probe(struct i2c_client *client,

data = iio_priv(indio_dev);
i2c_set_clientdata(client, indio_dev);
- data->dev = &client->dev;
data->regmap = regmap;

ret = mxc4005_chip_init(data);
--
2.1.4

2016-04-10 19:07:22

by Alison Schofield

[permalink] [raw]
Subject: [PATCH v2 3/5] iio: health: afe4403: use regmap to retrieve struct device

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 <[email protected]>
---
drivers/iio/health/afe4403.c | 36 +++++++++++++++++-------------------
1 file changed, 17 insertions(+), 19 deletions(-)

diff --git a/drivers/iio/health/afe4403.c b/drivers/iio/health/afe4403.c
index 88e43f8..71b8f70 100644
--- a/drivers/iio/health/afe4403.c
+++ b/drivers/iio/health/afe4403.c
@@ -104,7 +104,6 @@

/**
* struct afe4403_data
- * @dev - Device structure
* @spi - SPI device handle
* @regmap - Register map of the device
* @regulator - Pointer to the regulator for the IC
@@ -112,7 +111,6 @@
* @irq - ADC_RDY line interrupt number
*/
struct afe4403_data {
- struct device *dev;
struct spi_device *spi;
struct regmap *regmap;
struct regulator *regulator;
@@ -562,55 +560,54 @@ static int afe4403_probe(struct spi_device *spi)
afe = iio_priv(indio_dev);
spi_set_drvdata(spi, indio_dev);

- afe->dev = &spi->dev;
afe->spi = spi;
afe->irq = spi->irq;

afe->regmap = devm_regmap_init_spi(spi, &afe4403_regmap_config);
if (IS_ERR(afe->regmap)) {
- dev_err(afe->dev, "Unable to allocate register map\n");
+ dev_err(&spi->dev, "Unable to allocate register map\n");
return PTR_ERR(afe->regmap);
}

- afe->regulator = devm_regulator_get(afe->dev, "tx_sup");
+ afe->regulator = devm_regulator_get(&spi->dev, "tx_sup");
if (IS_ERR(afe->regulator)) {
- dev_err(afe->dev, "Unable to get regulator\n");
+ dev_err(&spi->dev, "Unable to get regulator\n");
return PTR_ERR(afe->regulator);
}
ret = regulator_enable(afe->regulator);
if (ret) {
- dev_err(afe->dev, "Unable to enable regulator\n");
+ dev_err(&spi->dev, "Unable to enable regulator\n");
return ret;
}

ret = regmap_write(afe->regmap, AFE440X_CONTROL0,
AFE440X_CONTROL0_SW_RESET);
if (ret) {
- dev_err(afe->dev, "Unable to reset device\n");
+ dev_err(&spi->dev, "Unable to reset device\n");
goto err_disable_reg;
}

ret = regmap_multi_reg_write(afe->regmap, afe4403_reg_sequences,
ARRAY_SIZE(afe4403_reg_sequences));
if (ret) {
- dev_err(afe->dev, "Unable to set register defaults\n");
+ dev_err(&spi->dev, "Unable to set register defaults\n");
goto err_disable_reg;
}

indio_dev->modes = INDIO_DIRECT_MODE;
- indio_dev->dev.parent = afe->dev;
+ indio_dev->dev.parent = &spi->dev;
indio_dev->channels = afe4403_channels;
indio_dev->num_channels = ARRAY_SIZE(afe4403_channels);
indio_dev->name = AFE4403_DRIVER_NAME;
indio_dev->info = &afe4403_iio_info;

if (afe->irq > 0) {
- afe->trig = devm_iio_trigger_alloc(afe->dev,
+ afe->trig = devm_iio_trigger_alloc(&spi->dev,
"%s-dev%d",
indio_dev->name,
indio_dev->id);
if (!afe->trig) {
- dev_err(afe->dev, "Unable to allocate IIO trigger\n");
+ dev_err(&spi->dev, "Unable to allocate IIO trigger\n");
ret = -ENOMEM;
goto err_disable_reg;
}
@@ -618,21 +615,21 @@ static int afe4403_probe(struct spi_device *spi)
iio_trigger_set_drvdata(afe->trig, indio_dev);

afe->trig->ops = &afe4403_trigger_ops;
- afe->trig->dev.parent = afe->dev;
+ afe->trig->dev.parent = &spi->dev;

ret = iio_trigger_register(afe->trig);
if (ret) {
- dev_err(afe->dev, "Unable to register IIO trigger\n");
+ dev_err(&spi->dev, "Unable to register IIO trigger\n");
goto err_disable_reg;
}

- ret = devm_request_threaded_irq(afe->dev, afe->irq,
+ ret = devm_request_threaded_irq(&spi->dev, afe->irq,
iio_trigger_generic_data_rdy_poll,
NULL, IRQF_ONESHOT,
AFE4403_DRIVER_NAME,
afe->trig);
if (ret) {
- dev_err(afe->dev, "Unable to request IRQ\n");
+ dev_err(&spi->dev, "Unable to request IRQ\n");
goto err_trig;
}
}
@@ -640,13 +637,13 @@ static int afe4403_probe(struct spi_device *spi)
ret = iio_triggered_buffer_setup(indio_dev, &iio_pollfunc_store_time,
afe4403_trigger_handler, NULL);
if (ret) {
- dev_err(afe->dev, "Unable to setup buffer\n");
+ dev_err(&spi->dev, "Unable to setup buffer\n");
goto err_trig;
}

ret = iio_device_register(indio_dev);
if (ret) {
- dev_err(afe->dev, "Unable to register IIO device\n");
+ dev_err(&spi->dev, "Unable to register IIO device\n");
goto err_buff;
}

@@ -667,6 +664,7 @@ static int afe4403_remove(struct spi_device *spi)
{
struct iio_dev *indio_dev = spi_get_drvdata(spi);
struct afe4403_data *afe = iio_priv(indio_dev);
+ struct device *dev = regmap_get_device(afe->regmap);
int ret;

iio_device_unregister(indio_dev);
@@ -678,7 +676,7 @@ static int afe4403_remove(struct spi_device *spi)

ret = regulator_disable(afe->regulator);
if (ret) {
- dev_err(afe->dev, "Unable to disable regulator\n");
+ dev_err(dev, "Unable to disable regulator\n");
return ret;
}

--
2.1.4

2016-04-10 19:07:53

by Alison Schofield

[permalink] [raw]
Subject: [PATCH v2 4/5] iio: health: afe4404: use regmap to retrieve struct device

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 <[email protected]>
---
drivers/iio/health/afe4404.c | 38 +++++++++++++++++++-------------------
1 file changed, 19 insertions(+), 19 deletions(-)

diff --git a/drivers/iio/health/afe4404.c b/drivers/iio/health/afe4404.c
index 5096a46..9cd8590 100644
--- a/drivers/iio/health/afe4404.c
+++ b/drivers/iio/health/afe4404.c
@@ -107,14 +107,12 @@

/**
* struct afe4404_data
- * @dev - Device structure
* @regmap - Register map of the device
* @regulator - Pointer to the regulator for the IC
* @trig - IIO trigger for this device
* @irq - ADC_RDY line interrupt number
*/
struct afe4404_data {
- struct device *dev;
struct regmap *regmap;
struct regulator *regulator;
struct iio_trigger *trig;
@@ -534,54 +532,54 @@ static int afe4404_probe(struct i2c_client *client,
afe = iio_priv(indio_dev);
i2c_set_clientdata(client, indio_dev);

- afe->dev = &client->dev;
afe->irq = client->irq;

afe->regmap = devm_regmap_init_i2c(client, &afe4404_regmap_config);
if (IS_ERR(afe->regmap)) {
- dev_err(afe->dev, "Unable to allocate register map\n");
+ dev_err(&client->dev, "Unable to allocate register map\n");
return PTR_ERR(afe->regmap);
}

- afe->regulator = devm_regulator_get(afe->dev, "tx_sup");
+ afe->regulator = devm_regulator_get(&client->dev, "tx_sup");
if (IS_ERR(afe->regulator)) {
- dev_err(afe->dev, "Unable to get regulator\n");
+ dev_err(&client->dev, "Unable to get regulator\n");
return PTR_ERR(afe->regulator);
}
ret = regulator_enable(afe->regulator);
if (ret) {
- dev_err(afe->dev, "Unable to enable regulator\n");
+ dev_err(&client->dev, "Unable to enable regulator\n");
return ret;
}

ret = regmap_write(afe->regmap, AFE440X_CONTROL0,
AFE440X_CONTROL0_SW_RESET);
if (ret) {
- dev_err(afe->dev, "Unable to reset device\n");
+ dev_err(&client->dev, "Unable to reset device\n");
goto disable_reg;
}

ret = regmap_multi_reg_write(afe->regmap, afe4404_reg_sequences,
ARRAY_SIZE(afe4404_reg_sequences));
if (ret) {
- dev_err(afe->dev, "Unable to set register defaults\n");
+ dev_err(&client->dev, "Unable to set register defaults\n");
goto disable_reg;
}

indio_dev->modes = INDIO_DIRECT_MODE;
- indio_dev->dev.parent = afe->dev;
+ indio_dev->dev.parent = &client->dev;
indio_dev->channels = afe4404_channels;
indio_dev->num_channels = ARRAY_SIZE(afe4404_channels);
indio_dev->name = AFE4404_DRIVER_NAME;
indio_dev->info = &afe4404_iio_info;

if (afe->irq > 0) {
- afe->trig = devm_iio_trigger_alloc(afe->dev,
+ afe->trig = devm_iio_trigger_alloc(&client->dev,
"%s-dev%d",
indio_dev->name,
indio_dev->id);
if (!afe->trig) {
- dev_err(afe->dev, "Unable to allocate IIO trigger\n");
+ dev_err(&client->dev,
+ "Unable to allocate IIO trigger\n");
ret = -ENOMEM;
goto disable_reg;
}
@@ -589,21 +587,22 @@ static int afe4404_probe(struct i2c_client *client,
iio_trigger_set_drvdata(afe->trig, indio_dev);

afe->trig->ops = &afe4404_trigger_ops;
- afe->trig->dev.parent = afe->dev;
+ afe->trig->dev.parent = &client->dev;

ret = iio_trigger_register(afe->trig);
if (ret) {
- dev_err(afe->dev, "Unable to register IIO trigger\n");
+ dev_err(&client->dev,
+ "Unable to register IIO trigger\n");
goto disable_reg;
}

- ret = devm_request_threaded_irq(afe->dev, afe->irq,
+ ret = devm_request_threaded_irq(&client->dev, afe->irq,
iio_trigger_generic_data_rdy_poll,
NULL, IRQF_ONESHOT,
AFE4404_DRIVER_NAME,
afe->trig);
if (ret) {
- dev_err(afe->dev, "Unable to request IRQ\n");
+ dev_err(&client->dev, "Unable to request IRQ\n");
goto disable_reg;
}
}
@@ -611,13 +610,13 @@ static int afe4404_probe(struct i2c_client *client,
ret = iio_triggered_buffer_setup(indio_dev, &iio_pollfunc_store_time,
afe4404_trigger_handler, NULL);
if (ret) {
- dev_err(afe->dev, "Unable to setup buffer\n");
+ dev_err(&client->dev, "Unable to setup buffer\n");
goto unregister_trigger;
}

ret = iio_device_register(indio_dev);
if (ret) {
- dev_err(afe->dev, "Unable to register IIO device\n");
+ dev_err(&client->dev, "Unable to register IIO device\n");
goto unregister_triggered_buffer;
}

@@ -638,6 +637,7 @@ static int afe4404_remove(struct i2c_client *client)
{
struct iio_dev *indio_dev = i2c_get_clientdata(client);
struct afe4404_data *afe = iio_priv(indio_dev);
+ struct device *dev = regmap_get_device(afe->regmap);
int ret;

iio_device_unregister(indio_dev);
@@ -649,7 +649,7 @@ static int afe4404_remove(struct i2c_client *client)

ret = regulator_disable(afe->regulator);
if (ret) {
- dev_err(afe->dev, "Unable to disable regulator\n");
+ dev_err(dev, "Unable to disable regulator\n");
return ret;
}

--
2.1.4

2016-04-10 19:08:23

by Alison Schofield

[permalink] [raw]
Subject: [PATCH v2 5/5] iio: gyro: bmg160: use regmap to retrieve struct device

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 <[email protected]>
---
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_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;
}
}
@@ -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].dps_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;
}

--
2.1.4

2016-04-16 19:20:12

by Jonathan Cameron

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

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 <[email protected]>
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_RESET);
> 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_triggers[i].name,
> + t->indio_trig = devm_iio_trigger_alloc(dev,
> + bmc150_accel_triggers[i].name,
> 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_handler,
> &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_handler,
> bmc150_accel_irq_thread_handler,
> IRQF_TRIGGER_RISING,
> @@ -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_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");
> 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)
>

2016-04-16 19:21:20

by Jonathan Cameron

[permalink] [raw]
Subject: Re: [PATCH v2 2/5] iio: accel: mxc4005: use regmap to retrieve struct device

On 10/04/16 20:06, 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 <[email protected]>
Again, I'm happy with this, but have cc'd Teodora whose driver this is
for info and comment.

Jonathan
> ---
> drivers/iio/accel/mxc4005.c | 26 +++++++++++++++-----------
> 1 file changed, 15 insertions(+), 11 deletions(-)
>
> diff --git a/drivers/iio/accel/mxc4005.c b/drivers/iio/accel/mxc4005.c
> index c23f47a..013d511 100644
> --- a/drivers/iio/accel/mxc4005.c
> +++ b/drivers/iio/accel/mxc4005.c
> @@ -60,7 +60,6 @@ enum mxc4005_range {
> };
>
> struct mxc4005_data {
> - struct device *dev;
> struct mutex mutex;
> struct regmap *regmap;
> struct iio_trigger *dready_trig;
> @@ -140,12 +139,13 @@ static const struct regmap_config mxc4005_regmap_config = {
>
> static int mxc4005_read_xyz(struct mxc4005_data *data)
> {
> + struct device *dev = regmap_get_device(data->regmap);
> int ret;
>
> ret = regmap_bulk_read(data->regmap, MXC4005_REG_XOUT_UPPER,
> (u8 *) data->buffer, sizeof(data->buffer));
> if (ret < 0) {
> - dev_err(data->dev, "failed to read axes\n");
> + dev_err(dev, "failed to read axes\n");
> return ret;
> }
>
> @@ -155,12 +155,13 @@ static int mxc4005_read_xyz(struct mxc4005_data *data)
> static int mxc4005_read_axis(struct mxc4005_data *data,
> unsigned int addr)
> {
> + struct device *dev = regmap_get_device(data->regmap);
> __be16 reg;
> int ret;
>
> ret = regmap_bulk_read(data->regmap, addr, (u8 *) &reg, sizeof(reg));
> if (ret < 0) {
> - dev_err(data->dev, "failed to read reg %02x\n", addr);
> + dev_err(dev, "failed to read reg %02x\n", addr);
> return ret;
> }
>
> @@ -169,13 +170,14 @@ static int mxc4005_read_axis(struct mxc4005_data *data,
>
> static int mxc4005_read_scale(struct mxc4005_data *data)
> {
> + struct device *dev = regmap_get_device(data->regmap);
> unsigned int reg;
> int ret;
> int i;
>
> ret = regmap_read(data->regmap, MXC4005_REG_CONTROL, &reg);
> if (ret < 0) {
> - dev_err(data->dev, "failed to read reg_control\n");
> + dev_err(dev, "failed to read reg_control\n");
> return ret;
> }
>
> @@ -189,6 +191,7 @@ static int mxc4005_read_scale(struct mxc4005_data *data)
>
> static int mxc4005_set_scale(struct mxc4005_data *data, int val)
> {
> + struct device *dev = regmap_get_device(data->regmap);
> unsigned int reg;
> int i;
> int ret;
> @@ -201,8 +204,7 @@ static int mxc4005_set_scale(struct mxc4005_data *data, int val)
> MXC4005_REG_CONTROL_MASK_FSR,
> reg);
> if (ret < 0)
> - dev_err(data->dev,
> - "failed to write reg_control\n");
> + dev_err(dev, "failed to write reg_control\n");
> return ret;
> }
> }
> @@ -321,13 +323,14 @@ err:
>
> static int mxc4005_clr_intr(struct mxc4005_data *data)
> {
> + struct device *dev = regmap_get_device(data->regmap);
> int ret;
>
> /* clear interrupt */
> ret = regmap_write(data->regmap, MXC4005_REG_INT_CLR1,
> MXC4005_REG_INT_CLR1_BIT_DRDYC);
> if (ret < 0) {
> - dev_err(data->dev, "failed to write to reg_int_clr1\n");
> + dev_err(dev, "failed to write to reg_int_clr1\n");
> return ret;
> }
>
> @@ -339,6 +342,7 @@ static int mxc4005_set_trigger_state(struct iio_trigger *trig,
> {
> struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig);
> struct mxc4005_data *data = iio_priv(indio_dev);
> + struct device *dev = regmap_get_device(data->regmap);
> int ret;
>
> mutex_lock(&data->mutex);
> @@ -352,7 +356,7 @@ static int mxc4005_set_trigger_state(struct iio_trigger *trig,
>
> if (ret < 0) {
> mutex_unlock(&data->mutex);
> - dev_err(data->dev, "failed to update reg_int_mask1");
> + dev_err(dev, "failed to update reg_int_mask1");
> return ret;
> }
>
> @@ -381,16 +385,17 @@ static const struct iio_trigger_ops mxc4005_trigger_ops = {
>
> static int mxc4005_chip_init(struct mxc4005_data *data)
> {
> + struct device *dev = regmap_get_device(data->regmap);
> int ret;
> unsigned int reg;
>
> ret = regmap_read(data->regmap, MXC4005_REG_DEVICE_ID, &reg);
> if (ret < 0) {
> - dev_err(data->dev, "failed to read chip id\n");
> + dev_err(dev, "failed to read chip id\n");
> return ret;
> }
>
> - dev_dbg(data->dev, "MXC4005 chip id %02x\n", reg);
> + dev_dbg(dev, "MXC4005 chip id %02x\n", reg);
>
> return 0;
> }
> @@ -415,7 +420,6 @@ static int mxc4005_probe(struct i2c_client *client,
>
> data = iio_priv(indio_dev);
> i2c_set_clientdata(client, indio_dev);
> - data->dev = &client->dev;
> data->regmap = regmap;
>
> ret = mxc4005_chip_init(data);
>

2016-04-16 19:22:22

by Jonathan Cameron

[permalink] [raw]
Subject: Re: [PATCH v2 3/5] iio: health: afe4403: use regmap to retrieve struct device

On 10/04/16 20:07, 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 <[email protected]>
cc'd Andrew for info and comment.

Again I'm happy with this one myself.

Jonathan
> ---
> drivers/iio/health/afe4403.c | 36 +++++++++++++++++-------------------
> 1 file changed, 17 insertions(+), 19 deletions(-)
>
> diff --git a/drivers/iio/health/afe4403.c b/drivers/iio/health/afe4403.c
> index 88e43f8..71b8f70 100644
> --- a/drivers/iio/health/afe4403.c
> +++ b/drivers/iio/health/afe4403.c
> @@ -104,7 +104,6 @@
>
> /**
> * struct afe4403_data
> - * @dev - Device structure
> * @spi - SPI device handle
> * @regmap - Register map of the device
> * @regulator - Pointer to the regulator for the IC
> @@ -112,7 +111,6 @@
> * @irq - ADC_RDY line interrupt number
> */
> struct afe4403_data {
> - struct device *dev;
> struct spi_device *spi;
> struct regmap *regmap;
> struct regulator *regulator;
> @@ -562,55 +560,54 @@ static int afe4403_probe(struct spi_device *spi)
> afe = iio_priv(indio_dev);
> spi_set_drvdata(spi, indio_dev);
>
> - afe->dev = &spi->dev;
> afe->spi = spi;
> afe->irq = spi->irq;
>
> afe->regmap = devm_regmap_init_spi(spi, &afe4403_regmap_config);
> if (IS_ERR(afe->regmap)) {
> - dev_err(afe->dev, "Unable to allocate register map\n");
> + dev_err(&spi->dev, "Unable to allocate register map\n");
> return PTR_ERR(afe->regmap);
> }
>
> - afe->regulator = devm_regulator_get(afe->dev, "tx_sup");
> + afe->regulator = devm_regulator_get(&spi->dev, "tx_sup");
> if (IS_ERR(afe->regulator)) {
> - dev_err(afe->dev, "Unable to get regulator\n");
> + dev_err(&spi->dev, "Unable to get regulator\n");
> return PTR_ERR(afe->regulator);
> }
> ret = regulator_enable(afe->regulator);
> if (ret) {
> - dev_err(afe->dev, "Unable to enable regulator\n");
> + dev_err(&spi->dev, "Unable to enable regulator\n");
> return ret;
> }
>
> ret = regmap_write(afe->regmap, AFE440X_CONTROL0,
> AFE440X_CONTROL0_SW_RESET);
> if (ret) {
> - dev_err(afe->dev, "Unable to reset device\n");
> + dev_err(&spi->dev, "Unable to reset device\n");
> goto err_disable_reg;
> }
>
> ret = regmap_multi_reg_write(afe->regmap, afe4403_reg_sequences,
> ARRAY_SIZE(afe4403_reg_sequences));
> if (ret) {
> - dev_err(afe->dev, "Unable to set register defaults\n");
> + dev_err(&spi->dev, "Unable to set register defaults\n");
> goto err_disable_reg;
> }
>
> indio_dev->modes = INDIO_DIRECT_MODE;
> - indio_dev->dev.parent = afe->dev;
> + indio_dev->dev.parent = &spi->dev;
> indio_dev->channels = afe4403_channels;
> indio_dev->num_channels = ARRAY_SIZE(afe4403_channels);
> indio_dev->name = AFE4403_DRIVER_NAME;
> indio_dev->info = &afe4403_iio_info;
>
> if (afe->irq > 0) {
> - afe->trig = devm_iio_trigger_alloc(afe->dev,
> + afe->trig = devm_iio_trigger_alloc(&spi->dev,
> "%s-dev%d",
> indio_dev->name,
> indio_dev->id);
> if (!afe->trig) {
> - dev_err(afe->dev, "Unable to allocate IIO trigger\n");
> + dev_err(&spi->dev, "Unable to allocate IIO trigger\n");
> ret = -ENOMEM;
> goto err_disable_reg;
> }
> @@ -618,21 +615,21 @@ static int afe4403_probe(struct spi_device *spi)
> iio_trigger_set_drvdata(afe->trig, indio_dev);
>
> afe->trig->ops = &afe4403_trigger_ops;
> - afe->trig->dev.parent = afe->dev;
> + afe->trig->dev.parent = &spi->dev;
>
> ret = iio_trigger_register(afe->trig);
> if (ret) {
> - dev_err(afe->dev, "Unable to register IIO trigger\n");
> + dev_err(&spi->dev, "Unable to register IIO trigger\n");
> goto err_disable_reg;
> }
>
> - ret = devm_request_threaded_irq(afe->dev, afe->irq,
> + ret = devm_request_threaded_irq(&spi->dev, afe->irq,
> iio_trigger_generic_data_rdy_poll,
> NULL, IRQF_ONESHOT,
> AFE4403_DRIVER_NAME,
> afe->trig);
> if (ret) {
> - dev_err(afe->dev, "Unable to request IRQ\n");
> + dev_err(&spi->dev, "Unable to request IRQ\n");
> goto err_trig;
> }
> }
> @@ -640,13 +637,13 @@ static int afe4403_probe(struct spi_device *spi)
> ret = iio_triggered_buffer_setup(indio_dev, &iio_pollfunc_store_time,
> afe4403_trigger_handler, NULL);
> if (ret) {
> - dev_err(afe->dev, "Unable to setup buffer\n");
> + dev_err(&spi->dev, "Unable to setup buffer\n");
> goto err_trig;
> }
>
> ret = iio_device_register(indio_dev);
> if (ret) {
> - dev_err(afe->dev, "Unable to register IIO device\n");
> + dev_err(&spi->dev, "Unable to register IIO device\n");
> goto err_buff;
> }
>
> @@ -667,6 +664,7 @@ static int afe4403_remove(struct spi_device *spi)
> {
> struct iio_dev *indio_dev = spi_get_drvdata(spi);
> struct afe4403_data *afe = iio_priv(indio_dev);
> + struct device *dev = regmap_get_device(afe->regmap);
> int ret;
>
> iio_device_unregister(indio_dev);
> @@ -678,7 +676,7 @@ static int afe4403_remove(struct spi_device *spi)
>
> ret = regulator_disable(afe->regulator);
> if (ret) {
> - dev_err(afe->dev, "Unable to disable regulator\n");
> + dev_err(dev, "Unable to disable regulator\n");
> return ret;
> }
>
>

2016-04-16 19:22:45

by Jonathan Cameron

[permalink] [raw]
Subject: Re: [PATCH v2 4/5] iio: health: afe4404: use regmap to retrieve struct device

On 10/04/16 20:07, 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 <[email protected]>
Cc'd Andrew
> ---
> drivers/iio/health/afe4404.c | 38 +++++++++++++++++++-------------------
> 1 file changed, 19 insertions(+), 19 deletions(-)
>
> diff --git a/drivers/iio/health/afe4404.c b/drivers/iio/health/afe4404.c
> index 5096a46..9cd8590 100644
> --- a/drivers/iio/health/afe4404.c
> +++ b/drivers/iio/health/afe4404.c
> @@ -107,14 +107,12 @@
>
> /**
> * struct afe4404_data
> - * @dev - Device structure
> * @regmap - Register map of the device
> * @regulator - Pointer to the regulator for the IC
> * @trig - IIO trigger for this device
> * @irq - ADC_RDY line interrupt number
> */
> struct afe4404_data {
> - struct device *dev;
> struct regmap *regmap;
> struct regulator *regulator;
> struct iio_trigger *trig;
> @@ -534,54 +532,54 @@ static int afe4404_probe(struct i2c_client *client,
> afe = iio_priv(indio_dev);
> i2c_set_clientdata(client, indio_dev);
>
> - afe->dev = &client->dev;
> afe->irq = client->irq;
>
> afe->regmap = devm_regmap_init_i2c(client, &afe4404_regmap_config);
> if (IS_ERR(afe->regmap)) {
> - dev_err(afe->dev, "Unable to allocate register map\n");
> + dev_err(&client->dev, "Unable to allocate register map\n");
> return PTR_ERR(afe->regmap);
> }
>
> - afe->regulator = devm_regulator_get(afe->dev, "tx_sup");
> + afe->regulator = devm_regulator_get(&client->dev, "tx_sup");
> if (IS_ERR(afe->regulator)) {
> - dev_err(afe->dev, "Unable to get regulator\n");
> + dev_err(&client->dev, "Unable to get regulator\n");
> return PTR_ERR(afe->regulator);
> }
> ret = regulator_enable(afe->regulator);
> if (ret) {
> - dev_err(afe->dev, "Unable to enable regulator\n");
> + dev_err(&client->dev, "Unable to enable regulator\n");
> return ret;
> }
>
> ret = regmap_write(afe->regmap, AFE440X_CONTROL0,
> AFE440X_CONTROL0_SW_RESET);
> if (ret) {
> - dev_err(afe->dev, "Unable to reset device\n");
> + dev_err(&client->dev, "Unable to reset device\n");
> goto disable_reg;
> }
>
> ret = regmap_multi_reg_write(afe->regmap, afe4404_reg_sequences,
> ARRAY_SIZE(afe4404_reg_sequences));
> if (ret) {
> - dev_err(afe->dev, "Unable to set register defaults\n");
> + dev_err(&client->dev, "Unable to set register defaults\n");
> goto disable_reg;
> }
>
> indio_dev->modes = INDIO_DIRECT_MODE;
> - indio_dev->dev.parent = afe->dev;
> + indio_dev->dev.parent = &client->dev;
> indio_dev->channels = afe4404_channels;
> indio_dev->num_channels = ARRAY_SIZE(afe4404_channels);
> indio_dev->name = AFE4404_DRIVER_NAME;
> indio_dev->info = &afe4404_iio_info;
>
> if (afe->irq > 0) {
> - afe->trig = devm_iio_trigger_alloc(afe->dev,
> + afe->trig = devm_iio_trigger_alloc(&client->dev,
> "%s-dev%d",
> indio_dev->name,
> indio_dev->id);
> if (!afe->trig) {
> - dev_err(afe->dev, "Unable to allocate IIO trigger\n");
> + dev_err(&client->dev,
> + "Unable to allocate IIO trigger\n");
> ret = -ENOMEM;
> goto disable_reg;
> }
> @@ -589,21 +587,22 @@ static int afe4404_probe(struct i2c_client *client,
> iio_trigger_set_drvdata(afe->trig, indio_dev);
>
> afe->trig->ops = &afe4404_trigger_ops;
> - afe->trig->dev.parent = afe->dev;
> + afe->trig->dev.parent = &client->dev;
>
> ret = iio_trigger_register(afe->trig);
> if (ret) {
> - dev_err(afe->dev, "Unable to register IIO trigger\n");
> + dev_err(&client->dev,
> + "Unable to register IIO trigger\n");
> goto disable_reg;
> }
>
> - ret = devm_request_threaded_irq(afe->dev, afe->irq,
> + ret = devm_request_threaded_irq(&client->dev, afe->irq,
> iio_trigger_generic_data_rdy_poll,
> NULL, IRQF_ONESHOT,
> AFE4404_DRIVER_NAME,
> afe->trig);
> if (ret) {
> - dev_err(afe->dev, "Unable to request IRQ\n");
> + dev_err(&client->dev, "Unable to request IRQ\n");
> goto disable_reg;
> }
> }
> @@ -611,13 +610,13 @@ static int afe4404_probe(struct i2c_client *client,
> ret = iio_triggered_buffer_setup(indio_dev, &iio_pollfunc_store_time,
> afe4404_trigger_handler, NULL);
> if (ret) {
> - dev_err(afe->dev, "Unable to setup buffer\n");
> + dev_err(&client->dev, "Unable to setup buffer\n");
> goto unregister_trigger;
> }
>
> ret = iio_device_register(indio_dev);
> if (ret) {
> - dev_err(afe->dev, "Unable to register IIO device\n");
> + dev_err(&client->dev, "Unable to register IIO device\n");
> goto unregister_triggered_buffer;
> }
>
> @@ -638,6 +637,7 @@ static int afe4404_remove(struct i2c_client *client)
> {
> struct iio_dev *indio_dev = i2c_get_clientdata(client);
> struct afe4404_data *afe = iio_priv(indio_dev);
> + struct device *dev = regmap_get_device(afe->regmap);
> int ret;
>
> iio_device_unregister(indio_dev);
> @@ -649,7 +649,7 @@ static int afe4404_remove(struct i2c_client *client)
>
> ret = regulator_disable(afe->regulator);
> if (ret) {
> - dev_err(afe->dev, "Unable to disable regulator\n");
> + dev_err(dev, "Unable to disable regulator\n");
> return ret;
> }
>
>

2016-04-16 19:24:22

by Jonathan Cameron

[permalink] [raw]
Subject: Re: [PATCH v2 5/5] iio: gyro: bmg160: use regmap to retrieve struct device

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 <[email protected]>
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_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;
> }
> }
> @@ -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].dps_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;
> }
>
>

2016-04-17 18:08:43

by Andrew Davis

[permalink] [raw]
Subject: Re: [PATCH v2 4/5] iio: health: afe4404: use regmap to retrieve struct device

On 04/16/2016 02:22 PM, Jonathan Cameron wrote:
> On 10/04/16 20:07, 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.
>>

Why? This adds nothing but more code to get dev through some
container_of trickery when we could just keep a dev pointer in the data
structure.

Andrew

2016-04-18 04:56:27

by Alison Schofield

[permalink] [raw]
Subject: Re: [PATCH v2 4/5] iio: health: afe4404: use regmap to retrieve struct device

On Sun, Apr 17, 2016 at 01:07:52PM -0500, Andrew F. Davis wrote:
> On 04/16/2016 02:22 PM, Jonathan Cameron wrote:
> > On 10/04/16 20:07, 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.
> >>
>
> Why? This adds nothing but more code to get dev through some
> container_of trickery when we could just keep a dev pointer in the data
> structure.
>
> Andrew

Thanks for the review and response. The why would be for
simplification and uniformity across IIO.

I think I see your point in general, but not sure I get your
specific concerns with these afe4403/04 drivers.

The drivers only use the device struct in probe and then
again at device remove time. At probe, the change no
longer stores it in the global data. At remove the
regmap_get_device() func is a simple dereference to retrieve
the device struct. That's the simplification: we don't carry
that ptr in global data waiting for the opportunity to use it
at device remove. We just find it when we need it at device
remove. (Perhaps these devices are getting removed frequently?)

Regards,
alisons

2016-04-18 12:18:14

by Tirdea, Irina

[permalink] [raw]
Subject: RE: [PATCH v2 1/5] iio: accel: bmc150: use regmap to retrieve struct device



> -----Original Message-----
> From: Jonathan Cameron [mailto:[email protected]]
> Sent: 16 April, 2016 22:20
> To: Alison Schofield
> Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; linux-
> [email protected]; [email protected]; [email protected]; [email protected];
> Srinivas Pandruvada; Tirdea, Irina
> Subject: Re: [PATCH v2 1/5] iio: accel: bmc150: use regmap to retrieve struct device
>
> 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 <[email protected]>
> 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.
>

Looks good to me.
Reviewed-by: Irina Tirdea <[email protected]>

Alison, I think bmc150_magn driver qualifies for this change as well
after Daniel's patches got merged [1].

Thanks,
Irina

[1] https://lkml.org/lkml/2016/4/15/407

> If no one comments in the meantime I'll probably pick these up sometime
> in the next week.
>
> Jonathan

2016-04-18 14:59:14

by srinivas pandruvada

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

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 <[email protected]>
Reviewed-by: Srinivas Pandruvada <[email protected]>

> 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)
> >

2016-04-18 15:03:45

by srinivas pandruvada

[permalink] [raw]
Subject: Re: [PATCH v2 5/5] iio: gyro: bmg160: use regmap to retrieve struct device

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 <[email protected]>
Reviewed-by: Srinivas Pandruvada <[email protected]>

> 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;
> >   }
> >  
> >

2016-04-18 15:53:39

by Andrew Davis

[permalink] [raw]
Subject: Re: [PATCH v2 4/5] iio: health: afe4404: use regmap to retrieve struct device

On 04/17/2016 11:56 PM, Alison Schofield wrote:
> On Sun, Apr 17, 2016 at 01:07:52PM -0500, Andrew F. Davis wrote:
>> On 04/16/2016 02:22 PM, Jonathan Cameron wrote:
>>> On 10/04/16 20:07, 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.
>>>>
>>
>> Why? This adds nothing but more code to get dev through some
>> container_of trickery when we could just keep a dev pointer in the data
>> structure.
>>
>> Andrew
>
> Thanks for the review and response. The why would be for
> simplification and uniformity across IIO.
>

I'm all for simplification and uniformity but I think this will take us
in the wrong direction, a lot drivers do not use regmap for instance and
so will need another method to lookup the device struct.

> I think I see your point in general, but not sure I get your
> specific concerns with these afe4403/04 drivers.
>
> The drivers only use the device struct in probe and then
> again at device remove time. At probe, the change no
> longer stores it in the global data. At remove the
> regmap_get_device() func is a simple dereference to retrieve
> the device struct. That's the simplification: we don't carry
> that ptr in global data waiting for the opportunity to use it
> at device remove. We just find it when we need it at device
> remove.

A lot of what drivers store in their per-instance data structure is only
held for use in remove. Using afe4404 as an example trig and irq are
also only stored for removal. A good driver framework will pass in
relevant information to the driver callbacks, and so instance data
structures have gotten very small, for afe4404 only regmap and regulator
are actually used during runtime currently.

The direction that would really be of best simplification would be to
remove the need for the remove function from these drivers, if
iio_trigger_register and iio_triggered_buffer_setup had devm_ versions
(like most other setup functions) everything would automatically be
cleaned up properly without needing a remove function. Then I would have
no problem removing the unused device structure pointer, but for now
their will never be a simpler trick to getting the device pointer than
simply storing it in the instance data.

> (Perhaps these devices are getting removed frequently?)
>

Quite the opposite, same for many drivers, the remove path is
dangerously untested in the real world, even more reason it's nice to
not need remove and let devm_ cleanup for us :)

Thanks,
Andrew

2016-04-18 19:16:32

by Jonathan Cameron

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

On 18/04/16 15:59, Srinivas Pandruvada wrote:
> 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 <[email protected]>
> Reviewed-by: Srinivas Pandruvada <[email protected]>
Applied to the togreg branch of iio.git

Thanks,

Jonathan
>
>> 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)
>>>
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>

2016-04-18 19:26:02

by Jonathan Cameron

[permalink] [raw]
Subject: Re: [PATCH v2 4/5] iio: health: afe4404: use regmap to retrieve struct device

On 18/04/16 16:53, Andrew F. Davis wrote:
> On 04/17/2016 11:56 PM, Alison Schofield wrote:
>> On Sun, Apr 17, 2016 at 01:07:52PM -0500, Andrew F. Davis wrote:
>>> On 04/16/2016 02:22 PM, Jonathan Cameron wrote:
>>>> On 10/04/16 20:07, 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.
>>>>>
>>>
>>> Why? This adds nothing but more code to get dev through some
>>> container_of trickery when we could just keep a dev pointer in the data
>>> structure.
>>>
>>> Andrew
>>
>> Thanks for the review and response. The why would be for
>> simplification and uniformity across IIO.
>>
>
> I'm all for simplification and uniformity but I think this will take us
> in the wrong direction, a lot drivers do not use regmap for instance and
> so will need another method to lookup the device struct.
>
>> I think I see your point in general, but not sure I get your
>> specific concerns with these afe4403/04 drivers.
>>
>> The drivers only use the device struct in probe and then
>> again at device remove time. At probe, the change no
>> longer stores it in the global data. At remove the
>> regmap_get_device() func is a simple dereference to retrieve
>> the device struct. That's the simplification: we don't carry
>> that ptr in global data waiting for the opportunity to use it
>> at device remove. We just find it when we need it at device
>> remove.
>
> A lot of what drivers store in their per-instance data structure is only
> held for use in remove. Using afe4404 as an example trig and irq are
> also only stored for removal. A good driver framework will pass in
> relevant information to the driver callbacks, and so instance data
> structures have gotten very small, for afe4404 only regmap and regulator
> are actually used during runtime currently.
The difference here is that we are handing over the device access to
entirely be via regmap - so to my mind we should probably also hand
over the dev pointer itself (which in fact we are doing anyway) as such
it makes sense to retrieve it from regmap when needed. Anyhow, whilst
I originally suggested this (in a driver review a while back) it's not
an important issue and can be left to the tastes of individual authors.

Alison, you win some you loose some with this sort of cleanup patch!
In this particular case the fact that it was used as a convenient
place to get hold of it in the probe function made the patch a lot
more 'noisy' than it would otherwise have been.
>
> The direction that would really be of best simplification would be to
> remove the need for the remove function from these drivers, if
> iio_trigger_register and iio_triggered_buffer_setup had devm_ versions
> (like most other setup functions) everything would automatically be
> cleaned up properly without needing a remove function. Then I would have
> no problem removing the unused device structure pointer, but for now
> their will never be a simpler trick to getting the device pointer than
> simply storing it in the instance data.
Whilst that might be nice.... Actually most devices need to do something
very much device specific in their shutdown - such as turning themselves off
so devm still only takes us so far. Still I don't mind patches proposing
moving more stuff over to devm - they do help for some devices
(though the devm_iio_device_register still causes me a enough issues in
incorrect usage that I'm doubtful that accepting that one was ever a good
idea!)
>
>> (Perhaps these devices are getting removed frequently?)
>>
>
> Quite the opposite, same for many drivers, the remove path is
> dangerously untested in the real world, even more reason it's nice to
> not need remove and let devm_ cleanup for us :)

>
> Thanks,
> Andrew
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to [email protected]
> More majordomo info at http://vger.kernel.org/majordomo-info.html
>