Skip to contentSkip to conversation

media: imx258: Add imx258 camera sensor driver

PATCH Superseded Andy Yeh 4 participants 9 messages Mar 14, 2018 – Mar 16, 2018

Subsystems (3)

v8 of 11 Superseded Latest is v11 →

lore
Share & tools
lore

Andy Yeh

author
#0 lore raw

PATCH v8 1/1 media: imx258: Add imx258 camera sensor driver

From: Jason Chen <[email protected]>

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 since v7:
-- Removed usleep due to sufficient delay implemented in coreboot -- Added handling for VBLANK control that auto frame-line-control is enabled

 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

Still wrong line break...
Please check the list instead. Thanks.
https://patchwork.linuxtv.org/patch/47936/

Regards, Andy

-----Original Message-----
From: Yeh, Andy
Sent: Thursday, March 15, 2018 12:24 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 v8] media: imx258: Add imx258 camera sensor driver

From: Jason Chen <[email protected]>

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 since v7:
-- Removed usleep due to sufficient delay implemented in coreboot -- Added handling for VBLANK control that auto frame-line-control is enabled

 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

maintainer
#3 lore raw
In reply to Andy Yeh

Hi Andy,

Thanks for the update. Two minor comments below.

On Thu, Mar 15, 2018 at 12:24:19AM +0800, Andy Yeh wrote:
...

Quoted 29 lines
drivers/media/i2c/imx258.c new file +29 -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);
+	int ret = 0;
+
+	/*
+	 * Applying V4L2 control value only happens
+	 * when power is up for streaming
+	 */
+	if (pm_runtime_get_if_in_use(&client->dev) == 0)
+		return 0;
+
+	switch (ctrl->id) {
+	case V4L2_CID_ANALOGUE_GAIN:
+		ret = imx258_write_reg(imx258, IMX258_REG_ANALOG_GAIN,
+				IMX258_REG_VALUE_16BIT,
+				ctrl->val);
+		break;
+	case V4L2_CID_EXPOSURE:
+		ret = imx258_write_reg(imx258, IMX258_REG_EXPOSURE,
+				IMX258_REG_VALUE_16BIT,
+				ctrl->val);
+		break;
+	case V4L2_CID_DIGITAL_GAIN:
+		ret = imx258_update_digital_gain(imx258, IMX258_REG_VALUE_16BIT,
+				ctrl->val);
+		break;

drivers/media/i2c/imx258.c line 771

Quoted 10 lines
drivers/media/i2c/imx258.c new file +10 -0
+	case V4L2_CID_VBLANK:
+		/*
+		 * Auto Frame Length Line Control is enabled by default.
+		 * Not need control Vblank Register.
+		 */
+		break;
+	default:
+		dev_info(&client->dev,
+			 "ctrl(id:0x%x,val:0x%x) is not handled\n",
+			 ctrl->id, ctrl->val);

As this is an error, I'd set ret to e.g. -EINVAL here.

Quoted 7 lines
drivers/media/i2c/imx258.c new file +7 -0
+		break;
+	}
+
+	pm_runtime_put(&client->dev);
+
+	return ret;
+}

...

