From patchwork Wed Oct 11 13:02:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 151423 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp521747vqb; Wed, 11 Oct 2023 06:03:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEoG/gsj7AsF7LIw8ehWAulpzb2qn8foAaVZp4JfE6iR3HKlk4EUhM/7FEkC04eDbCysLDt X-Received: by 2002:a17:902:d512:b0:1bf:349f:b85c with SMTP id b18-20020a170902d51200b001bf349fb85cmr23513045plg.1.1697029384494; Wed, 11 Oct 2023 06:03:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697029384; cv=none; d=google.com; s=arc-20160816; b=kK34DSSxwLcjSWiXajtUCO/4c6EdXM5oxSmZg96rXkp3UvFHrHCv1nUxq9oG9Gp7bU xe5a1mA+WUary7DWZNgSV6JJBVTZL/VxFsrO1XYuz0IVC+dJakKM65yhjna+zESeHTxj miMWV34DXa9kUuI0ikMshlmYtg30p7jY1LLmBPtYh0kNg0sbOqCdR/wX20632Y+BOCXM ue+Gf/4RdUTcm6vKcGNPPMBMms36qN2Y5b1gxB44mFkub0kn9QSwUixdlbkxK1nR4bdK pQXSBurSOckuM91sG9H3z9wh9zv9RTuzK/k1aZlyyuGTpNK3m4oLIHImkZww5a+Sj0f8 EoLA== 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=LxP50mjlFsla3Pz/fmyyE11r9eXmq7yiPt4F5Ys7dSE=; fh=YP/ZZen/fLhGMMezUuWB0b3Qyqd3gueBWEsOMCN9gx4=; b=aI91Y5EQqZCckKlm121p1s20xR59m/Vvh0LYoSgQh3otlzcpbFVrCNYYf08fViKX0C 6J3yc8DpK0ezUxAYiqlaCwBsF5nz7GGNJn/1ts4ltwMNXEyUdM3YBlqTjM2hMsrANmF0 lGniX0wRk0ebJaI8qZxbkPNkUf0o8X+WukyPnXaKk7RGNgcjR5v1rdagxzQmmcOfh9yx z0gYoKiugp5N+Vva03rgKwfDMoKQ8CN9Lt63TtXnJi2cJqdEstdtfZwsyaTvkuCiFsFU aRhPuOIcPkihijkbssswMjOEG4Etb6wjevNdJ5L3EFb1g/ADb8oz77y+eNf79tL1bQ1G pUcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20230601.gappssmtp.com header.s=20230601 header.b=HixFp+6D; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from pete.vger.email (pete.vger.email. [2620:137:e000::3:6]) by mx.google.com with ESMTPS id t10-20020a17090340ca00b001c589ba4a0bsi4148198pld.195.2023.10.11.06.02.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 06:03:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 as permitted sender) client-ip=2620:137:e000::3:6; Authentication-Results: mx.google.com; dkim=pass header.i=@bgdev-pl.20230601.gappssmtp.com header.s=20230601 header.b=HixFp+6D; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:6 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 pete.vger.email (Postfix) with ESMTP id CD1688182DC5; Wed, 11 Oct 2023 06:02:32 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at pete.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234805AbjJKNCQ (ORCPT + 18 others); Wed, 11 Oct 2023 09:02:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56376 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232165AbjJKNCN (ORCPT ); Wed, 11 Oct 2023 09:02:13 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 74E46B7 for ; Wed, 11 Oct 2023 06:02:11 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-3296b3f03e5so4732596f8f.2 for ; Wed, 11 Oct 2023 06:02:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1697029330; x=1697634130; 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=LxP50mjlFsla3Pz/fmyyE11r9eXmq7yiPt4F5Ys7dSE=; b=HixFp+6DGA75PN2s1S5OOYnodmM03iAfMTW1lZYShj/wRU7+8rOOSN1qRVIDGEfEH7 iRqfoOcS96HNdLzru+gwO5QtsfuKrug5OxjLPGXRHuIh4hpmKjaz3+0AjZXTSU9J8vRt uJp5Eh5Wl8jGYSBuv62ovY/1/op5f0Ac+ljbXqTlp1DhSZ3tjq5O8qlzHgdbMDMqQUTq 47vyMZMc+4SNf1mcSo4pUipeSLoXfaYr/SNh4uyrEhv8xCw3/PfjybOpWbdEHORz9uKs y6bL+bkRdXnr2w4G1wau5q6KIg3UdyapXi322rJels90s7In8hB+1OEwwCKGDlUO1AfD EhwA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697029330; x=1697634130; 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=LxP50mjlFsla3Pz/fmyyE11r9eXmq7yiPt4F5Ys7dSE=; b=hyTlGmbByvjXXPOtcU65COH9ooViDD1NzuzPegIGuFHyQTry5L/dw5QpqmsxTj4PTK WDGdRxmeJA0crta+T53zpCmHGSBpX7kcofggryPqV6f83H79kJBb8ny3HFRY2LZLpb9h YTplVHCzq0vwSy7JJAn4q6yv0UWuyypCfSXKcajUjcKyLpPnyxr1ZrkLRVDc5A0xBOSK dvoYBG1TWMkVwJslkeS8vXrk3ucuoNPpYwZ8CnVHct7VBbZaGa1SUFHKCeJ7Hnc/0Euh xn1XmStHNp1HijXJg9sNXcySpK+N86g4g0XKyY+j8JRdq/zZsfRJgGGK4S+Fwr6S9dd4 1zTQ== X-Gm-Message-State: AOJu0YxPUlido2FPVm+nOhUCUBsFkqLVMIeCBHEgVCLtffpneqILJYKq RdgKHkGKMvuuP7ROftu7c7ed8A== X-Received: by 2002:a05:6000:114d:b0:324:8502:6355 with SMTP id d13-20020a056000114d00b0032485026355mr17631600wrx.46.1697029329736; Wed, 11 Oct 2023 06:02:09 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:e551:3946:26fc:f94]) by smtp.gmail.com with ESMTPSA id s13-20020adfeccd000000b003198a9d758dsm15455375wro.78.2023.10.11.06.02.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 06:02:08 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Andy Shevchenko , Peter Korsgaard , Peter Rosin Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-i2c@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 1/3] gpiolib: provide gpio_device_to_device() Date: Wed, 11 Oct 2023 15:02:02 +0200 Message-Id: <20231011130204.52265-2-brgl@bgdev.pl> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231011130204.52265-1-brgl@bgdev.pl> References: <20231011130204.52265-1-brgl@bgdev.pl> MIME-Version: 1.0 X-Spam-Status: No, score=2.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_SBL_CSS, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on pete.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (pete.vger.email [0.0.0.0]); Wed, 11 Oct 2023 06:02:32 -0700 (PDT) X-Spam-Level: ** X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779464283808804846 X-GMAIL-MSGID: 1779464283808804846 From: Bartosz Golaszewski There are users in the kernel who need to retrieve the address of the struct device backing the GPIO device. Currently they needlessly poke in the internals of GPIOLIB. Add a dedicated getter function. Signed-off-by: Bartosz Golaszewski Reviewed-by: Peter Rosin Reviewed-by: Andy Shevchenko --- drivers/gpio/gpiolib.c | 17 +++++++++++++++++ include/linux/gpio/driver.h | 2 ++ 2 files changed, 19 insertions(+) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 191f9c87b4d0..ca2b5b424284 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -1169,6 +1169,23 @@ void gpio_device_put(struct gpio_device *gdev) } EXPORT_SYMBOL_GPL(gpio_device_put); +/** + * gpio_device_to_device() - Retrieve the address of the underlying struct + * device. + * @gdev: GPIO device for which to return the address. + * + * This does not increase the reference count of the GPIO device nor the + * underlying struct device. + * + * Returns: + * Address of struct device backing this GPIO device. + */ +struct device *gpio_device_to_device(struct gpio_device *gdev) +{ + return &gdev->dev; +} +EXPORT_SYMBOL_GPL(gpio_device_to_device); + #ifdef CONFIG_GPIOLIB_IRQCHIP /* diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h index f8ad7f40100c..0484bf90b25d 100644 --- a/include/linux/gpio/driver.h +++ b/include/linux/gpio/driver.h @@ -618,6 +618,8 @@ void gpio_device_put(struct gpio_device *gdev); DEFINE_FREE(gpio_device_put, struct gpio_device *, if (IS_ERR_OR_NULL(_T)) gpio_device_put(_T)); +struct device *gpio_device_to_device(struct gpio_device *gdev); + bool gpiochip_line_is_irq(struct gpio_chip *gc, unsigned int offset); int gpiochip_reqres_irq(struct gpio_chip *gc, unsigned int offset); void gpiochip_relres_irq(struct gpio_chip *gc, unsigned int offset); From patchwork Wed Oct 11 13:02:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 151421 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp521559vqb; Wed, 11 Oct 2023 06:02:50 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEfbBk+p7a0EKvBkOiZiPdhVAPneVfAeCQAHFf9iA3PGtFMC9MLH2vNSpZ5pxopPqU4/ooU X-Received: by 2002:a05:6a20:8f01:b0:15a:2c0b:6c81 with SMTP id b1-20020a056a208f0100b0015a2c0b6c81mr25342888pzk.3.1697029370229; Wed, 11 Oct 2023 06:02:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697029370; cv=none; d=google.com; s=arc-20160816; b=XcX5xXZflyMRipg9IWitfya7I1BI5JWJYd7CunjaEUlK0u3kEKL6Sf7/6Vi8zFNZa7 K6ApCtnLGUn0rDR+gvOBo9HMc2bKTgRVE5TT3aGWwlm0N0qbzRoa+QA+/ZMgP40FneqF aCuyunqoTxCceIqKWzMYlUX+FaZSI0MlCi/MsmDWeeoRBYMtfe+6qZTcUfz5Vpyh8uMh yetrvIZni/FGl5NJog9fJ8mLjmrgAhsIYt8OEO4V0YZfUBTekv9BJR3NP4xauR9AVaXQ OE2/s00u32vDtRTyt/nx2//4ns72IU9dMbj7WRHHvJHfXmKAn8F/L1BUXQWscy1fefyD 8glg== 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=4UAK8E7pePpgc7Mc8WJXJGU9y4S9NeTxPgxbowGv2Qg=; fh=YP/ZZen/fLhGMMezUuWB0b3Qyqd3gueBWEsOMCN9gx4=; b=fSilL8bl2M47/UnrOaaXrrHdb2vO18vaupSeCNmeGpjCjIfIQXzb1DwgVxFeBpz4YQ OSwFjprIAeyWt3tkP3AgMtMk9abbJqsA8VprCk1S6LEam9MX/YaTHgetMVOpi3Xg010s nHCzQpI6RZ9oLR8kBVEl/uurmTSxvV+1j22498qjFOCOjP7PeXLlTfzl8olrbcKUXb8U yKnFvdH7FMjzWejL7i/fK5k8rUV/UFZ0H9vyImnsxep5UH1MOqud823ZkVsQCjcmdgp1 dXnjgANuMaPGEixGVUwNH55q3XbL2GgdufjKxEIgXMnqB3YklPmipvB9hySyX+xVrqhB Bsfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20230601.gappssmtp.com header.s=20230601 header.b=XwEauL7w; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from groat.vger.email (groat.vger.email. [23.128.96.35]) by mx.google.com with ESMTPS id a26-20020a63705a000000b00573feb1e7c6si14988202pgn.888.2023.10.11.06.02.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 06:02:50 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 as permitted sender) client-ip=23.128.96.35; Authentication-Results: mx.google.com; dkim=pass header.i=@bgdev-pl.20230601.gappssmtp.com header.s=20230601 header.b=XwEauL7w; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.35 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 groat.vger.email (Postfix) with ESMTP id F1862810CAAF; Wed, 11 Oct 2023 06:02:43 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234894AbjJKNCU (ORCPT + 18 others); Wed, 11 Oct 2023 09:02:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56432 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232235AbjJKNCP (ORCPT ); Wed, 11 Oct 2023 09:02:15 -0400 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8D90398 for ; Wed, 11 Oct 2023 06:02:13 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id ffacd0b85a97d-32d885e97e2so430442f8f.0 for ; Wed, 11 Oct 2023 06:02:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1697029332; x=1697634132; 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=4UAK8E7pePpgc7Mc8WJXJGU9y4S9NeTxPgxbowGv2Qg=; b=XwEauL7wuLPxZFZQqqmEXTGZX6gmQT2LHBd1QymLvuBPSpRAlXD2o04gVfRdcpzwUS UXynbsrywNcIdayB40kRsmYOQ7B5BvlbT/kIooMvXPG+8f6CpPn8bggyM1SjhSz/BeBs qY6v2QIojzu5HW07by+jb7Qitpkue9Sfzztet3+e7alLHDRePIKdm1JQy33HmvrUFIVd oAQn2d+FA078a9aV6Tm+fbJECZsV6Ao4dgVOTRk9kYurn/OzwD5ZfJRfb64h289DNykA O4MpONPukI/N/ZrODt9H83VvHa029GVp2JOpohb0sM25930UoZjkRrmZFA9X0hLGLO0Y 2OMQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697029332; x=1697634132; 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=4UAK8E7pePpgc7Mc8WJXJGU9y4S9NeTxPgxbowGv2Qg=; b=EuHNdYWWnBhqAYP5WQAFzEfRzCpQxx1IK0R6nGz7mZk2E28d4JRQ1jTs8Q9R9AiXRw D7297LfAEd1wBFXKOR48V0VMRTH01xOV9AkusRwqcR/oXvaJdeQ80EIQAkDrur2muPJH M007pX2nfgSBpLgrkJHcwu2uxYYdd0NkvQ5Et37WPSK1ponsXWY6mkQdmaEzwwbBT0WZ p4VXzjnG8fnaq9kQPYii52vCVJNa5arIfZik96sNJ1l0+ojjzdmNYq2OcSoxgu1+Kg0m IwZitrpQeTMAHz3Ejh5qlYoefEsZ9KVPBctTIIKNDnVZDjN/vLeRC7ud5/pjfuzz+HOE EwPQ== X-Gm-Message-State: AOJu0Yx06hL1olHw0xmqn7zD9dRer2GRyXKPP9vMoVUZ5PrSECS1nfM8 /BYGkdxx8iui1dngbQ0R0e9uMQ== X-Received: by 2002:a5d:630c:0:b0:31f:fa6a:936e with SMTP id i12-20020a5d630c000000b0031ffa6a936emr18705062wru.17.1697029330935; Wed, 11 Oct 2023 06:02:10 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:e551:3946:26fc:f94]) by smtp.gmail.com with ESMTPSA id s13-20020adfeccd000000b003198a9d758dsm15455375wro.78.2023.10.11.06.02.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 06:02:10 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Andy Shevchenko , Peter Korsgaard , Peter Rosin Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-i2c@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 2/3] gpiolib: provide gpiod_to_gpio_device() Date: Wed, 11 Oct 2023 15:02:03 +0200 Message-Id: <20231011130204.52265-3-brgl@bgdev.pl> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231011130204.52265-1-brgl@bgdev.pl> References: <20231011130204.52265-1-brgl@bgdev.pl> MIME-Version: 1.0 X-Spam-Status: No, score=2.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_SBL_CSS, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Wed, 11 Oct 2023 06:02:44 -0700 (PDT) X-Spam-Level: ** X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779464268727234767 X-GMAIL-MSGID: 1779464268727234767 From: Bartosz Golaszewski Accessing struct gpio_chip backing a GPIO device is only allowed for the actual providers of that chip. Similarly to how we introduced gpio_device_find() in order to replace the abused gpiochip_find(), let's introduce a counterpart to gpiod_to_chip() that returns a reference to the GPIO device owning the descriptor. This is done in order to later remove gpiod_to_chip() entirely. Signed-off-by: Bartosz Golaszewski Reviewed-by: Peter Rosin --- drivers/gpio/gpiolib.c | 21 +++++++++++++++++++++ include/linux/gpio/driver.h | 1 + 2 files changed, 22 insertions(+) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index ca2b5b424284..1e0ed6f5bcd5 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -220,6 +220,27 @@ struct gpio_chip *gpiod_to_chip(const struct gpio_desc *desc) } EXPORT_SYMBOL_GPL(gpiod_to_chip); +/** + * gpiod_to_gpio_device() - Return the GPIO device to which this descriptor + * belongs. + * @desc: Descriptor for which to return the GPIO device. + * + * This *DOES NOT* increase the reference count of the GPIO device as it's + * expected that the descriptor is requested and the users already holds a + * reference to the device. + * + * Returns: + * Address of the GPIO device owning this descriptor. + */ +struct gpio_device *gpiod_to_gpio_device(struct gpio_desc *desc) +{ + if (!desc) + return NULL; + + return desc->gdev; +} +EXPORT_SYMBOL_GPL(gpiod_to_gpio_device); + /** * gpio_device_get_chip() - Get the gpio_chip implementation of this GPIO device * @gdev: GPIO device diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h index 0484bf90b25d..7a8725be1225 100644 --- a/include/linux/gpio/driver.h +++ b/include/linux/gpio/driver.h @@ -784,6 +784,7 @@ int gpiochip_lock_as_irq(struct gpio_chip *gc, unsigned int offset); void gpiochip_unlock_as_irq(struct gpio_chip *gc, unsigned int offset); struct gpio_chip *gpiod_to_chip(const struct gpio_desc *desc); +struct gpio_device *gpiod_to_gpio_device(struct gpio_desc *desc); #else /* CONFIG_GPIOLIB */ From patchwork Wed Oct 11 13:02:04 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 151422 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:612c:2908:b0:403:3b70:6f57 with SMTP id ib8csp521821vqb; Wed, 11 Oct 2023 06:03:09 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHlX6dEFpWB9Cs7o0J1a2ve7yNQOqnUtivTmT0UzvRYSEdn36X1G3mLsVeUK2wjdHF84a0x X-Received: by 2002:a05:6a00:3916:b0:68e:2fd4:288a with SMTP id fh22-20020a056a00391600b0068e2fd4288amr23821692pfb.3.1697029388653; Wed, 11 Oct 2023 06:03:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1697029388; cv=none; d=google.com; s=arc-20160816; b=nTgj3NAGkanggFthqpyMW10H9cZ45tbqyN71IuZ+67jIGbl3Pfc7DXy/jS828guepD Kk3RpcJJVDwvj5W+W1haAAUqSRzC7W0VGVt7WEmwQhq/zIq15Q3flewgw7KGV4plpF49 Ei9FxY3CoHKfFk/V6olfoATjS5iha4fB67J6TC/wplY5ThFqWkIebOsgnvK3OmzCui4O ChDiVhOmEMqFASy71BkqZBEUtxYfnMkaqftQTwQk7c/mF4jRISj1nEvATKtXa9f21S8m bfs5e5O6s4cmEyQ6pgTVN+IYM3bbH2c4fo+3zwpXQICdM0Sqtb7rtQON1iLruQI7bj9R pzlQ== 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=GOhmKBxnjPWo6ddzFX5PM60asyFhIGEHrRKZVC90wiM=; fh=YP/ZZen/fLhGMMezUuWB0b3Qyqd3gueBWEsOMCN9gx4=; b=PIlyaa2P2+yCQAjjDgwPJQTRb8ehMZYJ8A6P/GYDbAG/+02UfPBaGH9ooggM+R2wUf Ogwp1dex9exnLN+tKPcYuvbVMVL1/+PU6i4X21LIwByE1zAQ6z87JiVXePyoV8NR1DXL l0EHjmwRdvZWnp/Hq1A6Y/wOSofSa2uEAuiLt09zj0hASE1ISU4Q+yNHbYZ44kPMihG0 4QGiC4O0RfsTwaVDQ/PNaDUX9prpbhFmc6BORMRrXvkpCfp1Ofxx6mgidzR5yKhpdrwp Kg0fMh8yFcOluMEdxrtj+87GK3Y+TNCnZYpT6c23xspPazrI564AfThqnKNI+b2T5bek VCSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bgdev-pl.20230601.gappssmtp.com header.s=20230601 header.b=gHlFgqI3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from groat.vger.email (groat.vger.email. [2620:137:e000::3:5]) by mx.google.com with ESMTPS id fd17-20020a056a002e9100b006896e2f30f2si12620407pfb.365.2023.10.11.06.02.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 06:03:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 as permitted sender) client-ip=2620:137:e000::3:5; Authentication-Results: mx.google.com; dkim=pass header.i=@bgdev-pl.20230601.gappssmtp.com header.s=20230601 header.b=gHlFgqI3; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::3:5 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 groat.vger.email (Postfix) with ESMTP id EBDFE810CAB9; Wed, 11 Oct 2023 06:02:41 -0700 (PDT) X-Virus-Status: Clean X-Virus-Scanned: clamav-milter 0.103.10 at groat.vger.email Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346062AbjJKNCX (ORCPT + 18 others); Wed, 11 Oct 2023 09:02:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60192 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234884AbjJKNCS (ORCPT ); Wed, 11 Oct 2023 09:02:18 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6E1EDB0 for ; Wed, 11 Oct 2023 06:02:15 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id ffacd0b85a97d-325e9cd483eso6449406f8f.2 for ; Wed, 11 Oct 2023 06:02:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1697029334; x=1697634134; 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=GOhmKBxnjPWo6ddzFX5PM60asyFhIGEHrRKZVC90wiM=; b=gHlFgqI3ABxAxpZZcg/h8K2970YKKRpIJbmBqDjj8m6GmthEHqePRB8SyiV3V4Jdvt BLiUpOX8y5u543L5X2pQTz3q0ze3DZR/sHttB3nzHOT5ZSKLIpNSkfN2ts+gU8ZcxU12 Zt7OP2RiYo1UbuMyvJY5nVjeL1jGdLcHYtyG1a5I/GKUUon9yGZd/j9kNwhDmuZfX05K kmJHfcx9NiO331BgKqund/NaA2q7KxEGaPGPSjctLjOuhXSaxba6NyuVDo4TgQ5lsamQ POPUvBcvrccg4xRlrGU2AsaPN72QU8Xr2NYVQla52TjHncGRNMwc25nKEeKtPYDkU+Zc sUhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1697029334; x=1697634134; 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=GOhmKBxnjPWo6ddzFX5PM60asyFhIGEHrRKZVC90wiM=; b=W8GJXQma5zYvZ9Emk8a1E8V0YU6VqLXKN+L/WIki0+P55Ckg3ATvvhtbWOrZOg9klV dLVQ0fqhoTNrLNLevXSySBSWz5mHB5nLtE9N9msgoNgLTDaGrhKA6vHHg/FPThVCiAyN x9WKKgQdB90zM9ZXXlO3o/RJHptbjLZrcrbvitzwHFRJUkiF07C/zBO5K+fcCMJdZHth jQNVctnQ5KbCqP4IFVxHNl1T8NmB2A0v9BSEmsClcLKgkiTnWiH5+W0ZnxPUIhSEe47Z lzpuItWIzYcHqyzKMSgREr7cO3JEWQPG5bGj4+dK+WGeIpugxqAVNREoR7xbTkKczJYd ZL4w== X-Gm-Message-State: AOJu0YyF0kJPrpoRHQ1YxFToU/Mu5Lf5FG/JSYRIeNTm3LgATVsD49yk slJhgVUnZMlc10voOJ+PZHPtCg== X-Received: by 2002:a5d:4c50:0:b0:31f:dc60:13b5 with SMTP id n16-20020a5d4c50000000b0031fdc6013b5mr18364953wrt.25.1697029333084; Wed, 11 Oct 2023 06:02:13 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:e551:3946:26fc:f94]) by smtp.gmail.com with ESMTPSA id s13-20020adfeccd000000b003198a9d758dsm15455375wro.78.2023.10.11.06.02.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 Oct 2023 06:02:12 -0700 (PDT) From: Bartosz Golaszewski To: Linus Walleij , Andy Shevchenko , Peter Korsgaard , Peter Rosin Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-i2c@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 3/3] i2c: mux: gpio: don't fiddle with GPIOLIB internals Date: Wed, 11 Oct 2023 15:02:04 +0200 Message-Id: <20231011130204.52265-4-brgl@bgdev.pl> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20231011130204.52265-1-brgl@bgdev.pl> References: <20231011130204.52265-1-brgl@bgdev.pl> MIME-Version: 1.0 X-Spam-Status: No, score=2.8 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_SBL_CSS, SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on groat.vger.email Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Greylist: Sender passed SPF test, not delayed by milter-greylist-4.6.4 (groat.vger.email [0.0.0.0]); Wed, 11 Oct 2023 06:02:42 -0700 (PDT) X-Spam-Level: ** X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1779464288305651280 X-GMAIL-MSGID: 1779464288305651280 From: Bartosz Golaszewski Use the relevant API functions to retrieve the address of the underlying struct device instead of accessing GPIOLIB private structures manually. Signed-off-by: Bartosz Golaszewski Acked-by: Peter Rosin Acked-by: Wolfram Sang --- drivers/i2c/muxes/i2c-mux-gpio.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/drivers/i2c/muxes/i2c-mux-gpio.c b/drivers/i2c/muxes/i2c-mux-gpio.c index 5d5cbe0130cd..48a872a8196b 100644 --- a/drivers/i2c/muxes/i2c-mux-gpio.c +++ b/drivers/i2c/muxes/i2c-mux-gpio.c @@ -14,8 +14,7 @@ #include #include #include -/* FIXME: stop poking around inside gpiolib */ -#include "../../gpio/gpiolib.h" +#include struct gpiomux { struct i2c_mux_gpio_platform_data data; @@ -176,7 +175,8 @@ static int i2c_mux_gpio_probe(struct platform_device *pdev) } for (i = 0; i < ngpios; i++) { - struct device *gpio_dev; + struct gpio_device *gdev; + struct device *dev; struct gpio_desc *gpiod; enum gpiod_flags flag; @@ -195,9 +195,9 @@ static int i2c_mux_gpio_probe(struct platform_device *pdev) if (!muxc->mux_locked) continue; - /* FIXME: find a proper way to access the GPIO device */ - gpio_dev = &gpiod->gdev->dev; - muxc->mux_locked = i2c_root_adapter(gpio_dev) == root; + gdev = gpiod_to_gpio_device(gpiod); + dev = gpio_device_to_device(gdev); + muxc->mux_locked = i2c_root_adapter(dev) == root; } if (muxc->mux_locked)