/drivers/staging/iio/Documentation/device.txt

https://bitbucket.org/wisechild/galaxy-nexus · Plain Text · 81 lines · 69 code · 12 blank · 0 comment · 0 complexity · 0c0f882f29b708efbd61b19a8dee9bf3 MD5 · raw file

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