OV5640 on kernel 5.4

We’ve managed to build and flash qcomlt-5.4 to our 820uSoM.
Now we are trying to enable and try out ov5640 camera on 5.4 kernel. We’ve used 4.14 device tree entries for ov5640 for inspiration, but no luck. This is the current patch we have

diff --git a/arch/arm64/boot/dts/qcom/apq8096-db820c.dts b/arch/arm64/boot/dts/qcom/apq8096-db820c.dts
index 757afa27424d..1c03468dbda4 100644
--- a/arch/arm64/boot/dts/qcom/apq8096-db820c.dts
+++ b/arch/arm64/boot/dts/qcom/apq8096-db820c.dts
@@ -10,4 +10,208 @@
 / {
 	model = "Qualcomm Technologies, Inc. DB820c";
 	compatible = "arrow,apq8096-db820c", "qcom,apq8096-sbc", "qcom,apq8096";
+	qcom,msm-id = <291 0x30001>;
+	qcom,board-id = <10 28>;
+};
+
+&pmi8994_gpios {
+	wlan_vreg_3p3_en_gpio:pmi8996_gpio8 {
+		pinconf {
+			pins = "gpio8";
+			function = PMIC_GPIO_FUNC_NORMAL;
+			output-enable;
+			bias-pull-up;
+			qcom,drive-strength = <PMIC_GPIO_STRENGTH_LOW>;
+			power-source = <PM8994_GPIO_S4>; // 1.8V
+		};
+	};
+
+	wlan_vreg_1p8_en_gpio:pmi8996_gpio9 {
+		pinconf {
+			pins = "gpio9";
+			function = PMIC_GPIO_FUNC_NORMAL;
+			output-enable;
+			bias-pull-up;
+			qcom,drive-strength = <PMIC_GPIO_STRENGTH_LOW>;
+			power-source = <PM8994_GPIO_S4>; // 1.8V
+		};
+	};
+};
+
+&soc {
+	wlan_3p3_en: wlan-vreg-en-3-3v {
+		compatible = "regulator-fixed";
+		regulator-name = "wlan-vreg-en-3p3-regulator";
+		regulator-min-microvolt = <3300000>;
+		regulator-max-microvolt = <3300000>;
+		gpio = <&pmi8994_gpios 8 GPIO_ACTIVE_HIGH>;
+
+		/* WLAN card specific delay */
+		startup-delay-us = <5000>;
+		enable-active-high;
+	};
+
+	wlan_1p8_en: wlan-vreg-en-1-8v {
+		compatible = "regulator-fixed";
+		regulator-name = "wlan-vreg-en-1p8-regulator";
+		regulator-min-microvolt = <1800000>;
+		regulator-max-microvolt = <1800000>;
+		gpio = <&pmi8994_gpios 9 GPIO_ACTIVE_HIGH>;
+
+		/* WLAN card specific delay */
+		startup-delay-us = <5000>;
+		enable-active-high;
+		vin-supply = <&wlan_3p3_en>;
+	};
+};
+
+&wlan_en {
+	vin-supply = <&wlan_1p8_en>;
+};
+
+&{/} {
+	rpm-glink {
+		rpm_requests {
+			pm8994-regulators {
+
+				vdd_lvs1_2-supply = <&pm8994_s4>;
+
+				pm8994_lvs1: lvs1 {
+					regulator-min-microvolt = <1800000>;
+					regulator-max-microvolt = <1800000>;
+					regulator-always-on;
+				};
+
+				l17 {
+					regulator-min-microvolt = <2800000>;
+					regulator-max-microvolt = <2800000>;
+					regulator-always-on;
+				};
+
+				l18 {
+					regulator-min-microvolt = <2800000>;
+					regulator-max-microvolt = <2800000>;
+					regulator-always-on;
+				};
+				l23 {
+					regulator-always-on;
+				};
+				l29 {
+					regulator-always-on;
+				};
+			};
+		};
+	};
+};
+
+&soc {
+	cci@a0c000 {
+		status = "ok";
+
+		camera_rear@78 {
+			compatible = "ovti,ov5640";
+			reg = <0x78>;
+
+			powerdown-gpios = <&msmgpio 26 GPIO_ACTIVE_HIGH>;
+			reset-gpios = <&msmgpio 25 GPIO_ACTIVE_LOW>;
+
+			pinctrl-names = "default";
+			pinctrl-0 = <&camera_rear_default>;
+
+			clocks = <&mmcc CAMSS_MCLK0_CLK>;
+			clock-names = "xclk";
+			clock-frequency = <23880000>;
+			status = "ok";
+
+			port {
+				ov5640_ep: endpoint {
+					clock-lanes = <1>;
+					data-lanes = <0 2>;
+					remote-endpoint = <&csiphy0_ep>;
+				};
+			};
+		};
+
+
+		camera_board@3c {
+			compatible = "ovti,ov5640";
+			reg = <0x3c>;
+
+			powerdown-gpios = <&msmgpio 98 GPIO_ACTIVE_HIGH>;
+			reset-gpios = <&msmgpio 104 GPIO_ACTIVE_LOW>;
+			pinctrl-names = "default";
+			pinctrl-0 = <&camera_board_default>;
+
+			clocks = <&mmcc CAMSS_MCLK1_CLK>;
+			clock-names = "xclk";
+			clock-frequency = <23880000>;
+			status = "ok";
+
+			port {
+				ov5640_2_ep: endpoint {
+					clock-lanes = <1>;
+					data-lanes = <0 2>;
+					remote-endpoint = <&csiphy1_ep>;
+				};
+			};
+		};
+
+		camera_front@3a {
+			compatible = "ovti,ov5640";
+			reg = <0x3a>;
+			enable-gpios = <&msmgpio 133 GPIO_ACTIVE_HIGH>;
+			reset-gpios = <&msmgpio 23 GPIO_ACTIVE_LOW>;
+			pinctrl-names = "default";
+			pinctrl-0 = <&camera_front_default>;
+			clocks = <&mmcc CAMSS_MCLK2_CLK>;
+			clock-names = "xclk";
+			clock-frequency = <23880000>;
+			status = "ok";
+
+			port {
+				ov5640_3_ep: endpoint {
+					clock-lanes = <1>;
+					data-lanes = <0 2>;
+					remote-endpoint = <&csiphy2_ep>;
+				};
+			};
+		};
+	};
+
+	camss@a00000 {
+		status = "ok";
+
+		ports {
+			#address-cells = <1>;
+			#size-cells = <0>;
+			port@0 {
+				reg = <0>;
+				csiphy0_ep: endpoint {
+					clock-lanes = <7>;
+					data-lanes = <0 1>;
+					remote-endpoint = <&ov5640_ep>;
+					status = "ok";
+				};
+			};
+
+			port@1 {
+				reg = <1>;
+				csiphy1_ep: endpoint {
+					clock-lanes = <7>;
+					data-lanes = <0 1>;
+					remote-endpoint = <&ov5640_2_ep>;
+					status = "ok";
+				};
+			};
+			port@2 {
+				reg = <2>;
+				csiphy2_ep: endpoint {
+					clock-lanes = <7>;
+					data-lanes = <0 1>;
+					remote-endpoint = <&ov5640_3_ep>;
+					status = "ok";
+				};
+			};
+		};
+	};
 };
