From mboxrd@z Thu Jan 1 00:00:00 1970 From: Paul Cercueil Subject: Re: [PATCH v8 11/26] pwm: jz4740: Use regmap and clocks from TCU driver Date: Thu, 13 Dec 2018 15:34:48 +0100 Message-ID: <1544711688.18952.2@crapouillou.net> 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 Return-path: In-Reply-To: <20181213093049.rxdvf6tip7iqdj3c@pengutronix.de> Sender: linux-kernel-owner@vger.kernel.org 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 List-Id: devicetree@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/ | =