User avatar
RichShumaker
Posts: 357
Joined: Tue Jul 31, 2012 4:16 pm
Location: Sunny Southern CA near downtown LA
Contact: Website Facebook Twitter YouTube

4 lane CSI & IMX477 Camera Module

Thu Nov 05, 2020 6:01 pm

Since the compute module opens up access to 4 lane CSI-2 I have a question Since the Pi HQ camera is a CSI-2 with 2 lanes, how would I use a 4 lane IMX477 camera module?
Have any 4 lane CSI-2 devices been "approved" by the Pi Foundation or is the 4 lane CSI a roll your own connector?

I did already ask this question at the end of another thread in the camera forum and 6by9(who is awesome and should get a raise if you ask me) told me I need to write a device driver for any 4 lane boards. Is it simply a RasPi ARM linux driver(which is out of my wheelhouse so impossible for me) or is there some type of lower level kernel work as well that needs to be done?

My goal is film work(making films) with the Pi.
I am trying to get higher than 8 bit color space at 24fps on the HQ Camera (IMX477 sensor). I can get 9fps sustained at 12mp with 12bit RAW colorspace(THX HermannSW for your work on this) except we have maxed out 2 lanes and probably the storage bus as well.

Thanks in advance for your help.
Rich Shumaker
http://www.instructables.com/id/Pi-Zero-W-NoIR-8MP-Camera-Build-Overview-Introduct/

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 11271
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: 4 lane CSI & IMX477 Camera Module

Thu Nov 05, 2020 6:16 pm

You need to update the imx477 device tree overlay to have an option for 4 lanes instead of 2 at line 36 and 55. The TC358743 overlay gives an example of how to do that.

You then need to update the driver to look at that information, and update the I2C register set that the driver sends to the sensor to switch between 2 & 4 lanes based on that configuration.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

drich
Posts: 50
Joined: Tue Jul 28, 2015 7:36 pm

Re: 4 lane CSI & IMX477 Camera Module

Thu Nov 05, 2020 10:46 pm

Hello, I'm also interested in this as I read somewhere that an overclocked Pi 4 could be able to encode 1080p at 60 fps.
It looks like arducam did a copy of the HQ Camera with a 4-lane bus.
Considering 6by9's answer, the hardest part would be to "guess" the right I2C registers that have to be changed (since the imx477 registers map isn't public , nor leaked)

User avatar
RichShumaker
Posts: 357
Joined: Tue Jul 31, 2012 4:16 pm
Location: Sunny Southern CA near downtown LA
Contact: Website Facebook Twitter YouTube

Re: 4 lane CSI & IMX477 Camera Module

Fri Nov 06, 2020 5:18 am

Thanks 6by9!!!
Honestly it may take me a week to digest what you said as I am in the deep end for me. I really appreciate your helps as now I can learn new stuff & hopefully in the future I can test this out.
Rich Shumaker
http://www.instructables.com/id/Pi-Zero-W-NoIR-8MP-Camera-Build-Overview-Introduct/

Vinczek
Posts: 1
Joined: Thu Apr 01, 2021 2:19 pm

Re: 4 lane CSI & IMX477 Camera Module

Thu Apr 01, 2021 2:23 pm

Hello,

did anyone manage to successfully set up the 4-lane interface? I would like to use it with the IMX477 sensor which has 4 MIPI lanes and the RPi compute module 4.

I would appreciate help with setting up the drivers.

VeeAyyDee
Posts: 3
Joined: Wed Jun 09, 2021 4:09 am

Re: 4 lane CSI & IMX477 Camera Module

Wed Jun 09, 2021 4:21 am

drich wrote:
Thu Nov 05, 2020 10:46 pm
Hello, I'm also interested in this as I read somewhere that an overclocked Pi 4 could be able to encode 1080p at 60 fps.
It looks like arducam did a copy of the HQ Camera with a 4-lane bus.
Considering 6by9's answer, the hardest part would be to "guess" the right I2C registers that have to be changed (since the imx477 registers map isn't public , nor leaked)
Aren't registers maps similar between IMX sensors? You can probably use lane settings from another sensor. I have some "sensor profiles" I believe it's called, both 2 and 4 Lane with 999mbps and 1500mbps per lane. As far as I remember, lane and required bandwidth registers are marked. But you should probably dump sensor memory to verify if those registers are on the same address.

