First round of iio fixes for the 4.7 cycle.
A slightly bumper set due to travel delaying the pull request and a fair few issues with the recent merge window patches. Patches all over the place. The st-sensors one is probably the most involved, but definitly solves the issues seen. Note there are some other issues around that handler (and the fact that a lot of boards tie a level interrupt chip to an edge interrupt only irq chip). These are not regressions however, so will turn up the slow route. * core - iio_trigger_attach_pollfunc had some really badly wrong error handling. Another nasty triggered whilst chasing down issues with the st sensors rework below. * ad5592r - fix an off by one error when allocating channels. * am2315 - a stray mutex unlock before we ever take the lock. * apds9960 - missing a parent in the driver model (which should be the i2c device). Result is it doesn't turn up under /sys/bus/i2c/devices which some userspace code uses for repeatable device identification. * as3935 - ABI usage bug which meant a processed value was reported as raw. Now reporting scale as well to ensure userspace has the info it needs. - Don't return processed value via the buffer - it doesn't conform to the ABI and will overflow in some cases. - Fix a wrongly sized buffer which would overflow trashing part of the stack. Also move it onto the heap as part of the fix. * bh1780 - a missing return after write in debugfs lead to an incorrect read and a null pointer dereference. - dereferencing the wrong pointer in suspend and resume leading to unpredictable results. - assign a static name to avoid accidentally ending up with no name if loaded via device tree. * bmi160 - output data rate for the accelerometer was incorrectly reported. Fix it. - writing the output data rate was also wrong due to reverse parameters. * bmp280 - error message for wrong chip ID gave the wrong expected value. * hdc100x - mask for writing the integration time was wrong allowin g us to get 'stuck' in a particular value with no way back. - temperature reported in celsius rather than millicelsius as per the ABI. - Get rid of some incorrect data shifting which lead to readings being rather incorrect. * max44000 - drop scale attribute for proximity as it is an unscaled value (depends on what is in range rather than anything knowable at the detector). * st-pressure - ABI compliance fixes - units were wrong. * st-sensors - We introduced some nasty issues with the recent switch over to a a somewhat threaded handler in that we broke using a software trigger with these devices. Now do it properly. It's a larger patch than ideal for a fix, but the logic is straight forward. - Make sure the trigger is initialized before requesting the interrupt. This matters now the interrupt can be shared. Before it was ugly and wrong but short of flakey hardware could not be triggered. - Hammer down the dataready pin at boot - otherwise with really unlucky timing things could get interestingly wedged requiring a hard power down of the chip. -----BEGIN PGP SIGNATURE----- Version: GnuPG v2 iQIcBAABCAAGBQJXVxMzAAoJEFSFNJnE9BaI3QUP/2TLXJ4S+jNFSGslMmq9Ztqm fPGoyPf2nfJCzwgPFK7Yku8mFhqaRbbZrM0m1IA7hYbuZMXZjjQnSrIiDqsDuvXy 1mK3mieCu8hPFTcvVUp1q9HwrrEFIke52LIH6urSDpr1IIbhJQ2ZwXjZIJGhlukc yFwMuA7gz/akc3war+OlS1bbEOe4OuikWMP3Fc3QGKPR7C92M0S8oRyZwBmB2vqu 1lqCzS0JxL3Lz3TqDXkBd+77My7S4af/F7l8JfeCDBoE4zycASP1LUgiSD2aB3Rq hi7hrQjPCFk6rxZ+wFIyC8V0AGeGdEDpQ4JW9rgzDC/KO9Z3Wyq/h5UrQqsnZW0G xbJgLF3Wa0noh/bT0yIGZGcenM57QIJ0vTEymmikbWCNQfzqSG9a0SM7zMukB6Lr IAvMbF3Q3n/d4rzVOE5C9vRPRnG2jICxmA3EKp7blV0hRdd197J7UfN8ExG+9zC7 JxqQh5LLu76Ql7TJqQh7sZl/6Xi0DnUm+wqaxyCgtaZjmsVZ58S6G6E2eefO5Hma r3VUfthe7N0wnWwCs2RMBkBynhb7+4G11m2jp1a4PMYCYg4FhYP7QdDkeDiOSXbG s9Y1ILLI7ufzCyKf5GID7/FtAjdJahVR2ldIy7MwUqw7zAyjsm+ujIpTGZ8iYUvb whHwMtLLTnyB8Zj81LRD =EEPO -----END PGP SIGNATURE----- Merge tag 'iio-fixes-for-4.7a' of git://git.kernel.org/pub/scm/linux/kernel/git/jic23/iio into staging-linus Jonathan writes: First round of iio fixes for the 4.7 cycle. A slightly bumper set due to travel delaying the pull request and a fair few issues with the recent merge window patches. Patches all over the place. The st-sensors one is probably the most involved, but definitly solves the issues seen. Note there are some other issues around that handler (and the fact that a lot of boards tie a level interrupt chip to an edge interrupt only irq chip). These are not regressions however, so will turn up the slow route. * core - iio_trigger_attach_pollfunc had some really badly wrong error handling. Another nasty triggered whilst chasing down issues with the st sensors rework below. * ad5592r - fix an off by one error when allocating channels. * am2315 - a stray mutex unlock before we ever take the lock. * apds9960 - missing a parent in the driver model (which should be the i2c device). Result is it doesn't turn up under /sys/bus/i2c/devices which some userspace code uses for repeatable device identification. * as3935 - ABI usage bug which meant a processed value was reported as raw. Now reporting scale as well to ensure userspace has the info it needs. - Don't return processed value via the buffer - it doesn't conform to the ABI and will overflow in some cases. - Fix a wrongly sized buffer which would overflow trashing part of the stack. Also move it onto the heap as part of the fix. * bh1780 - a missing return after write in debugfs lead to an incorrect read and a null pointer dereference. - dereferencing the wrong pointer in suspend and resume leading to unpredictable results. - assign a static name to avoid accidentally ending up with no name if loaded via device tree. * bmi160 - output data rate for the accelerometer was incorrectly reported. Fix it. - writing the output data rate was also wrong due to reverse parameters. * bmp280 - error message for wrong chip ID gave the wrong expected value. * hdc100x - mask for writing the integration time was wrong allowin g us to get 'stuck' in a particular value with no way back. - temperature reported in celsius rather than millicelsius as per the ABI. - Get rid of some incorrect data shifting which lead to readings being rather incorrect. * max44000 - drop scale attribute for proximity as it is an unscaled value (depends on what is in range rather than anything knowable at the detector). * st-pressure - ABI compliance fixes - units were wrong. * st-sensors - We introduced some nasty issues with the recent switch over to a a somewhat threaded handler in that we broke using a software trigger with these devices. Now do it properly. It's a larger patch than ideal for a fix, but the logic is straight forward. - Make sure the trigger is initialized before requesting the interrupt. This matters now the interrupt can be shared. Before it was ugly and wrong but short of flakey hardware could not be triggered. - Hammer down the dataready pin at boot - otherwise with really unlucky timing things could get interestingly wedged requiring a hard power down of the chip.
This commit is contained in:
commit
03cce00b4b
|
@ -1,4 +1,4 @@
|
|||
What /sys/bus/iio/devices/iio:deviceX/in_proximity_raw
|
||||
What /sys/bus/iio/devices/iio:deviceX/in_proximity_input
|
||||
Date: March 2014
|
||||
KernelVersion: 3.15
|
||||
Contact: Matt Ranostay <mranostay@gmail.com>
|
||||
|
|
|
@ -91,7 +91,7 @@ static const struct iio_buffer_setup_ops st_accel_buffer_setup_ops = {
|
|||
|
||||
int st_accel_allocate_ring(struct iio_dev *indio_dev)
|
||||
{
|
||||
return iio_triggered_buffer_setup(indio_dev, &iio_pollfunc_store_time,
|
||||
return iio_triggered_buffer_setup(indio_dev, NULL,
|
||||
&st_sensors_trigger_handler, &st_accel_buffer_setup_ops);
|
||||
}
|
||||
|
||||
|
|
|
@ -741,6 +741,7 @@ static const struct iio_info accel_info = {
|
|||
static const struct iio_trigger_ops st_accel_trigger_ops = {
|
||||
.owner = THIS_MODULE,
|
||||
.set_trigger_state = ST_ACCEL_TRIGGER_SET_STATE,
|
||||
.validate_device = st_sensors_validate_device,
|
||||
};
|
||||
#define ST_ACCEL_TRIGGER_OPS (&st_accel_trigger_ops)
|
||||
#else
|
||||
|
|
|
@ -57,31 +57,20 @@ irqreturn_t st_sensors_trigger_handler(int irq, void *p)
|
|||
struct iio_poll_func *pf = p;
|
||||
struct iio_dev *indio_dev = pf->indio_dev;
|
||||
struct st_sensor_data *sdata = iio_priv(indio_dev);
|
||||
s64 timestamp;
|
||||
|
||||
/* If we have a status register, check if this IRQ came from us */
|
||||
if (sdata->sensor_settings->drdy_irq.addr_stat_drdy) {
|
||||
u8 status;
|
||||
|
||||
len = sdata->tf->read_byte(&sdata->tb, sdata->dev,
|
||||
sdata->sensor_settings->drdy_irq.addr_stat_drdy,
|
||||
&status);
|
||||
if (len < 0)
|
||||
dev_err(sdata->dev, "could not read channel status\n");
|
||||
|
||||
/*
|
||||
* If this was not caused by any channels on this sensor,
|
||||
* return IRQ_NONE
|
||||
*/
|
||||
if (!(status & (u8)indio_dev->active_scan_mask[0]))
|
||||
return IRQ_NONE;
|
||||
}
|
||||
/* If we do timetamping here, do it before reading the values */
|
||||
if (sdata->hw_irq_trigger)
|
||||
timestamp = sdata->hw_timestamp;
|
||||
else
|
||||
timestamp = iio_get_time_ns();
|
||||
|
||||
len = st_sensors_get_buffer_element(indio_dev, sdata->buffer_data);
|
||||
if (len < 0)
|
||||
goto st_sensors_get_buffer_element_error;
|
||||
|
||||
iio_push_to_buffers_with_timestamp(indio_dev, sdata->buffer_data,
|
||||
pf->timestamp);
|
||||
timestamp);
|
||||
|
||||
st_sensors_get_buffer_element_error:
|
||||
iio_trigger_notify_done(indio_dev->trig);
|
||||
|
|
|
@ -363,6 +363,11 @@ int st_sensors_init_sensor(struct iio_dev *indio_dev,
|
|||
if (err < 0)
|
||||
return err;
|
||||
|
||||
/* Disable DRDY, this might be still be enabled after reboot. */
|
||||
err = st_sensors_set_dataready_irq(indio_dev, false);
|
||||
if (err < 0)
|
||||
return err;
|
||||
|
||||
if (sdata->current_fullscale) {
|
||||
err = st_sensors_set_fullscale(indio_dev,
|
||||
sdata->current_fullscale->num);
|
||||
|
@ -424,6 +429,9 @@ int st_sensors_set_dataready_irq(struct iio_dev *indio_dev, bool enable)
|
|||
else
|
||||
drdy_mask = sdata->sensor_settings->drdy_irq.mask_int2;
|
||||
|
||||
/* Flag to the poll function that the hardware trigger is in use */
|
||||
sdata->hw_irq_trigger = enable;
|
||||
|
||||
/* Enable/Disable the interrupt generator for data ready. */
|
||||
err = st_sensors_write_data_with_mask(indio_dev,
|
||||
sdata->sensor_settings->drdy_irq.addr,
|
||||
|
|
|
@ -17,6 +17,73 @@
|
|||
#include <linux/iio/common/st_sensors.h>
|
||||
#include "st_sensors_core.h"
|
||||
|
||||
/**
|
||||
* st_sensors_irq_handler() - top half of the IRQ-based triggers
|
||||
* @irq: irq number
|
||||
* @p: private handler data
|
||||
*/
|
||||
irqreturn_t st_sensors_irq_handler(int irq, void *p)
|
||||
{
|
||||
struct iio_trigger *trig = p;
|
||||
struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig);
|
||||
struct st_sensor_data *sdata = iio_priv(indio_dev);
|
||||
|
||||
/* Get the time stamp as close in time as possible */
|
||||
sdata->hw_timestamp = iio_get_time_ns();
|
||||
return IRQ_WAKE_THREAD;
|
||||
}
|
||||
|
||||
/**
|
||||
* st_sensors_irq_thread() - bottom half of the IRQ-based triggers
|
||||
* @irq: irq number
|
||||
* @p: private handler data
|
||||
*/
|
||||
irqreturn_t st_sensors_irq_thread(int irq, void *p)
|
||||
{
|
||||
struct iio_trigger *trig = p;
|
||||
struct iio_dev *indio_dev = iio_trigger_get_drvdata(trig);
|
||||
struct st_sensor_data *sdata = iio_priv(indio_dev);
|
||||
int ret;
|
||||
|
||||
/*
|
||||
* If this trigger is backed by a hardware interrupt and we have a
|
||||
* status register, check if this IRQ came from us
|
||||
*/
|
||||
if (sdata->sensor_settings->drdy_irq.addr_stat_drdy) {
|
||||
u8 status;
|
||||
|
||||
ret = sdata->tf->read_byte(&sdata->tb, sdata->dev,
|
||||
sdata->sensor_settings->drdy_irq.addr_stat_drdy,
|
||||
&status);
|
||||
if (ret < 0) {
|
||||
dev_err(sdata->dev, "could not read channel status\n");
|
||||
goto out_poll;
|
||||
}
|
||||
/*
|
||||
* the lower bits of .active_scan_mask[0] is directly mapped
|
||||
* to the channels on the sensor: either bit 0 for
|
||||
* one-dimensional sensors, or e.g. x,y,z for accelerometers,
|
||||
* gyroscopes or magnetometers. No sensor use more than 3
|
||||
* channels, so cut the other status bits here.
|
||||
*/
|
||||
status &= 0x07;
|
||||
|
||||
/*
|
||||
* If this was not caused by any channels on this sensor,
|
||||
* return IRQ_NONE
|
||||
*/
|
||||
if (!indio_dev->active_scan_mask)
|
||||
return IRQ_NONE;
|
||||
if (!(status & (u8)indio_dev->active_scan_mask[0]))
|
||||
return IRQ_NONE;
|
||||
}
|
||||
|
||||
out_poll:
|
||||
/* It's our IRQ: proceed to handle the register polling */
|
||||
iio_trigger_poll_chained(p);
|
||||
return IRQ_HANDLED;
|
||||
}
|
||||
|
||||
int st_sensors_allocate_trigger(struct iio_dev *indio_dev,
|
||||
const struct iio_trigger_ops *trigger_ops)
|
||||
{
|
||||
|
@ -30,6 +97,10 @@ int st_sensors_allocate_trigger(struct iio_dev *indio_dev,
|
|||
return -ENOMEM;
|
||||
}
|
||||
|
||||
iio_trigger_set_drvdata(sdata->trig, indio_dev);
|
||||
sdata->trig->ops = trigger_ops;
|
||||
sdata->trig->dev.parent = sdata->dev;
|
||||
|
||||
irq = sdata->get_irq_data_ready(indio_dev);
|
||||
irq_trig = irqd_get_trigger_type(irq_get_irq_data(irq));
|
||||
/*
|
||||
|
@ -77,9 +148,12 @@ int st_sensors_allocate_trigger(struct iio_dev *indio_dev,
|
|||
sdata->sensor_settings->drdy_irq.addr_stat_drdy)
|
||||
irq_trig |= IRQF_SHARED;
|
||||
|
||||
err = request_threaded_irq(irq,
|
||||
iio_trigger_generic_data_rdy_poll,
|
||||
NULL,
|
||||
/* Let's create an interrupt thread masking the hard IRQ here */
|
||||
irq_trig |= IRQF_ONESHOT;
|
||||
|
||||
err = request_threaded_irq(sdata->get_irq_data_ready(indio_dev),
|
||||
st_sensors_irq_handler,
|
||||
st_sensors_irq_thread,
|
||||
irq_trig,
|
||||
sdata->trig->name,
|
||||
sdata->trig);
|
||||
|
@ -88,10 +162,6 @@ int st_sensors_allocate_trigger(struct iio_dev *indio_dev,
|
|||
goto iio_trigger_free;
|
||||
}
|
||||
|
||||
iio_trigger_set_drvdata(sdata->trig, indio_dev);
|
||||
sdata->trig->ops = trigger_ops;
|
||||
sdata->trig->dev.parent = sdata->dev;
|
||||
|
||||
err = iio_trigger_register(sdata->trig);
|
||||
if (err < 0) {
|
||||
dev_err(&indio_dev->dev, "failed to register iio trigger.\n");
|
||||
|
@ -119,6 +189,18 @@ void st_sensors_deallocate_trigger(struct iio_dev *indio_dev)
|
|||
}
|
||||
EXPORT_SYMBOL(st_sensors_deallocate_trigger);
|
||||
|
||||
int st_sensors_validate_device(struct iio_trigger *trig,
|
||||
struct iio_dev *indio_dev)
|
||||
{
|
||||
struct iio_dev *indio = iio_trigger_get_drvdata(trig);
|
||||
|
||||
if (indio != indio_dev)
|
||||
return -EINVAL;
|
||||
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL(st_sensors_validate_device);
|
||||
|
||||
MODULE_AUTHOR("Denis Ciocca <denis.ciocca@st.com>");
|
||||
MODULE_DESCRIPTION("STMicroelectronics ST-sensors trigger");
|
||||
MODULE_LICENSE("GPL v2");
|
||||
|
|
|
@ -525,7 +525,7 @@ static int ad5592r_alloc_channels(struct ad5592r_state *st)
|
|||
|
||||
device_for_each_child_node(st->dev, child) {
|
||||
ret = fwnode_property_read_u32(child, "reg", ®);
|
||||
if (ret || reg > ARRAY_SIZE(st->channel_modes))
|
||||
if (ret || reg >= ARRAY_SIZE(st->channel_modes))
|
||||
continue;
|
||||
|
||||
ret = fwnode_property_read_u32(child, "adi,mode", &tmp);
|
||||
|
|
|
@ -91,7 +91,7 @@ static const struct iio_buffer_setup_ops st_gyro_buffer_setup_ops = {
|
|||
|
||||
int st_gyro_allocate_ring(struct iio_dev *indio_dev)
|
||||
{
|
||||
return iio_triggered_buffer_setup(indio_dev, &iio_pollfunc_store_time,
|
||||
return iio_triggered_buffer_setup(indio_dev, NULL,
|
||||
&st_sensors_trigger_handler, &st_gyro_buffer_setup_ops);
|
||||
}
|
||||
|
||||
|
|
|
@ -409,6 +409,7 @@ static const struct iio_info gyro_info = {
|
|||
static const struct iio_trigger_ops st_gyro_trigger_ops = {
|
||||
.owner = THIS_MODULE,
|
||||
.set_trigger_state = ST_GYRO_TRIGGER_SET_STATE,
|
||||
.validate_device = st_sensors_validate_device,
|
||||
};
|
||||
#define ST_GYRO_TRIGGER_OPS (&st_gyro_trigger_ops)
|
||||
#else
|
||||
|
|
|
@ -165,10 +165,8 @@ static irqreturn_t am2315_trigger_handler(int irq, void *p)
|
|||
struct am2315_sensor_data sensor_data;
|
||||
|
||||
ret = am2315_read_data(data, &sensor_data);
|
||||
if (ret < 0) {
|
||||
mutex_unlock(&data->lock);
|
||||
if (ret < 0)
|
||||
goto err;
|
||||
}
|
||||
|
||||
mutex_lock(&data->lock);
|
||||
if (*(indio_dev->active_scan_mask) == AM2315_ALL_CHANNEL_MASK) {
|
||||
|
|
|
@ -55,7 +55,7 @@ static const struct {
|
|||
},
|
||||
{ /* IIO_HUMIDITYRELATIVE channel */
|
||||
.shift = 8,
|
||||
.mask = 2,
|
||||
.mask = 3,
|
||||
},
|
||||
};
|
||||
|
||||
|
@ -164,14 +164,14 @@ static int hdc100x_get_measurement(struct hdc100x_data *data,
|
|||
dev_err(&client->dev, "cannot read high byte measurement");
|
||||
return ret;
|
||||
}
|
||||
val = ret << 6;
|
||||
val = ret << 8;
|
||||
|
||||
ret = i2c_smbus_read_byte(client);
|
||||
if (ret < 0) {
|
||||
dev_err(&client->dev, "cannot read low byte measurement");
|
||||
return ret;
|
||||
}
|
||||
val |= ret >> 2;
|
||||
val |= ret;
|
||||
|
||||
return val;
|
||||
}
|
||||
|
@ -211,18 +211,18 @@ static int hdc100x_read_raw(struct iio_dev *indio_dev,
|
|||
return IIO_VAL_INT_PLUS_MICRO;
|
||||
case IIO_CHAN_INFO_SCALE:
|
||||
if (chan->type == IIO_TEMP) {
|
||||
*val = 165;
|
||||
*val2 = 65536 >> 2;
|
||||
*val = 165000;
|
||||
*val2 = 65536;
|
||||
return IIO_VAL_FRACTIONAL;
|
||||
} else {
|
||||
*val = 0;
|
||||
*val2 = 10000;
|
||||
return IIO_VAL_INT_PLUS_MICRO;
|
||||
*val = 100;
|
||||
*val2 = 65536;
|
||||
return IIO_VAL_FRACTIONAL;
|
||||
}
|
||||
break;
|
||||
case IIO_CHAN_INFO_OFFSET:
|
||||
*val = -3971;
|
||||
*val2 = 879096;
|
||||
*val = -15887;
|
||||
*val2 = 515151;
|
||||
return IIO_VAL_INT_PLUS_MICRO;
|
||||
default:
|
||||
return -EINVAL;
|
||||
|
|
|
@ -209,11 +209,11 @@ static const struct bmi160_scale_item bmi160_scale_table[] = {
|
|||
};
|
||||
|
||||
static const struct bmi160_odr bmi160_accel_odr[] = {
|
||||
{0x01, 0, 78125},
|
||||
{0x02, 1, 5625},
|
||||
{0x03, 3, 125},
|
||||
{0x04, 6, 25},
|
||||
{0x05, 12, 5},
|
||||
{0x01, 0, 781250},
|
||||
{0x02, 1, 562500},
|
||||
{0x03, 3, 125000},
|
||||
{0x04, 6, 250000},
|
||||
{0x05, 12, 500000},
|
||||
{0x06, 25, 0},
|
||||
{0x07, 50, 0},
|
||||
{0x08, 100, 0},
|
||||
|
@ -229,7 +229,7 @@ static const struct bmi160_odr bmi160_gyro_odr[] = {
|
|||
{0x08, 100, 0},
|
||||
{0x09, 200, 0},
|
||||
{0x0A, 400, 0},
|
||||
{0x0B, 8000, 0},
|
||||
{0x0B, 800, 0},
|
||||
{0x0C, 1600, 0},
|
||||
{0x0D, 3200, 0},
|
||||
};
|
||||
|
@ -364,8 +364,8 @@ int bmi160_set_odr(struct bmi160_data *data, enum bmi160_sensor_type t,
|
|||
|
||||
return regmap_update_bits(data->regmap,
|
||||
bmi160_regs[t].config,
|
||||
bmi160_odr_table[t].tbl[i].bits,
|
||||
bmi160_regs[t].config_odr_mask);
|
||||
bmi160_regs[t].config_odr_mask,
|
||||
bmi160_odr_table[t].tbl[i].bits);
|
||||
}
|
||||
|
||||
static int bmi160_get_odr(struct bmi160_data *data, enum bmi160_sensor_type t,
|
||||
|
|
|
@ -210,22 +210,35 @@ static int iio_trigger_attach_poll_func(struct iio_trigger *trig,
|
|||
|
||||
/* Prevent the module from being removed whilst attached to a trigger */
|
||||
__module_get(pf->indio_dev->info->driver_module);
|
||||
|
||||
/* Get irq number */
|
||||
pf->irq = iio_trigger_get_irq(trig);
|
||||
if (pf->irq < 0)
|
||||
goto out_put_module;
|
||||
|
||||
/* Request irq */
|
||||
ret = request_threaded_irq(pf->irq, pf->h, pf->thread,
|
||||
pf->type, pf->name,
|
||||
pf);
|
||||
if (ret < 0) {
|
||||
module_put(pf->indio_dev->info->driver_module);
|
||||
return ret;
|
||||
}
|
||||
if (ret < 0)
|
||||
goto out_put_irq;
|
||||
|
||||
/* Enable trigger in driver */
|
||||
if (trig->ops && trig->ops->set_trigger_state && notinuse) {
|
||||
ret = trig->ops->set_trigger_state(trig, true);
|
||||
if (ret < 0)
|
||||
module_put(pf->indio_dev->info->driver_module);
|
||||
goto out_free_irq;
|
||||
}
|
||||
|
||||
return ret;
|
||||
|
||||
out_free_irq:
|
||||
free_irq(pf->irq, pf);
|
||||
out_put_irq:
|
||||
iio_trigger_put_irq(trig, pf->irq);
|
||||
out_put_module:
|
||||
module_put(pf->indio_dev->info->driver_module);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int iio_trigger_detach_poll_func(struct iio_trigger *trig,
|
||||
|
|
|
@ -1011,6 +1011,7 @@ static int apds9960_probe(struct i2c_client *client,
|
|||
|
||||
iio_device_attach_buffer(indio_dev, buffer);
|
||||
|
||||
indio_dev->dev.parent = &client->dev;
|
||||
indio_dev->info = &apds9960_info;
|
||||
indio_dev->name = APDS9960_DRV_NAME;
|
||||
indio_dev->channels = apds9960_channels;
|
||||
|
|
|
@ -84,7 +84,7 @@ static int bh1780_debugfs_reg_access(struct iio_dev *indio_dev,
|
|||
int ret;
|
||||
|
||||
if (!readval)
|
||||
bh1780_write(bh1780, (u8)reg, (u8)writeval);
|
||||
return bh1780_write(bh1780, (u8)reg, (u8)writeval);
|
||||
|
||||
ret = bh1780_read(bh1780, (u8)reg);
|
||||
if (ret < 0)
|
||||
|
@ -187,7 +187,7 @@ static int bh1780_probe(struct i2c_client *client,
|
|||
|
||||
indio_dev->dev.parent = &client->dev;
|
||||
indio_dev->info = &bh1780_info;
|
||||
indio_dev->name = id->name;
|
||||
indio_dev->name = "bh1780";
|
||||
indio_dev->channels = bh1780_channels;
|
||||
indio_dev->num_channels = ARRAY_SIZE(bh1780_channels);
|
||||
indio_dev->modes = INDIO_DIRECT_MODE;
|
||||
|
@ -226,7 +226,8 @@ static int bh1780_remove(struct i2c_client *client)
|
|||
static int bh1780_runtime_suspend(struct device *dev)
|
||||
{
|
||||
struct i2c_client *client = to_i2c_client(dev);
|
||||
struct bh1780_data *bh1780 = i2c_get_clientdata(client);
|
||||
struct iio_dev *indio_dev = i2c_get_clientdata(client);
|
||||
struct bh1780_data *bh1780 = iio_priv(indio_dev);
|
||||
int ret;
|
||||
|
||||
ret = bh1780_write(bh1780, BH1780_REG_CONTROL, BH1780_POFF);
|
||||
|
@ -241,7 +242,8 @@ static int bh1780_runtime_suspend(struct device *dev)
|
|||
static int bh1780_runtime_resume(struct device *dev)
|
||||
{
|
||||
struct i2c_client *client = to_i2c_client(dev);
|
||||
struct bh1780_data *bh1780 = i2c_get_clientdata(client);
|
||||
struct iio_dev *indio_dev = i2c_get_clientdata(client);
|
||||
struct bh1780_data *bh1780 = iio_priv(indio_dev);
|
||||
int ret;
|
||||
|
||||
ret = bh1780_write(bh1780, BH1780_REG_CONTROL, BH1780_PON);
|
||||
|
|
|
@ -147,7 +147,6 @@ static const struct iio_chan_spec max44000_channels[] = {
|
|||
{
|
||||
.type = IIO_PROXIMITY,
|
||||
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
|
||||
.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE),
|
||||
.scan_index = MAX44000_SCAN_INDEX_PRX,
|
||||
.scan_type = {
|
||||
.sign = 'u',
|
||||
|
|
|
@ -82,7 +82,7 @@ static const struct iio_buffer_setup_ops st_magn_buffer_setup_ops = {
|
|||
|
||||
int st_magn_allocate_ring(struct iio_dev *indio_dev)
|
||||
{
|
||||
return iio_triggered_buffer_setup(indio_dev, &iio_pollfunc_store_time,
|
||||
return iio_triggered_buffer_setup(indio_dev, NULL,
|
||||
&st_sensors_trigger_handler, &st_magn_buffer_setup_ops);
|
||||
}
|
||||
|
||||
|
|
|
@ -572,6 +572,7 @@ static const struct iio_info magn_info = {
|
|||
static const struct iio_trigger_ops st_magn_trigger_ops = {
|
||||
.owner = THIS_MODULE,
|
||||
.set_trigger_state = ST_MAGN_TRIGGER_SET_STATE,
|
||||
.validate_device = st_sensors_validate_device,
|
||||
};
|
||||
#define ST_MAGN_TRIGGER_OPS (&st_magn_trigger_ops)
|
||||
#else
|
||||
|
|
|
@ -879,8 +879,8 @@ static int bmp280_probe(struct i2c_client *client,
|
|||
if (ret < 0)
|
||||
return ret;
|
||||
if (chip_id != id->driver_data) {
|
||||
dev_err(&client->dev, "bad chip id. expected %x got %x\n",
|
||||
BMP280_CHIP_ID, chip_id);
|
||||
dev_err(&client->dev, "bad chip id. expected %lx got %x\n",
|
||||
id->driver_data, chip_id);
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
|
|
|
@ -82,7 +82,7 @@ static const struct iio_buffer_setup_ops st_press_buffer_setup_ops = {
|
|||
|
||||
int st_press_allocate_ring(struct iio_dev *indio_dev)
|
||||
{
|
||||
return iio_triggered_buffer_setup(indio_dev, &iio_pollfunc_store_time,
|
||||
return iio_triggered_buffer_setup(indio_dev, NULL,
|
||||
&st_sensors_trigger_handler, &st_press_buffer_setup_ops);
|
||||
}
|
||||
|
||||
|
|
|
@ -28,15 +28,21 @@
|
|||
#include <linux/iio/common/st_sensors.h>
|
||||
#include "st_pressure.h"
|
||||
|
||||
#define MCELSIUS_PER_CELSIUS 1000
|
||||
|
||||
/* Default pressure sensitivity */
|
||||
#define ST_PRESS_LSB_PER_MBAR 4096UL
|
||||
#define ST_PRESS_KPASCAL_NANO_SCALE (100000000UL / \
|
||||
ST_PRESS_LSB_PER_MBAR)
|
||||
|
||||
/* Default temperature sensitivity */
|
||||
#define ST_PRESS_LSB_PER_CELSIUS 480UL
|
||||
#define ST_PRESS_CELSIUS_NANO_SCALE (1000000000UL / \
|
||||
ST_PRESS_LSB_PER_CELSIUS)
|
||||
#define ST_PRESS_MILLI_CELSIUS_OFFSET 42500UL
|
||||
|
||||
#define ST_PRESS_NUMBER_DATA_CHANNELS 1
|
||||
|
||||
/* FULLSCALE */
|
||||
#define ST_PRESS_FS_AVL_1100MB 1100
|
||||
#define ST_PRESS_FS_AVL_1260MB 1260
|
||||
|
||||
#define ST_PRESS_1_OUT_XL_ADDR 0x28
|
||||
|
@ -54,9 +60,6 @@
|
|||
#define ST_PRESS_LPS331AP_PW_MASK 0x80
|
||||
#define ST_PRESS_LPS331AP_FS_ADDR 0x23
|
||||
#define ST_PRESS_LPS331AP_FS_MASK 0x30
|
||||
#define ST_PRESS_LPS331AP_FS_AVL_1260_VAL 0x00
|
||||
#define ST_PRESS_LPS331AP_FS_AVL_1260_GAIN ST_PRESS_KPASCAL_NANO_SCALE
|
||||
#define ST_PRESS_LPS331AP_FS_AVL_TEMP_GAIN ST_PRESS_CELSIUS_NANO_SCALE
|
||||
#define ST_PRESS_LPS331AP_BDU_ADDR 0x20
|
||||
#define ST_PRESS_LPS331AP_BDU_MASK 0x04
|
||||
#define ST_PRESS_LPS331AP_DRDY_IRQ_ADDR 0x22
|
||||
|
@ -67,9 +70,14 @@
|
|||
#define ST_PRESS_LPS331AP_OD_IRQ_ADDR 0x22
|
||||
#define ST_PRESS_LPS331AP_OD_IRQ_MASK 0x40
|
||||
#define ST_PRESS_LPS331AP_MULTIREAD_BIT true
|
||||
#define ST_PRESS_LPS331AP_TEMP_OFFSET 42500
|
||||
|
||||
/* CUSTOM VALUES FOR LPS001WP SENSOR */
|
||||
|
||||
/* LPS001WP pressure resolution */
|
||||
#define ST_PRESS_LPS001WP_LSB_PER_MBAR 16UL
|
||||
/* LPS001WP temperature resolution */
|
||||
#define ST_PRESS_LPS001WP_LSB_PER_CELSIUS 64UL
|
||||
|
||||
#define ST_PRESS_LPS001WP_WAI_EXP 0xba
|
||||
#define ST_PRESS_LPS001WP_ODR_ADDR 0x20
|
||||
#define ST_PRESS_LPS001WP_ODR_MASK 0x30
|
||||
|
@ -78,6 +86,8 @@
|
|||
#define ST_PRESS_LPS001WP_ODR_AVL_13HZ_VAL 0x03
|
||||
#define ST_PRESS_LPS001WP_PW_ADDR 0x20
|
||||
#define ST_PRESS_LPS001WP_PW_MASK 0x40
|
||||
#define ST_PRESS_LPS001WP_FS_AVL_PRESS_GAIN \
|
||||
(100000000UL / ST_PRESS_LPS001WP_LSB_PER_MBAR)
|
||||
#define ST_PRESS_LPS001WP_BDU_ADDR 0x20
|
||||
#define ST_PRESS_LPS001WP_BDU_MASK 0x04
|
||||
#define ST_PRESS_LPS001WP_MULTIREAD_BIT true
|
||||
|
@ -94,11 +104,6 @@
|
|||
#define ST_PRESS_LPS25H_ODR_AVL_25HZ_VAL 0x04
|
||||
#define ST_PRESS_LPS25H_PW_ADDR 0x20
|
||||
#define ST_PRESS_LPS25H_PW_MASK 0x80
|
||||
#define ST_PRESS_LPS25H_FS_ADDR 0x00
|
||||
#define ST_PRESS_LPS25H_FS_MASK 0x00
|
||||
#define ST_PRESS_LPS25H_FS_AVL_1260_VAL 0x00
|
||||
#define ST_PRESS_LPS25H_FS_AVL_1260_GAIN ST_PRESS_KPASCAL_NANO_SCALE
|
||||
#define ST_PRESS_LPS25H_FS_AVL_TEMP_GAIN ST_PRESS_CELSIUS_NANO_SCALE
|
||||
#define ST_PRESS_LPS25H_BDU_ADDR 0x20
|
||||
#define ST_PRESS_LPS25H_BDU_MASK 0x04
|
||||
#define ST_PRESS_LPS25H_DRDY_IRQ_ADDR 0x23
|
||||
|
@ -109,7 +114,6 @@
|
|||
#define ST_PRESS_LPS25H_OD_IRQ_ADDR 0x22
|
||||
#define ST_PRESS_LPS25H_OD_IRQ_MASK 0x40
|
||||
#define ST_PRESS_LPS25H_MULTIREAD_BIT true
|
||||
#define ST_PRESS_LPS25H_TEMP_OFFSET 42500
|
||||
#define ST_PRESS_LPS25H_OUT_XL_ADDR 0x28
|
||||
#define ST_TEMP_LPS25H_OUT_L_ADDR 0x2b
|
||||
|
||||
|
@ -161,7 +165,9 @@ static const struct iio_chan_spec st_press_lps001wp_channels[] = {
|
|||
.storagebits = 16,
|
||||
.endianness = IIO_LE,
|
||||
},
|
||||
.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),
|
||||
.info_mask_separate =
|
||||
BIT(IIO_CHAN_INFO_RAW) |
|
||||
BIT(IIO_CHAN_INFO_SCALE),
|
||||
.modified = 0,
|
||||
},
|
||||
{
|
||||
|
@ -177,7 +183,7 @@ static const struct iio_chan_spec st_press_lps001wp_channels[] = {
|
|||
},
|
||||
.info_mask_separate =
|
||||
BIT(IIO_CHAN_INFO_RAW) |
|
||||
BIT(IIO_CHAN_INFO_OFFSET),
|
||||
BIT(IIO_CHAN_INFO_SCALE),
|
||||
.modified = 0,
|
||||
},
|
||||
IIO_CHAN_SOFT_TIMESTAMP(1)
|
||||
|
@ -212,11 +218,14 @@ static const struct st_sensor_settings st_press_sensors_settings[] = {
|
|||
.addr = ST_PRESS_LPS331AP_FS_ADDR,
|
||||
.mask = ST_PRESS_LPS331AP_FS_MASK,
|
||||
.fs_avl = {
|
||||
/*
|
||||
* Pressure and temperature sensitivity values
|
||||
* as defined in table 3 of LPS331AP datasheet.
|
||||
*/
|
||||
[0] = {
|
||||
.num = ST_PRESS_FS_AVL_1260MB,
|
||||
.value = ST_PRESS_LPS331AP_FS_AVL_1260_VAL,
|
||||
.gain = ST_PRESS_LPS331AP_FS_AVL_1260_GAIN,
|
||||
.gain2 = ST_PRESS_LPS331AP_FS_AVL_TEMP_GAIN,
|
||||
.gain = ST_PRESS_KPASCAL_NANO_SCALE,
|
||||
.gain2 = ST_PRESS_LSB_PER_CELSIUS,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -261,7 +270,17 @@ static const struct st_sensor_settings st_press_sensors_settings[] = {
|
|||
.value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE,
|
||||
},
|
||||
.fs = {
|
||||
.addr = 0,
|
||||
.fs_avl = {
|
||||
/*
|
||||
* Pressure and temperature resolution values
|
||||
* as defined in table 3 of LPS001WP datasheet.
|
||||
*/
|
||||
[0] = {
|
||||
.num = ST_PRESS_FS_AVL_1100MB,
|
||||
.gain = ST_PRESS_LPS001WP_FS_AVL_PRESS_GAIN,
|
||||
.gain2 = ST_PRESS_LPS001WP_LSB_PER_CELSIUS,
|
||||
},
|
||||
},
|
||||
},
|
||||
.bdu = {
|
||||
.addr = ST_PRESS_LPS001WP_BDU_ADDR,
|
||||
|
@ -298,14 +317,15 @@ static const struct st_sensor_settings st_press_sensors_settings[] = {
|
|||
.value_off = ST_SENSORS_DEFAULT_POWER_OFF_VALUE,
|
||||
},
|
||||
.fs = {
|
||||
.addr = ST_PRESS_LPS25H_FS_ADDR,
|
||||
.mask = ST_PRESS_LPS25H_FS_MASK,
|
||||
.fs_avl = {
|
||||
/*
|
||||
* Pressure and temperature sensitivity values
|
||||
* as defined in table 3 of LPS25H datasheet.
|
||||
*/
|
||||
[0] = {
|
||||
.num = ST_PRESS_FS_AVL_1260MB,
|
||||
.value = ST_PRESS_LPS25H_FS_AVL_1260_VAL,
|
||||
.gain = ST_PRESS_LPS25H_FS_AVL_1260_GAIN,
|
||||
.gain2 = ST_PRESS_LPS25H_FS_AVL_TEMP_GAIN,
|
||||
.gain = ST_PRESS_KPASCAL_NANO_SCALE,
|
||||
.gain2 = ST_PRESS_LSB_PER_CELSIUS,
|
||||
},
|
||||
},
|
||||
},
|
||||
|
@ -364,26 +384,26 @@ static int st_press_read_raw(struct iio_dev *indio_dev,
|
|||
|
||||
return IIO_VAL_INT;
|
||||
case IIO_CHAN_INFO_SCALE:
|
||||
*val = 0;
|
||||
|
||||
switch (ch->type) {
|
||||
case IIO_PRESSURE:
|
||||
*val = 0;
|
||||
*val2 = press_data->current_fullscale->gain;
|
||||
break;
|
||||
return IIO_VAL_INT_PLUS_NANO;
|
||||
case IIO_TEMP:
|
||||
*val = MCELSIUS_PER_CELSIUS;
|
||||
*val2 = press_data->current_fullscale->gain2;
|
||||
break;
|
||||
return IIO_VAL_FRACTIONAL;
|
||||
default:
|
||||
err = -EINVAL;
|
||||
goto read_error;
|
||||
}
|
||||
|
||||
return IIO_VAL_INT_PLUS_NANO;
|
||||
case IIO_CHAN_INFO_OFFSET:
|
||||
switch (ch->type) {
|
||||
case IIO_TEMP:
|
||||
*val = 425;
|
||||
*val2 = 10;
|
||||
*val = ST_PRESS_MILLI_CELSIUS_OFFSET *
|
||||
press_data->current_fullscale->gain2;
|
||||
*val2 = MCELSIUS_PER_CELSIUS;
|
||||
break;
|
||||
default:
|
||||
err = -EINVAL;
|
||||
|
@ -425,6 +445,7 @@ static const struct iio_info press_info = {
|
|||
static const struct iio_trigger_ops st_press_trigger_ops = {
|
||||
.owner = THIS_MODULE,
|
||||
.set_trigger_state = ST_PRESS_TRIGGER_SET_STATE,
|
||||
.validate_device = st_sensors_validate_device,
|
||||
};
|
||||
#define ST_PRESS_TRIGGER_OPS (&st_press_trigger_ops)
|
||||
#else
|
||||
|
|
|
@ -64,6 +64,7 @@ struct as3935_state {
|
|||
struct delayed_work work;
|
||||
|
||||
u32 tune_cap;
|
||||
u8 buffer[16]; /* 8-bit data + 56-bit padding + 64-bit timestamp */
|
||||
u8 buf[2] ____cacheline_aligned;
|
||||
};
|
||||
|
||||
|
@ -72,7 +73,8 @@ static const struct iio_chan_spec as3935_channels[] = {
|
|||
.type = IIO_PROXIMITY,
|
||||
.info_mask_separate =
|
||||
BIT(IIO_CHAN_INFO_RAW) |
|
||||
BIT(IIO_CHAN_INFO_PROCESSED),
|
||||
BIT(IIO_CHAN_INFO_PROCESSED) |
|
||||
BIT(IIO_CHAN_INFO_SCALE),
|
||||
.scan_index = 0,
|
||||
.scan_type = {
|
||||
.sign = 'u',
|
||||
|
@ -181,7 +183,12 @@ static int as3935_read_raw(struct iio_dev *indio_dev,
|
|||
/* storm out of range */
|
||||
if (*val == AS3935_DATA_MASK)
|
||||
return -EINVAL;
|
||||
*val *= 1000;
|
||||
|
||||
if (m == IIO_CHAN_INFO_PROCESSED)
|
||||
*val *= 1000;
|
||||
break;
|
||||
case IIO_CHAN_INFO_SCALE:
|
||||
*val = 1000;
|
||||
break;
|
||||
default:
|
||||
return -EINVAL;
|
||||
|
@ -206,10 +213,10 @@ static irqreturn_t as3935_trigger_handler(int irq, void *private)
|
|||
ret = as3935_read(st, AS3935_DATA, &val);
|
||||
if (ret)
|
||||
goto err_read;
|
||||
val &= AS3935_DATA_MASK;
|
||||
val *= 1000;
|
||||
|
||||
iio_push_to_buffers_with_timestamp(indio_dev, &val, pf->timestamp);
|
||||
st->buffer[0] = val & AS3935_DATA_MASK;
|
||||
iio_push_to_buffers_with_timestamp(indio_dev, &st->buffer,
|
||||
pf->timestamp);
|
||||
err_read:
|
||||
iio_trigger_notify_done(indio_dev->trig);
|
||||
|
||||
|
|
|
@ -223,6 +223,8 @@ struct st_sensor_settings {
|
|||
* @get_irq_data_ready: Function to get the IRQ used for data ready signal.
|
||||
* @tf: Transfer function structure used by I/O operations.
|
||||
* @tb: Transfer buffers and mutex used by I/O operations.
|
||||
* @hw_irq_trigger: if we're using the hardware interrupt on the sensor.
|
||||
* @hw_timestamp: Latest timestamp from the interrupt handler, when in use.
|
||||
*/
|
||||
struct st_sensor_data {
|
||||
struct device *dev;
|
||||
|
@ -247,6 +249,9 @@ struct st_sensor_data {
|
|||
|
||||
const struct st_sensor_transfer_function *tf;
|
||||
struct st_sensor_transfer_buffer tb;
|
||||
|
||||
bool hw_irq_trigger;
|
||||
s64 hw_timestamp;
|
||||
};
|
||||
|
||||
#ifdef CONFIG_IIO_BUFFER
|
||||
|
@ -260,7 +265,8 @@ int st_sensors_allocate_trigger(struct iio_dev *indio_dev,
|
|||
const struct iio_trigger_ops *trigger_ops);
|
||||
|
||||
void st_sensors_deallocate_trigger(struct iio_dev *indio_dev);
|
||||
|
||||
int st_sensors_validate_device(struct iio_trigger *trig,
|
||||
struct iio_dev *indio_dev);
|
||||
#else
|
||||
static inline int st_sensors_allocate_trigger(struct iio_dev *indio_dev,
|
||||
const struct iio_trigger_ops *trigger_ops)
|
||||
|
@ -271,6 +277,7 @@ static inline void st_sensors_deallocate_trigger(struct iio_dev *indio_dev)
|
|||
{
|
||||
return;
|
||||
}
|
||||
#define st_sensors_validate_device NULL
|
||||
#endif
|
||||
|
||||
int st_sensors_init_sensor(struct iio_dev *indio_dev,
|
||||
|
|
Loading…
Reference in New Issue