From patchwork Sat May 25 18:11:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Blumenstingl X-Patchwork-Id: 10961089 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0AB8F1575 for ; Sat, 25 May 2019 18:49:24 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EF31E28A7E for ; Sat, 25 May 2019 18:49:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DE75B28A86; Sat, 25 May 2019 18:49:23 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 81E3628A7E for ; Sat, 25 May 2019 18:49:23 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=w8qODxSHq+PC2o2qlliqawDw9zWumpA2NjRe+MnlnoE=; b=QGAzjlT+AawWn7 77bRnkfdBlXw6ECzNQuWCJ3u6odr0etgw1UstNJvRsaRRnDti0TSm0d8BlrA+wIxPG7FvGOTjq/kg FO7C2BrfpvJEvWda7xSwlAYbcgfyBPcgIgKDtLY3zYU42lXWvpLC8OjgVnSjCJPtjFvWHi+K3K7wk kSnRXqHokeo9b0FrKwRYlX0i5JcNG7pxyXhtI2lKq9UPOm+Q1S4sxudySGtsA1F6vuaFL4GLjN7kS ClPA97c1jKbmnRF5LDoJReXVi9QtdU+aLl9xqJF18juomRQTp1zykDRWJedpB+7CUTr+Cg5JNSSQa tksDoXzqa3JgSQdFF70g==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hUbjK-00046o-In; Sat, 25 May 2019 18:49:18 +0000 Received: from merlin.infradead.org ([2001:8b0:10b:1231::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hUbir-0003sf-1m; Sat, 25 May 2019 18:48:49 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=3846hpA0VZMszmYc1Od49f4w97KJgiyEWxP34Iw+ZOI=; b=vLwneUV9M945KNL/VIgvrBXVic mAas2ML2KK/cyvkneb+JyFd0LEoiQ1cYIjfxWUmEEwaXruGz9y2u1hzP+JfXxVsk1ifX84XD1F1yj 3qYVmw6VZ7WUGQnrRhl+TjZG+m21JJ1hnQrjIKBuHEBuM1l27lqb7MP2uS+JlXxLgqGQXu6DXfABp WsTyfs3JJhV1ZCK/GDj5MxgibY0C8Yhsu6ceOEPIVSo08FsyOwgTSXKLTGicTbqkWgFLkhaevmkUU M02MR7sqDNl1ORL7l00Ga8P+Z5Su4I7HIeDiDCvWP0L+kmiEOwClEfN+UEgPQvCutVT6MCYeb/mOW CIn8qnoA==; Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]) by merlin.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hUb93-0006e5-LR; Sat, 25 May 2019 18:11:50 +0000 Received: by mail-wr1-x441.google.com with SMTP id w13so4590548wru.11; Sat, 25 May 2019 11:11:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3846hpA0VZMszmYc1Od49f4w97KJgiyEWxP34Iw+ZOI=; b=OyX8MuNvfMozqpjcWk85AijY5aGyCBnJ+ElHglWl19+arEUmY2zSi/hOQI73ILV5/c hM/vKqcAfRjelxp/tfzddetGO8gSlXmfEgrYICHsyxLFBtLDNwCy6jyTtLF4maK8Y2Ox 637QHArHJeamZp7+cQheJX5gnLcrUnK694X5vJPQzKHqkD3tKHUGkyqtCPWAyoIe0/m3 PyVMzInd+JWvTSQa9Plw/HRaAwwPH214WBhQnkgXPn8VQBZuYdtXgIYqxmsI8XaeobH5 EVGFcPq4Z6PybieiNqHuEmGfkGXi/8gSd/aQuyTzJ14SQWy8d5xauxyDA4+hUOZeO3i9 qUqQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=3846hpA0VZMszmYc1Od49f4w97KJgiyEWxP34Iw+ZOI=; b=Rmtzu9bww502rz6Ry3CBvzaWy2ynSArmr7CYMzRGOA0sc+4NhI0Fk5jgyOw/+y5sXh Y9F3/ZTEly59zQjj6kStNTKqNx18fO8IrBSBCUmn6hxqXmO8NGVMl0gmcYrONF/dAmqx HPBiIuWDjMXlgl0FOIF33evxHrILuZ9I5dYgKkYFZahdkd7D0BujnN76+HgZVY4tXgOm sVbSOMGCmR6X6e4il8zabD7NtFXXG8opqoCPOcdsI3kL0odWLXhsYG9xU7/XQqJsIefF CiqANMPs5U7h4T5iXtiW8/Pgg/VHhOR0ZFlF30DGo07g6LHUsCNQYCj+X5S/LriPY6dU EDUg== X-Gm-Message-State: APjAAAWxE9y53kyImwh5eF7LtnGBD3E2BhqkFmaqNUNaxshEWVPqkD8F Qduf6Oy9K7+ie+Qpuz5hH/U9tdoD X-Google-Smtp-Source: APXvYqxiEfQUfycp8WtTaBUuBjs1RcNwjRJBotfEUd51P4MlDVWY5N1voIp3VdWZ9thnCsPEH/s33g== X-Received: by 2002:a5d:6189:: with SMTP id j9mr3534497wru.151.1558807905134; Sat, 25 May 2019 11:11:45 -0700 (PDT) Received: from blackbox.darklights.net (p200300F133DDA4007CB8841254CD64FD.dip0.t-ipconnect.de. [2003:f1:33dd:a400:7cb8:8412:54cd:64fd]) by smtp.googlemail.com with ESMTPSA id o8sm12794540wra.4.2019.05.25.11.11.43 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 25 May 2019 11:11:44 -0700 (PDT) From: Martin Blumenstingl To: linux-amlogic@lists.infradead.org, linux-pwm@vger.kernel.org, thierry.reding@gmail.com, u.kleine-koenig@pengutronix.de Subject: [PATCH 01/14] pwm: meson: unify the parameter list of meson_pwm_{enable, disable} Date: Sat, 25 May 2019 20:11:20 +0200 Message-Id: <20190525181133.4875-2-martin.blumenstingl@googlemail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190525181133.4875-1-martin.blumenstingl@googlemail.com> References: <20190525181133.4875-1-martin.blumenstingl@googlemail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190525_141149_705072_7A0884C5 X-CRM114-Status: GOOD ( 12.31 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Martin Blumenstingl , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This is a preparation for a future cleanup. Pass struct pwm_device instead of passing the individual values required by each function as these can be obtained for each struct pwm_device instance. As a nice side-effect the driver now uses "switch (pwm->hwpwm)" everywhere. Before some functions used "switch (id)" while others used "switch (pwm->hwpwm)". No functional changes. Signed-off-by: Martin Blumenstingl Reviewed-by: Neil Armstrong --- drivers/pwm/pwm-meson.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/drivers/pwm/pwm-meson.c b/drivers/pwm/pwm-meson.c index 5fef7e925282..3fbbc4128ce8 100644 --- a/drivers/pwm/pwm-meson.c +++ b/drivers/pwm/pwm-meson.c @@ -183,15 +183,14 @@ static int meson_pwm_calc(struct meson_pwm *meson, return 0; } -static void meson_pwm_enable(struct meson_pwm *meson, - struct meson_pwm_channel *channel, - unsigned int id) +static void meson_pwm_enable(struct meson_pwm *meson, struct pwm_device *pwm) { + struct meson_pwm_channel *channel = pwm_get_chip_data(pwm); u32 value, clk_shift, clk_enable, enable; unsigned int offset; unsigned long flags; - switch (id) { + switch (pwm->hwpwm) { case 0: clk_shift = MISC_A_CLK_DIV_SHIFT; clk_enable = MISC_A_CLK_EN; @@ -228,12 +227,12 @@ static void meson_pwm_enable(struct meson_pwm *meson, spin_unlock_irqrestore(&meson->lock, flags); } -static void meson_pwm_disable(struct meson_pwm *meson, unsigned int id) +static void meson_pwm_disable(struct meson_pwm *meson, struct pwm_device *pwm) { u32 value, enable; unsigned long flags; - switch (id) { + switch (pwm->hwpwm) { case 0: enable = MISC_A_EN; break; @@ -266,7 +265,7 @@ static int meson_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, return -EINVAL; if (!state->enabled) { - meson_pwm_disable(meson, pwm->hwpwm); + meson_pwm_disable(meson, pwm); channel->state.enabled = false; return 0; @@ -293,7 +292,7 @@ static int meson_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, } if (state->enabled && !channel->state.enabled) { - meson_pwm_enable(meson, channel, pwm->hwpwm); + meson_pwm_enable(meson, pwm); channel->state.enabled = true; } From patchwork Sat May 25 18:11:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Blumenstingl X-Patchwork-Id: 10961039 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8E76517E0 for ; Sat, 25 May 2019 18:13:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 80EB528A86 for ; Sat, 25 May 2019 18:13:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 750B428A8E; Sat, 25 May 2019 18:13:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 189F128A86 for ; Sat, 25 May 2019 18:13:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=qQRiR4FBkFUUlo3DdloMbzMZ65/zz2fD0EplTM5JgXc=; b=ni3AESlEsQ0CNf itwikNT+Gqyfq+wubLYHLBS5QtGTLHxoEJDJtAh9BYdClEuAr+zWHvFfRg5jXh5BuUKhKDwv1skvK L4LrlpGRLFBPSGhm5a9uRp9Gh65eXu+KT2W+4DMESZhirDkayoAhg+i9E6IO5BUlpQ4XOnkOlpPuQ LeD3DWOH7XlCvM4GFYZZrTusdawk1Scq3N1SX5E0UUSnAFF0AvJKFBfw7OvhMSLnRJbdu2uz4Khzf anJPfLFdOTBDBhDFzOr3ogaRUdc0lheopyavi4I2dtdqto4FHDyoQ4SdEKd3lMyjYbyIdrl85ymW6 mVOJarg1ZyiYht+TZdFA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hUbAt-0004Tp-6M; Sat, 25 May 2019 18:13:43 +0000 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hUb92-0002JW-Fr; Sat, 25 May 2019 18:11:57 +0000 Received: by mail-wm1-x343.google.com with SMTP id i3so12324872wml.4; Sat, 25 May 2019 11:11:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ore1r+dKR4AsT7KxL88Hg8/dGPX/2Y8Acm9/4eCEojE=; b=nHZYDf8YaoMbqMOwxPqAgeNXKRos+cq9aefZf6p10ZPPH5Do6B89b2LgjGxiVvBQWU equJR9FChOuFY1BUIzW+60NrCl9iRiWpR0nFeX3lSwu4xUquFzktcMjwH052JbxmK9i8 Fi1/FKNVoUCx5DZywgRWIgq7MLSK5srRzuOKI9fazBPplvA7T/naIrtgrDYRlF+N7Nzs aVLkFmy73N9q9ZE/IirHHTygjvvMinjKugjGL8ydk7hrdaJRPi3K+/CaMlfEh5dphQJZ QcdlMhj7/wUUAwSP7sy6w9+msWy0qEFbMkwTOO7M7e0CiiOxTI5sqNxGrA8pBLOLYMB+ 3YWg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ore1r+dKR4AsT7KxL88Hg8/dGPX/2Y8Acm9/4eCEojE=; b=RURXtPzIbBmZ3XjmuxwADGMAdmYFe4cDClFn8E1y5sehxZsokL68oXCcIUVYD94yTM Lp8EAhppjRoK2Dfuca92TK+eehlfkGJulwOMasUqSuFJjhR6qT2jeIlTRWNCsBFJy60X mNXZIkPFJYH1bms6z/oJa7ZdFGCs/W9v1nnqE+J6/+CmpX5XQV6hJsGcFP8aBojubvLi 8hfOHTGKL+VAu8a50QYTaQiAoGKa2+XK1eazWva3PZxFQiM7Pw0ZG1cLGFD0qoLzA0CL Btnib9l4w9RXtOdfEsLdsGiaAl/QBv1P5gF3KnlsCi8pBKB0govO9KrabDNKYPqpWGr/ i5wQ== X-Gm-Message-State: APjAAAV4f0TrlREkyi/jLKAZad+fnmd60JhyW3wxIhpRFpbS1wSoP2Vd e2iuYRIwivu7Zrsr/5YcNsPVFT1T X-Google-Smtp-Source: APXvYqy0bTm4jI4EyxEEibvtqTUC/09sCjBxlHpiBVsIbHD2fHjksgEWT1NhF5dHYSHrEwXtHO0wmw== X-Received: by 2002:a7b:c34b:: with SMTP id l11mr7581726wmj.69.1558807906172; Sat, 25 May 2019 11:11:46 -0700 (PDT) Received: from blackbox.darklights.net (p200300F133DDA4007CB8841254CD64FD.dip0.t-ipconnect.de. [2003:f1:33dd:a400:7cb8:8412:54cd:64fd]) by smtp.googlemail.com with ESMTPSA id o8sm12794540wra.4.2019.05.25.11.11.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 25 May 2019 11:11:45 -0700 (PDT) From: Martin Blumenstingl To: linux-amlogic@lists.infradead.org, linux-pwm@vger.kernel.org, thierry.reding@gmail.com, u.kleine-koenig@pengutronix.de Subject: [PATCH 02/14] pwm: meson: use devm_clk_get_optional() to get the input clock Date: Sat, 25 May 2019 20:11:21 +0200 Message-Id: <20190525181133.4875-3-martin.blumenstingl@googlemail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190525181133.4875-1-martin.blumenstingl@googlemail.com> References: <20190525181133.4875-1-martin.blumenstingl@googlemail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190525_111148_911317_E2B35509 X-CRM114-Status: GOOD ( 13.81 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Martin Blumenstingl , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Simplify the code which fetches the input clock for a PWM channel by using devm_clk_get_optional(). This comes with a small functional change: previously all errors except EPROBE_DEFER were ignored. Now all other errors are also treated as errors. If no input clock is present devm_clk_get_optional() will return NULL instead of an error which matches the behavior of the old code. Signed-off-by: Martin Blumenstingl Reviewed-by: Neil Armstrong --- drivers/pwm/pwm-meson.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/drivers/pwm/pwm-meson.c b/drivers/pwm/pwm-meson.c index 3fbbc4128ce8..35b38c7201c3 100644 --- a/drivers/pwm/pwm-meson.c +++ b/drivers/pwm/pwm-meson.c @@ -474,14 +474,9 @@ static int meson_pwm_init_channels(struct meson_pwm *meson, snprintf(name, sizeof(name), "clkin%u", i); - channel->clk_parent = devm_clk_get(dev, name); - if (IS_ERR(channel->clk_parent)) { - err = PTR_ERR(channel->clk_parent); - if (err == -EPROBE_DEFER) - return err; - - channel->clk_parent = NULL; - } + channel->clk_parent = devm_clk_get_optional(dev, name); + if (IS_ERR(channel->clk_parent)) + return PTR_ERR(channel->clk_parent); } return 0; From patchwork Sat May 25 18:11:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Blumenstingl X-Patchwork-Id: 10961075 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7F1DB1575 for ; Sat, 25 May 2019 18:29:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7248B28A86 for ; Sat, 25 May 2019 18:29:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 66C9628A8E; Sat, 25 May 2019 18:29:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 14BA228A86 for ; Sat, 25 May 2019 18:29:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=9We/Y/jKrqNH0kzwTKh9Q50JKCN7pj6htW7/hKlrGp8=; b=CmDD0O1WGAV/PF tbY87hlZZEKxMaY87BBw2AsV87P/K1OgEBeUoPB1STb0akwbtoWaauZnCqgWTCt14MJsxWfF5T1KK XsZS5jBR7FOp028aGmOC+LemJQhEnJDufQBvooEBjeIkAMEDfIEMNDyo4KQergWwZaOE+EOaNXnef plhOKR77wnCegXizL83ICa2gokpEDH4rwaZinorDV3wDCsGRBT1q/+/4NOdg48pUGvjGpy4W3oVbs GbIxeXyXf76nEunynEPhR2NtDuQ9JJeKX8sFNAZcAwkTeD0wHSFlb+cSf2b+ixq7LUSfbp/Z8MKHM +3sqHvmi2wPwAwMV1G3A==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hUbQR-0004Vb-4L; Sat, 25 May 2019 18:29:47 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hUbQ8-0003xz-6H; Sat, 25 May 2019 18:29:28 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=n+PNcF82aHvSsVWjJ6xxGU5P+zv9rDQAJYSA2FkuCyI=; b=BiOXZrxutnRNq3BIucJLphmMI/ pZaiyAS5FyzO5tWZx9iN9YFqK1spn4b0I/TxhYYqmOf5kt5Ocyx2KHHmR68hN8zsl9HE7C9ey4XrM 4HGG1sa/vNnSTgGara7VPdsWq8STF6WhZDgCYuws0dHPrPYpiD6cHmrmsl2dEOYWKhjW7m38oV9KN UPx/qKYuQja/0QsZRi6FAXFknRMdsj9mHF2dfz1pgKJRZbYWCU7OlDHjlz6tvt4L6GNM+Hk4xCU5L EJWt0eqJ+P2u42mTeTpA+aMcENVVKs6sINdTbFahx+krHi0NhLbfU7mYXLwhIz+ygBlpeC4wfw1gf zgoGgE9w==; Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]) by casper.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hUb93-00025W-He; Sat, 25 May 2019 18:11:51 +0000 Received: by mail-wm1-x341.google.com with SMTP id e19so4164338wme.1; Sat, 25 May 2019 11:11:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=n+PNcF82aHvSsVWjJ6xxGU5P+zv9rDQAJYSA2FkuCyI=; b=HOmH0HDkOr7SXnhIcKjEbMv5hPMaXwl9juWT/B/W2aqGGjOVQIs7AHYGMWCPwm/t4e Y9sFFjPKvWUkZvJs9lBPO5VekrHnjKFfFYeVP/x87C9QTOtgKpc3iSgm0lbbQVFazFWh YTvBXhbKt3wpBTV6JUp+0QMqVAOTiQeHQh1DUiSASdV5iLuuDjO5x3IoBXRBowoZ1gm0 Ab+rr6jnRMxNrVPd5gfDG9V9RrQTDjfUiUO8spS2+HSu+89X0Kr4sQGBnC8VsoZ5UI+2 wNxBUUSFXZCqPQfH61jVjEN7AKzhyzw1XmvSIfkW2lnTwukcYpWUgZFex6esZi28j4Xy XERA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=n+PNcF82aHvSsVWjJ6xxGU5P+zv9rDQAJYSA2FkuCyI=; b=PMpYvQCaleoocLOhngdekmGyk32vFHI7Y8PMFLlxHeNFVoXTiu2CVGrsQUWYN1sCXy DH6nkTRkl2n2zlQvGbs+/zd0tLJxUqnhKIe6ccE8ktyzv4rw5ETcpxwlUEPYB8/g5m2M HwLKclfivpZMUrvKkiKhdfxslPQjmgZldlWGgGasC7pEgjIdR3jsi1tREWbrohC/myls y1xVgHQr8ZNxZ4e1oAf9CmIRc0mu4E+ovpOY/kA7zTbqLE9GM6w3oAW/qmga3jlkvW0o 64tFFu8rgZwEiep4UJGM8FSZ+F1ioW5JjXvTZI4L8vN6b/xjXCcSPD9HOfDq5tYgnahl 6YJQ== X-Gm-Message-State: APjAAAXDJTx2GcScOGJbUb/l6+N5tNJrQhKftvH7M1gE9Py5hlFRGTes BsvQhDxLcLPmJYb+McHb8m4lbr19 X-Google-Smtp-Source: APXvYqxoBz1yNBbK0nsIKKxkJ6BPRwZafE9Jtj2RJXjDTEjHPteUwQIKRJc58Tq/sxZidVq4F1k8eA== X-Received: by 2002:a1c:cfc9:: with SMTP id f192mr7147926wmg.19.1558807907359; Sat, 25 May 2019 11:11:47 -0700 (PDT) Received: from blackbox.darklights.net (p200300F133DDA4007CB8841254CD64FD.dip0.t-ipconnect.de. [2003:f1:33dd:a400:7cb8:8412:54cd:64fd]) by smtp.googlemail.com with ESMTPSA id o8sm12794540wra.4.2019.05.25.11.11.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 25 May 2019 11:11:46 -0700 (PDT) From: Martin Blumenstingl To: linux-amlogic@lists.infradead.org, linux-pwm@vger.kernel.org, thierry.reding@gmail.com, u.kleine-koenig@pengutronix.de Subject: [PATCH 03/14] pwm: meson: use GENMASK and FIELD_PREP for the lo and hi values Date: Sat, 25 May 2019 20:11:22 +0200 Message-Id: <20190525181133.4875-4-martin.blumenstingl@googlemail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190525181133.4875-1-martin.blumenstingl@googlemail.com> References: <20190525181133.4875-1-martin.blumenstingl@googlemail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190525_191149_667103_50ED4351 X-CRM114-Status: GOOD ( 14.22 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Martin Blumenstingl , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP meson_pwm_calc() ensures that "lo" is always less than 16 bits wide (otherwise it would overflow into the "hi" part of the REG_PWM_{A,B} register). Use GENMASK and FIELD_PREP for the lo and hi values to make it easier to spot how wide these are internally. Additionally this is a preparation step for the .get_state() implementation where the GENMASK() for lo and hi becomes handy because it can be used with FIELD_GET() to extract the values from the register REG_PWM_{A,B} register. No functional changes intended. Signed-off-by: Martin Blumenstingl Reviewed-by: Neil Armstrong --- drivers/pwm/pwm-meson.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/drivers/pwm/pwm-meson.c b/drivers/pwm/pwm-meson.c index 35b38c7201c3..c62a3ac924d0 100644 --- a/drivers/pwm/pwm-meson.c +++ b/drivers/pwm/pwm-meson.c @@ -5,6 +5,8 @@ * Copyright (C) 2014 Amlogic, Inc. */ +#include +#include #include #include #include @@ -20,7 +22,8 @@ #define REG_PWM_A 0x0 #define REG_PWM_B 0x4 -#define PWM_HIGH_SHIFT 16 +#define PWM_LOW_MASK GENMASK(15, 0) +#define PWM_HIGH_MASK GENMASK(31, 16) #define REG_MISC_AB 0x8 #define MISC_B_CLK_EN BIT(23) @@ -217,7 +220,8 @@ static void meson_pwm_enable(struct meson_pwm *meson, struct pwm_device *pwm) value |= clk_enable; writel(value, meson->base + REG_MISC_AB); - value = (channel->hi << PWM_HIGH_SHIFT) | channel->lo; + value = FIELD_PREP(PWM_HIGH_MASK, channel->hi) | + FIELD_PREP(PWM_LOW_MASK, channel->lo); writel(value, meson->base + offset); value = readl(meson->base + REG_MISC_AB); From patchwork Sat May 25 18:11:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Blumenstingl X-Patchwork-Id: 10961069 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 72E7E14B6 for ; Sat, 25 May 2019 18:29:37 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6252B28A89 for ; Sat, 25 May 2019 18:29:37 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 514B528A86; Sat, 25 May 2019 18:29:37 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E2B7028A86 for ; Sat, 25 May 2019 18:29:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=iOCj6/H3dQzbyNjyV0UHaKowh3j31FHd9rOIUxKTUWw=; b=XmPy2BDXG+YMdW vCspLPT6EKk8j+WjiwVqIuyULsDdcLELBzGBTpLwETfG1SyE4j8yQ/emW27B4VM4Qr0MPt54lanmR Eae7t7Lv7dofQ+6jgJTI8rPVFWXKmSuS1VoeWaqHFuiR4FPml927/AOAPP7KuS7t3tWqLkTt3lOKS KGn9/UHhmCAV4SzuZMInboU2Ic28ZkwMvT8u7bixCLfF1i9qe25GeqNG4ou6yfC83GePfRYFuQzY2 d2690SMeKxoiXPHU4bzm+9EE2Ur0NeSeDhg9BoUoxrqmqB6Y3oINpr0O3+UbCx+4XzWGvS/eQRsGS POx4uxQrBPhaQ2595pXg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hUbQA-00049u-Sj; Sat, 25 May 2019 18:29:30 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hUbQ7-0003yY-E5; Sat, 25 May 2019 18:29:27 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help: List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=NTuYf2SN++XrzgOo/LowMD7xHt6KeFYnBiXdbjNn1Mc=; b=Wkvro0PLpZh/p9yhKXmTh5nYHH 2W2Id/f8Ak68LQwdtPEouQDetvEF3qsirUMbdv1mvdof2lqD99oPVvg1ibh2h/ClAT2JsB1yKUi5s 1il9AfTR1dJfPvIjN1SBqBIxT6GNoKIQprWQkK1xRx4ipKGgGlBDVdkE+SzVLwDkdSqDb51qEZvq9 qGA4ic74LpsYQcucFm1uTlN88eaMz/QPaITZOb0bVxxQ5IQx7zS6U+MLM/aj/dvQOB1ysr2QMchCP NCgHQp1Y41Xopl7NO1IF7N+sIlhOscGa1SyY6gt0ogEDjpl+8HgyPw4Him2/bCoCV/e4pBmk4Rpow wXB5FfGw==; Received: from mail-wm1-x341.google.com ([2a00:1450:4864:20::341]) by casper.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hUb93-00025u-Rv; Sat, 25 May 2019 18:11:53 +0000 Received: by mail-wm1-x341.google.com with SMTP id 7so12065954wmo.2; Sat, 25 May 2019 11:11:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NTuYf2SN++XrzgOo/LowMD7xHt6KeFYnBiXdbjNn1Mc=; b=VnKfwh0bGoV85geiehf3lF7Ro/8ZshaPwzuqppSHFpjUxlW8nxcaz1HWoxyvGuTRHz 8obIqVm7h0WsDAyI+PoOHI1yEHv+a7fGSkrf5sUrJhHMhyjVZtFCB2VVfe7dg6cEofUR dF3Yp4zbu3MiZn2VSAbwd77ukSrzUO/HqTAvT+lLvwLrqfIQbXDT91zKKyBLxuKgXCgK bbaGpLyRRMeYKs3Vm9/fMUZs+8EP+AKTGTAGqrh8Wj6NObw8RVZWCVpuoQZDIuJJsLRa kiK7rS/YY0lojeU0Pe3Kps2/+Oxqbt+LcAy7z44txeLaCTs7d72Dhg8lTx2lWyCosVIX XHLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=NTuYf2SN++XrzgOo/LowMD7xHt6KeFYnBiXdbjNn1Mc=; b=iJh3Nb4qmj41dGSAbhjvbzaqkyziCnDsgRAPSQUluYkdopBG70qIgqhbh2suD7xeM5 D7X1kMd9nKtij81+mER6KTej+lfDr1k6lVkijONgGVEHi1tmR+vKAjvgfeL4/kkHmAuJ FOdO+QCzBdor2tITUsOExUxNT5n7xEFNWnwK+Lo6iBtJTSnUWy7bWhUDFDyGNCGUqltq xKBV5LMLFkf6C6qJN9LKTwQL93/Ihj6gSPZZ1+Uem7J550CgECqxI7WrKyljpn9EW2HN meRM/eraRWFbgyuV4isfZI83MEt5oBmagblqGPnBmXdgP3UmaqAkj4pvmTMZJasZZhWY S8wQ== X-Gm-Message-State: APjAAAU6BzKL07yDwqwEu7K4fKpi/YB0qRy5GI9kZrGUw+5vADwJ/u0L 6oL6p8NbOmEX3OhALngadVuboKQl X-Google-Smtp-Source: APXvYqxzNHr1KHGccEbFz4UmNfvsgrRoH6NuLmip3pRZHRxdOtQ8QuPVBMnJaq2uWniu0zSEdRHOgA== X-Received: by 2002:a1c:e009:: with SMTP id x9mr4094446wmg.117.1558807908370; Sat, 25 May 2019 11:11:48 -0700 (PDT) Received: from blackbox.darklights.net (p200300F133DDA4007CB8841254CD64FD.dip0.t-ipconnect.de. [2003:f1:33dd:a400:7cb8:8412:54cd:64fd]) by smtp.googlemail.com with ESMTPSA id o8sm12794540wra.4.2019.05.25.11.11.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 25 May 2019 11:11:47 -0700 (PDT) From: Martin Blumenstingl To: linux-amlogic@lists.infradead.org, linux-pwm@vger.kernel.org, thierry.reding@gmail.com, u.kleine-koenig@pengutronix.de Subject: [PATCH 04/14] pwm: meson: change MISC_CLK_SEL_WIDTH to MISC_CLK_SEL_MASK Date: Sat, 25 May 2019 20:11:23 +0200 Message-Id: <20190525181133.4875-5-martin.blumenstingl@googlemail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190525181133.4875-1-martin.blumenstingl@googlemail.com> References: <20190525181133.4875-1-martin.blumenstingl@googlemail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190525_191150_000037_9C4C555D X-CRM114-Status: GOOD ( 13.98 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Martin Blumenstingl , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP MISC_CLK_SEL_WIDTH is only used in one place where it's converted into a bit-mask. Rename and change the macro to be a bit-mask so that conversion is not needed anymore. No functional changes intended. Signed-off-by: Martin Blumenstingl Reviewed-by: Neil Armstrong --- drivers/pwm/pwm-meson.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/pwm/pwm-meson.c b/drivers/pwm/pwm-meson.c index c62a3ac924d0..84b28ba0f903 100644 --- a/drivers/pwm/pwm-meson.c +++ b/drivers/pwm/pwm-meson.c @@ -33,7 +33,7 @@ #define MISC_A_CLK_DIV_SHIFT 8 #define MISC_B_CLK_SEL_SHIFT 6 #define MISC_A_CLK_SEL_SHIFT 4 -#define MISC_CLK_SEL_WIDTH 2 +#define MISC_CLK_SEL_MASK 0x3 #define MISC_B_EN BIT(1) #define MISC_A_EN BIT(0) @@ -463,7 +463,7 @@ static int meson_pwm_init_channels(struct meson_pwm *meson, channel->mux.reg = meson->base + REG_MISC_AB; channel->mux.shift = mux_reg_shifts[i]; - channel->mux.mask = BIT(MISC_CLK_SEL_WIDTH) - 1; + channel->mux.mask = MISC_CLK_SEL_MASK; channel->mux.flags = 0; channel->mux.lock = &meson->lock; channel->mux.table = NULL; From patchwork Sat May 25 18:11:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Blumenstingl X-Patchwork-Id: 10961011 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1404615A6 for ; Sat, 25 May 2019 18:12:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0560D28A86 for ; Sat, 25 May 2019 18:12:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EDBE628A8E; Sat, 25 May 2019 18:12:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A377628A86 for ; Sat, 25 May 2019 18:12:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=dg+8dWRLDKba5/FUGfp3sltJ0L3SOVhx+sxJRymLEvs=; b=gwNPg2vaowlWrz seC4bcusd4yZhthBdbRPpJEXGBiVabyjjy/U7XCzF6LN/LVYjjFxVwfiBfjtRBfgUavLDZ+SxaB9J yeX96TJx+rRBDlEn/EpP+jUOTa0FsGqzmKIbIgAO2DMBuApKquL8j4sHVi7s8rsCULtqVqrYALEn9 uyoH0SmaZ/npGElYp9GDs1QyDcjM+NS+oJQlc1psRUd/2hXXirlH+xg+bMPiSIvlHMF1kNRAmzX1l z9BGyx9v0QSUVtQ3JY3bWasDgs1YHaTY5VdJmiO4MOyiTIuULP1Lzw/vu73d1w2ZOeWdQBdEso+ty LsauwTJKjwKgitjA03Iw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hUb9l-0003G3-Lc; Sat, 25 May 2019 18:12:33 +0000 Received: from mail-wm1-f67.google.com ([209.85.128.67]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hUb96-0002Mr-5X; Sat, 25 May 2019 18:11:58 +0000 Received: by mail-wm1-f67.google.com with SMTP id i3so12324932wml.4; Sat, 25 May 2019 11:11:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Nn1lq5gWQykJ2fa3C4+FTZu1w/wv0i+nYPKx90V4RFM=; b=unEoYEq163JDPHz4GpYBoATDRMh+15QMqfxr+AHKhSvMSgwptHsRNKR8UMzbNUWkdb wsMB9PVohIZ05gyBMxH175ByVXPLK/OjYoTxNqwR/LChOSFJ285vN3v+1Wvt657xB39l Wjgpaq6C9cO0arrDdmKnWp1hljFYGJ+vpgtx6EB3qPeeFUz0+iccx7ebfYXdkfBqnU+3 PvInFGbDkBhjdOoQXLxa+Mxu9XMB+tA1YkxYf8pIwUIU/XV0naV8hSP3lMpiUCW29Fhl rhUOg3DvFJcIKHv6K2ktuXXOt7I/B5/f2oyx+5SDsa5yFt+946Q5icY0PvzXoQ54vJnc 8iKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Nn1lq5gWQykJ2fa3C4+FTZu1w/wv0i+nYPKx90V4RFM=; b=m3s9w/cAQQ2ls6IONaTQ6IQwktgpmE9+lx2MTeEd7G/vT3ITqFn8P58YAy8P9EnMze AtAHHFJ2Ypoht2WIOE2pR8ryX2JRduBC931WPzld+cEiofNmwMYzBs1G3XEcf+sTH7dH s27QiZr3/H31Swfw0yyBTQ/x71gXvkXZaxUvjg3l7lwMyZxGVr4DKT8neYV0RkcyVpbX 98BH3qfJ+knQS+qojEjzoVj6srSXp2TiCa1sHAE6O0uvVowQgxAPuRT7eBTBtYWPAj/n nX/87mxm4KKu5L0tBhEFkfNsbYRLVKcP12GZvShCnkk7+LxnEEfQgNeocCs2Vf55nLcH IJDA== X-Gm-Message-State: APjAAAX1qRlBKGlt2j6iyc7JPKqMgwKDBKSdYQ8ihqwGh2RuF3O8sy3r pDopHMk8J5N+gJO1kBHVvBpMLNP0 X-Google-Smtp-Source: APXvYqyArwVBOnsm4XmcG01yPAMcVx9BefPdZ5RdtyXTzaWpsVjGIOfb+gC8dfMpIwqaxfR6tXifMg== X-Received: by 2002:a1c:eb0c:: with SMTP id j12mr19669283wmh.55.1558807909296; Sat, 25 May 2019 11:11:49 -0700 (PDT) Received: from blackbox.darklights.net (p200300F133DDA4007CB8841254CD64FD.dip0.t-ipconnect.de. [2003:f1:33dd:a400:7cb8:8412:54cd:64fd]) by smtp.googlemail.com with ESMTPSA id o8sm12794540wra.4.2019.05.25.11.11.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 25 May 2019 11:11:48 -0700 (PDT) From: Martin Blumenstingl To: linux-amlogic@lists.infradead.org, linux-pwm@vger.kernel.org, thierry.reding@gmail.com, u.kleine-koenig@pengutronix.de Subject: [PATCH 05/14] pwm: meson: don't duplicate the polarity internally Date: Sat, 25 May 2019 20:11:24 +0200 Message-Id: <20190525181133.4875-6-martin.blumenstingl@googlemail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190525181133.4875-1-martin.blumenstingl@googlemail.com> References: <20190525181133.4875-1-martin.blumenstingl@googlemail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190525_111152_334435_1902C75C X-CRM114-Status: GOOD ( 14.25 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Martin Blumenstingl , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Let meson_pwm_calc() use the polarity from struct pwm_state directly. This removes a level of indirection where meson_pwm_apply() first had to set a driver-internal inverter mask which was then only used by meson_pwm_calc(). Instead of adding the polarity as parameter to meson_pwm_calc() switch to struct pwm_state directly to make it easier to see where the parameters are actually coming from. Signed-off-by: Martin Blumenstingl Reviewed-by: Neil Armstrong --- drivers/pwm/pwm-meson.c | 23 ++++++++--------------- 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/drivers/pwm/pwm-meson.c b/drivers/pwm/pwm-meson.c index 84b28ba0f903..39ea119add7b 100644 --- a/drivers/pwm/pwm-meson.c +++ b/drivers/pwm/pwm-meson.c @@ -63,7 +63,6 @@ struct meson_pwm { struct pwm_chip chip; const struct meson_pwm_data *data; void __iomem *base; - u8 inverter_mask; /* * Protects register (write) access to the REG_MISC_AB register * that is shared between the two PWMs. @@ -116,14 +115,17 @@ static void meson_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm) } static int meson_pwm_calc(struct meson_pwm *meson, - struct meson_pwm_channel *channel, unsigned int id, - unsigned int duty, unsigned int period) + struct meson_pwm_channel *channel, + struct pwm_state *state) { - unsigned int pre_div, cnt, duty_cnt; + unsigned int duty, period, pre_div, cnt, duty_cnt; unsigned long fin_freq = -1; u64 fin_ps; - if (~(meson->inverter_mask >> id) & 0x1) + duty = state->duty_cycle; + period = state->period; + + if (state->polarity == PWM_POLARITY_INVERSED) duty = period - duty; if (period == channel->state.period && @@ -278,15 +280,7 @@ static int meson_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, if (state->period != channel->state.period || state->duty_cycle != channel->state.duty_cycle || state->polarity != channel->state.polarity) { - if (state->polarity != channel->state.polarity) { - if (state->polarity == PWM_POLARITY_NORMAL) - meson->inverter_mask |= BIT(pwm->hwpwm); - else - meson->inverter_mask &= ~BIT(pwm->hwpwm); - } - - err = meson_pwm_calc(meson, channel, pwm->hwpwm, - state->duty_cycle, state->period); + err = meson_pwm_calc(meson, channel, state); if (err < 0) return err; @@ -520,7 +514,6 @@ static int meson_pwm_probe(struct platform_device *pdev) meson->chip.of_pwm_n_cells = 3; meson->data = of_device_get_match_data(&pdev->dev); - meson->inverter_mask = BIT(meson->chip.npwm) - 1; channels = devm_kcalloc(&pdev->dev, meson->chip.npwm, sizeof(*channels), GFP_KERNEL); From patchwork Sat May 25 18:11:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Blumenstingl X-Patchwork-Id: 10961037 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6161A16C1 for ; Sat, 25 May 2019 18:13:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 555E728A89 for ; Sat, 25 May 2019 18:13:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4991728A8E; Sat, 25 May 2019 18:13:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D277B28A96 for ; Sat, 25 May 2019 18:13:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Si0kRBxl2jLgXL9bkYEBrKjWPYBxexazh9eqK/qWoQw=; b=BxEw1eRjpnGKIX ZKK9cLinfDFtKHx/BtkrL1N2m2YdrgCwmZ5NsjglH1EbWp8fBr2/+w1tC7gVHPwF2S0y8BOO03Hug GEyGU5I7b+rDzbHlSWh+cDr4ywSYJkpqj7swwME8qPxWijC2MZDBpbfZUxXWv/gfOWhzYrmhJk6Nb BgNlgDw9ys8sZHU+5nSfLqzmOQRW0RHPYSwZr3b4bvr6lVxOwTHyvKPRdCUNe8oC3Cl0f/UwA8fym zKZbiczEPBbTzvVLbF+BnA7OE1uTQ6YKoIkbLEqDP3WGsEqUpKgG3CgtrGAFnxdpucx/Nn1R13X3+ W3L9lpn2EZJqB4GEGrng==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hUbB0-0004cV-37; Sat, 25 May 2019 18:13:50 +0000 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hUb95-0002N4-UN; Sat, 25 May 2019 18:11:57 +0000 Received: by mail-wm1-x343.google.com with SMTP id 198so12328489wme.3; Sat, 25 May 2019 11:11:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=kfVYlUJeQCHL5cSID78tPPaL8HnCS71jyLT/qQfWE0Y=; b=VptW1X7hURBN1YVC+q/LsurDbH+RmvNxxvli4gffs5StELw6dPFuEs3zWZrY11MakN CCRB5f63eRtJyiOYYObTObWvoPpRsHUO9rg1bROPf/+zVY7z2Pwd2qBAM4Gc0n1GaXWl vo4pUu86XALwiBqJG6WLQgHjHxljWQ61BOuO7cMOE90lJXPXZbulRkD0enpBM/BqwKL8 w+IF3LMyeHS+AkS4l8UP0lLB3JYXH3k795MWzp/t88hYUQ1eTj+rf/9Ox8TUXnbHmDch xEWedKpQ3/pLpso5MK7QqSSmLMLirFzT7SSXiDi/axfVhFrZvou3DWEaiyLVEgZ/EvxI c+OA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=kfVYlUJeQCHL5cSID78tPPaL8HnCS71jyLT/qQfWE0Y=; b=Y7aOW2+ArCicYSZUy0/RbPLsE9pA81iJUgt8v37LFKZVxrfgsL/wQ2J5cYI4q42LZL qhsn+s77aTSrpcY53q+T6zTLrPp+SqxHWccWcVIlYYFPHhmT1XSg0OAshxVo1kZFWsqO mC/ZkJ4bMFRRZOSk5B5Ywttza9Dp4naisFeTOBg34rkGQXE95DJFFkSDRLPnq9KSo5Vm xNIiPkojnZ+UV9EdgLNxgIlJBuf9P2U9g0SXfAh/3V55q0pbSXqeNfFrvI6XaLFCK1uH jsoEf3ktyXH/FfB43m6PmOEHjJXIu+ogMgHpcwcTP48CUyQTIatXApeDVgFna56Ralhe u3Rw== X-Gm-Message-State: APjAAAXliLLtlp0fRbAyiYTYX93sTq9SuSc3hAzno0+ylsVtdeIYwTNW TDrXwYkgDBwBWZ6HkMrQXeh8d7dH X-Google-Smtp-Source: APXvYqznM6UHLbHru14wH4QS6FkAKOANEzuRiTO0Lt36ObeG66JwdGsGb35NNstOPe7Tshf+VUKKWQ== X-Received: by 2002:a1c:be03:: with SMTP id o3mr3208464wmf.139.1558807910263; Sat, 25 May 2019 11:11:50 -0700 (PDT) Received: from blackbox.darklights.net (p200300F133DDA4007CB8841254CD64FD.dip0.t-ipconnect.de. [2003:f1:33dd:a400:7cb8:8412:54cd:64fd]) by smtp.googlemail.com with ESMTPSA id o8sm12794540wra.4.2019.05.25.11.11.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 25 May 2019 11:11:49 -0700 (PDT) From: Martin Blumenstingl To: linux-amlogic@lists.infradead.org, linux-pwm@vger.kernel.org, thierry.reding@gmail.com, u.kleine-koenig@pengutronix.de Subject: [PATCH 06/14] pwm: meson: pass struct pwm_device to meson_pwm_calc() Date: Sat, 25 May 2019 20:11:25 +0200 Message-Id: <20190525181133.4875-7-martin.blumenstingl@googlemail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190525181133.4875-1-martin.blumenstingl@googlemail.com> References: <20190525181133.4875-1-martin.blumenstingl@googlemail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190525_111152_077617_2D74A226 X-CRM114-Status: GOOD ( 14.39 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Martin Blumenstingl , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP meson_pwm_calc() is the last function that accepts a struct meson_pwm_channel. meson_pwm_enable(), meson_pwm_disable() and meson_pwm_apply() for example are all taking a struct pwm_device as parameter. When they need the struct meson_pwm_channel these functions simply call pwm_get_chip_data() internally. Make meson_pwm_calc() consistent with the other functions in the meson-pwm driver by passing struct pwm_device to it as well. The value of the "id" parameter is actually pwm->hwpwm, but the driver never read the "id" parameter, which is why there's no replacement for it in the new code. No functional changes. Signed-off-by: Martin Blumenstingl Reviewed-by: Neil Armstrong --- drivers/pwm/pwm-meson.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/pwm/pwm-meson.c b/drivers/pwm/pwm-meson.c index 39ea119add7b..d6eb4d04d5c9 100644 --- a/drivers/pwm/pwm-meson.c +++ b/drivers/pwm/pwm-meson.c @@ -114,10 +114,10 @@ static void meson_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm) clk_disable_unprepare(channel->clk); } -static int meson_pwm_calc(struct meson_pwm *meson, - struct meson_pwm_channel *channel, +static int meson_pwm_calc(struct meson_pwm *meson, struct pwm_device *pwm, struct pwm_state *state) { + struct meson_pwm_channel *channel = pwm_get_chip_data(pwm); unsigned int duty, period, pre_div, cnt, duty_cnt; unsigned long fin_freq = -1; u64 fin_ps; @@ -280,7 +280,7 @@ static int meson_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, if (state->period != channel->state.period || state->duty_cycle != channel->state.duty_cycle || state->polarity != channel->state.polarity) { - err = meson_pwm_calc(meson, channel, state); + err = meson_pwm_calc(meson, pwm, state); if (err < 0) return err; From patchwork Sat May 25 18:11:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Blumenstingl X-Patchwork-Id: 10961013 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C0FC015A6 for ; Sat, 25 May 2019 18:12:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B334628A86 for ; Sat, 25 May 2019 18:12:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id A78EC28A8E; Sat, 25 May 2019 18:12:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 25D4928A86 for ; Sat, 25 May 2019 18:12:45 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=hNiTEl7yivlBitaUeRKu1+BOgO5XyVKI4CCr1R3UQhY=; b=tgO6iMJN9RwYcv VACPiQJ3r18nZBAEkQDRCHnlwiJHih3BVE55S67SdIqwaAlipmM/edRWMq4xb1mS/UmAOCe6u5msM T97JWdf2X5zPH7MDdWqcaVazKl3IluveMXSU5n4mm3+TMM3Q+eBgF9Ra58srb9SuK7AgmNIQS7+Kr xq4LWS8WiXqHDlVO16fp/MarYF5F7pRn6fANZPQFbT9XN8M+b//SuRl3pJIIg7sIVztlC40dGF82c 2JKyURxGaMI3PEq/ASP3+dXaamHEsZSvvuKI4OONMRRPiNnVQEtL+wDo7xrgeqhmukJqm37W86U5r YauQzbzNFTzNIBDTPu4g==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hUb9s-0003PU-2H; Sat, 25 May 2019 18:12:40 +0000 Received: from mail-wm1-f67.google.com ([209.85.128.67]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hUb97-0002OF-F7; Sat, 25 May 2019 18:11:59 +0000 Received: by mail-wm1-f67.google.com with SMTP id w9so5955622wmi.0; Sat, 25 May 2019 11:11:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Vh14UlgAUkIljLzMtiNlC8F9kkg89y0/Qk0nPY9Q0wE=; b=OjPmG7u32W9bxtU+VPzPQ2qz0WmWIeBCLlAPE1sPJKMDIcVNrBXNHO8lsnVIdo9y45 h6F8//QMAxceKMyJKGFM9RRrKYieWqB7w3GLxVrX0EvdS26Gg7eWJXpax4v8lqNKr1FA KjRZpJpET0Xxy+cqpkr5+ggty2RCtjYF/ctI4KryecNx+wtznDh7jGF6XdYApiUT9pLP DfxsTTfB2Nczb7CW7GdDKV1zVu9C9Rm3KsA7V21//c4pfMVUyPfKGSNI76lptF49iBYr AS+gKKFj6HSUB05ukiH7B/yF9mYO6ttVAMaYBidN9uw4bvh2MyR5/j/yudLjq+Pd7yTb NMKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Vh14UlgAUkIljLzMtiNlC8F9kkg89y0/Qk0nPY9Q0wE=; b=psbPSCZnaCWZISepOxEkhLyMmNNpx9gqgjqy1iFLx+ojUsxSLSCk8XPdIihUlYVN3C VbsYC/4PO6CDwtaIboTFtCtlJK281jKiodsu876yEBFs7zWGzokT3XDviMZq0mCjrzNb +AhBJy892+i2BcUA+KG2tlxIeFN0wWZuauQyfa6OVPm6ztJSTRHsIhviwU340kn/HHh3 tMC2CsM4zeMEuLIzFqljR6aQA/atOkEfj9vVictrXKFj0jGIqzsJBB+c/UP5CBAuD8mb 3TLHILloSFED8sG2nyNTOnLk0dQmkW1yKaleGOefW6iSUL4VhKt5hCwQTu5stUF1MJ/V DE6g== X-Gm-Message-State: APjAAAUaFYSK1RjtCutCPn3GSYXdI5VebTvXNRepF5bpPabqqX3qA0po L4+q/1q7046a8lfe5XSZ5SaXteYH X-Google-Smtp-Source: APXvYqxA7x6dY6V0ULEhoWOYWuPm0XWiLfS7y9OgJaQ+D2//vYFJ/epu6mol03rolVLlg+EqXN3MIw== X-Received: by 2002:a1c:b789:: with SMTP id h131mr4004748wmf.71.1558807911278; Sat, 25 May 2019 11:11:51 -0700 (PDT) Received: from blackbox.darklights.net (p200300F133DDA4007CB8841254CD64FD.dip0.t-ipconnect.de. [2003:f1:33dd:a400:7cb8:8412:54cd:64fd]) by smtp.googlemail.com with ESMTPSA id o8sm12794540wra.4.2019.05.25.11.11.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 25 May 2019 11:11:50 -0700 (PDT) From: Martin Blumenstingl To: linux-amlogic@lists.infradead.org, linux-pwm@vger.kernel.org, thierry.reding@gmail.com, u.kleine-koenig@pengutronix.de Subject: [PATCH 07/14] pwm: meson: add the meson_pwm_channel data to struct meson_pwm Date: Sat, 25 May 2019 20:11:26 +0200 Message-Id: <20190525181133.4875-8-martin.blumenstingl@googlemail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190525181133.4875-1-martin.blumenstingl@googlemail.com> References: <20190525181133.4875-1-martin.blumenstingl@googlemail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190525_111153_524125_3AB88D79 X-CRM114-Status: GOOD ( 15.29 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Martin Blumenstingl , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Make struct meson_pwm_channel accessible from struct meson_pwm. PWM core has a limitation: per-channel data can only be set after pwmchip_add() is called. However, pwmchip_add() internally calls pwm_ops.get_state(). If pwm_ops.get_state() needs access to the per-channel data it has to obtain it from struct pwm_chip and struct pwm_device's hwpwm information. Add a struct meson_pwm_channel for each PWM channel to struct meson_pwm so the pwm_ops.get_state() callback can be implemented as it needs access to the clock from struct meson_pwm_channel. Signed-off-by: Martin Blumenstingl Reviewed-by: Neil Armstrong --- drivers/pwm/pwm-meson.c | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/drivers/pwm/pwm-meson.c b/drivers/pwm/pwm-meson.c index d6eb4d04d5c9..d1718f54ecec 100644 --- a/drivers/pwm/pwm-meson.c +++ b/drivers/pwm/pwm-meson.c @@ -37,6 +37,8 @@ #define MISC_B_EN BIT(1) #define MISC_A_EN BIT(0) +#define MESON_NUM_PWMS 2 + static const unsigned int mux_reg_shifts[] = { MISC_A_CLK_SEL_SHIFT, MISC_B_CLK_SEL_SHIFT @@ -62,6 +64,7 @@ struct meson_pwm_data { struct meson_pwm { struct pwm_chip chip; const struct meson_pwm_data *data; + struct meson_pwm_channel channels[MESON_NUM_PWMS]; void __iomem *base; /* * Protects register (write) access to the REG_MISC_AB register @@ -435,8 +438,7 @@ static const struct of_device_id meson_pwm_matches[] = { }; MODULE_DEVICE_TABLE(of, meson_pwm_matches); -static int meson_pwm_init_channels(struct meson_pwm *meson, - struct meson_pwm_channel *channels) +static int meson_pwm_init_channels(struct meson_pwm *meson) { struct device *dev = meson->chip.dev; struct clk_init_data init; @@ -445,7 +447,7 @@ static int meson_pwm_init_channels(struct meson_pwm *meson, int err; for (i = 0; i < meson->chip.npwm; i++) { - struct meson_pwm_channel *channel = &channels[i]; + struct meson_pwm_channel *channel = &meson->channels[i]; snprintf(name, sizeof(name), "%s#mux%u", dev_name(dev), i); @@ -480,18 +482,16 @@ static int meson_pwm_init_channels(struct meson_pwm *meson, return 0; } -static void meson_pwm_add_channels(struct meson_pwm *meson, - struct meson_pwm_channel *channels) +static void meson_pwm_add_channels(struct meson_pwm *meson) { unsigned int i; for (i = 0; i < meson->chip.npwm; i++) - pwm_set_chip_data(&meson->chip.pwms[i], &channels[i]); + pwm_set_chip_data(&meson->chip.pwms[i], &meson->channels[i]); } static int meson_pwm_probe(struct platform_device *pdev) { - struct meson_pwm_channel *channels; struct meson_pwm *meson; struct resource *regs; int err; @@ -509,18 +509,13 @@ static int meson_pwm_probe(struct platform_device *pdev) meson->chip.dev = &pdev->dev; meson->chip.ops = &meson_pwm_ops; meson->chip.base = -1; - meson->chip.npwm = 2; + meson->chip.npwm = MESON_NUM_PWM; meson->chip.of_xlate = of_pwm_xlate_with_flags; meson->chip.of_pwm_n_cells = 3; meson->data = of_device_get_match_data(&pdev->dev); - channels = devm_kcalloc(&pdev->dev, meson->chip.npwm, - sizeof(*channels), GFP_KERNEL); - if (!channels) - return -ENOMEM; - - err = meson_pwm_init_channels(meson, channels); + err = meson_pwm_init_channels(meson); if (err < 0) return err; @@ -530,7 +525,7 @@ static int meson_pwm_probe(struct platform_device *pdev) return err; } - meson_pwm_add_channels(meson, channels); + meson_pwm_add_channels(meson); platform_set_drvdata(pdev, meson); From patchwork Sat May 25 18:11:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Blumenstingl X-Patchwork-Id: 10961015 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DF85E933 for ; Sat, 25 May 2019 18:12:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D17D228A86 for ; Sat, 25 May 2019 18:12:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C51BC28A8E; Sat, 25 May 2019 18:12:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 4B89128A86 for ; Sat, 25 May 2019 18:12:57 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=nIzUWlQTS8ZGyRJ0nnNcybtIOuKyDBKs4sqNqeZH6jA=; b=FaeGz3jclKydMe l9XoN/UR6++znQ+Z750t/SuP7hEXrNpSkI63IZrp+TEBGBaiCjdDzNh/DfPErM4FSW399tobfordw l5SrdqosC8GhvCIHqaBFios2ZB/CO8RWfRUz1QyA7OZzFb1t2EsueRhZ6m3WeLeilSkMU+sF4gj8c S9AUWFTaF0PjlBw7Jr88kIHfbGUYqgYuuyOczs+9MJoxZ/oltv7Ovw+cij7dXsGgfrRjRAUmbCUaf 6aUVNJvyncamdoXpJIwMYp98dWuE5S46Og2bMqzUm/bCTwrRQqS5PdPiK7qJy/xXhNVcFy0qxyOoi znzAvXrFz6ckLUY8202A==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hUbA4-0003ht-S4; Sat, 25 May 2019 18:12:52 +0000 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hUb99-0002P0-HL; Sat, 25 May 2019 18:12:00 +0000 Received: by mail-wr1-x442.google.com with SMTP id e15so12964732wrs.4; Sat, 25 May 2019 11:11:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=CyBCl9uJwWt7AOB0uEXJnfkxqm8+ZxkuNoLVczPbksU=; b=kn503yMbuHx1wxsfWJIIN6JXq8oS3QFiw9BnhvEFjXWRxOiGHGPRRqBOng51g0BEqx WfRTnH9zN3cVH2DsjOHlwdh99SAc1pS99E0WwOraaD/iVyu9/XEQrILX0Bh+31yM7cBf r6MTEQUR45SpKg/A6Ec5vs4KeyXOH4pPAQY+7xjnpXJ+9wzzoMEznIwobLzau+jObssn YrRBLPMrjVNqpwk9iQKTNVnYwQ9+kAa2whx3Wj8HHRDUJuRUDlHw49ukL+KYNmVTLnzB v19FRLFC1Za5u43a+OKAr8n4UoTG46yX8PWiSdg3lrcSSlCd3jFTfTugd7z1b5NMsMsW DUvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=CyBCl9uJwWt7AOB0uEXJnfkxqm8+ZxkuNoLVczPbksU=; b=tMexlf5oVl/7GvJ9BAz5AvEELmhSUDTO/UvBVVdBuOtcLg/HrcCMxBUttWWv4i6bae o83g/oUgpQ8+auEb5rR6L35bQFGeJGpYSRUkH5VhEltDUF4SmADFvBdDmcLV5N+ZOdxw wTiwI+NjAYsCpNRIIZYgbPnzmQaq4pxEGO4jQOrVQ8vDftUqsLyaO7Gb5BZtO/hPxg7M OlnGU0pmVuMThc4PRJv6mC7CZz0fn8Dve4vHjX0bdJdLuf92c26hMXxFavB3pI+B1esN khQiw2H/ymLfYdcARoWBwe68fQQQzmXV6+z+y6ca8qb/nLMN2vLhEjASFveYrUjtJ7j/ XNgQ== X-Gm-Message-State: APjAAAW+P9Uub+p5W3nVSBSDk9oGLNvWeGeUKiy7W9f3dZUxnGSm7VCC rIKy17DnkWphnDTpJPKzKczw0jCK X-Google-Smtp-Source: APXvYqwMf6MQWMh2QCNyAFBt1iEO1oomE5pIjoqBQPxPKCDgzSwR5+L7xOXWFnXFRLijnUKxosY5/A== X-Received: by 2002:adf:f78d:: with SMTP id q13mr20309064wrp.220.1558807913721; Sat, 25 May 2019 11:11:53 -0700 (PDT) Received: from blackbox.darklights.net (p200300F133DDA4007CB8841254CD64FD.dip0.t-ipconnect.de. [2003:f1:33dd:a400:7cb8:8412:54cd:64fd]) by smtp.googlemail.com with ESMTPSA id o8sm12794540wra.4.2019.05.25.11.11.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 25 May 2019 11:11:52 -0700 (PDT) From: Martin Blumenstingl To: linux-amlogic@lists.infradead.org, linux-pwm@vger.kernel.org, thierry.reding@gmail.com, u.kleine-koenig@pengutronix.de Subject: [PATCH 08/14] pwm: meson: add the per-channel register offsets and bits in a struct Date: Sat, 25 May 2019 20:11:27 +0200 Message-Id: <20190525181133.4875-9-martin.blumenstingl@googlemail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190525181133.4875-1-martin.blumenstingl@googlemail.com> References: <20190525181133.4875-1-martin.blumenstingl@googlemail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190525_111155_817996_A5D49BB9 X-CRM114-Status: GOOD ( 14.24 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Martin Blumenstingl , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Introduce struct meson_pwm_channel_data which contains the per-channel offsets for the PWM register and REG_MISC_AB bits. Replace the existing switch (pwm->hwpwm) statements with an access to the new struct. This simplifies the code and will make it easier to implement pwm_ops.get_state() because the switch-case which all per-channel registers and offsets (as previously implemented in meson_pwm_enable()) doesn't have to be duplicated. No functional changes intended. Signed-off-by: Martin Blumenstingl Reviewed-by: Neil Armstrong --- drivers/pwm/pwm-meson.c | 92 ++++++++++++++++------------------------- 1 file changed, 35 insertions(+), 57 deletions(-) diff --git a/drivers/pwm/pwm-meson.c b/drivers/pwm/pwm-meson.c index d1718f54ecec..ac7e188155fd 100644 --- a/drivers/pwm/pwm-meson.c +++ b/drivers/pwm/pwm-meson.c @@ -39,9 +39,27 @@ #define MESON_NUM_PWMS 2 -static const unsigned int mux_reg_shifts[] = { - MISC_A_CLK_SEL_SHIFT, - MISC_B_CLK_SEL_SHIFT +static struct meson_pwm_channel_data { + u8 reg_offset; + u8 clk_sel_shift; + u8 clk_div_shift; + u32 clk_en_mask; + u32 pwm_en_mask; +} meson_pwm_per_channel_data[MESON_NUM_PWMS] = { + { + .reg_offset = REG_PWM_A, + .clk_sel_shift = MISC_A_CLK_SEL_SHIFT, + .clk_div_shift = MISC_A_CLK_DIV_SHIFT, + .clk_en_mask = MISC_A_CLK_EN, + .pwm_en_mask = MISC_A_EN, + }, + { + .reg_offset = REG_PWM_B, + .clk_sel_shift = MISC_B_CLK_SEL_SHIFT, + .clk_div_shift = MISC_B_CLK_DIV_SHIFT, + .clk_en_mask = MISC_B_CLK_EN, + .pwm_en_mask = MISC_B_EN, + } }; struct meson_pwm_channel { @@ -194,43 +212,26 @@ static int meson_pwm_calc(struct meson_pwm *meson, struct pwm_device *pwm, static void meson_pwm_enable(struct meson_pwm *meson, struct pwm_device *pwm) { struct meson_pwm_channel *channel = pwm_get_chip_data(pwm); - u32 value, clk_shift, clk_enable, enable; - unsigned int offset; + struct meson_pwm_channel_data *channel_data; unsigned long flags; + u32 value; - switch (pwm->hwpwm) { - case 0: - clk_shift = MISC_A_CLK_DIV_SHIFT; - clk_enable = MISC_A_CLK_EN; - enable = MISC_A_EN; - offset = REG_PWM_A; - break; - - case 1: - clk_shift = MISC_B_CLK_DIV_SHIFT; - clk_enable = MISC_B_CLK_EN; - enable = MISC_B_EN; - offset = REG_PWM_B; - break; - - default: - return; - } + channel_data = &meson_pwm_per_channel_data[pwm->hwpwm]; spin_lock_irqsave(&meson->lock, flags); value = readl(meson->base + REG_MISC_AB); - value &= ~(MISC_CLK_DIV_MASK << clk_shift); - value |= channel->pre_div << clk_shift; - value |= clk_enable; + value &= ~(MISC_CLK_DIV_MASK << channel_data->clk_div_shift); + value |= channel->pre_div << channel_data->clk_div_shift; + value |= channel_data->clk_en_mask; writel(value, meson->base + REG_MISC_AB); value = FIELD_PREP(PWM_HIGH_MASK, channel->hi) | FIELD_PREP(PWM_LOW_MASK, channel->lo); - writel(value, meson->base + offset); + writel(value, meson->base + channel_data->reg_offset); value = readl(meson->base + REG_MISC_AB); - value |= enable; + value |= channel_data->pwm_en_mask; writel(value, meson->base + REG_MISC_AB); spin_unlock_irqrestore(&meson->lock, flags); @@ -238,26 +239,13 @@ static void meson_pwm_enable(struct meson_pwm *meson, struct pwm_device *pwm) static void meson_pwm_disable(struct meson_pwm *meson, struct pwm_device *pwm) { - u32 value, enable; unsigned long flags; - - switch (pwm->hwpwm) { - case 0: - enable = MISC_A_EN; - break; - - case 1: - enable = MISC_B_EN; - break; - - default: - return; - } + u32 value; spin_lock_irqsave(&meson->lock, flags); value = readl(meson->base + REG_MISC_AB); - value &= ~enable; + value &= ~meson_pwm_per_channel_data[pwm->hwpwm].pwm_en_mask; writel(value, meson->base + REG_MISC_AB); spin_unlock_irqrestore(&meson->lock, flags); @@ -309,18 +297,7 @@ static void meson_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm, if (!state) return; - switch (pwm->hwpwm) { - case 0: - mask = MISC_A_EN; - break; - - case 1: - mask = MISC_B_EN; - break; - - default: - return; - } + mask = meson_pwm_per_channel_data[pwm->hwpwm].pwm_en_mask; value = readl(meson->base + REG_MISC_AB); state->enabled = (value & mask) != 0; @@ -458,7 +435,8 @@ static int meson_pwm_init_channels(struct meson_pwm *meson) init.num_parents = meson->data->num_parents; channel->mux.reg = meson->base + REG_MISC_AB; - channel->mux.shift = mux_reg_shifts[i]; + channel->mux.shift = + meson_pwm_per_channel_data[i].clk_sel_shift; channel->mux.mask = MISC_CLK_SEL_MASK; channel->mux.flags = 0; channel->mux.lock = &meson->lock; @@ -509,7 +487,7 @@ static int meson_pwm_probe(struct platform_device *pdev) meson->chip.dev = &pdev->dev; meson->chip.ops = &meson_pwm_ops; meson->chip.base = -1; - meson->chip.npwm = MESON_NUM_PWM; + meson->chip.npwm = MESON_NUM_PWMS; meson->chip.of_xlate = of_pwm_xlate_with_flags; meson->chip.of_pwm_n_cells = 3; From patchwork Sat May 25 18:11:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Blumenstingl X-Patchwork-Id: 10961049 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0753615A6 for ; Sat, 25 May 2019 18:17:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ED93328A86 for ; Sat, 25 May 2019 18:17:39 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E1C0D28A8E; Sat, 25 May 2019 18:17:39 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7E07028A86 for ; Sat, 25 May 2019 18:17:39 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=qnrw/33+HosiVVCGW5DusumLpy63v5n7lZow2zSrEOw=; b=pgbw+A/Kpk9kOV rFXLeBiVSxVIGiX5zqqnm0doJbZhgVzSk/WrfKx4wk85swXbBjLqCHNDIkBxMw7OPBw3rRknvuGjp mx6kY5jheXGJnZ8ucD1Jm8XzhCN7EmY5G7a2aKsxbRALKYwJemgx3ow1/v6ja47U19XgvJyQiGXLW iYDH9IUhEZg7ppmNDApT97YQ21Zq8LbNmHE5mzM+8w4iy8bOZFerkag4MnqFUZl80euCAYfAF3wUu KIWiXvlUgkOuneVwsPJQFRdJ9yBufTLfm+KSMdNSWsM4TN2w1B+/YK0BYnHVqj8vtKJ81GRiIrNDg iXXu9yESXrNCPBoDPf2g==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hUbBW-00053s-HS; Sat, 25 May 2019 18:14:22 +0000 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hUb9B-0002PR-5f; Sat, 25 May 2019 18:12:01 +0000 Received: by mail-wr1-x443.google.com with SMTP id m3so12960984wrv.2; Sat, 25 May 2019 11:11:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Sl7WM07hR08H8EVlL8BEDz+//aYuTyGwlSt+xVLLPA4=; b=O9vmAF+kUMYIvRHKCOfkAeLiseR0j9hjltBcchi7dPoB1PdjYN/fh4BGKbMFqWJ4fq e9hoZDAqwcd2LSGT2Jc/wze2oAt7dwfuAFkmI97eCraeCt3P4VNt5oOTE9P1tSPaKzr/ zDG7D/Cgur2Xzbpe5HDWRAKdJkF0adTJbSjiLMJZPrIxlHLn+1xtLcVelB23HCcDA2pa cXNVEGslH5NPNCl2kjZG9k93tbyRYibtycc90au0J73llwos3miKLJNkfZ+2f258CI1k HkbXBRucsaazWpeFmzpVLs99R7G9/7ncEaUSiLczsOAq9sSuVXP+yPrxVFXmCrqsbyyJ JPoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Sl7WM07hR08H8EVlL8BEDz+//aYuTyGwlSt+xVLLPA4=; b=pmFvyXOdmL5u2zACuNJcTuxrrtK0YQ8Y/P1dGapbjtRA/0Oyjt+FnL7lRUTgNnVJYY 0kvqzgERqsD4ol7P2oU0x8pNoXnAzHzdLrvyekzW7VE60o8VNskXMSwhRAoRdArmFQaN GPg51s8SlVQrKwn1QnUTkhW/ac8phT9w7pa971LCIWSdW6W3jU0H2Q8K3n94ezsxIAYu 1vFBdflt00DfERdvnRPkAg7x10qtPS3gsr7UZ0ZZjD1pIHPqD/4WqcSuR6k1JdqTUVZ2 9uc+UhfivI0e7ZXfIDyn5qt1+s38G/xQw9FV/EzOwWIvTY/SPBIKXAnMm9izrjqpuF28 XjEQ== X-Gm-Message-State: APjAAAXFRSFf96ubJOysUBqhyx4nggvyVc9sMLDKvgoY2z7Sy4c50KfZ aAy/IJCfP+jU9p7pZY9QA42ykdzf X-Google-Smtp-Source: APXvYqwz71MupkKANwKXksSJkIrXoMmQ+E9SpGbvVw8Rc58UkwUoghdumGcrzpipFiQqlugZA/dc5g== X-Received: by 2002:adf:f6cb:: with SMTP id y11mr9814990wrp.67.1558807914809; Sat, 25 May 2019 11:11:54 -0700 (PDT) Received: from blackbox.darklights.net (p200300F133DDA4007CB8841254CD64FD.dip0.t-ipconnect.de. [2003:f1:33dd:a400:7cb8:8412:54cd:64fd]) by smtp.googlemail.com with ESMTPSA id o8sm12794540wra.4.2019.05.25.11.11.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 25 May 2019 11:11:54 -0700 (PDT) From: Martin Blumenstingl To: linux-amlogic@lists.infradead.org, linux-pwm@vger.kernel.org, thierry.reding@gmail.com, u.kleine-koenig@pengutronix.de Subject: [PATCH 09/14] pwm: meson: move pwm_set_chip_data() to meson_pwm_request() Date: Sat, 25 May 2019 20:11:28 +0200 Message-Id: <20190525181133.4875-10-martin.blumenstingl@googlemail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190525181133.4875-1-martin.blumenstingl@googlemail.com> References: <20190525181133.4875-1-martin.blumenstingl@googlemail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190525_111157_214291_A7D50E50 X-CRM114-Status: GOOD ( 14.55 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Martin Blumenstingl , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP All existing PWM drivers (except pwm-meson and two other ones) call pwm_set_chip_data() from their pwm_ops.request() callback. Now that we can access the struct meson_pwm_channel from struct meson_pwm we can do the same. Move the call to pwm_set_chip_data() to meson_pwm_request() and drop the custom meson_pwm_add_channels(). This makes the implementation consistent with other drivers and makes it slightly more obvious thatpwm_get_chip_data() cannot be used from pwm_ops.get_state() (because that's called by the PWM core before pwm_ops.request()). No functional changes intended. Signed-off-by: Martin Blumenstingl Reviewed-by: Neil Armstrong --- drivers/pwm/pwm-meson.c | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/drivers/pwm/pwm-meson.c b/drivers/pwm/pwm-meson.c index ac7e188155fd..27915d6475e3 100644 --- a/drivers/pwm/pwm-meson.c +++ b/drivers/pwm/pwm-meson.c @@ -98,12 +98,16 @@ static inline struct meson_pwm *to_meson_pwm(struct pwm_chip *chip) static int meson_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm) { - struct meson_pwm_channel *channel = pwm_get_chip_data(pwm); + struct meson_pwm *meson = to_meson_pwm(chip); + struct meson_pwm_channel *channel; struct device *dev = chip->dev; int err; - if (!channel) - return -ENODEV; + channel = pwm_get_chip_data(pwm); + if (channel) + return 0; + + channel = &meson->channels[pwm->hwpwm]; if (channel->clk_parent) { err = clk_set_parent(channel->clk, channel->clk_parent); @@ -124,7 +128,7 @@ static int meson_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm) chip->ops->get_state(chip, pwm, &channel->state); - return 0; + return pwm_set_chip_data(pwm, channel); } static void meson_pwm_free(struct pwm_chip *chip, struct pwm_device *pwm) @@ -460,14 +464,6 @@ static int meson_pwm_init_channels(struct meson_pwm *meson) return 0; } -static void meson_pwm_add_channels(struct meson_pwm *meson) -{ - unsigned int i; - - for (i = 0; i < meson->chip.npwm; i++) - pwm_set_chip_data(&meson->chip.pwms[i], &meson->channels[i]); -} - static int meson_pwm_probe(struct platform_device *pdev) { struct meson_pwm *meson; @@ -503,8 +499,6 @@ static int meson_pwm_probe(struct platform_device *pdev) return err; } - meson_pwm_add_channels(meson); - platform_set_drvdata(pdev, meson); return 0; From patchwork Sat May 25 18:11:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Martin Blumenstingl X-Patchwork-Id: 10961059 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id EA95215A6 for ; Sat, 25 May 2019 18:18:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DDC7A28A86 for ; Sat, 25 May 2019 18:18:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CF85228A8E; Sat, 25 May 2019 18:18:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 65BC928A86 for ; Sat, 25 May 2019 18:18:49 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=EbivB+gJtK/NKkSaOHtdNUuGhuweyFO0M8xmSNET+M0=; b=u67pbl91es7K24 Fpi3dH3WPu9GY7PyJWeDLYJ5KCY0ASgiaMBYvi5EF++9iVKAED27yoS8aMmxuWTcJtWI0etFgXbOj zJdSO1gFfErpXhpCZmCjFy2VigfKkwzICU8K9CnZw5UbRfXeo8S8p7PXvMDJYNMTigWLxKN9Szgi3 r8kzGhyfmrx1PDop/0VxdMbMRlLV6qAtfZVy6dWqhaFu+xvr0NR7u7lmfbAY5c/T0IG2OJL+I79rv E34U7OHEgDZHeH2/nsBCbAbj+YBw+s4i9va/Iv5qkueADsfQNu5jRUpzVlQ4gBhx5acNlWiYB94o6 R6e+6UM0ivv73UzSufJQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hUbBa-00056I-7M; Sat, 25 May 2019 18:14:26 +0000 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hUb9B-0002Pv-GI; Sat, 25 May 2019 18:12:01 +0000 Received: by mail-wr1-x443.google.com with SMTP id d9so12968690wrx.0; Sat, 25 May 2019 11:11:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Zy3igJq07cYQSMxFomj95OIsp+cg4RA7m3SIK+lG8bU=; b=RWIwPiKWpW+8hhJ064VFfHfgeJUrYzzyTSpEwMVt2y7w5U1LDQPlCjNTLk0z5GqVmX /SvB9jaw4CudwdT9ej5tHOVNWB+LrVGJmUHbuucV4a3Tzn5m5vh2p8+CsaSL65BEcMbp 2zOonGmORz1V77vECNFInY1MgMO1n8324iCp8p3wCZJHICJnxGj9d8sdZUOcM08VRniZ 5LTEf8MAGuJMQzDDMK9ajNTMPKeLiao+h94sBiV1W7mdtS9QoFylcrxArsri3ZIWScZd 1SFi/Puqi0dTTk4wu0k/ujt+tbt3MPP90RZsZo2lYCdLFT04piE4G7jJW+ZJ49ofrv4A NIxA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Zy3igJq07cYQSMxFomj95OIsp+cg4RA7m3SIK+lG8bU=; b=KoVl/DFSCDX7n/0ZnU2SBjjviBJAIobHVb0KTNXpVZ9zlIP6Aweqk+LNQEFXx6mEmx 6gAcySlip2NoOCOvT2RiCv0nWoWhReG7GQLDdQC/JIxq9Jcj+at4QnBdKyxTG9k1I8ol Eu6nQtj81XFaQSfosIHDv/QS9P9PkEdjC5Wn4DbtGzboMV12wOcqqhVHi4Dfua+SaSF5 Tpvgmfk3v12ANG30WT1UcKtiO9hKpAIP0JKDELdtBza9ad9qIZRFyVwqNpJOvZQlCXva od4NGlvUUQ0zpebe7aY7ySeespKm9bVpCDq7HqHbz6buU5cD9aNUHsHz4Q6SmGIIVjhY faUA== X-Gm-Message-State: APjAAAWCVmaaFJ9UipOHi0JviMiXADIjZ7rV0FhpPPyWChM0os2XGiw5 KZTII3RiL0NqouIKNpzOCc2LMjbU X-Google-Smtp-Source: APXvYqyGLjQ0zfRugxJ+mFnXR75GhggtBiLimgCtvpXe9134qnfxnS/Gk3IRfijOU6tSHqUDc6AjyQ== X-Received: by 2002:adf:e909:: with SMTP id f9mr3364863wrm.231.1558807915828; Sat, 25 May 2019 11:11:55 -0700 (PDT) Received: from blackbox.darklights.net (p200300F133DDA4007CB8841254CD64FD.dip0.t-ipconnect.de. [2003:f1:33dd:a400:7cb8:8412:54cd:64fd]) by smtp.googlemail.com with ESMTPSA id o8sm12794540wra.4.2019.05.25.11.11.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 25 May 2019 11:11:55 -0700 (PDT) From: Martin Blumenstingl To: linux-amlogic@lists.infradead.org, linux-pwm@vger.kernel.org, thierry.reding@gmail.com, u.kleine-koenig@pengutronix.de Subject: [PATCH 10/14] pwm: meson: simplify the calculation of the pre-divider and count Date: Sat, 25 May 2019 20:11:29 +0200 Message-Id: <20190525181133.4875-11-martin.blumenstingl@googlemail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190525181133.4875-1-martin.blumenstingl@googlemail.com> References: <20190525181133.4875-1-martin.blumenstingl@googlemail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190525_111157_756729_33423B01 X-CRM114-Status: GOOD ( 15.31 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Martin Blumenstingl , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Replace the loop to calculate the pre-divider and count with two separate div64_u64() calculations. This makes the code easier to read and improves the precision. Two example cases: 1) 32.768kHz LPO clock for the SDIO wifi chip on Khadas VIM clock input: 500MHz (FCLK_DIV4) period: 30518ns duty cycle: 15259ns old algorithm: pre_div=0, cnt=15259 new algorithm: pre_div=0, cnt=15259 (no difference in calculated values) 2) PWM LED on Khadas VIM clock input: 24MHz (XTAL) period: 7812500ns duty cycle: 7812500ns old algorithm: pre_div=2, cnt=62004 new algorithm: pre_div=2, cnt=62500 Using a scope (24MHz sampling rate) shows the actual difference: - old: 7753000ns, off by -59500ns (0.7616%) - new: 7815000ns, off by +2500ns (0.032%) Suggested-by: Uwe Kleine-König Signed-off-by: Martin Blumenstingl Reviewed-by: Neil Armstrong --- drivers/pwm/pwm-meson.c | 25 ++++++++++--------------- 1 file changed, 10 insertions(+), 15 deletions(-) diff --git a/drivers/pwm/pwm-meson.c b/drivers/pwm/pwm-meson.c index 27915d6475e3..9afa1e5aaebf 100644 --- a/drivers/pwm/pwm-meson.c +++ b/drivers/pwm/pwm-meson.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include @@ -145,7 +146,6 @@ static int meson_pwm_calc(struct meson_pwm *meson, struct pwm_device *pwm, struct meson_pwm_channel *channel = pwm_get_chip_data(pwm); unsigned int duty, period, pre_div, cnt, duty_cnt; unsigned long fin_freq = -1; - u64 fin_ps; duty = state->duty_cycle; period = state->period; @@ -164,24 +164,19 @@ static int meson_pwm_calc(struct meson_pwm *meson, struct pwm_device *pwm, } dev_dbg(meson->chip.dev, "fin_freq: %lu Hz\n", fin_freq); - fin_ps = (u64)NSEC_PER_SEC * 1000; - do_div(fin_ps, fin_freq); - - /* Calc pre_div with the period */ - for (pre_div = 0; pre_div <= MISC_CLK_DIV_MASK; pre_div++) { - cnt = DIV_ROUND_CLOSEST_ULL((u64)period * 1000, - fin_ps * (pre_div + 1)); - dev_dbg(meson->chip.dev, "fin_ps=%llu pre_div=%u cnt=%u\n", - fin_ps, pre_div, cnt); - if (cnt <= 0xffff) - break; - } + pre_div = div64_u64(fin_freq * (u64)period, NSEC_PER_SEC * 0xffffLL); if (pre_div > MISC_CLK_DIV_MASK) { dev_err(meson->chip.dev, "unable to get period pre_div\n"); return -EINVAL; } + cnt = div64_u64(fin_freq * (u64)period, NSEC_PER_SEC * (pre_div + 1)); + if (cnt > 0xffff) { + dev_err(meson->chip.dev, "unable to get period cnt\n"); + return -EINVAL; + } + dev_dbg(meson->chip.dev, "period=%u pre_div=%u cnt=%u\n", period, pre_div, cnt); @@ -195,8 +190,8 @@ static int meson_pwm_calc(struct meson_pwm *meson, struct pwm_device *pwm, channel->lo = cnt; } else { /* Then check is we can have the duty with the same pre_div */ - duty_cnt = DIV_ROUND_CLOSEST_ULL((u64)duty * 1000, - fin_ps * (pre_div + 1)); + duty_cnt = div64_u64(fin_freq * (u64)duty, + NSEC_PER_SEC * (pre_div + 1)); if (duty_cnt > 0xffff) { dev_err(meson->chip.dev, "unable to get duty cycle\n"); return -EINVAL; From patchwork Sat May 25 18:11:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Blumenstingl X-Patchwork-Id: 10961053 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 551801575 for ; Sat, 25 May 2019 18:17:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4491628A86 for ; Sat, 25 May 2019 18:17:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3382D28A8E; Sat, 25 May 2019 18:17:56 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id C017428A86 for ; Sat, 25 May 2019 18:17:55 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=eqn+yADB0WU9IcEQlyOwml5aVhztqUS/55TGDIH0l+g=; b=I0hXdS61S0msFI xo5OkcZTVx+5OzaH1Rw4rHuuEA7efUlY0H7sdriYkzU+9rhDcxkbfTMQV7BMkmkfaeEO2BrW+QrCe ws7fNCEJAlnis3I7Xt+/gi4Xr1cI+D0OkgvOBr16H45Q2GNRsqYc2HQiT6w2+kLOzmpfSd4fV2bcU iZrSQzAyYPsB1K5uLxFR7AEa7xNge3I6JRp+KHJvUFDnfiuh8T8wJuy+O3DOBz9fST67JK6JHmFfm /qW8Cs6V2uJWtxohYk5K47dd7oM3bXtY9KnfGGc2/uNbK9ddmz4HjNBIt3lNHKN2oXm9z9bMB5xpi /Ao7kgpPsbHuPewQPwdg==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hUbBd-00059f-GP; Sat, 25 May 2019 18:14:29 +0000 Received: from mail-wm1-x343.google.com ([2a00:1450:4864:20::343]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hUb9C-0002QH-Gs; Sat, 25 May 2019 18:12:01 +0000 Received: by mail-wm1-x343.google.com with SMTP id v22so4816629wml.1; Sat, 25 May 2019 11:11:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=oGmx4EPee47ZcnAwDDemernEH2nzHCt+ROW/DzQRqH4=; b=NLjJV2J0js50+wwDSBN8P3m7XcjsHo8yqeLMaiBAwg5FW+Up2vKGQV0dKoyFT4UXAa siH1WlwloOBvqzH32foCJ/epwz61M5yX6TLfRv9o615KmxHQ8Xw5rc2ahEciTImkGFjr LGHIieMVbRQiw5h4qWM584X8DuCqJfd/ySn30BOGD1vRgoDN1Ophe9fAzHmhtQNo/nil 8FD4TUn/ZtIJXhl3gy1GmdxJvD95z2y+n+Y/js4E8+GIETsqZFLnH6ejlAZRiJ8oNYXu 12t/vknGV4hM0IXIjVnSj0T+Pk9cWjjbxtUILt04A0FLFTD9tR6asqRlaPPHiHr1N2Gj iKCQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=oGmx4EPee47ZcnAwDDemernEH2nzHCt+ROW/DzQRqH4=; b=V0xDNd0NdxaPG7XjgxwUblZeNK2THMFFv2XFzVGB5FBZbzQkNc7Qli0XE/dD3ar6s9 O8+d2qnSqJ4LcYyW5PE/Ni7cuF7YGuX+A0ISszwmF0wu+h4j1TTt0X14xSQBKREEyAva kGg/JZnuh6wvR88oBEpAOOEuNaC8xJKv6Xt+1A/n4fmfYJhS0BPr4ClxQikoraFdT0AT yngI4xju1eJB+pEoIauH8V0aeMN1fa0DKln5nlDoJ0bZi0F6y7w7uDYtuzFwwy9X7xNH Ku7scYIPvcHGj+J0kEbNrtiqmGwQ+FMPQLIqCRZN57CwGsIklHT3UIRiWbMAhPbU4NU/ mhUw== X-Gm-Message-State: APjAAAXi6B0ppIaIOI5o4Bb2eCEaEH54voV+47NG7T2dh4LIy6iNt3UN WojXw3iIIxwKnvormDiq7CUHeCgC X-Google-Smtp-Source: APXvYqxQULktAEL5DQ5YwcPwKLm/Q3r7ZI5mvk1sKtDOcewCJUj8+P0/kbO8Gvty/fop1JttdwlRqQ== X-Received: by 2002:a7b:c92a:: with SMTP id h10mr4034024wml.172.1558807916826; Sat, 25 May 2019 11:11:56 -0700 (PDT) Received: from blackbox.darklights.net (p200300F133DDA4007CB8841254CD64FD.dip0.t-ipconnect.de. [2003:f1:33dd:a400:7cb8:8412:54cd:64fd]) by smtp.googlemail.com with ESMTPSA id o8sm12794540wra.4.2019.05.25.11.11.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 25 May 2019 11:11:56 -0700 (PDT) From: Martin Blumenstingl To: linux-amlogic@lists.infradead.org, linux-pwm@vger.kernel.org, thierry.reding@gmail.com, u.kleine-koenig@pengutronix.de Subject: [PATCH 11/14] pwm: meson: read the full hardware state in meson_pwm_get_state() Date: Sat, 25 May 2019 20:11:30 +0200 Message-Id: <20190525181133.4875-12-martin.blumenstingl@googlemail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190525181133.4875-1-martin.blumenstingl@googlemail.com> References: <20190525181133.4875-1-martin.blumenstingl@googlemail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190525_111158_663037_225A6A00 X-CRM114-Status: GOOD ( 16.02 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Martin Blumenstingl , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Update the meson_pwm_get_state() implementation to take care of all information in the registers instead of only reading the "enabled" state. The PWM output is only enabled if two conditions are met: 1. the per-channel clock is enabled 2. the PWM output is enabled Calculate the PWM period and duty cycle using the reverse formula which we already have in meson_pwm_calc() and update struct pwm_state with the results. As result of this /sys/kernel/debug/pwm now shows the PWM state set by the bootloader (or firmware) after booting Linux. Signed-off-by: Martin Blumenstingl Reviewed-by: Neil Armstrong --- drivers/pwm/pwm-meson.c | 52 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 49 insertions(+), 3 deletions(-) diff --git a/drivers/pwm/pwm-meson.c b/drivers/pwm/pwm-meson.c index 9afa1e5aaebf..010212166d5d 100644 --- a/drivers/pwm/pwm-meson.c +++ b/drivers/pwm/pwm-meson.c @@ -287,19 +287,65 @@ static int meson_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, return 0; } +static unsigned int meson_pwm_cnt_to_ns(struct pwm_chip *chip, + struct pwm_device *pwm, u32 cnt) +{ + struct meson_pwm *meson = to_meson_pwm(chip); + struct meson_pwm_channel *channel; + unsigned long fin_freq; + u32 fin_ns; + + /* to_meson_pwm() can only be used after .get_state() is called */ + channel = &meson->channels[pwm->hwpwm]; + + fin_freq = clk_get_rate(channel->clk); + if (fin_freq == 0) + return 0; + + fin_ns = div_u64(NSEC_PER_SEC, fin_freq); + + return cnt * fin_ns * (channel->pre_div + 1); +} + static void meson_pwm_get_state(struct pwm_chip *chip, struct pwm_device *pwm, struct pwm_state *state) { struct meson_pwm *meson = to_meson_pwm(chip); - u32 value, mask; + struct meson_pwm_channel_data *channel_data; + struct meson_pwm_channel *channel; + u32 value, tmp; if (!state) return; - mask = meson_pwm_per_channel_data[pwm->hwpwm].pwm_en_mask; + channel = &meson->channels[pwm->hwpwm]; + channel_data = &meson_pwm_per_channel_data[pwm->hwpwm]; value = readl(meson->base + REG_MISC_AB); - state->enabled = (value & mask) != 0; + + tmp = channel_data->pwm_en_mask | channel_data->clk_en_mask; + state->enabled = (value & tmp) == tmp; + + tmp = value >> channel_data->clk_div_shift; + channel->pre_div = FIELD_GET(MISC_CLK_DIV_MASK, tmp); + + value = readl(meson->base + channel_data->reg_offset); + + channel->lo = FIELD_GET(PWM_LOW_MASK, value); + channel->hi = FIELD_GET(PWM_HIGH_MASK, value); + + if (channel->lo == 0) { + state->period = meson_pwm_cnt_to_ns(chip, pwm, channel->hi); + state->duty_cycle = state->period; + } else if (channel->lo >= channel->hi) { + state->period = meson_pwm_cnt_to_ns(chip, pwm, + channel->lo + channel->hi); + state->duty_cycle = meson_pwm_cnt_to_ns(chip, pwm, + channel->hi); + } else { + state->period = 0; + state->duty_cycle = 0; + } } static const struct pwm_ops meson_pwm_ops = { From patchwork Sat May 25 18:11:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Blumenstingl X-Patchwork-Id: 10961035 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DF41C933 for ; Sat, 25 May 2019 18:13:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D0C2928A86 for ; Sat, 25 May 2019 18:13:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C495628A8E; Sat, 25 May 2019 18:13:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 512E728A89 for ; Sat, 25 May 2019 18:13:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=C6g0m60Hb1+RLewOmN4Txap1HlmIKCLfyrME1VYsfQI=; b=l2gGlIb7wolBlP XI8s8D2/HwboJzR/8puqPnzWHuLmThdT/RIbHDdT3VoAfRoWdX+7KEw3OnnPoJGq4qz2x+fWf0fwM ZokahrLltNV2tCxK0ERuTMW5WlNUCuHbyOHcJewJ8+YTtSPCfj+3ooHU4Uzvb+rpo1MhUpevUYoYW Fp/aXVRYr/8U02bJyfBKACbc8srcwQVWAqUaC/IyCYDWVwsifs2ohNv24iIKTcJ7Z+5SMlcaFqp/D MAcNA7N0Z/T2DwZd7vRU8b2Ex66DV26riN0fAQmnuEwOB8WC4MrIJqbdus91p9GVV6NrmIymqdWpO Xt0hiTl1ZQHXEQrYee/Q==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hUbAd-0004BN-DM; Sat, 25 May 2019 18:13:27 +0000 Received: from mail-wm1-x342.google.com ([2a00:1450:4864:20::342]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hUb9D-0002Qx-La; Sat, 25 May 2019 18:12:02 +0000 Received: by mail-wm1-x342.google.com with SMTP id y3so12354106wmm.2; Sat, 25 May 2019 11:11:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ZZBrfkl16mJlGiWrnZRe//jeJtUZhnRCrg3oI0vNyFI=; b=MgUAmTL4yQFGoNbP7rExFDhLyToEDMu/d0vkne8q//dsS1wVYTc5RZ943WOgq3Wu3D 7C0kJswseNQVZJ10l7h2RMOJqFNusWEqF8YRh94m+J4618+oOsjp0NdVDk7u2auMCgtN KFxgTNGAFTpmEvvvrrGbdZF2B1dnsdByx48ZB3UeKE/okpT5KHo6Lb+BKTAwjkcXbNlj lsXY2Y/aLWsfE0hD0bJ4VdcLwj1GuIvZR+Ap34vgH1GQUXZrWZhQ3pN9RIp4Ad/ziwQQ YcJXBItvX19JiDrTBcOyvStOwsIkpVNbj9PYJqyKUE1FcmWvVo7Ffy/rs0zRN+vqkmEi t/iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZZBrfkl16mJlGiWrnZRe//jeJtUZhnRCrg3oI0vNyFI=; b=f3LlOIn+6jLRsnXU3gIIZ7iojUjg7r3WsNUTvPwb5IFmWH9Vb8DbXggushxBUP7HRm usAPFCBcM4fVcflQ0ng4K5BJCq6mPu3WutONG+ouvPXg0MUb/j5IYU79Tc1XOc9XHUWz +vlzS5ZCH2ksRBBDNXhagEMaQSml9890P7NOf019wex/90+41haX1ELrOFd2K9VPAs0P mv6zXYcO70J3FfviPWGxx6kQ8VP3QwYYIR3zspeJ3mCy9DtCI6wd7YPmRKGQ2hNC0Aa3 GOIVX+L8oXRgOKMll4jVx1HYyS9X19mg25ue1YL77tlFtH9MvwstowxYBOLNiZkp66tX FpiA== X-Gm-Message-State: APjAAAXtel6a6NkXthY7XPdPpezd+r5+tKP6ZbhPvX2PAM4ofBgBrk1J LVTRZc9rszreD0S7dUbEyc4q9/oj X-Google-Smtp-Source: APXvYqx7WEtmO5tBGD+Qk0uLxms3RRFGsn/SwE+f+++pGxOUKsvbHBDc+QgOZvlVI410mS9pcBvgSA== X-Received: by 2002:a7b:c4d2:: with SMTP id g18mr21216802wmk.78.1558807917837; Sat, 25 May 2019 11:11:57 -0700 (PDT) Received: from blackbox.darklights.net (p200300F133DDA4007CB8841254CD64FD.dip0.t-ipconnect.de. [2003:f1:33dd:a400:7cb8:8412:54cd:64fd]) by smtp.googlemail.com with ESMTPSA id o8sm12794540wra.4.2019.05.25.11.11.56 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 25 May 2019 11:11:57 -0700 (PDT) From: Martin Blumenstingl To: linux-amlogic@lists.infradead.org, linux-pwm@vger.kernel.org, thierry.reding@gmail.com, u.kleine-koenig@pengutronix.de Subject: [PATCH 12/14] pwm: meson: don't cache struct pwm_state internally Date: Sat, 25 May 2019 20:11:31 +0200 Message-Id: <20190525181133.4875-13-martin.blumenstingl@googlemail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190525181133.4875-1-martin.blumenstingl@googlemail.com> References: <20190525181133.4875-1-martin.blumenstingl@googlemail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190525_111159_848317_D6C42E43 X-CRM114-Status: GOOD ( 13.19 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Martin Blumenstingl , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP The PWM core already caches the "current struct pwm_state" as the "current state of the hardware registers" inside struct pwm_device. Drop the struct pwm_state from struct meson_pwm_channel in favour of the struct pwm_state in struct pwm_device. While here also drop any checks based on the pwm_state because the PWM core already takes care of this. No functional changes intended. Signed-off-by: Martin Blumenstingl Reviewed-by: Neil Armstrong --- drivers/pwm/pwm-meson.c | 25 +------------------------ 1 file changed, 1 insertion(+), 24 deletions(-) diff --git a/drivers/pwm/pwm-meson.c b/drivers/pwm/pwm-meson.c index 010212166d5d..900d362ec3c9 100644 --- a/drivers/pwm/pwm-meson.c +++ b/drivers/pwm/pwm-meson.c @@ -68,8 +68,6 @@ struct meson_pwm_channel { unsigned int lo; u8 pre_div; - struct pwm_state state; - struct clk *clk_parent; struct clk_mux mux; struct clk *clk; @@ -127,8 +125,6 @@ static int meson_pwm_request(struct pwm_chip *chip, struct pwm_device *pwm) return err; } - chip->ops->get_state(chip, pwm, &channel->state); - return pwm_set_chip_data(pwm, channel); } @@ -153,10 +149,6 @@ static int meson_pwm_calc(struct meson_pwm *meson, struct pwm_device *pwm, if (state->polarity == PWM_POLARITY_INVERSED) duty = period - duty; - if (period == channel->state.period && - duty == channel->state.duty_cycle) - return 0; - fin_freq = clk_get_rate(channel->clk); if (fin_freq == 0) { dev_err(meson->chip.dev, "invalid source clock frequency\n"); @@ -253,7 +245,6 @@ static void meson_pwm_disable(struct meson_pwm *meson, struct pwm_device *pwm) static int meson_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, struct pwm_state *state) { - struct meson_pwm_channel *channel = pwm_get_chip_data(pwm); struct meson_pwm *meson = to_meson_pwm(chip); int err = 0; @@ -262,26 +253,12 @@ static int meson_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, if (!state->enabled) { meson_pwm_disable(meson, pwm); - channel->state.enabled = false; - - return 0; - } - - if (state->period != channel->state.period || - state->duty_cycle != channel->state.duty_cycle || - state->polarity != channel->state.polarity) { + } else { err = meson_pwm_calc(meson, pwm, state); if (err < 0) return err; - channel->state.polarity = state->polarity; - channel->state.period = state->period; - channel->state.duty_cycle = state->duty_cycle; - } - - if (state->enabled && !channel->state.enabled) { meson_pwm_enable(meson, pwm); - channel->state.enabled = true; } return 0; From patchwork Sat May 25 18:11:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Blumenstingl X-Patchwork-Id: 10961055 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F01281575 for ; Sat, 25 May 2019 18:17:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E1DBE28A86 for ; Sat, 25 May 2019 18:17:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D5D0F28A8E; Sat, 25 May 2019 18:17:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8868B28A86 for ; Sat, 25 May 2019 18:17:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=YLpbx4eyYRlYwdBgj0741n5OOZ72x6x0UplzapD8Mkk=; b=LP+OUfaM1L3MeG pDBFIlq1BJr494ZqsA4/q2PstIUzeBPZnMJkvYcTs4NEEcoWnuv0LBUjjQr67kgEffNwAI5cKRIK5 1/NM1A+4P6dKTZ3Czmm5xIkgR6bE6VCCt7jDe6WJ3XsY7i6LfOPxohnN/msa/w/cULV0ft+2Cde0Y Mkh70bu+JHE6msrYzxVzE+LWHP6kqhJsgxdM1Kye3gJv04VRQjgz2gwtK6ew3rjeTL+hXQA0kVTm/ jsx+sbRlbS0diAsVo2g1e3qEN9ev8RN3jSsPkBVjwnzhl8YyT/Smqdu0FBvhUP2uf5Ru1o+Z8KMl6 cyJtR6c00KwB+dH91+nA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hUbBg-0005C3-O8; Sat, 25 May 2019 18:14:32 +0000 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hUb9F-0002S1-IN; Sat, 25 May 2019 18:12:03 +0000 Received: by mail-wm1-x344.google.com with SMTP id 15so12046051wmg.5; Sat, 25 May 2019 11:12:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=P6S6JiWbeadjUYysdt7Ty07UEhlqvmUYPEJBP3QF3hM=; b=lx8XVhGvLDMQjYEVrJPEmnwBBTQehcGtinH8oHdm/4miWFMb8wceXX8jL1uQYSvHcn WuKaflyXnEtIhg2pb3HvjEHGZrBrUpSa2yhsxgjaKiWKSgL5Rw0/Jk7rIb4u0KkSjdcM VfaXAwToMcOK6e3zFaqaC9ZoZN9tcQocVlAruqFfiZfiyrfxekfd5H6SW3c4tZbU55ku +jDmmH5/3loeJ50a/RXvt6ZtHzsnVS875Y5NwvkRZlDSg6Asum8PIcjEq3JhMVx1Btik OPE7MyUPTE4MmRiwg21SEH7/i3MZ+oxxLJCsH1z4wZs+8adtDUihlT2hCcPL4ownOz60 pK9g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=P6S6JiWbeadjUYysdt7Ty07UEhlqvmUYPEJBP3QF3hM=; b=fBVsEr0eMYE4z7GoJbtNNi+dSrsvXLyDlYV2X8qMixTZz6jJpcOWAlS9kN0lVNuyvr YXJTXodLtk3axY/W6trDEtzttECv04RgA/KSUUCv2ieya5vpBt58xfd7LrDENzSypTUY Te15uePx2AK1cyGkuNiuEuDTVWEZTakLhGpj4aqjLyp/iO5DG/U+iDAXlqmj5NgsNIP2 Ujl4u+oew5lw7s6eRVIOag3Sux/sxPZuJ7mLW5m2uZjlKQKHx5JgpboY49h30Vr4bZ13 tSEuOHHSqsMf7dOiRcXM1TimSs7YknznlTsB4j9IbPRqGYtTKmDS8izMc4h4tYmB+ESQ 86LQ== X-Gm-Message-State: APjAAAUBLqSGY56tfkajSmbYj6iRZj20dQjrCxBQ1FuRE2fc6sPGQIPx aFT+pvCZi8pnlLDo+BB0fsPWul9p X-Google-Smtp-Source: APXvYqx6kFreg3BLEOIWbXJYIuM1mGpx/LBYClCrw3+XYYRGohma4/peBmcQ0YcSmgi2Lq7OJuGEiQ== X-Received: by 2002:a1c:7001:: with SMTP id l1mr7127484wmc.40.1558807919098; Sat, 25 May 2019 11:11:59 -0700 (PDT) Received: from blackbox.darklights.net (p200300F133DDA4007CB8841254CD64FD.dip0.t-ipconnect.de. [2003:f1:33dd:a400:7cb8:8412:54cd:64fd]) by smtp.googlemail.com with ESMTPSA id o8sm12794540wra.4.2019.05.25.11.11.57 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 25 May 2019 11:11:58 -0700 (PDT) From: Martin Blumenstingl To: linux-amlogic@lists.infradead.org, linux-pwm@vger.kernel.org, thierry.reding@gmail.com, u.kleine-koenig@pengutronix.de Subject: [PATCH 13/14] pwm: meson: add support PWM_POLARITY_INVERSED when disabling Date: Sat, 25 May 2019 20:11:32 +0200 Message-Id: <20190525181133.4875-14-martin.blumenstingl@googlemail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190525181133.4875-1-martin.blumenstingl@googlemail.com> References: <20190525181133.4875-1-martin.blumenstingl@googlemail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190525_111201_671394_DA32D8B5 X-CRM114-Status: GOOD ( 17.61 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Martin Blumenstingl , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP meson_pwm_apply() has to consider the PWM polarity when disabling the output. With enabled=false and polarity=PWM_POLARITY_NORMAL the output needs to be LOW. The driver already supports this. With enabled=false and polarity=PWM_POLARITY_INVERSED the output needs to be HIGH. Implement this in the driver by internally enabling the output with the same settings that we already use for "period == duty". This fixes a PWM API violation which expects that the driver honors the polarity also for enabled=false. Due to the IP block not supporting this natively we only get "an as close as possible" to 100% HIGH signal (in my test setup with input clock of 24MHz and measuring the output with a logic analyzer at 24MHz sampling rate I got a duty cycle of 99.998475% on a Khadas VIM). Signed-off-by: Martin Blumenstingl Reviewed-by: Neil Armstrong --- drivers/pwm/pwm-meson.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/drivers/pwm/pwm-meson.c b/drivers/pwm/pwm-meson.c index 900d362ec3c9..bb48ba85f756 100644 --- a/drivers/pwm/pwm-meson.c +++ b/drivers/pwm/pwm-meson.c @@ -245,6 +245,7 @@ static void meson_pwm_disable(struct meson_pwm *meson, struct pwm_device *pwm) static int meson_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, struct pwm_state *state) { + struct meson_pwm_channel *channel = pwm_get_chip_data(pwm); struct meson_pwm *meson = to_meson_pwm(chip); int err = 0; @@ -252,7 +253,27 @@ static int meson_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, return -EINVAL; if (!state->enabled) { - meson_pwm_disable(meson, pwm); + if (state->polarity == PWM_POLARITY_INVERSED) { + /* + * This IP block revision doesn't have an "always high" + * setting which we can use for "inverted disabled". + * Instead we achieve this using the same settings + * that we use a pre_div of 0 (to get the shortest + * possible duration for one "count") and + * "period == duty_cycle". This results in a signal + * which is LOW for one "count", while being HIGH for + * the rest of the (so the signal is HIGH for slightly + * less than 100% of the period, but this is the best + * we can achieve). + */ + channel->pre_div = 0; + channel->hi = ~0; + channel->lo = 0; + + meson_pwm_enable(meson, pwm); + } else { + meson_pwm_disable(meson, pwm); + } } else { err = meson_pwm_calc(meson, pwm, state); if (err < 0) From patchwork Sat May 25 18:11:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Martin Blumenstingl X-Patchwork-Id: 10961041 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 75EAD933 for ; Sat, 25 May 2019 18:14:04 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6A39428A86 for ; Sat, 25 May 2019 18:14:04 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5E50828A8E; Sat, 25 May 2019 18:14:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED,DKIM_VALID,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1388528A86 for ; Sat, 25 May 2019 18:14:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=5myKOx33SyCFcoPYjxgjiSbZ9p2xbqWGfxVVhjPc+nE=; b=NVjcJkuo/ey+l2 rCh4YWqQUWUh8Oag2bRHkhnJyGoHodSoP9lk0ijX8aipnEOOgQ/W7ejiOXNpSMp51DAuNkEYWSugN g+GzL+C3VnCeqXjtAnr8dQw+D4m/9LxT+nThDmP5Lge3++Ex6kMpb3v/pn0LdpZbxp6q0tNYWrpkr 2B7eUaoZ4txPDVWJdcuTI8FHtaiuIhDMQRctRjbXyMFBIqocAbEG0CRgkbAuqLfn4q/DCi6txxgcG RAK1vja32PWi7o5b8iPh3ONw5nO5LJC9dxaIxTBZMpRYdQU0zqT64VTyjbwVa9WEDwQlWDWOe84Qn yz1SG7TTt4JfvcA0RAcw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hUbBB-0004rw-2Q; Sat, 25 May 2019 18:14:01 +0000 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hUb9F-0002SY-Qw; Sat, 25 May 2019 18:12:03 +0000 Received: by mail-wm1-x344.google.com with SMTP id 7so12066172wmo.2; Sat, 25 May 2019 11:12:01 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=nIoMcTrrivGWjqKFRKrQpbhTg0DwU0FAQEhN7ghOLBc=; b=YUJZFmlDDS9sV9t0FwAaA3uob1RJ1IKO64k1hx0VeZz++jx4eM8XoCSEP1HQUW5YCT Yg6X8OMcyRuAess6huRflmv0SgTKddbbEXVnjxBnlrmS5zgBf8Thu4QSXkel6JrF4gH6 0Nh+RzfkXnEzfzWU7jlm6MI9ivRU911ji63yc4ZRaWY8W8NNaYsfPznlNTHwgwlJYYid YgWjrUYKMFuyG/odJ1p+d8OF7MrkrEenArWMUleMDXqjhnh9om7QZJr8agRXOjq1Ys/a pgBINls59AMYHNDXQ+tROISOkYdsCpFcSC9EKYw7kepQE4tjK/7VY8yu6O/Zm74+SovP uunw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=nIoMcTrrivGWjqKFRKrQpbhTg0DwU0FAQEhN7ghOLBc=; b=leEl9KKws++8m1PhWePllVNJFHbYbIas1hlvTwrabkZxjgEuQuzwRx4d7qxvpeM94J stZlnaKtpTYvBJHORH2DM4Ggc72DUswk7JzuBfC5PCjTzpkHFlrth/XXBhybuEdfPgEi G9K5iNtfdi2MpCin8kkDPb4WURQ/bKcXxkG5HYoeEcluYK8PdgocNRuDIzYamg82AE6T Aa+qm6FxYFE/xl8564AxpFpItlw5DpvkMH6BwM+Q6aj4Y+7IFfKSuieK/7ib2Wuk1c1v /0CX80InWliIsN+Zu+Q5inW2fSj+4R/TUU+AvRxyktrqEiPbSk+emgyLxxzxktUj8ekT 4LDw== X-Gm-Message-State: APjAAAUy5tzToCmPhYgpqceK2bvwm1+SpgMb+nXwF+CoL8UzqDAowvpy NkNSVudowPm63uOycL1rAXUZaPDk X-Google-Smtp-Source: APXvYqyu3Be/yKPBPoTWAwazVEJwspi1jbLIzkDvL+i+B9Xl8I2P+UA0mJcEPB3BnlTthJdpmkyPcQ== X-Received: by 2002:a1c:a002:: with SMTP id j2mr20147153wme.131.1558807920083; Sat, 25 May 2019 11:12:00 -0700 (PDT) Received: from blackbox.darklights.net (p200300F133DDA4007CB8841254CD64FD.dip0.t-ipconnect.de. [2003:f1:33dd:a400:7cb8:8412:54cd:64fd]) by smtp.googlemail.com with ESMTPSA id o8sm12794540wra.4.2019.05.25.11.11.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 25 May 2019 11:11:59 -0700 (PDT) From: Martin Blumenstingl To: linux-amlogic@lists.infradead.org, linux-pwm@vger.kernel.org, thierry.reding@gmail.com, u.kleine-koenig@pengutronix.de Subject: [PATCH 14/14] pwm: meson: add documentation to the driver Date: Sat, 25 May 2019 20:11:33 +0200 Message-Id: <20190525181133.4875-15-martin.blumenstingl@googlemail.com> X-Mailer: git-send-email 2.21.0 In-Reply-To: <20190525181133.4875-1-martin.blumenstingl@googlemail.com> References: <20190525181133.4875-1-martin.blumenstingl@googlemail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190525_111201_977825_FB2D38DC X-CRM114-Status: GOOD ( 14.39 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Martin Blumenstingl , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Neil Armstrong Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Add a link to the datasheet and a short summary how the hardware works. The goal is to make it easier for other developers to understand why the pwm-meson driver is implemented the way it is. Suggested-by: Uwe Kleine-König Co-authored-by: Neil Armstrong Signed-off-by: Martin Blumenstingl Reviewed-by: Neil Armstrong --- drivers/pwm/pwm-meson.c | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/drivers/pwm/pwm-meson.c b/drivers/pwm/pwm-meson.c index bb48ba85f756..6a978caba483 100644 --- a/drivers/pwm/pwm-meson.c +++ b/drivers/pwm/pwm-meson.c @@ -1,5 +1,23 @@ // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause /* + * PWM controller driver for Amlogic Meson SoCs. + * + * This PWM is only a set of Gates, Dividers and Counters: + * PWM output is achieved by calculating a clock that permits calculating + * two periods (low and high). The counter then has to be set to switch after + * N cycles for the first half period. + * The hardware has no "polarity" setting. This driver reverses the period + * cycles (the low length is inverted with the high length) for + * PWM_POLARITY_INVERSED. This means that .get_state cannot read the polarity + * from the hardware. + * Setting the duty cycle will disable and re-enable the PWM output. + * Disabling the PWM stops the output immediately (without waiting for the + * current period to complete first). + * + * The public S922X datasheet contains some documentation for this PWM + * controller starting on page 1084: + * https://dl.khadas.com/Hardware/VIM2/Datasheet/S912_Datasheet_V0.220170314publicversion-Wesion.pdf + * * Copyright (c) 2016 BayLibre, SAS. * Author: Neil Armstrong * Copyright (C) 2014 Amlogic, Inc.