Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 27f5a85f authored by Greg Kroah-Hartman's avatar Greg Kroah-Hartman
Browse files

Merge tag 'iio-for-3.18b' of...

Merge tag 'iio-for-3.18b' of git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio into staging-next

Jonathan writes:

Second round of new IIO drivers, features and cleanups for the 3.18 cycle.

New drivers and part support
* Bosch bmg160 Gyroscope driver
* Dyna-Image al3320a ambient light sensor driver
* Bosh bmi055 gyroscope part driver (accelerometer part supported by bmc150)
* isl29018 - add support for isl29023 and isl29035
* kxcjk-1013 - add support for kxcj9-1008 and kxtj2-1009
* bmc150 - additional part support (BMI055 accelerometer part, BMA255,
  BMA222E, BMA250E and BMA280).  Different resolutions but otherwise similar
  parts.
* bma180 - add BMA250 (note different from the BMA250E support above despite
  the naming).  A lot of driver reworking lead up to this - described below.

New features
* kxcjk1013 - add threshold event support.
* rockchip - document DT bindings.
* isl29018 - ACPI support
* bma180 - enable use without IRQ

Cleanups
* Tree wide - drop owner field assignment if using the module_platform_driver
  helper as that assigns it anyway.
* kxcjk1013 - drop a redundant assignment of the current range and fix a
  a defined but not used warning.
* inv_mpu6050 - Remove an unnecessary cast form a void pointer.
* rockchip - drop and unused variable.
* at91_adc - make a local function static.
* st-sensors-core - correctly handle an error in setting in
  st_sensors_set_drdy_int_pin
* isl29018 - typo fix
* bmc150 - fix incorrect scale value for 16G range (Driver new this cycle)
* bmc150 - fix issues when CONFIG_PM_RUNTIME not set (Driver new this cycle)
* ad7606 - line length tidy up.
* bmg160 - set power state only if PM_RUNTIME is defined.
* ak8975 - fix some unnecessary casting between char * and const char *
* bma180 - prefix remaining bits and bobs with bma180_ and ensure consistent.
         - use a bool instead of an int for state (as its either on or off).
         - expose the temperature channel
         - statically allocate buffers to avoid need for update_scan_mode
           callback.
         - refactor to allow futher chip variants including support for part
           specific config and disable code + different resolutions.
parents caf382fe 2017cff2
Loading
Loading
Loading
Loading
+7 −0
Original line number Diff line number Diff line
What:		/sys/bus/iio/devices/triggerX/name = "bmg160-any-motion-devX"
KernelVersion:	3.17
Contact:	linux-iio@vger.kernel.org
Description:
		The BMG160 gyro kernel module provides an additional trigger,
		which sets driver in a mode, where data is pushed to the buffer
		only when there is any motion.
+24 −0
Original line number Diff line number Diff line
Rockchip Successive Approximation Register (SAR) A/D Converter bindings

Required properties:
- compatible: Should be "rockchip,saradc"
- reg: physical base address of the controller and length of memory mapped
       region.
- interrupts: The interrupt number to the cpu. The interrupt specifier format
              depends on the interrupt controller.
- clocks: Must contain an entry for each entry in clock-names.
- clock-names: Shall be "saradc" for the converter-clock, and "apb_pclk" for
               the peripheral clock.
- vref-supply: The regulator supply ADC reference voltage.
- #io-channel-cells: Should be 1, see ../iio-bindings.txt

Example:
	saradc: saradc@2006c000 {
		compatible = "rockchip,saradc";
		reg = <0x2006c000 0x100>;
		interrupts = <GIC_SPI 26 IRQ_TYPE_LEVEL_HIGH>;
		clocks = <&cru SCLK_SARADC>, <&cru PCLK_SARADC>;
		clock-names = "saradc", "apb_pclk";
		#io-channel-cells = <1>;
		vref-supply = <&vcc18>;
	};
+8 −5
Original line number Diff line number Diff line
@@ -6,13 +6,13 @@
menu "Accelerometers"

config BMA180
	tristate "Bosch BMA180 3-Axis Accelerometer Driver"
	tristate "Bosch BMA180/BMA250 3-Axis Accelerometer Driver"
	depends on I2C
	select IIO_BUFFER
	select IIO_TRIGGERED_BUFFER
	help
	  Say Y here if you want to build a driver for the Bosch BMA180
	  triaxial acceleration sensor.
	  Say Y here if you want to build a driver for the Bosch BMA180 or
	  BMA250 triaxial acceleration sensor.

	  To compile this driver as a module, choose M here: the
	  module will be called bma180.
