linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Eric Anholt <eric@anholt.net>
To: Remi Pommarel <repk@triplefau.lt>
Cc: Stephen Warren <swarren@wwwdotorg.org>,
	Lee Jones <lee@kernel.org>,
	Michael Turquette <mturquette@baylibre.com>,
	Stephen Boyd <sboyd@codeaurora.org>,
	linux-rpi-kernel@lists.infradead.org, linux-clk@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH v2 2/3] clk: bcm2835: Support for clock parent selection
Date: Thu, 03 Dec 2015 16:37:07 -0800	[thread overview]
Message-ID: <87io4fgibw.fsf@eliezer.anholt.net> (raw)
In-Reply-To: <20151118192423.GC491@cruxbox>

[-- Attachment #1: Type: text/plain, Size: 2446 bytes --]

Remi Pommarel <repk@triplefau.lt> writes:

> On Wed, Nov 18, 2015 at 10:30:17AM -0800, Eric Anholt wrote:
>
> [...]
>
>> > +static int bcm2835_clock_determine_rate(struct clk_hw *hw,
>> > +		struct clk_rate_request *req)
>> > +{
>> > +	struct bcm2835_clock *clock = bcm2835_clock_from_hw(hw);
>> > +	struct clk_hw *parent, *best_parent = NULL;
>> > +	struct clk_rate_request parent_req;
>> > +	unsigned long rate, best_rate = 0;
>> > +	unsigned long prate, best_prate = 0;
>> > +	size_t i;
>> > +	u32 div;
>> > +
>> > +	/*
>> > +	 * Select parent clock that results in the closest but lower rate
>> > +	 */
>> > +	for (i = 0; i < clk_hw_get_num_parents(hw); ++i) {
>> > +		parent = clk_hw_get_parent_by_index(hw, i);
>> > +		if (!parent)
>> > +			continue;
>> > +		parent_req = *req;
>> 
>> parent_req appears dead, so it should be removed.
>
> Yes, will do thanks.
>
>> > +		prate = clk_hw_get_rate(parent);
>> > +		div = bcm2835_clock_choose_div(hw, req->rate, prate);
>> > +		rate = bcm2835_clock_rate_from_divisor(clock, prate, div);
>> > +		if (rate > best_rate && rate <= req->rate) {
>> > +			best_parent = parent;
>> > +			best_prate = prate;
>> > +			best_rate = rate;
>> > +		}
>> > +	}
>> > +
>> > +	if (!best_parent)
>> > +		return -EINVAL;
>> > +
>> > +	req->best_parent_hw = best_parent;
>> > +	req->best_parent_rate = best_prate;
>> 
>> I think you're supposed to req->rate = best_rate, here, too.  With these
>> two fixes,
>
> I did not set req->rate to best_rate in order to avoid rounding down
> twice the actual clock rate.
>
> Indeed with patch 1 from this patchset bcm2835_clock_choose_div()
> chooses a divisor that produces a rate lower or equal to the requested
> one. As we call bcm2835_clock_choose_div() twice when using
> clk_set_rate() (once with ->determine_rate() and once with ->set_rate()),
> if I set req->rate in bcm2835_clock_determine_rate to the rounded down
> one, the final rate will likely be again rounded down in
> bcm2835_clock_set_rate().

If we pass bcm2835_clock_rate_from_divisor(bcm2835_clock_choose_div()),
to bcm2835_clock_choose_div(), will it actually give a different divisor
than the first call?  (That seems like an unfortunate problem in our
implementation, if so).

I'd be willing to go along with this, but if so I'd like a comment
explaining why we aren't setting the field that we should pretty
obviously be setting.

[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 818 bytes --]

  reply	other threads:[~2015-12-04  0:37 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-11 14:22 [PATCH v2 0/3] Add PWM clock support for bcm2835 Remi Pommarel
2015-11-11 14:22 ` [PATCH v2 1/3] clk: bcm2835: Always round up clock divisor Remi Pommarel
2015-11-18 18:25   ` Eric Anholt
2015-11-18 19:11     ` Remi Pommarel
2015-12-02 22:21       ` Remi Pommarel
2015-12-04  0:31       ` Eric Anholt
2015-11-11 14:22 ` [PATCH v2 2/3] clk: bcm2835: Support for clock parent selection Remi Pommarel
2015-11-18 18:30   ` Eric Anholt
2015-11-18 19:24     ` Remi Pommarel
2015-12-04  0:37       ` Eric Anholt [this message]
2015-12-04 20:37         ` Remi Pommarel
2015-12-06  0:19           ` Eric Anholt
2015-11-11 14:22 ` [PATCH v2 3/3] clk: bcm2835: Add PWM clock support Remi Pommarel
2015-11-18 18:32   ` Eric Anholt
2015-11-18 19:26     ` Remi Pommarel
2015-11-28 20:52 ` [PATCH v2 0/3] Add PWM clock support for bcm2835 Stefan Wahren
2015-11-29  0:31   ` Remi Pommarel
2015-11-29 21:22     ` Stefan Wahren
2015-11-29 22:25       ` Remi Pommarel

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=87io4fgibw.fsf@eliezer.anholt.net \
    --to=eric@anholt.net \
    --cc=lee@kernel.org \
    --cc=linux-clk@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-rpi-kernel@lists.infradead.org \
    --cc=mturquette@baylibre.com \
    --cc=repk@triplefau.lt \
    --cc=sboyd@codeaurora.org \
    --cc=swarren@wwwdotorg.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).