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_allocate_device(); 12 13Then fill in the following: 14 15indio_dev->dev.parent 16 the struct device associated with the underlying hardware. 17 18indio_dev->num_interrupt_lines 19 number of event triggering hardware lines the device has. 20 21indio_dev->event_attrs 22 attributes used to enable / disable hardware events - note the 23 attributes are embedded in iio_event_attr structures with an 24 associated iio_event_handler which may or may note be shared. 25 If num_interrupt_lines = 0, then no need to fill this in. 26 27indio_dev->attrs 28 general attributes such as polled access to device channels. 29 30indio_dev->dev_data 31 private device specific data. 32 33indio_dev->driver_module 34 typically set to THIS_MODULE. Used to specify ownership of some 35 iio created resources. 36 37indio_dev->modes 38 whether direct access and / or ring buffer access is supported. 39 40Once these are set up, a call to iio_device_register(indio_dev), 41will register the device with the iio core. 42 43Worth noting here is that, if a ring buffer is to be used, it can be 44allocated prior to registering the device with the iio-core, but must 45be registered afterwards (otherwise the whole parentage of devices 46gets confused) 47 48On remove, iio_device_unregister(indio_dev) will remove the device from 49the core, and iio_free_device will clean up. 50