All of lore.kernel.org
 help / color / mirror / Atom feed
From: Lukasz Majewski <l.majewski@samsung.com>
To: Thomas Abraham <ta.omasab@gmail.com>
Cc: linux-samsung-soc@vger.kernel.org, cpufreq@vger.kernel.org,
	devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org,
	t.figa@samsung.com, kgene.kim@samsung.com,
	viresh.kumar@linaro.org, shawn.guo@linaro.org,
	thomas.ab@samsung.com, Lukasz Majewski <l.majewski@majess.pl>
Subject: Re: [PATCH 2/6] clk: samsung: add infrastructure to register CPU clocks
Date: Fri, 10 Jan 2014 13:04:07 +0100	[thread overview]
Message-ID: <20140110130407.3390213d@amdc2363> (raw)
In-Reply-To: <1389283165-17708-3-git-send-email-thomas.ab@samsung.com>

Hi Thomas,

> The CPU clock provider supplies the clock to the CPU clock domain. The
> composition and organization of the CPU clock provider could vary
> among Exynos SoCs. A CPU clock provider can be composed of clock mux,
> dividers and gates. This patch defines a new clock type for CPU clock
> provider and adds infrastructure to register the CPU clock providers
> for Samsung platforms.
> 
> Signed-off-by: Thomas Abraham <thomas.ab@samsung.com>
> ---
>  drivers/clk/samsung/clk.c |   71
> +++++++++++++++++++++++++++++++++++++++++++++
> drivers/clk/samsung/clk.h |   37 +++++++++++++++++++++++- 2 files
> changed, 107 insertions(+), 1 deletions(-)
> 
> diff --git a/drivers/clk/samsung/clk.c b/drivers/clk/samsung/clk.c
> index f503f32..9ac9056 100644
> --- a/drivers/clk/samsung/clk.c
> +++ b/drivers/clk/samsung/clk.c
> @@ -316,3 +316,74 @@ unsigned long _get_rate(const char *clk_name)
>  
>  	return clk_get_rate(clk);
>  }
> +
> +/*
> + * On most platform, the core clock rate is equal to the clock rate
> of
> + * parent pll. This is a simple helper function to support
> recalc_rate
> + * callback for such platforms.
> + */
> +unsigned long samsung_core_clock_recalc_rate(struct clk_hw *hw,
> +				unsigned long parent_rate)
> +{
> +	/*
> +	 * Assuming that the output of the parent pll is the output
> clock
> +	 * frequency of the core clock.
> +	 */
> +	return parent_rate;
> +}
> +
> +/* This is a helper function to perform clock rounding for core
> clocks. */ +long samsung_core_clk_round_rate(struct clk_hw *hw,
> +			unsigned long drate, unsigned long *prate)
> +{
> +	struct samsung_core_clock *core_clk;
> +	const struct samsung_core_clock_freq_table *freq_tbl;
> +	int i;
> +
> +	core_clk = container_of(hw, struct samsung_core_clock, hw);
> +	freq_tbl = core_clk->freq_table;
> +	drate /= 1000;
> +
> +	for (i = 0; i < freq_tbl->freq_count; i++) {
> +		if (drate >= freq_tbl->freq[i])
> +			return freq_tbl->freq[i] * 1000;
> +	}
> +	return freq_tbl->freq[i - 1] * 1000;
> +}
> +
> +/* helper function to register a core clock */
> +void __init samsung_coreclk_register(const char *name, const char
> **parents,
> +			unsigned int num_parents, const char *pllclk,
> +			const struct clk_ops *clk_ops, unsigned int
> lookup_id,
> +			const struct samsung_core_clock_freq_table
> *freq_tbl) +{
> +	struct samsung_core_clock *coreclk;
> +	struct clk_init_data init;
> +	struct clk *clk;
> +
> +	coreclk = kzalloc(sizeof(*coreclk), GFP_KERNEL);
> +	if (!coreclk) {
> +		pr_err("%s: could not allocate memory for coreclk
> %s\n",
> +					__func__, name);
> +		return;
> +	}
> +
> +	init.name = name;
> +	init.flags = CLK_GET_RATE_NOCACHE;
> +	init.parent_names = parents;
> +	init.num_parents = num_parents;
> +	init.ops = clk_ops;
> +
> +	coreclk->hw.init = &init;
> +	coreclk->ctrl_base = reg_base;
> +	coreclk->fout_pll = __clk_lookup(pllclk);
> +	coreclk->freq_table = freq_tbl;
> +
> +	clk = clk_register(NULL, &coreclk->hw);
> +	if (IS_ERR(clk)) {
> +		pr_err("%s: could not register coreclk %s\n",
> __func__,	name);
> +		kfree(coreclk);
> +		return;
> +	}
> +	samsung_clk_add_lookup(clk, lookup_id);
> +}