Quoted 44 lines
drivers/media/i2c/imx258.c new file +44 -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,
+				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;
+
+	pixel_rate_max = link_freq_to_pixel_rate(link_freq_menu_items[0]);
+	pixel_rate_min = link_freq_to_pixel_rate(link_freq_menu_items[1]);
+	/* By default, PIXEL_RATE is read only */
+	imx258->pixel_rate = v4l2_ctrl_new_std(ctrl_hdlr, &imx258_ctrl_ops,
+					V4L2_CID_PIXEL_RATE,
+					pixel_rate_min, pixel_rate_max,
+					1, pixel_rate_max);
+
+
+	vblank_def = imx258->cur_mode->vts_def - imx258->cur_mode->height;
+	vblank_min = imx258->cur_mode->vts_min - imx258->cur_mode->height;
+	imx258->vblank = v4l2_ctrl_new_std(
+				ctrl_hdlr, &imx258_ctrl_ops, V4L2_CID_VBLANK,
+				vblank_min,
+				IMX258_VTS_MAX - imx258->cur_mode->height, 1,

drivers/media/i2c/imx258.c line 1142

Quoted 10 lines
drivers/media/i2c/imx258.c new file +10 -0
+				vblank_def);
+
+	imx258->hblank = v4l2_ctrl_new_std(
+				ctrl_hdlr, &imx258_ctrl_ops, V4L2_CID_HBLANK,
+				IMX258_PPL_DEFAULT - imx258->cur_mode->width,
+				IMX258_PPL_DEFAULT - imx258->cur_mode->width,
+				1,
+				IMX258_PPL_DEFAULT - imx258->cur_mode->width);
+
+	if (!imx258->hblank) {

Could you align handling for NULL hblank control with NULL link_freq above?

Quoted 44 lines
drivers/media/i2c/imx258.c new file +44 -0
+		ret = -EINVAL;
+		goto error;
+	}
+
+	imx258->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY;
+
+	exposure_max = imx258->cur_mode->vts_def - 8;
+	imx258->exposure = v4l2_ctrl_new_std(
+				ctrl_hdlr, &imx258_ctrl_ops,
+				V4L2_CID_EXPOSURE, IMX258_EXPOSURE_MIN,
+				IMX258_EXPOSURE_MAX, IMX258_EXPOSURE_STEP,
+				IMX258_EXPOSURE_DEFAULT);
+
+	v4l2_ctrl_new_std(ctrl_hdlr, &imx258_ctrl_ops, V4L2_CID_ANALOGUE_GAIN,
+				IMX258_ANA_GAIN_MIN, IMX258_ANA_GAIN_MAX,
+				IMX258_ANA_GAIN_STEP, IMX258_ANA_GAIN_DEFAULT);
+
+	v4l2_ctrl_new_std(ctrl_hdlr, &imx258_ctrl_ops, V4L2_CID_DIGITAL_GAIN,
+				IMX258_DGTL_GAIN_MIN, IMX258_DGTL_GAIN_MAX,
+				IMX258_DGTL_GAIN_STEP,
+				IMX258_DGTL_GAIN_DEFAULT);
+
+	v4l2_ctrl_new_std_menu_items(ctrl_hdlr, &imx258_ctrl_ops,
+				     V4L2_CID_TEST_PATTERN,
+				     ARRAY_SIZE(imx258_test_pattern_menu) - 1,
+				     0, 0, imx258_test_pattern_menu);
+
+	if (ctrl_hdlr->error) {
+		ret = ctrl_hdlr->error;
+		dev_err(&client->dev, "%s control init failed (%d)\n",
+			__func__, ret);
+		goto error;
+	}
+
+	imx258->sd.ctrl_handler = ctrl_hdlr;
+
+	return 0;
+
+error:
+	v4l2_ctrl_handler_free(ctrl_hdlr);
+	mutex_destroy(&imx258->mutex);
+
+	return ret;
+}
Signature · 4 lines
Kind regards,

Sakari Ailus
[email protected]
author
#4 lore raw

Sure will do. Thanks Sakari.

-----Original Message-----
From: Sakari Ailus [mailto:[email protected]]
Sent: Thursday, March 15, 2018 6:31 AM
To: Yeh, Andy <[email protected]>
Cc: [email protected]; [email protected]; Chen, JasonX Z <[email protected]>; Chiang, AlanX <[email protected]>; Lai, Jim <[email protected]>
Subject: Re: [PATCH v8] media: imx258: Add imx258 camera sensor driver

Hi Andy,

Thanks for the update. Two minor comments below.

On Thu, Mar 15, 2018 at 12:24:19AM +0800, Andy Yeh wrote:
...