diff --git a/arch/arm64/boot/dts/qcom/apq8096-db820c.dtsi b/arch/arm64/boot/dts/qcom/apq8096-db820c.dtsi
index 32c585012991..deaa9e6fab14 100644
--- a/arch/arm64/boot/dts/qcom/apq8096-db820c.dtsi
+++ b/arch/arm64/boot/dts/qcom/apq8096-db820c.dtsi
@@ -491,6 +491,154 @@
 
 				core-vdda-supply = <&pm8994_l12>;
 				core-vcc-supply = <&pm8994_s4>;
+				#sound-dai-cells = <1>;
+			};
+		};
+
+		camera_vdddo_1v8: fixedregulator@0 {
+			compatible = "regulator-fixed";
+			regulator-name = "camera_vdddo";
+			regulator-min-microvolt = <1800000>;
+			regulator-max-microvolt = <1800000>;
+			regulator-always-on;
+		};
+
+		camera_vdda_2v8: fixedregulator@1 {
+			compatible = "regulator-fixed";
+			regulator-name = "camera_vdda";
+			regulator-min-microvolt = <2800000>;
+			regulator-max-microvolt = <2800000>;
+			regulator-always-on;
+		};
+
+		camera_vddd_1v5: fixedregulator@2 {
+			compatible = "regulator-fixed";
+			regulator-name = "camera_vddd";
+			regulator-min-microvolt = <1500000>;
+			regulator-max-microvolt = <1500000>;
+			regulator-always-on;
+		};
+
+		cci@a0c000 {
+			status = "ok";
+
+			camera_rear@60 {
+				compatible = "ovti,ov7251";
+				reg = <0x60>;
+
+				enable-gpios = <&msmgpio 25 GPIO_ACTIVE_HIGH>;
+				pinctrl-names = "default";
+				pinctrl-0 = <&camera_rear_default>;
+
+				clocks = <&mmcc CAMSS_MCLK0_CLK>;
+				clock-names = "xclk";
+				clock-frequency = <24000000>;
+
+				vdddo-supply = <&camera_vdddo_1v8>;
+				vdda-supply = <&camera_vdda_2v8>;
+				vddd-supply = <&camera_vddd_1v5>;
+
+				status = "disabled";
+
+				port {
+					ov7251_ep: endpoint {
+						clock-lanes = <1>;
+						data-lanes = <0>;
+						remote-endpoint = <&csiphy0_ep>;
+					};
+				};
+			};
+
+			camera_board@39 {
+				compatible = "ovti,ov5645";
+				reg = <0x39>;
+
+				enable-gpios = <&msmgpio 98 GPIO_ACTIVE_HIGH>;
+				reset-gpios = <&msmgpio 104 GPIO_ACTIVE_LOW>;
+				pinctrl-names = "default";
+				pinctrl-0 = <&camera_board_default>;
+
+				clocks = <&mmcc CAMSS_MCLK1_CLK>;
+				clock-names = "xclk";
+				clock-frequency = <24000000>;
+
+				vdddo-supply = <&camera_vdddo_1v8>;
+				vdda-supply = <&camera_vdda_2v8>;
+				vddd-supply = <&camera_vddd_1v5>;
+
+				status = "disabled";
+
+				port {
+					ov5645_2_ep: endpoint {
+						clock-lanes = <1>;
+						data-lanes = <0 2>;
+						remote-endpoint = <&csiphy1_ep>;
+					};
+				};
+			};
+
+			camera_front@3a {
+				compatible = "ovti,ov5645";
+				reg = <0x3a>;
+
+				enable-gpios = <&msmgpio 133 GPIO_ACTIVE_HIGH>;
+				reset-gpios = <&msmgpio 23 GPIO_ACTIVE_LOW>;
+				pinctrl-names = "default";
+				pinctrl-0 = <&camera_front_default>;
+
+				clocks = <&mmcc CAMSS_MCLK2_CLK>;
+				clock-names = "xclk";
+				clock-frequency = <24000000>;
+
+				vdddo-supply = <&camera_vdddo_1v8>;
+				vdda-supply = <&camera_vdda_2v8>;
+				vddd-supply = <&camera_vddd_1v5>;
+
+				status = "disabled";
+
+				port {
+					ov5645_3_ep: endpoint {
+						clock-lanes = <1>;
+						data-lanes = <0 2>;
+						remote-endpoint = <&csiphy2_ep>;
+					};
+				};
+			};
+		};
+
+		camss@a00000 {
+			status = "ok";
+
+			ports {
+				#address-cells = <1>;
+				#size-cells = <0>;
+				port@0 {
+					reg = <0>;
+					csiphy0_ep: endpoint {
+						clock-lanes = <7>;
+						data-lanes = <0>;
+						remote-endpoint = <&ov7251_ep>;
+						status = "disabled";
+					};
+				};
+				port@1 {
+					reg = <1>;
+					csiphy1_ep: endpoint {
+						clock-lanes = <7>;
+						data-lanes = <0 1>;
+						remote-endpoint = <&ov5645_2_ep>;
+						status = "disabled";
+					};
+				};
+				port@2 {
+					reg = <2>;
+					csiphy2_ep: endpoint {
+						clock-lanes = <7>;
+						data-lanes = <0 1>;
+						remote-endpoint = <&ov5645_3_ep>;
+						status = "disabled";
+					};
+				};
 			};
 		};
 	};
