From patchwork Mon May 31 19:49:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 12289959 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 93D33C4709C for ; Mon, 31 May 2021 19:49:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 762D061057 for ; Mon, 31 May 2021 19:49:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231995AbhEaTvW (ORCPT ); Mon, 31 May 2021 15:51:22 -0400 Received: from mga11.intel.com ([192.55.52.93]:32368 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231418AbhEaTvS (ORCPT ); Mon, 31 May 2021 15:51:18 -0400 IronPort-SDR: FwF/s4PBsTufMwmPP8C3JKsKh27fNOun/vVBJ4ztz0s6/DtSiwQk363B+U28EngKyDYjG9+C7Z E5Q66H05+Jdg== X-IronPort-AV: E=McAfee;i="6200,9189,10001"; a="200396761" X-IronPort-AV: E=Sophos;i="5.83,238,1616482800"; d="scan'208";a="200396761" Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 May 2021 12:49:30 -0700 IronPort-SDR: tr++MuEQ1FbwlylOLS9zb64sl8VUaVMcrSnE/6dTPNGmaBGbVPW8w5SPq0ag1DsK9ymEYeWRHf fPUWwjnf2p+w== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.83,238,1616482800"; d="scan'208";a="482206806" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga002.fm.intel.com with ESMTP; 31 May 2021 12:49:28 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id F326F11D; Mon, 31 May 2021 22:49:50 +0300 (EEST) From: Andy Shevchenko To: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Andy Shevchenko , Flavio Suligoi , Thierry Reding , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pwm@vger.kernel.org, linux-acpi@vger.kernel.org Cc: Jonathan Corbet , Lee Jones , "Rafael J. Wysocki" , Len Brown Subject: [PATCH v2 1/7] docs: firmware-guide: ACPI: Add a PWM example Date: Mon, 31 May 2021 22:49:41 +0300 Message-Id: <20210531194947.10770-1-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org When PWM support for ACPI has been added into the kernel, it missed the documentation update. Hence update documentation here. Fixes: 4a6ef8e37c4d ("pwm: Add support referencing PWMs from ACPI") Signed-off-by: Andy Shevchenko --- v2: updated example to use 600 ms instead of 600 us (looks saner) .../firmware-guide/acpi/enumeration.rst | 32 +++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/Documentation/firmware-guide/acpi/enumeration.rst b/Documentation/firmware-guide/acpi/enumeration.rst index 9f0d5c854fa4..f588663ba906 100644 --- a/Documentation/firmware-guide/acpi/enumeration.rst +++ b/Documentation/firmware-guide/acpi/enumeration.rst @@ -258,6 +258,38 @@ input driver:: .id_table = mpu3050_ids, }; +Reference to PWM device +======================= + +Sometimes a device can be a consumer of PWM channel. Obviously OS would like +to know which one. To provide this mapping the special property has been +introduced, i.e.:: + + Device (DEV) + { + Name (_DSD, Package () + { + ToUUID("daffd814-6eba-4d8c-8a91-bc9bbf4aa301"), + Package () { + Package () { "compatible", Package () { "pwm-leds" } }, + Package () { "label", "alarm-led" }, + Package () { "pwms", + Package () { + "\\_SB.PCI0.PWM", // + 0, // + 600000000, // + 0, // + } + } + } + + }) + ... + +In the above example the PWM-based LED driver references to the PWM channel 0 +of \_SB.PCI0.PWM device with initial period setting equal to 600 ms (note that +value is given in nanoseconds). + GPIO support ============ From patchwork Mon May 31 19:49:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 12289957 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B16FEC4709E for ; Mon, 31 May 2021 19:49:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 927556128A for ; Mon, 31 May 2021 19:49:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232064AbhEaTvW (ORCPT ); Mon, 31 May 2021 15:51:22 -0400 Received: from mga14.intel.com ([192.55.52.115]:39326 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231624AbhEaTvS (ORCPT ); Mon, 31 May 2021 15:51:18 -0400 IronPort-SDR: pa3cvLMOxdJSs/GYct9eK+swECJ5e4lk0T+2sJysaVEfyXB6NEmiUnq90uHl2bIjSlVdTVQtkL tmZuN9sBXekg== X-IronPort-AV: E=McAfee;i="6200,9189,10001"; a="203215209" X-IronPort-AV: E=Sophos;i="5.83,238,1616482800"; d="scan'208";a="203215209" Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 May 2021 12:49:30 -0700 IronPort-SDR: o+p5JjvtZT6GahBTqKGHMK0fSLH3FVnQjA9jeNY6bjoZofTVwuWYV9q2ODK2oX44C//5aIO5FY CK37vW79+FkA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.83,238,1616482800"; d="scan'208";a="446696425" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga008.fm.intel.com with ESMTP; 31 May 2021 12:49:28 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 079C6F2; Mon, 31 May 2021 22:49:51 +0300 (EEST) From: Andy Shevchenko To: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Andy Shevchenko , Flavio Suligoi , Thierry Reding , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pwm@vger.kernel.org, linux-acpi@vger.kernel.org Cc: Jonathan Corbet , Lee Jones , "Rafael J. Wysocki" , Len Brown Subject: [PATCH v2 2/7] pwm: core: Always require PWM flags to be provided Date: Mon, 31 May 2021 22:49:42 +0300 Message-Id: <20210531194947.10770-2-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210531194947.10770-1-andriy.shevchenko@linux.intel.com> References: <20210531194947.10770-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org It makes little sense to make PWM flags optional since in case of multi-channel consumer the flags can be optional only for the last listed channel. Thus always require PWM flags to be provided. Fixes: 4a6ef8e37c4d ("pwm: Add support referencing PWMs from ACPI") Signed-off-by: Andy Shevchenko --- v2: no change drivers/pwm/core.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c index c165c5822703..25f7b3370672 100644 --- a/drivers/pwm/core.c +++ b/drivers/pwm/core.c @@ -852,8 +852,10 @@ static struct pwm_chip *device_to_pwmchip(struct device *dev) * * This is analogous to of_pwm_get() except con_id is not yet supported. * ACPI entries must look like - * Package () {"pwms", Package () - * { , , [, ]}} + * Package () { "pwms", Package () { + * , , , , + * } + * } * * Returns: A pointer to the requested PWM device or an ERR_PTR()-encoded * error code on failure. @@ -877,7 +879,7 @@ static struct pwm_device *acpi_pwm_get(struct fwnode_handle *fwnode) if (!acpi) return ERR_PTR(-EINVAL); - if (args.nargs < 2) + if (args.nargs < 3) return ERR_PTR(-EPROTO); chip = device_to_pwmchip(&acpi->dev); @@ -891,7 +893,7 @@ static struct pwm_device *acpi_pwm_get(struct fwnode_handle *fwnode) pwm->args.period = args.args[1]; pwm->args.polarity = PWM_POLARITY_NORMAL; - if (args.nargs > 2 && args.args[2] & PWM_POLARITY_INVERTED) + if (args.args[2] & PWM_POLARITY_INVERTED) pwm->args.polarity = PWM_POLARITY_INVERSED; #endif From patchwork Mon May 31 19:49:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 12289951 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 8AB8CC47083 for ; Mon, 31 May 2021 19:49:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6FCE56127C for ; Mon, 31 May 2021 19:49:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231680AbhEaTvT (ORCPT ); Mon, 31 May 2021 15:51:19 -0400 Received: from mga14.intel.com ([192.55.52.115]:39313 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230523AbhEaTvS (ORCPT ); Mon, 31 May 2021 15:51:18 -0400 IronPort-SDR: 6PxCvECNlrqMyFleUjxf5aLcrPh5uFx8tC5UtnaS7E1OjpLAH1rLyfJ96/Z3ALyxT8372pirRb LzKPfM4rlRXQ== X-IronPort-AV: E=McAfee;i="6200,9189,10001"; a="203215212" X-IronPort-AV: E=Sophos;i="5.83,238,1616482800"; d="scan'208";a="203215212" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 May 2021 12:49:32 -0700 IronPort-SDR: Ozhs2tWf5lCjkpYwORoWmInSsdlnyMuvVYrL2fhiyMefpnHFvvEMHFX1/6N85ZuzaLspRpGX0V Uji5rPTa9DHw== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.83,238,1616482800"; d="scan'208";a="399392000" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga006.jf.intel.com with ESMTP; 31 May 2021 12:49:28 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 1A08E1FC; Mon, 31 May 2021 22:49:51 +0300 (EEST) From: Andy Shevchenko To: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Andy Shevchenko , Flavio Suligoi , Thierry Reding , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pwm@vger.kernel.org, linux-acpi@vger.kernel.org Cc: Jonathan Corbet , Lee Jones , "Rafael J. Wysocki" , Len Brown Subject: [PATCH v2 3/7] pwm: core: Convert to use fwnode for matching Date: Mon, 31 May 2021 22:49:43 +0300 Message-Id: <20210531194947.10770-3-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210531194947.10770-1-andriy.shevchenko@linux.intel.com> References: <20210531194947.10770-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org When we traverse the list of the registered PWM controllers, use fwnode to match. This will help for further cleanup. Signed-off-by: Andy Shevchenko --- v2: no change drivers/pwm/core.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c index 25f7b3370672..338d8ee369db 100644 --- a/drivers/pwm/core.c +++ b/drivers/pwm/core.c @@ -691,14 +691,14 @@ int pwm_adjust_config(struct pwm_device *pwm) } EXPORT_SYMBOL_GPL(pwm_adjust_config); -static struct pwm_chip *of_node_to_pwmchip(struct device_node *np) +static struct pwm_chip *fwnode_to_pwmchip(struct fwnode_handle *fwnode) { struct pwm_chip *chip; mutex_lock(&pwm_lock); list_for_each_entry(chip, &pwm_chips, list) - if (chip->dev && chip->dev->of_node == np) { + if (chip->dev && dev_fwnode(chip->dev) == fwnode) { mutex_unlock(&pwm_lock); return chip; } @@ -777,7 +777,7 @@ struct pwm_device *of_pwm_get(struct device *dev, struct device_node *np, return ERR_PTR(err); } - pc = of_node_to_pwmchip(args.np); + pc = fwnode_to_pwmchip(of_fwnode_handle(args.np)); if (IS_ERR(pc)) { if (PTR_ERR(pc) != -EPROBE_DEFER) pr_err("%s(): PWM chip not found\n", __func__); From patchwork Mon May 31 19:49:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 12289961 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id E60C3C47096 for ; Mon, 31 May 2021 19:49:48 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CB84F6127C for ; Mon, 31 May 2021 19:49:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232116AbhEaTvZ (ORCPT ); Mon, 31 May 2021 15:51:25 -0400 Received: from mga14.intel.com ([192.55.52.115]:39313 "EHLO mga14.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231585AbhEaTvS (ORCPT ); Mon, 31 May 2021 15:51:18 -0400 IronPort-SDR: VOShKQLNHol3t4gDFaruJ7gS9r80cWotzH1HlxhovfDRmdepMNKbcsL+Kb9Hk8pwZVVmNtfcta WPb/mQszrBDQ== X-IronPort-AV: E=McAfee;i="6200,9189,10001"; a="203215213" X-IronPort-AV: E=Sophos;i="5.83,238,1616482800"; d="scan'208";a="203215213" Received: from orsmga006.jf.intel.com ([10.7.209.51]) by fmsmga103.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 May 2021 12:49:33 -0700 IronPort-SDR: 3qBobZTieYv8pdHEF/aQdOShafjQI7bjgp4XNDDS6ccMI4a+25+Zu0HfMvLt7p9kjGdgPDGt2s Ob1ZX4hPGWgA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.83,238,1616482800"; d="scan'208";a="399392001" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga006.jf.intel.com with ESMTP; 31 May 2021 12:49:28 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 26B1D12A; Mon, 31 May 2021 22:49:51 +0300 (EEST) From: Andy Shevchenko To: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Andy Shevchenko , Flavio Suligoi , Thierry Reding , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pwm@vger.kernel.org, linux-acpi@vger.kernel.org Cc: Jonathan Corbet , Lee Jones , "Rafael J. Wysocki" , Len Brown Subject: [PATCH v2 4/7] pwm: core: Reuse fwnode_to_pwmchip() in ACPI case Date: Mon, 31 May 2021 22:49:44 +0300 Message-Id: <20210531194947.10770-4-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210531194947.10770-1-andriy.shevchenko@linux.intel.com> References: <20210531194947.10770-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org In ACPI case we may use matching by fwnode as provided via fwnode_to_pwmchip(). This makes device_to_pwmchip() not needed anymore. Signed-off-by: Andy Shevchenko --- v2: no change drivers/pwm/core.c | 31 +------------------------------ 1 file changed, 1 insertion(+), 30 deletions(-) diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c index 338d8ee369db..2223a9b6644b 100644 --- a/drivers/pwm/core.c +++ b/drivers/pwm/core.c @@ -819,28 +819,6 @@ struct pwm_device *of_pwm_get(struct device *dev, struct device_node *np, } EXPORT_SYMBOL_GPL(of_pwm_get); -#if IS_ENABLED(CONFIG_ACPI) -static struct pwm_chip *device_to_pwmchip(struct device *dev) -{ - struct pwm_chip *chip; - - mutex_lock(&pwm_lock); - - list_for_each_entry(chip, &pwm_chips, list) { - struct acpi_device *adev = ACPI_COMPANION(chip->dev); - - if ((chip->dev == dev) || (adev && &adev->dev == dev)) { - mutex_unlock(&pwm_lock); - return chip; - } - } - - mutex_unlock(&pwm_lock); - - return ERR_PTR(-EPROBE_DEFER); -} -#endif - /** * acpi_pwm_get() - request a PWM via parsing "pwms" property in ACPI * @fwnode: firmware node to get the "pwm" property from @@ -863,9 +841,7 @@ static struct pwm_chip *device_to_pwmchip(struct device *dev) static struct pwm_device *acpi_pwm_get(struct fwnode_handle *fwnode) { struct pwm_device *pwm = ERR_PTR(-ENODEV); -#if IS_ENABLED(CONFIG_ACPI) struct fwnode_reference_args args; - struct acpi_device *acpi; struct pwm_chip *chip; int ret; @@ -875,14 +851,10 @@ static struct pwm_device *acpi_pwm_get(struct fwnode_handle *fwnode) if (ret < 0) return ERR_PTR(ret); - acpi = to_acpi_device_node(args.fwnode); - if (!acpi) - return ERR_PTR(-EINVAL); - if (args.nargs < 3) return ERR_PTR(-EPROTO); - chip = device_to_pwmchip(&acpi->dev); + chip = fwnode_to_pwmchip(args.fwnode); if (IS_ERR(chip)) return ERR_CAST(chip); @@ -895,7 +867,6 @@ static struct pwm_device *acpi_pwm_get(struct fwnode_handle *fwnode) if (args.args[2] & PWM_POLARITY_INVERTED) pwm->args.polarity = PWM_POLARITY_INVERSED; -#endif return pwm; } From patchwork Mon May 31 19:49:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 12289953 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id B8E34C47097 for ; Mon, 31 May 2021 19:49:42 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9476F6127C for ; Mon, 31 May 2021 19:49:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231809AbhEaTvU (ORCPT ); Mon, 31 May 2021 15:51:20 -0400 Received: from mga03.intel.com ([134.134.136.65]:46675 "EHLO mga03.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230288AbhEaTvS (ORCPT ); Mon, 31 May 2021 15:51:18 -0400 IronPort-SDR: YdJHNsOPYgYCxG+x3O49BQJqYrYjTz9f5tNH3DVqNNoyH/Il+JIgqkTDidTFOvgFmJdOu31I0F mnk+2OS55Z2g== X-IronPort-AV: E=McAfee;i="6200,9189,10001"; a="203448751" X-IronPort-AV: E=Sophos;i="5.83,238,1616482800"; d="scan'208";a="203448751" Received: from orsmga005.jf.intel.com ([10.7.209.41]) by orsmga103.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 May 2021 12:49:32 -0700 IronPort-SDR: vdQPZP1UmIhzvYrCbZnYJclHUXuLl7dqvk1nSpXfzACXPBGcwid9C/R6uKevuYsMSngTKYeFsi uDBNkUv+c6vQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.83,238,1616482800"; d="scan'208";a="616612686" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga005.jf.intel.com with ESMTP; 31 May 2021 12:49:28 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 3324F53E; Mon, 31 May 2021 22:49:51 +0300 (EEST) From: Andy Shevchenko To: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Andy Shevchenko , Flavio Suligoi , Thierry Reding , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pwm@vger.kernel.org, linux-acpi@vger.kernel.org Cc: Jonathan Corbet , Lee Jones , "Rafael J. Wysocki" , Len Brown Subject: [PATCH v2 5/7] pwm: core: Unify fwnode checks in the module Date: Mon, 31 May 2021 22:49:45 +0300 Message-Id: <20210531194947.10770-5-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210531194947.10770-1-andriy.shevchenko@linux.intel.com> References: <20210531194947.10770-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Historically we have two different approaches on how to check type of fwnode. Unify them using the latest and greatest fwnode related APIs. Signed-off-by: Andy Shevchenko --- v2: corrected property name in kernel doc drivers/pwm/core.c | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c index 2223a9b6644b..a27d7c2aa6fe 100644 --- a/drivers/pwm/core.c +++ b/drivers/pwm/core.c @@ -821,7 +821,7 @@ EXPORT_SYMBOL_GPL(of_pwm_get); /** * acpi_pwm_get() - request a PWM via parsing "pwms" property in ACPI - * @fwnode: firmware node to get the "pwm" property from + * @fwnode: firmware node to get the "pwms" property from * * Returns the PWM device parsed from the fwnode and index specified in the * "pwms" property or a negative error-code on failure. @@ -838,7 +838,7 @@ EXPORT_SYMBOL_GPL(of_pwm_get); * Returns: A pointer to the requested PWM device or an ERR_PTR()-encoded * error code on failure. */ -static struct pwm_device *acpi_pwm_get(struct fwnode_handle *fwnode) +static struct pwm_device *acpi_pwm_get(const struct fwnode_handle *fwnode) { struct pwm_device *pwm = ERR_PTR(-ENODEV); struct fwnode_reference_args args; @@ -922,6 +922,7 @@ void pwm_remove_table(struct pwm_lookup *table, size_t num) */ struct pwm_device *pwm_get(struct device *dev, const char *con_id) { + const struct fwnode_handle *fwnode = dev ? dev_fwnode(dev) : NULL; const char *dev_id = dev ? dev_name(dev) : NULL; struct pwm_device *pwm; struct pwm_chip *chip; @@ -932,12 +933,12 @@ struct pwm_device *pwm_get(struct device *dev, const char *con_id) int err; /* look up via DT first */ - if (IS_ENABLED(CONFIG_OF) && dev && dev->of_node) - return of_pwm_get(dev, dev->of_node, con_id); + if (is_of_node(fwnode)) + return of_pwm_get(dev, to_of_node(fwnode), con_id); /* then lookup via ACPI */ - if (dev && is_acpi_node(dev->fwnode)) { - pwm = acpi_pwm_get(dev->fwnode); + if (is_acpi_node(fwnode)) { + pwm = acpi_pwm_get(fwnode); if (!IS_ERR(pwm) || PTR_ERR(pwm) != -ENOENT) return pwm; } From patchwork Mon May 31 19:49:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 12289955 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 71A12C4709A for ; Mon, 31 May 2021 19:49:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5668C61057 for ; Mon, 31 May 2021 19:49:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231971AbhEaTvV (ORCPT ); Mon, 31 May 2021 15:51:21 -0400 Received: from mga02.intel.com ([134.134.136.20]:39812 "EHLO mga02.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231542AbhEaTvS (ORCPT ); Mon, 31 May 2021 15:51:18 -0400 IronPort-SDR: RnpqX1aVFeCWtdTjJ3GqBU/PSjhIsi0I+BNJ8KSBkPKEGOvR+KlaJUku+8XtrhqDvIhLWi44q+ SMYoMIkOmtKQ== X-IronPort-AV: E=McAfee;i="6200,9189,10001"; a="190528034" X-IronPort-AV: E=Sophos;i="5.83,238,1616482800"; d="scan'208";a="190528034" Received: from orsmga004.jf.intel.com ([10.7.209.38]) by orsmga101.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 May 2021 12:49:35 -0700 IronPort-SDR: BpUMOXnWRLq/Luqgqw2ZyRnaXxetWYCJQYTFx2dtERc8lNCuiYjt/jcxdTKib+Sa90FgpfpBWx 6x6vmzhmEafA== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.83,238,1616482800"; d="scan'208";a="548829862" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga004.jf.intel.com with ESMTP; 31 May 2021 12:49:32 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 46DAC6BC; Mon, 31 May 2021 22:49:51 +0300 (EEST) From: Andy Shevchenko To: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Andy Shevchenko , Flavio Suligoi , Thierry Reding , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pwm@vger.kernel.org, linux-acpi@vger.kernel.org Cc: Jonathan Corbet , Lee Jones , "Rafael J. Wysocki" , Len Brown Subject: [PATCH v2 6/7] pwm: core: Remove unused devm_pwm_put() Date: Mon, 31 May 2021 22:49:46 +0300 Message-Id: <20210531194947.10770-6-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210531194947.10770-1-andriy.shevchenko@linux.intel.com> References: <20210531194947.10770-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org There are no users and seems no will come of the devm_pwm_put(). Remove the function. While at it, slightly update documentation. Signed-off-by: Andy Shevchenko Reviewed-by: Uwe Kleine-König --- v2: new patch .../driver-api/driver-model/devres.rst | 3 ++- Documentation/driver-api/pwm.rst | 3 ++- drivers/pwm/core.c | 25 ------------------- include/linux/pwm.h | 5 ---- 4 files changed, 4 insertions(+), 32 deletions(-) diff --git a/Documentation/driver-api/driver-model/devres.rst b/Documentation/driver-api/driver-model/devres.rst index b2645870ef7e..cc1e0138ba9f 100644 --- a/Documentation/driver-api/driver-model/devres.rst +++ b/Documentation/driver-api/driver-model/devres.rst @@ -410,7 +410,8 @@ POWER PWM devm_pwm_get() - devm_pwm_put() + devm_of_pwm_get() + devm_fwnode_pwm_get() REGULATOR devm_regulator_bulk_get() diff --git a/Documentation/driver-api/pwm.rst b/Documentation/driver-api/pwm.rst index a7ca4f58305a..251e3f7be230 100644 --- a/Documentation/driver-api/pwm.rst +++ b/Documentation/driver-api/pwm.rst @@ -40,7 +40,8 @@ after usage with pwm_free(). New users should use the pwm_get() function and pass to it the consumer device or a consumer name. pwm_put() is used to free the PWM device. Managed -variants of these functions, devm_pwm_get() and devm_pwm_put(), also exist. +variants of the getter, devm_pwm_get(), devm_of_pwm_get(), +devm_fwnode_pwm_get(), also exist. After being requested, a PWM has to be configured using:: diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c index a27d7c2aa6fe..6d4410bd9793 100644 --- a/drivers/pwm/core.c +++ b/drivers/pwm/core.c @@ -1166,31 +1166,6 @@ struct pwm_device *devm_fwnode_pwm_get(struct device *dev, } EXPORT_SYMBOL_GPL(devm_fwnode_pwm_get); -static int devm_pwm_match(struct device *dev, void *res, void *data) -{ - struct pwm_device **p = res; - - if (WARN_ON(!p || !*p)) - return 0; - - return *p == data; -} - -/** - * devm_pwm_put() - resource managed pwm_put() - * @dev: device for PWM consumer - * @pwm: PWM device - * - * Release a PWM previously allocated using devm_pwm_get(). Calling this - * function is usually not needed because devm-allocated resources are - * automatically released on driver detach. - */ -void devm_pwm_put(struct device *dev, struct pwm_device *pwm) -{ - WARN_ON(devres_release(dev, devm_pwm_release, devm_pwm_match, pwm)); -} -EXPORT_SYMBOL_GPL(devm_pwm_put); - #ifdef CONFIG_DEBUG_FS static void pwm_dbg_show(struct pwm_chip *chip, struct seq_file *s) { diff --git a/include/linux/pwm.h b/include/linux/pwm.h index 5bb90af4997e..1eaded57c666 100644 --- a/include/linux/pwm.h +++ b/include/linux/pwm.h @@ -417,7 +417,6 @@ struct pwm_device *devm_of_pwm_get(struct device *dev, struct device_node *np, struct pwm_device *devm_fwnode_pwm_get(struct device *dev, struct fwnode_handle *fwnode, const char *con_id); -void devm_pwm_put(struct device *dev, struct pwm_device *pwm); #else static inline struct pwm_device *pwm_request(int pwm_id, const char *label) { @@ -524,10 +523,6 @@ devm_fwnode_pwm_get(struct device *dev, struct fwnode_handle *fwnode, { return ERR_PTR(-ENODEV); } - -static inline void devm_pwm_put(struct device *dev, struct pwm_device *pwm) -{ -} #endif static inline void pwm_apply_args(struct pwm_device *pwm) From patchwork Mon May 31 19:49:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 12289949 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2C6A5C47082 for ; Mon, 31 May 2021 19:49:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 1023A6128A for ; Mon, 31 May 2021 19:49:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231670AbhEaTvT (ORCPT ); Mon, 31 May 2021 15:51:19 -0400 Received: from mga05.intel.com ([192.55.52.43]:6903 "EHLO mga05.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231563AbhEaTvS (ORCPT ); Mon, 31 May 2021 15:51:18 -0400 IronPort-SDR: llgHi44og4euXMoGje9G5HJUcfP+D62CPMMSq4BlmGXi6VDK1vpG6F596kwawZQgw9ZUvlEpxj McsPxp5Nvjjg== X-IronPort-AV: E=McAfee;i="6200,9189,10001"; a="289027850" X-IronPort-AV: E=Sophos;i="5.83,238,1616482800"; d="scan'208";a="289027850" Received: from orsmga003.jf.intel.com ([10.7.209.27]) by fmsmga105.fm.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 May 2021 12:49:35 -0700 IronPort-SDR: V7ODrX3xLgQyAgWRdFqSl+psciNKF2/BbgM4EGLlNy0C6Qg7uBmF0wcNEQA7/7utGJmctNSwBw kRlVu71KxxqQ== X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.83,238,1616482800"; d="scan'208";a="399062437" Received: from black.fi.intel.com ([10.237.72.28]) by orsmga003.jf.intel.com with ESMTP; 31 May 2021 12:49:31 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id 4E0655B6; Mon, 31 May 2021 22:49:51 +0300 (EEST) From: Andy Shevchenko To: =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= , Andy Shevchenko , Flavio Suligoi , Thierry Reding , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-pwm@vger.kernel.org, linux-acpi@vger.kernel.org Cc: Jonathan Corbet , Lee Jones , "Rafael J. Wysocki" , Len Brown Subject: [PATCH v2 7/7] pwm: core: Simplify some devm_*pwm*() functions Date: Mon, 31 May 2021 22:49:47 +0300 Message-Id: <20210531194947.10770-7-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210531194947.10770-1-andriy.shevchenko@linux.intel.com> References: <20210531194947.10770-1-andriy.shevchenko@linux.intel.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-acpi@vger.kernel.org Use devm_add_action_or_reset() instead of devres_alloc() and devres_add(), which works the same. This will simplify the code. There is no functional changes. Signed-off-by: Andy Shevchenko Reviewed-by: Uwe Kleine-König --- v2: new patch drivers/pwm/core.c | 60 +++++++++++++++++++--------------------------- 1 file changed, 25 insertions(+), 35 deletions(-) diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c index 6d4410bd9793..9f643414676b 100644 --- a/drivers/pwm/core.c +++ b/drivers/pwm/core.c @@ -1059,9 +1059,9 @@ void pwm_put(struct pwm_device *pwm) } EXPORT_SYMBOL_GPL(pwm_put); -static void devm_pwm_release(struct device *dev, void *res) +static void devm_pwm_release(void *pwm) { - pwm_put(*(struct pwm_device **)res); + pwm_put(pwm); } /** @@ -1077,19 +1077,16 @@ static void devm_pwm_release(struct device *dev, void *res) */ struct pwm_device *devm_pwm_get(struct device *dev, const char *con_id) { - struct pwm_device **ptr, *pwm; - - ptr = devres_alloc(devm_pwm_release, sizeof(*ptr), GFP_KERNEL); - if (!ptr) - return ERR_PTR(-ENOMEM); + struct pwm_device *pwm; + int ret; pwm = pwm_get(dev, con_id); - if (!IS_ERR(pwm)) { - *ptr = pwm; - devres_add(dev, ptr); - } else { - devres_free(ptr); - } + if (IS_ERR(pwm)) + return pwm; + + ret = devm_add_action_or_reset(dev, devm_pwm_release, pwm); + if (ret) + return ERR_PTR(ret); return pwm; } @@ -1110,19 +1107,16 @@ EXPORT_SYMBOL_GPL(devm_pwm_get); struct pwm_device *devm_of_pwm_get(struct device *dev, struct device_node *np, const char *con_id) { - struct pwm_device **ptr, *pwm; - - ptr = devres_alloc(devm_pwm_release, sizeof(*ptr), GFP_KERNEL); - if (!ptr) - return ERR_PTR(-ENOMEM); + struct pwm_device *pwm; + int ret; pwm = of_pwm_get(dev, np, con_id); - if (!IS_ERR(pwm)) { - *ptr = pwm; - devres_add(dev, ptr); - } else { - devres_free(ptr); - } + if (IS_ERR(pwm)) + return pwm; + + ret = devm_add_action_or_reset(dev, devm_pwm_release, pwm); + if (ret) + return ERR_PTR(ret); return pwm; } @@ -1144,23 +1138,19 @@ struct pwm_device *devm_fwnode_pwm_get(struct device *dev, struct fwnode_handle *fwnode, const char *con_id) { - struct pwm_device **ptr, *pwm = ERR_PTR(-ENODEV); - - ptr = devres_alloc(devm_pwm_release, sizeof(*ptr), GFP_KERNEL); - if (!ptr) - return ERR_PTR(-ENOMEM); + struct pwm_device *pwm = ERR_PTR(-ENODEV); + int ret; if (is_of_node(fwnode)) pwm = of_pwm_get(dev, to_of_node(fwnode), con_id); else if (is_acpi_node(fwnode)) pwm = acpi_pwm_get(fwnode); + if (IS_ERR(pwm)) + return pwm; - if (!IS_ERR(pwm)) { - *ptr = pwm; - devres_add(dev, ptr); - } else { - devres_free(ptr); - } + ret = devm_add_action_or_reset(dev, devm_pwm_release, pwm); + if (ret) + return ERR_PTR(ret); return pwm; }