1IIO Device drivers
2
3This is not intended to provide a comprehensive guide to writing an
4IIO device driver.  For further information see the drivers within the
5subsystem.
6
7The crucial structure for device drivers in iio is iio_dev.
8
9First allocate one using:
10
11struct iio_dev *indio_dev = iio_device_alloc(sizeof(struct chip_state));
12where chip_state is a structure of local state data for this instance of
13the chip.
14
15That data can be accessed using iio_priv(struct iio_dev *).
16
17Then fill in the following:
18
19- indio_dev->dev.parent
20	Struct device associated with the underlying hardware.
21- indio_dev->name
22	Name of the device being driven - made available as the name
23	attribute in sysfs.
24
25- indio_dev->info
26	pointer to a structure with elements that tend to be fixed for
27	large sets of different parts supported by a given driver.
28	This contains:
29	* info->event_attrs:
30		Attributes used to enable / disable hardware events.
31	* info->attrs:
32		General device attributes. Typically used for the weird
33		and the wonderful bits not covered by the channel specification.
34	* info->read_raw:
35		Raw data reading function. Used for both raw channel access
36		and for associate parameters such as offsets and scales.
37	* info->write_raw:
38		Raw value writing function. Used for writable device values such
39		as DAC values and calibbias.
40	* info->read_event_config:
41		Typically only set if there are some interrupt lines.  This
42		is used to read if an on sensor event detector is enabled.
43	* info->write_event_config:
44		Enable / disable an on sensor event detector.
45	* info->read_event_value:
46		Read value associated with on sensor event detectors. Note that
47		the meaning of the returned value is dependent on the event
48		type.
49	* info->write_event_value:
50		Write the value associated with on sensor event detectors. E.g.
51		a threshold above which an interrupt occurs.  Note that the
52		meaning of the value to be set is event type dependent.
53
54- indio_dev->modes:
55	Specify whether direct access and / or ring buffer access is supported.
56- indio_dev->buffer:
57	An optional associated buffer.
58- indio_dev->pollfunc:
59	Poll function related elements. This controls what occurs when a trigger
60	to which this device is attached sends an event.
61- indio_dev->channels:
62	Specification of device channels. Most attributes etc. are built
63	from this spec.
64- indio_dev->num_channels:
65	How many channels are there?
66
67Once these are set up, a call to iio_device_register(indio_dev)
68will register the device with the iio core.
69
70Worth noting here is that, if a ring buffer is to be used, it can be
71allocated prior to registering the device with the iio-core, but must
72be registered afterwards (otherwise the whole parentage of devices
73gets confused)
74
75On remove, iio_device_unregister(indio_dev) will remove the device from
76the core, and iio_device_free(indio_dev) will clean up.
77