I think, that those definitions for samsung_core_clock shall be moved
to a separate file (maybe clk-exynos-cpu.c)?

Moreover, maybe you can choose a shorter name?

> diff --git a/drivers/clk/samsung/clk.h b/drivers/clk/samsung/clk.h
> index 31b4174..0e43023 100644
> --- a/drivers/clk/samsung/clk.h
> +++ b/drivers/clk/samsung/clk.h
> @@ -312,6 +312,37 @@ struct samsung_pll_clock {
>  	__PLL(_typ, _id, NULL, _name, _pname,
> CLK_GET_RATE_NOCACHE,	\ _lock, _con, _rtable, _alias)
>  
> +/**
> + * struct samsung_core_clock_freq_table: table of frequency
> supported by
> + * a core clock and associated data if any.
> + * @freq: points to a table of supported frequencies (in KHz)
> + * @freq_count: number of entries in the frequency table
> + * @data: core clock specific data, if any
> + */
> +struct samsung_core_clock_freq_table {
> +	const unsigned long	*freq;       /* in KHz */
> +	unsigned long		freq_count;
> +	const void		*data;
> +};

This is another instance of a structure, which holds the frequency for
the system (like struct cpufreq_frequency_table). 

Unfortunately, since the clk subsystem starts very early, the
cpufreq_frequency_table is not yet parsed from "operating-points"
attribute.

Maybe we can defer the clock registration?

> +
> +/**
> + * struct samsung_core_clock: information about clock supplied to a
> CPU core.
> + * @hw: handle between ccf and core clock.
> + * @ctrl_base: base address of the clock controller.
> + * @fout_pll: clock handle representing the clock output of the
> associated PLL.
> + */
> +struct samsung_core_clock {
> +	struct clk_hw		hw;
> +	void __iomem		*ctrl_base;
> +	struct clk		*fout_pll;
> +	const struct samsung_core_clock_freq_table *freq_table;
> +};
> +
> +extern unsigned long samsung_core_clock_recalc_rate(struct clk_hw
> *hw,
> +				unsigned long parent_rate);
> +extern long samsung_core_clk_round_rate(struct clk_hw *hw,
> +			unsigned long drate, unsigned long *prate);

IMHO, those methods shall be defined as static in a separate file.

> +
>  extern void __init samsung_clk_init(struct device_node *np, void
> __iomem *base, unsigned long nr_clks, unsigned long *rdump,
>  		unsigned long nr_rdump, unsigned long *soc_rdump,
> @@ -337,7 +368,11 @@ extern void __init samsung_clk_register_gate(
>  		struct samsung_gate_clock *clk_list, unsigned int
> nr_clk); extern void __init samsung_clk_register_pll(struct
> samsung_pll_clock *pll_list, unsigned int nr_clk, void __iomem *base);
> -
> +extern void __init samsung_coreclk_register(const char *coreclk,
> +		const char **parents, unsigned int num_parents,
> +		const char *pllclk, const struct clk_ops *clk_ops,
> +		unsigned int lookup_id,
> +		const struct samsung_core_clock_freq_table
> *freq_tbl); extern unsigned long _get_rate(const char *clk_name);
>  
>  #endif /* __SAMSUNG_CLK_H */



-- 
Best regards,

Lukasz Majewski

Samsung R&D Institute Poland (SRPOL) | Linux Platform Group

WARNING: multiple messages have this Message-ID (diff)
From: l.majewski@samsung.com (Lukasz Majewski)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH 2/6] clk: samsung: add infrastructure to register CPU clocks
Date: Fri, 10 Jan 2014 13:04:07 +0100	[thread overview]
Message-ID: <20140110130407.3390213d@amdc2363> (raw)
In-Reply-To: <1389283165-17708-3-git-send-email-thomas.ab@samsung.com>

Hi Thomas,

> The CPU clock provider supplies the clock to the CPU clock domain. The
> composition and organization of the CPU clock provider could vary
> among Exynos SoCs. A CPU clock provider can be composed of clock mux,
> dividers and gates. This patch defines a new clock type for CPU clock
> provider and adds infrastructure to register the CPU clock providers
> for Samsung platforms.
> 
> Signed-off-by: Thomas Abraham <thomas.ab@samsung.com>
> ---
>  drivers/clk/samsung/clk.c |   71
> +++++++++++++++++++++++++++++++++++++++++++++
> drivers/clk/samsung/clk.h |   37 +++++++++++++++++++++++- 2 files
> changed, 107 insertions(+), 1 deletions(-)
> 
> diff --git a/drivers/clk/samsung/clk.c b/drivers/clk/samsung/clk.c
> index f503f32..9ac9056 100644
> --- a/drivers/clk/samsung/clk.c
> +++ b/drivers/clk/samsung/clk.c
> @@ -316,3 +316,74 @@ unsigned long _get_rate(const char *clk_name)
>  
>  	return clk_get_rate(clk);
>  }
> +
> +/*
> + * On most platform, the core clock rate is equal to the clock rate
> of
> + * parent pll. This is a simple helper function to support
> recalc_rate
> + * callback for such platforms.
> + */
> +unsigned long samsung_core_clock_recalc_rate(struct clk_hw *hw,
> +				unsigned long parent_rate)
> +{
> +	/*
> +	 * Assuming that the output of the parent pll is the output
> clock
> +	 * frequency of the core clock.
> +	 */
> +	return parent_rate;
> +}
> +
> +/* This is a helper function to perform clock rounding for core
> clocks. */ +long samsung_core_clk_round_rate(struct clk_hw *hw,
> +			unsigned long drate, unsigned long *prate)
> +{
> +	struct samsung_core_clock *core_clk;
> +	const struct samsung_core_clock_freq_table *freq_tbl;
> +	int i;
> +
> +	core_clk = container_of(hw, struct samsung_core_clock, hw);
> +	freq_tbl = core_clk->freq_table;
> +	drate /= 1000;
> +
> +	for (i = 0; i < freq_tbl->freq_count; i++) {
> +		if (drate >= freq_tbl->freq[i])
> +			return freq_tbl->freq[i] * 1000;
> +	}
> +	return freq_tbl->freq[i - 1] * 1000;
> +}
> +
> +/* helper function to register a core clock */
> +void __init samsung_coreclk_register(const char *name, const char
> **parents,
> +			unsigned int num_parents, const char *pllclk,
> +			const struct clk_ops *clk_ops, unsigned int
> lookup_id,
> +			const struct samsung_core_clock_freq_table
> *freq_tbl) +{
> +	struct samsung_core_clock *coreclk;
> +	struct clk_init_data init;
> +	struct clk *clk;
> +
> +	coreclk = kzalloc(sizeof(*coreclk), GFP_KERNEL);
> +	if (!coreclk) {
> +		pr_err("%s: could not allocate memory for coreclk
> %s\n",
> +					__func__, name);
> +		return;
> +	}
> +
> +	init.name = name;
> +	init.flags = CLK_GET_RATE_NOCACHE;
> +	init.parent_names = parents;
> +	init.num_parents = num_parents;
> +	init.ops = clk_ops;
> +
> +	coreclk->hw.init = &init;
> +	coreclk->ctrl_base = reg_base;
> +	coreclk->fout_pll = __clk_lookup(pllclk);
> +	coreclk->freq_table = freq_tbl;
> +
> +	clk = clk_register(NULL, &coreclk->hw);
> +	if (IS_ERR(clk)) {
> +		pr_err("%s: could not register coreclk %s\n",
> __func__,	name);
> +		kfree(coreclk);
> +		return;
> +	}
> +	samsung_clk_add_lookup(clk, lookup_id);
> +}