Quoted 28 lines
drivers/media/i2c/imx258.c new file +28 -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);
+	int ret = 0;
+
+	/*
+	 * Applying V4L2 control value only happens
+	 * when power is up for streaming
+	 */
+	if (pm_runtime_get_if_in_use(&client->dev) == 0)
+		return 0;
+
+	switch (ctrl->id) {
+	case V4L2_CID_ANALOGUE_GAIN:
+		ret = imx258_write_reg(imx258, IMX258_REG_ANALOG_GAIN,
+				IMX258_REG_VALUE_16BIT,
+				ctrl->val);
+		break;
+	case V4L2_CID_EXPOSURE:
+		ret = imx258_write_reg(imx258, IMX258_REG_EXPOSURE,
+				IMX258_REG_VALUE_16BIT,
+				ctrl->val);
+		break;
+	case V4L2_CID_DIGITAL_GAIN:
+		ret = imx258_update_digital_gain(imx258, IMX258_REG_VALUE_16BIT,
+				ctrl->val);
+		break;

drivers/media/i2c/imx258.c line 771

Quoted 10 lines
drivers/media/i2c/imx258.c new file +10 -0
+	case V4L2_CID_VBLANK:
+		/*
+		 * Auto Frame Length Line Control is enabled by default.
+		 * Not need control Vblank Register.
+		 */
+		break;
+	default:
+		dev_info(&client->dev,
+			 "ctrl(id:0x%x,val:0x%x) is not handled\n",
+			 ctrl->id, ctrl->val);

As this is an error, I'd set ret to e.g. -EINVAL here.

Quoted 7 lines
drivers/media/i2c/imx258.c new file +7 -0
+		break;
+	}
+
+	pm_runtime_put(&client->dev);
+
+	return ret;
+}

...

Quoted 43 lines
drivers/media/i2c/imx258.c new file +43 -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,
+				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;
+
+	pixel_rate_max = link_freq_to_pixel_rate(link_freq_menu_items[0]);
+	pixel_rate_min = link_freq_to_pixel_rate(link_freq_menu_items[1]);
+	/* By default, PIXEL_RATE is read only */
+	imx258->pixel_rate = v4l2_ctrl_new_std(ctrl_hdlr, &imx258_ctrl_ops,
+					V4L2_CID_PIXEL_RATE,
+					pixel_rate_min, pixel_rate_max,
+					1, pixel_rate_max);
+
+
+	vblank_def = imx258->cur_mode->vts_def - imx258->cur_mode->height;
+	vblank_min = imx258->cur_mode->vts_min - imx258->cur_mode->height;
+	imx258->vblank = v4l2_ctrl_new_std(
+				ctrl_hdlr, &imx258_ctrl_ops, V4L2_CID_VBLANK,
+				vblank_min,
+				IMX258_VTS_MAX - imx258->cur_mode->height, 1,

drivers/media/i2c/imx258.c line 1142

Quoted 10 lines
drivers/media/i2c/imx258.c new file +10 -0
+				vblank_def);
+
+	imx258->hblank = v4l2_ctrl_new_std(
+				ctrl_hdlr, &imx258_ctrl_ops, V4L2_CID_HBLANK,
+				IMX258_PPL_DEFAULT - imx258->cur_mode->width,
+				IMX258_PPL_DEFAULT - imx258->cur_mode->width,
+				1,
+				IMX258_PPL_DEFAULT - imx258->cur_mode->width);
+
+	if (!imx258->hblank) {

Could you align handling for NULL hblank control with NULL link_freq above?

Quoted 34 lines
drivers/media/i2c/imx258.c new file +34 -0
+		ret = -EINVAL;
+		goto error;
+	}
+
+	imx258->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY;
+
+	exposure_max = imx258->cur_mode->vts_def - 8;
+	imx258->exposure = v4l2_ctrl_new_std(
+				ctrl_hdlr, &imx258_ctrl_ops,
+				V4L2_CID_EXPOSURE, IMX258_EXPOSURE_MIN,
+				IMX258_EXPOSURE_MAX, IMX258_EXPOSURE_STEP,
+				IMX258_EXPOSURE_DEFAULT);
+
+	v4l2_ctrl_new_std(ctrl_hdlr, &imx258_ctrl_ops, V4L2_CID_ANALOGUE_GAIN,
+				IMX258_ANA_GAIN_MIN, IMX258_ANA_GAIN_MAX,
+				IMX258_ANA_GAIN_STEP, IMX258_ANA_GAIN_DEFAULT);
+
+	v4l2_ctrl_new_std(ctrl_hdlr, &imx258_ctrl_ops, V4L2_CID_DIGITAL_GAIN,
+				IMX258_DGTL_GAIN_MIN, IMX258_DGTL_GAIN_MAX,
+				IMX258_DGTL_GAIN_STEP,
+				IMX258_DGTL_GAIN_DEFAULT);
+
+	v4l2_ctrl_new_std_menu_items(ctrl_hdlr, &imx258_ctrl_ops,
+				     V4L2_CID_TEST_PATTERN,
+				     ARRAY_SIZE(imx258_test_pattern_menu) - 1,
+				     0, 0, imx258_test_pattern_menu);
+
+	if (ctrl_hdlr->error) {
+		ret = ctrl_hdlr->error;
+		dev_err(&client->dev, "%s control init failed (%d)\n",
+			__func__, ret);
+		goto error;
+	}
+

