41
ring_data = kmalloc(ring->access.get_bytes_per_datum(ring), GFP_KERNEL);
40
ring_data = kmalloc(ring->access->get_bytes_per_datum(ring),
42
42
if (ring_data == NULL) {
46
ret = ring->access.read_last(ring, (u8 *) ring_data);
46
ret = ring->access->read_last(ring, (u8 *) ring_data);
48
48
goto error_free_ring_data;
49
49
/* Need a count of channels prior to this one */
84
82
if (st->id == ad7997 || st->id == ad7998)
85
ad799x_set_scan_mode(st, ring->scan_mask);
87
numvals = ring->scan_count;
89
if (ring->access.set_bytes_per_datum) {
90
d_size = numvals*2 + sizeof(s64);
92
d_size += 8 - (d_size % 8);
93
ring->access.set_bytes_per_datum(ring, d_size);
83
ad7997_8_set_scan_mode(st, ring->scan_mask);
85
st->d_size = ring->scan_count * 2;
87
if (ring->scan_timestamp) {
88
st->d_size += sizeof(s64);
90
if (st->d_size % sizeof(s64))
91
st->d_size += sizeof(s64) - (st->d_size % sizeof(s64));
94
if (indio_dev->ring->access->set_bytes_per_datum)
95
indio_dev->ring->access->set_bytes_per_datum(indio_dev->ring,
100
* ad799x_poll_func_th() th of trigger launched polling to ring buffer
102
* As sampling only occurs on i2c comms occuring, leave timestamping until
103
* then. Some triggers will generate their own time stamp. Currently
104
* there is no way of notifying them when no one cares.
106
static void ad799x_poll_func_th(struct iio_dev *indio_dev, s64 time)
108
struct ad799x_state *st = indio_dev->dev_data;
110
schedule_work(&st->poll_work);
115
* ad799x_poll_bh_to_ring() bh of trigger launched polling to ring buffer
116
* @work_s: the work struct through which this was scheduled
102
* ad799x_trigger_handler() bh of trigger launched polling to ring buffer
118
104
* Currently there is no option in this driver to disable the saving of
119
105
* timestamps within the ring.
120
* I think the one copy of this at a time was to avoid problems if the
121
* trigger was set far too high and the reads then locked up the computer.
123
static void ad799x_poll_bh_to_ring(struct work_struct *work_s)
108
static irqreturn_t ad799x_trigger_handler(int irq, void *p)
125
struct ad799x_state *st = container_of(work_s, struct ad799x_state,
127
struct iio_dev *indio_dev = st->indio_dev;
110
struct iio_poll_func *pf = p;
111
struct iio_dev *indio_dev = pf->private_data;
112
struct ad799x_state *st = iio_dev_get_devdata(indio_dev);
128
113
struct iio_ring_buffer *ring = indio_dev->ring;
129
struct iio_sw_ring_buffer *ring_sw = iio_to_sw_ring(indio_dev->ring);
136
unsigned long numvals = ring->scan_count;
138
/* Ensure the timestamp is 8 byte aligned */
139
d_size = numvals*2 + sizeof(s64);
141
if (d_size % sizeof(s64))
142
d_size += sizeof(s64) - (d_size % sizeof(s64));
144
/* Ensure only one copy of this function running at a time */
145
if (atomic_inc_return(&st->protect_ring) > 1)
148
/* Monitor mode prevents reading. Whilst not currently implemented
149
* might as well have this test in here in the meantime as it does
155
rxbuf = kmalloc(d_size, GFP_KERNEL);
119
rxbuf = kmalloc(st->d_size, GFP_KERNEL);
156
120
if (rxbuf == NULL)
159
123
switch (st->id) {
179
143
b_sent = i2c_smbus_read_i2c_block_data(st->client,
180
cmd, numvals*2, rxbuf);
144
cmd, ring->scan_count * 2, rxbuf);
184
148
time_ns = iio_get_time_ns();
186
memcpy(rxbuf + d_size - sizeof(s64), &time_ns, sizeof(time_ns));
150
if (ring->scan_timestamp)
151
memcpy(rxbuf + st->d_size - sizeof(s64),
152
&time_ns, sizeof(time_ns));
188
ring->access.store_to(&ring_sw->buf, rxbuf, time_ns);
154
ring->access->store_to(indio_dev->ring, rxbuf, time_ns);
191
atomic_dec(&st->protect_ring);
160
iio_trigger_notify_done(indio_dev->trig);
165
static const struct iio_ring_setup_ops ad799x_buf_setup_ops = {
166
.preenable = &ad799x_ring_preenable,
167
.postenable = &iio_triggered_ring_postenable,
168
.predisable = &iio_triggered_ring_predisable,
195
171
int ad799x_register_ring_funcs_and_init(struct iio_dev *indio_dev)
197
struct ad799x_state *st = indio_dev->dev_data;
200
175
indio_dev->ring = iio_sw_rb_allocate(indio_dev);
205
180
/* Effectively select the ring buffer implementation */
206
iio_ring_sw_register_funcs(&st->indio_dev->ring->access);
207
ret = iio_alloc_pollfunc(indio_dev, NULL, &ad799x_poll_func_th);
181
indio_dev->ring->access = &ring_sw_access_funcs;
182
indio_dev->pollfunc = iio_alloc_pollfunc(NULL,
183
&ad799x_trigger_handler,
189
if (indio_dev->pollfunc == NULL) {
209
191
goto error_deallocate_sw_rb;
211
194
/* Ring buffer functions - here trigger setup related */
213
indio_dev->ring->preenable = &ad799x_ring_preenable;
214
indio_dev->ring->postenable = &iio_triggered_ring_postenable;
215
indio_dev->ring->predisable = &iio_triggered_ring_predisable;
217
INIT_WORK(&st->poll_work, &ad799x_poll_bh_to_ring);
219
indio_dev->ring->scan_el_attrs = st->chip_info->scan_attrs;
195
indio_dev->ring->setup_ops = &ad799x_buf_setup_ops;
196
indio_dev->ring->scan_timestamp = true;
221
198
/* Flag that polled ring buffering is possible */
222
199
indio_dev->modes |= INDIO_RING_TRIGGERED;
224
202
error_deallocate_sw_rb:
225
203
iio_sw_rb_free(indio_dev->ring);