/**
 * 4-cam device tree for AlliedVision sensors
 * Supports following series:
 *  - 1800C -507c
 *  - 1500C -500c
 */

/ {
    /**
	 * i2c-mux @72
	 * CAM A --> 4 lanes	(VI port-index = 0)
	 * CAM C --> 4 lanes	(VI port-index = 2)
	 *
	 * i2c-mux @75
	 * CAM E --> 4 lanes	(VI port-index = 4)
	 * CAM F --> 4 lanes	(VI port-index = 5)	 
	 */
	host1x {
		vi@15c10000 {
			num-channels = <4>;
            status="okay";
			ports {
				#address-cells = <1>;
				#size-cells = <0>;
				port@0 {
					reg = <0>;
                    status="okay";
				    avt_csi2_vi_in0: endpoint {
                        status="okay";
						port-index = <0>;
						bus-width = <4>;
						remote-endpoint = <&avt_csi2_csi_out0>;
					};
				};			
			
				port@1 {
					reg = <1>;
                    status="okay";
				    avt_csi2_vi_in2: endpoint {
                        status="okay";
						port-index = <2>;
						bus-width = <4>;
						remote-endpoint = <&avt_csi2_csi_out2>;
					};
				};				
				
				port@2 {
					reg = <2>;
                    status="okay";
				    avt_csi2_vi_in4: endpoint {
                        status="okay";
						port-index = <4>;
						bus-width = <4>;
						remote-endpoint = <&avt_csi2_csi_out4>;
					};
				};
				
				port@3 {
					reg = <3>;
                    status="okay";
				    avt_csi2_vi_in5: endpoint {
                        status="okay";
						port-index = <5>;
						bus-width = <4>;
						remote-endpoint = <&avt_csi2_csi_out5>;
					};
				};
			};
		};

		nvcsi@15a00000 {
			num-channels = <4>;
			#address-cells = <1>;
			#size-cells = <0>;
            status="okay";
			
			channel@0 {
                status="okay";
				reg = <0>;
				ports {
                    status="okay";
				    #address-cells = <1>;
					#size-cells = <0>;
					port@0 {
						reg = <0>;
                        status="okay";
						avt_csi2_csi_in0: endpoint@0 {
                            status="okay";
							port-index = <0>;
							bus-width = <4>;
							remote-endpoint = <&avt_csi2_cam_out0>;
						};
					};
					port@1 {
                        status="okay";
						reg = <1>;
						avt_csi2_csi_out0: endpoint@1 {
                            status="okay";
							remote-endpoint = <&avt_csi2_vi_in0>;
						};
					};
				};
			};
			
			channel@1 {
                status="okay";
				reg = <1>;
				ports {
                    status="okay";
				    #address-cells = <1>;
					#size-cells = <0>;
					port@0 {
						reg = <0>;
                        status="okay";
						avt_csi2_csi_in2: endpoint@2 {
                            status="okay";
							port-index = <2>;
							bus-width = <4>;
							remote-endpoint = <&avt_csi2_cam_out2>;
						};
					};
					port@1 {
                        status="okay";
						reg = <1>;
						avt_csi2_csi_out2: endpoint@3 {
                            status="okay";
							remote-endpoint = <&avt_csi2_vi_in2>;
						};
					};
				};
			};
			
			channel@2 {
                status="okay";
				reg = <2>;
				ports {
                    status="okay";
				    #address-cells = <1>;
					#size-cells = <0>;
					port@0 {
						reg = <0>;
                        status="okay";
						avt_csi2_csi_in4: endpoint@4 {
                            status="okay";
							port-index = <4>;
							bus-width = <4>;
							remote-endpoint = <&avt_csi2_cam_out4>;
						};
					};
					port@1 {
                        status="okay";
						reg = <1>;
						avt_csi2_csi_out4: endpoint@5 {
                            status="okay";
							remote-endpoint = <&avt_csi2_vi_in4>;
						};
					};
				};
			};
			
			channel@3 {
                status="okay";
				reg = <3>;
				ports {
                    status="okay";
				    #address-cells = <1>;
					#size-cells = <0>;
					port@0 {
						reg = <0>;
                        status="okay";
						avt_csi2_csi_in5: endpoint@6 {
                            status="okay";
							port-index = <6>;
							bus-width = <4>;
							remote-endpoint = <&avt_csi2_cam_out5>;
						};
					};
					port@1 {
                        status="okay";
						reg = <1>;
						avt_csi2_csi_out5: endpoint@7 {
                            status="okay";
							remote-endpoint = <&avt_csi2_vi_in5>;
						};
					};
				};
			};
		};
	};

	/**I2C2*/
	i2c@c240000 {
		pinctrl-names = "default";
		pinctrl-0 = <&gen8_i2c_pinctrl>;	
	
		status = "okay";
		
		tca9544@72 {
            compatible = "nxp,pca9544";
            reg = <0x72>;
            #address-cells = <1>;
            #size-cells = <0>;
            skip_mux_detect = "yes";

			vif-supply = <&p2822_vdd_1v8_cvb>;
			vcc-supply = <&p2822_vdd_1v8_cvb>;

			vcc_lp = "vcc";			
            force_bus_start = <0x1A>;
            status = "okay";

			i2c@0 {
                reg = <0>;
                i2c-mux,deselect-on-exit;
                #address-cells = <1>;
                #size-cells = <0>;
				
				avt_csi2_a@3c {
					status = "okay";

					clocks = <&bpmp_clks TEGRA194_CLK_EXTPERIPH1>,
							 <&bpmp_clks TEGRA194_CLK_PLLP_OUT0>;
					clock-names = "extperiph1", "pllp_grtba";
					mclk = "extperiph1";
					
					devnode = "video0";
					compatible = "alliedvision,avt_csi2";
					reg = <0x3c>;

					mode0 {
						num_lanes = "4";
						tegra_sinterface = "serial_a";
						discontinuous_clk = "no";
						cil_settletime = "0";
						embedded_metadata_height = "0";

						/* not verified: */
						mclk_khz = "24000";
						phy_mode = "DPHY";
						dpcm_enable = "false";

						active_w = "5488";
						active_h = "4112";
						pixel_t = "bayer_bggr";
						readout_orientation = "0";
						line_length = "5488";
						inherent_gain = "1";
						mclk_multiplier = "31.25";
						pix_clk_hz = "750000000";

						gain_factor = "16";
						framerate_factor = "1000000";
						exposure_factor = "1000000";
						min_gain_val = "16"; /* 1.0 */
						max_gain_val = "256"; /* 16.0 */
						step_gain_val = "1"; /* 0.125 */
						min_hdr_ratio = "1";
						max_hdr_ratio = "64";
						min_framerate = "1500000"; /* 1.5 */
						max_framerate = "30000000"; /* 30 */
						step_framerate = "1";
						min_exp_time = "34"; /* us */
						max_exp_time = "550385"; /* us */
						step_exp_time = "1";
					};
					
					ports {
						#address-cells = <1>;
						#size-cells = <0>;

						port@0 {
							reg = <0>;
							avt_csi2_cam_out0: endpoint {
								port-index = <0>;
								bus-width = <4>;
								remote-endpoint = <&avt_csi2_csi_in0>;
							};
						};
					};
				};
		    };			

			i2c@2 {
                reg = <2>;
                i2c-mux,deselect-on-exit;
                #address-cells = <1>;
                #size-cells = <0>;
				
				avt_csi2_c@3c {
					status = "okay";

					clocks = <&bpmp_clks TEGRA194_CLK_EXTPERIPH1>,
							 <&bpmp_clks TEGRA194_CLK_PLLP_OUT0>;
					clock-names = "extperiph1", "pllp_grtba";
					mclk = "extperiph1";
					
					devnode = "video2";
					compatible = "alliedvision,avt_csi2";
					reg = <0x3c>;

					mode0 {
						num_lanes = "4";
						tegra_sinterface = "serial_c";
						discontinuous_clk = "no";
						cil_settletime = "0";
						embedded_metadata_height = "0";

						/* not verified: */
						mclk_khz = "24000";
						phy_mode = "DPHY";
						dpcm_enable = "false";

						active_w = "5488";
						active_h = "4112";
						pixel_t = "bayer_bggr";
						readout_orientation = "0";
						line_length = "5488";
						inherent_gain = "1";
						mclk_multiplier = "31.25";
						pix_clk_hz = "750000000";

						gain_factor = "16";
						framerate_factor = "1000000";
						exposure_factor = "1000000";
						min_gain_val = "16"; /* 1.0 */
						max_gain_val = "256"; /* 16.0 */
						step_gain_val = "1"; /* 0.125 */
						min_hdr_ratio = "1";
						max_hdr_ratio = "64";
						min_framerate = "1500000"; /* 1.5 */
						max_framerate = "30000000"; /* 30 */
						step_framerate = "1";
						min_exp_time = "34"; /* us */
						max_exp_time = "550385"; /* us */
						step_exp_time = "1";
					};
					
					ports {
						#address-cells = <1>;
						#size-cells = <0>;

						port@0 {
							reg = <0>;
							avt_csi2_cam_out2: endpoint {
								port-index = <2>;
								bus-width = <4>;
								remote-endpoint = <&avt_csi2_csi_in2>;
							};
						};
					};
				};
		    };
	    };		
		
		tca9544@75 {
            compatible = "nxp,pca9544";
            reg = <0x75>;
            #address-cells = <1>;
            #size-cells = <0>;
            skip_mux_detect = "yes";
			/*
			vif-supply = <&p2822_vdd_3v3_cvb>;
			vcc-supply = <&p2822_vdd_3v3_cvb>;
			*/
			vif-supply = <&p2822_vdd_1v8_cvb>;
			vcc-supply = <&p2822_vdd_1v8_cvb>;

			vcc_lp = "vcc";			
            force_bus_start = <0x1E>;
            status = "okay";

			i2c@0 {
                reg = <0>;
                i2c-mux,deselect-on-exit;
                #address-cells = <1>;
                #size-cells = <0>;
				
				avt_csi2_e@3c {
					status = "okay";

					clocks = <&bpmp_clks TEGRA194_CLK_EXTPERIPH1>,
							 <&bpmp_clks TEGRA194_CLK_PLLP_OUT0>;
					clock-names = "extperiph1", "pllp_grtba";
					mclk = "extperiph1";
					
					devnode = "video4";
					compatible = "alliedvision,avt_csi2";
					reg = <0x3c>;

					mode0 {
						num_lanes = "4";
						tegra_sinterface = "serial_e";
						discontinuous_clk = "no";
						cil_settletime = "0";
						embedded_metadata_height = "0";

						/* not verified: */
						mclk_khz = "24000";
						phy_mode = "DPHY";
						dpcm_enable = "false";

						active_w = "5488";
						active_h = "4112";
						pixel_t = "bayer_bggr";
						readout_orientation = "0";
						line_length = "5488";
						inherent_gain = "1";
						mclk_multiplier = "31.25";
						pix_clk_hz = "750000000";

						gain_factor = "16";
						framerate_factor = "1000000";
						exposure_factor = "1000000";
						min_gain_val = "16"; /* 1.0 */
						max_gain_val = "256"; /* 16.0 */
						step_gain_val = "1"; /* 0.125 */
						min_hdr_ratio = "1";
						max_hdr_ratio = "64";
						min_framerate = "1500000"; /* 1.5 */
						max_framerate = "30000000"; /* 30 */
						step_framerate = "1";
						min_exp_time = "34"; /* us */
						max_exp_time = "550385"; /* us */
						step_exp_time = "1";
					};
					
					ports {
						#address-cells = <1>;
						#size-cells = <0>;

						port@0 {
							reg = <0>;
							avt_csi2_cam_out4: endpoint {
								port-index = <4>;
								bus-width = <4>;
								remote-endpoint = <&avt_csi2_csi_in4>;
							};
						};
					};
				};
		    };

			i2c@1 {
                reg = <1>;
                i2c-mux,deselect-on-exit;
                #address-cells = <1>;
                #size-cells = <0>;
				
				avt_csi2_f@3c {
					status = "okay";

					clocks = <&bpmp_clks TEGRA194_CLK_EXTPERIPH1>,
							 <&bpmp_clks TEGRA194_CLK_PLLP_OUT0>;
					clock-names = "extperiph1", "pllp_grtba";
					mclk = "extperiph1";
					
					devnode = "video5";
					compatible = "alliedvision,avt_csi2";
					reg = <0x3c>;

					mode0 {
						num_lanes = "4";
						tegra_sinterface = "serial_g";
						discontinuous_clk = "no";
						cil_settletime = "0";
						embedded_metadata_height = "0";

						/* not verified: */
						mclk_khz = "24000";
						phy_mode = "DPHY";
						dpcm_enable = "false";

						active_w = "5488";
						active_h = "4112";
						pixel_t = "bayer_bggr";
						readout_orientation = "0";
						line_length = "5488";
						inherent_gain = "1";
						mclk_multiplier = "31.25";
						pix_clk_hz = "750000000";

						gain_factor = "16";
						framerate_factor = "1000000";
						exposure_factor = "1000000";
						min_gain_val = "16"; /* 1.0 */
						max_gain_val = "256"; /* 16.0 */
						step_gain_val = "1"; /* 0.125 */
						min_hdr_ratio = "1";
						max_hdr_ratio = "64";
						min_framerate = "1500000"; /* 1.5 */
						max_framerate = "30000000"; /* 30 */
						step_framerate = "1";
						min_exp_time = "34"; /* us */
						max_exp_time = "550385"; /* us */
						step_exp_time = "1";
					};
					
					ports {
						#address-cells = <1>;
						#size-cells = <0>;

						port@0 {
							reg = <0>;
							avt_csi2_cam_out5: endpoint {
								port-index = <6>;
								bus-width = <4>;
								remote-endpoint = <&avt_csi2_csi_in5>;
							};
						};
					};
				};
		    };
	    };
	};
	
	/**I2C3*/	
    i2c@3180000 {
        clock-frequency = <100000>;
        tca9539_74: tca9539@74 {
            compatible = "ti,tca9539";
            gpio-controller;
            #gpio-cells = <2>;
            reg = <0x74>;
            vcc-supply = <&p2822_vdd_1v8_cvb>;
            status = "okay";
            tca9539_74_outlow {
                /*
                 * GPIO-A  : 
                 * GPIO-B  : 
                 * GPIO-C  : 
                 * GPIO-D  : 
                 * GPIO-E  : 
                 * GPIO-F  : 
                 * GPIO-G  : Derived from dip switch
                 * GPIO-H  : Not used
                 */
                gpio-hog;
                gpios = <0 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0 8 0 9 0 10 0 11 0 12 0 13 0 14 0 15 0>;
                output-high;
                label = "tca9539_74_outlow_0",
                    "tca9539_74_outlow_1",
                    "tca9539_74_outlow_2",
                    "tca9539_74_outlow_3",
                    "tca9539_74_outlow_4",
                    "tca9539_74_outlow_5",
                    "tca9539_74_outlow_6",
                    "tca9539_74_outlow_7",
                    "tca9539_74_outlow_8",
                    "tca9539_74_outlow_9",
                    "tca9539_74_outlow_10",
                    "tca9539_74_outlow_11",
                    "tca9539_74_outlow_12",
                    "tca9539_74_outlow_13";
            };
            tca9539_74_outhigh {
                status= "disabled";
            };
            tca9539_74_input {
                status = "disabled";
            };
        };
    };

	pinmux@2430000 {
		gen8_i2c_pinctrl: gen8_i2c_pinctrl {
			gen8_i2c_scl {
				nvidia,pins = "gen8_i2c_scl_pdd1";
				nvidia,schmitt = <TEGRA_PIN_DISABLE>;
				nvidia,lpdr = <TEGRA_PIN_DISABLE>;
				nvidia,enable-input = <TEGRA_PIN_ENABLE>;
				nvidia,io-high-voltage = <TEGRA_PIN_DISABLE>;
				nvidia,tristate = <TEGRA_PIN_DISABLE>;
				nvidia,pull = <TEGRA_PIN_PULL_NONE>;
			};
			gen8_i2c_sda {
				nvidia,pins = "gen8_i2c_sda_pdd2";
				nvidia,schmitt = <TEGRA_PIN_DISABLE>;
				nvidia,lpdr = <TEGRA_PIN_DISABLE>;
				nvidia,enable-input = <TEGRA_PIN_ENABLE>;
				nvidia,io-high-voltage = <TEGRA_PIN_DISABLE>;
				nvidia,tristate = <TEGRA_PIN_DISABLE>;
				nvidia,pull = <TEGRA_PIN_PULL_NONE>;
			};
		};
	};
};



