Reputation: 412
I have a driver that supports multiple devices that aren't identical but are similar. I'm doing this so that the same library APIs can be used when writing apps for the devices.
Is there a way to specify which particular device to use in an app?
Is it possible to make an ioctl call before an open call in order to set which particular device gets used the next time open is called?
Upvotes: 0
Views: 602
Reputation: 86353
The common way to deal with this issue is to have a separate device node in /dev/
for each device and have your driver provide an ioctl()
that would return identification information for the corresponding device such as vendor, model and serial number. That would allow a userspace application to tell different devices apart. Depending on your exact needs, a few accompanying entries in sysfs
(/sys
) might also make sense.
You might want to have a look at some common existing APIs for ideas. For example, the V4L2 API contains the VIDIOC_QUERYCAP ioctl() that provides enough information for an application to be able to tell discrete devices apart.
Upvotes: 1