I'm wondering if there's a kernel API that allows one to obtain a struct device
based on a few parameters. I'm using mainline kernel, version 3.3.
Here's the situation:
I have registered platform device A
and set some driver data associated with A. There are multiple instances of A
with different ID's, so A(1), A(2), A(3)...
Now, I am registering platform device B
. The driver for B
needs to own a specific instance of a struct device
associated with A(1)
or A(2)
or
A(3)
...
So think of it like B
owning A(n)
in some way. One way that I could accomplish this is by having the A
driver have a global struct device
array that keeps track of all registered devices. However, with something as generic as platform drivers I'm wondering if the kernel supplies an API to obtain this based on a few parameters such as platform driver
name
and associated id
.
Thanks!
Not sure that it exists. Actually I do not see what parameters can be used to select a struct device
instance.
I think that you have to implement your own search method in the A driver. In the A driver you keep track (global variable) of all instances.
Export from driver A a function find_instance(<parameters>)
and use it in driver B.
If I remember well something similar is in place in the V4L2 framework in order to find I2C devices.