diff --git a/arch/arm64/boot/dts/qcom/msm8996.dtsi b/arch/arm64/boot/dts/qcom/msm8996.dtsi
index 96b9993edf8c..fc0cc9d36f32 100644
--- a/arch/arm64/boot/dts/qcom/msm8996.dtsi
+++ b/arch/arm64/boot/dts/qcom/msm8996.dtsi
@@ -1668,7 +1668,27 @@
 			};
 		};
 
-		vfe_smmu: iommu@da0000 {
+		cci: cci@a0c000 {
+			compatible = "qcom,cci-v1.4.0";
+			#address-cells = <1>;
+			#size-cells = <0>;
+			reg = <0xa0c000 0x1000>;
+			interrupts = <GIC_SPI 295 IRQ_TYPE_EDGE_RISING>;
+			power-domains = <&mmcc CAMSS_GDSC>;
+			clocks = <&mmcc CAMSS_TOP_AHB_CLK>,
+					<&mmcc CAMSS_CCI_AHB_CLK>,
+					<&mmcc CAMSS_CCI_CLK>,
+					<&mmcc CAMSS_AHB_CLK>;
+			clock-names = "camss_top_ahb",
+					"cci_ahb",
+					"cci",
+					"camss_ahb";
+			pinctrl-names = "default";
+			pinctrl-0 = <&cci0_default>;
+			status = "disabled";
+		};
+
+		vfe_smmu: iommu@da0000  {
 			compatible = "qcom,msm8996-smmu-v2", "qcom,smmu-v2";
 			reg = <0xda0000 0x10000>;
 
@@ -1682,6 +1702,7 @@
 			clock-names = "iface",
 				      "bus";
 			#iommu-cells = <1>;
+			status = "ok";
 		};
 
 		camss: camss@a00000 {
diff --git a/arch/arm64/configs/defconfig b/arch/arm64/configs/defconfig
index fac77bd32801..e99915375b2d 100644
--- a/arch/arm64/configs/defconfig
+++ b/arch/arm64/configs/defconfig
@@ -550,6 +550,7 @@ CONFIG_VIDEO_RENESAS_FCP=m
 CONFIG_VIDEO_RENESAS_VSP1=m
 CONFIG_VIDEO_QCOM_VENUS=m
 CONFIG_VIDEO_QCOM_CAMSS=m
+CONFIG_VIDEO_OV5640=y
 CONFIG_DRM=y
 CONFIG_DRM_I2C_NXP_TDA998X=m
 CONFIG_DRM_NOUVEAU=m

and here is the kernel output. The kernel spams internal error every few seconds

[  486.903318] Unable to handle kernel NULL pointer dereference at virtual address 000000000000000d␍␊
[16:08:56:662] [  486.903348] Mem abort info:␍␊
[16:08:56:662] [  486.911236]   ESR = 0x96000004␍␊
[16:08:56:662] [  486.913682]   EC = 0x25: DABT (current EL), IL = 32 bits␍␊
[16:08:56:662] [  486.916838]   SET = 0, FnV = 0␍␊
[16:08:56:662] [  486.922336]   EA = 0, S1PTW = 0␍␊
[16:08:56:662] [  486.925218] Data abort info:␍␊
[16:08:56:662] [  486.928598]   ISV = 0, ISS = 0x00000004␍␊
[16:08:56:662] [  486.931588]   CM = 0, WnR = 0␍␊
[16:08:56:662] [  486.934863] user pgtable: 4k pages, 48-bit VAs, pgdp=000000012f758000␍␊
[16:08:56:662] [  486.938432] [000000000000000d] pgd=0000000000000000␍␊
[16:08:56:705] [  486.944456] Internal error: Oops: 96000004 [#61] PREEMPT SMP␍␊
[16:08:56:705] [  486.949096] Modules linked in: ov5640 rfcomm snd_soc_hdmi_codec venus_dec venus_enc bnep msm ath10k_pci qcom_camss ath10k_core venus_core videobuf2_dma_sg hci_uart v4l2_fwnode v4l2_mem2mem videobuf2_memops videobuf2_v4l2 videobuf2_common snd_soc_apq8096 btqca ath snd_soc_qcom_common btbcm q6afe q6core videodev apr crct10dif_ce mc slim_qcom_ngd_ctrl bluetooth xhci_plat_hcd ecdh_generic xhci_hcd ecc qcom_rng rtc_pm8xxx qrtr qcom_q6v5_pas socinfo qcom_q6v5_mss qcom_sysmon qcom_q6v5 rmtfs_mem qmi_helpers glink_ssr mdt_loader qcom_common qcom_glink_smem ip_tables x_tables␍␊
[16:08:56:748] [  486.982869] CPU: 1 PID: 5208 Comm: systemd-logind Tainted: G      D W         5.4.54-GUA-Debian_v3.4 #1␍␊
[16:08:56:748] [  487.005105] Hardware name: Qualcomm Technologies, Inc. DB820c (DT)␍␊
[16:08:56:748] [  487.014289] pstate: 00000005 (nzcv daif -PAN -UAO)␍␊
[16:08:56:748] [  487.020543] pc : sysfs_kf_seq_show+0x2c/0x148␍␊
[16:08:56:748] [  487.025315] lr : kernfs_seq_show+0x28/0x30␍␊
[16:08:56:791] [  487.029742] sp : ffff800013e8bcd0␍␊
[16:08:56:791] ␍␍␊
[16:08:56:791] <0x07>Message from syslogd@OpenQ820 at Nov 11 15:08:56 ...␍[  487.033728] x29: ffff800013e8bcd0 x28: 0000aaaac8ed5a90 ␍␊
[16:08:56:791] ␍␊
[16:08:56:791]  k[  4erne87.0l:[ 4215 4867] x.94427: 456]0000 Int0000erna0[  487.047450] x25: 0000000000400cc0 x24: ffff0000aee5d500 ␍␊
[16:08:56:791] [  487.052752] x23: 0000000000000000 x22: ffff0000afc54200 ␍␊
[16:08:56:791] [  487.058040] x21: ffff0000ad452e78 x20: 0000000000000001 ␍␊
[16:08:56:791] [  487.063329] x19: ffff0000af4dc280 x18: 0000000000000000 ␍␊
[16:08:56:791] [  487.068625] x17: 0000000000000000 x16: 0000000000000000 ␍␊
[16:08:56:835] [  487.073920] x15: 0000000000000000 x14: 0000000000000000 ␍␊
[16:08:56:835] [  487.079217] x13: 0000000000000000 x12: 0000000000000000 ␍␊
[16:08:56:835] [  487.084511] x11: 0000000000000000 x10: 0000000000000000 ␍␊
[16:08:56:835] [  487.089807] x9 : 0000000000000000 x8 : 0000aaaac8ed5a90 ␍␊
[16:08:56:835] [  487.095101] x7 : 00000000fbada488 x6 : 0000000000000000 ␍␊
[16:08:56:835] [  487.100396] x5 : ffff0000ad6a4110 x4 : 0000000000000001 ␍␊
[16:08:56:835] [  487.105690] x3 : ffff0000afc54200 x2 : ffff80001031b8f0 ␍␊
[16:08:56:835] [  487.110986] x1 : 0000000000000005 x0 : ffff0000af4dc280 ␍␊
[16:08:56:878] [  487.116286] Call trace:␍␊
[16:08:56:878] EEMP[  4T SM87.1P␍␊
[16:08:56:878] ␍21587]  sysfs_kf_seq_show+[  487.123747]  kernfs_seq_show+0x28/0x30␍␊
[16:08:56:878] [  487.127916]  seq_read+0xcc/0x4f8␍␊
[16:08:56:878] [  487.131560]  kernfs_fop_read+0x14c/0x218␍␊
[16:08:56:878] [  487.134943]  __vfs_read+0x18/0x38␍␊
[16:08:56:878] [  487.138861]  vfs_read+0x98/0x188␍␊
[16:08:56:878] [  487.142064]  ksys_read+0x68/0xf8␍␊
[16:08:56:878] [  487.145362]  __arm64_sys_read+0x18/0x20␍␊
[16:08:56:878] [  487.148578]  el0_svc_common.constprop.2+0x64/0x168␍␊
[16:08:56:878] [  487.152135]  el0_svc_handler+0x20/0x80␍␊
[16:08:56:915] [  487.156997]  el0_svc+0x8/0x204␍␊
[16:08:56:915] [  487.160732] Code: f9400421 f9403035 f94016a1 b4000041 (f9400437) ␍␊
[16:08:56:915] [  487.163772] ---[ end trace aa1a92a7bb06c015 ]---␍␊
[16:08:56:915] ␍␍␊
[16:08:56:915] <0x07>Message from syslogd@OpenQ820 at Nov 11 15:08:56 ...␍␍␊
[16:08:56:915]  kernel:[  487.160732] Code: f9400421 f9403035 f94016a1 b4000041 (f9400437) ␍␊
[16:08:56:915] ␍

As you can see, there is no mention of ov5640 driver being run. We tried manually probing the ov5640 driver with manprobe -v ov5640, but to no avail.
modinfo ov5640 returns:

modinfo ov5640␍␊
[16:07:29:928] filename:       /lib/modules/5.4.54-GUA-Debian_v3.4/kernel/drivers/media/i2c/ov5640.ko␍␊
[16:07:29:981] license:        GPL␍␊
[16:07:29:981] description:    OV5640 MIPI Camera Subdev Driver␍␊
[16:07:29:981] alias:          i2c:ov5640␍␊
[16:07:29:981] alias:          of:N*T*Covti,ov5640C*␍␊
[16:07:29:981] alias:          of:N*T*Covti,ov5640␍␊
[16:07:29:981] depends:        videodev,v4l2-fwnode,mc␍␊
[16:07:29:981] intree:         Y␍␊
[16:07:29:981] name:           ov5640␍␊
[16:07:29:981] vermagic:       5.4.54-GUA-Debian_v3.4 SMP preempt mod_unload aarch64␍␊
[16:07:29:981] parm:           virtual_channel:MIPI CSI-2 virtual channel (0..3), default 0 (uint)␍␊
[16:07:29:981] root@OpenQ820:~# 

When running media-ctl -d /dev/media0 -p we get:

Failed to enumerate /dev/media0 (-2)␍␊

We are clearly doing something wrong, but have no idea how to set the nodes right to get the camera working and to also solve those kernel errors.

You should probably try with 5.15, not sure 5.4 has ever been stable on 820