I work with cpu management in big.LITTLE boards and the board on which I am developing on has some ina231 power sensors. Which I believe are handled by the ina2xx_driver (this would make sense to me). My knowledge of drivers is still in development so I am unsure about how I should get the information I need to my CPU module out of the driver/devices, in a way that wont make the Linux gods angry.
The board has 4 sensors which I believe are then stored in the struct i2c_driver
in the linked list struct list_head clients
. If I have understood this correctly, then my initial idea was to export a pointer to the driver
static struct i2c_driver ina2xx_driver = {
.driver = {
.name = "ina2xx",
},
.probe = ina2xx_probe,
.remove = ina2xx_remove,
.id_table = ina2xx_id,
};
+struct i2c_driver *ina2xx_driver_p = &ina2xx_driver;
+EXPORT_SYMBOL(ina2xx_driver_p);
to my module which could then step through the linked list of i2c clients allowing me to access individual device information by doing something like this
struct i2c_client *tmp
struct list_head *pos;
struct list_head *clients_head = &ina2xx_driver_p->clients;
list_for_each(pos, clients_head){
tmp = list_entry(pos, struct i2c_client, detected)
struct ina2xx_data *data = ina2xx_update_device(tmp.dev);
ina2xx_get_value(data, $(attribute));
}
I haven't actually tried this, it's just how I imagine one solution being after reading the header files. Given my lack of knowledge on the recommended practice I thought it would be best to ask before wasting a day or two trying to implement something that is destined to fail.
Is there a more standardized way that is used in the kernel to get device driver or device pointers to access information or way to get device information without reading it from files?
I hope my question makes sense and thanks.
The ina231 sensor on your board is most likely instantiated from DeviceTree. If that is the case, and your driver is also instantiated from DT, then it would be natural to store a phandle to ina231 sensor as a property in your DT node. Then you can use of_find_node_by_phandle()
to get a struct device_node
and then use of_find_i2c_device_by_node
to turn it into struct i2c_client
.
An alternative approach would be to use bus_find_device()
with &i2c_bus_type
as a first argument and using your custom match function
. See the of_find_i2c_device_by_node
implementation as an example on how this could be used.
Note that none of that will be pretty since you are planning on using driver private internal data which itself isn't a nice practice.