From 1afacfb0dfe9af88d8e831cfcfb8bda663cfc9b5 Mon Sep 17 00:00:00 2001 From: Alexandru Ardelean Date: Tue, 2 Oct 2018 14:57:57 +0300 Subject: staging: iio: ad5933: rename ext_clk_Hz -> ext_clk_hz The checkpatch script doesn't like camel-case names. Renamed the variable. Signed-off-by: Alexandru Ardelean Signed-off-by: Jonathan Cameron --- drivers/staging/iio/impedance-analyzer/ad5933.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'drivers/staging/iio') diff --git a/drivers/staging/iio/impedance-analyzer/ad5933.c b/drivers/staging/iio/impedance-analyzer/ad5933.c index a2370dd1e1a8..8a920f675b83 100644 --- a/drivers/staging/iio/impedance-analyzer/ad5933.c +++ b/drivers/staging/iio/impedance-analyzer/ad5933.c @@ -84,13 +84,13 @@ /** * struct ad5933_platform_data - platform specific data - * @ext_clk_Hz: the external clock frequency in Hz, if not set + * @ext_clk_hz: the external clock frequency in Hz, if not set * the driver uses the internal clock (16.776 MHz) * @vref_mv: the external reference voltage in millivolt */ struct ad5933_platform_data { - unsigned long ext_clk_Hz; + unsigned long ext_clk_hz; unsigned short vref_mv; }; @@ -726,8 +726,8 @@ static int ad5933_probe(struct i2c_client *client, else st->vref_mv = pdata->vref_mv; - if (pdata->ext_clk_Hz) { - st->mclk_hz = pdata->ext_clk_Hz; + if (pdata->ext_clk_hz) { + st->mclk_hz = pdata->ext_clk_hz; st->ctrl_lb = AD5933_CTRL_EXT_SYSCLK; } else { st->mclk_hz = AD5933_INT_OSC_FREQ_Hz; -- cgit v1.2.3 From 4bb199e51ddc45eeb823e2c7ae670de06912fa9c Mon Sep 17 00:00:00 2001 From: Slawomir Stepien Date: Fri, 5 Oct 2018 10:04:44 +0200 Subject: staging: iio: cdc: ad7150: use value copy to shorten the line length By using the copy of channel attribute, we can now make the lines short enough to eliminate the checkpatch.pl problem: CHECK: Alignment should match open parenthesis Signed-off-by: Slawomir Stepien Signed-off-by: Jonathan Cameron --- drivers/staging/iio/cdc/ad7150.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'drivers/staging/iio') diff --git a/drivers/staging/iio/cdc/ad7150.c b/drivers/staging/iio/cdc/ad7150.c index d16084d7068c..e2c70063fa0f 100644 --- a/drivers/staging/iio/cdc/ad7150.c +++ b/drivers/staging/iio/cdc/ad7150.c @@ -102,18 +102,19 @@ static int ad7150_read_raw(struct iio_dev *indio_dev, { int ret; struct ad7150_chip_info *chip = iio_priv(indio_dev); + int channel = chan->channel; switch (mask) { case IIO_CHAN_INFO_RAW: ret = i2c_smbus_read_word_data(chip->client, - ad7150_addresses[chan->channel][0]); + ad7150_addresses[channel][0]); if (ret < 0) return ret; *val = swab16(ret); return IIO_VAL_INT; case IIO_CHAN_INFO_AVERAGE_RAW: ret = i2c_smbus_read_word_data(chip->client, - ad7150_addresses[chan->channel][1]); + ad7150_addresses[channel][1]); if (ret < 0) return ret; *val = swab16(ret); -- cgit v1.2.3 From 2e00b533527cf4f53a8909b950d2a583c967cd65 Mon Sep 17 00:00:00 2001 From: Slawomir Stepien Date: Fri, 5 Oct 2018 10:05:15 +0200 Subject: staging: iio: cdc: ad7150: fix misaligned lines These lines were misaligned, but the checkpatch.pl didn't indicate them as such. Signed-off-by: Slawomir Stepien Signed-off-by: Jonathan Cameron --- drivers/staging/iio/cdc/ad7150.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'drivers/staging/iio') diff --git a/drivers/staging/iio/cdc/ad7150.c b/drivers/staging/iio/cdc/ad7150.c index e2c70063fa0f..24f74ce60f80 100644 --- a/drivers/staging/iio/cdc/ad7150.c +++ b/drivers/staging/iio/cdc/ad7150.c @@ -183,8 +183,8 @@ static int ad7150_write_event_params(struct iio_dev *indio_dev, case IIO_EV_TYPE_THRESH: value = chip->threshold[rising][chan]; return i2c_smbus_write_word_data(chip->client, - ad7150_addresses[chan][3], - swab16(value)); + ad7150_addresses[chan][3], + swab16(value)); case IIO_EV_TYPE_MAG_ADAPTIVE: sens = chip->mag_sensitivity[rising][chan]; timeout = chip->mag_timeout[rising][chan]; -- cgit v1.2.3 From 5c93f3ce98b6e5ceda6b2e9c80b071e556fac6f4 Mon Sep 17 00:00:00 2001 From: Matheus Tavares Date: Mon, 8 Oct 2018 00:29:38 -0300 Subject: staging: iio: ad2s1210: fix 'assignment operator' style checks This patch fixes all "Assignment operator '=' should be on the previous line" checks found in ad2s1210.c with checkpatch.pl. Signed-off-by: Matheus Tavares Signed-off-by: Jonathan Cameron --- drivers/staging/iio/resolver/ad2s1210.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) (limited to 'drivers/staging/iio') diff --git a/drivers/staging/iio/resolver/ad2s1210.c b/drivers/staging/iio/resolver/ad2s1210.c index ac13b99bd9cb..d4b1c2c010f2 100644 --- a/drivers/staging/iio/resolver/ad2s1210.c +++ b/drivers/staging/iio/resolver/ad2s1210.c @@ -301,8 +301,8 @@ static ssize_t ad2s1210_store_control(struct device *dev, "ad2s1210: write control register fail\n"); goto error_ret; } - st->resolution - = ad2s1210_resolution_value[data & AD2S1210_SET_RESOLUTION]; + st->resolution = + ad2s1210_resolution_value[data & AD2S1210_SET_RESOLUTION]; if (st->pdata->gpioin) { data = ad2s1210_read_resolution_pin(st); if (data != st->resolution) @@ -363,8 +363,8 @@ static ssize_t ad2s1210_store_resolution(struct device *dev, dev_err(dev, "ad2s1210: setting resolution fail\n"); goto error_ret; } - st->resolution - = ad2s1210_resolution_value[data & AD2S1210_SET_RESOLUTION]; + st->resolution = + ad2s1210_resolution_value[data & AD2S1210_SET_RESOLUTION]; if (st->pdata->gpioin) { data = ad2s1210_read_resolution_pin(st); if (data != st->resolution) -- cgit v1.2.3 From a476e20c30e8e1922c9573fe6862c5551e910ee1 Mon Sep 17 00:00:00 2001 From: Renato Lui Geh Date: Mon, 8 Oct 2018 19:12:05 -0300 Subject: staging: iio: adt7316: fix parenthesis alignment This patch fixes most "Alignment should match open parenthesis" check warnings found by checkpatch.pl in the addac/adt7316 driver. Signed-off-by: Renato Lui Geh Signed-off-by: Jonathan Cameron --- drivers/staging/iio/addac/adt7316.c | 462 ++++++++++++++++++------------------ drivers/staging/iio/addac/adt7316.h | 2 +- 2 files changed, 233 insertions(+), 231 deletions(-) (limited to 'drivers/staging/iio') diff --git a/drivers/staging/iio/addac/adt7316.c b/drivers/staging/iio/addac/adt7316.c index 3f22d1088713..2f8a122f475d 100644 --- a/drivers/staging/iio/addac/adt7316.c +++ b/drivers/staging/iio/addac/adt7316.c @@ -217,8 +217,8 @@ struct adt7316_limit_regs { }; static ssize_t adt7316_show_enabled(struct device *dev, - struct device_attribute *attr, - char *buf) + struct device_attribute *attr, + char *buf) { struct iio_dev *dev_info = dev_to_iio_dev(dev); struct adt7316_chip_info *chip = iio_priv(dev_info); @@ -227,7 +227,7 @@ static ssize_t adt7316_show_enabled(struct device *dev, } static ssize_t _adt7316_store_enabled(struct adt7316_chip_info *chip, - int enable) + int enable) { u8 config1; int ret; @@ -247,9 +247,9 @@ static ssize_t _adt7316_store_enabled(struct adt7316_chip_info *chip, } static ssize_t adt7316_store_enabled(struct device *dev, - struct device_attribute *attr, - const char *buf, - size_t len) + struct device_attribute *attr, + const char *buf, + size_t len) { struct iio_dev *dev_info = dev_to_iio_dev(dev); struct adt7316_chip_info *chip = iio_priv(dev_info); @@ -272,8 +272,8 @@ static IIO_DEVICE_ATTR(enabled, 0644, 0); static ssize_t adt7316_show_select_ex_temp(struct device *dev, - struct device_attribute *attr, - char *buf) + struct device_attribute *attr, + char *buf) { struct iio_dev *dev_info = dev_to_iio_dev(dev); struct adt7316_chip_info *chip = iio_priv(dev_info); @@ -285,9 +285,9 @@ static ssize_t adt7316_show_select_ex_temp(struct device *dev, } static ssize_t adt7316_store_select_ex_temp(struct device *dev, - struct device_attribute *attr, - const char *buf, - size_t len) + struct device_attribute *attr, + const char *buf, + size_t len) { struct iio_dev *dev_info = dev_to_iio_dev(dev); struct adt7316_chip_info *chip = iio_priv(dev_info); @@ -316,8 +316,8 @@ static IIO_DEVICE_ATTR(select_ex_temp, 0644, 0); static ssize_t adt7316_show_mode(struct device *dev, - struct device_attribute *attr, - char *buf) + struct device_attribute *attr, + char *buf) { struct iio_dev *dev_info = dev_to_iio_dev(dev); struct adt7316_chip_info *chip = iio_priv(dev_info); @@ -329,9 +329,9 @@ static ssize_t adt7316_show_mode(struct device *dev, } static ssize_t adt7316_store_mode(struct device *dev, - struct device_attribute *attr, - const char *buf, - size_t len) + struct device_attribute *attr, + const char *buf, + size_t len) { struct iio_dev *dev_info = dev_to_iio_dev(dev); struct adt7316_chip_info *chip = iio_priv(dev_info); @@ -357,8 +357,8 @@ static IIO_DEVICE_ATTR(mode, 0644, 0); static ssize_t adt7316_show_all_modes(struct device *dev, - struct device_attribute *attr, - char *buf) + struct device_attribute *attr, + char *buf) { return sprintf(buf, "single_channel\nround_robin\n"); } @@ -366,8 +366,8 @@ static ssize_t adt7316_show_all_modes(struct device *dev, static IIO_DEVICE_ATTR(all_modes, 0444, adt7316_show_all_modes, NULL, 0); static ssize_t adt7316_show_ad_channel(struct device *dev, - struct device_attribute *attr, - char *buf) + struct device_attribute *attr, + char *buf) { struct iio_dev *dev_info = dev_to_iio_dev(dev); struct adt7316_chip_info *chip = iio_priv(dev_info); @@ -382,7 +382,7 @@ static ssize_t adt7316_show_ad_channel(struct device *dev, return sprintf(buf, "1 - Internal Temperature\n"); case ADT7316_AD_SINGLE_CH_EX: if (((chip->id & ID_FAMILY_MASK) == ID_ADT75XX) && - (chip->config1 & ADT7516_SEL_AIN1_2_EX_TEMP_MASK) == 0) + (chip->config1 & ADT7516_SEL_AIN1_2_EX_TEMP_MASK) == 0) return sprintf(buf, "2 - AIN1\n"); return sprintf(buf, "2 - External Temperature\n"); @@ -404,9 +404,9 @@ static ssize_t adt7316_show_ad_channel(struct device *dev, } static ssize_t adt7316_store_ad_channel(struct device *dev, - struct device_attribute *attr, - const char *buf, - size_t len) + struct device_attribute *attr, + const char *buf, + size_t len) { struct iio_dev *dev_info = dev_to_iio_dev(dev); struct adt7316_chip_info *chip = iio_priv(dev_info); @@ -450,8 +450,8 @@ static IIO_DEVICE_ATTR(ad_channel, 0644, 0); static ssize_t adt7316_show_all_ad_channels(struct device *dev, - struct device_attribute *attr, - char *buf) + struct device_attribute *attr, + char *buf) { struct iio_dev *dev_info = dev_to_iio_dev(dev); struct adt7316_chip_info *chip = iio_priv(dev_info); @@ -471,8 +471,8 @@ static IIO_DEVICE_ATTR(all_ad_channels, 0444, adt7316_show_all_ad_channels, NULL, 0); static ssize_t adt7316_show_disable_averaging(struct device *dev, - struct device_attribute *attr, - char *buf) + struct device_attribute *attr, + char *buf) { struct iio_dev *dev_info = dev_to_iio_dev(dev); struct adt7316_chip_info *chip = iio_priv(dev_info); @@ -482,9 +482,9 @@ static ssize_t adt7316_show_disable_averaging(struct device *dev, } static ssize_t adt7316_store_disable_averaging(struct device *dev, - struct device_attribute *attr, - const char *buf, - size_t len) + struct device_attribute *attr, + const char *buf, + size_t len) { struct iio_dev *dev_info = dev_to_iio_dev(dev); struct adt7316_chip_info *chip = iio_priv(dev_info); @@ -510,8 +510,8 @@ static IIO_DEVICE_ATTR(disable_averaging, 0644, 0); static ssize_t adt7316_show_enable_smbus_timeout(struct device *dev, - struct device_attribute *attr, - char *buf) + struct device_attribute *attr, + char *buf) { struct iio_dev *dev_info = dev_to_iio_dev(dev); struct adt7316_chip_info *chip = iio_priv(dev_info); @@ -521,9 +521,9 @@ static ssize_t adt7316_show_enable_smbus_timeout(struct device *dev, } static ssize_t adt7316_store_enable_smbus_timeout(struct device *dev, - struct device_attribute *attr, - const char *buf, - size_t len) + struct device_attribute *attr, + const char *buf, + size_t len) { struct iio_dev *dev_info = dev_to_iio_dev(dev); struct adt7316_chip_info *chip = iio_priv(dev_info); @@ -549,8 +549,8 @@ static IIO_DEVICE_ATTR(enable_smbus_timeout, 0644, 0); static ssize_t adt7316_show_powerdown(struct device *dev, - struct device_attribute *attr, - char *buf) + struct device_attribute *attr, + char *buf) { struct iio_dev *dev_info = dev_to_iio_dev(dev); struct adt7316_chip_info *chip = iio_priv(dev_info); @@ -559,9 +559,9 @@ static ssize_t adt7316_show_powerdown(struct device *dev, } static ssize_t adt7316_store_powerdown(struct device *dev, - struct device_attribute *attr, - const char *buf, - size_t len) + struct device_attribute *attr, + const char *buf, + size_t len) { struct iio_dev *dev_info = dev_to_iio_dev(dev); struct adt7316_chip_info *chip = iio_priv(dev_info); @@ -587,8 +587,8 @@ static IIO_DEVICE_ATTR(powerdown, 0644, 0); static ssize_t adt7316_show_fast_ad_clock(struct device *dev, - struct device_attribute *attr, - char *buf) + struct device_attribute *attr, + char *buf) { struct iio_dev *dev_info = dev_to_iio_dev(dev); struct adt7316_chip_info *chip = iio_priv(dev_info); @@ -597,9 +597,9 @@ static ssize_t adt7316_show_fast_ad_clock(struct device *dev, } static ssize_t adt7316_store_fast_ad_clock(struct device *dev, - struct device_attribute *attr, - const char *buf, - size_t len) + struct device_attribute *attr, + const char *buf, + size_t len) { struct iio_dev *dev_info = dev_to_iio_dev(dev); struct adt7316_chip_info *chip = iio_priv(dev_info); @@ -625,8 +625,8 @@ static IIO_DEVICE_ATTR(fast_ad_clock, 0644, 0); static ssize_t adt7316_show_da_high_resolution(struct device *dev, - struct device_attribute *attr, - char *buf) + struct device_attribute *attr, + char *buf) { struct iio_dev *dev_info = dev_to_iio_dev(dev); struct adt7316_chip_info *chip = iio_priv(dev_info); @@ -642,9 +642,9 @@ static ssize_t adt7316_show_da_high_resolution(struct device *dev, } static ssize_t adt7316_store_da_high_resolution(struct device *dev, - struct device_attribute *attr, - const char *buf, - size_t len) + struct device_attribute *attr, + const char *buf, + size_t len) { struct iio_dev *dev_info = dev_to_iio_dev(dev); struct adt7316_chip_info *chip = iio_priv(dev_info); @@ -678,8 +678,8 @@ static IIO_DEVICE_ATTR(da_high_resolution, 0644, 0); static ssize_t adt7316_show_AIN_internal_Vref(struct device *dev, - struct device_attribute *attr, - char *buf) + struct device_attribute *attr, + char *buf) { struct iio_dev *dev_info = dev_to_iio_dev(dev); struct adt7316_chip_info *chip = iio_priv(dev_info); @@ -692,9 +692,9 @@ static ssize_t adt7316_show_AIN_internal_Vref(struct device *dev, } static ssize_t adt7316_store_AIN_internal_Vref(struct device *dev, - struct device_attribute *attr, - const char *buf, - size_t len) + struct device_attribute *attr, + const char *buf, + size_t len) { struct iio_dev *dev_info = dev_to_iio_dev(dev); struct adt7316_chip_info *chip = iio_priv(dev_info); @@ -724,8 +724,8 @@ static IIO_DEVICE_ATTR(AIN_internal_Vref, 0644, 0); static ssize_t adt7316_show_enable_prop_DACA(struct device *dev, - struct device_attribute *attr, - char *buf) + struct device_attribute *attr, + char *buf) { struct iio_dev *dev_info = dev_to_iio_dev(dev); struct adt7316_chip_info *chip = iio_priv(dev_info); @@ -735,9 +735,9 @@ static ssize_t adt7316_show_enable_prop_DACA(struct device *dev, } static ssize_t adt7316_store_enable_prop_DACA(struct device *dev, - struct device_attribute *attr, - const char *buf, - size_t len) + struct device_attribute *attr, + const char *buf, + size_t len) { struct iio_dev *dev_info = dev_to_iio_dev(dev); struct adt7316_chip_info *chip = iio_priv(dev_info); @@ -758,13 +758,13 @@ static ssize_t adt7316_store_enable_prop_DACA(struct device *dev, } static IIO_DEVICE_ATTR(enable_proportion_DACA, 0644, - adt7316_show_enable_prop_DACA, - adt7316_store_enable_prop_DACA, - 0); + adt7316_show_enable_prop_DACA, + adt7316_store_enable_prop_DACA, + 0); static ssize_t adt7316_show_enable_prop_DACB(struct device *dev, - struct device_attribute *attr, - char *buf) + struct device_attribute *attr, + char *buf) { struct iio_dev *dev_info = dev_to_iio_dev(dev); struct adt7316_chip_info *chip = iio_priv(dev_info); @@ -774,9 +774,9 @@ static ssize_t adt7316_show_enable_prop_DACB(struct device *dev, } static ssize_t adt7316_store_enable_prop_DACB(struct device *dev, - struct device_attribute *attr, - const char *buf, - size_t len) + struct device_attribute *attr, + const char *buf, + size_t len) { struct iio_dev *dev_info = dev_to_iio_dev(dev); struct adt7316_chip_info *chip = iio_priv(dev_info); @@ -797,13 +797,13 @@ static ssize_t adt7316_store_enable_prop_DACB(struct device *dev, } static IIO_DEVICE_ATTR(enable_proportion_DACB, 0644, - adt7316_show_enable_prop_DACB, - adt7316_store_enable_prop_DACB, - 0); + adt7316_show_enable_prop_DACB, + adt7316_store_enable_prop_DACB, + 0); static ssize_t adt7316_show_DAC_2Vref_ch_mask(struct device *dev, - struct device_attribute *attr, - char *buf) + struct device_attribute *attr, + char *buf) { struct iio_dev *dev_info = dev_to_iio_dev(dev); struct adt7316_chip_info *chip = iio_priv(dev_info); @@ -813,9 +813,9 @@ static ssize_t adt7316_show_DAC_2Vref_ch_mask(struct device *dev, } static ssize_t adt7316_store_DAC_2Vref_ch_mask(struct device *dev, - struct device_attribute *attr, - const char *buf, - size_t len) + struct device_attribute *attr, + const char *buf, + size_t len) { struct iio_dev *dev_info = dev_to_iio_dev(dev); struct adt7316_chip_info *chip = iio_priv(dev_info); @@ -840,13 +840,13 @@ static ssize_t adt7316_store_DAC_2Vref_ch_mask(struct device *dev, } static IIO_DEVICE_ATTR(DAC_2Vref_channels_mask, 0644, - adt7316_show_DAC_2Vref_ch_mask, - adt7316_store_DAC_2Vref_ch_mask, - 0); + adt7316_show_DAC_2Vref_ch_mask, + adt7316_store_DAC_2Vref_ch_mask, + 0); static ssize_t adt7316_show_DAC_update_mode(struct device *dev, - struct device_attribute *attr, - char *buf) + struct device_attribute *attr, + char *buf) { struct iio_dev *dev_info = dev_to_iio_dev(dev); struct adt7316_chip_info *chip = iio_priv(dev_info); @@ -870,9 +870,9 @@ static ssize_t adt7316_show_DAC_update_mode(struct device *dev, } static ssize_t adt7316_store_DAC_update_mode(struct device *dev, - struct device_attribute *attr, - const char *buf, - size_t len) + struct device_attribute *attr, + const char *buf, + size_t len) { struct iio_dev *dev_info = dev_to_iio_dev(dev); struct adt7316_chip_info *chip = iio_priv(dev_info); @@ -900,13 +900,13 @@ static ssize_t adt7316_store_DAC_update_mode(struct device *dev, } static IIO_DEVICE_ATTR(DAC_update_mode, 0644, - adt7316_show_DAC_update_mode, - adt7316_store_DAC_update_mode, - 0); + adt7316_show_DAC_update_mode, + adt7316_store_DAC_update_mode, + 0); static ssize_t adt7316_show_all_DAC_update_modes(struct device *dev, - struct device_attribute *attr, - char *buf) + struct device_attribute *attr, + char *buf) { struct iio_dev *dev_info = dev_to_iio_dev(dev); struct adt7316_chip_info *chip = iio_priv(dev_info); @@ -920,12 +920,12 @@ static ssize_t adt7316_show_all_DAC_update_modes(struct device *dev, } static IIO_DEVICE_ATTR(all_DAC_update_modes, 0444, - adt7316_show_all_DAC_update_modes, NULL, 0); + adt7316_show_all_DAC_update_modes, NULL, 0); static ssize_t adt7316_store_update_DAC(struct device *dev, - struct device_attribute *attr, - const char *buf, - size_t len) + struct device_attribute *attr, + const char *buf, + size_t len) { struct iio_dev *dev_info = dev_to_iio_dev(dev); struct adt7316_chip_info *chip = iio_priv(dev_info); @@ -958,13 +958,13 @@ static ssize_t adt7316_store_update_DAC(struct device *dev, } static IIO_DEVICE_ATTR(update_DAC, 0644, - NULL, - adt7316_store_update_DAC, - 0); + NULL, + adt7316_store_update_DAC, + 0); static ssize_t adt7316_show_DA_AB_Vref_bypass(struct device *dev, - struct device_attribute *attr, - char *buf) + struct device_attribute *attr, + char *buf) { struct iio_dev *dev_info = dev_to_iio_dev(dev); struct adt7316_chip_info *chip = iio_priv(dev_info); @@ -977,9 +977,9 @@ static ssize_t adt7316_show_DA_AB_Vref_bypass(struct device *dev, } static ssize_t adt7316_store_DA_AB_Vref_bypass(struct device *dev, - struct device_attribute *attr, - const char *buf, - size_t len) + struct device_attribute *attr, + const char *buf, + size_t len) { struct iio_dev *dev_info = dev_to_iio_dev(dev); struct adt7316_chip_info *chip = iio_priv(dev_info); @@ -1003,13 +1003,13 @@ static ssize_t adt7316_store_DA_AB_Vref_bypass(struct device *dev, } static IIO_DEVICE_ATTR(DA_AB_Vref_bypass, 0644, - adt7316_show_DA_AB_Vref_bypass, - adt7316_store_DA_AB_Vref_bypass, - 0); + adt7316_show_DA_AB_Vref_bypass, + adt7316_store_DA_AB_Vref_bypass, + 0); static ssize_t adt7316_show_DA_CD_Vref_bypass(struct device *dev, - struct device_attribute *attr, - char *buf) + struct device_attribute *attr, + char *buf) { struct iio_dev *dev_info = dev_to_iio_dev(dev); struct adt7316_chip_info *chip = iio_priv(dev_info); @@ -1022,9 +1022,9 @@ static ssize_t adt7316_show_DA_CD_Vref_bypass(struct device *dev, } static ssize_t adt7316_store_DA_CD_Vref_bypass(struct device *dev, - struct device_attribute *attr, - const char *buf, - size_t len) + struct device_attribute *attr, + const char *buf, + size_t len) { struct iio_dev *dev_info = dev_to_iio_dev(dev); struct adt7316_chip_info *chip = iio_priv(dev_info); @@ -1048,13 +1048,13 @@ static ssize_t adt7316_store_DA_CD_Vref_bypass(struct device *dev, } static IIO_DEVICE_ATTR(DA_CD_Vref_bypass, 0644, - adt7316_show_DA_CD_Vref_bypass, - adt7316_store_DA_CD_Vref_bypass, - 0); + adt7316_show_DA_CD_Vref_bypass, + adt7316_store_DA_CD_Vref_bypass, + 0); static ssize_t adt7316_show_DAC_internal_Vref(struct device *dev, - struct device_attribute *attr, - char *buf) + struct device_attribute *attr, + char *buf) { struct iio_dev *dev_info = dev_to_iio_dev(dev); struct adt7316_chip_info *chip = iio_priv(dev_info); @@ -1068,9 +1068,9 @@ static ssize_t adt7316_show_DAC_internal_Vref(struct device *dev, } static ssize_t adt7316_store_DAC_internal_Vref(struct device *dev, - struct device_attribute *attr, - const char *buf, - size_t len) + struct device_attribute *attr, + const char *buf, + size_t len) { struct iio_dev *dev_info = dev_to_iio_dev(dev); struct adt7316_chip_info *chip = iio_priv(dev_info); @@ -1109,12 +1109,12 @@ static ssize_t adt7316_store_DAC_internal_Vref(struct device *dev, } static IIO_DEVICE_ATTR(DAC_internal_Vref, 0644, - adt7316_show_DAC_internal_Vref, - adt7316_store_DAC_internal_Vref, - 0); + adt7316_show_DAC_internal_Vref, + adt7316_store_DAC_internal_Vref, + 0); static ssize_t adt7316_show_ad(struct adt7316_chip_info *chip, - int channel, char *buf) + int channel, char *buf) { u16 data; u8 msb, lsb; @@ -1122,7 +1122,7 @@ static ssize_t adt7316_show_ad(struct adt7316_chip_info *chip, int ret; if ((chip->config2 & ADT7316_AD_SINGLE_CH_MODE) && - channel != (chip->config2 & ADT7516_AD_SINGLE_CH_MASK)) + channel != (chip->config2 & ADT7516_AD_SINGLE_CH_MASK)) return -EPERM; switch (channel) { @@ -1189,8 +1189,8 @@ static ssize_t adt7316_show_ad(struct adt7316_chip_info *chip, } static ssize_t adt7316_show_VDD(struct device *dev, - struct device_attribute *attr, - char *buf) + struct device_attribute *attr, + char *buf) { struct iio_dev *dev_info = dev_to_iio_dev(dev); struct adt7316_chip_info *chip = iio_priv(dev_info); @@ -1200,8 +1200,8 @@ static ssize_t adt7316_show_VDD(struct device *dev, static IIO_DEVICE_ATTR(VDD, 0444, adt7316_show_VDD, NULL, 0); static ssize_t adt7316_show_in_temp(struct device *dev, - struct device_attribute *attr, - char *buf) + struct device_attribute *attr, + char *buf) { struct iio_dev *dev_info = dev_to_iio_dev(dev); struct adt7316_chip_info *chip = iio_priv(dev_info); @@ -1212,8 +1212,8 @@ static ssize_t adt7316_show_in_temp(struct device *dev, static IIO_DEVICE_ATTR(in_temp, 0444, adt7316_show_in_temp, NULL, 0); static ssize_t adt7316_show_ex_temp_AIN1(struct device *dev, - struct device_attribute *attr, - char *buf) + struct device_attribute *attr, + char *buf) { struct iio_dev *dev_info = dev_to_iio_dev(dev); struct adt7316_chip_info *chip = iio_priv(dev_info); @@ -1222,12 +1222,12 @@ static ssize_t adt7316_show_ex_temp_AIN1(struct device *dev, } static IIO_DEVICE_ATTR(ex_temp_AIN1, 0444, adt7316_show_ex_temp_AIN1, - NULL, 0); + NULL, 0); static IIO_DEVICE_ATTR(ex_temp, 0444, adt7316_show_ex_temp_AIN1, NULL, 0); static ssize_t adt7316_show_AIN2(struct device *dev, - struct device_attribute *attr, - char *buf) + struct device_attribute *attr, + char *buf) { struct iio_dev *dev_info = dev_to_iio_dev(dev); struct adt7316_chip_info *chip = iio_priv(dev_info); @@ -1237,8 +1237,8 @@ static ssize_t adt7316_show_AIN2(struct device *dev, static IIO_DEVICE_ATTR(AIN2, 0444, adt7316_show_AIN2, NULL, 0); static ssize_t adt7316_show_AIN3(struct device *dev, - struct device_attribute *attr, - char *buf) + struct device_attribute *attr, + char *buf) { struct iio_dev *dev_info = dev_to_iio_dev(dev); struct adt7316_chip_info *chip = iio_priv(dev_info); @@ -1248,8 +1248,8 @@ static ssize_t adt7316_show_AIN3(struct device *dev, static IIO_DEVICE_ATTR(AIN3, 0444, adt7316_show_AIN3, NULL, 0); static ssize_t adt7316_show_AIN4(struct device *dev, - struct device_attribute *attr, - char *buf) + struct device_attribute *attr, + char *buf) { struct iio_dev *dev_info = dev_to_iio_dev(dev); struct adt7316_chip_info *chip = iio_priv(dev_info); @@ -1259,7 +1259,7 @@ static ssize_t adt7316_show_AIN4(struct device *dev, static IIO_DEVICE_ATTR(AIN4, 0444, adt7316_show_AIN4, NULL, 0); static ssize_t adt7316_show_temp_offset(struct adt7316_chip_info *chip, - int offset_addr, char *buf) + int offset_addr, char *buf) { int data; u8 val; @@ -1277,7 +1277,9 @@ static ssize_t adt7316_show_temp_offset(struct adt7316_chip_info *chip, } static ssize_t adt7316_store_temp_offset(struct adt7316_chip_info *chip, - int offset_addr, const char *buf, size_t len) + int offset_addr, + const char *buf, + size_t len) { int data; u8 val; @@ -1300,8 +1302,8 @@ static ssize_t adt7316_store_temp_offset(struct adt7316_chip_info *chip, } static ssize_t adt7316_show_in_temp_offset(struct device *dev, - struct device_attribute *attr, - char *buf) + struct device_attribute *attr, + char *buf) { struct iio_dev *dev_info = dev_to_iio_dev(dev); struct adt7316_chip_info *chip = iio_priv(dev_info); @@ -1310,9 +1312,9 @@ static ssize_t adt7316_show_in_temp_offset(struct device *dev, } static ssize_t adt7316_store_in_temp_offset(struct device *dev, - struct device_attribute *attr, - const char *buf, - size_t len) + struct device_attribute *attr, + const char *buf, + size_t len) { struct iio_dev *dev_info = dev_to_iio_dev(dev); struct adt7316_chip_info *chip = iio_priv(dev_info); @@ -1322,12 +1324,12 @@ static ssize_t adt7316_store_in_temp_offset(struct device *dev, } static IIO_DEVICE_ATTR(in_temp_offset, 0644, - adt7316_show_in_temp_offset, - adt7316_store_in_temp_offset, 0); + adt7316_show_in_temp_offset, + adt7316_store_in_temp_offset, 0); static ssize_t adt7316_show_ex_temp_offset(struct device *dev, - struct device_attribute *attr, - char *buf) + struct device_attribute *attr, + char *buf) { struct iio_dev *dev_info = dev_to_iio_dev(dev); struct adt7316_chip_info *chip = iio_priv(dev_info); @@ -1336,9 +1338,9 @@ static ssize_t adt7316_show_ex_temp_offset(struct device *dev, } static ssize_t adt7316_store_ex_temp_offset(struct device *dev, - struct device_attribute *attr, - const char *buf, - size_t len) + struct device_attribute *attr, + const char *buf, + size_t len) { struct iio_dev *dev_info = dev_to_iio_dev(dev); struct adt7316_chip_info *chip = iio_priv(dev_info); @@ -1348,12 +1350,12 @@ static ssize_t adt7316_store_ex_temp_offset(struct device *dev, } static IIO_DEVICE_ATTR(ex_temp_offset, 0644, - adt7316_show_ex_temp_offset, - adt7316_store_ex_temp_offset, 0); + adt7316_show_ex_temp_offset, + adt7316_store_ex_temp_offset, 0); static ssize_t adt7316_show_in_analog_temp_offset(struct device *dev, - struct device_attribute *attr, - char *buf) + struct device_attribute *attr, + char *buf) { struct iio_dev *dev_info = dev_to_iio_dev(dev); struct adt7316_chip_info *chip = iio_priv(dev_info); @@ -1363,9 +1365,9 @@ static ssize_t adt7316_show_in_analog_temp_offset(struct device *dev, } static ssize_t adt7316_store_in_analog_temp_offset(struct device *dev, - struct device_attribute *attr, - const char *buf, - size_t len) + struct device_attribute *attr, + const char *buf, + size_t len) { struct iio_dev *dev_info = dev_to_iio_dev(dev); struct adt7316_chip_info *chip = iio_priv(dev_info); @@ -1375,12 +1377,12 @@ static ssize_t adt7316_store_in_analog_temp_offset(struct device *dev, } static IIO_DEVICE_ATTR(in_analog_temp_offset, 0644, - adt7316_show_in_analog_temp_offset, - adt7316_store_in_analog_temp_offset, 0); + adt7316_show_in_analog_temp_offset, + adt7316_store_in_analog_temp_offset, 0); static ssize_t adt7316_show_ex_analog_temp_offset(struct device *dev, - struct device_attribute *attr, - char *buf) + struct device_attribute *attr, + char *buf) { struct iio_dev *dev_info = dev_to_iio_dev(dev); struct adt7316_chip_info *chip = iio_priv(dev_info); @@ -1390,9 +1392,9 @@ static ssize_t adt7316_show_ex_analog_temp_offset(struct device *dev, } static ssize_t adt7316_store_ex_analog_temp_offset(struct device *dev, - struct device_attribute *attr, - const char *buf, - size_t len) + struct device_attribute *attr, + const char *buf, + size_t len) { struct iio_dev *dev_info = dev_to_iio_dev(dev); struct adt7316_chip_info *chip = iio_priv(dev_info); @@ -1402,21 +1404,21 @@ static ssize_t adt7316_store_ex_analog_temp_offset(struct device *dev, } static IIO_DEVICE_ATTR(ex_analog_temp_offset, 0644, - adt7316_show_ex_analog_temp_offset, - adt7316_store_ex_analog_temp_offset, 0); + adt7316_show_ex_analog_temp_offset, + adt7316_store_ex_analog_temp_offset, 0); static ssize_t adt7316_show_DAC(struct adt7316_chip_info *chip, - int channel, char *buf) + int channel, char *buf) { u16 data; u8 msb, lsb, offset; int ret; if (channel >= ADT7316_DA_MSB_DATA_REGS || - (channel == 0 && - (chip->config3 & ADT7316_EN_IN_TEMP_PROP_DACA)) || - (channel == 1 && - (chip->config3 & ADT7316_EN_EX_TEMP_PROP_DACB))) + (channel == 0 && + (chip->config3 & ADT7316_EN_IN_TEMP_PROP_DACA)) || + (channel == 1 && + (chip->config3 & ADT7316_EN_EX_TEMP_PROP_DACB))) return -EPERM; offset = chip->dac_bits - 8; @@ -1439,17 +1441,17 @@ static ssize_t adt7316_show_DAC(struct adt7316_chip_info *chip, } static ssize_t adt7316_store_DAC(struct adt7316_chip_info *chip, - int channel, const char *buf, size_t len) + int channel, const char *buf, size_t len) { u8 msb, lsb, offset; u16 data; int ret; if (channel >= ADT7316_DA_MSB_DATA_REGS || - (channel == 0 && - (chip->config3 & ADT7316_EN_IN_TEMP_PROP_DACA)) || - (channel == 1 && - (chip->config3 & ADT7316_EN_EX_TEMP_PROP_DACB))) + (channel == 0 && + (chip->config3 & ADT7316_EN_IN_TEMP_PROP_DACA)) || + (channel == 1 && + (chip->config3 & ADT7316_EN_EX_TEMP_PROP_DACB))) return -EPERM; offset = chip->dac_bits - 8; @@ -1476,8 +1478,8 @@ static ssize_t adt7316_store_DAC(struct adt7316_chip_info *chip, } static ssize_t adt7316_show_DAC_A(struct device *dev, - struct device_attribute *attr, - char *buf) + struct device_attribute *attr, + char *buf) { struct iio_dev *dev_info = dev_to_iio_dev(dev); struct adt7316_chip_info *chip = iio_priv(dev_info); @@ -1486,9 +1488,9 @@ static ssize_t adt7316_show_DAC_A(struct device *dev, } static ssize_t adt7316_store_DAC_A(struct device *dev, - struct device_attribute *attr, - const char *buf, - size_t len) + struct device_attribute *attr, + const char *buf, + size_t len) { struct iio_dev *dev_info = dev_to_iio_dev(dev); struct adt7316_chip_info *chip = iio_priv(dev_info); @@ -1497,11 +1499,11 @@ static ssize_t adt7316_store_DAC_A(struct device *dev, } static IIO_DEVICE_ATTR(DAC_A, 0644, adt7316_show_DAC_A, - adt7316_store_DAC_A, 0); + adt7316_store_DAC_A, 0); static ssize_t adt7316_show_DAC_B(struct device *dev, - struct device_attribute *attr, - char *buf) + struct device_attribute *attr, + char *buf) { struct iio_dev *dev_info = dev_to_iio_dev(dev); struct adt7316_chip_info *chip = iio_priv(dev_info); @@ -1510,9 +1512,9 @@ static ssize_t adt7316_show_DAC_B(struct device *dev, } static ssize_t adt7316_store_DAC_B(struct device *dev, - struct device_attribute *attr, - const char *buf, - size_t len) + struct device_attribute *attr, + const char *buf, + size_t len) { struct iio_dev *dev_info = dev_to_iio_dev(dev); struct adt7316_chip_info *chip = iio_priv(dev_info); @@ -1521,11 +1523,11 @@ static ssize_t adt7316_store_DAC_B(struct device *dev, } static IIO_DEVICE_ATTR(DAC_B, 0644, adt7316_show_DAC_B, - adt7316_store_DAC_B, 0); + adt7316_store_DAC_B, 0); static ssize_t adt7316_show_DAC_C(struct device *dev, - struct device_attribute *attr, - char *buf) + struct device_attribute *attr, + char *buf) { struct iio_dev *dev_info = dev_to_iio_dev(dev); struct adt7316_chip_info *chip = iio_priv(dev_info); @@ -1534,9 +1536,9 @@ static ssize_t adt7316_show_DAC_C(struct device *dev, } static ssize_t adt7316_store_DAC_C(struct device *dev, - struct device_attribute *attr, - const char *buf, - size_t len) + struct device_attribute *attr, + const char *buf, + size_t len) { struct iio_dev *dev_info = dev_to_iio_dev(dev); struct adt7316_chip_info *chip = iio_priv(dev_info); @@ -1545,11 +1547,11 @@ static ssize_t adt7316_store_DAC_C(struct device *dev, } static IIO_DEVICE_ATTR(DAC_C, 0644, adt7316_show_DAC_C, - adt7316_store_DAC_C, 0); + adt7316_store_DAC_C, 0); static ssize_t adt7316_show_DAC_D(struct device *dev, - struct device_attribute *attr, - char *buf) + struct device_attribute *attr, + char *buf) { struct iio_dev *dev_info = dev_to_iio_dev(dev); struct adt7316_chip_info *chip = iio_priv(dev_info); @@ -1558,9 +1560,9 @@ static ssize_t adt7316_show_DAC_D(struct device *dev, } static ssize_t adt7316_store_DAC_D(struct device *dev, - struct device_attribute *attr, - const char *buf, - size_t len) + struct device_attribute *attr, + const char *buf, + size_t len) { struct iio_dev *dev_info = dev_to_iio_dev(dev); struct adt7316_chip_info *chip = iio_priv(dev_info); @@ -1569,11 +1571,11 @@ static ssize_t adt7316_store_DAC_D(struct device *dev, } static IIO_DEVICE_ATTR(DAC_D, 0644, adt7316_show_DAC_D, - adt7316_store_DAC_D, 0); + adt7316_store_DAC_D, 0); static ssize_t adt7316_show_device_id(struct device *dev, - struct device_attribute *attr, - char *buf) + struct device_attribute *attr, + char *buf) { struct iio_dev *dev_info = dev_to_iio_dev(dev); struct adt7316_chip_info *chip = iio_priv(dev_info); @@ -1590,8 +1592,8 @@ static ssize_t adt7316_show_device_id(struct device *dev, static IIO_DEVICE_ATTR(device_id, 0444, adt7316_show_device_id, NULL, 0); static ssize_t adt7316_show_manufactorer_id(struct device *dev, - struct device_attribute *attr, - char *buf) + struct device_attribute *attr, + char *buf) { struct iio_dev *dev_info = dev_to_iio_dev(dev); struct adt7316_chip_info *chip = iio_priv(dev_info); @@ -1606,11 +1608,11 @@ static ssize_t adt7316_show_manufactorer_id(struct device *dev, } static IIO_DEVICE_ATTR(manufactorer_id, 0444, - adt7316_show_manufactorer_id, NULL, 0); + adt7316_show_manufactorer_id, NULL, 0); static ssize_t adt7316_show_device_rev(struct device *dev, - struct device_attribute *attr, - char *buf) + struct device_attribute *attr, + char *buf) { struct iio_dev *dev_info = dev_to_iio_dev(dev); struct adt7316_chip_info *chip = iio_priv(dev_info); @@ -1627,8 +1629,8 @@ static ssize_t adt7316_show_device_rev(struct device *dev, static IIO_DEVICE_ATTR(device_rev, 0444, adt7316_show_device_rev, NULL, 0); static ssize_t adt7316_show_bus_type(struct device *dev, - struct device_attribute *attr, - char *buf) + struct device_attribute *attr, + char *buf) { struct iio_dev *dev_info = dev_to_iio_dev(dev); struct adt7316_chip_info *chip = iio_priv(dev_info); @@ -1811,8 +1813,8 @@ static irqreturn_t adt7316_event_handler(int irq, void *private) * Show mask of enabled interrupts in Hex. */ static ssize_t adt7316_show_int_mask(struct device *dev, - struct device_attribute *attr, - char *buf) + struct device_attribute *attr, + char *buf) { struct iio_dev *dev_info = dev_to_iio_dev(dev); struct adt7316_chip_info *chip = iio_priv(dev_info); @@ -1824,9 +1826,9 @@ static ssize_t adt7316_show_int_mask(struct device *dev, * Set 1 to the mask in Hex to enabled interrupts. */ static ssize_t adt7316_set_int_mask(struct device *dev, - struct device_attribute *attr, - const char *buf, - size_t len) + struct device_attribute *attr, + const char *buf, + size_t len) { struct iio_dev *dev_info = dev_to_iio_dev(dev); struct adt7316_chip_info *chip = iio_priv(dev_info); @@ -1865,8 +1867,8 @@ static ssize_t adt7316_set_int_mask(struct device *dev, } static inline ssize_t adt7316_show_ad_bound(struct device *dev, - struct device_attribute *attr, - char *buf) + struct device_attribute *attr, + char *buf) { struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); struct iio_dev *dev_info = dev_to_iio_dev(dev); @@ -1876,7 +1878,7 @@ static inline ssize_t adt7316_show_ad_bound(struct device *dev, int ret; if ((chip->id & ID_FAMILY_MASK) == ID_ADT73XX && - this_attr->address > ADT7316_EX_TEMP_LOW) + this_attr->address > ADT7316_EX_TEMP_LOW) return -EPERM; ret = chip->bus.read(chip->bus.client, this_attr->address, &val); @@ -1886,7 +1888,7 @@ static inline ssize_t adt7316_show_ad_bound(struct device *dev, data = (int)val; if (!((chip->id & ID_FAMILY_MASK) == ID_ADT75XX && - (chip->config1 & ADT7516_SEL_AIN1_2_EX_TEMP_MASK) == 0)) { + (chip->config1 & ADT7516_SEL_AIN1_2_EX_TEMP_MASK) == 0)) { if (data & 0x80) data -= 256; } @@ -1895,9 +1897,9 @@ static inline ssize_t adt7316_show_ad_bound(struct device *dev, } static inline ssize_t adt7316_set_ad_bound(struct device *dev, - struct device_attribute *attr, - const char *buf, - size_t len) + struct device_attribute *attr, + const char *buf, + size_t len) { struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); struct iio_dev *dev_info = dev_to_iio_dev(dev); @@ -1907,7 +1909,7 @@ static inline ssize_t adt7316_set_ad_bound(struct device *dev, int ret; if ((chip->id & ID_FAMILY_MASK) == ID_ADT73XX && - this_attr->address > ADT7316_EX_TEMP_LOW) + this_attr->address > ADT7316_EX_TEMP_LOW) return -EPERM; ret = kstrtoint(buf, 10, &data); @@ -1915,7 +1917,7 @@ static inline ssize_t adt7316_set_ad_bound(struct device *dev, return -EINVAL; if ((chip->id & ID_FAMILY_MASK) == ID_ADT75XX && - (chip->config1 & ADT7516_SEL_AIN1_2_EX_TEMP_MASK) == 0) { + (chip->config1 & ADT7516_SEL_AIN1_2_EX_TEMP_MASK) == 0) { if (data > 255 || data < 0) return -EINVAL; } else { @@ -1936,8 +1938,8 @@ static inline ssize_t adt7316_set_ad_bound(struct device *dev, } static ssize_t adt7316_show_int_enabled(struct device *dev, - struct device_attribute *attr, - char *buf) + struct device_attribute *attr, + char *buf) { struct iio_dev *dev_info = dev_to_iio_dev(dev); struct adt7316_chip_info *chip = iio_priv(dev_info); @@ -1946,9 +1948,9 @@ static ssize_t adt7316_show_int_enabled(struct device *dev, } static ssize_t adt7316_set_int_enabled(struct device *dev, - struct device_attribute *attr, - const char *buf, - size_t len) + struct device_attribute *attr, + const char *buf, + size_t len) { struct iio_dev *dev_info = dev_to_iio_dev(dev); struct adt7316_chip_info *chip = iio_priv(dev_info); @@ -2097,7 +2099,7 @@ static const struct iio_info adt7516_info = { * device probe and remove */ int adt7316_probe(struct device *dev, struct adt7316_bus *bus, - const char *name) + const char *name) { struct adt7316_chip_info *chip; struct iio_dev *indio_dev; @@ -2169,7 +2171,7 @@ int adt7316_probe(struct device *dev, struct adt7316_bus *bus, return ret; dev_info(dev, "%s temperature sensor, ADC and DAC registered.\n", - indio_dev->name); + indio_dev->name); return 0; } diff --git a/drivers/staging/iio/addac/adt7316.h b/drivers/staging/iio/addac/adt7316.h index ec40fbb698a6..b954dcbc92db 100644 --- a/drivers/staging/iio/addac/adt7316.h +++ b/drivers/staging/iio/addac/adt7316.h @@ -31,6 +31,6 @@ extern const struct dev_pm_ops adt7316_pm_ops; #define ADT7316_PM_OPS NULL #endif int adt7316_probe(struct device *dev, struct adt7316_bus *bus, - const char *name); + const char *name); #endif -- cgit v1.2.3 From 0559ef7fde67bc6c83c6eb6329dbd6649528263e Mon Sep 17 00:00:00 2001 From: Slawomir Stepien Date: Sat, 20 Oct 2018 23:04:11 +0200 Subject: staging: iio: adc: ad7280a: handle error from __ad7280_read32() Inside __ad7280_read32(), the spi_sync_transfer() can fail with negative error code. This change will ensure that this error is being passed up in the call stack, so it can be handled. Signed-off-by: Slawomir Stepien Signed-off-by: Jonathan Cameron --- drivers/staging/iio/adc/ad7280a.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) (limited to 'drivers/staging/iio') diff --git a/drivers/staging/iio/adc/ad7280a.c b/drivers/staging/iio/adc/ad7280a.c index 58420dcb406d..cbeb52485a31 100644 --- a/drivers/staging/iio/adc/ad7280a.c +++ b/drivers/staging/iio/adc/ad7280a.c @@ -256,7 +256,9 @@ static int ad7280_read(struct ad7280_state *st, unsigned int devaddr, if (ret) return ret; - __ad7280_read32(st, &tmp); + ret = __ad7280_read32(st, &tmp); + if (ret) + return ret; if (ad7280_check_crc(st, tmp)) return -EIO; @@ -294,7 +296,9 @@ static int ad7280_read_channel(struct ad7280_state *st, unsigned int devaddr, ad7280_delay(st); - __ad7280_read32(st, &tmp); + ret = __ad7280_read32(st, &tmp); + if (ret) + return ret; if (ad7280_check_crc(st, tmp)) return -EIO; @@ -327,7 +331,9 @@ static int ad7280_read_all_channels(struct ad7280_state *st, unsigned int cnt, ad7280_delay(st); for (i = 0; i < cnt; i++) { - __ad7280_read32(st, &tmp); + ret = __ad7280_read32(st, &tmp); + if (ret) + return ret; if (ad7280_check_crc(st, tmp)) return -EIO; @@ -370,7 +376,10 @@ static int ad7280_chain_setup(struct ad7280_state *st) return ret; for (n = 0; n <= AD7280A_MAX_CHAIN; n++) { - __ad7280_read32(st, &val); + ret = __ad7280_read32(st, &val); + if (ret) + return ret; + if (val == 0) return n - 1; -- cgit v1.2.3 From 4cd62a5425115ad14b54f2c7dece597c0c57d701 Mon Sep 17 00:00:00 2001 From: Slawomir Stepien Date: Thu, 18 Oct 2018 20:59:33 +0200 Subject: staging: iio: adc: ad7280a: use crc8.h API to build crc table The custom build function ad7280_crc8_build_table is not needed. The crc8_populate_msb function from linux/crc8.h will build the same crc table. Signed-off-by: Slawomir Stepien Acked-by: Lars-Peter Clausen Signed-off-by: Jonathan Cameron --- drivers/staging/iio/adc/Kconfig | 1 + drivers/staging/iio/adc/ad7280a.c | 24 +++--------------------- 2 files changed, 4 insertions(+), 21 deletions(-) (limited to 'drivers/staging/iio') diff --git a/drivers/staging/iio/adc/Kconfig b/drivers/staging/iio/adc/Kconfig index 9d3062a07460..fc23059f1673 100644 --- a/drivers/staging/iio/adc/Kconfig +++ b/drivers/staging/iio/adc/Kconfig @@ -73,6 +73,7 @@ config AD7192 config AD7280 tristate "Analog Devices AD7280A Lithium Ion Battery Monitoring System" depends on SPI + select CRC8 help Say yes here to build support for Analog Devices AD7280A Lithium Ion Battery Monitoring System. diff --git a/drivers/staging/iio/adc/ad7280a.c b/drivers/staging/iio/adc/ad7280a.c index cbeb52485a31..7161998c8a0e 100644 --- a/drivers/staging/iio/adc/ad7280a.c +++ b/drivers/staging/iio/adc/ad7280a.c @@ -6,6 +6,7 @@ * Licensed under the GPL-2. */ +#include #include #include #include @@ -121,8 +122,6 @@ static unsigned int ad7280a_devaddr(unsigned int addr) * P(x) = x^8 + x^5 + x^3 + x^2 + x^1 + x^0 = 0b100101111 => 0x2F */ #define POLYNOM 0x2F -#define POLYNOM_ORDER 8 -#define HIGHBIT (1 << (POLYNOM_ORDER - 1)) struct ad7280_state { struct spi_device *spi; @@ -131,7 +130,7 @@ struct ad7280_state { int slave_num; int scan_cnt; int readback_delay_us; - unsigned char crc_tab[256]; + unsigned char crc_tab[CRC8_TABLE_SIZE]; unsigned char ctrl_hb; unsigned char ctrl_lb; unsigned char cell_threshhigh; @@ -144,23 +143,6 @@ struct ad7280_state { __be32 buf[2] ____cacheline_aligned; }; -static void ad7280_crc8_build_table(unsigned char *crc_tab) -{ - unsigned char bit, crc; - int cnt, i; - - for (cnt = 0; cnt < 256; cnt++) { - crc = cnt; - for (i = 0; i < 8; i++) { - bit = crc & HIGHBIT; - crc <<= 1; - if (bit) - crc ^= POLYNOM; - } - crc_tab[cnt] = crc; - } -} - static unsigned char ad7280_calc_crc8(unsigned char *crc_tab, unsigned int val) { unsigned char crc; @@ -866,7 +848,7 @@ static int ad7280_probe(struct spi_device *spi) if (!pdata) pdata = &ad7793_default_pdata; - ad7280_crc8_build_table(st->crc_tab); + crc8_populate_msb(st->crc_tab, POLYNOM); st->spi->max_speed_hz = AD7280A_MAX_SPI_CLK_HZ; st->spi->mode = SPI_MODE_1; -- cgit v1.2.3 From e480490c90956f8e46ba666b49bc56000083bbfe Mon Sep 17 00:00:00 2001 From: Marcelo Schmitt Date: Wed, 17 Oct 2018 22:31:47 -0300 Subject: Staging:iio:adc:ad7606: Match parenthesis alignment Change close parenthesis alignment to match respective open parenthesis at iio/drivers/staging/iio/adc/ad7606.c line 379. This makes the file more compliant with the preferred coding style for the linux kernel. Signed-of-by: Marcelo Schmitt Signed-off-by: Jonathan Cameron --- drivers/staging/iio/adc/ad7606.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/staging/iio') diff --git a/drivers/staging/iio/adc/ad7606.c b/drivers/staging/iio/adc/ad7606.c index 0b728b6ea135..230faae38c12 100644 --- a/drivers/staging/iio/adc/ad7606.c +++ b/drivers/staging/iio/adc/ad7606.c @@ -376,7 +376,7 @@ static int ad7606_request_gpios(struct ad7606_state *st) return 0; st->gpio_os = devm_gpiod_get_array_optional(dev, "oversampling-ratio", - GPIOD_OUT_LOW); + GPIOD_OUT_LOW); return PTR_ERR_OR_ZERO(st->gpio_os); } -- cgit v1.2.3 From 073a391ca0352d4c66b6ffc4ff5db18a457f5519 Mon Sep 17 00:00:00 2001 From: Nishad Kamdar Date: Wed, 17 Oct 2018 20:17:20 +0530 Subject: staging: iio: ad7816: Switch to the gpio descriptor interface Use the gpiod interface for rdwr_pin, convert_pin and busy_pin instead of the deprecated old non-descriptor interface. Note that Phil Reid identified that some of this code would never have worked. A follow up patch can fix that as this is just a direct change of interface. Signed-off-by: Nishad Kamdar Acked-by: Lars-Peter Clausen Signed-off-by: Jonathan Cameron --- drivers/staging/iio/adc/ad7816.c | 80 +++++++++++++++++----------------------- 1 file changed, 34 insertions(+), 46 deletions(-) (limited to 'drivers/staging/iio') diff --git a/drivers/staging/iio/adc/ad7816.c b/drivers/staging/iio/adc/ad7816.c index bf76a8620bdb..12c4e0ab4713 100644 --- a/drivers/staging/iio/adc/ad7816.c +++ b/drivers/staging/iio/adc/ad7816.c @@ -7,7 +7,7 @@ */ #include -#include +#include #include #include #include @@ -44,9 +44,9 @@ struct ad7816_chip_info { struct spi_device *spi_dev; - u16 rdwr_pin; - u16 convert_pin; - u16 busy_pin; + struct gpio_desc *rdwr_pin; + struct gpio_desc *convert_pin; + struct gpio_desc *busy_pin; u8 oti_data[AD7816_CS_MAX + 1]; u8 channel_id; /* 0 always be temperature */ u8 mode; @@ -61,28 +61,28 @@ static int ad7816_spi_read(struct ad7816_chip_info *chip, u16 *data) int ret = 0; __be16 buf; - gpio_set_value(chip->rdwr_pin, 1); - gpio_set_value(chip->rdwr_pin, 0); + gpiod_set_value(chip->rdwr_pin, 1); + gpiod_set_value(chip->rdwr_pin, 0); ret = spi_write(spi_dev, &chip->channel_id, sizeof(chip->channel_id)); if (ret < 0) { dev_err(&spi_dev->dev, "SPI channel setting error\n"); return ret; } - gpio_set_value(chip->rdwr_pin, 1); + gpiod_set_value(chip->rdwr_pin, 1); if (chip->mode == AD7816_PD) { /* operating mode 2 */ - gpio_set_value(chip->convert_pin, 1); - gpio_set_value(chip->convert_pin, 0); + gpiod_set_value(chip->convert_pin, 1); + gpiod_set_value(chip->convert_pin, 0); } else { /* operating mode 1 */ - gpio_set_value(chip->convert_pin, 0); - gpio_set_value(chip->convert_pin, 1); + gpiod_set_value(chip->convert_pin, 0); + gpiod_set_value(chip->convert_pin, 1); } - while (gpio_get_value(chip->busy_pin)) + while (gpiod_get_value(chip->busy_pin)) cpu_relax(); - gpio_set_value(chip->rdwr_pin, 0); - gpio_set_value(chip->rdwr_pin, 1); + gpiod_set_value(chip->rdwr_pin, 0); + gpiod_set_value(chip->rdwr_pin, 1); ret = spi_read(spi_dev, &buf, sizeof(*data)); if (ret < 0) { dev_err(&spi_dev->dev, "SPI data read error\n"); @@ -99,8 +99,8 @@ static int ad7816_spi_write(struct ad7816_chip_info *chip, u8 data) struct spi_device *spi_dev = chip->spi_dev; int ret = 0; - gpio_set_value(chip->rdwr_pin, 1); - gpio_set_value(chip->rdwr_pin, 0); + gpiod_set_value(chip->rdwr_pin, 1); + gpiod_set_value(chip->rdwr_pin, 0); ret = spi_write(spi_dev, &data, sizeof(data)); if (ret < 0) dev_err(&spi_dev->dev, "SPI oti data write error\n"); @@ -129,10 +129,10 @@ static ssize_t ad7816_store_mode(struct device *dev, struct ad7816_chip_info *chip = iio_priv(indio_dev); if (strcmp(buf, "full")) { - gpio_set_value(chip->rdwr_pin, 1); + gpiod_set_value(chip->rdwr_pin, 1); chip->mode = AD7816_FULL; } else { - gpio_set_value(chip->rdwr_pin, 0); + gpiod_set_value(chip->rdwr_pin, 0); chip->mode = AD7816_PD; } @@ -345,15 +345,9 @@ static int ad7816_probe(struct spi_device *spi_dev) { struct ad7816_chip_info *chip; struct iio_dev *indio_dev; - unsigned short *pins = dev_get_platdata(&spi_dev->dev); int ret = 0; int i; - if (!pins) { - dev_err(&spi_dev->dev, "No necessary GPIO platform data.\n"); - return -EINVAL; - } - indio_dev = devm_iio_device_alloc(&spi_dev->dev, sizeof(*chip)); if (!indio_dev) return -ENOMEM; @@ -364,34 +358,28 @@ static int ad7816_probe(struct spi_device *spi_dev) chip->spi_dev = spi_dev; for (i = 0; i <= AD7816_CS_MAX; i++) chip->oti_data[i] = 203; - chip->rdwr_pin = pins[0]; - chip->convert_pin = pins[1]; - chip->busy_pin = pins[2]; - - ret = devm_gpio_request(&spi_dev->dev, chip->rdwr_pin, - spi_get_device_id(spi_dev)->name); - if (ret) { - dev_err(&spi_dev->dev, "Fail to request rdwr gpio PIN %d.\n", - chip->rdwr_pin); + + chip->rdwr_pin = devm_gpiod_get(&spi_dev->dev, "rdwr", GPIOD_IN); + if (IS_ERR(chip->rdwr_pin)) { + ret = PTR_ERR(chip->rdwr_pin); + dev_err(&spi_dev->dev, "Failed to request rdwr GPIO: %d\n", + ret); return ret; } - gpio_direction_input(chip->rdwr_pin); - ret = devm_gpio_request(&spi_dev->dev, chip->convert_pin, - spi_get_device_id(spi_dev)->name); - if (ret) { - dev_err(&spi_dev->dev, "Fail to request convert gpio PIN %d.\n", - chip->convert_pin); + chip->convert_pin = devm_gpiod_get(&spi_dev->dev, "convert", GPIOD_IN); + if (IS_ERR(chip->convert_pin)) { + ret = PTR_ERR(chip->convert_pin); + dev_err(&spi_dev->dev, "Failed to request convert GPIO: %d\n", + ret); return ret; } - gpio_direction_input(chip->convert_pin); - ret = devm_gpio_request(&spi_dev->dev, chip->busy_pin, - spi_get_device_id(spi_dev)->name); - if (ret) { - dev_err(&spi_dev->dev, "Fail to request busy gpio PIN %d.\n", - chip->busy_pin); + chip->busy_pin = devm_gpiod_get(&spi_dev->dev, "busy", GPIOD_IN); + if (IS_ERR(chip->busy_pin)) { + ret = PTR_ERR(chip->busy_pin); + dev_err(&spi_dev->dev, "Failed to request busy GPIO: %d\n", + ret); return ret; } - gpio_direction_input(chip->busy_pin); indio_dev->name = spi_get_device_id(spi_dev)->name; indio_dev->dev.parent = &spi_dev->dev; -- cgit v1.2.3 From e147791fa13dea35b62ac80f885dbb9378bc0976 Mon Sep 17 00:00:00 2001 From: Victor Colombo Date: Mon, 22 Oct 2018 17:40:25 -0300 Subject: staging: iio: ad5933: Remove unnecessary space on casting This patch fixes the checkpatch.pl warning: WARNING: No space is necessary after a cast Signed-off-by: Victor Colombo Signed-off-by: Jonathan Cameron --- drivers/staging/iio/impedance-analyzer/ad5933.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/staging/iio') diff --git a/drivers/staging/iio/impedance-analyzer/ad5933.c b/drivers/staging/iio/impedance-analyzer/ad5933.c index 8a920f675b83..7a216ea90784 100644 --- a/drivers/staging/iio/impedance-analyzer/ad5933.c +++ b/drivers/staging/iio/impedance-analyzer/ad5933.c @@ -210,7 +210,7 @@ static int ad5933_set_freq(struct ad5933_state *st, u8 d8[4]; } dat; - freqreg = (u64) freq * (u64) (1 << 27); + freqreg = (u64)freq * (u64)(1 << 27); do_div(freqreg, st->mclk_hz / 4); switch (reg) { -- cgit v1.2.3 From 3138bbc12915d3b894b70e8f9dc44de2948c1c25 Mon Sep 17 00:00:00 2001 From: Victor Colombo Date: Mon, 22 Oct 2018 17:41:27 -0300 Subject: staging: iio: ad5933: Remove unnecessary blank line This patch fixes the checkpatch.pl warning: WARNING: Blank lines aren't necessary before a close brace '}' Signed-off-by: Victor Colombo Signed-off-by: Jonathan Cameron --- drivers/staging/iio/impedance-analyzer/ad5933.c | 1 - 1 file changed, 1 deletion(-) (limited to 'drivers/staging/iio') diff --git a/drivers/staging/iio/impedance-analyzer/ad5933.c b/drivers/staging/iio/impedance-analyzer/ad5933.c index 7a216ea90784..f9bcb8310e21 100644 --- a/drivers/staging/iio/impedance-analyzer/ad5933.c +++ b/drivers/staging/iio/impedance-analyzer/ad5933.c @@ -267,7 +267,6 @@ static void ad5933_calc_out_ranges(struct ad5933_state *st) for (i = 0; i < 4; i++) st->range_avail[i] = normalized_3v3[i] * st->vref_mv / 3300; - } /* -- cgit v1.2.3 From fdee2ca14bcaecbd5738c679f91acbab74b349aa Mon Sep 17 00:00:00 2001 From: Slawomir Stepien Date: Fri, 26 Oct 2018 18:53:10 +0200 Subject: staging: iio: adc: ad7280a: don't cast type inside switch expression The type promotion will kick in, so the comparison will work. Signed-off-by: Slawomir Stepien Signed-off-by: Jonathan Cameron --- drivers/staging/iio/adc/ad7280a.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'drivers/staging/iio') diff --git a/drivers/staging/iio/adc/ad7280a.c b/drivers/staging/iio/adc/ad7280a.c index 7161998c8a0e..89c2c2deca64 100644 --- a/drivers/staging/iio/adc/ad7280a.c +++ b/drivers/staging/iio/adc/ad7280a.c @@ -601,7 +601,7 @@ static ssize_t ad7280_read_channel_config(struct device *dev, struct iio_dev_attr *this_attr = to_iio_dev_attr(attr); unsigned int val; - switch ((u32)this_attr->address) { + switch (this_attr->address) { case AD7280A_CELL_OVERVOLTAGE: val = 1000 + (st->cell_threshhigh * 1568) / 100; break; @@ -637,7 +637,7 @@ static ssize_t ad7280_write_channel_config(struct device *dev, if (ret) return ret; - switch ((u32)this_attr->address) { + switch (this_attr->address) { case AD7280A_CELL_OVERVOLTAGE: case AD7280A_CELL_UNDERVOLTAGE: val = ((val - 1000) * 100) / 1568; /* LSB 15.68mV */ @@ -653,7 +653,7 @@ static ssize_t ad7280_write_channel_config(struct device *dev, val = clamp(val, 0L, 0xFFL); mutex_lock(&st->lock); - switch ((u32)this_attr->address) { + switch (this_attr->address) { case AD7280A_CELL_OVERVOLTAGE: st->cell_threshhigh = val; break; -- cgit v1.2.3 From f356dc6ec26b3990070ca16ec12a4239e9128bd8 Mon Sep 17 00:00:00 2001 From: Nishad Kamdar Date: Wed, 31 Oct 2018 21:28:52 +0530 Subject: staging: iio: ad2s1210: Switch to the gpio descriptor interface Use the gpiod interface instead of the deprecated old non-descriptor interface. Signed-off-by: Nishad Kamdar Signed-off-by: Jonathan Cameron --- drivers/staging/iio/resolver/ad2s1210.c | 107 +++++++++++++++++++------------- drivers/staging/iio/resolver/ad2s1210.h | 3 - 2 files changed, 63 insertions(+), 47 deletions(-) (limited to 'drivers/staging/iio') diff --git a/drivers/staging/iio/resolver/ad2s1210.c b/drivers/staging/iio/resolver/ad2s1210.c index d4b1c2c010f2..e2623984b200 100644 --- a/drivers/staging/iio/resolver/ad2s1210.c +++ b/drivers/staging/iio/resolver/ad2s1210.c @@ -15,7 +15,7 @@ #include #include #include -#include +#include #include #include @@ -67,12 +67,42 @@ enum ad2s1210_mode { MOD_RESERVED, }; +enum ad2s1210_gpios { + AD2S1210_SAMPLE, + AD2S1210_A0, + AD2S1210_A1, + AD2S1210_RES0, + AD2S1210_RES1, +}; + +struct ad2s1210_gpio { + const char *name; + unsigned long flags; +}; + +static const struct ad2s1210_gpio gpios_in[] = { + [AD2S1210_SAMPLE] = { .name = "adi,sample", .flags = GPIOD_IN }, + [AD2S1210_A0] = { .name = "adi,a0", .flags = GPIOD_IN }, + [AD2S1210_A1] = { .name = "adi,a1", .flags = GPIOD_IN }, + [AD2S1210_RES0] = { .name = "adi,res0", .flags = GPIOD_IN }, + [AD2S1210_RES1] = { .name = "adi,res1", .flags = GPIOD_IN }, +}; + +static const struct ad2s1210_gpio gpios_out[] = { + [AD2S1210_SAMPLE] = { .name = "adi,sample", .flags = GPIOD_OUT_LOW }, + [AD2S1210_A0] = { .name = "adi,a0", .flags = GPIOD_OUT_LOW }, + [AD2S1210_A1] = { .name = "adi,a1", .flags = GPIOD_OUT_LOW }, + [AD2S1210_RES0] = { .name = "adi,res0", .flags = GPIOD_OUT_LOW }, + [AD2S1210_RES1] = { .name = "adi,res1", .flags = GPIOD_OUT_LOW }, +}; + static const unsigned int ad2s1210_resolution_value[] = { 10, 12, 14, 16 }; struct ad2s1210_state { const struct ad2s1210_platform_data *pdata; struct mutex lock; struct spi_device *sdev; + struct gpio_desc *gpios[5]; unsigned int fclkin; unsigned int fexcit; bool hysteresis; @@ -91,8 +121,8 @@ static const int ad2s1210_mode_vals[4][2] = { static inline void ad2s1210_set_mode(enum ad2s1210_mode mode, struct ad2s1210_state *st) { - gpio_set_value(st->pdata->a[0], ad2s1210_mode_vals[mode][0]); - gpio_set_value(st->pdata->a[1], ad2s1210_mode_vals[mode][1]); + gpiod_set_value(st->gpios[AD2S1210_A0], ad2s1210_mode_vals[mode][0]); + gpiod_set_value(st->gpios[AD2S1210_A1], ad2s1210_mode_vals[mode][1]); st->mode = mode; } @@ -152,8 +182,8 @@ int ad2s1210_update_frequency_control_word(struct ad2s1210_state *st) static unsigned char ad2s1210_read_resolution_pin(struct ad2s1210_state *st) { - int resolution = (gpio_get_value(st->pdata->res[0]) << 1) | - gpio_get_value(st->pdata->res[1]); + int resolution = (gpiod_get_value(st->gpios[AD2S1210_RES0]) << 1) | + gpiod_get_value(st->gpios[AD2S1210_RES1]); return ad2s1210_resolution_value[resolution]; } @@ -164,10 +194,10 @@ static const int ad2s1210_res_pins[4][2] = { static inline void ad2s1210_set_resolution_pin(struct ad2s1210_state *st) { - gpio_set_value(st->pdata->res[0], - ad2s1210_res_pins[(st->resolution - 10) / 2][0]); - gpio_set_value(st->pdata->res[1], - ad2s1210_res_pins[(st->resolution - 10) / 2][1]); + gpiod_set_value(st->gpios[AD2S1210_RES0], + ad2s1210_res_pins[(st->resolution - 10) / 2][0]); + gpiod_set_value(st->gpios[AD2S1210_RES1], + ad2s1210_res_pins[(st->resolution - 10) / 2][1]); } static inline int ad2s1210_soft_reset(struct ad2s1210_state *st) @@ -401,15 +431,15 @@ static ssize_t ad2s1210_clear_fault(struct device *dev, int ret; mutex_lock(&st->lock); - gpio_set_value(st->pdata->sample, 0); + gpiod_set_value(st->gpios[AD2S1210_SAMPLE], 0); /* delay (2 * tck + 20) nano seconds */ udelay(1); - gpio_set_value(st->pdata->sample, 1); + gpiod_set_value(st->gpios[AD2S1210_SAMPLE], 1); ret = ad2s1210_config_read(st, AD2S1210_REG_FAULT); if (ret < 0) goto error_ret; - gpio_set_value(st->pdata->sample, 0); - gpio_set_value(st->pdata->sample, 1); + gpiod_set_value(st->gpios[AD2S1210_SAMPLE], 0); + gpiod_set_value(st->gpios[AD2S1210_SAMPLE], 1); error_ret: mutex_unlock(&st->lock); @@ -466,7 +496,7 @@ static int ad2s1210_read_raw(struct iio_dev *indio_dev, s16 vel; mutex_lock(&st->lock); - gpio_set_value(st->pdata->sample, 0); + gpiod_set_value(st->gpios[AD2S1210_SAMPLE], 0); /* delay (6 * tck + 20) nano seconds */ udelay(1); @@ -512,7 +542,7 @@ static int ad2s1210_read_raw(struct iio_dev *indio_dev, } error_ret: - gpio_set_value(st->pdata->sample, 1); + gpiod_set_value(st->gpios[AD2S1210_SAMPLE], 1); /* delay (2 * tck + 20) nano seconds */ udelay(1); mutex_unlock(&st->lock); @@ -630,30 +660,24 @@ static const struct iio_info ad2s1210_info = { static int ad2s1210_setup_gpios(struct ad2s1210_state *st) { - unsigned long flags = st->pdata->gpioin ? GPIOF_DIR_IN : GPIOF_DIR_OUT; - struct gpio ad2s1210_gpios[] = { - { st->pdata->sample, GPIOF_DIR_IN, "sample" }, - { st->pdata->a[0], flags, "a0" }, - { st->pdata->a[1], flags, "a1" }, - { st->pdata->res[0], flags, "res0" }, - { st->pdata->res[0], flags, "res1" }, - }; - - return gpio_request_array(ad2s1210_gpios, ARRAY_SIZE(ad2s1210_gpios)); -} - -static void ad2s1210_free_gpios(struct ad2s1210_state *st) -{ - unsigned long flags = st->pdata->gpioin ? GPIOF_DIR_IN : GPIOF_DIR_OUT; - struct gpio ad2s1210_gpios[] = { - { st->pdata->sample, GPIOF_DIR_IN, "sample" }, - { st->pdata->a[0], flags, "a0" }, - { st->pdata->a[1], flags, "a1" }, - { st->pdata->res[0], flags, "res0" }, - { st->pdata->res[0], flags, "res1" }, - }; + const struct ad2s1210_gpio *pin = st->pdata->gpioin ? + &gpios_in[0] : &gpios_out[0]; + struct spi_device *spi = st->sdev; + int i, ret; + + for (i = 0; i < ARRAY_SIZE(gpios_in); i++) { + st->gpios[i] = devm_gpiod_get(&spi->dev, pin[i].name, + pin[i].flags); + if (IS_ERR(st->gpios[i])) { + ret = PTR_ERR(st->gpios[i]); + dev_err(&spi->dev, + "ad2s1210: failed to request %s GPIO: %d\n", + pin[i].name, ret); + return ret; + } + } - gpio_free_array(ad2s1210_gpios, ARRAY_SIZE(ad2s1210_gpios)); + return 0; } static int ad2s1210_probe(struct spi_device *spi) @@ -692,7 +716,7 @@ static int ad2s1210_probe(struct spi_device *spi) ret = iio_device_register(indio_dev); if (ret) - goto error_free_gpios; + return ret; st->fclkin = spi->max_speed_hz; spi->mode = SPI_MODE_3; @@ -700,10 +724,6 @@ static int ad2s1210_probe(struct spi_device *spi) ad2s1210_initial(st); return 0; - -error_free_gpios: - ad2s1210_free_gpios(st); - return ret; } static int ad2s1210_remove(struct spi_device *spi) @@ -711,7 +731,6 @@ static int ad2s1210_remove(struct spi_device *spi) struct iio_dev *indio_dev = spi_get_drvdata(spi); iio_device_unregister(indio_dev); - ad2s1210_free_gpios(iio_priv(indio_dev)); return 0; } diff --git a/drivers/staging/iio/resolver/ad2s1210.h b/drivers/staging/iio/resolver/ad2s1210.h index e9b2147701fc..63d479b20a6c 100644 --- a/drivers/staging/iio/resolver/ad2s1210.h +++ b/drivers/staging/iio/resolver/ad2s1210.h @@ -12,9 +12,6 @@ #define _AD2S1210_H struct ad2s1210_platform_data { - unsigned int sample; - unsigned int a[2]; - unsigned int res[2]; bool gpioin; }; #endif /* _AD2S1210_H */ -- cgit v1.2.3 From 66dd9e3d5e038f46f2cbecc76a1e970b614dc824 Mon Sep 17 00:00:00 2001 From: Nishad Kamdar Date: Wed, 31 Oct 2018 21:29:53 +0530 Subject: staging: iio: ad2s1210: Drop the gpioin flag. Drop gpioin flag which decides how the GPIOs are controlled as the GPIOs must be outputs for the host as per the datasheet. Removes need for platform data so that is dropped as well. Signed-off-by: Nishad Kamdar Signed-off-by: Jonathan Cameron --- drivers/staging/iio/resolver/ad2s1210.c | 52 +++++---------------------------- drivers/staging/iio/resolver/ad2s1210.h | 17 ----------- 2 files changed, 8 insertions(+), 61 deletions(-) delete mode 100644 drivers/staging/iio/resolver/ad2s1210.h (limited to 'drivers/staging/iio') diff --git a/drivers/staging/iio/resolver/ad2s1210.c b/drivers/staging/iio/resolver/ad2s1210.c index e2623984b200..235944189ab0 100644 --- a/drivers/staging/iio/resolver/ad2s1210.c +++ b/drivers/staging/iio/resolver/ad2s1210.c @@ -20,7 +20,6 @@ #include #include -#include "ad2s1210.h" #define DRV_NAME "ad2s1210" @@ -80,15 +79,7 @@ struct ad2s1210_gpio { unsigned long flags; }; -static const struct ad2s1210_gpio gpios_in[] = { - [AD2S1210_SAMPLE] = { .name = "adi,sample", .flags = GPIOD_IN }, - [AD2S1210_A0] = { .name = "adi,a0", .flags = GPIOD_IN }, - [AD2S1210_A1] = { .name = "adi,a1", .flags = GPIOD_IN }, - [AD2S1210_RES0] = { .name = "adi,res0", .flags = GPIOD_IN }, - [AD2S1210_RES1] = { .name = "adi,res1", .flags = GPIOD_IN }, -}; - -static const struct ad2s1210_gpio gpios_out[] = { +static const struct ad2s1210_gpio gpios[] = { [AD2S1210_SAMPLE] = { .name = "adi,sample", .flags = GPIOD_OUT_LOW }, [AD2S1210_A0] = { .name = "adi,a0", .flags = GPIOD_OUT_LOW }, [AD2S1210_A1] = { .name = "adi,a1", .flags = GPIOD_OUT_LOW }, @@ -99,7 +90,6 @@ static const struct ad2s1210_gpio gpios_out[] = { static const unsigned int ad2s1210_resolution_value[] = { 10, 12, 14, 16 }; struct ad2s1210_state { - const struct ad2s1210_platform_data *pdata; struct mutex lock; struct spi_device *sdev; struct gpio_desc *gpios[5]; @@ -180,14 +170,6 @@ int ad2s1210_update_frequency_control_word(struct ad2s1210_state *st) return ad2s1210_config_write(st, fcw); } -static unsigned char ad2s1210_read_resolution_pin(struct ad2s1210_state *st) -{ - int resolution = (gpiod_get_value(st->gpios[AD2S1210_RES0]) << 1) | - gpiod_get_value(st->gpios[AD2S1210_RES1]); - - return ad2s1210_resolution_value[resolution]; -} - static const int ad2s1210_res_pins[4][2] = { { 0, 0 }, {0, 1}, {1, 0}, {1, 1} }; @@ -333,13 +315,7 @@ static ssize_t ad2s1210_store_control(struct device *dev, } st->resolution = ad2s1210_resolution_value[data & AD2S1210_SET_RESOLUTION]; - if (st->pdata->gpioin) { - data = ad2s1210_read_resolution_pin(st); - if (data != st->resolution) - dev_warn(dev, "ad2s1210: resolution settings not match\n"); - } else { - ad2s1210_set_resolution_pin(st); - } + ad2s1210_set_resolution_pin(st); ret = len; st->hysteresis = !!(data & AD2S1210_ENABLE_HYSTERESIS); @@ -395,13 +371,7 @@ static ssize_t ad2s1210_store_resolution(struct device *dev, } st->resolution = ad2s1210_resolution_value[data & AD2S1210_SET_RESOLUTION]; - if (st->pdata->gpioin) { - data = ad2s1210_read_resolution_pin(st); - if (data != st->resolution) - dev_warn(dev, "ad2s1210: resolution settings not match\n"); - } else { - ad2s1210_set_resolution_pin(st); - } + ad2s1210_set_resolution_pin(st); ret = len; error_ret: mutex_unlock(&st->lock); @@ -622,10 +592,7 @@ static int ad2s1210_initial(struct ad2s1210_state *st) int ret; mutex_lock(&st->lock); - if (st->pdata->gpioin) - st->resolution = ad2s1210_read_resolution_pin(st); - else - ad2s1210_set_resolution_pin(st); + ad2s1210_set_resolution_pin(st); ret = ad2s1210_config_write(st, AD2S1210_REG_CONTROL); if (ret < 0) @@ -660,19 +627,17 @@ static const struct iio_info ad2s1210_info = { static int ad2s1210_setup_gpios(struct ad2s1210_state *st) { - const struct ad2s1210_gpio *pin = st->pdata->gpioin ? - &gpios_in[0] : &gpios_out[0]; struct spi_device *spi = st->sdev; int i, ret; - for (i = 0; i < ARRAY_SIZE(gpios_in); i++) { - st->gpios[i] = devm_gpiod_get(&spi->dev, pin[i].name, - pin[i].flags); + for (i = 0; i < ARRAY_SIZE(gpios); i++) { + st->gpios[i] = devm_gpiod_get(&spi->dev, gpios[i].name, + gpios[i].flags); if (IS_ERR(st->gpios[i])) { ret = PTR_ERR(st->gpios[i]); dev_err(&spi->dev, "ad2s1210: failed to request %s GPIO: %d\n", - pin[i].name, ret); + gpios[i].name, ret); return ret; } } @@ -693,7 +658,6 @@ static int ad2s1210_probe(struct spi_device *spi) if (!indio_dev) return -ENOMEM; st = iio_priv(indio_dev); - st->pdata = spi->dev.platform_data; ret = ad2s1210_setup_gpios(st); if (ret < 0) return ret; diff --git a/drivers/staging/iio/resolver/ad2s1210.h b/drivers/staging/iio/resolver/ad2s1210.h deleted file mode 100644 index 63d479b20a6c..000000000000 --- a/drivers/staging/iio/resolver/ad2s1210.h +++ /dev/null @@ -1,17 +0,0 @@ -/* - * ad2s1210.h plaform data for the ADI Resolver to Digital Converters: - * AD2S1210 - * - * Copyright (c) 2010-2010 Analog Devices Inc. - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License version 2 as - * published by the Free Software Foundation. - */ -#ifndef _AD2S1210_H -#define _AD2S1210_H - -struct ad2s1210_platform_data { - bool gpioin; -}; -#endif /* _AD2S1210_H */ -- cgit v1.2.3 From 382c7fce7005b55f0583cf5905758d2b8def803a Mon Sep 17 00:00:00 2001 From: Nishad Kamdar Date: Wed, 31 Oct 2018 21:30:36 +0530 Subject: staging: iio: ad2s1210: Add device tree table. Add device tree table for matching vendor ID. Note that as the driver is still heavily in flux and there are some non obvious aspects to a comprehensive binding, that binding will be submitted at a later date (before leaving staging!) Signed-off-by: Nishad Kamdar Signed-off-by: Jonathan Cameron --- drivers/staging/iio/resolver/ad2s1210.c | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'drivers/staging/iio') diff --git a/drivers/staging/iio/resolver/ad2s1210.c b/drivers/staging/iio/resolver/ad2s1210.c index 235944189ab0..cec9d995b3df 100644 --- a/drivers/staging/iio/resolver/ad2s1210.c +++ b/drivers/staging/iio/resolver/ad2s1210.c @@ -699,6 +699,12 @@ static int ad2s1210_remove(struct spi_device *spi) return 0; } +static const struct of_device_id ad2s1210_of_match[] = { + { .compatible = "adi,ad2s1210", }, + { } +}; +MODULE_DEVICE_TABLE(of, ad2s1210_of_match); + static const struct spi_device_id ad2s1210_id[] = { { "ad2s1210" }, {} @@ -708,6 +714,7 @@ MODULE_DEVICE_TABLE(spi, ad2s1210_id); static struct spi_driver ad2s1210_driver = { .driver = { .name = DRV_NAME, + .of_match_table = of_match_ptr(ad2s1210_of_match), }, .probe = ad2s1210_probe, .remove = ad2s1210_remove, -- cgit v1.2.3 From 5ccc612b835b5e1560f913ec96ed6fdc7835892e Mon Sep 17 00:00:00 2001 From: Renato Lui Geh Date: Thu, 1 Nov 2018 11:43:02 -0300 Subject: staging: iio: ad7780: fix offset read value Variable val subtracted an uninitialized value on IIO_CHAN_INFO_OFFSET. This was fixed by assigning the correct value instead. Signed-off-by: Renato Lui Geh Acked-by: Alexandru Ardelean Signed-off-by: Jonathan Cameron --- drivers/staging/iio/adc/ad7780.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/staging/iio') diff --git a/drivers/staging/iio/adc/ad7780.c b/drivers/staging/iio/adc/ad7780.c index b67412db0318..91e016d534ed 100644 --- a/drivers/staging/iio/adc/ad7780.c +++ b/drivers/staging/iio/adc/ad7780.c @@ -96,7 +96,7 @@ static int ad7780_read_raw(struct iio_dev *indio_dev, *val2 = chan->scan_type.realbits - 1; return IIO_VAL_FRACTIONAL_LOG2; case IIO_CHAN_INFO_OFFSET: - *val -= (1 << (chan->scan_type.realbits - 1)); + *val = -(1 << (chan->scan_type.realbits - 1)); return IIO_VAL_INT; } -- cgit v1.2.3 From 070e8c7da116b81faf0026ecd281e92ad4917a81 Mon Sep 17 00:00:00 2001 From: Matheus Tavares Date: Sat, 3 Nov 2018 19:49:43 -0300 Subject: staging:iio:ad2s90: Make read_raw return spi_read's error code Previously, when spi_read returned an error code inside ad2s90_read_raw, the code was ignored and IIO_VAL_INT was returned. This patch makes the function return the error code returned by spi_read when it fails. Signed-off-by: Matheus Tavares Signed-off-by: Jonathan Cameron --- drivers/staging/iio/resolver/ad2s90.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'drivers/staging/iio') diff --git a/drivers/staging/iio/resolver/ad2s90.c b/drivers/staging/iio/resolver/ad2s90.c index 59586947a936..ba55de29ef36 100644 --- a/drivers/staging/iio/resolver/ad2s90.c +++ b/drivers/staging/iio/resolver/ad2s90.c @@ -36,11 +36,12 @@ static int ad2s90_read_raw(struct iio_dev *indio_dev, mutex_lock(&st->lock); ret = spi_read(st->sdev, st->rx, 2); - if (ret) - goto error_ret; + if (ret < 0) { + mutex_unlock(&st->lock); + return ret; + } *val = (((u16)(st->rx[0])) << 4) | ((st->rx[1] & 0xF0) >> 4); -error_ret: mutex_unlock(&st->lock); return IIO_VAL_INT; -- cgit v1.2.3 From b3a3eafeef769c6982e15f83631dcbf8d1794efb Mon Sep 17 00:00:00 2001 From: Matheus Tavares Date: Sat, 3 Nov 2018 19:49:44 -0300 Subject: staging:iio:ad2s90: Make probe handle spi_setup failure Previously, ad2s90_probe ignored the return code from spi_setup, not handling its possible failure. This patch makes ad2s90_probe check if the code is an error code and, if so, do the following: - Call dev_err with an appropriate error message. - Return the spi_setup's error code. Note: The 'return ret' statement could be out of the 'if' block, but this whole block will be moved up in the function in the patch: 'staging:iio:ad2s90: Move device registration to the end of probe'. Signed-off-by: Matheus Tavares Signed-off-by: Jonathan Cameron --- drivers/staging/iio/resolver/ad2s90.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'drivers/staging/iio') diff --git a/drivers/staging/iio/resolver/ad2s90.c b/drivers/staging/iio/resolver/ad2s90.c index ba55de29ef36..4908c8a95fad 100644 --- a/drivers/staging/iio/resolver/ad2s90.c +++ b/drivers/staging/iio/resolver/ad2s90.c @@ -86,7 +86,12 @@ static int ad2s90_probe(struct spi_device *spi) /* need 600ns between CS and the first falling edge of SCLK */ spi->max_speed_hz = 830000; spi->mode = SPI_MODE_3; - spi_setup(spi); + ret = spi_setup(spi); + + if (ret < 0) { + dev_err(&spi->dev, "spi_setup failed!\n"); + return ret; + } return 0; } -- cgit v1.2.3 From addb2ebe4a346b36cd7f4b12eeda1a0e2e92550a Mon Sep 17 00:00:00 2001 From: Matheus Tavares Date: Sat, 3 Nov 2018 19:49:45 -0300 Subject: staging:iio:ad2s90: Remove always overwritten assignment This patch removes an initial assignment to the variable ret at probe, that was always overwritten. Signed-off-by: Matheus Tavares Signed-off-by: Jonathan Cameron --- drivers/staging/iio/resolver/ad2s90.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'drivers/staging/iio') diff --git a/drivers/staging/iio/resolver/ad2s90.c b/drivers/staging/iio/resolver/ad2s90.c index 4908c8a95fad..54ad85bd9dc6 100644 --- a/drivers/staging/iio/resolver/ad2s90.c +++ b/drivers/staging/iio/resolver/ad2s90.c @@ -62,7 +62,7 @@ static int ad2s90_probe(struct spi_device *spi) { struct iio_dev *indio_dev; struct ad2s90_state *st; - int ret = 0; + int ret; indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); if (!indio_dev) -- cgit v1.2.3 From f14a283c2d58d9a86dab20ab2e0671f826042600 Mon Sep 17 00:00:00 2001 From: Matheus Tavares Date: Sat, 3 Nov 2018 19:49:46 -0300 Subject: staging:iio:ad2s90: Move device registration to the end of probe Previously, devm_iio_device_register was being called before the spi_setup call and the spi_device's max_speed_hz and mode assignments. This could lead to a race condition since the driver was still being set up after it was already made ready to use. To fix it, this patch moves the device registration to the end of ad2s90_probe. Signed-off-by: Matheus Tavares Signed-off-by: Jonathan Cameron --- drivers/staging/iio/resolver/ad2s90.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) (limited to 'drivers/staging/iio') diff --git a/drivers/staging/iio/resolver/ad2s90.c b/drivers/staging/iio/resolver/ad2s90.c index 54ad85bd9dc6..8f79cccf4814 100644 --- a/drivers/staging/iio/resolver/ad2s90.c +++ b/drivers/staging/iio/resolver/ad2s90.c @@ -79,10 +79,6 @@ static int ad2s90_probe(struct spi_device *spi) indio_dev->num_channels = 1; indio_dev->name = spi_get_device_id(spi)->name; - ret = devm_iio_device_register(indio_dev->dev.parent, indio_dev); - if (ret) - return ret; - /* need 600ns between CS and the first falling edge of SCLK */ spi->max_speed_hz = 830000; spi->mode = SPI_MODE_3; @@ -93,7 +89,7 @@ static int ad2s90_probe(struct spi_device *spi) return ret; } - return 0; + return devm_iio_device_register(indio_dev->dev.parent, indio_dev); } static const struct spi_device_id ad2s90_id[] = { -- cgit v1.2.3 From ccba40e9f76f65a755f8da00d4e00f49883c7d52 Mon Sep 17 00:00:00 2001 From: Victor Colombo Date: Sat, 3 Nov 2018 19:49:47 -0300 Subject: staging:iio:ad2s90: Add IIO_CHAN_INFO_SCALE to channel spec and read_raw This patch adds the IIO_CHAN_INFO_SCALE mask to ad2s90_chan and implements the relative read behavior at ad2s90_read_raw. Signed-off-by: Victor Colombo Signed-off-by: Matheus Tavares Signed-off-by: Jonathan Cameron --- drivers/staging/iio/resolver/ad2s90.c | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) (limited to 'drivers/staging/iio') diff --git a/drivers/staging/iio/resolver/ad2s90.c b/drivers/staging/iio/resolver/ad2s90.c index 8f79cccf4814..9c168b7410d0 100644 --- a/drivers/staging/iio/resolver/ad2s90.c +++ b/drivers/staging/iio/resolver/ad2s90.c @@ -34,17 +34,29 @@ static int ad2s90_read_raw(struct iio_dev *indio_dev, int ret; struct ad2s90_state *st = iio_priv(indio_dev); - mutex_lock(&st->lock); - ret = spi_read(st->sdev, st->rx, 2); - if (ret < 0) { + switch (m) { + case IIO_CHAN_INFO_SCALE: + /* 2 * Pi / 2^12 */ + *val = 6283; /* mV */ + *val2 = 12; + return IIO_VAL_FRACTIONAL_LOG2; + case IIO_CHAN_INFO_RAW: + mutex_lock(&st->lock); + ret = spi_read(st->sdev, st->rx, 2); + if (ret < 0) { + mutex_unlock(&st->lock); + return ret; + } + *val = (((u16)(st->rx[0])) << 4) | ((st->rx[1] & 0xF0) >> 4); + mutex_unlock(&st->lock); - return ret; - } - *val = (((u16)(st->rx[0])) << 4) | ((st->rx[1] & 0xF0) >> 4); - mutex_unlock(&st->lock); + return IIO_VAL_INT; + default: + break; + } - return IIO_VAL_INT; + return -EINVAL; } static const struct iio_info ad2s90_info = { @@ -55,7 +67,7 @@ static const struct iio_chan_spec ad2s90_chan = { .type = IIO_ANGL, .indexed = 1, .channel = 0, - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | BIT(IIO_CHAN_INFO_SCALE), }; static int ad2s90_probe(struct spi_device *spi) -- cgit v1.2.3 From addacf3b49ffc0ad0e8ec96697394fd2c2d0fcdb Mon Sep 17 00:00:00 2001 From: Matheus Tavares Date: Sat, 3 Nov 2018 19:49:48 -0300 Subject: staging:iio:ad2s90: Check channel type at read_raw This patch adds a channel type check at the beginning of the ad2s90_read_raw function. Since ad2s90 has only one channel, it just checks if the given channel is the expected one and if not, return -EINVAL. Signed-off-by: Matheus Tavares Signed-off-by: Jonathan Cameron --- drivers/staging/iio/resolver/ad2s90.c | 3 +++ 1 file changed, 3 insertions(+) (limited to 'drivers/staging/iio') diff --git a/drivers/staging/iio/resolver/ad2s90.c b/drivers/staging/iio/resolver/ad2s90.c index 9c168b7410d0..3e257ac46f7a 100644 --- a/drivers/staging/iio/resolver/ad2s90.c +++ b/drivers/staging/iio/resolver/ad2s90.c @@ -34,6 +34,9 @@ static int ad2s90_read_raw(struct iio_dev *indio_dev, int ret; struct ad2s90_state *st = iio_priv(indio_dev); + if (chan->type != IIO_ANGL) + return -EINVAL; + switch (m) { case IIO_CHAN_INFO_SCALE: /* 2 * Pi / 2^12 */ -- cgit v1.2.3 From 06c77f564ddb6a3f4a2553c02c36d62cc1a596f7 Mon Sep 17 00:00:00 2001 From: Nishad Kamdar Date: Fri, 9 Nov 2018 13:06:24 +0530 Subject: staging: iio: ad7816: Do not use busy_pin in case of AD7818 AD7818 does not support busy_pin functionality as per datasheet. Hence drop busy_pin when AD7818 is used. Signed-off-by: Nishad Kamdar Signed-off-by: Jonathan Cameron --- drivers/staging/iio/adc/ad7816.c | 35 ++++++++++++++++++++++++----------- 1 file changed, 24 insertions(+), 11 deletions(-) (limited to 'drivers/staging/iio') diff --git a/drivers/staging/iio/adc/ad7816.c b/drivers/staging/iio/adc/ad7816.c index 12c4e0ab4713..3cda5cd09365 100644 --- a/drivers/staging/iio/adc/ad7816.c +++ b/drivers/staging/iio/adc/ad7816.c @@ -43,6 +43,7 @@ */ struct ad7816_chip_info { + kernel_ulong_t id; struct spi_device *spi_dev; struct gpio_desc *rdwr_pin; struct gpio_desc *convert_pin; @@ -52,6 +53,12 @@ struct ad7816_chip_info { u8 mode; }; +enum ad7816_type { + ID_AD7816, + ID_AD7817, + ID_AD7818, +}; + /* * ad7816 data access by SPI */ @@ -78,8 +85,10 @@ static int ad7816_spi_read(struct ad7816_chip_info *chip, u16 *data) gpiod_set_value(chip->convert_pin, 1); } - while (gpiod_get_value(chip->busy_pin)) - cpu_relax(); + if (chip->id == ID_AD7816 || chip->id == ID_AD7817) { + while (gpiod_get_value(chip->busy_pin)) + cpu_relax(); + } gpiod_set_value(chip->rdwr_pin, 0); gpiod_set_value(chip->rdwr_pin, 1); @@ -359,6 +368,7 @@ static int ad7816_probe(struct spi_device *spi_dev) for (i = 0; i <= AD7816_CS_MAX; i++) chip->oti_data[i] = 203; + chip->id = spi_get_device_id(spi_dev)->driver_data; chip->rdwr_pin = devm_gpiod_get(&spi_dev->dev, "rdwr", GPIOD_IN); if (IS_ERR(chip->rdwr_pin)) { ret = PTR_ERR(chip->rdwr_pin); @@ -373,12 +383,15 @@ static int ad7816_probe(struct spi_device *spi_dev) ret); return ret; } - chip->busy_pin = devm_gpiod_get(&spi_dev->dev, "busy", GPIOD_IN); - if (IS_ERR(chip->busy_pin)) { - ret = PTR_ERR(chip->busy_pin); - dev_err(&spi_dev->dev, "Failed to request busy GPIO: %d\n", - ret); - return ret; + if (chip->id == ID_AD7816 || chip->id == ID_AD7817) { + chip->busy_pin = devm_gpiod_get(&spi_dev->dev, "busy", + GPIOD_IN); + if (IS_ERR(chip->busy_pin)) { + ret = PTR_ERR(chip->busy_pin); + dev_err(&spi_dev->dev, "Failed to request busy GPIO: %d\n", + ret); + return ret; + } } indio_dev->name = spi_get_device_id(spi_dev)->name; @@ -409,9 +422,9 @@ static int ad7816_probe(struct spi_device *spi_dev) } static const struct spi_device_id ad7816_id[] = { - { "ad7816", 0 }, - { "ad7817", 0 }, - { "ad7818", 0 }, + { "ad7816", ID_AD7816 }, + { "ad7817", ID_AD7817 }, + { "ad7818", ID_AD7818 }, {} }; -- cgit v1.2.3 From 72e3a5248da9046d17aec9366976a3ec45ceeb3c Mon Sep 17 00:00:00 2001 From: Nishad Kamdar Date: Fri, 9 Nov 2018 13:07:18 +0530 Subject: staging: iio: ad7816: Set RD/WR pin and CONVST pin as outputs. The RD/WR pin and CONVST pin are logical inputs to the AD78xx chip as per the datasheet. Hence convert them to outputs. Signed-off-by: Nishad Kamdar Signed-off-by: Jonathan Cameron --- drivers/staging/iio/adc/ad7816.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'drivers/staging/iio') diff --git a/drivers/staging/iio/adc/ad7816.c b/drivers/staging/iio/adc/ad7816.c index 3cda5cd09365..a2fead85cd46 100644 --- a/drivers/staging/iio/adc/ad7816.c +++ b/drivers/staging/iio/adc/ad7816.c @@ -369,14 +369,15 @@ static int ad7816_probe(struct spi_device *spi_dev) chip->oti_data[i] = 203; chip->id = spi_get_device_id(spi_dev)->driver_data; - chip->rdwr_pin = devm_gpiod_get(&spi_dev->dev, "rdwr", GPIOD_IN); + chip->rdwr_pin = devm_gpiod_get(&spi_dev->dev, "rdwr", GPIOD_OUT_HIGH); if (IS_ERR(chip->rdwr_pin)) { ret = PTR_ERR(chip->rdwr_pin); dev_err(&spi_dev->dev, "Failed to request rdwr GPIO: %d\n", ret); return ret; } - chip->convert_pin = devm_gpiod_get(&spi_dev->dev, "convert", GPIOD_IN); + chip->convert_pin = devm_gpiod_get(&spi_dev->dev, "convert", + GPIOD_OUT_HIGH); if (IS_ERR(chip->convert_pin)) { ret = PTR_ERR(chip->convert_pin); dev_err(&spi_dev->dev, "Failed to request convert GPIO: %d\n", -- cgit v1.2.3 From 23da6a15113e97043d37b2ac83d234cd43dc627b Mon Sep 17 00:00:00 2001 From: Giuliano Belinassi Date: Thu, 8 Nov 2018 11:03:20 -0200 Subject: staging: iio: ad7780: check if ad778x before gain update Only the ad778x have the 'gain' status bit. Check it before updating through a new variable is_ad778x in chip_info. Signed-off-by: Giuliano Belinassi Acked-by: Alexandru Ardelean Signed-off-by: Jonathan Cameron --- drivers/staging/iio/adc/ad7780.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) (limited to 'drivers/staging/iio') diff --git a/drivers/staging/iio/adc/ad7780.c b/drivers/staging/iio/adc/ad7780.c index 91e016d534ed..9ec2b002539e 100644 --- a/drivers/staging/iio/adc/ad7780.c +++ b/drivers/staging/iio/adc/ad7780.c @@ -35,6 +35,7 @@ struct ad7780_chip_info { struct iio_chan_spec channel; unsigned int pattern_mask; unsigned int pattern; + bool is_ad778x; }; struct ad7780_state { @@ -113,10 +114,12 @@ static int ad7780_postprocess_sample(struct ad_sigma_delta *sigma_delta, ((raw_sample & chip_info->pattern_mask) != chip_info->pattern)) return -EIO; - if (raw_sample & AD7780_GAIN) - st->gain = 1; - else - st->gain = 128; + if (chip_info->is_ad778x) { + if (raw_sample & AD7780_GAIN) + st->gain = 1; + else + st->gain = 128; + } return 0; } @@ -135,21 +138,25 @@ static const struct ad7780_chip_info ad7780_chip_info_tbl[] = { .channel = AD7780_CHANNEL(12, 24), .pattern = 0x5, .pattern_mask = 0x7, + .is_ad778x = false, }, [ID_AD7171] = { .channel = AD7780_CHANNEL(16, 24), .pattern = 0x5, .pattern_mask = 0x7, + .is_ad778x = false, }, [ID_AD7780] = { .channel = AD7780_CHANNEL(24, 32), .pattern = 0x1, .pattern_mask = 0x3, + .is_ad778x = true, }, [ID_AD7781] = { .channel = AD7780_CHANNEL(20, 32), .pattern = 0x1, .pattern_mask = 0x3, + .is_ad778x = true, }, }; -- cgit v1.2.3 From c036a324c03eed9a31a2733fa2ad4ae96840244e Mon Sep 17 00:00:00 2001 From: Giuliano Belinassi Date: Thu, 8 Nov 2018 11:03:40 -0200 Subject: staging: iio: ad7780: generates pattern_mask from PAT bits Previously, all pattern_masks and patterns in the chip_info table were hardcoded. Now they are generated using the PAT macros, as described in the datasheets. Signed-off-by: Giuliano Belinassi Signed-off-by: Jonathan Cameron --- drivers/staging/iio/adc/ad7780.c | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) (limited to 'drivers/staging/iio') diff --git a/drivers/staging/iio/adc/ad7780.c b/drivers/staging/iio/adc/ad7780.c index 9ec2b002539e..ff8e3b2d0efc 100644 --- a/drivers/staging/iio/adc/ad7780.c +++ b/drivers/staging/iio/adc/ad7780.c @@ -22,14 +22,22 @@ #include #include -#define AD7780_RDY BIT(7) -#define AD7780_FILTER BIT(6) -#define AD7780_ERR BIT(5) -#define AD7780_ID1 BIT(4) -#define AD7780_ID0 BIT(3) -#define AD7780_GAIN BIT(2) -#define AD7780_PAT1 BIT(1) -#define AD7780_PAT0 BIT(0) +#define AD7780_RDY BIT(7) +#define AD7780_FILTER BIT(6) +#define AD7780_ERR BIT(5) +#define AD7780_ID1 BIT(4) +#define AD7780_ID0 BIT(3) +#define AD7780_GAIN BIT(2) +#define AD7780_PAT1 BIT(1) +#define AD7780_PAT0 BIT(0) + +#define AD7780_PATTERN (AD7780_PAT0) +#define AD7780_PATTERN_MASK (AD7780_PAT0 | AD7780_PAT1) + +#define AD7170_PAT2 BIT(2) + +#define AD7170_PATTERN (AD7780_PAT0 | AD7170_PAT2) +#define AD7170_PATTERN_MASK (AD7780_PAT0 | AD7780_PAT1 | AD7170_PAT2) struct ad7780_chip_info { struct iio_chan_spec channel; @@ -136,26 +144,26 @@ static const struct ad_sigma_delta_info ad7780_sigma_delta_info = { static const struct ad7780_chip_info ad7780_chip_info_tbl[] = { [ID_AD7170] = { .channel = AD7780_CHANNEL(12, 24), - .pattern = 0x5, - .pattern_mask = 0x7, + .pattern = AD7170_PATTERN, + .pattern_mask = AD7170_PATTERN_MASK, .is_ad778x = false, }, [ID_AD7171] = { .channel = AD7780_CHANNEL(16, 24), - .pattern = 0x5, - .pattern_mask = 0x7, + .pattern = AD7170_PATTERN, + .pattern_mask = AD7170_PATTERN_MASK, .is_ad778x = false, }, [ID_AD7780] = { .channel = AD7780_CHANNEL(24, 32), - .pattern = 0x1, - .pattern_mask = 0x3, + .pattern = AD7780_PATTERN, + .pattern_mask = AD7780_PATTERN_MASK, .is_ad778x = true, }, [ID_AD7781] = { .channel = AD7780_CHANNEL(20, 32), - .pattern = 0x1, - .pattern_mask = 0x3, + .pattern = AD7780_PATTERN, + .pattern_mask = AD7780_PATTERN_MASK, .is_ad778x = true, }, }; -- cgit v1.2.3 From 336650c785b62c3bea7c8cf6061c933a90241f67 Mon Sep 17 00:00:00 2001 From: Renato Lui Geh Date: Mon, 5 Nov 2018 17:14:58 -0200 Subject: staging: iio: ad7780: update voltage on read The ad7780 driver previously did not read the correct device output, as it read an outdated value set at initialization. It now updates its voltage on read. Signed-off-by: Renato Lui Geh Acked-by: Alexandru Ardelean Signed-off-by: Jonathan Cameron --- drivers/staging/iio/adc/ad7780.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'drivers/staging/iio') diff --git a/drivers/staging/iio/adc/ad7780.c b/drivers/staging/iio/adc/ad7780.c index ff8e3b2d0efc..aa0521a309db 100644 --- a/drivers/staging/iio/adc/ad7780.c +++ b/drivers/staging/iio/adc/ad7780.c @@ -96,12 +96,16 @@ static int ad7780_read_raw(struct iio_dev *indio_dev, long m) { struct ad7780_state *st = iio_priv(indio_dev); + int voltage_uv; switch (m) { case IIO_CHAN_INFO_RAW: return ad_sigma_delta_single_conversion(indio_dev, chan, val); case IIO_CHAN_INFO_SCALE: - *val = st->int_vref_mv * st->gain; + voltage_uv = regulator_get_voltage(st->reg); + if (voltage_uv < 0) + return voltage_uv; + *val = (voltage_uv / 1000) * st->gain; *val2 = chan->scan_type.realbits - 1; return IIO_VAL_FRACTIONAL_LOG2; case IIO_CHAN_INFO_OFFSET: -- cgit v1.2.3 From befa9f6a3e1f00df0cff9d991650dc8d541fb730 Mon Sep 17 00:00:00 2001 From: Renato Lui Geh Date: Mon, 5 Nov 2018 17:16:14 -0200 Subject: staging: iio: ad7780: remove unnecessary stashed voltage value This patch removes the unnecessary field int_vref_mv in ad7780_state referring to the device's voltage. Signed-off-by: Renato Lui Geh Acked-by: Alexandru Ardelean Signed-off-by: Jonathan Cameron --- drivers/staging/iio/adc/ad7780.c | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) (limited to 'drivers/staging/iio') diff --git a/drivers/staging/iio/adc/ad7780.c b/drivers/staging/iio/adc/ad7780.c index aa0521a309db..c4a85789c2db 100644 --- a/drivers/staging/iio/adc/ad7780.c +++ b/drivers/staging/iio/adc/ad7780.c @@ -51,7 +51,6 @@ struct ad7780_state { struct regulator *reg; struct gpio_desc *powerdown_gpio; unsigned int gain; - u16 int_vref_mv; struct ad_sigma_delta sd; }; @@ -180,7 +179,7 @@ static int ad7780_probe(struct spi_device *spi) { struct ad7780_state *st; struct iio_dev *indio_dev; - int ret, voltage_uv = 0; + int ret; indio_dev = devm_iio_device_alloc(&spi->dev, sizeof(*st)); if (!indio_dev) @@ -200,16 +199,10 @@ static int ad7780_probe(struct spi_device *spi) dev_err(&spi->dev, "Failed to enable specified AVdd supply\n"); return ret; } - voltage_uv = regulator_get_voltage(st->reg); st->chip_info = &ad7780_chip_info_tbl[spi_get_device_id(spi)->driver_data]; - if (voltage_uv) - st->int_vref_mv = voltage_uv / 1000; - else - dev_warn(&spi->dev, "Reference voltage unspecified\n"); - spi_set_drvdata(spi, indio_dev); indio_dev->dev.parent = &spi->dev; -- cgit v1.2.3 From 9829f9e5415c17824f23aa6e1573829256c8c298 Mon Sep 17 00:00:00 2001 From: Slawomir Stepien Date: Sun, 11 Nov 2018 16:59:10 +0100 Subject: staging: iio: adc: ad7280a: power down the device on error in probe Power down the device if anything goes wrong after the SPI has been setup correctly in the probe function. Existing code that toggles the AD7280A_CTRL_LB_SWRST bit inside ad7280_chain_setup function is responsible for powering up the device. Signed-off-by: Slawomir Stepien Signed-off-by: Jonathan Cameron --- drivers/staging/iio/adc/ad7280a.c | 30 +++++++++++++++++++++--------- 1 file changed, 21 insertions(+), 9 deletions(-) (limited to 'drivers/staging/iio') diff --git a/drivers/staging/iio/adc/ad7280a.c b/drivers/staging/iio/adc/ad7280a.c index 89c2c2deca64..5de701eda08e 100644 --- a/drivers/staging/iio/adc/ad7280a.c +++ b/drivers/staging/iio/adc/ad7280a.c @@ -350,29 +350,38 @@ static int ad7280_chain_setup(struct ad7280_state *st) AD7280A_CTRL_LB_MUST_SET | st->ctrl_lb); if (ret) - return ret; + goto error_power_down; ret = ad7280_write(st, AD7280A_DEVADDR_MASTER, AD7280A_READ, 1, AD7280A_CONTROL_LB << 2); if (ret) - return ret; + goto error_power_down; for (n = 0; n <= AD7280A_MAX_CHAIN; n++) { ret = __ad7280_read32(st, &val); if (ret) - return ret; + goto error_power_down; if (val == 0) return n - 1; - if (ad7280_check_crc(st, val)) - return -EIO; + if (ad7280_check_crc(st, val)) { + ret = -EIO; + goto error_power_down; + } - if (n != ad7280a_devaddr(val >> 27)) - return -EIO; + if (n != ad7280a_devaddr(val >> 27)) { + ret = -EIO; + goto error_power_down; + } } + ret = -EFAULT; - return -EFAULT; +error_power_down: + ad7280_write(st, AD7280A_DEVADDR_MASTER, AD7280A_CONTROL_HB, 1, + AD7280A_CTRL_HB_PWRDN_SW | st->ctrl_hb); + + return ret; } static ssize_t ad7280_show_balance_sw(struct device *dev, @@ -892,7 +901,7 @@ static int ad7280_probe(struct spi_device *spi) ret = ad7280_channel_init(st); if (ret < 0) - return ret; + goto error_power_down; indio_dev->num_channels = ret; indio_dev->channels = st->channels; @@ -941,6 +950,9 @@ error_free_attr: error_free_channels: kfree(st->channels); +error_power_down: + ad7280_write(st, AD7280A_DEVADDR_MASTER, AD7280A_CONTROL_HB, 1, + AD7280A_CTRL_HB_PWRDN_SW | st->ctrl_hb); return ret; } -- cgit v1.2.3 From cc9c58ef6e0623f92edc2988c8a8ebfb63b40cea Mon Sep 17 00:00:00 2001 From: Slawomir Stepien Date: Sun, 11 Nov 2018 16:59:11 +0100 Subject: staging: iio: adc: ad7280a: use devm_* APIs devm_* APIs are device managed and make code simpler. Signed-off-by: Slawomir Stepien Signed-off-by: Jonathan Cameron --- drivers/staging/iio/adc/ad7280a.c | 100 +++++++++++++++----------------------- 1 file changed, 40 insertions(+), 60 deletions(-) (limited to 'drivers/staging/iio') diff --git a/drivers/staging/iio/adc/ad7280a.c b/drivers/staging/iio/adc/ad7280a.c index 5de701eda08e..0bb9ab174f2a 100644 --- a/drivers/staging/iio/adc/ad7280a.c +++ b/drivers/staging/iio/adc/ad7280a.c @@ -330,6 +330,14 @@ static int ad7280_read_all_channels(struct ad7280_state *st, unsigned int cnt, return sum; } +static void ad7280_sw_power_down(void *data) +{ + struct ad7280_state *st = data; + + ad7280_write(st, AD7280A_DEVADDR_MASTER, AD7280A_CONTROL_HB, 1, + AD7280A_CTRL_HB_PWRDN_SW | st->ctrl_hb); +} + static int ad7280_chain_setup(struct ad7280_state *st) { unsigned int val, n; @@ -492,8 +500,8 @@ static int ad7280_channel_init(struct ad7280_state *st) { int dev, ch, cnt; - st->channels = kcalloc((st->slave_num + 1) * 12 + 2, - sizeof(*st->channels), GFP_KERNEL); + st->channels = devm_kcalloc(&st->spi->dev, (st->slave_num + 1) * 12 + 2, + sizeof(*st->channels), GFP_KERNEL); if (!st->channels) return -ENOMEM; @@ -552,16 +560,18 @@ static int ad7280_channel_init(struct ad7280_state *st) static int ad7280_attr_init(struct ad7280_state *st) { int dev, ch, cnt; + unsigned int index; - st->iio_attr = kcalloc(2, sizeof(*st->iio_attr) * - (st->slave_num + 1) * AD7280A_CELLS_PER_DEV, - GFP_KERNEL); + st->iio_attr = devm_kcalloc(&st->spi->dev, 2, sizeof(*st->iio_attr) * + (st->slave_num + 1) * AD7280A_CELLS_PER_DEV, + GFP_KERNEL); if (!st->iio_attr) return -ENOMEM; for (dev = 0, cnt = 0; dev <= st->slave_num; dev++) for (ch = AD7280A_CELL_VOLTAGE_1; ch <= AD7280A_CELL_VOLTAGE_6; ch++, cnt++) { + index = dev * AD7280A_CELLS_PER_DEV + ch; st->iio_attr[cnt].address = ad7280a_devaddr(dev) << 8 | ch; st->iio_attr[cnt].dev_attr.attr.mode = @@ -571,10 +581,9 @@ static int ad7280_attr_init(struct ad7280_state *st) st->iio_attr[cnt].dev_attr.store = ad7280_store_balance_sw; st->iio_attr[cnt].dev_attr.attr.name = - kasprintf(GFP_KERNEL, - "in%d-in%d_balance_switch_en", - dev * AD7280A_CELLS_PER_DEV + ch, - dev * AD7280A_CELLS_PER_DEV + ch + 1); + devm_kasprintf(&st->spi->dev, GFP_KERNEL, + "in%d-in%d_balance_switch_en", + index, index + 1); ad7280_attributes[cnt] = &st->iio_attr[cnt].dev_attr.attr; cnt++; @@ -588,10 +597,9 @@ static int ad7280_attr_init(struct ad7280_state *st) st->iio_attr[cnt].dev_attr.store = ad7280_store_balance_timer; st->iio_attr[cnt].dev_attr.attr.name = - kasprintf(GFP_KERNEL, - "in%d-in%d_balance_timer", - dev * AD7280A_CELLS_PER_DEV + ch, - dev * AD7280A_CELLS_PER_DEV + ch + 1); + devm_kasprintf(&st->spi->dev, GFP_KERNEL, + "in%d-in%d_balance_timer", + index, index + 1); ad7280_attributes[cnt] = &st->iio_attr[cnt].dev_attr.attr; } @@ -872,6 +880,10 @@ static int ad7280_probe(struct spi_device *spi) if (ret < 0) return ret; + ret = devm_add_action_or_reset(&spi->dev, ad7280_sw_power_down, st); + if (ret) + return ret; + st->slave_num = ret; st->scan_cnt = (st->slave_num + 1) * AD7280A_NUM_CH; st->cell_threshhigh = 0xFF; @@ -901,7 +913,7 @@ static int ad7280_probe(struct spi_device *spi) ret = ad7280_channel_init(st); if (ret < 0) - goto error_power_down; + return ret; indio_dev->num_channels = ret; indio_dev->channels = st->channels; @@ -909,68 +921,37 @@ static int ad7280_probe(struct spi_device *spi) ret = ad7280_attr_init(st); if (ret < 0) - goto error_free_channels; + return ret; - ret = iio_device_register(indio_dev); + ret = devm_iio_device_register(&spi->dev, indio_dev); if (ret) - goto error_free_attr; + return ret; if (spi->irq > 0) { ret = ad7280_write(st, AD7280A_DEVADDR_MASTER, AD7280A_ALERT, 1, AD7280A_ALERT_RELAY_SIG_CHAIN_DOWN); if (ret) - goto error_unregister; + return ret; ret = ad7280_write(st, ad7280a_devaddr(st->slave_num), AD7280A_ALERT, 0, AD7280A_ALERT_GEN_STATIC_HIGH | (pdata->chain_last_alert_ignore & 0xF)); if (ret) - goto error_unregister; - - ret = request_threaded_irq(spi->irq, - NULL, - ad7280_event_handler, - IRQF_TRIGGER_FALLING | - IRQF_ONESHOT, - indio_dev->name, - indio_dev); + return ret; + + ret = devm_request_threaded_irq(&spi->dev, spi->irq, + NULL, + ad7280_event_handler, + IRQF_TRIGGER_FALLING | + IRQF_ONESHOT, + indio_dev->name, + indio_dev); if (ret) - goto error_unregister; + return ret; } - return 0; -error_unregister: - iio_device_unregister(indio_dev); - -error_free_attr: - kfree(st->iio_attr); - -error_free_channels: - kfree(st->channels); - -error_power_down: - ad7280_write(st, AD7280A_DEVADDR_MASTER, AD7280A_CONTROL_HB, 1, - AD7280A_CTRL_HB_PWRDN_SW | st->ctrl_hb); - return ret; -} - -static int ad7280_remove(struct spi_device *spi) -{ - struct iio_dev *indio_dev = spi_get_drvdata(spi); - struct ad7280_state *st = iio_priv(indio_dev); - - if (spi->irq > 0) - free_irq(spi->irq, indio_dev); - iio_device_unregister(indio_dev); - - ad7280_write(st, AD7280A_DEVADDR_MASTER, AD7280A_CONTROL_HB, 1, - AD7280A_CTRL_HB_PWRDN_SW | st->ctrl_hb); - - kfree(st->channels); - kfree(st->iio_attr); - return 0; } @@ -985,7 +966,6 @@ static struct spi_driver ad7280_driver = { .name = "ad7280", }, .probe = ad7280_probe, - .remove = ad7280_remove, .id_table = ad7280_id, }; module_spi_driver(ad7280_driver); -- cgit v1.2.3 From c24a4173f6bbea49b09ae2c137db23035d3a7932 Mon Sep 17 00:00:00 2001 From: Nishad Kamdar Date: Wed, 14 Nov 2018 23:16:14 +0530 Subject: staging: iio: ad7816: Add device tree table. Add device tree table for matching vendor ID. Signed-off-by: Nishad Kamdar Signed-off-by: Jonathan Cameron --- drivers/staging/iio/adc/ad7816.c | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'drivers/staging/iio') diff --git a/drivers/staging/iio/adc/ad7816.c b/drivers/staging/iio/adc/ad7816.c index a2fead85cd46..5209651a1b25 100644 --- a/drivers/staging/iio/adc/ad7816.c +++ b/drivers/staging/iio/adc/ad7816.c @@ -422,6 +422,14 @@ static int ad7816_probe(struct spi_device *spi_dev) return 0; } +static const struct of_device_id ad7816_of_match[] = { + { .compatible = "adi,ad7816", }, + { .compatible = "adi,ad7817", }, + { .compatible = "adi,ad7818", }, + { } +}; +MODULE_DEVICE_TABLE(of, ad7816_of_match); + static const struct spi_device_id ad7816_id[] = { { "ad7816", ID_AD7816 }, { "ad7817", ID_AD7817 }, @@ -434,6 +442,7 @@ MODULE_DEVICE_TABLE(spi, ad7816_id); static struct spi_driver ad7816_driver = { .driver = { .name = "ad7816", + .of_match_table = ad7816_of_match, }, .probe = ad7816_probe, .id_table = ad7816_id, -- cgit v1.2.3 From 688cd642ba0c393344c802647848da5f0d925d0e Mon Sep 17 00:00:00 2001 From: Shreeya Patel Date: Sat, 17 Nov 2018 04:19:07 +0530 Subject: Staging: iio: adt7316: Fix i2c data reading, set the data field adt7316_i2c_read function nowhere sets the data field. It is necessary to have an appropriate value for it. Hence, assign the value stored in 'ret' variable to data field. This is an ancient bug, and as no one seems to have noticed, probably no sense in applying it to stable. Signed-off-by: Shreeya Patel Signed-off-by: Jonathan Cameron --- drivers/staging/iio/addac/adt7316-i2c.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'drivers/staging/iio') diff --git a/drivers/staging/iio/addac/adt7316-i2c.c b/drivers/staging/iio/addac/adt7316-i2c.c index f66dd3ebbab1..856bcfa60c6c 100644 --- a/drivers/staging/iio/addac/adt7316-i2c.c +++ b/drivers/staging/iio/addac/adt7316-i2c.c @@ -35,6 +35,8 @@ static int adt7316_i2c_read(void *client, u8 reg, u8 *data) return ret; } + *data = ret; + return 0; } -- cgit v1.2.3 From 00426e99789357dbff7e719a092ce36a3ce49d94 Mon Sep 17 00:00:00 2001 From: Shreeya Patel Date: Sat, 17 Nov 2018 04:21:32 +0530 Subject: Staging: iio: adt7316: Add an extra check for 'ret' equals to 0 ret = 0 indicates a case of no error but no data read from the bus which is an invalid case. This case doesn't ever happen in reality. It should perhaps be handled for correctness though. Signed-off-by: Shreeya Patel Signed-off-by: Jonathan Cameron --- drivers/staging/iio/addac/adt7316-i2c.c | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'drivers/staging/iio') diff --git a/drivers/staging/iio/addac/adt7316-i2c.c b/drivers/staging/iio/addac/adt7316-i2c.c index 856bcfa60c6c..473e5e34ec00 100644 --- a/drivers/staging/iio/addac/adt7316-i2c.c +++ b/drivers/staging/iio/addac/adt7316-i2c.c @@ -30,6 +30,10 @@ static int adt7316_i2c_read(void *client, u8 reg, u8 *data) } ret = i2c_smbus_read_byte(client); + + if (!ret) + return -EIO; + if (ret < 0) { dev_err(&cl->dev, "I2C read error\n"); return ret; -- cgit v1.2.3