User avatar
Gavinmc42
Posts: 5701
Joined: Wed Aug 28, 2013 3:31 am

Re: 4 lane CSI & IMX477 Camera Module

Fri Jun 11, 2021 1:42 am

It would cool to have CM4 and HQ camera shooting 4K.

Set resolution to 2160 lines to get higher fps?

According to this, doing 4056 x 2288, 79fps on CSI-2
https://www.arducam.com/sony/imx477/#wh ... nd-imx477r

Can the censor do 12bit at 4056x2288 at 60fps?
Maybe CSI-4 could do it?

HDR would be interesting to figure out too.

Lots to figure out still with these Pi's and cameras.
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

VeeAyyDee
Posts: 3
Joined: Wed Jun 09, 2021 4:09 am

Re: 4 lane CSI & IMX477 Camera Module

Fri Jun 11, 2021 2:02 am

Gavinmc42 wrote:
Fri Jun 11, 2021 1:42 am
It would cool to have CM4 and HQ camera shooting 4K.

Set resolution to 2160 lines to get higher fps?

According to this, doing 4056 x 2288, 79fps on CSI-2
https://www.arducam.com/sony/imx477/#wh ... nd-imx477r

Can the censor do 12bit at 4056x2288 at 60fps?
Maybe CSI-4 could do it?

HDR would be interesting to figure out too.

Lots to figure out still with these Pi's and cameras.
Nvidia Jetson can record 4K, but RPI4 as far as I remember can only do 1080p 30.
Do you mean 4 Lane CSI under "CSI-4"?

The sensor is probably capable of 12bit at 4056x2288 at 60fps, but you'll have to figure it out by yourself.

HDR requires an ISP to process it, or you can record raw and post-process it.

4K@60 HDR is definitely possible, but requires 4 Lane connection and a device capable of processing it.

I imagine it's possible to pull off 4K@30 HDR on a Jetson (with either processing HDR on board with CUDA, or post-processing with RAW), with an external SSD to dump data to, but that's not Pi.

I have a documentation for HDR for another sensor, but it's under NDA and all I can do is give a public " sensor profile" where the HDR register is marked and say "figure it out by yourself"

User avatar
Gavinmc42
Posts: 5701
Joined: Wed Aug 28, 2013 3:31 am

Re: 4 lane CSI & IMX477 Camera Module

Fri Jun 11, 2021 2:58 am

The sensor is probably capable of 12bit at 4056x2288 at 60fps, but you'll have to figure it out by yourself.

HDR requires an ISP to process it, or you can record raw and post-process it.
Record raw and save it to PCIe NVMe drive and post process later.
That I think is doable.

Post process on a Pi cluster ;)
DIY hobby 4K movie making?

Yes CSI-4 is 4 lane.

There are other sensors out there that might work.
RAW data is better for semi pro photo use.
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

VeeAyyDee
Posts: 3
Joined: Wed Jun 09, 2021 4:09 am

Re: 4 lane CSI & IMX477 Camera Module

Fri Jun 11, 2021 3:45 am

Gavinmc42 wrote:
Fri Jun 11, 2021 2:58 am


Record raw and save it to PCIe NVMe drive and post process later.
That I think is doable.

Post process on a Pi cluster ;)
DIY hobby 4K movie making?
We are talking data rates of over 1.5 gigabytes per second for 4k 60 RAW and half of that for 30 fps.
And something you might not have known is that HDR actually doesn't need more bandwidth(depends on HDR implementation). At least for what I have here, it's just a pattern of interleaving normal and overexposed pixels.

I believe most of the 12 MP IMX Exmor R sensors can do 4k60 and most of those can do HDR natively. IMX 377, 378, 477 can do 4k60 and I know for sure 378 supports HDR.

User avatar
Gavinmc42
Posts: 5701
Joined: Wed Aug 28, 2013 3:31 am

