From a477a6351575aa173f9f82857f5797e384fbc704 Mon Sep 17 00:00:00 2001
From: JinShil <slavo5150@yahoo.com>
Date: Tue, 28 Nov 2023 17:05:44 +0900
Subject: [PATCH] overlays: ADS1115: allow specification of the i2c bus

---
 arch/arm/boot/dts/overlays/README             | 10 +++
 .../arm/boot/dts/overlays/ads1115-overlay.dts | 80 +++++++++++++------
 2 files changed, 66 insertions(+), 24 deletions(-)

--- a/arch/arm/boot/dts/overlays/README
+++ b/arch/arm/boot/dts/overlays/README
@@ -489,6 +489,16 @@ Params: addr                    I2C bus
         cha_gain                Set the gain of the Programmable Gain
                                 Amplifier for this channel. (Default 1 sets the
                                 full scale of the channel to 4.096 Volts)
+        i2c0                    Choose the I2C0 bus on GPIOs 0&1
+        i2c_csi_dsi             Choose the I2C0 bus on GPIOs 44&45
+        i2c3                    Choose the I2C3 bus (configure with the i2c3
+                                overlay - BCM2711 only)
+        i2c4                    Choose the I2C4 bus (configure with the i2c4
+                                overlay - BCM2711 only)
+        i2c5                    Choose the I2C5 bus (configure with the i2c5
+                                overlay - BCM2711 only)
+        i2c6                    Choose the I2C6 bus (configure with the i2c6
+                                overlay - BCM2711 only)
 
         Channel parameters can be set for each enabled channel.
         A maximum of 4 channels can be enabled (letters a thru d).
--- a/arch/arm/boot/dts/overlays/ads1115-overlay.dts
+++ b/arch/arm/boot/dts/overlays/ads1115-overlay.dts
@@ -9,23 +9,6 @@
 	compatible = "brcm,bcm2835";
 
 	fragment@0 {
-		target = <&i2c_arm>;
-		__overlay__ {
-			#address-cells = <1>;
-			#size-cells = <0>;
-			status = "okay";
-
-			ads1115: ads1115@48 {
-				compatible = "ti,ads1115";
-				status = "okay";
-				#address-cells = <1>;
-				#size-cells = <0>;
-				reg = <0x48>;
-			};
-		};
-	};
-
-	fragment@1 {
 		target = <&ads1115>;
 		__dormant__ {
 			#address-cells = <1>;
@@ -39,7 +22,7 @@
 		};
 	};
 
-	fragment@2 {
+	fragment@1 {
 		target = <&ads1115>;
 		__dormant__ {
 			#address-cells = <1>;
@@ -53,7 +36,7 @@
 		};
 	};
 
-	fragment@3 {
+	fragment@2 {
 		target = <&ads1115>;
 		__dormant__ {
 			#address-cells = <1>;
@@ -67,7 +50,7 @@
 		};
 	};
 
-	fragment@4 {
+	fragment@3 {
 		target = <&ads1115>;
 		__dormant__ {
 			#address-cells = <1>;
@@ -81,23 +64,72 @@
 		};
 	};
 
+	fragment@4 {
+		target = <&i2cbus>;
+		__overlay__ {
+			#address-cells = <1>;
+			#size-cells = <0>;
+			status = "okay";
+
+			ads1115: ads1115@48 {
+				compatible = "ti,ads1115";
+				status = "okay";
+				#address-cells = <1>;
+				#size-cells = <0>;
+				reg = <0x48>;
+			};
+		};
+	};
+
+	frag100: fragment@100 {
+		target = <&i2c1>;
+		i2cbus: __overlay__ {
+			status = "okay";
+		};
+	};
+
+	fragment@101 {
+		target = <&i2c0if>;
+		__dormant__ {
+			status = "okay";
+		};
+	};
+
+	fragment@102 {
+		target = <&i2c0mux>;
+		__dormant__ {
+			status = "okay";
+		};
+	};
+
 	__overrides__ {
 		addr =            <&ads1115>,"reg:0";
-		cha_enable =      <0>,"=1";
+		cha_enable =      <0>,"=0";
 		cha_cfg =         <&channel_a>,"reg:0";
 		cha_gain =        <&channel_a>,"ti,gain:0";
 		cha_datarate =    <&channel_a>,"ti,datarate:0";
-		chb_enable =      <0>,"=2";
+		chb_enable =      <0>,"=1";
 		chb_cfg =         <&channel_b>,"reg:0";
 		chb_gain =        <&channel_b>,"ti,gain:0";
 		chb_datarate =    <&channel_b>,"ti,datarate:0";
-		chc_enable =      <0>,"=3";
+		chc_enable =      <0>,"=2";
 		chc_cfg =         <&channel_c>,"reg:0";
 		chc_gain =        <&channel_c>,"ti,gain:0";
 		chc_datarate =    <&channel_c>,"ti,datarate:0";
-		chd_enable =      <0>,"=4";
+		chd_enable =      <0>,"=3";
 		chd_cfg =         <&channel_d>,"reg:0";
 		chd_gain =        <&channel_d>,"ti,gain:0";
 		chd_datarate =    <&channel_d>,"ti,datarate:0";
+		i2c0 = <&frag100>, "target:0=",<&i2c0>;
+		i2c_csi_dsi = <&frag100>, "target:0=",<&i2c_csi_dsi>,
+			      <0>,"+101+102";
+		i2c3 = <&frag100>, "target?=0",
+		       <&frag100>, "target-path=i2c3";
+		i2c4 = <&frag100>, "target?=0",
+		       <&frag100>, "target-path=i2c4";
+		i2c5 = <&frag100>, "target?=0",
+		       <&frag100>, "target-path=i2c5";
+		i2c6 = <&frag100>, "target?=0",
+		       <&frag100>, "target-path=i2c6";
 	};
 };
