Skip to contentSkip to conversation

media: imx258: Add imx258 camera sensor driver

PATCH Superseded Andy Yeh 2 participants 4 messages Mar 11, 2018 – Mar 14, 2018

Subsystems (3)

v7 of 11 Superseded Latest is v11 →

lore
Share & tools
lore

Andy Yeh

author
#0 lore raw

PATCH v7 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.

---
since v2:
-- Update the streaming function to remove SW_STANDBY in the beginning. -- Adjust the delay time from 1ms to 12ms before set stream-on register. since v3:
-- fix the sd.entity to make code be compiled on the mainline kernel. since v4:
-- Enabled AG, DG, and Exposure time control correctly.
since v5:
-- Sensor vendor provided a new setting to fix different CLK issue -- Add one more resolution for 1048x780, used for VGA streaming since v6:
-- improved i2c read/write function to support writing 2 registers -- modified i2c reg read/write function with a more portable way -- utilized v4l2_find_nearest_size instead of the local find_best_fit function -- defined an enum for the link freq entries for explicit indexing

 MAINTAINERS                |    7 +
 drivers/media/i2c/Kconfig  |   11 +
 drivers/media/i2c/Makefile |    1 +
 drivers/media/i2c/imx258.c | 1299 ++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 1318 insertions(+)
 create mode 100644 drivers/media/i2c/imx258.c
MAINTAINERS +7 -0
index a339bb5..9f75510 100644
@@ -12646,6 +12646,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
index fd01842..bcd4bf1 100644
@@ -565,6 +565,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
index 1b62639..4bf7d00 100644
@@ -94,6 +94,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 +1299 -0

1,299 lines not on this page · raw message

Signature · 1 line
2.7.4
author
#1 lore raw

Dear all,

Please kindly check this v7.
I noticed many incorrect line breaks again in this mail which was not identical to the original patch. Not sure how it was resulted. Such as
-- Add one more resolution for 1048x780, used for VGA streaming "\n" since v6:
-- improved i2c read/write function to support writing 2 registers

