-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Description
Some (most) of the drivers for i2c connected and SPI connected devices initialize the bus as a step in their own initialization procedure. I think this is bad practice, at least when more than one device is connected to the same bus.
In my opinion, it only makes sense to initialize the bus in the device driver for the bus slave if the slave device is the only device on the bus, but generally you can connect many devices to the bus and you (as application designer) need to decide on the greatest common subset of parameters which can be combined by looking over all of the bus slaves' parameters with regards to timing, polarity etc.
If this is not properly handled, some bus slaves may just not work at all (best case), or break, or it may bring down the entire bus, or seem fine on the development board, but the same application won't work on a customer's board (very difficult to debug).
I suggest that bus initialization (spi_init_master
, i2c_init_master
) should not be called from the bus slave initialization (e.g. mag3110_init
etc.), and instead be called with a proper set of parameters for the application, before any bus slaves are initialized.
I don't think there is any non-convoluted way of automatically computing the best available parameters given a set of slave devices because of the great variation in different parameters, some devices have both minimum and maximum timings, some can work at either polarity, some can handle high baud rates but need a long idle time between each byte transferred etc. etc.. I think it is best if human application designers handle the bus parameters for the time being.
Opinions on this?