[PATCH 02/31] clk: export generic routines
Simon Glass
sjg at chromium.org
Sat Aug 29 01:36:32 CEST 2020
Hi Dario,
On Tue, 25 Aug 2020 at 03:24, Dario Binacchi <dariobin at libero.it> wrote:
>
> Export routines that can be used by other drivers avoiding duplicating
> code.
>
> Signed-off-by: Dario Binacchi <dariobin at libero.it>
> ---
>
> drivers/clk/clk-divider.c | 18 +++++++++---------
> include/linux/clk-provider.h | 10 ++++++++++
> 2 files changed, 19 insertions(+), 9 deletions(-)
>
> diff --git a/drivers/clk/clk-divider.c b/drivers/clk/clk-divider.c
> index 8f59d7fb72..9fd5fa8423 100644
> --- a/drivers/clk/clk-divider.c
> +++ b/drivers/clk/clk-divider.c
> @@ -28,7 +28,7 @@
>
> #define UBOOT_DM_CLK_CCF_DIVIDER "ccf_clk_divider"
>
> -static unsigned int _get_table_div(const struct clk_div_table *table,
> +unsigned int divider_get_table_div(const struct clk_div_table *table,
> unsigned int val)
I think clkdiv_ or clk_divider_ might be a good prefix for the
expected functions in this file, so it is clear it relates to clock.
> {
> const struct clk_div_table *clkt;
> @@ -49,7 +49,7 @@ static unsigned int _get_div(const struct clk_div_table *table,
> if (flags & CLK_DIVIDER_MAX_AT_ZERO)
> return val ? val : clk_div_mask(width) + 1;
> if (table)
> - return _get_table_div(table, val);
> + return divider_get_table_div(table, val);
> return val + 1;
> }
>
> @@ -89,7 +89,7 @@ static ulong clk_divider_recalc_rate(struct clk *clk)
> divider->flags, divider->width);
> }
>
> -static bool _is_valid_table_div(const struct clk_div_table *table,
> +bool divider_is_valid_table_div(const struct clk_div_table *table,
> unsigned int div)
> {
> const struct clk_div_table *clkt;
> @@ -100,17 +100,17 @@ static bool _is_valid_table_div(const struct clk_div_table *table,
> return false;
> }
>
> -static bool _is_valid_div(const struct clk_div_table *table, unsigned int div,
> - unsigned long flags)
> +bool divider_is_valid_div(const struct clk_div_table *table,
> + unsigned int div, unsigned long flags)
> {
> if (flags & CLK_DIVIDER_POWER_OF_TWO)
> return is_power_of_2(div);
> if (table)
> - return _is_valid_table_div(table, div);
> + return divider_is_valid_table_div(table, div);
> return true;
> }
>
> -static unsigned int _get_table_val(const struct clk_div_table *table,
> +unsigned int divider_get_table_val(const struct clk_div_table *table,
> unsigned int div)
> {
> const struct clk_div_table *clkt;
> @@ -131,7 +131,7 @@ static unsigned int _get_val(const struct clk_div_table *table,
> if (flags & CLK_DIVIDER_MAX_AT_ZERO)
> return (div == clk_div_mask(width) + 1) ? 0 : div;
> if (table)
> - return _get_table_val(table, div);
> + return divider_get_table_val(table, div);
> return div - 1;
> }
> int divider_get_val(unsigned long rate, unsigned long parent_rate,
> @@ -142,7 +142,7 @@ int divider_get_val(unsigned long rate, unsigned long parent_rate,
>
> div = DIV_ROUND_UP_ULL((u64)parent_rate, rate);
>
> - if (!_is_valid_div(table, div, flags))
> + if (!divider_is_valid_div(table, div, flags))
> return -EINVAL;
>
> value = _get_val(table, div, flags, width);
> diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
> index a2630056de..b7cc8d89f1 100644
> --- a/include/linux/clk-provider.h
> +++ b/include/linux/clk-provider.h
> @@ -74,6 +74,7 @@ struct clk_mux {
> #define to_clk_mux(_clk) container_of(_clk, struct clk_mux, clk)
> extern const struct clk_ops clk_mux_ops;
> u8 clk_mux_get_parent(struct clk *clk);
> +unsigned int clk_mux_index_to_val(u32 *table, unsigned int flags, u8 index);
>
> struct clk_gate {
> struct clk clk;
> @@ -124,6 +125,15 @@ struct clk_divider {
> #define CLK_DIVIDER_READ_ONLY BIT(5)
> #define CLK_DIVIDER_MAX_AT_ZERO BIT(6)
> extern const struct clk_ops clk_divider_ops;
> +
> +unsigned int divider_get_table_div(const struct clk_div_table *table,
> + unsigned int val);
> +unsigned int divider_get_table_val(const struct clk_div_table *table,
> + unsigned int div);
> +bool divider_is_valid_div(const struct clk_div_table *table,
> + unsigned int div, unsigned long flags);
> +bool divider_is_valid_table_div(const struct clk_div_table *table,
> + unsigned int div);
These need full function comments.
> unsigned long divider_recalc_rate(struct clk *hw, unsigned long parent_rate,
> unsigned int val,
> const struct clk_div_table *table,
> --
> 2.17.1
>
Regards,
SImon
More information about the U-Boot
mailing list