Skip to content

Commit 6d923f8

Browse files
committed
Merge tag 'iio-fixes-5.0a' of git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio into staging-linus
Jonathan writes: First set of IIO fixes for the 5.0 cycle. Been a busy month, so these are rather later than they should have been. * atlas-ph-sensor: - Temperature scale didn't correspond to the ABI. * axp288: - A few different fixes around the TS-pin handling. * ti-ads8688 - Not enough space in the buffer used to build the scan to allow for the timestamp. * tools - iio_generic_buffer - Make num_loops signed so that we really are running for ever rather than just a long time when we specify -1. * tag 'iio-fixes-5.0a' of git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio: iio: ti-ads8688: Update buffer allocation for timestamps tools: iio: iio_generic_buffer: make num_loops signed iio: adc: axp288: Fix TS-pin handling iio: chemical: atlas-ph-sensor: correct IIO_TEMP values to millicelsius
2 parents 798badf + f214ff5 commit 6d923f8

File tree

4 files changed

+66
-22
lines changed

4 files changed

+66
-22
lines changed

drivers/iio/adc/axp288_adc.c

Lines changed: 60 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,18 @@
2727
#include <linux/iio/machine.h>
2828
#include <linux/iio/driver.h>
2929

30-
#define AXP288_ADC_EN_MASK 0xF1
31-
#define AXP288_ADC_TS_PIN_GPADC 0xF2
32-
#define AXP288_ADC_TS_PIN_ON 0xF3
30+
/*
31+
* This mask enables all ADCs except for the battery temp-sensor (TS), that is
32+
* left as-is to avoid breaking charging on devices without a temp-sensor.
33+
*/
34+
#define AXP288_ADC_EN_MASK 0xF0
35+
#define AXP288_ADC_TS_ENABLE 0x01
36+
37+
#define AXP288_ADC_TS_CURRENT_ON_OFF_MASK GENMASK(1, 0)
38+
#define AXP288_ADC_TS_CURRENT_OFF (0 << 0)
39+
#define AXP288_ADC_TS_CURRENT_ON_WHEN_CHARGING (1 << 0)
40+
#define AXP288_ADC_TS_CURRENT_ON_ONDEMAND (2 << 0)
41+
#define AXP288_ADC_TS_CURRENT_ON (3 << 0)
3342

