From patchwork Fri Dec 3 13:29:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Bartosz Golaszewski X-Patchwork-Id: 520355 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 2B13AC43219 for ; Fri, 3 Dec 2021 13:30:30 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1381015AbhLCNdw (ORCPT ); Fri, 3 Dec 2021 08:33:52 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39474 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244813AbhLCNdv (ORCPT ); Fri, 3 Dec 2021 08:33:51 -0500 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 45C8DC06173E for ; Fri, 3 Dec 2021 05:30:27 -0800 (PST) Received: by mail-wr1-x42b.google.com with SMTP id j3so5808246wrp.1 for ; Fri, 03 Dec 2021 05:30:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bgdev-pl.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xqeLJfA6Oh1Rlp7lz59H7g3xKzDYJY/OKrjBpIm8aAE=; b=zWDuOzN/V1dH4p0NTobrVRwvt8EFsFmiBoNJYtFdS/IGfbAKPvdnxwSppNGZqcoRd6 fNnxE2FM1PxiUi6yDMtP5SOZvJRKzxNwVBtBIjmPY4TSn6Ez/hBeOmv7bDu0N+6Gnt5U 2xrhjVJu0cxrTSvS3gRkMworZxKSXNjdgWIOjhQVEyH+fRFjFvC2ZtilqBnq6VO4rQae 4sq3BTAUEIowDDKu75nE9t/bIVB1oV2h3LXm3PzK4OwNsN95H9TXxE60YixD0aEOppSm LGXRq6IEyW3NmTH3oHCdjVLYomlzdVQKbhDoK36EQPvfKmfFUeGUcKexN/Cz183tduu9 9ONg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xqeLJfA6Oh1Rlp7lz59H7g3xKzDYJY/OKrjBpIm8aAE=; b=EjjJaBCHoVoM82e6jXHGhwoZn6yW7FaHUoqwwcPn748DCvL92YgPQIWXVNJcgjLllC kMGdEa9C6Tw4ysw9j0X/95/QpfLDVxZXS+SC0sP1AJgzo52qQGiyzjcBTWwV2P6rLYJR vxAGyWQ8dkSRMXZm5pxuGMyJkEPOcOxfAQNLIeODxjCa+IBMaIaSeTP96SV5RfAzIuDH ZZKzoLDc6BXQIbp5J6si0cD2elQwyGT3ZA9dMmwDNYOzwVlc80uJjfQvJXSsjHbPwCBL hG+N1hF4HqPCiNh0kfjYNMtyCXQvtE7C26NxSNQcD1LJ/NJrp+x2enuyeN5NwO2lf5jw h6iA== X-Gm-Message-State: AOAM530vz9H1D4GCRx1riSlWbMQYtpHmpR8zHxvVaplmiuS0Hpw0UvG1 AbOr12FgvanuvOvvXm3i2XVBMA== X-Google-Smtp-Source: ABdhPJxpVAgKWu6RXur2Q/VtAQ4ojbemkc59901iwKJufP6rwcMMSvpUpn3W9blhJxr3jWobWC10Dw== X-Received: by 2002:a05:6000:1010:: with SMTP id a16mr21945249wrx.155.1638538225847; Fri, 03 Dec 2021 05:30:25 -0800 (PST) Received: from debian-brgl.home ([2a01:cb1d:334:ac00:7d50:ff5:f5c1:e225]) by smtp.gmail.com with ESMTPSA id j11sm2755910wrt.3.2021.12.03.05.30.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Dec 2021 05:30:25 -0800 (PST) From: Bartosz Golaszewski To: Kent Gibson , Linus Walleij , Andy Shevchenko , Shuah Khan , Geert Uytterhoeven , Viresh Kumar Cc: linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org, linux-kselftest@vger.kernel.org, Bartosz Golaszewski Subject: [PATCH v12 2/7] gpiolib: allow to specify the firmware node in struct gpio_chip Date: Fri, 3 Dec 2021 14:29:58 +0100 Message-Id: <20211203133003.31786-3-brgl@bgdev.pl> X-Mailer: git-send-email 2.30.1 In-Reply-To: <20211203133003.31786-1-brgl@bgdev.pl> References: <20211203133003.31786-1-brgl@bgdev.pl> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-gpio@vger.kernel.org Software nodes allow us to represent hierarchies for device components that don't have their struct device representation yet - for instance: banks of GPIOs under a common GPIO expander. The core gpiolib core however doesn't offer any way of passing this information from the drivers. This extends struct gpio_chip with a pointer to fwnode that can be set by the driver and used to pass device properties for child nodes. This is similar to how we handle device-tree sub-nodes with CONFIG_OF_GPIO enabled. Signed-off-by: Bartosz Golaszewski --- drivers/gpio/gpiolib.c | 7 ++++++- include/linux/gpio/driver.h | 2 ++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 22b98a590a88..6af732bf4c99 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -593,13 +593,18 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data, struct lock_class_key *lock_key, struct lock_class_key *request_key) { - struct fwnode_handle *fwnode = gc->parent ? dev_fwnode(gc->parent) : NULL; + struct fwnode_handle *fwnode = NULL; unsigned long flags; int ret = 0; unsigned i; int base = gc->base; struct gpio_device *gdev; + if (gc->fwnode) + fwnode = gc->fwnode; + else if (gc->parent) + fwnode = dev_fwnode(gc->parent); + /* * First: allocate and populate the internal stat container, and * set up the struct device. diff --git a/include/linux/gpio/driver.h b/include/linux/gpio/driver.h index a673a359e20b..b0728c8ad90c 100644 --- a/include/linux/gpio/driver.h +++ b/include/linux/gpio/driver.h @@ -289,6 +289,7 @@ struct gpio_irq_chip { * number or the name of the SoC IP-block implementing it. * @gpiodev: the internal state holder, opaque struct * @parent: optional parent device providing the GPIOs + * @fwnode: optional fwnode providing this controller's properties * @owner: helps prevent removal of modules exporting active GPIOs * @request: optional hook for chip-specific activation, such as * enabling module power and clock; may sleep @@ -377,6 +378,7 @@ struct gpio_chip { const char *label; struct gpio_device *gpiodev; struct device *parent; + struct fwnode_handle *fwnode; struct module *owner; int (*request)(struct gpio_chip *gc,