Skip to contentSkip to conversation

media: imx208: Add imx208 camera sensor driver

PATCH Superseded Ping-chung Chen 2 participants 3 messages Aug 1, 2018 – Aug 2, 2018

Subsystems (3)

v3 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 media: imx208: Add imx208 camera sensor driver

From: "Chen, Ping-chung" <[email protected]>

Add a V4L2 sub-device driver for the Sony IMX208 image sensor. This is a camera sensor using the I2C bus for control and the CSI-2 bus for data.

---
since v1:
-- Update the function media_entity_pads_init for upstreaming. -- Change the structure name mutex as imx208_mx.
-- Refine the control flow of test pattern function.
-- vflip/hflip control support (will impact the output bayer order) -- support 4 bayer orders output (via change v/hflip)
- SRGGB10(default), SGRBG10, SGBRG10, SBGGR10
-- Simplify error handling in the set_stream function. since v2:
-- Refine coding style.
-- Fix the if statement to use pm_runtime_get_if_in_use(). -- Print more error log during error handling.
-- Remove mutex_destroy() from imx208_free_controls(). -- Add more comments.

 MAINTAINERS                |   7 +
 drivers/media/i2c/Kconfig  |  11 +
 drivers/media/i2c/Makefile |   1 +
 drivers/media/i2c/imx208.c | 995 +++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 1014 insertions(+)
 create mode 100644 drivers/media/i2c/imx208.c
MAINTAINERS +7 -0
index bbd9b9b..896c1df 100644
@@ -13268,6 +13268,13 @@ S:	Maintained
 F:	drivers/ssb/
 F:	include/linux/ssb/
 
+SONY IMX208 SENSOR DRIVER
+M:	Sakari Ailus <[email protected]>
+L:	[email protected]
+T:	git git://linuxtv.org/media_tree.git
+S:	Maintained
+F:	drivers/media/i2c/imx208.c
+
 SONY IMX258 SENSOR DRIVER
 M:	Sakari Ailus <[email protected]>
 L:	[email protected]
drivers/media/i2c/Kconfig +11 -0
index 8669853..ae11f1e 100644
@@ -595,6 +595,17 @@ config VIDEO_APTINA_PLL
 config VIDEO_SMIAPP_PLL
 	tristate
 
+config VIDEO_IMX208
+	tristate "Sony IMX208 sensor support"
+	depends on I2C && VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API
+	depends on MEDIA_CAMERA_SUPPORT
+	---help---
+	  This is a Video4Linux2 sensor driver for the Sony
+	  IMX208 camera.
+
+          To compile this driver as a module, choose M here: the
+          module will be called imx208.
+
 config VIDEO_IMX258
 	tristate "Sony IMX258 sensor support"
 	depends on I2C && VIDEO_V4L2 && VIDEO_V4L2_SUBDEV_API
drivers/media/i2c/Makefile +1 -0
index 837c428..47604c2 100644
@@ -104,6 +104,7 @@ obj-$(CONFIG_VIDEO_I2C)		+= video-i2c.o
 obj-$(CONFIG_VIDEO_ML86V7667)	+= ml86v7667.o
 obj-$(CONFIG_VIDEO_OV2659)	+= ov2659.o
 obj-$(CONFIG_VIDEO_TC358743)	+= tc358743.o
+obj-$(CONFIG_VIDEO_IMX208)	+= imx208.o
 obj-$(CONFIG_VIDEO_IMX258)	+= imx258.o
 obj-$(CONFIG_VIDEO_IMX274)	+= imx274.o
 
drivers/media/i2c/imx208.c new file +995 -0

995 lines not on this page · raw message

Signature · 1 line
1.9.1
#1 lore raw

Hi Ping-chung,

Quoted 8 lines · Ping-chung Chen

From: "Chen, Ping-chung" <[email protected]>

Add a V4L2 sub-device driver for the Sony IMX208 image sensor. This is a camera sensor using the I2C bus for control and the CSI-2 bus for data.

Quoted 15 lines