drivers/media/i2c/imx258.c line 1186

Quoted 10 lines
drivers/media/i2c/imx258.c new file +10 -0
+	imx258->sd.ctrl_handler = ctrl_hdlr;
+
+	return 0;
+
+error:
+	v4l2_ctrl_handler_free(ctrl_hdlr);
+	mutex_destroy(&imx258->mutex);
+
+	return ret;
+}

--
Kind regards,

Sakari Ailus
[email protected]

author
#5 lore raw
In reply to Sakari Ailus

Both comments are OKAY.

Thanks.

-----Original Message-----
From: Sakari Ailus [mailto:[email protected]]
Sent: Thursday, March 15, 2018 6:31 AM
To: Yeh, Andy <[email protected]>
Cc: [email protected]; [email protected]; Chen, JasonX Z <[email protected]>; Chiang, AlanX <[email protected]>; Lai, Jim <[email protected]>
Subject: Re: [PATCH v8] media: imx258: Add imx258 camera sensor driver

Hi Andy,

Thanks for the update. Two minor comments below.

On Thu, Mar 15, 2018 at 12:24:19AM +0800, Andy Yeh wrote:
...

Quoted 28 lines
drivers/media/i2c/imx258.c new file +28 -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);
+	int ret = 0;
+
+	/*
+	 * Applying V4L2 control value only happens
+	 * when power is up for streaming
+	 */
+	if (pm_runtime_get_if_in_use(&client->dev) == 0)
+		return 0;
+
+	switch (ctrl->id) {
+	case V4L2_CID_ANALOGUE_GAIN:
+		ret = imx258_write_reg(imx258, IMX258_REG_ANALOG_GAIN,
+				IMX258_REG_VALUE_16BIT,
+				ctrl->val);
+		break;
+	case V4L2_CID_EXPOSURE:
+		ret = imx258_write_reg(imx258, IMX258_REG_EXPOSURE,
+				IMX258_REG_VALUE_16BIT,
+				ctrl->val);
+		break;
+	case V4L2_CID_DIGITAL_GAIN:
+		ret = imx258_update_digital_gain(imx258, IMX258_REG_VALUE_16BIT,
+				ctrl->val);
+		break;

drivers/media/i2c/imx258.c line 771

Quoted 10 lines
drivers/media/i2c/imx258.c new file +10 -0
+	case V4L2_CID_VBLANK:
+		/*
+		 * Auto Frame Length Line Control is enabled by default.
+		 * Not need control Vblank Register.
+		 */
+		break;
+	default:
+		dev_info(&client->dev,
+			 "ctrl(id:0x%x,val:0x%x) is not handled\n",
+			 ctrl->id, ctrl->val);

As this is an error, I'd set ret to e.g. -EINVAL here.

Quoted 7 lines
drivers/media/i2c/imx258.c new file +7 -0
+		break;
+	}
+
+	pm_runtime_put(&client->dev);
+
+	return ret;
+}

...

