From patchwork Tue Sep 17 23:29:30 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Packham X-Patchwork-Id: 829295 Received: from gate2.alliedtelesis.co.nz (gate2.alliedtelesis.co.nz [202.36.163.20]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 02ED3174EFA for ; Tue, 17 Sep 2024 23:29:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.36.163.20 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726615788; cv=none; b=Je1PufrkDX5ZXCNy3iPfzaRY+oso0MeszCUk+uic5/R+9zpwuh30UHpzggTLcfNddO5HiRiPXq2yItJdSRZREhgfydT/5vBr7OsAqO2MlRIOxLMbCv3FNqbJQ1yjEW+dCToz0BmUc4QGDLJ95Pn7PvHhIGwVVzS9dt7d7R2feB8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726615788; c=relaxed/simple; bh=ggT/JygajZbkwXDzCkcyJgBfpPq7WGDRNRsRLHaXit4=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=sf6Mu9NKKk6nsj78Ut8KUIZcOitBQXhGj73S77o5Z1SBrCKL19PcspO1bXBxSkTmZi1/3kQPtlskII2q6KdLY35Wp5aCHesbjzWthk2vLCiKN+zfNnYopxiwOF+uAbB0eh/a1lAw3BG/E4CamgJr1y6XR2D+IWzjZn/pdFU9IQo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=alliedtelesis.co.nz; spf=pass smtp.mailfrom=alliedtelesis.co.nz; dkim=pass (2048-bit key) header.d=alliedtelesis.co.nz header.i=@alliedtelesis.co.nz header.b=tLseoCoY; arc=none smtp.client-ip=202.36.163.20 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=alliedtelesis.co.nz Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=alliedtelesis.co.nz Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=alliedtelesis.co.nz header.i=@alliedtelesis.co.nz header.b="tLseoCoY" Received: from svr-chch-seg1.atlnz.lc (mmarshal3.atlnz.lc [10.32.18.43]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by gate2.alliedtelesis.co.nz (Postfix) with ESMTPS id 3DE9F2C0540; Wed, 18 Sep 2024 11:29:37 +1200 (NZST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alliedtelesis.co.nz; s=mail181024; t=1726615777; bh=vi8pzi938Vj1EV8QrWqlaOuET/C1cPMvb/I5VHhl44c=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=tLseoCoYgQ60Jy8KnpM/1FCIgTTk9K7rBMGQLh8vUZYwZ4AdKElU4L/Zk0oLkTEcH omiDOVcExE8zcDEI9VhNsAnIQRc6jbl2l2O4kOqJs8m/8gUeB45bZ+s933kwsx056X mC/1mYilwYig74+gdVdBw0AfH5cq/p8LsbFqKcXZQPL7fpQpjorf/9f62S3q+kUyh/ T4PqENAHc41CwPnRnXeuVSSoABP1HlelKNbGQkM1pQv9JZQEH42OIqLOP/3TysxUfm GC3Swe/XIJsLixkBC17b+JjKYq/oR9MxCA6fMpf+pfQ0vaYGMtIIBhyFvbhtCYPe81 rokTLhqgP/55A== Received: from pat.atlnz.lc (Not Verified[10.32.16.33]) by svr-chch-seg1.atlnz.lc with Trustwave SEG (v8,2,6,11305) id ; Wed, 18 Sep 2024 11:29:36 +1200 Received: from chrisp-dl.ws.atlnz.lc (chrisp-dl.ws.atlnz.lc [10.33.22.30]) by pat.atlnz.lc (Postfix) with ESMTP id 82FB313EE85; Wed, 18 Sep 2024 11:29:36 +1200 (NZST) Received: by chrisp-dl.ws.atlnz.lc (Postfix, from userid 1030) id 7FD37280347; Wed, 18 Sep 2024 11:29:36 +1200 (NZST) From: Chris Packham To: andi.shyti@kernel.org, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, tsbogend@alpha.franken.de Cc: linux-i2c@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, Chris Packham Subject: [PATCH 3/5] mips: dts: realtek: Add I2C controllers Date: Wed, 18 Sep 2024 11:29:30 +1200 Message-ID: <20240917232932.3641992-4-chris.packham@alliedtelesis.co.nz> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20240917232932.3641992-1-chris.packham@alliedtelesis.co.nz> References: <20240917232932.3641992-1-chris.packham@alliedtelesis.co.nz> Precedence: bulk X-Mailing-List: linux-i2c@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SEG-SpamProfiler-Analysis: v=2.4 cv=Id0kWnqa c=1 sm=1 tr=0 ts=66ea10e0 a=KLBiSEs5mFS1a/PbTCJxuA==:117 a=EaEq8P2WXUwA:10 a=fhtXptwnTS7QFdIPH-sA:9 a=3ZKOabzyN94A:10 X-SEG-SpamProfiler-Score: 0 x-atlnz-ls: pat Add the I2C controllers that are part of the RTL9300 SoC. Signed-off-by: Chris Packham --- arch/mips/boot/dts/realtek/rtl930x.dtsi | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/arch/mips/boot/dts/realtek/rtl930x.dtsi b/arch/mips/boot/dts/realtek/rtl930x.dtsi index cf1b38b6c353..c579665df700 100644 --- a/arch/mips/boot/dts/realtek/rtl930x.dtsi +++ b/arch/mips/boot/dts/realtek/rtl930x.dtsi @@ -39,6 +39,24 @@ reboot { offset = <0x0c>; value = <0x01>; }; + + i2c0: i2c@36c { + compatible = "realtek,rtl9300-i2c"; + realtek,control-offset = <0x36c>; + realtek,global-control-offset = <0x384>; + status = "disabled"; + #address-cells = <1>; + #size-cells = <0>; + }; + + i2c1: i2c@388 { + compatible = "realtek,rtl9300-i2c"; + realtek,control-offset = <0x388>; + realtek,global-control-offset = <0x384>; + status = "disabled"; + #address-cells = <1>; + #size-cells = <0>; + }; }; }; From patchwork Tue Sep 17 23:29:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Packham X-Patchwork-Id: 829296 Received: from gate2.alliedtelesis.co.nz (gate2.alliedtelesis.co.nz [202.36.163.20]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 10D3B1925A3 for ; Tue, 17 Sep 2024 23:29:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.36.163.20 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726615787; cv=none; b=MaY824K8WxWHQwcq5CJmiR5lFAqBwfx3LBepLqMXR7CRkpknJgzzhPPWCZ7apFnejjgnEjb6Dlk+kJWYJ3VvOjonVJxHpZXWIKvOYq8DdeKUyveoZwqmfpbSBDnswhAi4PlFhpnDld1J6LVT8rvrG2A2/DT7J+AZmEFdFVaysUI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726615787; c=relaxed/simple; bh=4XKWbHDH3k5IZJIEee2ZDxN3yH0PLm7mX4JK9TUlNuk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ulzPYA3Ga09kgYBbshT9sPyLavRTbfdAMy17v/HlIlY3n0SvimmINnLWA36s0+zLUWldt54gZ9055bm8xngVyunCKE6k0WJjdVSA+w7xO7+4M5dHFpVHlnPKzkkg7Owc9UkFXfrnATq2yXdTa6SL584QLZbfL6SX8XNaLzR0XZc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=alliedtelesis.co.nz; spf=pass smtp.mailfrom=alliedtelesis.co.nz; dkim=pass (2048-bit key) header.d=alliedtelesis.co.nz header.i=@alliedtelesis.co.nz header.b=cvef+SEg; arc=none smtp.client-ip=202.36.163.20 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=alliedtelesis.co.nz Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=alliedtelesis.co.nz Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=alliedtelesis.co.nz header.i=@alliedtelesis.co.nz header.b="cvef+SEg" Received: from svr-chch-seg1.atlnz.lc (mmarshal3.atlnz.lc [10.32.18.43]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by gate2.alliedtelesis.co.nz (Postfix) with ESMTPS id 3F1C62C062F; Wed, 18 Sep 2024 11:29:37 +1200 (NZST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alliedtelesis.co.nz; s=mail181024; t=1726615777; bh=Es0GKGajP1taBUIavduYfU2QHg3cC2kreSbopHTF+4o=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cvef+SEgMoyot37PMHr5cFPQaUjNYKb8v1gut1BR8Lwzcdim7IFAMCiw8Kg69edFX V2rh09K4HJMOr2X4EEYdeB5mjWlCV4aTvowRDfD7DLGZOcHOv1hMJwwuafE+zL1kkn wMHyQnSZhBise6oPG+LK9dLgkAFgaFy0vHX0SuCEWAy+WMh8Wh8H965YpNa/7kX4pK pUIqnbBC5DMYU7E6wMxMlxUJtjpEpAltnhjxXBeA8Q8ES32QFihpYmqrgCFROTAEGF QOFD2sSR8BRM0sl7U/gh6GdbXgS3hD/umkhMm4WpMIfFuyf67wM7kU8LBxrFlyBJ9X QdZJIooD0GNmA== Received: from pat.atlnz.lc (Not Verified[10.32.16.33]) by svr-chch-seg1.atlnz.lc with Trustwave SEG (v8,2,6,11305) id ; Wed, 18 Sep 2024 11:29:36 +1200 Received: from chrisp-dl.ws.atlnz.lc (chrisp-dl.ws.atlnz.lc [10.33.22.30]) by pat.atlnz.lc (Postfix) with ESMTP id 86F4513ED56; Wed, 18 Sep 2024 11:29:36 +1200 (NZST) Received: by chrisp-dl.ws.atlnz.lc (Postfix, from userid 1030) id 840AF280347; Wed, 18 Sep 2024 11:29:36 +1200 (NZST) From: Chris Packham To: andi.shyti@kernel.org, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, tsbogend@alpha.franken.de Cc: linux-i2c@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, Chris Packham Subject: [PATCH 4/5] dt-bindings: i2c: Add RTL9300 I2C multiplexer Date: Wed, 18 Sep 2024 11:29:31 +1200 Message-ID: <20240917232932.3641992-5-chris.packham@alliedtelesis.co.nz> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20240917232932.3641992-1-chris.packham@alliedtelesis.co.nz> References: <20240917232932.3641992-1-chris.packham@alliedtelesis.co.nz> Precedence: bulk X-Mailing-List: linux-i2c@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SEG-SpamProfiler-Analysis: v=2.4 cv=Id0kWnqa c=1 sm=1 tr=0 ts=66ea10e0 a=KLBiSEs5mFS1a/PbTCJxuA==:117 a=EaEq8P2WXUwA:10 a=gEfo2CItAAAA:8 a=VwQbUJbxAAAA:8 a=8lrFv0nGYZjcjRuYp20A:9 a=3ZKOabzyN94A:10 a=sptkURWiP4Gy88Gu7hUp:22 X-SEG-SpamProfiler-Score: 0 x-atlnz-ls: pat An extension of the RTL9300 SoC is to support multiplexing by selecting the SDA pins that are being used dynamically. Add a binding that allows us to describe hardware that makes use of this. Signed-off-by: Chris Packham --- .../bindings/i2c/realtek,rtl9300-i2c-mux.yaml | 82 +++++++++++++++++++ MAINTAINERS | 1 + 2 files changed, 83 insertions(+) create mode 100644 Documentation/devicetree/bindings/i2c/realtek,rtl9300-i2c-mux.yaml diff --git a/Documentation/devicetree/bindings/i2c/realtek,rtl9300-i2c-mux.yaml b/Documentation/devicetree/bindings/i2c/realtek,rtl9300-i2c-mux.yaml new file mode 100644 index 000000000000..a64879d0fda7 --- /dev/null +++ b/Documentation/devicetree/bindings/i2c/realtek,rtl9300-i2c-mux.yaml @@ -0,0 +1,82 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/i2c/realtek,rtl9300-i2c-mux.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Realtek RTL I2C Multiplexer + +maintainers: + - Chris Packham + +description: | + The I2C controllers on the RTL9300 support a level of multiplexing. In the + simple case the rtl9300-i2c binding can provide a single SDA pin per + controller. This binding allows a more than one SDA line to be used per + controller providing a level of multiplexing. + +properties: + compatible: + const: realtek,rtl9300-i2c-mux + + i2c-parent: + description: phandle of the I2C bus controller that this multiplexer + operates on. + $ref: /schemas/types.yaml#/definitions/phandle + +allOf: + - $ref: i2c-mux.yaml + +unevaluatedProperties: false + +required: + - compatible + - i2c-parent + +examples: + - | + switch@1b000000 { + compatible = "realtek,rtl9302c-switch", "syscon", "simple-mfd"; + reg = <0x1b000000 0x10000>; + + i2c0: i2c@36c { + compatible = "realtek,rtl9300-i2c"; + realtek,control-offset = <0x36c>; + realtek,global-control-offset = <0x384>; + #address-cells = <1>; + #size-cells = <0>; + }; + }; + + base { + i2c-mux { + compatible = "realtek,rtl9300-i2c-mux"; + #address-cells = <1>; + #size-cells = <0>; + i2c-parent = <&i2c0>; + + i2c@0 { + reg = <0>; + #address-cells = <1>; + #size-cells = <0>; + gpio@20 { + compatible = "nxp,pca9555"; + gpio-controller; + #gpio-cells = <2>; + reg = <0x20>; + }; + }; + + i2c@2 { + reg = <2>; + #address-cells = <1>; + #size-cells = <0>; + gpio@20 { + compatible = "nxp,pca9555"; + gpio-controller; + #gpio-cells = <2>; + reg = <0x20>; + }; + }; + }; + }; diff --git a/MAINTAINERS b/MAINTAINERS index 9e123e9839a5..178ac8a7e843 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -19891,6 +19891,7 @@ RTL9300 I2C DRIVER (rtl9300-i2c) M: Chris Packham L: linux-i2c@vger.kernel.org S: Maintained +F: Documentation/devicetree/bindings/i2c/realtek,rtl9300-i2c-mux.yaml F: Documentation/devicetree/bindings/i2c/realtek,rtl9300-i2c.yaml F: drivers/i2c/busses/i2c-rtl9300.c From patchwork Tue Sep 17 23:29:32 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Packham X-Patchwork-Id: 829294 Received: from gate2.alliedtelesis.co.nz (gate2.alliedtelesis.co.nz [202.36.163.20]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 00DC8191F95 for ; Tue, 17 Sep 2024 23:29:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=202.36.163.20 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726615790; cv=none; b=NkZpbvIRQvce2jkdF6rakX5e0Y69LC1MVDLMz3rbIggHeaNdsgmwUv6SZhMBOxkyMwEipNCOE62FKGIsRFI4K8svjov52GhbLO5W3TwNUo6TVJqPTGOPr3ZJ3OR6Nl2iGKYHaetdF3/CjqsJUfqC1p3YzPl1I6uGn0pe0ZSC4YA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726615790; c=relaxed/simple; bh=R8vgpwFocTgr2VLRkYvO2Feee8qPVPsrOMT6Jy/NsVU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NjBq2hyfDTtQpd4pzsg3z4E4E2+BOCY833w1NUy+LeqICxVefLRPUB0xPKv2hss/gn3THYE+ia079xJhbKKIlTu7KzPAwS0qvOhuuWXe71oACftKqyllmOI6KN/slsb0CuuxwSQd1RDdBG08AapNH4EGGn539y2TbyArqjUFla0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=alliedtelesis.co.nz; spf=pass smtp.mailfrom=alliedtelesis.co.nz; dkim=pass (2048-bit key) header.d=alliedtelesis.co.nz header.i=@alliedtelesis.co.nz header.b=nEgGxKan; arc=none smtp.client-ip=202.36.163.20 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=alliedtelesis.co.nz Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=alliedtelesis.co.nz Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=alliedtelesis.co.nz header.i=@alliedtelesis.co.nz header.b="nEgGxKan" Received: from svr-chch-seg1.atlnz.lc (mmarshal3.atlnz.lc [10.32.18.43]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by gate2.alliedtelesis.co.nz (Postfix) with ESMTPS id 606AA2C0654; Wed, 18 Sep 2024 11:29:37 +1200 (NZST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alliedtelesis.co.nz; s=mail181024; t=1726615777; bh=hciNQ7JyuCrV8+IFGAGI+LOFvSKN/EA4AgHDtQZ7WFQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=nEgGxKanHgWXfz0jDzo+IC6/A7RGtMKLRrONGyQRt2vT/Juiin4NJU46Dnq24YWnu w3Hpr8Fyu/7eX+CYLCAmtBYSE21sRHzvfRUR0BOY2TWrZ3u2DXdzqQPGe0kN9z1es5 fAxSd9rO2bPU5rAUu2MVMHMsojVr0cKL+KpAbl7F3U5EWCn7l6wLULWBYsW3cw8pOz BCxZXLrVBCtRmiLSQwTMAeWkVLMpG+nKzeXbBz5U6DV2zuPriRX1MZzWXJ3rBsSImA 9hcsCWVtUM1gK+/oChZxghEss8e3k5HpGyjPFH6WEN05yJ/6cDPOJwNlwlDli151d8 WhjEdQohCty5w== Received: from pat.atlnz.lc (Not Verified[10.32.16.33]) by svr-chch-seg1.atlnz.lc with Trustwave SEG (v8,2,6,11305) id ; Wed, 18 Sep 2024 11:29:36 +1200 Received: from chrisp-dl.ws.atlnz.lc (chrisp-dl.ws.atlnz.lc [10.33.22.30]) by pat.atlnz.lc (Postfix) with ESMTP id 8B18613EE87; Wed, 18 Sep 2024 11:29:36 +1200 (NZST) Received: by chrisp-dl.ws.atlnz.lc (Postfix, from userid 1030) id 88203280347; Wed, 18 Sep 2024 11:29:36 +1200 (NZST) From: Chris Packham To: andi.shyti@kernel.org, robh@kernel.org, krzk+dt@kernel.org, conor+dt@kernel.org, tsbogend@alpha.franken.de Cc: linux-i2c@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, Chris Packham Subject: [PATCH 5/5] i2c: rtl9300: Add multiplexing support Date: Wed, 18 Sep 2024 11:29:32 +1200 Message-ID: <20240917232932.3641992-6-chris.packham@alliedtelesis.co.nz> X-Mailer: git-send-email 2.46.1 In-Reply-To: <20240917232932.3641992-1-chris.packham@alliedtelesis.co.nz> References: <20240917232932.3641992-1-chris.packham@alliedtelesis.co.nz> Precedence: bulk X-Mailing-List: linux-i2c@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SEG-SpamProfiler-Analysis: v=2.4 cv=Id0kWnqa c=1 sm=1 tr=0 ts=66ea10e0 a=KLBiSEs5mFS1a/PbTCJxuA==:117 a=EaEq8P2WXUwA:10 a=v7xNKfeFtFACfAgD-bQA:9 a=3ZKOabzyN94A:10 X-SEG-SpamProfiler-Score: 0 x-atlnz-ls: pat The RTL9300 I2C controller can support multiplexing by choosing the SDA pin to be used dynamically. Add mutliplexing support to the rtl9300 driver. Signed-off-by: Chris Packham --- drivers/i2c/busses/i2c-rtl9300.c | 168 ++++++++++++++++++++++++++++++- 1 file changed, 167 insertions(+), 1 deletion(-) diff --git a/drivers/i2c/busses/i2c-rtl9300.c b/drivers/i2c/busses/i2c-rtl9300.c index f16e9b6343bf..a934a2526c92 100644 --- a/drivers/i2c/busses/i2c-rtl9300.c +++ b/drivers/i2c/busses/i2c-rtl9300.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-only #include +#include #include #include #include @@ -44,6 +45,14 @@ struct rtl9300_i2c { #define RTL9300_I2C_STD_FREQ 0 #define RTL9300_I2C_FAST_FREQ 1 +struct rtl9300_i2c_chan { + int parent; + const unsigned int *chans; + int n_chan; +}; + +#define RTL9300_I2C_MUX_NCHAN 8 + DEFINE_MUTEX(i2c_lock); static int rtl9300_i2c_reg_addr_set(struct rtl9300_i2c *i2c, u32 reg, u16 len) @@ -370,7 +379,164 @@ static struct platform_driver rtl9300_i2c_driver = { }, }; -module_platform_driver(rtl9300_i2c_driver); +static int rtl9300_i2c_select_chan(struct i2c_mux_core *muxc, u32 chan) +{ + struct i2c_adapter *adap = muxc->parent; + struct rtl9300_i2c *i2c = i2c_get_adapdata(adap); + int ret; + + ret = rtl9300_i2c_config_io(i2c, chan); + if (ret) + return ret; + + return 0; +} + +static int rtl9300_i2c_deselect_mux(struct i2c_mux_core *muxc, u32 chan) +{ + struct i2c_adapter *adap = muxc->parent; + struct rtl9300_i2c *i2c = i2c_get_adapdata(adap); + int ret; + + ret = rtl9300_i2c_config_io(i2c, i2c->sda_pin); + if (ret) + return ret; + + return 0; +} + +static int rtl9300_i2c_mux_probe_fw(struct rtl9300_i2c_chan *mux, struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct fwnode_handle *fwnode = dev_fwnode(dev); + struct device_node *np = dev->of_node; + struct device_node *adap_np; + struct i2c_adapter *adap = NULL; + struct fwnode_handle *child; + unsigned int *chans; + int i = 0; + + if (!is_of_node(fwnode)) + return -EOPNOTSUPP; + + if (!np) + return -ENODEV; + + adap_np = of_parse_phandle(np, "i2c-parent", 0); + if (!adap_np) { + dev_err(&pdev->dev, "Cannot parse i2c-parent\n"); + return -ENODEV; + } + adap = of_find_i2c_adapter_by_node(adap_np); + of_node_put(adap_np); + + if (!adap) + return -EPROBE_DEFER; + + mux->parent = i2c_adapter_id(adap); + put_device(&adap->dev); + + mux->n_chan = device_get_child_node_count(dev); + if (mux->n_chan >= RTL9300_I2C_MUX_NCHAN) + return -EINVAL; + + chans = devm_kcalloc(dev, mux->n_chan, sizeof(*mux->chans), GFP_KERNEL); + if (!chans) + return -ENOMEM; + + device_for_each_child_node(dev, child) { + fwnode_property_read_u32(child, "reg", chans + i); + i++; + } + mux->chans = chans; + + return 0; +} + +static int rtl9300_i2c_mux_probe(struct platform_device *pdev) +{ + struct i2c_mux_core *muxc; + struct i2c_adapter *adap; + struct rtl9300_i2c_chan *mux; + int ret, i; + + mux = devm_kzalloc(&pdev->dev, sizeof(*mux), GFP_KERNEL); + if (!mux) + return -ENOMEM; + + ret = rtl9300_i2c_mux_probe_fw(mux, pdev); + if (ret) + return ret; + + adap = i2c_get_adapter(mux->parent); + if (!adap) + return -EPROBE_DEFER; + + muxc = i2c_mux_alloc(adap, &pdev->dev, mux->n_chan, 0, 0, + rtl9300_i2c_select_chan, rtl9300_i2c_deselect_mux); + if (!muxc) { + ret = -ENOMEM; + goto err_alloc; + } + muxc->priv = mux; + + platform_set_drvdata(pdev, muxc); + + for (i = 0; i < mux->n_chan; i++) { + ret = i2c_mux_add_adapter(muxc, 0, mux->chans[i]); + if (ret) + goto err_del_adapters; + } + + return 0; + +err_del_adapters: + i2c_mux_del_adapters(muxc); +err_alloc: + i2c_put_adapter(adap); + + return ret; +} + +static void rtl9300_i2c_mux_remove(struct platform_device *pdev) +{ + struct i2c_mux_core *muxc = platform_get_drvdata(pdev); + + i2c_mux_del_adapters(muxc); + i2c_put_adapter(muxc->parent); +} + +static const struct of_device_id i2c_rtl9300_mux_dt_ids[] = { + { .compatible = "realtek,rtl9300-i2c-mux" }, + {} +}; +MODULE_DEVICE_TABLE(of, i2c_rtl9300_mux_dt_ids); + +static struct platform_driver rtl9300_i2c_mux_driver = { + .probe = rtl9300_i2c_mux_probe, + .remove = rtl9300_i2c_mux_remove, + .driver = { + .name = "i2c-mux-rtl9300", + .of_match_table = i2c_rtl9300_mux_dt_ids, + }, +}; + +static struct platform_driver * const drivers[] = { + &rtl9300_i2c_driver, + &rtl9300_i2c_mux_driver, +}; + +static int __init rtl9300_i2c_init(void) +{ + return platform_register_drivers(drivers, ARRAY_SIZE(drivers)); +} +module_init(rtl9300_i2c_init); + +static void __exit rtl9300_i2c_exit(void) +{ + platform_unregister_drivers(drivers, ARRAY_SIZE(drivers)); +} +module_exit(rtl9300_i2c_exit); MODULE_DESCRIPTION("RTL9300 I2C controller driver"); MODULE_LICENSE("GPL");