-
Notifications
You must be signed in to change notification settings - Fork 7.3k
Video: addition of the imx335 driver #88825
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
base: main
Are you sure you want to change the base?
Video: addition of the imx335 driver #88825
Conversation
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 awesome and we can even order the module from here.
I did my best to proofread without the datasheet (as often with image sensors, secret).
A few comments in case these were omissions. If these are intentional, please keep them like so!
drivers/video/imx335.c
Outdated
ret = imx335_set_input_clk(dev, MHZ(24)); | ||
if (ret) { | ||
LOG_ERR("Unable to configure INCK"); | ||
return -EIO; |
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.
return -EIO; | |
return ret; |
drivers/video/imx335.c
Outdated
ret = video_write_cci_multi(&cfg->i2c, imx335_mode_2l_10b); | ||
if (ret) { | ||
LOG_ERR("Unable to initialize the sensor"); | ||
return -EIO; |
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.
return -EIO; | |
return ret; |
drivers/video/imx335.c
Outdated
ret = video_write_cci_multi(&cfg->i2c, imx335_init_params); | ||
if (ret) { | ||
LOG_ERR("Unable to initialize the sensor"); | ||
return -EIO; |
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.
return -EIO; | |
return ret; |
drivers/video/imx335.c
Outdated
break; | ||
default: | ||
LOG_ERR("Unsupported inck freq (%d)\n", rate); | ||
return -EIO; |
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.
return -EIO; | |
return -EINVAL; |
If interested in making test of this sensor more easy, it is possible to add the devicetree snippets needed to integrate this sensor with a compatible board via a shield. For instance like these:
Permitting to run |
Thanks for all your comments. I think all of your comments are valid so I will correct the code. |
95979fe
to
442eb3e
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.
LGTM in general. Eager for more features coming in the future (chipID, controls, data lanes, resolution, etc.) :-).
Could you add an entry to https://github.com/zephyrproject-rtos/zephyr/blob/main/tests/drivers/build_all/video/app.overlay so that we can have a minimal built-only CI test. Without it, we cannot detect even only compilation errors. As you can see, the PRs has "passed" CI although it cannot be compiled because of the dependency on #87935.
Thanks
drivers/video/imx335.c
Outdated
static int imx335_set_ctrl_exposure(const struct device *dev, int value) | ||
{ | ||
const struct imx335_config *cfg = dev->config; | ||
uint32_t shutter; | ||
int ret; | ||
|
||
/* Since we never update VMAX, we can use the default value directly */ | ||
shutter = (IMX335_VMAX_DEFAULT - (value / IMX335_1H_PERIOD_USEC)); | ||
if (shutter < IMX335_SHR0_MIN) { | ||
return -EINVAL; | ||
} | ||
|
||
ret = video_write_cci_reg(&cfg->i2c, IMX335_REGHOLD, 1); | ||
if (ret) { | ||
return ret; | ||
} | ||
|
||
ret = video_write_cci_reg(&cfg->i2c, IMX335_SHR0, shutter); | ||
if (ret) { | ||
return ret; | ||
} | ||
|
||
return video_write_cci_reg(&cfg->i2c, IMX335_REGHOLD, 0); | ||
} | ||
|
||
static int imx335_set_ctrl(const struct device *dev, unsigned int cid, void *value) | ||
{ | ||
switch (cid) { | ||
case VIDEO_CID_GAIN: | ||
return imx335_set_ctrl_gain(dev, (int)(value)); | ||
case VIDEO_CID_EXPOSURE: | ||
return imx335_set_ctrl_exposure(dev, (int)(value)); | ||
default: | ||
return -ENOTSUP; | ||
} | ||
} |
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.
Just out of curiosity. In Linux, it seems exposure and gain are clustered (dependent each other). Here, it can be set independently ?
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.
Actually I based this driver on the imx335 driver that is provided with the STM32 HAL.
As far as registers are concerned, gain & exposure aren't really linked to each others. However they both need to be set upon putting the sensor register in hold mode so it can help to set both of them at once to avoid more register access.
I also actually changed another thing which is the range of the exposure. In the previous version I pushed, the exposure was expressed in us, while now it is done in lines, in order to be consistent with the exposure value used in the Linux world.
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.
Thanks for the clarification, just checked in Linux and see they are independent in terms of registers, another interesting usecase of auto-cluster.
Converting to draft until the dependency is merged as suggested earlier. |
I completely forgot to check that the sensor needed to be added to |
Introduction of bindings for the imx335 sensor. Signed-off-by: Alain Volmat <alain.volmat@foss.st.com>
I push a new version of the driver, all rebased on top of the HEAD, meaning top of new ctrl and video dev frameworks. |
442eb3e
to
50bbd8c
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.
Pull Request Overview
This PR introduces a new device tree binding for the Sony IMX335 sensor driver, enabling support for the CMOS sensor with 10-bit operation and a dedicated reset-gpios property.
- Added a YAML binding file with sensor description, compatibility information, and reset-gpios property.
- Defined a child-binding section to include video interface bindings.
Files not reviewed (4)
- drivers/video/CMakeLists.txt: Language not supported
- drivers/video/Kconfig: Language not supported
- drivers/video/Kconfig.imx335: Language not supported
- tests/drivers/build_all/video/app.overlay: Language not supported
drivers/video/imx335.c
Outdated
static int imx335_set_ctrl_exposure(const struct device *dev, int value) | ||
{ | ||
const struct imx335_config *cfg = dev->config; | ||
uint32_t shutter; | ||
int ret; | ||
|
||
/* Since we never update VMAX, we can use the default value directly */ | ||
shutter = (IMX335_VMAX_DEFAULT - (value / IMX335_1H_PERIOD_USEC)); | ||
if (shutter < IMX335_SHR0_MIN) { | ||
return -EINVAL; | ||
} | ||
|
||
ret = video_write_cci_reg(&cfg->i2c, IMX335_REGHOLD, 1); | ||
if (ret) { | ||
return ret; | ||
} | ||
|
||
ret = video_write_cci_reg(&cfg->i2c, IMX335_SHR0, shutter); | ||
if (ret) { | ||
return ret; | ||
} | ||
|
||
return video_write_cci_reg(&cfg->i2c, IMX335_REGHOLD, 0); | ||
} | ||
|
||
static int imx335_set_ctrl(const struct device *dev, unsigned int cid, void *value) | ||
{ | ||
switch (cid) { | ||
case VIDEO_CID_GAIN: | ||
return imx335_set_ctrl_gain(dev, (int)(value)); | ||
case VIDEO_CID_EXPOSURE: | ||
return imx335_set_ctrl_exposure(dev, (int)(value)); | ||
default: | ||
return -ENOTSUP; | ||
} | ||
} |
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.
Thanks for the clarification, just checked in Linux and see they are independent in terms of registers, another interesting usecase of auto-cluster.
50bbd8c
to
f162899
Compare
Actually, doing further tests I noticed an issue with the exposure / analogue_gain control. I might have misunderstood the (auto)-cluster and current code simply lead to not being able to set the exposure correctly. Considering that the application will perform set_ctrl on gain and exposure and their value aren't related, I think they have to be put outside of a cluster. |
Add support for the Sony IMX335 CSI sensor. This sensor supports resolution of 2592x1944 in RGGB bayer format either 10 or 12 bits and using 2 or 4 CSI lanes. For the time being only 10 bits on 2 CSI lanes is supported via this commit. Signed-off-by: Alain Volmat <alain.volmat@foss.st.com>
f162899
to
8290ded
Compare
This PR introduces the CSI IMX335 Sensor driver (5MPix). The sensor supports both 10 and 12 bits bayer format in 2 or 4 csi lanes.
It is based on the CCI helper in order to have a cleaner code.
I kept few TODO within the source code:
This PR depends on #87935