From nobody Fri Dec 19 11:04:14 2025 Received: from mail-ed1-f41.google.com (mail-ed1-f41.google.com [209.85.208.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8FB40264FB5 for ; Tue, 4 Nov 2025 21:00:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762290034; cv=none; b=IziKN4tICCVhr4uj6sj0eL8YD/QJCiwzrtlhZx164DRym3wiynrJ5FyrPQl3VOo2YDJSXtRPvvm/juxzkreeJq8bYh/7gVhl+yNFkoveimuYAwaiTbtu40TOyOh6NPuQ3t6LQ8I5jctSqx5k/bUnMDV0ydo1TUsuaW25TZa/VsE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762290034; c=relaxed/simple; bh=HGBTfOQBPwpsmExRchxi1+yUGYBmqmX1znyWWlQLGsE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=ceF+DNv94b9Exj4aSZcXlzYMxATZcao6m1jrRyy7uClHJNeQymLngICqu487VKWV0ER1v7/lsWzbb2w5Rgzbv2LaG3IlfvlTy/9ahV+GoYG1lvpPXNtGmPRshWLemfiRjZRsJNoG0S/q9QFzQz62Q3/7oSf5UpEqztD6DcMs8mQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=eDkjBmC1; arc=none smtp.client-ip=209.85.208.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="eDkjBmC1" Received: by mail-ed1-f41.google.com with SMTP id 4fb4d7f45d1cf-640b0639dabso5379757a12.3 for ; Tue, 04 Nov 2025 13:00:32 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1762290031; x=1762894831; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=diMGLQMOH2QeJxZ+8+/p5Vax6ZB1kADxnRzyZWCkaKc=; b=eDkjBmC1l/l9p8/H504uum+4L2PO0JnfnBcaL935Q1yRHorjvKR02Oxzy3rSv9+zcy nXmXSp+Buynyv4/f/21X2/LzXJyOu45lLIlYRao4Dvu5SeAblMl2XSfAbVjgDjYTqhfn 2inNBcOzOemmP9wDTWKXH90TNJg9e0yjbg5Onz1QlMz2AhdmbEOmpKPE3N7mUtWNoL1K THkwAuDtxqlNP5bUM6EJN5KLTTNSzD0LQVQG7TsJucaGFR5Lm2Q2UimiRDkg3Fcp9Xez 3RhyNxmTzDtZ8d77kgoCMVg/5iD37A4TmapcY/yrn34ZBf0BnvIWhlLD3Mq+8YUo81gv 5s4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762290031; x=1762894831; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=diMGLQMOH2QeJxZ+8+/p5Vax6ZB1kADxnRzyZWCkaKc=; b=I5tShARtvxh8e3WX1nY0kPbZkgzZxDfn0/MTdyFh22Af6gNGa0Lha7eBPaHklyvUBY cLNfDiynXEYHiZ/IEiklVutfl/T73Wz0obg7KIc9OSn7l5klGu/wnlkftCgOEb85DZQ3 uXD5FzqIIc5jv88pY5PSmY1/HULAjrtg6050WItd3en08mjf0UIJQ5cxoIVpQ0Bywwea bm69GUzbAkWtJtxZwTuyVmqlVOe6V1CJ8vr1Zkn5ZJgeAtGifzJr2u2QvO2joVjEk39d Q2cOzg27sGgHDxwSlJqsFTK2nYom5CQpDa85OHGlk9UYnW2l/4uOWcn580l9f3wuGnXj i8fw== X-Forwarded-Encrypted: i=1; AJvYcCUgy8u/7GhbXlgdIrt5q7VupU1sq2JlCIKB53+0bZ9CEPBsliXG0UcBS0QcKEVQs3y7fNDbAMfBDB6LoSA=@vger.kernel.org X-Gm-Message-State: AOJu0YxnduZsTmfXY/TVExnntTYO8fAWMROHgtA4FxNx+se2aGZlsET+ LXybvF6S2EEl90g3vJ2fNN6gDzyrwRHJUUqfX3A+JHwU9W+07ImeFj9b X-Gm-Gg: ASbGncssD280Txp7Ly3Xx7UpvDvNZz3dxNp9RCyPfnlYDntULt7lJA1eudhXabtnXtE l23ONMabI2AZfAh7lshbCfv/mcs/Cw/d/yeao2rNGZAxLj/Lkl0HaRy6qKzBvI8betcynLH7OYM r2SH+jV2DIZjdISylJjJg0inKCQvi/benVp8bFT2+a+ktaGWgswYGgEaSsSTtHLK/ackbZd9AeC G2ZGPoTjIAV+QX0GNsK+ZYJk5uQiLJPttdYGoTTVLpM8+eNekjK8l2/rQKroPml465q/5CislUD Fdj5YWgfe7pEQG3M1YPfp9lbDVdMF6ixcm6L4zjb2NbYFdZAVlr7YN+bGx4joW5NiTCNgW0vulr 1Ck6Uhbk+78423D0Q5SBroNBc4lsinFYowuPLyWrmdmSi20DnCucC29wn1nN+KSD9KYJr/EiI4k X0XlU= X-Google-Smtp-Source: AGHT+IGe88tQlCXZ1detqx04tkzOyjNn+VPlSyky3nCcOGM0tLRYBgYcMOCqO7uFpOPlo7oKEg8VBg== X-Received: by 2002:a05:6402:274b:b0:640:efad:cdf4 with SMTP id 4fb4d7f45d1cf-6410588ddd5mr577387a12.6.1762290030506; Tue, 04 Nov 2025 13:00:30 -0800 (PST) Received: from builder.. ([2001:9e8:f13f:9116:be24:11ff:fe30:5d85]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-640e6a70b5bsm2990017a12.26.2025.11.04.13.00.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Nov 2025 13:00:30 -0800 (PST) From: Jonas Jelonek To: Linus Walleij , Bartosz Golaszewski , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Peter Rosin , Geert Uytterhoeven Cc: linux-gpio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Thomas Richard , Jonas Jelonek Subject: [PATCH v3 1/2] dt-bindings: gpio: add gpio-line-mux controller Date: Tue, 4 Nov 2025 21:00:20 +0000 Message-ID: <20251104210021.247476-2-jelonek.jonas@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251104210021.247476-1-jelonek.jonas@gmail.com> References: <20251104210021.247476-1-jelonek.jonas@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add dt-schema for a gpio-line-mux controller which exposes virtual GPIOs for a shared GPIO controlled by a multiplexer, e.g. a gpio-mux. The gpio-line-mux controller is a gpio-controller, thus has mostly the same semantics. However, it requires a mux-control to be specified upon which it will operate. Signed-off-by: Jonas Jelonek Reviewed-by: Krzysztof Kozlowski --- .../bindings/gpio/gpio-line-mux.yaml | 109 ++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 Documentation/devicetree/bindings/gpio/gpio-line-mux.ya= ml diff --git a/Documentation/devicetree/bindings/gpio/gpio-line-mux.yaml b/Do= cumentation/devicetree/bindings/gpio/gpio-line-mux.yaml new file mode 100644 index 000000000000..fb91500fa10f --- /dev/null +++ b/Documentation/devicetree/bindings/gpio/gpio-line-mux.yaml @@ -0,0 +1,109 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/gpio/gpio-line-mux.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: GPIO line mux + +maintainers: + - Jonas Jelonek + +description: | + A GPIO controller to provide virtual GPIOs for a 1-to-many input-only ma= pping + backed by a single shared GPIO and a multiplexer. A simple illustrated + example is + + +----- A + IN / + <-----o------- B + / |\ + | | +----- C + | | \ + | | +--- D + | | + M1 M0 + + MUX CONTROL + + M1 M0 IN + 0 0 A + 0 1 B + 1 0 C + 1 1 D + + This can be used in case a real GPIO is connected to multiple inputs and + controlled by a multiplexer, and another subsystem/driver does not work + directly with the multiplexer subsystem. + +properties: + compatible: + const: gpio-line-mux + + gpio-controller: true + + "#gpio-cells": + const: 2 + + gpio-line-mux-states: + description: Mux states corresponding to the virtual GPIOs. + $ref: /schemas/types.yaml#/definitions/uint32-array + + gpio-line-names: true + + mux-controls: + $ref: /schemas/types.yaml#/definitions/phandle-array + maxItems: 1 + description: + Phandle to the multiplexer to control access to the GPIOs. + + ngpios: false + + shared-gpios: + maxItems: 1 + description: + GPIO which is the '1' in 1-to-many and is shared by the virtual GPIOs + and controlled via the mux. + +required: + - compatible + - gpio-controller + - gpio-line-mux-states + - mux-controls + - shared-gpios + +additionalProperties: false + +examples: + - | + #include + #include + + sfp_gpio_mux: mux-controller-1 { + compatible =3D "gpio-mux"; + mux-gpios =3D <&gpio0 0 GPIO_ACTIVE_HIGH>, + <&gpio0 1 GPIO_ACTIVE_HIGH>; + #mux-control-cells =3D <0>; + idle-state =3D ; + }; + + sfp1_gpio: sfp-gpio-1 { + compatible =3D "gpio-line-mux"; + gpio-controller; + #gpio-cells =3D <2>; + + mux-controls =3D <&sfp_gpio_mux>; + shared-gpios =3D <&gpio0 2 GPIO_ACTIVE_HIGH>; + + gpio-line-names =3D "SFP1_LOS", "SFP1_MOD_ABS", "SFP1_TX_FAULT"; + gpio-line-mux-states =3D <0>, <1>, <3>; + }; + + sfp1: sfp-p1 { + compatible =3D "sff,sfp"; + + i2c-bus =3D <&sfp1_i2c>; + los-gpios =3D <&sfp1_gpio 0 GPIO_ACTIVE_HIGH>; + mod-def0-gpios =3D <&sfp1_gpio 1 GPIO_ACTIVE_LOW>; + tx-fault-gpios =3D <&sfp1_gpio 2 GPIO_ACTIVE_HIGH>; + }; --=20 2.48.1 From nobody Fri Dec 19 11:04:14 2025 Received: from mail-ed1-f51.google.com (mail-ed1-f51.google.com [209.85.208.51]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 6C95827E056 for ; Tue, 4 Nov 2025 21:00:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.51 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762290035; cv=none; b=DiGoWf86sh27vL2S86uou2MaWhYkyWgryUTMqMnciyQ7S61XfkClE+F0BuaJ7vjBohkUxNnHBGH9CwP9MwOOojFQiv1LPsyACrZ1/WWDTlNRN+R/fsvryEXnGYUq2TKj3gr6vcuagiOl68NfScYqP9ELli/1DAjQkgj9K3uc1B8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1762290035; c=relaxed/simple; bh=GskfKVaPLqQ/vCmRCVQyHxD0lSp9G/moBVGUDvRGe0k=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cOzzbSKem5p12vLZvLSCg1qhAv/krtuJVGU5bPpWlfj4jk1HkRoLKqvp7zOhT0wzS8ENx8eJtQ+teq9qh9JMnvB21uEcUqpD+YGB846myzQdcLu+TqTiM7/4pyc5Ja+rMJgGSbdfRpGKGxqajeX8YlKSMWxuf5ddqyMuxuWxnU8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Fo1mnkhe; arc=none smtp.client-ip=209.85.208.51 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Fo1mnkhe" Received: by mail-ed1-f51.google.com with SMTP id 4fb4d7f45d1cf-640c3940649so4008087a12.1 for ; Tue, 04 Nov 2025 13:00:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1762290031; x=1762894831; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=8Z3otzeim6Fx/klRMW+iz5WyDhYisYpULPID5Kk4CcY=; b=Fo1mnkheEz8F9UVbkH+mwlNwhw+UrWrUsRuUgMlgm6aMO2fQ1OGue1xuYTNSE6SgwG r7jonZ8+KwIcwgswSKC3/rmOmJ8GykunIB9T6FXDjpXqxSWaBIBDc+lDEMd7O5R/E6p7 rqsNQwi+GwAjLrgghV8e2tY+DmdhtLMk3Ypyztu1snHlaFcjUA6s6ll7KHmmDQKhlIBl TKASx90m9ZAXcgYDx5h/KS94+Y/sN56inTpJrYCjxe/A23fzJOQ/Yls71XHGKbwOtrS0 fiQHLDPOuHFPdGlchwhJonLzdpMZKHwAStvnLbpoLTO71AC3ZZQP1GEmmCAmHt3mvSL0 iwcQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1762290031; x=1762894831; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=8Z3otzeim6Fx/klRMW+iz5WyDhYisYpULPID5Kk4CcY=; b=g093/YAJQVJ1dp5KWImdnj3r2ZoA1+coDw6oB4nCfFdJM8JPlhwtN/giIsb6xO7RL2 CCs40upb5TTPfh3iGqM10x2Uk9URRYFAs8tlcfl2TW9NxR228GJPl+95KRjVh4tD+Oe5 MYx1xmyaRJJrT70BLltnDqDPedq6Qvp5OOQH2WJLP9mc33sBkIihUeYjD3ZKKDV+v+O+ m8bmHj0ZojMw+8NpgSisBdTJoysgAIGmIJ4WkMKTD08wqe7E+1KqzonT9BP4vFtPqzDf gjQuwAfDlElbwyhrAWqK2IIy62fEavQQkavSgPVaM5pMlPs0CtXQRP78AGoP7INqvT9E UfUw== X-Forwarded-Encrypted: i=1; AJvYcCWMK7EZ3B923r9Kv6cYfUQTG2XYBHRErxyUgoqhorFmJXRX6mv8xtTbS7MmpXfzcueXtj3Bex+FlpFsSVU=@vger.kernel.org X-Gm-Message-State: AOJu0YwPO2SZfGrggzs/ehLZBG5JitXQERZx2Kx76sLs/KIwZVmb+p1X XzJSLMAg11o2SkeC5vIZr76FvXAwYeeh5glmttutrlpI5qzhGLufeGuI X-Gm-Gg: ASbGncsXLw7e1aosPaQqS2d2uSLPh77OWsQlFOEqt6734I2OjdBG/4/cJpKup+wpdnI bp6876KT4FvDC+EZzVw4GRh1HFYGHTLe8SmW6seGRyVEsUUuvf9TBvC8QGIuH6GF1uJDVshqkCZ tljkJOZ3/jhNLoPF1EzdiJ6nTPus+EU7NjV2G5lESlKmy1GeRj+BC8lDOpcd208IhzcRGVD0QiV d6dyPKoPjCp/MeqJ13BDWpuXq1uOprc4D2YRhcDQ4n49shokoEi4eh8SZEPmX2kIML5wZBSubLg J3BW9yCMAS06iVnDq5PxWzPFu7CEtxQRJ2XEs3BUELVKn4ec4pfvXurob315KKHXCOlh2KM7sFG bb9q5EBvL0a/n6K61NOmLLX1VG8d60XIjKLQfqQF3RvU+vWPpiJh0K7Fz7CCt8CGmXdpu+3hk2G umjz61fErHdhL9Ng== X-Google-Smtp-Source: AGHT+IH5nziiExB9aZmDZ+ym3aHM5MBr8CbYq4Ikkfou+I40LHj7J5IwIjAsXB09UiDpcCtUSu4GiA== X-Received: by 2002:a05:6402:13cb:b0:640:9ce9:a8e6 with SMTP id 4fb4d7f45d1cf-641058a22c3mr527333a12.4.1762290031318; Tue, 04 Nov 2025 13:00:31 -0800 (PST) Received: from builder.. ([2001:9e8:f13f:9116:be24:11ff:fe30:5d85]) by smtp.gmail.com with ESMTPSA id 4fb4d7f45d1cf-640e6a70b5bsm2990017a12.26.2025.11.04.13.00.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Nov 2025 13:00:31 -0800 (PST) From: Jonas Jelonek To: Linus Walleij , Bartosz Golaszewski , Rob Herring , Krzysztof Kozlowski , Conor Dooley , Peter Rosin , Geert Uytterhoeven Cc: linux-gpio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, Thomas Richard , Jonas Jelonek Subject: [PATCH v3 2/2] gpio: add gpio-line-mux driver Date: Tue, 4 Nov 2025 21:00:21 +0000 Message-ID: <20251104210021.247476-3-jelonek.jonas@gmail.com> X-Mailer: git-send-email 2.48.1 In-Reply-To: <20251104210021.247476-1-jelonek.jonas@gmail.com> References: <20251104210021.247476-1-jelonek.jonas@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add a new driver which provides a 1-to-many mapping for a single real GPIO using a multiplexer. Each virtual GPIO corresponds to a multiplexer state which, if set for the multiplexer, connects the real GPIO to the corresponding virtual GPIO. This can help in various usecases. One practical case is the special hardware design of the Realtek-based XS1930-10 switch from Zyxel. It features two SFP+ ports/cages whose signals are wired to directly to the switch SoC. Although Realtek SoCs are short on GPIOs, there are usually enough the fit the SFP signals without any hacks. However, Zyxel did some weird design and connected RX_LOS, MOD_ABS and TX_FAULT of one SFP cage onto a single GPIO line controlled by a multiplexer (the same for the other SFP cage). The single multiplexer controls the lines for both SFP and depending on the state, the designated 'signal GPIO lines' are connected to one of the three SFP signals. Because the SFP core/driver doesn't support multiplexer but needs single GPIOs for each of the signals, this driver fills the gap between both. It registers a gpio_chip, provides multiple virtual GPIOs and sets the backing multiplexer accordingly. Due to several practical issues, this is input-only and doesn't support IRQs. Signed-off-by: Jonas Jelonek --- MAINTAINERS | 6 ++ drivers/gpio/Kconfig | 9 +++ drivers/gpio/Makefile | 1 + drivers/gpio/gpio-line-mux.c | 137 +++++++++++++++++++++++++++++++++++ 4 files changed, 153 insertions(+) create mode 100644 drivers/gpio/gpio-line-mux.c diff --git a/MAINTAINERS b/MAINTAINERS index 3da2c26a796b..66f8706d9b4b 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -10653,6 +10653,12 @@ S: Maintained F: Documentation/devicetree/bindings/leds/irled/gpio-ir-tx.yaml F: drivers/media/rc/gpio-ir-tx.c =20 +GPIO LINE MUX +M: Jonas Jelonek +S: Maintained +F: Documentation/devicetree/bindings/gpio/gpio-line-mux.yaml +F: drivers/gpio/gpio-line-mux.c + GPIO MOCKUP DRIVER M: Bamvor Jian Zhang L: linux-gpio@vger.kernel.org diff --git a/drivers/gpio/Kconfig b/drivers/gpio/Kconfig index ce237398fa00..5f8082ae99cc 100644 --- a/drivers/gpio/Kconfig +++ b/drivers/gpio/Kconfig @@ -1986,6 +1986,15 @@ config GPIO_LATCH Say yes here to enable a driver for GPIO multiplexers based on latches connected to other GPIOs. =20 +config GPIO_LINE_MUX + tristate "GPIO line mux driver" + depends on OF_GPIO + select MULTIPLEXER + help + Say Y here to support the GPIO line mux, which can provide virtual + GPIOs backed by a shared real GPIO and a multiplexer in a 1-to-many + fashion. + config GPIO_MOCKUP tristate "GPIO Testing Driver (DEPRECATED)" select IRQ_SIM diff --git a/drivers/gpio/Makefile b/drivers/gpio/Makefile index ee260a0809d3..6caee52b0356 100644 --- a/drivers/gpio/Makefile +++ b/drivers/gpio/Makefile @@ -89,6 +89,7 @@ obj-$(CONFIG_GPIO_IXP4XX) +=3D gpio-ixp4xx.o obj-$(CONFIG_GPIO_JANZ_TTL) +=3D gpio-janz-ttl.o obj-$(CONFIG_GPIO_KEMPLD) +=3D gpio-kempld.o obj-$(CONFIG_GPIO_LATCH) +=3D gpio-latch.o +obj-$(CONFIG_GPIO_LINE_MUX) +=3D gpio-line-mux.o obj-$(CONFIG_GPIO_LJCA) +=3D gpio-ljca.o obj-$(CONFIG_GPIO_LOGICVC) +=3D gpio-logicvc.o obj-$(CONFIG_GPIO_LOONGSON1) +=3D gpio-loongson1.o diff --git a/drivers/gpio/gpio-line-mux.c b/drivers/gpio/gpio-line-mux.c new file mode 100644 index 000000000000..3a9fe899c041 --- /dev/null +++ b/drivers/gpio/gpio-line-mux.c @@ -0,0 +1,137 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * GPIO line mux which acts as virtual gpiochip and provides a 1-to-many + * mapping between virtual GPIOs and a real GPIO + multiplexer. + * + * Copyright (c) 2025 Jonas Jelonek + */ + +#include +#include +#include +#include +#include +#include +#include + +#define MUX_SELECT_DELAY_US 100 + +struct gpio_lmux { + struct gpio_chip gc; + struct mux_control *mux; + struct mutex lock; + + struct gpio_desc *shared_gpio; + /* dynamically sized, must be last */ + unsigned int gpio_mux_states[]; +}; + +DEFINE_GUARD(gpio_lmux, struct gpio_lmux *, mutex_lock(&_T->lock), mutex_u= nlock(&_T->lock)) + +static int gpio_lmux_gpio_get(struct gpio_chip *gc, unsigned int offset) +{ + struct gpio_lmux *glm =3D (struct gpio_lmux *)gpiochip_get_data(gc); + int ret; + + if (offset > gc->ngpio) + return -EINVAL; + + guard(gpio_lmux)(glm); + + ret =3D mux_control_select_delay(glm->mux, glm->gpio_mux_states[offset], + MUX_SELECT_DELAY_US); + if (ret < 0) + return ret; + + ret =3D gpiod_get_raw_value_cansleep(glm->shared_gpio); + mux_control_deselect(glm->mux); + return ret; +} + +static int gpio_lmux_gpio_set(struct gpio_chip *gc, unsigned int offset, + int value) +{ + return -EOPNOTSUPP; +} + +static int gpio_lmux_gpio_get_direction(struct gpio_chip *gc, + unsigned int offset) +{ + return GPIO_LINE_DIRECTION_IN; +} + +static int gpio_lmux_probe(struct platform_device *pdev) +{ + struct device *dev =3D &pdev->dev; + struct gpio_lmux *glm; + unsigned int ngpio; + size_t size; + int ret; + + ngpio =3D device_property_count_u32(dev, "gpio-line-mux-states"); + if (!ngpio) + return -EINVAL; + + size =3D struct_size(glm, gpio_mux_states, ngpio); + glm =3D devm_kzalloc(dev, size, GFP_KERNEL); + if (!glm) + return -ENOMEM; + + mutex_init(&glm->lock); + + glm->gc.base =3D -1; + glm->gc.can_sleep =3D true; + glm->gc.fwnode =3D dev_fwnode(dev); + glm->gc.label =3D dev_name(dev); + glm->gc.ngpio =3D ngpio; + glm->gc.owner =3D THIS_MODULE; + glm->gc.parent =3D dev; + + glm->gc.get =3D gpio_lmux_gpio_get; + glm->gc.set =3D gpio_lmux_gpio_set; + glm->gc.get_direction =3D gpio_lmux_gpio_get_direction; + + glm->mux =3D devm_mux_control_get(dev, NULL); + if (IS_ERR(glm->mux)) + return dev_err_probe(dev, PTR_ERR(glm->mux), + "could not get mux controller\n"); + + glm->shared_gpio =3D devm_gpiod_get(dev, "shared", GPIOD_ASIS); + if (IS_ERR(glm->shared_gpio)) + return dev_err_probe(dev, PTR_ERR(glm->shared_gpio), + "could not get shared-gpio\n"); + + ret =3D gpiod_direction_input(glm->shared_gpio); + if (ret) + return dev_err_probe(dev, ret, "could not set shared gpio as input\n"); + + ret =3D device_property_read_u32_array(dev, "gpio-line-mux-states", + &glm->gpio_mux_states[0], ngpio); + if (ret) + return dev_err_probe(dev, ret, "could not get mux states\n"); + + ret =3D devm_gpiochip_add_data(dev, &glm->gc, glm); + if (ret) + return dev_err_probe(dev, ret, "failed to add gpiochip\n"); + + return 0; +} + +static const struct of_device_id gpio_lmux_of_match[] =3D { + { .compatible =3D "gpio-line-mux" }, + { } +}; +MODULE_DEVICE_TABLE(of, gpio_lmux_of_match); + +static struct platform_driver gpio_lmux_driver =3D { + .driver =3D { + .name =3D "gpio-line-mux", + .of_match_table =3D gpio_lmux_of_match, + }, + .probe =3D gpio_lmux_probe, +}; +module_platform_driver(gpio_lmux_driver); + +MODULE_AUTHOR("Jonas Jelonek "); +MODULE_DESCRIPTION("GPIO line mux driver"); +MODULE_LICENSE("GPL"); --=20 2.48.1