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

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

Merge tag 'iio-fixes-for-4.1a-take2' of...

Merge tag 'iio-fixes-for-4.1a-take2' of git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio into staging-linus

Jonathan writes:

The usual mixed bag of fixes for IIO in the 4.1 cycle.

Second version of this pull request as a small fix to a fix turned
up before Greg pulled it for a cc10001 patch near the top of the tree.

One core fix

* Set updated for a iio kfifo was incorrectly set to false during a failed
  update, resulting in atttempts to repeat the failed operation appearing
  to succeed.

This time I've decided to list the driver fixes in alphabetical order rather
than 'randomly'.

* axp288_adc - a recent change added a check for valid info masks when
  reading channels from consumer drivers.
* bmp280 - temperature compensation was failing to read the tfine value, hence
  causing a temperature of 0 to always be returned and incorrect presure
  measurements.
* cc10001 - Fix channel number mapping when some channels are reserved for
  remote CPUs. Fix an issue with the use of the power-up/power-down register
  (basically wrong polarity). Fix an issue due to the missinterpretting the
  return value from regulator_get_voltage. Add a delay before the start bit
  as recommended for the hardware to avoid data corruption.
* hid pressure - fix channel spec of modfiied, but no modifier (which makes no
  sense!)
* hid proximity - fix channel spec of modified, but no modifier (which makes
  no sense!). Fix a memory leak in the probe function.
* mcp320x - occasional incorrect readings on dma using spi busses due to
  cacheline corruption. Fixed by forcing ___cacheline_aligned for the buffers.
* mma9551 - buffer overrun fix (miss specified maximum length of buffers)
* mma9553 - endian fix on status message. Add an enable element for activity
  channel. Input checking for activity period to avoid rather unpredictable
  results.
* spmi-vadc - fix an overflow in the output value normalization seen on some
  boards.
* st-snesors - oops due to use of a mutex that is not yet initialized during
  probe.
* xilinx adc - Some wrong register addresses, a wrong address for vccaux
  channel, incorrect scale on VREFP and incorrect sign on VREFN.
