From: Eric Anholt <eric@anholt.net>
To: Remi Pommarel <repk@triplefau.lt>,
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
Cc: Remi Pommarel <repk@triplefau.lt>
Subject: Re: [PATCH 1/2] clk: bcm2835: Support for clock parent selection
Date: Wed, 04 Nov 2015 18:03:31 -0800 [thread overview]
Message-ID: <87si4l2oek.fsf@eliezer.anholt.net> (raw)
In-Reply-To: <1446678502-16243-2-git-send-email-repk@triplefau.lt>
[-- Attachment #1: Type: text/plain, Size: 2764 bytes --]
Remi Pommarel <repk@triplefau.lt> writes:
> Some bcm2835 clocks used by hardware (like "PWM" or "H264") can have multiple
> parents. These clocks divide the rate of one parent which can be selected by
> setting the proper bits in their clock control register.
>
> Previously all these parents where handled by a mux clock. But a mux clock
> cannot be used because updating clock control register to select parent needs a
> password to be xor'd with the parent index.
Good point. I previously was doing parent detection from muxes
manually, then simplified to using the generic mux later. I didn't have
any clocks I wanted to change mux on, so I missed this requirement.
It looks like there's not too much work to folding the muxing back into
the driver, so it seems like you have a good plan.
> -static long bcm2835_clock_round_rate(struct clk_hw *hw,
> - unsigned long rate,
> - unsigned long *parent_rate)
> -{
> - struct bcm2835_clock *clock = bcm2835_clock_from_hw(hw);
> - u32 div = bcm2835_clock_choose_div(hw, rate, *parent_rate);
> -
> - return bcm2835_clock_rate_from_divisor(clock, *parent_rate, div);
> -}
> -
> static unsigned long bcm2835_clock_get_rate(struct clk_hw *hw,
> unsigned long parent_rate)
> {
> @@ -1278,13 +1268,69 @@ static int bcm2835_clock_set_rate(struct clk_hw *hw,
> return 0;
> }
>
> +static int bcm2835_clock_determine_source(struct clk_hw *hw,
> + struct clk_rate_request *req)
> +{
> + struct clk_hw *parent, *best_parent = NULL;
> + struct clk_rate_request parent_req;
> + unsigned long prate, best_rate = ULONG_MAX;
> + size_t i;
> +
> + /*
> + * Select parent clock that has the closest but higher 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;
> + prate = clk_hw_get_rate(parent);
> + if (prate < best_rate && prate >= req->rate) {
> + best_parent = parent;
> + best_rate = prate;
> + }
> + }
> +
> + if (!best_parent)
> + return -EINVAL;
> +
> + req->best_parent_hw = best_parent;
> + req->best_parent_rate = best_rate;
> +
> + return 0;
> +}
It looks like you've dropped the use of the divisor off of the PLL
channel when setting a rate. That seems bad for all the other clocks in
the system, and a feature we couldn't lose.
Also, you're choosing the lowest but higher rate, while
mux_is_better_rate() chooses the highest but lower rate (which seems
much safer). What led to that choice?
Also, if we're going to have this function, I think it should be called
"bcm2835_clock_determine_rate" to match the method name.
The parent get/setting looks good, though.
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 818 bytes --]
next prev parent reply other threads:[~2015-11-05 2:03 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-11-04 23:08 [PATCH 0/2] Add PWM clock support for bcm2835 Remi Pommarel
2015-11-04 23:08 ` [PATCH 1/2] clk: bcm2835: Support for clock parent selection Remi Pommarel
2015-11-05 2:03 ` Eric Anholt [this message]
2015-11-05 18:53 ` Remi Pommarel
2015-11-09 16:38 ` Eric Anholt
2015-11-04 23:08 ` [PATCH 2/2] clk: bcm2835: Add PWM clock support Remi Pommarel
2015-11-05 2:17 ` Eric Anholt
2015-11-05 18:59 ` 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=87si4l2oek.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