From patchwork Mon Jan 8 04:19:13 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Packham X-Patchwork-Id: 185809 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:37c1:b0:101:2151:f287 with SMTP id y1csp824018dyq; Sun, 7 Jan 2024 20:19:41 -0800 (PST) X-Google-Smtp-Source: AGHT+IE6wiJHNuyXjxRpaM5vnplzsSK1KTQX8dh6sDR2JPVvYw9dWesgOcCkwss9vC81ulQIp1NZ X-Received: by 2002:ad4:5ccd:0:b0:681:11e:1258 with SMTP id iu13-20020ad45ccd000000b00681011e1258mr2580097qvb.120.1704687580796; Sun, 07 Jan 2024 20:19:40 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704687580; cv=none; d=google.com; s=arc-20160816; b=j1/L3NX/exQagyZdQ4tt8aoWwvQFXLSlScbXuhtZvMXnNeA3EBnOwAfQXU5nKTWCBX l2b0w381/lwHuZAPx4hu6A/aaTPuZu1feES4OPRi/b9a/yv83fItnZex4Kperc/3ihp1 DE0KZDuzkPW3exziHl9+xcswfHRHkslgh7AzOBScx32xTLC1cAAwoa2CYpCY3SUy/2nl VQXDflVBt5LfvJVgt6aULmRkB59FUqlC3uFZ6pzwzV7Ca40g75uz7XkVy/yFVbVNzHJq EowAW//xoRYfsU+nU6qbMABqED5G2mcInMlf7rfHSUvFsFnRAyXz5YSjSCBqQROM/q6M c/uw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=6Do2x9DDn0JcnO2x8tiIauxm3a6XuafqPzj8c5YiWQg=; fh=uYrK66oSOqKr9pqHb+5e0YvghZ4BvtIhcX8ggIznIPs=; b=GY2pzKg7/9Vh4QTDlljEsJB9Qdl9Qp3rjxm4iLvu4eFdI+8hJ467b403/UaiY1H3xz vAdAxKSbIV+D6vDf7Aobcpj58mCyzdiyeYS+2SJJkktyzVSWDMMrIxN+9fEnIjsRAXQG Gxfbb7PP0G//Vbv+hk4v8SyhFCp6W5BJ5o7hrrQoBARbiMp2zxewRHZEZXSO5R6n95LW ApV0QFflIi049UxNFlRX1yR5fvpDMJxFDojogP+NlKDoaF8bNXc/+c2J5kPBizj+SQ+5 PXqNy6VQBB1SHTGz13fmLSBY+RnATossEPu9L3Td1790UkCHb50NFNydx1r+MQ3wyGeN DXiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@alliedtelesis.co.nz header.s=mail181024 header.b=ognd4N7d; spf=pass (google.com: domain of linux-kernel+bounces-19079-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-19079-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=REJECT dis=NONE) header.from=alliedtelesis.co.nz Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id s13-20020a0ce30d000000b0067f638b58ffsi7041405qvl.436.2024.01.07.20.19.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 07 Jan 2024 20:19:40 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-19079-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@alliedtelesis.co.nz header.s=mail181024 header.b=ognd4N7d; spf=pass (google.com: domain of linux-kernel+bounces-19079-ouuuleilei=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-19079-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=QUARANTINE sp=REJECT dis=NONE) header.from=alliedtelesis.co.nz Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 88FB81C2147B for ; Mon, 8 Jan 2024 04:19:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4D0BC8BFC; Mon, 8 Jan 2024 04:19:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=alliedtelesis.co.nz header.i=@alliedtelesis.co.nz header.b="ognd4N7d" X-Original-To: linux-kernel@vger.kernel.org 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 C88A36FA9 for ; Mon, 8 Jan 2024 04:19:21 +0000 (UTC) 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 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 832862C03C7; Mon, 8 Jan 2024 17:19:19 +1300 (NZDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=alliedtelesis.co.nz; s=mail181024; t=1704687559; bh=6Do2x9DDn0JcnO2x8tiIauxm3a6XuafqPzj8c5YiWQg=; h=From:To:Cc:Subject:Date:From; b=ognd4N7dN2vmJ54v05sIMYu7xidOhJwxxxs6nqO2VQsMqFyve3ET2tJjpnXBTVmEY n1ZHA5aQMMmH6viV20QCrcI7zMAYWV+HM9dwwtc0EVfitlaPdov+R9UG7UcLPphCOW Gq/Hh8Q99JdSdBXdaIKpdrxqvWDHxcTu78h47VxgLjGPgyYnQEExNRaq11Ed6kbKjQ HB6RXgFhPzs+gIEaaeZ57yp3xrs6iWLIMvs7UTQFuxI9ZKLKmGYYX4VRl6YvQUPNO6 Ijelp43uCcHdfpxGOt+qkpQeBf377adDFUdYRcXIpkweq+jV25gIzBLUcEwqxQktDF +wxZrstuPtD9g== 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 ; Mon, 08 Jan 2024 17:19:19 +1300 Received: from chrisp-dl.ws.atlnz.lc (chrisp-dl.ws.atlnz.lc [10.33.22.30]) by pat.atlnz.lc (Postfix) with ESMTP id 20AD613ED5A; Mon, 8 Jan 2024 17:19:19 +1300 (NZDT) Received: by chrisp-dl.ws.atlnz.lc (Postfix, from userid 1030) id 1C327280974; Mon, 8 Jan 2024 17:19:19 +1300 (NZDT) From: Chris Packham To: krzysztof.kozlowski@linaro.org, peda@axentia.se, p.zabel@pengutronix.de Cc: linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org, Chris Packham Subject: [PATCH] i2c: muxes: pca954x: Allow sharing reset GPIO Date: Mon, 8 Jan 2024 17:19:13 +1300 Message-ID: <20240108041913.7078-1-chris.packham@alliedtelesis.co.nz> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-SEG-SpamProfiler-Analysis: v=2.3 cv=CYB2G4jl c=1 sm=1 tr=0 a=KLBiSEs5mFS1a/PbTCJxuA==:117 a=dEuoMetlWLkA:10 a=VwQbUJbxAAAA:8 a=KKAkSRfTAAAA:8 a=H3RM6WYtTQQ9Ov2Cx3cA:9 a=AjGcO6oz07-iQ99wixmX:22 a=cvBusfyB2V15izCimMoJ:22 X-SEG-SpamProfiler-Score: 0 x-atlnz-ls: pat X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1787494485090454877 X-GMAIL-MSGID: 1787494485090454877 Some hardware designs with multiple PCA954x devices use a reset GPIO connected to all the muxes. Support this configuration by making use of the reset controller framework which can deal with the shared reset GPIOs. Fall back to the old GPIO descriptor method if the reset controller framework is not enabled. Signed-off-by: Chris Packham Reviewed-by: Krzysztof Kozlowski Acked-by: Peter Rosin --- Notes: This patch goes on top of Krzysztof's series adding the GPIO based reset controller[1]. With this I'm able to correctly describe my hardware platform in the DTS and have the resets appropriately controlled. Krzysztof, I'd be really happy if you included this in your series (if there is another round) but I'd also be OK with waiting until your series is in and re-sending this after. [1] - https://lore.kernel.org/lkml/20240105155918.279657-1-krzysztof.kozlowski@linaro.org/ drivers/i2c/muxes/i2c-mux-pca954x.c | 46 ++++++++++++++++++++++++----- 1 file changed, 38 insertions(+), 8 deletions(-) diff --git a/drivers/i2c/muxes/i2c-mux-pca954x.c b/drivers/i2c/muxes/i2c-mux-pca954x.c index 2219062104fb..1702e8d49b91 100644 --- a/drivers/i2c/muxes/i2c-mux-pca954x.c +++ b/drivers/i2c/muxes/i2c-mux-pca954x.c @@ -49,6 +49,7 @@ #include #include #include +#include #include #include #include @@ -102,6 +103,9 @@ struct pca954x { unsigned int irq_mask; raw_spinlock_t lock; struct regulator *supply; + + struct gpio_desc *reset_gpio; + struct reset_control *reset_cont; }; /* Provide specs for the MAX735x, PCA954x and PCA984x types we know about */ @@ -477,6 +481,35 @@ static int pca954x_init(struct i2c_client *client, struct pca954x *data) return ret; } +static int pca954x_get_reset(struct device *dev, struct pca954x *data) +{ + data->reset_cont = devm_reset_control_get_optional_shared(dev, NULL); + if (IS_ERR(data->reset_cont)) + return dev_err_probe(dev, PTR_ERR(data->reset_cont), + "Failed to get reset\n"); + else if (data->reset_cont) + return 0; + + /* + * fallback to legacy reset-gpios + */ + data->reset_gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH); + if (IS_ERR(data->reset_gpio)) { + return dev_err_probe(dev, PTR_ERR(data->reset_gpio), + "Failed to get reset gpio"); + } + + return 0; +} + +static void pca954x_reset_deassert(struct pca954x *data) +{ + if (data->reset_cont) + reset_control_deassert(data->reset_cont); + else + gpiod_set_value_cansleep(data->reset_gpio, 0); +} + /* * I2C init/probing/exit functions */ @@ -485,7 +518,6 @@ static int pca954x_probe(struct i2c_client *client) const struct i2c_device_id *id = i2c_client_get_device_id(client); struct i2c_adapter *adap = client->adapter; struct device *dev = &client->dev; - struct gpio_desc *gpio; struct i2c_mux_core *muxc; struct pca954x *data; int num; @@ -513,15 +545,13 @@ static int pca954x_probe(struct i2c_client *client) return dev_err_probe(dev, ret, "Failed to enable vdd supply\n"); - /* Reset the mux if a reset GPIO is specified. */ - gpio = devm_gpiod_get_optional(dev, "reset", GPIOD_OUT_HIGH); - if (IS_ERR(gpio)) { - ret = PTR_ERR(gpio); + ret = pca954x_get_reset(dev, data); + if (ret) goto fail_cleanup; - } - if (gpio) { + + if (data->reset_cont || data->reset_gpio) { udelay(1); - gpiod_set_value_cansleep(gpio, 0); + pca954x_reset_deassert(data); /* Give the chip some time to recover. */ udelay(1); }