From patchwork Thu Feb 23 08:38:40 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Claudiu Beznea X-Patchwork-Id: 9587945 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 9857060210 for ; Thu, 23 Feb 2017 08:48:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 876E7286A3 for ; Thu, 23 Feb 2017 08:48:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7B5E8286D0; Thu, 23 Feb 2017 08:48:27 +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=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.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 772F6286A3 for ; Thu, 23 Feb 2017 08:48:26 +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=FEaS7O8DuwEzwJ58ZFmpXPVMvatxS8vVWFxxkvZOWg4=; b=Em4WkVFIr6p5tN Sh0fj8bwSYU2QxouhImlHRl/2RpQn4zc0VP77cWt/H6KjoeD+XIgtuNrRw/OpLzcAqqAZROExKBFu u+2Dnhwwxj/kU6nUOcDfwLJ+n9YR1ZsJHyR5EwAQk/X7TlG5dPsAYefabE/fdHN/LwIgyJ1m7fm8c hPPiwc9qiAFOPES+tRUup3E4TUSMi9rWVSjcY46KGBZ33iQwOtjLGD8DydVlxVPfeeEP9siMcQq8t eizONf2hIz5Dyt5ULjOZszKchSYp9XxFlT1dfgFtWIn33s6A++toQCMN41SLedYfVjiTt6RqRh0mq xbHCfCDSKJ2of12HtXaA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1cgp4Z-00045R-EP; Thu, 23 Feb 2017 08:48:23 +0000 Received: from casper.infradead.org ([2001:770:15f::2]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cgozL-0001O0-F5 for linux-arm-kernel@bombadil.infradead.org; Thu, 23 Feb 2017 08:42:59 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Type:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:CC:To:From:Sender:Reply-To: Content-Transfer-Encoding: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=Kbje4WWFNEVmRFTFdt0+4ve/jFR04hxnBK6zM5f4okg=; b=j1WVmPH1Webpi59BwIlg2/Hoy cQq+vLfYh31+mg4bnnnUZxYdrMEXc5P2BwDcfI6a1xTYYLRZ0wzXWw7cmdqxBI/wsPIUl2OYEu8h1 j5IvE9pWMmd3grkWe1h72ibdQJOJT7VjlG7EjI+9r6f85QSmH4vofjefYQm81VOAos6w6RvrQAw/L WeoDre5KX4WUuWdyT+dVjjCTC0v6AQzpXwld/AXdjkjnpnZ5T1Ea1Z7PnW91AiHVmX+5KSvIHHdRE JGcjWRVlbtJY8Q1kF9l1TmI60OnLb/9VOIepYvvGYC8jjl8IgidxkrjK9qwmHRCnOKB91Dqx1o1JX suOvH0frQ==; Received: from smtpout.microchip.com ([198.175.253.82] helo=email.microchip.com) by casper.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1cgozG-0001QI-Tk for linux-arm-kernel@lists.infradead.org; Thu, 23 Feb 2017 08:42:57 +0000 Received: from m18063-ThinkPad-T460p.microchip.com (10.10.76.4) by chn-sv-exch07.mchp-main.com (10.10.76.108) with Microsoft SMTP Server id 14.3.181.6; Thu, 23 Feb 2017 01:42:30 -0700 From: Claudiu Beznea To: , , , , , , , Subject: [PATCH 2/2] drivers: pwm: pwm-atmel: add support to allow run time changing of pwm parameters Date: Thu, 23 Feb 2017 10:38:40 +0200 Message-ID: <1487839120-13650-3-git-send-email-claudiu.beznea@microchip.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1487839120-13650-1-git-send-email-claudiu.beznea@microchip.com> References: <1487839120-13650-1-git-send-email-claudiu.beznea@microchip.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170223_084255_237727_EA6A7601 X-CRM114-Status: GOOD ( 13.46 ) 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: linux-pwm@vger.kernel.org, Claudiu Beznea , linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, devicetree@vger.kernel.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 sama5d2 supports changing of pwm parameters like period and duty factor without first to disable pwm. Since pwm code is supported by more than one SoC add allow_runtime_cfg parameter to atmel_pwm_chip data structure. This will be filled statically for every SoC, saved in pwm specific structure at probing time and checked while configuring the device. Based on this, pwm clock will not be enabled/disabled while configuring if it still enabled. Signed-off-by: Claudiu Beznea --- drivers/pwm/pwm-atmel.c | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/drivers/pwm/pwm-atmel.c b/drivers/pwm/pwm-atmel.c index 4406639..9e1dece 100644 --- a/drivers/pwm/pwm-atmel.c +++ b/drivers/pwm/pwm-atmel.c @@ -68,6 +68,8 @@ struct atmel_pwm_chip { void (*config)(struct pwm_chip *chip, struct pwm_device *pwm, unsigned long dty, unsigned long prd); + + bool allow_runtime_cfg; }; static inline struct atmel_pwm_chip *to_atmel_pwm_chip(struct pwm_chip *chip) @@ -114,7 +116,8 @@ static int atmel_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, u32 val; int ret; - if (pwm_is_enabled(pwm) && (period_ns != pwm_get_period(pwm))) { + if (!atmel_pwm->allow_runtime_cfg && + pwm_is_enabled(pwm) && (period_ns != pwm_get_period(pwm))) { dev_err(chip->dev, "cannot change PWM period while enabled\n"); return -EBUSY; } @@ -139,10 +142,12 @@ static int atmel_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, do_div(div, period_ns); dty = prd - div; - ret = clk_enable(atmel_pwm->clk); - if (ret) { - dev_err(chip->dev, "failed to enable PWM clock\n"); - return ret; + if (!pwm_is_enabled(pwm)) { + ret = clk_enable(atmel_pwm->clk); + if (ret) { + dev_err(chip->dev, "failed to enable PWM clock\n"); + return ret; + } } /* It is necessary to preserve CPOL, inside CMR */ @@ -155,7 +160,9 @@ static int atmel_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, atmel_pwm->updated_pwms &= ~(1 << pwm->hwpwm); mutex_unlock(&atmel_pwm->isr_lock); - clk_disable(atmel_pwm->clk); + if (!pwm_is_enabled(pwm)) + clk_disable(atmel_pwm->clk); + return ret; } @@ -294,18 +301,22 @@ static const struct pwm_ops atmel_pwm_ops = { struct atmel_pwm_data { void (*config)(struct pwm_chip *chip, struct pwm_device *pwm, unsigned long dty, unsigned long prd); + bool allow_runtime_cfg; }; static const struct atmel_pwm_data atmel_pwm_data_v1 = { .config = atmel_pwm_config_v1, + .allow_runtime_cfg = false, }; static const struct atmel_pwm_data atmel_pwm_data_v2 = { .config = atmel_pwm_config_v2, + .allow_runtime_cfg = false, }; static const struct atmel_pwm_data atmel_pwm_data_v3 = { .config = atmel_pwm_config_v3, + .allow_runtime_cfg = true, }; static const struct platform_device_id atmel_pwm_devtypes[] = { @@ -399,6 +410,7 @@ static int atmel_pwm_probe(struct platform_device *pdev) atmel_pwm->chip.npwm = 4; atmel_pwm->chip.can_sleep = true; atmel_pwm->config = data->config; + atmel_pwm->allow_runtime_cfg = data->allow_runtime_cfg; atmel_pwm->updated_pwms = 0; mutex_init(&atmel_pwm->isr_lock);