Received: by 2002:a5b:505:0:0:0:0:0 with SMTP id o5csp942685ybp; Fri, 4 Oct 2019 07:21:05 -0700 (PDT) X-Google-Smtp-Source: APXvYqwmc50YpwENeK0rIxWV5UjbsFwRFHvAS65XUIU/D+5ApshH0BbbTvbvLJuIFqDsm4J58JkW X-Received: by 2002:aa7:c306:: with SMTP id l6mr15540990edq.78.1570198865172; Fri, 04 Oct 2019 07:21:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1570198865; cv=none; d=google.com; s=arc-20160816; b=jdH8mOMbQKnE+ZWbbaNo7m4R/254awBzhpYXQu+RqBMRhuoS58zfpPE9YuWgSa/oro HZGvPOOZf0teyqb3fLdg7frYLof54lpJe3PzArwYt7fRySn5G8UK92mnnvOrWIgiDtuX EShQ2nD4KONwfMGeW3B9HuCw68523n3fCt6Z8Zg8lFuOGEOz1SBS8zW7YWmVQjKYKS2K 16hkJ4sOkIOmGY3mHcMac6/b0OZhPiXCWcodqqmbXuIYjnTFwK0d/scKRTHdAJFNUECz BCvzZPAGtLNgMM3qIrGE8biKbsGyNKII11iIjrx1aljudo5i7z4DJ+v4U5j2jTgqZNgD iUvQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-transfer-encoding:content-disposition:mime-version :references:message-id:subject:cc:to:from:date; bh=xFwCEefPQbzEihK7TEk9eCOh4T5CYsyrUarH9mRwVp0=; b=0wzMYdAoKPsI5RLmGOb0JGAhXYCaevcigdmSi41ise6cxI7k+1ZjOsDzssTnmxoSVG 2b0mAL6TTm3NQCvrcWL7wnO5SXen1uQZTxGnWuyChIJbOn26X1UZym9Yum2bJ8Q7aPWq yrZ6as75gy++7iQTqrAYYQGN0XeQW0eyN/ned1H3jY9SRLl4+jsXvwNedBUSrtS4fBv7 i0vtUn+eVZemPCvUgwynzlxkSsoDSUly+8Gon8Geqvo2yuoQlnyhxjah8o0Fh/scyChD 5NnWuoFR+RfZtcteX+pYrTKR0cDnA389jq7CKkVW8Q2tmhLAn+h54Zn9/fgdX18Mdvx3 hmtQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id e23si3455803edq.344.2019.10.04.07.20.40; Fri, 04 Oct 2019 07:21:05 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388987AbfJDOSn (ORCPT + 99 others); Fri, 4 Oct 2019 10:18:43 -0400 Received: from metis.ext.pengutronix.de ([85.220.165.71]:60381 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2388874AbfJDOSm (ORCPT ); Fri, 4 Oct 2019 10:18:42 -0400 Received: from pty.hi.pengutronix.de ([2001:67c:670:100:1d::c5]) by metis.ext.pengutronix.de with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1iGOPj-000863-Ht; Fri, 04 Oct 2019 16:18:35 +0200 Received: from ukl by pty.hi.pengutronix.de with local (Exim 4.89) (envelope-from ) id 1iGOPi-0004fb-Cb; Fri, 04 Oct 2019 16:18:34 +0200 Date: Fri, 4 Oct 2019 16:18:34 +0200 From: Uwe =?iso-8859-1?Q?Kleine-K=F6nig?= To: Rasmus Villemoes Cc: Thierry Reding , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team , devicetree@vger.kernel.org, Rob Herring , linux-pwm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v2 1/6] pwm: mxs: implement ->apply Message-ID: <20191004141834.4blhpjzvkh3hvlqf@pengutronix.de> References: <20191004133207.6663-1-linux@rasmusvillemoes.dk> <20191004133207.6663-2-linux@rasmusvillemoes.dk> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20191004133207.6663-2-linux@rasmusvillemoes.dk> User-Agent: NeoMutt/20170113 (1.7.2) X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::c5 X-SA-Exim-Mail-From: ukl@pengutronix.de X-SA-Exim-Scanned: No (on metis.ext.pengutronix.de); SAEximRunCond expanded to false X-PTX-Original-Recipient: linux-kernel@vger.kernel.org Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hello, On Fri, Oct 04, 2019 at 03:32:02PM +0200, Rasmus Villemoes wrote: > In preparation for supporting setting the polarity, switch the driver > to support the ->apply method. > > Signed-off-by: Rasmus Villemoes > --- > drivers/pwm/pwm-mxs.c | 70 +++++++++++++++++++++++++++++++++++++++++++ > 1 file changed, 70 insertions(+) > > diff --git a/drivers/pwm/pwm-mxs.c b/drivers/pwm/pwm-mxs.c > index b14376b47ac8..10efd3de0bb3 100644 > --- a/drivers/pwm/pwm-mxs.c > +++ b/drivers/pwm/pwm-mxs.c > @@ -26,6 +26,7 @@ > #define PERIOD_PERIOD_MAX 0x10000 > #define PERIOD_ACTIVE_HIGH (3 << 16) > #define PERIOD_INACTIVE_LOW (2 << 18) > +#define PERIOD_POLARITY_NORMAL (PERIOD_ACTIVE_HIGH | PERIOD_INACTIVE_LOW) > #define PERIOD_CDIV(div) (((div) & 0x7) << 20) > #define PERIOD_CDIV_MAX 8 > > @@ -41,6 +42,74 @@ struct mxs_pwm_chip { > > #define to_mxs_pwm_chip(_chip) container_of(_chip, struct mxs_pwm_chip, chip) > > +static int mxs_pwm_apply(struct pwm_chip *chip, struct pwm_device *pwm, > + const struct pwm_state *state) > +{ > + struct mxs_pwm_chip *mxs = to_mxs_pwm_chip(chip); > + int ret, div = 0; > + unsigned int period_cycles, duty_cycles; > + unsigned long rate; > + unsigned long long c; > + > + if (state->polarity != PWM_POLARITY_NORMAL) > + return -ENOTSUPP; > + > + /* > + * If the PWM channel is disabled, make sure to turn on the > + * clock before calling clk_get_rate() and writing to the > + * registers. Otherwise, just keep it enabled. > + */ > + if (!pwm_is_enabled(pwm)) { > + ret = clk_prepare_enable(mxs->clk); > + if (ret) > + return ret; > + } > + > + if (!state->enabled && pwm_is_enabled(pwm)) > + writel(1 << pwm->hwpwm, mxs->base + PWM_CTRL + CLR); @Thierry: I wonder if it would be beneficial to stop the calculation of register contents if !state->enabled here. The only drawback (I'm aware) is that pwm_get_state won't return the previously set .period and .duty_cycle. (I also wonder if we should return (e.g.) .duty = 0, .period = 1 in pwm_get_state() if the PWM is off.) For the patch (which is orthogonal regarding the above question): Reviewed-by: Uwe Kleine-K?nig Best regards Uwe -- Pengutronix e.K. | Uwe Kleine-K?nig | Industrial Linux Solutions | http://www.pengutronix.de/ |