Garrix
Posts: 9
Joined: Thu Aug 16, 2018 10:48 pm

GPIO number for CAM_GPIO0

Mon Sep 17, 2018 3:07 pm

Hi,

I have several Raspberry PIs and I want to drive the CAM_GPIO0 line of these devices.
I was looking around in the forum and internet without success...

What are the corresponding pin numbers for the
- Pi 2 Model B
- Pi 3 Model B
- Pi 3 Model B+

By GPIO numbers I mean the numbers for sysfs:

Code: Select all

echo xxx > /sys/class/gpio/export
Thanks for the help

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

Re: GPIO number for CAM_GPIO0

Mon Sep 17, 2018 3:48 pm

https://github.com/raspberrypi/firmware ... t-blob.dts is the config file that the firmware uses.
You're looking for CAMERA_0_SHUTDOWN for your appropriate platform. Where it reports "external", then add 128 to the number.
Therefore:
2B is GPIO 41
3B and 3B+ are GPIO external 5, or 133.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
Please don't send PMs asking for support - use the forum.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

Garrix
Posts: 9
Joined: Thu Aug 16, 2018 10:48 pm

Re: GPIO number for CAM_GPIO0

Mon Sep 17, 2018 4:07 pm

6by9 wrote:
Mon Sep 17, 2018 3:48 pm
https://github.com/raspberrypi/firmware ... t-blob.dts is the config file that the firmware uses.
You're looking for CAMERA_0_SHUTDOWN for your appropriate platform. Where it reports "external", then add 128 to the number.
Therefore:
2B is GPIO 41
3B and 3B+ are GPIO external 5, or 133.
Okay, thanks. Works like a charm!
How would I integrate this portably into the device tree? Let's say I have a V4L2 device, where the driver shall use this pin (it is the reset pin of the imager in my case).

I copied my code from the ov5647-overlay.dts:

Code: Select all

ov5647: [email protected] {
				compatible = "ov5647";
				reg = <0x36>;
				status = "okay";

				pwdn-gpios = <&gpio 41 1>, <&gpio 32 1>;
				clocks = <&ov5647_clk>;

				ov5647_clk: camera-clk {
					compatible = "fixed-clock";
					#clock-cells = <0>;
					clock-frequency = <25000000>;
				};

				port {
					ov5647_0: endpoint {
						remote-endpoint = <&csi1_ep>;
						clock-lanes = <0>;
						data-lanes = <1 2>;
						clock-noncontinuous;
						link-frequencies =
							/bits/ 64 <297000000>;
					};
				};
			};
			
The line of interest for me is:

Code: Select all

pwdn-gpios = <&gpio 41 1>, <&gpio 32 1>;
what can I do to have it 41 in case of 2B and 133 in case of 3B/3B+ ?

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

Re: GPIO number for CAM_GPIO0

Mon Sep 17, 2018 4:20 pm

Garrix wrote:
Mon Sep 17, 2018 4:07 pm
Okay, thanks. Works like a charm!
How would I integrate this portably into the device tree? Let's say I have a V4L2 device, where the driver shall use this pin (it is the reset pin of the imager in my case).
<snip>

The line of interest for me is:

Code: Select all

pwdn-gpios = <&gpio 41 1>, <&gpio 32 1>;
what can I do to have it 41 in case of 2B and 133 in case of 3B/3B+ ?
There's some DT magic in the firmware.

Note at the bottom of the overlay

Code: Select all

	__overrides__ {
		cam0-pwdn = <&ov5647>,"pwdn-gpios:4";
		cam0-led = <&ov5647>,"pwdn-gpios:16";
};
The firmware should look for those override parameters and set them to match the CAMERA_0_SHUTDOWN and CAMERA_0_LED defines from dt-blob.dts. Omitting one or other is perfectly acceptable.
If you add "dtdebug=1" to /boot/config.txt, then "sudo vcdbg log msg" should dump out a load of extra debug related to DT parsing and overlay application.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
Please don't send PMs asking for support - use the forum.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

