Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp989123imu; Thu, 13 Dec 2018 07:41:55 -0800 (PST) X-Google-Smtp-Source: AFSGD/Xs8c7ANqhlKTe/+l5/tLsFnunabWZVVu+9wzEbNHsGn9XVwE+66lr3xF048hePRt8s0wnf X-Received: by 2002:a63:cd11:: with SMTP id i17mr3217687pgg.345.1544715715276; Thu, 13 Dec 2018 07:41:55 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1544715715; cv=none; d=google.com; s=arc-20160816; b=lvtn3LgnjBbxeHmmrSH4salzyiySddlcyZBb2AyvnHXEnJ3nse5dO1BhqmyAqxzUJN aLhPx6mKBvNIMvgW4vv1T5MPMNLrhGLkejSGBadYrtu9WgcXRk32KqvPKNSDOAKk7uDT sUxxqBNJOmUme9EC5SzXwHEQF3m5G0O+WQ0TmSI5oGuAQyl9MuElgseltAS9vep3Goby ecXP4huBb2F68nJX4KixnheI5P7A6nMS/ttOiv0Br89lGg74LT4BEyQ1yndnq5THBg9U oEfV8adZw7CojaPcDEluHnvz4gxIMhjOUGKMxlvZ3U1+JwFz1xe/bghA1mukw3x1zDqp VJOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:dkim-signature:content-transfer-encoding :mime-version:references:in-reply-to:message-id:cc:to:subject:from :date; bh=vaRtKNxh69Zx4hzvWE5BlnM9SpbIUcaAwID6xRuePy8=; b=T/6W2W+6kUECiGigPm4n6TLnsKw4cTQ100UhPCuyCeGrGJ4Q8PuyQCIdWDyfs9C2NJ 9Db3aHqE3qpu3l1J59qeUrh9oyTmmYmBymuE4/4NKw2y8cKa34B49SXOCa7BFw26hel1 2dQ3iE57bn1ngwdkL1qbHd1QHAr+TcGB4DGGQByQFTWjUdGrLwsymhXEV2F2QEq9QeqT fX4dArLwMqSaut5yP7hGlaFzzxtAyREwJwhWAoGZRxPZ+nkI44baSJI0S6JG2SsNJWzT 8/lwXQKVj+meEapK2NZyD8lfzq95/EhP5oixpSlOEhgSXQE3neto4HhXqQpsGLmbffWO HGdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@crapouillou.net header.s=mail header.b="T7UHAV5/"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=crapouillou.net Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d4si154616pls.348.2018.12.13.07.41.37; Thu, 13 Dec 2018 07:41:55 -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; dkim=pass header.i=@crapouillou.net header.s=mail header.b="T7UHAV5/"; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=crapouillou.net Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728788AbeLMOe7 (ORCPT + 99 others); Thu, 13 Dec 2018 09:34:59 -0500 Received: from outils.crapouillou.net ([89.234.176.41]:33626 "EHLO crapouillou.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727618AbeLMOe6 (ORCPT ); Thu, 13 Dec 2018 09:34:58 -0500 Date: Thu, 13 Dec 2018 15:34:48 +0100 From: Paul Cercueil Subject: Re: [PATCH v8 11/26] pwm: jz4740: Use regmap and clocks from TCU driver To: Uwe =?iso-8859-1?q?Kleine-K=F6nig?= 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 Message-Id: <1544711688.18952.2@crapouillou.net> In-Reply-To: <20181213093049.rxdvf6tip7iqdj3c@pengutronix.de> References: <20181212220922.18759-1-paul@crapouillou.net> <20181212220922.18759-12-paul@crapouillou.net> <20181213093049.rxdvf6tip7iqdj3c@pengutronix.de> MIME-Version: 1.0 Content-Type: text/plain; charset=iso-8859-1; format=flowed Content-Transfer-Encoding: quoted-printable DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=crapouillou.net; s=mail; t=1544711695; bh=vaRtKNxh69Zx4hzvWE5BlnM9SpbIUcaAwID6xRuePy8=; h=Date:From:Subject:To:Cc:Message-Id:In-Reply-To:References:MIME-Version:Content-Type:Content-Transfer-Encoding; b=T7UHAV5/VDNreRQfwVVjkZX+9isrsLbPDUyjv9HX0ECy20R2rJZgWtH8FSok79fnY87YvQff34fYuHIwmRmCVTFQGkRzUs0Lclil4Imr34ZWTQy6ETzwB2nJX8dGGZskwkrWKvJNBRbUrM+DSnhnqOcNo5FSow8chDMzWibIufs= Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi, Le jeu. 13 d=E9c. 2018 =E0 10:30, Uwe Kleine-K=F6nig=20 a =E9crit : > Hello, >=20 > On Wed, Dec 12, 2018 at 11:09:06PM +0100, Paul Cercueil wrote: >> [...] >> static int jz4740_pwm_enable(struct pwm_chip *chip, struct=20 >> pwm_device *pwm) >> { >> - uint32_t ctrl =3D jz4740_timer_get_ctrl(pwm->pwm); >> + struct jz4740_pwm_chip *jz =3D to_jz4740(chip); >>=20 >> - ctrl |=3D 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); >=20 > Usually follow-up lines are indented to the matching parenthesis. OK. >> [...] >> static int jz4740_pwm_config(struct pwm_chip *chip, struct=20 >> pwm_device *pwm, >> int duty_ns, int period_ns) >> { >> struct jz4740_pwm_chip *jz4740 =3D to_jz4740(pwm->chip); >> + struct clk *clk =3D jz4740->clks[pwm->hwpwm]; >> + unsigned long rate, new_rate, period, duty; >> unsigned long long tmp; >> - unsigned long period, duty; >> - unsigned int prescaler =3D 0; >> - uint16_t ctrl; >> + unsigned int tcsr; >> bool is_enabled; >>=20 >> - tmp =3D (unsigned long long)clk_get_rate(jz4740->clk) * period_ns; >> - do_div(tmp, 1000000000); >> - period =3D tmp; >> + rate =3D clk_get_rate(clk); >> + >> + for (;;) { >> + tmp =3D (unsigned long long) rate * period_ns; >> + do_div(tmp, 1000000000); >>=20 >> - while (period > 0xffff && prescaler < 6) { >> - period >>=3D 2; >> - ++prescaler; >> + if (tmp <=3D 0xffff) >> + break; >> + >> + new_rate =3D clk_round_rate(clk, rate / 2); >> + >> + if (new_rate < rate) >> + rate =3D new_rate; >> + else >> + return -EINVAL; >> } >>=20 >> - if (prescaler =3D=3D 6) >> - return -EINVAL; >> + clk_set_rate(clk, rate); >=20 > 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=20 > the > clk settings each of the patches is easier to review than this one=20 > patch > that does all three things at once. I can try. > Best regards > Uwe >=20 > -- > Pengutronix e.K. | Uwe Kleine-K=F6nig =20 > | > Industrial Linux Solutions |=20 > http://www.pengutronix.de/ | =