Merge branch 'clk/mxs-for-3.6' of git://git.linaro.org/people/shawnguo/linux-2.6...
[deliverable/linux.git] / drivers / staging / iio / Documentation / device.txt
CommitLineData
c57f1ba7
JC
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
7cbb7537 11struct iio_dev *indio_dev = iio_device_alloc(sizeof(struct chip_state));
44d8b354
JC
12where chip_state is a structure of local state data for this instance of
13the chip.
c57f1ba7 14
44d8b354 15That data can be accessed using iio_priv(struct iio_dev *)
c57f1ba7 16
44d8b354 17Then fill in the following:
c57f1ba7 18
44d8b354
JC
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.
c57f1ba7 24
44d8b354
JC
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->driver_module:
30 Set to THIS_MODULE. Used to ensure correct ownership
31 of various resources allocate by the core.
44d8b354
JC
32 * info->event_attrs:
33 Attributes used to enable / disable hardware events.
34 * info->attrs:
35 General device attributes. Typically used for the weird
36 and the wonderful bits not covered by the channel specification.
37 * info->read_raw:
38 Raw data reading function. Used for both raw channel access
39 and for associate parameters such as offsets and scales.
40 * info->write_raw:
41 Raw value writing function. Used for writable device values such
42 as DAC values and caliboffset.
43 * info->read_event_config:
44 Typically only set if there are some interrupt lines. This
45 is used to read if an on sensor event detector is enabled.
46 * info->write_event_config:
47 Enable / disable an on sensor event detector.
48 * info->read_event_value:
49 Read value associated with on sensor event detectors. Note that
50 the meaning of the returned value is dependent on the event
51 type.
52 * info->write_event_value:
53 Write the value associated with on sensor event detectors. E.g.
54 a threshold above which an interrupt occurs. Note that the
55 meaning of the value to be set is event type dependant.
c57f1ba7 56
44d8b354
JC
57- indio_dev->modes:
58 Specify whether direct access and / or ring buffer access is supported.
59- indio_dev->ring:
60 An optional associated buffer.
61- indio_dev->pollfunc:
62 Poll function related elements. This controls what occurs when a trigger
4abf6f8b 63 to which this device is attached sends an event.
44d8b354
JC
64- indio_dev->channels:
65 Specification of device channels. Most attributes etc are built
66 form this spec.
67- indio_dev->num_channels:
68 How many channels are there?
c57f1ba7
JC
69
70Once these are set up, a call to iio_device_register(indio_dev),
71will register the device with the iio core.
72
73Worth noting here is that, if a ring buffer is to be used, it can be
74allocated prior to registering the device with the iio-core, but must
75be registered afterwards (otherwise the whole parentage of devices
76gets confused)
77
51bf00ae 78On remove, iio_device_unregister(indio_dev) will remove the device from
7cbb7537 79the core, and iio_device_free will clean up.
This page took 0.240068 seconds and 5 git commands to generate.