Add cpufreq driver for Tegra194
Subsystems (2)
v2 cover Add cpufreq driver for Tegra194
The patch series adds cpufreq driver for Tegra194 SOC.
v1[1] -> v2:
- Remove cpufreq_lock mutex from tegra194_cpufreq_set_target [Viresh].
- Remove CPUFREQ_ASYNC_NOTIFICATION flag [Viresh].
- Remove redundant _begin|end() call from tegra194_cpufreq_set_target.
- Rename opp_table to freq_table [Viresh].
Sumit Gupta (3):
firmware: tegra: adding function to get BPMP data
cpufreq: Add Tegra194 cpufreq driver
arm64: defconfig: Enable CONFIG_ARM_TEGRA194_CPUFREQ
arch/arm64/configs/defconfig | 1 + drivers/cpufreq/Kconfig.arm | 6 + drivers/cpufreq/Makefile | 1 + drivers/cpufreq/tegra194-cpufreq.c | 412 +++++++++++++++++++++++++++++++++++++ drivers/firmware/tegra/bpmp.c | 38 ++++ include/soc/tegra/bpmp.h | 5 + 6 files changed, 463 insertions(+) create mode 100644 drivers/cpufreq/tegra194-cpufreq.c
[1] https://marc.info/?t=157539452300001&r=1&w=2
Signature · 1 line
2.7.4
PATCH v2 1/3 firmware: tegra: adding function to get BPMP data
Adding new function of_tegra_bpmp_get() to get BPMP data. This function can be used by other drivers like cpufreq to get BPMP data without adding any property in respective drivers DT node.
--- drivers/firmware/tegra/bpmp.c | 38 ++++++++++++++++++++++++++++++++++++++ include/soc/tegra/bpmp.h | 5 +++++ 2 files changed, 43 insertions(+)
drivers/firmware/tegra/bpmp.c +38 -0
@@ -38,6 +38,44 @@ channel_to_ops(struct tegra_bpmp_channel *channel)return bpmp->soc->ops; } +struct tegra_bpmp *of_tegra_bpmp_get (void ) +{ +struct platform_device *pdev; +struct device_node *bpmp_dev; +struct tegra_bpmp *bpmp; + +/* Check for bpmp device status in DT */ + bpmp_dev =of_find_compatible_node (NULL ,NULL ,"nvidia,tegra186-bpmp" ); +if (!bpmp_dev) { + bpmp =ERR_PTR (-ENODEV ); + goto err_out; + } +if (!of_device_is_available (bpmp_dev)) { + bpmp =ERR_PTR (-ENODEV ); + goto err_put; + } + + pdev =of_find_device_by_node (bpmp_dev); +if (!pdev) { + bpmp =ERR_PTR (-ENODEV ); + goto err_put; + } + + bpmp =platform_get_drvdata (pdev); +if (!bpmp) { + bpmp =ERR_PTR (-EPROBE_DEFER ); +put_device (&pdev->dev); + goto err_put; + } + +return bpmp; +err_put: +of_node_put (bpmp_dev); +err_out: +return bpmp; +} +EXPORT_SYMBOL_GPL (of_tegra_bpmp_get); +struct tegra_bpmp *tegra_bpmp_get (struct device *dev) {struct platform_device *pdev;
include/soc/tegra/bpmp.h +5 -0
@@ -107,6 +107,7 @@ struct tegra_bpmp_message { };#if IS_ENABLED (CONFIG_TEGRA_BPMP ) +struct tegra_bpmp *of_tegra_bpmp_get (void );struct tegra_bpmp *tegra_bpmp_get (struct device *dev);void tegra_bpmp_put (struct tegra_bpmp *bpmp); int tegra_bpmp_transfer_atomic(struct tegra_bpmp *bpmp,
@@ -122,6 +123,10 @@ void tegra_bpmp_free_mrq(struct tegra_bpmp *bpmp, unsigned int mrq, void *data);bool tegra_bpmp_mrq_is_supported (struct tegra_bpmp *bpmp,unsigned int mrq);#else +static inline struct tegra_bpmp *of_tegra_bpmp_get (void ) +{ +return ERR_PTR (-ENOTSUPP ); +}static inline struct tegra_bpmp *tegra_bpmp_get (struct device *dev) {return ERR_PTR (-ENOTSUPP );
Signature · 1 line
2.7.4
PATCH v2 2/3 cpufreq: Add Tegra194 cpufreq driver
In reply to Sumit GuptaAdd support for CPU frequency scaling on Tegra194. The frequency of each core can be adjusted by writing a clock divisor value to an MSR on the core. The range of valid divisors is queried from the BPMP.
--- drivers/cpufreq/Kconfig.arm | 6 + drivers/cpufreq/Makefile | 1 + drivers/cpufreq/tegra194-cpufreq.c | 412 +++++++++++++++++++++++++++++++++++++ 3 files changed, 419 insertions(+) create mode 100644 drivers/cpufreq/tegra194-cpufreq.c
drivers/cpufreq/Kconfig.arm +6 -0
@@ -320,6 +320,12 @@ config ARM_TEGRA186_CPUFREQ help This adds the CPUFreq driver support for Tegra186 SOCs. +config ARM_TEGRA194_CPUFREQ + tristate "Tegra194 CPUFreq support" + depends on ARCH_TEGRA && TEGRA_BPMP + help + This adds CPU frequency driver support for Tegra194 SOCs. + config ARM_TI_CPUFREQ bool "Texas Instruments CPUFreq support" depends on ARCH_OMAP2PLUS
drivers/cpufreq/Makefile +1 -0
@@ -85,6 +85,7 @@ obj-$(CONFIG_ARM_TANGO_CPUFREQ) += tango-cpufreq.o obj-$(CONFIG_ARM_TEGRA20_CPUFREQ) += tegra20-cpufreq.o obj-$(CONFIG_ARM_TEGRA124_CPUFREQ) += tegra124-cpufreq.o obj-$(CONFIG_ARM_TEGRA186_CPUFREQ) += tegra186-cpufreq.o +obj-$(CONFIG_ARM_TEGRA194_CPUFREQ) += tegra194-cpufreq.o obj-$(CONFIG_ARM_TI_CPUFREQ) += ti-cpufreq.o obj-$(CONFIG_ARM_VEXPRESS_SPC_CPUFREQ) += vexpress-spc-cpufreq.o
drivers/cpufreq/tegra194-cpufreq.c new file +412 -0
412 lines not on this page · raw message
Signature · 1 line
2.7.4
Re: [TEGRA194_CPUFREQ Patch v2 2/3] cpufreq: Add Tegra194 cpufreq driver
04.04.2020 22:29, Sumit Gupta пишет:
...
Quoted 43 lines
drivers/cpufreq/tegra194-cpufreq.c new file +43
-0+static void tegra_read_counters (struct work_struct *work) +{ +struct read_counters_work *read_counters_work; +struct tegra_cpu_ctr *c; +u64 val; + +/* +* ref_clk_counter(32 bit counter) runs on constant clk, +* pll_p(408MHz). +* It will take = 2 ^ 32 / 408 MHz to overflow ref clk counter +* = 10526880 usec = 10.527 sec to overflow +* +* Like wise core_clk_counter(32 bit counter) runs on core clock. +* It's synchronized to crab_clk (cpu_crab_clk) which runs at +* freq of cluster. Assuming max cluster clock ~2000MHz, +* It will take = 2 ^ 32 / 2000 MHz to overflow core clk counter +* = ~2.147 sec to overflow +*/ + read_counters_work = container_of(work, struct read_counters_work, + work); + c = &read_counters_work->c; + + val =read_freq_feedback (); + c->last_refclk_cnt =lower_32_bits (val); + c->last_coreclk_cnt =upper_32_bits (val); +udelay (c->delay); + val =read_freq_feedback (); + c->refclk_cnt =lower_32_bits (val); + c->coreclk_cnt =upper_32_bits (val); +} + +/* +* Return instantaneous cpu speed +* Instantaneous freq is calculated as - +* -Takes sample on every query of getting the freq. +* - Read core and ref clock counters; +* - Delay for X us +* - Read above cycle counters again +* - Calculates freq by subtracting current and previous counters +* divided by the delay time or eqv. of ref_clk_counter in delta time +* - Return Kcycles/second, freq in KHz +* +* delta time period = x sec
drivers/cpufreq/tegra194-cpufreq.c line 143
Quoted 10 lines
drivers/cpufreq/tegra194-cpufreq.c new file +8
-0+* = delta ref_clk_counter / (408 * 10^6) sec +* freq in Hz = cycles/sec +* = (delta cycles / x sec +* = (delta cycles * 408 * 10^6) / delta ref_clk_counter +* in KHz = (delta cycles * 408 * 10^3) / delta ref_clk_counter +* +* @cpu - logical cpu whose freq to be updated +* Returns freq in KHz on success, 0 if cpu is offline
I don't see any checks in the code about whether CPU is offline.
Googling for "queue_work_on offline cpu" suggests that this function should hang.
Quoted 36 lines
+ */
drivers/cpufreq/tegra194-cpufreq.c new file +35
-0+static unsigned int tegra194_get_speed_common (u32 cpu,u32 delay) +{ +struct read_counters_work read_counters_work; +struct tegra_cpu_ctr c; +u32 delta_refcnt; +u32 delta_ccnt; +u32 rate_mhz; + + read_counters_work.c.cpu = cpu; + read_counters_work.c.delay = delay; +INIT_WORK_ONSTACK (&read_counters_work.work, tegra_read_counters); +queue_work_on (cpu, read_counters_wq, &read_counters_work.work); +flush_work (&read_counters_work.work); + c = read_counters_work.c; + +if (c.coreclk_cnt < c.last_coreclk_cnt) + delta_ccnt = c.coreclk_cnt + (MAX_CNT - c.last_coreclk_cnt); +else + delta_ccnt = c.coreclk_cnt - c.last_coreclk_cnt; +if (!delta_ccnt) +return 0 ; + +/* ref clock is 32 bits */ +if (c.refclk_cnt < c.last_refclk_cnt) + delta_refcnt = c.refclk_cnt + (MAX_CNT - c.last_refclk_cnt); +else + delta_refcnt = c.refclk_cnt - c.last_refclk_cnt; +if (!delta_refcnt) { +pr_debug ("cpufreq: %d is idle, delta_refcnt: 0\n" , cpu); +return 0 ; + } + rate_mhz = ((unsigned long )(delta_ccnt *REF_CLK_MHZ )) / delta_refcnt; + +return (rate_mhz *KHZ );/* in KHz */ +}
Re: [TEGRA194_CPUFREQ Patch v2 2/3] cpufreq: Add Tegra194 cpufreq driver
Quoted 57 lines · Dmitry Osipenko
External email: Use caution opening links or attachments
04.04.2020 22:29, Sumit Gupta пишет:
...Quoted 50 lines
drivers/cpufreq/tegra194-cpufreq.c new file +50
-0+static void tegra_read_counters (struct work_struct *work) +{ +struct read_counters_work *read_counters_work; +struct tegra_cpu_ctr *c; +u64 val; + +/* +* ref_clk_counter(32 bit counter) runs on constant clk, +* pll_p(408MHz). +* It will take = 2 ^ 32 / 408 MHz to overflow ref clk counter +* = 10526880 usec = 10.527 sec to overflow +* +* Like wise core_clk_counter(32 bit counter) runs on core clock. +* It's synchronized to crab_clk (cpu_crab_clk) which runs at +* freq of cluster. Assuming max cluster clock ~2000MHz, +* It will take = 2 ^ 32 / 2000 MHz to overflow core clk counter +* = ~2.147 sec to overflow +*/ + read_counters_work = container_of(work, struct read_counters_work, + work); + c = &read_counters_work->c; + + val =read_freq_feedback (); + c->last_refclk_cnt =lower_32_bits (val); + c->last_coreclk_cnt =upper_32_bits (val); +udelay (c->delay); + val =read_freq_feedback (); + c->refclk_cnt =lower_32_bits (val); + c->coreclk_cnt =upper_32_bits (val); +} + +/* +* Return instantaneous cpu speed +* Instantaneous freq is calculated as - +* -Takes sample on every query of getting the freq. +* - Read core and ref clock counters; +* - Delay for X us +* - Read above cycle counters again +* - Calculates freq by subtracting current and previous counters +* divided by the delay time or eqv. of ref_clk_counter in delta time +* - Return Kcycles/second, freq in KHz +* +* delta time period = x sec +* = delta ref_clk_counter / (408 * 10^6) sec +* freq in Hz = cycles/sec +* = (delta cycles / x sec +* = (delta cycles * 408 * 10^6) / delta ref_clk_counter +* in KHz = (delta cycles * 408 * 10^3) / delta ref_clk_counter +* +* @cpu - logical cpu whose freq to be updated
Quoted 7 lines
Quoted 1 line
+ * Returns freq in KHz on success, 0 if cpu is offline
I don't see any checks in the code about whether CPU is offline.
Googling for "
queue_work_onoffline cpu" suggests that this function should hang.
Tried this and didn't get crash or hang.show_cpuinfo_cur_freq() returns "<unknown>" value on reading frequency from a cluster having both it's cores offline. If only one cpu is offline, then frequency of other online cpu which is managing the policy of that cluster is returned. Have still added below check as guard in get|set() freq calls.
if (!cpu_online(cpu)) return -EINVAL;
Thankyou for the input.
Quoted 37 lines
Quoted 36 lines
+ */
drivers/cpufreq/tegra194-cpufreq.c new file +35
-0+static unsigned int tegra194_get_speed_common (u32 cpu,u32 delay) +{ +struct read_counters_work read_counters_work; +struct tegra_cpu_ctr c; +u32 delta_refcnt; +u32 delta_ccnt; +u32 rate_mhz; + + read_counters_work.c.cpu = cpu; + read_counters_work.c.delay = delay; +INIT_WORK_ONSTACK (&read_counters_work.work, tegra_read_counters); +queue_work_on (cpu, read_counters_wq, &read_counters_work.work); +flush_work (&read_counters_work.work); + c = read_counters_work.c; + +if (c.coreclk_cnt < c.last_coreclk_cnt) + delta_ccnt = c.coreclk_cnt + (MAX_CNT - c.last_coreclk_cnt); +else + delta_ccnt = c.coreclk_cnt - c.last_coreclk_cnt; +if (!delta_ccnt) +return 0 ; + +/* ref clock is 32 bits */ +if (c.refclk_cnt < c.last_refclk_cnt) + delta_refcnt = c.refclk_cnt + (MAX_CNT - c.last_refclk_cnt); +else + delta_refcnt = c.refclk_cnt - c.last_refclk_cnt; +if (!delta_refcnt) { +pr_debug ("cpufreq: %d is idle, delta_refcnt: 0\n" , cpu); +return 0 ; + } + rate_mhz = ((unsigned long )(delta_ccnt *REF_CLK_MHZ )) / delta_refcnt; + +return (rate_mhz *KHZ );/* in KHz */ +}
Re: [TEGRA194_CPUFREQ Patch v2 2/3] cpufreq: Add Tegra194 cpufreq driver
07.04.2020 21:55, sumitg пишет:
...
Quoted 7 lines
Quoted 7 lines
Quoted 1 line
+ * Returns freq in KHz on success, 0 if cpu is offline
I don't see any checks in the code about whether CPU is offline.
Googling for "
queue_work_onoffline cpu" suggests that this function should hang.
Quoted 9 lines
Tried this and didn't get crash or hang.
show_cpuinfo_cur_freq()returns "<unknown>" value on reading frequency from a cluster having both it's cores offline.
If only one cpu is offline, then frequency of other online cpu which is managing the policy of that cluster is returned.
Have still added below check as guard in get|set() freq calls. if (!cpu_online(cpu))
return-EINVAL;
Thankyou for the input.
If CPUFreq core takes care of taking into account the offline CPU, then the check isn't needed. It also wouldn't be enough if there was a problem here.
Re: [TEGRA194_CPUFREQ Patch v2 2/3] cpufreq: Add Tegra194 cpufreq driver
In reply to Sumit Gupta04.04.2020 22:29, Sumit Gupta пишет:
...
drivers/cpufreq/tegra194-cpufreq.c line 101
Quoted 9 lines
drivers/cpufreq/tegra194-cpufreq.c new file +9
-0+static void tegra_read_counters (struct work_struct *work) +{ +struct read_counters_work *read_counters_work; +struct tegra_cpu_ctr *c; +u64 val; + +/* +* ref_clk_counter(32 bit counter) runs on constant clk, +* pll_p(408MHz).
Is changing PLLP rate really impossible on T194? What makes you say that it runs on a fixed 408MHz?
Re: [TEGRA194_CPUFREQ Patch v2 2/3] cpufreq: Add Tegra194 cpufreq driver
Quoted 5 lines · Dmitry Osipenko
External email: Use caution opening links or attachments
04.04.2020 22:29, Sumit Gupta пишет:
...
Quoted 13 lines
drivers/cpufreq/tegra194-cpufreq.c line 101
Quoted 9 lines
drivers/cpufreq/tegra194-cpufreq.c new file +9
-0+static void tegra_read_counters (struct work_struct *work) +{ +struct read_counters_work *read_counters_work; +struct tegra_cpu_ctr *c; +u64 val; + +/* +* ref_clk_counter(32 bit counter) runs on constant clk, +* pll_p(408MHz). Is changing PLLP rate really impossible on T194? What makes you say that it runs on a fixed 408MHz?
Pasting below from TRM.
Register "NVFREQ_FEEDBACK_EL1":
....
[31:0] PLLP counter: This counter counts at a fixed frequency (408 MHz).
PATCH v2 3/3 arm64: defconfig: Enable CONFIG_ARM_TEGRA194_CPUFREQ
In reply to Sumit GuptaEnable Tegra194 CPU frequency scaling support by default.
--- arch/arm64/configs/defconfig | 1 + 1 file changed, 1 insertion(+)
arch/arm64/configs/defconfig +1 -0
@@ -87,6 +87,7 @@ CONFIG_ARM_SCPI_CPUFREQ=y CONFIG_ARM_IMX_CPUFREQ_DT=m CONFIG_ARM_RASPBERRYPI_CPUFREQ=m CONFIG_ARM_TEGRA186_CPUFREQ=y +CONFIG_ARM_TEGRA194_CPUFREQ=y CONFIG_ARM_SCPI_PROTOCOL=y CONFIG_RASPBERRYPI_FIRMWARE=y CONFIG_INTEL_STRATIX10_SERVICE=y
Signature · 1 line
2.7.4
Viresh Kumar
maintainerQuoted 7 lines · Sumit Gupta
The patch series adds cpufreq driver for Tegra194 SOC.
v1[1] -> v2:
- Removecpufreq_lockmutex fromtegra194_cpufreq_set_target[Viresh].
- RemoveCPUFREQ_ASYNC_NOTIFICATIONflag [Viresh].
- Remove redundant _begin|end() call fromtegra194_cpufreq_set_target.
- Renameopp_tabletofreq_table[Viresh].
Have we concluded the earlier discussion already ? I posted some questions where I had doubts and you just answered them and posted a new version. Please wait for the reviewers to have a chance to reply to them. Your new version may be okay, but still we can avoid another set of patches which may be wrong.
Signature · 1 line
viresh
Quoted 12 lines · Viresh Kumar
External email: Use caution opening links or attachments
Quoted 7 lines · Sumit Gupta
The patch series adds cpufreq driver for Tegra194 SOC.
v1[1] -> v2:
- Removecpufreq_lockmutex fromtegra194_cpufreq_set_target[Viresh].
- RemoveCPUFREQ_ASYNC_NOTIFICATIONflag [Viresh].
- Remove redundant _begin|end() call fromtegra194_cpufreq_set_target.
- Renameopp_tabletofreq_table[Viresh].
Quoted 9 lines
Have we concluded the earlier discussion already ? I posted some questions where I had doubts and you just answered them and posted a new version. Please wait for the reviewers to have a chance to reply to them. Your new version may be okay, but still we can avoid another set of patches which may be wrong.
--
viresh
Sorry for that. I will wait for ongoing review to conclude before posting new version. Thankyou for the inputs.