Skip to content

Sony IMX290/IMX327 support - #3691

Merged
pelwell merged 23 commits into
raspberrypi:rpi-5.4.yfrom
6by9:imx290
Jun 26, 2020
Merged

pelwell merged 23 commits into
raspberrypi:rpi-5.4.yfrom
6by9:imx290

Conversation

@6by9

@6by9 6by9 commented Jun 26, 2020

Copy link
Copy Markdown
Contributor

Sony IMX290 and IMX327 are broadly compatible sensors.
Backport the mainline driver and latest fixes (in linuxtv/master, not yet in torvalds linux/master).
Adds additional controls, alternate oscillator frequency support, and an overlay to load the thing.

I still need to compile test this branch, and make sure that the changes in the header comments to the driver are in a sensible patch (I think they may have got mixed up with other stuff).

Mani-Sadhasivam and others added 3 commits June 26, 2020 15:23
Commit 8a97a46 upstream.

Add devicetree binding for IMX290 CMOS image sensor. Let's also
add MAINTAINERS entry for the binding and driver.

Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Reviewed-by: Rob Herring <robh@kernel.org>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
Commit 828dbc2 upstream.

Add driver for Sony IMX290 CMOS image sensor driver. The driver only
supports I2C interface for programming and MIPI CSI-2 for sensor output.

[Sakari Ailus: Rewrapped a few lines over 80 chars a little.]

Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
Commit d46cfdc upstream.

With the current driver 'media-ctl -p' issued right after the imx290 driver
is loaded prints:
pad0: Source
             [fmt:unknown/0x0]

The format value of zero is due to the current_format field of the imx290
struct not being initialized yet.

As imx290_entity_init_cfg() calls imx290_set_fmt(), the current_mode field
is also initialized, so the line which set current_mode to a default value
in driver's probe() function is no longer needed.

Signed-off-by: Andrey Konovalov <andrey.konovalov@linaro.org>
Reviewed-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
@6by9 6by9 changed the title WIP: Sony IMX290/IMX327 support Sony IMX290/IMX327 support Jun 26, 2020
@6by9

6by9 commented Jun 26, 2020

Copy link
Copy Markdown
Contributor Author

Rebased and removed the WIP tag.
I think this is good for review now.

@6by9

6by9 commented Jun 26, 2020

Copy link
Copy Markdown
Contributor Author

@andrey-konovalov FYI Your/Mani's patches backport, and my couple of extras on top.

Hopefully @davidplowman will be getting it running with libcamera next week when his module arrives.

@pelwell

pelwell commented Jun 26, 2020

Copy link
Copy Markdown
Contributor

Is there a preferred merge order between this and #3688?

@6by9

6by9 commented Jun 26, 2020

Copy link
Copy Markdown
Contributor Author

Is there a preferred merge order between this and #3688?

There shouldn't be. This should work with the older Unicam driver. The imx290 dtoverlay may have a couple of extra bits that the older unicam driver doesn't care about, but those will be ignored.

@6by9

6by9 commented Jun 26, 2020

Copy link
Copy Markdown
Contributor Author

Oh, and the reason I've split the dtoverlay into a imx290 and imx290_327 overlay is so that we can add an imx327 overlay easily if we get to a point where we support the differences between the two (120fps mode on IMX290).

Comment thread arch/arm/boot/dts/overlays/README Resolved
Comment thread drivers/media/i2c/imx290.c Resolved
Comment thread drivers/media/i2c/imx290.c Resolved
Comment thread drivers/media/i2c/imx290.c Resolved
Comment thread drivers/media/i2c/imx290.c Resolved
Comment thread drivers/media/i2c/imx290.c Resolved
Comment thread drivers/media/i2c/imx290.c Resolved
Comment thread drivers/media/i2c/imx290.c Resolved
andrey-konovalov and others added 9 commits June 26, 2020 17:52
Commit 8d2d1be upstream.

The macro is defined as SET_RUNTIME_PM_OPS(suspend_fn, resume_fn, idle_fn),
so imx290_power_off must be the 1st arg, and imx290_power_on the 2nd.

Signed-off-by: Andrey Konovalov <andrey.konovalov@linaro.org>
Reviewed-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Commit 3909a92 upstream.

According to https://www.kernel.org/doc/Documentation/gpio/consumer.txt,

- all of the gpiod_set_value_xxx() functions operate with the *logical*
value. So in imx290_power_on() the reset signal should be cleared
(de-asserted) with gpiod_set_value_cansleep(imx290->rst_gpio, 0), and in
imx290_power_off() the value of 1 must be used to apply/assert the reset
to the sensor. In the device tree the reset pin is described as
GPIO_ACTIVE_LOW, and gpiod_set_value_xxx() functions take this into
account,

- when devm_gpiod_get_optional() is called with GPIOD_ASIS, the GPIO is
not initialized, and the direction must be set later; using a GPIO
without setting its direction first is illegal and will result in undefined
behavior. Fix this by using GPIOD_OUT_HIGH instead of GPIOD_ASIS (this
asserts the reset signal to the sensor initially).

Signed-off-by: Andrey Konovalov <andrey.konovalov@linaro.org>
Reviewed-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Commit 97589ad upstream.

