Message ID | 20230913115001.23183-4-brgl@bgdev.pl |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:a8d:b0:3f2:4152:657d with SMTP id gr13csp145230vqb; Wed, 13 Sep 2023 16:16:37 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGvrKfzSPZERNZzYeCBVj/lxTkV87A3aG/tpBzQKZ3BzddHIH5RiDh3pzq3x3Lvi0HkgWal X-Received: by 2002:a17:903:1208:b0:1c3:6251:a78 with SMTP id l8-20020a170903120800b001c362510a78mr5068341plh.3.1694646997082; Wed, 13 Sep 2023 16:16:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1694646997; cv=none; d=google.com; s=arc-20160816; b=MWPLvNixDwgwvgRqSleRHIW/h6GL8Oi25pIKsD9p4tCx4BW5VcbcpJb6Ob+3GY05PW QDSJuQk8dEvQ0r8oKaEpR3MhV0hn0fyzMimXcMTYsDLsmMFWYiLxCrWx5j3MaWOoRdDb LT0gazgd1rG2XLD4iByt3hacKBUpmDbN1YZd641SBtODJG2YgVI4gX/YljDVarC6OmBI khHzNx5eEHwYwMy8o+Zq927a1/C1BeEf3p6vqV/5c0z4RLObqPR7osCgf1hiqMcIxopJ jYskROROw7OnaCMTqTpVoKQHL/P+QinDtzcXfDtkxxWfLTgNCSATT1P7xDg93mWY7wG+ i9aA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=9VygHWUUTxJcwgk20gKLWHe+YEMHPQx8FheNmwIckcQ=; fh=0APTZUKOvF74sGqrjhjjJpAFLL5Kw9fbVHsTj8Q1YJA=; b=Wq0wtlfNNoMzj8t7/DcL8sMcK51k6qUsYhu9k6XqdGeA/AxuHR45hKqHpHhi9edLWh WV+ryeKxJ1+vZmgPDhn34qL2ruhraVHwFvVr+rsDcvNqTcu2+rfeakRcIuSh1cLARDoA Luy8ih/S9T83urJh5gRFNrcSt+7mYVweCeMd9KmwQ4AcbSP/sT9JuS2buUMRAJsmJbV4 ZPlNaeh6bLr/6yBveJK+IxQAkgghN7XZrOpfNUIF0+aXH6LcFAmn/5rdLmTLlXcuUxlt IQVD1tVPOZpQgioFGD52iJ10IHnQcq0PfnjvaElOyZ/mjNLEe66MhybUTM7lW3Z4Z+K5 eYEw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20230601.gappssmtp.com header.s=20230601 header.b=it6XWD63; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from snail.vger.email (snail.vger.email. [23.128.96.37]) by mx.google.com with ESMTPS id j14-20020a170902da8e00b001b82da85c5asi367328plx.336.2023.09.13.16.16.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 16:16:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) client-ip=23.128.96.37; Authentication-Results: mx.google.com; dkim=pass header.i=@bgdev-pl.20230601.gappssmtp.com header.s=20230601 header.b=it6XWD63; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.37 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (depot.vger.email [IPv6:2620:137:e000::3:0]) by snail.vger.email (Postfix) with ESMTP id 2AF1F822075D; Wed, 13 Sep 2023 04:50:36 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at snail.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240618AbjIMLuc (ORCPT <rfc822;pwkd43@gmail.com> + 36 others); Wed, 13 Sep 2023 07:50:32 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47190 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240548AbjIMLu1 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 13 Sep 2023 07:50:27 -0400 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A82651990 for <linux-kernel@vger.kernel.org>; Wed, 13 Sep 2023 04:50:22 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id ffacd0b85a97d-31dcf18f9e2so6728747f8f.0 for <linux-kernel@vger.kernel.org>; Wed, 13 Sep 2023 04:50:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1694605821; x=1695210621; 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=9VygHWUUTxJcwgk20gKLWHe+YEMHPQx8FheNmwIckcQ=; b=it6XWD63NWzmlXIvizvgT6JCD9RWAoAEwGWTLHbrTB9cBevk2KasDN3Hvq/cBcMTci /GZ9Jwaj3xM6j67vzx0Iu70UkpbvB/MQox/v6wEkDAdFf3qXsl/3mZZZtqkS8bp8KuEy QUuoJeTzvYc38TIzguvRl1iCzvgBaQ8W41EclIJ/ZVpEn8pEHkEpd23pjO4K3N3wBM9H DDEOdS9C0jYoGRySHc9yWUKHEIFBjQOkH2f2nmNDbYsVShyXfoHVYa2xVDd4aSE/QwIg D7l1gyjKSb6urjJ+WXeDWMiGHlarDCCQMYTori2ay49npCywVbUYkzZA42ZXGjOj/3X9 Vcfw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1694605821; x=1695210621; 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=9VygHWUUTxJcwgk20gKLWHe+YEMHPQx8FheNmwIckcQ=; b=rigoOD7s31kdjxMMj4+FYEYDhipM2FyB7DXDibwkEvauJ6PNcUbBbGKo9Hj/vkmuBU IU1rMjAzr1MzWN7TudodPphgeDSh2eG70kSIi/HXUrGg0pw5U8dTmyamnEf90DUXEWeE 8VAZtoW8jh0nQrzkZqNILXJ8q4ClVI99FOa55H+hIahzqs36e2XGkNEo+awM+1XPsTX6 cC2Oq8gpbMtEJVwe6Z7Y/uD+gTm2ilD4fGJ8h0ERhL3eYca4/WFHXKPoSSgaBk7SzYIV 3vcXwoa+ImhlIvzQJ+/Kun4Aa/hCgT9vCvwrYuB04wwn+FGUGjyysjf99iV/kXay4Rev nu2g== X-Gm-Message-State: AOJu0YwiKvkiADx0MeELb6L6Oa5ep7Kn9LwxjmyOfuBHeFM0SBJ2a8zL Yvyx279/kCE/5dYVYp7J5XzuzQ== X-Received: by 2002:a5d:5957:0:b0:314:12c:4322 with SMTP id e23-20020a5d5957000000b00314012c4322mr1948005wri.4.1694605821222; Wed, 13 Sep 2023 04:50:21 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:3b50:bca5:a754:7463]) by smtp.gmail.com with ESMTPSA id j14-20020adfd20e000000b0031fc4c31d77sm1932689wrh.88.2023.09.13.04.50.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 13 Sep 2023 04:50:20 -0700 (PDT) From: Bartosz Golaszewski <brgl@bgdev.pl> To: Linus Walleij <linus.walleij@linaro.org>, Andy Shevchenko <andy@kernel.org>, Ulf Hansson <ulf.hansson@linaro.org>, Paul Cercueil <paul@crapouillou.net>, Harvey Hunt <harveyhuntnexus@gmail.com>, Miquel Raynal <miquel.raynal@bootlin.com>, Richard Weinberger <richard@nod.at>, Vignesh Raghavendra <vigneshr@ti.com>, Daniel Scally <djrscally@gmail.com>, Hans de Goede <hdegoede@redhat.com>, Mark Gross <markgross@kernel.org>, Heiner Kallweit <hkallweit1@gmail.com> Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mmc@vger.kernel.org, linux-mips@vger.kernel.org, linux-mtd@lists.infradead.org, platform-driver-x86@vger.kernel.org, Bartosz Golaszewski <bartosz.golaszewski@linaro.org> Subject: [PATCH 3/5] mmc: slot-gpio: use gpiod_set_active_[low|high]() Date: Wed, 13 Sep 2023 13:49:59 +0200 Message-Id: <20230913115001.23183-4-brgl@bgdev.pl> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230913115001.23183-1-brgl@bgdev.pl> References: <20230913115001.23183-1-brgl@bgdev.pl> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (snail.vger.email [0.0.0.0]); Wed, 13 Sep 2023 04:50:36 -0700 (PDT) X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1776933121004740938 X-GMAIL-MSGID: 1776966169939703293 |
Series |
gpio: remove gpiod_toggle_active_low()
|
|
Commit Message
Bartosz Golaszewski
Sept. 13, 2023, 11:49 a.m. UTC
From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org> We have new, less cumbersome and clearer interfaces for controlling GPIO polarity. Use them in the MMC code. Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org> --- drivers/mmc/core/slot-gpio.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-)
Comments
On Wed, Sep 13, 2023 at 2:24 PM Linus Walleij <linus.walleij@linaro.org> wrote: > > On Wed, Sep 13, 2023 at 1:50 PM Bartosz Golaszewski <brgl@bgdev.pl> wrote: > > > From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org> > > > > We have new, less cumbersome and clearer interfaces for controlling GPIO > > polarity. Use them in the MMC code. > > > > Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org> > > I like the looks of the code better, obviously but this looks like this for > a reason unfortunately. > > See the following from > Documentation/devicetree/bindings/mmc/mmc-controller.yaml: > > # CD and WP lines can be implemented on the hardware in one of two > # ways: as GPIOs, specified in cd-gpios and wp-gpios properties, or > # as dedicated pins. Polarity of dedicated pins can be specified, > # using *-inverted properties. GPIO polarity can also be specified > # using the GPIO_ACTIVE_LOW flag. This creates an ambiguity in the > # latter case. We choose to use the XOR logic for GPIO CD and WP > # lines. This means, the two properties are "superimposed," for > # example leaving the GPIO_ACTIVE_LOW flag clear and specifying the > # respective *-inverted property property results in a > # double-inversion and actually means the "normal" line polarity is > # in effect. > I hate it, thanks. :) > Will you still provide the desired "double inversion" after this patch? > Not in the current form. Would it work to go: if (override_active_level) { if (!(host->caps2 & MMC_CAP2_CD_ACTIVE_HIGH)) gpiod_set_active_high(desc); else gpiod_set_active_low(desc); } else { if (host->caps2 & MMC_CAP2_CD_ACTIVE_HIGH) gpiod_set_active_high(desc); else gpiod_set_active_low(desc); } ? Alternatively we could reimplement the toggle semantics locally in a helper function in order to get rid of it from GPIOLIB. Bart
On Wed, Sep 13, 2023 at 2:39 PM Bartosz Golaszewski <brgl@bgdev.pl> wrote: > On Wed, Sep 13, 2023 at 2:24 PM Linus Walleij <linus.walleij@linaro.org> wrote: > > > > On Wed, Sep 13, 2023 at 1:50 PM Bartosz Golaszewski <brgl@bgdev.pl> wrote: > > > > > From: Bartosz Golaszewski <bartosz.golaszewski@linaro.org> > > > > > > We have new, less cumbersome and clearer interfaces for controlling GPIO > > > polarity. Use them in the MMC code. > > > > > > Signed-off-by: Bartosz Golaszewski <bartosz.golaszewski@linaro.org> > > > > I like the looks of the code better, obviously but this looks like this for > > a reason unfortunately. > > > > See the following from > > Documentation/devicetree/bindings/mmc/mmc-controller.yaml: > > > > # CD and WP lines can be implemented on the hardware in one of two > > # ways: as GPIOs, specified in cd-gpios and wp-gpios properties, or > > # as dedicated pins. Polarity of dedicated pins can be specified, > > # using *-inverted properties. GPIO polarity can also be specified > > # using the GPIO_ACTIVE_LOW flag. This creates an ambiguity in the > > # latter case. We choose to use the XOR logic for GPIO CD and WP > > # lines. This means, the two properties are "superimposed," for > > # example leaving the GPIO_ACTIVE_LOW flag clear and specifying the > > # respective *-inverted property property results in a > > # double-inversion and actually means the "normal" line polarity is > > # in effect. > > > > I hate it, thanks. :) > > > Will you still provide the desired "double inversion" after this patch? > > > > Not in the current form. Would it work to go: > > if (override_active_level) { > if (!(host->caps2 & MMC_CAP2_CD_ACTIVE_HIGH)) > gpiod_set_active_high(desc); > else > gpiod_set_active_low(desc); > } else { > if (host->caps2 & MMC_CAP2_CD_ACTIVE_HIGH) > gpiod_set_active_high(desc); > else > gpiod_set_active_low(desc); > } > > ? I *think* so but my boolean parser i known to be flawed since I have screwed up double inversions repeatedly over the years, so it should not be trusted at all. > Alternatively we could reimplement the toggle semantics locally in a > helper function in order to get rid of it from GPIOLIB. I don't know about that, the flag is inside gpio_desc so we cannot access it (struct is private to gpiolib...) Yours, Linus Walleij
On Thu, Sep 14, 2023 at 10:31 AM Linus Walleij <linus.walleij@linaro.org> wrote: > On Wed, Sep 13, 2023 at 2:39 PM Bartosz Golaszewski <brgl@bgdev.pl> wrote: > > Alternatively we could reimplement the toggle semantics locally in a > > helper function in order to get rid of it from GPIOLIB. > > I don't know about that, the flag is inside gpio_desc so we cannot > access it (struct is private to gpiolib...) Actually I think the way the toggle call came about was for this one MMC usecase. Then other subsystems have used it without asking the GPIO maintainers or without implementing the more proper accessors or patching drivers/gpio/gpiolib-of.c because why not, probably thinking something like "hey weird that it is just toggle I guess they are not so smart, but it works, ship it". Yours, Linus Walleij
diff --git a/drivers/mmc/core/slot-gpio.c b/drivers/mmc/core/slot-gpio.c index 2a2d949a9344..a6fea6559a5e 100644 --- a/drivers/mmc/core/slot-gpio.c +++ b/drivers/mmc/core/slot-gpio.c @@ -204,12 +204,11 @@ int mmc_gpiod_request_cd(struct mmc_host *host, const char *con_id, } /* override forces default (active-low) polarity ... */ - if (override_active_level && !gpiod_is_active_low(desc)) - gpiod_toggle_active_low(desc); - + if (override_active_level) + gpiod_set_active_low(desc); /* ... or active-high */ - if (host->caps2 & MMC_CAP2_CD_ACTIVE_HIGH) - gpiod_toggle_active_low(desc); + else if (host->caps2 & MMC_CAP2_CD_ACTIVE_HIGH) + gpiod_set_active_high(desc); ctx->cd_gpio = desc; @@ -256,7 +255,7 @@ int mmc_gpiod_request_ro(struct mmc_host *host, const char *con_id, } if (host->caps2 & MMC_CAP2_RO_ACTIVE_HIGH) - gpiod_toggle_active_low(desc); + gpiod_set_active_high(desc); ctx->ro_gpio = desc;