@@ -23,7 +23,9 @@ config BMC150_ACCEL
	select IIO_BUFFER
	select IIO_TRIGGERED_BUFFER
	help
	  Say yes here to build support for the Bosch BMC150 accelerometer.
	  Say yes here to build support for the following Bosch accelerometers:
	  BMC150, BMI055, BMA250E, BMA222E, BMA255, BMA280.

	  Currently this only supports the device via an i2c interface.

	  This is a combo module with both accelerometer and magnetometer.
@@ -97,7 +99,8 @@ config KXCJK1013
	select IIO_TRIGGERED_BUFFER
	help
	  Say Y here if you want to build a driver for the Kionix KXCJK-1013
	  triaxial acceleration sensor.
	  triaxial acceleration sensor. This driver also supports KXCJ9-1008
	  and KXTJ2-1009.

	  To compile this driver as a module, choose M here: the module will
	  be called kxcjk-1013.
+329 −147
Original line number Diff line number Diff line
@@ -3,9 +3,15 @@
 *
 * Copyright 2013 Oleksandr Kravchenko <x0199363@ti.com>
 *
 * Support for BMA250 (c) Peter Meerwald <pmeerw@pmeerw.net>
 *
 * This file is subject to the terms and conditions of version 2 of
 * the GNU General Public License.  See the file COPYING in the main
 * directory of this archive for more details.
 *
 * SPI is not supported by driver
 * BMA180: 7-bit I2C slave address 0x40 or 0x41
 * BMA250: 7-bit I2C slave address 0x18 or 0x19
 */

#include <linux/module.h>
@@ -26,9 +32,37 @@
#define BMA180_DRV_NAME "bma180"
#define BMA180_IRQ_NAME "bma180_event"

enum {
	BMA180,
	BMA250,
};

struct bma180_data;

struct bma180_part_info {
	const struct iio_chan_spec *channels;
	unsigned num_channels;
	const int *scale_table;
	unsigned num_scales;
	const int *bw_table;
	unsigned num_bw;

	u8 int_reset_reg, int_reset_mask;
	u8 sleep_reg, sleep_mask;
	u8 bw_reg, bw_mask;
	u8 scale_reg, scale_mask;
	u8 power_reg, power_mask, lowpower_val;
	u8 int_enable_reg, int_enable_mask;
	u8 softreset_reg;

	int (*chip_config)(struct bma180_data *data);
	void (*chip_disable)(struct bma180_data *data);
};

/* Register set */
#define BMA180_CHIP_ID		0x00 /* Need to distinguish BMA180 from other */
#define BMA180_ACC_X_LSB	0x02 /* First of 6 registers of accel data */
#define BMA180_TEMP		0x08
#define BMA180_CTRL_REG0	0x0d
#define BMA180_RESET		0x10
#define BMA180_BW_TCS		0x20
@@ -56,58 +90,74 @@
/* We have to write this value in reset register to do soft reset */
#define BMA180_RESET_VAL	0xb6

#define BMA_180_ID_REG_VAL	0x03
#define BMA180_ID_REG_VAL	0x03

/* Chip power modes */
#define BMA180_LOW_NOISE	0x00
#define BMA180_LOW_POWER	0x03

#define BMA180_LOW_NOISE_STR	"low_noise"
#define BMA180_LOW_POWER_STR	"low_power"

/* Defaults values */
#define BMA180_DEF_PMODE	0
#define BMA180_DEF_BW		20
#define BMA180_DEF_SCALE	2452

/* Available values for sysfs */
#define BMA180_FLP_FREQ_AVAILABLE \
	"10 20 40 75 150 300"
#define BMA180_SCALE_AVAILABLE \
	"0.001275 0.001863 0.002452 0.003727 0.004903 0.009709 0.019417"
#define BMA250_RANGE_REG	0x0f
#define BMA250_BW_REG		0x10
#define BMA250_POWER_REG	0x11
#define BMA250_RESET_REG	0x14
#define BMA250_INT_ENABLE_REG	0x17
#define BMA250_INT_MAP_REG	0x1a
#define BMA250_INT_RESET_REG	0x21