Quoted 43 lines
drivers/media/i2c/imx258.c new file +43 -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,
+				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;
+
+	pixel_rate_max = link_freq_to_pixel_rate(link_freq_menu_items[0]);
+	pixel_rate_min = link_freq_to_pixel_rate(link_freq_menu_items[1]);
+	/* By default, PIXEL_RATE is read only */
+	imx258->pixel_rate = v4l2_ctrl_new_std(ctrl_hdlr, &imx258_ctrl_ops,
+					V4L2_CID_PIXEL_RATE,
+					pixel_rate_min, pixel_rate_max,
+					1, pixel_rate_max);
+
+
+	vblank_def = imx258->cur_mode->vts_def - imx258->cur_mode->height;
+	vblank_min = imx258->cur_mode->vts_min - imx258->cur_mode->height;
+	imx258->vblank = v4l2_ctrl_new_std(
+				ctrl_hdlr, &imx258_ctrl_ops, V4L2_CID_VBLANK,
+				vblank_min,
+				IMX258_VTS_MAX - imx258->cur_mode->height, 1,

drivers/media/i2c/imx258.c line 1142

Quoted 10 lines
drivers/media/i2c/imx258.c new file +10 -0
+				vblank_def);
+
+	imx258->hblank = v4l2_ctrl_new_std(
+				ctrl_hdlr, &imx258_ctrl_ops, V4L2_CID_HBLANK,
+				IMX258_PPL_DEFAULT - imx258->cur_mode->width,
+				IMX258_PPL_DEFAULT - imx258->cur_mode->width,
+				1,
+				IMX258_PPL_DEFAULT - imx258->cur_mode->width);
+
+	if (!imx258->hblank) {

Could you align handling for NULL hblank control with NULL link_freq above?

Quoted 34 lines
drivers/media/i2c/imx258.c new file +34 -0
+		ret = -EINVAL;
+		goto error;
+	}
+
+	imx258->hblank->flags |= V4L2_CTRL_FLAG_READ_ONLY;
+
+	exposure_max = imx258->cur_mode->vts_def - 8;
+	imx258->exposure = v4l2_ctrl_new_std(
+				ctrl_hdlr, &imx258_ctrl_ops,
+				V4L2_CID_EXPOSURE, IMX258_EXPOSURE_MIN,
+				IMX258_EXPOSURE_MAX, IMX258_EXPOSURE_STEP,
+				IMX258_EXPOSURE_DEFAULT);
+
+	v4l2_ctrl_new_std(ctrl_hdlr, &imx258_ctrl_ops, V4L2_CID_ANALOGUE_GAIN,
+				IMX258_ANA_GAIN_MIN, IMX258_ANA_GAIN_MAX,
+				IMX258_ANA_GAIN_STEP, IMX258_ANA_GAIN_DEFAULT);
+
+	v4l2_ctrl_new_std(ctrl_hdlr, &imx258_ctrl_ops, V4L2_CID_DIGITAL_GAIN,
+				IMX258_DGTL_GAIN_MIN, IMX258_DGTL_GAIN_MAX,
+				IMX258_DGTL_GAIN_STEP,
+				IMX258_DGTL_GAIN_DEFAULT);
+
+	v4l2_ctrl_new_std_menu_items(ctrl_hdlr, &imx258_ctrl_ops,
+				     V4L2_CID_TEST_PATTERN,
+				     ARRAY_SIZE(imx258_test_pattern_menu) - 1,
+				     0, 0, imx258_test_pattern_menu);
+
+	if (ctrl_hdlr->error) {
+		ret = ctrl_hdlr->error;
+		dev_err(&client->dev, "%s control init failed (%d)\n",
+			__func__, ret);
+		goto error;
+	}
+

drivers/media/i2c/imx258.c line 1186

Quoted 10 lines
drivers/media/i2c/imx258.c new file +10 -0
+	imx258->sd.ctrl_handler = ctrl_hdlr;
+
+	return 0;
+
+error:
+	v4l2_ctrl_handler_free(ctrl_hdlr);
+	mutex_destroy(&imx258->mutex);
+
+	return ret;
+}

--
Kind regards,

Sakari Ailus
[email protected]

#6 lore raw
In reply to Andy Yeh
Thank you for the patch! Yet something to improve:

Hi Jason,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on linus/master]
[also build test ERROR on v4.16-rc5 next-20180316]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url: https://github.com/0day-ci/linux/commits/Andy-Yeh/media-imx258-Add-imx258-camera-sensor-driver/20180316-201540
config: i386-allmodconfig (attached as .config)
compiler: gcc-7 (Debian 7.3.0-1) 7.3.0 reproduce:

        # save the attached .config to linux build tree
        make ARCH=i386 

All errors (new ones prefixed by >>):

drivers/media/i2c/imx258.c: In function 'imx258_set_pad_format':