Garrix
Posts: 9
Joined: Thu Aug 16, 2018 10:48 pm

Re: GPIO number for CAM_GPIO0

Mon Sep 17, 2018 6:52 pm

Okay, I'm not sure whether I got the point correctly.

I stripped down my __overrides__ to look like:
__overrides__ {
i2c_pins_28_29 = <0>,"+4-5";
cam0-pwdn = <&irs1125>,"pwdn-gpios:4";
};
I'm not sure what "pwdn-gpios:4" means. I did not modify that. Also I left the pwdn-gpios as in the original ov5647-overlay.dts except that I changed <&gpio 41 1> to <&gpio 21 1> (just to play a bit around)
pwdn-gpios = <&gpio 21 1>, <&gpio 32 1>;
When I do a
echo 133 > /sys/class/gpio/export
echo out > /sys/class/gpio133/direction
echo 1 > /sys/class/gpio133/value
The CAMERA_0_SHUTDOWN pin moves as expected (verified with a logic analyser). However I still don't get this pin inside my V4L2 code. I use

Code: Select all

sensor->reset = devm_gpiod_get(&client->dev, "pwdn",
					       GPIOD_OUT_LOW);	
	
	if (IS_ERR(sensor->reset)) {
		dev_err(dev, "could not get reset");
		return PTR_ERR(sensor->reset);
	}
	
	
	gpio_num = desc_to_gpio(sensor->reset);
	dev_err(dev, "reset on GPIO %d", gpio_num);
and dmesg shows (I also see GPIO21 toggling as expected):
[ 659.079773] irs1125 0-003d: reset on GPIO 21
Do I have to activate something to get the "DT firmware magic", or didn't I understand correctly?

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

Re: GPIO number for CAM_GPIO0

Mon Sep 17, 2018 7:24 pm

Looking at the original ov5647 overlay

Code: Select all

pwdn-gpios = <&gpio 41 1>, <&gpio 32 1>;
Each of the values after the equals are 32 bit ints. &gpio gets remapped to the phandle for the gpio node.

Code: Select all

cam0-pwdn = <&irs1125>,"pwdn-gpios:4";
says to update the pwdn-gpios definition starting at byte 4 (0-based, so the 5th byte), ie overwriting the 41.

Enable dtdebug=1 in config.txt to see what it says over parsing the overlays.
To prove that the override section is correct you should also be able to manually override it in the dtoverlay line with "dtoverlay=irs1125,cam0-pwdn=21". The override needs to also switch from &gpio to &expgpio for the external gpio expander. You can't do that manually easily, but the firmware will be trying to if it can find the correct aliases.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
Please don't send PMs asking for support - use the forum.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

Garrix
Posts: 9
Joined: Thu Aug 16, 2018 10:48 pm

Re: GPIO number for CAM_GPIO0

Mon Sep 17, 2018 8:07 pm

6by9 wrote: Looking at the original ov5647 overlay

Code: Select all

pwdn-gpios = <&gpio 41 1>, <&gpio 32 1>;
Each of the values after the equals are 32 bit ints. &gpio gets remapped to the phandle for the gpio node.
Okay, understood. Actually I can recommend https://github.com/raspberrypi/document ... ce-tree.md. It is very clearly documented there.
6by9 wrote: Enable dtdebug=1 in config.txt to see what it says over parsing the overlays.
I get a lot of output there, but don't really understand it...

Code: Select all