/ {
	tegra-camera-platform {
		compatible = "nvidia, tegra-camera-platform";
		num_csi_lanes = <18>;
		max_lane_speed = <1500000>;
		min_bits_per_pixel = <10>;
		vi_peak_byte_per_pixel = <2>;
		vi_bw_margin_pct = <25>;
		max_pixel_rate = <160000>;
		isp_peak_byte_per_pixel = <5>;
		isp_bw_margin_pct = <25>;

		/**
		 * The general guideline for naming badge_info contains 3 parts, and is as follows,
		 * The first part is the camera_board_id for the module; if the module is in a FFD
		 * platform, then use the platform name for this part.
		 * The second part contains the position of the module, ex. "rear" or "front".
		 * The third part contains the last 6 characters of a part number which is found
		 * in the module's specsheet from the vender.
		 */
		modules {
			module0 {
				status = "okay";
				badge = "avt_csi2_0";
				position = "top";
				orientation = "1";
				drivernode0 {
					pcl_id = "v4l2_sensor";
					devname = "avt_csi2 0 26-003c";
					proc-device-tree = "/proc/device-tree/i2c@c240000/tca9544@72/i2c@0/avt_csi2_a@3c";					
				};
				drivernode1 {
					pcl_id = "v4l2_lens";
				};
			};
			
			module1 {
				status = "okay";
				badge = "avt_csi2_2";
				position = "bottom";
				orientation = "1";
				drivernode0 {
					pcl_id = "v4l2_sensor";
					devname = "avt_csi2 2 28-003c";
					proc-device-tree = "/proc/device-tree/i2c@c240000/tca9544@72/i2c@2/avt_csi2_c@3c";					
				};
				drivernode1 {
					pcl_id = "v4l2_lens";
				};
			};
			
			module2 {
				status = "okay";
				badge = "avt_csi2_4";
				position = "center-right";
				orientation = "1";
				drivernode0 {
					pcl_id = "v4l2_sensor";
					devname = "avt_csi2 4 30-003c";
					proc-device-tree = "/proc/device-tree/i2c@c240000/tca9544@75/i2c@0/avt_csi2_e@3c";
				};
				drivernode1 {
					pcl_id = "v4l2_lens";
				};
			};
			
			module3 {
				status = "okay";
				badge = "avt_csi2_5";
				position = "topright";
				orientation = "1";
				drivernode0 {
					pcl_id = "v4l2_sensor";
					devname = "avt_csi2 5 31-003c";
					proc-device-tree = "/proc/device-tree/i2c@c240000/tca9544@75/i2c@1/avt_csi2_f@3c";					
				};
				drivernode1 {
					pcl_id = "v4l2_lens";
				};
			};
		};
	};
};