-
Notifications
You must be signed in to change notification settings - Fork 7.6k
drivers: video: common: introduce CCI utilities #87935
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
drivers: video: common: introduce CCI utilities #87935
Conversation
Force-push:
|
64c8e7c
to
ef13afe
Compare
Thanks ! It will help drivers not need to define their own read / write register functions. Each drivers has different type of register address and value:
Does the CCI library will work in all these cases ? Per my observation, Linux also has CCI library but I don't know why (video) drivers still define and use their own read / write function (?). Will we have also modify register functions (to modify only some bit through a mask) ? |
Yes the goal is to offer a replacement for all the custom write functions for compatible sensors. Supported address sizes:
Supported Data sizes:
Supported operations:
|
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.
LGTM (I didn't test the GC2145 part), thanks !
BTW, in order to use the CCI read/write/modify functions, we need to convert all the register addresses to 32-bit:
For drivers that uses dozens or hundreds of registers, it seems rather a significant amount of memory. Should it be better if we take these additional information as function parameters (maybe separate functions for 8bit, 16bit, 24 bit registers) and/or as a config (LE or BE does not change on a platform) instead of encoding all of them in the address parameter ? |
The flags are forced o be 32-bit here but good to clear any doubt through an obvious syntax.
For instance, for the The first implementation (unpublished) used 7 variants (write8, write16le, write16be, write24le, write24be, write32le, write32le), although this does not permit to define table of registers with many . Switching to another strategy that implementation was wrapping the "table" declaration like this: #define VIDEO_REG_ADDR16_DATA24(addr, reg) \
{ (addr) + 0, (reg) >> 16 }, \
{ (addr) + 1, (reg) >> 8 }, \
{ (addr) + 2, (reg) >> 0 }
struct { uint16_t addr; uint8_t data; } init_regs[] = {
VIDEO_REG_ADDR16_DATA24(0x3008, 0xaabbcc),
IMX335_REG8(0x3016, 0),
IMX335_REG16(0x3014, 8),
{0},
}; For 16-bit addresses and 24-bit registers:before: 8 bytes [ addr0 | addr1 | | | data0 | data1 | data2 | ] 4 + 4 after: 16 bytes: [ addr0 | addr1 | data0 | ] 2 + 2
[ addr0 | addr1 | data1 | ] 2 + 2
[ addr0 | addr1 | data2 | ] 2 + 2
[ addr0 | addr1 | data3 | ] 2 + 2 For 8-bit addresses and 8-bit registersA frequent pathological case for small image sensors (8-bit address) with big tables of undocumented register... before: 8 bytes: [ addr0 | addr1 | | | data0 | | | ] 4 + 4 after: 2 bytes: [ addr0 | data0 ] 1 + 1 |
Currently, the There could be variants to cover the compromises to wrap these frequent "big data tables" use-cases, this is only 2 extra types to add:
|
It was a compromise to reduce the API size non-V4L2 embedded developers need to face to avoid too much domain-specific knowledge required for writing video drivers:
If another compromise is possible, glad to hear about it, I probably did not think about 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.
Nice work, just a first pass :)
help | ||
If set to 0, only a single write attempt will be done with no retry. | ||
The default is to not retry. Board configuration files or user project can then | ||
use the number of retries that matches their situation. |
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.
What is the reason for not retry as default?
I2C usage on video is synchronous so a retry presence here would add a level of robustness.
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.
For me this does not matter much, as it can be overridden easily by boards and users.
@avolmat-st I remember you discussing about the RETRY, do you have more insights on that topic?
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 I agree that this is the good place to put the retry feature but so far I have actually seen no case where such retry is necessary. It is really board dependent I think so what would be the reason for introducing such retry by default ? If there is a HW issue or so leading to those transmit failure, better first notice them and add a retry only if necessary no ?
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.
Makes sense for me now, there is no point to put a retry without undestand the potential source of failure which is hardware dependent.
Feel free to resolve that @josuah :)
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.
Makes sense for me now, there is no point to put a retry without undestand the potential source of failure which is hardware dependent.
Feel free to resolve that @josuah :)
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.
If putting it the default, then it might be better to put a warning when a retry happens or something to raise awareness of the user that a retry happened (i.e. something else could be going wrong).
It might be possible to start at zero and let the boards decide as they are contributed. If most ends-up wanting a retry, the default better be increased to reduce the amount of config in boards.
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.
Maybe the strategy of users would be different during development (notice the slightest issue, hardware or software related, with CONFIG_ASSERT=y
) and production builds (take some margin to cover for unexpected EMI that might happen in the field far from the engineer supervision)... That sounds like a broader topic than this PR though (i.e. I2C-wise?) as if image sensor I2C communication fails, so might other sensors.
@kartben could you have a look at this PR so that we could merge it if ok since it is a dependency of several other PR. Thanks ;) |
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.
Pull Request Overview
This PR introduces Camera Control Interface (CCI) utilities in the video driver module to support I2C-based configuration of camera sensors. Key changes include:
- Addition of a new header (video_common.h) defining CCI register and flag macros, plus API prototypes.
- Implementation of CCI functions in video_common.c with retry logic and endianness handling.
- Addition of a Kconfig option (VIDEO_I2C_RETRY_NUM) for configuring I2C retry attempts.
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
File | Description |
---|---|
drivers/video/video_common.h | Introduces CCI register structures, macros, and function prototypes for camera control. |
drivers/video/video_common.c | Implements the CCI read, write, modify, and multi-register operations with retry logic. |
drivers/video/Kconfig | Adds a new configuration option controlling the number of I2C communication retries. |
Comments suppressed due to low confidence (2)
drivers/video/video_common.c:263
- The parameter name 'data' in the implementation does not match the header's 'reg_value'. Consider renaming it to 'reg_value' for consistency.
int video_write_cci_reg(const struct i2c_dt_spec *i2c, uint32_t reg_addr, uint32_t data)
drivers/video/video_common.c:198
- The parameter name 'data' differs from the header's 'reg_value'. Aligning these names would improve clarity.
int video_read_cci_reg(const struct i2c_dt_spec *i2c, uint32_t reg_addr, uint32_t *data)
drivers/video/video_common.h
Outdated
* @brief Register for building tables supporting 8/16 bit address and 8/16/24/32 bit value sizes. | ||
* | ||
* A flag in the address indicates the size of the register address, and the size and endinaness of | ||
* thevalue. |
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.
Consider inserting a space to read 'the value' instead of 'thevalue' for improved readability in the comment.
* thevalue. | |
* the value. |
Copilot uses AI. Check for mistakes.
The blocking PR was about a copilot review, which we can trigger independently, so let's go with it then dismiss the stale change request once Copilot review is addressed. :)
|
Force-push:
|
71d8a7f
Force-push:
Tested via #87937 just rebased on top of it. |
The change request was based on Copilot feedback. This was addressed and Copilot feedback was requested again, and new changes were addressed again.
I suppose this means your change request was addressed (+3 days) and a new change request is welcome for new topics.
drivers/video/video_common.h
Outdated
/** | ||
* @brief Register for building tables supporting 8/16 bit address and 8/16/24/32 bit value sizes. | ||
* | ||
* A flag in the address indicates the size of the register address, and the size and endinaness of |
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.
Very very minor typo, spotted while checking the very last update via the compare.
endinaness -> endianness
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.
Thank you, much easier to fix now than in subsequent PRs.
Add a library for the Camera Common Interface, part of the MIPI CSI protocol standard defining methods to configure a camera device over I2C, such as which size for the register address/data. Signed-off-by: Josuah Demangeon <me@josuah.net>
|
No dependency. Split out of:
Downstream:
Add a library for the Camera Common Interface, part of the MIPI CSI protocol standard defining methods to configure a camera device over I2C, such as which size for the register address/data.
This is applied to the GC2145 image sensor. Ping @uLipe @iabdalkader who last worked with it.
Also tested with an IMX219 and the emulated video imager, not part of this PR.