>> drivers/media/i2c/imx258.c:869:9: error: implicit declaration of function 'v4l2_find_nearest_size'; did you mean 'v4l2_find_nearest_format'? [-Werror=implicit-function-declaration]
     mode = v4l2_find_nearest_size(
            ^~~~~~~~~~~~~~~~~~~~~~
            v4l2_find_nearest_format
>> drivers/media/i2c/imx258.c:870:49: error: 'width' undeclared (first use in this function)
      supported_modes, ARRAY_SIZE(supported_modes), width, height,
                                                    ^~~~~
   drivers/media/i2c/imx258.c:870:49: note: each undeclared identifier is reported only once for each function it appears in
>> drivers/media/i2c/imx258.c:870:56: error: 'height' undeclared (first use in this function); did you mean 'hweight8'?
      supported_modes, ARRAY_SIZE(supported_modes), width, height,
                                                           ^~~~~~
                                                           hweight8
>> drivers/media/i2c/imx258.c:871:3: error: 'fmr' undeclared (first use in this function); did you mean 'fmt'?
      fmr->format.width, fmt->format.height);
      ^~~
      fmt

cc1: some warnings being treated as errors

vim +869 drivers/media/i2c/imx258.c

850
851 static int imx258_set_pad_format(struct v4l2_subdev *sd,
852 struct v4l2_subdev_pad_config *cfg,
853 struct v4l2_subdev_format *fmt)
854 {
855 struct imx258 *imx258 = to_imx258(sd);
856 const struct imx258_mode *mode;
857 struct v4l2_mbus_framefmt *framefmt;
858 s32 vblank_def;
859 s32 vblank_min;
860 s64 h_blank;
861 s64 pixel_rate;
862 s64 link_freq;
863
864 mutex_lock(&imx258->mutex);
865
866 /* Only one raw bayer(GBRG) order is supported */
867 fmt->format.code = MEDIA_BUS_FMT_SGRBG10_1X10;
868

 > 869		mode = v4l2_find_nearest_size(
 > 870			supported_modes, ARRAY_SIZE(supported_modes), width, height,
 > 871			fmr->format.width, fmt->format.height);

872 imx258_update_pad_format(mode, fmt);
873 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
874 framefmt = v4l2_subdev_get_try_format(sd, cfg, fmt->pad);
875 *framefmt = fmt->format;
876 } else {
877 imx258->cur_mode = mode;
878 __v4l2_ctrl_s_ctrl(imx258->link_freq, mode->link_freq_index);
879
880 link_freq = link_freq_menu_items[mode->link_freq_index];
881 pixel_rate = link_freq_to_pixel_rate(link_freq);
882 __v4l2_ctrl_s_ctrl_int64(imx258->pixel_rate, pixel_rate);
883 /* Update limits and set FPS to default */
884 vblank_def = imx258->cur_mode->vts_def -
885 imx258->cur_mode->height;
886 vblank_min = imx258->cur_mode->vts_min -
887 imx258->cur_mode->height;
888 __v4l2_ctrl_modify_range(
889 imx258->vblank, vblank_min,
890 IMX258_VTS_MAX - imx258->cur_mode->height, 1,
891 vblank_def);
892 __v4l2_ctrl_s_ctrl(imx258->vblank, vblank_def);
893 h_blank =
894 link_freq_configs[mode->link_freq_index].pixels_per_line
895 - imx258->cur_mode->width;
896 __v4l2_ctrl_modify_range(imx258->hblank, h_blank,
897 h_blank, 1, h_blank);
898 }
899
900 mutex_unlock(&imx258->mutex);
901
902 return 0;
903 }
904

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

author
#7 lore raw

Hi Ikp,

Per sync with Sakari, Mauro'd handle the pull request for "v4l2_find_nearest_size" patch (https://patchwork.kernel.org/patch/10207087/) early next week. Hence only fixed a typo in v9.1. https://patchwork.linuxtv.org/patch/47976/
Thanks a lot!

Regards, Andy

-----Original Message-----
From: lkp
Sent: Friday, March 16, 2018 10:14 PM
To: Yeh, Andy <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; Yeh, Andy <[email protected]>; Chen, JasonX Z <[email protected]>; Chiang, AlanX <[email protected]>; Lai, Jim <[email protected]>
Subject: Re: [PATCH v8] media: imx258: Add imx258 camera sensor driver

