From patchwork Thu Feb 13 19:48:46 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 864898 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DA86324A06A; Thu, 13 Feb 2025 19:56:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.17 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739476589; cv=none; b=E5DDIM/nnShWj2ktudcNzkncKe7QvfG9UOMzlAkcdGhU8058WA3eWyL68bEXaPoKO6Ei+2tCNhh+amoztbuWcinMIhzqTP0H4PDu1b4787Wfty/xKg5L6zos3EiqckD+F/cFZSd70cj7lXEdBJiX0d1/JxKYT0IZQhZe3canQac= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739476589; c=relaxed/simple; bh=m3vAOwp3v5jm9IYwxdobl1MmrutpXhEMoaFY6XPFJXE=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mOYDAix5b+SZOSioVTA+Ejyj21gfmayp1/BWGSVemvtZq4kFHpO303LvC9Yd7DEhu3PFPPMakdmZP7X5Jgec37LyjCFB4m6MDWHcF/bfTw9Pa4LcPJCB03+aQlVAze5ERXyXLh5oDBxUFkAltR9YKrmiN1IaG/qKhaDB1k02Ly4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=QT3gjq7U; arc=none smtp.client-ip=192.198.163.17 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="QT3gjq7U" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1739476588; x=1771012588; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=m3vAOwp3v5jm9IYwxdobl1MmrutpXhEMoaFY6XPFJXE=; b=QT3gjq7UP/Lp8qMesemL14gZebmdmBA9TAed+ghQ9hLCwa3YCZFWGq5G e5fnK6sYKxIvVAcvhFzprPATpC1p+BV3z9NgPVJj3+y/6qFNsJvKVelSt R+Aqx/p9ktlTE4VJGk92fiizDPgMhknUNvQktb0AmcLksLwnUqee9MCin UQsWZxoWf2jWRdA7T5OtyzlDQqM4XEoYurPB5Qpw59luQLHCFtbbhkE9K BZRGLnaamwXXiB52Wrlze77lBBRHl7kDwX6ihdfEcM62sNM/UMjwXwOsU yCqAdVI0HU1X0h+ARgXpXfWnzjq0LPGgl0RDJDizz7eu4qNMkrAjjS5iy Q==; X-CSE-ConnectionGUID: /A1GEE69QSyowFGCJ+XTHw== X-CSE-MsgGUID: g1vUj12cTIWnYyWCRPxC1w== X-IronPort-AV: E=McAfee;i="6700,10204,11344"; a="40078534" X-IronPort-AV: E=Sophos;i="6.13,282,1732608000"; d="scan'208";a="40078534" Received: from orviesa001.jf.intel.com ([10.64.159.141]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Feb 2025 11:56:25 -0800 X-CSE-ConnectionGUID: kMwpz9emSkW/rhtm30yPnw== X-CSE-MsgGUID: WTPqt1mdSlCxQaUOdZKBgA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,224,1728975600"; d="scan'208";a="150421159" Received: from black.fi.intel.com ([10.237.72.28]) by orviesa001.jf.intel.com with ESMTP; 13 Feb 2025 11:56:24 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id F305A1F5; Thu, 13 Feb 2025 21:56:21 +0200 (EET) From: Andy Shevchenko To: Andy Shevchenko , Bartosz Golaszewski , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Michael Walle , Linus Walleij , Bartosz Golaszewski , athieu Dubois-Briand Subject: [PATCH v1 1/5] gpiolib: Extract gpiochip_choose_fwnode() for wider use Date: Thu, 13 Feb 2025 21:48:46 +0200 Message-ID: <20250213195621.3133406-2-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.45.1.3035.g276e886db78b In-Reply-To: <20250213195621.3133406-1-andriy.shevchenko@linux.intel.com> References: <20250213195621.3133406-1-andriy.shevchenko@linux.intel.com> Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Extract gpiochip_choose_fwnode() for the future use in another function. Signed-off-by: Andy Shevchenko --- drivers/gpio/gpiolib.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index d6ebdb2f2e92..0f93aa7736c6 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -883,6 +883,21 @@ void *gpiochip_get_data(struct gpio_chip *gc) } EXPORT_SYMBOL_GPL(gpiochip_get_data); +/* + * If the calling driver provides the specific firmware node, + * use it. Otherwise use the one from the parent device, if any. + */ +static struct fwnode_handle *gpiochip_choose_fwnode(struct gpio_chip *gc) +{ + if (gc->fwnode) + return gc->fwnode; + + if (gc->parent) + return dev_fwnode(gc->parent); + + return NULL; +} + int gpiochip_get_ngpios(struct gpio_chip *gc, struct device *dev) { u32 ngpios = gc->ngpio; @@ -942,14 +957,7 @@ int gpiochip_add_data_with_key(struct gpio_chip *gc, void *data, gc->gpiodev = gdev; gpiochip_set_data(gc, data); - /* - * If the calling driver did not initialize firmware node, - * do it here using the parent device, if any. - */ - if (gc->fwnode) - device_set_node(&gdev->dev, gc->fwnode); - else if (gc->parent) - device_set_node(&gdev->dev, dev_fwnode(gc->parent)); + device_set_node(&gdev->dev, gpiochip_choose_fwnode(gc)); gdev->id = ida_alloc(&gpio_ida, GFP_KERNEL); if (gdev->id < 0) { From patchwork Thu Feb 13 19:48:47 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 864899 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3838824A04C; Thu, 13 Feb 2025 19:56:25 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.17 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739476587; cv=none; b=dE2xVmCpMc20RC0SQXXsjIpNovy3JwIv4X1DIfqXMb8pO9Rdl7oJDhh5gJu3G/PW975LNTTcqVNpzvEBYEpz/njsz4Mwr2B70sr+iXIvG4oomkX/9GTA1I+YJoJDN5QMlkRZ4Aqdoq3T9W+lMTrRnBe+bkXSwU4J7iDN1o6hoFE= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739476587; c=relaxed/simple; bh=3SdugL5iTLTHLtxG9CDRWvnEvj74QRJ9r6nUGkd2tRc=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=kHf4eLMzoN+TP8gEa4Ui3ZTDJ7fnfmuJkh9015tLTT5SZvVyUgwVz7v6UtCJhdNDCJYTw1Oc73PhDbF25qzSKSF6jzWMK98zYvA/1295LCogRIi7MMJDWOKNHqcnUTiyHHIsLlNPjYnZ4pIlipz+A/2uPp6x+VrIMa/Y+GaXSn4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=nwEulxT+; arc=none smtp.client-ip=192.198.163.17 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="nwEulxT+" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1739476586; x=1771012586; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=3SdugL5iTLTHLtxG9CDRWvnEvj74QRJ9r6nUGkd2tRc=; b=nwEulxT+RrH4e51rLvbbb7ETtej7Eqqvp/KdxnOVgBmS3kJ9QkTgM5w8 /4rMgGNO/Hf2QNzVje7QS9JvKqVDa/ycGJJAaMXuh2opSHqAabCm805+Z o6AFjxdawKELsqO2gWlsl++AYwthKnhnb9vqLECeExrIbl+EYu5kg+qTU 5e9rZNR+nwUIdiFCJ26Z7a4NbAAYz+UBvHlnYXqCCy2WOZy7z7hff7mdb MIlQoS4cpT9LcF+I3O0Kr+U3t6dvDEPiw0W/gYsivhSyid26CUCDeGSkK owIriWv3+YOdjF9gXiD1FHSdgxFgIql6leXwol9q5pyt+XV9hNTIkTOv0 w==; X-CSE-ConnectionGUID: pPflms1QQI+R2b8ykYpZmg== X-CSE-MsgGUID: b5SxgA/mRu+6Y4tdQP/Cww== X-IronPort-AV: E=McAfee;i="6700,10204,11344"; a="40078530" X-IronPort-AV: E=Sophos;i="6.13,282,1732608000"; d="scan'208";a="40078530" Received: from orviesa001.jf.intel.com ([10.64.159.141]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Feb 2025 11:56:25 -0800 X-CSE-ConnectionGUID: L/wvlg1cQmWzSjHqq1JkNQ== X-CSE-MsgGUID: OKM3m+yzSi+qlOq9CB5nDA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,224,1728975600"; d="scan'208";a="150421158" Received: from black.fi.intel.com ([10.237.72.28]) by orviesa001.jf.intel.com with ESMTP; 13 Feb 2025 11:56:24 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id 139BB2CA; Thu, 13 Feb 2025 21:56:22 +0200 (EET) From: Andy Shevchenko To: Andy Shevchenko , Bartosz Golaszewski , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Michael Walle , Linus Walleij , Bartosz Golaszewski , athieu Dubois-Briand Subject: [PATCH v1 2/5] gpiolib: Use fwnode instead of device in gpiochip_get_ngpios() Date: Thu, 13 Feb 2025 21:48:47 +0200 Message-ID: <20250213195621.3133406-3-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.45.1.3035.g276e886db78b In-Reply-To: <20250213195621.3133406-1-andriy.shevchenko@linux.intel.com> References: <20250213195621.3133406-1-andriy.shevchenko@linux.intel.com> Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The gpiochip_get_ngpios() can be used in the cases where passed device is not a provider of the certain property. Use fwnode instead. Signed-off-by: Andy Shevchenko --- drivers/gpio/gpiolib.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index 0f93aa7736c6..0ede5e3eecfd 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -900,11 +900,12 @@ static struct fwnode_handle *gpiochip_choose_fwnode(struct gpio_chip *gc) int gpiochip_get_ngpios(struct gpio_chip *gc, struct device *dev) { + struct fwnode_handle *fwnode = gpiochip_choose_fwnode(gc); u32 ngpios = gc->ngpio; int ret; if (ngpios == 0) { - ret = device_property_read_u32(dev, "ngpios", &ngpios); + ret = fwnode_property_read_u32(fwnode, "ngpios", &ngpios); if (ret == -ENODATA) /* * -ENODATA means that there is no property found and From patchwork Thu Feb 13 19:48:48 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 865192 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5648824A07E; Thu, 13 Feb 2025 19:56:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.17 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739476589; cv=none; b=HWVoRQmAaQwfIGxePgkVFqXFxA9vFtrJGhNxDuCQrjcl1fqyexHZEMVdCWIIIRpd+YK3moq4snmdyR+VP+FJFB1qBvUe9fPEEsMcramBibGqTj6bi1KlFxfZnrpMJqFJIx8SIssm5qGYfrKgdClw+BMlre4NSWAbau2dz15m80Y= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739476589; c=relaxed/simple; bh=e86C71mshsm1vSox8d1u/ipm+lGPGwqYZMTfGlI8LvU=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cX9lZpCCnA2n23KfI9yI3DhJyFXszOiGhC1/N+ldd0D3tQt0l3UaMVCMF+ov4U/+T0BtCumB5/oFAn7YUlrggpy19jFxWJAG+E6Q9MJsj4nagI2g9v7hEu0c7id8Q2lv34B7/gyTFNns7P8WIOF0lPJhBqEq/Nom1BXyeQUgFKU= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=hYIF2Kpn; arc=none smtp.client-ip=192.198.163.17 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="hYIF2Kpn" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1739476588; x=1771012588; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=e86C71mshsm1vSox8d1u/ipm+lGPGwqYZMTfGlI8LvU=; b=hYIF2KpnR4wXRLWezPMoLoI5piLnM9TSGTLjZfZh5iF63gj+0c2CNI7v FkqZh5nwQ1NbDeWPSDrMBQfjrKiWpwtjkNu0LaU54lIfd8T1sginnqUc3 UgPxq2B6ou5es+00NqDuqYZ+Cjt+jt5jG9xC3MpjABVDWdvzfUzJtQBmV /V9d5tri/6rDRwOVE5jhHI/iXM8wtnec/jN9kvDmXTnW9xlc/tPxJEryS a9ew17MhOQOSHKynrXgvwuQ9eqSE3wcQnv/ZxUFDguCbqTzbOeP3v44Qn fo3IOWLLOYLSiZvggZMKmZkaStC9+FCq109Zazd8Bm6xX7ESkMhfyjDce A==; X-CSE-ConnectionGUID: b7DA7Ox/QpylVJ2NY2PQOw== X-CSE-MsgGUID: F9J8zHPRRWiNu1MYhbYzxA== X-IronPort-AV: E=McAfee;i="6700,10204,11344"; a="40078538" X-IronPort-AV: E=Sophos;i="6.13,282,1732608000"; d="scan'208";a="40078538" Received: from orviesa001.jf.intel.com ([10.64.159.141]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Feb 2025 11:56:26 -0800 X-CSE-ConnectionGUID: 2G6nTZXgRGC9pfwqBVnVnA== X-CSE-MsgGUID: vzh7xowATdqNdUdNGhjYDA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,224,1728975600"; d="scan'208";a="150421160" Received: from black.fi.intel.com ([10.237.72.28]) by orviesa001.jf.intel.com with ESMTP; 13 Feb 2025 11:56:24 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id 234CC31C; Thu, 13 Feb 2025 21:56:22 +0200 (EET) From: Andy Shevchenko To: Andy Shevchenko , Bartosz Golaszewski , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Michael Walle , Linus Walleij , Bartosz Golaszewski , athieu Dubois-Briand Subject: [PATCH v1 3/5] gpio: regmap: Group optional assignments together for better understanding Date: Thu, 13 Feb 2025 21:48:48 +0200 Message-ID: <20250213195621.3133406-4-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.45.1.3035.g276e886db78b In-Reply-To: <20250213195621.3133406-1-andriy.shevchenko@linux.intel.com> References: <20250213195621.3133406-1-andriy.shevchenko@linux.intel.com> Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Group ngpio_per_reg, reg_stride, and reg_mask_xlate assignments together with the respective conditional for better understanding what's going on in the code. While at it, mark ngpio_per_reg as (Optional) in the kernel-doc in accordance with what code actually does. Signed-off-by: Andy Shevchenko --- drivers/gpio/gpio-regmap.c | 6 +++--- include/linux/gpio/regmap.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/gpio/gpio-regmap.c b/drivers/gpio/gpio-regmap.c index 05f8781b5204..7775b0c56602 100644 --- a/drivers/gpio/gpio-regmap.c +++ b/drivers/gpio/gpio-regmap.c @@ -233,9 +233,6 @@ struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config gpio->parent = config->parent; gpio->driver_data = config->drvdata; gpio->regmap = config->regmap; - gpio->ngpio_per_reg = config->ngpio_per_reg; - gpio->reg_stride = config->reg_stride; - gpio->reg_mask_xlate = config->reg_mask_xlate; gpio->reg_dat_base = config->reg_dat_base; gpio->reg_set_base = config->reg_set_base; gpio->reg_clr_base = config->reg_clr_base; @@ -243,13 +240,16 @@ struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config gpio->reg_dir_out_base = config->reg_dir_out_base; /* if not set, assume there is only one register */ + gpio->ngpio_per_reg = config->ngpio_per_reg; if (!gpio->ngpio_per_reg) gpio->ngpio_per_reg = config->ngpio; /* if not set, assume they are consecutive */ + gpio->reg_stride = config->reg_stride; if (!gpio->reg_stride) gpio->reg_stride = 1; + gpio->reg_mask_xlate = config->reg_mask_xlate; if (!gpio->reg_mask_xlate) gpio->reg_mask_xlate = gpio_regmap_simple_xlate; diff --git a/include/linux/gpio/regmap.h b/include/linux/gpio/regmap.h index a9f7b7faf57b..b9240e4156cc 100644 --- a/include/linux/gpio/regmap.h +++ b/include/linux/gpio/regmap.h @@ -30,7 +30,7 @@ struct regmap; * @reg_dir_out_base: (Optional) out setting register base address * @reg_stride: (Optional) May be set if the registers (of the * same type, dat, set, etc) are not consecutive. - * @ngpio_per_reg: Number of GPIOs per register + * @ngpio_per_reg: (Optional) Number of GPIOs per register * @irq_domain: (Optional) IRQ domain if the controller is * interrupt-capable * @reg_mask_xlate: (Optional) Translates base address and GPIO From patchwork Thu Feb 13 19:48:49 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 864897 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.14]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id DCB4F24BBF6; Thu, 13 Feb 2025 19:56:28 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.14 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739476590; cv=none; b=TbULhmkA3xZcYyYqvqp7GWQHOGlytaHelAIEvfPDNF0xSHZzbKhCM7H+uS5Gs9Fd98k0SfJIbHTwAgqdv6EhXnZs36W7BUo1GCfUVpHoPP+cY1VEMXfJ8vi0q8GF081db0uPrBNOo5OY92lewt8OU+XU4s34mlo7/n5BY5nYh1E= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739476590; c=relaxed/simple; bh=iHwGxYpMwuP2zk+GRPxjAQdMF+OcbFeFkFYimRgAIwk=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eShsGQKtNPf7TZRMKPUr8Sn5Jj7aJAh8xz/LNR3B+3fy8HHPS1L/JM1D9bGu19sScVZ2p6y/byrF+SLtROMNq14GSD90V2oJ6i+wwPxXBBd0qlQ9Q7f6ZHyEHpvhq/pVmjFpYBgvlT6Q8pZRXTB5RwYdQICTtJBOVrjtOJqqPOs= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=in9Omtpn; arc=none smtp.client-ip=192.198.163.14 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="in9Omtpn" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1739476589; x=1771012589; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=iHwGxYpMwuP2zk+GRPxjAQdMF+OcbFeFkFYimRgAIwk=; b=in9Omtpn0LWRHojMoxkJyywusbANONnMsqOtsOatOFLyC/qbrZnNSTCw G7K63pNQpm1tEM2ULU5vTFJVD8bq94mF2b/KfDXHsHQI56Xo5zCOi+aTA VKJz3lPSCOagNDAp703/4tb6W5AmRbeHS55fTgPgnOeOe9EfXPmOQhZNM 8ivhRYqUSZXLevfUipny1N36nPwe5C8QLqRHRKPmGSTP7kRTUgmiwzhzL j6YfxtIMpgSgcrHU7qN7x4pMlSz3r23RNQZi4xajwxPbYKaBuuQ4N9rl+ Dmr2wWwADROQSBcbP0X34P7RSHi2RfeZh/yaUlmvk6Jwt7C/xI8ECAciv Q==; X-CSE-ConnectionGUID: +wYp0r/RRxySrPGnMjDX6A== X-CSE-MsgGUID: s54JVnbSSxqG85m1MBJYTg== X-IronPort-AV: E=McAfee;i="6700,10204,11344"; a="40466025" X-IronPort-AV: E=Sophos;i="6.13,282,1732608000"; d="scan'208";a="40466025" Received: from orviesa007.jf.intel.com ([10.64.159.147]) by fmvoesa108.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Feb 2025 11:56:25 -0800 X-CSE-ConnectionGUID: xKuVD2+eTm+le5ugCOVjNQ== X-CSE-MsgGUID: A6XCuCTJRkSKvLntjR+1ug== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,224,1728975600"; d="scan'208";a="113745542" Received: from black.fi.intel.com ([10.237.72.28]) by orviesa007.jf.intel.com with ESMTP; 13 Feb 2025 11:56:23 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id 32CB3322; Thu, 13 Feb 2025 21:56:22 +0200 (EET) From: Andy Shevchenko To: Andy Shevchenko , Bartosz Golaszewski , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Michael Walle , Linus Walleij , Bartosz Golaszewski , athieu Dubois-Briand Subject: [PATCH v1 4/5] gpio: regmap: Move optional assignments down in the code Date: Thu, 13 Feb 2025 21:48:49 +0200 Message-ID: <20250213195621.3133406-5-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.45.1.3035.g276e886db78b In-Reply-To: <20250213195621.3133406-1-andriy.shevchenko@linux.intel.com> References: <20250213195621.3133406-1-andriy.shevchenko@linux.intel.com> Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Move optional assignments down in the code, so they may use some values from the (updated) struct gpio_chip later on. Signed-off-by: Andy Shevchenko --- drivers/gpio/gpio-regmap.c | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/drivers/gpio/gpio-regmap.c b/drivers/gpio/gpio-regmap.c index 7775b0c56602..41ee576e7cd0 100644 --- a/drivers/gpio/gpio-regmap.c +++ b/drivers/gpio/gpio-regmap.c @@ -239,20 +239,6 @@ struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config gpio->reg_dir_in_base = config->reg_dir_in_base; gpio->reg_dir_out_base = config->reg_dir_out_base; - /* if not set, assume there is only one register */ - gpio->ngpio_per_reg = config->ngpio_per_reg; - if (!gpio->ngpio_per_reg) - gpio->ngpio_per_reg = config->ngpio; - - /* if not set, assume they are consecutive */ - gpio->reg_stride = config->reg_stride; - if (!gpio->reg_stride) - gpio->reg_stride = 1; - - gpio->reg_mask_xlate = config->reg_mask_xlate; - if (!gpio->reg_mask_xlate) - gpio->reg_mask_xlate = gpio_regmap_simple_xlate; - chip = &gpio->gpio_chip; chip->parent = config->parent; chip->fwnode = config->fwnode; @@ -276,6 +262,20 @@ struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config chip->direction_output = gpio_regmap_direction_output; } + /* if not set, assume there is only one register */ + gpio->ngpio_per_reg = config->ngpio_per_reg; + if (!gpio->ngpio_per_reg) + gpio->ngpio_per_reg = config->ngpio; + + /* if not set, assume they are consecutive */ + gpio->reg_stride = config->reg_stride; + if (!gpio->reg_stride) + gpio->reg_stride = 1; + + gpio->reg_mask_xlate = config->reg_mask_xlate; + if (!gpio->reg_mask_xlate) + gpio->reg_mask_xlate = gpio_regmap_simple_xlate; + ret = gpiochip_add_data(chip, gpio); if (ret < 0) goto err_free_gpio; From patchwork Thu Feb 13 19:48:50 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 865191 Received: from mgamail.intel.com (mgamail.intel.com [192.198.163.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 90B2524BC11; Thu, 13 Feb 2025 19:56:29 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=192.198.163.17 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739476591; cv=none; b=CQnuFkY/lo2wkA8BNZ4NPjFlsPi4J6ld/YlfaLxw2/VxaJ2qOWVSYLj9ZPDEOENRjA44k8I0Qwyw9cPBW2lDd7vKGgWE77FsKcDdy7AYB+SYI+NA1uJP1rWYfk0PPPQRuBwb1t707OvloApcH+oHE+xKpu8i2+3WRLRovmdSV78= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739476591; c=relaxed/simple; bh=PJmRW2KaIfrpizikoDdSsfo6z+i8RUkbQGWcNuTn1m8=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=gYFj9qTE5KMEK5JlhZjflrXMS+Fc+37SK1eL9lgMJQ6nNmnb/fHmWsRjKcalbvdg/TM/3ilD/ez2yR964HP+/3Cb/2b1zV424WkSuzA96H5fbJgo1+Q090kXLiZtUvU0AvmmKSd4LkCEFRm7ByFyfk2Bu5PSVBo8EOvGhQPbSkA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com; spf=none smtp.mailfrom=linux.intel.com; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b=j3cQLwhw; arc=none smtp.client-ip=192.198.163.17 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; spf=none smtp.mailfrom=linux.intel.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=intel.com header.i=@intel.com header.b="j3cQLwhw" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1739476589; x=1771012589; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=PJmRW2KaIfrpizikoDdSsfo6z+i8RUkbQGWcNuTn1m8=; b=j3cQLwhw9rrmcchGmrcWd9LFA+yE/jHi5WXKAU+LZyv/Iq5oKQzo0waB m7cOsMQ5qPY9s+yy228BGX5RJEtbtLB0i254/wGfrE6a8uhW6iAJg9SwT kQMtTvlaXFw9iuJ6/qrNehe88OworooHFvArOSYrNoLdBIvT/1kYZnzT6 f0MUWVjaBiIZL+ysK4lFoIowA4wQveL3ccw+zrGYd0lytFEKdHrVWk3ua PM7pVU/S3tUxTvvp/j+3USpiGNPHOjWOmSPcqwzSZj27uPluMqg40ze+m rxWnJmpqh62MWq5K8jKuT9mmoVVBjTB2nHI0LEiNtKeskZEfQk1vPt6aE g==; X-CSE-ConnectionGUID: moXuq2SQShKtqD4nmSPN8w== X-CSE-MsgGUID: KuzlKpVdRk6ADCdn4d8gjA== X-IronPort-AV: E=McAfee;i="6700,10204,11344"; a="40078548" X-IronPort-AV: E=Sophos;i="6.13,282,1732608000"; d="scan'208";a="40078548" Received: from orviesa001.jf.intel.com ([10.64.159.141]) by fmvoesa111.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 13 Feb 2025 11:56:28 -0800 X-CSE-ConnectionGUID: I+8HbDY6RvGH7W7Paeh5Rw== X-CSE-MsgGUID: AZJKqqLORUODhGoCsOzjWQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="6.12,224,1728975600"; d="scan'208";a="150421164" Received: from black.fi.intel.com ([10.237.72.28]) by orviesa001.jf.intel.com with ESMTP; 13 Feb 2025 11:56:27 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id 3E6673BA; Thu, 13 Feb 2025 21:56:22 +0200 (EET) From: Andy Shevchenko To: Andy Shevchenko , Bartosz Golaszewski , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Michael Walle , Linus Walleij , Bartosz Golaszewski , athieu Dubois-Briand Subject: [PATCH v1 5/5] gpio: regmap: Allow ngpio to be read from the property Date: Thu, 13 Feb 2025 21:48:50 +0200 Message-ID: <20250213195621.3133406-6-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.45.1.3035.g276e886db78b In-Reply-To: <20250213195621.3133406-1-andriy.shevchenko@linux.intel.com> References: <20250213195621.3133406-1-andriy.shevchenko@linux.intel.com> Precedence: bulk X-Mailing-List: linux-gpio@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 GPIOLIB supports the case when number of supported GPIOs can be read from the device property. Enable this for drivers that are using GPIO regmap layer. Signed-off-by: Andy Shevchenko --- drivers/gpio/gpio-regmap.c | 13 +++++++++---- include/linux/gpio/regmap.h | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/drivers/gpio/gpio-regmap.c b/drivers/gpio/gpio-regmap.c index 41ee576e7cd0..856f8569566e 100644 --- a/drivers/gpio/gpio-regmap.c +++ b/drivers/gpio/gpio-regmap.c @@ -17,6 +17,8 @@ #include #include +#include "gpiolib.h" + struct gpio_regmap { struct device *parent; struct regmap *regmap; @@ -210,9 +212,6 @@ struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config if (!config->parent) return ERR_PTR(-EINVAL); - if (!config->ngpio) - return ERR_PTR(-EINVAL); - /* we need at least one */ if (!config->reg_dat_base && !config->reg_set_base) return ERR_PTR(-EINVAL); @@ -243,7 +242,6 @@ struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config chip->parent = config->parent; chip->fwnode = config->fwnode; chip->base = -1; - chip->ngpio = config->ngpio; chip->names = config->names; chip->label = config->label ?: dev_name(config->parent); chip->can_sleep = regmap_might_sleep(config->regmap); @@ -262,6 +260,13 @@ struct gpio_regmap *gpio_regmap_register(const struct gpio_regmap_config *config chip->direction_output = gpio_regmap_direction_output; } + chip->ngpio = config->ngpio; + if (!chip->ngpio) { + ret = gpiochip_get_ngpios(chip, chip->parent); + if (ret) + return ERR_PTR(ret); + } + /* if not set, assume there is only one register */ gpio->ngpio_per_reg = config->ngpio_per_reg; if (!gpio->ngpio_per_reg) diff --git a/include/linux/gpio/regmap.h b/include/linux/gpio/regmap.h index b9240e4156cc..c722c67668c6 100644 --- a/include/linux/gpio/regmap.h +++ b/include/linux/gpio/regmap.h @@ -21,7 +21,7 @@ struct regmap; * If not given, the fwnode of the parent is used. * @label: (Optional) Descriptive name for GPIO controller. * If not given, the name of the device is used. - * @ngpio: Number of GPIOs + * @ngpio: (Optional) Number of GPIOs * @names: (Optional) Array of names for gpios * @reg_dat_base: (Optional) (in) register base address * @reg_set_base: (Optional) set register base address