Re: 4 lane CSI & IMX477 Camera Module

Fri Jun 11, 2021 5:23 am

Might have to wait for the CM5 but something can be done now with CM4, CSI connectors and NVMe.
No idea what the max 4K fps will be.

Not going to be a Pi based Red Ranger replacement but could be handy as a an Astrocamera that can take slower fps.

Been impressed with the Pi based HQ camera shots Astro guys have been getting.
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 11271
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: 4 lane CSI & IMX477 Camera Module

Fri Jun 11, 2021 7:51 am

Gavinmc42 wrote:
Fri Jun 11, 2021 2:58 am
Yes CSI-4 is 4 lane.
No it's not. Please don't invent terms as it will cause confusion.

MIPI CSI-2 is a specification for a Camera Serial Interface over 1 to 4 (potentially extendable up to 8) data lanes over MIPI C-PHY or D-PHY

MIPI CSI-3 exists and is a new and incompatible interface, generally using MIPI M-PHY.

MIPI CSI-1 is largely the same as the SMIA CCP2 interface.

https://en.wikipedia.org/wiki/Camera_Serial_Interface
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

User avatar
Gavinmc42
Posts: 5701
Joined: Wed Aug 28, 2013 3:31 am

Re: 4 lane CSI & IMX477 Camera Module

Fri Jun 11, 2021 10:29 am

My shorthand for CSI-2 with 4 channels, that's what I meant by CSI-4.

Will Libcamera work on 4 lanes on a CM4 I/O board?
If I can find a 4 Lane sensor.

i really only need RAW so I might give RaspiRaw some compile time now.
Hmm that was a quick compile.
Yikes going to take getting used too, hmm 8,10,12,16 bit depth :D

"No sensor found", Libcamera dtoverlay conflict?
Stay tuned. be right back after a quick reboot.
Nope still got issues, forum search time

Code: Select all

[./raspiraw -m
Using I2C device /dev/i2c-10
RaspiRaw: Probing sensor ov5647 on addr 36
RaspiRaw: Probing sensor imx219 on addr 10
RaspiRaw: Probing sensor adv7282 on addr 21
RaspiRaw: Probing sensor imx477 on addr 1A
RaspiRaw: No sensor found. Aborting
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

jamesh
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 28680
Joined: Sat Jul 30, 2011 7:41 pm

Re: 4 lane CSI & IMX477 Camera Module

Fri Jun 11, 2021 10:50 am

Gavinmc42 wrote:
Fri Jun 11, 2021 10:29 am
My shorthand for CSI-2 with 4 channels, that's what I meant by CSI-4.
So, that's not confusing at all then....

I'd really suggest not using that shorthand.
Principal Software Engineer at Raspberry Pi (Trading) Ltd.
Working in the Application's Team.

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 11271
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: 4 lane CSI & IMX477 Camera Module

Fri Jun 11, 2021 11:03 am

Gavinmc42 wrote:
Fri Jun 11, 2021 10:29 am
Will Libcamera work on 4 lanes on a CM4 I/O board?
If I can find a 4 Lane sensor.
If you make appropriate driver changes to configure the sensor to drive all 4 lanes.

Gavinmc42 wrote:"No sensor found", Libcamera dtoverlay conflict?
Stay tuned. be right back after a quick reboot.
Nope still got issues, forum search time

Code: Select all

[./raspiraw -m
Using I2C device /dev/i2c-10
RaspiRaw: Probing sensor ov5647 on addr 36
RaspiRaw: Probing sensor imx219 on addr 10
RaspiRaw: Probing sensor adv7282 on addr 21
RaspiRaw: Probing sensor imx477 on addr 1A
RaspiRaw: No sensor found. Aborting
If there is a kernel driver using an i2c bus/addr pair, then a new client trying to request that pairing will be rejected (unless you use I2C_SLAVE_FORCE instead of I2C_SLAVE).

But also the firmware will not touch the CSI2 receiver peripheral if it finds DT configuring it under Linux as there is no inter-processor arbitration.
So, yes, you need to unload the Linux kernel driver for imx477 before trying to use raspiraw.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

User avatar
Gavinmc42
Posts: 5701
Joined: Wed Aug 28, 2013 3:31 am

Re: 4 lane CSI & IMX477 Camera Module

Fri Jun 11, 2021 11:32 am

If you make appropriate driver changes to configure the sensor to drive all 4 lanes.
You mean figure out what all those sensor registers in the Linux Kernel media i2c section do?

Lots of sensors in there ;)

Tried with and without ov5647 DT loaded, made no difference

Will try more messing about tomorrow after sleep ;)
Thanks for the help.
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 11271
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: 4 lane CSI & IMX477 Camera Module

Fri Jun 11, 2021 12:08 pm

Gavinmc42 wrote:
Fri Jun 11, 2021 11:32 am
If you make appropriate driver changes to configure the sensor to drive all 4 lanes.
You mean figure out what all those sensor registers in the Linux Kernel media i2c section do?

Lots of sensors in there ;)
Yes, but you only need to look at the appropriate one for your sensor. You'll need the appropriate datasheet to know what to change.
Gavinmc42 wrote:Tried with and without ov5647 DT loaded, made no difference
With ov5647 dt loaded it will fail.
And you ran the camera_i2c script to enable the power GPIO to the sensor?
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

User avatar
Gavinmc42
Posts: 5701
Joined: Wed Aug 28, 2013 3:31 am

Re: 4 lane CSI & IMX477 Camera Module

Sat Jun 12, 2021 1:06 am

And you ran the camera_i2c script to enable the power GPIO to the sensor?
Hmm, now you know why i needed that sleep, thanks again, wondered what that was for.

Been a busy week or two crash course learning every camera interface method around including baremetal.
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

User avatar
Gavinmc42
Posts: 5701
Joined: Wed Aug 28, 2013 3:31 am

Re: 4 lane CSI & IMX477 Camera Module

Sat Jun 12, 2021 6:45 am

-y, --i2c : Set the I2C bus to use.
Range is 0-2.
Hmm, does Raspiraw works on Pi4's?

Code: Select all

./camera_i2c 
setting GPIO for board revsion: c03111
4B(1G/2G/4G/8G)
Set state of 133 to 1
Use i2c-10 for the sensor (-y 10)
Off to find a Pi3.
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 11271
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: 4 lane CSI & IMX477 Camera Module

Sat Jun 12, 2021 6:56 am

Gavinmc42 wrote:
Sat Jun 12, 2021 6:45 am
-y, --i2c : Set the I2C bus to use.
Range is 0-2.
Hmm, does Raspiraw works on Pi4's?

Code: Select all

./camera_i2c 
setting GPIO for board revsion: c03111
4B(1G/2G/4G/8G)
Set state of 133 to 1
Use i2c-10 for the sensor (-y 10)
Off to find a Pi3.
Yes it does.
I largely don't worry about the README text - it was contributed by others. The app gives help via -h, and it doesn't mention range.
There is no validation of a range within the app, it just tries to open /dev/i2c-N, where N is the value from -y.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

User avatar
Gavinmc42
Posts: 5701
Joined: Wed Aug 28, 2013 3:31 am

Re: 4 lane CSI & IMX477 Camera Module

Sat Jun 12, 2021 7:35 am

Ran this on a Pi3B+

Code: Select all

 ./camera_i2c 
setting GPIO for board revsion: a020d3
Raspberry Pi3B / Pi3B+ / 3A
Set state of 133 to 1
Use i2c-10 for the sensor (-y 10)
Is there a i2c-10 on 3's?
Ok, something missing in the wiki.
Missing a clue somewhere.

Code: Select all

./raspiraw -m
Using I2C device /dev/i2c-10
RaspiRaw: Probing sensor ov5647 on addr 36
RaspiRaw: Probing sensor imx219 on addr 10
RaspiRaw: Probing sensor adv7282 on addr 21
RaspiRaw: Probing sensor imx477 on addr 1A
RaspiRaw: No sensor found. Aborting
Anyway good news, while looking for old Pi3 HDMI cables I found the CM4 camera cables.
Test Raspiraw etc on two cameras at once?

Never did test stereo mode.
I'm dancing on Rainbows.
Raspberries are not Apples or Oranges

yekm
Posts: 3
Joined: Sun Jun 13, 2021 8:42 am
Contact: Website

Re: 4 lane CSI & IMX477 Camera Module

Sun Jun 13, 2021 9:23 am

6by9 wrote:
Thu Nov 05, 2020 6:16 pm
You need to update the imx477 device tree overlay to have an option for 4 lanes instead of 2 at line 36 and 55. The TC358743 overlay gives an example of how to do that.

You then need to update the driver to look at that information, and update the I2C register set that the driver sends to the sensor to switch between 2 & 4 lanes based on that configuration.

Code: Select all

[root@alarmpi4 ~]# dtc -I dts -O dtb -o /boot/overlays/imx477-4-overlay.dtbo ./imx477-overlay.dts
./imx477-overlay.dts:70.34-75.6: Warning (unit_address_vs_reg): /fragment@3/overlay/fixedregulator@0: node has a unit name, but no reg property
./imx477-overlay.dts:76.34-81.6: Warning (unit_address_vs_reg): /fragment@3/overlay/fixedregulator@1: node has a unit name, but no reg property
[root@alarmpi4 ~]# dtoverlay -a |grep imx477
  imx477
  imx477-4-overlay
[root@alarmpi4 ~]# dtoverlay -D imx477-4-overlay
[root@alarmpi4 ~]# dtc -I dtb dry_run.dtbo | grep lanes
<stdout>: Warning (unit_address_vs_reg): /fragment@3/overlay/fixedregulator@0: node has a unit name, but no reg property
<stdout>: Warning (unit_address_vs_reg): /fragment@3/overlay/fixedregulator@1: node has a unit name, but no reg property
<stdout>: Warning (unit_address_vs_reg): /local_fixups/fragment@0/overlay/imx477@1a: node has a unit name, but no reg property
                                                clock-lanes = <0x00>;
                                                data-lanes = <0x01 0x02 0x03 0x04>;
                                        clock-lanes = <0x00>;
                                        data-lanes = <0x01 0x02 0x03 0x04>;
[root@alarmpi4 ~]# journalctl -t kernel -f
-- Journal begins at Mon 2020-12-21 06:38:12 MSK. --
Jun 13 12:20:31 alarmpi4 kernel: OF: overlay: WARNING: memory leak will occur if overlay removed, property: /cam1_reg/regulator-max-microvolt
Jun 13 12:20:31 alarmpi4 kernel: unicam fe801000.csi: subdevice requires 4 data lanes when 2 are supported
Jun 13 12:20:31 alarmpi4 kernel: i2c i2c-11: Added multiplexed i2c bus 0
Jun 13 12:20:31 alarmpi4 kernel: i2c i2c-11: Added multiplexed i2c bus 10
Jun 13 12:20:31 alarmpi4 kernel: imx477 10-001a: only 2 data lanes are currently supported
Jun 13 12:20:31 alarmpi4 kernel: imx477: probe of 10-001a failed with error -22
So, what's with the i2c registers?

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 11271
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: 4 lane CSI & IMX477 Camera Module

Sun Jun 13, 2021 2:24 pm

yekm wrote:
Sun Jun 13, 2021 9:23 am

Code: Select all

[root@alarmpi4 ~]# dtc -I dts -O dtb -o /boot/overlays/imx477-4-overlay.dtbo ./imx477-overlay.dts
./imx477-overlay.dts:70.34-75.6: Warning (unit_address_vs_reg): /fragment@3/overlay/fixedregulator@0: node has a unit name, but no reg property
./imx477-overlay.dts:76.34-81.6: Warning (unit_address_vs_reg): /fragment@3/overlay/fixedregulator@1: node has a unit name, but no reg property
[root@alarmpi4 ~]# dtoverlay -a |grep imx477
  imx477
  imx477-4-overlay
[root@alarmpi4 ~]# dtoverlay -D imx477-4-overlay
[root@alarmpi4 ~]# dtc -I dtb dry_run.dtbo | grep lanes
<stdout>: Warning (unit_address_vs_reg): /fragment@3/overlay/fixedregulator@0: node has a unit name, but no reg property
<stdout>: Warning (unit_address_vs_reg): /fragment@3/overlay/fixedregulator@1: node has a unit name, but no reg property
<stdout>: Warning (unit_address_vs_reg): /local_fixups/fragment@0/overlay/imx477@1a: node has a unit name, but no reg property
                                                clock-lanes = <0x00>;
                                                data-lanes = <0x01 0x02 0x03 0x04>;
                                        clock-lanes = <0x00>;
                                        data-lanes = <0x01 0x02 0x03 0x04>;
[root@alarmpi4 ~]# journalctl -t kernel -f
-- Journal begins at Mon 2020-12-21 06:38:12 MSK. --
Jun 13 12:20:31 alarmpi4 kernel: OF: overlay: WARNING: memory leak will occur if overlay removed, property: /cam1_reg/regulator-max-microvolt
Jun 13 12:20:31 alarmpi4 kernel: unicam fe801000.csi: subdevice requires 4 data lanes when 2 are supported
Jun 13 12:20:31 alarmpi4 kernel: i2c i2c-11: Added multiplexed i2c bus 0
Jun 13 12:20:31 alarmpi4 kernel: i2c i2c-11: Added multiplexed i2c bus 10
Jun 13 12:20:31 alarmpi4 kernel: imx477 10-001a: only 2 data lanes are currently supported
Jun 13 12:20:31 alarmpi4 kernel: imx477: probe of 10-001a failed with error -22
So, what's with the i2c registers?
https://github.com/raspberrypi/linux/bl ... 77.c#L2054

Code: Select all

	/* Check the number of MIPI CSI2 data lanes */
	if (ep_cfg.bus.mipi_csi2.num_data_lanes != 2) {
		dev_err(dev, "only 2 data lanes are currently supported\n");
		goto error_out;
	}
So the driver validates the configuration it is given, and currently rejects it.

If you looked at the imx290 driver then you'll see if validates that either 2 or 4 lanes are configured, and then later on it sends different register values for the different options (it also changes other settings if you look at other places that use nlanes).

The IMX477 driver doesn't have that as yet, so without it you can not just change the device tree configuration to say "4 lanes".
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

yekm
Posts: 3
Joined: Sun Jun 13, 2021 8:42 am
Contact: Website

Re: 4 lane CSI & IMX477 Camera Module

Sun Jun 13, 2021 7:05 pm

6by9 wrote:
Sun Jun 13, 2021 2:24 pm
The IMX477 driver doesn't have that as yet, so without it you can not just change the device tree configuration to say "4 lanes".
Am I doing it right?

Code: Select all

diff --git a/drivers/media/i2c/imx477.c b/drivers/media/i2c/imx477.c
index b06add219cb4..11ad01426abf 100644
--- a/drivers/media/i2c/imx477.c
+++ b/drivers/media/i2c/imx477.c
@@ -1077,6 +1077,7 @@ struct imx477 {
 
 	struct clk *xclk;
 	u32 xclk_freq;
+	u8 num_lanes;
 
 	struct gpio_desc *reset_gpio;
 	struct regulator_bulk_data supplies[IMX477_NUM_SUPPLIES];
@@ -1235,9 +1236,14 @@ static u32 imx477_get_format_code(struct imx477 *imx477, u32 code)
 
 static void imx477_set_default_format(struct imx477 *imx477)
 {
-	/* Set default mode to max resolution */
-	imx477->mode = &supported_modes_12bit[0];
-	imx477->fmt_code = MEDIA_BUS_FMT_SRGGB12_1X12;
+	if (imx477->num_lanes == 2) {
+		/* Set default mode to max resolution */
+		imx477->mode = &supported_modes_12bit[0];
+		imx477->fmt_code = MEDIA_BUS_FMT_SRGGB12_1X12;
+	} else if (imx477->num_lanes == 4) {
+		imx477->mode = &supported_modes_12bit[2];
+		imx477->fmt_code = MEDIA_BUS_FMT_SRGGB12_1X12;
+	}
 }
 
 static int imx477_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
@@ -2051,7 +2057,10 @@ static int imx477_check_hwcfg(struct device *dev)
 	}
 
 	/* Check the number of MIPI CSI2 data lanes */
-	if (ep_cfg.bus.mipi_csi2.num_data_lanes != 2) {
+	if (ep_cfg.bus.mipi_csi2.num_data_lanes == 4 ||
+		ep_cfg.bus.mipi_csi2.num_data_lanes == 4) {
+		imx477->num_lanes = ep_cfg.bus.mipi_csi2.num_data_lanes
+	else {
 		dev_err(dev, "only 2 data lanes are currently supported\n");
 		goto error_out;
 	}

6by9
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 11271
Joined: Wed Dec 04, 2013 11:27 am
Location: ZZ9 Plural Z Alpha, aka just outside Cambridge.

Re: 4 lane CSI & IMX477 Camera Module

Sun Jun 13, 2021 7:44 pm

yekm wrote:
Sun Jun 13, 2021 7:05 pm
6by9 wrote:
Sun Jun 13, 2021 2:24 pm
The IMX477 driver doesn't have that as yet, so without it you can not just change the device tree configuration to say "4 lanes".
Am I doing it right?

Code: Select all

diff --git a/drivers/media/i2c/imx477.c b/drivers/media/i2c/imx477.c
index b06add219cb4..11ad01426abf 100644
--- a/drivers/media/i2c/imx477.c
+++ b/drivers/media/i2c/imx477.c
@@ -1077,6 +1077,7 @@ struct imx477 {
 
 	struct clk *xclk;
 	u32 xclk_freq;
+	u8 num_lanes;
 
 	struct gpio_desc *reset_gpio;
 	struct regulator_bulk_data supplies[IMX477_NUM_SUPPLIES];
@@ -1235,9 +1236,14 @@ static u32 imx477_get_format_code(struct imx477 *imx477, u32 code)
 
 static void imx477_set_default_format(struct imx477 *imx477)
 {
-	/* Set default mode to max resolution */
-	imx477->mode = &supported_modes_12bit[0];
-	imx477->fmt_code = MEDIA_BUS_FMT_SRGGB12_1X12;
+	if (imx477->num_lanes == 2) {
+		/* Set default mode to max resolution */
+		imx477->mode = &supported_modes_12bit[0];
+		imx477->fmt_code = MEDIA_BUS_FMT_SRGGB12_1X12;
+	} else if (imx477->num_lanes == 4) {
+		imx477->mode = &supported_modes_12bit[2];
+		imx477->fmt_code = MEDIA_BUS_FMT_SRGGB12_1X12;
No, all modes are valid for any number of lanes.

Code: Select all

+	}
 }
 
 static int imx477_open(struct v4l2_subdev *sd, struct v4l2_subdev_fh *fh)
@@ -2051,7 +2057,10 @@ static int imx477_check_hwcfg(struct device *dev)
 	}
 
 	/* Check the number of MIPI CSI2 data lanes */
-	if (ep_cfg.bus.mipi_csi2.num_data_lanes != 2) {
+	if (ep_cfg.bus.mipi_csi2.num_data_lanes == 4 ||
+		ep_cfg.bus.mipi_csi2.num_data_lanes == 4) {
Is it 4? Are you sure?

Code: Select all

+		imx477->num_lanes = ep_cfg.bus.mipi_csi2.num_data_lanes
+	else {
 		dev_err(dev, "only 2 data lanes are currently supported\n");
 		goto error_out;
 	}
Part of the I2C register setup in the struct imx477_reg tables sets the number of lanes. Sorry the datasheets we have are under NDA, so I can't discuss them.
If there is a point that Raspberry PI are looking at supporting a 4 lane configuration for the IMX477 then the driver will be updated accordingly, otherwise it needs to be a discussion with Sony or the 3rd party manufacturer making the sensor module.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

Return to “Compute Module”