media: imx258: Add imx258 camera sensor driver
PATCH v4 1/1 media: imx258: Add imx258 camera sensor driver
Add a V4L2 sub-device driver for the Sony IMX258 image sensor. This is a camera sensor using the I2C bus for control and the CSI-2 bus for data.
---
- v2->v3
-- Update the streaming function to remove SW_STANDBY in the beginning. -- Adjust the delay time from 1ms to 12ms before set stream-on register.
- v3->v4
-- fix the sd.entity to make code be compiled on the mainline kernel. -- " - imx258->sd.entity.type = MEDIA_ENT_T_V4L2_SUBDEV_SENSOR;" -- " + imx258->sd.entity.function = MEDIA_ENT_F_CAM_SENSOR;"
MAINTAINERS | 7 + drivers/media/i2c/Kconfig | 11 + drivers/media/i2c/Makefile | 1 + drivers/media/i2c/imx258.c | 1148 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 1167 insertions(+) create mode 100644 drivers/media/i2c/imx258.c
MAINTAINERS +7 -0
@@ -12640,6 +12640,13 @@ S: Maintained F: drivers/ssb/ F: include/linux/ssb/ +SONY IMX258 SENSOR DRIVER +M: Sakari Ailus <[email protected]> +L: [email protected] +T: git git://linuxtv.org/media_tree.git +S: Maintained +F: drivers/media/i2c/imx258.c + SONY IMX274 SENSOR DRIVER M: Leon Luo <[email protected]> L: [email protected]
drivers/media/i2c/Kconfig +11 -0
@@ -555,6 +555,17 @@ config VIDEO_APTINA_PLL config VIDEO_SMIAPP_PLL tristate +config VIDEO_IMX258 + tristate "Sony IMX258 sensor support" + depends on I2C && VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API + depends on MEDIA_CAMERA_SUPPORT + ---help--- + This is a Video4Linux2 sensor-level driver for the Sony + IMX258 camera. + + To compile this driver as a module, choose M here: the + module will be called imx258. + config VIDEO_IMX274 tristate "Sony IMX274 sensor support" depends on I2C && VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API
drivers/media/i2c/Makefile +1 -0
@@ -93,6 +93,7 @@ obj-$(CONFIG_VIDEO_IR_I2C) += ir-kbd-i2c.o obj-$(CONFIG_VIDEO_ML86V7667) += ml86v7667.o obj-$(CONFIG_VIDEO_OV2659) += ov2659.o obj-$(CONFIG_VIDEO_TC358743) += tc358743.o +obj-$(CONFIG_VIDEO_IMX258) += imx258.o obj-$(CONFIG_VIDEO_IMX274) += imx274.o obj-$(CONFIG_SDR_MAX2175) += max2175.o
drivers/media/i2c/imx258.c new file +1148 -0
1,148 lines not on this page · raw message
Signature · 1 line
2.7.4
Hi Andy,
Thanks for the patch. Please see my comments inline.
Quoted 20 lines · Andy Yeh
Add a V4L2 sub-device driver for the Sony IMX258 image sensor. This is a camera sensor using the I2C bus for control and the CSI-2 bus for data.
Signed-off-by Andy Yeh <[email protected]>---
-v2->v3
-- Update the streaming function to removeSW_STANDBYin the beginning. -- Adjust the delay time from 1ms to 12ms before set stream-on register.
-v3->v4
-- fix the sd.entity to make code be compiled on the mainline kernel. -- " -imx258->sd.entity.type=MEDIA_ENT_T_V4L2_SUBDEV_SENSOR;" -- " +imx258->sd.entity.function=MEDIA_ENT_F_CAM_SENSOR;"MAINTAINERS | 7 + drivers/media/i2c/Kconfig | 11 + drivers/media/i2c/Makefile | 1 + drivers/media/i2c/imx258.c | 1148 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 1167 insertions(+) create mode 100644 drivers/media/i2c/imx258.c
[snip]
Quoted 13 lines
drivers/media/i2c/imx258.c new file +13
-0+static int imx258_set_ctrl (struct v4l2_ctrl *ctrl) +{ +struct imx258 *imx258 = + container_of(ctrl->handler, struct imx258, ctrl_handler); +struct i2c_client *client =v4l2_get_subdevdata (&imx258->sd); +s64 max; +int ret =0 ; + +/* Propagate change of current control to all related controls */ +if (ctrl->id ==V4L2_CID_VBLANK ) { +/* Update max exposure while meeting expected vblanking */ + max = imx258->cur_mode->height + ctrl->val -8 ; + __v4l2_ctrl_modify_range(imx258->exposure,
drivers/media/i2c/imx258.c line 567
Quoted 10 lines
drivers/media/i2c/imx258.c new file +10
-0+ imx258->exposure->minimum, + max, imx258->exposure->step, max); + } + +/* +* Applying V4L2 control value only happens +* when power is up for streaming +*/ +if (pm_runtime_get_if_in_use (&client->dev) <=0 ) +return 0 ;
This won't work if runtime PM is not compiled in or is disabled at runtime, i.e. pm_runtime_get_if_in_use() returns -EINVAL.
But actually, do we need to care about runtime PM here? Could we just return early if we're not streaming? Then the controls would be handled when streaming starts, since we call __v4l2_ctrl_handler_setup() from _start_streaming().
Best regards,
Tomasz
Thanks Tomasz,
Agree with your point, if so, we could just change as below with a simple check of streaming flag. And for Sakari, do you agree with Tomasz's comment?
Kindly review and I would send v5 with the change.
drivers/media/i2c/imx258.c +2 -4
@@ -561,10 +561,13 @@ static int imx258_set_ctrl(struct v4l2_ctrl *ctrl)/* * Applying V4L2 control value only happens -* when power is up for qstreaming +* when streaming flag is on */ -if (pm_runtime_get_if_in_use (&client->dev) <=0 ) +if (imx258->streaming ==0 )return 0 ;switch (ctrl->id) {case V4L2_CID_ANALOGUE_GAIN :
@@ -590,8 +593,6 @@ static int imx258_set_ctrl(struct v4l2_ctrl *ctrl)break ; } -pm_runtime_put (&client->dev); -return ret; }
Regards, Andy
-----Original Message-----
From: Tomasz Figa [mailto:[email protected]]
Sent: Friday, January 19, 2018 12:18 PM
To: Yeh, Andy <[email protected]>
Cc: Linux Media Mailing List <[email protected]>; Sakari Ailus <[email protected]>
Subject: Re: [PATCH v4] media: imx258: Add imx258 camera sensor driver
Hi Andy,
Thanks for the patch. Please see my comments inline.
Quoted 21 lines · Andy Yeh
Add a V4L2 sub-device driver for the Sony IMX258 image sensor. This is a camera sensor using the I2C bus for control and the CSI-2 bus for data.
Signed-off-by Andy Yeh <[email protected]>---
-v2->v3
-- Update the streaming function to removeSW_STANDBYin the beginning. -- Adjust the delay time from 1ms to 12ms before set stream-on register.
-v3->v4
-- fix the sd.entity to make code be compiled on the mainline kernel. -- " -imx258->sd.entity.type=MEDIA_ENT_T_V4L2_SUBDEV_SENSOR;" -- " +imx258->sd.entity.function=MEDIA_ENT_F_CAM_SENSOR;"MAINTAINERS | 7 + drivers/media/i2c/Kconfig | 11 + drivers/media/i2c/Makefile | 1 + drivers/media/i2c/imx258.c | 1148 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 1167 insertions(+) create mode 100644 drivers/media/i2c/imx258.c
[snip]
Quoted 12 lines
(quoted diff) +12
-0+static int imx258_set_ctrl(struct v4l2_ctrl *ctrl) { + struct imx258 *imx258 = + container_of(ctrl->handler, struct imx258, ctrl_handler); + struct i2c_client *client = v4l2_get_subdevdata(&imx258->sd); + s64 max; + int ret = 0; + + /* Propagate change of current control to all related controls */ + if (ctrl->id == V4L2_CID_VBLANK) { + /* Update max exposure while meeting expected vblanking */ + max = imx258->cur_mode->height + ctrl->val - 8; + __v4l2_ctrl_modify_range(imx258->exposure,
Review
Quoted 10 lines
(quoted diff) +10
-0+ imx258->exposure->minimum, + max, imx258->exposure->step, max); + } + + /* + * Applying V4L2 control value only happens + * when power is up for streaming + */ + if (pm_runtime_get_if_in_use(&client->dev) <= 0) + return 0;
This won't work if runtime PM is not compiled in or is disabled at runtime, i.e. pm_runtime_get_if_in_use() returns -EINVAL.
But actually, do we need to care about runtime PM here? Could we just return early if we're not streaming? Then the controls would be handled when streaming starts, since we call __v4l2_ctrl_handler_setup() from _start_streaming().
Best regards,
Tomasz
Sakari Ailus
maintainerHi Andy,
Quoted 12 lines · Andy
Thanks Tomasz,
Agree with your point, if so, we could just change as below with a simple check of streaming flag. And for Sakari, do you agree with Tomasz's comment?
Kindly review and I would send v5 with the change.
drivers/media/i2c/imx258.c +0
-0
drivers/media/i2c/imx258.c static int imx258_set_ctrl(struct v4l2_ctrl *ctrl) · line 566
Quoted 8 lines
drivers/media/i2c/imx258.c +2
-2@@ -561,10 +561,13 @@ static int imx258_set_ctrl(struct v4l2_ctrl *ctrl)/* * Applying V4L2 control value only happens -* when power is up for qstreaming +* when streaming flag is on */ -if (pm_runtime_get_if_in_use (&client->dev) <=0 ) +if (imx258->streaming ==0 )
This doesn't address the problem yet. I think we'll need one more field in the device specific struct to convey this to the driver. Please see the smiapp driver, and its use of "active" field.
It's a little different implementation, you could well put the check here rather than the function performing the writes.
This isn't a severe issue though, in practice it'll be unlikely to be noticed as it hasn't been noticed in some other drivers that use the same pattern. IMO this could be addressed later on, possibly together with other drivers with similar issues.
Quoted 12 lines
drivers/media/i2c/imx258.c +0
-2return 0 ;switch (ctrl->id) {case V4L2_CID_ANALOGUE_GAIN :@@ -590,8 +593,6 @@ static int imx258_set_ctrl(struct v4l2_ctrl *ctrl)break ; } -pm_runtime_put (&client->dev); -return ret; }
Signature · 4 lines
Kind regards, Sakari Ailus [email protected]
Hi Sakari, Tomasz,
As below discussion that other drivers are with this pattern, I would prefer to defer to address the concern in later discussion with you and owners of other sensors.
Thanks a lot.
Regards, Andy
-----Original Message-----
From: Sakari Ailus [mailto:[email protected]]
Sent: Friday, January 19, 2018 5:18 PM
To: Yeh, Andy <[email protected]>
Cc: Tomasz Figa <[email protected]>; Linux Media Mailing List <[email protected]>
Subject: Re: [PATCH v4] media: imx258: Add imx258 camera sensor driver
Hi Andy,
Quoted 12 lines · Andy
Thanks Tomasz,
Agree with your point, if so, we could just change as below with a simple check of streaming flag. And for Sakari, do you agree with Tomasz's comment?
Kindly review and I would send v5 with the change.
drivers/media/i2c/imx258.c +0
-0
drivers/media/i2c/imx258.c static int imx258_set_ctrl(struct v4l2_ctrl · line 567
Quoted 9 lines
drivers/media/i2c/imx258.c +2
-2@@ -561,10 +561,13 @@ static int imx258_set_ctrl(struct v4l2_ctrl *ctrl)/* * Applying V4L2 control value only happens -* when power is up for qstreaming +* when streaming flag is on */ -if (pm_runtime_get_if_in_use (&client->dev) <=0 ) +if (imx258->streaming ==0 )
This doesn't address the problem yet. I think we'll need one more field in the device specific struct to convey this to the driver. Please see the smiapp driver, and its use of "active" field.
It's a little different implementation, you could well put the check here rather than the function performing the writes.
This isn't a severe issue though, in practice it'll be unlikely to be noticed as it hasn't been noticed in some other drivers that use the same pattern. IMO this could be addressed later on, possibly together with other drivers with similar issues.
drivers/media/i2c/imx258.c static int imx258_set_ctrl(struct v4l2_ctrl *ctrl) · line 597
Quoted 12 lines
drivers/media/i2c/imx258.c +0
-2return 0 ;switch (ctrl->id) {case V4L2_CID_ANALOGUE_GAIN :@@ -590,8 +593,6 @@ static int imx258_set_ctrl(struct v4l2_ctrl *ctrl)break ; } -pm_runtime_put (&client->dev); -return ret; }
--
Kind regards,
Sakari Ailus
[email protected]
Sakari Ailus
maintainerQuoted 7 lines · Andy
Hi Sakari, Tomasz,
As below discussion that other drivers are with this pattern, I would prefer to defer to address the concern in later discussion with you and owners of other sensors.
Thanks a lot.
Works for me.
Signature · 2 lines
Sakari Ailus [email protected]
Sakari Ailus
maintainerHi Andy,
Quoted 5 lines · Andy
Hi Sakari, Tomasz,
As below discussion that other drivers are with this pattern, I would prefer to defer to address the concern in later discussion with you and owners of other sensors.
Thanks a lot.
I thought of taking a look into the problem area and one sensor driver which doesn't appear to have the problem in this respect is imx258. This is because the v4l2_ctrl_handler_setup() isn't called in a runtime PM callback, but through V4L2 sub-dev s_stream callback instead. The runtime PM transition has already taken place by then. This isn't entirely optimal but works. Other sensor drivers will still need to be fixed.
Signature · 2 lines
Sakari Ailus [email protected]
Sakari Ailus
maintainerQuoted 7 lines · Sakari Ailus
Hi Andy,
Quoted 4 lines · Andy
Hi Sakari, Tomasz,
As below discussion that other drivers are with this pattern, I would prefer to defer to address the concern in later discussion with you and owners of other sensors.
Quoted 8 lines
Quoted 1 line
Thanks a lot.
I thought of taking a look into the problem area and one sensor driver which doesn't appear to have the problem in this respect is imx258. This is because the
v4l2_ctrl_handler_setup()isn't called in a runtime PM callback, but through V4L2 sub-devs_streamcallback instead. The runtime PM transition has already taken place by then. This isn't entirely optimal but works. Other sensor drivers will still need to be fixed.
And by a quick check we seem to have no sensor drivers doing this after all... the v4l2_ctrl_handler_setup is called in the s_stream callback.
Signature · 2 lines
Sakari Ailus [email protected]