memory: tegra: Deduplicate rate request management code
Subsystems (2)
PATCH 1/1 memory: tegra: Deduplicate rate request management code
As is, the EMC drivers for each 32-bit platform contain almost identical duplicated code for aggregating rate requests. Move this code out to a shared tegra-emc-common file to reduce duplication.
---
This patch is on top of 'memory: tegra: Add Tegra114 EMC driver'
--- drivers/memory/tegra/Kconfig | 7 ++ drivers/memory/tegra/Makefile | 1 + drivers/memory/tegra/tegra-emc-common.c | 96 ++++++++++++++++++++++++++++ drivers/memory/tegra/tegra-emc-common.h | 38 +++++++++++ drivers/memory/tegra/tegra114-emc.c | 107 ++----------------------------- drivers/memory/tegra/tegra124-emc.c | 107 ++----------------------------- drivers/memory/tegra/tegra20-emc.c | 110 ++------------------------------ drivers/memory/tegra/tegra30-emc.c | 107 ++----------------------------- 8 files changed, 167 insertions(+), 406 deletions(-)
drivers/memory/tegra/Kconfig +7 -0
@@ -17,6 +17,7 @@ config TEGRA20_EMC select DEVFREQ_GOV_SIMPLE_ONDEMAND select PM_DEVFREQ select DDR + select TEGRA_EMC_COMMON help This driver is for the External Memory Controller (EMC) found on Tegra20 chips. The EMC controls the external DRAM on the board.
@@ -29,6 +30,7 @@ config TEGRA30_EMC depends on ARCH_TEGRA_3x_SOC || COMPILE_TEST select PM_OPP select DDR + select TEGRA_EMC_COMMON help This driver is for the External Memory Controller (EMC) found on Tegra30 chips. The EMC controls the external DRAM on the board.
@@ -41,6 +43,7 @@ config TEGRA114_EMC depends on ARCH_TEGRA_114_SOC || COMPILE_TEST select TEGRA124_CLK_EMC if ARCH_TEGRA select PM_OPP + select TEGRA_EMC_COMMON help This driver is for the External Memory Controller (EMC) found on Tegra114 chips. The EMC controls the external DRAM on the board.
@@ -53,6 +56,7 @@ config TEGRA124_EMC depends on ARCH_TEGRA_124_SOC || COMPILE_TEST select TEGRA124_CLK_EMC if ARCH_TEGRA select PM_OPP + select TEGRA_EMC_COMMON help This driver is for the External Memory Controller (EMC) found on Tegra124 chips. The EMC controls the external DRAM on the board.
@@ -73,4 +77,7 @@ config TEGRA210_EMC This driver is required to change memory timings / clock rate for external memory. +config TEGRA_EMC_COMMON + tristate + endif
drivers/memory/tegra/Makefile +1 -0
@@ -14,6 +14,7 @@ tegra-mc-$(CONFIG_ARCH_TEGRA_264_SOC) += tegra186.o tegra264.o obj-$(CONFIG_TEGRA_MC) += tegra-mc.o +obj-$(CONFIG_TEGRA_EMC_COMMON) += tegra-emc-common.o obj-$(CONFIG_TEGRA20_EMC) += tegra20-emc.o obj-$(CONFIG_TEGRA30_EMC) += tegra30-emc.o obj-$(CONFIG_TEGRA114_EMC) += tegra114-emc.o
drivers/memory/tegra/tegra-emc-common.c new file +96 -0
96 lines not on this page · raw message
drivers/memory/tegra/tegra-emc-common.h new file +38 -0
@@ -0,0 +1,38 @@ +/* SPDX-License-Identifier: GPL-2.0 */ + +#ifndef TEGRA_EMC_COMMON_H +#define TEGRA_EMC_COMMON_H + +#include <linux/device.h> +#include <linux/mutex.h> + +enum tegra_emc_rate_request_type { +TEGRA_EMC_RATE_DEVFREQ , +TEGRA_EMC_RATE_DEBUG , +TEGRA_EMC_RATE_ICC , +TEGRA_EMC_RATE_TYPE_MAX , +}; + +struct tegra_emc_rate_request { +unsigned long min_rate; +unsigned long max_rate; +}; + +struct tegra_emc_rate_requests { +struct tegra_emc_rate_request requested_rate[TEGRA_EMC_RATE_TYPE_MAX ]; +struct mutex rate_lock; +struct device *dev; +}; + +void tegra_emc_rate_requests_init (struct tegra_emc_rate_requests *reqs, +struct device *dev); + +int tegra_emc_set_min_rate (struct tegra_emc_rate_requests *reqs, +unsigned long rate, +enum tegra_emc_rate_request_type type); + +int tegra_emc_set_max_rate (struct tegra_emc_rate_requests *reqs, +unsigned long rate, +enum tegra_emc_rate_request_type type); + +#endif /* TEGRA_EMC_COMMON_H */
drivers/memory/tegra/tegra114-emc.c +6 -101
161 lines not on this page · raw message
drivers/memory/tegra/tegra124-emc.c +6 -101
161 lines not on this page · raw message
drivers/memory/tegra/tegra20-emc.c +7 -103
170 lines not on this page · raw message
drivers/memory/tegra/tegra30-emc.c +6 -101
161 lines not on this page · raw message
---
base-commit: ed4cdcc0b03e72cfdffbff9f0ea24338517bc893
change-id: 20260203-memory-refactor-54a6089a8dcf
prerequisite-message-id: <[email protected]>
prerequisite-patch-id: d0cc6cf04447264ce099226c9157f1def25df716
prerequisite-patch-id: c57efa588876ea5cf00ea0f28f814ec818bbea58
prerequisite-patch-id: cddf792516ed7582a3cc20eb00ae7745969ff984
prerequisite-patch-id: 9e7e9d889caed5b5deeb60e03b233ffcb0f25724
prerequisite-patch-id: 90ba18fe5154b59da1c7b2db058e93c9f007854e
Krzysztof Kozlowski
maintainerQuoted 7 lines · Mikko Perttunen
As is, the EMC drivers for each 32-bit platform contain almost identical duplicated code for aggregating rate requests. Move this code out to a shared tegra-emc-common file to reduce duplication.
Signed-off-by Mikko Perttunen <[email protected]>---
This patch is on top of 'memory: tegra: Add Tegra114 EMC driver'
If that patch is not merged, then this should be reversed. First you remove duplication then you add smaller new patch. Not vice versa, where you add duplicated code just to remove it.
Quoted 73 lines
--- drivers/memory/tegra/Kconfig | 7 ++ drivers/memory/tegra/Makefile | 1 + drivers/memory/tegra/tegra-emc-common.c | 96 ++++++++++++++++++++++++++++ drivers/memory/tegra/tegra-emc-common.h | 38 +++++++++++ drivers/memory/tegra/tegra114-emc.c | 107 ++----------------------------- drivers/memory/tegra/tegra124-emc.c | 107 ++----------------------------- drivers/memory/tegra/tegra20-emc.c | 110 ++------------------------------ drivers/memory/tegra/tegra30-emc.c | 107 ++----------------------------- 8 files changed, 167 insertions(+), 406 deletions(-)drivers/memory/tegra/Kconfig +7
-0@@ -17,6 +17,7 @@ config TEGRA20_EMC select DEVFREQ_GOV_SIMPLE_ONDEMAND select PM_DEVFREQ select DDR + select TEGRA_EMC_COMMON help This driver is for the External Memory Controller (EMC) found on Tegra20 chips. The EMC controls the external DRAM on the board.@@ -29,6 +30,7 @@ config TEGRA30_EMC depends on ARCH_TEGRA_3x_SOC || COMPILE_TEST select PM_OPP select DDR + select TEGRA_EMC_COMMON help This driver is for the External Memory Controller (EMC) found on Tegra30 chips. The EMC controls the external DRAM on the board.@@ -41,6 +43,7 @@ config TEGRA114_EMC depends on ARCH_TEGRA_114_SOC || COMPILE_TEST select TEGRA124_CLK_EMC if ARCH_TEGRA select PM_OPP + select TEGRA_EMC_COMMON help This driver is for the External Memory Controller (EMC) found on Tegra114 chips. The EMC controls the external DRAM on the board.@@ -53,6 +56,7 @@ config TEGRA124_EMC depends on ARCH_TEGRA_124_SOC || COMPILE_TEST select TEGRA124_CLK_EMC if ARCH_TEGRA select PM_OPP + select TEGRA_EMC_COMMON help This driver is for the External Memory Controller (EMC) found on Tegra124 chips. The EMC controls the external DRAM on the board.@@ -73,4 +77,7 @@ config TEGRA210_EMC This driver is required to change memory timings / clock rate for external memory. +config TEGRA_EMC_COMMON + tristate + endifdrivers/memory/tegra/Makefile +1
-0@@ -14,6 +14,7 @@ tegra-mc-$(CONFIG_ARCH_TEGRA_264_SOC) += tegra186.o tegra264.o obj-$(CONFIG_TEGRA_MC) += tegra-mc.o +obj-$(CONFIG_TEGRA_EMC_COMMON) += tegra-emc-common.o obj-$(CONFIG_TEGRA20_EMC) += tegra20-emc.o obj-$(CONFIG_TEGRA30_EMC) += tegra30-emc.o obj-$(CONFIG_TEGRA114_EMC) += tegra114-emc.odrivers/memory/tegra/tegra-emc-common.c new file +0
-0
drivers/memory/tegra/tegra-emc-common.c line 1
Quoted 1 line
drivers/memory/tegra/tegra-emc-common.c new file +1
-0@@ -0,0 +1,96 @@ +// SPDX-License-Identifier: GPL-2.0
... and that's why we ask for consistent license. Code in tegra30-emc has difference license, so I assume here you copied the one matching license above. Explain in the commit msg which code you copied or on which existing code you based this.
drivers/memory/tegra/tegra-emc-common.c line 8
Quoted 7 lines
drivers/memory/tegra/tegra-emc-common.c new file +7
-0+ +#include <linux/device.h> +#include <linux/mutex.h> +#include <linux/pm_opp.h> + +#include "tegra-emc-common.h" +
All exported functions need kerneldoc.
Quoted 5 lines
drivers/memory/tegra/tegra-emc-common.c new file +5
-0+void tegra_emc_rate_requests_init (struct tegra_emc_rate_requests *reqs, +struct device *dev) +{ +unsigned int i; +
drivers/memory/tegra/tegra-emc-common.c line 23
Quoted 10 lines
drivers/memory/tegra/tegra-emc-common.c new file +10
-0+mutex_init (&reqs->rate_lock); + reqs->dev = dev; + +for (i =0 ; i <TEGRA_EMC_RATE_TYPE_MAX ; i++) { + reqs->requested_rate[i].min_rate =0 ; + reqs->requested_rate[i].max_rate =ULONG_MAX ; + } +} +EXPORT_SYMBOL_GPL (tegra_emc_rate_requests_init); +
Best regards,
Krzysztof
Quoted 5 lines · Krzysztof Kozlowski
Quoted 4 lines · Mikko Perttunen
As is, the EMC drivers for each 32-bit platform contain almost identical duplicated code for aggregating rate requests. Move this code out to a shared tegra-emc-common file to reduce duplication.
Quoted 7 lines
Quoted 3 lines
Signed-off-by Mikko Perttunen <[email protected]>---
This patch is on top of 'memory: tegra: Add Tegra114 EMC driver'If that patch is not merged, then this should be reversed. First you remove duplication then you add smaller new patch. Not vice versa, where you add duplicated code just to remove it.
The code is already duplicated multiple times before. The Tegra114 driver doesn't change the situation in any significant way. Sequencing in this way is just easier rather than disrupting that - more important - series.
Quoted 73 lines
Quoted 73 lines
--- drivers/memory/tegra/Kconfig | 7 ++ drivers/memory/tegra/Makefile | 1 + drivers/memory/tegra/tegra-emc-common.c | 96 ++++++++++++++++++++++++++++ drivers/memory/tegra/tegra-emc-common.h | 38 +++++++++++ drivers/memory/tegra/tegra114-emc.c | 107 ++----------------------------- drivers/memory/tegra/tegra124-emc.c | 107 ++----------------------------- drivers/memory/tegra/tegra20-emc.c | 110 ++------------------------------ drivers/memory/tegra/tegra30-emc.c | 107 ++----------------------------- 8 files changed, 167 insertions(+), 406 deletions(-)drivers/memory/tegra/Kconfig +7
-0@@ -17,6 +17,7 @@ config TEGRA20_EMC select DEVFREQ_GOV_SIMPLE_ONDEMAND select PM_DEVFREQ select DDR + select TEGRA_EMC_COMMON help This driver is for the External Memory Controller (EMC) found on Tegra20 chips. The EMC controls the external DRAM on the board.@@ -29,6 +30,7 @@ config TEGRA30_EMC depends on ARCH_TEGRA_3x_SOC || COMPILE_TEST select PM_OPP select DDR + select TEGRA_EMC_COMMON help This driver is for the External Memory Controller (EMC) found on Tegra30 chips. The EMC controls the external DRAM on the board.@@ -41,6 +43,7 @@ config TEGRA114_EMC depends on ARCH_TEGRA_114_SOC || COMPILE_TEST select TEGRA124_CLK_EMC if ARCH_TEGRA select PM_OPP + select TEGRA_EMC_COMMON help This driver is for the External Memory Controller (EMC) found on Tegra114 chips. The EMC controls the external DRAM on the board.@@ -53,6 +56,7 @@ config TEGRA124_EMC depends on ARCH_TEGRA_124_SOC || COMPILE_TEST select TEGRA124_CLK_EMC if ARCH_TEGRA select PM_OPP + select TEGRA_EMC_COMMON help This driver is for the External Memory Controller (EMC) found on Tegra124 chips. The EMC controls the external DRAM on the board.@@ -73,4 +77,7 @@ config TEGRA210_EMC This driver is required to change memory timings / clock rate for external memory. +config TEGRA_EMC_COMMON + tristate + endifdrivers/memory/tegra/Makefile +1
-0@@ -14,6 +14,7 @@ tegra-mc-$(CONFIG_ARCH_TEGRA_264_SOC) += tegra186.o tegra264.o obj-$(CONFIG_TEGRA_MC) += tegra-mc.o +obj-$(CONFIG_TEGRA_EMC_COMMON) += tegra-emc-common.o obj-$(CONFIG_TEGRA20_EMC) += tegra20-emc.o obj-$(CONFIG_TEGRA30_EMC) += tegra30-emc.o obj-$(CONFIG_TEGRA114_EMC) += tegra114-emc.odrivers/memory/tegra/tegra-emc-common.c new file +0
-0
Quoted 8 lines
drivers/memory/tegra/tegra-emc-common.c line 1
Quoted 2 lines
drivers/memory/tegra/tegra-emc-common.c new file +1
-0@@ -0,0 +1,96 @@ +// SPDX-License-Identifier: GPL-2.0 ... and that's why we ask for consistent license. Code in tegra30-emc has difference license, so I assume here you copied the one matching license above. Explain in the commit msg which code you copied or on which existing code you based this.
Ok.
Quoted 10 lines
drivers/memory/tegra/tegra-emc-common.c line 8
Quoted 8 lines
drivers/memory/tegra/tegra-emc-common.c new file +7
-0+ +#include <linux/device.h> +#include <linux/mutex.h> +#include <linux/pm_opp.h> + +#include "tegra-emc-common.h" +All exported functions need kerneldoc.
Ok.
Quoted 20 lines
Quoted 6 lines
drivers/memory/tegra/tegra-emc-common.c new file +5
-0+void tegra_emc_rate_requests_init (struct tegra_emc_rate_requests *reqs, +struct device *dev) +{ +unsigned int i; +drivers/memory/tegra/tegra-emc-common.c line 23
Quoted 10 lines
drivers/memory/tegra/tegra-emc-common.c new file +10
-0+mutex_init (&reqs->rate_lock); + reqs->dev = dev; + +for (i =0 ; i <TEGRA_EMC_RATE_TYPE_MAX ; i++) { + reqs->requested_rate[i].min_rate =0 ; + reqs->requested_rate[i].max_rate =ULONG_MAX ; + } +} +EXPORT_SYMBOL_GPL (tegra_emc_rate_requests_init); +Best regards,
Krzysztof
Krzysztof Kozlowski
maintainerQuoted 10 lines · Mikko Perttunen
Quoted 9 lines · Krzysztof Kozlowski
Quoted 7 lines · Mikko Perttunen
As is, the EMC drivers for each 32-bit platform contain almost identical duplicated code for aggregating rate requests. Move this code out to a shared tegra-emc-common file to reduce duplication.
Signed-off-by Mikko Perttunen <[email protected]>---
This patch is on top of 'memory: tegra: Add Tegra114 EMC driver'
Quoted 5 lines
Quoted 3 lines
If that patch is not merged, then this should be reversed. First you remove duplication then you add smaller new patch. Not vice versa, where you add duplicated code just to remove it.
The code is already duplicated multiple times before.
That's the meaning of duplication... and adding more duplicated code is obviously not proper choice.
Quoted 1 line
The Tegra114 driver doesn't change the situation in any significant way. Sequencing in this way is just easier rather than disrupting that - more important - series.
Fix your email so message will be properly wrapped.
Also in the future, please use normal ways to express dependencies - by lore links or b4 deps.
Best regards,
Krzysztof
Quoted 11 lines · Krzysztof Kozlowski
Quoted 10 lines · Mikko Perttunen
Quoted 9 lines · Krzysztof Kozlowski
Quoted 7 lines · Mikko Perttunen
As is, the EMC drivers for each 32-bit platform contain almost identical duplicated code for aggregating rate requests. Move this code out to a shared tegra-emc-common file to reduce duplication.
Signed-off-by Mikko Perttunen <[email protected]>---
This patch is on top of 'memory: tegra: Add Tegra114 EMC driver'
Quoted 8 lines
Quoted 5 lines
Quoted 3 lines
If that patch is not merged, then this should be reversed. First you remove duplication then you add smaller new patch. Not vice versa, where you add duplicated code just to remove it.
The code is already duplicated multiple times before.
That's the meaning of duplication... and adding more duplicated code is obviously not proper choice.
I understand you want the cleanup to be done first, and that's fine and you decide -- and more duplicated code is obviously not good, but I don't think the order these series should go in is obvious. I'm only saying that because to me your wording reads as accusing me of making obviously bad arguments, and it's not making my day better.
Quoted 5 lines
Quoted 4 lines
The Tegra114 driver doesn't change the situation in any significant way. Sequencing in this way is just easier rather than disrupting that - more important - series.
Fix your email so message will be properly wrapped.
It seems some update must have overridden my email config. I think I have fixed it.
Quoted 3 lines
Also in the future, please use normal ways to express dependencies - by lore links or b4 deps.
I did use b4 deps.
Quoted 4 lines
Best regards,
Krzysztof
Cheers,
Mikko