提交 1139df53 编写于 作者: M Michael Hennerich 提交者: Greg Kroah-Hartman

staging: iio: adc: ad799x miscellaneous cleanups

-Simplify by using iio_alloc_pollfunc helper function
-Print in_scale in decimal format.
-Simplify ring pointer dereferences
Signed-off-by: NMichael Hennerich <michael.hennerich@analog.com>
Acked-by: NJonathan Cameron <jic23@cam.ac.uk>
Signed-off-by: NGreg Kroah-Hartman <gregkh@suse.de>
上级 668413e9
...@@ -428,14 +428,11 @@ static ssize_t ad799x_show_scale(struct device *dev, ...@@ -428,14 +428,11 @@ static ssize_t ad799x_show_scale(struct device *dev,
/* Driver currently only support internal vref */ /* Driver currently only support internal vref */
struct iio_dev *dev_info = dev_get_drvdata(dev); struct iio_dev *dev_info = dev_get_drvdata(dev);
struct ad799x_state *st = iio_dev_get_devdata(dev_info); struct ad799x_state *st = iio_dev_get_devdata(dev_info);
/* Corresponds to Vref / 2^(bits) */ /* Corresponds to Vref / 2^(bits) */
unsigned int scale_uv = (st->int_vref_mv * 1000) >> st->chip_info->bits;
if ((1 << (st->chip_info->bits + 1)) return sprintf(buf, "%d.%d\n", scale_uv / 1000, scale_uv % 1000);
> st->int_vref_mv)
return sprintf(buf, "0.5\n");
else
return sprintf(buf, "%d\n",
st->int_vref_mv >> st->chip_info->bits);
} }
static IIO_DEVICE_ATTR(in_scale, S_IRUGO, ad799x_show_scale, NULL, 0); static IIO_DEVICE_ATTR(in_scale, S_IRUGO, ad799x_show_scale, NULL, 0);
......
...@@ -32,6 +32,7 @@ int ad799x_single_channel_from_ring(struct ad799x_state *st, long mask) ...@@ -32,6 +32,7 @@ int ad799x_single_channel_from_ring(struct ad799x_state *st, long mask)
struct iio_ring_buffer *ring = st->indio_dev->ring; struct iio_ring_buffer *ring = st->indio_dev->ring;
int count = 0, ret; int count = 0, ret;
u16 *ring_data; u16 *ring_data;
if (!(ring->scan_mask & mask)) { if (!(ring->scan_mask & mask)) {
ret = -EBUSY; ret = -EBUSY;
goto error_ret; goto error_ret;
...@@ -70,6 +71,7 @@ int ad799x_single_channel_from_ring(struct ad799x_state *st, long mask) ...@@ -70,6 +71,7 @@ int ad799x_single_channel_from_ring(struct ad799x_state *st, long mask)
**/ **/
static int ad799x_ring_preenable(struct iio_dev *indio_dev) static int ad799x_ring_preenable(struct iio_dev *indio_dev)
{ {
struct iio_ring_buffer *ring = indio_dev->ring;
struct ad799x_state *st = indio_dev->dev_data; struct ad799x_state *st = indio_dev->dev_data;
size_t d_size; size_t d_size;
unsigned long numvals; unsigned long numvals;
...@@ -80,16 +82,15 @@ static int ad799x_ring_preenable(struct iio_dev *indio_dev) ...@@ -80,16 +82,15 @@ static int ad799x_ring_preenable(struct iio_dev *indio_dev)
*/ */
if (st->id == ad7997 || st->id == ad7998) if (st->id == ad7997 || st->id == ad7998)
ad799x_set_scan_mode(st, st->indio_dev->ring->scan_mask); ad799x_set_scan_mode(st, ring->scan_mask);
numvals = st->indio_dev->ring->scan_count; numvals = ring->scan_count;
if (indio_dev->ring->access.set_bytes_per_datum) { if (ring->access.set_bytes_per_datum) {
d_size = numvals*2 + sizeof(s64); d_size = numvals*2 + sizeof(s64);
if (d_size % 8) if (d_size % 8)
d_size += 8 - (d_size % 8); d_size += 8 - (d_size % 8);
indio_dev->ring->access.set_bytes_per_datum(indio_dev->ring, ring->access.set_bytes_per_datum(ring, d_size);
d_size);
} }
return 0; return 0;
...@@ -124,14 +125,15 @@ static void ad799x_poll_bh_to_ring(struct work_struct *work_s) ...@@ -124,14 +125,15 @@ static void ad799x_poll_bh_to_ring(struct work_struct *work_s)
struct ad799x_state *st = container_of(work_s, struct ad799x_state, struct ad799x_state *st = container_of(work_s, struct ad799x_state,
poll_work); poll_work);
struct iio_dev *indio_dev = st->indio_dev; struct iio_dev *indio_dev = st->indio_dev;
struct iio_sw_ring_buffer *ring = iio_to_sw_ring(indio_dev->ring); struct iio_ring_buffer *ring = indio_dev->ring;
struct iio_sw_ring_buffer *ring_sw = iio_to_sw_ring(indio_dev->ring);
s64 time_ns; s64 time_ns;
__u8 *rxbuf; __u8 *rxbuf;
int b_sent; int b_sent;
size_t d_size; size_t d_size;
u8 cmd; u8 cmd;
unsigned long numvals = st->indio_dev->ring->scan_count; unsigned long numvals = ring->scan_count;
/* Ensure the timestamp is 8 byte aligned */ /* Ensure the timestamp is 8 byte aligned */
d_size = numvals*2 + sizeof(s64); d_size = numvals*2 + sizeof(s64);
...@@ -158,14 +160,13 @@ static void ad799x_poll_bh_to_ring(struct work_struct *work_s) ...@@ -158,14 +160,13 @@ static void ad799x_poll_bh_to_ring(struct work_struct *work_s)
case ad7991: case ad7991:
case ad7995: case ad7995:
case ad7999: case ad7999:
cmd = st->config | (st->indio_dev->ring->scan_mask << cmd = st->config | (ring->scan_mask << AD799X_CHANNEL_SHIFT);
AD799X_CHANNEL_SHIFT);
break; break;
case ad7992: case ad7992:
case ad7993: case ad7993:
case ad7994: case ad7994:
cmd = (st->indio_dev->ring->scan_mask << cmd = (ring->scan_mask << AD799X_CHANNEL_SHIFT) |
AD799X_CHANNEL_SHIFT) | AD7998_CONV_RES_REG; AD7998_CONV_RES_REG;
break; break;
case ad7997: case ad7997:
case ad7998: case ad7998:
...@@ -184,7 +185,7 @@ static void ad799x_poll_bh_to_ring(struct work_struct *work_s) ...@@ -184,7 +185,7 @@ static void ad799x_poll_bh_to_ring(struct work_struct *work_s)
memcpy(rxbuf + d_size - sizeof(s64), &time_ns, sizeof(time_ns)); memcpy(rxbuf + d_size - sizeof(s64), &time_ns, sizeof(time_ns));
indio_dev->ring->access.store_to(&ring->buf, rxbuf, time_ns); ring->access.store_to(&ring_sw->buf, rxbuf, time_ns);
done: done:
kfree(rxbuf); kfree(rxbuf);
atomic_dec(&st->protect_ring); atomic_dec(&st->protect_ring);
...@@ -203,14 +204,9 @@ int ad799x_register_ring_funcs_and_init(struct iio_dev *indio_dev) ...@@ -203,14 +204,9 @@ int ad799x_register_ring_funcs_and_init(struct iio_dev *indio_dev)
} }
/* Effectively select the ring buffer implementation */ /* Effectively select the ring buffer implementation */
iio_ring_sw_register_funcs(&st->indio_dev->ring->access); iio_ring_sw_register_funcs(&st->indio_dev->ring->access);
indio_dev->pollfunc = kzalloc(sizeof(*indio_dev->pollfunc), GFP_KERNEL); ret = iio_alloc_pollfunc(indio_dev, NULL, &ad799x_poll_func_th);
if (indio_dev->pollfunc == NULL) { if (ret)
ret = -ENOMEM;
goto error_deallocate_sw_rb; goto error_deallocate_sw_rb;
}
/* Configure the polling function called on trigger interrupts */
indio_dev->pollfunc->poll_func_main = &ad799x_poll_func_th;
indio_dev->pollfunc->private_data = indio_dev;
/* Ring buffer functions - here trigger setup related */ /* Ring buffer functions - here trigger setup related */
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册