// SPDX-License-Identifier: GPL-2.0-only /* * Copyright (c) 2011 Jonathan Cameron * * A reference industrial I/O driver to illustrate the functionality available. * * There are numerous real drivers to illustrate the finer points. * The purpose of this driver is to provide a driver with far more comments * and explanatory notes than any 'real' driver would have. * Anyone starting out writing an IIO driver should first make sure they * understand all of this driver except those bits specifically marked * as being present to allow us to 'fake' the presence of hardware. */ #include <linux/kernel.h> #include <linux/slab.h> #include <linux/module.h> #include <linux/string.h> #include <linux/iio/iio.h> #include <linux/iio/sysfs.h> #include <linux/iio/events.h> #include <linux/iio/buffer.h> #include <linux/iio/sw_device.h> #include "iio_simple_dummy.h" static const struct config_item_type iio_dummy_type = …; /** * struct iio_dummy_accel_calibscale - realworld to register mapping * @val: first value in read_raw - here integer part. * @val2: second value in read_raw etc - here micro part. * @regval: register value - magic device specific numbers. */ struct iio_dummy_accel_calibscale { … }; static const struct iio_dummy_accel_calibscale dummy_scales[] = …; #ifdef CONFIG_IIO_SIMPLE_DUMMY_EVENTS /* * simple event - triggered when value rises above * a threshold */ static const struct iio_event_spec iio_dummy_event = …; /* * simple step detect event - triggered when a step is detected */ static const struct iio_event_spec step_detect_event = …; /* * simple transition event - triggered when the reported running confidence * value rises above a threshold value */ static const struct iio_event_spec iio_running_event = …; /* * simple transition event - triggered when the reported walking confidence * value falls under a threshold value */ static const struct iio_event_spec iio_walking_event = …; #endif /* * iio_dummy_channels - Description of available channels * * This array of structures tells the IIO core about what the device * actually provides for a given channel. */ static const struct iio_chan_spec iio_dummy_channels[] = …; /** * iio_dummy_read_raw() - data read function. * @indio_dev: the struct iio_dev associated with this device instance * @chan: the channel whose data is to be read * @val: first element of returned value (typically INT) * @val2: second element of returned value (typically MICRO) * @mask: what we actually want to read as per the info_mask_* * in iio_chan_spec. */ static int iio_dummy_read_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int *val, int *val2, long mask) { … } /** * iio_dummy_write_raw() - data write function. * @indio_dev: the struct iio_dev associated with this device instance * @chan: the channel whose data is to be written * @val: first element of value to set (typically INT) * @val2: second element of value to set (typically MICRO) * @mask: what we actually want to write as per the info_mask_* * in iio_chan_spec. * * Note that all raw writes are assumed IIO_VAL_INT and info mask elements * are assumed to be IIO_INT_PLUS_MICRO unless the callback write_raw_get_fmt * in struct iio_info is provided by the driver. */ static int iio_dummy_write_raw(struct iio_dev *indio_dev, struct iio_chan_spec const *chan, int val, int val2, long mask) { … } /* * Device type specific information. */ static const struct iio_info iio_dummy_info = …; /** * iio_dummy_init_device() - device instance specific init * @indio_dev: the iio device structure * * Most drivers have one of these to set up default values, * reset the device to known state etc. */ static int iio_dummy_init_device(struct iio_dev *indio_dev) { … } /** * iio_dummy_probe() - device instance probe * @name: name of this instance. * * Arguments are bus type specific. * I2C: iio_dummy_probe(struct i2c_client *client, * const struct i2c_device_id *id) * SPI: iio_dummy_probe(struct spi_device *spi) */ static struct iio_sw_device *iio_dummy_probe(const char *name) { … } /** * iio_dummy_remove() - device instance removal function * @swd: pointer to software IIO device abstraction * * Parameters follow those of iio_dummy_probe for buses. */ static int iio_dummy_remove(struct iio_sw_device *swd) { … } /* * module_iio_sw_device_driver() - device driver registration * * Varies depending on bus type of the device. As there is no device * here, call probe directly. For information on device registration * i2c: * Documentation/i2c/writing-clients.rst * spi: * Documentation/spi/spi-summary.rst */ static const struct iio_sw_device_ops iio_dummy_device_ops = …; static struct iio_sw_device_type iio_dummy_device = …; module_iio_sw_device_driver(…); MODULE_AUTHOR(…) …; MODULE_DESCRIPTION(…) …; MODULE_LICENSE(…) …;