2015-08-12 14:50:39

by Markus Pargmann

[permalink] [raw]
Subject: [PATCH v3 0/6] iio: bmg160: Add SPI connection

Hi,

bmg160 and bmi055 can be used via I2C and SPI. This series converts the driver
to regmap and splits core driver and I2C/SPI.

Changes in v3:
- removed 'select REGMAP' as it is selected by REGMAP_I2C
- added EXPORT_SYMBOL_GPL for the core functions
- removed default values from regmap_config
- Added max_register and unset use_single_rw in regmap_config
- Changed Makefile to always compile bmg160-core with either spi or i2c. It is
not possible now to compile the core alone.

Changes in v2:
- Added the id->name from the SPI driver to be used as iio device name
- Fixed Kconfig in patch 2 to add selects for REGMAP_I2C
- Fixed regmap configs to be static const


Best regards,

Markus


Markus Pargmann (6):
iio: bmg160: Use i2c regmap instead of direct i2c access
iio: bmg160: Remove i2c_client from data struct
iio: bmg160: Use generic dev_drvdata
iio: bmg160: Remove remaining uses of i2c_client
iio: bmg160: Separate i2c and core driver
iio: bmg160: Add SPI driver

drivers/iio/gyro/Kconfig | 28 ++-
drivers/iio/gyro/Makefile | 3 +-
drivers/iio/gyro/bmg160.h | 10 +
drivers/iio/gyro/{bmg160.c => bmg160_core.c} | 358 +++++++++++----------------
drivers/iio/gyro/bmg160_i2c.c | 71 ++++++
drivers/iio/gyro/bmg160_spi.c | 57 +++++
6 files changed, 306 insertions(+), 221 deletions(-)
create mode 100644 drivers/iio/gyro/bmg160.h
rename drivers/iio/gyro/{bmg160.c => bmg160_core.c} (74%)
create mode 100644 drivers/iio/gyro/bmg160_i2c.c
create mode 100644 drivers/iio/gyro/bmg160_spi.c

--
2.4.6


2015-08-12 14:51:20

by Markus Pargmann

[permalink] [raw]
Subject: [PATCH v3 1/6] iio: bmg160: Use i2c regmap instead of direct i2c access

This patch introduces regmap usage into the driver. This is done to
later easily support the SPI interface of this chip.

Signed-off-by: Markus Pargmann <[email protected]>
---
drivers/iio/gyro/Kconfig | 1 +
drivers/iio/gyro/bmg160.c | 198 ++++++++++++++++++++--------------------------
2 files changed, 88 insertions(+), 111 deletions(-)

diff --git a/drivers/iio/gyro/Kconfig b/drivers/iio/gyro/Kconfig
index 8d2439345673..cf82d74139a2 100644
--- a/drivers/iio/gyro/Kconfig
+++ b/drivers/iio/gyro/Kconfig
@@ -55,6 +55,7 @@ config BMG160
depends on I2C
select IIO_BUFFER
select IIO_TRIGGERED_BUFFER
+ select REGMAP_I2C
help
Say yes here to build support for Bosch BMG160 Tri-axis Gyro Sensor
driver. This driver also supports BMI055 gyroscope.
diff --git a/drivers/iio/gyro/bmg160.c b/drivers/iio/gyro/bmg160.c
index 460bf715d541..bbe02053e98a 100644
--- a/drivers/iio/gyro/bmg160.c
+++ b/drivers/iio/gyro/bmg160.c
@@ -28,6 +28,7 @@
#include <linux/iio/events.h>
#include <linux/iio/trigger_consumer.h>
#include <linux/iio/triggered_buffer.h>
+#include <linux/regmap.h>

#define BMG160_DRV_NAME "bmg160"
#define BMG160_IRQ_NAME "bmg160_event"
@@ -98,6 +99,7 @@

