-
Notifications
You must be signed in to change notification settings - Fork 8.2k
drivers: i2c: Introduce basic bflb I2C driver #98364
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
f6169ed to
95cac46
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting to see what's happening with phase0, phase1, phase2, phase3 (timing of individual signal steps of I2C AFAIU).
I would have assumed sys_read32/sys_write32 would have been enough to tell GCC not to shuffle the order of IO register read/write, curious to follow-up on that.
Just proposing reminders about MHZ() but not sure if that's something you even wanted to use (i.e. other I2C drivers don't use them).
2b71baa to
37cdc50
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Extra hardware + bus/protocol error handling added, also LGTM!
Adds i2c binding and nodes Signed-off-by: Camille BAUD <[email protected]>
|
@teburd PTAL |
teburd
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please use kernel primitives for queueing threads rather than looping on hardware busy status.
| return 0; | ||
| } | ||
|
|
||
| while (i2c_bflb_busy(dev) && !sys_timepoint_expired(end_timeout)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
k_sem/k_mutex here instead of busy looping to provide a thread queuing mechanism with a timeout.
e.g.
k_sem_take(data->lock, K_FOREVER);There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not intended for checking thread queuing, it's for bad states. there no thread queuing mechanism, i suppose there should be one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes there should be a semaphore or mutex here on the blocking transfer call to block threads until the hardware is usable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
done
| } | ||
| i += ret; | ||
| end_timeout = sys_timepoint_calc(K_MSEC(I2C_WAIT_TIMEOUT_MS)); | ||
| while ((i2c_bflb_busy(dev) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You have some interrupts it seems to get events from the hardware, tight looping for completions like this is I'd say generally frowned on if you have an interrupt to tell you instead.
Broadly speaking looping over the messages int he thread context, sending, waiting, repeat isn't workable with any other I2C API (submit) which means supporting this device with sensors will involve a fallback mechanism which is less than optimal.
Non-blocking comment but highly recommended.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well it does mostly check the interrupts, are you saying it should set a completion flag from the interrupt instead and semaphore wait for it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You should set a completion flag (semaphore) one time when the entire transfer of i2c_msg array is done. You should not be looping in i2c_transfer ideally.
Writing your driver this way will enable you to add .submit later much easier (highly recommended).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah i see. I am aware of this issue, this is intended to be basic like this, improvement on this angle would be done when/if submit and other async stuffs are implemented, I have no issue rewriting this bit when this will be necessary.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is why its a non-blocking comment, it'd be nice, but its not expected in this PR
Introduce synchronous i2c driver Signed-off-by: Camille BAUD <[email protected]>
Adds I2C tests running Signed-off-by: Camille BAUD <[email protected]>
Fix bad formatting. Signed-off-by: Camille BAUD <[email protected]>
|



No DMA, no async.
Tested on bl602 and bl618.