I think, that those definitions for samsung_core_clock shall be moved
to a separate file (maybe clk-exynos-cpu.c)?

Moreover, maybe you can choose a shorter name?

> diff --git a/drivers/clk/samsung/clk.h b/drivers/clk/samsung/clk.h
> index 31b4174..0e43023 100644
> --- a/drivers/clk/samsung/clk.h
> +++ b/drivers/clk/samsung/clk.h
> @@ -312,6 +312,37 @@ struct samsung_pll_clock {
>  	__PLL(_typ, _id, NULL, _name, _pname,
> CLK_GET_RATE_NOCACHE,	\ _lock, _con, _rtable, _alias)
>  
> +/**
> + * struct samsung_core_clock_freq_table: table of frequency
> supported by
> + * a core clock and associated data if any.
> + * @freq: points to a table of supported frequencies (in KHz)
> + * @freq_count: number of entries in the frequency table
> + * @data: core clock specific data, if any
> + */
> +struct samsung_core_clock_freq_table {
> +	const unsigned long	*freq;       /* in KHz */
> +	unsigned long		freq_count;
> +	const void		*data;
> +};

This is another instance of a structure, which holds the frequency for
the system (like struct cpufreq_frequency_table). 

Unfortunately, since the clk subsystem starts very early, the
cpufreq_frequency_table is not yet parsed from "operating-points"
attribute.

Maybe we can defer the clock registration?

> +
> +/**
> + * struct samsung_core_clock: information about clock supplied to a
> CPU core.
> + * @hw: handle between ccf and core clock.
> + * @ctrl_base: base address of the clock controller.
> + * @fout_pll: clock handle representing the clock output of the
> associated PLL.
> + */
> +struct samsung_core_clock {
> +	struct clk_hw		hw;
> +	void __iomem		*ctrl_base;
> +	struct clk		*fout_pll;
> +	const struct samsung_core_clock_freq_table *freq_table;
> +};
> +
> +extern unsigned long samsung_core_clock_recalc_rate(struct clk_hw
> *hw,
> +				unsigned long parent_rate);
> +extern long samsung_core_clk_round_rate(struct clk_hw *hw,
> +			unsigned long drate, unsigned long *prate);

IMHO, those methods shall be defined as static in a separate file.

> +
>  extern void __init samsung_clk_init(struct device_node *np, void
> __iomem *base, unsigned long nr_clks, unsigned long *rdump,
>  		unsigned long nr_rdump, unsigned long *soc_rdump,
> @@ -337,7 +368,11 @@ extern void __init samsung_clk_register_gate(
>  		struct samsung_gate_clock *clk_list, unsigned int
> nr_clk); extern void __init samsung_clk_register_pll(struct
> samsung_pll_clock *pll_list, unsigned int nr_clk, void __iomem *base);
> -
> +extern void __init samsung_coreclk_register(const char *coreclk,
> +		const char **parents, unsigned int num_parents,
> +		const char *pllclk, const struct clk_ops *clk_ops,
> +		unsigned int lookup_id,
> +		const struct samsung_core_clock_freq_table
> *freq_tbl); extern unsigned long _get_rate(const char *clk_name);
>  
>  #endif /* __SAMSUNG_CLK_H */



-- 
Best regards,

Lukasz Majewski

Samsung R&D Institute Poland (SRPOL) | Linux Platform Group

  reply	other threads:[~2014-01-10 12:04 UTC|newest]

Thread overview: 80+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-01-09 15:59 [PATCH 0/6] cpufreq: use cpufreq-cpu0 driver for exynos4210 based platforms Thomas Abraham
2014-01-09 15:59 ` Thomas Abraham
2014-01-09 15:59 ` [PATCH 1/6] cpufreq: cpufreq-cpu0: allow optional safe voltage during frequency transitions Thomas Abraham
2014-01-09 15:59   ` Thomas Abraham
2014-01-10 12:03   ` Lukasz Majewski
2014-01-10 12:03     ` Lukasz Majewski
2014-01-12 13:39   ` Tomasz Figa
2014-01-12 13:39     ` Tomasz Figa
2014-01-13  3:14   ` Shawn Guo
2014-01-13  3:14     ` Shawn Guo
2014-01-13 14:21     ` Thomas Abraham
2014-01-13 14:21       ` Thomas Abraham
2014-01-13 14:28       ` Shawn Guo
2014-01-13 14:28         ` Shawn Guo
2014-01-09 15:59 ` [PATCH 2/6] clk: samsung: add infrastructure to register CPU clocks Thomas Abraham
2014-01-09 15:59   ` Thomas Abraham
2014-01-10 12:04   ` Lukasz Majewski [this message]
2014-01-10 12:04     ` Lukasz Majewski
2014-01-10 12:19     ` Thomas Abraham
2014-01-10 12:19       ` Thomas Abraham
2014-01-10 13:25       ` Lukasz Majewski
2014-01-10 13:25         ` Lukasz Majewski
2014-01-11  4:43         ` Thomas Abraham
2014-01-11  4:43           ` Thomas Abraham
2014-01-12  1:47           ` Tomasz Figa
2014-01-12  1:47             ` Tomasz Figa
2014-01-12  8:04             ` Lukasz Majewski
2014-01-12  8:04               ` Lukasz Majewski
2014-01-13 13:15             ` Thomas Abraham
2014-01-13 13:15               ` Thomas Abraham
2014-01-09 15:59 ` [PATCH 3/6] clk: samsung: register cpu clock provider for exynos4210 SoC Thomas Abraham
2014-01-09 15:59   ` Thomas Abraham
2014-01-10 12:04   ` Lukasz Majewski
2014-01-10 12:04     ` Lukasz Majewski
2014-01-10 12:37     ` Thomas Abraham
2014-01-10 12:37       ` Thomas Abraham
2014-01-10 14:18       ` Lukasz Majewski
2014-01-10 14:18         ` Lukasz Majewski
2014-01-11  5:25         ` Thomas Abraham
2014-01-11  5:25           ` Thomas Abraham
2014-01-12  2:19           ` Tomasz Figa
2014-01-12  2:19             ` Tomasz Figa
2014-01-12  8:23             ` Lukasz Majewski
2014-01-12  8:23               ` Lukasz Majewski
2014-01-12 12:05               ` Tomasz Figa
2014-01-12 12:05                 ` Tomasz Figa
2014-01-12 12:41                 ` Lukasz Majewski
2014-01-12 12:41                   ` Lukasz Majewski
2014-01-12 12:58                   ` Tomasz Figa
2014-01-12 12:58                     ` Tomasz Figa
2014-01-13 14:12                     ` Thomas Abraham
2014-01-13 14:12                       ` Thomas Abraham
2014-01-13 14:07             ` Thomas Abraham
2014-01-13 14:07               ` Thomas Abraham
2014-01-09 15:59 ` [PATCH 4/6] cpufreq: exynos: remove Exynos4210 specific cpufreq driver support Thomas Abraham
2014-01-09 15:59   ` Thomas Abraham
2014-01-10 10:20   ` Lukasz Majewski
2014-01-10 10:20     ` Lukasz Majewski
2014-01-09 15:59 ` [PATCH 5/6] arm: exynos4-dt: statically add platform device for cpufreq-cpu0 platform driver Thomas Abraham
2014-01-09 15:59   ` Thomas Abraham
2014-01-10 10:23   ` Lukasz Majewski
2014-01-10 10:23     ` Lukasz Majewski
2014-01-13  3:17   ` Shawn Guo
2014-01-13  3:17     ` Shawn Guo
2014-01-09 15:59 ` [PATCH 6/6] arm: dts: add cpu nodes for Exynos4210 SoC Thomas Abraham
2014-01-09 15:59   ` Thomas Abraham
2014-01-10 10:32   ` Lukasz Majewski
2014-01-10 10:32     ` Lukasz Majewski
2014-01-10 12:06     ` Thomas Abraham
2014-01-10 12:06       ` Thomas Abraham
2014-01-10 10:32 ` [PATCH 0/6] cpufreq: use cpufreq-cpu0 driver for exynos4210 based platforms Lukasz Majewski
2014-01-10 10:32   ` Lukasz Majewski
2014-01-10 11:59   ` Thomas Abraham
2014-01-10 11:59     ` Thomas Abraham
2014-01-12  2:26     ` Tomasz Figa
2014-01-12  2:26       ` Tomasz Figa
2014-01-13 14:27       ` Thomas Abraham
2014-01-13 14:27         ` Thomas Abraham
     [not found] <'@samsung.com>
2015-04-03 16:43 ` [PATCH 0/6] cpufreq: use generic cpufreq drivers for Exynos4210 platform Bartlomiej Zolnierkiewicz
2015-04-03 16:43   ` [PATCH 2/6] clk: samsung: add infrastructure to register cpu clocks Bartlomiej Zolnierkiewicz
2015-04-03 16:43     ` Bartlomiej Zolnierkiewicz

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=20140110130407.3390213d@amdc2363 \
    --to=l.majewski@samsung.com \
    --cc=cpufreq@vger.kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=kgene.kim@samsung.com \
    --cc=l.majewski@majess.pl \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-samsung-soc@vger.kernel.org \
    --cc=shawn.guo@linaro.org \
    --cc=t.figa@samsung.com \
    --cc=ta.omasab@gmail.com \
    --cc=thomas.ab@samsung.com \
    --cc=viresh.kumar@linaro.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.