From patchwork Tue Sep 5 18:52:57 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 720296 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 E6D31C83F3E for ; Tue, 5 Sep 2023 19:13:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235339AbjIETNB (ORCPT ); Tue, 5 Sep 2023 15:13:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60098 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242373AbjIETMy (ORCPT ); Tue, 5 Sep 2023 15:12:54 -0400 Received: from mail-ed1-x532.google.com (mail-ed1-x532.google.com [IPv6:2a00:1450:4864:20::532]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 32D28CFE for ; Tue, 5 Sep 2023 12:12:25 -0700 (PDT) Received: by mail-ed1-x532.google.com with SMTP id 4fb4d7f45d1cf-5298e43bb67so351135a12.1 for ; Tue, 05 Sep 2023 12:12:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20230601.gappssmtp.com; s=20230601; t=1693941075; x=1694545875; 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=LktKQq4MWoQ/qKoiT9d7DgSnCPQ1kCPUYmKK3IZgeGM=; b=3cNz/rsOHFO/TU6B62Xp/VhlAk7MGki89oAXs9X6H4mo4QfRV0PSzbkKBUfsQZpmmQ oEMfiL/nQ6uEYxfwuaM7acMf2hTJ8Ikou3vA0vXhtonMuBtlCOvJEdz7t9rexJIIlRze MlkFmdI8WoBIfYx7BSc/cfBln5tVjqYPOLGWTjuBp6otOKWqcsBba8ZrY9Oq2HGbKYSU 4ZbgMH6h1YvPCLFdPGY001y5yT1GKTBnnh9RClyumGgZVJrtaokyHdXEZFNQfwIGVKml d/W3M2NA7c+riQ7YJ4ywLy+rYFLQhyA2WVL/Pl1URdrEcisaTUs+l3HCemUKFIQYjlYq 0+/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1693941075; x=1694545875; 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=LktKQq4MWoQ/qKoiT9d7DgSnCPQ1kCPUYmKK3IZgeGM=; b=QaVH1w4ZtTgk/2XcsbS7lY2SFxJfwD+2WOL/6dJWxtQEYgxXLLvIfgQ5Frm7hvdkbS d46JdnrE0bzeBM53NDy7NYO3gVxsFzvTwmqSCqnrr09rbQ6PVw2H+7/XOGPTpmqjLBzh ujHDLEpYWJLOkZhzeS3dksHyysZgWlnPEflFV2Ki2W+XxtdpKTLbV8GT+EIhv/kJBpVe Iqx4YypZJoK8sivt6wu27nMXQyZzer2fuw4Xx1L2g1QOWPvU46XQXTh2Z6g++s58HLbm 0TxuJy2/w/9CGBBBhjgJOuwcWqhg3S6EvoqSW4fAWF66gLMTgUC9VO+BMunH5ualZYaD 1MSw== X-Gm-Message-State: AOJu0Yyv5kaDBmo3vyG5UoODkqoS8vLH/3sXS2rZlIlkvuI4p/3+md+h JvSKbBSQzXzq+0jSL2ZcmPCHN/NXKU6tSzsy0g0= X-Google-Smtp-Source: AGHT+IEKE+XCvxCtmXJO+rvvHv5Ifn1+auM+4ZurnpxJ8t+aLjhMPMETigx/CB4V/gfiHQTOepYw2A== X-Received: by 2002:a05:600c:4b1f:b0:401:bcec:be3e with SMTP id i31-20020a05600c4b1f00b00401bcecbe3emr598796wmp.17.1693940017155; Tue, 05 Sep 2023 11:53:37 -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.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Sep 2023 11:53:36 -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 09/21] gpiolib: reluctantly provide gpio_device_get_chip() Date: Tue, 5 Sep 2023 20:52:57 +0200 Message-Id: <20230905185309.131295-10-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 Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org From: Bartosz Golaszewski The process of converting all unauthorized users of struct gpio_chip to using dedicated struct gpio_device function will be long so in the meantime we must provide a way of retrieving the pointer to struct gpio_chip from a GPIO device. Signed-off-by: Bartosz Golaszewski Reviewed-by: Linus Walleij --- drivers/gpio/gpiolib.c | 18 ++++++++++++++++++ include/linux/gpio/driver.h | 1 + 2 files changed, 19 insertions(+) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 9715bbc698e9..408f8a7753f9 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -246,6 +246,24 @@ int gpio_device_get_base(struct gpio_device *gdev) } EXPORT_SYMBOL_GPL(gpio_device_get_base); +/** + * gpio_device_get_chip() - Get the gpio_chip implementation of this GPIO device + * @gdev: GPIO device + * + * Until we can get rid of all non-driver users struct gpio_chip, we must + * provide a way of retrieving the pointer to it from struct gpio_device. This + * is *NOT* safe as the GPIO API is considered to be hot-unpluggable and the + * chip can dissapear at any moment (unlike reference-counted struct + * gpio_device). + * + * Use at your own risk. + */ +struct gpio_chip *gpio_device_get_chip(struct gpio_device *gdev) +{ + return gdev->chip; +} +EXPORT_SYMBOL_GPL(gpio_device_get_chip); + /* 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 47906bc56b3d..bb9ec741bfda 100644 --- a/include/linux/gpio/driver.h +++ b/include/linux/gpio/driver.h @@ -782,6 +782,7 @@ struct gpio_device *gpiod_to_device(struct gpio_desc *desc); /* struct gpio_device getters */ int gpio_device_get_base(struct gpio_device *gdev); +struct gpio_chip *gpio_device_get_chip(struct gpio_device *gdev); #else /* CONFIG_GPIOLIB */