IMX334 Camera Sensor Driver
Subsystems (4)
v4 cover IMX334 Camera Sensor Driver
From: Martina Krasteva <[email protected]>
Hello,
This patch series contains Sony imx334 sensor driver and device tree binding document.
A v4l2 sub-device driver for the Sony imx334 image sensor is added. This is a camera sensor using the i2c bus for control and the csi-2 bus for data.
The following features are supported:
- manual exposure and analog gain control support
- vblank/hblank/pixel rate control support
- supported resolution:
- 3840x2160 @ 60fps
- supported bayer order output:
- SRGGB12
v1: https://patchwork.kernel.org/project/linux-media/list/?series=388393
v1->v2:
- dt-bindings doc fixes
- minor cosmetic changes
- improvement in write_reg()
- set all media bus format fields to pass v4l2-compliance test
- remove link_validate from source entity
v2: https://patchwork.kernel.org/project/linux-media/list/?series=396393
v2->v3:
- small cosmetic changes
v3: https://patchwork.kernel.org/project/linux-media/list/?series=397689
v3->v4:
- fix read/write_reg() functions
Best Regards,
Martina
Martina Krasteva (2):
dt-bindings: media: Add bindings for imx334
media: i2c: Add imx334 camera sensor driver
.../devicetree/bindings/media/i2c/sony,imx334.yaml | 62 ++ MAINTAINERS | 9 + drivers/media/i2c/Kconfig | 14 + drivers/media/i2c/Makefile | 1 + drivers/media/i2c/imx334.c | 1038 ++++++++++++++++++++ 5 files changed, 1124 insertions(+) create mode 100644 Documentation/devicetree/bindings/media/i2c/sony,imx334.yaml create mode 100644 drivers/media/i2c/imx334.c
Signature · 1 line
2.11.0
PATCH v4 1/2 dt-bindings: media: Add bindings for imx334
From: Martina Krasteva <[email protected]>
- Add dt-bindings documentation for Sony imx334 sensor driver.
- Add MAINTAINERS entry for Sony imx334 binding documentation.
--- .../devicetree/bindings/media/i2c/sony,imx334.yaml | 62 ++++++++++++++++++++++ MAINTAINERS | 8 +++ 2 files changed, 70 insertions(+) create mode 100644 Documentation/devicetree/bindings/media/i2c/sony,imx334.yaml
Documentation/devicetree/bindings/media/i2c/sony,imx334.yaml new file +62 -0
@@ -0,0 +1,62 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +# Copyright (C) 2020 Intel Corporation +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/media/i2c/sony,imx334.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Sony IMX334 Sensor + +maintainers: + - Paul J. Murphy <[email protected]> + - Daniele Alessandrelli <[email protected]> + +description: + IMX334 sensor is a Sony CMOS active pixel digital image sensor with an active + array size of 3864H x 2202V. It is programmable through I2C interface. The + I2C client address is fixed to 0x1a as per sensor data sheet. Image data is + sent through MIPI CSI-2. + +properties: + compatible: + const: sony,imx334 + reg: + description: I2C address + maxItems: 1 + + # See ../video-interfaces.txt for more details + port: + type: object + properties: + endpoint: + type: object + properties: + remote-endpoint: + description: See ../video-interfaces.txt + data-lanes: + description: See ../video-interfaces.txt + +additionalProperties: false + +required: + - compatible + - port + +examples: + - | + i2c0 { + #address-cells = <1>; + #size-cells = <0>; + + camera@1a { + compatible = "sony,imx334"; + reg = <0x1a>; + + port { + imx334: endpoint { + remote-endpoint = <&cam>; + data-lanes = <1 2 3 4>; + }; + }; + }; + };
MAINTAINERS +8 -0
@@ -16308,6 +16308,14 @@ S: Maintained T: git git://linuxtv.org/media_tree.git F: drivers/media/i2c/imx319.c +SONY IMX334 SENSOR DRIVER +M: Paul J. Murphy <[email protected]> +M: Daniele Alessandrelli <[email protected]> +L: [email protected] +S: Maintained +T: git git://linuxtv.org/media_tree.git +F: Documentation/devicetree/bindings/media/i2c/sony,imx334.yaml + SONY IMX355 SENSOR DRIVER M: Tianshu Qiu <[email protected]> L: [email protected]
Signature · 1 line
2.11.0
PATCH v4 2/2 media: i2c: Add imx334 camera sensor driver
In reply to Martina KrastevaFrom: Martina Krasteva <[email protected]>
Add a v4l2 sub-device driver for the Sony imx334 image sensor. This is a camera sensor using the i2c bus for control and the csi-2 bus for data.
The following features are supported:
- manual exposure and analog gain control support
- vblank/hblank/pixel rate control support
- supported resolution:
- 3840x2160 @ 60fps
- supported bayer order output:
- SRGGB12
--- MAINTAINERS | 1 + drivers/media/i2c/Kconfig | 14 + drivers/media/i2c/Makefile | 1 + drivers/media/i2c/imx334.c | 1038 ++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 1054 insertions(+) create mode 100644 drivers/media/i2c/imx334.c
MAINTAINERS +1 -0
@@ -16315,6 +16315,7 @@ L: [email protected] S: Maintained T: git git://linuxtv.org/media_tree.git F: Documentation/devicetree/bindings/media/i2c/sony,imx334.yaml +F: drivers/media/i2c/imx334.c SONY IMX355 SENSOR DRIVER M: Tianshu Qiu <[email protected]>
drivers/media/i2c/Kconfig +14 -0
@@ -813,6 +813,20 @@ config VIDEO_IMX319 To compile this driver as a module, choose M here: the module will be called imx319. +config VIDEO_IMX334 + tristate "Sony IMX334 sensor support" + depends on OF_GPIO + depends on I2C && VIDEO_V4L2 + select VIDEO_V4L2_SUBDEV_API + select MEDIA_CONTROLLER + select V4L2_FWNODE + help + This is a Video4Linux2 sensor driver for the Sony + IMX334 camera. + + To compile this driver as a module, choose M here: the + module will be called imx334. + config VIDEO_IMX355 tristate "Sony IMX355 sensor support" depends on I2C && VIDEO_V4L2
drivers/media/i2c/Makefile +1 -0
@@ -118,6 +118,7 @@ obj-$(CONFIG_VIDEO_IMX258) += imx258.o obj-$(CONFIG_VIDEO_IMX274) += imx274.o obj-$(CONFIG_VIDEO_IMX290) += imx290.o obj-$(CONFIG_VIDEO_IMX319) += imx319.o +obj-$(CONFIG_VIDEO_IMX334) += imx334.o obj-$(CONFIG_VIDEO_IMX355) += imx355.o obj-$(CONFIG_VIDEO_MAX9286) += max9286.o rdacm20-camera_module-objs := rdacm20.o max9271.o
drivers/media/i2c/imx334.c new file +1038 -0
1,038 lines not on this page · raw message
Signature · 1 line
2.11.0
Sakari Ailus
maintainerRe: [PATCH v4 2/2] media: i2c: Add imx334 camera sensor driver
Hi Martina,
On Fri, Dec 11, 2020 at 10:56:33AM +0000, Martina Krasteva wrote:
...
Quoted 20 lines
drivers/media/i2c/imx334.c new file +20
-0+static int imx334_read_reg (struct imx334 *imx334,u16 reg,u32 len,u32 *val) +{ +struct i2c_client *client =v4l2_get_subdevdata (&imx334->sd); +struct i2c_msg msgs[2 ] = {0 }; +u8 addr_buf[2 ] = {0 }; +u8 data_buf[4 ] = {0 }; +int ret; + +if (WARN_ON (len >4 )) +return -EINVAL ; + +put_unaligned_be16 (reg, addr_buf); + +/* Write register address */ + msgs[0 ].addr = client->addr; + msgs[0 ].flags =0 ; + msgs[0 ].len =ARRAY_SIZE (addr_buf); + msgs[0 ].buf = addr_buf; + +/* Read data from register */
drivers/media/i2c/imx334.c line 296
Quoted 10 lines
drivers/media/i2c/imx334.c new file +10
-0+ msgs[1 ].addr = client->addr; + msgs[1 ].flags =I2C_M_RD ; + msgs[1 ].len = len; + msgs[1 ].buf = &data_buf[4 - len]; + + ret =i2c_transfer (client->adapter, msgs,ARRAY_SIZE (msgs)); +if (ret !=ARRAY_SIZE (msgs)) +return -EIO ; + + *val =get_unaligned_le32 (data_buf + (4 - len));
Hmm. The device native endianness is big (on control interface) unless something very unexpected happened in hardware development.
You also can't do this as this will overrun data_buf.
Quoted 13 lines
drivers/media/i2c/imx334.c new file +13
-0+ +return 0 ; +} + +/** +* imx334_write_reg() - Write register +* @imx334: pointer to imx334 device +* @reg: register address +* @len: length of bytes. Max supported bytes is 4 +* @val: register value +* +* Return: 0 if successful, error code otherwise. +*/
drivers/media/i2c/imx334.c line 319
Quoted 10 lines
drivers/media/i2c/imx334.c new file +10
-0+static int imx334_write_reg (struct imx334 *imx334,u16 reg,u32 len,u32 val) +{ +struct i2c_client *client =v4l2_get_subdevdata (&imx334->sd); +u8 buf[6 ] = {0 }; + +if (WARN_ON (len >4 )) +return -EINVAL ; + +put_unaligned_be16 (reg, buf); +put_unaligned_le32 (val, buf +2 );
Similar comment on this one.
Signature · 3 lines
Kind regards, Sakari Ailus
RE: [PATCH v4 2/2] media: i2c: Add imx334 camera sensor driver
Hi Sakari,
Quoted 47 lines
-----Original Message-----
From: Sakari Ailus <[email protected]>
Sent: Friday, December 11, 2020 11:32 AM
To: Martina Krasteva <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v4 2/2] media: i2c: Add imx334 camera sensor driverHi Martina,
On Fri, Dec 11, 2020 at 10:56:33AM +0000, Martina Krasteva wrote:
...Quoted 20 lines
drivers/media/i2c/imx334.c new file +20
-0+static int imx334_read_reg (struct imx334 *imx334,u16 reg,u32 len, +u32 *val) { +struct i2c_client *client =v4l2_get_subdevdata (&imx334->sd); +struct i2c_msg msgs[2 ] = {0 }; +u8 addr_buf[2 ] = {0 }; +u8 data_buf[4 ] = {0 }; +int ret; + +if (WARN_ON (len >4 )) +return -EINVAL ; + +put_unaligned_be16 (reg, addr_buf); + +/* Write register address */ + msgs[0 ].addr = client->addr; + msgs[0 ].flags =0 ; + msgs[0 ].len =ARRAY_SIZE (addr_buf); + msgs[0 ].buf = addr_buf; + +/* Read data from register */ drivers/media/i2c/imx334.c line 296
Quoted 10 lines
drivers/media/i2c/imx334.c new file +10
-0+ msgs[1 ].addr = client->addr; + msgs[1 ].flags =I2C_M_RD ; + msgs[1 ].len = len; + msgs[1 ].buf = &data_buf[4 - len]; + + ret =i2c_transfer (client->adapter, msgs,ARRAY_SIZE (msgs)); +if (ret !=ARRAY_SIZE (msgs)) +return -EIO ; + + *val =get_unaligned_le32 (data_buf + (4 - len));Hmm. The device native endianness is big (on control interface) unless something very unexpected happened in hardware development.
Quoted 1 line
You also can't do this as this will overrun
data_buf.
Imx334 uses little endian so I have to convert the values.
Quoted 31 lines
Quoted 14 lines
drivers/media/i2c/imx334.c new file +13
-0+ +return 0 ; +} + +/** +* imx334_write_reg() - Write register +* @imx334: pointer to imx334 device +* @reg: register address +* @len: length of bytes. Max supported bytes is 4 +* @val: register value +* +* Return: 0 if successful, error code otherwise. +*/ drivers/media/i2c/imx334.c line 319
Quoted 10 lines
drivers/media/i2c/imx334.c new file +10
-0+static int imx334_write_reg (struct imx334 *imx334,u16 reg,u32 len, +u32 val) { +struct i2c_client *client =v4l2_get_subdevdata (&imx334->sd); +u8 buf[6 ] = {0 }; + +if (WARN_ON (len >4 )) +return -EINVAL ; + +put_unaligned_be16 (reg, buf); +put_unaligned_le32 (val, buf +2 );Similar comment on this one.
--
Kind regards,Sakari Ailus
'Sakari Ailus'
maintainerRe: [PATCH v4 2/2] media: i2c: Add imx334 camera sensor driver
Hi Martina,
Quoted 49 lines · Martina Krasteva
Hi Sakari,
Quoted 47 lines
-----Original Message-----
From: Sakari Ailus <[email protected]>
Sent: Friday, December 11, 2020 11:32 AM
To: Martina Krasteva <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v4 2/2] media: i2c: Add imx334 camera sensor driverHi Martina,
On Fri, Dec 11, 2020 at 10:56:33AM +0000, Martina Krasteva wrote:
...Quoted 20 lines
drivers/media/i2c/imx334.c new file +20
-0+static int imx334_read_reg (struct imx334 *imx334,u16 reg,u32 len, +u32 *val) { +struct i2c_client *client =v4l2_get_subdevdata (&imx334->sd); +struct i2c_msg msgs[2 ] = {0 }; +u8 addr_buf[2 ] = {0 }; +u8 data_buf[4 ] = {0 }; +int ret; + +if (WARN_ON (len >4 )) +return -EINVAL ; + +put_unaligned_be16 (reg, addr_buf); + +/* Write register address */ + msgs[0 ].addr = client->addr; + msgs[0 ].flags =0 ; + msgs[0 ].len =ARRAY_SIZE (addr_buf); + msgs[0 ].buf = addr_buf; + +/* Read data from register */ drivers/media/i2c/imx334.c line 296
Quoted 10 lines
drivers/media/i2c/imx334.c new file +10
-0+ msgs[1 ].addr = client->addr; + msgs[1 ].flags =I2C_M_RD ; + msgs[1 ].len = len; + msgs[1 ].buf = &data_buf[4 - len]; + + ret =i2c_transfer (client->adapter, msgs,ARRAY_SIZE (msgs)); +if (ret !=ARRAY_SIZE (msgs)) +return -EIO ; + + *val =get_unaligned_le32 (data_buf + (4 - len));Hmm. The device native endianness is big (on control interface) unless something very unexpected happened in hardware development.
Quoted 3 lines
Quoted 1 line
You also can't do this as this will overrun
data_buf.Imx334 uses little endian so I have to convert the values.
Ack. That's very unusual, and probably the first raw camera sensor implemented that way.
Could you fix the data_buf overrun?
Signature · 1 line
Sakari Ailus
RE: [PATCH v4 2/2] media: i2c: Add imx334 camera sensor driver
Hi Sakari,
Quoted 25 lines
-----Original Message-----
From: 'Sakari Ailus' <[email protected]>
Sent: Monday, January 25, 2021 12:55 PM
To: Martina Krasteva <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v4 2/2] media: i2c: Add imx334 camera sensor driverHi Martina,
Quoted 13 lines · Martina Krasteva
Hi Sakari,
Quoted 11 lines
-----Original Message-----
From: Sakari Ailus <[email protected]>
Sent: Friday, December 11, 2020 11:32 AM
To: Martina Krasteva <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v4 2/2] media: i2c: Add imx334 camera sensor driver
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
Hi Martina,
On Fri, Dec 11, 2020 at 10:56:33AM +0000, Martina Krasteva wrote:
...Review
Quoted 4 lines
(quoted diff) +4
-0+static int imx334_read_reg(struct imx334 *imx334, u16 reg, u32 +len, +u32 *val) { + struct i2c_client *client =
v4l2_get_subdevdata(&imx334->sd);
Quoted 31 lines
Quoted 31 lines
Quoted 31 lines
Quoted 17 lines
drivers/media/i2c/imx334.c new file +17
-0+struct i2c_msg msgs[2 ] = {0 }; +u8 addr_buf[2 ] = {0 }; +u8 data_buf[4 ] = {0 }; +int ret; + +if (WARN_ON (len >4 )) +return -EINVAL ; + +put_unaligned_be16 (reg, addr_buf); + +/* Write register address */ + msgs[0 ].addr = client->addr; + msgs[0 ].flags =0 ; + msgs[0 ].len =ARRAY_SIZE (addr_buf); + msgs[0 ].buf = addr_buf; + +/* Read data from register */ drivers/media/i2c/imx334.c line 296
Quoted 10 lines
drivers/media/i2c/imx334.c new file +10
-0+ msgs[1 ].addr = client->addr; + msgs[1 ].flags =I2C_M_RD ; + msgs[1 ].len = len; + msgs[1 ].buf = &data_buf[4 - len]; + + ret =i2c_transfer (client->adapter, msgs,ARRAY_SIZE (msgs)); +if (ret !=ARRAY_SIZE (msgs)) +return -EIO ; + + *val =get_unaligned_le32 (data_buf + (4 - len));Hmm. The device native endianness is big (on control interface) unless something very unexpected happened in hardware development.
Quoted 5 lines
Quoted 3 lines
Quoted 1 line
You also can't do this as this will overrun
data_buf.Imx334 uses little endian so I have to convert the values.
Ack. That's very unusual, and probably the first raw camera sensor
implemented
Quoted 4 lines
that way.
Could you fix the
data_bufoverrun?
Yes, will be fixed in next version :)
Quoted 2 lines
--
Sakari Ailus
Kind Regards,
Martina
Sakari Ailus
maintainerRe: [PATCH v4 2/2] media: i2c: Add imx334 camera sensor driver
In reply to Martina KrastevaHi Martina,
A few more comments.
Quoted 6 lines · Martina Krasteva
From: Martina Krasteva <[email protected]>
Add a v4l2 sub-device driver for the Sony imx334 image sensor. This is a camera sensor using the i2c bus for control and the csi-2 bus for data.
Quoted 7 lines
The following features are supported:
- manual exposure and analog gain control support
- vblank/hblank/pixel rate control support
- supported resolution:
- 3840x2160 @ 60fps
- supported bayer order output:
- SRGGB12
Could you add the external clock and link frequencies related properties to the bindings and use them in the driver?
<URL:https://hverkuil.home.xs4all.nl/spec/driver-api/camera-sensor.html>
Apart from these it looks good to me.
Signature · 3 lines
Kind regards, Sakari Ailus
RE: [PATCH v4 2/2] media: i2c: Add imx334 camera sensor driver
Hi Sakari,
Quoted 28 lines
-----Original Message-----
From: Sakari Ailus <[email protected]>
Sent: Monday, January 25, 2021 1:09 PM
To: Martina Krasteva <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v4 2/2] media: i2c: Add imx334 camera sensor driverHi Martina,
A few more comments.
Quoted 6 lines · Martina Krasteva
From: Martina Krasteva <[email protected]>
Add a v4l2 sub-device driver for the Sony imx334 image sensor. This is a camera sensor using the i2c bus for control and the csi-2 bus for data.
Quoted 7 lines
The following features are supported:
- manual exposure and analog gain control support
- vblank/hblank/pixel rate control support
- supported resolution:
- 3840x2160 @ 60fps
- supported bayer order output:
- SRGGB12
Quoted 1 line
Could you add the external clock and link frequencies related properties
to the
Quoted 5 lines
bindings and use them in the driver?
<URL:https://hverkuil.home.xs4all.nl/spec/driver-api/camera-sensor.html>
Apart from these it looks good to me.
Thanks, the properties and the handling in the driver will be added in next version
Quoted 5 lines
--
Kind regards,Sakari Ailus
Kind Regards,
Martina