From nobody Fri Jan 2 12:27:29 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id DC408CD6E67 for ; Wed, 11 Oct 2023 13:02:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234809AbjJKNCR (ORCPT ); Wed, 11 Oct 2023 09:02:17 -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-Google-Smtp-Source: AGHT+IGYhTLRS1ySFrvLEdfx4DVvOxzjNWYMLUovd7enoTOl6e3YiL6ysdL4Cx27hmJEiLkCHUkySA== 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 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 Acked-by: Linus Walleij Reviewed-by: Andy Shevchenko Reviewed-by: Peter Rosin --- 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); =20 +/** + * 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 =20 /* 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)); =20 +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); --=20 2.39.2 From nobody Fri Jan 2 12:27:29 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 74DE7CD6E68 for ; Wed, 11 Oct 2023 13:02:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346150AbjJKNCV (ORCPT ); Wed, 11 Oct 2023 09:02:21 -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-Google-Smtp-Source: AGHT+IG+PgbKaxRkhPzK3/tUyQn7QeqD3ixqH6HWwH9XOZbCQkn1vPFZrL6kEepcP5KM5ReCds1y/Q== 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 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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 Acked-by: Linus Walleij 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); =20 +/** + * 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); =20 struct gpio_chip *gpiod_to_chip(const struct gpio_desc *desc); +struct gpio_device *gpiod_to_gpio_device(struct gpio_desc *desc); =20 #else /* CONFIG_GPIOLIB */ =20 --=20 2.39.2 From nobody Fri Jan 2 12:27:29 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7604BCD6E64 for ; Wed, 11 Oct 2023 13:02:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1346728AbjJKNCZ (ORCPT ); Wed, 11 Oct 2023 09:02:25 -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-Google-Smtp-Source: AGHT+IG1ury2Xk2zMZ3J3z9yMYpHMD/S3uprCdExUEscuR0frxJAWI6bhpv+Tb8sn704HMfhO27rNQ== 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 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" 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: Linus Walleij 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-g= pio.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 =20 struct gpiomux { struct i2c_mux_gpio_platform_data data; @@ -176,7 +175,8 @@ static int i2c_mux_gpio_probe(struct platform_device *p= dev) } =20 for (i =3D 0; i < ngpios; i++) { - struct device *gpio_dev; + struct gpio_device *gdev; + struct device *dev; struct gpio_desc *gpiod; enum gpiod_flags flag; =20 @@ -195,9 +195,9 @@ static int i2c_mux_gpio_probe(struct platform_device *p= dev) if (!muxc->mux_locked) continue; =20 - /* FIXME: find a proper way to access the GPIO device */ - gpio_dev =3D &gpiod->gdev->dev; - muxc->mux_locked =3D i2c_root_adapter(gpio_dev) =3D=3D root; + gdev =3D gpiod_to_gpio_device(gpiod); + dev =3D gpio_device_to_device(gdev); + muxc->mux_locked =3D i2c_root_adapter(dev) =3D=3D root; } =20 if (muxc->mux_locked) --=20 2.39.2