#define BMA250_RANGE_MASK	GENMASK(3, 0) /* Range of accel values */
#define BMA250_BW_MASK		GENMASK(4, 0) /* Accel bandwidth */
#define BMA250_SUSPEND_MASK	BIT(7) /* chip will sleep */
#define BMA250_LOWPOWER_MASK	BIT(6)
#define BMA250_DATA_INTEN_MASK	BIT(4)
#define BMA250_INT1_DATA_MASK	BIT(0)
#define BMA250_INT_RESET_MASK	BIT(7) /* Reset pending interrupts */

struct bma180_data {
	struct i2c_client *client;
	struct iio_trigger *trig;
	const struct bma180_part_info *part_info;
	struct mutex mutex;
	int sleep_state;
	bool sleep_state;
	int scale;
	int bw;
	int pmode;
	char *buff;
	bool pmode;
	u8 buff[16]; /* 3x 16-bit + 8-bit + padding + timestamp */
};

enum bma180_axis {
enum bma180_chan {
	AXIS_X,
	AXIS_Y,
	AXIS_Z,
	TEMP
};

static int bw_table[] = { 10, 20, 40, 75, 150, 300 }; /* Hz */
static int scale_table[] = { 1275, 1863, 2452, 3727, 4903, 9709, 19417 };
static int bma180_bw_table[] = { 10, 20, 40, 75, 150, 300 }; /* Hz */
static int bma180_scale_table[] = { 1275, 1863, 2452, 3727, 4903, 9709, 19417 };

static int bma250_bw_table[] = { 8, 16, 31, 63, 125, 250 }; /* Hz */
static int bma250_scale_table[] = { 0, 0, 0, 38344, 0, 76590, 0, 0, 153180, 0,
	0, 0, 306458 };

static int bma180_get_acc_reg(struct bma180_data *data, enum bma180_axis axis)
static int bma180_get_data_reg(struct bma180_data *data, enum bma180_chan chan)
{
	u8 reg = BMA180_ACC_X_LSB + axis * 2;
	int ret;

	if (data->sleep_state)
		return -EBUSY;

	ret = i2c_smbus_read_word_data(data->client, reg);
	switch (chan) {
	case TEMP:
		ret = i2c_smbus_read_byte_data(data->client, BMA180_TEMP);
		if (ret < 0)
			dev_err(&data->client->dev, "failed to read temp register\n");
		break;
	default:
		ret = i2c_smbus_read_word_data(data->client,
			BMA180_ACC_X_LSB + chan * 2);
		if (ret < 0)
			dev_err(&data->client->dev,
			"failed to read accel_%c registers\n", 'x' + axis);
				"failed to read accel_%c register\n",
				'x' + chan);
	}

	return ret;
}
@@ -125,7 +175,8 @@ static int bma180_set_bits(struct bma180_data *data, u8 reg, u8 mask, u8 val)

static int bma180_reset_intr(struct bma180_data *data)
{
	int ret = bma180_set_bits(data, BMA180_CTRL_REG0, BMA180_RESET_INT, 1);
	int ret = bma180_set_bits(data, data->part_info->int_reset_reg,
		data->part_info->int_reset_mask, 1);

	if (ret)
		dev_err(&data->client->dev, "failed to reset interrupt\n");
@@ -133,12 +184,10 @@ static int bma180_reset_intr(struct bma180_data *data)
	return ret;
}

static int bma180_set_new_data_intr_state(struct bma180_data *data, int state)
static int bma180_set_new_data_intr_state(struct bma180_data *data, bool state)
{
	u8 reg_val = state ? BMA180_NEW_DATA_INT : 0x00;
	int ret = i2c_smbus_write_byte_data(data->client, BMA180_CTRL_REG3,
			reg_val);

	int ret = bma180_set_bits(data, data->part_info->int_enable_reg,
			data->part_info->int_enable_mask, state);
	if (ret)
		goto err;
	ret = bma180_reset_intr(data);
@@ -153,9 +202,10 @@ static int bma180_set_new_data_intr_state(struct bma180_data *data, int state)
	return ret;
}

static int bma180_set_sleep_state(struct bma180_data *data, int state)
static int bma180_set_sleep_state(struct bma180_data *data, bool state)
{
	int ret = bma180_set_bits(data, BMA180_CTRL_REG0, BMA180_SLEEP, state);
	int ret = bma180_set_bits(data, data->part_info->sleep_reg,
		data->part_info->sleep_mask, state);

	if (ret) {
		dev_err(&data->client->dev,
@@ -167,7 +217,7 @@ static int bma180_set_sleep_state(struct bma180_data *data, int state)
	return 0;
}

static int bma180_set_ee_writing_state(struct bma180_data *data, int state)
static int bma180_set_ee_writing_state(struct bma180_data *data, bool state)
{
	int ret = bma180_set_bits(data, BMA180_CTRL_REG0, BMA180_EE_W, state);

@@ -185,10 +235,10 @@ static int bma180_set_bw(struct bma180_data *data, int val)
	if (data->sleep_state)
		return -EBUSY;

	for (i = 0; i < ARRAY_SIZE(bw_table); ++i) {
		if (bw_table[i] == val) {
			ret = bma180_set_bits(data,
					BMA180_BW_TCS, BMA180_BW, i);
	for (i = 0; i < data->part_info->num_bw; ++i) {
		if (data->part_info->bw_table[i] == val) {
			ret = bma180_set_bits(data, data->part_info->bw_reg,
				data->part_info->bw_mask, i);
			if (ret) {
				dev_err(&data->client->dev,
					"failed to set bandwidth\n");
@@ -209,10 +259,10 @@ static int bma180_set_scale(struct bma180_data *data, int val)
	if (data->sleep_state)
		return -EBUSY;

	for (i = 0; i < ARRAY_SIZE(scale_table); ++i)
		if (scale_table[i] == val) {
			ret = bma180_set_bits(data,
					BMA180_OFFSET_LSB1, BMA180_RANGE, i);
	for (i = 0; i < data->part_info->num_scales; ++i)
		if (data->part_info->scale_table[i] == val) {
			ret = bma180_set_bits(data, data->part_info->scale_reg,
				data->part_info->scale_mask, i);
			if (ret) {
				dev_err(&data->client->dev,
					"failed to set scale\n");
@@ -225,11 +275,11 @@ static int bma180_set_scale(struct bma180_data *data, int val)
	return -EINVAL;
}

static int bma180_set_pmode(struct bma180_data *data, int mode)
static int bma180_set_pmode(struct bma180_data *data, bool mode)
{
	u8 reg_val = mode ? BMA180_LOW_POWER : BMA180_LOW_NOISE;
	int ret = bma180_set_bits(data, BMA180_TCO_Z, BMA180_MODE_CONFIG,
			reg_val);
	u8 reg_val = mode ? data->part_info->lowpower_val : 0;
	int ret = bma180_set_bits(data, data->part_info->power_reg,
		data->part_info->power_mask, reg_val);

	if (ret) {
		dev_err(&data->client->dev, "failed to set power mode\n");
@@ -243,7 +293,7 @@ static int bma180_set_pmode(struct bma180_data *data, int mode)
static int bma180_soft_reset(struct bma180_data *data)
{
	int ret = i2c_smbus_write_byte_data(data->client,
			BMA180_RESET, BMA180_RESET_VAL);
		data->part_info->softreset_reg, BMA180_RESET_VAL);

	if (ret)
		dev_err(&data->client->dev, "failed to reset the chip\n");
@@ -257,57 +307,99 @@ static int bma180_chip_init(struct bma180_data *data)
	int ret = i2c_smbus_read_byte_data(data->client, BMA180_CHIP_ID);

	if (ret < 0)
		goto err;
	if (ret != BMA_180_ID_REG_VAL) {
		ret = -ENODEV;
		goto err;
	}
		return ret;
	if (ret != BMA180_ID_REG_VAL)
		return -ENODEV;

	ret = bma180_soft_reset(data);
	if (ret)
		goto err;
		return ret;
	/*
	 * No serial transaction should occur within minimum 10 us
	 * after soft_reset command
	 */
	msleep(20);

	ret = bma180_set_bits(data, BMA180_CTRL_REG0, BMA180_DIS_WAKE_UP, 1);
	ret = bma180_set_new_data_intr_state(data, false);
	if (ret)
		return ret;

	return bma180_set_pmode(data, false);
}

static int bma180_chip_config(struct bma180_data *data)
{
	int ret = bma180_chip_init(data);

	if (ret)
		goto err;
	ret = bma180_set_ee_writing_state(data, 1);
	ret = bma180_set_bits(data, BMA180_CTRL_REG0, BMA180_DIS_WAKE_UP, 1);
	if (ret)
		goto err;
	ret = bma180_set_new_data_intr_state(data, 0);
	ret = bma180_set_ee_writing_state(data, true);
	if (ret)
		goto err;
	ret = bma180_set_bits(data, BMA180_OFFSET_LSB1, BMA180_SMP_SKIP, 1);
	if (ret)
		goto err;
	ret = bma180_set_pmode(data, BMA180_DEF_PMODE);
	ret = bma180_set_bw(data, 20); /* 20 Hz */
	if (ret)
		goto err;
	ret = bma180_set_scale(data, 2452); /* 2 G */
	if (ret)
		goto err;

	return 0;

err:
	dev_err(&data->client->dev, "failed to config the chip\n");
	return ret;
}

static int bma250_chip_config(struct bma180_data *data)
{
	int ret = bma180_chip_init(data);

	if (ret)
		goto err;
	ret = bma180_set_bw(data, 16); /* 16 Hz */
	if (ret)
		goto err;
	ret = bma180_set_bw(data, BMA180_DEF_BW);
	ret = bma180_set_scale(data, 38344); /* 2 G */
	if (ret)
		goto err;
	ret = bma180_set_scale(data, BMA180_DEF_SCALE);
	ret = bma180_set_bits(data, BMA250_INT_MAP_REG,
		BMA250_INT1_DATA_MASK, 1);
	if (ret)
		goto err;

	return 0;

err:
	dev_err(&data->client->dev, "failed to init the chip\n");
	dev_err(&data->client->dev, "failed to config the chip\n");
	return ret;
}

static void bma180_chip_disable(struct bma180_data *data)
{
	if (bma180_set_new_data_intr_state(data, 0))
	if (bma180_set_new_data_intr_state(data, false))
		goto err;
	if (bma180_set_ee_writing_state(data, 0))
	if (bma180_set_ee_writing_state(data, false))
		goto err;
	if (bma180_set_sleep_state(data, true))
		goto err;

	return;

err:
	dev_err(&data->client->dev, "failed to disable the chip\n");
}

static void bma250_chip_disable(struct bma180_data *data)
{
	if (bma180_set_new_data_intr_state(data, false))
		goto err;
	if (bma180_set_sleep_state(data, 1))
	if (bma180_set_sleep_state(data, true))
		goto err;

	return;
@@ -316,13 +408,51 @@ static void bma180_chip_disable(struct bma180_data *data)
	dev_err(&data->client->dev, "failed to disable the chip\n");
}

static IIO_CONST_ATTR(in_accel_filter_low_pass_3db_frequency_available,
		BMA180_FLP_FREQ_AVAILABLE);
static IIO_CONST_ATTR(in_accel_scale_available, BMA180_SCALE_AVAILABLE);
static ssize_t bma180_show_avail(char *buf, const int *vals, unsigned n,
				 bool micros)
{
	size_t len = 0;
	int i;

	for (i = 0; i < n; i++) {
		if (!vals[i])
			continue;
		len += scnprintf(buf + len, PAGE_SIZE - len,
			micros ? "0.%06d " : "%d ", vals[i]);
	}
	buf[len - 1] = '\n';

	return len;
}

static ssize_t bma180_show_filter_freq_avail(struct device *dev,
				struct device_attribute *attr, char *buf)
{
	struct bma180_data *data = iio_priv(dev_to_iio_dev(dev));

	return bma180_show_avail(buf, data->part_info->bw_table,
		data->part_info->num_bw, false);
}

static ssize_t bma180_show_scale_avail(struct device *dev,
				struct device_attribute *attr, char *buf)
{
	struct bma180_data *data = iio_priv(dev_to_iio_dev(dev));

	return bma180_show_avail(buf, data->part_info->scale_table,
		data->part_info->num_scales, true);
}

static IIO_DEVICE_ATTR(in_accel_filter_low_pass_3db_frequency_available,
	S_IRUGO, bma180_show_filter_freq_avail, NULL, 0);

static IIO_DEVICE_ATTR(in_accel_scale_available,
	S_IRUGO, bma180_show_scale_avail, NULL, 0);

static struct attribute *bma180_attributes[] = {
	&iio_const_attr_in_accel_filter_low_pass_3db_frequency_available.dev_attr.attr,
	&iio_const_attr_in_accel_scale_available.dev_attr.attr,
	&iio_dev_attr_in_accel_filter_low_pass_3db_frequency_available.
		dev_attr.attr,
	&iio_dev_attr_in_accel_scale_available.dev_attr.attr,
	NULL,
};

@@ -340,22 +470,35 @@ static int bma180_read_raw(struct iio_dev *indio_dev,
	switch (mask) {
	case IIO_CHAN_INFO_RAW:
		mutex_lock(&data->mutex);
		if (iio_buffer_enabled(indio_dev))
			ret = -EBUSY;
		else
			ret = bma180_get_acc_reg(data, chan->scan_index);
		if (iio_buffer_enabled(indio_dev)) {
			mutex_unlock(&data->mutex);
			return -EBUSY;
		}
		ret = bma180_get_data_reg(data, chan->scan_index);
		mutex_unlock(&data->mutex);
		if (ret < 0)
			return ret;
		*val = (s16)ret >> chan->scan_type.shift;
		*val = sign_extend32(ret >> chan->scan_type.shift,
			chan->scan_type.realbits - 1);
		return IIO_VAL_INT;
	case IIO_CHAN_INFO_LOW_PASS_FILTER_3DB_FREQUENCY:
		*val = data->bw;
		return IIO_VAL_INT;
	case IIO_CHAN_INFO_SCALE:
		switch (chan->type) {
		case IIO_ACCEL:
			*val = 0;
			*val2 = data->scale;
			return IIO_VAL_INT_PLUS_MICRO;
		case IIO_TEMP:
			*val = 500;
			return IIO_VAL_INT;
		default:
			return -EINVAL;
		}
	case IIO_CHAN_INFO_OFFSET:
		*val = 48; /* 0 LSB @ 24 degree C */
		return IIO_VAL_INT;
	default:
		return -EINVAL;
	}
@@ -387,33 +530,14 @@ static int bma180_write_raw(struct iio_dev *indio_dev,
	}
}

static int bma180_update_scan_mode(struct iio_dev *indio_dev,
		const unsigned long *scan_mask)
{
	struct bma180_data *data = iio_priv(indio_dev);

	if (data->buff)
		devm_kfree(&indio_dev->dev, data->buff);
	data->buff = devm_kzalloc(&indio_dev->dev,
			indio_dev->scan_bytes, GFP_KERNEL);
	if (!data->buff)
		return -ENOMEM;

	return 0;
}

static const struct iio_info bma180_info = {
	.attrs			= &bma180_attrs_group,
	.read_raw		= bma180_read_raw,
	.write_raw		= bma180_write_raw,
	.update_scan_mode	= bma180_update_scan_mode,
	.driver_module		= THIS_MODULE,
};

static const char * const bma180_power_modes[] = {
	BMA180_LOW_NOISE_STR,
	BMA180_LOW_POWER_STR,
};
static const char * const bma180_power_modes[] = { "low_noise", "low_power" };

static int bma180_get_power_mode(struct iio_dev *indio_dev,
		const struct iio_chan_spec *chan)
@@ -449,7 +573,7 @@ static const struct iio_chan_spec_ext_info bma180_ext_info[] = {
	{ },
};

#define BMA180_CHANNEL(_axis) {					\
#define BMA180_ACC_CHANNEL(_axis, _bits) {				\
	.type = IIO_ACCEL,						\
	.modified = 1,							\
	.channel2 = IIO_MOD_##_axis,					\
@@ -459,18 +583,70 @@ static const struct iio_chan_spec_ext_info bma180_ext_info[] = {
	.scan_index = AXIS_##_axis,					\
	.scan_type = {							\
		.sign = 's',						\
		.realbits = 14,						\
		.realbits = _bits,					\
		.storagebits = 16,					\
		.shift = 2,						\
		.shift = 16 - _bits,					\
	},								\
	.ext_info = bma180_ext_info,					\
}

#define BMA180_TEMP_CHANNEL {						\
	.type = IIO_TEMP,						\
	.info_mask_separate = BIT(IIO_CHAN_INFO_RAW) |			\
		BIT(IIO_CHAN_INFO_SCALE) | BIT(IIO_CHAN_INFO_OFFSET),	\
	.scan_index = TEMP,						\
	.scan_type = {							\
		.sign = 's',						\
		.realbits = 8,						\
		.storagebits = 16,					\
	},								\
}

static const struct iio_chan_spec bma180_channels[] = {
	BMA180_CHANNEL(X),
	BMA180_CHANNEL(Y),
	BMA180_CHANNEL(Z),
	IIO_CHAN_SOFT_TIMESTAMP(3),
	BMA180_ACC_CHANNEL(X, 14),
	BMA180_ACC_CHANNEL(Y, 14),
	BMA180_ACC_CHANNEL(Z, 14),
	BMA180_TEMP_CHANNEL,
	IIO_CHAN_SOFT_TIMESTAMP(4),
};

static const struct iio_chan_spec bma250_channels[] = {
	BMA180_ACC_CHANNEL(X, 10),
	BMA180_ACC_CHANNEL(Y, 10),
	BMA180_ACC_CHANNEL(Z, 10),
	BMA180_TEMP_CHANNEL,
	IIO_CHAN_SOFT_TIMESTAMP(4),
};

static const struct bma180_part_info bma180_part_info[] = {
	[BMA180] = {
		bma180_channels, ARRAY_SIZE(bma180_channels),
		bma180_scale_table, ARRAY_SIZE(bma180_scale_table),
		bma180_bw_table, ARRAY_SIZE(bma180_bw_table),
		BMA180_CTRL_REG0, BMA180_RESET_INT,
		BMA180_CTRL_REG0, BMA180_SLEEP,
		BMA180_BW_TCS, BMA180_BW,
		BMA180_OFFSET_LSB1, BMA180_RANGE,
		BMA180_TCO_Z, BMA180_MODE_CONFIG, BMA180_LOW_POWER,
		BMA180_CTRL_REG3, BMA180_NEW_DATA_INT,
		BMA180_RESET,
		bma180_chip_config,
		bma180_chip_disable,
	},
	[BMA250] = {
		bma250_channels, ARRAY_SIZE(bma250_channels),
		bma250_scale_table, ARRAY_SIZE(bma250_scale_table),
		bma250_bw_table, ARRAY_SIZE(bma250_bw_table),
		BMA250_INT_RESET_REG, BMA250_INT_RESET_MASK,
		BMA250_POWER_REG, BMA250_SUSPEND_MASK,
		BMA250_BW_REG, BMA250_BW_MASK,
		BMA250_RANGE_REG, BMA250_RANGE_MASK,
		BMA250_POWER_REG, BMA250_LOWPOWER_MASK, 1,
		BMA250_INT_ENABLE_REG, BMA250_DATA_INTEN_MASK,
		BMA250_RESET_REG,
		bma250_chip_config,
		bma250_chip_disable,
	},
};

static irqreturn_t bma180_trigger_handler(int irq, void *p)
@@ -485,13 +661,14 @@ static irqreturn_t bma180_trigger_handler(int irq, void *p)

	for_each_set_bit(bit, indio_dev->buffer->scan_mask,
			 indio_dev->masklength) {
		ret = bma180_get_acc_reg(data, bit);
		ret = bma180_get_data_reg(data, bit);
		if (ret < 0) {
			mutex_unlock(&data->mutex);
			goto err;
		}
		((s16 *)data->buff)[i++] = ret;
	}

	mutex_unlock(&data->mutex);

	iio_push_to_buffers_with_timestamp(indio_dev, data->buff, time_ns);
@@ -529,7 +706,6 @@ static int bma180_probe(struct i2c_client *client,
{
	struct bma180_data *data;
	struct iio_dev *indio_dev;
	struct iio_trigger *trig;
	int ret;

	indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*data));
@@ -539,43 +715,45 @@ static int bma180_probe(struct i2c_client *client,
	data = iio_priv(indio_dev);
	i2c_set_clientdata(client, indio_dev);
	data->client = client;
	data->part_info = &bma180_part_info[id->driver_data];

	ret = bma180_chip_init(data);
	ret = data->part_info->chip_config(data);
	if (ret < 0)
		goto err_chip_disable;

	mutex_init(&data->mutex);

	indio_dev->dev.parent = &client->dev;
	indio_dev->channels = bma180_channels;
	indio_dev->num_channels = ARRAY_SIZE(bma180_channels);
	indio_dev->name = BMA180_DRV_NAME;
	indio_dev->channels = data->part_info->channels;
	indio_dev->num_channels = data->part_info->num_channels;
	indio_dev->name = id->name;
	indio_dev->modes = INDIO_DIRECT_MODE;
	indio_dev->info = &bma180_info;

	trig = iio_trigger_alloc("%s-dev%d", indio_dev->name, indio_dev->id);
	if (!trig) {
	if (client->irq > 0) {
		data->trig = iio_trigger_alloc("%s-dev%d", indio_dev->name,
			indio_dev->id);
		if (!data->trig) {
			ret = -ENOMEM;
			goto err_chip_disable;
		}

		ret = devm_request_irq(&client->dev, client->irq,
			iio_trigger_generic_data_rdy_poll,
			IRQF_TRIGGER_RISING, BMA180_IRQ_NAME, trig);
			iio_trigger_generic_data_rdy_poll, IRQF_TRIGGER_RISING,
			"bma180_event", data->trig);
		if (ret) {
			dev_err(&client->dev, "unable to request IRQ\n");
			goto err_trigger_free;
		}

	trig->dev.parent = &client->dev;
	trig->ops = &bma180_trigger_ops;
	iio_trigger_set_drvdata(trig, indio_dev);
	data->trig = trig;
	indio_dev->trig = trig;
		data->trig->dev.parent = &client->dev;
		data->trig->ops = &bma180_trigger_ops;
		iio_trigger_set_drvdata(data->trig, indio_dev);
		indio_dev->trig = data->trig;

	ret = iio_trigger_register(trig);
		ret = iio_trigger_register(data->trig);
		if (ret)
			goto err_trigger_free;
	}

	ret = iio_triggered_buffer_setup(indio_dev, NULL,
			bma180_trigger_handler, NULL);
@@ -595,11 +773,12 @@ static int bma180_probe(struct i2c_client *client,
err_buffer_cleanup:
	iio_triggered_buffer_cleanup(indio_dev);
err_trigger_unregister:
	iio_trigger_unregister(trig);
	if (data->trig)
		iio_trigger_unregister(data->trig);
err_trigger_free:
	iio_trigger_free(trig);
	iio_trigger_free(data->trig);
err_chip_disable:
	bma180_chip_disable(data);
	data->part_info->chip_disable(data);

	return ret;
}
@@ -611,11 +790,13 @@ static int bma180_remove(struct i2c_client *client)

	iio_device_unregister(indio_dev);
	iio_triggered_buffer_cleanup(indio_dev);
	if (data->trig) {
		iio_trigger_unregister(data->trig);
		iio_trigger_free(data->trig);
	}

	mutex_lock(&data->mutex);
	bma180_chip_disable(data);
	data->part_info->chip_disable(data);
	mutex_unlock(&data->mutex);

	return 0;
@@ -629,7 +810,7 @@ static int bma180_suspend(struct device *dev)
	int ret;

	mutex_lock(&data->mutex);
	ret = bma180_set_sleep_state(data, 1);
	ret = bma180_set_sleep_state(data, true);
	mutex_unlock(&data->mutex);

	return ret;
@@ -642,7 +823,7 @@ static int bma180_resume(struct device *dev)
	int ret;

	mutex_lock(&data->mutex);
	ret = bma180_set_sleep_state(data, 0);
	ret = bma180_set_sleep_state(data, false);
	mutex_unlock(&data->mutex);

	return ret;
@@ -654,27 +835,28 @@ static SIMPLE_DEV_PM_OPS(bma180_pm_ops, bma180_suspend, bma180_resume);
#define BMA180_PM_OPS NULL
#endif

static struct i2c_device_id bma180_id[] = {
	{ BMA180_DRV_NAME, 0 },
static struct i2c_device_id bma180_ids[] = {
	{ "bma180", BMA180 },
	{ "bma250", BMA250 },
	{ }
};

MODULE_DEVICE_TABLE(i2c, bma180_id);
MODULE_DEVICE_TABLE(i2c, bma180_ids);

static struct i2c_driver bma180_driver = {
	.driver = {
		.name	= BMA180_DRV_NAME,
		.name	= "bma180",
		.owner	= THIS_MODULE,
		.pm	= BMA180_PM_OPS,
	},
	.probe		= bma180_probe,
	.remove		= bma180_remove,
	.id_table	= bma180_id,
	.id_table	= bma180_ids,
};

module_i2c_driver(bma180_driver);

MODULE_AUTHOR("Kravchenko Oleksandr <x0199363@ti.com>");
MODULE_AUTHOR("Texas Instruments, Inc.");
MODULE_DESCRIPTION("Bosch BMA180 triaxial acceleration sensor");
MODULE_DESCRIPTION("Bosch BMA180/BMA250 triaxial acceleration sensor");
MODULE_LICENSE("GPL");
Loading