From patchwork Tue Sep 5 18:52:54 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 13374933 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 7F0BBCA0FFA for ; Tue, 5 Sep 2023 18:54:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=qlg5xQnNRbkUt7WL2Imc0XkwT9IxTkV7l8TaUCeN+Oo=; b=d2E/9WR/8B/jn+ ooiAjKgoNcJzsv/LI3gwO/6UBceGVRDDhfOZWgZxXyCiTXxOtb/aG/Jfi1W8R/XdhEp1VOvpbvm+g Gcdu96eV1OQZePYrahpExdJUpRXKDPAjX7xodvYe99DjZy7VwNHENntruyGvyTgH3kfdSlsOa6CBY Bh4lGf46fwO3DeeM5t+cFQ2HZmlQt+3EqJOUDLDktGT2/S4i3xbPWxg7IMb0YfkudnhdWG3uUYthM LQ0y4rbgSdTfq+CbuXY8br+L/Nq4REsAd1XaeLymQrv+Nu0FC1cdwQyWY51jkyV0Jjt3DwLDg7neP TenXTQHdc4hM854NrwHQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1qdbBI-006YVH-1k; Tue, 05 Sep 2023 18:53:44 +0000 Received: from mail-wm1-x333.google.com ([2a00:1450:4864:20::333]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1qdbBB-006YOs-3D for linux-arm-kernel@lists.infradead.org; Tue, 05 Sep 2023 18:53:39 +0000 Received: by mail-wm1-x333.google.com with SMTP id 5b1f17b1804b1-401ec23be82so30149565e9.0 for ; Tue, 05 Sep 2023 11:53:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1693940013; x=1694544813; darn=lists.infradead.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=rGZDmwAMqeUVhOTfv7ZtpSGAuFAAm5HZQ+raVbVaSso=; b=OkHnvR0aT4JQUucL4ECTEjcNA6FMBqV7iGsxNBT41HYAy0Wm+JQx2IDJaXradt/ZQA R3Q+R2CJA9omIVzcI+Xzh767Ybv4pkveiTMH4JXvToEWmDM11BNWU/jAhjSLIxpTRS8t FZJEZYTpK8XVXWmMF5IybDivmc4dNoDjnJ5nlPR1U08DJwJ2xOpUSZInTnwo6kiRIwNI CeryrmbNi6mX4gaJ4F9FLpTU3e+Qs728QZKi++sCPV9XrxqCW6PIZl0RHTQoNGRstqHN 62BSDDlAyHxlo+Nf0N1rfo5ZoveZZ51rlhllKwpPLD+a4fUTG71+IlW50lmiQyqLfyKp Gjww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693940013; x=1694544813; 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=rGZDmwAMqeUVhOTfv7ZtpSGAuFAAm5HZQ+raVbVaSso=; b=N9/H3WhrF4GA0k50ok6PmZPfwLBFDGlFx+jrJtrh1a+kx82QUbhsVnwtnRPA682QLE Al1Og3iztUMBafRRwdIc0KRRTkEhVHKynvP/VeJAxBZqH7kzDUvPeBpyrBkImVx62BHR fZGUsjTy3+kdx8d7fmoOd3wbuSUdNA8C+lzsfy21rL66qEqPDTBwo/rNNkBdMAAB+ke8 DNqDnCFcJnEtHm6PyHnDbjcrKVvdiM2HfEYtDGT1W8qB2nyFsMciZoLSmWd3Wclmlw2k N5316xZ1WR1RIXWi9iC2dIehygcydwDaBNBpBgHGAWhIh32dKTAb1EY6+kwRztAdSv/e VunQ== X-Gm-Message-State: AOJu0Yy6cvlHzJK/TRUqRbiCoViZmwSk1J60+EXoUdQBcNiOKi+svaQw sXQcdd+ahQGiI8DeuDa90cW0Dw== X-Google-Smtp-Source: AGHT+IE6a92Y8/0xOq//9BYLFPzr9xAdeK40uWCbwfh4Inevy5jL9Qx5QtQIzqIf7nl+RNMdD6lXWg== X-Received: by 2002:a05:600c:2149:b0:402:8c7b:ceea with SMTP id v9-20020a05600c214900b004028c7bceeamr402336wml.30.1693940013467; Tue, 05 Sep 2023 11:53:33 -0700 (PDT) Received: from brgl-uxlite.home ([2a01:cb1d:334:ac00:7a54:5dbc:6d09:48b7]) by smtp.gmail.com with ESMTPSA id 17-20020a05600c249100b003fbc30825fbsm17550010wms.39.2023.09.05.11.53.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Sep 2023 11:53:33 -0700 (PDT) From: Bartosz Golaszewski To: Aaro Koskinen , Janusz Krzysztofik , Tony Lindgren , Russell King , Mika Westerberg , Andy Shevchenko , Linus Walleij , Bartosz Golaszewski , Dipen Patel , Thierry Reding , Jonathan Hunter , Hans de Goede , Mark Gross Cc: linux-arm-kernel@lists.infradead.org, linux-omap@vger.kernel.org, linux-kernel@vger.kernel.org, linux-gpio@vger.kernel.org, linux-acpi@vger.kernel.org, timestamp@lists.linux.dev, linux-tegra@vger.kernel.org, platform-driver-x86@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH 06/21] gpiolib: provide gpiod_to_device() Date: Tue, 5 Sep 2023 20:52:54 +0200 Message-Id: <20230905185309.131295-7-brgl@bgdev.pl> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230905185309.131295-1-brgl@bgdev.pl> References: <20230905185309.131295-1-brgl@bgdev.pl> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230905_115338_069799_AE654432 X-CRM114-Status: GOOD ( 14.08 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Bartosz Golaszewski struct gpio_desc is opaque so provide a way for users to retrieve the underlying GPIO device. Signed-off-by: Bartosz Golaszewski Reviewed-by: Linus Walleij --- drivers/gpio/gpiolib.c | 14 ++++++++++++++ include/linux/gpio/driver.h | 1 + 2 files changed, 15 insertions(+) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 4a9af6bfc6d4..9637a79a9a60 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -219,6 +219,20 @@ struct gpio_chip *gpiod_to_chip(const struct gpio_desc *desc) } EXPORT_SYMBOL_GPL(gpiod_to_chip); +/** + * gpiod_to_device() - Return the GPIO device owning this descriptor + * @desc: GPIO descriptor + * + * Returns: + * Pointer to the opaque struct gpio_device object. This function does not + * increase the reference count of gpio_device. + */ +struct gpio_device *gpiod_to_device(struct gpio_desc *desc) +{ + return gpio_device_get(desc->gdev); +} +EXPORT_SYMBOL_GPL(gpiod_to_device); + /* dynamic allocation of GPIOs, e.g. on a hotplugged device */ static int gpiochip_find_base(int ngpio) { diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h index b2572b26c8e3..e3747e730ed1 100644 --- a/include/linux/gpio/driver.h +++ b/include/linux/gpio/driver.h @@ -778,6 +778,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_device(struct gpio_desc *desc); #else /* CONFIG_GPIOLIB */