Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp632154imu; Thu, 13 Dec 2018 01:33:25 -0800 (PST) X-Google-Smtp-Source: AFSGD/Ucfe6DcxbSNHiMFyrWJ/6hlg3Wc1QMLFgQQd5wwgyRBMTvL9K3yj4FdEMQinW+h/11E2pE X-Received: by 2002:a63:62c4:: with SMTP id w187mr1143368pgb.230.1544693605862; Thu, 13 Dec 2018 01:33:25 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544693605; cv=none; d=google.com; s=arc-20160816; b=MSwnmnk4dac0v8EC178tn2HkT+zkUC2hHi48KJoCpu5TA/mVQLT2vokpNW6UDgg3dq XG74r6/wppeXXe7Zmt8DhJnD/iQJN3lRaQ7394hW8Koj259Dl0GG2yk7uki+q2mszxAo nEIC4HwgROAV//YIN+otELJK6F7bvs/G0F/4/0lcucBGDsNAbK2PvryBkeBBr4iVhVDx tiunxQPdX8jEkCYhuR2B3sapv15rlPC4cbmUumenWrmTGO6nKXjQZNWMJ5DM+VdqhU74 0w/Bnz1SWe8gW3tznjzYyhHFaRC1/K3iZ5iLuRtxKcEIxlNA812m39W4VXz69t8Rbiwq g9ZA== 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=VlPZCNqZIrzqM4+E3bR9mUOKJyaUs7tive5hVzJW76w=; b=qpPB8GfH4EYeWFxAKh/fGbgOP3GEt3F/kcXdD7ItqTGficM29mGInpI3300XErQ+FF L0SQY4r3997yz0XYYsRqUnb+fT2rzhahi0BzvAQ0YT60SQbzFUQXf+s1RUnan/N8qARp rqzftcKB5DPWkqKYxvaIBgGqkOiMmhoABLR1+6TPXSl9cooKOgi2xjcNIxWgj+IoVMgL g2anFnu/n1L1bdcvGTfKGxuP4eM5Fjzjn3CUYmMo0rU6ReANKRly+ic5li1L4DnYmCKw nY24ah+oKTA77wXzv/HaKKGq6JilbHi8N8cYrTJf791ESzzl9Yl41okrmi3KpTvg6xV4 yibg== 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 f82si1247996pfa.221.2018.12.13.01.33.10; Thu, 13 Dec 2018 01:33:25 -0800 (PST) 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 S1727718AbeLMJbD (ORCPT + 99 others); Thu, 13 Dec 2018 04:31:03 -0500 Received: from metis.ext.pengutronix.de ([85.220.165.71]:57627 "EHLO metis.ext.pengutronix.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726578AbeLMJbC (ORCPT ); Thu, 13 Dec 2018 04:31:02 -0500 Received: from ptx.hi.pengutronix.de ([2001:67c:670:100:1d::c0]) by metis.ext.pengutronix.de with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1gXNKV-00073L-4E; Thu, 13 Dec 2018 10:30:51 +0100 Received: from ukl by ptx.hi.pengutronix.de with local (Exim 4.89) (envelope-from ) id 1gXNKT-0006Vw-9B; Thu, 13 Dec 2018 10:30:49 +0100 Date: Thu, 13 Dec 2018 10:30:49 +0100 From: Uwe =?iso-8859-1?Q?Kleine-K=F6nig?= To: Paul Cercueil Cc: Thierry Reding , Rob Herring , Mark Rutland , Daniel Lezcano , Thomas Gleixner , Ralf Baechle , Paul Burton , James Hogan , Jonathan Corbet , Mathieu Malaterre , Ezequiel Garcia , PrasannaKumar Muralidharan , linux-pwm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-watchdog@vger.kernel.org, linux-mips@vger.kernel.org, linux-doc@vger.kernel.org, linux-clk@vger.kernel.org, od@zcrc.me Subject: Re: [PATCH v8 11/26] pwm: jz4740: Use regmap and clocks from TCU driver Message-ID: <20181213093049.rxdvf6tip7iqdj3c@pengutronix.de> References: <20181212220922.18759-1-paul@crapouillou.net> <20181212220922.18759-12-paul@crapouillou.net> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1 Content-Disposition: inline Content-Transfer-Encoding: 8bit In-Reply-To: <20181212220922.18759-12-paul@crapouillou.net> User-Agent: NeoMutt/20170113 (1.7.2) X-SA-Exim-Connect-IP: 2001:67c:670:100:1d::c0 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 Wed, Dec 12, 2018 at 11:09:06PM +0100, Paul Cercueil wrote: > [...] > static int jz4740_pwm_enable(struct pwm_chip *chip, struct pwm_device *pwm) > { > - uint32_t ctrl = jz4740_timer_get_ctrl(pwm->pwm); > + struct jz4740_pwm_chip *jz = to_jz4740(chip); > > - ctrl |= JZ_TIMER_CTRL_PWM_ENABLE; > - jz4740_timer_set_ctrl(pwm->hwpwm, ctrl); > - jz4740_timer_enable(pwm->hwpwm); > + /* Enable PWM output */ > + regmap_update_bits(jz->map, TCU_REG_TCSRc(pwm->hwpwm), > + TCU_TCSR_PWM_EN, TCU_TCSR_PWM_EN); Usually follow-up lines are indented to the matching parenthesis. > [...] > static int jz4740_pwm_config(struct pwm_chip *chip, struct pwm_device *pwm, > int duty_ns, int period_ns) > { > struct jz4740_pwm_chip *jz4740 = to_jz4740(pwm->chip); > + struct clk *clk = jz4740->clks[pwm->hwpwm]; > + unsigned long rate, new_rate, period, duty; > unsigned long long tmp; > - unsigned long period, duty; > - unsigned int prescaler = 0; > - uint16_t ctrl; > + unsigned int tcsr; > bool is_enabled; > > - tmp = (unsigned long long)clk_get_rate(jz4740->clk) * period_ns; > - do_div(tmp, 1000000000); > - period = tmp; > + rate = clk_get_rate(clk); > + > + for (;;) { > + tmp = (unsigned long long) rate * period_ns; > + do_div(tmp, 1000000000); > > - while (period > 0xffff && prescaler < 6) { > - period >>= 2; > - ++prescaler; > + if (tmp <= 0xffff) > + break; > + > + new_rate = clk_round_rate(clk, rate / 2); > + > + if (new_rate < rate) > + rate = new_rate; > + else > + return -EINVAL; > } > > - if (prescaler == 6) > - return -EINVAL; > + clk_set_rate(clk, rate); Maybe this could better live in a separate patch. If you split still further to have the conversion to regmap in a single patch, then the conversion to the clk_* functions and then improve the algorithm for the clk settings each of the patches is easier to review than this one patch that does all three things at once. Best regards Uwe -- Pengutronix e.K. | Uwe Kleine-K?nig | Industrial Linux Solutions | http://www.pengutronix.de/ |