parents 892c89d5 f0828ba9
Loading
Loading
Loading
Loading
+18 −3
Original line number Diff line number Diff line
@@ -389,7 +389,12 @@ int mma9551_read_config_words(struct i2c_client *client, u8 app_id,
{
	int ret, i;
	int len_words = len / sizeof(u16);
	__be16 be_buf[MMA9551_MAX_MAILBOX_DATA_REGS];
	__be16 be_buf[MMA9551_MAX_MAILBOX_DATA_REGS / 2];

	if (len_words > ARRAY_SIZE(be_buf)) {
		dev_err(&client->dev, "Invalid buffer size %d\n", len);
		return -EINVAL;
	}

	ret = mma9551_transfer(client, app_id, MMA9551_CMD_READ_CONFIG,
			       reg, NULL, 0, (u8 *) be_buf, len);
@@ -424,7 +429,12 @@ int mma9551_read_status_words(struct i2c_client *client, u8 app_id,
{
	int ret, i;
	int len_words = len / sizeof(u16);
	__be16 be_buf[MMA9551_MAX_MAILBOX_DATA_REGS];
	__be16 be_buf[MMA9551_MAX_MAILBOX_DATA_REGS / 2];

	if (len_words > ARRAY_SIZE(be_buf)) {
		dev_err(&client->dev, "Invalid buffer size %d\n", len);
		return -EINVAL;
	}

	ret = mma9551_transfer(client, app_id, MMA9551_CMD_READ_STATUS,
			       reg, NULL, 0, (u8 *) be_buf, len);
@@ -459,7 +469,12 @@ int mma9551_write_config_words(struct i2c_client *client, u8 app_id,
{
	int i;
	int len_words = len / sizeof(u16);
	__be16 be_buf[MMA9551_MAX_MAILBOX_DATA_REGS];
	__be16 be_buf[(MMA9551_MAX_MAILBOX_DATA_REGS - 1) / 2];

	if (len_words > ARRAY_SIZE(be_buf)) {
		dev_err(&client->dev, "Invalid buffer size %d\n", len);
		return -EINVAL;
	}

	for (i = 0; i < len_words; i++)
		be_buf[i] = cpu_to_be16(buf[i]);
+10 −8
Original line number Diff line number Diff line
@@ -54,6 +54,7 @@
#define MMA9553_MASK_CONF_STEPCOALESCE		GENMASK(7, 0)

#define MMA9553_REG_CONF_ACTTHD			0x0E
#define MMA9553_MAX_ACTTHD			GENMASK(15, 0)

/* Pedometer status registers (R-only) */
#define MMA9553_REG_STATUS			0x00
@@ -316,22 +317,19 @@ static int mma9553_set_config(struct mma9553_data *data, u16 reg,
static int mma9553_read_activity_stepcnt(struct mma9553_data *data,
					 u8 *activity, u16 *stepcnt)
{
	u32 status_stepcnt;
	u16 status;
	u16 buf[2];
	int ret;

	ret = mma9551_read_status_words(data->client, MMA9551_APPID_PEDOMETER,
					MMA9553_REG_STATUS, sizeof(u32),
					(u16 *) &status_stepcnt);
					MMA9553_REG_STATUS, sizeof(u32), buf);
	if (ret < 0) {
		dev_err(&data->client->dev,
			"error reading status and stepcnt\n");
		return ret;
	}

	status = status_stepcnt & MMA9553_MASK_CONF_WORD;
	*activity = mma9553_get_bits(status, MMA9553_MASK_STATUS_ACTIVITY);
	*stepcnt = status_stepcnt >> 16;
	*activity = mma9553_get_bits(buf[0], MMA9553_MASK_STATUS_ACTIVITY);
	*stepcnt = buf[1];

	return 0;
}
@@ -872,6 +870,9 @@ static int mma9553_write_event_value(struct iio_dev *indio_dev,
	case IIO_EV_INFO_PERIOD:
		switch (chan->type) {
		case IIO_ACTIVITY:
			if (val < 0 || val > MMA9553_ACTIVITY_THD_TO_SEC(
			    MMA9553_MAX_ACTTHD))
				return -EINVAL;
			mutex_lock(&data->mutex);
			ret = mma9553_set_config(data, MMA9553_REG_CONF_ACTTHD,
						 &data->conf.actthd,
@@ -971,7 +972,8 @@ static const struct iio_chan_spec_ext_info mma9553_ext_info[] = {
	.modified = 1,							\
	.channel2 = _chan2,						\
	.info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),		\
	.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_CALIBHEIGHT),	\
	.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_CALIBHEIGHT) |	\
				    BIT(IIO_CHAN_INFO_ENABLE),		\
	.event_spec = mma9553_activity_events,				\
	.num_event_specs = ARRAY_SIZE(mma9553_activity_events),		\
	.ext_info = mma9553_ext_info,					\
+1 −0
Original line number Diff line number Diff line
@@ -546,6 +546,7 @@ int st_accel_common_probe(struct iio_dev *indio_dev)

	indio_dev->modes = INDIO_DIRECT_MODE;
	indio_dev->info = &accel_info;
	mutex_init(&adata->tb.buf_lock);

	st_sensors_power_enable(indio_dev);

+6 −6
Original line number Diff line number Diff line
@@ -53,39 +53,42 @@ static const struct iio_chan_spec const axp288_adc_channels[] = {
		.channel = 0,
		.address = AXP288_TS_ADC_H,
		.datasheet_name = "TS_PIN",
		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
	}, {
		.indexed = 1,
		.type = IIO_TEMP,
		.channel = 1,
		.address = AXP288_PMIC_ADC_H,
		.datasheet_name = "PMIC_TEMP",
		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
	}, {
		.indexed = 1,
		.type = IIO_TEMP,
		.channel = 2,
		.address = AXP288_GP_ADC_H,
		.datasheet_name = "GPADC",
		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
	}, {
		.indexed = 1,
		.type = IIO_CURRENT,
		.channel = 3,
		.address = AXP20X_BATT_CHRG_I_H,
		.datasheet_name = "BATT_CHG_I",
		.info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
	}, {
		.indexed = 1,
		.type = IIO_CURRENT,
		.channel = 4,
		.address = AXP20X_BATT_DISCHRG_I_H,
		.datasheet_name = "BATT_DISCHRG_I",
		.info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
	}, {
		.indexed = 1,
		.type = IIO_VOLTAGE,
		.channel = 5,
		.address = AXP20X_BATT_V_H,
		.datasheet_name = "BATT_V",
		.info_mask_separate = BIT(IIO_CHAN_INFO_PROCESSED),
		.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
	},
};

@@ -151,9 +154,6 @@ static int axp288_adc_read_raw(struct iio_dev *indio_dev,
						chan->address))
			dev_err(&indio_dev->dev, "TS pin restore\n");
		break;
	case IIO_CHAN_INFO_PROCESSED:
		ret = axp288_adc_read_channel(val, chan->address, info->regmap);
		break;
	default:
		ret = -EINVAL;
	}
+34 −26
Original line number Diff line number Diff line
@@ -35,8 +35,9 @@
#define CC10001_ADC_EOC_SET		BIT(0)

#define CC10001_ADC_CHSEL_SAMPLED	0x0c
#define CC10001_ADC_POWER_UP		0x10
#define CC10001_ADC_POWER_UP_SET	BIT(0)
#define CC10001_ADC_POWER_DOWN		0x10
#define CC10001_ADC_POWER_DOWN_SET	BIT(0)

#define CC10001_ADC_DEBUG		0x14
#define CC10001_ADC_DATA_COUNT		0x20

@@ -62,7 +63,6 @@ struct cc10001_adc_device {
	u16 *buf;

	struct mutex lock;
	unsigned long channel_map;
	unsigned int start_delay_ns;
	unsigned int eoc_delay_ns;
};
@@ -79,6 +79,18 @@ static inline u32 cc10001_adc_read_reg(struct cc10001_adc_device *adc_dev,
	return readl(adc_dev->reg_base + reg);
}

static void cc10001_adc_power_up(struct cc10001_adc_device *adc_dev)
{
	cc10001_adc_write_reg(adc_dev, CC10001_ADC_POWER_DOWN, 0);
	ndelay(adc_dev->start_delay_ns);
}

static void cc10001_adc_power_down(struct cc10001_adc_device *adc_dev)
{
	cc10001_adc_write_reg(adc_dev, CC10001_ADC_POWER_DOWN,
			      CC10001_ADC_POWER_DOWN_SET);
}

static void cc10001_adc_start(struct cc10001_adc_device *adc_dev,
			      unsigned int channel)
{
@@ -88,6 +100,7 @@ static void cc10001_adc_start(struct cc10001_adc_device *adc_dev,
	val = (channel & CC10001_ADC_CH_MASK) | CC10001_ADC_MODE_SINGLE_CONV;
	cc10001_adc_write_reg(adc_dev, CC10001_ADC_CONFIG, val);

	udelay(1);
	val = cc10001_adc_read_reg(adc_dev, CC10001_ADC_CONFIG);
	val = val | CC10001_ADC_START_CONV;
	cc10001_adc_write_reg(adc_dev, CC10001_ADC_CONFIG, val);
@@ -129,6 +142,7 @@ static irqreturn_t cc10001_adc_trigger_h(int irq, void *p)
	struct iio_dev *indio_dev;
	unsigned int delay_ns;
	unsigned int channel;
	unsigned int scan_idx;
	bool sample_invalid;
	u16 *data;
	int i;
@@ -139,20 +153,17 @@ static irqreturn_t cc10001_adc_trigger_h(int irq, void *p)

	mutex_lock(&adc_dev->lock);

	cc10001_adc_write_reg(adc_dev, CC10001_ADC_POWER_UP,
			      CC10001_ADC_POWER_UP_SET);

	/* Wait for 8 (6+2) clock cycles before activating START */
	ndelay(adc_dev->start_delay_ns);
	cc10001_adc_power_up(adc_dev);

	/* Calculate delay step for eoc and sampled data */
	delay_ns = adc_dev->eoc_delay_ns / CC10001_MAX_POLL_COUNT;

	i = 0;
	sample_invalid = false;
	for_each_set_bit(channel, indio_dev->active_scan_mask,
	for_each_set_bit(scan_idx, indio_dev->active_scan_mask,
				  indio_dev->masklength) {

		channel = indio_dev->channels[scan_idx].channel;
		cc10001_adc_start(adc_dev, channel);

		data[i] = cc10001_adc_poll_done(indio_dev, channel, delay_ns);
@@ -166,7 +177,7 @@ static irqreturn_t cc10001_adc_trigger_h(int irq, void *p)
	}

done:
	cc10001_adc_write_reg(adc_dev, CC10001_ADC_POWER_UP, 0);
	cc10001_adc_power_down(adc_dev);

	mutex_unlock(&adc_dev->lock);

@@ -185,11 +196,7 @@ static u16 cc10001_adc_read_raw_voltage(struct iio_dev *indio_dev,
	unsigned int delay_ns;
	u16 val;

	cc10001_adc_write_reg(adc_dev, CC10001_ADC_POWER_UP,
			      CC10001_ADC_POWER_UP_SET);

	/* Wait for 8 (6+2) clock cycles before activating START */
	ndelay(adc_dev->start_delay_ns);
	cc10001_adc_power_up(adc_dev);

	/* Calculate delay step for eoc and sampled data */
	delay_ns = adc_dev->eoc_delay_ns / CC10001_MAX_POLL_COUNT;
@@ -198,7 +205,7 @@ static u16 cc10001_adc_read_raw_voltage(struct iio_dev *indio_dev,

	val = cc10001_adc_poll_done(indio_dev, chan->channel, delay_ns);

	cc10001_adc_write_reg(adc_dev, CC10001_ADC_POWER_UP, 0);
	cc10001_adc_power_down(adc_dev);

	return val;
}
@@ -224,7 +231,7 @@ static int cc10001_adc_read_raw(struct iio_dev *indio_dev,

	case IIO_CHAN_INFO_SCALE:
		ret = regulator_get_voltage(adc_dev->reg);
		if (ret)
		if (ret < 0)
			return ret;

		*val = ret / 1000;
@@ -255,22 +262,22 @@ static const struct iio_info cc10001_adc_info = {
	.update_scan_mode = &cc10001_update_scan_mode,
};

static int cc10001_adc_channel_init(struct iio_dev *indio_dev)
static int cc10001_adc_channel_init(struct iio_dev *indio_dev,
				    unsigned long channel_map)
{
	struct cc10001_adc_device *adc_dev = iio_priv(indio_dev);
	struct iio_chan_spec *chan_array, *timestamp;
	unsigned int bit, idx = 0;

	indio_dev->num_channels = bitmap_weight(&adc_dev->channel_map,
						CC10001_ADC_NUM_CHANNELS);
	indio_dev->num_channels = bitmap_weight(&channel_map,
						CC10001_ADC_NUM_CHANNELS) + 1;

	chan_array = devm_kcalloc(&indio_dev->dev, indio_dev->num_channels + 1,
	chan_array = devm_kcalloc(&indio_dev->dev, indio_dev->num_channels,
				  sizeof(struct iio_chan_spec),
				  GFP_KERNEL);
	if (!chan_array)
		return -ENOMEM;

	for_each_set_bit(bit, &adc_dev->channel_map, CC10001_ADC_NUM_CHANNELS) {
	for_each_set_bit(bit, &channel_map, CC10001_ADC_NUM_CHANNELS) {
		struct iio_chan_spec *chan = &chan_array[idx];

		chan->type = IIO_VOLTAGE;
@@ -305,6 +312,7 @@ static int cc10001_adc_probe(struct platform_device *pdev)
	unsigned long adc_clk_rate;
	struct resource *res;
	struct iio_dev *indio_dev;
	unsigned long channel_map;
	int ret;

	indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*adc_dev));
@@ -313,9 +321,9 @@ static int cc10001_adc_probe(struct platform_device *pdev)

	adc_dev = iio_priv(indio_dev);

	adc_dev->channel_map = GENMASK(CC10001_ADC_NUM_CHANNELS - 1, 0);
	channel_map = GENMASK(CC10001_ADC_NUM_CHANNELS - 1, 0);
	if (!of_property_read_u32(node, "adc-reserved-channels", &ret))
		adc_dev->channel_map &= ~ret;
		channel_map &= ~ret;

	adc_dev->reg = devm_regulator_get(&pdev->dev, "vref");
	if (IS_ERR(adc_dev->reg))
@@ -361,7 +369,7 @@ static int cc10001_adc_probe(struct platform_device *pdev)
	adc_dev->start_delay_ns = adc_dev->eoc_delay_ns * CC10001_WAIT_CYCLES;

	/* Setup the ADC channels available on the device */
	ret = cc10001_adc_channel_init(indio_dev);
	ret = cc10001_adc_channel_init(indio_dev, channel_map);
	if (ret < 0)
		goto err_disable_clk;

Loading