+/* Mode : resolution and related config&values */ "\n" struct imx258_mode {

Therefore please help check the patch on the list, which is with correct line break.
https://patchwork.linuxtv.org/patch/47869/

Sorry to bring you inconvenience.

Regards, Andy

-----Original Message-----
From: Yeh, Andy
Sent: Monday, March 12, 2018 12:02 AM
To: [email protected]; [email protected]
Cc: [email protected]; Yeh, Andy <[email protected]>; Chen, JasonX Z <[email protected]>; Chiang, AlanX <[email protected]>; Lai, Jim <[email protected]>
Subject: [PATCH v7] 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.

---
since v2:
-- Update the streaming function to remove SW_STANDBY in the beginning. -- Adjust the delay time from 1ms to 12ms before set stream-on register. since v3:
-- fix the sd.entity to make code be compiled on the mainline kernel. since v4:
-- Enabled AG, DG, and Exposure time control correctly.
since v5:
-- Sensor vendor provided a new setting to fix different CLK issue -- Add one more resolution for 1048x780, used for VGA streaming since v6:
-- improved i2c read/write function to support writing 2 registers -- modified i2c reg read/write function with a more portable way -- utilized v4l2_find_nearest_size instead of the local find_best_fit function -- defined an enum for the link freq entries for explicit indexing

 MAINTAINERS                |    7 +
 drivers/media/i2c/Kconfig  |   11 +
 drivers/media/i2c/Makefile |    1 +
 drivers/media/i2c/imx258.c | 1299 ++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 1318 insertions(+)
 create mode 100644 drivers/media/i2c/imx258.c
MAINTAINERS +7 -0
index a339bb5..9f75510 100644
@@ -12646,6 +12646,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 +13 -1
@@ -565,6 +565,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 diff --git a/drivers/media/i2c/Makefile b/drivers/media/i2c/Makefile index 1b62639..4bf7d00 100644
--- a/drivers/media/i2c/Makefile
+++ b/drivers/media/i2c/Makefile
@@ -94,6 +94,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 +1272 -0

1,272 lines not on this page · raw message

--
2.7.4

#2 lore raw
In reply to Andy Yeh

Hi Andy,

Quoted 6 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.

Quoted 16 lines

---
since v2:
-- Update the streaming function to remove SW_STANDBY in the beginning. -- Adjust the delay time from 1ms to 12ms before set stream-on register. since v3:
-- fix the sd.entity to make code be compiled on the mainline kernel. since v4:
-- Enabled AG, DG, and Exposure time control correctly.
since v5:
-- Sensor vendor provided a new setting to fix different CLK issue -- Add one more resolution for 1048x780, used for VGA streaming since v6:
-- improved i2c read/write function to support writing 2 registers -- modified i2c reg read/write function with a more portable way -- utilized v4l2_find_nearest_size instead of the local find_best_fit function -- defined an enum for the link freq entries for explicit indexing

Thanks for the patch. Looks almost good now. Just two new comments inline.

[snip]

Quoted 10 lines
drivers/media/i2c/imx258.c new file +10 -0
+       /* Set Orientation be 180 degree */
+       ret = imx258_write_reg(imx258, REG_MIRROR_FLIP_CONTROL,
+                               IMX258_REG_VALUE_08BIT, REG_CONFIG_MIRROR_FLIP);
+       if (ret) {
+               dev_err(&client->dev, "%s failed to set orientation\n",
+                       __func__);
+               return ret;
+       }
+
+       /* Apply customized values from user */

drivers/media/i2c/imx258.c line 937

Quoted 10 lines
drivers/media/i2c/imx258.c new file +10 -0
+       ret =  __v4l2_ctrl_handler_setup(imx258->sd.ctrl_handler);
+       if (ret)
+               return ret;
+
+       /*
+        * Per sensor datasheet:
+        * These are the minimum 12ms delays for accessing the sensor through
+        * I2C and enabling streaming after lifting the device from reset.
+        */
+       usleep_range(12000, 13000);

Hmm, the code above already accesses the sensor through I2C. If this works, is this sleep perhaps already done by ACPI code or it is only needed for streaming?

[snip]

Quoted 22 lines
drivers/media/i2c/imx258.c new file +22 -0
+/* Initialize control handlers */
+static int imx258_init_controls(struct imx258 *imx258)
+{
+       struct i2c_client *client = v4l2_get_subdevdata(&imx258->sd);
+       struct v4l2_ctrl_handler *ctrl_hdlr;
+       s64 exposure_max;
+       s64 vblank_def;
+       s64 vblank_min;
+       s64 pixel_rate_min;
+       s64 pixel_rate_max;
+       int ret;
+
+       ctrl_hdlr = &imx258->ctrl_handler;
+       ret = v4l2_ctrl_handler_init(ctrl_hdlr, 8);
+       if (ret)
+               return ret;
+
+       mutex_init(&imx258->mutex);
+       ctrl_hdlr->lock = &imx258->mutex;
+       imx258->link_freq = v4l2_ctrl_new_int_menu(ctrl_hdlr,
+                               &imx258_ctrl_ops,
+                               V4L2_CID_LINK_FREQ,

drivers/media/i2c/imx258.c line 1116

Quoted 10 lines
drivers/media/i2c/imx258.c new file +10 -0
+                               ARRAY_SIZE(link_freq_menu_items) - 1,
+                               0,
+                               link_freq_menu_items);
+
+       if (!imx258->link_freq) {
+               ret = -EINVAL;
+               goto error;
+       }
+
+       imx258->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY;

nit: As discussed earlier with Sakari, I think we agreed on making this, and other controls that need dereferencing here, as follows:

        imx258->link_freq = v4l2_ctrl_new_int_menu(ctrl_hdlr,
                                &imx258_ctrl_ops,
                                V4L2_CID_LINK_FREQ,
                                ARRAY_SIZE(link_freq_menu_items) - 1,
                                0,
                                link_freq_menu_items);
        if (imx258->link_freq)
                imx258->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY;

The error will be reported at the end of this function, through the check for ctrl_hdlr->error.

Best regards,
Tomasz

author
#3 lore raw

Hi Tomasz,

Thanks for the comments. OKAY as inline.
Please check the Patch V8.

Regards, Andy

-----Original Message-----
From: Tomasz Figa [mailto:[email protected]]
Sent: Monday, March 12, 2018 3:33 PM
To: Yeh, Andy <[email protected]>
Cc: Linux Media Mailing List <[email protected]>; Sakari Ailus <[email protected]>; Chen, JasonX Z <[email protected]>; Chiang, AlanX <[email protected]>; Lai, Jim <[email protected]>
Subject: Re: [PATCH v7] media: imx258: Add imx258 camera sensor driver

Hi Andy,

Quoted 41 lines · Andy Yeh
Quoted 15 lines

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.

---
since v2:
-- Update the streaming function to remove SW_STANDBY in the beginning. -- Adjust the delay time from 1ms to 12ms before set stream-on register. since v3:
-- fix the sd.entity to make code be compiled on the mainline kernel. since v4:
-- Enabled AG, DG, and Exposure time control correctly. since v5:

Quoted 8 lines

-- Sensor vendor provided a new setting to fix different CLK issue -- Add one more resolution for 1048x780, used for VGA streaming since v6:
-- improved i2c read/write function to support writing 2 registers -- modified i2c reg read/write function with a more portable way -- utilized v4l2_find_nearest_size instead of the local find_best_fit function
-- defined an enum for the link freq entries for explicit indexing

Thanks for the patch. Looks almost good now. Just two new comments inline.

[snip]

Quoted 14 lines
drivers/media/i2c/imx258.c new file +14 -0
+       /* Set Orientation be 180 degree */
+       ret = imx258_write_reg(imx258, REG_MIRROR_FLIP_CONTROL,
+                               IMX258_REG_VALUE_08BIT, REG_CONFIG_MIRROR_FLIP);
+       if (ret) {
+               dev_err(&client->dev, "%s failed to set orientation\n",
+                       __func__);
+               return ret;
+       }
+
+       /* Apply customized values from user */
+       ret =  __v4l2_ctrl_handler_setup(imx258->sd.ctrl_handler);
+       if (ret)
+               return ret;
+
Quoted 9 lines

drivers/media/i2c/imx258.c line 937

Quoted 6 lines
drivers/media/i2c/imx258.c new file +6 -0
+       /*
+        * Per sensor datasheet:
+        * These are the minimum 12ms delays for accessing the sensor through
+        * I2C and enabling streaming after lifting the device from reset.
+        */
+       usleep_range(12000, 13000);

Hmm, the code above already accesses the sensor through I2C. If this works, is this sleep perhaps already done by ACPI code or it is only needed for streaming?

Okay.
usleep removed since confirmed sufficient delay implemented in coreboot. Stress test passed.

Quoted 44 lines

[snip]

Quoted 21 lines
drivers/media/i2c/imx258.c new file +21 -0
+/* Initialize control handlers */
+static int imx258_init_controls(struct imx258 *imx258) {
+       struct i2c_client *client = v4l2_get_subdevdata(&imx258->sd);
+       struct v4l2_ctrl_handler *ctrl_hdlr;
+       s64 exposure_max;
+       s64 vblank_def;
+       s64 vblank_min;
+       s64 pixel_rate_min;
+       s64 pixel_rate_max;
+       int ret;
+
+       ctrl_hdlr = &imx258->ctrl_handler;
+       ret = v4l2_ctrl_handler_init(ctrl_hdlr, 8);
+       if (ret)
+               return ret;
+
+       mutex_init(&imx258->mutex);
+       ctrl_hdlr->lock = &imx258->mutex;
+       imx258->link_freq = v4l2_ctrl_new_int_menu(ctrl_hdlr,
+                               &imx258_ctrl_ops,
+                               V4L2_CID_LINK_FREQ,

drivers/media/i2c/imx258.c line 1116

Quoted 10 lines
drivers/media/i2c/imx258.c new file +10 -0
+                               ARRAY_SIZE(link_freq_menu_items) - 1,
+                               0,
+                               link_freq_menu_items);
+
+       if (!imx258->link_freq) {
+               ret = -EINVAL;
+               goto error;
+       }
+
+       imx258->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY;

nit: As discussed earlier with Sakari, I think we agreed on making this, and other controls that need dereferencing here, as follows:

       imx258->link_freq = v4l2_ctrl_new_int_menu(ctrl_hdlr,
                               &imx258_ctrl_ops,
                               V4L2_CID_LINK_FREQ,
                               ARRAY_SIZE(link_freq_menu_items) - 1,
                               0,
                               link_freq_menu_items);
       if (imx258->link_freq)
               imx258->link_freq->flags |= V4L2_CTRL_FLAG_READ_ONLY;
Quoted 3 lines

The error will be reported at the end of this function, through the check for ctrl_hdlr->error.

OKAY

Best regards,
Tomasz