Hi Jason,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on linus/master]
[also build test ERROR on v4.16-rc5 next-20180316] [if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url: https://github.com/0day-ci/linux/commits/Andy-Yeh/media-imx258-Add-imx258-camera-sensor-driver/20180316-201540
config: i386-allmodconfig (attached as .config)
compiler: gcc-7 (Debian 7.3.0-1) 7.3.0
reproduce:

        # save the attached .config to linux build tree
        make ARCH=i386 

All errors (new ones prefixed by >>):

drivers/media/i2c/imx258.c: In function 'imx258_set_pad_format':

Quoted 3 lines
Quoted 3 lines

drivers/media/i2c/imx258.c:869:9: error: implicit declaration of function 'v4l2_find_nearest_size'; did you mean 'v4l2_find_nearest_format'? [-Werror=implicit-function-declaration]

     mode = v4l2_find_nearest_size(
            ^~~~~~~~~~~~~~~~~~~~~~
            v4l2_find_nearest_format
Quoted 2 lines
Quoted 2 lines

drivers/media/i2c/imx258.c:870:49: error: 'width' undeclared (first use in this function)

supported_modes, ARRAY_SIZE(supported_modes), width, height,
^~~~~
drivers/media/i2c/imx258.c:870:49: note: each undeclared identifier is reported only once for each function it appears in

Quoted 1 line
Quoted 1 line

drivers/media/i2c/imx258.c:870:56: error: 'height' undeclared (first use in this function); did you mean 'hweight8'?

supported_modes, ARRAY_SIZE(supported_modes), width, height,
^~~~~~ hweight8

Quoted 1 line
Quoted 1 line

drivers/media/i2c/imx258.c:871:3: error: 'fmr' undeclared (first use in this function); did you mean 'fmt'?

      fmr->format.width, fmt->format.height);
      ^~~
      fmt

cc1: some warnings being treated as errors

vim +869 drivers/media/i2c/imx258.c

850
851 static int imx258_set_pad_format(struct v4l2_subdev *sd,
852 struct v4l2_subdev_pad_config *cfg,
853 struct v4l2_subdev_format *fmt)
854 {
855 struct imx258 *imx258 = to_imx258(sd);
856 const struct imx258_mode *mode;
857 struct v4l2_mbus_framefmt *framefmt;
858 s32 vblank_def;
859 s32 vblank_min;
860 s64 h_blank;
861 s64 pixel_rate;
862 s64 link_freq;
863
864 mutex_lock(&imx258->mutex);
865
866 /* Only one raw bayer(GBRG) order is supported */
867 fmt->format.code = MEDIA_BUS_FMT_SGRBG10_1X10;
868

Quoted 3 lines

869 mode = v4l2_find_nearest_size(
870 supported_modes, ARRAY_SIZE(supported_modes), width, height,
871 fmr->format.width, fmt->format.height);

872 imx258_update_pad_format(mode, fmt);
873 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
874 framefmt = v4l2_subdev_get_try_format(sd, cfg, fmt->pad);
875 *framefmt = fmt->format;
876 } else {
877 imx258->cur_mode = mode;
878 __v4l2_ctrl_s_ctrl(imx258->link_freq, mode->link_freq_index);
879
880 link_freq = link_freq_menu_items[mode->link_freq_index];
881 pixel_rate = link_freq_to_pixel_rate(link_freq);
882 __v4l2_ctrl_s_ctrl_int64(imx258->pixel_rate, pixel_rate);
883 /* Update limits and set FPS to default */
884 vblank_def = imx258->cur_mode->vts_def -
885 imx258->cur_mode->height;
886 vblank_min = imx258->cur_mode->vts_min -
887 imx258->cur_mode->height;
888 __v4l2_ctrl_modify_range(
889 imx258->vblank, vblank_min,
890 IMX258_VTS_MAX - imx258->cur_mode->height, 1,
891 vblank_def);
892 __v4l2_ctrl_s_ctrl(imx258->vblank, vblank_def);
893 h_blank =
894 link_freq_configs[mode->link_freq_index].pixels_per_line
895 - imx258->cur_mode->width;
896 __v4l2_ctrl_modify_range(imx258->hblank, h_blank,
897 h_blank, 1, h_blank);
898 }
899
900 mutex_unlock(&imx258->mutex);
901
902 return 0;
903 }
904

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

#8 lore raw
In reply to Andy Yeh
Thank you for the patch! Yet something to improve:

