Skip to contentSkip to conversation

memory: tegra: Deduplicate rate request management code

PATCH Superseded Mikko Perttunen 2 participants 4 messages Apr 17 – Apr 30

Subsystems (2)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

PATCH v2 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, and add kerneldoc comments.

Based on code from the tegra20-emc driver.

---
v2:
- Add kerneldoc comments.
- Add note about source of the code to commit message.
- Drop the Tegra114 EMC series as dependency. Rebase on v7.0.

---
 drivers/memory/tegra/Kconfig            |   6 ++
 drivers/memory/tegra/Makefile           |   1 +
 drivers/memory/tegra/tegra-emc-common.c | 139 ++++++++++++++++++++++++++++++++
 drivers/memory/tegra/tegra-emc-common.h |  45 +++++++++++
 drivers/memory/tegra/tegra124-emc.c     | 107 ++----------------------
 drivers/memory/tegra/tegra20-emc.c      | 110 ++-----------------------
 drivers/memory/tegra/tegra30-emc.c      | 107 ++----------------------
 7 files changed, 210 insertions(+), 305 deletions(-)
drivers/memory/tegra/Kconfig +6 -0
index fc5a27791826..92671f9df672 100644
@@ -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 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.
@@ -61,4 +64,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
index 6334601e6120..75ebb4cb4f29 100644
@@ -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_TEGRA124_EMC) += tegra124-emc.o
drivers/memory/tegra/tegra-emc-common.c new file +139 -0

139 lines not on this page · raw message

drivers/memory/tegra/tegra-emc-common.h new file +45 -0

45 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: 028ef9c96e96197026887c0f092424679298aae8
change-id: 20260203-memory-refactor-54a6089a8dcf

#1 lore raw

drivers/memory/tegra/tegra-emc-common.h line 30

Quoted 9 lines · Mikko Perttunen
drivers/memory/tegra/tegra-emc-common.h new file +9 -0
+
+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;

You introduced a new checkpatch warning. Wasn't there before. Probably the old comment feels to obvious in this context, so it should be extended to be meaningful, e.g. what data structure, which members, which code paths etc.

Best regards,
Krzysztof

#2 lore raw
Quoted 15 lines · Krzysztof Kozlowski

drivers/memory/tegra/tegra-emc-common.h line 30

Quoted 9 lines · Mikko Perttunen
drivers/memory/tegra/tegra-emc-common.h new file +9 -0
+
+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;

You introduced a new checkpatch warning. Wasn't there before. Probably the old comment feels to obvious in this context, so it should be extended to be meaningful, e.g. what data structure, which members, which code paths etc.

On my system, it's just a 'CHECK', not a 'WARNING', so I thought it not necessary to address in this relatively simple circumstance.

However, I do agree it's best to err on the side of verbosity when dealing with locking, so I'll add a description for v3.

Mikko

Quoted 4 lines

Best regards,
Krzysztof

#3 lore raw
Quoted 17 lines · Mikko Perttunen
Quoted 15 lines · Krzysztof Kozlowski

drivers/memory/tegra/tegra-emc-common.h line 30

Quoted 9 lines · Mikko Perttunen
drivers/memory/tegra/tegra-emc-common.h new file +9 -0
+
+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;

You introduced a new checkpatch warning. Wasn't there before. Probably the old comment feels to obvious in this context, so it should be extended to be meaningful, e.g. what data structure, which members, which code paths etc.

Quoted 5 lines

On my system, it's just a 'CHECK', not a 'WARNING', so I thought it not necessary to address in this relatively simple circumstance.

However, I do agree it's best to err on the side of verbosity when dealing with locking, so I'll add a description for v3.

It's still a warning both in CI and maintainer commit tools. The meaning of "CHECK" means only amount of false positives, so you are supposed to check it. And if you checked it you would see it is valid report.

Best regards,
Krzysztof