struct bmg160_data {
struct i2c_client *client;
+ struct regmap *regmap;
struct iio_trigger *dready_trig;
struct iio_trigger *motion_trig;
struct mutex mutex;
@@ -134,12 +136,17 @@ static const struct {
{ 133, BMG160_RANGE_250DPS},
{ 66, BMG160_RANGE_125DPS} };

+struct regmap_config bmg160_regmap_i2c_conf = {
+ .reg_bits = 8,
+ .val_bits = 8,
+ .max_register = 0x3f
+};
+
static int bmg160_set_mode(struct bmg160_data *data, u8 mode)
{
int ret;

- ret = i2c_smbus_write_byte_data(data->client,
- BMG160_REG_PMU_LPW, mode);
+ ret = regmap_write(data->regmap, BMG160_REG_PMU_LPW, mode);
if (ret < 0) {
dev_err(&data->client->dev, "Error writing reg_pmu_lpw\n");
return ret;
@@ -169,8 +176,7 @@ static int bmg160_set_bw(struct bmg160_data *data, int val)
if (bw_bits < 0)
return bw_bits;

- ret = i2c_smbus_write_byte_data(data->client, BMG160_REG_PMU_BW,
- bw_bits);
+ ret = regmap_write(data->regmap, BMG160_REG_PMU_BW, bw_bits);
if (ret < 0) {
dev_err(&data->client->dev, "Error writing reg_pmu_bw\n");
return ret;
@@ -184,16 +190,17 @@ static int bmg160_set_bw(struct bmg160_data *data, int val)
static int bmg160_chip_init(struct bmg160_data *data)
{
int ret;
+ unsigned int val;

- ret = i2c_smbus_read_byte_data(data->client, BMG160_REG_CHIP_ID);
+ ret = regmap_read(data->regmap, BMG160_REG_CHIP_ID, &val);
if (ret < 0) {
dev_err(&data->client->dev, "Error reading reg_chip_id\n");
return ret;
}

- dev_dbg(&data->client->dev, "Chip Id %x\n", ret);
- if (ret != BMG160_CHIP_ID_VAL) {
- dev_err(&data->client->dev, "invalid chip %x\n", ret);
+ dev_dbg(&data->client->dev, "Chip Id %x\n", val);
+ if (val != BMG160_CHIP_ID_VAL) {
+ dev_err(&data->client->dev, "invalid chip %x\n", val);
return -ENODEV;
}

@@ -210,40 +217,31 @@ static int bmg160_chip_init(struct bmg160_data *data)
return ret;

/* Set Default Range */
- ret = i2c_smbus_write_byte_data(data->client,
- BMG160_REG_RANGE,
- BMG160_RANGE_500DPS);
+ ret = regmap_write(data->regmap, BMG160_REG_RANGE, BMG160_RANGE_500DPS);
if (ret < 0) {
dev_err(&data->client->dev, "Error writing reg_range\n");
return ret;
}
data->dps_range = BMG160_RANGE_500DPS;

- ret = i2c_smbus_read_byte_data(data->client, BMG160_REG_SLOPE_THRES);
+ ret = regmap_read(data->regmap, BMG160_REG_SLOPE_THRES, &val);
if (ret < 0) {
dev_err(&data->client->dev, "Error reading reg_slope_thres\n");
return ret;
}
- data->slope_thres = ret;
+ data->slope_thres = val;

/* Set default interrupt mode */
- ret = i2c_smbus_read_byte_data(data->client, BMG160_REG_INT_EN_1);
- if (ret < 0) {
- dev_err(&data->client->dev, "Error reading reg_int_en_1\n");
- return ret;
- }
- ret &= ~BMG160_INT1_BIT_OD;
- ret = i2c_smbus_write_byte_data(data->client,
- BMG160_REG_INT_EN_1, ret);
+ ret = regmap_update_bits(data->regmap, BMG160_REG_INT_EN_1,
+ BMG160_INT1_BIT_OD, 0);
if (ret < 0) {
- dev_err(&data->client->dev, "Error writing reg_int_en_1\n");
+ dev_err(&data->client->dev, "Error updating bits in reg_int_en_1\n");
return ret;
}

- ret = i2c_smbus_write_byte_data(data->client,
- BMG160_REG_INT_RST_LATCH,
- BMG160_INT_MODE_LATCH_INT |
- BMG160_INT_MODE_LATCH_RESET);
+ ret = regmap_write(data->regmap, BMG160_REG_INT_RST_LATCH,
+ BMG160_INT_MODE_LATCH_INT |
+ BMG160_INT_MODE_LATCH_RESET);
if (ret < 0) {
dev_err(&data->client->dev,
"Error writing reg_motion_intr\n");
@@ -284,41 +282,28 @@ static int bmg160_setup_any_motion_interrupt(struct bmg160_data *data,
int ret;

/* Enable/Disable INT_MAP0 mapping */
- ret = i2c_smbus_read_byte_data(data->client, BMG160_REG_INT_MAP_0);
- if (ret < 0) {
- dev_err(&data->client->dev, "Error reading reg_int_map0\n");
- return ret;
- }
- if (status)
- ret |= BMG160_INT_MAP_0_BIT_ANY;
- else
- ret &= ~BMG160_INT_MAP_0_BIT_ANY;
-
- ret = i2c_smbus_write_byte_data(data->client,
- BMG160_REG_INT_MAP_0,
- ret);
+ ret = regmap_update_bits(data->regmap, BMG160_REG_INT_MAP_0,
+ BMG160_INT_MAP_0_BIT_ANY,
+ (status ? BMG160_INT_MAP_0_BIT_ANY : 0));
if (ret < 0) {
- dev_err(&data->client->dev, "Error writing reg_int_map0\n");
+ dev_err(&data->client->dev, "Error updating bits reg_int_map0\n");
return ret;
}

/* Enable/Disable slope interrupts */
if (status) {
/* Update slope thres */
- ret = i2c_smbus_write_byte_data(data->client,
- BMG160_REG_SLOPE_THRES,
- data->slope_thres);
+ ret = regmap_write(data->regmap, BMG160_REG_SLOPE_THRES,
+ data->slope_thres);
if (ret < 0) {
dev_err(&data->client->dev,
"Error writing reg_slope_thres\n");
return ret;
}

- ret = i2c_smbus_write_byte_data(data->client,
- BMG160_REG_MOTION_INTR,
- BMG160_INT_MOTION_X |
- BMG160_INT_MOTION_Y |
- BMG160_INT_MOTION_Z);
+ ret = regmap_write(data->regmap, BMG160_REG_MOTION_INTR,
+ BMG160_INT_MOTION_X | BMG160_INT_MOTION_Y |
+ BMG160_INT_MOTION_Z);
if (ret < 0) {
dev_err(&data->client->dev,
"Error writing reg_motion_intr\n");
@@ -331,10 +316,10 @@ static int bmg160_setup_any_motion_interrupt(struct bmg160_data *data,
* to set latched mode, we will be flooded anyway with INTR
*/
if (!data->dready_trigger_on) {
- ret = i2c_smbus_write_byte_data(data->client,
- BMG160_REG_INT_RST_LATCH,
- BMG160_INT_MODE_LATCH_INT |
- BMG160_INT_MODE_LATCH_RESET);
+ ret = regmap_write(data->regmap,
+ BMG160_REG_INT_RST_LATCH,
+ BMG160_INT_MODE_LATCH_INT |
+ BMG160_INT_MODE_LATCH_RESET);
if (ret < 0) {
dev_err(&data->client->dev,
"Error writing reg_rst_latch\n");
@@ -342,14 +327,12 @@ static int bmg160_setup_any_motion_interrupt(struct bmg160_data *data,
}
}

- ret = i2c_smbus_write_byte_data(data->client,
- BMG160_REG_INT_EN_0,
- BMG160_DATA_ENABLE_INT);
+ ret = regmap_write(data->regmap, BMG160_REG_INT_EN_0,
+ BMG160_DATA_ENABLE_INT);

- } else
- ret = i2c_smbus_write_byte_data(data->client,
- BMG160_REG_INT_EN_0,
- 0);
+ } else {
+ ret = regmap_write(data->regmap, BMG160_REG_INT_EN_0, 0);
+ }

if (ret < 0) {
dev_err(&data->client->dev, "Error writing reg_int_en0\n");
@@ -365,55 +348,39 @@ static int bmg160_setup_new_data_interrupt(struct bmg160_data *data,
int ret;

/* Enable/Disable INT_MAP1 mapping */
- ret = i2c_smbus_read_byte_data(data->client, BMG160_REG_INT_MAP_1);
- if (ret < 0) {
- dev_err(&data->client->dev, "Error reading reg_int_map1\n");
- return ret;
- }
-
- if (status)
- ret |= BMG160_INT_MAP_1_BIT_NEW_DATA;
- else
- ret &= ~BMG160_INT_MAP_1_BIT_NEW_DATA;
-
- ret = i2c_smbus_write_byte_data(data->client,
- BMG160_REG_INT_MAP_1,
- ret);
+ ret = regmap_update_bits(data->regmap, BMG160_REG_INT_MAP_1,
+ BMG160_INT_MAP_1_BIT_NEW_DATA,
+ (status ? BMG160_INT_MAP_1_BIT_NEW_DATA : 0));
if (ret < 0) {
- dev_err(&data->client->dev, "Error writing reg_int_map1\n");
+ dev_err(&data->client->dev, "Error updating bits in reg_int_map1\n");
return ret;
}

if (status) {
- ret = i2c_smbus_write_byte_data(data->client,
- BMG160_REG_INT_RST_LATCH,
- BMG160_INT_MODE_NON_LATCH_INT |
- BMG160_INT_MODE_LATCH_RESET);
+ ret = regmap_write(data->regmap, BMG160_REG_INT_RST_LATCH,
+ BMG160_INT_MODE_NON_LATCH_INT |
+ BMG160_INT_MODE_LATCH_RESET);
if (ret < 0) {
dev_err(&data->client->dev,
"Error writing reg_rst_latch\n");
return ret;
}

- ret = i2c_smbus_write_byte_data(data->client,
- BMG160_REG_INT_EN_0,
- BMG160_DATA_ENABLE_INT);
+ ret = regmap_write(data->regmap, BMG160_REG_INT_EN_0,
+ BMG160_DATA_ENABLE_INT);

} else {
/* Restore interrupt mode */
- ret = i2c_smbus_write_byte_data(data->client,
- BMG160_REG_INT_RST_LATCH,
- BMG160_INT_MODE_LATCH_INT |
- BMG160_INT_MODE_LATCH_RESET);
+ ret = regmap_write(data->regmap, BMG160_REG_INT_RST_LATCH,
+ BMG160_INT_MODE_LATCH_INT |
+ BMG160_INT_MODE_LATCH_RESET);
if (ret < 0) {
dev_err(&data->client->dev,
"Error writing reg_rst_latch\n");
return ret;
}

- ret = i2c_smbus_write_byte_data(data->client,
- BMG160_REG_INT_EN_0,
- 0);
+ ret = regmap_write(data->regmap, BMG160_REG_INT_EN_0, 0);
}

if (ret < 0) {
@@ -444,10 +411,8 @@ static int bmg160_set_scale(struct bmg160_data *data, int val)

for (i = 0; i < ARRAY_SIZE(bmg160_scale_table); ++i) {
if (bmg160_scale_table[i].scale == val) {
- ret = i2c_smbus_write_byte_data(
- data->client,
- BMG160_REG_RANGE,
- bmg160_scale_table[i].dps_range);
+ ret = regmap_write(data->regmap, BMG160_REG_RANGE,
+ bmg160_scale_table[i].dps_range);
if (ret < 0) {
dev_err(&data->client->dev,
"Error writing reg_range\n");
@@ -464,6 +429,7 @@ static int bmg160_set_scale(struct bmg160_data *data, int val)
static int bmg160_get_temp(struct bmg160_data *data, int *val)
{
int ret;
+ unsigned int raw_val;

mutex_lock(&data->mutex);
ret = bmg160_set_power_state(data, true);
@@ -472,7 +438,7 @@ static int bmg160_get_temp(struct bmg160_data *data, int *val)
return ret;
}

- ret = i2c_smbus_read_byte_data(data->client, BMG160_REG_TEMP);
+ ret = regmap_read(data->regmap, BMG160_REG_TEMP, &raw_val);
if (ret < 0) {
dev_err(&data->client->dev, "Error reading reg_temp\n");
bmg160_set_power_state(data, false);
@@ -480,7 +446,7 @@ static int bmg160_get_temp(struct bmg160_data *data, int *val)
return ret;
}

- *val = sign_extend32(ret, 7);
+ *val = sign_extend32(raw_val, 7);
ret = bmg160_set_power_state(data, false);
mutex_unlock(&data->mutex);
if (ret < 0)
@@ -492,6 +458,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)
{
int ret;
+ unsigned int raw_val;

mutex_lock(&data->mutex);
ret = bmg160_set_power_state(data, true);
@@ -500,7 +467,8 @@ static int bmg160_get_axis(struct bmg160_data *data, int axis, int *val)
return ret;
}

- ret = i2c_smbus_read_word_data(data->client, BMG160_AXIS_TO_REG(axis));
+ ret = regmap_bulk_read(data->regmap, BMG160_AXIS_TO_REG(axis), &raw_val,
+ 2);
if (ret < 0) {
dev_err(&data->client->dev, "Error reading axis %d\n", axis);
bmg160_set_power_state(data, false);
@@ -508,7 +476,7 @@ static int bmg160_get_axis(struct bmg160_data *data, int axis, int *val)
return ret;
}

- *val = sign_extend32(ret, 15);
+ *val = sign_extend32(raw_val, 15);
ret = bmg160_set_power_state(data, false);
mutex_unlock(&data->mutex);
if (ret < 0)
@@ -807,12 +775,13 @@ static irqreturn_t bmg160_trigger_handler(int irq, void *p)
struct iio_dev *indio_dev = pf->indio_dev;
struct bmg160_data *data = iio_priv(indio_dev);
int bit, ret, i = 0;
+ unsigned int val;

mutex_lock(&data->mutex);
for_each_set_bit(bit, indio_dev->active_scan_mask,
indio_dev->masklength) {
- ret = i2c_smbus_read_word_data(data->client,
- BMG160_AXIS_TO_REG(bit));
+ ret = regmap_bulk_read(data->regmap, BMG160_AXIS_TO_REG(bit),
+ &val, 2);
if (ret < 0) {
mutex_unlock(&data->mutex);
goto err;
@@ -840,10 +809,9 @@ static int bmg160_trig_try_reen(struct iio_trigger *trig)
return 0;

/* Set latched mode interrupt and clear any latched interrupt */
- ret = i2c_smbus_write_byte_data(data->client,
- BMG160_REG_INT_RST_LATCH,
- BMG160_INT_MODE_LATCH_INT |
- BMG160_INT_MODE_LATCH_RESET);
+ ret = regmap_write(data->regmap, BMG160_REG_INT_RST_LATCH,
+ BMG160_INT_MODE_LATCH_INT |
+ BMG160_INT_MODE_LATCH_RESET);
if (ret < 0) {
dev_err(&data->client->dev, "Error writing reg_rst_latch\n");
return ret;
@@ -907,33 +875,34 @@ static irqreturn_t bmg160_event_handler(int irq, void *private)
struct bmg160_data *data = iio_priv(indio_dev);
int ret;
int dir;
+ unsigned int val;

- ret = i2c_smbus_read_byte_data(data->client, BMG160_REG_INT_STATUS_2);
+ ret = regmap_read(data->regmap, BMG160_REG_INT_STATUS_2, &val);
if (ret < 0) {
dev_err(&data->client->dev, "Error reading reg_int_status2\n");
goto ack_intr_status;
}

- if (ret & 0x08)
+ if (val & 0x08)
dir = IIO_EV_DIR_RISING;
else
dir = IIO_EV_DIR_FALLING;

- if (ret & BMG160_ANY_MOTION_BIT_X)
+ if (val & BMG160_ANY_MOTION_BIT_X)
iio_push_event(indio_dev, IIO_MOD_EVENT_CODE(IIO_ANGL_VEL,
0,
IIO_MOD_X,
IIO_EV_TYPE_ROC,
dir),
iio_get_time_ns());
- if (ret & BMG160_ANY_MOTION_BIT_Y)
+ if (val & BMG160_ANY_MOTION_BIT_Y)
iio_push_event(indio_dev, IIO_MOD_EVENT_CODE(IIO_ANGL_VEL,
0,
IIO_MOD_Y,
IIO_EV_TYPE_ROC,
dir),
iio_get_time_ns());
- if (ret & BMG160_ANY_MOTION_BIT_Z)
+ if (val & BMG160_ANY_MOTION_BIT_Z)
iio_push_event(indio_dev, IIO_MOD_EVENT_CODE(IIO_ANGL_VEL,
0,
IIO_MOD_Z,
@@ -943,10 +912,9 @@ static irqreturn_t bmg160_event_handler(int irq, void *private)

ack_intr_status:
if (!data->dready_trigger_on) {
- ret = i2c_smbus_write_byte_data(data->client,
- BMG160_REG_INT_RST_LATCH,
- BMG160_INT_MODE_LATCH_INT |
- BMG160_INT_MODE_LATCH_RESET);
+ ret = regmap_write(data->regmap, BMG160_REG_INT_RST_LATCH,
+ BMG160_INT_MODE_LATCH_INT |
+ BMG160_INT_MODE_LATCH_RESET);
if (ret < 0)
dev_err(&data->client->dev,
"Error writing reg_rst_latch\n");
@@ -1038,6 +1006,14 @@ static int bmg160_probe(struct i2c_client *client,
struct iio_dev *indio_dev;
int ret;
const char *name = NULL;
+ struct regmap *regmap;
+
+ regmap = devm_regmap_init_i2c(client, &bmg160_regmap_i2c_conf);
+ if (IS_ERR(regmap)) {
+ dev_err(&client->dev, "Failed to register i2c regmap %d\n",
+ (int)PTR_ERR(regmap));
+ return PTR_ERR(regmap);
+ }

indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
if (!indio_dev)
--
2.4.6

2015-08-12 14:50:24

by Markus Pargmann

[permalink] [raw]
Subject: [PATCH v3 2/6] iio: bmg160: Remove i2c_client from data struct

i2c_client variable is not really used anymore in the core driver. It is
only used to get the device to make proper outputs.

This patch replaces all i2c_client usage through direct usage of the
device pointer.

Signed-off-by: Markus Pargmann <[email protected]>
---
drivers/iio/gyro/bmg160.c | 64 +++++++++++++++++++++++------------------------
1 file changed, 32 insertions(+), 32 deletions(-)

diff --git a/drivers/iio/gyro/bmg160.c b/drivers/iio/gyro/bmg160.c
index bbe02053e98a..4701ea17baea 100644
--- a/drivers/iio/gyro/bmg160.c
+++ b/drivers/iio/gyro/bmg160.c
@@ -98,7 +98,7 @@
#define BMG160_AUTO_SUSPEND_DELAY_MS 2000

struct bmg160_data {
- struct i2c_client *client;
+ struct device *dev;
struct regmap *regmap;
struct iio_trigger *dready_trig;
struct iio_trigger *motion_trig;
@@ -148,7 +148,7 @@ static int bmg160_set_mode(struct bmg160_data *data, u8 mode)

ret = regmap_write(data->regmap, BMG160_REG_PMU_LPW, mode);
if (ret < 0) {
- dev_err(&data->client->dev, "Error writing reg_pmu_lpw\n");
+ dev_err(data->dev, "Error writing reg_pmu_lpw\n");
return ret;
}

@@ -178,7 +178,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->client->dev, "Error writing reg_pmu_bw\n");
+ dev_err(data->dev, "Error writing reg_pmu_bw\n");
return ret;
}

@@ -194,13 +194,13 @@ static int bmg160_chip_init(struct bmg160_data *data)

ret = regmap_read(data->regmap, BMG160_REG_CHIP_ID, &val);
if (ret < 0) {
- dev_err(&data->client->dev, "Error reading reg_chip_id\n");
+ dev_err(data->dev, "Error reading reg_chip_id\n");
return ret;
}

- dev_dbg(&data->client->dev, "Chip Id %x\n", val);
+ dev_dbg(data->dev, "Chip Id %x\n", val);
if (val != BMG160_CHIP_ID_VAL) {
- dev_err(&data->client->dev, "invalid chip %x\n", val);
+ dev_err(data->dev, "invalid chip %x\n", val);
return -ENODEV;
}

@@ -219,14 +219,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->client->dev, "Error writing reg_range\n");
+ dev_err(data->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->client->dev, "Error reading reg_slope_thres\n");
+ dev_err(data->dev, "Error reading reg_slope_thres\n");
return ret;
}
data->slope_thres = val;
@@ -235,7 +235,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->client->dev, "Error updating bits in reg_int_en_1\n");
+ dev_err(data->dev, "Error updating bits in reg_int_en_1\n");
return ret;
}

@@ -243,7 +243,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->client->dev,
+ dev_err(data->dev,
"Error writing reg_motion_intr\n");
return ret;
}
@@ -257,17 +257,17 @@ static int bmg160_set_power_state(struct bmg160_data *data, bool on)
int ret;

if (on)
- ret = pm_runtime_get_sync(&data->client->dev);
+ ret = pm_runtime_get_sync(data->dev);
else {
- pm_runtime_mark_last_busy(&data->client->dev);
- ret = pm_runtime_put_autosuspend(&data->client->dev);
+ pm_runtime_mark_last_busy(data->dev);
+ ret = pm_runtime_put_autosuspend(data->dev);
}

if (ret < 0) {
- dev_err(&data->client->dev,
+ dev_err(data->dev,
"Failed: bmg160_set_power_state for %d\n", on);
if (on)
- pm_runtime_put_noidle(&data->client->dev);
+ pm_runtime_put_noidle(data->dev);

return ret;
}
@@ -286,7 +286,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->client->dev, "Error updating bits reg_int_map0\n");
+ dev_err(data->dev, "Error updating bits reg_int_map0\n");
return ret;
}

@@ -296,7 +296,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->client->dev,
+ dev_err(data->dev,
"Error writing reg_slope_thres\n");
return ret;
}
@@ -305,7 +305,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->client->dev,
+ dev_err(data->dev,
"Error writing reg_motion_intr\n");
return ret;
}
@@ -321,7 +321,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->client->dev,
+ dev_err(data->dev,
"Error writing reg_rst_latch\n");
return ret;
}
@@ -335,7 +335,7 @@ static int bmg160_setup_any_motion_interrupt(struct bmg160_data *data,
}

if (ret < 0) {
- dev_err(&data->client->dev, "Error writing reg_int_en0\n");
+ dev_err(data->dev, "Error writing reg_int_en0\n");
return ret;
}

@@ -352,7 +352,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->client->dev, "Error updating bits in reg_int_map1\n");
+ dev_err(data->dev, "Error updating bits in reg_int_map1\n");
return ret;
}

@@ -361,7 +361,7 @@ 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->client->dev,
+ dev_err(data->dev,
"Error writing reg_rst_latch\n");
return ret;
}
@@ -375,7 +375,7 @@ 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->client->dev,
+ dev_err(data->dev,
"Error writing reg_rst_latch\n");
return ret;
}
@@ -384,7 +384,7 @@ static int bmg160_setup_new_data_interrupt(struct bmg160_data *data,
}

if (ret < 0) {
- dev_err(&data->client->dev, "Error writing reg_int_en0\n");
+ dev_err(data->dev, "Error writing reg_int_en0\n");
return ret;
}

@@ -414,7 +414,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->client->dev,
+ dev_err(data->dev,
"Error writing reg_range\n");
return ret;
}
@@ -440,7 +440,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->client->dev, "Error reading reg_temp\n");
+ dev_err(data->dev, "Error reading reg_temp\n");
bmg160_set_power_state(data, false);
mutex_unlock(&data->mutex);
return ret;
@@ -470,7 +470,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->client->dev, "Error reading axis %d\n", axis);
+ dev_err(data->dev, "Error reading axis %d\n", axis);
bmg160_set_power_state(data, false);
mutex_unlock(&data->mutex);
return ret;
@@ -813,7 +813,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->client->dev, "Error writing reg_rst_latch\n");
+ dev_err(data->dev, "Error writing reg_rst_latch\n");
return ret;
}

@@ -879,7 +879,7 @@ static irqreturn_t bmg160_event_handler(int irq, void *private)

ret = regmap_read(data->regmap, BMG160_REG_INT_STATUS_2, &val);
if (ret < 0) {
- dev_err(&data->client->dev, "Error reading reg_int_status2\n");
+ dev_err(data->dev, "Error reading reg_int_status2\n");
goto ack_intr_status;
}

@@ -916,7 +916,7 @@ ack_intr_status:
BMG160_INT_MODE_LATCH_INT |
BMG160_INT_MODE_LATCH_RESET);
if (ret < 0)
- dev_err(&data->client->dev,
+ dev_err(data->dev,
"Error writing reg_rst_latch\n");
}

@@ -1021,7 +1021,7 @@ static int bmg160_probe(struct i2c_client *client,

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

ret = bmg160_chip_init(data);
if (ret < 0)
@@ -1188,7 +1188,7 @@ static int bmg160_runtime_suspend(struct device *dev)

ret = bmg160_set_mode(data, BMG160_MODE_SUSPEND);
if (ret < 0) {
- dev_err(&data->client->dev, "set mode failed\n");
+ dev_err(data->dev, "set mode failed\n");
return -EAGAIN;
}

--
2.4.6

2015-08-12 14:50:30

by Markus Pargmann

[permalink] [raw]
Subject: [PATCH v3 3/6] iio: bmg160: Use generic dev_drvdata

i2c_get_clientdata() is specifically for i2c. Replace it with the
generic dev_get/set_drvdata() to support different protocols.

Signed-off-by: Markus Pargmann <[email protected]>
---
drivers/iio/gyro/bmg160.c | 10 +++++-----
1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/iio/gyro/bmg160.c b/drivers/iio/gyro/bmg160.c
index 4701ea17baea..6eab91ba8977 100644
--- a/drivers/iio/gyro/bmg160.c
+++ b/drivers/iio/gyro/bmg160.c
@@ -1020,7 +1020,7 @@ static int bmg160_probe(struct i2c_client *client,
return -ENOMEM;

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

ret = bmg160_chip_init(data);
@@ -1154,7 +1154,7 @@ static int bmg160_remove(struct i2c_client *client)
#ifdef CONFIG_PM_SLEEP
static int bmg160_suspend(struct device *dev)
{
- struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
+ struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct bmg160_data *data = iio_priv(indio_dev);

mutex_lock(&data->mutex);
@@ -1166,7 +1166,7 @@ static int bmg160_suspend(struct device *dev)

static int bmg160_resume(struct device *dev)
{
- struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
+ struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct bmg160_data *data = iio_priv(indio_dev);

mutex_lock(&data->mutex);
@@ -1182,7 +1182,7 @@ static int bmg160_resume(struct device *dev)
#ifdef CONFIG_PM
static int bmg160_runtime_suspend(struct device *dev)
{
- struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
+ struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct bmg160_data *data = iio_priv(indio_dev);
int ret;

@@ -1197,7 +1197,7 @@ static int bmg160_runtime_suspend(struct device *dev)

static int bmg160_runtime_resume(struct device *dev)
{
- struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
+ struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct bmg160_data *data = iio_priv(indio_dev);
int ret;

--
2.4.6

2015-08-12 14:51:21

by Markus Pargmann

[permalink] [raw]
Subject: [PATCH v3 4/6] iio: bmg160: Remove remaining uses of i2c_client

Signed-off-by: Markus Pargmann <[email protected]>
---
drivers/iio/gyro/bmg160.c | 55 +++++++++++++++++++++++------------------------
1 file changed, 27 insertions(+), 28 deletions(-)

diff --git a/drivers/iio/gyro/bmg160.c b/drivers/iio/gyro/bmg160.c
index 6eab91ba8977..39df64fb4262 100644
--- a/drivers/iio/gyro/bmg160.c
+++ b/drivers/iio/gyro/bmg160.c
@@ -110,6 +110,7 @@ struct bmg160_data {
int slope_thres;
bool dready_trigger_on;
bool motion_trigger_on;
+ int irq;
};

enum bmg160_axis {
@@ -961,18 +962,14 @@ static const struct iio_buffer_setup_ops bmg160_buffer_setup_ops = {
.postdisable = bmg160_buffer_postdisable,
};

-static int bmg160_gpio_probe(struct i2c_client *client,
- struct bmg160_data *data)
+static int bmg160_gpio_probe(struct bmg160_data *data)

{
struct device *dev;
struct gpio_desc *gpio;
int ret;

- if (!client)
- return -EINVAL;
-
- dev = &client->dev;
+ dev = data->dev;

/* data ready gpio interrupt pin */
gpio = devm_gpiod_get_index(dev, BMG160_GPIO_NAME, 0, GPIOD_IN);
@@ -981,11 +978,11 @@ static int bmg160_gpio_probe(struct i2c_client *client,
return PTR_ERR(gpio);
}

- ret = gpiod_to_irq(gpio);
+ data->irq = gpiod_to_irq(gpio);

dev_dbg(dev, "GPIO resource, no:%d irq:%d\n", desc_to_gpio(gpio), ret);

- return ret;
+ return 0;
}

static const char *bmg160_match_acpi_device(struct device *dev)
@@ -1007,6 +1004,7 @@ static int bmg160_probe(struct i2c_client *client,
int ret;
const char *name = NULL;
struct regmap *regmap;
+ struct device *dev = &client->dev;

regmap = devm_regmap_init_i2c(client, &bmg160_regmap_i2c_conf);
if (IS_ERR(regmap)) {
@@ -1020,8 +1018,9 @@ static int bmg160_probe(struct i2c_client *client,
return -ENOMEM;

data = iio_priv(indio_dev);
- dev_set_drvdata(&client->dev, indio_dev);
- data->dev = &client->dev;
+ dev_set_drvdata(dev, indio_dev);
+ data->dev = dev;
+ data->irq = client->irq;

ret = bmg160_chip_init(data);
if (ret < 0)
@@ -1032,22 +1031,22 @@ static int bmg160_probe(struct i2c_client *client,
if (id)
name = id->name;

- if (ACPI_HANDLE(&client->dev))
- name = bmg160_match_acpi_device(&client->dev);
+ if (ACPI_HANDLE(dev))
+ name = bmg160_match_acpi_device(dev);

- indio_dev->dev.parent = &client->dev;
+ indio_dev->dev.parent = dev;
indio_dev->channels = bmg160_channels;
indio_dev->num_channels = ARRAY_SIZE(bmg160_channels);
indio_dev->name = name;
indio_dev->modes = INDIO_DIRECT_MODE;
indio_dev->info = &bmg160_info;

- if (client->irq <= 0)
- client->irq = bmg160_gpio_probe(client, data);
+ if (data->irq <= 0)
+ bmg160_gpio_probe(data);

- if (client->irq > 0) {
- ret = devm_request_threaded_irq(&client->dev,
- client->irq,
+ if (data->irq > 0) {
+ ret = devm_request_threaded_irq(dev,
+ data->irq,
bmg160_data_rdy_trig_poll,
bmg160_event_handler,
IRQF_TRIGGER_RISING,
@@ -1056,28 +1055,28 @@ static int bmg160_probe(struct i2c_client *client,
if (ret)
return ret;

- data->dready_trig = devm_iio_trigger_alloc(&client->dev,
+ data->dready_trig = devm_iio_trigger_alloc(dev,
"%s-dev%d",
indio_dev->name,
indio_dev->id);
if (!data->dready_trig)
return -ENOMEM;

- data->motion_trig = devm_iio_trigger_alloc(&client->dev,
+ data->motion_trig = devm_iio_trigger_alloc(dev,
"%s-any-motion-dev%d",
indio_dev->name,
indio_dev->id);
if (!data->motion_trig)
return -ENOMEM;

- data->dready_trig->dev.parent = &client->dev;
+ data->dready_trig->dev.parent = dev;
data->dready_trig->ops = &bmg160_trigger_ops;
iio_trigger_set_drvdata(data->dready_trig, indio_dev);
ret = iio_trigger_register(data->dready_trig);
if (ret)
return ret;

- data->motion_trig->dev.parent = &client->dev;
+ data->motion_trig->dev.parent = dev;
data->motion_trig->ops = &bmg160_trigger_ops;
iio_trigger_set_drvdata(data->motion_trig, indio_dev);
ret = iio_trigger_register(data->motion_trig);
@@ -1092,25 +1091,25 @@ static int bmg160_probe(struct i2c_client *client,
bmg160_trigger_handler,
&bmg160_buffer_setup_ops);
if (ret < 0) {
- dev_err(&client->dev,
+ dev_err(dev,
"iio triggered buffer setup failed\n");
goto err_trigger_unregister;
}

ret = iio_device_register(indio_dev);
if (ret < 0) {
- dev_err(&client->dev, "unable to register iio device\n");
+ dev_err(dev, "unable to register iio device\n");
goto err_buffer_cleanup;
}

- ret = pm_runtime_set_active(&client->dev);
+ ret = pm_runtime_set_active(dev);
if (ret)
goto err_iio_unregister;

- pm_runtime_enable(&client->dev);
- pm_runtime_set_autosuspend_delay(&client->dev,
+ pm_runtime_enable(dev);
+ pm_runtime_set_autosuspend_delay(dev,
BMG160_AUTO_SUSPEND_DELAY_MS);
- pm_runtime_use_autosuspend(&client->dev);
+ pm_runtime_use_autosuspend(dev);

return 0;

--
2.4.6

2015-08-12 14:50:37

by Markus Pargmann

[permalink] [raw]
Subject: [PATCH v3 5/6] iio: bmg160: Separate i2c and core driver

This patch separates the core driver using regmap and the i2c driver
which creates the i2c regmap. Also in the Kconfig file BMG160 and
BMG160_I2C are separate now.

Signed-off-by: Markus Pargmann <[email protected]>
---
drivers/iio/gyro/Kconfig | 18 +++++--
drivers/iio/gyro/Makefile | 2 +-
drivers/iio/gyro/bmg160.h | 10 ++++
drivers/iio/gyro/{bmg160.c => bmg160_core.c} | 77 +++++-----------------------
drivers/iio/gyro/bmg160_i2c.c | 71 +++++++++++++++++++++++++
5 files changed, 109 insertions(+), 69 deletions(-)
create mode 100644 drivers/iio/gyro/bmg160.h
rename drivers/iio/gyro/{bmg160.c => bmg160_core.c} (94%)
create mode 100644 drivers/iio/gyro/bmg160_i2c.c

diff --git a/drivers/iio/gyro/Kconfig b/drivers/iio/gyro/Kconfig
index cf82d74139a2..13f8e0051615 100644
--- a/drivers/iio/gyro/Kconfig
+++ b/drivers/iio/gyro/Kconfig
@@ -51,17 +51,27 @@ config ADXRS450
will be called adxrs450.

config BMG160
- tristate "BOSCH BMG160 Gyro Sensor"
- depends on I2C
+ bool "BOSCH BMG160 Gyro Sensor"
select IIO_BUFFER
select IIO_TRIGGERED_BUFFER
- select REGMAP_I2C
help
Say yes here to build support for Bosch BMG160 Tri-axis Gyro Sensor
driver. This driver also supports BMI055 gyroscope.

+if BMG160
+
+config BMG160_I2C
+ tristate "Driver for connection via I2C"
+ depends on I2C
+ select REGMAP_I2C
+ help
+ Say yes here to build support for Bosch BMG160 Tri-axis Gyro Sensor
+ driver connected via I2C. This driver also supports BMI055 gyroscope.
+
This driver can also be built as a module. If so, the module
- will be called bmg160.
+ will be called bmg160_i2c.
+
+endif

config HID_SENSOR_GYRO_3D
depends on HID_SENSOR_HUB
diff --git a/drivers/iio/gyro/Makefile b/drivers/iio/gyro/Makefile
index f46341b39139..73b41e43a974 100644
--- a/drivers/iio/gyro/Makefile
+++ b/drivers/iio/gyro/Makefile
@@ -8,7 +8,7 @@ obj-$(CONFIG_ADIS16130) += adis16130.o
obj-$(CONFIG_ADIS16136) += adis16136.o
obj-$(CONFIG_ADIS16260) += adis16260.o
obj-$(CONFIG_ADXRS450) += adxrs450.o
-obj-$(CONFIG_BMG160) += bmg160.o
+obj-$(CONFIG_BMG160_I2C) += bmg160_core.o bmg160_i2c.o

obj-$(CONFIG_HID_SENSOR_GYRO_3D) += hid-sensor-gyro-3d.o

diff --git a/drivers/iio/gyro/bmg160.h b/drivers/iio/gyro/bmg160.h
new file mode 100644
index 000000000000..72db723c8fb6
--- /dev/null
+++ b/drivers/iio/gyro/bmg160.h
@@ -0,0 +1,10 @@
+#ifndef BMG160_H_
+#define BMG160_H_
+
+extern const struct dev_pm_ops bmg160_pm_ops;
+
+int bmg160_core_probe(struct device *dev, struct regmap *regmap, int irq,
+ const char *name);
+void bmg160_core_remove(struct device *dev);
+
+#endif /* BMG160_H_ */
diff --git a/drivers/iio/gyro/bmg160.c b/drivers/iio/gyro/bmg160_core.c
similarity index 94%
rename from drivers/iio/gyro/bmg160.c
rename to drivers/iio/gyro/bmg160_core.c
index 39df64fb4262..d64e3a87e0a1 100644
--- a/drivers/iio/gyro/bmg160.c
+++ b/drivers/iio/gyro/bmg160_core.c
@@ -13,7 +13,6 @@
*/

#include <linux/module.h>
-#include <linux/i2c.h>
#include <linux/interrupt.h>
#include <linux/delay.h>
#include <linux/slab.h>
@@ -30,7 +29,6 @@
#include <linux/iio/triggered_buffer.h>
#include <linux/regmap.h>

-#define BMG160_DRV_NAME "bmg160"
#define BMG160_IRQ_NAME "bmg160_event"
#define BMG160_GPIO_NAME "gpio_int"

@@ -137,12 +135,6 @@ static const struct {
{ 133, BMG160_RANGE_250DPS},
{ 66, BMG160_RANGE_125DPS} };

-struct regmap_config bmg160_regmap_i2c_conf = {
- .reg_bits = 8,
- .val_bits = 8,
- .max_register = 0x3f
-};
-
static int bmg160_set_mode(struct bmg160_data *data, u8 mode)
{
int ret;
@@ -996,31 +988,22 @@ static const char *bmg160_match_acpi_device(struct device *dev)
return dev_name(dev);
}

-static int bmg160_probe(struct i2c_client *client,
- const struct i2c_device_id *id)
+int bmg160_core_probe(struct device *dev, struct regmap *regmap, int irq,
+ const char *name)
{
struct bmg160_data *data;
struct iio_dev *indio_dev;
int ret;
- const char *name = NULL;
- struct regmap *regmap;
- struct device *dev = &client->dev;
-
- regmap = devm_regmap_init_i2c(client, &bmg160_regmap_i2c_conf);
- if (IS_ERR(regmap)) {
- dev_err(&client->dev, "Failed to register i2c regmap %d\n",
- (int)PTR_ERR(regmap));
- return PTR_ERR(regmap);
- }

- indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
+ indio_dev = devm_iio_device_alloc(dev, sizeof(*data));
if (!indio_dev)
return -ENOMEM;

data = iio_priv(indio_dev);
dev_set_drvdata(dev, indio_dev);
data->dev = dev;
- data->irq = client->irq;
+ data->irq = irq;
+ data->regmap = regmap;

ret = bmg160_chip_init(data);
if (ret < 0)
@@ -1028,9 +1011,6 @@ static int bmg160_probe(struct i2c_client *client,

mutex_init(&data->mutex);

- if (id)
- name = id->name;
-
if (ACPI_HANDLE(dev))
name = bmg160_match_acpi_device(dev);

@@ -1125,15 +1105,16 @@ err_trigger_unregister:

return ret;
}
+EXPORT_SYMBOL_GPL(bmg160_core_probe);

-static int bmg160_remove(struct i2c_client *client)
+void bmg160_core_remove(struct device *dev)
{
- struct iio_dev *indio_dev = i2c_get_clientdata(client);
+ struct iio_dev *indio_dev = dev_get_drvdata(dev);
struct bmg160_data *data = iio_priv(indio_dev);

- pm_runtime_disable(&client->dev);
- pm_runtime_set_suspended(&client->dev);
- pm_runtime_put_noidle(&client->dev);
+ pm_runtime_disable(dev);
+ pm_runtime_set_suspended(dev);
+ pm_runtime_put_noidle(dev);

iio_device_unregister(indio_dev);
iio_triggered_buffer_cleanup(indio_dev);
@@ -1146,9 +1127,8 @@ static int bmg160_remove(struct i2c_client *client)
mutex_lock(&data->mutex);
bmg160_set_mode(data, BMG160_MODE_DEEP_SUSPEND);
mutex_unlock(&data->mutex);
-
- return 0;
}
+EXPORT_SYMBOL_GPL(bmg160_core_remove);

#ifdef CONFIG_PM_SLEEP
static int bmg160_suspend(struct device *dev)
@@ -1210,40 +1190,9 @@ static int bmg160_runtime_resume(struct device *dev)
}
#endif

-static const struct dev_pm_ops bmg160_pm_ops = {
+const struct dev_pm_ops bmg160_pm_ops = {
SET_SYSTEM_SLEEP_PM_OPS(bmg160_suspend, bmg160_resume)
SET_RUNTIME_PM_OPS(bmg160_runtime_suspend,
bmg160_runtime_resume, NULL)
};

-static const struct acpi_device_id bmg160_acpi_match[] = {
- {"BMG0160", 0},
- {"BMI055B", 0},
- {},
-};
-
-MODULE_DEVICE_TABLE(acpi, bmg160_acpi_match);
-
-static const struct i2c_device_id bmg160_id[] = {
- {"bmg160", 0},
- {"bmi055_gyro", 0},
- {}
-};
-
-MODULE_DEVICE_TABLE(i2c, bmg160_id);
-
-static struct i2c_driver bmg160_driver = {
- .driver = {
- .name = BMG160_DRV_NAME,
- .acpi_match_table = ACPI_PTR(bmg160_acpi_match),
- .pm = &bmg160_pm_ops,
- },
- .probe = bmg160_probe,
- .remove = bmg160_remove,
- .id_table = bmg160_id,
-};
-module_i2c_driver(bmg160_driver);
-
-MODULE_AUTHOR("Srinivas Pandruvada <[email protected]>");
-MODULE_LICENSE("GPL v2");
-MODULE_DESCRIPTION("BMG160 Gyro driver");
diff --git a/drivers/iio/gyro/bmg160_i2c.c b/drivers/iio/gyro/bmg160_i2c.c
new file mode 100644
index 000000000000..90126a5a7663
--- /dev/null
+++ b/drivers/iio/gyro/bmg160_i2c.c
@@ -0,0 +1,71 @@
+#include <linux/i2c.h>
+#include <linux/regmap.h>
+#include <linux/iio/iio.h>
+#include <linux/module.h>
+#include <linux/acpi.h>
+
+#include "bmg160.h"
+
+static const struct regmap_config bmg160_regmap_i2c_conf = {
+ .reg_bits = 8,
+ .val_bits = 8,
+ .max_register = 0x3f
+};
+
+static int bmg160_i2c_probe(struct i2c_client *client,
+ const struct i2c_device_id *id)
+{
+ struct regmap *regmap;
+ const char *name = NULL;
+
+ regmap = devm_regmap_init_i2c(client, &bmg160_regmap_i2c_conf);
+ if (IS_ERR(regmap)) {
+ dev_err(&client->dev, "Failed to register i2c regmap %d\n",
+ (int)PTR_ERR(regmap));
+ return PTR_ERR(regmap);
+ }
+
+ if (id)
+ name = id->name;
+
+ return bmg160_core_probe(&client->dev, regmap, client->irq, name);
+}
+
+static int bmg160_i2c_remove(struct i2c_client *client)
+{
+ bmg160_core_remove(&client->dev);
+
+ return 0;
+}
+
+static const struct acpi_device_id bmg160_acpi_match[] = {
+ {"BMG0160", 0},
+ {"BMI055B", 0},
+ {},
+};
+
+MODULE_DEVICE_TABLE(acpi, bmg160_acpi_match);
+
+static const struct i2c_device_id bmg160_i2c_id[] = {
+ {"bmg160", 0},
+ {"bmi055_gyro", 0},
+ {}
+};
+
+MODULE_DEVICE_TABLE(i2c, bmg160_i2c_id);
+
+static struct i2c_driver bmg160_i2c_driver = {
+ .driver = {
+ .name = "bmg160_i2c",
+ .acpi_match_table = ACPI_PTR(bmg160_acpi_match),
+ .pm = &bmg160_pm_ops,
+ },
+ .probe = bmg160_i2c_probe,
+ .remove = bmg160_i2c_remove,
+ .id_table = bmg160_i2c_id,
+};
+module_i2c_driver(bmg160_i2c_driver);
+
+MODULE_AUTHOR("Srinivas Pandruvada <[email protected]>");
+MODULE_LICENSE("GPL v2");
+MODULE_DESCRIPTION("BMG160 I2C Gyro driver");
--
2.4.6

2015-08-12 14:50:23

by Markus Pargmann

[permalink] [raw]
Subject: [PATCH v3 6/6] iio: bmg160: Add SPI driver

Signed-off-by: Markus Pargmann <[email protected]>
---
drivers/iio/gyro/Kconfig | 11 +++++++++
drivers/iio/gyro/Makefile | 1 +
drivers/iio/gyro/bmg160_spi.c | 57 +++++++++++++++++++++++++++++++++++++++++++
3 files changed, 69 insertions(+)
create mode 100644 drivers/iio/gyro/bmg160_spi.c

diff --git a/drivers/iio/gyro/Kconfig b/drivers/iio/gyro/Kconfig
index 13f8e0051615..a77dbb0062fe 100644
--- a/drivers/iio/gyro/Kconfig
+++ b/drivers/iio/gyro/Kconfig
@@ -71,6 +71,17 @@ config BMG160_I2C
This driver can also be built as a module. If so, the module
will be called bmg160_i2c.

+config BMG160_SPI
+ tristate "Driver for connection via SPI"
+ depends on SPI
+ select REGMAP_SPI
+ help
+ Say yes here to build support for Bosch BMG160 Tri-axis Gyro Sensor
+ driver connected via SPI. This driver also supports BMI055 gyroscope.
+
+ This driver can also be built as a module. If so, the module
+ will be called bmg160_spi.
+
endif

config HID_SENSOR_GYRO_3D
diff --git a/drivers/iio/gyro/Makefile b/drivers/iio/gyro/Makefile
index 73b41e43a974..848e55c605c0 100644
--- a/drivers/iio/gyro/Makefile
+++ b/drivers/iio/gyro/Makefile
@@ -9,6 +9,7 @@ obj-$(CONFIG_ADIS16136) += adis16136.o
obj-$(CONFIG_ADIS16260) += adis16260.o
obj-$(CONFIG_ADXRS450) += adxrs450.o
obj-$(CONFIG_BMG160_I2C) += bmg160_core.o bmg160_i2c.o
+obj-$(CONFIG_BMG160_I2C) += bmg160_core.o bmg160_spi.o

obj-$(CONFIG_HID_SENSOR_GYRO_3D) += hid-sensor-gyro-3d.o

diff --git a/drivers/iio/gyro/bmg160_spi.c b/drivers/iio/gyro/bmg160_spi.c
new file mode 100644
index 000000000000..8a358571b702
--- /dev/null
+++ b/drivers/iio/gyro/bmg160_spi.c
@@ -0,0 +1,57 @@
+#include <linux/spi/spi.h>
+#include <linux/regmap.h>
+#include <linux/iio/iio.h>
+#include <linux/module.h>
+
+#include <bmg160.h>
+
+static const struct regmap_config bmg160_regmap_spi_conf = {
+ .reg_bits = 8,
+ .val_bits = 8,
+ .max_register = 0x3f,
+};
+
+static int bmg160_spi_probe(struct spi_device *spi)
+{
+ struct regmap *regmap;
+ const struct spi_device_id *id = spi_get_device_id(spi);
+
+ regmap = devm_regmap_init_spi(spi, &bmg160_regmap_spi_conf);
+ if (IS_ERR(regmap)) {
+ dev_err(&spi->dev, "Failed to register spi regmap %d\n",
+ (int)PTR_ERR(regmap));
+ return PTR_ERR(regmap);
+ }
+
+ return bmg160_core_probe(&spi->dev, regmap, spi->irq, id->name);
+}
+
+static int bmg160_spi_remove(struct spi_device *spi)
+{
+ bmg160_core_remove(&spi->dev);
+
+ return 0;
+}
+
+static const struct spi_device_id bmg160_spi_id[] = {
+ {"bmg160", 0},
+ {"bmi055_gyro", 0},
+ {}
+};
+
+MODULE_DEVICE_TABLE(spi, bmg160_spi_id);
+
+static struct spi_driver bmg160_spi_driver = {
+ .driver = {
+ .name = "bmg160_spi",
+ .pm = &bmg160_pm_ops,
+ },
+ .probe = bmg160_spi_probe,
+ .remove = bmg160_spi_remove,
+ .id_table = bmg160_spi_id,
+};
+module_spi_driver(bmg160_spi_driver);
+
+MODULE_AUTHOR("Markus Pargmann <[email protected]>");
+MODULE_LICENSE("GPL v2");
+MODULE_DESCRIPTION("BMG160 SPI Gyro driver");
--
2.4.6

2015-08-12 15:04:11

by Lars-Peter Clausen

[permalink] [raw]
Subject: Re: [PATCH v3 0/6] iio: bmg160: Add SPI connection

Hi,

Markus and Irina can you try to synchronize your efforts. This series will
conflict with http://marc.info/?l=linux-iio&m=143938994602171&w=2

I think it would be best if the multi-read emulation support is added to
regmap (which I think Markus' earlier series did).

- Lars

On 08/12/2015 04:50 PM, Markus Pargmann wrote:
> Hi,
>
> bmg160 and bmi055 can be used via I2C and SPI. This series converts the driver
> to regmap and splits core driver and I2C/SPI.
>
> Changes in v3:
> - removed 'select REGMAP' as it is selected by REGMAP_I2C
> - added EXPORT_SYMBOL_GPL for the core functions
> - removed default values from regmap_config
> - Added max_register and unset use_single_rw in regmap_config
> - Changed Makefile to always compile bmg160-core with either spi or i2c. It is
> not possible now to compile the core alone.
>
> Changes in v2:
> - Added the id->name from the SPI driver to be used as iio device name
> - Fixed Kconfig in patch 2 to add selects for REGMAP_I2C
> - Fixed regmap configs to be static const
>
>
> Best regards,
>
> Markus
>
>
> Markus Pargmann (6):
> iio: bmg160: Use i2c regmap instead of direct i2c access
> iio: bmg160: Remove i2c_client from data struct
> iio: bmg160: Use generic dev_drvdata
> iio: bmg160: Remove remaining uses of i2c_client
> iio: bmg160: Separate i2c and core driver
> iio: bmg160: Add SPI driver
>
> drivers/iio/gyro/Kconfig | 28 ++-
> drivers/iio/gyro/Makefile | 3 +-
> drivers/iio/gyro/bmg160.h | 10 +
> drivers/iio/gyro/{bmg160.c => bmg160_core.c} | 358 +++++++++++----------------
> drivers/iio/gyro/bmg160_i2c.c | 71 ++++++
> drivers/iio/gyro/bmg160_spi.c | 57 +++++
> 6 files changed, 306 insertions(+), 221 deletions(-)
> create mode 100644 drivers/iio/gyro/bmg160.h
> rename drivers/iio/gyro/{bmg160.c => bmg160_core.c} (74%)
> create mode 100644 drivers/iio/gyro/bmg160_i2c.c
> create mode 100644 drivers/iio/gyro/bmg160_spi.c
>

2015-08-12 15:19:41

by Peter Meerwald-Stadler

[permalink] [raw]
Subject: Re: [PATCH v3 6/6] iio: bmg160: Add SPI driver

On Wed, 12 Aug 2015, Markus Pargmann wrote:

> Signed-off-by: Markus Pargmann <[email protected]>

the spelling of Bosch is inconsistent, sometimes it is BOSCH, I'd prefer
the former

please find a slightly more relevant comment below :)

> ---
> drivers/iio/gyro/Kconfig | 11 +++++++++
> drivers/iio/gyro/Makefile | 1 +
> drivers/iio/gyro/bmg160_spi.c | 57 +++++++++++++++++++++++++++++++++++++++++++
> 3 files changed, 69 insertions(+)
> create mode 100644 drivers/iio/gyro/bmg160_spi.c
>
> diff --git a/drivers/iio/gyro/Kconfig b/drivers/iio/gyro/Kconfig
> index 13f8e0051615..a77dbb0062fe 100644
> --- a/drivers/iio/gyro/Kconfig
> +++ b/drivers/iio/gyro/Kconfig
> @@ -71,6 +71,17 @@ config BMG160_I2C
> This driver can also be built as a module. If so, the module
> will be called bmg160_i2c.
>
> +config BMG160_SPI
> + tristate "Driver for connection via SPI"
> + depends on SPI
> + select REGMAP_SPI
> + help
> + Say yes here to build support for Bosch BMG160 Tri-axis Gyro Sensor
> + driver connected via SPI. This driver also supports BMI055 gyroscope.
> +
> + This driver can also be built as a module. If so, the module
> + will be called bmg160_spi.
> +
> endif
>
> config HID_SENSOR_GYRO_3D
> diff --git a/drivers/iio/gyro/Makefile b/drivers/iio/gyro/Makefile
> index 73b41e43a974..848e55c605c0 100644
> --- a/drivers/iio/gyro/Makefile
> +++ b/drivers/iio/gyro/Makefile
> @@ -9,6 +9,7 @@ obj-$(CONFIG_ADIS16136) += adis16136.o
> obj-$(CONFIG_ADIS16260) += adis16260.o
> obj-$(CONFIG_ADXRS450) += adxrs450.o
> obj-$(CONFIG_BMG160_I2C) += bmg160_core.o bmg160_i2c.o
> +obj-$(CONFIG_BMG160_I2C) += bmg160_core.o bmg160_spi.o
>
> obj-$(CONFIG_HID_SENSOR_GYRO_3D) += hid-sensor-gyro-3d.o
>
> diff --git a/drivers/iio/gyro/bmg160_spi.c b/drivers/iio/gyro/bmg160_spi.c
> new file mode 100644
> index 000000000000..8a358571b702
> --- /dev/null
> +++ b/drivers/iio/gyro/bmg160_spi.c
> @@ -0,0 +1,57 @@
> +#include <linux/spi/spi.h>
> +#include <linux/regmap.h>
> +#include <linux/iio/iio.h>
> +#include <linux/module.h>
> +
> +#include <bmg160.h>

I think this should be
#include "bmg160.h"
as in the _i2c part of the driver

> +
> +static const struct regmap_config bmg160_regmap_spi_conf = {
> + .reg_bits = 8,
> + .val_bits = 8,
> + .max_register = 0x3f,
> +};
> +
> +static int bmg160_spi_probe(struct spi_device *spi)
> +{
> + struct regmap *regmap;
> + const struct spi_device_id *id = spi_get_device_id(spi);
> +
> + regmap = devm_regmap_init_spi(spi, &bmg160_regmap_spi_conf);
> + if (IS_ERR(regmap)) {
> + dev_err(&spi->dev, "Failed to register spi regmap %d\n",
> + (int)PTR_ERR(regmap));
> + return PTR_ERR(regmap);
> + }
> +
> + return bmg160_core_probe(&spi->dev, regmap, spi->irq, id->name);
> +}
> +
> +static int bmg160_spi_remove(struct spi_device *spi)
> +{
> + bmg160_core_remove(&spi->dev);
> +
> + return 0;
> +}
> +
> +static const struct spi_device_id bmg160_spi_id[] = {
> + {"bmg160", 0},
> + {"bmi055_gyro", 0},
> + {}
> +};
> +
> +MODULE_DEVICE_TABLE(spi, bmg160_spi_id);
> +
> +static struct spi_driver bmg160_spi_driver = {
> + .driver = {
> + .name = "bmg160_spi",
> + .pm = &bmg160_pm_ops,
> + },
> + .probe = bmg160_spi_probe,
> + .remove = bmg160_spi_remove,
> + .id_table = bmg160_spi_id,
> +};
> +module_spi_driver(bmg160_spi_driver);
> +
> +MODULE_AUTHOR("Markus Pargmann <[email protected]>");
> +MODULE_LICENSE("GPL v2");
> +MODULE_DESCRIPTION("BMG160 SPI Gyro driver");
>

--

Peter Meerwald
+43-664-2444418 (mobile)

2015-08-12 16:02:02

by srinivas pandruvada

[permalink] [raw]
Subject: Re: [PATCH v3 1/6] iio: bmg160: Use i2c regmap instead of direct i2c access

On Wed, 2015-08-12 at 16:50 +0200, Markus Pargmann wrote:
> This patch introduces regmap usage into the driver. This is done to
> later easily support the SPI interface of this chip.
>
> Signed-off-by: Markus Pargmann <[email protected]>
Reviewed-by: Srinivas Pandruvada <[email protected]>
> ---
> drivers/iio/gyro/Kconfig | 1 +
> drivers/iio/gyro/bmg160.c | 198 ++++++++++++++++++++--------------------------
> 2 files changed, 88 insertions(+), 111 deletions(-)
>
> diff --git a/drivers/iio/gyro/Kconfig b/drivers/iio/gyro/Kconfig
> index 8d2439345673..cf82d74139a2 100644
> --- a/drivers/iio/gyro/Kconfig
> +++ b/drivers/iio/gyro/Kconfig
> @@ -55,6 +55,7 @@ config BMG160
> depends on I2C
> select IIO_BUFFER
> select IIO_TRIGGERED_BUFFER
> + select REGMAP_I2C
> help
> Say yes here to build support for Bosch BMG160 Tri-axis Gyro Sensor
> driver. This driver also supports BMI055 gyroscope.
> diff --git a/drivers/iio/gyro/bmg160.c b/drivers/iio/gyro/bmg160.c
> index 460bf715d541..bbe02053e98a 100644
> --- a/drivers/iio/gyro/bmg160.c
> +++ b/drivers/iio/gyro/bmg160.c
> @@ -28,6 +28,7 @@
> #include <linux/iio/events.h>
> #include <linux/iio/trigger_consumer.h>
> #include <linux/iio/triggered_buffer.h>
> +#include <linux/regmap.h>
>
> #define BMG160_DRV_NAME "bmg160"
> #define BMG160_IRQ_NAME "bmg160_event"
> @@ -98,6 +99,7 @@
>
> struct bmg160_data {
> struct i2c_client *client;
> + struct regmap *regmap;
> struct iio_trigger *dready_trig;
> struct iio_trigger *motion_trig;
> struct mutex mutex;
> @@ -134,12 +136,17 @@ static const struct {
> { 133, BMG160_RANGE_250DPS},
> { 66, BMG160_RANGE_125DPS} };
>
> +struct regmap_config bmg160_regmap_i2c_conf = {
> + .reg_bits = 8,
> + .val_bits = 8,
> + .max_register = 0x3f
> +};
> +
> static int bmg160_set_mode(struct bmg160_data *data, u8 mode)
> {
> int ret;
>
> - ret = i2c_smbus_write_byte_data(data->client,
> - BMG160_REG_PMU_LPW, mode);
> + ret = regmap_write(data->regmap, BMG160_REG_PMU_LPW, mode);
> if (ret < 0) {
> dev_err(&data->client->dev, "Error writing reg_pmu_lpw\n");
> return ret;
> @@ -169,8 +176,7 @@ static int bmg160_set_bw(struct bmg160_data *data, int val)
> if (bw_bits < 0)
> return bw_bits;
>
> - ret = i2c_smbus_write_byte_data(data->client, BMG160_REG_PMU_BW,
> - bw_bits);
> + ret = regmap_write(data->regmap, BMG160_REG_PMU_BW, bw_bits);
> if (ret < 0) {
> dev_err(&data->client->dev, "Error writing reg_pmu_bw\n");
> return ret;
> @@ -184,16 +190,17 @@ static int bmg160_set_bw(struct bmg160_data *data, int val)
> static int bmg160_chip_init(struct bmg160_data *data)
> {
> int ret;
> + unsigned int val;
>
> - ret = i2c_smbus_read_byte_data(data->client, BMG160_REG_CHIP_ID);
> + ret = regmap_read(data->regmap, BMG160_REG_CHIP_ID, &val);
> if (ret < 0) {
> dev_err(&data->client->dev, "Error reading reg_chip_id\n");
> return ret;
> }
>
> - dev_dbg(&data->client->dev, "Chip Id %x\n", ret);
> - if (ret != BMG160_CHIP_ID_VAL) {
> - dev_err(&data->client->dev, "invalid chip %x\n", ret);
> + dev_dbg(&data->client->dev, "Chip Id %x\n", val);
> + if (val != BMG160_CHIP_ID_VAL) {
> + dev_err(&data->client->dev, "invalid chip %x\n", val);
> return -ENODEV;
> }
>
> @@ -210,40 +217,31 @@ static int bmg160_chip_init(struct bmg160_data *data)
> return ret;
>
> /* Set Default Range */
> - ret = i2c_smbus_write_byte_data(data->client,
> - BMG160_REG_RANGE,
> - BMG160_RANGE_500DPS);
> + ret = regmap_write(data->regmap, BMG160_REG_RANGE, BMG160_RANGE_500DPS);
> if (ret < 0) {
> dev_err(&data->client->dev, "Error writing reg_range\n");
> return ret;
> }
> data->dps_range = BMG160_RANGE_500DPS;
>
> - ret = i2c_smbus_read_byte_data(data->client, BMG160_REG_SLOPE_THRES);
> + ret = regmap_read(data->regmap, BMG160_REG_SLOPE_THRES, &val);
> if (ret < 0) {
> dev_err(&data->client->dev, "Error reading reg_slope_thres\n");
> return ret;
> }
> - data->slope_thres = ret;
> + data->slope_thres = val;
>
> /* Set default interrupt mode */
> - ret = i2c_smbus_read_byte_data(data->client, BMG160_REG_INT_EN_1);
> - if (ret < 0) {
> - dev_err(&data->client->dev, "Error reading reg_int_en_1\n");
> - return ret;
> - }
> - ret &= ~BMG160_INT1_BIT_OD;
> - ret = i2c_smbus_write_byte_data(data->client,
> - BMG160_REG_INT_EN_1, ret);
> + ret = regmap_update_bits(data->regmap, BMG160_REG_INT_EN_1,
> + BMG160_INT1_BIT_OD, 0);
> if (ret < 0) {
> - dev_err(&data->client->dev, "Error writing reg_int_en_1\n");
> + dev_err(&data->client->dev, "Error updating bits in reg_int_en_1\n");
> return ret;
> }
>
> - ret = i2c_smbus_write_byte_data(data->client,
> - BMG160_REG_INT_RST_LATCH,
> - BMG160_INT_MODE_LATCH_INT |
> - BMG160_INT_MODE_LATCH_RESET);
> + ret = regmap_write(data->regmap, BMG160_REG_INT_RST_LATCH,
> + BMG160_INT_MODE_LATCH_INT |
> + BMG160_INT_MODE_LATCH_RESET);
> if (ret < 0) {
> dev_err(&data->client->dev,
> "Error writing reg_motion_intr\n");
> @@ -284,41 +282,28 @@ static int bmg160_setup_any_motion_interrupt(struct bmg160_data *data,
> int ret;
>
> /* Enable/Disable INT_MAP0 mapping */
> - ret = i2c_smbus_read_byte_data(data->client, BMG160_REG_INT_MAP_0);
> - if (ret < 0) {
> - dev_err(&data->client->dev, "Error reading reg_int_map0\n");
> - return ret;
> - }
> - if (status)
> - ret |= BMG160_INT_MAP_0_BIT_ANY;
> - else
> - ret &= ~BMG160_INT_MAP_0_BIT_ANY;
> -
> - ret = i2c_smbus_write_byte_data(data->client,
> - BMG160_REG_INT_MAP_0,
> - ret);
> + ret = regmap_update_bits(data->regmap, BMG160_REG_INT_MAP_0,
> + BMG160_INT_MAP_0_BIT_ANY,
> + (status ? BMG160_INT_MAP_0_BIT_ANY : 0));
> if (ret < 0) {
> - dev_err(&data->client->dev, "Error writing reg_int_map0\n");
> + dev_err(&data->client->dev, "Error updating bits reg_int_map0\n");
> return ret;
> }
>
> /* Enable/Disable slope interrupts */
> if (status) {
> /* Update slope thres */
> - ret = i2c_smbus_write_byte_data(data->client,
> - BMG160_REG_SLOPE_THRES,
> - data->slope_thres);
> + ret = regmap_write(data->regmap, BMG160_REG_SLOPE_THRES,
> + data->slope_thres);
> if (ret < 0) {
> dev_err(&data->client->dev,
> "Error writing reg_slope_thres\n");
> return ret;
> }
>
> - ret = i2c_smbus_write_byte_data(data->client,
> - BMG160_REG_MOTION_INTR,
> - BMG160_INT_MOTION_X |
> - BMG160_INT_MOTION_Y |
> - BMG160_INT_MOTION_Z);
> + ret = regmap_write(data->regmap, BMG160_REG_MOTION_INTR,
> + BMG160_INT_MOTION_X | BMG160_INT_MOTION_Y |
> + BMG160_INT_MOTION_Z);
> if (ret < 0) {
> dev_err(&data->client->dev,
> "Error writing reg_motion_intr\n");
> @@ -331,10 +316,10 @@ static int bmg160_setup_any_motion_interrupt(struct bmg160_data *data,
> * to set latched mode, we will be flooded anyway with INTR
> */
> if (!data->dready_trigger_on) {
> - ret = i2c_smbus_write_byte_data(data->client,
> - BMG160_REG_INT_RST_LATCH,
> - BMG160_INT_MODE_LATCH_INT |
> - BMG160_INT_MODE_LATCH_RESET);
> + ret = regmap_write(data->regmap,
> + BMG160_REG_INT_RST_LATCH,
> + BMG160_INT_MODE_LATCH_INT |
> + BMG160_INT_MODE_LATCH_RESET);
> if (ret < 0) {
> dev_err(&data->client->dev,
> "Error writing reg_rst_latch\n");
> @@ -342,14 +327,12 @@ static int bmg160_setup_any_motion_interrupt(struct bmg160_data *data,
> }
> }
>
> - ret = i2c_smbus_write_byte_data(data->client,
> - BMG160_REG_INT_EN_0,
> - BMG160_DATA_ENABLE_INT);
> + ret = regmap_write(data->regmap, BMG160_REG_INT_EN_0,
> + BMG160_DATA_ENABLE_INT);
>
> - } else
> - ret = i2c_smbus_write_byte_data(data->client,
> - BMG160_REG_INT_EN_0,
> - 0);
> + } else {
> + ret = regmap_write(data->regmap, BMG160_REG_INT_EN_0, 0);
> + }
>
> if (ret < 0) {
> dev_err(&data->client->dev, "Error writing reg_int_en0\n");
> @@ -365,55 +348,39 @@ static int bmg160_setup_new_data_interrupt(struct bmg160_data *data,
> int ret;
>
> /* Enable/Disable INT_MAP1 mapping */
> - ret = i2c_smbus_read_byte_data(data->client, BMG160_REG_INT_MAP_1);
> - if (ret < 0) {
> - dev_err(&data->client->dev, "Error reading reg_int_map1\n");
> - return ret;
> - }
> -
> - if (status)
> - ret |= BMG160_INT_MAP_1_BIT_NEW_DATA;
> - else
> - ret &= ~BMG160_INT_MAP_1_BIT_NEW_DATA;
> -
> - ret = i2c_smbus_write_byte_data(data->client,
> - BMG160_REG_INT_MAP_1,
> - ret);
> + ret = regmap_update_bits(data->regmap, BMG160_REG_INT_MAP_1,
> + BMG160_INT_MAP_1_BIT_NEW_DATA,
> + (status ? BMG160_INT_MAP_1_BIT_NEW_DATA : 0));
> if (ret < 0) {
> - dev_err(&data->client->dev, "Error writing reg_int_map1\n");
> + dev_err(&data->client->dev, "Error updating bits in reg_int_map1\n");
> return ret;
> }
>
> if (status) {
> - ret = i2c_smbus_write_byte_data(data->client,
> - BMG160_REG_INT_RST_LATCH,
> - BMG160_INT_MODE_NON_LATCH_INT |
> - BMG160_INT_MODE_LATCH_RESET);
> + ret = regmap_write(data->regmap, BMG160_REG_INT_RST_LATCH,
> + BMG160_INT_MODE_NON_LATCH_INT |
> + BMG160_INT_MODE_LATCH_RESET);
> if (ret < 0) {
> dev_err(&data->client->dev,
> "Error writing reg_rst_latch\n");
> return ret;
> }
>
> - ret = i2c_smbus_write_byte_data(data->client,
> - BMG160_REG_INT_EN_0,
> - BMG160_DATA_ENABLE_INT);
> + ret = regmap_write(data->regmap, BMG160_REG_INT_EN_0,
> + BMG160_DATA_ENABLE_INT);
>
> } else {
> /* Restore interrupt mode */
> - ret = i2c_smbus_write_byte_data(data->client,
> - BMG160_REG_INT_RST_LATCH,
> - BMG160_INT_MODE_LATCH_INT |
> - BMG160_INT_MODE_LATCH_RESET);
> + ret = regmap_write(data->regmap, BMG160_REG_INT_RST_LATCH,
> + BMG160_INT_MODE_LATCH_INT |
> + BMG160_INT_MODE_LATCH_RESET);
> if (ret < 0) {
> dev_err(&data->client->dev,
> "Error writing reg_rst_latch\n");
> return ret;
> }
>
> - ret = i2c_smbus_write_byte_data(data->client,
> - BMG160_REG_INT_EN_0,
> - 0);
> + ret = regmap_write(data->regmap, BMG160_REG_INT_EN_0, 0);
> }
>
> if (ret < 0) {
> @@ -444,10 +411,8 @@ static int bmg160_set_scale(struct bmg160_data *data, int val)
>
> for (i = 0; i < ARRAY_SIZE(bmg160_scale_table); ++i) {
> if (bmg160_scale_table[i].scale == val) {
> - ret = i2c_smbus_write_byte_data(
> - data->client,
> - BMG160_REG_RANGE,
> - bmg160_scale_table[i].dps_range);
> + ret = regmap_write(data->regmap, BMG160_REG_RANGE,
> + bmg160_scale_table[i].dps_range);
> if (ret < 0) {
> dev_err(&data->client->dev,
> "Error writing reg_range\n");
> @@ -464,6 +429,7 @@ static int bmg160_set_scale(struct bmg160_data *data, int val)
> static int bmg160_get_temp(struct bmg160_data *data, int *val)
> {
> int ret;
> + unsigned int raw_val;
>
> mutex_lock(&data->mutex);
> ret = bmg160_set_power_state(data, true);
> @@ -472,7 +438,7 @@ static int bmg160_get_temp(struct bmg160_data *data, int *val)
> return ret;
> }
>
> - ret = i2c_smbus_read_byte_data(data->client, BMG160_REG_TEMP);
> + ret = regmap_read(data->regmap, BMG160_REG_TEMP, &raw_val);
> if (ret < 0) {
> dev_err(&data->client->dev, "Error reading reg_temp\n");
> bmg160_set_power_state(data, false);
> @@ -480,7 +446,7 @@ static int bmg160_get_temp(struct bmg160_data *data, int *val)
> return ret;
> }
>
> - *val = sign_extend32(ret, 7);
> + *val = sign_extend32(raw_val, 7);
> ret = bmg160_set_power_state(data, false);
> mutex_unlock(&data->mutex);
> if (ret < 0)
> @@ -492,6 +458,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)
> {
> int ret;
> + unsigned int raw_val;
>
> mutex_lock(&data->mutex);
> ret = bmg160_set_power_state(data, true);
> @@ -500,7 +467,8 @@ static int bmg160_get_axis(struct bmg160_data *data, int axis, int *val)
> return ret;
> }
>
> - ret = i2c_smbus_read_word_data(data->client, BMG160_AXIS_TO_REG(axis));
> + ret = regmap_bulk_read(data->regmap, BMG160_AXIS_TO_REG(axis), &raw_val,
> + 2);
> if (ret < 0) {
> dev_err(&data->client->dev, "Error reading axis %d\n", axis);
> bmg160_set_power_state(data, false);
> @@ -508,7 +476,7 @@ static int bmg160_get_axis(struct bmg160_data *data, int axis, int *val)
> return ret;
> }
>
> - *val = sign_extend32(ret, 15);
> + *val = sign_extend32(raw_val, 15);
> ret = bmg160_set_power_state(data, false);
> mutex_unlock(&data->mutex);
> if (ret < 0)
> @@ -807,12 +775,13 @@ static irqreturn_t bmg160_trigger_handler(int irq, void *p)
> struct iio_dev *indio_dev = pf->indio_dev;
> struct bmg160_data *data = iio_priv(indio_dev);
> int bit, ret, i = 0;
> + unsigned int val;
>
> mutex_lock(&data->mutex);
> for_each_set_bit(bit, indio_dev->active_scan_mask,
> indio_dev->masklength) {
> - ret = i2c_smbus_read_word_data(data->client,
> - BMG160_AXIS_TO_REG(bit));
> + ret = regmap_bulk_read(data->regmap, BMG160_AXIS_TO_REG(bit),
> + &val, 2);
> if (ret < 0) {
> mutex_unlock(&data->mutex);
> goto err;
> @@ -840,10 +809,9 @@ static int bmg160_trig_try_reen(struct iio_trigger *trig)
> return 0;
>
> /* Set latched mode interrupt and clear any latched interrupt */
> - ret = i2c_smbus_write_byte_data(data->client,
> - BMG160_REG_INT_RST_LATCH,
> - BMG160_INT_MODE_LATCH_INT |
> - BMG160_INT_MODE_LATCH_RESET);
> + ret = regmap_write(data->regmap, BMG160_REG_INT_RST_LATCH,
> + BMG160_INT_MODE_LATCH_INT |
> + BMG160_INT_MODE_LATCH_RESET);
> if (ret < 0) {
> dev_err(&data->client->dev, "Error writing reg_rst_latch\n");
> return ret;
> @@ -907,33 +875,34 @@ static irqreturn_t bmg160_event_handler(int irq, void *private)
> struct bmg160_data *data = iio_priv(indio_dev);
> int ret;
> int dir;
> + unsigned int val;
>
> - ret = i2c_smbus_read_byte_data(data->client, BMG160_REG_INT_STATUS_2);
> + ret = regmap_read(data->regmap, BMG160_REG_INT_STATUS_2, &val);
> if (ret < 0) {
> dev_err(&data->client->dev, "Error reading reg_int_status2\n");
> goto ack_intr_status;
> }
>
> - if (ret & 0x08)
> + if (val & 0x08)
> dir = IIO_EV_DIR_RISING;
> else
> dir = IIO_EV_DIR_FALLING;
>
> - if (ret & BMG160_ANY_MOTION_BIT_X)
> + if (val & BMG160_ANY_MOTION_BIT_X)
> iio_push_event(indio_dev, IIO_MOD_EVENT_CODE(IIO_ANGL_VEL,
> 0,
> IIO_MOD_X,
> IIO_EV_TYPE_ROC,
> dir),
> iio_get_time_ns());
> - if (ret & BMG160_ANY_MOTION_BIT_Y)
> + if (val & BMG160_ANY_MOTION_BIT_Y)
> iio_push_event(indio_dev, IIO_MOD_EVENT_CODE(IIO_ANGL_VEL,
> 0,
> IIO_MOD_Y,
> IIO_EV_TYPE_ROC,
> dir),
> iio_get_time_ns());
> - if (ret & BMG160_ANY_MOTION_BIT_Z)
> + if (val & BMG160_ANY_MOTION_BIT_Z)
> iio_push_event(indio_dev, IIO_MOD_EVENT_CODE(IIO_ANGL_VEL,
> 0,
> IIO_MOD_Z,
> @@ -943,10 +912,9 @@ static irqreturn_t bmg160_event_handler(int irq, void *private)
>
> ack_intr_status:
> if (!data->dready_trigger_on) {
> - ret = i2c_smbus_write_byte_data(data->client,
> - BMG160_REG_INT_RST_LATCH,
> - BMG160_INT_MODE_LATCH_INT |
> - BMG160_INT_MODE_LATCH_RESET);
> + ret = regmap_write(data->regmap, BMG160_REG_INT_RST_LATCH,
> + BMG160_INT_MODE_LATCH_INT |
> + BMG160_INT_MODE_LATCH_RESET);
> if (ret < 0)
> dev_err(&data->client->dev,
> "Error writing reg_rst_latch\n");
> @@ -1038,6 +1006,14 @@ static int bmg160_probe(struct i2c_client *client,
> struct iio_dev *indio_dev;
> int ret;
> const char *name = NULL;
> + struct regmap *regmap;
> +
> + regmap = devm_regmap_init_i2c(client, &bmg160_regmap_i2c_conf);
> + if (IS_ERR(regmap)) {
> + dev_err(&client->dev, "Failed to register i2c regmap %d\n",
> + (int)PTR_ERR(regmap));
> + return PTR_ERR(regmap);
> + }
>
> indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
> if (!indio_dev)

2015-08-12 16:04:35

by srinivas pandruvada

[permalink] [raw]
Subject: Re: [PATCH v3 2/6] iio: bmg160: Remove i2c_client from data struct

On Wed, 2015-08-12 at 16:50 +0200, Markus Pargmann wrote:
> i2c_client variable is not really used anymore in the core driver. It is
> only used to get the device to make proper outputs.
>
> This patch replaces all i2c_client usage through direct usage of the
> device pointer.
>
> Signed-off-by: Markus Pargmann <[email protected]>
Reviewed-by: Srinivas Pandruvada <[email protected]>
> ---
> drivers/iio/gyro/bmg160.c | 64 +++++++++++++++++++++++------------------------
> 1 file changed, 32 insertions(+), 32 deletions(-)
>
> diff --git a/drivers/iio/gyro/bmg160.c b/drivers/iio/gyro/bmg160.c
> index bbe02053e98a..4701ea17baea 100644
> --- a/drivers/iio/gyro/bmg160.c
> +++ b/drivers/iio/gyro/bmg160.c
> @@ -98,7 +98,7 @@
> #define BMG160_AUTO_SUSPEND_DELAY_MS 2000
>
> struct bmg160_data {
> - struct i2c_client *client;
> + struct device *dev;
> struct regmap *regmap;
> struct iio_trigger *dready_trig;
> struct iio_trigger *motion_trig;
> @@ -148,7 +148,7 @@ static int bmg160_set_mode(struct bmg160_data *data, u8 mode)
>
> ret = regmap_write(data->regmap, BMG160_REG_PMU_LPW, mode);
> if (ret < 0) {
> - dev_err(&data->client->dev, "Error writing reg_pmu_lpw\n");
> + dev_err(data->dev, "Error writing reg_pmu_lpw\n");
> return ret;
> }
>
> @@ -178,7 +178,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->client->dev, "Error writing reg_pmu_bw\n");
> + dev_err(data->dev, "Error writing reg_pmu_bw\n");
> return ret;
> }
>
> @@ -194,13 +194,13 @@ static int bmg160_chip_init(struct bmg160_data *data)
>
> ret = regmap_read(data->regmap, BMG160_REG_CHIP_ID, &val);
> if (ret < 0) {
> - dev_err(&data->client->dev, "Error reading reg_chip_id\n");
> + dev_err(data->dev, "Error reading reg_chip_id\n");
> return ret;
> }
>
> - dev_dbg(&data->client->dev, "Chip Id %x\n", val);
> + dev_dbg(data->dev, "Chip Id %x\n", val);
> if (val != BMG160_CHIP_ID_VAL) {
> - dev_err(&data->client->dev, "invalid chip %x\n", val);
> + dev_err(data->dev, "invalid chip %x\n", val);
> return -ENODEV;
> }
>
> @@ -219,14 +219,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->client->dev, "Error writing reg_range\n");
> + dev_err(data->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->client->dev, "Error reading reg_slope_thres\n");
> + dev_err(data->dev, "Error reading reg_slope_thres\n");
> return ret;
> }
> data->slope_thres = val;
> @@ -235,7 +235,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->client->dev, "Error updating bits in reg_int_en_1\n");
> + dev_err(data->dev, "Error updating bits in reg_int_en_1\n");
> return ret;
> }
>
> @@ -243,7 +243,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->client->dev,
> + dev_err(data->dev,
> "Error writing reg_motion_intr\n");
> return ret;
> }
> @@ -257,17 +257,17 @@ static int bmg160_set_power_state(struct bmg160_data *data, bool on)
> int ret;
>
> if (on)
> - ret = pm_runtime_get_sync(&data->client->dev);
> + ret = pm_runtime_get_sync(data->dev);
> else {
> - pm_runtime_mark_last_busy(&data->client->dev);
> - ret = pm_runtime_put_autosuspend(&data->client->dev);
> + pm_runtime_mark_last_busy(data->dev);
> + ret = pm_runtime_put_autosuspend(data->dev);
> }
>
> if (ret < 0) {
> - dev_err(&data->client->dev,
> + dev_err(data->dev,
> "Failed: bmg160_set_power_state for %d\n", on);
> if (on)
> - pm_runtime_put_noidle(&data->client->dev);
> + pm_runtime_put_noidle(data->dev);
>
> return ret;
> }
> @@ -286,7 +286,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->client->dev, "Error updating bits reg_int_map0\n");
> + dev_err(data->dev, "Error updating bits reg_int_map0\n");
> return ret;
> }
>
> @@ -296,7 +296,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->client->dev,
> + dev_err(data->dev,
> "Error writing reg_slope_thres\n");
> return ret;
> }
> @@ -305,7 +305,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->client->dev,
> + dev_err(data->dev,
> "Error writing reg_motion_intr\n");
> return ret;
> }
> @@ -321,7 +321,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->client->dev,
> + dev_err(data->dev,
> "Error writing reg_rst_latch\n");
> return ret;
> }
> @@ -335,7 +335,7 @@ static int bmg160_setup_any_motion_interrupt(struct bmg160_data *data,
> }
>
> if (ret < 0) {
> - dev_err(&data->client->dev, "Error writing reg_int_en0\n");
> + dev_err(data->dev, "Error writing reg_int_en0\n");
> return ret;
> }
>
> @@ -352,7 +352,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->client->dev, "Error updating bits in reg_int_map1\n");
> + dev_err(data->dev, "Error updating bits in reg_int_map1\n");
> return ret;
> }
>
> @@ -361,7 +361,7 @@ 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->client->dev,
> + dev_err(data->dev,
> "Error writing reg_rst_latch\n");
> return ret;
> }
> @@ -375,7 +375,7 @@ 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->client->dev,
> + dev_err(data->dev,
> "Error writing reg_rst_latch\n");
> return ret;
> }
> @@ -384,7 +384,7 @@ static int bmg160_setup_new_data_interrupt(struct bmg160_data *data,
> }
>
> if (ret < 0) {
> - dev_err(&data->client->dev, "Error writing reg_int_en0\n");
> + dev_err(data->dev, "Error writing reg_int_en0\n");
> return ret;
> }
>
> @@ -414,7 +414,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->client->dev,
> + dev_err(data->dev,
> "Error writing reg_range\n");
> return ret;
> }
> @@ -440,7 +440,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->client->dev, "Error reading reg_temp\n");
> + dev_err(data->dev, "Error reading reg_temp\n");
> bmg160_set_power_state(data, false);
> mutex_unlock(&data->mutex);
> return ret;
> @@ -470,7 +470,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->client->dev, "Error reading axis %d\n", axis);
> + dev_err(data->dev, "Error reading axis %d\n", axis);
> bmg160_set_power_state(data, false);
> mutex_unlock(&data->mutex);
> return ret;
> @@ -813,7 +813,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->client->dev, "Error writing reg_rst_latch\n");
> + dev_err(data->dev, "Error writing reg_rst_latch\n");
> return ret;
> }
>
> @@ -879,7 +879,7 @@ static irqreturn_t bmg160_event_handler(int irq, void *private)
>
> ret = regmap_read(data->regmap, BMG160_REG_INT_STATUS_2, &val);
> if (ret < 0) {
> - dev_err(&data->client->dev, "Error reading reg_int_status2\n");
> + dev_err(data->dev, "Error reading reg_int_status2\n");
> goto ack_intr_status;
> }
>
> @@ -916,7 +916,7 @@ ack_intr_status:
> BMG160_INT_MODE_LATCH_INT |
> BMG160_INT_MODE_LATCH_RESET);
> if (ret < 0)
> - dev_err(&data->client->dev,
> + dev_err(data->dev,
> "Error writing reg_rst_latch\n");
> }
>
> @@ -1021,7 +1021,7 @@ static int bmg160_probe(struct i2c_client *client,
>
> data = iio_priv(indio_dev);
> i2c_set_clientdata(client, indio_dev);
> - data->client = client;
> + data->dev = &client->dev;
>
> ret = bmg160_chip_init(data);
> if (ret < 0)
> @@ -1188,7 +1188,7 @@ static int bmg160_runtime_suspend(struct device *dev)
>
> ret = bmg160_set_mode(data, BMG160_MODE_SUSPEND);
> if (ret < 0) {
> - dev_err(&data->client->dev, "set mode failed\n");
> + dev_err(data->dev, "set mode failed\n");
> return -EAGAIN;
> }
>

2015-08-12 16:06:23

by srinivas pandruvada

[permalink] [raw]
Subject: Re: [PATCH v3 3/6] iio: bmg160: Use generic dev_drvdata

On Wed, 2015-08-12 at 16:50 +0200, Markus Pargmann wrote:
> i2c_get_clientdata() is specifically for i2c. Replace it with the
> generic dev_get/set_drvdata() to support different protocols.
>
> Signed-off-by: Markus Pargmann <[email protected]>
Reviewed-by: Srinivas Pandruvada <[email protected]>
> ---
> drivers/iio/gyro/bmg160.c | 10 +++++-----
> 1 file changed, 5 insertions(+), 5 deletions(-)
>
> diff --git a/drivers/iio/gyro/bmg160.c b/drivers/iio/gyro/bmg160.c
> index 4701ea17baea..6eab91ba8977 100644
> --- a/drivers/iio/gyro/bmg160.c
> +++ b/drivers/iio/gyro/bmg160.c
> @@ -1020,7 +1020,7 @@ static int bmg160_probe(struct i2c_client *client,
> return -ENOMEM;
>
> data = iio_priv(indio_dev);
> - i2c_set_clientdata(client, indio_dev);
> + dev_set_drvdata(&client->dev, indio_dev);
> data->dev = &client->dev;
>
> ret = bmg160_chip_init(data);
> @@ -1154,7 +1154,7 @@ static int bmg160_remove(struct i2c_client *client)
> #ifdef CONFIG_PM_SLEEP
> static int bmg160_suspend(struct device *dev)
> {
> - struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
> + struct iio_dev *indio_dev = dev_get_drvdata(dev);
> struct bmg160_data *data = iio_priv(indio_dev);
>
> mutex_lock(&data->mutex);
> @@ -1166,7 +1166,7 @@ static int bmg160_suspend(struct device *dev)
>
> static int bmg160_resume(struct device *dev)
> {
> - struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
> + struct iio_dev *indio_dev = dev_get_drvdata(dev);
> struct bmg160_data *data = iio_priv(indio_dev);
>
> mutex_lock(&data->mutex);
> @@ -1182,7 +1182,7 @@ static int bmg160_resume(struct device *dev)
> #ifdef CONFIG_PM
> static int bmg160_runtime_suspend(struct device *dev)
> {
> - struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
> + struct iio_dev *indio_dev = dev_get_drvdata(dev);
> struct bmg160_data *data = iio_priv(indio_dev);
> int ret;
>
> @@ -1197,7 +1197,7 @@ static int bmg160_runtime_suspend(struct device *dev)
>
> static int bmg160_runtime_resume(struct device *dev)
> {
> - struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
> + struct iio_dev *indio_dev = dev_get_drvdata(dev);
> struct bmg160_data *data = iio_priv(indio_dev);
> int ret;
>

2015-08-12 16:08:35

by srinivas pandruvada

[permalink] [raw]
Subject: Re: [PATCH v3 4/6] iio: bmg160: Remove remaining uses of i2c_client

Can you not merge this with patch 2/6?
On Wed, 2015-08-12 at 16:50 +0200, Markus Pargmann wrote:
> Signed-off-by: Markus Pargmann <[email protected]>
> ---
> drivers/iio/gyro/bmg160.c | 55 +++++++++++++++++++++++------------------------
> 1 file changed, 27 insertions(+), 28 deletions(-)
>
> diff --git a/drivers/iio/gyro/bmg160.c b/drivers/iio/gyro/bmg160.c
> index 6eab91ba8977..39df64fb4262 100644
> --- a/drivers/iio/gyro/bmg160.c
> +++ b/drivers/iio/gyro/bmg160.c
> @@ -110,6 +110,7 @@ struct bmg160_data {
> int slope_thres;
> bool dready_trigger_on;
> bool motion_trigger_on;
> + int irq;
> };
>
> enum bmg160_axis {
> @@ -961,18 +962,14 @@ static const struct iio_buffer_setup_ops bmg160_buffer_setup_ops = {
> .postdisable = bmg160_buffer_postdisable,
> };
>
> -static int bmg160_gpio_probe(struct i2c_client *client,
> - struct bmg160_data *data)
> +static int bmg160_gpio_probe(struct bmg160_data *data)
>
> {
> struct device *dev;
> struct gpio_desc *gpio;
> int ret;
>
> - if (!client)
> - return -EINVAL;
> -
> - dev = &client->dev;
> + dev = data->dev;
>
> /* data ready gpio interrupt pin */
> gpio = devm_gpiod_get_index(dev, BMG160_GPIO_NAME, 0, GPIOD_IN);
> @@ -981,11 +978,11 @@ static int bmg160_gpio_probe(struct i2c_client *client,
> return PTR_ERR(gpio);
> }
>
> - ret = gpiod_to_irq(gpio);
> + data->irq = gpiod_to_irq(gpio);
>
> dev_dbg(dev, "GPIO resource, no:%d irq:%d\n", desc_to_gpio(gpio), ret);
>
> - return ret;
> + return 0;
> }
>
> static const char *bmg160_match_acpi_device(struct device *dev)
> @@ -1007,6 +1004,7 @@ static int bmg160_probe(struct i2c_client *client,
> int ret;
> const char *name = NULL;
> struct regmap *regmap;
> + struct device *dev = &client->dev;
>
> regmap = devm_regmap_init_i2c(client, &bmg160_regmap_i2c_conf);
> if (IS_ERR(regmap)) {
> @@ -1020,8 +1018,9 @@ static int bmg160_probe(struct i2c_client *client,
> return -ENOMEM;
>
> data = iio_priv(indio_dev);
> - dev_set_drvdata(&client->dev, indio_dev);
> - data->dev = &client->dev;
> + dev_set_drvdata(dev, indio_dev);
> + data->dev = dev;
> + data->irq = client->irq;
>
> ret = bmg160_chip_init(data);
> if (ret < 0)
> @@ -1032,22 +1031,22 @@ static int bmg160_probe(struct i2c_client *client,
> if (id)
> name = id->name;
>
> - if (ACPI_HANDLE(&client->dev))
> - name = bmg160_match_acpi_device(&client->dev);
> + if (ACPI_HANDLE(dev))
> + name = bmg160_match_acpi_device(dev);
>
> - indio_dev->dev.parent = &client->dev;
> + indio_dev->dev.parent = dev;
> indio_dev->channels = bmg160_channels;
> indio_dev->num_channels = ARRAY_SIZE(bmg160_channels);
> indio_dev->name = name;
> indio_dev->modes = INDIO_DIRECT_MODE;
> indio_dev->info = &bmg160_info;
>
> - if (client->irq <= 0)
> - client->irq = bmg160_gpio_probe(client, data);
> + if (data->irq <= 0)
> + bmg160_gpio_probe(data);
>
> - if (client->irq > 0) {
> - ret = devm_request_threaded_irq(&client->dev,
> - client->irq,
> + if (data->irq > 0) {
> + ret = devm_request_threaded_irq(dev,
> + data->irq,
> bmg160_data_rdy_trig_poll,
> bmg160_event_handler,
> IRQF_TRIGGER_RISING,
> @@ -1056,28 +1055,28 @@ static int bmg160_probe(struct i2c_client *client,
> if (ret)
> return ret;
>
> - data->dready_trig = devm_iio_trigger_alloc(&client->dev,
> + data->dready_trig = devm_iio_trigger_alloc(dev,
> "%s-dev%d",
> indio_dev->name,
> indio_dev->id);
> if (!data->dready_trig)
> return -ENOMEM;
>
> - data->motion_trig = devm_iio_trigger_alloc(&client->dev,
> + data->motion_trig = devm_iio_trigger_alloc(dev,
> "%s-any-motion-dev%d",
> indio_dev->name,
> indio_dev->id);
> if (!data->motion_trig)
> return -ENOMEM;
>
> - data->dready_trig->dev.parent = &client->dev;
> + data->dready_trig->dev.parent = dev;
> data->dready_trig->ops = &bmg160_trigger_ops;
> iio_trigger_set_drvdata(data->dready_trig, indio_dev);
> ret = iio_trigger_register(data->dready_trig);
> if (ret)
> return ret;
>
> - data->motion_trig->dev.parent = &client->dev;
> + data->motion_trig->dev.parent = dev;
> data->motion_trig->ops = &bmg160_trigger_ops;
> iio_trigger_set_drvdata(data->motion_trig, indio_dev);
> ret = iio_trigger_register(data->motion_trig);
> @@ -1092,25 +1091,25 @@ static int bmg160_probe(struct i2c_client *client,
> bmg160_trigger_handler,
> &bmg160_buffer_setup_ops);
> if (ret < 0) {
> - dev_err(&client->dev,
> + dev_err(dev,
> "iio triggered buffer setup failed\n");
> goto err_trigger_unregister;
> }
>
> ret = iio_device_register(indio_dev);
> if (ret < 0) {
> - dev_err(&client->dev, "unable to register iio device\n");
> + dev_err(dev, "unable to register iio device\n");
> goto err_buffer_cleanup;
> }
>
> - ret = pm_runtime_set_active(&client->dev);
> + ret = pm_runtime_set_active(dev);
> if (ret)
> goto err_iio_unregister;
>
> - pm_runtime_enable(&client->dev);
> - pm_runtime_set_autosuspend_delay(&client->dev,
> + pm_runtime_enable(dev);
> + pm_runtime_set_autosuspend_delay(dev,
> BMG160_AUTO_SUSPEND_DELAY_MS);
> - pm_runtime_use_autosuspend(&client->dev);
> + pm_runtime_use_autosuspend(dev);
>
> return 0;
>

2015-08-12 16:22:46

by srinivas pandruvada

[permalink] [raw]
Subject: Re: [PATCH v3 5/6] iio: bmg160: Separate i2c and core driver

On Wed, 2015-08-12 at 16:50 +0200, Markus Pargmann wrote:
> This patch separates the core driver using regmap and the i2c driver
> which creates the i2c regmap. Also in the Kconfig file BMG160 and
> BMG160_I2C are separate now.
>
> Signed-off-by: Markus Pargmann <[email protected]>
Reviewed-by: Srinivas Pandruvada <[email protected]>
> ---
> drivers/iio/gyro/Kconfig | 18 +++++--
> drivers/iio/gyro/Makefile | 2 +-
> drivers/iio/gyro/bmg160.h | 10 ++++
> drivers/iio/gyro/{bmg160.c => bmg160_core.c} | 77 +++++-----------------------
> drivers/iio/gyro/bmg160_i2c.c | 71 +++++++++++++++++++++++++
> 5 files changed, 109 insertions(+), 69 deletions(-)
> create mode 100644 drivers/iio/gyro/bmg160.h
> rename drivers/iio/gyro/{bmg160.c => bmg160_core.c} (94%)
> create mode 100644 drivers/iio/gyro/bmg160_i2c.c
>
> diff --git a/drivers/iio/gyro/Kconfig b/drivers/iio/gyro/Kconfig
> index cf82d74139a2..13f8e0051615 100644
> --- a/drivers/iio/gyro/Kconfig
> +++ b/drivers/iio/gyro/Kconfig
> @@ -51,17 +51,27 @@ config ADXRS450
> will be called adxrs450.
>
> config BMG160
> - tristate "BOSCH BMG160 Gyro Sensor"
> - depends on I2C
> + bool "BOSCH BMG160 Gyro Sensor"
> select IIO_BUFFER
> select IIO_TRIGGERED_BUFFER
> - select REGMAP_I2C
> help
> Say yes here to build support for Bosch BMG160 Tri-axis Gyro Sensor
> driver. This driver also supports BMI055 gyroscope.
>
> +if BMG160
> +
> +config BMG160_I2C
> + tristate "Driver for connection via I2C"
> + depends on I2C
> + select REGMAP_I2C
> + help
> + Say yes here to build support for Bosch BMG160 Tri-axis Gyro Sensor
> + driver connected via I2C. This driver also supports BMI055 gyroscope.
> +
> This driver can also be built as a module. If so, the module
> - will be called bmg160.
> + will be called bmg160_i2c.
> +
> +endif
>
> config HID_SENSOR_GYRO_3D
> depends on HID_SENSOR_HUB
> diff --git a/drivers/iio/gyro/Makefile b/drivers/iio/gyro/Makefile
> index f46341b39139..73b41e43a974 100644
> --- a/drivers/iio/gyro/Makefile
> +++ b/drivers/iio/gyro/Makefile
> @@ -8,7 +8,7 @@ obj-$(CONFIG_ADIS16130) += adis16130.o
> obj-$(CONFIG_ADIS16136) += adis16136.o
> obj-$(CONFIG_ADIS16260) += adis16260.o
> obj-$(CONFIG_ADXRS450) += adxrs450.o
> -obj-$(CONFIG_BMG160) += bmg160.o
> +obj-$(CONFIG_BMG160_I2C) += bmg160_core.o bmg160_i2c.o
>
> obj-$(CONFIG_HID_SENSOR_GYRO_3D) += hid-sensor-gyro-3d.o
>
> diff --git a/drivers/iio/gyro/bmg160.h b/drivers/iio/gyro/bmg160.h
> new file mode 100644
> index 000000000000..72db723c8fb6
> --- /dev/null
> +++ b/drivers/iio/gyro/bmg160.h
> @@ -0,0 +1,10 @@
> +#ifndef BMG160_H_
> +#define BMG160_H_
> +
> +extern const struct dev_pm_ops bmg160_pm_ops;
> +
> +int bmg160_core_probe(struct device *dev, struct regmap *regmap, int irq,
> + const char *name);
> +void bmg160_core_remove(struct device *dev);
> +
> +#endif /* BMG160_H_ */
> diff --git a/drivers/iio/gyro/bmg160.c b/drivers/iio/gyro/bmg160_core.c
> similarity index 94%
> rename from drivers/iio/gyro/bmg160.c
> rename to drivers/iio/gyro/bmg160_core.c
> index 39df64fb4262..d64e3a87e0a1 100644
> --- a/drivers/iio/gyro/bmg160.c
> +++ b/drivers/iio/gyro/bmg160_core.c
> @@ -13,7 +13,6 @@
> */
>
> #include <linux/module.h>
> -#include <linux/i2c.h>
> #include <linux/interrupt.h>
> #include <linux/delay.h>
> #include <linux/slab.h>
> @@ -30,7 +29,6 @@
> #include <linux/iio/triggered_buffer.h>
> #include <linux/regmap.h>
>
> -#define BMG160_DRV_NAME "bmg160"
> #define BMG160_IRQ_NAME "bmg160_event"
> #define BMG160_GPIO_NAME "gpio_int"
>
> @@ -137,12 +135,6 @@ static const struct {
> { 133, BMG160_RANGE_250DPS},
> { 66, BMG160_RANGE_125DPS} };
>
> -struct regmap_config bmg160_regmap_i2c_conf = {
> - .reg_bits = 8,
> - .val_bits = 8,
> - .max_register = 0x3f
> -};
> -
> static int bmg160_set_mode(struct bmg160_data *data, u8 mode)
> {
> int ret;
> @@ -996,31 +988,22 @@ static const char *bmg160_match_acpi_device(struct device *dev)
> return dev_name(dev);
> }
>
> -static int bmg160_probe(struct i2c_client *client,
> - const struct i2c_device_id *id)
> +int bmg160_core_probe(struct device *dev, struct regmap *regmap, int irq,
> + const char *name)
> {
> struct bmg160_data *data;
> struct iio_dev *indio_dev;
> int ret;
> - const char *name = NULL;
> - struct regmap *regmap;
> - struct device *dev = &client->dev;
> -
> - regmap = devm_regmap_init_i2c(client, &bmg160_regmap_i2c_conf);
> - if (IS_ERR(regmap)) {
> - dev_err(&client->dev, "Failed to register i2c regmap %d\n",
> - (int)PTR_ERR(regmap));
> - return PTR_ERR(regmap);
> - }
>
> - indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
> + indio_dev = devm_iio_device_alloc(dev, sizeof(*data));
> if (!indio_dev)
> return -ENOMEM;
>
> data = iio_priv(indio_dev);
> dev_set_drvdata(dev, indio_dev);
> data->dev = dev;
> - data->irq = client->irq;
> + data->irq = irq;
> + data->regmap = regmap;
>
> ret = bmg160_chip_init(data);
> if (ret < 0)
> @@ -1028,9 +1011,6 @@ static int bmg160_probe(struct i2c_client *client,
>
> mutex_init(&data->mutex);
>
> - if (id)
> - name = id->name;
> -
> if (ACPI_HANDLE(dev))
> name = bmg160_match_acpi_device(dev);
>
> @@ -1125,15 +1105,16 @@ err_trigger_unregister:
>
> return ret;
> }
> +EXPORT_SYMBOL_GPL(bmg160_core_probe);
>
> -static int bmg160_remove(struct i2c_client *client)
> +void bmg160_core_remove(struct device *dev)
> {
> - struct iio_dev *indio_dev = i2c_get_clientdata(client);
> + struct iio_dev *indio_dev = dev_get_drvdata(dev);
> struct bmg160_data *data = iio_priv(indio_dev);
>
> - pm_runtime_disable(&client->dev);
> - pm_runtime_set_suspended(&client->dev);
> - pm_runtime_put_noidle(&client->dev);
> + pm_runtime_disable(dev);
> + pm_runtime_set_suspended(dev);
> + pm_runtime_put_noidle(dev);
>
> iio_device_unregister(indio_dev);
> iio_triggered_buffer_cleanup(indio_dev);
> @@ -1146,9 +1127,8 @@ static int bmg160_remove(struct i2c_client *client)
> mutex_lock(&data->mutex);
> bmg160_set_mode(data, BMG160_MODE_DEEP_SUSPEND);
> mutex_unlock(&data->mutex);
> -
> - return 0;
> }
> +EXPORT_SYMBOL_GPL(bmg160_core_remove);
>
> #ifdef CONFIG_PM_SLEEP
> static int bmg160_suspend(struct device *dev)
> @@ -1210,40 +1190,9 @@ static int bmg160_runtime_resume(struct device *dev)
> }
> #endif
>
> -static const struct dev_pm_ops bmg160_pm_ops = {
> +const struct dev_pm_ops bmg160_pm_ops = {
> SET_SYSTEM_SLEEP_PM_OPS(bmg160_suspend, bmg160_resume)
> SET_RUNTIME_PM_OPS(bmg160_runtime_suspend,
> bmg160_runtime_resume, NULL)
> };
>
> -static const struct acpi_device_id bmg160_acpi_match[] = {
> - {"BMG0160", 0},
> - {"BMI055B", 0},
> - {},
> -};
> -
> -MODULE_DEVICE_TABLE(acpi, bmg160_acpi_match);
> -
> -static const struct i2c_device_id bmg160_id[] = {
> - {"bmg160", 0},
> - {"bmi055_gyro", 0},
> - {}
> -};
> -
> -MODULE_DEVICE_TABLE(i2c, bmg160_id);
> -
> -static struct i2c_driver bmg160_driver = {
> - .driver = {
> - .name = BMG160_DRV_NAME,
> - .acpi_match_table = ACPI_PTR(bmg160_acpi_match),
> - .pm = &bmg160_pm_ops,
> - },
> - .probe = bmg160_probe,
> - .remove = bmg160_remove,
> - .id_table = bmg160_id,
> -};
> -module_i2c_driver(bmg160_driver);
> -
> -MODULE_AUTHOR("Srinivas Pandruvada <[email protected]>");
> -MODULE_LICENSE("GPL v2");
> -MODULE_DESCRIPTION("BMG160 Gyro driver");
> diff --git a/drivers/iio/gyro/bmg160_i2c.c b/drivers/iio/gyro/bmg160_i2c.c
> new file mode 100644
> index 000000000000..90126a5a7663
> --- /dev/null
> +++ b/drivers/iio/gyro/bmg160_i2c.c
> @@ -0,0 +1,71 @@
> +#include <linux/i2c.h>
> +#include <linux/regmap.h>
> +#include <linux/iio/iio.h>
> +#include <linux/module.h>
> +#include <linux/acpi.h>
> +
> +#include "bmg160.h"
> +
> +static const struct regmap_config bmg160_regmap_i2c_conf = {
> + .reg_bits = 8,
> + .val_bits = 8,
> + .max_register = 0x3f
> +};
> +
> +static int bmg160_i2c_probe(struct i2c_client *client,
> + const struct i2c_device_id *id)
> +{
> + struct regmap *regmap;
> + const char *name = NULL;
> +
> + regmap = devm_regmap_init_i2c(client, &bmg160_regmap_i2c_conf);
> + if (IS_ERR(regmap)) {
> + dev_err(&client->dev, "Failed to register i2c regmap %d\n",
> + (int)PTR_ERR(regmap));
> + return PTR_ERR(regmap);
> + }
> +
> + if (id)
> + name = id->name;
> +
> + return bmg160_core_probe(&client->dev, regmap, client->irq, name);
> +}
> +
> +static int bmg160_i2c_remove(struct i2c_client *client)
> +{
> + bmg160_core_remove(&client->dev);
> +
> + return 0;
> +}
> +
> +static const struct acpi_device_id bmg160_acpi_match[] = {
> + {"BMG0160", 0},
> + {"BMI055B", 0},
> + {},
> +};
> +
> +MODULE_DEVICE_TABLE(acpi, bmg160_acpi_match);
> +
> +static const struct i2c_device_id bmg160_i2c_id[] = {
> + {"bmg160", 0},
> + {"bmi055_gyro", 0},
> + {}
> +};
> +
> +MODULE_DEVICE_TABLE(i2c, bmg160_i2c_id);
> +
> +static struct i2c_driver bmg160_i2c_driver = {
> + .driver = {
> + .name = "bmg160_i2c",
> + .acpi_match_table = ACPI_PTR(bmg160_acpi_match),
> + .pm = &bmg160_pm_ops,
> + },
> + .probe = bmg160_i2c_probe,
> + .remove = bmg160_i2c_remove,
> + .id_table = bmg160_i2c_id,
> +};
> +module_i2c_driver(bmg160_i2c_driver);
> +
> +MODULE_AUTHOR("Srinivas Pandruvada <[email protected]>");
> +MODULE_LICENSE("GPL v2");
> +MODULE_DESCRIPTION("BMG160 I2C Gyro driver");

2015-08-15 14:41:29

by Jonathan Cameron

[permalink] [raw]
Subject: Re: [PATCH v3 1/6] iio: bmg160: Use i2c regmap instead of direct i2c access

On 12/08/15 17:01, Srinivas Pandruvada wrote:
> On Wed, 2015-08-12 at 16:50 +0200, Markus Pargmann wrote:
>> This patch introduces regmap usage into the driver. This is done to
>> later easily support the SPI interface of this chip.
>>
>> Signed-off-by: Markus Pargmann <[email protected]>
> Reviewed-by: Srinivas Pandruvada <[email protected]>
Applied to the togreg branch of iio.git. Initially pushed out as testing.
Unfortunately these have probably just missed the merge window for this
cycle. I'll get them to Greg and hence into linux-next in about 3-4 weeks
time.

Jonathan
>> ---
>> drivers/iio/gyro/Kconfig | 1 +
>> drivers/iio/gyro/bmg160.c | 198 ++++++++++++++++++++--------------------------
>> 2 files changed, 88 insertions(+), 111 deletions(-)
>>
>> diff --git a/drivers/iio/gyro/Kconfig b/drivers/iio/gyro/Kconfig
>> index 8d2439345673..cf82d74139a2 100644
>> --- a/drivers/iio/gyro/Kconfig
>> +++ b/drivers/iio/gyro/Kconfig
>> @@ -55,6 +55,7 @@ config BMG160
>> depends on I2C
>> select IIO_BUFFER
>> select IIO_TRIGGERED_BUFFER
>> + select REGMAP_I2C
>> help
>> Say yes here to build support for Bosch BMG160 Tri-axis Gyro Sensor
>> driver. This driver also supports BMI055 gyroscope.
>> diff --git a/drivers/iio/gyro/bmg160.c b/drivers/iio/gyro/bmg160.c
>> index 460bf715d541..bbe02053e98a 100644
>> --- a/drivers/iio/gyro/bmg160.c
>> +++ b/drivers/iio/gyro/bmg160.c
>> @@ -28,6 +28,7 @@
>> #include <linux/iio/events.h>
>> #include <linux/iio/trigger_consumer.h>
>> #include <linux/iio/triggered_buffer.h>
>> +#include <linux/regmap.h>
>>
>> #define BMG160_DRV_NAME "bmg160"
>> #define BMG160_IRQ_NAME "bmg160_event"
>> @@ -98,6 +99,7 @@
>>
>> struct bmg160_data {
>> struct i2c_client *client;
>> + struct regmap *regmap;
>> struct iio_trigger *dready_trig;
>> struct iio_trigger *motion_trig;
>> struct mutex mutex;
>> @@ -134,12 +136,17 @@ static const struct {
>> { 133, BMG160_RANGE_250DPS},
>> { 66, BMG160_RANGE_125DPS} };
>>
>> +struct regmap_config bmg160_regmap_i2c_conf = {
>> + .reg_bits = 8,
>> + .val_bits = 8,
>> + .max_register = 0x3f
>> +};
>> +
>> static int bmg160_set_mode(struct bmg160_data *data, u8 mode)
>> {
>> int ret;
>>
>> - ret = i2c_smbus_write_byte_data(data->client,
>> - BMG160_REG_PMU_LPW, mode);
>> + ret = regmap_write(data->regmap, BMG160_REG_PMU_LPW, mode);
>> if (ret < 0) {
>> dev_err(&data->client->dev, "Error writing reg_pmu_lpw\n");
>> return ret;
>> @@ -169,8 +176,7 @@ static int bmg160_set_bw(struct bmg160_data *data, int val)
>> if (bw_bits < 0)
>> return bw_bits;
>>
>> - ret = i2c_smbus_write_byte_data(data->client, BMG160_REG_PMU_BW,
>> - bw_bits);
>> + ret = regmap_write(data->regmap, BMG160_REG_PMU_BW, bw_bits);
>> if (ret < 0) {
>> dev_err(&data->client->dev, "Error writing reg_pmu_bw\n");
>> return ret;
>> @@ -184,16 +190,17 @@ static int bmg160_set_bw(struct bmg160_data *data, int val)
>> static int bmg160_chip_init(struct bmg160_data *data)
>> {
>> int ret;
>> + unsigned int val;
>>
>> - ret = i2c_smbus_read_byte_data(data->client, BMG160_REG_CHIP_ID);
>> + ret = regmap_read(data->regmap, BMG160_REG_CHIP_ID, &val);
>> if (ret < 0) {
>> dev_err(&data->client->dev, "Error reading reg_chip_id\n");
>> return ret;
>> }
>>
>> - dev_dbg(&data->client->dev, "Chip Id %x\n", ret);
>> - if (ret != BMG160_CHIP_ID_VAL) {
>> - dev_err(&data->client->dev, "invalid chip %x\n", ret);
>> + dev_dbg(&data->client->dev, "Chip Id %x\n", val);
>> + if (val != BMG160_CHIP_ID_VAL) {
>> + dev_err(&data->client->dev, "invalid chip %x\n", val);
>> return -ENODEV;
>> }
>>
>> @@ -210,40 +217,31 @@ static int bmg160_chip_init(struct bmg160_data *data)
>> return ret;
>>
>> /* Set Default Range */
>> - ret = i2c_smbus_write_byte_data(data->client,
>> - BMG160_REG_RANGE,
>> - BMG160_RANGE_500DPS);
>> + ret = regmap_write(data->regmap, BMG160_REG_RANGE, BMG160_RANGE_500DPS);
>> if (ret < 0) {
>> dev_err(&data->client->dev, "Error writing reg_range\n");
>> return ret;
>> }
>> data->dps_range = BMG160_RANGE_500DPS;
>>
>> - ret = i2c_smbus_read_byte_data(data->client, BMG160_REG_SLOPE_THRES);
>> + ret = regmap_read(data->regmap, BMG160_REG_SLOPE_THRES, &val);
>> if (ret < 0) {
>> dev_err(&data->client->dev, "Error reading reg_slope_thres\n");
>> return ret;
>> }
>> - data->slope_thres = ret;
>> + data->slope_thres = val;
>>
>> /* Set default interrupt mode */
>> - ret = i2c_smbus_read_byte_data(data->client, BMG160_REG_INT_EN_1);
>> - if (ret < 0) {
>> - dev_err(&data->client->dev, "Error reading reg_int_en_1\n");
>> - return ret;
>> - }
>> - ret &= ~BMG160_INT1_BIT_OD;
>> - ret = i2c_smbus_write_byte_data(data->client,
>> - BMG160_REG_INT_EN_1, ret);
>> + ret = regmap_update_bits(data->regmap, BMG160_REG_INT_EN_1,
>> + BMG160_INT1_BIT_OD, 0);
>> if (ret < 0) {
>> - dev_err(&data->client->dev, "Error writing reg_int_en_1\n");
>> + dev_err(&data->client->dev, "Error updating bits in reg_int_en_1\n");
>> return ret;
>> }
>>
>> - ret = i2c_smbus_write_byte_data(data->client,
>> - BMG160_REG_INT_RST_LATCH,
>> - BMG160_INT_MODE_LATCH_INT |
>> - BMG160_INT_MODE_LATCH_RESET);
>> + ret = regmap_write(data->regmap, BMG160_REG_INT_RST_LATCH,
>> + BMG160_INT_MODE_LATCH_INT |
>> + BMG160_INT_MODE_LATCH_RESET);
>> if (ret < 0) {
>> dev_err(&data->client->dev,
>> "Error writing reg_motion_intr\n");
>> @@ -284,41 +282,28 @@ static int bmg160_setup_any_motion_interrupt(struct bmg160_data *data,
>> int ret;
>>
>> /* Enable/Disable INT_MAP0 mapping */
>> - ret = i2c_smbus_read_byte_data(data->client, BMG160_REG_INT_MAP_0);
>> - if (ret < 0) {
>> - dev_err(&data->client->dev, "Error reading reg_int_map0\n");
>> - return ret;
>> - }
>> - if (status)
>> - ret |= BMG160_INT_MAP_0_BIT_ANY;
>> - else
>> - ret &= ~BMG160_INT_MAP_0_BIT_ANY;
>> -
>> - ret = i2c_smbus_write_byte_data(data->client,
>> - BMG160_REG_INT_MAP_0,
>> - ret);
>> + ret = regmap_update_bits(data->regmap, BMG160_REG_INT_MAP_0,
>> + BMG160_INT_MAP_0_BIT_ANY,
>> + (status ? BMG160_INT_MAP_0_BIT_ANY : 0));
>> if (ret < 0) {
>> - dev_err(&data->client->dev, "Error writing reg_int_map0\n");
>> + dev_err(&data->client->dev, "Error updating bits reg_int_map0\n");
>> return ret;
>> }
>>
>> /* Enable/Disable slope interrupts */
>> if (status) {
>> /* Update slope thres */
>> - ret = i2c_smbus_write_byte_data(data->client,
>> - BMG160_REG_SLOPE_THRES,
>> - data->slope_thres);
>> + ret = regmap_write(data->regmap, BMG160_REG_SLOPE_THRES,
>> + data->slope_thres);
>> if (ret < 0) {
>> dev_err(&data->client->dev,
>> "Error writing reg_slope_thres\n");
>> return ret;
>> }
>>
>> - ret = i2c_smbus_write_byte_data(data->client,
>> - BMG160_REG_MOTION_INTR,
>> - BMG160_INT_MOTION_X |
>> - BMG160_INT_MOTION_Y |
>> - BMG160_INT_MOTION_Z);
>> + ret = regmap_write(data->regmap, BMG160_REG_MOTION_INTR,
>> + BMG160_INT_MOTION_X | BMG160_INT_MOTION_Y |
>> + BMG160_INT_MOTION_Z);
>> if (ret < 0) {
>> dev_err(&data->client->dev,
>> "Error writing reg_motion_intr\n");
>> @@ -331,10 +316,10 @@ static int bmg160_setup_any_motion_interrupt(struct bmg160_data *data,
>> * to set latched mode, we will be flooded anyway with INTR
>> */
>> if (!data->dready_trigger_on) {
>> - ret = i2c_smbus_write_byte_data(data->client,
>> - BMG160_REG_INT_RST_LATCH,
>> - BMG160_INT_MODE_LATCH_INT |
>> - BMG160_INT_MODE_LATCH_RESET);
>> + ret = regmap_write(data->regmap,
>> + BMG160_REG_INT_RST_LATCH,
>> + BMG160_INT_MODE_LATCH_INT |
>> + BMG160_INT_MODE_LATCH_RESET);
>> if (ret < 0) {
>> dev_err(&data->client->dev,
>> "Error writing reg_rst_latch\n");
>> @@ -342,14 +327,12 @@ static int bmg160_setup_any_motion_interrupt(struct bmg160_data *data,
>> }
>> }
>>
>> - ret = i2c_smbus_write_byte_data(data->client,
>> - BMG160_REG_INT_EN_0,
>> - BMG160_DATA_ENABLE_INT);
>> + ret = regmap_write(data->regmap, BMG160_REG_INT_EN_0,
>> + BMG160_DATA_ENABLE_INT);
>>
>> - } else
>> - ret = i2c_smbus_write_byte_data(data->client,
>> - BMG160_REG_INT_EN_0,
>> - 0);
>> + } else {
>> + ret = regmap_write(data->regmap, BMG160_REG_INT_EN_0, 0);
>> + }
>>
>> if (ret < 0) {
>> dev_err(&data->client->dev, "Error writing reg_int_en0\n");
>> @@ -365,55 +348,39 @@ static int bmg160_setup_new_data_interrupt(struct bmg160_data *data,
>> int ret;
>>
>> /* Enable/Disable INT_MAP1 mapping */
>> - ret = i2c_smbus_read_byte_data(data->client, BMG160_REG_INT_MAP_1);
>> - if (ret < 0) {
>> - dev_err(&data->client->dev, "Error reading reg_int_map1\n");
>> - return ret;
>> - }
>> -
>> - if (status)
>> - ret |= BMG160_INT_MAP_1_BIT_NEW_DATA;
>> - else
>> - ret &= ~BMG160_INT_MAP_1_BIT_NEW_DATA;
>> -
>> - ret = i2c_smbus_write_byte_data(data->client,
>> - BMG160_REG_INT_MAP_1,
>> - ret);
>> + ret = regmap_update_bits(data->regmap, BMG160_REG_INT_MAP_1,
>> + BMG160_INT_MAP_1_BIT_NEW_DATA,
>> + (status ? BMG160_INT_MAP_1_BIT_NEW_DATA : 0));
>> if (ret < 0) {
>> - dev_err(&data->client->dev, "Error writing reg_int_map1\n");
>> + dev_err(&data->client->dev, "Error updating bits in reg_int_map1\n");
>> return ret;
>> }
>>
>> if (status) {
>> - ret = i2c_smbus_write_byte_data(data->client,
>> - BMG160_REG_INT_RST_LATCH,
>> - BMG160_INT_MODE_NON_LATCH_INT |
>> - BMG160_INT_MODE_LATCH_RESET);
>> + ret = regmap_write(data->regmap, BMG160_REG_INT_RST_LATCH,
>> + BMG160_INT_MODE_NON_LATCH_INT |
>> + BMG160_INT_MODE_LATCH_RESET);
>> if (ret < 0) {
>> dev_err(&data->client->dev,
>> "Error writing reg_rst_latch\n");
>> return ret;
>> }
>>
>> - ret = i2c_smbus_write_byte_data(data->client,
>> - BMG160_REG_INT_EN_0,
>> - BMG160_DATA_ENABLE_INT);
>> + ret = regmap_write(data->regmap, BMG160_REG_INT_EN_0,
>> + BMG160_DATA_ENABLE_INT);
>>
>> } else {
>> /* Restore interrupt mode */
>> - ret = i2c_smbus_write_byte_data(data->client,
>> - BMG160_REG_INT_RST_LATCH,
>> - BMG160_INT_MODE_LATCH_INT |
>> - BMG160_INT_MODE_LATCH_RESET);
>> + ret = regmap_write(data->regmap, BMG160_REG_INT_RST_LATCH,
>> + BMG160_INT_MODE_LATCH_INT |
>> + BMG160_INT_MODE_LATCH_RESET);
>> if (ret < 0) {
>> dev_err(&data->client->dev,
>> "Error writing reg_rst_latch\n");
>> return ret;
>> }
>>
>> - ret = i2c_smbus_write_byte_data(data->client,
>> - BMG160_REG_INT_EN_0,
>> - 0);
>> + ret = regmap_write(data->regmap, BMG160_REG_INT_EN_0, 0);
>> }
>>
>> if (ret < 0) {
>> @@ -444,10 +411,8 @@ static int bmg160_set_scale(struct bmg160_data *data, int val)
>>
>> for (i = 0; i < ARRAY_SIZE(bmg160_scale_table); ++i) {
>> if (bmg160_scale_table[i].scale == val) {
>> - ret = i2c_smbus_write_byte_data(
>> - data->client,
>> - BMG160_REG_RANGE,
>> - bmg160_scale_table[i].dps_range);
>> + ret = regmap_write(data->regmap, BMG160_REG_RANGE,
>> + bmg160_scale_table[i].dps_range);
>> if (ret < 0) {
>> dev_err(&data->client->dev,
>> "Error writing reg_range\n");
>> @@ -464,6 +429,7 @@ static int bmg160_set_scale(struct bmg160_data *data, int val)
>> static int bmg160_get_temp(struct bmg160_data *data, int *val)
>> {
>> int ret;
>> + unsigned int raw_val;
>>
>> mutex_lock(&data->mutex);
>> ret = bmg160_set_power_state(data, true);
>> @@ -472,7 +438,7 @@ static int bmg160_get_temp(struct bmg160_data *data, int *val)
>> return ret;
>> }
>>
>> - ret = i2c_smbus_read_byte_data(data->client, BMG160_REG_TEMP);
>> + ret = regmap_read(data->regmap, BMG160_REG_TEMP, &raw_val);
>> if (ret < 0) {
>> dev_err(&data->client->dev, "Error reading reg_temp\n");
>> bmg160_set_power_state(data, false);
>> @@ -480,7 +446,7 @@ static int bmg160_get_temp(struct bmg160_data *data, int *val)
>> return ret;
>> }
>>
>> - *val = sign_extend32(ret, 7);
>> + *val = sign_extend32(raw_val, 7);
>> ret = bmg160_set_power_state(data, false);
>> mutex_unlock(&data->mutex);
>> if (ret < 0)
>> @@ -492,6 +458,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)
>> {
>> int ret;
>> + unsigned int raw_val;
>>
>> mutex_lock(&data->mutex);
>> ret = bmg160_set_power_state(data, true);
>> @@ -500,7 +467,8 @@ static int bmg160_get_axis(struct bmg160_data *data, int axis, int *val)
>> return ret;
>> }
>>
>> - ret = i2c_smbus_read_word_data(data->client, BMG160_AXIS_TO_REG(axis));
>> + ret = regmap_bulk_read(data->regmap, BMG160_AXIS_TO_REG(axis), &raw_val,
>> + 2);
>> if (ret < 0) {
>> dev_err(&data->client->dev, "Error reading axis %d\n", axis);
>> bmg160_set_power_state(data, false);
>> @@ -508,7 +476,7 @@ static int bmg160_get_axis(struct bmg160_data *data, int axis, int *val)
>> return ret;
>> }
>>
>> - *val = sign_extend32(ret, 15);
>> + *val = sign_extend32(raw_val, 15);
>> ret = bmg160_set_power_state(data, false);
>> mutex_unlock(&data->mutex);
>> if (ret < 0)
>> @@ -807,12 +775,13 @@ static irqreturn_t bmg160_trigger_handler(int irq, void *p)
>> struct iio_dev *indio_dev = pf->indio_dev;
>> struct bmg160_data *data = iio_priv(indio_dev);
>> int bit, ret, i = 0;
>> + unsigned int val;
>>
>> mutex_lock(&data->mutex);
>> for_each_set_bit(bit, indio_dev->active_scan_mask,
>> indio_dev->masklength) {
>> - ret = i2c_smbus_read_word_data(data->client,
>> - BMG160_AXIS_TO_REG(bit));
>> + ret = regmap_bulk_read(data->regmap, BMG160_AXIS_TO_REG(bit),
>> + &val, 2);
>> if (ret < 0) {
>> mutex_unlock(&data->mutex);
>> goto err;
>> @@ -840,10 +809,9 @@ static int bmg160_trig_try_reen(struct iio_trigger *trig)
>> return 0;
>>
>> /* Set latched mode interrupt and clear any latched interrupt */
>> - ret = i2c_smbus_write_byte_data(data->client,
>> - BMG160_REG_INT_RST_LATCH,
>> - BMG160_INT_MODE_LATCH_INT |
>> - BMG160_INT_MODE_LATCH_RESET);
>> + ret = regmap_write(data->regmap, BMG160_REG_INT_RST_LATCH,
>> + BMG160_INT_MODE_LATCH_INT |
>> + BMG160_INT_MODE_LATCH_RESET);
>> if (ret < 0) {
>> dev_err(&data->client->dev, "Error writing reg_rst_latch\n");
>> return ret;
>> @@ -907,33 +875,34 @@ static irqreturn_t bmg160_event_handler(int irq, void *private)
>> struct bmg160_data *data = iio_priv(indio_dev);
>> int ret;
>> int dir;
>> + unsigned int val;
>>
>> - ret = i2c_smbus_read_byte_data(data->client, BMG160_REG_INT_STATUS_2);
>> + ret = regmap_read(data->regmap, BMG160_REG_INT_STATUS_2, &val);
>> if (ret < 0) {
>> dev_err(&data->client->dev, "Error reading reg_int_status2\n");
>> goto ack_intr_status;
>> }
>>
>> - if (ret & 0x08)
>> + if (val & 0x08)
>> dir = IIO_EV_DIR_RISING;
>> else
>> dir = IIO_EV_DIR_FALLING;
>>
>> - if (ret & BMG160_ANY_MOTION_BIT_X)
>> + if (val & BMG160_ANY_MOTION_BIT_X)
>> iio_push_event(indio_dev, IIO_MOD_EVENT_CODE(IIO_ANGL_VEL,
>> 0,
>> IIO_MOD_X,
>> IIO_EV_TYPE_ROC,
>> dir),
>> iio_get_time_ns());
>> - if (ret & BMG160_ANY_MOTION_BIT_Y)
>> + if (val & BMG160_ANY_MOTION_BIT_Y)
>> iio_push_event(indio_dev, IIO_MOD_EVENT_CODE(IIO_ANGL_VEL,
>> 0,
>> IIO_MOD_Y,
>> IIO_EV_TYPE_ROC,
>> dir),
>> iio_get_time_ns());
>> - if (ret & BMG160_ANY_MOTION_BIT_Z)
>> + if (val & BMG160_ANY_MOTION_BIT_Z)
>> iio_push_event(indio_dev, IIO_MOD_EVENT_CODE(IIO_ANGL_VEL,
>> 0,
>> IIO_MOD_Z,
>> @@ -943,10 +912,9 @@ static irqreturn_t bmg160_event_handler(int irq, void *private)
>>
>> ack_intr_status:
>> if (!data->dready_trigger_on) {
>> - ret = i2c_smbus_write_byte_data(data->client,
>> - BMG160_REG_INT_RST_LATCH,
>> - BMG160_INT_MODE_LATCH_INT |
>> - BMG160_INT_MODE_LATCH_RESET);
>> + ret = regmap_write(data->regmap, BMG160_REG_INT_RST_LATCH,
>> + BMG160_INT_MODE_LATCH_INT |
>> + BMG160_INT_MODE_LATCH_RESET);
>> if (ret < 0)
>> dev_err(&data->client->dev,
>> "Error writing reg_rst_latch\n");
>> @@ -1038,6 +1006,14 @@ static int bmg160_probe(struct i2c_client *client,
>> struct iio_dev *indio_dev;
>> int ret;
>> const char *name = NULL;
>> + struct regmap *regmap;
>> +
>> + regmap = devm_regmap_init_i2c(client, &bmg160_regmap_i2c_conf);
>> + if (IS_ERR(regmap)) {
>> + dev_err(&client->dev, "Failed to register i2c regmap %d\n",
>> + (int)PTR_ERR(regmap));
>> + return PTR_ERR(regmap);
>> + }
>>
>> indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
>> if (!indio_dev)
>
>

2015-08-15 14:43:06

by Jonathan Cameron

[permalink] [raw]
Subject: Re: [PATCH v3 1/6] iio: bmg160: Use i2c regmap instead of direct i2c access

On 15/08/15 15:41, Jonathan Cameron wrote:
> On 12/08/15 17:01, Srinivas Pandruvada wrote:
>> On Wed, 2015-08-12 at 16:50 +0200, Markus Pargmann wrote:
>>> This patch introduces regmap usage into the driver. This is done to
>>> later easily support the SPI interface of this chip.
>>>
>>> Signed-off-by: Markus Pargmann <[email protected]>
>> Reviewed-by: Srinivas Pandruvada <[email protected]>
> Applied to the togreg branch of iio.git. Initially pushed out as testing.
> Unfortunately these have probably just missed the merge window for this
> cycle. I'll get them to Greg and hence into linux-next in about 3-4 weeks
> time.
>
> Jonathan
One slight quirk from build test. I've added a static below.
>>> ---
>>> drivers/iio/gyro/Kconfig | 1 +
>>> drivers/iio/gyro/bmg160.c | 198 ++++++++++++++++++++--------------------------
>>> 2 files changed, 88 insertions(+), 111 deletions(-)
>>>
>>> diff --git a/drivers/iio/gyro/Kconfig b/drivers/iio/gyro/Kconfig
>>> index 8d2439345673..cf82d74139a2 100644
>>> --- a/drivers/iio/gyro/Kconfig
>>> +++ b/drivers/iio/gyro/Kconfig
>>> @@ -55,6 +55,7 @@ config BMG160
>>> depends on I2C
>>> select IIO_BUFFER
>>> select IIO_TRIGGERED_BUFFER
>>> + select REGMAP_I2C
>>> help
>>> Say yes here to build support for Bosch BMG160 Tri-axis Gyro Sensor
>>> driver. This driver also supports BMI055 gyroscope.
>>> diff --git a/drivers/iio/gyro/bmg160.c b/drivers/iio/gyro/bmg160.c
>>> index 460bf715d541..bbe02053e98a 100644
>>> --- a/drivers/iio/gyro/bmg160.c
>>> +++ b/drivers/iio/gyro/bmg160.c
>>> @@ -28,6 +28,7 @@
>>> #include <linux/iio/events.h>
>>> #include <linux/iio/trigger_consumer.h>
>>> #include <linux/iio/triggered_buffer.h>
>>> +#include <linux/regmap.h>
>>>
>>> #define BMG160_DRV_NAME "bmg160"
>>> #define BMG160_IRQ_NAME "bmg160_event"
>>> @@ -98,6 +99,7 @@
>>>
>>> struct bmg160_data {
>>> struct i2c_client *client;
>>> + struct regmap *regmap;
>>> struct iio_trigger *dready_trig;
>>> struct iio_trigger *motion_trig;
>>> struct mutex mutex;
>>> @@ -134,12 +136,17 @@ static const struct {
>>> { 133, BMG160_RANGE_250DPS},
>>> { 66, BMG160_RANGE_125DPS} };
>>>
>>> +struct regmap_config bmg160_regmap_i2c_conf = {
Should be static.

>>> + .reg_bits = 8,
>>> + .val_bits = 8,
>>> + .max_register = 0x3f
>>> +};
>>> +
>>> static int bmg160_set_mode(struct bmg160_data *data, u8 mode)
>>> {
>>> int ret;
>>>
>>> - ret = i2c_smbus_write_byte_data(data->client,
>>> - BMG160_REG_PMU_LPW, mode);
>>> + ret = regmap_write(data->regmap, BMG160_REG_PMU_LPW, mode);
>>> if (ret < 0) {
>>> dev_err(&data->client->dev, "Error writing reg_pmu_lpw\n");
>>> return ret;
>>> @@ -169,8 +176,7 @@ static int bmg160_set_bw(struct bmg160_data *data, int val)
>>> if (bw_bits < 0)
>>> return bw_bits;
>>>
>>> - ret = i2c_smbus_write_byte_data(data->client, BMG160_REG_PMU_BW,
>>> - bw_bits);
>>> + ret = regmap_write(data->regmap, BMG160_REG_PMU_BW, bw_bits);
>>> if (ret < 0) {
>>> dev_err(&data->client->dev, "Error writing reg_pmu_bw\n");
>>> return ret;
>>> @@ -184,16 +190,17 @@ static int bmg160_set_bw(struct bmg160_data *data, int val)
>>> static int bmg160_chip_init(struct bmg160_data *data)
>>> {
>>> int ret;
>>> + unsigned int val;
>>>
>>> - ret = i2c_smbus_read_byte_data(data->client, BMG160_REG_CHIP_ID);
>>> + ret = regmap_read(data->regmap, BMG160_REG_CHIP_ID, &val);
>>> if (ret < 0) {
>>> dev_err(&data->client->dev, "Error reading reg_chip_id\n");
>>> return ret;
>>> }
>>>
>>> - dev_dbg(&data->client->dev, "Chip Id %x\n", ret);
>>> - if (ret != BMG160_CHIP_ID_VAL) {
>>> - dev_err(&data->client->dev, "invalid chip %x\n", ret);
>>> + dev_dbg(&data->client->dev, "Chip Id %x\n", val);
>>> + if (val != BMG160_CHIP_ID_VAL) {
>>> + dev_err(&data->client->dev, "invalid chip %x\n", val);
>>> return -ENODEV;
>>> }
>>>
>>> @@ -210,40 +217,31 @@ static int bmg160_chip_init(struct bmg160_data *data)
>>> return ret;
>>>
>>> /* Set Default Range */
>>> - ret = i2c_smbus_write_byte_data(data->client,
>>> - BMG160_REG_RANGE,
>>> - BMG160_RANGE_500DPS);
>>> + ret = regmap_write(data->regmap, BMG160_REG_RANGE, BMG160_RANGE_500DPS);
>>> if (ret < 0) {
>>> dev_err(&data->client->dev, "Error writing reg_range\n");
>>> return ret;
>>> }
>>> data->dps_range = BMG160_RANGE_500DPS;
>>>
>>> - ret = i2c_smbus_read_byte_data(data->client, BMG160_REG_SLOPE_THRES);
>>> + ret = regmap_read(data->regmap, BMG160_REG_SLOPE_THRES, &val);
>>> if (ret < 0) {
>>> dev_err(&data->client->dev, "Error reading reg_slope_thres\n");
>>> return ret;
>>> }
>>> - data->slope_thres = ret;
>>> + data->slope_thres = val;
>>>
>>> /* Set default interrupt mode */
>>> - ret = i2c_smbus_read_byte_data(data->client, BMG160_REG_INT_EN_1);
>>> - if (ret < 0) {
>>> - dev_err(&data->client->dev, "Error reading reg_int_en_1\n");
>>> - return ret;
>>> - }
>>> - ret &= ~BMG160_INT1_BIT_OD;
>>> - ret = i2c_smbus_write_byte_data(data->client,
>>> - BMG160_REG_INT_EN_1, ret);
>>> + ret = regmap_update_bits(data->regmap, BMG160_REG_INT_EN_1,
>>> + BMG160_INT1_BIT_OD, 0);
>>> if (ret < 0) {
>>> - dev_err(&data->client->dev, "Error writing reg_int_en_1\n");
>>> + dev_err(&data->client->dev, "Error updating bits in reg_int_en_1\n");
>>> return ret;
>>> }
>>>
>>> - ret = i2c_smbus_write_byte_data(data->client,
>>> - BMG160_REG_INT_RST_LATCH,
>>> - BMG160_INT_MODE_LATCH_INT |
>>> - BMG160_INT_MODE_LATCH_RESET);
>>> + ret = regmap_write(data->regmap, BMG160_REG_INT_RST_LATCH,
>>> + BMG160_INT_MODE_LATCH_INT |
>>> + BMG160_INT_MODE_LATCH_RESET);
>>> if (ret < 0) {
>>> dev_err(&data->client->dev,
>>> "Error writing reg_motion_intr\n");
>>> @@ -284,41 +282,28 @@ static int bmg160_setup_any_motion_interrupt(struct bmg160_data *data,
>>> int ret;
>>>
>>> /* Enable/Disable INT_MAP0 mapping */
>>> - ret = i2c_smbus_read_byte_data(data->client, BMG160_REG_INT_MAP_0);
>>> - if (ret < 0) {
>>> - dev_err(&data->client->dev, "Error reading reg_int_map0\n");
>>> - return ret;
>>> - }
>>> - if (status)
>>> - ret |= BMG160_INT_MAP_0_BIT_ANY;
>>> - else
>>> - ret &= ~BMG160_INT_MAP_0_BIT_ANY;
>>> -
>>> - ret = i2c_smbus_write_byte_data(data->client,
>>> - BMG160_REG_INT_MAP_0,
>>> - ret);
>>> + ret = regmap_update_bits(data->regmap, BMG160_REG_INT_MAP_0,
>>> + BMG160_INT_MAP_0_BIT_ANY,
>>> + (status ? BMG160_INT_MAP_0_BIT_ANY : 0));
>>> if (ret < 0) {
>>> - dev_err(&data->client->dev, "Error writing reg_int_map0\n");
>>> + dev_err(&data->client->dev, "Error updating bits reg_int_map0\n");
>>> return ret;
>>> }
>>>
>>> /* Enable/Disable slope interrupts */
>>> if (status) {
>>> /* Update slope thres */
>>> - ret = i2c_smbus_write_byte_data(data->client,
>>> - BMG160_REG_SLOPE_THRES,
>>> - data->slope_thres);
>>> + ret = regmap_write(data->regmap, BMG160_REG_SLOPE_THRES,
>>> + data->slope_thres);
>>> if (ret < 0) {
>>> dev_err(&data->client->dev,
>>> "Error writing reg_slope_thres\n");
>>> return ret;
>>> }
>>>
>>> - ret = i2c_smbus_write_byte_data(data->client,
>>> - BMG160_REG_MOTION_INTR,
>>> - BMG160_INT_MOTION_X |
>>> - BMG160_INT_MOTION_Y |
>>> - BMG160_INT_MOTION_Z);
>>> + ret = regmap_write(data->regmap, BMG160_REG_MOTION_INTR,
>>> + BMG160_INT_MOTION_X | BMG160_INT_MOTION_Y |
>>> + BMG160_INT_MOTION_Z);
>>> if (ret < 0) {
>>> dev_err(&data->client->dev,
>>> "Error writing reg_motion_intr\n");
>>> @@ -331,10 +316,10 @@ static int bmg160_setup_any_motion_interrupt(struct bmg160_data *data,
>>> * to set latched mode, we will be flooded anyway with INTR
>>> */
>>> if (!data->dready_trigger_on) {
>>> - ret = i2c_smbus_write_byte_data(data->client,
>>> - BMG160_REG_INT_RST_LATCH,
>>> - BMG160_INT_MODE_LATCH_INT |
>>> - BMG160_INT_MODE_LATCH_RESET);
>>> + ret = regmap_write(data->regmap,
>>> + BMG160_REG_INT_RST_LATCH,
>>> + BMG160_INT_MODE_LATCH_INT |
>>> + BMG160_INT_MODE_LATCH_RESET);
>>> if (ret < 0) {
>>> dev_err(&data->client->dev,
>>> "Error writing reg_rst_latch\n");
>>> @@ -342,14 +327,12 @@ static int bmg160_setup_any_motion_interrupt(struct bmg160_data *data,
>>> }
>>> }
>>>
>>> - ret = i2c_smbus_write_byte_data(data->client,
>>> - BMG160_REG_INT_EN_0,
>>> - BMG160_DATA_ENABLE_INT);
>>> + ret = regmap_write(data->regmap, BMG160_REG_INT_EN_0,
>>> + BMG160_DATA_ENABLE_INT);
>>>
>>> - } else
>>> - ret = i2c_smbus_write_byte_data(data->client,
>>> - BMG160_REG_INT_EN_0,
>>> - 0);
>>> + } else {
>>> + ret = regmap_write(data->regmap, BMG160_REG_INT_EN_0, 0);
>>> + }
>>>
>>> if (ret < 0) {
>>> dev_err(&data->client->dev, "Error writing reg_int_en0\n");
>>> @@ -365,55 +348,39 @@ static int bmg160_setup_new_data_interrupt(struct bmg160_data *data,
>>> int ret;
>>>
>>> /* Enable/Disable INT_MAP1 mapping */
>>> - ret = i2c_smbus_read_byte_data(data->client, BMG160_REG_INT_MAP_1);
>>> - if (ret < 0) {
>>> - dev_err(&data->client->dev, "Error reading reg_int_map1\n");
>>> - return ret;
>>> - }
>>> -
>>> - if (status)
>>> - ret |= BMG160_INT_MAP_1_BIT_NEW_DATA;
>>> - else
>>> - ret &= ~BMG160_INT_MAP_1_BIT_NEW_DATA;
>>> -
>>> - ret = i2c_smbus_write_byte_data(data->client,
>>> - BMG160_REG_INT_MAP_1,
>>> - ret);
>>> + ret = regmap_update_bits(data->regmap, BMG160_REG_INT_MAP_1,
>>> + BMG160_INT_MAP_1_BIT_NEW_DATA,
>>> + (status ? BMG160_INT_MAP_1_BIT_NEW_DATA : 0));
>>> if (ret < 0) {
>>> - dev_err(&data->client->dev, "Error writing reg_int_map1\n");
>>> + dev_err(&data->client->dev, "Error updating bits in reg_int_map1\n");
>>> return ret;
>>> }
>>>
>>> if (status) {
>>> - ret = i2c_smbus_write_byte_data(data->client,
>>> - BMG160_REG_INT_RST_LATCH,
>>> - BMG160_INT_MODE_NON_LATCH_INT |
>>> - BMG160_INT_MODE_LATCH_RESET);
>>> + ret = regmap_write(data->regmap, BMG160_REG_INT_RST_LATCH,
>>> + BMG160_INT_MODE_NON_LATCH_INT |
>>> + BMG160_INT_MODE_LATCH_RESET);
>>> if (ret < 0) {
>>> dev_err(&data->client->dev,
>>> "Error writing reg_rst_latch\n");
>>> return ret;
>>> }
>>>
>>> - ret = i2c_smbus_write_byte_data(data->client,
>>> - BMG160_REG_INT_EN_0,
>>> - BMG160_DATA_ENABLE_INT);
>>> + ret = regmap_write(data->regmap, BMG160_REG_INT_EN_0,
>>> + BMG160_DATA_ENABLE_INT);
>>>
>>> } else {
>>> /* Restore interrupt mode */
>>> - ret = i2c_smbus_write_byte_data(data->client,
>>> - BMG160_REG_INT_RST_LATCH,
>>> - BMG160_INT_MODE_LATCH_INT |
>>> - BMG160_INT_MODE_LATCH_RESET);
>>> + ret = regmap_write(data->regmap, BMG160_REG_INT_RST_LATCH,
>>> + BMG160_INT_MODE_LATCH_INT |
>>> + BMG160_INT_MODE_LATCH_RESET);
>>> if (ret < 0) {
>>> dev_err(&data->client->dev,
>>> "Error writing reg_rst_latch\n");
>>> return ret;
>>> }
>>>
>>> - ret = i2c_smbus_write_byte_data(data->client,
>>> - BMG160_REG_INT_EN_0,
>>> - 0);
>>> + ret = regmap_write(data->regmap, BMG160_REG_INT_EN_0, 0);
>>> }
>>>
>>> if (ret < 0) {
>>> @@ -444,10 +411,8 @@ static int bmg160_set_scale(struct bmg160_data *data, int val)
>>>
>>> for (i = 0; i < ARRAY_SIZE(bmg160_scale_table); ++i) {
>>> if (bmg160_scale_table[i].scale == val) {
>>> - ret = i2c_smbus_write_byte_data(
>>> - data->client,
>>> - BMG160_REG_RANGE,
>>> - bmg160_scale_table[i].dps_range);
>>> + ret = regmap_write(data->regmap, BMG160_REG_RANGE,
>>> + bmg160_scale_table[i].dps_range);
>>> if (ret < 0) {
>>> dev_err(&data->client->dev,
>>> "Error writing reg_range\n");
>>> @@ -464,6 +429,7 @@ static int bmg160_set_scale(struct bmg160_data *data, int val)
>>> static int bmg160_get_temp(struct bmg160_data *data, int *val)
>>> {
>>> int ret;
>>> + unsigned int raw_val;
>>>
>>> mutex_lock(&data->mutex);
>>> ret = bmg160_set_power_state(data, true);
>>> @@ -472,7 +438,7 @@ static int bmg160_get_temp(struct bmg160_data *data, int *val)
>>> return ret;
>>> }
>>>
>>> - ret = i2c_smbus_read_byte_data(data->client, BMG160_REG_TEMP);
>>> + ret = regmap_read(data->regmap, BMG160_REG_TEMP, &raw_val);
>>> if (ret < 0) {
>>> dev_err(&data->client->dev, "Error reading reg_temp\n");
>>> bmg160_set_power_state(data, false);
>>> @@ -480,7 +446,7 @@ static int bmg160_get_temp(struct bmg160_data *data, int *val)
>>> return ret;
>>> }
>>>
>>> - *val = sign_extend32(ret, 7);
>>> + *val = sign_extend32(raw_val, 7);
>>> ret = bmg160_set_power_state(data, false);
>>> mutex_unlock(&data->mutex);
>>> if (ret < 0)
>>> @@ -492,6 +458,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)
>>> {
>>> int ret;
>>> + unsigned int raw_val;
>>>
>>> mutex_lock(&data->mutex);
>>> ret = bmg160_set_power_state(data, true);
>>> @@ -500,7 +467,8 @@ static int bmg160_get_axis(struct bmg160_data *data, int axis, int *val)
>>> return ret;
>>> }
>>>
>>> - ret = i2c_smbus_read_word_data(data->client, BMG160_AXIS_TO_REG(axis));
>>> + ret = regmap_bulk_read(data->regmap, BMG160_AXIS_TO_REG(axis), &raw_val,
>>> + 2);
>>> if (ret < 0) {
>>> dev_err(&data->client->dev, "Error reading axis %d\n", axis);
>>> bmg160_set_power_state(data, false);
>>> @@ -508,7 +476,7 @@ static int bmg160_get_axis(struct bmg160_data *data, int axis, int *val)
>>> return ret;
>>> }
>>>
>>> - *val = sign_extend32(ret, 15);
>>> + *val = sign_extend32(raw_val, 15);
>>> ret = bmg160_set_power_state(data, false);
>>> mutex_unlock(&data->mutex);
>>> if (ret < 0)
>>> @@ -807,12 +775,13 @@ static irqreturn_t bmg160_trigger_handler(int irq, void *p)
>>> struct iio_dev *indio_dev = pf->indio_dev;
>>> struct bmg160_data *data = iio_priv(indio_dev);
>>> int bit, ret, i = 0;
>>> + unsigned int val;
>>>
>>> mutex_lock(&data->mutex);
>>> for_each_set_bit(bit, indio_dev->active_scan_mask,
>>> indio_dev->masklength) {
>>> - ret = i2c_smbus_read_word_data(data->client,
>>> - BMG160_AXIS_TO_REG(bit));
>>> + ret = regmap_bulk_read(data->regmap, BMG160_AXIS_TO_REG(bit),
>>> + &val, 2);
>>> if (ret < 0) {
>>> mutex_unlock(&data->mutex);
>>> goto err;
>>> @@ -840,10 +809,9 @@ static int bmg160_trig_try_reen(struct iio_trigger *trig)
>>> return 0;
>>>
>>> /* Set latched mode interrupt and clear any latched interrupt */
>>> - ret = i2c_smbus_write_byte_data(data->client,
>>> - BMG160_REG_INT_RST_LATCH,
>>> - BMG160_INT_MODE_LATCH_INT |
>>> - BMG160_INT_MODE_LATCH_RESET);
>>> + ret = regmap_write(data->regmap, BMG160_REG_INT_RST_LATCH,
>>> + BMG160_INT_MODE_LATCH_INT |
>>> + BMG160_INT_MODE_LATCH_RESET);
>>> if (ret < 0) {
>>> dev_err(&data->client->dev, "Error writing reg_rst_latch\n");
>>> return ret;
>>> @@ -907,33 +875,34 @@ static irqreturn_t bmg160_event_handler(int irq, void *private)
>>> struct bmg160_data *data = iio_priv(indio_dev);
>>> int ret;
>>> int dir;
>>> + unsigned int val;
>>>
>>> - ret = i2c_smbus_read_byte_data(data->client, BMG160_REG_INT_STATUS_2);
>>> + ret = regmap_read(data->regmap, BMG160_REG_INT_STATUS_2, &val);
>>> if (ret < 0) {
>>> dev_err(&data->client->dev, "Error reading reg_int_status2\n");
>>> goto ack_intr_status;
>>> }
>>>
>>> - if (ret & 0x08)
>>> + if (val & 0x08)
>>> dir = IIO_EV_DIR_RISING;
>>> else
>>> dir = IIO_EV_DIR_FALLING;
>>>
>>> - if (ret & BMG160_ANY_MOTION_BIT_X)
>>> + if (val & BMG160_ANY_MOTION_BIT_X)
>>> iio_push_event(indio_dev, IIO_MOD_EVENT_CODE(IIO_ANGL_VEL,
>>> 0,
>>> IIO_MOD_X,
>>> IIO_EV_TYPE_ROC,
>>> dir),
>>> iio_get_time_ns());
>>> - if (ret & BMG160_ANY_MOTION_BIT_Y)
>>> + if (val & BMG160_ANY_MOTION_BIT_Y)
>>> iio_push_event(indio_dev, IIO_MOD_EVENT_CODE(IIO_ANGL_VEL,
>>> 0,
>>> IIO_MOD_Y,
>>> IIO_EV_TYPE_ROC,
>>> dir),
>>> iio_get_time_ns());
>>> - if (ret & BMG160_ANY_MOTION_BIT_Z)
>>> + if (val & BMG160_ANY_MOTION_BIT_Z)
>>> iio_push_event(indio_dev, IIO_MOD_EVENT_CODE(IIO_ANGL_VEL,
>>> 0,
>>> IIO_MOD_Z,
>>> @@ -943,10 +912,9 @@ static irqreturn_t bmg160_event_handler(int irq, void *private)
>>>
>>> ack_intr_status:
>>> if (!data->dready_trigger_on) {
>>> - ret = i2c_smbus_write_byte_data(data->client,
>>> - BMG160_REG_INT_RST_LATCH,
>>> - BMG160_INT_MODE_LATCH_INT |
>>> - BMG160_INT_MODE_LATCH_RESET);
>>> + ret = regmap_write(data->regmap, BMG160_REG_INT_RST_LATCH,
>>> + BMG160_INT_MODE_LATCH_INT |
>>> + BMG160_INT_MODE_LATCH_RESET);
>>> if (ret < 0)
>>> dev_err(&data->client->dev,
>>> "Error writing reg_rst_latch\n");
>>> @@ -1038,6 +1006,14 @@ static int bmg160_probe(struct i2c_client *client,
>>> struct iio_dev *indio_dev;
>>> int ret;
>>> const char *name = NULL;
>>> + struct regmap *regmap;
>>> +
>>> + regmap = devm_regmap_init_i2c(client, &bmg160_regmap_i2c_conf);
>>> + if (IS_ERR(regmap)) {
>>> + dev_err(&client->dev, "Failed to register i2c regmap %d\n",
>>> + (int)PTR_ERR(regmap));
>>> + return PTR_ERR(regmap);
>>> + }
>>>
>>> indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
>>> if (!indio_dev)
>>
>>
>
> --
> 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
>

2015-08-15 14:49:20

by Jonathan Cameron

[permalink] [raw]
Subject: Re: [PATCH v3 0/6] iio: bmg160: Add SPI connection

On 12/08/15 16:04, Lars-Peter Clausen wrote:
> Hi,
>
> Markus and Irina can you try to synchronize your efforts. This series will
> conflict with http://marc.info/?l=linux-iio&m=143938994602171&w=2
>
> I think it would be best if the multi-read emulation support is added to
> regmap (which I think Markus' earlier series did).
Good spot Lars, I'd managed to miss this clash entirely (and had both sets
marked for applying - though I'd marked them for such on totally different
days!)

Anyhow, I'm going to take this series for now and we'll have to deal with
the emulation stuff on top of it.

Jonathan
>
> - Lars
>
> On 08/12/2015 04:50 PM, Markus Pargmann wrote:
>> Hi,
>>
>> bmg160 and bmi055 can be used via I2C and SPI. This series converts the driver
>> to regmap and splits core driver and I2C/SPI.
>>
>> Changes in v3:
>> - removed 'select REGMAP' as it is selected by REGMAP_I2C
>> - added EXPORT_SYMBOL_GPL for the core functions
>> - removed default values from regmap_config
>> - Added max_register and unset use_single_rw in regmap_config
>> - Changed Makefile to always compile bmg160-core with either spi or i2c. It is
>> not possible now to compile the core alone.
>>
>> Changes in v2:
>> - Added the id->name from the SPI driver to be used as iio device name
>> - Fixed Kconfig in patch 2 to add selects for REGMAP_I2C
>> - Fixed regmap configs to be static const
>>
>>
>> Best regards,
>>
>> Markus
>>
>>
>> Markus Pargmann (6):
>> iio: bmg160: Use i2c regmap instead of direct i2c access
>> iio: bmg160: Remove i2c_client from data struct
>> iio: bmg160: Use generic dev_drvdata
>> iio: bmg160: Remove remaining uses of i2c_client
>> iio: bmg160: Separate i2c and core driver
>> iio: bmg160: Add SPI driver
>>
>> drivers/iio/gyro/Kconfig | 28 ++-
>> drivers/iio/gyro/Makefile | 3 +-
>> drivers/iio/gyro/bmg160.h | 10 +
>> drivers/iio/gyro/{bmg160.c => bmg160_core.c} | 358 +++++++++++----------------
>> drivers/iio/gyro/bmg160_i2c.c | 71 ++++++
>> drivers/iio/gyro/bmg160_spi.c | 57 +++++
>> 6 files changed, 306 insertions(+), 221 deletions(-)
>> create mode 100644 drivers/iio/gyro/bmg160.h
>> rename drivers/iio/gyro/{bmg160.c => bmg160_core.c} (74%)
>> create mode 100644 drivers/iio/gyro/bmg160_i2c.c
>> create mode 100644 drivers/iio/gyro/bmg160_spi.c
>>
>
> --
> 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
>

2015-08-15 14:50:14

by Jonathan Cameron

[permalink] [raw]
Subject: Re: [PATCH v3 2/6] iio: bmg160: Remove i2c_client from data struct

On 12/08/15 17:03, Srinivas Pandruvada wrote:
> On Wed, 2015-08-12 at 16:50 +0200, Markus Pargmann wrote:
>> i2c_client variable is not really used anymore in the core driver. It is
>> only used to get the device to make proper outputs.
>>
>> This patch replaces all i2c_client usage through direct usage of the
>> device pointer.
>>
>> Signed-off-by: Markus Pargmann <[email protected]>
> Reviewed-by: Srinivas Pandruvada <[email protected]>
Applied to the togreg branch of iio.git

Thanks,

Jonathan
>> ---
>> drivers/iio/gyro/bmg160.c | 64 +++++++++++++++++++++++------------------------
>> 1 file changed, 32 insertions(+), 32 deletions(-)
>>
>> diff --git a/drivers/iio/gyro/bmg160.c b/drivers/iio/gyro/bmg160.c
>> index bbe02053e98a..4701ea17baea 100644
>> --- a/drivers/iio/gyro/bmg160.c
>> +++ b/drivers/iio/gyro/bmg160.c
>> @@ -98,7 +98,7 @@
>> #define BMG160_AUTO_SUSPEND_DELAY_MS 2000
>>
>> struct bmg160_data {
>> - struct i2c_client *client;
>> + struct device *dev;
>> struct regmap *regmap;
>> struct iio_trigger *dready_trig;
>> struct iio_trigger *motion_trig;
>> @@ -148,7 +148,7 @@ static int bmg160_set_mode(struct bmg160_data *data, u8 mode)
>>
>> ret = regmap_write(data->regmap, BMG160_REG_PMU_LPW, mode);
>> if (ret < 0) {
>> - dev_err(&data->client->dev, "Error writing reg_pmu_lpw\n");
>> + dev_err(data->dev, "Error writing reg_pmu_lpw\n");
>> return ret;
>> }
>>
>> @@ -178,7 +178,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->client->dev, "Error writing reg_pmu_bw\n");
>> + dev_err(data->dev, "Error writing reg_pmu_bw\n");
>> return ret;
>> }
>>
>> @@ -194,13 +194,13 @@ static int bmg160_chip_init(struct bmg160_data *data)
>>
>> ret = regmap_read(data->regmap, BMG160_REG_CHIP_ID, &val);
>> if (ret < 0) {
>> - dev_err(&data->client->dev, "Error reading reg_chip_id\n");
>> + dev_err(data->dev, "Error reading reg_chip_id\n");
>> return ret;
>> }
>>
>> - dev_dbg(&data->client->dev, "Chip Id %x\n", val);
>> + dev_dbg(data->dev, "Chip Id %x\n", val);
>> if (val != BMG160_CHIP_ID_VAL) {
>> - dev_err(&data->client->dev, "invalid chip %x\n", val);
>> + dev_err(data->dev, "invalid chip %x\n", val);
>> return -ENODEV;
>> }
>>
>> @@ -219,14 +219,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->client->dev, "Error writing reg_range\n");
>> + dev_err(data->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->client->dev, "Error reading reg_slope_thres\n");
>> + dev_err(data->dev, "Error reading reg_slope_thres\n");
>> return ret;
>> }
>> data->slope_thres = val;
>> @@ -235,7 +235,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->client->dev, "Error updating bits in reg_int_en_1\n");
>> + dev_err(data->dev, "Error updating bits in reg_int_en_1\n");
>> return ret;
>> }
>>
>> @@ -243,7 +243,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->client->dev,
>> + dev_err(data->dev,
>> "Error writing reg_motion_intr\n");
>> return ret;
>> }
>> @@ -257,17 +257,17 @@ static int bmg160_set_power_state(struct bmg160_data *data, bool on)
>> int ret;
>>
>> if (on)
>> - ret = pm_runtime_get_sync(&data->client->dev);
>> + ret = pm_runtime_get_sync(data->dev);
>> else {
>> - pm_runtime_mark_last_busy(&data->client->dev);
>> - ret = pm_runtime_put_autosuspend(&data->client->dev);
>> + pm_runtime_mark_last_busy(data->dev);
>> + ret = pm_runtime_put_autosuspend(data->dev);
>> }
>>
>> if (ret < 0) {
>> - dev_err(&data->client->dev,
>> + dev_err(data->dev,
>> "Failed: bmg160_set_power_state for %d\n", on);
>> if (on)
>> - pm_runtime_put_noidle(&data->client->dev);
>> + pm_runtime_put_noidle(data->dev);
>>
>> return ret;
>> }
>> @@ -286,7 +286,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->client->dev, "Error updating bits reg_int_map0\n");
>> + dev_err(data->dev, "Error updating bits reg_int_map0\n");
>> return ret;
>> }
>>
>> @@ -296,7 +296,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->client->dev,
>> + dev_err(data->dev,
>> "Error writing reg_slope_thres\n");
>> return ret;
>> }
>> @@ -305,7 +305,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->client->dev,
>> + dev_err(data->dev,
>> "Error writing reg_motion_intr\n");
>> return ret;
>> }
>> @@ -321,7 +321,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->client->dev,
>> + dev_err(data->dev,
>> "Error writing reg_rst_latch\n");
>> return ret;
>> }
>> @@ -335,7 +335,7 @@ static int bmg160_setup_any_motion_interrupt(struct bmg160_data *data,
>> }
>>
>> if (ret < 0) {
>> - dev_err(&data->client->dev, "Error writing reg_int_en0\n");
>> + dev_err(data->dev, "Error writing reg_int_en0\n");
>> return ret;
>> }
>>
>> @@ -352,7 +352,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->client->dev, "Error updating bits in reg_int_map1\n");
>> + dev_err(data->dev, "Error updating bits in reg_int_map1\n");
>> return ret;
>> }
>>
>> @@ -361,7 +361,7 @@ 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->client->dev,
>> + dev_err(data->dev,
>> "Error writing reg_rst_latch\n");
>> return ret;
>> }
>> @@ -375,7 +375,7 @@ 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->client->dev,
>> + dev_err(data->dev,
>> "Error writing reg_rst_latch\n");
>> return ret;
>> }
>> @@ -384,7 +384,7 @@ static int bmg160_setup_new_data_interrupt(struct bmg160_data *data,
>> }
>>
>> if (ret < 0) {
>> - dev_err(&data->client->dev, "Error writing reg_int_en0\n");
>> + dev_err(data->dev, "Error writing reg_int_en0\n");
>> return ret;
>> }
>>
>> @@ -414,7 +414,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->client->dev,
>> + dev_err(data->dev,
>> "Error writing reg_range\n");
>> return ret;
>> }
>> @@ -440,7 +440,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->client->dev, "Error reading reg_temp\n");
>> + dev_err(data->dev, "Error reading reg_temp\n");
>> bmg160_set_power_state(data, false);
>> mutex_unlock(&data->mutex);
>> return ret;
>> @@ -470,7 +470,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->client->dev, "Error reading axis %d\n", axis);
>> + dev_err(data->dev, "Error reading axis %d\n", axis);
>> bmg160_set_power_state(data, false);
>> mutex_unlock(&data->mutex);
>> return ret;
>> @@ -813,7 +813,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->client->dev, "Error writing reg_rst_latch\n");
>> + dev_err(data->dev, "Error writing reg_rst_latch\n");
>> return ret;
>> }
>>
>> @@ -879,7 +879,7 @@ static irqreturn_t bmg160_event_handler(int irq, void *private)
>>
>> ret = regmap_read(data->regmap, BMG160_REG_INT_STATUS_2, &val);
>> if (ret < 0) {
>> - dev_err(&data->client->dev, "Error reading reg_int_status2\n");
>> + dev_err(data->dev, "Error reading reg_int_status2\n");
>> goto ack_intr_status;
>> }
>>
>> @@ -916,7 +916,7 @@ ack_intr_status:
>> BMG160_INT_MODE_LATCH_INT |
>> BMG160_INT_MODE_LATCH_RESET);
>> if (ret < 0)
>> - dev_err(&data->client->dev,
>> + dev_err(data->dev,
>> "Error writing reg_rst_latch\n");
>> }
>>
>> @@ -1021,7 +1021,7 @@ static int bmg160_probe(struct i2c_client *client,
>>
>> data = iio_priv(indio_dev);
>> i2c_set_clientdata(client, indio_dev);
>> - data->client = client;
>> + data->dev = &client->dev;
>>
>> ret = bmg160_chip_init(data);
>> if (ret < 0)
>> @@ -1188,7 +1188,7 @@ static int bmg160_runtime_suspend(struct device *dev)
>>
>> ret = bmg160_set_mode(data, BMG160_MODE_SUSPEND);
>> if (ret < 0) {
>> - dev_err(&data->client->dev, "set mode failed\n");
>> + dev_err(data->dev, "set mode failed\n");
>> return -EAGAIN;
>> }
>>
>
>

2015-08-15 14:51:00

by Jonathan Cameron

[permalink] [raw]
Subject: Re: [PATCH v3 3/6] iio: bmg160: Use generic dev_drvdata

On 12/08/15 17:05, Srinivas Pandruvada wrote:
> On Wed, 2015-08-12 at 16:50 +0200, Markus Pargmann wrote:
>> i2c_get_clientdata() is specifically for i2c. Replace it with the
>> generic dev_get/set_drvdata() to support different protocols.
>>
>> Signed-off-by: Markus Pargmann <[email protected]>
> Reviewed-by: Srinivas Pandruvada <[email protected]>
Applied.
>> ---
>> drivers/iio/gyro/bmg160.c | 10 +++++-----
>> 1 file changed, 5 insertions(+), 5 deletions(-)
>>
>> diff --git a/drivers/iio/gyro/bmg160.c b/drivers/iio/gyro/bmg160.c
>> index 4701ea17baea..6eab91ba8977 100644
>> --- a/drivers/iio/gyro/bmg160.c
>> +++ b/drivers/iio/gyro/bmg160.c
>> @@ -1020,7 +1020,7 @@ static int bmg160_probe(struct i2c_client *client,
>> return -ENOMEM;
>>
>> data = iio_priv(indio_dev);
>> - i2c_set_clientdata(client, indio_dev);
>> + dev_set_drvdata(&client->dev, indio_dev);
>> data->dev = &client->dev;
>>
>> ret = bmg160_chip_init(data);
>> @@ -1154,7 +1154,7 @@ static int bmg160_remove(struct i2c_client *client)
>> #ifdef CONFIG_PM_SLEEP
>> static int bmg160_suspend(struct device *dev)
>> {
>> - struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
>> + struct iio_dev *indio_dev = dev_get_drvdata(dev);
>> struct bmg160_data *data = iio_priv(indio_dev);
>>
>> mutex_lock(&data->mutex);
>> @@ -1166,7 +1166,7 @@ static int bmg160_suspend(struct device *dev)
>>
>> static int bmg160_resume(struct device *dev)
>> {
>> - struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
>> + struct iio_dev *indio_dev = dev_get_drvdata(dev);
>> struct bmg160_data *data = iio_priv(indio_dev);
>>
>> mutex_lock(&data->mutex);
>> @@ -1182,7 +1182,7 @@ static int bmg160_resume(struct device *dev)
>> #ifdef CONFIG_PM
>> static int bmg160_runtime_suspend(struct device *dev)
>> {
>> - struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
>> + struct iio_dev *indio_dev = dev_get_drvdata(dev);
>> struct bmg160_data *data = iio_priv(indio_dev);
>> int ret;
>>
>> @@ -1197,7 +1197,7 @@ static int bmg160_runtime_suspend(struct device *dev)
>>
>> static int bmg160_runtime_resume(struct device *dev)
>> {
>> - struct iio_dev *indio_dev = i2c_get_clientdata(to_i2c_client(dev));
>> + struct iio_dev *indio_dev = dev_get_drvdata(dev);
>> struct bmg160_data *data = iio_priv(indio_dev);
>> int ret;
>>
>
>
> --
> 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
>

2015-08-15 14:53:17

by Jonathan Cameron

[permalink] [raw]
Subject: Re: [PATCH v3 4/6] iio: bmg160: Remove remaining uses of i2c_client

On 12/08/15 17:08, Srinivas Pandruvada wrote:
> Can you not merge this with patch 2/6?
Meh, I already took that one so will take this one separately.

You are correct of course that it might makes sense to do this
all together. Ah well ;)


> On Wed, 2015-08-12 at 16:50 +0200, Markus Pargmann wrote:
>> Signed-off-by: Markus Pargmann <[email protected]>
Applied.
>> ---
>> drivers/iio/gyro/bmg160.c | 55 +++++++++++++++++++++++------------------------
>> 1 file changed, 27 insertions(+), 28 deletions(-)
>>
>> diff --git a/drivers/iio/gyro/bmg160.c b/drivers/iio/gyro/bmg160.c
>> index 6eab91ba8977..39df64fb4262 100644
>> --- a/drivers/iio/gyro/bmg160.c
>> +++ b/drivers/iio/gyro/bmg160.c
>> @@ -110,6 +110,7 @@ struct bmg160_data {
>> int slope_thres;
>> bool dready_trigger_on;
>> bool motion_trigger_on;
>> + int irq;
>> };
>>
>> enum bmg160_axis {
>> @@ -961,18 +962,14 @@ static const struct iio_buffer_setup_ops bmg160_buffer_setup_ops = {
>> .postdisable = bmg160_buffer_postdisable,
>> };
>>
>> -static int bmg160_gpio_probe(struct i2c_client *client,
>> - struct bmg160_data *data)
>> +static int bmg160_gpio_probe(struct bmg160_data *data)
>>
>> {
>> struct device *dev;
>> struct gpio_desc *gpio;
>> int ret;
>>
>> - if (!client)
>> - return -EINVAL;
>> -
>> - dev = &client->dev;
>> + dev = data->dev;
>>
>> /* data ready gpio interrupt pin */
>> gpio = devm_gpiod_get_index(dev, BMG160_GPIO_NAME, 0, GPIOD_IN);
>> @@ -981,11 +978,11 @@ static int bmg160_gpio_probe(struct i2c_client *client,
>> return PTR_ERR(gpio);
>> }
>>
>> - ret = gpiod_to_irq(gpio);
>> + data->irq = gpiod_to_irq(gpio);
>>
>> dev_dbg(dev, "GPIO resource, no:%d irq:%d\n", desc_to_gpio(gpio), ret);
>>
>> - return ret;
>> + return 0;
>> }
>>
>> static const char *bmg160_match_acpi_device(struct device *dev)
>> @@ -1007,6 +1004,7 @@ static int bmg160_probe(struct i2c_client *client,
>> int ret;
>> const char *name = NULL;
>> struct regmap *regmap;
>> + struct device *dev = &client->dev;
>>
>> regmap = devm_regmap_init_i2c(client, &bmg160_regmap_i2c_conf);
>> if (IS_ERR(regmap)) {
>> @@ -1020,8 +1018,9 @@ static int bmg160_probe(struct i2c_client *client,
>> return -ENOMEM;
>>
>> data = iio_priv(indio_dev);
>> - dev_set_drvdata(&client->dev, indio_dev);
>> - data->dev = &client->dev;
>> + dev_set_drvdata(dev, indio_dev);
>> + data->dev = dev;
>> + data->irq = client->irq;
>>
>> ret = bmg160_chip_init(data);
>> if (ret < 0)
>> @@ -1032,22 +1031,22 @@ static int bmg160_probe(struct i2c_client *client,
>> if (id)
>> name = id->name;
>>
>> - if (ACPI_HANDLE(&client->dev))
>> - name = bmg160_match_acpi_device(&client->dev);
>> + if (ACPI_HANDLE(dev))
>> + name = bmg160_match_acpi_device(dev);
>>
>> - indio_dev->dev.parent = &client->dev;
>> + indio_dev->dev.parent = dev;
>> indio_dev->channels = bmg160_channels;
>> indio_dev->num_channels = ARRAY_SIZE(bmg160_channels);
>> indio_dev->name = name;
>> indio_dev->modes = INDIO_DIRECT_MODE;
>> indio_dev->info = &bmg160_info;
>>
>> - if (client->irq <= 0)
>> - client->irq = bmg160_gpio_probe(client, data);
>> + if (data->irq <= 0)
>> + bmg160_gpio_probe(data);
>>
>> - if (client->irq > 0) {
>> - ret = devm_request_threaded_irq(&client->dev,
>> - client->irq,
>> + if (data->irq > 0) {
>> + ret = devm_request_threaded_irq(dev,
>> + data->irq,
>> bmg160_data_rdy_trig_poll,
>> bmg160_event_handler,
>> IRQF_TRIGGER_RISING,
>> @@ -1056,28 +1055,28 @@ static int bmg160_probe(struct i2c_client *client,
>> if (ret)
>> return ret;
>>
>> - data->dready_trig = devm_iio_trigger_alloc(&client->dev,
>> + data->dready_trig = devm_iio_trigger_alloc(dev,
>> "%s-dev%d",
>> indio_dev->name,
>> indio_dev->id);
>> if (!data->dready_trig)
>> return -ENOMEM;
>>
>> - data->motion_trig = devm_iio_trigger_alloc(&client->dev,
>> + data->motion_trig = devm_iio_trigger_alloc(dev,
>> "%s-any-motion-dev%d",
>> indio_dev->name,
>> indio_dev->id);
>> if (!data->motion_trig)
>> return -ENOMEM;
>>
>> - data->dready_trig->dev.parent = &client->dev;
>> + data->dready_trig->dev.parent = dev;
>> data->dready_trig->ops = &bmg160_trigger_ops;
>> iio_trigger_set_drvdata(data->dready_trig, indio_dev);
>> ret = iio_trigger_register(data->dready_trig);
>> if (ret)
>> return ret;
>>
>> - data->motion_trig->dev.parent = &client->dev;
>> + data->motion_trig->dev.parent = dev;
>> data->motion_trig->ops = &bmg160_trigger_ops;
>> iio_trigger_set_drvdata(data->motion_trig, indio_dev);
>> ret = iio_trigger_register(data->motion_trig);
>> @@ -1092,25 +1091,25 @@ static int bmg160_probe(struct i2c_client *client,
>> bmg160_trigger_handler,
>> &bmg160_buffer_setup_ops);
>> if (ret < 0) {
>> - dev_err(&client->dev,
>> + dev_err(dev,
>> "iio triggered buffer setup failed\n");
>> goto err_trigger_unregister;
>> }
>>
>> ret = iio_device_register(indio_dev);
>> if (ret < 0) {
>> - dev_err(&client->dev, "unable to register iio device\n");
>> + dev_err(dev, "unable to register iio device\n");
>> goto err_buffer_cleanup;
>> }
>>
>> - ret = pm_runtime_set_active(&client->dev);
>> + ret = pm_runtime_set_active(dev);
>> if (ret)
>> goto err_iio_unregister;
>>
>> - pm_runtime_enable(&client->dev);
>> - pm_runtime_set_autosuspend_delay(&client->dev,
>> + pm_runtime_enable(dev);
>> + pm_runtime_set_autosuspend_delay(dev,
>> BMG160_AUTO_SUSPEND_DELAY_MS);
>> - pm_runtime_use_autosuspend(&client->dev);
>> + pm_runtime_use_autosuspend(dev);
>>
>> return 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
>

2015-08-15 14:59:17

by Jonathan Cameron

[permalink] [raw]
Subject: Re: [PATCH v3 5/6] iio: bmg160: Separate i2c and core driver

On 12/08/15 17:16, Srinivas Pandruvada wrote:
> On Wed, 2015-08-12 at 16:50 +0200, Markus Pargmann wrote:
>> This patch separates the core driver using regmap and the i2c driver
>> which creates the i2c regmap. Also in the Kconfig file BMG160 and
>> BMG160_I2C are separate now.
>>
>> Signed-off-by: Markus Pargmann <[email protected]>
> Reviewed-by: Srinivas Pandruvada <[email protected]>
As I mentioned in the review of you other recent set, I'm not so keen on
the way you have the Kconfig.
>> ---
>> drivers/iio/gyro/Kconfig | 18 +++++--
>> drivers/iio/gyro/Makefile | 2 +-
>> drivers/iio/gyro/bmg160.h | 10 ++++
>> drivers/iio/gyro/{bmg160.c => bmg160_core.c} | 77 +++++-----------------------
>> drivers/iio/gyro/bmg160_i2c.c | 71 +++++++++++++++++++++++++
>> 5 files changed, 109 insertions(+), 69 deletions(-)
>> create mode 100644 drivers/iio/gyro/bmg160.h
>> rename drivers/iio/gyro/{bmg160.c => bmg160_core.c} (94%)
>> create mode 100644 drivers/iio/gyro/bmg160_i2c.c
>>
>> diff --git a/drivers/iio/gyro/Kconfig b/drivers/iio/gyro/Kconfig
>> index cf82d74139a2..13f8e0051615 100644
>> --- a/drivers/iio/gyro/Kconfig
>> +++ b/drivers/iio/gyro/Kconfig
>> @@ -51,17 +51,27 @@ config ADXRS450
>> will be called adxrs450.
>>
>> config BMG160
>> - tristate "BOSCH BMG160 Gyro Sensor"
>> - depends on I2C
>> + bool "BOSCH BMG160 Gyro Sensor"
This prevents building the core as a module?
>> select IIO_BUFFER
>> select IIO_TRIGGERED_BUFFER
>> - select REGMAP_I2C
>> help
>> Say yes here to build support for Bosch BMG160 Tri-axis Gyro Sensor
>> driver. This driver also supports BMI055 gyroscope.
I prefer the logic the way the ST accelerometer driver has it. A core
module that you get to pick in the menu, then building the i2c / spi
parts dependent on their dependencies being met. Cuts down on the
complexity of presented configuration.

Jonathan
>>
>> +if BMG160
>> +
>> +config BMG160_I2C
>> + tristate "Driver for connection via I2C"
>> + depends on I2C
>> + select REGMAP_I2C
>> + help
>> + Say yes here to build support for Bosch BMG160 Tri-axis Gyro Sensor
>> + driver connected via I2C. This driver also supports BMI055 gyroscope.
>> +
>> This driver can also be built as a module. If so, the module
>> - will be called bmg160.
>> + will be called bmg160_i2c.
>> +
>> +endif
>>
>> config HID_SENSOR_GYRO_3D
>> depends on HID_SENSOR_HUB
>> diff --git a/drivers/iio/gyro/Makefile b/drivers/iio/gyro/Makefile
>> index f46341b39139..73b41e43a974 100644
>> --- a/drivers/iio/gyro/Makefile
>> +++ b/drivers/iio/gyro/Makefile
>> @@ -8,7 +8,7 @@ obj-$(CONFIG_ADIS16130) += adis16130.o
>> obj-$(CONFIG_ADIS16136) += adis16136.o
>> obj-$(CONFIG_ADIS16260) += adis16260.o
>> obj-$(CONFIG_ADXRS450) += adxrs450.o
>> -obj-$(CONFIG_BMG160) += bmg160.o
>> +obj-$(CONFIG_BMG160_I2C) += bmg160_core.o bmg160_i2c.o
>>
>> obj-$(CONFIG_HID_SENSOR_GYRO_3D) += hid-sensor-gyro-3d.o
>>
>> diff --git a/drivers/iio/gyro/bmg160.h b/drivers/iio/gyro/bmg160.h
>> new file mode 100644
>> index 000000000000..72db723c8fb6
>> --- /dev/null
>> +++ b/drivers/iio/gyro/bmg160.h
>> @@ -0,0 +1,10 @@
>> +#ifndef BMG160_H_
>> +#define BMG160_H_
>> +
>> +extern const struct dev_pm_ops bmg160_pm_ops;
>> +
>> +int bmg160_core_probe(struct device *dev, struct regmap *regmap, int irq,
>> + const char *name);
>> +void bmg160_core_remove(struct device *dev);
>> +
>> +#endif /* BMG160_H_ */
>> diff --git a/drivers/iio/gyro/bmg160.c b/drivers/iio/gyro/bmg160_core.c
>> similarity index 94%
>> rename from drivers/iio/gyro/bmg160.c
>> rename to drivers/iio/gyro/bmg160_core.c
>> index 39df64fb4262..d64e3a87e0a1 100644
>> --- a/drivers/iio/gyro/bmg160.c
>> +++ b/drivers/iio/gyro/bmg160_core.c
>> @@ -13,7 +13,6 @@
>> */
>>
>> #include <linux/module.h>
>> -#include <linux/i2c.h>
>> #include <linux/interrupt.h>
>> #include <linux/delay.h>
>> #include <linux/slab.h>
>> @@ -30,7 +29,6 @@
>> #include <linux/iio/triggered_buffer.h>
>> #include <linux/regmap.h>
>>
>> -#define BMG160_DRV_NAME "bmg160"
>> #define BMG160_IRQ_NAME "bmg160_event"
>> #define BMG160_GPIO_NAME "gpio_int"
>>
>> @@ -137,12 +135,6 @@ static const struct {
>> { 133, BMG160_RANGE_250DPS},
>> { 66, BMG160_RANGE_125DPS} };
>>
>> -struct regmap_config bmg160_regmap_i2c_conf = {
>> - .reg_bits = 8,
>> - .val_bits = 8,
>> - .max_register = 0x3f
>> -};
>> -
>> static int bmg160_set_mode(struct bmg160_data *data, u8 mode)
>> {
>> int ret;
>> @@ -996,31 +988,22 @@ static const char *bmg160_match_acpi_device(struct device *dev)
>> return dev_name(dev);
>> }
>>
>> -static int bmg160_probe(struct i2c_client *client,
>> - const struct i2c_device_id *id)
>> +int bmg160_core_probe(struct device *dev, struct regmap *regmap, int irq,
>> + const char *name)
>> {
>> struct bmg160_data *data;
>> struct iio_dev *indio_dev;
>> int ret;
>> - const char *name = NULL;
>> - struct regmap *regmap;
>> - struct device *dev = &client->dev;
>> -
>> - regmap = devm_regmap_init_i2c(client, &bmg160_regmap_i2c_conf);
>> - if (IS_ERR(regmap)) {
>> - dev_err(&client->dev, "Failed to register i2c regmap %d\n",
>> - (int)PTR_ERR(regmap));
>> - return PTR_ERR(regmap);
>> - }
>>
>> - indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
>> + indio_dev = devm_iio_device_alloc(dev, sizeof(*data));
>> if (!indio_dev)
>> return -ENOMEM;
>>
>> data = iio_priv(indio_dev);
>> dev_set_drvdata(dev, indio_dev);
>> data->dev = dev;
>> - data->irq = client->irq;
>> + data->irq = irq;
>> + data->regmap = regmap;
>>
>> ret = bmg160_chip_init(data);
>> if (ret < 0)
>> @@ -1028,9 +1011,6 @@ static int bmg160_probe(struct i2c_client *client,
>>
>> mutex_init(&data->mutex);
>>
>> - if (id)
>> - name = id->name;
>> -
>> if (ACPI_HANDLE(dev))
>> name = bmg160_match_acpi_device(dev);
>>
>> @@ -1125,15 +1105,16 @@ err_trigger_unregister:
>>
>> return ret;
>> }
>> +EXPORT_SYMBOL_GPL(bmg160_core_probe);
>>
>> -static int bmg160_remove(struct i2c_client *client)
>> +void bmg160_core_remove(struct device *dev)
>> {
>> - struct iio_dev *indio_dev = i2c_get_clientdata(client);
>> + struct iio_dev *indio_dev = dev_get_drvdata(dev);
>> struct bmg160_data *data = iio_priv(indio_dev);
>>
>> - pm_runtime_disable(&client->dev);
>> - pm_runtime_set_suspended(&client->dev);
>> - pm_runtime_put_noidle(&client->dev);
>> + pm_runtime_disable(dev);
>> + pm_runtime_set_suspended(dev);
>> + pm_runtime_put_noidle(dev);
>>
>> iio_device_unregister(indio_dev);
>> iio_triggered_buffer_cleanup(indio_dev);
>> @@ -1146,9 +1127,8 @@ static int bmg160_remove(struct i2c_client *client)
>> mutex_lock(&data->mutex);
>> bmg160_set_mode(data, BMG160_MODE_DEEP_SUSPEND);
>> mutex_unlock(&data->mutex);
>> -
>> - return 0;
>> }
>> +EXPORT_SYMBOL_GPL(bmg160_core_remove);
>>
>> #ifdef CONFIG_PM_SLEEP
>> static int bmg160_suspend(struct device *dev)
>> @@ -1210,40 +1190,9 @@ static int bmg160_runtime_resume(struct device *dev)
>> }
>> #endif
>>
>> -static const struct dev_pm_ops bmg160_pm_ops = {
>> +const struct dev_pm_ops bmg160_pm_ops = {
>> SET_SYSTEM_SLEEP_PM_OPS(bmg160_suspend, bmg160_resume)
>> SET_RUNTIME_PM_OPS(bmg160_runtime_suspend,
>> bmg160_runtime_resume, NULL)
>> };
>>
>> -static const struct acpi_device_id bmg160_acpi_match[] = {
>> - {"BMG0160", 0},
>> - {"BMI055B", 0},
>> - {},
>> -};
>> -
>> -MODULE_DEVICE_TABLE(acpi, bmg160_acpi_match);
>> -
>> -static const struct i2c_device_id bmg160_id[] = {
>> - {"bmg160", 0},
>> - {"bmi055_gyro", 0},
>> - {}
>> -};
>> -
>> -MODULE_DEVICE_TABLE(i2c, bmg160_id);
>> -
>> -static struct i2c_driver bmg160_driver = {
>> - .driver = {
>> - .name = BMG160_DRV_NAME,
>> - .acpi_match_table = ACPI_PTR(bmg160_acpi_match),
>> - .pm = &bmg160_pm_ops,
>> - },
>> - .probe = bmg160_probe,
>> - .remove = bmg160_remove,
>> - .id_table = bmg160_id,
>> -};
>> -module_i2c_driver(bmg160_driver);
>> -
>> -MODULE_AUTHOR("Srinivas Pandruvada <[email protected]>");
>> -MODULE_LICENSE("GPL v2");
>> -MODULE_DESCRIPTION("BMG160 Gyro driver");
>> diff --git a/drivers/iio/gyro/bmg160_i2c.c b/drivers/iio/gyro/bmg160_i2c.c
>> new file mode 100644
>> index 000000000000..90126a5a7663
>> --- /dev/null
>> +++ b/drivers/iio/gyro/bmg160_i2c.c
>> @@ -0,0 +1,71 @@
>> +#include <linux/i2c.h>
>> +#include <linux/regmap.h>
>> +#include <linux/iio/iio.h>
>> +#include <linux/module.h>
>> +#include <linux/acpi.h>
>> +
>> +#include "bmg160.h"
>> +
>> +static const struct regmap_config bmg160_regmap_i2c_conf = {
>> + .reg_bits = 8,
>> + .val_bits = 8,
>> + .max_register = 0x3f
>> +};
>> +
>> +static int bmg160_i2c_probe(struct i2c_client *client,
>> + const struct i2c_device_id *id)
>> +{
>> + struct regmap *regmap;
>> + const char *name = NULL;
>> +
>> + regmap = devm_regmap_init_i2c(client, &bmg160_regmap_i2c_conf);
>> + if (IS_ERR(regmap)) {
>> + dev_err(&client->dev, "Failed to register i2c regmap %d\n",
>> + (int)PTR_ERR(regmap));
>> + return PTR_ERR(regmap);
>> + }
>> +
>> + if (id)
>> + name = id->name;
>> +
>> + return bmg160_core_probe(&client->dev, regmap, client->irq, name);
>> +}
>> +
>> +static int bmg160_i2c_remove(struct i2c_client *client)
>> +{
>> + bmg160_core_remove(&client->dev);
>> +
>> + return 0;
>> +}
>> +
>> +static const struct acpi_device_id bmg160_acpi_match[] = {
>> + {"BMG0160", 0},
>> + {"BMI055B", 0},
>> + {},
>> +};
>> +
>> +MODULE_DEVICE_TABLE(acpi, bmg160_acpi_match);
>> +
>> +static const struct i2c_device_id bmg160_i2c_id[] = {
>> + {"bmg160", 0},
>> + {"bmi055_gyro", 0},
>> + {}
>> +};
>> +
>> +MODULE_DEVICE_TABLE(i2c, bmg160_i2c_id);
>> +
>> +static struct i2c_driver bmg160_i2c_driver = {
>> + .driver = {
>> + .name = "bmg160_i2c",
>> + .acpi_match_table = ACPI_PTR(bmg160_acpi_match),
>> + .pm = &bmg160_pm_ops,
>> + },
>> + .probe = bmg160_i2c_probe,
>> + .remove = bmg160_i2c_remove,
>> + .id_table = bmg160_i2c_id,
>> +};
>> +module_i2c_driver(bmg160_i2c_driver);
>> +
>> +MODULE_AUTHOR("Srinivas Pandruvada <[email protected]>");
>> +MODULE_LICENSE("GPL v2");
>> +MODULE_DESCRIPTION("BMG160 I2C Gyro driver");
>
>
> --
> 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
>

2015-08-15 15:03:28

by Jonathan Cameron

[permalink] [raw]
Subject: Re: [PATCH v3 6/6] iio: bmg160: Add SPI driver

On 12/08/15 16:19, Peter Meerwald wrote:
> On Wed, 12 Aug 2015, Markus Pargmann wrote:
>
>> Signed-off-by: Markus Pargmann <[email protected]>
>
> the spelling of Bosch is inconsistent, sometimes it is BOSCH, I'd prefer
> the former
>
> please find a slightly more relevant comment below :)
Another comment on the break up of modules you have here
which is a bit odd and leads to two large modules instead
of 1 large and 2 small (which I think would be preferable).

Jonathan
>
>> ---
>> drivers/iio/gyro/Kconfig | 11 +++++++++
>> drivers/iio/gyro/Makefile | 1 +
>> drivers/iio/gyro/bmg160_spi.c | 57 +++++++++++++++++++++++++++++++++++++++++++
>> 3 files changed, 69 insertions(+)
>> create mode 100644 drivers/iio/gyro/bmg160_spi.c
>>
>> diff --git a/drivers/iio/gyro/Kconfig b/drivers/iio/gyro/Kconfig
>> index 13f8e0051615..a77dbb0062fe 100644
>> --- a/drivers/iio/gyro/Kconfig
>> +++ b/drivers/iio/gyro/Kconfig
>> @@ -71,6 +71,17 @@ config BMG160_I2C
>> This driver can also be built as a module. If so, the module
>> will be called bmg160_i2c.
>>
>> +config BMG160_SPI
>> + tristate "Driver for connection via SPI"
>> + depends on SPI
>> + select REGMAP_SPI
>> + help
>> + Say yes here to build support for Bosch BMG160 Tri-axis Gyro Sensor
>> + driver connected via SPI. This driver also supports BMI055 gyroscope.
>> +
>> + This driver can also be built as a module. If so, the module
>> + will be called bmg160_spi.
>> +
>> endif
>>
>> config HID_SENSOR_GYRO_3D
>> diff --git a/drivers/iio/gyro/Makefile b/drivers/iio/gyro/Makefile
>> index 73b41e43a974..848e55c605c0 100644
>> --- a/drivers/iio/gyro/Makefile
>> +++ b/drivers/iio/gyro/Makefile
>> @@ -9,6 +9,7 @@ obj-$(CONFIG_ADIS16136) += adis16136.o
>> obj-$(CONFIG_ADIS16260) += adis16260.o
>> obj-$(CONFIG_ADXRS450) += adxrs450.o
>> obj-$(CONFIG_BMG160_I2C) += bmg160_core.o bmg160_i2c.o
>> +obj-$(CONFIG_BMG160_I2C) += bmg160_core.o bmg160_spi.o
So if both are present (and most distros will build both) we will have
the core stuff built twice? I'd rather that was a separate module
as is usually done for this sort of case. See how the ST accelerometer
driver does it (slightly more complex case)
>>
>> obj-$(CONFIG_HID_SENSOR_GYRO_3D) += hid-sensor-gyro-3d.o
>>
>> diff --git a/drivers/iio/gyro/bmg160_spi.c b/drivers/iio/gyro/bmg160_spi.c
>> new file mode 100644
>> index 000000000000..8a358571b702
>> --- /dev/null
>> +++ b/drivers/iio/gyro/bmg160_spi.c
>> @@ -0,0 +1,57 @@
>> +#include <linux/spi/spi.h>
>> +#include <linux/regmap.h>
>> +#include <linux/iio/iio.h>
>> +#include <linux/module.h>
>> +
>> +#include <bmg160.h>
>
> I think this should be
> #include "bmg160.h"
> as in the _i2c part of the driver
>
>> +
>> +static const struct regmap_config bmg160_regmap_spi_conf = {
>> + .reg_bits = 8,
>> + .val_bits = 8,
>> + .max_register = 0x3f,
>> +};
>> +
>> +static int bmg160_spi_probe(struct spi_device *spi)
>> +{
>> + struct regmap *regmap;
>> + const struct spi_device_id *id = spi_get_device_id(spi);
>> +
>> + regmap = devm_regmap_init_spi(spi, &bmg160_regmap_spi_conf);
>> + if (IS_ERR(regmap)) {
>> + dev_err(&spi->dev, "Failed to register spi regmap %d\n",
>> + (int)PTR_ERR(regmap));
>> + return PTR_ERR(regmap);
>> + }
>> +
>> + return bmg160_core_probe(&spi->dev, regmap, spi->irq, id->name);
>> +}
>> +
>> +static int bmg160_spi_remove(struct spi_device *spi)
>> +{
>> + bmg160_core_remove(&spi->dev);
>> +
>> + return 0;
>> +}
>> +
>> +static const struct spi_device_id bmg160_spi_id[] = {
>> + {"bmg160", 0},
>> + {"bmi055_gyro", 0},
>> + {}
>> +};
>> +
>> +MODULE_DEVICE_TABLE(spi, bmg160_spi_id);
>> +
>> +static struct spi_driver bmg160_spi_driver = {
>> + .driver = {
>> + .name = "bmg160_spi",
>> + .pm = &bmg160_pm_ops,
>> + },
>> + .probe = bmg160_spi_probe,
>> + .remove = bmg160_spi_remove,
>> + .id_table = bmg160_spi_id,
>> +};
>> +module_spi_driver(bmg160_spi_driver);
>> +
>> +MODULE_AUTHOR("Markus Pargmann <[email protected]>");
>> +MODULE_LICENSE("GPL v2");
>> +MODULE_DESCRIPTION("BMG160 SPI Gyro driver");
>>
>

2015-08-17 06:39:16

by Markus Pargmann

[permalink] [raw]
Subject: Re: [PATCH v3 6/6] iio: bmg160: Add SPI driver

On Wed, Aug 12, 2015 at 05:19:37PM +0200, Peter Meerwald wrote:
> On Wed, 12 Aug 2015, Markus Pargmann wrote:
>
> > Signed-off-by: Markus Pargmann <[email protected]>
>
> the spelling of Bosch is inconsistent, sometimes it is BOSCH, I'd prefer
> the former

Right, I can fix it in this patch, yes.

>
> please find a slightly more relevant comment below :)
>
> > ---
> > drivers/iio/gyro/Kconfig | 11 +++++++++
> > drivers/iio/gyro/Makefile | 1 +
> > drivers/iio/gyro/bmg160_spi.c | 57 +++++++++++++++++++++++++++++++++++++++++++
> > 3 files changed, 69 insertions(+)
> > create mode 100644 drivers/iio/gyro/bmg160_spi.c
> >
> > diff --git a/drivers/iio/gyro/Kconfig b/drivers/iio/gyro/Kconfig
> > index 13f8e0051615..a77dbb0062fe 100644
> > --- a/drivers/iio/gyro/Kconfig
> > +++ b/drivers/iio/gyro/Kconfig
> > @@ -71,6 +71,17 @@ config BMG160_I2C
> > This driver can also be built as a module. If so, the module
> > will be called bmg160_i2c.
> >
> > +config BMG160_SPI
> > + tristate "Driver for connection via SPI"
> > + depends on SPI
> > + select REGMAP_SPI
> > + help
> > + Say yes here to build support for Bosch BMG160 Tri-axis Gyro Sensor
> > + driver connected via SPI. This driver also supports BMI055 gyroscope.
> > +
> > + This driver can also be built as a module. If so, the module
> > + will be called bmg160_spi.
> > +
> > endif
> >
> > config HID_SENSOR_GYRO_3D
> > diff --git a/drivers/iio/gyro/Makefile b/drivers/iio/gyro/Makefile
> > index 73b41e43a974..848e55c605c0 100644
> > --- a/drivers/iio/gyro/Makefile
> > +++ b/drivers/iio/gyro/Makefile
> > @@ -9,6 +9,7 @@ obj-$(CONFIG_ADIS16136) += adis16136.o
> > obj-$(CONFIG_ADIS16260) += adis16260.o
> > obj-$(CONFIG_ADXRS450) += adxrs450.o
> > obj-$(CONFIG_BMG160_I2C) += bmg160_core.o bmg160_i2c.o
> > +obj-$(CONFIG_BMG160_I2C) += bmg160_core.o bmg160_spi.o
> >
> > obj-$(CONFIG_HID_SENSOR_GYRO_3D) += hid-sensor-gyro-3d.o
> >
> > diff --git a/drivers/iio/gyro/bmg160_spi.c b/drivers/iio/gyro/bmg160_spi.c
> > new file mode 100644
> > index 000000000000..8a358571b702
> > --- /dev/null
> > +++ b/drivers/iio/gyro/bmg160_spi.c
> > @@ -0,0 +1,57 @@
> > +#include <linux/spi/spi.h>
> > +#include <linux/regmap.h>
> > +#include <linux/iio/iio.h>
> > +#include <linux/module.h>
> > +
> > +#include <bmg160.h>
>
> I think this should be
> #include "bmg160.h"
> as in the _i2c part of the driver

Yes, thanks.

Best regards,

Markus

>
> > +
> > +static const struct regmap_config bmg160_regmap_spi_conf = {
> > + .reg_bits = 8,
> > + .val_bits = 8,
> > + .max_register = 0x3f,
> > +};
> > +
> > +static int bmg160_spi_probe(struct spi_device *spi)
> > +{
> > + struct regmap *regmap;
> > + const struct spi_device_id *id = spi_get_device_id(spi);
> > +
> > + regmap = devm_regmap_init_spi(spi, &bmg160_regmap_spi_conf);
> > + if (IS_ERR(regmap)) {
> > + dev_err(&spi->dev, "Failed to register spi regmap %d\n",
> > + (int)PTR_ERR(regmap));
> > + return PTR_ERR(regmap);
> > + }
> > +
> > + return bmg160_core_probe(&spi->dev, regmap, spi->irq, id->name);
> > +}
> > +
> > +static int bmg160_spi_remove(struct spi_device *spi)
> > +{
> > + bmg160_core_remove(&spi->dev);
> > +
> > + return 0;
> > +}
> > +
> > +static const struct spi_device_id bmg160_spi_id[] = {
> > + {"bmg160", 0},
> > + {"bmi055_gyro", 0},
> > + {}
> > +};
> > +
> > +MODULE_DEVICE_TABLE(spi, bmg160_spi_id);
> > +
> > +static struct spi_driver bmg160_spi_driver = {
> > + .driver = {
> > + .name = "bmg160_spi",
> > + .pm = &bmg160_pm_ops,
> > + },
> > + .probe = bmg160_spi_probe,
> > + .remove = bmg160_spi_remove,
> > + .id_table = bmg160_spi_id,
> > +};
> > +module_spi_driver(bmg160_spi_driver);
> > +
> > +MODULE_AUTHOR("Markus Pargmann <[email protected]>");
> > +MODULE_LICENSE("GPL v2");
> > +MODULE_DESCRIPTION("BMG160 SPI Gyro driver");
> >
>
> --
>
> Peter Meerwald
> +43-664-2444418 (mobile)
>

--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |


Attachments:
(No filename) (4.12 kB)
signature.asc (819.00 B)
Digital signature
Download all attachments

2015-08-17 06:41:42

by Markus Pargmann

[permalink] [raw]
Subject: Re: [PATCH v3 6/6] iio: bmg160: Add SPI driver

Hi,

On Sat, Aug 15, 2015 at 04:03:24PM +0100, Jonathan Cameron wrote:
> On 12/08/15 16:19, Peter Meerwald wrote:
> > On Wed, 12 Aug 2015, Markus Pargmann wrote:
> >
> >> Signed-off-by: Markus Pargmann <[email protected]>
> >
> > the spelling of Bosch is inconsistent, sometimes it is BOSCH, I'd prefer
> > the former
> >
> > please find a slightly more relevant comment below :)
> Another comment on the break up of modules you have here
> which is a bit odd and leads to two large modules instead
> of 1 large and 2 small (which I think would be preferable).

Thanks, I will fix that.

Best Regards,

Markus

>
> Jonathan
> >
> >> ---
> >> drivers/iio/gyro/Kconfig | 11 +++++++++
> >> drivers/iio/gyro/Makefile | 1 +
> >> drivers/iio/gyro/bmg160_spi.c | 57 +++++++++++++++++++++++++++++++++++++++++++
> >> 3 files changed, 69 insertions(+)
> >> create mode 100644 drivers/iio/gyro/bmg160_spi.c
> >>
> >> diff --git a/drivers/iio/gyro/Kconfig b/drivers/iio/gyro/Kconfig
> >> index 13f8e0051615..a77dbb0062fe 100644
> >> --- a/drivers/iio/gyro/Kconfig
> >> +++ b/drivers/iio/gyro/Kconfig
> >> @@ -71,6 +71,17 @@ config BMG160_I2C
> >> This driver can also be built as a module. If so, the module
> >> will be called bmg160_i2c.
> >>
> >> +config BMG160_SPI
> >> + tristate "Driver for connection via SPI"
> >> + depends on SPI
> >> + select REGMAP_SPI
> >> + help
> >> + Say yes here to build support for Bosch BMG160 Tri-axis Gyro Sensor
> >> + driver connected via SPI. This driver also supports BMI055 gyroscope.
> >> +
> >> + This driver can also be built as a module. If so, the module
> >> + will be called bmg160_spi.
> >> +
> >> endif
> >>
> >> config HID_SENSOR_GYRO_3D
> >> diff --git a/drivers/iio/gyro/Makefile b/drivers/iio/gyro/Makefile
> >> index 73b41e43a974..848e55c605c0 100644
> >> --- a/drivers/iio/gyro/Makefile
> >> +++ b/drivers/iio/gyro/Makefile
> >> @@ -9,6 +9,7 @@ obj-$(CONFIG_ADIS16136) += adis16136.o
> >> obj-$(CONFIG_ADIS16260) += adis16260.o
> >> obj-$(CONFIG_ADXRS450) += adxrs450.o
> >> obj-$(CONFIG_BMG160_I2C) += bmg160_core.o bmg160_i2c.o
> >> +obj-$(CONFIG_BMG160_I2C) += bmg160_core.o bmg160_spi.o
> So if both are present (and most distros will build both) we will have
> the core stuff built twice? I'd rather that was a separate module
> as is usually done for this sort of case. See how the ST accelerometer
> driver does it (slightly more complex case)
> >>
> >> obj-$(CONFIG_HID_SENSOR_GYRO_3D) += hid-sensor-gyro-3d.o
> >>
> >> diff --git a/drivers/iio/gyro/bmg160_spi.c b/drivers/iio/gyro/bmg160_spi.c
> >> new file mode 100644
> >> index 000000000000..8a358571b702
> >> --- /dev/null
> >> +++ b/drivers/iio/gyro/bmg160_spi.c
> >> @@ -0,0 +1,57 @@
> >> +#include <linux/spi/spi.h>
> >> +#include <linux/regmap.h>
> >> +#include <linux/iio/iio.h>
> >> +#include <linux/module.h>
> >> +
> >> +#include <bmg160.h>
> >
> > I think this should be
> > #include "bmg160.h"
> > as in the _i2c part of the driver
> >
> >> +
> >> +static const struct regmap_config bmg160_regmap_spi_conf = {
> >> + .reg_bits = 8,
> >> + .val_bits = 8,
> >> + .max_register = 0x3f,
> >> +};
> >> +
> >> +static int bmg160_spi_probe(struct spi_device *spi)
> >> +{
> >> + struct regmap *regmap;
> >> + const struct spi_device_id *id = spi_get_device_id(spi);
> >> +
> >> + regmap = devm_regmap_init_spi(spi, &bmg160_regmap_spi_conf);
> >> + if (IS_ERR(regmap)) {
> >> + dev_err(&spi->dev, "Failed to register spi regmap %d\n",
> >> + (int)PTR_ERR(regmap));
> >> + return PTR_ERR(regmap);
> >> + }
> >> +
> >> + return bmg160_core_probe(&spi->dev, regmap, spi->irq, id->name);
> >> +}
> >> +
> >> +static int bmg160_spi_remove(struct spi_device *spi)
> >> +{
> >> + bmg160_core_remove(&spi->dev);
> >> +
> >> + return 0;
> >> +}
> >> +
> >> +static const struct spi_device_id bmg160_spi_id[] = {
> >> + {"bmg160", 0},
> >> + {"bmi055_gyro", 0},
> >> + {}
> >> +};
> >> +
> >> +MODULE_DEVICE_TABLE(spi, bmg160_spi_id);
> >> +
> >> +static struct spi_driver bmg160_spi_driver = {
> >> + .driver = {
> >> + .name = "bmg160_spi",
> >> + .pm = &bmg160_pm_ops,
> >> + },
> >> + .probe = bmg160_spi_probe,
> >> + .remove = bmg160_spi_remove,
> >> + .id_table = bmg160_spi_id,
> >> +};
> >> +module_spi_driver(bmg160_spi_driver);
> >> +
> >> +MODULE_AUTHOR("Markus Pargmann <[email protected]>");
> >> +MODULE_LICENSE("GPL v2");
> >> +MODULE_DESCRIPTION("BMG160 SPI Gyro driver");
> >>
> >
>
>

--
Pengutronix e.K. | |
Industrial Linux Solutions | http://www.pengutronix.de/ |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0 |
Amtsgericht Hildesheim, HRA 2686 | Fax: +49-5121-206917-5555 |


Attachments:
(No filename) (4.67 kB)
signature.asc (819.00 B)
Digital signature
Download all attachments

2015-08-17 09:27:09

by Tirdea, Irina

[permalink] [raw]
Subject: RE: [PATCH v3 0/6] iio: bmg160: Add SPI connection



> -----Original Message-----
> From: Lars-Peter Clausen [mailto:[email protected]]
> Sent: 12 August, 2015 18:04
> To: Markus Pargmann; Jonathan Cameron
> Cc: Srinivas Pandruvada; Dogaru, Vlad; Paul Bolle; [email protected]; [email protected]; [email protected];
> Tirdea, Irina
> Subject: Re: [PATCH v3 0/6] iio: bmg160: Add SPI connection
>
> Hi,
>
> Markus and Irina can you try to synchronize your efforts. This series will
> conflict with http://marc.info/?l=linux-iio&m=143938994602171&w=2
>

Hi Lars,

Good catch, especially since those patches might have been merged
through another tree. Completely missed this one.

> I think it would be best if the multi-read emulation support is added to
> regmap (which I think Markus' earlier series did).
>

I think my i2c controllers will work directly with regmap_bulk_read,
so I probably won't need additional changes for regmap. I will rebase
the bmg160 patches on top of the ones that add regmap support.

Thanks,
Irina

> - Lars
>
> On 08/12/2015 04:50 PM, Markus Pargmann wrote:
> > Hi,
> >
> > bmg160 and bmi055 can be used via I2C and SPI. This series converts the driver
> > to regmap and splits core driver and I2C/SPI.
> >
> > Changes in v3:
> > - removed 'select REGMAP' as it is selected by REGMAP_I2C
> > - added EXPORT_SYMBOL_GPL for the core functions
> > - removed default values from regmap_config
> > - Added max_register and unset use_single_rw in regmap_config
> > - Changed Makefile to always compile bmg160-core with either spi or i2c. It is
> > not possible now to compile the core alone.
> >
> > Changes in v2:
> > - Added the id->name from the SPI driver to be used as iio device name
> > - Fixed Kconfig in patch 2 to add selects for REGMAP_I2C
> > - Fixed regmap configs to be static const
> >
> >
> > Best regards,
> >
> > Markus
> >
> >
> > Markus Pargmann (6):
> > iio: bmg160: Use i2c regmap instead of direct i2c access
> > iio: bmg160: Remove i2c_client from data struct
> > iio: bmg160: Use generic dev_drvdata
> > iio: bmg160: Remove remaining uses of i2c_client
> > iio: bmg160: Separate i2c and core driver
> > iio: bmg160: Add SPI driver
> >
> > drivers/iio/gyro/Kconfig | 28 ++-
> > drivers/iio/gyro/Makefile | 3 +-
> > drivers/iio/gyro/bmg160.h | 10 +
> > drivers/iio/gyro/{bmg160.c => bmg160_core.c} | 358 +++++++++++----------------
> > drivers/iio/gyro/bmg160_i2c.c | 71 ++++++
> > drivers/iio/gyro/bmg160_spi.c | 57 +++++
> > 6 files changed, 306 insertions(+), 221 deletions(-)
> > create mode 100644 drivers/iio/gyro/bmg160.h
> > rename drivers/iio/gyro/{bmg160.c => bmg160_core.c} (74%)
> > create mode 100644 drivers/iio/gyro/bmg160_i2c.c
> > create mode 100644 drivers/iio/gyro/bmg160_spi.c
> >