002236.774: Loaded overlay 'irs1125'
002236.892: dtparam: audio=on
002237.239: dtdebug: /__overrides__ has no audio property
002242.611: dtdebug: Found override audio
002242.645: dtdebug:   override audio: string target 'status'
002256.451: dtdebug: Found fragment 0 (offset 36)
002268.170: dtdebug: merge_fragment(/soc/[email protected],/[email protected]/__overlay__)
002268.199: dtdebug:   +prop(#address-cells)
002270.259: dtdebug:   +prop(#size-cells)
002272.317: dtdebug:   +prop(status)
002280.677: dtdebug: merge_fragment(/soc/[email protected]/[email protected],/[email protected]/__overlay__/[email protected])
002280.702: dtdebug:   +prop(compatible)
002282.701: dtdebug:   +prop(reg)
002284.803: dtdebug:   +prop(status)
002286.994: dtdebug:   +prop(pwdn-gpios)
002289.695: dtdebug:   +prop(clocks)
002291.869: dtdebug:   +prop(phandle)
002300.389: dtdebug: merge_fragment(/soc/[email protected]/[email protected]/camera-clk,/[email protected]/__overlay__/[email protected]/camera-clk)
002300.415: dtdebug:   +prop(compatible)
002302.416: dtdebug:   +prop(#clock-cells)
002304.548: dtdebug:   +prop(clock-frequency)
002306.775: dtdebug:   +prop(phandle)
002308.908: dtdebug: merge_fragment() end
002315.614: dtdebug: merge_fragment(/soc/[email protected]/[email protected]/port,/[email protected]/__overlay__/[email protected]/port)
002321.983: dtdebug: merge_fragment(/soc/[email protected]/[email protected]/port/endpoint,/[email protected]/__overlay__/[email protected]/port/endpoint)
002322.011: dtdebug:   +prop(remote-endpoint)
002324.677: dtdebug:   +prop(clock-lanes)
002327.365: dtdebug:   +prop(data-lanes)
002329.643: dtdebug:   +prop(clock-noncontinuous)
002332.372: dtdebug:   +prop(link-frequencies)
002335.105: dtdebug:   +prop(phandle)
002337.280: dtdebug: merge_fragment() end
002337.313: dtdebug: merge_fragment() end
002337.354: dtdebug: merge_fragment() end
002337.435: dtdebug: merge_fragment() end
002337.564: dtdebug: Found fragment 1 (offset 516)
002352.923: dtdebug: merge_fragment(/soc/[email protected],/[email protected]/__overlay__)
002352.952: dtdebug:   +prop(#address-cells)
002354.688: dtdebug:   +prop(#size-cells)
002356.433: dtdebug:   +prop(status)
002363.771: dtdebug: merge_fragment(/soc/[email protected]/port,/[email protected]/__overlay__/port)
002363.796: dtdebug:   +prop(#address-cells)
002365.489: dtdebug:   +prop(#size-cells)
002372.780: dtdebug: merge_fragment(/soc/[email protected]/port/endpoint,/[email protected]/__overlay__/port/endpoint)
002372.808: dtdebug:   +prop(remote-endpoint)
002375.145: dtdebug:   +prop(phandle)
002376.929: dtdebug: merge_fragment() end
002376.955: dtdebug: merge_fragment() end
002376.995: dtdebug: merge_fragment() end
002377.080: dtdebug: Found fragment 2 (offset 724)
002377.141: dtdebug: fragment 2 disabled
002377.201: dtdebug: Found fragment 3 (offset 816)
002386.877: dtdebug: merge_fragment(/soc/[email protected]/i2c0,/[email protected]/__overlay__)
002386.906: dtdebug:   +prop(brcm,pins)
002389.212: dtdebug:   +prop(brcm,function)
002391.543: dtdebug: merge_fragment() end
002391.603: dtdebug: Found fragment 4 (offset 908)
002403.641: dtdebug: merge_fragment(/soc/[email protected],/[email protected]/__overlay__)
002403.667: dtdebug:   +prop(status)
002405.796: dtdebug: merge_fragment() end
002418.437: dtparam: uart1=off
002423.890: dtdebug: Found override uart1
002423.925: dtdebug:   override uart1: string target 'status'
003546.211: dtparam: cam0-pwdn-ctrl=23
003552.012: dtdebug: /__overrides__ has no cam0-pwdn-ctrl property
003552.027: Unknown dtparam 'cam0-pwdn-ctrl' - ignored
003552.091: dtparam: cam0-pwdn=5
003557.876: dtdebug: /__overrides__ has no cam0-pwdn property
003557.891: Unknown dtparam 'cam0-pwdn' - ignored
003570.025: dtparam: cam0-led-ctrl=23
003575.860: dtdebug: /__overrides__ has no cam0-led-ctrl property
003575.874: Unknown dtparam 'cam0-led-ctrl' - ignored
003575.938: dtparam: cam0-led=6
003581.713: dtdebug: /__overrides__ has no cam0-led property
003581.727: Unknown dtparam 'cam0-led' - ignored
003581.791: gpioman: gpioman_get_pin_num: pin EMMC_ENABLE not defined
003581.890: dtparam: arm_freq=1200000000
003587.650: dtdebug: Found override arm_freq
003587.700: dtdebug:   override arm_freq: cell target clock-frequency @ offset 0 (size 4)
003603.254: dtdebug:   override arm_freq: cell target clock-frequency @ offset 0 (size 4)
003618.921: dtdebug:   override arm_freq: cell target clock-frequency @ offset 0 (size 4)
003634.652: dtdebug:   override arm_freq: cell target clock-frequency @ offset 0 (size 4)
003650.809: dtparam: core_freq=400000000
003656.650: dtdebug: /__overrides__ has no core_freq property
I understood the above output in a way that it misses the cam-pwdn property in the /__overrides__ node. But if I decompile my device tree overlay it looks like it contains the property:

Code: Select all

fdtdump /boot/overlays/irs1125.dtbo
...

/ {
    compatible = "brcm,bcm2708";
...
    __overrides__ {
        i2c_pins_28_29 = [00 00 00 00 2b 34 2d 35 00];
        cam0-pwdn = [00 00 00 04 70 77 64 6e 2d 67 70 69 6f 73 3a 34 00];
    };

6by9 wrote:To prove that the override section is correct you should also be able to manually override it in the dtoverlay line with "dtoverlay=irs1125,cam0-pwdn=21".
Yes I tested this also. It works as expected. I'm able to manually do the overwrite (without changing &gpio to &extgpio)

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

Re: GPIO number for CAM_GPIO0

Tue Sep 18, 2018 9:42 am

Hmm, I think something may have gone wrong in merging trees. I know this was working at one point, but then we had fun and games merging trees with/without I2C mux support, and I suspect something has gone missing.
Checking the firmware, it is looking for overrides for camN-pwdn-ctrl for the pwdn phandle, and camN-pwdn for the GPIO number, and camN-led-ctrl for the led phandle, and camN-led for the GPIO number. I'm now trying to find my relevant git branch that includes cam0-pwdn-ctrl as that certainly hasn't been merged.
...
Found, and it was a very bad merge. Sorry about that.
The patch I'm just testing is:

Code: Select all

diff --git a/arch/arm/boot/dts/bcm270x.dtsi b/arch/arm/boot/dts/bcm270x.dtsi
index 0582827..f086ff0 100644
--- a/arch/arm/boot/dts/bcm270x.dtsi
+++ b/arch/arm/boot/dts/bcm270x.dtsi
@@ -152,6 +152,13 @@
                regulator-max-microvolt = <3300000>;
                regulator-always-on;
        };
+
+       __overrides__ {
+               cam0-pwdn-ctrl;
+               cam0-pwdn;
+               cam0-led-ctrl;
+               cam0-led;
+       };
 };
 
 /* Configure and use the auxilliary interrupt controller */
diff --git a/arch/arm/boot/dts/overlays/ov5647-overlay.dts b/arch/arm/boot/dts/overlays/ov5647-overlay.dts
index c92306a..f53122e 100644
--- a/arch/arm/boot/dts/overlays/ov5647-overlay.dts
+++ b/arch/arm/boot/dts/overlays/ov5647-overlay.dts
@@ -78,9 +78,17 @@
                };
        };
 
+       [email protected] {
+               target-path="/__overrides__"; // Or we add a label
+               __overlay__ {
+                       cam0-pwdn-ctrl = <&ov5647>,"pwdn-gpios:0";
+                       cam0-pwdn      = <&ov5647>,"pwdn-gpios:4";
+                       cam0-led-ctrl  = <&ov5647>,"pwdn-gpios:12";
+                       cam0-led       = <&ov5647>,"pwdn-gpios:16";
+               };
+       };
+
        __overrides__ {
                i2c_pins_28_29 = <0>,"+4-5";
-               cam0-pwdn = <&ov5647>,"pwdn-gpios:4";
-               cam0-led = <&ov5647>,"pwdn-gpios:16";
        };
 };
So the base DT defines the nodes in the __overrides__ section, but as empty. The overlay then redirects them to the appropriate GPIO control nodes. The firmware will then find the overrides and update accordingly.
Most of my testing previously had been on a 2B, but running it now has just shown up an error in the ov5647 driver - the calls need to be to gpiod_set_value_cansleep, not gpiod_set_value. With the gpio expander it will block (ie sleep) as it makes the IPC across to the VPU to update the GPIO setting. This seems to be a common issue in almost all the drivers in the main kernel for no very good reason.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
Please don't send PMs asking for support - use the forum.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

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

Re: GPIO number for CAM_GPIO0

Tue Sep 18, 2018 11:19 am

PR created at https://github.com/raspberrypi/linux/pull/2686 for the mods. Sorry for the confusion.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
Please don't send PMs asking for support - use the forum.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

Garrix
Posts: 9
Joined: Thu Aug 16, 2018 10:48 pm

Re: GPIO number for CAM_GPIO0

Tue Sep 18, 2018 10:25 pm

I added the patches from the PR to my local sources. The log message indeed don't show the error any longer:

Code: Select all

002199.089: Loaded overlay 'ov5647'
002199.209: dtparam: audio=on
002199.562: dtdebug: /__overrides__ has no audio property
002204.927: dtdebug: Found override audio
002204.962: dtdebug:   override audio: string target 'status'
002218.692: dtdebug: Found fragment 0 (offset 36)
002230.497: dtdebug: merge_fragment(/soc/[email protected],/[email protected]/__overlay__)
002230.524: dtdebug:   +prop(#address-cells)
002232.593: dtdebug:   +prop(#size-cells)
002234.661: dtdebug:   +prop(status)
002243.061: dtdebug: merge_fragment(/soc/[email protected]/[email protected],/[email protected]/__overlay__/[email protected])
002243.089: dtdebug:   +prop(compatible)
002245.099: dtdebug:   +prop(reg)
002247.225: dtdebug:   +prop(status)
002249.434: dtdebug:   +prop(pwdn-gpios)
002252.147: dtdebug:   +prop(clocks)
002254.329: dtdebug:   +prop(phandle)
002262.816: dtdebug: merge_fragment(/soc/[email protected]/[email protected]/camera-clk,/[email protected]/__overlay__/[email protected]/camera-clk)
002262.844: dtdebug:   +prop(compatible)
002264.870: dtdebug:   +prop(#clock-cells)
002267.278: dtdebug:   +prop(clock-frequency)
002269.517: dtdebug:   +prop(phandle)
002271.662: dtdebug: merge_fragment() end
002278.135: dtdebug: merge_fragment(/soc/[email protected]/[email protected]/port,/[email protected]/__overlay__/[email protected]/port)
002284.493: dtdebug: merge_fragment(/soc/[email protected]/[email protected]/port/endpoint,/[email protected]/__overlay__/[email protected]/port/endpoint)
002284.519: dtdebug:   +prop(remote-endpoint)
002287.217: dtdebug:   +prop(clock-lanes)
002289.931: dtdebug:   +prop(data-lanes)
002292.207: dtdebug:   +prop(clock-noncontinuous)
002294.951: dtdebug:   +prop(link-frequencies)
002297.713: dtdebug:   +prop(phandle)
002299.912: dtdebug: merge_fragment() end
002299.944: dtdebug: merge_fragment() end
002299.987: dtdebug: merge_fragment() end
002300.067: dtdebug: merge_fragment() end
002300.199: dtdebug: Found fragment 1 (offset 516)
002315.611: dtdebug: merge_fragment(/soc/[email protected],/[email protected]/__overlay__)
002315.637: dtdebug:   +prop(#address-cells)
002317.398: dtdebug:   +prop(#size-cells)
002319.155: dtdebug:   +prop(status)
002326.486: dtdebug: merge_fragment(/soc/[email protected]/port,/[email protected]/__overlay__/port)
002326.509: dtdebug:   +prop(#address-cells)
002328.215: dtdebug:   +prop(#size-cells)
002335.479: dtdebug: merge_fragment(/soc/[email protected]/port/endpoint,/[email protected]/__overlay__/port/endpoint)
002335.505: dtdebug:   +prop(remote-endpoint)
002337.871: dtdebug:   +prop(phandle)
002339.666: dtdebug: merge_fragment() end
002339.692: dtdebug: merge_fragment() end
002339.730: dtdebug: merge_fragment() end
002339.818: dtdebug: Found fragment 2 (offset 724)
002339.878: dtdebug: fragment 2 disabled
002339.936: dtdebug: Found fragment 3 (offset 816)
002349.621: dtdebug: merge_fragment(/soc/[email protected]/i2c0,/[email protected]/__overlay__)
002349.648: dtdebug:   +prop(brcm,pins)
002351.965: dtdebug:   +prop(brcm,function)
002354.299: dtdebug: merge_fragment() end
002354.357: dtdebug: Found fragment 4 (offset 908)
002366.484: dtdebug: merge_fragment(/soc/[email protected],/[email protected]/__overlay__)
002366.512: dtdebug:   +prop(status)
002368.917: dtdebug: merge_fragment() end
002381.301: dtparam: uart1=off
002386.726: dtdebug: Found override uart1
002386.761: dtdebug:   override uart1: string target 'status'
003521.779: dtparam: cam0-pwdn-ctrl=23
003527.200: dtdebug: Found override cam0-pwdn-ctrl
003527.222: dtparam: cam0-pwdn=5
003532.665: dtdebug: Found override cam0-pwdn
003544.844: dtparam: cam0-led-ctrl=23
003550.313: dtdebug: Found override cam0-led-ctrl
003550.334: dtparam: cam0-led=6
003555.776: dtdebug: Found override cam0-led
003555.798: gpioman: gpioman_get_pin_num: pin EMMC_ENABLE not defined
003555.881: dtparam: arm_freq=1200000000
003561.551: dtdebug: Found override arm_freq
003561.602: dtdebug:   override arm_freq: cell target clock-frequency @ offset 0 (size 4)
003577.143: dtdebug:   override arm_freq: cell target clock-frequency @ offset 0 (size 4)
003592.776: dtdebug:   override arm_freq: cell target clock-frequency @ offset 0 (size 4)
003608.504: dtdebug:   override arm_freq: cell target clock-frequency @ offset 0 (size 4)
003624.603: dtparam: core_freq=400000000
But still I don't understand the sense of this auto-magically replacement - or maybe it still doesn't work as expected on my raspberry.

I have enabled the ov5647 now in my /boot/config.txt (dtoverlay=ov5647). I added the following patch to the driver:

Code: Select all

diff --git a/drivers/media/i2c/ov5647.c b/drivers/media/i2c/ov5647.c
index b7bacaa..078d023 100644
--- a/drivers/media/i2c/ov5647.c
+++ b/drivers/media/i2c/ov5647.c
@@ -580,6 +580,7 @@ static int ov5647_probe(struct i2c_client *client,
        struct v4l2_subdev *sd;
        struct device_node *np = client->dev.of_node;
        u32 xclk_freq;
+       int gpio_num;
 
        sensor = devm_kzalloc(dev, sizeof(*sensor), GFP_KERNEL);
        if (!sensor)
@@ -609,6 +610,9 @@ static int ov5647_probe(struct i2c_client *client,
        /* Request the power down GPIO asserted */
        sensor->pwdn = devm_gpiod_get_optional(&client->dev, "pwdn",
                                               GPIOD_OUT_HIGH);
+       
+       gpio_num = desc_to_gpio(sensor->pwdn);
+       dev_err(dev, "reset on GPIO %d", gpio_num);
 
        mutex_init(&sensor->lock);
Now in dmesg I would expect to get pin ID 133 because I'm running on a rpi 3B (cat /proc/cpuinfo gives revision a02082), but dmesg shows:

Code: Select all

[    3.943592] ov5647 0-0036: reset on GPIO 41
Is this behaviour expected?

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

Re: GPIO number for CAM_GPIO0

Wed Sep 19, 2018 9:28 am

Check your overlays, and the actual state of device tree.

Code: Select all

003521.779: dtparam: cam0-pwdn-ctrl=23
003527.200: dtdebug: Found override cam0-pwdn-ctrl
003527.222: dtparam: cam0-pwdn=5
003532.665: dtdebug: Found override cam0-pwdn
003544.844: dtparam: cam0-led-ctrl=23
003550.313: dtdebug: Found override cam0-led-ctrl
003550.334: dtparam: cam0-led=6
003555.776: dtdebug: Found override cam0-led
is correct. 23 should be the phandle for the expgpio gpio controller, and then pwdn is on output 5 of that, and the led is on ouptut 6, same as is described in dt-blob.dts. The log lines say that it has found the override.

Check where it believes that override is. device tree presents a standard file/directory representation under /proc/device-tree. /proc/device-tree/__overrides__/cam0-pwdn by default will be empty, but with ov5647 correctly loaded will contain

Code: Select all

[email protected]:/ $ xxd /proc/device-tree/__overrides__/cam0-pwdn
00000000: 0000 007c 7077 646e 2d67 7069 6f73 3a34  ...|pwdn-gpios:4
00000010: 00                                       .
Look at /proc/device-tree/soc/[email protected]/[email protected]/phandle and it should match the value at the start of that line, in my case 7c.

And looking at /proc/device-tree/soc/[email protected]/[email protected]/pwdn-gpios I get

Code: Select all

[email protected]:/ $ xxd /proc/device-tree/soc/[email protected]/[email protected]/pwdn-gpios 
00000000: 0000 0030 0000 0005 0000 0001 0000 0030  ...0...........0
00000010: 0000 0006 0000 0001                      ........
phandle 30 for the expgpio, gpio 5, (can't remember what the 1 means), phandle 30 for the expgpio, gpio 6, (and still can't remember).

Something along that path hasn't been correctly processed for you.
Check your firmware is new enough. "vcgencmd version" needs to return a firmware after 14th Nov 2017.
Check that you did actually update the base dtbs and overlays when you rebuilt.
I've just done this on a 3B+, but the mechanisms are identical for all the platforms.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
Please don't send PMs asking for support - use the forum.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

Garrix
Posts: 9
Joined: Thu Aug 16, 2018 10:48 pm

Re: GPIO number for CAM_GPIO0

Wed Sep 19, 2018 7:01 pm

Check where it believes that override is. device tree presents a standard file/directory representation under /proc/device-tree. /proc/device-tree/__overrides__/cam0-pwdn by default will be empty, but with ov5647 correctly loaded will contain
On my side it is empty. If I decompile the device tree with

Code: Select all

dtc -I fs -O dts /sys/firmware/devicetree/base >> devicetree.dts
I get these __overrides__

Code: Select all

__overrides__ {
		pwr_led_gpio = "", "", "", "/gpios:4";
		cam0-led-ctrl;
		i2c1 = "", "", "", "#status";
		i2c_vc = "", "", "", "\"status";
		sd_overclock = "", "", "", "'brcm,overclock-50:0";
		sdio_overclock = "", "", "", "(brcm,overclock-50:0";
		i2c0_baudrate = "", "", "", "\"clock-frequency:0";
		sd_pio_limit = "", "", "", "'brcm,pio-limit:0";
		act_led_trigger = "", "", "", ".linux,default-trigger";
		audio = "", "", "", "$status";
		sd_debug = "", "", "", "'brcm,debug";
		cam0-pwdn-ctrl;
		cache_line_size = [00 00 00 1d 63 61 63 68 65 2d 6c 69 6e 65 2d 73 69 7a 65 3a 30 00];
		cam0-led;
		i2c1_baudrate = "", "", "", "#clock-frequency:0";
		spi = "", "", "", "!status";
		i2c_arm = "", "", "", "#status";
		pwr_led_activelow = "", "", "", "/gpios:8";
		uart0 = [00 00 00 1e 73 74 61 74 75 73 00];
		i2c2_iknowwhatimdoing = [00 00 00 16 73 74 61 74 75 73 00];
		i2s = "", "", "", " status";
		i2c0 = "", "", "", "\"status";
		arm_freq = "", "", "", "*clock-frequency:0", "", "", "", "+clock-frequency:0", "", "", "", ",clock-frequency:0", "", "", "", "-clock-frequency:0";
		watchdog = "", "", "", "%status";
		i2c_baudrate = "", "", "", "#clock-frequency:0";
		i2c_vc_baudrate = "", "", "", "\"clock-frequency:0";
		axiperf = "", "", "", ")status";
		act_led_activelow = "", "", "", ".gpios:8";
		i2c2_baudrate = [00 00 00 16 63 6c 6f 63 6b 2d 66 72 65 71 75 65 6e 63 79 3a 30 00];
		sd_force_pio = "", "", "", "'brcm,force-pio?";
		pwr_led_trigger = "", "", "", "/linux,default-trigger";
		cam0-pwdn;
		uart1 = [00 00 00 1f 73 74 61 74 75 73 00];
		i2c_arm_baudrate = "", "", "", "#clock-frequency:0";
		random = "", "", "", "&status";
		act_led_gpio = "", "", "", ".gpios:4";
		i2c = "", "", "", "#status";
	};
	
I don't have the camera attached, but would expect the overload to work also without the having the hardware connected to it... I'm working on the default rpi-4.14.y branch (with your patches from the above PR), I followed these instructions to compile the kernel, modules and device tree: https://www.raspberrypi.org/documentati ... uilding.md
but maybe something went wrong on my side.
Anyway the most important point is that I understood how it will work on a system that is set up correctly. I coded my driver in the same way as OV5647, so I assume that it will work.

Thanks a lot for the help

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

Re: GPIO number for CAM_GPIO0

Wed Sep 19, 2018 8:13 pm

The PR is merged, so no need to cherry-pick anything. Those are the correct instructions for building the kernel.

It sounds like the overlay hasn't been updated in /boot/overlay as it should have updated cam0-pwdn etc. Check timestamps on the overlay, and "vcdbg log msg" for any info on what it is applying. The firmware can't update the parameters if it hasn't been pointed at the correct place.

Without the camera attached it will try probing for it over I2C, and then abort if it doesn't get the correct ID value read back. But you're correct that it should set all the DT stuff up regardless.
Software Engineer at Raspberry Pi Trading. Views expressed are still personal views.
Please don't send PMs asking for support - use the forum.
I'm not interested in doing contracts for bespoke functionality - please don't ask.

Return to “Advanced users”