---
since v1:
-- Update the function media_entity_pads_init for upstreaming. -- Change the structure name mutex as imx208_mx.
-- Refine the control flow of test pattern function.
-- vflip/hflip control support (will impact the output bayer order) -- support 4 bayer orders output (via change v/hflip)
- SRGGB10(default), SGRBG10, SGBRG10, SBGGR10
-- Simplify error handling in the set_stream function. since v2:
-- Refine coding style.
-- Fix the if statement to use pm_runtime_get_if_in_use(). -- Print more error log during error handling.
-- Remove mutex_destroy() from imx208_free_controls(). -- Add more comments.

Thanks for addressing the comments. There are still few remaining, though. Please see inline.

[snip]

Quoted 11 lines
drivers/media/i2c/imx208.c new file +11 -0
+enum {
+       IMX208_LINK_FREQ_384MHZ_INDEX,
+       IMX208_LINK_FREQ_96MHZ_INDEX,
+};
+
+/*
+ * pixel_rate = link_freq * data-rate * nr_of_lanes / bits_per_sample
+ * data rate => double data rate; number of lanes => 2; bits per pixel => 10
+ */
+static u64 link_freq_to_pixel_rate(u64 f)
+{

drivers/media/i2c/imx208.c line 218

Quoted 10 lines
drivers/media/i2c/imx208.c new file +10 -0
+       f *= IMX208_DATA_RATE_DOUBLE * IMX208_NUM_OF_LANES;
+       do_div(f, IMX208_PIXEL_BITS);
+
+       return f;
+}
+
+/* Menu items for LINK_FREQ V4L2 control */
+static const s64 link_freq_menu_items[] = {
+       IMX208_LINK_FREQ_384MHZ,
+       IMX208_LINK_FREQ_96MHZ,

I asked for having explicit indices using IMX208_LINK_FREQ_*_INDEX enum used here too.

Quoted 13 lines
drivers/media/i2c/imx208.c new file +13 -0
+};
+
+/* Link frequency configs */
+static const struct imx208_link_freq_config link_freq_configs[] = {
+       [IMX208_LINK_FREQ_384MHZ_INDEX] = {
+               .pixels_per_line = IMX208_PPL_384MHZ,
+               .reg_list = {
+                       .num_of_regs = ARRAY_SIZE(pll_ctrl_reg),
+                       .regs = pll_ctrl_reg,
+               }
+       },
+       [IMX208_LINK_FREQ_96MHZ_INDEX] = {
+               .pixels_per_line = IMX208_PPL_96MHZ,

drivers/media/i2c/imx208.c line 241

Quoted 10 lines
drivers/media/i2c/imx208.c new file +10 -0
+               .reg_list = {
+                       .num_of_regs = ARRAY_SIZE(pll_ctrl_reg),
+                       .regs = pll_ctrl_reg,
+               }
+       },
+};
+
+/* Mode configs */
+static const struct imx208_mode supported_modes[] = {
+       [IMX208_LINK_FREQ_384MHZ_INDEX] = {

This is not the right index for this array (even if numerically the same. This array is just a list of available modes (resolutions) and there is no other data structure referring to particular entries of it, so it doesn't need explicit indexing.

drivers/media/i2c/imx208.c line 252

Quoted 11 lines
drivers/media/i2c/imx208.c new file +11 -0
+               .width = 1936,
+               .height = 1096,
+               .vts_def = IMX208_VTS_60FPS,
+               .vts_min = IMX208_VTS_60FPS_MIN,
+               .reg_list = {
+                       .num_of_regs = ARRAY_SIZE(mode_1936x1096_60fps_regs),
+                       .regs = mode_1936x1096_60fps_regs,
+               },
+               .link_freq_index = IMX208_LINK_FREQ_384MHZ_INDEX,
+       },
+       [IMX208_LINK_FREQ_96MHZ_INDEX] = {

Ditto.

Best regards,
Tomasz

#2 lore raw

Hi Tomasz,

Please see my comments.

-----Original Message-----

Quoted 28 lines

Hi Ping-chung,

On Wed, Aug 1, 2018 at 11:31 AM Ping-chung Chen <[email protected]> wrote:

From: "Chen, Ping-chung" <[email protected]>

Add a V4L2 sub-device driver for the Sony IMX208 image sensor. This is a camera sensor using the I2C bus for control and the CSI-2 bus for data.

---
since v1:
-- Update the function media_entity_pads_init for upstreaming. -- Change the structure name mutex as imx208_mx.
-- Refine the control flow of test pattern function.
-- vflip/hflip control support (will impact the output bayer order) -- support 4 bayer orders output (via change v/hflip)
- SRGGB10(default), SGRBG10, SGBRG10, SBGGR10
-- Simplify error handling in the set_stream function. since v2:
-- Refine coding style.
-- Fix the if statement to use pm_runtime_get_if_in_use(). -- Print more error log during error handling.
-- Remove mutex_destroy() from imx208_free_controls(). -- Add more comments.

Thanks for addressing the comments. There are still few remaining, though. Please see inline.

[snip]

Quoted 20 lines
drivers/media/i2c/imx208.c new file +19 -0
+enum {
+       IMX208_LINK_FREQ_384MHZ_INDEX,
+       IMX208_LINK_FREQ_96MHZ_INDEX,
+};
+
+/*
+ * pixel_rate = link_freq * data-rate * nr_of_lanes / bits_per_sample
+ * data rate => double data rate; number of lanes => 2; bits per 
+pixel => 10  */ static u64 link_freq_to_pixel_rate(u64 f) {
+       f *= IMX208_DATA_RATE_DOUBLE * IMX208_NUM_OF_LANES;
+       do_div(f, IMX208_PIXEL_BITS);
+
+       return f;
+}
+
+/* Menu items for LINK_FREQ V4L2 control */ static const s64 
+link_freq_menu_items[] = {
+       IMX208_LINK_FREQ_384MHZ,
+       IMX208_LINK_FREQ_96MHZ,
Quoted 1 line

I asked for having explicit indices using IMX208_LINK_FREQ_*_INDEX enum used here too.

Sorry I forgot this one, fixed.

Quoted 24 lines
drivers/media/i2c/imx208.c new file +23 -0
+};
+
+/* Link frequency configs */
+static const struct imx208_link_freq_config link_freq_configs[] = {
+       [IMX208_LINK_FREQ_384MHZ_INDEX] = {
+               .pixels_per_line = IMX208_PPL_384MHZ,
+               .reg_list = {
+                       .num_of_regs = ARRAY_SIZE(pll_ctrl_reg),
+                       .regs = pll_ctrl_reg,
+               }
+       },
+       [IMX208_LINK_FREQ_96MHZ_INDEX] = {
+               .pixels_per_line = IMX208_PPL_96MHZ,
+               .reg_list = {
+                       .num_of_regs = ARRAY_SIZE(pll_ctrl_reg),
+                       .regs = pll_ctrl_reg,
+               }
+       },
+};
+
+/* Mode configs */
+static const struct imx208_mode supported_modes[] = {
+       [IMX208_LINK_FREQ_384MHZ_INDEX] = {
Quoted 1 line

This is not the right index for this array (even if numerically the same. This array is just a list of available modes (resolutions) and there is no other data structure referring to particular entries of it, so it doesn't need explicit indexing.

Done.

Quoted 12 lines
drivers/media/i2c/imx208.c new file +11 -0
+               .width = 1936,
+               .height = 1096,
+               .vts_def = IMX208_VTS_60FPS,
+               .vts_min = IMX208_VTS_60FPS_MIN,
+               .reg_list = {
+                       .num_of_regs = ARRAY_SIZE(mode_1936x1096_60fps_regs),
+                       .regs = mode_1936x1096_60fps_regs,
+               },
+               .link_freq_index = IMX208_LINK_FREQ_384MHZ_INDEX,
+       },
+       [IMX208_LINK_FREQ_96MHZ_INDEX] = {
Quoted 1 line

Ditto.

Best regards,
Tomasz