Received: by 2002:a25:c593:0:0:0:0:0 with SMTP id v141csp61780ybe; Wed, 18 Sep 2019 12:59:15 -0700 (PDT) X-Google-Smtp-Source: APXvYqz1C2rXEZ7U3rBgbsdm8oERBIdCjTEh5mrz/VQhTrdL7hyMW2DdeB34OAWSwz6JCX5gx72N X-Received: by 2002:a05:6402:1a4c:: with SMTP id bf12mr12406390edb.277.1568836755011; Wed, 18 Sep 2019 12:59:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568836755; cv=none; d=google.com; s=arc-20160816; b=qioG/oyIl+M2KlySBuhiom+az40W6B6nWvZY5/aaTKQqM6fThrM+uDSsiAyS+DqjSf Jq25gN03S1Wl7RJ5gNsOlThq7m1g35FaRga/ZQx6/S3GsTE+h2LffkFUSXgrO0hih6Mf 0Xm6GEPtf0U84hIT4Vx4uNtnaiZl4dy747owL6VDnEEk+9enlBZi7fl/kUqAgomOYKPl fu+eLxuDh+eH7cFbZVxfl9CM3nkNS/pYLkHtoxljQ4z53MN7oc6oOzYmoBEA+rgpw4Y+ TLCzEEzszYgpOo+puLX0iiVK7KRZiaCPLnJm0BCA6x6NeS7MP3Qx5/GGjtK4659SmdW/ PXgA== 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=cD867xpNlHw183fWBtmP5RePdpdzDuRDvuXLwW/Sj14=; b=ERJD2QALcID1WH2p+JW/T6njIGnsJjU0m9VaSgoii9q5RekcqDjLbtpAEO6k78K+y0 +ynWRX/U2th4bJ+idtbnqFU+7OSS59NszQU+DYhf/gliMACd4mMh9Z/V6zUjOT02954X UKX+3uukNyDFUwdyhklRzgyuV/UM6kXwD2DiY8kyKe1uDaMZuPEmljxHfuzl1/xEhzYV nnfKk+17BzLw9BVHez6Lul54AfJnsuEV3bH5ugZ3D1bM216i8QctEGH3uAtGxpoEhm0h y+qoM91w0jz9+gAXspiLcNdKZjgFUVe0WTV5McmPi+zZG4MZmx9OxWydGke/aZNJ4+ph KaxQ== 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 j4si4542407edl.192.2019.09.18.12.58.51; Wed, 18 Sep 2019 12:59:14 -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 S2388828AbfIRSks (ORCPT + 99 others); Wed, 18 Sep 2019 14:40:48 -0400 Received: from metis.ext.pengutronix.de ([85.220.165.71]:58025 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725899AbfIRSks (ORCPT ); Wed, 18 Sep 2019 14:40:48 -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 1iAesa-00059E-Ip; Wed, 18 Sep 2019 20:40:40 +0200 Received: from ukl by pty.hi.pengutronix.de with local (Exim 4.89) (envelope-from ) id 1iAesZ-0002ge-3I; Wed, 18 Sep 2019 20:40:39 +0200 Date: Wed, 18 Sep 2019 20:40:39 +0200 From: Uwe =?iso-8859-1?Q?Kleine-K=F6nig?= To: Fabrice Gasnier Cc: thierry.reding@gmail.com, alexandre.torgue@st.com, linux-pwm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-stm32@st-md-mailman.stormreply.com Subject: Re: [PATCH v2] pwm: stm32-lp: add check in case requested period cannot be achieved Message-ID: <20190918184039.27dtd3zguawijsqo@pengutronix.de> References: <1568818461-19995-1-git-send-email-fabrice.gasnier@st.com> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <1568818461-19995-1-git-send-email-fabrice.gasnier@st.com> 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 On Wed, Sep 18, 2019 at 04:54:21PM +0200, Fabrice Gasnier wrote: > LPTimer can use a 32KHz clock for counting. It depends on clock tree > configuration. In such a case, PWM output frequency range is limited. > Although unlikely, nothing prevents user from requesting a PWM frequency > above counting clock (32KHz for instance): > - This causes (prd - 1) = 0xffff to be written in ARR register later in > the apply() routine. > This results in badly configured PWM period (and also duty_cycle). > Add a check to report an error is such a case. > > Signed-off-by: Fabrice Gasnier Reviewed-by: Uwe Kleine-K?nig If you are interested to improve the driver further, there are a few things that I would welcome to see fixed in a tested patch: - duty calculation uses requested instead of implemented period. - stm32_pwm_lp_apply calls pwm_get_state - Calculation of prd could be done without a loop - A hint about relevant documentation in the driver's header would be great - Documentation about behaviour of the hardware is missing: - Does the hardware complete the currently running period when STM32_LPTIM_CR is cleared? - Does the output stop in the inactive output level when the PWM is stopped? - clk_get_rate might be called without the clock being enabled. - The driver does: ret = regmap_write(priv->regmap, STM32_LPTIM_CMP, prd - (1 + dty)); That looks wrong. (Consider dty == prd.) Best regards Uwe -- Pengutronix e.K. | Uwe Kleine-K?nig | Industrial Linux Solutions | http://www.pengutronix.de/ |