My recent experience with the dwxe driver has emboldened me to look at the sxitwi driver again. A few months ago I worked with Artturi Alm to get the driver working with a driver he wrote for a BME280 sensor. At that time I tested the non-interrupt option (I2C_F_POLL) only. This time I tried the interrupt option as I thought it would be more appropriate in a production situation. The non-interrupt option can tie up the system for periods of time.
My environment is an orange pi one (Allwinner H3) with one BME280 sensor on i2c bus 0 and another on bus 1. Most of my testing was done with a scope on the SDA and SCL lines of bus 0 and printf statements in the drivers. The BME280 driver does a lot of device calibration reading and setup in the attach phase and then reads data once a second into sysctl hw.sensors. My first issue is that the dtb has the i2c busses disabled. So I had to dtc the dtb, enable the busses 0 and 1 and add BME280 sections to the i2c busses. The dtb provides a third i2c bus, but the orange pi one does not bring it out to the header and so it makes no sense to enable it. A serious issue that hindered my testing is that the printf statements in the driver affected the console driver, garbling the output and often stopping all output and input. The output always appeared correctly in the message log file. Even now it seems that the console is affected when the sxitwi driver is in use and there is a lot of other console output. Another item I noticed is that the i2c busses were running at half the standard speed of 100kHz. The comments in the driver code, which are taken right out of the Allwinner doc, set the speed for a 48MHz master clock. However, the orange pi one runs at 24MHz. The sxitwi driver was sprinkled with delays. I took most of them out without any side effects. I added a bus reset function to help in error recovery. In my testing I left the BME280 driver to do device initialization in non-interrupt mode and only changed the cyclic data read to use interrupts. This made testing easier as it is hard to capture something on a scope that happens only on system boot. Also I am not clear if interrupts are working at system boot. It seems that the interrupt controller is set up after the sxitwi controller. It looks like the device status can change after the interrupt is released in the interrupt service routine, sxitwi_intr. Therefore I saved the status for later use when the driver wakes up in sxitwi_wait. To make that work I separated the interrupt and non-interrupt parts of sxitwi_wait and added some recovery code. I took out a lot of the sxitwi_send_stop code because as the comment says "Interrupt is not generated" and there is no need to do anything. The next send start will wait, or for that matter another master on the bus may be trying to do a start and will wait for the stop to complete. I sort of messed up the formatting (tabs spaces?) with all my changes and I hesitate do show a diff. The working code for sxitwi and BNE280 drivers is attached. Is the sxitwi driver used by any other devices other than Allwinner? Is anyone interested in testing my code?
bme280.c
Description: Binary data
sxitwi.c
Description: Binary data