I've made a driver that is an Industrial I/O (IIO) "producer" (it provides ADC readings). I've compiled it as a module. I've got another driver that is an IIO "consumer" that uses an ADC input from the first driver (it calls iio_channel_get()
in its probe()
function).
Both these drivers are compiled as modules, and they work fine together. But I've found that it's possible to rmmod
the first driver, even when the second driver is loaded and thus using its ADC, which seems surprising because it's "in use" by the second driver. What would be great is to prevent the first driver being unloaded while the second driver is using it. That is, increment the first module's refcnt
when the second driver calls iio_channel_get()
, and decrement the refcnt
when the second driver calls iio_channel_release()
. This would be conceptually similar to a module for a char device, which has its refcnt
incremented for each process that has it open—so it can't be unloaded until all processes have closed the char device file open.
But I can't see a way to achieve this for an IIO producer (e.g. I can't see any ops function that might be called when the second driver calls iio_channel_get()
). How could that be done?
Note, this is not a module dependency in the classical sense, where one module depends on functions/symbols provided by another module. It's an IIO consumer/producer dependency. The dependency from one to the other is hardware-specific, and is specified in the device tree for the hardware. On different hardware, the consumer/producer dependency could involve a different IIO producer module.