Hi Jason,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on linus/master]
[also build test ERROR on v4.16-rc5 next-20180316]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url: https://github.com/0day-ci/linux/commits/Andy-Yeh/media-imx258-Add-imx258-camera-sensor-driver/20180316-201540
config: i386-allyesconfig (attached as .config)
compiler: gcc-7 (Debian 7.3.0-1) 7.3.0 reproduce:

        # save the attached .config to linux build tree
        make ARCH=i386 

All errors (new ones prefixed by >>):

drivers/media/i2c/imx258.c: In function 'imx258_set_pad_format':
drivers/media/i2c/imx258.c:869:9: error: implicit declaration of function 'v4l2_find_nearest_size'; did you mean 'v4l2_find_nearest_format'? [-Werror=implicit-function-declaration]

     mode = v4l2_find_nearest_size(
            ^~~~~~~~~~~~~~~~~~~~~~
            v4l2_find_nearest_format
   drivers/media/i2c/imx258.c:870:200: error: 'width' undeclared (first use in this function)
      supported_modes, ARRAY_SIZE(supported_modes), width, height,
                                                                                                                                                                                                           ^    
   drivers/media/i2c/imx258.c:870:200: note: each undeclared identifier is reported only once for each function it appears in
>> drivers/media/i2c/imx258.c:870:207: error: 'height' undeclared (first use in this function); did you mean '__iget'?
      supported_modes, ARRAY_SIZE(supported_modes), width, height,
                                                                                                                                                                                                                  ^     
                                                                                                                                                                                                                  __iget
   drivers/media/i2c/imx258.c:871:3: error: 'fmr' undeclared (first use in this function); did you mean 'fmt'?
      fmr->format.width, fmt->format.height);
      ^~~
      fmt

cc1: some warnings being treated as errors

vim +870 drivers/media/i2c/imx258.c

850
851 static int imx258_set_pad_format(struct v4l2_subdev *sd,
852 struct v4l2_subdev_pad_config *cfg,
853 struct v4l2_subdev_format *fmt)
854 {
855 struct imx258 *imx258 = to_imx258(sd);
856 const struct imx258_mode *mode;
857 struct v4l2_mbus_framefmt *framefmt;
858 s32 vblank_def;
859 s32 vblank_min;
860 s64 h_blank;
861 s64 pixel_rate;
862 s64 link_freq;
863
864 mutex_lock(&imx258->mutex);
865
866 /* Only one raw bayer(GBRG) order is supported */
867 fmt->format.code = MEDIA_BUS_FMT_SGRBG10_1X10;
868

 > 869		mode = v4l2_find_nearest_size(
 > 870			supported_modes, ARRAY_SIZE(supported_modes), width, height,

871 fmr->format.width, fmt->format.height);
872 imx258_update_pad_format(mode, fmt);
873 if (fmt->which == V4L2_SUBDEV_FORMAT_TRY) {
874 framefmt = v4l2_subdev_get_try_format(sd, cfg, fmt->pad);
875 *framefmt = fmt->format;
876 } else {
877 imx258->cur_mode = mode;
878 __v4l2_ctrl_s_ctrl(imx258->link_freq, mode->link_freq_index);
879
880 link_freq = link_freq_menu_items[mode->link_freq_index];
881 pixel_rate = link_freq_to_pixel_rate(link_freq);
882 __v4l2_ctrl_s_ctrl_int64(imx258->pixel_rate, pixel_rate);
883 /* Update limits and set FPS to default */
884 vblank_def = imx258->cur_mode->vts_def -
885 imx258->cur_mode->height;
886 vblank_min = imx258->cur_mode->vts_min -
887 imx258->cur_mode->height;
888 __v4l2_ctrl_modify_range(
889 imx258->vblank, vblank_min,
890 IMX258_VTS_MAX - imx258->cur_mode->height, 1,
891 vblank_def);
892 __v4l2_ctrl_s_ctrl(imx258->vblank, vblank_def);
893 h_blank =
894 link_freq_configs[mode->link_freq_index].pixels_per_line
895 - imx258->cur_mode->width;
896 __v4l2_ctrl_modify_range(imx258->hblank, h_blank,
897 h_blank, 1, h_blank);
898 }
899
900 mutex_unlock(&imx258->mutex);
901
902 return 0;
903 }
904

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation