From 4c73b809a99fc4df39fb18664288921b052f9649 Mon Sep 17 00:00:00 2001 From: Richard Lai Date: Wed, 14 Feb 2018 01:08:35 +0000 Subject: [PATCH 01/47] iio: chemical: ccs811: Renamed resistance member in ccs811_reading struct MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The resistance member in ccs811_reading struct is an unsigned 16-bit integer variable used to store RAW_DATA register bytes read from CCS811. It is kind of misleading to name this struct member as resistance. About the RAW_DATA register bytes, the CCS811 datasheet states that: ----- Two byte read only register which contains the latest readings from the sense resistor. The most significant 6 bits of the Byte 0 contain the value of the current through the sensor (0μA to 63μA). The lower 10 bits contain (as computed from the ADC) the readings of the voltage across the sensor with the selected current (1023 = 1.65V)" ----- Hence, the RAW_DATA register byte contains information about electric current and voltage of the CCS811 sensor. Calling this struct member 'resistance' is kind of misleading, although both electric current and voltage are needed to calculate the electrical resistance of the sensor using Ohm's law, V = I x R, in which a new channel type of IIO_RESISTANCE may be added to the driver in the future. Signed-off-by: Richard Lai Signed-off-by: Jonathan Cameron --- drivers/iio/chemical/ccs811.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/iio/chemical/ccs811.c b/drivers/iio/chemical/ccs811.c index cfaf86b248d9..e092ffe1431e 100644 --- a/drivers/iio/chemical/ccs811.c +++ b/drivers/iio/chemical/ccs811.c @@ -69,7 +69,7 @@ struct ccs811_reading { __be16 voc; u8 status; u8 error; - __be16 resistance; + __be16 raw_data; } __attribute__((__packed__)); struct ccs811_data { @@ -210,12 +210,12 @@ static int ccs811_read_raw(struct iio_dev *indio_dev, switch (chan->type) { case IIO_VOLTAGE: - *val = be16_to_cpu(data->buffer.resistance) & + *val = be16_to_cpu(data->buffer.raw_data) & CCS811_VOLTAGE_MASK; ret = IIO_VAL_INT; break; case IIO_CURRENT: - *val = be16_to_cpu(data->buffer.resistance) >> 10; + *val = be16_to_cpu(data->buffer.raw_data) >> 10; ret = IIO_VAL_INT; break; case IIO_CONCENTRATION: From adc18ba9061eade402b8d84c6bbcb5ca87add8da Mon Sep 17 00:00:00 2001 From: Quentin Schulz Date: Mon, 19 Feb 2018 13:47:36 +0100 Subject: [PATCH 02/47] iio: adc: axp20x_adc: remove !! in favor of ternary condition !!'s behaviour isn't that obvious and sparse complained about it, so let's replace it with a ternary condition. Signed-off-by: Quentin Schulz Signed-off-by: Jonathan Cameron --- drivers/iio/adc/axp20x_adc.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/iio/adc/axp20x_adc.c b/drivers/iio/adc/axp20x_adc.c index 7cdb8bc8cde6..5be789269353 100644 --- a/drivers/iio/adc/axp20x_adc.c +++ b/drivers/iio/adc/axp20x_adc.c @@ -445,7 +445,7 @@ static int axp20x_adc_offset_voltage(struct iio_dev *indio_dev, int channel, return -EINVAL; } - *val = !!(*val) * 700000; + *val = *val ? 700000 : 0; return IIO_VAL_INT; } @@ -542,15 +542,17 @@ static int axp20x_write_raw(struct iio_dev *indio_dev, if (val != 0 && val != 700000) return -EINVAL; + val = val ? 1 : 0; + switch (chan->channel) { case AXP20X_GPIO0_V: reg = AXP20X_GPIO10_IN_RANGE_GPIO0; - regval = AXP20X_GPIO10_IN_RANGE_GPIO0_VAL(!!val); + regval = AXP20X_GPIO10_IN_RANGE_GPIO0_VAL(val); break; case AXP20X_GPIO1_V: reg = AXP20X_GPIO10_IN_RANGE_GPIO1; - regval = AXP20X_GPIO10_IN_RANGE_GPIO1_VAL(!!val); + regval = AXP20X_GPIO10_IN_RANGE_GPIO1_VAL(val); break; default: From 1b3079a721106a441dcbd14c55908ab406324c66 Mon Sep 17 00:00:00 2001 From: Andy Shevchenko Date: Thu, 22 Feb 2018 20:58:58 +0200 Subject: [PATCH 03/47] iio: accel: bmc150: Remove redundant __func__ in dev_dbg() Dynamic debug has a run time knob to enable function name printing. Remove this from dev_dbg() calls. Furthermore, functional tracing when enabled can show what function is called, therefore remove empty dev_dbg() calls. Signed-off-by: Andy Shevchenko Signed-off-by: Jonathan Cameron --- drivers/iio/accel/bmc150-accel-core.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/drivers/iio/accel/bmc150-accel-core.c b/drivers/iio/accel/bmc150-accel-core.c index 870f92ef61c2..208f2d9f0e8a 100644 --- a/drivers/iio/accel/bmc150-accel-core.c +++ b/drivers/iio/accel/bmc150-accel-core.c @@ -336,8 +336,7 @@ static int bmc150_accel_update_slope(struct bmc150_accel_data *data) return ret; } - dev_dbg(dev, "%s: %x %x\n", __func__, data->slope_thres, - data->slope_dur); + dev_dbg(dev, "%x %x\n", data->slope_thres, data->slope_dur); return ret; } @@ -1716,7 +1715,6 @@ static int bmc150_accel_runtime_suspend(struct device *dev) struct bmc150_accel_data *data = iio_priv(indio_dev); int ret; - dev_dbg(dev, __func__); ret = bmc150_accel_set_mode(data, BMC150_ACCEL_SLEEP_MODE_SUSPEND, 0); if (ret < 0) return -EAGAIN; @@ -1731,8 +1729,6 @@ static int bmc150_accel_runtime_resume(struct device *dev) int ret; int sleep_val; - dev_dbg(dev, __func__); - ret = bmc150_accel_set_mode(data, BMC150_ACCEL_SLEEP_MODE_NORMAL, 0); if (ret < 0) return ret; From c50fadeff758d4cc6e1ed196f776ae3016b3e021 Mon Sep 17 00:00:00 2001 From: Dan Carpenter Date: Thu, 22 Feb 2018 12:14:53 +0300 Subject: [PATCH 04/47] iio temperature/mlx90632: silence a static checker warning This shouldn't affect runtime at all, but Smatch complains that we should check if mlx90632_read_ambient_raw() otherwise we "ambient_new_raw" can be uninitialized. drivers/iio/temperature/mlx90632.c:509 mlx90632_calc_ambient_dsp105() error: uninitialized symbol 'ambient_new_raw'. Signed-off-by: Dan Carpenter Acked-by: Crt Mori Signed-off-by: Jonathan Cameron --- drivers/iio/temperature/mlx90632.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/iio/temperature/mlx90632.c b/drivers/iio/temperature/mlx90632.c index d695ab97d27f..9851311aa3fd 100644 --- a/drivers/iio/temperature/mlx90632.c +++ b/drivers/iio/temperature/mlx90632.c @@ -506,6 +506,8 @@ static int mlx90632_calc_ambient_dsp105(struct mlx90632_data *data, int *val) ret = mlx90632_read_ambient_raw(data->regmap, &ambient_new_raw, &ambient_old_raw); + if (ret < 0) + return ret; *val = mlx90632_calc_temp_ambient(ambient_new_raw, ambient_old_raw, PT, PR, PG, PO, Gb); return ret; From 6de543e31d187a6cc4944c76b6234aa1c8f79383 Mon Sep 17 00:00:00 2001 From: Rodrigo Siqueira Date: Wed, 21 Feb 2018 16:54:35 -0300 Subject: [PATCH 05/47] staging:iio:meter: Add name to function definition arguments This patch fixes the checkpatch.pl warning: drivers/staging/iio/meter/ade7854.h:157: WARNING: function definition argument 'struct device *' should also have an identifier name... This commit adds arguments names to the signature declared in the ade7854_state struct. For consistency reason, It also renames all arguments in function definitions. Signed-off-by: Rodrigo Siqueira Signed-off-by: Jonathan Cameron --- drivers/staging/iio/meter/ade7754.c | 6 +++--- drivers/staging/iio/meter/ade7854-i2c.c | 28 ++++++++++++------------- drivers/staging/iio/meter/ade7854-spi.c | 28 ++++++++++++------------- drivers/staging/iio/meter/ade7854.h | 28 ++++++++++++------------- 4 files changed, 45 insertions(+), 45 deletions(-) diff --git a/drivers/staging/iio/meter/ade7754.c b/drivers/staging/iio/meter/ade7754.c index 3a1e342d75fb..9aa067736715 100644 --- a/drivers/staging/iio/meter/ade7754.c +++ b/drivers/staging/iio/meter/ade7754.c @@ -132,7 +132,7 @@ static int ade7754_spi_write_reg_8(struct device *dev, u8 reg_address, u8 val) } static int ade7754_spi_write_reg_16(struct device *dev, - u8 reg_address, u16 value) + u8 reg_address, u16 val) { int ret; struct iio_dev *indio_dev = dev_to_iio_dev(dev); @@ -140,8 +140,8 @@ static int ade7754_spi_write_reg_16(struct device *dev, mutex_lock(&st->buf_lock); st->tx[0] = ADE7754_WRITE_REG(reg_address); - st->tx[1] = (value >> 8) & 0xFF; - st->tx[2] = value & 0xFF; + st->tx[1] = (val >> 8) & 0xFF; + st->tx[2] = val & 0xFF; ret = spi_write(st->us, st->tx, 3); mutex_unlock(&st->buf_lock); diff --git a/drivers/staging/iio/meter/ade7854-i2c.c b/drivers/staging/iio/meter/ade7854-i2c.c index 8106f8cceeab..317e4f0d8176 100644 --- a/drivers/staging/iio/meter/ade7854-i2c.c +++ b/drivers/staging/iio/meter/ade7854-i2c.c @@ -17,7 +17,7 @@ static int ade7854_i2c_write_reg_8(struct device *dev, u16 reg_address, - u8 value) + u8 val) { int ret; struct iio_dev *indio_dev = dev_to_iio_dev(dev); @@ -26,7 +26,7 @@ static int ade7854_i2c_write_reg_8(struct device *dev, mutex_lock(&st->buf_lock); st->tx[0] = (reg_address >> 8) & 0xFF; st->tx[1] = reg_address & 0xFF; - st->tx[2] = value; + st->tx[2] = val; ret = i2c_master_send(st->i2c, st->tx, 3); mutex_unlock(&st->buf_lock); @@ -36,7 +36,7 @@ static int ade7854_i2c_write_reg_8(struct device *dev, static int ade7854_i2c_write_reg_16(struct device *dev, u16 reg_address, - u16 value) + u16 val) { int ret; struct iio_dev *indio_dev = dev_to_iio_dev(dev); @@ -45,8 +45,8 @@ static int ade7854_i2c_write_reg_16(struct device *dev, mutex_lock(&st->buf_lock); st->tx[0] = (reg_address >> 8) & 0xFF; st->tx[1] = reg_address & 0xFF; - st->tx[2] = (value >> 8) & 0xFF; - st->tx[3] = value & 0xFF; + st->tx[2] = (val >> 8) & 0xFF; + st->tx[3] = val & 0xFF; ret = i2c_master_send(st->i2c, st->tx, 4); mutex_unlock(&st->buf_lock); @@ -56,7 +56,7 @@ static int ade7854_i2c_write_reg_16(struct device *dev, static int ade7854_i2c_write_reg_24(struct device *dev, u16 reg_address, - u32 value) + u32 val) { int ret; struct iio_dev *indio_dev = dev_to_iio_dev(dev); @@ -65,9 +65,9 @@ static int ade7854_i2c_write_reg_24(struct device *dev, mutex_lock(&st->buf_lock); st->tx[0] = (reg_address >> 8) & 0xFF; st->tx[1] = reg_address & 0xFF; - st->tx[2] = (value >> 16) & 0xFF; - st->tx[3] = (value >> 8) & 0xFF; - st->tx[4] = value & 0xFF; + st->tx[2] = (val >> 16) & 0xFF; + st->tx[3] = (val >> 8) & 0xFF; + st->tx[4] = val & 0xFF; ret = i2c_master_send(st->i2c, st->tx, 5); mutex_unlock(&st->buf_lock); @@ -77,7 +77,7 @@ static int ade7854_i2c_write_reg_24(struct device *dev, static int ade7854_i2c_write_reg_32(struct device *dev, u16 reg_address, - u32 value) + u32 val) { int ret; struct iio_dev *indio_dev = dev_to_iio_dev(dev); @@ -86,10 +86,10 @@ static int ade7854_i2c_write_reg_32(struct device *dev, mutex_lock(&st->buf_lock); st->tx[0] = (reg_address >> 8) & 0xFF; st->tx[1] = reg_address & 0xFF; - st->tx[2] = (value >> 24) & 0xFF; - st->tx[3] = (value >> 16) & 0xFF; - st->tx[4] = (value >> 8) & 0xFF; - st->tx[5] = value & 0xFF; + st->tx[2] = (val >> 24) & 0xFF; + st->tx[3] = (val >> 16) & 0xFF; + st->tx[4] = (val >> 8) & 0xFF; + st->tx[5] = val & 0xFF; ret = i2c_master_send(st->i2c, st->tx, 6); mutex_unlock(&st->buf_lock); diff --git a/drivers/staging/iio/meter/ade7854-spi.c b/drivers/staging/iio/meter/ade7854-spi.c index 63e200ffd1f2..72eddfec21f7 100644 --- a/drivers/staging/iio/meter/ade7854-spi.c +++ b/drivers/staging/iio/meter/ade7854-spi.c @@ -17,7 +17,7 @@ static int ade7854_spi_write_reg_8(struct device *dev, u16 reg_address, - u8 value) + u8 val) { int ret; struct iio_dev *indio_dev = dev_to_iio_dev(dev); @@ -32,7 +32,7 @@ static int ade7854_spi_write_reg_8(struct device *dev, st->tx[0] = ADE7854_WRITE_REG; st->tx[1] = (reg_address >> 8) & 0xFF; st->tx[2] = reg_address & 0xFF; - st->tx[3] = value & 0xFF; + st->tx[3] = val & 0xFF; ret = spi_sync_transfer(st->spi, &xfer, 1); mutex_unlock(&st->buf_lock); @@ -42,7 +42,7 @@ static int ade7854_spi_write_reg_8(struct device *dev, static int ade7854_spi_write_reg_16(struct device *dev, u16 reg_address, - u16 value) + u16 val) { int ret; struct iio_dev *indio_dev = dev_to_iio_dev(dev); @@ -57,8 +57,8 @@ static int ade7854_spi_write_reg_16(struct device *dev, st->tx[0] = ADE7854_WRITE_REG; st->tx[1] = (reg_address >> 8) & 0xFF; st->tx[2] = reg_address & 0xFF; - st->tx[3] = (value >> 8) & 0xFF; - st->tx[4] = value & 0xFF; + st->tx[3] = (val >> 8) & 0xFF; + st->tx[4] = val & 0xFF; ret = spi_sync_transfer(st->spi, &xfer, 1); mutex_unlock(&st->buf_lock); @@ -68,7 +68,7 @@ static int ade7854_spi_write_reg_16(struct device *dev, static int ade7854_spi_write_reg_24(struct device *dev, u16 reg_address, - u32 value) + u32 val) { int ret; struct iio_dev *indio_dev = dev_to_iio_dev(dev); @@ -83,9 +83,9 @@ static int ade7854_spi_write_reg_24(struct device *dev, st->tx[0] = ADE7854_WRITE_REG; st->tx[1] = (reg_address >> 8) & 0xFF; st->tx[2] = reg_address & 0xFF; - st->tx[3] = (value >> 16) & 0xFF; - st->tx[4] = (value >> 8) & 0xFF; - st->tx[5] = value & 0xFF; + st->tx[3] = (val >> 16) & 0xFF; + st->tx[4] = (val >> 8) & 0xFF; + st->tx[5] = val & 0xFF; ret = spi_sync_transfer(st->spi, &xfer, 1); mutex_unlock(&st->buf_lock); @@ -95,7 +95,7 @@ static int ade7854_spi_write_reg_24(struct device *dev, static int ade7854_spi_write_reg_32(struct device *dev, u16 reg_address, - u32 value) + u32 val) { int ret; struct iio_dev *indio_dev = dev_to_iio_dev(dev); @@ -110,10 +110,10 @@ static int ade7854_spi_write_reg_32(struct device *dev, st->tx[0] = ADE7854_WRITE_REG; st->tx[1] = (reg_address >> 8) & 0xFF; st->tx[2] = reg_address & 0xFF; - st->tx[3] = (value >> 24) & 0xFF; - st->tx[4] = (value >> 16) & 0xFF; - st->tx[5] = (value >> 8) & 0xFF; - st->tx[6] = value & 0xFF; + st->tx[3] = (val >> 24) & 0xFF; + st->tx[4] = (val >> 16) & 0xFF; + st->tx[5] = (val >> 8) & 0xFF; + st->tx[6] = val & 0xFF; ret = spi_sync_transfer(st->spi, &xfer, 1); mutex_unlock(&st->buf_lock); diff --git a/drivers/staging/iio/meter/ade7854.h b/drivers/staging/iio/meter/ade7854.h index c27247a7891a..a82d38224cbd 100644 --- a/drivers/staging/iio/meter/ade7854.h +++ b/drivers/staging/iio/meter/ade7854.h @@ -152,20 +152,20 @@ * @rx: receive buffer **/ struct ade7854_state { - struct spi_device *spi; - struct i2c_client *i2c; - int (*read_reg_8)(struct device *, u16, u8 *); - int (*read_reg_16)(struct device *, u16, u16 *); - int (*read_reg_24)(struct device *, u16, u32 *); - int (*read_reg_32)(struct device *, u16, u32 *); - int (*write_reg_8)(struct device *, u16, u8); - int (*write_reg_16)(struct device *, u16, u16); - int (*write_reg_24)(struct device *, u16, u32); - int (*write_reg_32)(struct device *, u16, u32); - int irq; - struct mutex buf_lock; - u8 tx[ADE7854_MAX_TX] ____cacheline_aligned; - u8 rx[ADE7854_MAX_RX]; + struct spi_device *spi; + struct i2c_client *i2c; + int (*read_reg_8)(struct device *dev, u16 reg_address, u8 *val); + int (*read_reg_16)(struct device *dev, u16 reg_address, u16 *val); + int (*read_reg_24)(struct device *dev, u16 reg_address, u32 *val); + int (*read_reg_32)(struct device *dev, u16 reg_address, u32 *val); + int (*write_reg_8)(struct device *dev, u16 reg_address, u8 val); + int (*write_reg_16)(struct device *dev, u16 reg_address, u16 val); + int (*write_reg_24)(struct device *dev, u16 reg_address, u32 val); + int (*write_reg_32)(struct device *dev, u16 reg_address, u32 val); + int irq; + struct mutex buf_lock; + u8 tx[ADE7854_MAX_TX] ____cacheline_aligned; + u8 rx[ADE7854_MAX_RX]; }; From 0dad1eceeb9c7497e7e2a592900ddac79b128c56 Mon Sep 17 00:00:00 2001 From: Gwendal Grignou Date: Wed, 21 Feb 2018 16:11:09 +0100 Subject: [PATCH 06/47] iio: cros_ec: Relax sampling frequency before suspending If an application set a tight sampling frequency, given the interrupt use is a wakeup source, suspend will not happen: the kernel will receive a wake up interrupt and will cancel the suspend process. Given cros_ec sensors type is non wake up, this patch adds prepare and complete callbacks to set 1s sampling period just before suspend. This ensures the sensor hub will not be a source of interrupt during the suspend process. Signed-off-by: Gwendal Grignou Signed-off-by: Enric Balletbo i Serra Acked-by: Jonathan Cameron Signed-off-by: Jonathan Cameron --- .../common/cros_ec_sensors/cros_ec_sensors.c | 1 + .../cros_ec_sensors/cros_ec_sensors_core.c | 49 +++++++++++++++++++ .../cros_ec_sensors/cros_ec_sensors_core.h | 2 + drivers/iio/light/cros_ec_light_prox.c | 1 + 4 files changed, 53 insertions(+) diff --git a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c index 7d30c59da3e2..705cb3e72663 100644 --- a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c +++ b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors.c @@ -289,6 +289,7 @@ MODULE_DEVICE_TABLE(platform, cros_ec_sensors_ids); static struct platform_driver cros_ec_sensors_platform_driver = { .driver = { .name = "cros-ec-sensors", + .pm = &cros_ec_sensors_pm_ops, }, .probe = cros_ec_sensors_probe, .id_table = cros_ec_sensors_ids, diff --git a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c index 416cae5ebbd0..a620eb5ce202 100644 --- a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c +++ b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.c @@ -446,5 +446,54 @@ int cros_ec_sensors_core_write(struct cros_ec_sensors_core_state *st, } EXPORT_SYMBOL_GPL(cros_ec_sensors_core_write); +static int __maybe_unused cros_ec_sensors_prepare(struct device *dev) +{ + struct platform_device *pdev = to_platform_device(dev); + struct iio_dev *indio_dev = platform_get_drvdata(pdev); + struct cros_ec_sensors_core_state *st = iio_priv(indio_dev); + + if (st->curr_sampl_freq == 0) + return 0; + + /* + * If the sensors are sampled at high frequency, we will not be able to + * sleep. Set sampling to a long period if necessary. + */ + if (st->curr_sampl_freq < CROS_EC_MIN_SUSPEND_SAMPLING_FREQUENCY) { + mutex_lock(&st->cmd_lock); + st->param.cmd = MOTIONSENSE_CMD_EC_RATE; + st->param.ec_rate.data = CROS_EC_MIN_SUSPEND_SAMPLING_FREQUENCY; + cros_ec_motion_send_host_cmd(st, 0); + mutex_unlock(&st->cmd_lock); + } + return 0; +} + +static void __maybe_unused cros_ec_sensors_complete(struct device *dev) +{ + struct platform_device *pdev = to_platform_device(dev); + struct iio_dev *indio_dev = platform_get_drvdata(pdev); + struct cros_ec_sensors_core_state *st = iio_priv(indio_dev); + + if (st->curr_sampl_freq == 0) + return; + + if (st->curr_sampl_freq < CROS_EC_MIN_SUSPEND_SAMPLING_FREQUENCY) { + mutex_lock(&st->cmd_lock); + st->param.cmd = MOTIONSENSE_CMD_EC_RATE; + st->param.ec_rate.data = st->curr_sampl_freq; + cros_ec_motion_send_host_cmd(st, 0); + mutex_unlock(&st->cmd_lock); + } +} + +const struct dev_pm_ops cros_ec_sensors_pm_ops = { +#ifdef CONFIG_PM_SLEEP + .prepare = cros_ec_sensors_prepare, + .complete = cros_ec_sensors_complete +#endif +}; +EXPORT_SYMBOL_GPL(cros_ec_sensors_pm_ops); + MODULE_DESCRIPTION("ChromeOS EC sensor hub core functions"); MODULE_LICENSE("GPL v2"); diff --git a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.h b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.h index 8bc2ca3c2e2e..2edf68dc7336 100644 --- a/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.h +++ b/drivers/iio/common/cros_ec_sensors/cros_ec_sensors_core.h @@ -169,6 +169,8 @@ int cros_ec_sensors_core_write(struct cros_ec_sensors_core_state *st, struct iio_chan_spec const *chan, int val, int val2, long mask); +extern const struct dev_pm_ops cros_ec_sensors_pm_ops; + /* List of extended channel specification for all sensors */ extern const struct iio_chan_spec_ext_info cros_ec_sensors_ext_info[]; diff --git a/drivers/iio/light/cros_ec_light_prox.c b/drivers/iio/light/cros_ec_light_prox.c index acfad4aeb27a..8e8a0e7f78d1 100644 --- a/drivers/iio/light/cros_ec_light_prox.c +++ b/drivers/iio/light/cros_ec_light_prox.c @@ -276,6 +276,7 @@ MODULE_DEVICE_TABLE(platform, cros_ec_light_prox_ids); static struct platform_driver cros_ec_light_prox_platform_driver = { .driver = { .name = "cros-ec-light-prox", + .pm = &cros_ec_sensors_pm_ops, }, .probe = cros_ec_light_prox_probe, .id_table = cros_ec_light_prox_ids, From c0879ed6188789c6252e91cedabf46236cfa1d42 Mon Sep 17 00:00:00 2001 From: Fabrice Gasnier Date: Fri, 23 Feb 2018 12:11:00 +0100 Subject: [PATCH 07/47] dt-bindings: iio: adc: stm32-dfsdm: fix types, add missing pinctrl - Add missing pinctrl description. Support is made optional as dfsdm may use internal sources (e.g. via registers) - Fix typo in IIO STM32 DFSDM filter "MANCH_F" description. Basically, this should be "falling edge = logic 0", not "1" that applies to "MANCH_R". BTW, make the description complete by describing both rising/falling edges as described in reference manuals. Fixes: 6c82f947fc97 ("IIO: add DT bindings for stm32 DFSDM filter") Signed-off-by: Fabrice Gasnier Reviewed-by: Rob Herring Signed-off-by: Jonathan Cameron --- .../devicetree/bindings/iio/adc/st,stm32-dfsdm-adc.txt | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/Documentation/devicetree/bindings/iio/adc/st,stm32-dfsdm-adc.txt b/Documentation/devicetree/bindings/iio/adc/st,stm32-dfsdm-adc.txt index 911492da48f3..ed7520d1d051 100644 --- a/Documentation/devicetree/bindings/iio/adc/st,stm32-dfsdm-adc.txt +++ b/Documentation/devicetree/bindings/iio/adc/st,stm32-dfsdm-adc.txt @@ -32,6 +32,10 @@ Optional properties: to "clock" property. Frequency must be a multiple of the rcc clock frequency. If not, SPI CLKOUT frequency will not be accurate. +- pinctrl-names: Set to "default". +- pinctrl-0: List of phandles pointing to pin configuration + nodes to set pins in mode of operation for dfsdm + on external pin. Contents of a STM32 DFSDM child nodes: -------------------------------------- @@ -68,8 +72,8 @@ Optional properties: - st,adc-channel-types: Single-ended channel input type. - "SPI_R": SPI with data on rising edge (default) - "SPI_F": SPI with data on falling edge - - "MANCH_R": manchester codec, rising edge = logic 0 - - "MANCH_F": manchester codec, falling edge = logic 1 + - "MANCH_R": manchester codec, rising edge = logic 0, falling edge = logic 1 + - "MANCH_F": manchester codec, rising edge = logic 1, falling edge = logic 0 - st,adc-channel-clk-src: Conversion clock source. - "CLKIN": external SPI clock (CLKIN x) - "CLKOUT": internal SPI clock (CLKOUT) (default) From b61d8e630a8577600813acb2d0ce43ced8e9d107 Mon Sep 17 00:00:00 2001 From: Andy Shevchenko Date: Mon, 26 Feb 2018 21:37:35 +0200 Subject: [PATCH 08/47] iio: proximity: sx9500: Add GPIO ACPI mapping table In order to satisfy GPIO ACPI library requirements convert users of gpiod_get_index() to correctly behave when there no mapping is provided by firmware. Here we add explicit mapping between _CRS GpioIo() resources and their names used in the driver. Signed-off-by: Andy Shevchenko Signed-off-by: Jonathan Cameron --- drivers/iio/proximity/sx9500.c | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/drivers/iio/proximity/sx9500.c b/drivers/iio/proximity/sx9500.c index b8a2c2c8cac5..ff80409e0c44 100644 --- a/drivers/iio/proximity/sx9500.c +++ b/drivers/iio/proximity/sx9500.c @@ -32,9 +32,6 @@ #define SX9500_DRIVER_NAME "sx9500" #define SX9500_IRQ_NAME "sx9500_event" -#define SX9500_GPIO_INT "interrupt" -#define SX9500_GPIO_RESET "reset" - /* Register definitions. */ #define SX9500_REG_IRQ_SRC 0x00 #define SX9500_REG_STAT 0x01 @@ -866,26 +863,44 @@ static int sx9500_init_device(struct iio_dev *indio_dev) return sx9500_init_compensation(indio_dev); } +static const struct acpi_gpio_params reset_gpios = { 0, 0, false }; +static const struct acpi_gpio_params interrupt_gpios = { 2, 0, false }; + +static const struct acpi_gpio_mapping acpi_sx9500_gpios[] = { + { "reset-gpios", &reset_gpios, 1 }, + /* + * Some platforms have a bug in ACPI GPIO description making IRQ + * GPIO to be output only. Ask the GPIO core to ignore this limit. + */ + { "interrupt-gpios", &interrupt_gpios, 1, ACPI_GPIO_QUIRK_NO_IO_RESTRICTION }, + { }, +}; + static void sx9500_gpio_probe(struct i2c_client *client, struct sx9500_data *data) { struct gpio_desc *gpiod_int; struct device *dev; + int ret; if (!client) return; dev = &client->dev; + ret = devm_acpi_dev_add_driver_gpios(dev, acpi_sx9500_gpios); + if (ret) + dev_dbg(dev, "Unable to add GPIO mapping table\n"); + if (client->irq <= 0) { - gpiod_int = devm_gpiod_get(dev, SX9500_GPIO_INT, GPIOD_IN); + gpiod_int = devm_gpiod_get(dev, "interrupt", GPIOD_IN); if (IS_ERR(gpiod_int)) dev_err(dev, "gpio get irq failed\n"); else client->irq = gpiod_to_irq(gpiod_int); } - data->gpiod_rst = devm_gpiod_get(dev, SX9500_GPIO_RESET, GPIOD_OUT_HIGH); + data->gpiod_rst = devm_gpiod_get(dev, "reset", GPIOD_OUT_HIGH); if (IS_ERR(data->gpiod_rst)) { dev_warn(dev, "gpio get reset pin failed\n"); data->gpiod_rst = NULL; From 0f079547150a8669da28720a4b9e3f767512ea6f Mon Sep 17 00:00:00 2001 From: Jeff LaBundy Date: Mon, 26 Feb 2018 20:11:51 -0600 Subject: [PATCH 09/47] iio: light: lv0104cs: Add support for LV0104CS light sensor This patch adds support for the On Semiconductor LV0104CS ambient light sensor. Signed-off-by: Jeff LaBundy Signed-off-by: Jonathan Cameron --- drivers/iio/light/Kconfig | 10 + drivers/iio/light/Makefile | 1 + drivers/iio/light/lv0104cs.c | 531 +++++++++++++++++++++++++++++++++++ 3 files changed, 542 insertions(+) create mode 100644 drivers/iio/light/lv0104cs.c diff --git a/drivers/iio/light/Kconfig b/drivers/iio/light/Kconfig index 93fd421b10d7..074e50657366 100644 --- a/drivers/iio/light/Kconfig +++ b/drivers/iio/light/Kconfig @@ -275,6 +275,16 @@ config LTR501 This driver can also be built as a module. If so, the module will be called ltr501. +config LV0104CS + tristate "LV0104CS Ambient Light Sensor" + depends on I2C + help + Say Y here if you want to build support for the On Semiconductor + LV0104CS ambient light sensor. + + To compile this driver as a module, choose M here: + the module will be called lv0104cs. + config MAX44000 tristate "MAX44000 Ambient and Infrared Proximity Sensor" depends on I2C diff --git a/drivers/iio/light/Makefile b/drivers/iio/light/Makefile index f714067a7816..f1777036d4f8 100644 --- a/drivers/iio/light/Makefile +++ b/drivers/iio/light/Makefile @@ -26,6 +26,7 @@ obj-$(CONFIG_ISL29125) += isl29125.o obj-$(CONFIG_JSA1212) += jsa1212.o obj-$(CONFIG_SENSORS_LM3533) += lm3533-als.o obj-$(CONFIG_LTR501) += ltr501.o +obj-$(CONFIG_LV0104CS) += lv0104cs.o obj-$(CONFIG_MAX44000) += max44000.o obj-$(CONFIG_OPT3001) += opt3001.o obj-$(CONFIG_PA12203001) += pa12203001.o diff --git a/drivers/iio/light/lv0104cs.c b/drivers/iio/light/lv0104cs.c new file mode 100644 index 000000000000..55b8e2855647 --- /dev/null +++ b/drivers/iio/light/lv0104cs.c @@ -0,0 +1,531 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * lv0104cs.c: LV0104CS Ambient Light Sensor Driver + * + * Copyright (C) 2018 + * Author: Jeff LaBundy + * + * 7-bit I2C slave address: 0x13 + * + * Link to data sheet: http://www.onsemi.com/pub/Collateral/LV0104CS-D.PDF + */ + +#include +#include +#include +#include +#include +#include +#include +#include + +#define LV0104CS_REGVAL_MEASURE 0xE0 +#define LV0104CS_REGVAL_SLEEP 0x00 + +#define LV0104CS_SCALE_0_25X 0 +#define LV0104CS_SCALE_1X 1 +#define LV0104CS_SCALE_2X 2 +#define LV0104CS_SCALE_8X 3 +#define LV0104CS_SCALE_SHIFT 3 + +#define LV0104CS_INTEG_12_5MS 0 +#define LV0104CS_INTEG_100MS 1 +#define LV0104CS_INTEG_200MS 2 +#define LV0104CS_INTEG_SHIFT 1 + +#define LV0104CS_CALIBSCALE_UNITY 31 + +struct lv0104cs_private { + struct i2c_client *client; + struct mutex lock; + u8 calibscale; + u8 scale; + u8 int_time; +}; + +struct lv0104cs_mapping { + int val; + int val2; + u8 regval; +}; + +static const struct lv0104cs_mapping lv0104cs_calibscales[] = { + { 0, 666666, 0x81 }, + { 0, 800000, 0x82 }, + { 0, 857142, 0x83 }, + { 0, 888888, 0x84 }, + { 0, 909090, 0x85 }, + { 0, 923076, 0x86 }, + { 0, 933333, 0x87 }, + { 0, 941176, 0x88 }, + { 0, 947368, 0x89 }, + { 0, 952380, 0x8A }, + { 0, 956521, 0x8B }, + { 0, 960000, 0x8C }, + { 0, 962962, 0x8D }, + { 0, 965517, 0x8E }, + { 0, 967741, 0x8F }, + { 0, 969696, 0x90 }, + { 0, 971428, 0x91 }, + { 0, 972972, 0x92 }, + { 0, 974358, 0x93 }, + { 0, 975609, 0x94 }, + { 0, 976744, 0x95 }, + { 0, 977777, 0x96 }, + { 0, 978723, 0x97 }, + { 0, 979591, 0x98 }, + { 0, 980392, 0x99 }, + { 0, 981132, 0x9A }, + { 0, 981818, 0x9B }, + { 0, 982456, 0x9C }, + { 0, 983050, 0x9D }, + { 0, 983606, 0x9E }, + { 0, 984126, 0x9F }, + { 1, 0, 0x80 }, + { 1, 16129, 0xBF }, + { 1, 16666, 0xBE }, + { 1, 17241, 0xBD }, + { 1, 17857, 0xBC }, + { 1, 18518, 0xBB }, + { 1, 19230, 0xBA }, + { 1, 20000, 0xB9 }, + { 1, 20833, 0xB8 }, + { 1, 21739, 0xB7 }, + { 1, 22727, 0xB6 }, + { 1, 23809, 0xB5 }, + { 1, 24999, 0xB4 }, + { 1, 26315, 0xB3 }, + { 1, 27777, 0xB2 }, + { 1, 29411, 0xB1 }, + { 1, 31250, 0xB0 }, + { 1, 33333, 0xAF }, + { 1, 35714, 0xAE }, + { 1, 38461, 0xAD }, + { 1, 41666, 0xAC }, + { 1, 45454, 0xAB }, + { 1, 50000, 0xAA }, + { 1, 55555, 0xA9 }, + { 1, 62500, 0xA8 }, + { 1, 71428, 0xA7 }, + { 1, 83333, 0xA6 }, + { 1, 100000, 0xA5 }, + { 1, 125000, 0xA4 }, + { 1, 166666, 0xA3 }, + { 1, 250000, 0xA2 }, + { 1, 500000, 0xA1 }, +}; + +static const struct lv0104cs_mapping lv0104cs_scales[] = { + { 0, 250000, LV0104CS_SCALE_0_25X << LV0104CS_SCALE_SHIFT }, + { 1, 0, LV0104CS_SCALE_1X << LV0104CS_SCALE_SHIFT }, + { 2, 0, LV0104CS_SCALE_2X << LV0104CS_SCALE_SHIFT }, + { 8, 0, LV0104CS_SCALE_8X << LV0104CS_SCALE_SHIFT }, +}; + +static const struct lv0104cs_mapping lv0104cs_int_times[] = { + { 0, 12500, LV0104CS_INTEG_12_5MS << LV0104CS_INTEG_SHIFT }, + { 0, 100000, LV0104CS_INTEG_100MS << LV0104CS_INTEG_SHIFT }, + { 0, 200000, LV0104CS_INTEG_200MS << LV0104CS_INTEG_SHIFT }, +}; + +static int lv0104cs_write_reg(struct i2c_client *client, u8 regval) +{ + int ret; + + ret = i2c_master_send(client, (char *)®val, sizeof(regval)); + if (ret < 0) + return ret; + if (ret != sizeof(regval)) + return -EIO; + + return 0; +} + +static int lv0104cs_read_adc(struct i2c_client *client, u16 *adc_output) +{ + __be16 regval; + int ret; + + ret = i2c_master_recv(client, (char *)®val, sizeof(regval)); + if (ret < 0) + return ret; + if (ret != sizeof(regval)) + return -EIO; + + *adc_output = be16_to_cpu(regval); + + return 0; +} + +static int lv0104cs_get_lux(struct lv0104cs_private *lv0104cs, + int *val, int *val2) +{ + u8 regval = LV0104CS_REGVAL_MEASURE; + u16 adc_output; + int ret; + + regval |= lv0104cs_scales[lv0104cs->scale].regval; + regval |= lv0104cs_int_times[lv0104cs->int_time].regval; + ret = lv0104cs_write_reg(lv0104cs->client, regval); + if (ret) + return ret; + + /* wait for integration time to pass (with margin) */ + switch (lv0104cs->int_time) { + case LV0104CS_INTEG_12_5MS: + msleep(50); + break; + + case LV0104CS_INTEG_100MS: + msleep(150); + break; + + case LV0104CS_INTEG_200MS: + msleep(250); + break; + + default: + return -EINVAL; + } + + ret = lv0104cs_read_adc(lv0104cs->client, &adc_output); + if (ret) + return ret; + + ret = lv0104cs_write_reg(lv0104cs->client, LV0104CS_REGVAL_SLEEP); + if (ret) + return ret; + + /* convert ADC output to lux */ + switch (lv0104cs->scale) { + case LV0104CS_SCALE_0_25X: + *val = adc_output * 4; + *val2 = 0; + return 0; + + case LV0104CS_SCALE_1X: + *val = adc_output; + *val2 = 0; + return 0; + + case LV0104CS_SCALE_2X: + *val = adc_output / 2; + *val2 = (adc_output % 2) * 500000; + return 0; + + case LV0104CS_SCALE_8X: + *val = adc_output / 8; + *val2 = (adc_output % 8) * 125000; + return 0; + + default: + return -EINVAL; + } +} + +static int lv0104cs_read_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int *val, int *val2, long mask) +{ + struct lv0104cs_private *lv0104cs = iio_priv(indio_dev); + int ret; + + if (chan->type != IIO_LIGHT) + return -EINVAL; + + mutex_lock(&lv0104cs->lock); + + switch (mask) { + case IIO_CHAN_INFO_PROCESSED: + ret = lv0104cs_get_lux(lv0104cs, val, val2); + if (ret) + goto err_mutex; + ret = IIO_VAL_INT_PLUS_MICRO; + break; + + case IIO_CHAN_INFO_CALIBSCALE: + *val = lv0104cs_calibscales[lv0104cs->calibscale].val; + *val2 = lv0104cs_calibscales[lv0104cs->calibscale].val2; + ret = IIO_VAL_INT_PLUS_MICRO; + break; + + case IIO_CHAN_INFO_SCALE: + *val = lv0104cs_scales[lv0104cs->scale].val; + *val2 = lv0104cs_scales[lv0104cs->scale].val2; + ret = IIO_VAL_INT_PLUS_MICRO; + break; + + case IIO_CHAN_INFO_INT_TIME: + *val = lv0104cs_int_times[lv0104cs->int_time].val; + *val2 = lv0104cs_int_times[lv0104cs->int_time].val2; + ret = IIO_VAL_INT_PLUS_MICRO; + break; + + default: + ret = -EINVAL; + } + +err_mutex: + mutex_unlock(&lv0104cs->lock); + + return ret; +} + +static int lv0104cs_set_calibscale(struct lv0104cs_private *lv0104cs, + int val, int val2) +{ + int calibscale = val * 1000000 + val2; + int floor, ceil, mid; + int ret, i, index; + + /* round to nearest quantized calibscale (sensitivity) */ + for (i = 0; i < ARRAY_SIZE(lv0104cs_calibscales) - 1; i++) { + floor = lv0104cs_calibscales[i].val * 1000000 + + lv0104cs_calibscales[i].val2; + ceil = lv0104cs_calibscales[i + 1].val * 1000000 + + lv0104cs_calibscales[i + 1].val2; + mid = (floor + ceil) / 2; + + /* round down */ + if (calibscale >= floor && calibscale < mid) { + index = i; + break; + } + + /* round up */ + if (calibscale >= mid && calibscale <= ceil) { + index = i + 1; + break; + } + } + + if (i == ARRAY_SIZE(lv0104cs_calibscales) - 1) + return -EINVAL; + + mutex_lock(&lv0104cs->lock); + + /* set calibscale (sensitivity) */ + ret = lv0104cs_write_reg(lv0104cs->client, + lv0104cs_calibscales[index].regval); + if (ret) + goto err_mutex; + + lv0104cs->calibscale = index; + +err_mutex: + mutex_unlock(&lv0104cs->lock); + + return ret; +} + +static int lv0104cs_set_scale(struct lv0104cs_private *lv0104cs, + int val, int val2) +{ + int i; + + /* hard matching */ + for (i = 0; i < ARRAY_SIZE(lv0104cs_scales); i++) { + if (val != lv0104cs_scales[i].val) + continue; + + if (val2 == lv0104cs_scales[i].val2) + break; + } + + if (i == ARRAY_SIZE(lv0104cs_scales)) + return -EINVAL; + + mutex_lock(&lv0104cs->lock); + lv0104cs->scale = i; + mutex_unlock(&lv0104cs->lock); + + return 0; +} + +static int lv0104cs_set_int_time(struct lv0104cs_private *lv0104cs, + int val, int val2) +{ + int i; + + /* hard matching */ + for (i = 0; i < ARRAY_SIZE(lv0104cs_int_times); i++) { + if (val != lv0104cs_int_times[i].val) + continue; + + if (val2 == lv0104cs_int_times[i].val2) + break; + } + + if (i == ARRAY_SIZE(lv0104cs_int_times)) + return -EINVAL; + + mutex_lock(&lv0104cs->lock); + lv0104cs->int_time = i; + mutex_unlock(&lv0104cs->lock); + + return 0; +} + +static int lv0104cs_write_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int val, int val2, long mask) +{ + struct lv0104cs_private *lv0104cs = iio_priv(indio_dev); + + if (chan->type != IIO_LIGHT) + return -EINVAL; + + switch (mask) { + case IIO_CHAN_INFO_CALIBSCALE: + return lv0104cs_set_calibscale(lv0104cs, val, val2); + + case IIO_CHAN_INFO_SCALE: + return lv0104cs_set_scale(lv0104cs, val, val2); + + case IIO_CHAN_INFO_INT_TIME: + return lv0104cs_set_int_time(lv0104cs, val, val2); + + default: + return -EINVAL; + } +} + +static ssize_t lv0104cs_show_calibscale_avail(struct device *dev, + struct device_attribute *attr, char *buf) +{ + ssize_t len = 0; + int i; + + for (i = 0; i < ARRAY_SIZE(lv0104cs_calibscales); i++) { + len += scnprintf(buf + len, PAGE_SIZE - len, "%d.%06d ", + lv0104cs_calibscales[i].val, + lv0104cs_calibscales[i].val2); + } + + buf[len - 1] = '\n'; + + return len; +} + +static ssize_t lv0104cs_show_scale_avail(struct device *dev, + struct device_attribute *attr, char *buf) +{ + ssize_t len = 0; + int i; + + for (i = 0; i < ARRAY_SIZE(lv0104cs_scales); i++) { + len += scnprintf(buf + len, PAGE_SIZE - len, "%d.%06d ", + lv0104cs_scales[i].val, + lv0104cs_scales[i].val2); + } + + buf[len - 1] = '\n'; + + return len; +} + +static ssize_t lv0104cs_show_int_time_avail(struct device *dev, + struct device_attribute *attr, char *buf) +{ + ssize_t len = 0; + int i; + + for (i = 0; i < ARRAY_SIZE(lv0104cs_int_times); i++) { + len += scnprintf(buf + len, PAGE_SIZE - len, "%d.%06d ", + lv0104cs_int_times[i].val, + lv0104cs_int_times[i].val2); + } + + buf[len - 1] = '\n'; + + return len; +} + +static IIO_DEVICE_ATTR(calibscale_available, 0444, + lv0104cs_show_calibscale_avail, NULL, 0); +static IIO_DEVICE_ATTR(scale_available, 0444, + lv0104cs_show_scale_avail, NULL, 0); +static IIO_DEV_ATTR_INT_TIME_AVAIL(lv0104cs_show_int_time_avail); + +static struct attribute *lv0104cs_attributes[] = { + &iio_dev_attr_calibscale_available.dev_attr.attr, + &iio_dev_attr_scale_available.dev_attr.attr, + &iio_dev_attr_integration_time_available.dev_attr.attr, + NULL +}; + +static const struct attribute_group lv0104cs_attribute_group = { + .attrs = lv0104cs_attributes, +}; + +static const struct iio_info lv0104cs_info = { + .attrs = &lv0104cs_attribute_group, + .read_raw = &lv0104cs_read_raw, + .write_raw = &lv0104cs_write_raw, +}; + +static const struct iio_chan_spec lv0104cs_channels[] = { + { + .type = IIO_LIGHT, + .info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED) | + BIT(IIO_CHAN_INFO_CALIBSCALE) | + BIT(IIO_CHAN_INFO_SCALE) | + BIT(IIO_CHAN_INFO_INT_TIME), + }, +}; + +static int lv0104cs_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct iio_dev *indio_dev; + struct lv0104cs_private *lv0104cs; + int ret; + + indio_dev = devm_iio_device_alloc(&client->dev, sizeof(*lv0104cs)); + if (!indio_dev) + return -ENOMEM; + + lv0104cs = iio_priv(indio_dev); + + i2c_set_clientdata(client, lv0104cs); + lv0104cs->client = client; + + mutex_init(&lv0104cs->lock); + + lv0104cs->calibscale = LV0104CS_CALIBSCALE_UNITY; + lv0104cs->scale = LV0104CS_SCALE_1X; + lv0104cs->int_time = LV0104CS_INTEG_200MS; + + ret = lv0104cs_write_reg(lv0104cs->client, + lv0104cs_calibscales[LV0104CS_CALIBSCALE_UNITY].regval); + if (ret) + return ret; + + indio_dev->modes = INDIO_DIRECT_MODE; + indio_dev->dev.parent = &client->dev; + indio_dev->channels = lv0104cs_channels; + indio_dev->num_channels = ARRAY_SIZE(lv0104cs_channels); + indio_dev->name = client->name; + indio_dev->info = &lv0104cs_info; + + return devm_iio_device_register(&client->dev, indio_dev); +} + +static const struct i2c_device_id lv0104cs_id[] = { + { "lv0104cs", 0 }, + { } +}; +MODULE_DEVICE_TABLE(i2c, lv0104cs_id); + +static struct i2c_driver lv0104cs_i2c_driver = { + .driver = { + .name = "lv0104cs", + }, + .id_table = lv0104cs_id, + .probe = lv0104cs_probe, +}; +module_i2c_driver(lv0104cs_i2c_driver); + +MODULE_AUTHOR("Jeff LaBundy "); +MODULE_DESCRIPTION("LV0104CS Ambient Light Sensor Driver"); +MODULE_LICENSE("GPL"); From a34a3ed73ca067bedbc8194ab20b959c65ea71a4 Mon Sep 17 00:00:00 2001 From: Rodrigo Siqueira Date: Tue, 27 Feb 2018 10:46:51 -0300 Subject: [PATCH 10/47] iio: dummy: Add correct tabs and spaces to Kconfig Kconfig from iio/dummy does not follow the coding style recommendations. According to the coding-style, Lines under a config definition are indented with one tab, while help text is indented an additional two spaces. This patch adds the proper tabulation and space. Signed-off-by: Rodrigo Siqueira Reviewed-by: Daniel Baluta Signed-off-by: Jonathan Cameron --- drivers/iio/dummy/Kconfig | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/drivers/iio/dummy/Kconfig b/drivers/iio/dummy/Kconfig index 5a29fbd3c531..85e13b2e35bf 100644 --- a/drivers/iio/dummy/Kconfig +++ b/drivers/iio/dummy/Kconfig @@ -9,20 +9,20 @@ config IIO_DUMMY_EVGEN tristate config IIO_SIMPLE_DUMMY - tristate "An example driver with no hardware requirements" - depends on IIO_SW_DEVICE - help - Driver intended mainly as documentation for how to write - a driver. May also be useful for testing userspace code - without hardware. + tristate "An example driver with no hardware requirements" + depends on IIO_SW_DEVICE + help + Driver intended mainly as documentation for how to write + a driver. May also be useful for testing userspace code + without hardware. if IIO_SIMPLE_DUMMY config IIO_SIMPLE_DUMMY_EVENTS - bool "Event generation support" - select IIO_DUMMY_EVGEN - help - Add some dummy events to the simple dummy driver. + bool "Event generation support" + select IIO_DUMMY_EVGEN + help + Add some dummy events to the simple dummy driver. config IIO_SIMPLE_DUMMY_BUFFER bool "Buffered capture support" From 5556dfe54be421b1b2897513adf61d9b6d3ab271 Mon Sep 17 00:00:00 2001 From: Rodrigo Siqueira Date: Tue, 27 Feb 2018 10:47:06 -0300 Subject: [PATCH 11/47] iio:dummy: Add extra paragraphs on Kconfig This patch fixes the checkpatch.pl warning: drivers/iio/dummy/Kconfig:21: WARNING: please write a paragraph that describes the config symbol fully drivers/iio/dummy/Kconfig:27: WARNING: please write a paragraph that describes the config symbol fully This patch expands the explanation about IIO_DUMMY_EVGEN by using the code documentation found in iio/dummy/iio_dummy_evgen.c. In the same way, the information related to IIO_SIMPLE_DUMMY_BUFFER was extracted from file iio_simple_dummy_buffer.c. Signed-off-by: Rodrigo Siqueira Reviewed-by: Daniel Baluta Signed-off-by: Jonathan Cameron --- drivers/iio/dummy/Kconfig | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/iio/dummy/Kconfig b/drivers/iio/dummy/Kconfig index 85e13b2e35bf..c4fd108e91d3 100644 --- a/drivers/iio/dummy/Kconfig +++ b/drivers/iio/dummy/Kconfig @@ -24,6 +24,10 @@ config IIO_SIMPLE_DUMMY_EVENTS help Add some dummy events to the simple dummy driver. + The purpose of this is to generate 'fake' event interrupts thus + allowing that driver's code to be as close as possible to that + a normal driver talking to hardware. + config IIO_SIMPLE_DUMMY_BUFFER bool "Buffered capture support" select IIO_BUFFER @@ -32,6 +36,9 @@ config IIO_SIMPLE_DUMMY_BUFFER help Add buffered data capture to the simple dummy driver. + Buffer handling elements of industrial I/O reference driver. + Uses the kfifo buffer. + endif # IIO_SIMPLE_DUMMY endmenu From 5def839c481712f2f0a3a34755ee6b27279e7cbe Mon Sep 17 00:00:00 2001 From: Rodrigo Siqueira Date: Tue, 27 Feb 2018 11:47:55 -0300 Subject: [PATCH 12/47] iio:magnetometer: Replace magic number 0 by IIO_CHAN_INFO_RAW The function magn_3d_read_raw has a switch statement handling multiple cases per channel. The first case statement uses the magic number 0, which means IIO_CHAN_INFO_RAW. Additionally, the iio_chan_spec for magn_3d_channels is configured to be IIO_CHAN_INFO_RAW. Therefore, this patch replaces the magic number 0 for the appropriate IIO_CHAN_INFO_RAW. Signed-off-by: Rodrigo Siqueira Signed-off-by: Jonathan Cameron --- drivers/iio/magnetometer/hid-sensor-magn-3d.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/iio/magnetometer/hid-sensor-magn-3d.c b/drivers/iio/magnetometer/hid-sensor-magn-3d.c index a1fd9d591818..d55c4885211a 100644 --- a/drivers/iio/magnetometer/hid-sensor-magn-3d.c +++ b/drivers/iio/magnetometer/hid-sensor-magn-3d.c @@ -167,7 +167,7 @@ static int magn_3d_read_raw(struct iio_dev *indio_dev, *val = 0; *val2 = 0; switch (mask) { - case 0: + case IIO_CHAN_INFO_RAW: hid_sensor_power_state(&magn_state->magn_flux_attributes, true); report_id = magn_state->magn[chan->address].report_id; From 5824d0938dab99503b9a5c18f1ed8ad04a13b62a Mon Sep 17 00:00:00 2001 From: Shreeya Patel Date: Fri, 2 Mar 2018 18:49:23 +0530 Subject: [PATCH 13/47] Staging: iio: adis16209: Arrange headers in alphabetical order Arrange the headers in alphabetical order for cleanup purpose. Signed-off-by: Shreeya Patel Signed-off-by: Jonathan Cameron --- drivers/staging/iio/accel/adis16209.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/staging/iio/accel/adis16209.c b/drivers/staging/iio/accel/adis16209.c index 7fcef9a2590a..58f604d11a40 100644 --- a/drivers/staging/iio/accel/adis16209.c +++ b/drivers/staging/iio/accel/adis16209.c @@ -9,11 +9,11 @@ #include #include #include +#include +#include #include #include #include -#include -#include #include #include From c97712c41f7419c98723581a1b9566cd84cad44c Mon Sep 17 00:00:00 2001 From: Shreeya Patel Date: Fri, 2 Mar 2018 18:53:41 +0530 Subject: [PATCH 14/47] Staging: iio: adis16209: Change the definition name The change in the definition name makes it then obvious what the units are throughout the driver and there will be no need of the comment. Signed-off-by: Shreeya Patel Signed-off-by: Jonathan Cameron --- drivers/staging/iio/accel/adis16209.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/staging/iio/accel/adis16209.c b/drivers/staging/iio/accel/adis16209.c index 58f604d11a40..830c278dea52 100644 --- a/drivers/staging/iio/accel/adis16209.c +++ b/drivers/staging/iio/accel/adis16209.c @@ -20,7 +20,7 @@ #include #include -#define ADIS16209_STARTUP_DELAY 220 /* ms */ +#define ADIS16209_STARTUP_DELAY_MS 220 /* Flash memory write count */ #define ADIS16209_FLASH_CNT 0x00 @@ -303,7 +303,7 @@ static const struct adis_data adis16209_data = { .self_test_mask = ADIS16209_MSC_CTRL_SELF_TEST_EN, .self_test_no_autoclear = true, - .startup_delay = ADIS16209_STARTUP_DELAY, + .startup_delay = ADIS16209_STARTUP_DELAY_MS, .status_error_msgs = adis16209_status_error_msgs, .status_error_mask = BIT(ADIS16209_DIAG_STAT_SELFTEST_FAIL_BIT) | From 200905fdf08ab8168826b6ce43406d0638de22bf Mon Sep 17 00:00:00 2001 From: Shreeya Patel Date: Fri, 2 Mar 2018 18:55:56 +0530 Subject: [PATCH 15/47] Staging: iio: adis16209: Add _REG postfix for registers The defined names for registers does not make it very clear that they are registers and hence, add _REG postfix. This improves the readability of the code. Signed-off-by: Shreeya Patel Signed-off-by: Jonathan Cameron --- drivers/staging/iio/accel/adis16209.c | 85 ++++++++++++++------------- 1 file changed, 43 insertions(+), 42 deletions(-) diff --git a/drivers/staging/iio/accel/adis16209.c b/drivers/staging/iio/accel/adis16209.c index 830c278dea52..151120fab58a 100644 --- a/drivers/staging/iio/accel/adis16209.c +++ b/drivers/staging/iio/accel/adis16209.c @@ -23,85 +23,85 @@ #define ADIS16209_STARTUP_DELAY_MS 220 /* Flash memory write count */ -#define ADIS16209_FLASH_CNT 0x00 +#define ADIS16209_FLASH_CNT_REG 0x00 /* Output, power supply */ -#define ADIS16209_SUPPLY_OUT 0x02 +#define ADIS16209_SUPPLY_OUT_REG 0x02 /* Output, x-axis accelerometer */ -#define ADIS16209_XACCL_OUT 0x04 +#define ADIS16209_XACCL_OUT_REG 0x04 /* Output, y-axis accelerometer */ -#define ADIS16209_YACCL_OUT 0x06 +#define ADIS16209_YACCL_OUT_REG 0x06 /* Output, auxiliary ADC input */ -#define ADIS16209_AUX_ADC 0x08 +#define ADIS16209_AUX_ADC_REG 0x08 /* Output, temperature */ -#define ADIS16209_TEMP_OUT 0x0A +#define ADIS16209_TEMP_OUT_REG 0x0A /* Output, x-axis inclination */ -#define ADIS16209_XINCL_OUT 0x0C +#define ADIS16209_XINCL_OUT_REG 0x0C /* Output, y-axis inclination */ -#define ADIS16209_YINCL_OUT 0x0E +#define ADIS16209_YINCL_OUT_REG 0x0E /* Output, +/-180 vertical rotational position */ -#define ADIS16209_ROT_OUT 0x10 +#define ADIS16209_ROT_OUT_REG 0x10 /* Calibration, x-axis acceleration offset null */ -#define ADIS16209_XACCL_NULL 0x12 +#define ADIS16209_XACCL_NULL_REG 0x12 /* Calibration, y-axis acceleration offset null */ -#define ADIS16209_YACCL_NULL 0x14 +#define ADIS16209_YACCL_NULL_REG 0x14 /* Calibration, x-axis inclination offset null */ -#define ADIS16209_XINCL_NULL 0x16 +#define ADIS16209_XINCL_NULL_REG 0x16 /* Calibration, y-axis inclination offset null */ -#define ADIS16209_YINCL_NULL 0x18 +#define ADIS16209_YINCL_NULL_REG 0x18 /* Calibration, vertical rotation offset null */ -#define ADIS16209_ROT_NULL 0x1A +#define ADIS16209_ROT_NULL_REG 0x1A /* Alarm 1 amplitude threshold */ -#define ADIS16209_ALM_MAG1 0x20 +#define ADIS16209_ALM_MAG1_REG 0x20 /* Alarm 2 amplitude threshold */ -#define ADIS16209_ALM_MAG2 0x22 +#define ADIS16209_ALM_MAG2_REG 0x22 /* Alarm 1, sample period */ -#define ADIS16209_ALM_SMPL1 0x24 +#define ADIS16209_ALM_SMPL1_REG 0x24 /* Alarm 2, sample period */ -#define ADIS16209_ALM_SMPL2 0x26 +#define ADIS16209_ALM_SMPL2_REG 0x26 /* Alarm control */ -#define ADIS16209_ALM_CTRL 0x28 +#define ADIS16209_ALM_CTRL_REG 0x28 /* Auxiliary DAC data */ -#define ADIS16209_AUX_DAC 0x30 +#define ADIS16209_AUX_DAC_REG 0x30 /* General-purpose digital input/output control */ -#define ADIS16209_GPIO_CTRL 0x32 +#define ADIS16209_GPIO_CTRL_REG 0x32 /* Miscellaneous control */ -#define ADIS16209_MSC_CTRL 0x34 +#define ADIS16209_MSC_CTRL_REG 0x34 /* Internal sample period (rate) control */ -#define ADIS16209_SMPL_PRD 0x36 +#define ADIS16209_SMPL_PRD_REG 0x36 /* Operation, filter configuration */ -#define ADIS16209_AVG_CNT 0x38 +#define ADIS16209_AVG_CNT_REG 0x38 /* Operation, sleep mode control */ -#define ADIS16209_SLP_CNT 0x3A +#define ADIS16209_SLP_CNT_REG 0x3A /* Diagnostics, system status register */ -#define ADIS16209_DIAG_STAT 0x3C +#define ADIS16209_DIAG_STAT_REG 0x3C /* Operation, system command register */ -#define ADIS16209_GLOB_CMD 0x3E +#define ADIS16209_GLOB_CMD_REG 0x3E /* MSC_CTRL */ @@ -165,10 +165,10 @@ enum adis16209_scan { static const u8 adis16209_addresses[8][1] = { [ADIS16209_SCAN_SUPPLY] = { }, [ADIS16209_SCAN_AUX_ADC] = { }, - [ADIS16209_SCAN_ACC_X] = { ADIS16209_XACCL_NULL }, - [ADIS16209_SCAN_ACC_Y] = { ADIS16209_YACCL_NULL }, - [ADIS16209_SCAN_INCLI_X] = { ADIS16209_XINCL_NULL }, - [ADIS16209_SCAN_INCLI_Y] = { ADIS16209_YINCL_NULL }, + [ADIS16209_SCAN_ACC_X] = { ADIS16209_XACCL_NULL_REG }, + [ADIS16209_SCAN_ACC_Y] = { ADIS16209_YACCL_NULL_REG }, + [ADIS16209_SCAN_INCLI_X] = { ADIS16209_XINCL_NULL_REG }, + [ADIS16209_SCAN_INCLI_Y] = { ADIS16209_YINCL_NULL_REG }, [ADIS16209_SCAN_ROT] = { }, [ADIS16209_SCAN_TEMP] = { }, }; @@ -266,18 +266,19 @@ static int adis16209_read_raw(struct iio_dev *indio_dev, } static const struct iio_chan_spec adis16209_channels[] = { - ADIS_SUPPLY_CHAN(ADIS16209_SUPPLY_OUT, ADIS16209_SCAN_SUPPLY, 0, 14), - ADIS_TEMP_CHAN(ADIS16209_TEMP_OUT, ADIS16209_SCAN_TEMP, 0, 12), - ADIS_ACCEL_CHAN(X, ADIS16209_XACCL_OUT, ADIS16209_SCAN_ACC_X, + ADIS_SUPPLY_CHAN(ADIS16209_SUPPLY_OUT_REG, ADIS16209_SCAN_SUPPLY, + 0, 14), + ADIS_TEMP_CHAN(ADIS16209_TEMP_OUT_REG, ADIS16209_SCAN_TEMP, 0, 12), + ADIS_ACCEL_CHAN(X, ADIS16209_XACCL_OUT_REG, ADIS16209_SCAN_ACC_X, BIT(IIO_CHAN_INFO_CALIBBIAS), 0, 14), - ADIS_ACCEL_CHAN(Y, ADIS16209_YACCL_OUT, ADIS16209_SCAN_ACC_Y, + ADIS_ACCEL_CHAN(Y, ADIS16209_YACCL_OUT_REG, ADIS16209_SCAN_ACC_Y, BIT(IIO_CHAN_INFO_CALIBBIAS), 0, 14), - ADIS_AUX_ADC_CHAN(ADIS16209_AUX_ADC, ADIS16209_SCAN_AUX_ADC, 0, 12), - ADIS_INCLI_CHAN(X, ADIS16209_XINCL_OUT, ADIS16209_SCAN_INCLI_X, + ADIS_AUX_ADC_CHAN(ADIS16209_AUX_ADC_REG, ADIS16209_SCAN_AUX_ADC, 0, 12), + ADIS_INCLI_CHAN(X, ADIS16209_XINCL_OUT_REG, ADIS16209_SCAN_INCLI_X, 0, 0, 14), - ADIS_INCLI_CHAN(Y, ADIS16209_YINCL_OUT, ADIS16209_SCAN_INCLI_Y, + ADIS_INCLI_CHAN(Y, ADIS16209_YINCL_OUT_REG, ADIS16209_SCAN_INCLI_Y, 0, 0, 14), - ADIS_ROT_CHAN(X, ADIS16209_ROT_OUT, ADIS16209_SCAN_ROT, 0, 0, 14), + ADIS_ROT_CHAN(X, ADIS16209_ROT_OUT_REG, ADIS16209_SCAN_ROT, 0, 0, 14), IIO_CHAN_SOFT_TIMESTAMP(8) }; @@ -297,9 +298,9 @@ static const char * const adis16209_status_error_msgs[] = { static const struct adis_data adis16209_data = { .read_delay = 30, - .msc_ctrl_reg = ADIS16209_MSC_CTRL, - .glob_cmd_reg = ADIS16209_GLOB_CMD, - .diag_stat_reg = ADIS16209_DIAG_STAT, + .msc_ctrl_reg = ADIS16209_MSC_CTRL_REG, + .glob_cmd_reg = ADIS16209_GLOB_CMD_REG, + .diag_stat_reg = ADIS16209_DIAG_STAT_REG, .self_test_mask = ADIS16209_MSC_CTRL_SELF_TEST_EN, .self_test_no_autoclear = true, From bd28425a307417d3bd5bdf18e819cc7f90ac1a4d Mon Sep 17 00:00:00 2001 From: Arushi Singhal Date: Wed, 7 Mar 2018 18:47:17 +0530 Subject: [PATCH 16/47] staging: iio: Remove unnecessary cast on void pointer The following Coccinelle script was used to detect this: @r@ expression x; void* e; type T; identifier f; @@ ( *((T *)e) | ((T *)x)[...] | ((T*)x)->f | - (T*) e ) Signed-off-by: Arushi Singhal Signed-off-by: Jonathan Cameron --- drivers/staging/iio/adc/ad7816.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/staging/iio/adc/ad7816.c b/drivers/staging/iio/adc/ad7816.c index bfe180a475ee..bf76a8620bdb 100644 --- a/drivers/staging/iio/adc/ad7816.c +++ b/drivers/staging/iio/adc/ad7816.c @@ -254,7 +254,7 @@ static const struct attribute_group ad7816_attribute_group = { static irqreturn_t ad7816_event_handler(int irq, void *private) { iio_push_event(private, IIO_EVENT_CODE_AD7816_OTI, - iio_get_time_ns((struct iio_dev *)private)); + iio_get_time_ns(private)); return IRQ_HANDLED; } From 844ed8220cd10a233bc0825f6992a2949c0c440b Mon Sep 17 00:00:00 2001 From: HariPrasath Elango Date: Wed, 7 Mar 2018 11:08:04 +0530 Subject: [PATCH 17/47] staging: iio: meter: Remove reduntant __func__ from debug print dev_dbg includes the function name & line number by default when dynamic debugging is enabled. Hence__func__ is reduntant here and removed. Signed-off-by: HariPrasath Elango Signed-off-by: Jonathan Cameron --- drivers/staging/iio/meter/ade7758_trigger.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/staging/iio/meter/ade7758_trigger.c b/drivers/staging/iio/meter/ade7758_trigger.c index 1f0d1a0cf889..da489ae8cb86 100644 --- a/drivers/staging/iio/meter/ade7758_trigger.c +++ b/drivers/staging/iio/meter/ade7758_trigger.c @@ -34,7 +34,7 @@ static int ade7758_data_rdy_trigger_set_state(struct iio_trigger *trig, { struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig); - dev_dbg(&indio_dev->dev, "%s (%d)\n", __func__, state); + dev_dbg(&indio_dev->dev, "(%d)\n", state); return ade7758_set_irq(&indio_dev->dev, state); } From 75f800a7eb48de38ede855bd834dfb92effe714b Mon Sep 17 00:00:00 2001 From: Rodrigo Siqueira Date: Tue, 6 Mar 2018 21:43:47 -0300 Subject: [PATCH 18/47] staging:iio:meter: Replaces IIO_DEV_ATTR_CH_OFF by IIO_DEVICE_ATTR The macro IIO_DEV_ATTR_CH_OFF is a wrapper for IIO_DEVICE_ATTR, with a tiny change in the name definition. This extra macro does not improve the readability and also creates some checkpatch errors. This patch fixes the checkpatch.pl errors: staging/iio/meter/ade7753.c:391: ERROR: Use 4 digit octal (0777) not decimal permissions staging/iio/meter/ade7753.c:395: ERROR: Use 4 digit octal (0777) not decimal permissions staging/iio/meter/ade7759.c:331: ERROR: Use 4 digit octal (0777) not decimal permissions staging/iio/meter/ade7759.c:335: ERROR: Use 4 digit octal (0777) not decimal permissions Signed-off-by: Rodrigo Siqueira Signed-off-by: Jonathan Cameron --- drivers/staging/iio/meter/ade7753.c | 18 ++++++++++-------- drivers/staging/iio/meter/ade7759.c | 18 ++++++++++-------- 2 files changed, 20 insertions(+), 16 deletions(-) diff --git a/drivers/staging/iio/meter/ade7753.c b/drivers/staging/iio/meter/ade7753.c index c44eb577dc35..275e8dfff836 100644 --- a/drivers/staging/iio/meter/ade7753.c +++ b/drivers/staging/iio/meter/ade7753.c @@ -388,14 +388,16 @@ static IIO_DEV_ATTR_VPERIOD(0444, ade7753_read_16bit, NULL, ADE7753_PERIOD); -static IIO_DEV_ATTR_CH_OFF(1, 0644, - ade7753_read_8bit, - ade7753_write_8bit, - ADE7753_CH1OS); -static IIO_DEV_ATTR_CH_OFF(2, 0644, - ade7753_read_8bit, - ade7753_write_8bit, - ADE7753_CH2OS); + +static IIO_DEVICE_ATTR(choff_1, 0644, + ade7753_read_8bit, + ade7753_write_8bit, + ADE7753_CH1OS); + +static IIO_DEVICE_ATTR(choff_2, 0644, + ade7753_read_8bit, + ade7753_write_8bit, + ADE7753_CH2OS); static int ade7753_set_irq(struct device *dev, bool enable) { diff --git a/drivers/staging/iio/meter/ade7759.c b/drivers/staging/iio/meter/ade7759.c index 1decb2b8afab..c078b770fa53 100644 --- a/drivers/staging/iio/meter/ade7759.c +++ b/drivers/staging/iio/meter/ade7759.c @@ -328,14 +328,16 @@ static IIO_DEV_ATTR_ACTIVE_POWER_GAIN(0644, ade7759_read_16bit, ade7759_write_16bit, ADE7759_APGAIN); -static IIO_DEV_ATTR_CH_OFF(1, 0644, - ade7759_read_8bit, - ade7759_write_8bit, - ADE7759_CH1OS); -static IIO_DEV_ATTR_CH_OFF(2, 0644, - ade7759_read_8bit, - ade7759_write_8bit, - ADE7759_CH2OS); + +static IIO_DEVICE_ATTR(choff_1, 0644, + ade7759_read_8bit, + ade7759_write_8bit, + ADE7759_CH1OS); + +static IIO_DEVICE_ATTR(choff_2, 0644, + ade7759_read_8bit, + ade7759_write_8bit, + ADE7759_CH2OS); static int ade7759_set_irq(struct device *dev, bool enable) { From b5724925da03cffca3c18c0cd10ea7e0c5dda2df Mon Sep 17 00:00:00 2001 From: Rodrigo Siqueira Date: Tue, 6 Mar 2018 21:44:07 -0300 Subject: [PATCH 19/47] staging:iio:meter: Remove unused macro IIO_DEV_ATTR_CH_OFF This patch removes the macro IIO_DEV_ATTR_CH_OFF. The macro IIO_DEV_ATTR_CH_OFF is not required, due to the replace of it by the direct use of IIO_DEVICE_ATTR in files staging/iio/meter/ade7759.c and staging/iio/meter/ade7753.c. Signed-off-by: Rodrigo Siqueira Signed-off-by: Jonathan Cameron --- drivers/staging/iio/meter/meter.h | 3 --- 1 file changed, 3 deletions(-) diff --git a/drivers/staging/iio/meter/meter.h b/drivers/staging/iio/meter/meter.h index edf26302fa57..5ed59bf30a25 100644 --- a/drivers/staging/iio/meter/meter.h +++ b/drivers/staging/iio/meter/meter.h @@ -348,9 +348,6 @@ #define IIO_DEV_ATTR_VPERIOD(_mode, _show, _store, _addr) \ IIO_DEVICE_ATTR(vperiod, _mode, _show, _store, _addr) -#define IIO_DEV_ATTR_CH_OFF(_num, _mode, _show, _store, _addr) \ - IIO_DEVICE_ATTR(choff_##_num, _mode, _show, _store, _addr) - /* active energy register, AENERGY, is more than half full */ #define IIO_EVENT_ATTR_AENERGY_HALF_FULL(_evlist, _show, _store, _mask) \ IIO_EVENT_ATTR_SH(aenergy_half_full, _evlist, _show, _store, _mask) From f22fb87d4c3bf52daadd1184531dcbabf1a8ab60 Mon Sep 17 00:00:00 2001 From: Rodrigo Siqueira Date: Tue, 6 Mar 2018 21:44:26 -0300 Subject: [PATCH 20/47] staging:iio:meter: Aligns open parenthesis This patch fixes the checkpatch.pl checks: staging/iio/meter/ade7854-spi.c:19: CHECK: Alignment should match open parenthesis staging/iio/meter/ade7854-spi.c:44: CHECK: Alignment should match open parenthesis staging/iio/meter/ade7854-spi.c:70: CHECK: Alignment should match open parenthesis staging/iio/meter/ade7854-spi.c:97: CHECK: Alignment should match open parenthesis staging/iio/meter/ade7854-spi.c:125: CHECK: Alignment should match open parenthesis ... Signed-off-by: Rodrigo Siqueira Signed-off-by: Jonathan Cameron --- drivers/staging/iio/meter/ade7758_trigger.c | 6 ++-- drivers/staging/iio/meter/ade7854-spi.c | 40 ++++++++++----------- 2 files changed, 23 insertions(+), 23 deletions(-) diff --git a/drivers/staging/iio/meter/ade7758_trigger.c b/drivers/staging/iio/meter/ade7758_trigger.c index da489ae8cb86..4f6b338cffeb 100644 --- a/drivers/staging/iio/meter/ade7758_trigger.c +++ b/drivers/staging/iio/meter/ade7758_trigger.c @@ -30,7 +30,7 @@ static irqreturn_t ade7758_data_rdy_trig_poll(int irq, void *private) * ade7758_data_rdy_trigger_set_state() set datardy interrupt state **/ static int ade7758_data_rdy_trigger_set_state(struct iio_trigger *trig, - bool state) + bool state) { struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig); @@ -63,8 +63,8 @@ int ade7758_probe_trigger(struct iio_dev *indio_dev) int ret; st->trig = iio_trigger_alloc("%s-dev%d", - spi_get_device_id(st->us)->name, - indio_dev->id); + spi_get_device_id(st->us)->name, + indio_dev->id); if (!st->trig) { ret = -ENOMEM; goto error_ret; diff --git a/drivers/staging/iio/meter/ade7854-spi.c b/drivers/staging/iio/meter/ade7854-spi.c index 72eddfec21f7..4419b8f06197 100644 --- a/drivers/staging/iio/meter/ade7854-spi.c +++ b/drivers/staging/iio/meter/ade7854-spi.c @@ -16,8 +16,8 @@ #include "ade7854.h" static int ade7854_spi_write_reg_8(struct device *dev, - u16 reg_address, - u8 val) + u16 reg_address, + u8 val) { int ret; struct iio_dev *indio_dev = dev_to_iio_dev(dev); @@ -41,8 +41,8 @@ static int ade7854_spi_write_reg_8(struct device *dev, } static int ade7854_spi_write_reg_16(struct device *dev, - u16 reg_address, - u16 val) + u16 reg_address, + u16 val) { int ret; struct iio_dev *indio_dev = dev_to_iio_dev(dev); @@ -67,8 +67,8 @@ static int ade7854_spi_write_reg_16(struct device *dev, } static int ade7854_spi_write_reg_24(struct device *dev, - u16 reg_address, - u32 val) + u16 reg_address, + u32 val) { int ret; struct iio_dev *indio_dev = dev_to_iio_dev(dev); @@ -94,8 +94,8 @@ static int ade7854_spi_write_reg_24(struct device *dev, } static int ade7854_spi_write_reg_32(struct device *dev, - u16 reg_address, - u32 val) + u16 reg_address, + u32 val) { int ret; struct iio_dev *indio_dev = dev_to_iio_dev(dev); @@ -122,8 +122,8 @@ static int ade7854_spi_write_reg_32(struct device *dev, } static int ade7854_spi_read_reg_8(struct device *dev, - u16 reg_address, - u8 *val) + u16 reg_address, + u8 *val) { struct iio_dev *indio_dev = dev_to_iio_dev(dev); struct ade7854_state *st = iio_priv(indio_dev); @@ -149,7 +149,7 @@ static int ade7854_spi_read_reg_8(struct device *dev, ret = spi_sync_transfer(st->spi, xfers, ARRAY_SIZE(xfers)); if (ret) { dev_err(&st->spi->dev, "problem when reading 8 bit register 0x%02X", - reg_address); + reg_address); goto error_ret; } *val = st->rx[0]; @@ -160,8 +160,8 @@ error_ret: } static int ade7854_spi_read_reg_16(struct device *dev, - u16 reg_address, - u16 *val) + u16 reg_address, + u16 *val) { struct iio_dev *indio_dev = dev_to_iio_dev(dev); struct ade7854_state *st = iio_priv(indio_dev); @@ -186,7 +186,7 @@ static int ade7854_spi_read_reg_16(struct device *dev, ret = spi_sync_transfer(st->spi, xfers, ARRAY_SIZE(xfers)); if (ret) { dev_err(&st->spi->dev, "problem when reading 16 bit register 0x%02X", - reg_address); + reg_address); goto error_ret; } *val = be16_to_cpup((const __be16 *)st->rx); @@ -197,8 +197,8 @@ error_ret: } static int ade7854_spi_read_reg_24(struct device *dev, - u16 reg_address, - u32 *val) + u16 reg_address, + u32 *val) { struct iio_dev *indio_dev = dev_to_iio_dev(dev); struct ade7854_state *st = iio_priv(indio_dev); @@ -224,7 +224,7 @@ static int ade7854_spi_read_reg_24(struct device *dev, ret = spi_sync_transfer(st->spi, xfers, ARRAY_SIZE(xfers)); if (ret) { dev_err(&st->spi->dev, "problem when reading 24 bit register 0x%02X", - reg_address); + reg_address); goto error_ret; } *val = (st->rx[0] << 16) | (st->rx[1] << 8) | st->rx[2]; @@ -235,8 +235,8 @@ error_ret: } static int ade7854_spi_read_reg_32(struct device *dev, - u16 reg_address, - u32 *val) + u16 reg_address, + u32 *val) { struct iio_dev *indio_dev = dev_to_iio_dev(dev); struct ade7854_state *st = iio_priv(indio_dev); @@ -262,7 +262,7 @@ static int ade7854_spi_read_reg_32(struct device *dev, ret = spi_sync_transfer(st->spi, xfers, ARRAY_SIZE(xfers)); if (ret) { dev_err(&st->spi->dev, "problem when reading 32 bit register 0x%02X", - reg_address); + reg_address); goto error_ret; } *val = be32_to_cpup((const __be32 *)st->rx); From 67464a54e5156ed2e5a72ffb516308b58f25e6ca Mon Sep 17 00:00:00 2001 From: Rodrigo Siqueira Date: Tue, 6 Mar 2018 09:02:57 -0300 Subject: [PATCH 21/47] iio: Replace occurrences of magic number 0 by IIO_CHAN_INFO_RAW Usually, functions responsible for reading raw data typically relies on values from iio_chan_info_enum to correctly identify the type of data to be read. There is a set of a device driver that uses the magic number 0 instead of IIO_CHAN_INFO_RAW. This patch improves the readability by replaces the magic number 0 for the appropriate IIO_CHAN_INFO_RAW in six devices driver in the IIO subsystem. Signed-off-by: Rodrigo Siqueira Signed-off-by: Jonathan Cameron --- drivers/iio/accel/hid-sensor-accel-3d.c | 2 +- drivers/iio/dac/ad5380.c | 2 +- drivers/iio/dac/ad5764.c | 2 +- drivers/iio/gyro/hid-sensor-gyro-3d.c | 2 +- drivers/iio/light/hid-sensor-als.c | 2 +- drivers/iio/light/lm3533-als.c | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/iio/accel/hid-sensor-accel-3d.c b/drivers/iio/accel/hid-sensor-accel-3d.c index c066a3bdbff7..41d97faf5013 100644 --- a/drivers/iio/accel/hid-sensor-accel-3d.c +++ b/drivers/iio/accel/hid-sensor-accel-3d.c @@ -155,7 +155,7 @@ static int accel_3d_read_raw(struct iio_dev *indio_dev, *val = 0; *val2 = 0; switch (mask) { - case 0: + case IIO_CHAN_INFO_RAW: hid_sensor_power_state(&accel_state->common_attributes, true); report_id = accel_state->accel[chan->scan_index].report_id; address = accel_3d_addresses[chan->scan_index]; diff --git a/drivers/iio/dac/ad5380.c b/drivers/iio/dac/ad5380.c index 845fd1c0fd9d..873c2bf637c0 100644 --- a/drivers/iio/dac/ad5380.c +++ b/drivers/iio/dac/ad5380.c @@ -158,7 +158,7 @@ static unsigned int ad5380_info_to_reg(struct iio_chan_spec const *chan, long info) { switch (info) { - case 0: + case IIO_CHAN_INFO_RAW: return AD5380_REG_DATA(chan->address); case IIO_CHAN_INFO_CALIBBIAS: return AD5380_REG_OFFSET(chan->address); diff --git a/drivers/iio/dac/ad5764.c b/drivers/iio/dac/ad5764.c index 033f20eca616..9333177062c0 100644 --- a/drivers/iio/dac/ad5764.c +++ b/drivers/iio/dac/ad5764.c @@ -168,7 +168,7 @@ static int ad5764_read(struct iio_dev *indio_dev, unsigned int reg, static int ad5764_chan_info_to_reg(struct iio_chan_spec const *chan, long info) { switch (info) { - case 0: + case IIO_CHAN_INFO_RAW: return AD5764_REG_DATA(chan->address); case IIO_CHAN_INFO_CALIBBIAS: return AD5764_REG_OFFSET(chan->address); diff --git a/drivers/iio/gyro/hid-sensor-gyro-3d.c b/drivers/iio/gyro/hid-sensor-gyro-3d.c index f59995a90387..36941e69f959 100644 --- a/drivers/iio/gyro/hid-sensor-gyro-3d.c +++ b/drivers/iio/gyro/hid-sensor-gyro-3d.c @@ -115,7 +115,7 @@ static int gyro_3d_read_raw(struct iio_dev *indio_dev, *val = 0; *val2 = 0; switch (mask) { - case 0: + case IIO_CHAN_INFO_RAW: hid_sensor_power_state(&gyro_state->common_attributes, true); report_id = gyro_state->gyro[chan->scan_index].report_id; address = gyro_3d_addresses[chan->scan_index]; diff --git a/drivers/iio/light/hid-sensor-als.c b/drivers/iio/light/hid-sensor-als.c index befd693a4a31..406caaee9a3c 100644 --- a/drivers/iio/light/hid-sensor-als.c +++ b/drivers/iio/light/hid-sensor-als.c @@ -97,7 +97,7 @@ static int als_read_raw(struct iio_dev *indio_dev, *val = 0; *val2 = 0; switch (mask) { - case 0: + case IIO_CHAN_INFO_RAW: switch (chan->scan_index) { case CHANNEL_SCAN_INDEX_INTENSITY: case CHANNEL_SCAN_INDEX_ILLUM: diff --git a/drivers/iio/light/lm3533-als.c b/drivers/iio/light/lm3533-als.c index 36208a3652e9..ff5a3324b489 100644 --- a/drivers/iio/light/lm3533-als.c +++ b/drivers/iio/light/lm3533-als.c @@ -199,7 +199,7 @@ static int lm3533_als_read_raw(struct iio_dev *indio_dev, int ret; switch (mask) { - case 0: + case IIO_CHAN_INFO_RAW: switch (chan->type) { case IIO_LIGHT: ret = lm3533_als_get_adc(indio_dev, false, val); From 189cef998c30db3ede5de5ab6f9b9ba92d490f64 Mon Sep 17 00:00:00 2001 From: Himanshu Jha Date: Mon, 5 Mar 2018 13:19:20 +0530 Subject: [PATCH 22/47] Staging: iio: accel: adis16201: Prefer alphabetical sequence of header files Arrange header files in alphabetical sequence to improve readability. Signed-off-by: Himanshu Jha Signed-off-by: Jonathan Cameron --- drivers/staging/iio/accel/adis16201.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/staging/iio/accel/adis16201.c b/drivers/staging/iio/accel/adis16201.c index 2ebd27536216..0f6a20414023 100644 --- a/drivers/staging/iio/accel/adis16201.c +++ b/drivers/staging/iio/accel/adis16201.c @@ -7,13 +7,13 @@ */ #include -#include #include #include -#include -#include -#include #include +#include +#include +#include +#include #include #include From 75aa306c232e0343b41eb3d8f5c39cd3124afae2 Mon Sep 17 00:00:00 2001 From: Himanshu Jha Date: Mon, 5 Mar 2018 13:19:21 +0530 Subject: [PATCH 23/47] Staging: iio: accel: adis16201: Add a blank space before returns Adding a blank space before/after some returns improves readability. Signed-off-by: Himanshu Jha Signed-off-by: Jonathan Cameron --- drivers/staging/iio/accel/adis16201.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/staging/iio/accel/adis16201.c b/drivers/staging/iio/accel/adis16201.c index 0f6a20414023..0fae8aaf1cf4 100644 --- a/drivers/staging/iio/accel/adis16201.c +++ b/drivers/staging/iio/accel/adis16201.c @@ -232,6 +232,7 @@ static int adis16201_read_raw(struct iio_dev *indio_dev, *val = val16; return IIO_VAL_INT; } + return -EINVAL; } @@ -262,6 +263,7 @@ static int adis16201_write_raw(struct iio_dev *indio_dev, addr = adis16201_addresses[chan->scan_index]; return adis_write_reg_16(st, addr, val16); } + return -EINVAL; } @@ -336,6 +338,7 @@ static int adis16201_probe(struct spi_device *spi) ret = adis_init(st, indio_dev, spi, &adis16201_data); if (ret) return ret; + ret = adis_setup_buffer_and_trigger(st, indio_dev, NULL); if (ret) return ret; @@ -348,6 +351,7 @@ static int adis16201_probe(struct spi_device *spi) ret = iio_device_register(indio_dev); if (ret < 0) goto error_cleanup_buffer_trigger; + return 0; error_cleanup_buffer_trigger: From f3cfe187c8984ddcbda39fc88592d3ffc2f0e5f7 Mon Sep 17 00:00:00 2001 From: Shreeya Patel Date: Sun, 4 Mar 2018 18:06:22 +0530 Subject: [PATCH 24/47] Staging: iio: adis16209: Remove and add some comments and group the definitions Remove some unnecessay comments and group the control register and register field macros together. Some of the register names does not make it's puporse very clear and hence, add some comments for more information. Also there are certain unit based comments which are not providing sufficient information, so expand those comments. Signed-off-by: Shreeya Patel Signed-off-by: Jonathan Cameron --- drivers/staging/iio/accel/adis16209.c | 132 ++++++++------------------ 1 file changed, 39 insertions(+), 93 deletions(-) diff --git a/drivers/staging/iio/accel/adis16209.c b/drivers/staging/iio/accel/adis16209.c index 151120fab58a..e0a5e350214b 100644 --- a/drivers/staging/iio/accel/adis16209.c +++ b/drivers/staging/iio/accel/adis16209.c @@ -21,135 +21,70 @@ #include #define ADIS16209_STARTUP_DELAY_MS 220 - -/* Flash memory write count */ #define ADIS16209_FLASH_CNT_REG 0x00 -/* Output, power supply */ +/* Data Output Register Definitions */ #define ADIS16209_SUPPLY_OUT_REG 0x02 - -/* Output, x-axis accelerometer */ #define ADIS16209_XACCL_OUT_REG 0x04 - -/* Output, y-axis accelerometer */ #define ADIS16209_YACCL_OUT_REG 0x06 - /* Output, auxiliary ADC input */ #define ADIS16209_AUX_ADC_REG 0x08 - /* Output, temperature */ #define ADIS16209_TEMP_OUT_REG 0x0A - -/* Output, x-axis inclination */ +/* Output, +/- 90 degrees X-axis inclination */ #define ADIS16209_XINCL_OUT_REG 0x0C - -/* Output, y-axis inclination */ #define ADIS16209_YINCL_OUT_REG 0x0E - /* Output, +/-180 vertical rotational position */ #define ADIS16209_ROT_OUT_REG 0x10 -/* Calibration, x-axis acceleration offset null */ +/* + * Calibration Register Definitions. + * Acceleration, inclination or rotation offset null. + */ #define ADIS16209_XACCL_NULL_REG 0x12 - -/* Calibration, y-axis acceleration offset null */ #define ADIS16209_YACCL_NULL_REG 0x14 - -/* Calibration, x-axis inclination offset null */ #define ADIS16209_XINCL_NULL_REG 0x16 - -/* Calibration, y-axis inclination offset null */ #define ADIS16209_YINCL_NULL_REG 0x18 - -/* Calibration, vertical rotation offset null */ #define ADIS16209_ROT_NULL_REG 0x1A -/* Alarm 1 amplitude threshold */ +/* Alarm Register Definitions */ #define ADIS16209_ALM_MAG1_REG 0x20 - -/* Alarm 2 amplitude threshold */ #define ADIS16209_ALM_MAG2_REG 0x22 - -/* Alarm 1, sample period */ #define ADIS16209_ALM_SMPL1_REG 0x24 - -/* Alarm 2, sample period */ #define ADIS16209_ALM_SMPL2_REG 0x26 - -/* Alarm control */ #define ADIS16209_ALM_CTRL_REG 0x28 -/* Auxiliary DAC data */ #define ADIS16209_AUX_DAC_REG 0x30 - -/* General-purpose digital input/output control */ #define ADIS16209_GPIO_CTRL_REG 0x32 - -/* Miscellaneous control */ -#define ADIS16209_MSC_CTRL_REG 0x34 - -/* Internal sample period (rate) control */ #define ADIS16209_SMPL_PRD_REG 0x36 - -/* Operation, filter configuration */ #define ADIS16209_AVG_CNT_REG 0x38 - -/* Operation, sleep mode control */ #define ADIS16209_SLP_CNT_REG 0x3A -/* Diagnostics, system status register */ -#define ADIS16209_DIAG_STAT_REG 0x3C - -/* Operation, system command register */ -#define ADIS16209_GLOB_CMD_REG 0x3E - -/* MSC_CTRL */ - -/* Self-test at power-on: 1 = disabled, 0 = enabled */ -#define ADIS16209_MSC_CTRL_PWRUP_SELF_TEST BIT(10) - -/* Self-test enable */ -#define ADIS16209_MSC_CTRL_SELF_TEST_EN BIT(8) - -/* Data-ready enable: 1 = enabled, 0 = disabled */ -#define ADIS16209_MSC_CTRL_DATA_RDY_EN BIT(2) - +#define ADIS16209_MSC_CTRL_REG 0x34 +#define ADIS16209_MSC_CTRL_PWRUP_SELF_TEST BIT(10) +#define ADIS16209_MSC_CTRL_SELF_TEST_EN BIT(8) +#define ADIS16209_MSC_CTRL_DATA_RDY_EN BIT(2) /* Data-ready polarity: 1 = active high, 0 = active low */ -#define ADIS16209_MSC_CTRL_ACTIVE_HIGH BIT(1) +#define ADIS16209_MSC_CTRL_ACTIVE_HIGH BIT(1) +#define ADIS16209_MSC_CTRL_DATA_RDY_DIO2 BIT(0) -/* Data-ready line selection: 1 = DIO2, 0 = DIO1 */ -#define ADIS16209_MSC_CTRL_DATA_RDY_DIO2 BIT(0) - -/* DIAG_STAT */ - -/* Alarm 2 status: 1 = alarm active, 0 = alarm inactive */ -#define ADIS16209_DIAG_STAT_ALARM2 BIT(9) - -/* Alarm 1 status: 1 = alarm active, 0 = alarm inactive */ -#define ADIS16209_DIAG_STAT_ALARM1 BIT(8) - -/* Self-test diagnostic error flag: 1 = error condition, 0 = normal operation */ +#define ADIS16209_DIAG_STAT_REG 0x3C +#define ADIS16209_DIAG_STAT_ALARM2 BIT(9) +#define ADIS16209_DIAG_STAT_ALARM1 BIT(8) #define ADIS16209_DIAG_STAT_SELFTEST_FAIL_BIT 5 - -/* SPI communications failure */ #define ADIS16209_DIAG_STAT_SPI_FAIL_BIT 3 - -/* Flash update failure */ #define ADIS16209_DIAG_STAT_FLASH_UPT_BIT 2 - /* Power supply above 3.625 V */ #define ADIS16209_DIAG_STAT_POWER_HIGH_BIT 1 - /* Power supply below 3.15 V */ #define ADIS16209_DIAG_STAT_POWER_LOW_BIT 0 -/* GLOB_CMD */ +#define ADIS16209_GLOB_CMD_REG 0x3E +#define ADIS16209_GLOB_CMD_SW_RESET BIT(7) +#define ADIS16209_GLOB_CMD_CLEAR_STAT BIT(4) +#define ADIS16209_GLOB_CMD_FACTORY_CAL BIT(1) -#define ADIS16209_GLOB_CMD_SW_RESET BIT(7) -#define ADIS16209_GLOB_CMD_CLEAR_STAT BIT(4) -#define ADIS16209_GLOB_CMD_FACTORY_CAL BIT(1) - -#define ADIS16209_ERROR_ACTIVE BIT(14) +#define ADIS16209_ERROR_ACTIVE BIT(14) enum adis16209_scan { ADIS16209_SCAN_SUPPLY, @@ -226,24 +161,38 @@ static int adis16209_read_raw(struct iio_dev *indio_dev, *val2 = 610500; /* 0.6105 mV */ return IIO_VAL_INT_PLUS_MICRO; case IIO_TEMP: - *val = -470; /* -0.47 C */ + *val = -470; *val2 = 0; return IIO_VAL_INT_PLUS_MICRO; case IIO_ACCEL: + /* + * IIO base unit for sensitivity of accelerometer + * is milli g. + * 1 LSB represents 0.244 mg. + */ *val = 0; - *val2 = IIO_G_TO_M_S_2(244140); /* 0.244140 mg */ + *val2 = IIO_G_TO_M_S_2(244140); return IIO_VAL_INT_PLUS_NANO; case IIO_INCLI: case IIO_ROT: + /* + * IIO base units for rotation are degrees. + * 1 LSB represents 0.025 milli degrees. + */ *val = 0; - *val2 = 25000; /* 0.025 degree */ + *val2 = 25000; return IIO_VAL_INT_PLUS_MICRO; default: return -EINVAL; } break; case IIO_CHAN_INFO_OFFSET: - *val = 25000 / -470 - 0x4FE; /* 25 C = 0x4FE */ + /* + * The raw ADC value is 0x4FE when the temperature + * is 25 degrees and the scale factor per milli + * degree celcius is -470. + */ + *val = 25000 / -470 - 0x4FE; return IIO_VAL_INT; case IIO_CHAN_INFO_CALIBBIAS: switch (chan->type) { @@ -320,12 +269,10 @@ static int adis16209_probe(struct spi_device *spi) struct adis *st; struct iio_dev *indio_dev; - /* setup the industrialio driver allocated elements */ indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); if (!indio_dev) return -ENOMEM; st = iio_priv(indio_dev); - /* this is only used for removal purposes */ spi_set_drvdata(spi, indio_dev); indio_dev->name = spi->dev.driver->name; @@ -342,7 +289,6 @@ static int adis16209_probe(struct spi_device *spi) if (ret) return ret; - /* Get the device into a sane initial state */ ret = adis_initial_startup(st); if (ret) goto error_cleanup_buffer_trigger; From 1026bb35371a499f977174f9f297ce8e2dfd1efb Mon Sep 17 00:00:00 2001 From: Shreeya Patel Date: Sun, 4 Mar 2018 18:11:17 +0530 Subject: [PATCH 25/47] Staging: iio: adis16209: Change some macro names Make some of the macro names according to the names given in the datasheet of the adis16209 driver. Signed-off-by: Shreeya Patel Signed-off-by: Jonathan Cameron --- drivers/staging/iio/accel/adis16209.c | 48 +++++++++++++-------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/drivers/staging/iio/accel/adis16209.c b/drivers/staging/iio/accel/adis16209.c index e0a5e350214b..68a2f2f80f88 100644 --- a/drivers/staging/iio/accel/adis16209.c +++ b/drivers/staging/iio/accel/adis16209.c @@ -68,21 +68,21 @@ #define ADIS16209_MSC_CTRL_ACTIVE_HIGH BIT(1) #define ADIS16209_MSC_CTRL_DATA_RDY_DIO2 BIT(0) -#define ADIS16209_DIAG_STAT_REG 0x3C -#define ADIS16209_DIAG_STAT_ALARM2 BIT(9) -#define ADIS16209_DIAG_STAT_ALARM1 BIT(8) -#define ADIS16209_DIAG_STAT_SELFTEST_FAIL_BIT 5 -#define ADIS16209_DIAG_STAT_SPI_FAIL_BIT 3 -#define ADIS16209_DIAG_STAT_FLASH_UPT_BIT 2 +#define ADIS16209_STAT_REG 0x3C +#define ADIS16209_STAT_ALARM2 BIT(9) +#define ADIS16209_STAT_ALARM1 BIT(8) +#define ADIS16209_STAT_SELFTEST_FAIL_BIT 5 +#define ADIS16209_STAT_SPI_FAIL_BIT 3 +#define ADIS16209_STAT_FLASH_UPT_FAIL_BIT 2 /* Power supply above 3.625 V */ -#define ADIS16209_DIAG_STAT_POWER_HIGH_BIT 1 +#define ADIS16209_STAT_POWER_HIGH_BIT 1 /* Power supply below 3.15 V */ -#define ADIS16209_DIAG_STAT_POWER_LOW_BIT 0 +#define ADIS16209_STAT_POWER_LOW_BIT 0 -#define ADIS16209_GLOB_CMD_REG 0x3E -#define ADIS16209_GLOB_CMD_SW_RESET BIT(7) -#define ADIS16209_GLOB_CMD_CLEAR_STAT BIT(4) -#define ADIS16209_GLOB_CMD_FACTORY_CAL BIT(1) +#define ADIS16209_CMD_REG 0x3E +#define ADIS16209_CMD_SW_RESET BIT(7) +#define ADIS16209_CMD_CLEAR_STAT BIT(4) +#define ADIS16209_CMD_FACTORY_CAL BIT(1) #define ADIS16209_ERROR_ACTIVE BIT(14) @@ -238,29 +238,29 @@ static const struct iio_info adis16209_info = { }; static const char * const adis16209_status_error_msgs[] = { - [ADIS16209_DIAG_STAT_SELFTEST_FAIL_BIT] = "Self test failure", - [ADIS16209_DIAG_STAT_SPI_FAIL_BIT] = "SPI failure", - [ADIS16209_DIAG_STAT_FLASH_UPT_BIT] = "Flash update failed", - [ADIS16209_DIAG_STAT_POWER_HIGH_BIT] = "Power supply above 3.625V", - [ADIS16209_DIAG_STAT_POWER_LOW_BIT] = "Power supply below 3.15V", + [ADIS16209_STAT_SELFTEST_FAIL_BIT] = "Self test failure", + [ADIS16209_STAT_SPI_FAIL_BIT] = "SPI failure", + [ADIS16209_STAT_FLASH_UPT_FAIL_BIT] = "Flash update failed", + [ADIS16209_STAT_POWER_HIGH_BIT] = "Power supply above 3.625V", + [ADIS16209_STAT_POWER_LOW_BIT] = "Power supply below 3.15V", }; static const struct adis_data adis16209_data = { .read_delay = 30, .msc_ctrl_reg = ADIS16209_MSC_CTRL_REG, - .glob_cmd_reg = ADIS16209_GLOB_CMD_REG, - .diag_stat_reg = ADIS16209_DIAG_STAT_REG, + .glob_cmd_reg = ADIS16209_CMD_REG, + .diag_stat_reg = ADIS16209_STAT_REG, .self_test_mask = ADIS16209_MSC_CTRL_SELF_TEST_EN, .self_test_no_autoclear = true, .startup_delay = ADIS16209_STARTUP_DELAY_MS, .status_error_msgs = adis16209_status_error_msgs, - .status_error_mask = BIT(ADIS16209_DIAG_STAT_SELFTEST_FAIL_BIT) | - BIT(ADIS16209_DIAG_STAT_SPI_FAIL_BIT) | - BIT(ADIS16209_DIAG_STAT_FLASH_UPT_BIT) | - BIT(ADIS16209_DIAG_STAT_POWER_HIGH_BIT) | - BIT(ADIS16209_DIAG_STAT_POWER_LOW_BIT), + .status_error_mask = BIT(ADIS16209_STAT_SELFTEST_FAIL_BIT) | + BIT(ADIS16209_STAT_SPI_FAIL_BIT) | + BIT(ADIS16209_STAT_FLASH_UPT_FAIL_BIT) | + BIT(ADIS16209_STAT_POWER_HIGH_BIT) | + BIT(ADIS16209_STAT_POWER_LOW_BIT), }; static int adis16209_probe(struct spi_device *spi) From 0df8baeab1ee2a5ccd3c725a44a431fcc63fe416 Mon Sep 17 00:00:00 2001 From: Shreeya Patel Date: Sun, 4 Mar 2018 18:13:12 +0530 Subject: [PATCH 26/47] Staging: iio: adis16209: Adjust a switch statement Adjust a switch block to explicitly match channels and return -EINVAL as default case which makes the code semantically more clear. Signed-off-by: Shreeya Patel Signed-off-by: Jonathan Cameron --- drivers/staging/iio/accel/adis16209.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/drivers/staging/iio/accel/adis16209.c b/drivers/staging/iio/accel/adis16209.c index 68a2f2f80f88..8ffde7ea94c4 100644 --- a/drivers/staging/iio/accel/adis16209.c +++ b/drivers/staging/iio/accel/adis16209.c @@ -155,10 +155,16 @@ static int adis16209_read_raw(struct iio_dev *indio_dev, switch (chan->type) { case IIO_VOLTAGE: *val = 0; - if (chan->channel == 0) + switch (chan->channel) { + case 0: *val2 = 305180; /* 0.30518 mV */ - else + break; + case 1: *val2 = 610500; /* 0.6105 mV */ + break; + default: + return -EINVAL; + } return IIO_VAL_INT_PLUS_MICRO; case IIO_TEMP: *val = -470; From 9dd6ec17a8b06a75558b00c50676f847f7fa6513 Mon Sep 17 00:00:00 2001 From: Shreeya Patel Date: Sun, 4 Mar 2018 18:15:06 +0530 Subject: [PATCH 27/47] Staging: iio: adis16209: Use sign_extend32 function Use sign_extend32 function instead of manually coding it. Signed-off-by: Shreeya Patel Signed-off-by: Jonathan Cameron --- drivers/staging/iio/accel/adis16209.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/drivers/staging/iio/accel/adis16209.c b/drivers/staging/iio/accel/adis16209.c index 8ffde7ea94c4..72a18cfe81ee 100644 --- a/drivers/staging/iio/accel/adis16209.c +++ b/drivers/staging/iio/accel/adis16209.c @@ -212,9 +212,8 @@ static int adis16209_read_raw(struct iio_dev *indio_dev, ret = adis_read_reg_16(st, addr, &val16); if (ret) return ret; - val16 &= (1 << bits) - 1; - val16 = (s16)(val16 << (16 - bits)) >> (16 - bits); - *val = val16; + + *val = sign_extend32(val16, bits - 1); return IIO_VAL_INT; } return -EINVAL; From a4a214143ef899a5eb46707f3049f38134d63ccd Mon Sep 17 00:00:00 2001 From: Brian Masney Date: Sat, 3 Mar 2018 20:49:31 -0500 Subject: [PATCH 28/47] staging: iio: tsl2x7x: remove power functions from tsl2X7X_platform_data The tsl2X7X_platform_data structure contains the platform_power, power_on, and power_off function pointers. These power management functions should not be in the platform data. These functions were likely used before the regulator framework was put in place. There are no users of these functions in the mainline kernel. Signed-off-by: Brian Masney Signed-off-by: Jonathan Cameron --- drivers/staging/iio/light/tsl2x7x.c | 18 ------------------ drivers/staging/iio/light/tsl2x7x.h | 4 ---- 2 files changed, 22 deletions(-) diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c index 126e11530ce0..b7e3f966c3a6 100644 --- a/drivers/staging/iio/light/tsl2x7x.c +++ b/drivers/staging/iio/light/tsl2x7x.c @@ -588,9 +588,6 @@ static int tsl2x7x_chip_on(struct iio_dev *indio_dev) struct tsl2X7X_chip *chip = iio_priv(indio_dev); u8 reg_val = 0; - if (chip->pdata && chip->pdata->power_on) - chip->pdata->power_on(indio_dev); - /* Non calculated parameters */ chip->tsl2x7x_config[TSL2X7X_PRX_TIME] = chip->settings.prx_time; chip->tsl2x7x_config[TSL2X7X_WAIT_TIME] = chip->settings.wait_time; @@ -736,9 +733,6 @@ static int tsl2x7x_chip_off(struct iio_dev *indio_dev) ret = i2c_smbus_write_byte_data(chip->client, TSL2X7X_CMD_REG | TSL2X7X_CNTRL, 0x00); - if (chip->pdata && chip->pdata->power_off) - chip->pdata->power_off(chip->client); - return ret; } @@ -1792,12 +1786,6 @@ static int tsl2x7x_suspend(struct device *dev) chip->tsl2x7x_chip_status = TSL2X7X_CHIP_SUSPENDED; } - if (chip->pdata && chip->pdata->platform_power) { - pm_message_t pmm = {PM_EVENT_SUSPEND}; - - chip->pdata->platform_power(dev, pmm); - } - return ret; } @@ -1807,12 +1795,6 @@ static int tsl2x7x_resume(struct device *dev) struct tsl2X7X_chip *chip = iio_priv(indio_dev); int ret = 0; - if (chip->pdata && chip->pdata->platform_power) { - pm_message_t pmm = {PM_EVENT_RESUME}; - - chip->pdata->platform_power(dev, pmm); - } - if (chip->tsl2x7x_chip_status == TSL2X7X_CHIP_SUSPENDED) ret = tsl2x7x_chip_on(indio_dev); diff --git a/drivers/staging/iio/light/tsl2x7x.h b/drivers/staging/iio/light/tsl2x7x.h index df00f2ec1719..6624cbca7a83 100644 --- a/drivers/staging/iio/light/tsl2x7x.h +++ b/drivers/staging/iio/light/tsl2x7x.h @@ -21,7 +21,6 @@ #ifndef __TSL2X7X_H #define __TSL2X7X_H -#include struct tsl2x7x_lux { unsigned int ratio; @@ -91,9 +90,6 @@ struct tsl2x7x_settings { * */ struct tsl2X7X_platform_data { - int (*platform_power)(struct device *dev, pm_message_t); - int (*power_on)(struct iio_dev *indio_dev); - int (*power_off)(struct i2c_client *dev); struct tsl2x7x_lux platform_lux_table[TSL2X7X_MAX_LUX_TABLE_SIZE]; struct tsl2x7x_settings *platform_default_settings; }; From eac15d8ded8f23a7cda681e2b2c7b86cf8535688 Mon Sep 17 00:00:00 2001 From: Brian Masney Date: Sat, 3 Mar 2018 20:49:32 -0500 Subject: [PATCH 29/47] staging: iio: tsl2x7x: add common function for clearing interrupts There were three places where the same chunk of code was used to clear interrupts. This patch creates a common function tsl2x7x_clear_interrupts() to reduce duplicate code. Signed-off-by: Brian Masney Signed-off-by: Jonathan Cameron --- drivers/staging/iio/light/tsl2x7x.c | 52 +++++++++++++---------------- 1 file changed, 24 insertions(+), 28 deletions(-) diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c index b7e3f966c3a6..c02db03ef369 100644 --- a/drivers/staging/iio/light/tsl2x7x.c +++ b/drivers/staging/iio/light/tsl2x7x.c @@ -279,6 +279,20 @@ static const u8 device_channel_config[] = { ALSPRX2 }; +static int tsl2x7x_clear_interrupts(struct tsl2X7X_chip *chip, int reg) +{ + int ret; + + ret = i2c_smbus_write_byte(chip->client, + TSL2X7X_CMD_REG | TSL2X7X_CMD_SPL_FN | reg); + if (ret < 0) + dev_err(&chip->client->dev, + "%s: failed to clear interrupt status %x: %d\n", + __func__, reg, ret); + + return ret; +} + /** * tsl2x7x_get_lux() - Reads and calculates current lux value. * @indio_dev: pointer to IIO device @@ -346,16 +360,9 @@ static int tsl2x7x_get_lux(struct iio_dev *indio_dev) buf[i] = ret; } - /* clear any existing interrupt status */ - ret = i2c_smbus_write_byte(chip->client, - TSL2X7X_CMD_REG | - TSL2X7X_CMD_SPL_FN | - TSL2X7X_CMD_ALS_INT_CLR); - if (ret < 0) { - dev_err(&chip->client->dev, - "i2c_write_command failed - err = %d\n", ret); - goto out_unlock; /* have no data, so return failure */ - } + ret = tsl2x7x_clear_interrupts(chip, TSL2X7X_CMD_ALS_INT_CLR); + if (ret < 0) + goto out_unlock; /* extract ALS/lux data */ ch0 = le16_to_cpup((const __le16 *)&buf[0]); @@ -706,17 +713,10 @@ static int tsl2x7x_chip_on(struct iio_dev *indio_dev) "%s: failed in tsl2x7x_IOCTL_INT_SET.\n", __func__); - /* Clear out any initial interrupts */ - ret = i2c_smbus_write_byte(chip->client, - TSL2X7X_CMD_REG | - TSL2X7X_CMD_SPL_FN | - TSL2X7X_CMD_PROXALS_INT_CLR); - if (ret < 0) { - dev_err(&chip->client->dev, - "%s: Failed to clear Int status\n", - __func__); - return ret; - } + ret = tsl2x7x_clear_interrupts(chip, + TSL2X7X_CMD_PROXALS_INT_CLR); + if (ret < 0) + return ret; } return ret; @@ -1421,14 +1421,10 @@ static irqreturn_t tsl2x7x_event_handler(int irq, void *private) IIO_EV_DIR_EITHER), timestamp); } - /* Clear interrupt now that we have handled it. */ - ret = i2c_smbus_write_byte(chip->client, - TSL2X7X_CMD_REG | TSL2X7X_CMD_SPL_FN | - TSL2X7X_CMD_PROXALS_INT_CLR); + + ret = tsl2x7x_clear_interrupts(chip, TSL2X7X_CMD_PROXALS_INT_CLR); if (ret < 0) - dev_err(&chip->client->dev, - "Failed to clear irq from event handler. err = %d\n", - ret); + return ret; return IRQ_HANDLED; } From 107eb59bc15ccd999b8cd297172691673396ec8f Mon Sep 17 00:00:00 2001 From: Brian Masney Date: Sat, 3 Mar 2018 20:49:33 -0500 Subject: [PATCH 30/47] staging: iio: tsl2x7x: add common function for reading chip status There were three places where the same chunk of code was used to read the chip status. This patch creates a common function tsl2x7x_read_status() to reduce duplicate code. This patch also corrects tsl2x7x_event_handler() to properly check for an error after reading the chip status. Signed-off-by: Brian Masney Signed-off-by: Jonathan Cameron --- drivers/staging/iio/light/tsl2x7x.c | 40 +++++++++++++++++------------ 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c index c02db03ef369..6bb622816660 100644 --- a/drivers/staging/iio/light/tsl2x7x.c +++ b/drivers/staging/iio/light/tsl2x7x.c @@ -293,6 +293,20 @@ static int tsl2x7x_clear_interrupts(struct tsl2X7X_chip *chip, int reg) return ret; } +static int tsl2x7x_read_status(struct tsl2X7X_chip *chip) +{ + int ret; + + ret = i2c_smbus_read_byte_data(chip->client, + TSL2X7X_CMD_REG | TSL2X7X_STATUS); + if (ret < 0) + dev_err(&chip->client->dev, + "%s: failed to read STATUS register: %d\n", __func__, + ret); + + return ret; +} + /** * tsl2x7x_get_lux() - Reads and calculates current lux value. * @indio_dev: pointer to IIO device @@ -332,13 +346,10 @@ static int tsl2x7x_get_lux(struct iio_dev *indio_dev) goto out_unlock; } - ret = i2c_smbus_read_byte_data(chip->client, - TSL2X7X_CMD_REG | TSL2X7X_STATUS); - if (ret < 0) { - dev_err(&chip->client->dev, - "%s: Failed to read STATUS Reg\n", __func__); + ret = tsl2x7x_read_status(chip); + if (ret < 0) goto out_unlock; - } + /* is data new & valid */ if (!(ret & TSL2X7X_STA_ADC_VALID)) { dev_err(&chip->client->dev, @@ -458,12 +469,9 @@ static int tsl2x7x_get_prox(struct iio_dev *indio_dev) return -EBUSY; } - ret = i2c_smbus_read_byte_data(chip->client, - TSL2X7X_CMD_REG | TSL2X7X_STATUS); - if (ret < 0) { - dev_err(&chip->client->dev, "i2c err=%d\n", ret); + ret = tsl2x7x_read_status(chip); + if (ret < 0) goto prox_poll_err; - } switch (chip->id) { case tsl2571: @@ -1396,13 +1404,13 @@ static irqreturn_t tsl2x7x_event_handler(int irq, void *private) struct tsl2X7X_chip *chip = iio_priv(indio_dev); s64 timestamp = iio_get_time_ns(indio_dev); int ret; - u8 value; - value = i2c_smbus_read_byte_data(chip->client, - TSL2X7X_CMD_REG | TSL2X7X_STATUS); + ret = tsl2x7x_read_status(chip); + if (ret < 0) + return ret; /* What type of interrupt do we need to process */ - if (value & TSL2X7X_STA_PRX_INTR) { + if (ret & TSL2X7X_STA_PRX_INTR) { tsl2x7x_get_prox(indio_dev); /* freshen data for ABI */ iio_push_event(indio_dev, IIO_UNMOD_EVENT_CODE(IIO_PROXIMITY, @@ -1412,7 +1420,7 @@ static irqreturn_t tsl2x7x_event_handler(int irq, void *private) timestamp); } - if (value & TSL2X7X_STA_ALS_INTR) { + if (ret & TSL2X7X_STA_ALS_INTR) { tsl2x7x_get_lux(indio_dev); /* freshen data for ABI */ iio_push_event(indio_dev, IIO_UNMOD_EVENT_CODE(IIO_LIGHT, From f5d9bca666078871f27eef6b18e507498840eb70 Mon Sep 17 00:00:00 2001 From: Brian Masney Date: Sat, 3 Mar 2018 20:49:34 -0500 Subject: [PATCH 31/47] staging: iio: tsl2x7x: add common function for writing to the control register There were four places where the same chunk of code was used to write to the control register. This patch creates a common function tsl2x7x_write_control_reg() to reduce duplicate code. The function tsl2x7x_chip_off() did not correctly return an error code so this patch also corrects that issue. Signed-off-by: Brian Masney Signed-off-by: Jonathan Cameron --- drivers/staging/iio/light/tsl2x7x.c | 54 +++++++++++++---------------- 1 file changed, 25 insertions(+), 29 deletions(-) diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c index 6bb622816660..cf16dd206c0b 100644 --- a/drivers/staging/iio/light/tsl2x7x.c +++ b/drivers/staging/iio/light/tsl2x7x.c @@ -307,6 +307,21 @@ static int tsl2x7x_read_status(struct tsl2X7X_chip *chip) return ret; } +static int tsl2x7x_write_control_reg(struct tsl2X7X_chip *chip, u8 data) +{ + int ret; + + ret = i2c_smbus_write_byte_data(chip->client, + TSL2X7X_CMD_REG | TSL2X7X_CNTRL, data); + if (ret < 0) { + dev_err(&chip->client->dev, + "%s: failed to write to control register %x: %d\n", + __func__, data, ret); + } + + return ret; +} + /** * tsl2x7x_get_lux() - Reads and calculates current lux value. * @indio_dev: pointer to IIO device @@ -597,7 +612,6 @@ static int tsl2x7x_chip_on(struct iio_dev *indio_dev) int i; int ret = 0; u8 *dev_reg; - u8 utmp; int als_count; int als_time; struct tsl2X7X_chip *chip = iio_priv(indio_dev); @@ -659,14 +673,9 @@ static int tsl2x7x_chip_on(struct iio_dev *indio_dev) * TSL2X7X Specific power-on / adc enable sequence * Power on the device 1st. */ - utmp = TSL2X7X_CNTL_PWR_ON; - ret = i2c_smbus_write_byte_data(chip->client, - TSL2X7X_CMD_REG | TSL2X7X_CNTRL, utmp); - if (ret < 0) { - dev_err(&chip->client->dev, - "%s: failed on CNTRL reg.\n", __func__); + ret = tsl2x7x_write_control_reg(chip, TSL2X7X_CNTL_PWR_ON); + if (ret < 0) return ret; - } /* * Use the following shadow copy for our delay before enabling ADC. @@ -691,16 +700,12 @@ static int tsl2x7x_chip_on(struct iio_dev *indio_dev) * NOW enable the ADC * initialize the desired mode of operation */ - utmp = TSL2X7X_CNTL_PWR_ON | - TSL2X7X_CNTL_ADC_ENBL | - TSL2X7X_CNTL_PROX_DET_ENBL; - ret = i2c_smbus_write_byte_data(chip->client, - TSL2X7X_CMD_REG | TSL2X7X_CNTRL, utmp); - if (ret < 0) { - dev_err(&chip->client->dev, - "%s: failed on 2nd CTRL reg.\n", __func__); + ret = tsl2x7x_write_control_reg(chip, + TSL2X7X_CNTL_PWR_ON | + TSL2X7X_CNTL_ADC_ENBL | + TSL2X7X_CNTL_PROX_DET_ENBL); + if (ret < 0) return ret; - } chip->tsl2x7x_chip_status = TSL2X7X_CHIP_WORKING; @@ -713,13 +718,9 @@ static int tsl2x7x_chip_on(struct iio_dev *indio_dev) reg_val |= TSL2X7X_CNTL_PROX_DET_ENBL; reg_val |= chip->settings.interrupts_en; - ret = i2c_smbus_write_byte_data(chip->client, - TSL2X7X_CMD_REG | TSL2X7X_CNTRL, - reg_val); + ret = tsl2x7x_write_control_reg(chip, reg_val); if (ret < 0) - dev_err(&chip->client->dev, - "%s: failed in tsl2x7x_IOCTL_INT_SET.\n", - __func__); + return ret; ret = tsl2x7x_clear_interrupts(chip, TSL2X7X_CMD_PROXALS_INT_CLR); @@ -732,16 +733,11 @@ static int tsl2x7x_chip_on(struct iio_dev *indio_dev) static int tsl2x7x_chip_off(struct iio_dev *indio_dev) { - int ret; struct tsl2X7X_chip *chip = iio_priv(indio_dev); /* turn device off */ chip->tsl2x7x_chip_status = TSL2X7X_CHIP_SUSPENDED; - - ret = i2c_smbus_write_byte_data(chip->client, - TSL2X7X_CMD_REG | TSL2X7X_CNTRL, 0x00); - - return ret; + return tsl2x7x_write_control_reg(chip, 0x00); } /** From a0722d05a19542616a42b6239165d7ac9c542057 Mon Sep 17 00:00:00 2001 From: Brian Masney Date: Sat, 3 Mar 2018 20:49:35 -0500 Subject: [PATCH 32/47] staging: iio: tsl2x7x: convert mutex_trylock() to mutex_lock() The driver uses mutex_lock() and mutex_trylock() in several places. Convert the mutex_trylock() to mutex_lock() for consistency with other IIO light drivers in mainline. Signed-off-by: Brian Masney Signed-off-by: Jonathan Cameron --- drivers/staging/iio/light/tsl2x7x.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c index cf16dd206c0b..5c611250127f 100644 --- a/drivers/staging/iio/light/tsl2x7x.c +++ b/drivers/staging/iio/light/tsl2x7x.c @@ -350,8 +350,7 @@ static int tsl2x7x_get_lux(struct iio_dev *indio_dev) u32 ch0lux = 0; u32 ch1lux = 0; - if (mutex_trylock(&chip->als_mutex) == 0) - return chip->als_cur_info.lux; /* busy, so return LAST VALUE */ + mutex_lock(&chip->als_mutex); if (chip->tsl2x7x_chip_status != TSL2X7X_CHIP_WORKING) { /* device is not enabled */ @@ -478,11 +477,7 @@ static int tsl2x7x_get_prox(struct iio_dev *indio_dev) u8 chdata[2]; struct tsl2X7X_chip *chip = iio_priv(indio_dev); - if (mutex_trylock(&chip->prox_mutex) == 0) { - dev_err(&chip->client->dev, - "%s: Can't get prox mutex\n", __func__); - return -EBUSY; - } + mutex_lock(&chip->prox_mutex); ret = tsl2x7x_read_status(chip); if (ret < 0) From 07ab2f4fac0f6ef62d8201713068bfbc8cba7f1a Mon Sep 17 00:00:00 2001 From: Brian Masney Date: Sat, 3 Mar 2018 20:49:36 -0500 Subject: [PATCH 33/47] staging: iio: tsl2x7x: correctly return errors in tsl2x7x_get_prox() Not all errors that occurred in tsl2x7x_get_prox() were correctly reported in the return value. This patch changes the error handling so that errors are now returned properly. Note that the ret variable is from the call to tsl2x7x_read_status(), and it already has the correct error check. The -EINVAL error code is for an unexpected value in the register. This patch also corrects an unnecessary word wrap in the call to le16_to_cpup() while changes are being made to this code. Signed-off-by: Brian Masney Signed-off-by: Jonathan Cameron --- drivers/staging/iio/light/tsl2x7x.c | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c index 5c611250127f..cc209b64ed5a 100644 --- a/drivers/staging/iio/light/tsl2x7x.c +++ b/drivers/staging/iio/light/tsl2x7x.c @@ -489,16 +489,20 @@ static int tsl2x7x_get_prox(struct iio_dev *indio_dev) case tmd2671: case tsl2771: case tmd2771: - if (!(ret & TSL2X7X_STA_ADC_VALID)) + if (!(ret & TSL2X7X_STA_ADC_VALID)) { + ret = -EINVAL; goto prox_poll_err; + } break; case tsl2572: case tsl2672: case tmd2672: case tsl2772: case tmd2772: - if (!(ret & TSL2X7X_STA_PRX_VALID)) + if (!(ret & TSL2X7X_STA_PRX_VALID)) { + ret = -EINVAL; goto prox_poll_err; + } break; } @@ -512,14 +516,13 @@ static int tsl2x7x_get_prox(struct iio_dev *indio_dev) chdata[i] = ret; } - chip->prox_data = - le16_to_cpup((const __le16 *)&chdata[0]); + chip->prox_data = le16_to_cpup((const __le16 *)&chdata[0]); + ret = chip->prox_data; prox_poll_err: - mutex_unlock(&chip->prox_mutex); - return chip->prox_data; + return ret; } /** From 6f80ff9ec8533991c854082cce1ea3e024da36a5 Mon Sep 17 00:00:00 2001 From: Brian Masney Date: Sat, 3 Mar 2018 20:49:37 -0500 Subject: [PATCH 34/47] staging: iio: tsl2x7x: correct 'Avoid CamelCase' warning from checkpatch The statP and calP variables triggered an 'Avoid CamelCase' warning from checkpatch.pl. This patch renames these variables to stat and cal to fix this warning. Signed-off-by: Brian Masney Signed-off-by: Jonathan Cameron --- drivers/staging/iio/light/tsl2x7x.c | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c index cc209b64ed5a..380a6c96a69a 100644 --- a/drivers/staging/iio/light/tsl2x7x.c +++ b/drivers/staging/iio/light/tsl2x7x.c @@ -773,7 +773,7 @@ unlock: } static void tsl2x7x_prox_calculate(int *data, int length, - struct tsl2x7x_prox_stat *statP) + struct tsl2x7x_prox_stat *stat) { int i; int sample_sum; @@ -783,21 +783,21 @@ static void tsl2x7x_prox_calculate(int *data, int length, length = 1; sample_sum = 0; - statP->min = INT_MAX; - statP->max = INT_MIN; + stat->min = INT_MAX; + stat->max = INT_MIN; for (i = 0; i < length; i++) { sample_sum += data[i]; - statP->min = min(statP->min, data[i]); - statP->max = max(statP->max, data[i]); + stat->min = min(stat->min, data[i]); + stat->max = max(stat->max, data[i]); } - statP->mean = sample_sum / length; + stat->mean = sample_sum / length; sample_sum = 0; for (i = 0; i < length; i++) { - tmp = data[i] - statP->mean; + tmp = data[i] - stat->mean; sample_sum += tmp * tmp; } - statP->stddev = int_sqrt((long)sample_sum / length); + stat->stddev = int_sqrt((long)sample_sum / length); } /** @@ -812,7 +812,7 @@ static void tsl2x7x_prox_cal(struct iio_dev *indio_dev) int prox_history[MAX_SAMPLES_CAL + 1]; int i; struct tsl2x7x_prox_stat prox_stat_data[2]; - struct tsl2x7x_prox_stat *calP; + struct tsl2x7x_prox_stat *cal; struct tsl2X7X_chip *chip = iio_priv(indio_dev); u8 tmp_irq_settings; u8 current_state = chip->tsl2x7x_chip_status; @@ -844,13 +844,13 @@ static void tsl2x7x_prox_cal(struct iio_dev *indio_dev) } tsl2x7x_chip_off(indio_dev); - calP = &prox_stat_data[PROX_STAT_CAL]; + cal = &prox_stat_data[PROX_STAT_CAL]; tsl2x7x_prox_calculate(prox_history, - chip->settings.prox_max_samples_cal, calP); - chip->settings.prox_thres_high = (calP->max << 1) - calP->mean; + chip->settings.prox_max_samples_cal, cal); + chip->settings.prox_thres_high = (cal->max << 1) - cal->mean; dev_info(&chip->client->dev, " cal min=%d mean=%d max=%d\n", - calP->min, calP->mean, calP->max); + cal->min, cal->mean, cal->max); dev_info(&chip->client->dev, "%s proximity threshold set to %d\n", chip->client->name, chip->settings.prox_thres_high); From dbe0f59c7cdaf3815fa6cb13cd925e9736f33388 Mon Sep 17 00:00:00 2001 From: Brian Masney Date: Sat, 3 Mar 2018 20:49:38 -0500 Subject: [PATCH 35/47] staging: iio: tsl2x7x: add error handling to tsl2x7x_prox_cal() tsl2x7x_prox_cal() did not have any error checks. This patch adds the missing error handling and ensures that any errors are reported to user space via in_proximity0_calibrate_store(). Signed-off-by: Brian Masney Signed-off-by: Jonathan Cameron --- drivers/staging/iio/light/tsl2x7x.c | 36 +++++++++++++++++++++-------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c index 380a6c96a69a..8adc6db44790 100644 --- a/drivers/staging/iio/light/tsl2x7x.c +++ b/drivers/staging/iio/light/tsl2x7x.c @@ -807,10 +807,10 @@ static void tsl2x7x_prox_calculate(int *data, int length, * Calculates a standard deviation based on the samples, * and sets the threshold accordingly. */ -static void tsl2x7x_prox_cal(struct iio_dev *indio_dev) +static int tsl2x7x_prox_cal(struct iio_dev *indio_dev) { int prox_history[MAX_SAMPLES_CAL + 1]; - int i; + int i, ret; struct tsl2x7x_prox_stat prox_stat_data[2]; struct tsl2x7x_prox_stat *cal; struct tsl2X7X_chip *chip = iio_priv(indio_dev); @@ -825,25 +825,33 @@ static void tsl2x7x_prox_cal(struct iio_dev *indio_dev) } /* have to stop to change settings */ - tsl2x7x_chip_off(indio_dev); + ret = tsl2x7x_chip_off(indio_dev); + if (ret < 0) + return ret; /* Enable proximity detection save just in case prox not wanted yet*/ tmp_irq_settings = chip->settings.interrupts_en; chip->settings.interrupts_en |= TSL2X7X_CNTL_PROX_INT_ENBL; /*turn on device if not already on*/ - tsl2x7x_chip_on(indio_dev); + ret = tsl2x7x_chip_on(indio_dev); + if (ret < 0) + return ret; /*gather the samples*/ for (i = 0; i < chip->settings.prox_max_samples_cal; i++) { usleep_range(15000, 17500); - tsl2x7x_get_prox(indio_dev); + ret = tsl2x7x_get_prox(indio_dev); + if (ret < 0) + return ret; prox_history[i] = chip->prox_data; dev_info(&chip->client->dev, "2 i=%d prox data= %d\n", i, chip->prox_data); } - tsl2x7x_chip_off(indio_dev); + ret = tsl2x7x_chip_off(indio_dev); + if (ret < 0) + return ret; cal = &prox_stat_data[PROX_STAT_CAL]; tsl2x7x_prox_calculate(prox_history, chip->settings.prox_max_samples_cal, cal); @@ -857,8 +865,13 @@ static void tsl2x7x_prox_cal(struct iio_dev *indio_dev) /* back to the way they were */ chip->settings.interrupts_en = tmp_irq_settings; - if (current_state == TSL2X7X_CHIP_WORKING) - tsl2x7x_chip_on(indio_dev); + if (current_state == TSL2X7X_CHIP_WORKING) { + ret = tsl2x7x_chip_on(indio_dev); + if (ret < 0) + return ret; + } + + return 0; } static ssize_t @@ -1018,8 +1031,11 @@ static ssize_t in_proximity0_calibrate_store(struct device *dev, if (strtobool(buf, &value)) return -EINVAL; - if (value) - tsl2x7x_prox_cal(indio_dev); + if (value) { + ret = tsl2x7x_prox_cal(indio_dev); + if (ret < 0) + return ret; + } ret = tsl2x7x_invoke_change(indio_dev); if (ret < 0) From 8514976685e664df8cdeaf737a3f73e1e33bc7bd Mon Sep 17 00:00:00 2001 From: Brian Masney Date: Sat, 3 Mar 2018 20:49:39 -0500 Subject: [PATCH 36/47] staging: iio: tsl2x7x: add missing error checks The functions in_illuminance0_calibrate_store() and in_illuminance0_lux_table_store() did not have complete error handling in place. This patch adds the missing error handling. Signed-off-by: Brian Masney Signed-off-by: Jonathan Cameron --- drivers/staging/iio/light/tsl2x7x.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c index 8adc6db44790..da7a4e025083 100644 --- a/drivers/staging/iio/light/tsl2x7x.c +++ b/drivers/staging/iio/light/tsl2x7x.c @@ -940,8 +940,11 @@ static ssize_t in_illuminance0_calibrate_store(struct device *dev, if (strtobool(buf, &value)) return -EINVAL; - if (value) - tsl2x7x_als_calibrate(indio_dev); + if (value) { + ret = tsl2x7x_als_calibrate(indio_dev); + if (ret < 0) + return ret; + } ret = tsl2x7x_invoke_change(indio_dev); if (ret < 0) @@ -1006,8 +1009,11 @@ static ssize_t in_illuminance0_lux_table_store(struct device *dev, return -EINVAL; } - if (chip->tsl2x7x_chip_status == TSL2X7X_CHIP_WORKING) - tsl2x7x_chip_off(indio_dev); + if (chip->tsl2x7x_chip_status == TSL2X7X_CHIP_WORKING) { + ret = tsl2x7x_chip_off(indio_dev); + if (ret < 0) + return ret; + } /* Zero out the table */ memset(chip->tsl2x7x_device_lux, 0, sizeof(chip->tsl2x7x_device_lux)); From 8d923921f9ae2a1bc20ce37a2abcc2dbce16188e Mon Sep 17 00:00:00 2001 From: Brian Masney Date: Sat, 3 Mar 2018 20:49:41 -0500 Subject: [PATCH 37/47] staging: iio: tsl2x7x: remove unnecessary sysfs attribute The tsl2771 and tmd2771 devices create the in_proximity0_calibscale_available sysfs attribute. These two particular devices do not support changing the proximity gain value on the chip so this patch removes that sysfs attribute. As expected, these two devices already did not create the IIO_CHAN_INFO_CALIBSCALE channel and proximity0_calibrate sysfs attribute. Page 38 of the tsl2772 data sheet shows that the proximity gain can be adjusted with bits 2-3 on the control register: https://ams.com/eng/content/download/291503/1066377/file/TSL2772_DS000181_2-00.pdf Page 35 of the tsl2771 and tmd2771 data sheets shows that bits 2-3 on the control register are reserved and changing the proximity gain is not supported: https://ams.com/eng/content/download/250264/976045/file/TSL2771_DS000105_3-00.pdf https://ams.com/eng/content/download/250283/976077/file/TMD2771_DS000177_2-00.pdf Signed-off-by: Brian Masney Signed-off-by: Jonathan Cameron --- drivers/staging/iio/light/tsl2x7x.c | 1 - 1 file changed, 1 deletion(-) diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c index da7a4e025083..c2b08a5d5b0e 100644 --- a/drivers/staging/iio/light/tsl2x7x.c +++ b/drivers/staging/iio/light/tsl2x7x.c @@ -1475,7 +1475,6 @@ static struct attribute *tsl2x7x_ALSPRX_device_attrs[] = { &dev_attr_in_illuminance0_target_input.attr, &dev_attr_in_illuminance0_calibrate.attr, &dev_attr_in_illuminance0_lux_table.attr, - &iio_const_attr_in_proximity0_calibscale_available.dev_attr.attr, NULL }; From 2ab5b72453672ea18a176925becc40888df435ce Mon Sep 17 00:00:00 2001 From: Brian Masney Date: Sat, 3 Mar 2018 20:49:42 -0500 Subject: [PATCH 38/47] staging: iio: tsl2x7x: make proximity sensor function correctly The bits for setting up the proximity diode were not setup correctly and this was causing the proximity sensor to not function correctly. This patch sets up the correct bit mask in tsl2x7x_chip_on() based on what the data sheet expects. From page 35 of the TSL2771 data sheet: https://ams.com/eng/content/download/250264/976045/file/TSL2771_DS000105_3-00.pdf - Bits 0-1 is the ALS gain control - Bits 2-3 is reserved (The proximity gain control on other tsl2x7x chips) - Bits 4-5 is the proximity diode select - Bits 6-7 is the LED drive strength tsl2x7x_chip_on() had the power and diode hardcoded, so these are extracted out into the settings so that these fields can be configured in the platform data. The default prox_gain is changed from 1 (2X gain) to 0 (1X gain) since the proximity gain control on the TSL2771, TMD2771, and other chips have these fields listed as reserved, and to write 0 into those bits. Verified that the proximity sensor now works correctly on a TSL2771 hooked up to a Raspberry Pi 2. Signed-off-by: Brian Masney Signed-off-by: Jonathan Cameron --- drivers/staging/iio/light/tsl2x7x.c | 25 ++++++++++++++----------- drivers/staging/iio/light/tsl2x7x.h | 2 ++ 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/drivers/staging/iio/light/tsl2x7x.c b/drivers/staging/iio/light/tsl2x7x.c index c2b08a5d5b0e..82681300e106 100644 --- a/drivers/staging/iio/light/tsl2x7x.c +++ b/drivers/staging/iio/light/tsl2x7x.c @@ -109,15 +109,15 @@ #define TSL2X7X_CNTL_INTPROXPON_ENBL 0x2F /*Prox diode to use */ -#define TSL2X7X_DIODE0 0x10 -#define TSL2X7X_DIODE1 0x20 -#define TSL2X7X_DIODE_BOTH 0x30 +#define TSL2X7X_DIODE0 0x01 +#define TSL2X7X_DIODE1 0x02 +#define TSL2X7X_DIODE_BOTH 0x03 /* LED Power */ #define TSL2X7X_100_mA 0x00 -#define TSL2X7X_50_mA 0x40 -#define TSL2X7X_25_mA 0x80 -#define TSL2X7X_13_mA 0xD0 +#define TSL2X7X_50_mA 0x01 +#define TSL2X7X_25_mA 0x02 +#define TSL2X7X_13_mA 0x03 #define TSL2X7X_MAX_TIMER_CNT 0xFF #define TSL2X7X_MIN_ITIME 3 @@ -228,7 +228,7 @@ static const struct tsl2x7x_settings tsl2x7x_default_settings = { .als_time = 219, /* 101 ms */ .als_gain = 0, .prx_time = 254, /* 5.4 ms */ - .prox_gain = 1, + .prox_gain = 0, .wait_time = 245, .prox_config = 0, .als_gain_trim = 1000, @@ -240,7 +240,9 @@ static const struct tsl2x7x_settings tsl2x7x_default_settings = { .prox_thres_low = 0, .prox_thres_high = 512, .prox_max_samples_cal = 30, - .prox_pulse_count = 8 + .prox_pulse_count = 8, + .prox_diode = TSL2X7X_DIODE1, + .prox_power = TSL2X7X_100_mA }; static const s16 tsl2x7x_als_gain[] = { @@ -659,9 +661,10 @@ static int tsl2x7x_chip_on(struct iio_dev *indio_dev) /* Set the gain based on tsl2x7x_settings struct */ chip->tsl2x7x_config[TSL2X7X_GAIN] = - chip->settings.als_gain | - (TSL2X7X_100_mA | TSL2X7X_DIODE1) | - (chip->settings.prox_gain << 2); + (chip->settings.als_gain & 0xFF) | + ((chip->settings.prox_gain & 0xFF) << 2) | + (chip->settings.prox_diode << 4) | + (chip->settings.prox_power << 6); /* set chip struct re scaling and saturation */ chip->als_saturation = als_count * 922; /* 90% of full scale */ diff --git a/drivers/staging/iio/light/tsl2x7x.h b/drivers/staging/iio/light/tsl2x7x.h index 6624cbca7a83..28b0e7fdc9b8 100644 --- a/drivers/staging/iio/light/tsl2x7x.h +++ b/drivers/staging/iio/light/tsl2x7x.h @@ -78,6 +78,8 @@ struct tsl2x7x_settings { int prox_thres_high; int prox_pulse_count; int prox_max_samples_cal; + int prox_diode; + int prox_power; }; /** From a937729c9358f1c66a444af1f4f64ececc9a2f68 Mon Sep 17 00:00:00 2001 From: Himanshu Jha Date: Fri, 9 Mar 2018 00:15:33 +0530 Subject: [PATCH 39/47] iio: potentiometer: ds1803: Remove VLA usage In preparation to enabling -Wvla, remove VLA usage and replace it with fixed a fixed length array and therefore, prevent potential stack overflow attacks. Fixed as a part of the discussion to remove all VLAs from the kernel: https://lkml.org/lkml/2018/3/7/621 Cc: keescook@chromium.org Signed-off-by: Himanshu Jha Signed-off-by: Jonathan Cameron --- drivers/iio/potentiometer/ds1803.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/iio/potentiometer/ds1803.c b/drivers/iio/potentiometer/ds1803.c index 9b0ff4ab2f9c..6bf12c9eccbd 100644 --- a/drivers/iio/potentiometer/ds1803.c +++ b/drivers/iio/potentiometer/ds1803.c @@ -64,7 +64,7 @@ static int ds1803_read_raw(struct iio_dev *indio_dev, struct ds1803_data *data = iio_priv(indio_dev); int pot = chan->channel; int ret; - u8 result[indio_dev->num_channels]; + u8 result[ARRAY_SIZE(ds1803_channels)]; switch (mask) { case IIO_CHAN_INFO_RAW: From 1237a3d4a04827d62eceb664e56898f84c909524 Mon Sep 17 00:00:00 2001 From: David Veenstra Date: Thu, 8 Mar 2018 10:47:29 +0100 Subject: [PATCH 40/47] Staging: iio: adt7316: Move symbol export to definition This patch clears the following checkpatch.pl warning: WARNING: EXPORT_SYMBOL(foo); should immediately follow its function/variable +EXPORT_SYMBOL_GPL(adt7316_pm_ops); Signed-off-by: David Veenstra Signed-off-by: Jonathan Cameron --- drivers/staging/iio/addac/adt7316.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/drivers/staging/iio/addac/adt7316.c b/drivers/staging/iio/addac/adt7316.c index 2d33632c00e8..3f22d1088713 100644 --- a/drivers/staging/iio/addac/adt7316.c +++ b/drivers/staging/iio/addac/adt7316.c @@ -2079,9 +2079,8 @@ static int adt7316_enable(struct device *dev) return _adt7316_store_enabled(chip, 1); } - -SIMPLE_DEV_PM_OPS(adt7316_pm_ops, adt7316_disable, adt7316_enable); EXPORT_SYMBOL_GPL(adt7316_pm_ops); +SIMPLE_DEV_PM_OPS(adt7316_pm_ops, adt7316_disable, adt7316_enable); #endif static const struct iio_info adt7316_info = { From d90f21408bf923aee0fd778fa6fb877ea006a198 Mon Sep 17 00:00:00 2001 From: David Veenstra Date: Thu, 8 Mar 2018 10:48:13 +0100 Subject: [PATCH 41/47] Staging: iio: ad7746: Adjust arguments to match open parenthesis This patch clears all checkpatch.pl CHECKS, about alignment not matching open parenthesis, whenever it is possible without going beyond 80 columns. Signed-off-by: David Veenstra Signed-off-by: Jonathan Cameron --- drivers/staging/iio/cdc/ad7746.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/staging/iio/cdc/ad7746.c b/drivers/staging/iio/cdc/ad7746.c index c4a864725376..4882dbc81c53 100644 --- a/drivers/staging/iio/cdc/ad7746.c +++ b/drivers/staging/iio/cdc/ad7746.c @@ -217,7 +217,7 @@ static const unsigned char ad7746_cap_filter_rate_table[][2] = { }; static int ad7746_select_channel(struct iio_dev *indio_dev, - struct iio_chan_spec const *chan) + struct iio_chan_spec const *chan) { struct ad7746_chip_info *chip = iio_priv(indio_dev); int ret, delay, idx; @@ -487,13 +487,13 @@ static int ad7746_write_raw(struct iio_dev *indio_dev, AD7746_CAPDAC_DACP(val) | AD7746_CAPDAC_DACEN : 0; ret = i2c_smbus_write_byte_data(chip->client, - AD7746_REG_CAPDACA, - chip->capdac[chan->channel][0]); + AD7746_REG_CAPDACA, + chip->capdac[chan->channel][0]); if (ret < 0) goto out; ret = i2c_smbus_write_byte_data(chip->client, - AD7746_REG_CAPDACB, - chip->capdac[chan->channel][1]); + AD7746_REG_CAPDACB, + chip->capdac[chan->channel][1]); if (ret < 0) goto out; @@ -675,7 +675,7 @@ static const struct iio_info ad7746_info = { */ static int ad7746_probe(struct i2c_client *client, - const struct i2c_device_id *id) + const struct i2c_device_id *id) { struct ad7746_platform_data *pdata = client->dev.platform_data; struct ad7746_chip_info *chip; From 5214ad6dcc1bf72ea60a72741a0143356b8d66b7 Mon Sep 17 00:00:00 2001 From: Peter Rosin Date: Thu, 8 Mar 2018 20:58:30 +0100 Subject: [PATCH 42/47] iio: potentiometer: mcp4018: driver for Microchip digital potentiometers Add support for Microchip digital potentiometers and rheostats MCP4017, MCP4018, MCP4019 They all have one wiper with 128 steps and come in 5, 10, 50 and 100 kOhm variations. Datasheet: http://www.microchip.com/downloads/en/DeviceDoc/22147a.pdf Signed-off-by: Peter Rosin Signed-off-by: Jonathan Cameron --- MAINTAINERS | 3 +- drivers/iio/potentiometer/Kconfig | 11 ++ drivers/iio/potentiometer/Makefile | 1 + drivers/iio/potentiometer/mcp4018.c | 194 ++++++++++++++++++++++++++++ 4 files changed, 208 insertions(+), 1 deletion(-) create mode 100644 drivers/iio/potentiometer/mcp4018.c diff --git a/MAINTAINERS b/MAINTAINERS index 885d20072d97..36f1442a9aae 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -8586,11 +8586,12 @@ W: https://linuxtv.org S: Maintained F: drivers/media/radio/radio-maxiradio* -MCP4531 MICROCHIP DIGITAL POTENTIOMETER DRIVER +MCP4018 AND MCP4531 MICROCHIP DIGITAL POTENTIOMETER DRIVERS M: Peter Rosin L: linux-iio@vger.kernel.org S: Maintained F: Documentation/ABI/testing/sysfs-bus-iio-potentiometer-mcp4531 +F: drivers/iio/potentiometer/mcp4018.c F: drivers/iio/potentiometer/mcp4531.c MEASUREMENT COMPUTING CIO-DAC IIO DRIVER diff --git a/drivers/iio/potentiometer/Kconfig b/drivers/iio/potentiometer/Kconfig index 8daf6d1f4e05..79ec2eba4969 100644 --- a/drivers/iio/potentiometer/Kconfig +++ b/drivers/iio/potentiometer/Kconfig @@ -47,6 +47,17 @@ config MAX5487 To compile this driver as a module, choose M here: the module will be called max5487. +config MCP4018 + tristate "Microchip MCP4017/18/19 Digital Potentiometer driver" + depends on I2C + help + Say yes here to build support for the Microchip + MCP4017, MCP4018, MCP4019 + digital potentiometer chips. + + To compile this driver as a module, choose M here: the + module will be called mcp4018. + config MCP4131 tristate "Microchip MCP413X/414X/415X/416X/423X/424X/425X/426X Digital Potentiometer driver" depends on SPI diff --git a/drivers/iio/potentiometer/Makefile b/drivers/iio/potentiometer/Makefile index dbc139cec376..4af657883c3f 100644 --- a/drivers/iio/potentiometer/Makefile +++ b/drivers/iio/potentiometer/Makefile @@ -8,6 +8,7 @@ obj-$(CONFIG_AD5272) += ad5272.o obj-$(CONFIG_DS1803) += ds1803.o obj-$(CONFIG_MAX5481) += max5481.o obj-$(CONFIG_MAX5487) += max5487.o +obj-$(CONFIG_MCP4018) += mcp4018.o obj-$(CONFIG_MCP4131) += mcp4131.o obj-$(CONFIG_MCP4531) += mcp4531.o obj-$(CONFIG_TPL0102) += tpl0102.o diff --git a/drivers/iio/potentiometer/mcp4018.c b/drivers/iio/potentiometer/mcp4018.c new file mode 100644 index 000000000000..601b25d1f387 --- /dev/null +++ b/drivers/iio/potentiometer/mcp4018.c @@ -0,0 +1,194 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Industrial I/O driver for Microchip digital potentiometers + * Copyright (c) 2018 Axentia Technologies AB + * Author: Peter Rosin + * + * Datasheet: http://www.microchip.com/downloads/en/DeviceDoc/22147a.pdf + * + * DEVID #Wipers #Positions Resistor Opts (kOhm) + * mcp4017 1 128 5, 10, 50, 100 + * mcp4018 1 128 5, 10, 50, 100 + * mcp4019 1 128 5, 10, 50, 100 + */ + +#include +#include +#include +#include +#include +#include + +#define MCP4018_WIPER_MAX 127 + +struct mcp4018_cfg { + int kohms; +}; + +enum mcp4018_type { + MCP4018_502, + MCP4018_103, + MCP4018_503, + MCP4018_104, +}; + +static const struct mcp4018_cfg mcp4018_cfg[] = { + [MCP4018_502] = { .kohms = 5, }, + [MCP4018_103] = { .kohms = 10, }, + [MCP4018_503] = { .kohms = 50, }, + [MCP4018_104] = { .kohms = 100, }, +}; + +struct mcp4018_data { + struct i2c_client *client; + const struct mcp4018_cfg *cfg; +}; + +static const struct iio_chan_spec mcp4018_channel = { + .type = IIO_RESISTANCE, + .indexed = 1, + .output = 1, + .channel = 0, + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), + .info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE), +}; + +static int mcp4018_read_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int *val, int *val2, long mask) +{ + struct mcp4018_data *data = iio_priv(indio_dev); + s32 ret; + + switch (mask) { + case IIO_CHAN_INFO_RAW: + ret = i2c_smbus_read_byte(data->client); + if (ret < 0) + return ret; + *val = ret; + return IIO_VAL_INT; + case IIO_CHAN_INFO_SCALE: + *val = 1000 * data->cfg->kohms; + *val2 = MCP4018_WIPER_MAX; + return IIO_VAL_FRACTIONAL; + } + + return -EINVAL; +} + +static int mcp4018_write_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int val, int val2, long mask) +{ + struct mcp4018_data *data = iio_priv(indio_dev); + + switch (mask) { + case IIO_CHAN_INFO_RAW: + if (val > MCP4018_WIPER_MAX || val < 0) + return -EINVAL; + break; + default: + return -EINVAL; + } + + return i2c_smbus_write_byte(data->client, val); +} + +static const struct iio_info mcp4018_info = { + .read_raw = mcp4018_read_raw, + .write_raw = mcp4018_write_raw, +}; + +#ifdef CONFIG_OF + +#define MCP4018_COMPATIBLE(of_compatible, cfg) { \ + .compatible = of_compatible, \ + .data = &mcp4018_cfg[cfg], \ +} + +static const struct of_device_id mcp4018_of_match[] = { + MCP4018_COMPATIBLE("microchip,mcp4017-502", MCP4018_502), + MCP4018_COMPATIBLE("microchip,mcp4017-103", MCP4018_103), + MCP4018_COMPATIBLE("microchip,mcp4017-503", MCP4018_503), + MCP4018_COMPATIBLE("microchip,mcp4017-104", MCP4018_104), + MCP4018_COMPATIBLE("microchip,mcp4018-502", MCP4018_502), + MCP4018_COMPATIBLE("microchip,mcp4018-103", MCP4018_103), + MCP4018_COMPATIBLE("microchip,mcp4018-503", MCP4018_503), + MCP4018_COMPATIBLE("microchip,mcp4018-104", MCP4018_104), + MCP4018_COMPATIBLE("microchip,mcp4019-502", MCP4018_502), + MCP4018_COMPATIBLE("microchip,mcp4019-103", MCP4018_103), + MCP4018_COMPATIBLE("microchip,mcp4019-503", MCP4018_503), + MCP4018_COMPATIBLE("microchip,mcp4019-104", MCP4018_104), + { /* sentinel */ } +}; +MODULE_DEVICE_TABLE(of, mcp4018_of_match); + +#endif + +static int mcp4018_probe(struct i2c_client *client, + const struct i2c_device_id *id) +{ + struct device *dev = &client->dev; + struct mcp4018_data *data; + struct iio_dev *indio_dev; + const struct of_device_id *match; + + if (!i2c_check_functionality(client->adapter, + I2C_FUNC_SMBUS_BYTE)) { + dev_err(dev, "SMBUS Byte transfers not supported\n"); + return -EOPNOTSUPP; + } + + indio_dev = devm_iio_device_alloc(dev, sizeof(*data)); + if (!indio_dev) + return -ENOMEM; + data = iio_priv(indio_dev); + i2c_set_clientdata(client, indio_dev); + data->client = client; + + match = of_match_device(of_match_ptr(mcp4018_of_match), dev); + if (match) + data->cfg = of_device_get_match_data(dev); + else + data->cfg = &mcp4018_cfg[id->driver_data]; + + indio_dev->dev.parent = dev; + indio_dev->info = &mcp4018_info; + indio_dev->channels = &mcp4018_channel; + indio_dev->num_channels = 1; + indio_dev->name = client->name; + + return devm_iio_device_register(dev, indio_dev); +} + +static const struct i2c_device_id mcp4018_id[] = { + { "mcp4017-502", MCP4018_502 }, + { "mcp4017-103", MCP4018_103 }, + { "mcp4017-503", MCP4018_503 }, + { "mcp4017-104", MCP4018_104 }, + { "mcp4018-502", MCP4018_502 }, + { "mcp4018-103", MCP4018_103 }, + { "mcp4018-503", MCP4018_503 }, + { "mcp4018-104", MCP4018_104 }, + { "mcp4019-502", MCP4018_502 }, + { "mcp4019-103", MCP4018_103 }, + { "mcp4019-503", MCP4018_503 }, + { "mcp4019-104", MCP4018_104 }, + {} +}; +MODULE_DEVICE_TABLE(i2c, mcp4018_id); + +static struct i2c_driver mcp4018_driver = { + .driver = { + .name = "mcp4018", + .of_match_table = of_match_ptr(mcp4018_of_match), + }, + .probe = mcp4018_probe, + .id_table = mcp4018_id, +}; + +module_i2c_driver(mcp4018_driver); + +MODULE_AUTHOR("Peter Rosin "); +MODULE_DESCRIPTION("MCP4018 digital potentiometer"); +MODULE_LICENSE("GPL"); From d6570e198062c47cbe02bc2321c0514ffc57bc2f Mon Sep 17 00:00:00 2001 From: Tom Lebreux Date: Thu, 8 Mar 2018 18:19:04 -0500 Subject: [PATCH 43/47] staging:iio:ad7152: Align arguments to match open parenthesis This patch fixes checkpatch.pl CHECK for alignment. Signed-off-by: Tom Lebreux Signed-off-by: Jonathan Cameron --- drivers/staging/iio/cdc/ad7152.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/staging/iio/cdc/ad7152.c b/drivers/staging/iio/cdc/ad7152.c index 19dc896603a1..25f51db05d2d 100644 --- a/drivers/staging/iio/cdc/ad7152.c +++ b/drivers/staging/iio/cdc/ad7152.c @@ -426,8 +426,8 @@ out: } static int ad7152_write_raw_get_fmt(struct iio_dev *indio_dev, - struct iio_chan_spec const *chan, - long mask) + struct iio_chan_spec const *chan, + long mask) { switch (mask) { case IIO_CHAN_INFO_SCALE: @@ -493,7 +493,7 @@ static const struct iio_chan_spec ad7152_channels[] = { */ static int ad7152_probe(struct i2c_client *client, - const struct i2c_device_id *id) + const struct i2c_device_id *id) { int ret = 0; struct ad7152_chip_info *chip; From 6e2e828de05acbe2f4e070b3d51129fb1220b17d Mon Sep 17 00:00:00 2001 From: Tom Lebreux Date: Thu, 8 Mar 2018 18:56:07 -0500 Subject: [PATCH 44/47] staging:iio:ad7150: Align arguments to match open parenthesis This fixes the following checkpatch.pl CHECK: Alignment should match open parenthesis Signed-off-by: Tom Lebreux Signed-off-by: Jonathan Cameron --- drivers/staging/iio/cdc/ad7150.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/staging/iio/cdc/ad7150.c b/drivers/staging/iio/cdc/ad7150.c index 2fe916c48848..d16084d7068c 100644 --- a/drivers/staging/iio/cdc/ad7150.c +++ b/drivers/staging/iio/cdc/ad7150.c @@ -124,8 +124,9 @@ static int ad7150_read_raw(struct iio_dev *indio_dev, } static int ad7150_read_event_config(struct iio_dev *indio_dev, - const struct iio_chan_spec *chan, enum iio_event_type type, - enum iio_event_direction dir) + const struct iio_chan_spec *chan, + enum iio_event_type type, + enum iio_event_direction dir) { int ret; u8 threshtype; From 23c537ae0e2f109165ef231edc25155a64427cc1 Mon Sep 17 00:00:00 2001 From: Rodrigo Siqueira Date: Fri, 9 Mar 2018 20:45:50 -0300 Subject: [PATCH 45/47] staging:iio:ad2s1210: Remove end of line with '[' This patch fixes the checkpatch.pl check: iio/resolver/ad2s1210.c:202: CHECK: Lines should not end with a '[' Signed-off-by: Rodrigo Siqueira Signed-off-by: Jonathan Cameron --- drivers/staging/iio/resolver/ad2s1210.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/staging/iio/resolver/ad2s1210.c b/drivers/staging/iio/resolver/ad2s1210.c index f8baab061eba..0cdcd71e285b 100644 --- a/drivers/staging/iio/resolver/ad2s1210.c +++ b/drivers/staging/iio/resolver/ad2s1210.c @@ -165,9 +165,10 @@ int ad2s1210_update_frequency_control_word(struct ad2s1210_state *st) static unsigned char ad2s1210_read_resolution_pin(struct ad2s1210_state *st) { - return ad2s1210_resolution_value[ - (gpio_get_value(st->pdata->res[0]) << 1) | - gpio_get_value(st->pdata->res[1])]; + int resolution = (gpio_get_value(st->pdata->res[0]) << 1) | + gpio_get_value(st->pdata->res[1]); + + return ad2s1210_resolution_value[resolution]; } static const int ad2s1210_res_pins[4][2] = { From a8cf0d829af69e64aa1cbf9bc8816389c5cce5e9 Mon Sep 17 00:00:00 2001 From: Rodrigo Siqueira Date: Fri, 9 Mar 2018 20:46:05 -0300 Subject: [PATCH 46/47] staging:iio:ad2s1210: Remove unused #define directive This patch removes some #define directives not used in the code. Signed-off-by: Rodrigo Siqueira Signed-off-by: Jonathan Cameron --- drivers/staging/iio/resolver/ad2s1210.c | 10 ---------- 1 file changed, 10 deletions(-) diff --git a/drivers/staging/iio/resolver/ad2s1210.c b/drivers/staging/iio/resolver/ad2s1210.c index 0cdcd71e285b..79cb56670fc2 100644 --- a/drivers/staging/iio/resolver/ad2s1210.c +++ b/drivers/staging/iio/resolver/ad2s1210.c @@ -35,8 +35,6 @@ #define AD2S1210_SET_RES1 0x02 #define AD2S1210_SET_RES0 0x01 -#define AD2S1210_SET_ENRESOLUTION (AD2S1210_SET_ENRES1 | \ - AD2S1210_SET_ENRES0) #define AD2S1210_SET_RESOLUTION (AD2S1210_SET_RES1 | AD2S1210_SET_RES0) #define AD2S1210_REG_POSITION 0x80 @@ -53,10 +51,6 @@ #define AD2S1210_REG_SOFT_RESET 0xF0 #define AD2S1210_REG_FAULT 0xFF -/* pin SAMPLE, A0, A1, RES0, RES1, is controlled by driver */ -#define AD2S1210_SAA 3 -#define AD2S1210_PN (AD2S1210_SAA + AD2S1210_RES) - #define AD2S1210_MIN_CLKIN 6144000 #define AD2S1210_MAX_CLKIN 10240000 #define AD2S1210_MIN_EXCIT 2000 @@ -64,10 +58,6 @@ #define AD2S1210_MIN_FCW 0x4 #define AD2S1210_MAX_FCW 0x50 -/* default input clock on serial interface */ -#define AD2S1210_DEF_CLKIN 8192000 -/* clock period in nano second */ -#define AD2S1210_DEF_TCK (1000000000 / AD2S1210_DEF_CLKIN) #define AD2S1210_DEF_EXCIT 10000 enum ad2s1210_mode { From 9aa5134ac486b48c4c8ac14571e6034131f040f8 Mon Sep 17 00:00:00 2001 From: Rodrigo Siqueira Date: Fri, 9 Mar 2018 20:46:25 -0300 Subject: [PATCH 47/47] staging:iio:ad2s1210: Remove old_data from ad2s1210_state The variable old_data is a bool type, which only receives the value 'true' in the function ad2s1210_config_write and ad2s1210_config_read. There is no other use for this variable. This patch removes old_data from the ad2s1210_state and from all the function that use it. Signed-off-by: Rodrigo Siqueira Signed-off-by: Jonathan Cameron --- drivers/staging/iio/resolver/ad2s1210.c | 3 --- 1 file changed, 3 deletions(-) diff --git a/drivers/staging/iio/resolver/ad2s1210.c b/drivers/staging/iio/resolver/ad2s1210.c index 79cb56670fc2..ac13b99bd9cb 100644 --- a/drivers/staging/iio/resolver/ad2s1210.c +++ b/drivers/staging/iio/resolver/ad2s1210.c @@ -76,7 +76,6 @@ struct ad2s1210_state { unsigned int fclkin; unsigned int fexcit; bool hysteresis; - bool old_data; u8 resolution; enum ad2s1210_mode mode; u8 rx[2] ____cacheline_aligned; @@ -107,7 +106,6 @@ static int ad2s1210_config_write(struct ad2s1210_state *st, u8 data) ret = spi_write(st->sdev, st->tx, 1); if (ret < 0) return ret; - st->old_data = true; return 0; } @@ -129,7 +127,6 @@ static int ad2s1210_config_read(struct ad2s1210_state *st, ret = spi_sync_transfer(st->sdev, &xfer, 1); if (ret < 0) return ret; - st->old_data = true; return st->rx[1]; }