The IMX290 sensor can output frames with 2/4 CSI2 data lanes. This commit
adds support for 2 lane mode in addition to the 4 lane and also
configuring the data lane settings in the driver based on system
configuration.

Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Signed-off-by: Andrey Konovalov <andrey.konovalov@linaro.org>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Commit 98e0500 upstream.

IMX290 operates with multiple link frequency and pixel rate combinations.
The initial driver used a single setting for both but since we now have
the lane count support in place, let's add configurable link frequency
and pixel rate.

Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Signed-off-by: Andrey Konovalov <andrey.konovalov@linaro.org>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Commit a58df1f upstream.

Add support for generating following test patterns by IMX290:

* Sequence Pattern 1
* Horizontal Color-bar Chart
* Vertical Color-bar Chart
* Sequence Pattern 2
* Gradation Pattern 1
* Gradation Pattern 2
* 000/555h Toggle Pattern

Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Signed-off-by: Andrey Konovalov <andrey.konovalov@linaro.org>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Commit c566ac0 upstream.

IMX290 is capable of outputting frames in both Raw Bayer (packed) 10 and
12 bit formats. Since the driver already supports RAW10 mode, let's add
the missing RAW12 mode as well.

Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Signed-off-by: Andrey Konovalov <andrey.konovalov@linaro.org>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Commit 3b867fb upstream.

Add support to enumerate all frame sizes supported by IMX290. This is
required for using with userspace tools such as libcamera.

Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Signed-off-by: Andrey Konovalov <andrey.konovalov@linaro.org>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Commit 6544af9 upstream.

The 10ms settle time is needed only at the end of all consecutive
register writes. So move the delay to outside of the for loop of
imx290_set_register_array().

Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
Signed-off-by: Andrey Konovalov <andrey.konovalov@linaro.org>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
…alloc_parse()

Commit a270675 upstream.

The bus_type field of v4l2_fwnode_endpoint structure passed as the argument
to v4l2_fwnode_endpoint_alloc_parse() function must be initiaized.
Set it to V4L2_MBUS_CSI2_DPHY, and check for -ENXIO which is returned
when the requested media bus type doesn't match the fwnode.

Also remove v4l2_fwnode_endpoint field from struct imx290 as it is only
needed in the probe function: use the local variable for this purpose.

Signed-off-by: Andrey Konovalov <andrey.konovalov@linaro.org>
Signed-off-by: Sakari Ailus <sakari.ailus@linux.intel.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
Comment thread drivers/media/i2c/imx290.c Outdated
.data_size = ARRAY_SIZE(imx290_1080p_settings),
.clk_data = {
[CLK_37_125] = imx290_37_125mhz_clock_1080p,
[CLK_74_250] = imx290_74_250mhz_clock_1080p,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be CLK_74_25, and below. And the _4lanes modes could also do with the same treatment.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My compile was still running :-(

6by9 added 6 commits June 26, 2020 18:20
The existing driver only supported a clock of 37.125MHz, but the
sensor also supports 74.25MHz.

Add the relevant register modifications to support this alternate
clock frequency.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
The datasheet lists the gain as being 0.0 to 72.0dB in 0.3dB steps, which
makes 238 steps total.
Correct the 0-72 range defined in the driver.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
Userspace needs to know HBLANK if it is to work out exposure times
and frame rates, therefore convert it to map onto V4L2_CID_HBLANK

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
In order to calculate framerate and durations userspace needs
the vertical blanking information. This can be configurable,
and indeed the datasheet lists different values for VBLANK for
the 1080p and 720p modes.

Add the new control, and adopt the datasheet values for each mode.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
Adds support for V4L2_CID_EXPOSURE so that userspace can control
the sensor exposure time.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
The sensor supports horizontal and vertical flips, so support them
through V4L2_CID_HFLIP and V4L2_CID_VFLIP.

This sensor does NOT change the Bayer order when changing the
direction of readout, therefore no special handling is required for
that.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
6by9 added 5 commits June 26, 2020 18:20
The IMX290 module is available as either monochrome or colour and
the variant is not detectable at runtime.

Add a new compatible string for the monochrome version.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
The IMX290 module is available as either mono or colour (Bayer).

Update the driver so that it can advertise the correct mono
formats instead of the colour ones.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
imx290_set_hmax was using two independent writes to set up hmax,
when all other multi-register writes were using imx290_write_buffered_reg
which claims the group hold first.

Switch imx290_set_hmax to using imx290_write_buffered_reg too.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
Adds an overlay to configure the IMX290 image sensor.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
Adds the mainline IMX290 sensor driver (with extra features) to
the default configs.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
@6by9

6by9 commented Jun 26, 2020

Copy link
Copy Markdown
Contributor Author

Branch updated based on your review comments, but my test build is still running....

@pelwell

pelwell commented Jun 26, 2020

Copy link
Copy Markdown
Contributor

Spoiler - it builds.

@pelwell

pelwell commented Jun 26, 2020

Copy link
Copy Markdown
Contributor

Happy for me to merge?

@6by9

6by9 commented Jun 26, 2020

Copy link
Copy Markdown
Contributor Author

Spoiler - it builds.

I need a faster machine, or to switch branches less.

Happy for me to merge?

Yes. Thanks for your review.

@pelwell
pelwell merged commit 8de45fd into raspberrypi:rpi-5.4.y Jun 26, 2020
@pelwell

pelwell commented Jun 26, 2020

Copy link
Copy Markdown
Contributor

Use git worktrees, and buildbot.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants