tagsense
Posts: 28
Joined: Sun Sep 30, 2018 2:16 pm

Adding a new i2c image sensor to RPI 4B

Fri Sep 22, 2023 9:25 am

Greetings!!
I am trying to add a new image sensor (no driver is available for this) to RPI 4B device tree. This image sensor has 2 interfaces - 1. I2C for control and config 2. MIPI for transferring image data. when I run i2cdetect -l , I get the following output:

Code: Select all

i2c-20	i2c       	fef04500.i2c                    	I2C adapter
i2c-10	i2c       	i2c-22-mux (chan_id 1)          	I2C adapter
i2c-1	i2c       	bcm2835 (i2c@7e804000)          	I2C adapter
i2c-21	i2c       	fef09500.i2c                    	I2C adapter
i2c-0	i2c       	i2c-22-mux (chan_id 0)          	I2C adapter
i2c-22	i2c       	bcm2835 (i2c@7e205000)          	I2C adapter
when I run i2cdetect -y 0 or i2cdetect -y 1, I get no response.
however, when I run i2cdetect -y 10 or i2cdetect -y 22, I get the following output:

Code: Select all

     0  1  2  3  4  5  6  7  8  9  a  b  c  d  e  f
00:                         -- -- -- -- -- -- -- -- 
10: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
20: -- 21 -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
30: -- -- -- -- -- -- 36 -- -- -- -- -- -- -- -- -- 
40: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
50: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
60: -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- 
70: -- -- -- -- -- -- -- --  
Now, when I try to add the sensor to device tree, as shown below, only i2c1 and i2c0 work for target. However, only on bus 10 and bus 22, I2Cdetect finds the bridge chip.
When I use i2c10 or i2c22, I get dterror: can't find symbol i2c10.

Code: Select all

fragment@0 {
        target = <&i2c10>;
How to resolve this? Please advise.

PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5607
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Adding a new i2c image sensor to RPI 4B

Fri Sep 22, 2023 10:00 am

i2c10 is the numeric ID for I2C0 on the camera GPIOs, but in DT it's called "i2c_csi_dsi".

You can probably get over many hurdles like this by reading one of the existing camera overlays, e.g. https://github.com/raspberrypi/linux/bl ... verlay.dts
I am trying to add a new image sensor (no driver is available for this)
Does this mean you are going to write one?

tagsense
Posts: 28
Joined: Sun Sep 30, 2018 2:16 pm

Re: Adding a new i2c image sensor to RPI 4B

Fri Sep 22, 2023 5:00 pm

ok, thank you so much for your advice. I looked at the overlay files for image sensors such as imx_219.
but, will look at this one as well.

yes, i have to write a driver and an overlay for a new image sensor.

tagsense
Posts: 28
Joined: Sun Sep 30, 2018 2:16 pm

Re: Adding a new i2c image sensor to RPI 4B

Fri Sep 29, 2023 3:18 pm

As I wrote before, I am working with an image sensor for which I have to create an overlay file and a driver. This image sensor is different from conventional cameras is that it is on a separate board with its own power supplies and clock. So I didn't need to any details about the clock or power supply in the overlay file.
The aforementioned board (with the image sensor) is connected to a RPI 4B through I2C (on bus 10 at address 0x36) and MIPI. BTW, I had to change the sensor and vendor names before posting because I was asked to do so by the client.

I have attached the overlay file for your review. I was able to compile it (using dtc) and place the dtbo file in /boot/overlays directory.
When RPI boots, it is able to read the file and correctly loads the driver I have written. It even correctly runs the probe function.

However, when I run vcgencmd get_camera, it does not detect any cameras. I get the following response:
supported=1 detected=0, libcamera interfaces=1

what could be wrong? Please advise how to debug this. Thank you!

Code: Select all

/dts-v1/;
/plugin/;

#include <dt-bindings/gpio/gpio.h>

/ {
    compatible = "brcm,bcm2835";

    fragment@0 {
		target = <&i2c0if>;
		__overlay__ {
			status = "okay";
		};
	};

	clk_frag: fragment@1 {
		target = <&cam1_clk>;
		__overlay__ {
			status = "okay";
			clock-frequency = <24000000>;
		};
	};

    fragment@2 {
		target = <&i2c0mux>;
		__overlay__ {
			status = "okay";
		};
	};

    fragment@3 {
        target-path = "/";
        __overlay__ {
            clk24mhz: clk24mhz {
                compatible = "fixed-clock";
                #clock-cells = <0>;
                clock-frequency = <24000000>;
            };
        };
    };

    i2c_frag: fragment@100 {
        target = <&i2c_csi_dsi>;
        __overlay__ {
            #address-cells = <1>;
            #size-cells = <0>;

            ims123: ims123@36 {
                compatible = "vendor,ims123";
                reg = <0x36>;
                clocks = <&clk24mhz>;

                clock-names = "xclk";
                status = "disabled";

                rotation = <180>;
                orientation = <2>;

                port {
                    cam_endpoint: endpoint {
                        clock-lanes = <0>;
                        data-lanes = <1 2>;
                        clock-noncontinuous;
                        link-frequencies = /bits/ 64 <60000000>;
                    };
                };
            };
        };
    };

	csi_frag: fragment@101 {
		target = <&csi1>;
		csi: __overlay__ {
			status = "okay";
			brcm,media-controller;

			port {
				csi_ep: endpoint {
					remote-endpoint = <&cam_endpoint>;
					clock-lanes = <0>;
					data-lanes = <1 2>;
					clock-noncontinuous;
				};
			};
		};
	};

	__overrides__ {
		rotation = <&ims123>,"rotation:0";
		orientation = <&ims123>,"orientation:0";
		media-controller = <&csi>,"brcm,media-controller?";
		cam0 = <&i2c_frag>, "target:0=",<&i2c_vc>,
		       <&csi_frag>, "target:0=",<&csi0>,
		       <&clk_frag>, "target:0=",<&cam0_clk>,
		       <&ims123>, "clocks:0=",<&cam0_clk>;
	};
};

&ims123 {
    status = "okay";
};

&cam_endpoint {
    remote-endpoint = <&csi_ep>;
};


PhilE
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 5607
Joined: Mon Sep 29, 2014 1:07 pm
Location: Cambridge

Re: Adding a new i2c image sensor to RPI 4B

Fri Sep 29, 2023 4:31 pm

That message is just reporting that the firmware hasn't detected any cameras, and therefore not automatically loaded any camera overlays. This isn't surprising - it has no way to know what is a camera except for the ones it has been specifically told about, i.e. the first-party cameras. Once you've loaded your custom overlay manually, libcamera should be happy to use it.

tagsense
Posts: 28
Joined: Sun Sep 30, 2018 2:16 pm

Re: Adding a new i2c image sensor to RPI 4B

Fri Sep 29, 2023 6:23 pm

i ran

Code: Select all

 dtc -I fs -O dts -o /tmp/livedt.dts /proc/device-tree
to get the loaded live device tree. I see that the overlay I created is a part of that device tree. I also see the bridge chip responds to messages sent over I2C. Only the CSI interface does not seem to come up.

Return to “Device Tree”