From patchwork Mon Nov 7 16:10:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 16530 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2146362wru; Mon, 7 Nov 2022 08:12:30 -0800 (PST) X-Google-Smtp-Source: AMsMyM7ZwFxSNcsEBPDn2ZxKL9EbcRvngeI72N5FEGjWEWyv8e9Spx4tNecBGC+wsiCLRoK70/k8 X-Received: by 2002:a17:907:1ddd:b0:7ad:8371:b59c with SMTP id og29-20020a1709071ddd00b007ad8371b59cmr48089211ejc.429.1667837550008; Mon, 07 Nov 2022 08:12:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667837549; cv=none; d=google.com; s=arc-20160816; b=F7iSxkKpOjZXBU5ENTHoKcw/itcU+GN3Nyjz5HAPcMSHNHQBubnJCVd1PMks+2QagK yeH5McL+zpW88yhYiXxamXDVm26oSHNN/FoGdFKNTpLpNTIyuN79FAaod28CGfaCUsyX QrqLnUrJ4z5QkFplEs0XoyPTbtullSNSfMXHoEz/fviA2pa6ETGjX/749/VtviePcEWS Nc2dtB+2U9a6S1kpgei9yJBrLgsztLaFEbmUiPuF6s0a7h2r5jI+AHhZjjqLESNK0bL0 mpUB5uf8Fkis+N7E6Ia05LYa33602pJ1YklapSjrbSq1Abc5ucz/O+5MiPX6MN9ucmwr DLRA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=no7TWWWNoTkvMbZtOyrNAwYUs0xdDSVaWEAJ3skqk+o=; b=rogrOoFn8UJsVP+EsaGrsmgb8LlMiZJf2HdX/IGm/bm8Y1wz4s9lL6LXS5bmUwxPQF XBr4qLLA5PVtIgJFsxqjvNmmWdz5xSStBWHObRx5e+O+OVrSbOgBKRXaTalD/CSuzQwl VvJWjTbNxrakwijHoETMsHIqc+yeHH8yUNEPPbScq1TutRTcmctRanUtzSg0z3F00bOy j7n14rSjRXHF7JM179KGFr7tNC00i/97yPnjLHFlucwZ0gz+MCWsSZGLSPU7RqZg9/a9 RCaKoyGOm3rIVbo0O1tNAUK+but0nkIhh5CjeJjdwS0lBHprMHXbhuRB4v2d81AaP4fW XZ3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=MVthJ47D; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e24-20020a50a698000000b0045938ab7129si8627555edc.330.2022.11.07.08.12.05; Mon, 07 Nov 2022 08:12:29 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=MVthJ47D; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232345AbiKGQLH (ORCPT + 99 others); Mon, 7 Nov 2022 11:11:07 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35176 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231557AbiKGQLE (ORCPT ); Mon, 7 Nov 2022 11:11:04 -0500 Received: from mga14.intel.com (mga14.intel.com [192.55.52.115]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 23BF9254; Mon, 7 Nov 2022 08:11:04 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1667837464; x=1699373464; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=/kSwwswIzgCUAxVBjbvEobr7bEAkyBfEjUc94Vf2hq4=; b=MVthJ47D5e0Q/HsA/oSXeNIhCmeE81stHEEqQ+vuIxLbaiEXwC5TTUht ADRZ/9c+kQmvqJoV+O9yhemIpm0B+Y+XhVb5DVgCJOF7v9KNB0OJqPRfK eNpEm5Nn/08LVu9nxLukGbl081mDISD3IHAFh2e90RtTRISvGPffNHX5o j+nXQ3AyE0Qa031B+v0h41qczPP44NPASdyVasOk/jF1dm1M2X1W8piSE HkKrMHv1Vbwt4Fhm67+e6aRqgdFfszx2mZEvupxwRw4wWwXZi99Ikqmaj oCLqeLKD1XYWe8XflwfvXpkME5ArLyyMTcYemQwcvjuDshZkukYjUXHUE w==; X-IronPort-AV: E=McAfee;i="6500,9779,10524"; a="310451919" X-IronPort-AV: E=Sophos;i="5.96,145,1665471600"; d="scan'208";a="310451919" Received: from fmsmga001.fm.intel.com ([10.253.24.23]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Nov 2022 08:10:09 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10524"; a="778543956" X-IronPort-AV: E=Sophos;i="5.96,145,1665471600"; d="scan'208";a="778543956" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga001.fm.intel.com with ESMTP; 07 Nov 2022 08:10:08 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id E6B49F7; Mon, 7 Nov 2022 18:10:31 +0200 (EET) From: Andy Shevchenko To: Bartosz Golaszewski , Dmitry Torokhov , Andy Shevchenko , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Linus Walleij Subject: [PATCH v1 1/2] gpiolib: of: Prepare of_gpiochip_add() / of_gpiochip_remove() for fwnode Date: Mon, 7 Nov 2022 18:10:26 +0200 Message-Id: <20221107161027.43384-1-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 X-Spam-Status: No, score=-7.0 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_HI,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748854426672905051?= X-GMAIL-MSGID: =?utf-8?q?1748854426672905051?= GPIO library is getting rid of of_node, fwnode should be utilized instead. Prepare of_gpiochip_add() / of_gpiochip_remove() for fwnode. Signed-off-by: Andy Shevchenko Reviewed-by: Dmitry Torokhov --- drivers/gpio/gpiolib-of.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c index be9c34cca322..000020eb78d8 100644 --- a/drivers/gpio/gpiolib-of.c +++ b/drivers/gpio/gpiolib-of.c @@ -1104,9 +1104,11 @@ static int of_gpiochip_add_pin_range(struct gpio_chip *chip) { return 0; } int of_gpiochip_add(struct gpio_chip *chip) { + struct device_node *np; int ret; - if (!chip->of_node) + np = to_of_node(chip->fwnode); + if (!np) return 0; if (!chip->of_xlate) { @@ -1123,18 +1125,18 @@ int of_gpiochip_add(struct gpio_chip *chip) if (ret) return ret; - of_node_get(chip->of_node); + fwnode_handle_get(chip->fwnode); ret = of_gpiochip_scan_gpios(chip); if (ret) - of_node_put(chip->of_node); + fwnode_handle_put(chip->fwnode); return ret; } void of_gpiochip_remove(struct gpio_chip *chip) { - of_node_put(chip->of_node); + fwnode_handle_put(chip->fwnode); } void of_gpio_dev_init(struct gpio_chip *gc, struct gpio_device *gdev) From patchwork Mon Nov 7 16:10:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 16529 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:6687:0:0:0:0:0 with SMTP id l7csp2146025wru; Mon, 7 Nov 2022 08:12:00 -0800 (PST) X-Google-Smtp-Source: AMsMyM4kJ7ff6MvsLogTmps+mTqBakwpHI3F7OVzCXPEGPOMxCnC3cBFdmU8znY3T8G5rjfoEpxJ X-Received: by 2002:a05:6402:2793:b0:462:39d7:3bbc with SMTP id b19-20020a056402279300b0046239d73bbcmr51110678ede.47.1667837519883; Mon, 07 Nov 2022 08:11:59 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1667837519; cv=none; d=google.com; s=arc-20160816; b=jVgFdFSJYFoAy/Yjsxyt+rypUgawYnEiSbx7g5VVXDl4nclsn8hFxslH5V27K5GQKc J5TOSRUVw5oX8Oftc0fmplPc3/Pr4N5fekEOhK4fdwbpyAcpgMuqT7NeB3Z4lYQfwwqj S/mNFz6B4gMveMDsNJvkel74FclMTRZ5TFVuSWF6ViXX6YMolgwE4m/Bxh1AS6bNG84u nepZuP1vRcyiLHP/+SG71fpDan2oUcQlFsFuYWhlnaYL1qIU2bnkM1ATE8V85M5+p3Yy +xyf523RmdqgqWOE6v6TUWIMDMAcbabRejXVPMLEOWIQg0I5osPpeDMbuDZi6upaot53 7nrQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=woUzUGKoJvD3DMEFoWLefCcVMZagLinvwQnCs44kjD4=; b=s3H8l9gwCNLpU4BxqkZRPWgBlBZTe5CuvV067pkybzFKy7+/BlNsfkDOx/b3QDRo5G ARNlEenZi8G1cHJ9eh7VtRa7Eo7JhV//196SurdGqYMoBFYsWuSiAByBFRuE6FMtyRZn f32YI9QcjAVWad54MzR1qoehw5CWma+FjhFej5IrbmRDnbYRx82fmH46RaeoQzxEOpD2 2VwN3zcSjkaL9iW+m4BALVAdr71rZxKuwO3jbdPX58RljgsjJNzW76dv/UYykyiKkGaY CEnXO6azCRvOdOTMEVHWYtZEVGUDyMaRvbu9cLhk5xU3/Rasal2nCQxhRv6d07KkubR9 f25Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=gPV4zWBu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h2-20020a17090619c200b0078e27f2ef52si6760274ejd.603.2022.11.07.08.11.35; Mon, 07 Nov 2022 08:11:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=gPV4zWBu; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232533AbiKGQKY (ORCPT + 99 others); Mon, 7 Nov 2022 11:10:24 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34564 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232511AbiKGQKT (ORCPT ); Mon, 7 Nov 2022 11:10:19 -0500 Received: from mga03.intel.com (mga03.intel.com [134.134.136.65]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 48E0413FBE; Mon, 7 Nov 2022 08:10:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1667837410; x=1699373410; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=ob2VcCD8eQ1INAspt4Ij3GP7vl0BcLPuHM41kGRdqME=; b=gPV4zWBuSiQIcYQUcRggBpU+pUC+f5u+9OlIDhTC82vgN7Rw9v4cOueW vXVMqieMyOltjxggqFxyE+whEc6NuTOnP9YP6GahSBL5s+cmRMj1QOBD8 OBCJI3qbhYYaRAd4FqcH4u/ACcK/OUjokQWBotfLzNvezp8QVikQbllzp MYnCGBNdjpLPJ/T4xnKLD+dRzw3bOFBRSFF2ZMWNFzjRrfgk9T25z+aTR wWF2BStZK6JOS6Mn119K16ERnYVIPHIJKyDdvTvbMS7jCdneRxlRnOV2T FLwRwA8cPLmIFr55f+cHl24unT730sBWjUWyOHJFymeaE6LTdgpdh0fQR g==; X-IronPort-AV: E=McAfee;i="6500,9779,10524"; a="312215920" X-IronPort-AV: E=Sophos;i="5.96,145,1665471600"; d="scan'208";a="312215920" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 07 Nov 2022 08:10:09 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10524"; a="613910899" X-IronPort-AV: E=Sophos;i="5.96,145,1665471600"; d="scan'208";a="613910899" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga006.jf.intel.com with ESMTP; 07 Nov 2022 08:10:08 -0800 Received: by black.fi.intel.com (Postfix, from userid 1003) id F0074D0; Mon, 7 Nov 2022 18:10:31 +0200 (EET) From: Andy Shevchenko To: Bartosz Golaszewski , Dmitry Torokhov , Andy Shevchenko , linux-gpio@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Linus Walleij Subject: [PATCH v1 2/2] gpiolib: of: Integrate of_gpiochip_init_valid_mask() into gpiochip_init_valid_mask() Date: Mon, 7 Nov 2022 18:10:27 +0200 Message-Id: <20221107161027.43384-2-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20221107161027.43384-1-andriy.shevchenko@linux.intel.com> References: <20221107161027.43384-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 X-Spam-Status: No, score=-4.3 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_NONE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1748854395692984519?= X-GMAIL-MSGID: =?utf-8?q?1748854395692984519?= In preparation to complete fwnode switch, integrate of_gpiochip_init_valid_mask() into gpiochip_init_valid_mask(). Signed-off-by: Andy Shevchenko Reviewed-by: Dmitry Torokhov --- drivers/gpio/gpiolib-of.c | 42 ------------------------------- drivers/gpio/gpiolib-of.h | 5 ---- drivers/gpio/gpiolib.c | 52 ++++++++++++++++++++++++++++++++++++++- 3 files changed, 51 insertions(+), 48 deletions(-) diff --git a/drivers/gpio/gpiolib-of.c b/drivers/gpio/gpiolib-of.c index 000020eb78d8..4be3c21aa718 100644 --- a/drivers/gpio/gpiolib-of.c +++ b/drivers/gpio/gpiolib-of.c @@ -112,24 +112,6 @@ static struct gpio_desc *of_xlate_and_get_gpiod_flags(struct gpio_chip *chip, return gpiochip_get_desc(chip, ret); } -/** - * of_gpio_need_valid_mask() - figure out if the OF GPIO driver needs - * to set the .valid_mask - * @gc: the target gpio_chip - * - * Return: true if the valid mask needs to be set - */ -bool of_gpio_need_valid_mask(const struct gpio_chip *gc) -{ - int size; - const struct device_node *np = gc->of_node; - - size = of_property_count_u32_elems(np, "gpio-reserved-ranges"); - if (size > 0 && size % 2 == 0) - return true; - return false; -} - /* * Overrides stated polarity of a gpio line and warns when there is a * discrepancy. @@ -989,28 +971,6 @@ void of_mm_gpiochip_remove(struct of_mm_gpio_chip *mm_gc) } EXPORT_SYMBOL_GPL(of_mm_gpiochip_remove); -static void of_gpiochip_init_valid_mask(struct gpio_chip *chip) -{ - int len, i; - u32 start, count; - struct device_node *np = chip->of_node; - - len = of_property_count_u32_elems(np, "gpio-reserved-ranges"); - if (len < 0 || len % 2 != 0) - return; - - for (i = 0; i < len; i += 2) { - of_property_read_u32_index(np, "gpio-reserved-ranges", - i, &start); - of_property_read_u32_index(np, "gpio-reserved-ranges", - i + 1, &count); - if (start >= chip->ngpio || start + count > chip->ngpio) - continue; - - bitmap_clear(chip->valid_mask, start, count); - } -}; - #ifdef CONFIG_PINCTRL static int of_gpiochip_add_pin_range(struct gpio_chip *chip) { @@ -1119,8 +1079,6 @@ int of_gpiochip_add(struct gpio_chip *chip) if (chip->of_gpio_n_cells > MAX_PHANDLE_ARGS) return -EINVAL; - of_gpiochip_init_valid_mask(chip); - ret = of_gpiochip_add_pin_range(chip); if (ret) return ret; diff --git a/drivers/gpio/gpiolib-of.h b/drivers/gpio/gpiolib-of.h index 1b5df39a952e..2a2f7d17fa7e 100644 --- a/drivers/gpio/gpiolib-of.h +++ b/drivers/gpio/gpiolib-of.h @@ -23,7 +23,6 @@ struct gpio_desc *of_find_gpio(struct device *dev, int of_gpiochip_add(struct gpio_chip *gc); void of_gpiochip_remove(struct gpio_chip *gc); int of_gpio_get_count(struct device *dev, const char *con_id); -bool of_gpio_need_valid_mask(const struct gpio_chip *gc); void of_gpio_dev_init(struct gpio_chip *gc, struct gpio_device *gdev); #else static inline struct gpio_desc *of_find_gpio(struct device *dev, @@ -39,10 +38,6 @@ static inline int of_gpio_get_count(struct device *dev, const char *con_id) { return 0; } -static inline bool of_gpio_need_valid_mask(const struct gpio_chip *gc) -{ - return false; -} static inline void of_gpio_dev_init(struct gpio_chip *gc, struct gpio_device *gdev) { diff --git a/drivers/gpio/gpiolib.c b/drivers/gpio/gpiolib.c index e8faedca6b14..2ab7b7949171 100644 --- a/drivers/gpio/gpiolib.c +++ b/drivers/gpio/gpiolib.c @@ -445,9 +445,20 @@ static unsigned long *gpiochip_allocate_mask(struct gpio_chip *gc) return p; } +static unsigned int gpiochip_count_reserved_ranges(struct gpio_chip *gc) +{ + int size; + + size = fwnode_property_count_u32(gc->fwnode, "gpio-reserved-ranges"); + if (size > 0 && size % 2 == 0) + return size; + + return 0; +} + static int gpiochip_alloc_valid_mask(struct gpio_chip *gc) { - if (!(of_gpio_need_valid_mask(gc) || gc->init_valid_mask)) + if (!(gpiochip_count_reserved_ranges(gc) || gc->init_valid_mask)) return 0; gc->valid_mask = gpiochip_allocate_mask(gc); @@ -457,8 +468,47 @@ static int gpiochip_alloc_valid_mask(struct gpio_chip *gc) return 0; } +static int gpiochip_apply_reserved_ranges(struct gpio_chip *gc, unsigned int sz) +{ + u32 *ranges; + int ret; + + ranges = kmalloc_array(sz, sizeof(*ranges), GFP_KERNEL); + if (!ranges) + return -ENOMEM; + + ret = fwnode_property_read_u32_array(gc->fwnode, "gpio-reserved-ranges", ranges, sz); + if (ret) { + kfree(ranges); + return ret; + } + + while (sz) { + u32 count = ranges[--sz]; + u32 start = ranges[--sz]; + + if (start >= gc->ngpio || start + count > gc->ngpio) + continue; + + bitmap_clear(gc->valid_mask, start, count); + } + + kfree(ranges); + return 0; +} + static int gpiochip_init_valid_mask(struct gpio_chip *gc) { + unsigned int sz; + int ret; + + sz = gpiochip_count_reserved_ranges(gc); + if (sz) { + ret = gpiochip_apply_reserved_ranges(gc, sz); + if (ret) + return ret; + } + if (gc->init_valid_mask) return gc->init_valid_mask(gc, gc->valid_mask,