| |
| ---------- Devices and drivers in barebox -------------- |
| |
| We follow a rather simplistic driver model here. There is a struct device which |
| describes a particular device present in the system. A struct driver represents |
| a driver present in the system. Both structs find together via the members |
| 'type' (int) and 'name' (char *). If both members match, the driver's probe |
| function is called with the struct device as argument. People familiar with |
| the Linux platform bus will recognize this behaviour and in fact many things were |
| stolen from there. Some selected members of the structs will be described in this |
| document. |
| Currently all devices and drivers are handled in simple linked lists. When it comes |
| to USB or PCI it may be desirable to have a tree structure, but this may also be |
| unnecessary overhead. |
| |
| struct device |
| ------------- |
| |
| char name[MAX_DRIVER_NAME]; |
| |
| This member (and 'type' described below) is used to match with a driver. This is |
| a descriptive name and could be MPC5XXX_ether or imx_serial. |
| |
| char id[MAX_DRIVER_NAME]; |
| |
| The id is used to uniquely identify a device in the system. The id will show up |
| under /dev/ as the device's name. Usually this is something like eth0 or nor0. |
| |
| void *type_data; |
| |
| Devices of a particular class normaly need to store more information than struct |
| device holds. This entry holds a pointer to the type specific struct. |
| |
| void *priv; |
| |
| Used by the device driver to store private information. |
| |
| void *platform_data; |
| |
| This is used to carry information of board specific data from the board code to the |
| device driver. |
| |
| struct param_d *param; |
| |
| The parameters for this device. See Documentation/parameters.txt for more info. |
| |
| struct driver_d |
| --------------- |
| |
| char name[MAX_DRIVER_NAME]; |
| unsigned long type; |
| |
| See above. |
| |
| int (*probe) (struct device_d *); |
| int (*remove)(struct device_d *); |
| |
| These are called if an instance of a device is found or gone. |
| |
| ssize_t (*read) (struct device_d*, void* buf, size_t count, ulong offset, ulong flags); |
| ssize_t (*write) (struct device_d*, const void* buf, size_t count, ulong offset, ulong flags); |
| |
| The standard read/write functions. These are called as a response to the read/write |
| system calls. No driver needs to implement these. |
| |
| void *type_data; |
| |
| This is somewhat redundant with the type data in struct device. Currently the |
| filesystem implementation uses this field while ethernet drivers use the same |
| field in struct device. Probably one of them should be removed. |
| |
| |