3443
enum axp288_adc_id {
3544
AXP288_ADC_TS,
@@ -44,6 +53,7 @@ enum axp288_adc_id {
4453
struct axp288_adc_info {
4554
int irq;
4655
struct regmap *regmap;
56+
bool ts_enabled;
4757
};
4858

4959
static const struct iio_chan_spec axp288_adc_channels[] = {
@@ -115,21 +125,33 @@ static int axp288_adc_read_channel(int *val, unsigned long address,
115125
return IIO_VAL_INT;
116126
}
117127

118-
static int axp288_adc_set_ts(struct regmap *regmap, unsigned int mode,
119-
unsigned long address)
128+
/*
129+
* The current-source used for the battery temp-sensor (TS) is shared
130+
* with the GPADC. For proper fuel-gauge and charger operation the TS
131+
* current-source needs to be permanently on. But to read the GPADC we
132+
* need to temporary switch the TS current-source to ondemand, so that
133+
* the GPADC can use it, otherwise we will always read an all 0 value.
134+
*/
135+
static int axp288_adc_set_ts(struct axp288_adc_info *info,
136+
unsigned int mode, unsigned long address)
120137
{
121138
int ret;
122139

123-
/* channels other than GPADC do not need to switch TS pin */
140+
/* No need to switch the current-source if the TS pin is disabled */
141+
if (!info->ts_enabled)
142+
return 0;
143+
144+
/* Channels other than GPADC do not need the current source */
124145
if (address != AXP288_GP_ADC_H)
125146
return 0;
126147

127-
ret = regmap_write(regmap, AXP288_ADC_TS_PIN_CTRL, mode);
148+
ret = regmap_update_bits(info->regmap, AXP288_ADC_TS_PIN_CTRL,
149+
AXP288_ADC_TS_CURRENT_ON_OFF_MASK, mode);
128150
if (ret)
129151
return ret;
130152

131153
/* When switching to the GPADC pin give things some time to settle */
132-
if (mode == AXP288_ADC_TS_PIN_GPADC)
154+
if (mode == AXP288_ADC_TS_CURRENT_ON_ONDEMAND)
133155
usleep_range(6000, 10000);
134156

135157
return 0;
@@ -145,14 +167,14 @@ static int axp288_adc_read_raw(struct iio_dev *indio_dev,
145167
mutex_lock(&indio_dev->mlock);
146168
switch (mask) {
147169
case IIO_CHAN_INFO_RAW:
148-
if (axp288_adc_set_ts(info->regmap, AXP288_ADC_TS_PIN_GPADC,
170+
if (axp288_adc_set_ts(info, AXP288_ADC_TS_CURRENT_ON_ONDEMAND,
149171
chan->address)) {
150172
dev_err(&indio_dev->dev, "GPADC mode\n");
151173
ret = -EINVAL;
152174
break;
153175
}
154176
ret = axp288_adc_read_channel(val, chan->address, info->regmap);
155-
if (axp288_adc_set_ts(info->regmap, AXP288_ADC_TS_PIN_ON,
177+
if (axp288_adc_set_ts(info, AXP288_ADC_TS_CURRENT_ON,
156178
chan->address))
157179
dev_err(&indio_dev->dev, "TS pin restore\n");
158180
break;
@@ -164,13 +186,35 @@ static int axp288_adc_read_raw(struct iio_dev *indio_dev,
164186
return ret;
165187
}
166188

167-
static int axp288_adc_set_state(struct regmap *regmap)
189+
static int axp288_adc_initialize(struct axp288_adc_info *info)
168190
{
169-
/* ADC should be always enabled for internal FG to function */
170-
if (regmap_write(regmap, AXP288_ADC_TS_PIN_CTRL, AXP288_ADC_TS_PIN_ON))
171-
return -EIO;
191+
int ret, adc_enable_val;
192+
193+
/*
194+
* Determine if the TS pin is enabled and set the TS current-source
195+
* accordingly.
196+
*/
197+
ret = regmap_read(info->regmap, AXP20X_ADC_EN1, &adc_enable_val);
198+
if (ret)
199+
return ret;
200+
201+
if (adc_enable_val & AXP288_ADC_TS_ENABLE) {
202+
info->ts_enabled = true;
203+
ret = regmap_update_bits(info->regmap, AXP288_ADC_TS_PIN_CTRL,
204+
AXP288_ADC_TS_CURRENT_ON_OFF_MASK,
205+
AXP288_ADC_TS_CURRENT_ON);
206+
} else {
207+
info->ts_enabled = false;
208+
ret = regmap_update_bits(info->regmap, AXP288_ADC_TS_PIN_CTRL,
209+
AXP288_ADC_TS_CURRENT_ON_OFF_MASK,
210+
AXP288_ADC_TS_CURRENT_OFF);
211+
}
212+
if (ret)
213+
return ret;
172214

173-
return regmap_write(regmap, AXP20X_ADC_EN1, AXP288_ADC_EN_MASK);
215+
/* Turn on the ADC for all channels except TS, leave TS as is */
216+
return regmap_update_bits(info->regmap, AXP20X_ADC_EN1,
217+
AXP288_ADC_EN_MASK, AXP288_ADC_EN_MASK);
174218
}
175219

176220
static const struct iio_info axp288_adc_iio_info = {
@@ -200,7 +244,7 @@ static int axp288_adc_probe(struct platform_device *pdev)
200244
* Set ADC to enabled state at all time, including system suspend.
201245
* otherwise internal fuel gauge functionality may be affected.
202246
*/
203-
ret = axp288_adc_set_state(axp20x->regmap);
247+
ret = axp288_adc_initialize(info);
204248
if (ret) {
205249
dev_err(&pdev->dev, "unable to enable ADC device\n");
206250
return ret;

drivers/iio/adc/ti-ads8688.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141

4242
#define ADS8688_VREF_MV 4096
4343
#define ADS8688_REALBITS 16
44+
#define ADS8688_MAX_CHANNELS 8
4445

4546
/*
4647
* enum ads8688_range - ADS8688 reference voltage range
@@ -385,7 +386,7 @@ static irqreturn_t ads8688_trigger_handler(int irq, void *p)
385386
{
386387
struct iio_poll_func *pf = p;
387388
struct iio_dev *indio_dev = pf->indio_dev;
388-
u16 buffer[8];
389+
u16 buffer[ADS8688_MAX_CHANNELS + sizeof(s64)/sizeof(u16)];
389390
int i, j = 0;
390391

391392
for (i = 0; i < indio_dev->masklength; i++) {

drivers/iio/chemical/atlas-ph-sensor.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -444,9 +444,8 @@ static int atlas_read_raw(struct iio_dev *indio_dev,
444444
case IIO_CHAN_INFO_SCALE:
445445
switch (chan->type) {
446446
case IIO_TEMP:
447-
*val = 1; /* 0.01 */
448-
*val2 = 100;
449-
break;
447+
*val = 10;
448+
return IIO_VAL_INT;
450449
case IIO_PH:
451450
*val = 1; /* 0.001 */
452451
*val2 = 1000;
@@ -477,7 +476,7 @@ static int atlas_write_raw(struct iio_dev *indio_dev,
477476
int val, int val2, long mask)
478477
{
479478
struct atlas_data *data = iio_priv(indio_dev);
480-
__be32 reg = cpu_to_be32(val);
479+
__be32 reg = cpu_to_be32(val / 10);
481480

482481
if (val2 != 0 || val < 0 || val > 20000)
483482
return -EINVAL;

tools/iio/iio_generic_buffer.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ static const struct option longopts[] = {
330330

331331
int main(int argc, char **argv)
332332
{
333-
unsigned long long num_loops = 2;
333+
long long num_loops = 2;
334334
unsigned long timedelay = 1000000;
335335
unsigned long buf_len = 128;
336336

0 commit comments

Comments
 (0)