|
@@ -150,38 +150,40 @@ ssize_t lis3l02dq_read_accel_from_ring(struct device *dev,
|
|
int ret, len = 0, i = 0;
|
|
int ret, len = 0, i = 0;
|
|
struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
|
|
struct iio_dev_attr *this_attr = to_iio_dev_attr(attr);
|
|
struct iio_dev *dev_info = dev_get_drvdata(dev);
|
|
struct iio_dev *dev_info = dev_get_drvdata(dev);
|
|
|
|
+ struct iio_ring_buffer *ring = dev_info->ring;
|
|
|
|
+ struct attribute_group *scan_el_attrs = ring->scan_el_attrs;
|
|
s16 *data;
|
|
s16 *data;
|
|
|
|
|
|
- while (dev_info->scan_el_attrs->attrs[i]) {
|
|
|
|
|
|
+ while (scan_el_attrs->attrs[i]) {
|
|
el = to_iio_scan_el((struct device_attribute *)
|
|
el = to_iio_scan_el((struct device_attribute *)
|
|
- (dev_info->scan_el_attrs->attrs[i]));
|
|
|
|
|
|
+ (scan_el_attrs->attrs[i]));
|
|
/* label is in fact the address */
|
|
/* label is in fact the address */
|
|
if (el->label == this_attr->address)
|
|
if (el->label == this_attr->address)
|
|
break;
|
|
break;
|
|
i++;
|
|
i++;
|
|
}
|
|
}
|
|
- if (!dev_info->scan_el_attrs->attrs[i]) {
|
|
|
|
|
|
+ if (!scan_el_attrs->attrs[i]) {
|
|
ret = -EINVAL;
|
|
ret = -EINVAL;
|
|
goto error_ret;
|
|
goto error_ret;
|
|
}
|
|
}
|
|
/* If this element is in the scan mask */
|
|
/* If this element is in the scan mask */
|
|
- ret = iio_scan_mask_query(dev_info, el->number);
|
|
|
|
|
|
+ ret = iio_scan_mask_query(ring, el->number);
|
|
if (ret < 0)
|
|
if (ret < 0)
|
|
goto error_ret;
|
|
goto error_ret;
|
|
if (ret) {
|
|
if (ret) {
|
|
- data = kmalloc(dev_info->ring->access.get_bytes_per_datum(dev_info->ring),
|
|
|
|
|
|
+ data = kmalloc(ring->access.get_bytes_per_datum(ring),
|
|
GFP_KERNEL);
|
|
GFP_KERNEL);
|
|
if (data == NULL)
|
|
if (data == NULL)
|
|
return -ENOMEM;
|
|
return -ENOMEM;
|
|
- ret = dev_info->ring->access.read_last(dev_info->ring,
|
|
|
|
- (u8 *)data);
|
|
|
|
|
|
+ ret = ring->access.read_last(ring,
|
|
|
|
+ (u8 *)data);
|
|
if (ret)
|
|
if (ret)
|
|
goto error_free_data;
|
|
goto error_free_data;
|
|
} else {
|
|
} else {
|
|
ret = -EINVAL;
|
|
ret = -EINVAL;
|
|
goto error_ret;
|
|
goto error_ret;
|
|
}
|
|
}
|
|
- len = iio_scan_mask_count_to_right(dev_info, el->number);
|
|
|
|
|
|
+ len = iio_scan_mask_count_to_right(ring, el->number);
|
|
if (len < 0) {
|
|
if (len < 0) {
|
|
ret = len;
|
|
ret = len;
|
|
goto error_free_data;
|
|
goto error_free_data;
|
|
@@ -211,11 +213,12 @@ static const u8 read_all_tx_array[] = {
|
|
**/
|
|
**/
|
|
static int lis3l02dq_read_all(struct lis3l02dq_state *st, u8 *rx_array)
|
|
static int lis3l02dq_read_all(struct lis3l02dq_state *st, u8 *rx_array)
|
|
{
|
|
{
|
|
|
|
+ struct iio_ring_buffer *ring = st->help.indio_dev->ring;
|
|
struct spi_transfer *xfers;
|
|
struct spi_transfer *xfers;
|
|
struct spi_message msg;
|
|
struct spi_message msg;
|
|
int ret, i, j = 0;
|
|
int ret, i, j = 0;
|
|
|
|
|
|
- xfers = kzalloc((st->help.indio_dev->scan_count) * 2
|
|
|
|
|
|
+ xfers = kzalloc((ring->scan_count) * 2
|
|
* sizeof(*xfers), GFP_KERNEL);
|
|
* sizeof(*xfers), GFP_KERNEL);
|
|
if (!xfers)
|
|
if (!xfers)
|
|
return -ENOMEM;
|
|
return -ENOMEM;
|
|
@@ -223,7 +226,7 @@ static int lis3l02dq_read_all(struct lis3l02dq_state *st, u8 *rx_array)
|
|
mutex_lock(&st->buf_lock);
|
|
mutex_lock(&st->buf_lock);
|
|
|
|
|
|
for (i = 0; i < ARRAY_SIZE(read_all_tx_array)/4; i++) {
|
|
for (i = 0; i < ARRAY_SIZE(read_all_tx_array)/4; i++) {
|
|
- if (st->help.indio_dev->scan_mask & (1 << i)) {
|
|
|
|
|
|
+ if (ring->scan_mask & (1 << i)) {
|
|
/* lower byte */
|
|
/* lower byte */
|
|
xfers[j].tx_buf = st->tx + 2*j;
|
|
xfers[j].tx_buf = st->tx + 2*j;
|
|
st->tx[2*j] = read_all_tx_array[i*4];
|
|
st->tx[2*j] = read_all_tx_array[i*4];
|
|
@@ -251,7 +254,7 @@ static int lis3l02dq_read_all(struct lis3l02dq_state *st, u8 *rx_array)
|
|
* values in alternate bytes
|
|
* values in alternate bytes
|
|
*/
|
|
*/
|
|
spi_message_init(&msg);
|
|
spi_message_init(&msg);
|
|
- for (j = 0; j < st->help.indio_dev->scan_count * 2; j++)
|
|
|
|
|
|
+ for (j = 0; j < ring->scan_count * 2; j++)
|
|
spi_message_add_tail(&xfers[j], &msg);
|
|
spi_message_add_tail(&xfers[j], &msg);
|
|
|
|
|
|
ret = spi_sync(st->us, &msg);
|
|
ret = spi_sync(st->us, &msg);
|
|
@@ -279,13 +282,13 @@ static int lis3l02dq_get_ring_element(struct iio_sw_ring_helper_state *h,
|
|
u8 *rx_array ;
|
|
u8 *rx_array ;
|
|
s16 *data = (s16 *)buf;
|
|
s16 *data = (s16 *)buf;
|
|
|
|
|
|
- rx_array = kzalloc(4 * (h->indio_dev->scan_count), GFP_KERNEL);
|
|
|
|
|
|
+ rx_array = kzalloc(4 * (h->indio_dev->ring->scan_count), GFP_KERNEL);
|
|
if (rx_array == NULL)
|
|
if (rx_array == NULL)
|
|
return -ENOMEM;
|
|
return -ENOMEM;
|
|
ret = lis3l02dq_read_all(lis3l02dq_h_to_s(h), rx_array);
|
|
ret = lis3l02dq_read_all(lis3l02dq_h_to_s(h), rx_array);
|
|
if (ret < 0)
|
|
if (ret < 0)
|
|
return ret;
|
|
return ret;
|
|
- for (i = 0; i < h->indio_dev->scan_count; i++)
|
|
|
|
|
|
+ for (i = 0; i < h->indio_dev->ring->scan_count; i++)
|
|
data[i] = combine_8_to_16(rx_array[i*4+1],
|
|
data[i] = combine_8_to_16(rx_array[i*4+1],
|
|
rx_array[i*4+3]);
|
|
rx_array[i*4+3]);
|
|
kfree(rx_array);
|
|
kfree(rx_array);
|
|
@@ -481,14 +484,7 @@ int lis3l02dq_configure_ring(struct iio_dev *indio_dev)
|
|
struct iio_sw_ring_helper_state *h = iio_dev_get_devdata(indio_dev);
|
|
struct iio_sw_ring_helper_state *h = iio_dev_get_devdata(indio_dev);
|
|
struct iio_ring_buffer *ring;
|
|
struct iio_ring_buffer *ring;
|
|
INIT_WORK(&h->work_trigger_to_ring, lis3l02dq_trigger_bh_to_ring);
|
|
INIT_WORK(&h->work_trigger_to_ring, lis3l02dq_trigger_bh_to_ring);
|
|
- /* Set default scan mode */
|
|
|
|
h->get_ring_element = &lis3l02dq_get_ring_element;
|
|
h->get_ring_element = &lis3l02dq_get_ring_element;
|
|
- iio_scan_mask_set(indio_dev, iio_scan_el_accel_x.number);
|
|
|
|
- iio_scan_mask_set(indio_dev, iio_scan_el_accel_y.number);
|
|
|
|
- iio_scan_mask_set(indio_dev, iio_scan_el_accel_z.number);
|
|
|
|
- indio_dev->scan_timestamp = true;
|
|
|
|
-
|
|
|
|
- indio_dev->scan_el_attrs = &lis3l02dq_scan_el_group;
|
|
|
|
|
|
|
|
ring = iio_sw_rb_allocate(indio_dev);
|
|
ring = iio_sw_rb_allocate(indio_dev);
|
|
if (!ring)
|
|
if (!ring)
|
|
@@ -498,11 +494,18 @@ int lis3l02dq_configure_ring(struct iio_dev *indio_dev)
|
|
/* Effectively select the ring buffer implementation */
|
|
/* Effectively select the ring buffer implementation */
|
|
iio_ring_sw_register_funcs(&ring->access);
|
|
iio_ring_sw_register_funcs(&ring->access);
|
|
ring->bpe = 2;
|
|
ring->bpe = 2;
|
|
|
|
+ ring->scan_el_attrs = &lis3l02dq_scan_el_group;
|
|
|
|
+ ring->scan_timestamp = true;
|
|
ring->preenable = &iio_sw_ring_preenable;
|
|
ring->preenable = &iio_sw_ring_preenable;
|
|
ring->postenable = &iio_triggered_ring_postenable;
|
|
ring->postenable = &iio_triggered_ring_postenable;
|
|
ring->predisable = &iio_triggered_ring_predisable;
|
|
ring->predisable = &iio_triggered_ring_predisable;
|
|
ring->owner = THIS_MODULE;
|
|
ring->owner = THIS_MODULE;
|
|
|
|
|
|
|
|
+ /* Set default scan mode */
|
|
|
|
+ iio_scan_mask_set(ring, iio_scan_el_accel_x.number);
|
|
|
|
+ iio_scan_mask_set(ring, iio_scan_el_accel_y.number);
|
|
|
|
+ iio_scan_mask_set(ring, iio_scan_el_accel_z.number);
|
|
|
|
+
|
|
ret = iio_alloc_pollfunc(indio_dev, NULL, &lis3l02dq_poll_func_th);
|
|
ret = iio_alloc_pollfunc(indio_dev, NULL, &lis3l02dq_poll_func_th);
|
|
if (ret)
|
|
if (ret)
|
|
goto error_iio_sw_rb_free;;
|
|
goto error_iio_sw_rb_free;;
|