linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Chen-Yu Tsai <wens@csie.org>
To: Michael Turquette <mturquette@baylibre.com>
Cc: Chen-Yu Tsai <wens@csie.org>, Lee Jones <lee.jones@linaro.org>,
	Alessandro Zummo <a.zummo@towertech.it>,
	Alexandre Belloni <alexandre.belloni@free-electrons.com>,
	Rob Herring <robh+dt@kernel.org>,
	Mark Rutland <mark.rutland@arm.com>,
	Maxime Ripard <maxime.ripard@free-electrons.com>,
	Stephen Boyd <sboyd@codeaurora.org>,
	linux-arm-kernel <linux-arm-kernel@lists.infradead.org>,
	rtc-linux@googlegroups.com, linux-clk <linux-clk@vger.kernel.org>,
	devicetree <devicetree@vger.kernel.org>,
	linux-kernel <linux-kernel@vger.kernel.org>
Subject: Re: [PATCH v4 4/7] rtc: ac100: Add clk output support
Date: Thu, 14 Jul 2016 11:34:34 +0800	[thread overview]
Message-ID: <CAGb2v67ft=EktCcfGFdBN1K4SoOyK+Stz2WuvqScMmRjoBWxfA@mail.gmail.com> (raw)
In-Reply-To: <146800297598.73491.13472152266331488346@resonance>

On Sat, Jul 9, 2016 at 2:36 AM, Michael Turquette
<mturquette@baylibre.com> wrote:
> Quoting Chen-Yu Tsai (2016-06-30 08:58:48)
>> +static long ac100_clkout_round_rate(struct clk_hw *hw, unsigned long rate,
>> +                                   unsigned long prate)
>> +{
>> +       unsigned long best_rate = 0, tmp_rate, tmp_prate;
>> +       int i;
>> +
>> +       if (prate == AC100_RTC_32K_RATE)
>> +               return divider_round_rate(hw, rate, &prate, NULL,
>> +                                         AC100_CLKOUT_DIV_WIDTH,
>> +                                         CLK_DIVIDER_POWER_OF_TWO);
>> +
>> +       for (i = 0; ac100_clkout_prediv[i].div; i++) {
>> +               tmp_prate = DIV_ROUND_UP(prate, ac100_clkout_prediv[i].val);
>> +               tmp_rate = divider_round_rate(hw, rate, &tmp_prate, NULL,
>> +                                             AC100_CLKOUT_DIV_WIDTH,
>> +                                             CLK_DIVIDER_POWER_OF_TWO);
>> +
>> +               if (tmp_rate > rate)
>> +                       continue;
>> +               if (rate - tmp_rate < best_rate - tmp_rate)
>> +                       best_rate = tmp_rate;
>> +       }
>> +
>> +       return best_rate;
>> +}
>> +
>> +static int ac100_clkout_determine_rate(struct clk_hw *hw,
>> +                                      struct clk_rate_request *req)
>> +{
>> +       struct clk_hw *best_parent;
>> +       unsigned long best = 0;
>> +       int i, num_parents = clk_hw_get_num_parents(hw);
>> +
>> +       for (i = 0; i < num_parents; i++) {
>> +               struct clk_hw *parent = clk_hw_get_parent_by_index(hw, i);
>> +               unsigned long tmp, prate = clk_hw_get_rate(parent);
>> +
>> +               tmp = ac100_clkout_round_rate(hw, req->rate, prate);
>> +
>> +               if (tmp > req->rate)
>> +                       continue;
>> +               if (req->rate - tmp < req->rate - best) {
>> +                       best = tmp;
>> +                       best_parent = parent;
>> +               }
>> +       }
>> +
>> +       if (!best)
>> +               return -EINVAL;
>> +
>> +       req->best_parent_hw = best_parent;
>> +       req->best_parent_rate = best;
>> +       req->rate = best;
>> +
>> +       return 0;
>> +}
>
> You only need one of the two functions above. Keep the .determine_rate
> callback and drop .round_rate.

Only .round_rate is set in the clk_ops. ac100_clkout_round_rate just
serves to split out some of the calculations done per parent.

> Otherwise the rest of the clk support looks great to me. Feel free to
> add:
>
> Reviewed-by: Michael Turquette <mturquette@baylibre.com>

Thanks!

ChenYu

  reply	other threads:[~2016-07-14  3:35 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-06-30 15:58 [PATCH v4 0/7] mfd: ac100: Add support for X-Powers AC100 audio codec / RTC combo IC Chen-Yu Tsai
2016-06-30 15:58 ` [PATCH v4 1/7] mfd: ac100: Add device tree bindings for X-Powers AC100 codec/RTC " Chen-Yu Tsai
2016-07-01  2:48   ` Rob Herring
2016-07-01  8:40   ` Lee Jones
2016-06-30 15:58 ` [PATCH v4 2/7] mfd: ac100: Add driver for X-Powers AC100 audio codec / RTC " Chen-Yu Tsai
2016-06-30 15:58 ` [PATCH v4 3/7] rtc: ac100: Add RTC driver for X-Powers AC100 Chen-Yu Tsai
2016-06-30 15:58 ` [PATCH v4 4/7] rtc: ac100: Add clk output support Chen-Yu Tsai
2016-07-08 18:36   ` Michael Turquette
2016-07-14  3:34     ` Chen-Yu Tsai [this message]
     [not found]       ` <146914709427.8780.16475894348537760808@resonance>
2016-07-22  1:22         ` Chen-Yu Tsai
2016-06-30 15:58 ` [PATCH v4 5/7] ARM: dts: sun9i: a80-optimus: Add device node for AC100 Chen-Yu Tsai
2016-06-30 15:58 ` [PATCH v4 6/7] ARM: dts: sun9i: cubieboard4: " Chen-Yu Tsai
2016-06-30 15:58 ` [PATCH v4 7/7] ARM: dts: sun9i: Switch to the AC100 RTC clock outputs for osc32k Chen-Yu Tsai

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAGb2v67ft=EktCcfGFdBN1K4SoOyK+Stz2WuvqScMmRjoBWxfA@mail.gmail.com' \
    --to=wens@csie.org \
    --cc=a.zummo@towertech.it \
    --cc=alexandre.belloni@free-electrons.com \
    --cc=devicetree@vger.kernel.org \
    --cc=lee.jones@linaro.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=maxime.ripard@free-electrons.com \
    --cc=mturquette@baylibre.com \
    --cc=robh+dt@kernel.org \
    --cc=rtc-linux@googlegroups.com \
    --cc=sboyd@codeaurora.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).