2019-06-04 10:11:33 +02:00
// SPDX-License-Identifier: GPL-2.0-only
2020-07-16 14:59:16 +01:00
/*
2011-10-14 16:34:15 +01:00
* Copyright ( c ) 2011 Jonathan Cameron
*
* Buffer handling elements of industrial I / O reference driver .
* Uses the kfifo buffer .
*
* To test without hardware use the sysfs trigger .
*/
# include <linux/kernel.h>
2011-07-10 13:09:12 -04:00
# include <linux/export.h>
2011-10-14 16:34:15 +01:00
# include <linux/slab.h>
# include <linux/interrupt.h>
# include <linux/irq.h>
# include <linux/bitmap.h>
2012-04-25 15:54:58 +01:00
# include <linux/iio/iio.h>
2017-01-02 19:28:30 +00:00
# include <linux/iio/buffer.h>
2021-02-15 12:40:37 +02:00
# include <linux/iio/trigger_consumer.h>
# include <linux/iio/triggered_buffer.h>
2011-10-14 16:34:15 +01:00
# include "iio_simple_dummy.h"
/* Some fake data */
static const s16 fakedata [ ] = {
2015-10-26 13:48:23 -07:00
[ DUMMY_INDEX_VOLTAGE_0 ] = 7 ,
[ DUMMY_INDEX_DIFFVOLTAGE_1M2 ] = - 33 ,
[ DUMMY_INDEX_DIFFVOLTAGE_3M4 ] = - 2 ,
[ DUMMY_INDEX_ACCELX ] = 344 ,
2011-10-14 16:34:15 +01:00
} ;
2015-07-10 17:10:21 +03:00
2011-10-14 16:34:15 +01:00
/**
* iio_simple_dummy_trigger_h ( ) - the trigger handler function
* @ irq : the interrupt number
* @ p : private data - always a pointer to the poll func .
*
2012-05-09 03:18:17 +09:00
* This is the guts of buffered capture . On a trigger event occurring ,
2011-10-14 16:34:15 +01:00
* if the pollfunc is attached then this handler is called as a threaded
* interrupt ( and hence may sleep ) . It is responsible for grabbing data
* from the device and pushing it into the associated buffer .
*/
static irqreturn_t iio_simple_dummy_trigger_h ( int irq , void * p )
{
struct iio_poll_func * pf = p ;
struct iio_dev * indio_dev = pf - > indio_dev ;
2022-02-09 10:28:16 -08:00
int i = 0 , j ;
2012-04-21 10:09:35 +01:00
u16 * data ;
data = kmalloc ( indio_dev - > scan_bytes , GFP_KERNEL ) ;
2015-03-31 12:51:38 +03:00
if ( ! data )
2012-07-04 17:09:00 +01:00
goto done ;
2011-10-14 16:34:15 +01:00
2022-02-09 10:28:16 -08:00
/*
* Three common options here :
* hardware scans :
* certain combinations of channels make up a fast read . The capture
* will consist of all of them . Hence we just call the grab data
* function and fill the buffer without processing .
* software scans :
* can be considered to be random access so efficient reading is just
* a case of minimal bus transactions .
* software culled hardware scans :
* occasionally a driver may process the nearest hardware scan to avoid
* storing elements that are not desired . This is the fiddliest option
* by far .
* Here let ' s pretend we have random access . And the values are in the
* constant table fakedata .
*/
for_each_set_bit ( j , indio_dev - > active_scan_mask , indio_dev - > masklength )
data [ i + + ] = fakedata [ j ] ;
2013-09-19 14:00:00 +01:00
2016-03-09 19:05:49 +01:00
iio_push_to_buffers_with_timestamp ( indio_dev , data ,
iio_get_time_ns ( indio_dev ) ) ;
2011-10-14 16:34:15 +01:00
kfree ( data ) ;
2012-07-04 17:09:00 +01:00
done :
2011-10-14 16:34:15 +01:00
/*
* Tell the core we are done with this trigger and ready for the
* next one .
*/
iio_trigger_notify_done ( indio_dev - > trig ) ;
return IRQ_HANDLED ;
}
static const struct iio_buffer_setup_ops iio_simple_dummy_buffer_setup_ops = {
} ;
2014-11-26 18:55:11 +01:00
int iio_simple_dummy_configure_buffer ( struct iio_dev * indio_dev )
2011-10-14 16:34:15 +01:00
{
2021-02-15 12:40:37 +02:00
return iio_triggered_buffer_setup ( indio_dev , NULL ,
iio_simple_dummy_trigger_h ,
& iio_simple_dummy_buffer_setup_ops ) ;
2011-10-14 16:34:15 +01:00
}
/**
* iio_simple_dummy_unconfigure_buffer ( ) - release buffer resources
2020-07-16 14:59:16 +01:00
* @ indio_dev : device instance state
2011-10-14 16:34:15 +01:00
*/
void iio_simple_dummy_unconfigure_buffer ( struct iio_dev * indio_dev )
{
2021-02-15 12:40:37 +02:00
iio_triggered_buffer_cleanup ( indio_dev ) ;
2011-10-14 16:34:15 +01:00
}