Skip to contentSkip to conversation

Add EMC scaling support for Tegra210

PATCH Applied Thierry Reding 3 participants 60 messages Apr 9, 2020 – Apr 16, 2020

Subsystems (6)
lore
Share & tools
lore
#0 lore raw

v6 cover Add EMC scaling support for Tegra210

From: Thierry Reding <[email protected]>

This series introduces the EMC clock scaling support for Tegra210. The EMC table of supported frequencies is passed to the kernel via a device tree reserved memory region.

Joseph posted the v4 of this series[0] about a year ago. I've dusted it off a bit and tried to address all of the comments that Dmitry had made in response to v4.

Changes in v6:
- add support for derated tables which are used under high temperatures
- add patches to support memory-region-names property in DT
- address review comments

Changes in v5:
- major rework to split this into a clk driver and an EMC driver
- refactored some code to remove duplication and improve readability
- removed some unused code and variables

Thierry

[0]: https://lore.kernel.org/linux-arm-kernel/20190529082139.5581-1-josephl-DDmLM1+adcrQT0dZR+AlfA@public.gmane.org/

Joseph Lo (8):
clk: tegra: Add PLLP_UD and PLLMB_UD for Tegra210
clk: tegra: Export functions for EMC clock scaling
clk: tegra: Implement Tegra210 EMC clock
dt-bindings: memory: tegra: Add external memory controller binding for

    Tegra210

memory: tegra: Add EMC scaling support code for Tegra210
memory: tegra: Add EMC scaling sequence code for Tegra210
arm64: tegra: Add external memory controller node for Tegra210
clk: tegra: Remove the old emc_mux clock for Tegra210

Thierry Reding (6):
dt-bindings: reserved-memory: Introduce memory-region-names
of: reserved-memory: Support lookup of regions by name
of: reserved-memory: Support multiple regions per device
clk: tegra: Rename Tegra124 EMC clock source file
memory: tegra: Support derated timings on Tegra210
arm64: tegra: Hook up EMC cooling device

 .../nvidia,tegra210-emc.yaml                  |   82 +
 .../reserved-memory/reserved-memory.txt       |    2 +
 arch/arm64/boot/dts/nvidia/tegra210.dtsi      |   37 +-
 drivers/clk/tegra/Makefile                    |    3 +-
 .../tegra/{clk-emc.c => clk-tegra124-emc.c}   |    0
 drivers/clk/tegra/clk-tegra210-emc.c          |  369 +++
 drivers/clk/tegra/clk-tegra210.c              |   87 +-
 drivers/clk/tegra/clk.h                       |    3 +
 drivers/memory/tegra/Kconfig                  |   14 +
 drivers/memory/tegra/Makefile                 |    4 +
 drivers/memory/tegra/mc.h                     |    1 +
 drivers/memory/tegra/tegra210-emc-cc-r21021.c | 1744 ++++++++++++++
 drivers/memory/tegra/tegra210-emc-core.c      | 2099 +++++++++++++++++
 drivers/memory/tegra/tegra210-emc-table.c     |   94 +
 drivers/memory/tegra/tegra210-emc.h           | 1023 ++++++++
 drivers/memory/tegra/tegra210-mc.h            |   49 +
 drivers/of/of_reserved_mem.c                  |   41 +-
 include/dt-bindings/clock/tegra210-car.h      |    4 +-
 include/linux/clk/tegra.h                     |   27 +
 include/linux/of_reserved_mem.h               |   11 +
 20 files changed, 5656 insertions(+), 38 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/memory-controllers/nvidia,tegra210-emc.yaml
 rename drivers/clk/tegra/{clk-emc.c => clk-tegra124-emc.c} (100%)
 create mode 100644 drivers/clk/tegra/clk-tegra210-emc.c
 create mode 100644 drivers/memory/tegra/tegra210-emc-cc-r21021.c
 create mode 100644 drivers/memory/tegra/tegra210-emc-core.c
 create mode 100644 drivers/memory/tegra/tegra210-emc-table.c
 create mode 100644 drivers/memory/tegra/tegra210-emc.h
 create mode 100644 drivers/memory/tegra/tegra210-mc.h
Signature · 1 line
2.24.1
#1 lore raw

PATCH v6 1/14 dt-bindings: reserved-memory: Introduce memory-region-names

From: Thierry Reding <[email protected]>

In order to make the reserved-memory bindings more consistent with other existing bindings, add a memory-region-names property that contains an array of strings that name the entries of the memory-region property and allows these regions to be looked up by name.

---
Changes in v6:
- drop addition of memory-regions alias

 .../devicetree/bindings/reserved-memory/reserved-memory.txt     | 2 ++
 1 file changed, 2 insertions(+)
Documentation/devicetree/bindings/reserved-memory/reserved-memory.txt +2 -0
index bac4afa3b197..4dd20de6977f 100644
@@ -77,6 +77,8 @@ Regions in the /reserved-memory node may be referenced by other device
 nodes by adding a memory-region property to the device node.
 
 memory-region (optional) - phandle, specifier pairs to children of /reserved-memory
+memory-region-names (optional) - a list of names, one for each corresponding
+  entry in the memory-region property
 
 Example
 -------
Signature · 1 line
2.24.1
maintainer Applied
#2 lore raw

Re: [PATCH v6 01/14] dt-bindings: reserved-memory: Introduce memory-region-names

Quoted 7 lines · Thierry Reding

From: Thierry Reding <[email protected]>

In order to make the reserved-memory bindings more consistent with other existing bindings, add a memory-region-names property that contains an array of strings that name the entries of the memory-region property and allows these regions to be looked up by name.

Quoted 8 lines

---
Changes in v6:
- drop addition of memory-regions alias

 .../devicetree/bindings/reserved-memory/reserved-memory.txt     | 2 ++
 1 file changed, 2 insertions(+)

Applied, thanks.

Rob

#3 lore raw

PATCH v6 2/14 of: reserved-memory: Support lookup of regions by name

In reply to Thierry Reding

From: Thierry Reding <[email protected]>

Add support for looking up memory regions by name. This looks up the given name in the newly introduced memory-region-names property and returns the memory region at the corresponding index in the memory- region(s) property.

---
 drivers/of/of_reserved_mem.c    | 19 +++++++++++++++++++
 include/linux/of_reserved_mem.h | 11 +++++++++++
 2 files changed, 30 insertions(+)
drivers/of/of_reserved_mem.c +19 -0
index 1a84bc0d5fa8..ed2ff6f01d32 100644
@@ -357,6 +357,25 @@ int of_reserved_mem_device_init_by_idx(struct device *dev,
 }
 EXPORT_SYMBOL_GPL(of_reserved_mem_device_init_by_idx);
 
+/**
+ * of_reserved_mem_device_init_by_name() - assign named reserved memory region
+ *					   to given device
+ * @dev: pointer to the device to configure
+ * @np: pointer to the device node with 'memory-region' property
+ * @name: name of the selected memory region
+ *
+ * Returns: 0 on success or a negative error-code on failure.
+ */
+int of_reserved_mem_device_init_by_name(struct device *dev,
+					struct device_node *np,
+					const char *name)
+{
+	int idx = of_property_match_string(np, "memory-region-names", name);
+
+	return of_reserved_mem_device_init_by_idx(dev, np, idx);
+}
+EXPORT_SYMBOL_GPL(of_reserved_mem_device_init_by_name);
+
 /**
  * of_reserved_mem_device_release() - release reserved memory device structures
  * @dev:	Pointer to the device to deconfigure
include/linux/of_reserved_mem.h +11 -0
index 60f541912ccf..a1b427ac291b 100644
@@ -33,6 +33,9 @@ typedef int (*reservedmem_of_init_fn)(struct reserved_mem *rmem);
 
 int of_reserved_mem_device_init_by_idx(struct device *dev,
 				       struct device_node *np, int idx);
+int of_reserved_mem_device_init_by_name(struct device *dev,
+					struct device_node *np,
+					const char *name);
 void of_reserved_mem_device_release(struct device *dev);
 
 void fdt_init_reserved_mem(void);
@@ -45,6 +48,14 @@ static inline int of_reserved_mem_device_init_by_idx(struct device *dev,
 {
 	return -ENOSYS;
 }
+
+static inline int of_reserved_mem_device_init_by_name(struct device *dev,
+						      struct device_node *np,
+						      const char *name)
+{
+	return -ENOSYS;
+}
+
 static inline void of_reserved_mem_device_release(struct device *pdev) { }
 
 static inline void fdt_init_reserved_mem(void) { }
Signature · 1 line
2.24.1
maintainer Reviewed-by on v6 2/14
#4 lore raw

Re: [PATCH v6 02/14] of: reserved-memory: Support lookup of regions by name

Quoted 7 lines · Thierry Reding

From: Thierry Reding <[email protected]>

Add support for looking up memory regions by name. This looks up the given name in the newly introduced memory-region-names property and returns the memory region at the corresponding index in the memory- region(s) property.

Quoted 6 lines
---
 drivers/of/of_reserved_mem.c    | 19 +++++++++++++++++++
 include/linux/of_reserved_mem.h | 11 +++++++++++
 2 files changed, 30 insertions(+)
#5 lore raw

Re: [PATCH v6 02/14] of: reserved-memory: Support lookup of regions by name

Quoted 8 lines · Rob Herring
Quoted 7 lines · Thierry Reding

From: Thierry Reding <[email protected]>

Add support for looking up memory regions by name. This looks up the given name in the newly introduced memory-region-names property and returns the memory region at the corresponding index in the memory- region(s) property.

Quoted 8 lines
Quoted 6 lines
---
 drivers/of/of_reserved_mem.c    | 19 +++++++++++++++++++
 include/linux/of_reserved_mem.h | 11 +++++++++++
 2 files changed, 30 insertions(+)

Hi Rob,

thanks for the review. Do you want me to apply this and patch 3/14 to a stable branch and send to you as a pull request? That way I could use that same branch to resolve the dependency in the Tegra tree for the memory controller driver patches.

Thierry

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

maintainer
#6 lore raw

Re: [PATCH v6 02/14] of: reserved-memory: Support lookup of regions by name

Quoted 17 lines · Thierry Reding
Quoted 15 lines · Rob Herring
Quoted 13 lines · Thierry Reding

From: Thierry Reding <[email protected]>

Add support for looking up memory regions by name. This looks up the given name in the newly introduced memory-region-names property and returns the memory region at the corresponding index in the memory- region(s) property.

---
 drivers/of/of_reserved_mem.c    | 19 +++++++++++++++++++
 include/linux/of_reserved_mem.h | 11 +++++++++++
 2 files changed, 30 insertions(+)
Quoted 8 lines
Quoted 1 line

Hi Rob,

thanks for the review. Do you want me to apply this and patch 3/14 to a stable branch and send to you as a pull request? That way I could use that same branch to resolve the dependency in the Tegra tree for the memory controller driver patches.

I think it is fine for you to just take the patches.

Rob

#7 lore raw

PATCH v6 3/14 of: reserved-memory: Support multiple regions per device

In reply to Thierry Reding

From: Thierry Reding <[email protected]>

While the lookup/initialization code already supports multiple memory regions per device, the release code will only ever release the first matching memory region.

Enhance the code to release all matching regions. Each attachment of a region to a device is uniquely identifiable using a struct device pointer and a pointer to the memory region's struct reserved_mem.

---
 drivers/of/of_reserved_mem.c | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)
drivers/of/of_reserved_mem.c +10 -12
index ed2ff6f01d32..f61e8739502a 100644
@@ -385,24 +385,22 @@ EXPORT_SYMBOL_GPL(of_reserved_mem_device_init_by_name);
  */
 void of_reserved_mem_device_release(struct device *dev)
 {
-	struct rmem_assigned_device *rd;
-	struct reserved_mem *rmem = NULL;
+	struct rmem_assigned_device *rd, *tmp;
+	LIST_HEAD(release_list);
 
 	mutex_lock(&of_rmem_assigned_device_mutex);
-	list_for_each_entry(rd, &of_rmem_assigned_device_list, list) {
-		if (rd->dev == dev) {
-			rmem = rd->rmem;
-			list_del(&rd->list);
-			kfree(rd);
-			break;
-		}
+	list_for_each_entry_safe(rd, tmp, &of_rmem_assigned_device_list, list) {
+		if (rd->dev == dev)
+			list_move_tail(&rd->list, &release_list);
 	}
 	mutex_unlock(&of_rmem_assigned_device_mutex);
 
-	if (!rmem || !rmem->ops || !rmem->ops->device_release)
-		return;
+	list_for_each_entry_safe(rd, tmp, &release_list, list) {
+		if (rd->rmem && rd->rmem->ops && rd->rmem->ops->device_release)
+			rd->rmem->ops->device_release(rd->rmem, dev);
 
-	rmem->ops->device_release(rmem, dev);
+		kfree(rd);
+	}
 }
 EXPORT_SYMBOL_GPL(of_reserved_mem_device_release);
 
Signature · 1 line
2.24.1
maintainer Reviewed-by on v6 3/14
#8 lore raw

Re: [PATCH v6 03/14] of: reserved-memory: Support multiple regions per device

Quoted 6 lines · Thierry Reding

From: Thierry Reding <[email protected]>

While the lookup/initialization code already supports multiple memory regions per device, the release code will only ever release the first matching memory region.

Quoted 9 lines

Enhance the code to release all matching regions. Each attachment of a region to a device is uniquely identifiable using a struct device pointer and a pointer to the memory region's struct reserved_mem.

---
 drivers/of/of_reserved_mem.c | 22 ++++++++++------------
 1 file changed, 10 insertions(+), 12 deletions(-)
#9 lore raw

PATCH v6 4/14 clk: tegra: Rename Tegra124 EMC clock source file

In reply to Thierry Reding

From: Thierry Reding <[email protected]>

This code is only used on Tegra124, so rename it accordingly to make it more consistent with other file names.

---
 drivers/clk/tegra/Makefile                          | 2 +-
 drivers/clk/tegra/{clk-emc.c => clk-tegra124-emc.c} | 0
 2 files changed, 1 insertion(+), 1 deletion(-)
 rename drivers/clk/tegra/{clk-emc.c => clk-tegra124-emc.c} (100%)
drivers/clk/tegra/Makefile +1 -1
index 1f7c30f87ece..dec508ef2ada 100644
@@ -14,7 +14,6 @@ obj-y					+= clk-tegra-audio.o
 obj-y					+= clk-tegra-periph.o
 obj-y					+= clk-tegra-fixed.o
 obj-y					+= clk-tegra-super-gen4.o
-obj-$(CONFIG_TEGRA_CLK_EMC)		+= clk-emc.o
 obj-$(CONFIG_ARCH_TEGRA_2x_SOC)         += clk-tegra20.o
 obj-$(CONFIG_ARCH_TEGRA_2x_SOC)		+= clk-tegra20-emc.o
 obj-$(CONFIG_ARCH_TEGRA_3x_SOC)         += clk-tegra30.o
@@ -22,6 +21,7 @@ obj-$(CONFIG_ARCH_TEGRA_3x_SOC)		+= clk-tegra20-emc.o
 obj-$(CONFIG_ARCH_TEGRA_114_SOC)	+= clk-tegra114.o
 obj-$(CONFIG_ARCH_TEGRA_124_SOC)	+= clk-tegra124.o
 obj-$(CONFIG_TEGRA_CLK_DFLL)		+= clk-tegra124-dfll-fcpu.o
+obj-$(CONFIG_TEGRA_CLK_EMC)		+= clk-tegra124-emc.o
 obj-$(CONFIG_ARCH_TEGRA_132_SOC)	+= clk-tegra124.o
 obj-y					+= cvb.o
 obj-$(CONFIG_ARCH_TEGRA_210_SOC)	+= clk-tegra210.o
drivers/clk/tegra/clk-tegra124-emc.c renamed from drivers/clk/tegra/clk-emc.c +0 -0
similarity index 100%
rename from drivers/clk/tegra/clk-emc.c
rename to drivers/clk/tegra/clk-tegra124-emc.c
Signature · 1 line
2.24.1
#10 lore raw

Re: [PATCH v6 04/14] clk: tegra: Rename Tegra124 EMC clock source file

09.04.2020 20:52, Thierry Reding пишет:

Quoted 25 lines

From: Thierry Reding <[email protected]>

This code is only used on Tegra124, so rename it accordingly to make it more consistent with other file names.

---
 drivers/clk/tegra/Makefile                          | 2 +-
 drivers/clk/tegra/{clk-emc.c => clk-tegra124-emc.c} | 0
 2 files changed, 1 insertion(+), 1 deletion(-)
 rename drivers/clk/tegra/{clk-emc.c => clk-tegra124-emc.c} (100%)
drivers/clk/tegra/Makefile +0 -1
index 1f7c30f87ece..dec508ef2ada 100644
@@ -14,7 +14,6 @@ obj-y					+= clk-tegra-audio.o
 obj-y					+= clk-tegra-periph.o
 obj-y					+= clk-tegra-fixed.o
 obj-y					+= clk-tegra-super-gen4.o
-obj-$(CONFIG_TEGRA_CLK_EMC)		+= clk-emc.o
 obj-$(CONFIG_ARCH_TEGRA_2x_SOC)         += clk-tegra20.o
 obj-$(CONFIG_ARCH_TEGRA_2x_SOC)		+= clk-tegra20-emc.o
 obj-$(CONFIG_ARCH_TEGRA_3x_SOC)         += clk-tegra30.o

drivers/clk/tegra/Makefile obj-$(CONFIG_ARCH_TEGRA_3x_SOC) += clk-tegra20-emc.o · line 24

Quoted 4 lines
drivers/clk/tegra/Makefile +1 -0
@@ -22,6 +21,7 @@ obj-$(CONFIG_ARCH_TEGRA_3x_SOC)		+= clk-tegra20-emc.o
 obj-$(CONFIG_ARCH_TEGRA_114_SOC)	+= clk-tegra114.o
 obj-$(CONFIG_ARCH_TEGRA_124_SOC)	+= clk-tegra124.o
 obj-$(CONFIG_TEGRA_CLK_DFLL)		+= clk-tegra124-dfll-fcpu.o
+obj-$(CONFIG_TEGRA_CLK_EMC)		+= clk-tegra124-emc.o

What about to rename CONFIG_TEGRA_CLK_EMC to CONFIG_TEGRA124_CLK_EMC as well?

Also.. maybe the CONFIG_TEGRA_CLK_EMC isn't really needed at all and the TEGRA124_EMC of memory/tegra could be re-used here?

#11 lore raw

Re: [PATCH v6 04/14] clk: tegra: Rename Tegra124 EMC clock source file

Quoted 25 lines · Dmitry Osipenko

09.04.2020 20:52, Thierry Reding пишет:

Quoted 24 lines

From: Thierry Reding <[email protected]>

This code is only used on Tegra124, so rename it accordingly to make it more consistent with other file names.

---
 drivers/clk/tegra/Makefile                          | 2 +-
 drivers/clk/tegra/{clk-emc.c => clk-tegra124-emc.c} | 0
 2 files changed, 1 insertion(+), 1 deletion(-)
 rename drivers/clk/tegra/{clk-emc.c => clk-tegra124-emc.c} (100%)
drivers/clk/tegra/Makefile +0 -1
index 1f7c30f87ece..dec508ef2ada 100644
@@ -14,7 +14,6 @@ obj-y					+= clk-tegra-audio.o
 obj-y					+= clk-tegra-periph.o
 obj-y					+= clk-tegra-fixed.o
 obj-y					+= clk-tegra-super-gen4.o
-obj-$(CONFIG_TEGRA_CLK_EMC)		+= clk-emc.o
 obj-$(CONFIG_ARCH_TEGRA_2x_SOC)         += clk-tegra20.o
 obj-$(CONFIG_ARCH_TEGRA_2x_SOC)		+= clk-tegra20-emc.o
 obj-$(CONFIG_ARCH_TEGRA_3x_SOC)         += clk-tegra30.o
Quoted 8 lines

drivers/clk/tegra/Makefile obj-$(CONFIG_ARCH_TEGRA_3x_SOC) += clk-tegra20-emc.o · line 24

Quoted 5 lines
drivers/clk/tegra/Makefile +1 -0
@@ -22,6 +21,7 @@ obj-$(CONFIG_ARCH_TEGRA_3x_SOC)		+= clk-tegra20-emc.o
 obj-$(CONFIG_ARCH_TEGRA_114_SOC)	+= clk-tegra114.o
 obj-$(CONFIG_ARCH_TEGRA_124_SOC)	+= clk-tegra124.o
 obj-$(CONFIG_TEGRA_CLK_DFLL)		+= clk-tegra124-dfll-fcpu.o
+obj-$(CONFIG_TEGRA_CLK_EMC)		+= clk-tegra124-emc.o

What about to rename CONFIG_TEGRA_CLK_EMC to CONFIG_TEGRA124_CLK_EMC as well?

Yeah, I could do that.

Quoted 2 lines

Also.. maybe the CONFIG_TEGRA_CLK_EMC isn't really needed at all and the TEGRA124_EMC of memory/tegra could be re-used here?

Sounds like that should work... let me see what I can do.

Thierry

#12 lore raw

PATCH v6 5/14 clk: tegra: Add PLLP_UD and PLLMB_UD for Tegra210

In reply to Thierry Reding

From: Joseph Lo <[email protected]>

Introduce the low jitter path of PLLP and PLLMB which can be used as EMC clock source.

---
 drivers/clk/tegra/clk-tegra210.c         | 11 +++++++++++
 include/dt-bindings/clock/tegra210-car.h |  4 ++--
 2 files changed, 13 insertions(+), 2 deletions(-)
drivers/clk/tegra/clk-tegra210.c +11 -0
index defe3b7ebfa4..57d97e87d870 100644
@@ -3153,6 +3153,17 @@ static void __init tegra210_pll_init(void __iomem *clk_base,
 	clk_register_clkdev(clk, "pll_m_ud", NULL);
 	clks[TEGRA210_CLK_PLL_M_UD] = clk;
 
+	/* PLLMB_UD */
+	clk = clk_register_fixed_factor(NULL, "pll_mb_ud", "pll_mb",
+					CLK_SET_RATE_PARENT, 1, 1);
+	clk_register_clkdev(clk, "pll_mb_ud", NULL);
+	clks[TEGRA210_CLK_PLL_MB_UD] = clk;
+
+	/* PLLP_UD */
+	clk = clk_register_fixed_factor(NULL, "pll_p_ud", "pll_p",
+					0, 1, 1);
+	clks[TEGRA210_CLK_PLL_P_UD] = clk;
+
 	/* PLLU_VCO */
 	if (!tegra210_init_pllu()) {
 		clk = clk_register_fixed_rate(NULL, "pll_u_vco", "pll_ref", 0,
include/dt-bindings/clock/tegra210-car.h +2 -2
index 7a8f10b9a66d..5c93b01156d4 100644
@@ -351,8 +351,8 @@
 #define TEGRA210_CLK_PLL_P_OUT_XUSB 317
 #define TEGRA210_CLK_XUSB_SSP_SRC 318
 #define TEGRA210_CLK_PLL_RE_OUT1 319
-/* 320 */
-/* 321 */
+#define TEGRA210_CLK_PLL_MB_UD 320
+#define TEGRA210_CLK_PLL_P_UD 321
 #define TEGRA210_CLK_ISP 322
 #define TEGRA210_CLK_PLL_A_OUT_ADSP 323
 #define TEGRA210_CLK_PLL_A_OUT0_OUT_ADSP 324
Signature · 1 line
2.24.1
#13 lore raw

PATCH v6 6/14 clk: tegra: Export functions for EMC clock scaling

In reply to Thierry Reding

From: Joseph Lo <[email protected]>

Export functions to allow accessing the CAR register required by EMC clock scaling. These functions will be used to access the CAR register as part of the scaling sequence.

---
Changes in v5:
- remove tegra210_clk_emc_get_setting() which is no longer needed

 drivers/clk/tegra/clk-tegra210.c | 26 ++++++++++++++++++++++++++
 include/linux/clk/tegra.h        |  3 +++
 2 files changed, 29 insertions(+)
drivers/clk/tegra/clk-tegra210.c +26 -0
index 57d97e87d870..798920ec50e9 100644
@@ -37,6 +37,7 @@
 #define CLK_SOURCE_LA 0x1f8
 #define CLK_SOURCE_SDMMC2 0x154
 #define CLK_SOURCE_SDMMC4 0x164
+#define CLK_SOURCE_EMC_DLL 0x664
 
 #define PLLC_BASE 0x80
 #define PLLC_OUT 0x84
@@ -227,6 +228,10 @@
 #define RST_DFLL_DVCO 0x2f4
 #define DVFS_DFLL_RESET_SHIFT 0
 
+#define CLK_RST_CONTROLLER_CLK_OUT_ENB_X_SET	0x284
+#define CLK_RST_CONTROLLER_CLK_OUT_ENB_X_CLR	0x288
+#define CLK_OUT_ENB_X_CLK_ENB_EMC_DLL		BIT(14)
+
 #define CLK_RST_CONTROLLER_RST_DEV_Y_SET 0x2a8
 #define CLK_RST_CONTROLLER_RST_DEV_Y_CLR 0x2ac
 #define CPU_SOFTRST_CTRL 0x380
@@ -555,6 +560,27 @@ void tegra210_set_sata_pll_seq_sw(bool state)
 }
 EXPORT_SYMBOL_GPL(tegra210_set_sata_pll_seq_sw);
 
+void tegra210_clk_emc_dll_enable(bool flag)
+{
+	u32 offset = flag ? CLK_RST_CONTROLLER_CLK_OUT_ENB_X_SET :
+		     CLK_RST_CONTROLLER_CLK_OUT_ENB_X_CLR;
+
+	writel_relaxed(CLK_OUT_ENB_X_CLK_ENB_EMC_DLL, clk_base + offset);
+}
+EXPORT_SYMBOL_GPL(tegra210_clk_emc_dll_enable);
+
+void tegra210_clk_emc_dll_update_setting(u32 emc_dll_src_value)
+{
+	writel_relaxed(emc_dll_src_value, clk_base + CLK_SOURCE_EMC_DLL);
+}
+EXPORT_SYMBOL_GPL(tegra210_clk_emc_dll_update_setting);
+
+void tegra210_clk_emc_update_setting(u32 emc_src_value)
+{
+	writel_relaxed(emc_src_value, clk_base + CLK_SOURCE_EMC);
+}
+EXPORT_SYMBOL_GPL(tegra210_clk_emc_update_setting);
+
 static void tegra210_generic_mbist_war(struct tegra210_domain_mbist_war *mbist)
 {
 	u32 val;
include/linux/clk/tegra.h +3 -0
index 2b1b35240074..5b0bdb413460 100644
@@ -131,6 +131,9 @@ extern void tegra210_set_sata_pll_seq_sw(bool state);
 extern void tegra210_put_utmipll_in_iddq(void);
 extern void tegra210_put_utmipll_out_iddq(void);
 extern int tegra210_clk_handle_mbist_war(unsigned int id);
+extern void tegra210_clk_emc_dll_enable(bool flag);
+extern void tegra210_clk_emc_dll_update_setting(u32 emc_dll_src_value);
+extern void tegra210_clk_emc_update_setting(u32 emc_src_value);
 
 struct clk;
 
Signature · 1 line
2.24.1
#14 lore raw

PATCH v6 7/14 clk: tegra: Implement Tegra210 EMC clock

In reply to Thierry Reding

From: Joseph Lo <[email protected]>

The EMC clock needs to carefully coordinate with the EMC controller programming to make sure external memory can be properly clocked. Do so by hooking up the EMC clock with an EMC provider that will specify which rates are supported by the EMC and provide a callback to use for setting the clock rate at the EMC.

Based on work by Peter De Schrijver <[email protected]>.

---
Changes in v6:
- work around CCF assumptions on parent clock and rate in driver rather than rely on core to handle it
- maintain reference to EMC provider's module
- move EMC driver hunks to later patch
- use macros from linux/bitfield.h

Changes in v5:
- major rework and cleanup

 drivers/clk/tegra/Makefile           |   1 +
 drivers/clk/tegra/clk-tegra210-emc.c | 369 +++++++++++++++++++++++++++
 drivers/clk/tegra/clk.h              |   3 +
 include/linux/clk/tegra.h            |  24 ++
 4 files changed, 397 insertions(+)
 create mode 100644 drivers/clk/tegra/clk-tegra210-emc.c
drivers/clk/tegra/Makefile +1 -0
index dec508ef2ada..fc369a5d21dc 100644
@@ -25,5 +25,6 @@ obj-$(CONFIG_TEGRA_CLK_EMC)		+= clk-tegra124-emc.o
 obj-$(CONFIG_ARCH_TEGRA_132_SOC)	+= clk-tegra124.o
 obj-y					+= cvb.o
 obj-$(CONFIG_ARCH_TEGRA_210_SOC)	+= clk-tegra210.o
+obj-$(CONFIG_ARCH_TEGRA_210_SOC)	+= clk-tegra210-emc.o
 obj-$(CONFIG_CLK_TEGRA_BPMP)		+= clk-bpmp.o
 obj-y					+= clk-utils.o
drivers/clk/tegra/clk-tegra210-emc.c new file +369 -0

369 lines not on this page · raw message

drivers/clk/tegra/clk.h +3 -0
index 2c9a68302e02..b87e90569314 100644
@@ -907,4 +907,7 @@ void tegra_clk_periph_resume(void);
 bool tegra20_clk_emc_driver_available(struct clk_hw *emc_hw);
 struct clk *tegra20_clk_register_emc(void __iomem *ioaddr, bool low_jitter);
 
+struct clk *tegra210_clk_register_emc(struct device_node *np,
+				      void __iomem *regs);
+
 #endif /* TEGRA_CLK_H */
include/linux/clk/tegra.h +24 -0
index 5b0bdb413460..3f01d43f0598 100644
@@ -146,4 +146,28 @@ void tegra20_clk_set_emc_round_callback(tegra20_clk_emc_round_cb *round_cb,
 					void *cb_arg);
 int tegra20_clk_prepare_emc_mc_same_freq(struct clk *emc_clk, bool same);
 
+struct tegra210_clk_emc_config {
+	unsigned long rate;
+	bool same_freq;
+	u32 value;
+
+	unsigned long parent_rate;
+	u8 parent;
+};
+
+struct tegra210_clk_emc_provider {
+	struct module *owner;
+	struct device *dev;
+
+	struct tegra210_clk_emc_config *configs;
+	unsigned int num_configs;
+
+	int (*set_rate)(struct device *dev,
+			const struct tegra210_clk_emc_config *config);
+};
+
+int tegra210_clk_emc_attach(struct clk *clk,
+			    struct tegra210_clk_emc_provider *provider);
+void tegra210_clk_emc_detach(struct clk *clk);
+
 #endif /* __LINUX_CLK_TEGRA_H_ */
Signature · 1 line
2.24.1
#15 lore raw

Re: [PATCH v6 07/14] clk: tegra: Implement Tegra210 EMC clock

09.04.2020 20:52, Thierry Reding пишет:
...

drivers/clk/tegra/clk-tegra210-emc.c line 95

Quoted 9 lines
drivers/clk/tegra/clk-tegra210-emc.c new file +9 -0
+static long tegra210_clk_emc_round_rate(struct clk_hw *hw, unsigned long rate,
+					unsigned long *prate)
+{
+	struct tegra210_clk_emc *emc = to_tegra210_clk_emc(hw);
+	struct tegra210_clk_emc_provider *provider = emc->provider;
+	unsigned int i;
+
+	if (!provider || !provider->configs || provider->num_configs == 0)
+		return clk_hw_get_rate(hw);

This still looks wrong to me. Nobody should be able to get EMC clock until provider is registered.

This is troublesome, especially given that you're allowing the EMC driver to be compiled as a loadable module. For example, this won't work with the current ACTMON driver because it builds OPP table based on the clk-rate rounding during the driver's probe, so it won't be able to do it properly if provider is "temporarily" missing.

... I think that in a longer run we should stop manually building the ACTMON's OPP table and instead define a proper OPP table (per-HW Speedo ID, with voltages) in a device-tree. But this is just a vague plans for the future for now.

#16 lore raw

Re: [PATCH v6 07/14] clk: tegra: Implement Tegra210 EMC clock

Quoted 14 lines · Dmitry Osipenko

09.04.2020 20:52, Thierry Reding пишет:
...

drivers/clk/tegra/clk-tegra210-emc.c line 95

Quoted 9 lines
drivers/clk/tegra/clk-tegra210-emc.c new file +9 -0
+static long tegra210_clk_emc_round_rate(struct clk_hw *hw, unsigned long rate,
+					unsigned long *prate)
+{
+	struct tegra210_clk_emc *emc = to_tegra210_clk_emc(hw);
+	struct tegra210_clk_emc_provider *provider = emc->provider;
+	unsigned int i;
+
+	if (!provider || !provider->configs || provider->num_configs == 0)
+		return clk_hw_get_rate(hw);

This still looks wrong to me. Nobody should be able to get EMC clock until provider is registered.

The EMC clock is mostly orthogonal to the provider. The provider really only allows you to actually change the frequency. The clock will still remain even if the provider goes away, it just will loose the ability to change rate.

Quoted 10 lines

This is troublesome, especially given that you're allowing the EMC driver to be compiled as a loadable module. For example, this won't work with the current ACTMON driver because it builds OPP table based on the clk-rate rounding during the driver's probe, so it won't be able to do it properly if provider is "temporarily" missing.

... I think that in a longer run we should stop manually building the ACTMON's OPP table and instead define a proper OPP table (per-HW Speedo ID, with voltages) in a device-tree. But this is just a vague plans for the future for now.

This code only applies to Tegra210 and we don't currently support ACTMON on Tegra210. I'm also not sure we'll ever do because using interconnects to describe paths to system memory and then using ICC requests for each driver to submit memory bandwidth requests seems like a better way of dealing with this problem than using ACTMON to monitor activity because that only allows you to react, whereas we really want to be able to allocate memory bandwidth upfront.

Thierry

#17 lore raw

Re: [PATCH v6 07/14] clk: tegra: Implement Tegra210 EMC clock

14.04.2020 17:34, Thierry Reding пишет:

Quoted 16 lines · Dmitry Osipenko
Quoted 14 lines

09.04.2020 20:52, Thierry Reding пишет:
...

drivers/clk/tegra/clk-tegra210-emc.c line 95

Quoted 9 lines
drivers/clk/tegra/clk-tegra210-emc.c new file +9 -0
+static long tegra210_clk_emc_round_rate(struct clk_hw *hw, unsigned long rate,
+					unsigned long *prate)
+{
+	struct tegra210_clk_emc *emc = to_tegra210_clk_emc(hw);
+	struct tegra210_clk_emc_provider *provider = emc->provider;
+	unsigned int i;
+
+	if (!provider || !provider->configs || provider->num_configs == 0)
+		return clk_hw_get_rate(hw);

This still looks wrong to me. Nobody should be able to get EMC clock until provider is registered.

Quoted 4 lines

The EMC clock is mostly orthogonal to the provider. The provider really only allows you to actually change the frequency. The clock will still remain even if the provider goes away, it just will loose the ability to change rate.

It's not only about changing the clock rate, but also about rounding the rate and etc.

Besides, you won't be able to change the rate until provider is registered, which might be a quite big problem by itself.

Quoted 11 lines
Quoted 10 lines

This is troublesome, especially given that you're allowing the EMC driver to be compiled as a loadable module. For example, this won't work with the current ACTMON driver because it builds OPP table based on the clk-rate rounding during the driver's probe, so it won't be able to do it properly if provider is "temporarily" missing.

... I think that in a longer run we should stop manually building the ACTMON's OPP table and instead define a proper OPP table (per-HW Speedo ID, with voltages) in a device-tree. But this is just a vague plans for the future for now.

Quoted 7 lines

This code only applies to Tegra210 and we don't currently support ACTMON on Tegra210. I'm also not sure we'll ever do because using interconnects to describe paths to system memory and then using ICC requests for each driver to submit memory bandwidth requests seems like a better way of dealing with this problem than using ACTMON to monitor activity because that only allows you to react, whereas we really want to be able to allocate memory bandwidth upfront.

You absolutely have to have the ACTMON support if you want to provide a good user experience because interconnect won't take into account the dynamic CPU memory traffic. Without ACTMON support CPU will turn into a "turtle" if memory runs on a lowest freq, while CPU needs the highest.

Secondly, the interconnect could underestimate the memory BW requirement because memory performance depends quite a lot on the memory-accessing patterns and it's not possible to predict it properly. Otherwise you may need to always overestimate the BW, which perhaps is not what anyone would really want to have.

I'm not sure why you're resisting to do it all properly from the start, it looks to me that it will take you just a few lines of code (like in a case of the T20/30 EMC).

#18 lore raw

Re: [PATCH v6 07/14] clk: tegra: Implement Tegra210 EMC clock

Quoted 17 lines · Dmitry Osipenko

14.04.2020 17:34, Thierry Reding пишет:

Quoted 16 lines · Dmitry Osipenko
Quoted 14 lines

09.04.2020 20:52, Thierry Reding пишет:
...

drivers/clk/tegra/clk-tegra210-emc.c line 95

Quoted 9 lines
drivers/clk/tegra/clk-tegra210-emc.c new file +9 -0
+static long tegra210_clk_emc_round_rate(struct clk_hw *hw, unsigned long rate,
+					unsigned long *prate)
+{
+	struct tegra210_clk_emc *emc = to_tegra210_clk_emc(hw);
+	struct tegra210_clk_emc_provider *provider = emc->provider;
+	unsigned int i;
+
+	if (!provider || !provider->configs || provider->num_configs == 0)
+		return clk_hw_get_rate(hw);

This still looks wrong to me. Nobody should be able to get EMC clock until provider is registered.

Quoted 7 lines
Quoted 4 lines

The EMC clock is mostly orthogonal to the provider. The provider really only allows you to actually change the frequency. The clock will still remain even if the provider goes away, it just will loose the ability to change rate.

It's not only about changing the clock rate, but also about rounding the rate and etc.

The code will currently just return the configured rate when no provider is available. It's going to always round to that one rate and it will refuse to set another one. The EMC clock is basically going to function as a fixed clock while no provider is attached.

Quoted 2 lines

Besides, you won't be able to change the rate until provider is registered, which might be a quite big problem by itself.

Until the provider is registered, there's just no way to change the rate. You always need to write MC and EMC registers in order to change the rate, so trying to change it when the MC/EMC drivers aren't available isn't going to work.

Quoted 19 lines
Quoted 11 lines
Quoted 10 lines

This is troublesome, especially given that you're allowing the EMC driver to be compiled as a loadable module. For example, this won't work with the current ACTMON driver because it builds OPP table based on the clk-rate rounding during the driver's probe, so it won't be able to do it properly if provider is "temporarily" missing.

... I think that in a longer run we should stop manually building the ACTMON's OPP table and instead define a proper OPP table (per-HW Speedo ID, with voltages) in a device-tree. But this is just a vague plans for the future for now.

Quoted 7 lines

This code only applies to Tegra210 and we don't currently support ACTMON on Tegra210. I'm also not sure we'll ever do because using interconnects to describe paths to system memory and then using ICC requests for each driver to submit memory bandwidth requests seems like a better way of dealing with this problem than using ACTMON to monitor activity because that only allows you to react, whereas we really want to be able to allocate memory bandwidth upfront.

Quoted 4 lines

You absolutely have to have the ACTMON support if you want to provide a good user experience because interconnect won't take into account the dynamic CPU memory traffic. Without ACTMON support CPU will turn into a "turtle" if memory runs on a lowest freq, while CPU needs the highest.

Can we not guess a bandwidth based on the CPU frequency? Yes, that's perhaps going to be an overestimation if the CPU doesn't actually access memory, but that's better than nothing at all.

Also, at this point I'm less worried about power consumption rather than making Tegra210 devices perform useful tasks. Yes, eventually we'll want to fine-tune power consumption, but it's going to take a bit of work to get there. In the meantime, giving people a way to set an EMC frequency other than that set on boot is going to make them very happy.

Quoted 5 lines

Secondly, the interconnect could underestimate the memory BW requirement because memory performance depends quite a lot on the memory-accessing patterns and it's not possible to predict it properly. Otherwise you may need to always overestimate the BW, which perhaps is not what anyone would really want to have.

Overestimating might be a good starting point, though. At this point I'm mostly concerned about being able to change the memory frequency at all because many systems are mostly unusable at the boot EMC frequency.

Like I said, if ACTMON really does prove to be useful I'm all for adding support on Tegra210, but I don't think trying to do everything all at once is a very good plan. So I'm trying to get there in incremental steps.

Quoted 3 lines

I'm not sure why you're resisting to do it all properly from the start, it looks to me that it will take you just a few lines of code (like in a case of the T20/30 EMC).

I'm not trying to resist anything. I'm just saying that all of the issues that you're bringing up aren't an immediate concern.

My main concerns right now are to: a) allow people to change the EMC frequency (and hopefully soon also allow the EMC frequency to be changed based on bandwidth demands by memory client drivers) and b) not bloat the kernel more than it has to (while my configuration isn't tweaked, it's pretty standard and the resulting image is roughly 20 MiB; adding the Tegra210 EMC driver adds another 64 KiB).

And if we really do want to add ACTMON support later on, you already suggested a better way of moving forward, so it sounds to me like that would be a nice incremental improvement, certainly much better than bloating the kernel even further by requiring this to be built-in and preventing it from being unloaded.

Thierry

#19 lore raw

Re: [PATCH v6 07/14] clk: tegra: Implement Tegra210 EMC clock

14.04.2020 20:10, Thierry Reding пишет:

Quoted 23 lines · Dmitry Osipenko
Quoted 22 lines

14.04.2020 17:34, Thierry Reding пишет:

Quoted 20 lines · Dmitry Osipenko
Quoted 14 lines

09.04.2020 20:52, Thierry Reding пишет:
...

drivers/clk/tegra/clk-tegra210-emc.c line 95

Quoted 9 lines
drivers/clk/tegra/clk-tegra210-emc.c new file +9 -0
+static long tegra210_clk_emc_round_rate(struct clk_hw *hw, unsigned long rate,
+					unsigned long *prate)
+{
+	struct tegra210_clk_emc *emc = to_tegra210_clk_emc(hw);
+	struct tegra210_clk_emc_provider *provider = emc->provider;
+	unsigned int i;
+
+	if (!provider || !provider->configs || provider->num_configs == 0)
+		return clk_hw_get_rate(hw);

This still looks wrong to me. Nobody should be able to get EMC clock until provider is registered.

The EMC clock is mostly orthogonal to the provider. The provider really only allows you to actually change the frequency. The clock will still remain even if the provider goes away, it just will loose the ability to change rate.

Quoted 7 lines
Quoted 2 lines

It's not only about changing the clock rate, but also about rounding the rate and etc.

The code will currently just return the configured rate when no provider is available. It's going to always round to that one rate and it will refuse to set another one. The EMC clock is basically going to function as a fixed clock while no provider is attached.

Yes, I'm telling that this should be a wrong thing to do.

Quoted 7 lines
Quoted 2 lines

Besides, you won't be able to change the rate until provider is registered, which might be a quite big problem by itself.

Until the provider is registered, there's just no way to change the rate. You always need to write MC and EMC registers in order to change the rate, so trying to change it when the MC/EMC drivers aren't available isn't going to work.

Again, clk_get() should return -EPROBE_DEFER until provider is registered.

Quoted 19 lines
Quoted 19 lines
Quoted 18 lines
Quoted 10 lines

This is troublesome, especially given that you're allowing the EMC driver to be compiled as a loadable module. For example, this won't work with the current ACTMON driver because it builds OPP table based on the clk-rate rounding during the driver's probe, so it won't be able to do it properly if provider is "temporarily" missing.

... I think that in a longer run we should stop manually building the ACTMON's OPP table and instead define a proper OPP table (per-HW Speedo ID, with voltages) in a device-tree. But this is just a vague plans for the future for now.

This code only applies to Tegra210 and we don't currently support ACTMON on Tegra210. I'm also not sure we'll ever do because using interconnects to describe paths to system memory and then using ICC requests for each driver to submit memory bandwidth requests seems like a better way of dealing with this problem than using ACTMON to monitor activity because that only allows you to react, whereas we really want to be able to allocate memory bandwidth upfront.

Quoted 8 lines
Quoted 4 lines

You absolutely have to have the ACTMON support if you want to provide a good user experience because interconnect won't take into account the dynamic CPU memory traffic. Without ACTMON support CPU will turn into a "turtle" if memory runs on a lowest freq, while CPU needs the highest.

Can we not guess a bandwidth based on the CPU frequency? Yes, that's perhaps going to be an overestimation if the CPU doesn't actually access memory, but that's better than nothing at all.

CPU load doesn't reflect the memory usage.

1. CPU could be 100% loaded while not making memory accesses at all (100% cache hit).

2. CPU governor settings could be changed by user and CPU != memory.

ACTMON is specifically designated to memory scaling based on actual memory usage statistics. T210 ACTMON is similar to T124, it should be easy to support.

Quoted 35 lines

Also, at this point I'm less worried about power consumption rather than making Tegra210 devices perform useful tasks. Yes, eventually we'll want to fine-tune power consumption, but it's going to take a bit of work to get there. In the meantime, giving people a way to set an EMC frequency other than that set on boot is going to make them very happy.

Quoted 5 lines

Secondly, the interconnect could underestimate the memory BW requirement because memory performance depends quite a lot on the memory-accessing patterns and it's not possible to predict it properly. Otherwise you may need to always overestimate the BW, which perhaps is not what anyone would really want to have.

Overestimating might be a good starting point, though. At this point I'm mostly concerned about being able to change the memory frequency at all because many systems are mostly unusable at the boot EMC frequency.

Like I said, if ACTMON really does prove to be useful I'm all for adding support on Tegra210, but I don't think trying to do everything all at once is a very good plan. So I'm trying to get there in incremental steps.

Quoted 3 lines

I'm not sure why you're resisting to do it all properly from the start, it looks to me that it will take you just a few lines of code (like in a case of the T20/30 EMC).

I'm not trying to resist anything. I'm just saying that all of the issues that you're bringing up aren't an immediate concern.

My main concerns right now are to: a) allow people to change the EMC frequency (and hopefully soon also allow the EMC frequency to be changed based on bandwidth demands by memory client drivers) and b) not bloat the kernel more than it has to (while my configuration isn't tweaked, it's pretty standard and the resulting image is roughly 20 MiB; adding the Tegra210 EMC driver adds another 64 KiB).

Quoted 5 lines

And if we really do want to add ACTMON support later on, you already suggested a better way of moving forward, so it sounds to me like that would be a nice incremental improvement, certainly much better than bloating the kernel even further by requiring this to be built-in and preventing it from being unloaded.

Up to you then :)

#20 lore raw

Re: [PATCH v6 07/14] clk: tegra: Implement Tegra210 EMC clock

In reply to Thierry Reding

09.04.2020 20:52, Thierry Reding пишет:
...

drivers/clk/tegra/clk-tegra210-emc.c line 303

Quoted 11 lines
drivers/clk/tegra/clk-tegra210-emc.c new file +11 -0
+int tegra210_clk_emc_attach(struct clk *clk,
+			    struct tegra210_clk_emc_provider *provider)
+{
+	struct clk_hw *hw = __clk_get_hw(clk);
+	struct tegra210_clk_emc *emc = to_tegra210_clk_emc(hw);
+	struct device *dev = provider->dev;
+	unsigned int i;
+	int err;
+
+	if (!try_module_get(provider->owner))
+		return -ENODEV;

Is the EMC driver module bumping its own refcount by itself?

In the other patch I already suggested that the EMC module should be disallowed to be unloaded once it has been loaded, seems you're already doing it. Correct?

#21 lore raw

Re: [PATCH v6 07/14] clk: tegra: Implement Tegra210 EMC clock

Quoted 15 lines · Dmitry Osipenko

09.04.2020 20:52, Thierry Reding пишет:
...

drivers/clk/tegra/clk-tegra210-emc.c line 303

Quoted 11 lines
drivers/clk/tegra/clk-tegra210-emc.c new file +11 -0
+int tegra210_clk_emc_attach(struct clk *clk,
+			    struct tegra210_clk_emc_provider *provider)
+{
+	struct clk_hw *hw = __clk_get_hw(clk);
+	struct tegra210_clk_emc *emc = to_tegra210_clk_emc(hw);
+	struct device *dev = provider->dev;
+	unsigned int i;
+	int err;
+
+	if (!try_module_get(provider->owner))
+		return -ENODEV;

Is the EMC driver module bumping its own refcount by itself?

Hm... this doesn't really look useful in retrospect. Yes, the EMC is effectively grabbing a reference to itself.

Quoted 3 lines

In the other patch I already suggested that the EMC module should be disallowed to be unloaded once it has been loaded, seems you're already doing it. Correct?

Interestingly, it all seems to work fine if I unload the module at runtime, not sure why I'm not prevented from unloading the module.

Thierry

#22 lore raw

PATCH v6 8/14 dt-bindings: memory: tegra: Add external memory controller binding for Tegra210

In reply to Thierry Reding

From: Joseph Lo <[email protected]>

Add the binding document for the external memory controller (EMC) which communicates with external LPDDR4 devices. It includes the bindings of the EMC node and a sub-node of EMC table which under the reserved memory node. The EMC table contains the data of the rates that EMC supported.

---
Changes in v6:
- fix example by changing #address-cells and #size-cells
- remove status property from example

Changes in v5:
- convert to dt-schema

 .../nvidia,tegra210-emc.yaml                  | 82 +++++++++++++++++++
 1 file changed, 82 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/memory-controllers/nvidia,tegra210-emc.yaml
Documentation/devicetree/bindings/memory-controllers/nvidia,tegra210-emc.yaml new file +82 -0
new file mode 100644
index 000000000000..49ab09252e52
@@ -0,0 +1,82 @@
+# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause)
+%YAML 1.2
+---
+$id: http://devicetree.org/schemas/memory-controllers/nvidia,tegra210-emc.yaml#
+$schema: http://devicetree.org/meta-schemas/core.yaml#
+
+title: NVIDIA Tegra210 SoC External Memory Controller
+
+maintainers:
+  - Thierry Reding <[email protected]>
+  - Jon Hunter <[email protected]>
+
+description: |
+  The EMC interfaces with the off-chip SDRAM to service the request stream
+  sent from the memory controller.
+
+properties:
+  compatible:
+    const: nvidia,tegra210-emc
+
+  reg:
+    maxItems: 3
+
+  clocks:
+    items:
+      - description: external memory clock
+
+  clock-names:
+    items:
+      - const: emc
+
+  interrupts:
+    items:
+      - description: EMC general interrupt
+
+  memory-region:
+    $ref: /schemas/types.yaml#/definitions/phandle
+    description:
+      phandle to a reserved memory region describing the table of EMC
+      frequencies trained by the firmware
+
+  nvidia,memory-controller:
+    $ref: /schemas/types.yaml#/definitions/phandle
+    description:
+      phandle of the memory controller node
+
+required:
+  - compatible
+  - reg
+  - clocks
+  - clock-names
+  - nvidia,memory-controller
+
+additionalProperties: false
+
+examples:
+  - |
+    #include <dt-bindings/clock/tegra210-car.h>
+    #include <dt-bindings/interrupt-controller/arm-gic.h>
+
+    reserved-memory {
+        #address-cells = <1>;
+        #size-cells = <1>;
+        ranges;
+
+        emc_table: emc-table@83400000 {
+            compatible = "nvidia,tegra210-emc-table";
+            reg = <0x83400000 0x10000>;
+        };
+    };
+
+    external-memory-controller@7001b000 {
+        compatible = "nvidia,tegra210-emc";
+        reg = <0x7001b000 0x1000>,
+              <0x7001e000 0x1000>,
+              <0x7001f000 0x1000>;
+        clocks = <&tegra_car TEGRA210_CLK_EMC>;
+        clock-names = "emc";
+        interrupts = <GIC_SPI 78 IRQ_TYPE_LEVEL_HIGH>;
+        memory-region = <&emc_table>;
+        nvidia,memory-controller = <&mc>;
+    };
Signature · 1 line
2.24.1
maintainer Applied
#23 lore raw

Re: [PATCH v6 08/14] dt-bindings: memory: tegra: Add external memory controller binding for Tegra210

Quoted 14 lines · Thierry Reding

From: Joseph Lo <[email protected]>

Add the binding document for the external memory controller (EMC) which communicates with external LPDDR4 devices. It includes the bindings of the EMC node and a sub-node of EMC table which under the reserved memory node. The EMC table contains the data of the rates that EMC supported.

---
Changes in v6:
- fix example by changing #address-cells and #size-cells
- remove status property from example

Quoted 7 lines

Changes in v5:
- convert to dt-schema

 .../nvidia,tegra210-emc.yaml                  | 82 +++++++++++++++++++
 1 file changed, 82 insertions(+)
 create mode 100644 Documentation/devicetree/bindings/memory-controllers/nvidia,tegra210-emc.yaml

Applied, thanks.

Rob

#24 lore raw

PATCH v6 9/14 memory: tegra: Add EMC scaling support code for Tegra210

In reply to Thierry Reding

From: Joseph Lo <[email protected]>

This is the initial patch for Tegra210 EMC frequency scaling. It has the code to program various aspects of the EMC that are standardized, but it does not yet include the specific programming sequence needed for clock scaling.

The driver is designed to support LPDDR4 SDRAM. Devices that use LPDDR4 need to perform training of the RAM before it can be used. Firmware will perform this training during early boot and pass a table of supported frequencies to the kernel via device tree.

For the frequencies above 800 MHz, periodic retraining is needed to compensate for changes in timing. This periodic training will have to be performed until the frequency drops back to or below 800 MHz.

This driver provides helpers used during this runtime retraining that will be used by the sequence specific code in a follow-up patch.

Based on work by Peter De Schrijver <[email protected]>.

---
Changes in v6:
- use __maybe_unused instead of #ifdef'ery for suspend/resume callbacks
- take exclusive control of EMC clock during suspend/resume
- move EMC driver changes from clk patch to this patch
- make the driver buildable as a module
- remove unnecessary suspend tracking
- remove duplicate register defines
- add tegra210-emc.h for Tegra210-specific registers
- detect number of channels, number of devices and DRAM type at probe time and store them in struct tegra210_emc, remove the corresponding function parameters where no longer needed
- properly clean up on failure

Changes in v5:
- major rework and cleanup

 drivers/memory/tegra/Kconfig              |   14 +
 drivers/memory/tegra/Makefile             |    4 +
 drivers/memory/tegra/mc.h                 |    1 +
 drivers/memory/tegra/tegra210-emc-core.c  | 1849 +++++++++++++++++++++
 drivers/memory/tegra/tegra210-emc-table.c |   61 +
 drivers/memory/tegra/tegra210-emc.h       |  902 ++++++++++
 drivers/memory/tegra/tegra210-mc.h        |   49 +
 7 files changed, 2880 insertions(+)
 create mode 100644 drivers/memory/tegra/tegra210-emc-core.c
 create mode 100644 drivers/memory/tegra/tegra210-emc-table.c
 create mode 100644 drivers/memory/tegra/tegra210-emc.h
 create mode 100644 drivers/memory/tegra/tegra210-mc.h
drivers/memory/tegra/Kconfig +14 -0
index fbfbaada61a2..9f0a96bf9ccc 100644
@@ -36,3 +36,17 @@ config TEGRA124_EMC
 	  Tegra124 chips. The EMC controls the external DRAM on the board.
 	  This driver is required to change memory timings / clock rate for
 	  external memory.
+
+config TEGRA210_EMC_TABLE
+	bool
+	depends on ARCH_TEGRA_210_SOC
+
+config TEGRA210_EMC
+	tristate "NVIDIA Tegra210 External Memory Controller driver"
+	depends on TEGRA_MC && ARCH_TEGRA_210_SOC
+	select TEGRA210_EMC_TABLE
+	help
+	  This driver is for the External Memory Controller (EMC) found on
+	  Tegra210 chips. The EMC controls the external DRAM on the board.
+	  This driver is required to change memory timings / clock rate for
+	  external memory.
drivers/memory/tegra/Makefile +4 -0
index 529d10bc5650..ad9406c0829b 100644
@@ -13,5 +13,9 @@ obj-$(CONFIG_TEGRA_MC) += tegra-mc.o
 obj-$(CONFIG_TEGRA20_EMC)  += tegra20-emc.o
 obj-$(CONFIG_TEGRA30_EMC)  += tegra30-emc.o
 obj-$(CONFIG_TEGRA124_EMC) += tegra124-emc.o
+obj-$(CONFIG_TEGRA210_EMC_TABLE) += tegra210-emc-table.o
+obj-$(CONFIG_TEGRA210_EMC) += tegra210-emc.o
 obj-$(CONFIG_ARCH_TEGRA_186_SOC) += tegra186.o tegra186-emc.o
 obj-$(CONFIG_ARCH_TEGRA_194_SOC) += tegra186.o tegra186-emc.o
+
+tegra210-emc-y := tegra210-emc-core.o
drivers/memory/tegra/mc.h +1 -0
index 957c6eb74ff9..afa3ba45c9e6 100644
@@ -34,6 +34,7 @@
 #define MC_EMEM_ARB_TIMING_W2W				0xbc
 #define MC_EMEM_ARB_TIMING_R2W				0xc0
 #define MC_EMEM_ARB_TIMING_W2R				0xc4
+#define MC_EMEM_ARB_MISC2				0xc8
 #define MC_EMEM_ARB_DA_TURNS				0xd0
 #define MC_EMEM_ARB_DA_COVERS				0xd4
 #define MC_EMEM_ARB_MISC0				0xd8
drivers/memory/tegra/tegra210-emc-core.c new file +1849 -0

1,849 lines not on this page · raw message

drivers/memory/tegra/tegra210-emc-table.c new file +61 -0

61 lines not on this page · raw message

drivers/memory/tegra/tegra210-emc.h new file +902 -0

902 lines not on this page · raw message

drivers/memory/tegra/tegra210-mc.h new file +49 -0

49 lines not on this page · raw message

Signature · 1 line
2.24.1
#25 lore raw

Re: [PATCH v6 09/14] memory: tegra: Add EMC scaling support code for Tegra210

09.04.2020 20:52, Thierry Reding пишет:
...

Quoted 33 lines
drivers/memory/tegra/tegra210-emc-core.c new file +33 -0
+static void tegra210_emc_debugfs_init(struct tegra210_emc *emc)
+{
+	struct device *dev = emc->dev;
+	unsigned int i;
+	int err;
+
+	emc->debugfs.min_rate = ULONG_MAX;
+	emc->debugfs.max_rate = 0;
+
+	for (i = 0; i < emc->num_timings; i++) {
+		if (emc->timings[i].rate * 1000UL < emc->debugfs.min_rate)
+			emc->debugfs.min_rate = emc->timings[i].rate * 1000UL;
+
+		if (emc->timings[i].rate * 1000UL > emc->debugfs.max_rate)
+			emc->debugfs.max_rate = emc->timings[i].rate * 1000UL;
+	}
+
+	if (!emc->num_timings) {
+		emc->debugfs.min_rate = clk_get_rate(emc->clk);
+		emc->debugfs.max_rate = emc->debugfs.min_rate;
+	}
+
+	err = clk_set_rate_range(emc->clk, emc->debugfs.min_rate,
+				 emc->debugfs.max_rate);
+	if (err < 0) {
+		dev_err(dev, "failed to set rate range [%lu-%lu] for %pC\n",
+			emc->debugfs.min_rate, emc->debugfs.max_rate,
+			emc->clk);
+		return;
+	}
+
+	emc->debugfs.root = debugfs_create_dir("emc", NULL);
+	if (!emc->debugfs.root) {

drivers/memory/tegra/tegra210-emc-core.c line 1556

Quoted 10 lines
drivers/memory/tegra/tegra210-emc-core.c new file +10 -0
+		dev_err(dev, "failed to create debugfs directory\n");
+		return;
+	}
+
+	debugfs_create_file("available_rates", S_IRUGO, emc->debugfs.root, emc,
+			    &tegra210_emc_debug_available_rates_fops);
+	debugfs_create_file("min_rate", S_IRUGO | S_IWUSR, emc->debugfs.root,
+			    emc, &tegra210_emc_debug_min_rate_fops);
+	debugfs_create_file("max_rate", S_IRUGO | S_IWUSR, emc->debugfs.root,
+			    emc, &tegra210_emc_debug_max_rate_fops);

I assume you used the checkpatch before sending the patches, no?

I sent out a patch recently to make the permissions readable, please take a look if you haven't seen it yet.

https://patchwork.ozlabs.org/patch/1254301/

#26 lore raw

Re: [PATCH v6 09/14] memory: tegra: Add EMC scaling support code for Tegra210

Quoted 39 lines · Dmitry Osipenko

09.04.2020 20:52, Thierry Reding пишет:
...

Quoted 37 lines
drivers/memory/tegra/tegra210-emc-core.c new file +37 -0
+static void tegra210_emc_debugfs_init(struct tegra210_emc *emc)
+{
+	struct device *dev = emc->dev;
+	unsigned int i;
+	int err;
+
+	emc->debugfs.min_rate = ULONG_MAX;
+	emc->debugfs.max_rate = 0;
+
+	for (i = 0; i < emc->num_timings; i++) {
+		if (emc->timings[i].rate * 1000UL < emc->debugfs.min_rate)
+			emc->debugfs.min_rate = emc->timings[i].rate * 1000UL;
+
+		if (emc->timings[i].rate * 1000UL > emc->debugfs.max_rate)
+			emc->debugfs.max_rate = emc->timings[i].rate * 1000UL;
+	}
+
+	if (!emc->num_timings) {
+		emc->debugfs.min_rate = clk_get_rate(emc->clk);
+		emc->debugfs.max_rate = emc->debugfs.min_rate;
+	}
+
+	err = clk_set_rate_range(emc->clk, emc->debugfs.min_rate,
+				 emc->debugfs.max_rate);
+	if (err < 0) {
+		dev_err(dev, "failed to set rate range [%lu-%lu] for %pC\n",
+			emc->debugfs.min_rate, emc->debugfs.max_rate,
+			emc->clk);
+		return;
+	}
+
+	emc->debugfs.root = debugfs_create_dir("emc", NULL);
+	if (!emc->debugfs.root) {
+		dev_err(dev, "failed to create debugfs directory\n");
+		return;
+	}
+
Quoted 8 lines

drivers/memory/tegra/tegra210-emc-core.c line 1556

Quoted 6 lines
drivers/memory/tegra/tegra210-emc-core.c new file +6 -0
+	debugfs_create_file("available_rates", S_IRUGO, emc->debugfs.root, emc,
+			    &tegra210_emc_debug_available_rates_fops);
+	debugfs_create_file("min_rate", S_IRUGO | S_IWUSR, emc->debugfs.root,
+			    emc, &tegra210_emc_debug_min_rate_fops);
+	debugfs_create_file("max_rate", S_IRUGO | S_IWUSR, emc->debugfs.root,
+			    emc, &tegra210_emc_debug_max_rate_fops);

I assume you used the checkpatch before sending the patches, no?

I have a pre-commit hook that runs checkpatch, but for some reason it was disabled. Fixed these to be numeric now.

Quoted 4 lines

I sent out a patch recently to make the permissions readable, please take a look if you haven't seen it yet.

https://patchwork.ozlabs.org/patch/1254301/

I've applied this now.

Thierry

#27 lore raw

Re: [PATCH v6 09/14] memory: tegra: Add EMC scaling support code for Tegra210

In reply to Thierry Reding

09.04.2020 20:52, Thierry Reding пишет:
...

drivers/memory/tegra/tegra210-emc-core.c line 1354

Quoted 12 lines
drivers/memory/tegra/tegra210-emc-core.c new file +12 -0
+static int tegra210_emc_set_rate(struct device *dev,
+				 const struct tegra210_clk_emc_config *config)
+{
+	struct tegra210_emc *emc = dev_get_drvdata(dev);
+	struct tegra210_emc_timing *timing = NULL;
+	unsigned long rate = config->rate;
+	s64 last_change_delay;
+	unsigned long flags;
+	unsigned int i;
+
+	if (rate == emc->last->rate * 1000UL)
+		return 0;

Couldn't all the rates be expressed in Hz? Then you won't need all these multiplications by 1000.

Quoted 19 lines
drivers/memory/tegra/tegra210-emc-core.c new file +19 -0
+	for (i = 0; i < emc->num_timings; i++) {
+		if (emc->timings[i].rate * 1000UL == rate) {
+			timing = &emc->timings[i];
+			break;
+		}
+	}
+
+	if (!timing)
+		return -EINVAL;
+
+	if (rate > 204000000 && !timing->trained)
+		return -EINVAL;
+
+	emc->next = timing;
+	last_change_delay = ktime_us_delta(ktime_get(), emc->clkchange_time);
+
+	/* XXX use non-busy-looping sleep? */
+	if ((last_change_delay >= 0) &&
+	    (last_change_delay < emc->clkchange_delay))

drivers/memory/tegra/tegra210-emc-core.c line 1384

Quoted 10 lines
drivers/memory/tegra/tegra210-emc-core.c new file +10 -0
+		udelay(emc->clkchange_delay - (int)last_change_delay);
+
+	spin_lock_irqsave(&emc->lock, flags);
+	tegra210_emc_set_clock(emc, config->value);
+	emc->clkchange_time = ktime_get();
+	emc->last = timing;
+	spin_unlock_irqrestore(&emc->lock, flags);
+
+	return 0;
+}

I'd suggest to check how much time invocation of ktime_get() takes, at least it came to a surprise to me in a case of the tegra-cpuidle driver.

It may be well over the emc->clkchange_delay.

...

Quoted 2 lines
drivers/memory/tegra/tegra210-emc-core.c new file +2 -0
+static int tegra210_emc_probe(struct platform_device *pdev)
+{

...

drivers/memory/tegra/tegra210-emc-core.c line 1752

Quoted 2 lines
drivers/memory/tegra/tegra210-emc-core.c new file +2 -0
+	emc->clkchange_delay = 100;
+	emc->training_interval = 100;

Not sure why these aren't a constant with the code.. ?

#28 lore raw

Re: [PATCH v6 09/14] memory: tegra: Add EMC scaling support code for Tegra210

Quoted 17 lines · Dmitry Osipenko

09.04.2020 20:52, Thierry Reding пишет:
...

drivers/memory/tegra/tegra210-emc-core.c line 1354

Quoted 12 lines
drivers/memory/tegra/tegra210-emc-core.c new file +12 -0
+static int tegra210_emc_set_rate(struct device *dev,
+				 const struct tegra210_clk_emc_config *config)
+{
+	struct tegra210_emc *emc = dev_get_drvdata(dev);
+	struct tegra210_emc_timing *timing = NULL;
+	unsigned long rate = config->rate;
+	s64 last_change_delay;
+	unsigned long flags;
+	unsigned int i;
+
+	if (rate == emc->last->rate * 1000UL)
+		return 0;

Couldn't all the rates be expressed in Hz? Then you won't need all these multiplications by 1000.

The EMC table is generated with kHz and I'd rather not change the values in those entries. There's only a few cases where we need to convert from one to the other, and they are always only when we compare a CCF rate to the EMC rate, so I think it's fairly explicit when it's needed.

Quoted 33 lines
Quoted 19 lines
drivers/memory/tegra/tegra210-emc-core.c new file +19 -0
+	for (i = 0; i < emc->num_timings; i++) {
+		if (emc->timings[i].rate * 1000UL == rate) {
+			timing = &emc->timings[i];
+			break;
+		}
+	}
+
+	if (!timing)
+		return -EINVAL;
+
+	if (rate > 204000000 && !timing->trained)
+		return -EINVAL;
+
+	emc->next = timing;
+	last_change_delay = ktime_us_delta(ktime_get(), emc->clkchange_time);
+
+	/* XXX use non-busy-looping sleep? */
+	if ((last_change_delay >= 0) &&
+	    (last_change_delay < emc->clkchange_delay))

drivers/memory/tegra/tegra210-emc-core.c line 1384

Quoted 10 lines
drivers/memory/tegra/tegra210-emc-core.c new file +10 -0
+		udelay(emc->clkchange_delay - (int)last_change_delay);
+
+	spin_lock_irqsave(&emc->lock, flags);
+	tegra210_emc_set_clock(emc, config->value);
+	emc->clkchange_time = ktime_get();
+	emc->last = timing;
+	spin_unlock_irqrestore(&emc->lock, flags);
+
+	return 0;
+}

I'd suggest to check how much time invocation of ktime_get() takes, at least it came to a surprise to me in a case of the tegra-cpuidle driver.

Quoted 1 line

It may be well over the emc->clkchange_delay.

I assume that at least each invocation would take roughly the same amount of time? Since we only use the value to compute the time since the last clock change the result should always be valid. In the worst case if ktime_get() really takes that long we may be waiting longer than we need to, but that wouldn't be all that bad either. Changing the EMC clock rate isn't something that you want to do a lot.

Quoted 8 lines

...

Quoted 2 lines
drivers/memory/tegra/tegra210-emc-core.c new file +2 -0
+static int tegra210_emc_probe(struct platform_device *pdev)
+{

...

drivers/memory/tegra/tegra210-emc-core.c line 1752

Quoted 2 lines
drivers/memory/tegra/tegra210-emc-core.c new file +2 -0
+	emc->clkchange_delay = 100;
+	emc->training_interval = 100;

Not sure why these aren't a constant with the code.. ?

The idea is to make them easily tunable without having to go hunt for them later on. We don't use them in a lot of computations, so making them constants isn't going to buy us a lot. Also, none of these code paths are really hot, so I like the flexibility that this gives us in being able to quickly tweak if we ever need to without having to worry that we'll forget a location.

Thierry

#29 lore raw

Re: [PATCH v6 09/14] memory: tegra: Add EMC scaling support code for Tegra210

14.04.2020 17:54, Thierry Reding пишет:
...

Quoted 7 lines
Quoted 4 lines

I'd suggest to check how much time invocation of ktime_get() takes, at least it came to a surprise to me in a case of the tegra-cpuidle driver.

It may be well over the emc->clkchange_delay.

I assume that at least each invocation would take roughly the same amount of time?

Not sure.

Quoted 5 lines

Since we only use the value to compute the time since
the last clock change the result should always be valid. In the worst case if ktime_get() really takes that long we may be waiting longer than we need to, but that wouldn't be all that bad either. Changing the EMC clock rate isn't something that you want to do a lot.

Then probably should be cleaner and simpler to have a constant delay in the code?

#30 lore raw

Re: [PATCH v6 09/14] memory: tegra: Add EMC scaling support code for Tegra210

In reply to Thierry Reding

09.04.2020 20:52, Thierry Reding пишет:
...

Quoted 1 line

+#define CLK_RST_CONTROLLER_CLK_SOURCE_EMC 0x19c

...

Quoted 1 line

+#define CLK_RST_CONTROLLER_CLK_SOURCE_EMC_DLL 0x664

I'd suggest to double check all the macros and remove everything unused, to not pollute the code.

...

Quoted 15 lines
drivers/memory/tegra/tegra210-emc-core.c new file +15 -0
+#define TRIM_REG(chan, rank, reg, byte)					\
+	(((EMC_PMACRO_OB_DDLL_LONG_DQ_RANK ## rank ## _ ## reg ##	\
+	   _OB_DDLL_LONG_DQ_RANK ## rank ## _BYTE ## byte ## _MASK &	\
+	   next->trim_regs[EMC_PMACRO_OB_DDLL_LONG_DQ_RANK ##		\
+				 rank ## _ ## reg ## _INDEX]) >>	\
+	  EMC_PMACRO_OB_DDLL_LONG_DQ_RANK ## rank ## _ ## reg ##	\
+	  _OB_DDLL_LONG_DQ_RANK ## rank ## _BYTE ## byte ## _SHIFT)	\
+	 +								\
+	 (((EMC_DATA_BRLSHFT_ ## rank ## _RANK ## rank ## _BYTE ##	\
+	    byte ## _DATA_BRLSHFT_MASK &				\
+	    next->trim_perch_regs[EMC ## chan ##			\
+			      _EMC_DATA_BRLSHFT_ ## rank ## _INDEX]) >>	\
+	   EMC_DATA_BRLSHFT_ ## rank ## _RANK ## rank ## _BYTE ##	\
+	   byte ## _DATA_BRLSHFT_SHIFT) * 64))
+

drivers/memory/tegra/tegra210-emc-core.c line 79

Quoted 10 lines
drivers/memory/tegra/tegra210-emc-core.c new file +10 -0
+#define CALC_TEMP(rank, reg, byte1, byte2, n)				\
+	(((new[n] << EMC_PMACRO_OB_DDLL_LONG_DQ_RANK ## rank ## _ ##	\
+	   reg ## _OB_DDLL_LONG_DQ_RANK ## rank ## _BYTE ## byte1 ## _SHIFT) & \
+	  EMC_PMACRO_OB_DDLL_LONG_DQ_RANK ## rank ## _ ## reg ##	\
+	  _OB_DDLL_LONG_DQ_RANK ## rank ## _BYTE ## byte1 ## _MASK)	\
+	 |								\
+	 ((new[n + 1] << EMC_PMACRO_OB_DDLL_LONG_DQ_RANK ## rank ## _ ##\
+	   reg ## _OB_DDLL_LONG_DQ_RANK ## rank ## _BYTE ## byte2 ## _SHIFT) & \
+	  EMC_PMACRO_OB_DDLL_LONG_DQ_RANK ## rank ## _ ## reg ##	\
+	  _OB_DDLL_LONG_DQ_RANK ## rank ## _BYTE ## byte2 ## _MASK))

My eyes.. :P

#31 lore raw

Re: [PATCH v6 09/14] memory: tegra: Add EMC scaling support code for Tegra210

Quoted 18 lines

...

Quoted 17 lines
drivers/memory/tegra/tegra210-emc-core.c new file +17 -0
+#define TRIM_REG(chan, rank, reg, byte)					\
+	(((EMC_PMACRO_OB_DDLL_LONG_DQ_RANK ## rank ## _ ## reg ##	\
+	   _OB_DDLL_LONG_DQ_RANK ## rank ## _BYTE ## byte ## _MASK &	\
+	   next->trim_regs[EMC_PMACRO_OB_DDLL_LONG_DQ_RANK ##		\
+				 rank ## _ ## reg ## _INDEX]) >>	\
+	  EMC_PMACRO_OB_DDLL_LONG_DQ_RANK ## rank ## _ ## reg ##	\
+	  _OB_DDLL_LONG_DQ_RANK ## rank ## _BYTE ## byte ## _SHIFT)	\
+	 +								\
+	 (((EMC_DATA_BRLSHFT_ ## rank ## _RANK ## rank ## _BYTE ##	\
+	    byte ## _DATA_BRLSHFT_MASK &				\
+	    next->trim_perch_regs[EMC ## chan ##			\
+			      _EMC_DATA_BRLSHFT_ ## rank ## _INDEX]) >>	\
+	   EMC_DATA_BRLSHFT_ ## rank ## _RANK ## rank ## _BYTE ##	\
+	   byte ## _DATA_BRLSHFT_SHIFT) * 64))
+
+#define CALC_TEMP(rank, reg, byte1, byte2, n)				\
+	(((new[n] << EMC_PMACRO_OB_DDLL_LONG_DQ_RANK ## rank ## _ ##	\
Quoted 8 lines

drivers/memory/tegra/tegra210-emc-core.c line 79

Quoted 8 lines
drivers/memory/tegra/tegra210-emc-core.c new file +8 -0
+	   reg ## _OB_DDLL_LONG_DQ_RANK ## rank ## _BYTE ## byte1 ## _SHIFT) & \
+	  EMC_PMACRO_OB_DDLL_LONG_DQ_RANK ## rank ## _ ## reg ##	\
+	  _OB_DDLL_LONG_DQ_RANK ## rank ## _BYTE ## byte1 ## _MASK)	\
+	 |								\
+	 ((new[n + 1] << EMC_PMACRO_OB_DDLL_LONG_DQ_RANK ## rank ## _ ##\
+	   reg ## _OB_DDLL_LONG_DQ_RANK ## rank ## _BYTE ## byte2 ## _SHIFT) & \
+	  EMC_PMACRO_OB_DDLL_LONG_DQ_RANK ## rank ## _ ## reg ##	\
+	  _OB_DDLL_LONG_DQ_RANK ## rank ## _BYTE ## byte2 ## _MASK))

What about replacing those barely readable concatenated macros with a raw values?

Like:

TRIM_REG(brlshft_idx, ob_ddll_long_dq_rank_mask, ...)

#32 lore raw

Re: [PATCH v6 09/14] memory: tegra: Add EMC scaling support code for Tegra210

Quoted 30 lines · Dmitry Osipenko
Quoted 18 lines

...

Quoted 17 lines
drivers/memory/tegra/tegra210-emc-core.c new file +17 -0
+#define TRIM_REG(chan, rank, reg, byte)					\
+	(((EMC_PMACRO_OB_DDLL_LONG_DQ_RANK ## rank ## _ ## reg ##	\
+	   _OB_DDLL_LONG_DQ_RANK ## rank ## _BYTE ## byte ## _MASK &	\
+	   next->trim_regs[EMC_PMACRO_OB_DDLL_LONG_DQ_RANK ##		\
+				 rank ## _ ## reg ## _INDEX]) >>	\
+	  EMC_PMACRO_OB_DDLL_LONG_DQ_RANK ## rank ## _ ## reg ##	\
+	  _OB_DDLL_LONG_DQ_RANK ## rank ## _BYTE ## byte ## _SHIFT)	\
+	 +								\
+	 (((EMC_DATA_BRLSHFT_ ## rank ## _RANK ## rank ## _BYTE ##	\
+	    byte ## _DATA_BRLSHFT_MASK &				\
+	    next->trim_perch_regs[EMC ## chan ##			\
+			      _EMC_DATA_BRLSHFT_ ## rank ## _INDEX]) >>	\
+	   EMC_DATA_BRLSHFT_ ## rank ## _RANK ## rank ## _BYTE ##	\
+	   byte ## _DATA_BRLSHFT_SHIFT) * 64))
+
+#define CALC_TEMP(rank, reg, byte1, byte2, n)				\
+	(((new[n] << EMC_PMACRO_OB_DDLL_LONG_DQ_RANK ## rank ## _ ##	\
Quoted 8 lines

drivers/memory/tegra/tegra210-emc-core.c line 79

Quoted 8 lines
drivers/memory/tegra/tegra210-emc-core.c new file +8 -0
+	   reg ## _OB_DDLL_LONG_DQ_RANK ## rank ## _BYTE ## byte1 ## _SHIFT) & \
+	  EMC_PMACRO_OB_DDLL_LONG_DQ_RANK ## rank ## _ ## reg ##	\
+	  _OB_DDLL_LONG_DQ_RANK ## rank ## _BYTE ## byte1 ## _MASK)	\
+	 |								\
+	 ((new[n + 1] << EMC_PMACRO_OB_DDLL_LONG_DQ_RANK ## rank ## _ ##\
+	   reg ## _OB_DDLL_LONG_DQ_RANK ## rank ## _BYTE ## byte2 ## _SHIFT) & \
+	  EMC_PMACRO_OB_DDLL_LONG_DQ_RANK ## rank ## _ ## reg ##	\
+	  _OB_DDLL_LONG_DQ_RANK ## rank ## _BYTE ## byte2 ## _MASK))

What about replacing those barely readable concatenated macros with a raw values?

Quoted 3 lines

Like:

TRIM_REG(brlshft_idx, ob_ddll_long_dq_rank_mask, ...)

That's just going to move the complexity from the macros to the callsites, isn't it?

I suppose I could spend a few cycles trying to make this a little more readable, but to be frank, the complexity in this driver is already so high that this doesn't really make much of a difference, in my opinion.

Thierry

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#33 lore raw

Re: [PATCH v6 09/14] memory: tegra: Add EMC scaling support code for Tegra210

14.04.2020 18:05, Thierry Reding пишет:
...

Quoted 5 lines
Quoted 5 lines

What about replacing those barely readable concatenated macros with a raw values?

Like:

Quoted 8 lines
Quoted 1 line

TRIM_REG(brlshft_idx, ob_ddll_long_dq_rank_mask, ...)

That's just going to move the complexity from the macros to the callsites, isn't it?

I suppose I could spend a few cycles trying to make this a little more readable, but to be frank, the complexity in this driver is already so high that this doesn't really make much of a difference, in my opinion.

I can't guarantee that the final result will be excellent, but I'd try to turn that macro into the function and then use the raw HW values instead of the defines. It looks to me that the result at least should be better.

#34 lore raw

Re: [PATCH v6 09/14] memory: tegra: Add EMC scaling support code for Tegra210

In reply to Dmitry Osipenko
Quoted 8 lines · Dmitry Osipenko

09.04.2020 20:52, Thierry Reding пишет:
...

Quoted 1 line

+#define CLK_RST_CONTROLLER_CLK_SOURCE_EMC 0x19c

...

Quoted 1 line

+#define CLK_RST_CONTROLLER_CLK_SOURCE_EMC_DLL 0x664

I'd suggest to double check all the macros and remove everything unused, to not pollute the code.

I recall checking most of these, but I'll make another pass to see if I can spot more that I can drop.

Quoted 20 lines

...

Quoted 19 lines
drivers/memory/tegra/tegra210-emc-core.c new file +19 -0
+#define TRIM_REG(chan, rank, reg, byte)					\
+	(((EMC_PMACRO_OB_DDLL_LONG_DQ_RANK ## rank ## _ ## reg ##	\
+	   _OB_DDLL_LONG_DQ_RANK ## rank ## _BYTE ## byte ## _MASK &	\
+	   next->trim_regs[EMC_PMACRO_OB_DDLL_LONG_DQ_RANK ##		\
+				 rank ## _ ## reg ## _INDEX]) >>	\
+	  EMC_PMACRO_OB_DDLL_LONG_DQ_RANK ## rank ## _ ## reg ##	\
+	  _OB_DDLL_LONG_DQ_RANK ## rank ## _BYTE ## byte ## _SHIFT)	\
+	 +								\
+	 (((EMC_DATA_BRLSHFT_ ## rank ## _RANK ## rank ## _BYTE ##	\
+	    byte ## _DATA_BRLSHFT_MASK &				\
+	    next->trim_perch_regs[EMC ## chan ##			\
+			      _EMC_DATA_BRLSHFT_ ## rank ## _INDEX]) >>	\
+	   EMC_DATA_BRLSHFT_ ## rank ## _RANK ## rank ## _BYTE ##	\
+	   byte ## _DATA_BRLSHFT_SHIFT) * 64))
+
+#define CALC_TEMP(rank, reg, byte1, byte2, n)				\
+	(((new[n] << EMC_PMACRO_OB_DDLL_LONG_DQ_RANK ## rank ## _ ##	\
+	   reg ## _OB_DDLL_LONG_DQ_RANK ## rank ## _BYTE ## byte1 ## _SHIFT) & \
+	  EMC_PMACRO_OB_DDLL_LONG_DQ_RANK ## rank ## _ ## reg ##	\
Quoted 8 lines

drivers/memory/tegra/tegra210-emc-core.c line 79

Quoted 6 lines
drivers/memory/tegra/tegra210-emc-core.c new file +6 -0
+	  _OB_DDLL_LONG_DQ_RANK ## rank ## _BYTE ## byte1 ## _MASK)	\
+	 |								\
+	 ((new[n + 1] << EMC_PMACRO_OB_DDLL_LONG_DQ_RANK ## rank ## _ ##\
+	   reg ## _OB_DDLL_LONG_DQ_RANK ## rank ## _BYTE ## byte2 ## _SHIFT) & \
+	  EMC_PMACRO_OB_DDLL_LONG_DQ_RANK ## rank ## _ ## reg ##	\
+	  _OB_DDLL_LONG_DQ_RANK ## rank ## _BYTE ## byte2 ## _MASK))

My eyes.. :P

Heh... yes, this is pretty bad. At least the code at the callsites is clean.

Thierry

#35 lore raw

Re: [PATCH v6 09/14] memory: tegra: Add EMC scaling support code for Tegra210

In reply to Thierry Reding

09.04.2020 20:52, Thierry Reding пишет:
...

drivers/memory/tegra/tegra210-emc-core.c line 1777

Quoted 6 lines
drivers/memory/tegra/tegra210-emc-core.c new file +6 -0
+static int tegra210_emc_remove(struct platform_device *pdev)
+{
+	struct tegra210_emc *emc = platform_get_drvdata(pdev);
+
+	debugfs_remove_recursive(emc->debugfs.root);
+	tegra210_clk_emc_detach(emc->clk);

It's great that you want to make this driver modular, but I don't think that it's a good idea to suddenly rip off the EMC clock from the users.

It should be better to simply disallow unloading of this driver once it's loaded.

#36 lore raw

Re: [PATCH v6 09/14] memory: tegra: Add EMC scaling support code for Tegra210

Quoted 12 lines · Dmitry Osipenko

09.04.2020 20:52, Thierry Reding пишет:
...

drivers/memory/tegra/tegra210-emc-core.c line 1777

Quoted 6 lines
drivers/memory/tegra/tegra210-emc-core.c new file +6 -0
+static int tegra210_emc_remove(struct platform_device *pdev)
+{
+	struct tegra210_emc *emc = platform_get_drvdata(pdev);
+
+	debugfs_remove_recursive(emc->debugfs.root);
+	tegra210_clk_emc_detach(emc->clk);

It's great that you want to make this driver modular, but I don't think that it's a good idea to suddenly rip off the EMC clock from the users.

Quoted 2 lines

It should be better to simply disallow unloading of this driver once it's loaded.

That's not what we're doing. The clock is going to stay around and users will be able to access it. The only thing that the above does is take away the possibility to change the rate of the EMC clock.

So I think this actually makes this really nice both for testing that unload/reload works and it also gives users an easy way to disable EMC frequency scaling by simply blacklisting the module.

Thierry

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#37 lore raw

Re: [PATCH v6 09/14] memory: tegra: Add EMC scaling support code for Tegra210

In reply to Thierry Reding

09.04.2020 20:52, Thierry Reding пишет:

Quoted 4 lines
drivers/memory/tegra/tegra210-emc-table.c new file +4 -0
+static int tegra210_emc_table_device_init(struct reserved_mem *rmem,
+					  struct device *dev)
+{
+	struct tegra210_emc *emc = dev_get_drvdata(dev);

drivers/memory/tegra/tegra210-emc-table.c line 25

Quoted 10 lines
drivers/memory/tegra/tegra210-emc-table.c new file +10 -0
+	unsigned int i;
+	void *table;
+
+	table = memremap(rmem->base, rmem->size, MEMREMAP_WB);
+	if (!table) {
+		dev_err(dev, "failed to map EMC table\n");
+		return -ENOMEM;
+	}
+
+	emc->timings = (struct tegra210_emc_timing *)table;

No need to cast the void.

#38 lore raw

Re: [PATCH v6 09/14] memory: tegra: Add EMC scaling support code for Tegra210

Quoted 17 lines · Dmitry Osipenko

09.04.2020 20:52, Thierry Reding пишет:

Quoted 4 lines
drivers/memory/tegra/tegra210-emc-table.c new file +4 -0
+static int tegra210_emc_table_device_init(struct reserved_mem *rmem,
+					  struct device *dev)
+{
+	struct tegra210_emc *emc = dev_get_drvdata(dev);

drivers/memory/tegra/tegra210-emc-table.c line 25

Quoted 10 lines
drivers/memory/tegra/tegra210-emc-table.c new file +10 -0
+	unsigned int i;
+	void *table;
+
+	table = memremap(rmem->base, rmem->size, MEMREMAP_WB);
+	if (!table) {
+		dev_err(dev, "failed to map EMC table\n");
+		return -ENOMEM;
+	}
+
+	emc->timings = (struct tegra210_emc_timing *)table;

No need to cast the void.

Indeed, looks like I can get rid of that table variable altogether.

Thierry

#39 lore raw

Re: [PATCH v6 09/14] memory: tegra: Add EMC scaling support code for Tegra210

In reply to Thierry Reding

09.04.2020 20:52, Thierry Reding пишет:
...

Quoted 14 lines

---
Changes in v6:
- use __maybe_unused instead of #ifdef'ery for suspend/resume callbacks
- take exclusive control of EMC clock during suspend/resume
- move EMC driver changes from clk patch to this patch
- make the driver buildable as a module
- remove unnecessary suspend tracking
- remove duplicate register defines
- add tegra210-emc.h for Tegra210-specific registers
- detect number of channels, number of devices and DRAM type at probe time and store them in struct tegra210_emc, remove the corresponding function parameters where no longer needed
- properly clean up on failure

Quoted 2 lines

Changes in v5:
- major rework and cleanup

I happened to notice that the patches have an individual changelog only by accident :)

Next time will be nice if at least you could mention about this in the cover-letter, or move (or duplicate) the whole log in the cover-letter.

#40 lore raw

Re: [PATCH v6 09/14] memory: tegra: Add EMC scaling support code for Tegra210

Quoted 16 lines · Dmitry Osipenko

09.04.2020 20:52, Thierry Reding пишет:
...

Quoted 14 lines

---
Changes in v6:
- use __maybe_unused instead of #ifdef'ery for suspend/resume callbacks
- take exclusive control of EMC clock during suspend/resume
- move EMC driver changes from clk patch to this patch
- make the driver buildable as a module
- remove unnecessary suspend tracking
- remove duplicate register defines
- add tegra210-emc.h for Tegra210-specific registers
- detect number of channels, number of devices and DRAM type at probe time and store them in struct tegra210_emc, remove the corresponding function parameters where no longer needed
- properly clean up on failure

Quoted 8 lines
Quoted 2 lines

Changes in v5:
- major rework and cleanup

I happened to notice that the patches have an individual changelog only by accident :)

Next time will be nice if at least you could mention about this in the cover-letter, or move (or duplicate) the whole log in the cover-letter.

Given the amount of changes that seemed a little impractical. I can try to give a high-level overview of the changes and perhaps mention in the cover letter that there will be individual changelogs for each patch.

Thierry

#41 lore raw

Re: [PATCH v6 09/14] memory: tegra: Add EMC scaling support code for Tegra210

In reply to Thierry Reding

09.04.2020 20:52, Thierry Reding пишет:
...

drivers/memory/tegra/tegra210-emc-core.c line 1354

Quoted 12 lines
drivers/memory/tegra/tegra210-emc-core.c new file +12 -0
+static int tegra210_emc_set_rate(struct device *dev,
+				 const struct tegra210_clk_emc_config *config)
+{
+	struct tegra210_emc *emc = dev_get_drvdata(dev);
+	struct tegra210_emc_timing *timing = NULL;
+	unsigned long rate = config->rate;
+	s64 last_change_delay;
+	unsigned long flags;
+	unsigned int i;
+
+	if (rate == emc->last->rate * 1000UL)
+		return 0;

Isn't it possible that parent is changed, while the rate is not? I think the clock change should proceed in this case.

#42 lore raw

Re: [PATCH v6 09/14] memory: tegra: Add EMC scaling support code for Tegra210

In reply to Thierry Reding

09.04.2020 20:52, Thierry Reding пишет:
...

Quoted 24 lines
drivers/memory/tegra/tegra210-emc-core.c new file +24 -0
+static void tegra210_change_dll_src(struct tegra210_emc *emc,
+				    u32 clksrc)
+{
+	u32 dll_setting = emc->next->dll_clk_src;
+	u32 emc_clk_src;
+	u32 emc_clk_div;
+
+	emc_clk_src = (clksrc & EMC_CLK_EMC_2X_CLK_SRC_MASK) >>
+		       EMC_CLK_EMC_2X_CLK_SRC_SHIFT;
+	emc_clk_div = (clksrc & EMC_CLK_EMC_2X_CLK_DIVISOR_MASK) >>
+		       EMC_CLK_EMC_2X_CLK_DIVISOR_SHIFT;
+
+	dll_setting &= ~(DLL_CLK_EMC_DLL_CLK_SRC_MASK |
+			 DLL_CLK_EMC_DLL_CLK_DIVISOR_MASK);
+	dll_setting |= emc_clk_src << DLL_CLK_EMC_DLL_CLK_SRC_SHIFT;
+	dll_setting |= emc_clk_div << DLL_CLK_EMC_DLL_CLK_DIVISOR_SHIFT;
+
+	dll_setting &= ~DLL_CLK_EMC_DLL_DDLL_CLK_SEL_MASK;
+	if (emc_clk_src == EMC_CLK_SOURCE_PLLMB_LJ)
+		dll_setting |= (PLLM_VCOB <<
+				DLL_CLK_EMC_DLL_DDLL_CLK_SEL_SHIFT);
+	else if (emc_clk_src == EMC_CLK_SOURCE_PLLM_LJ)
+		dll_setting |= (PLLM_VCOA <<
+				DLL_CLK_EMC_DLL_DDLL_CLK_SEL_SHIFT);

drivers/memory/tegra/tegra210-emc-core.c line 625

Quoted 10 lines
drivers/memory/tegra/tegra210-emc-core.c new file +10 -0
+	else
+		dll_setting |= (EMC_DLL_SWITCH_OUT <<
+				DLL_CLK_EMC_DLL_DDLL_CLK_SEL_SHIFT);
+
+	tegra210_clk_emc_dll_update_setting(dll_setting);
+
+	if (emc->next->clk_out_enb_x_0_clk_enb_emc_dll)
+		tegra210_clk_emc_dll_enable(true);
+	else
+		tegra210_clk_emc_dll_enable(false);

Isn't something like fence_udelay(1) needed after touching clk registers?

#43 lore raw

Re: [PATCH v6 09/14] memory: tegra: Add EMC scaling support code for Tegra210

14.04.2020 23:46, Dmitry Osipenko пишет:

Quoted 30 lines

09.04.2020 20:52, Thierry Reding пишет:
...

Quoted 28 lines
drivers/memory/tegra/tegra210-emc-core.c new file +28 -0
+static void tegra210_change_dll_src(struct tegra210_emc *emc,
+				    u32 clksrc)
+{
+	u32 dll_setting = emc->next->dll_clk_src;
+	u32 emc_clk_src;
+	u32 emc_clk_div;
+
+	emc_clk_src = (clksrc & EMC_CLK_EMC_2X_CLK_SRC_MASK) >>
+		       EMC_CLK_EMC_2X_CLK_SRC_SHIFT;
+	emc_clk_div = (clksrc & EMC_CLK_EMC_2X_CLK_DIVISOR_MASK) >>
+		       EMC_CLK_EMC_2X_CLK_DIVISOR_SHIFT;
+
+	dll_setting &= ~(DLL_CLK_EMC_DLL_CLK_SRC_MASK |
+			 DLL_CLK_EMC_DLL_CLK_DIVISOR_MASK);
+	dll_setting |= emc_clk_src << DLL_CLK_EMC_DLL_CLK_SRC_SHIFT;
+	dll_setting |= emc_clk_div << DLL_CLK_EMC_DLL_CLK_DIVISOR_SHIFT;
+
+	dll_setting &= ~DLL_CLK_EMC_DLL_DDLL_CLK_SEL_MASK;
+	if (emc_clk_src == EMC_CLK_SOURCE_PLLMB_LJ)
+		dll_setting |= (PLLM_VCOB <<
+				DLL_CLK_EMC_DLL_DDLL_CLK_SEL_SHIFT);
+	else if (emc_clk_src == EMC_CLK_SOURCE_PLLM_LJ)
+		dll_setting |= (PLLM_VCOA <<
+				DLL_CLK_EMC_DLL_DDLL_CLK_SEL_SHIFT);
+	else
+		dll_setting |= (EMC_DLL_SWITCH_OUT <<
+				DLL_CLK_EMC_DLL_DDLL_CLK_SEL_SHIFT);
+
Quoted 9 lines

drivers/memory/tegra/tegra210-emc-core.c line 625

Quoted 6 lines
drivers/memory/tegra/tegra210-emc-core.c new file +6 -0
+	tegra210_clk_emc_dll_update_setting(dll_setting);
+
+	if (emc->next->clk_out_enb_x_0_clk_enb_emc_dll)
+		tegra210_clk_emc_dll_enable(true);
+	else
+		tegra210_clk_emc_dll_enable(false);

Isn't something like fence_udelay(1) needed after touching clk registers?

Won't be better to move this whole function into clk/tegra?

It feels a bit dirty that a raw clk pointer is passed to the EMC code. I'd factor all the clk functions into clk/tegra to have a clean separation of the code.

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#44 lore raw

PATCH v6 10/14 memory: tegra: Add EMC scaling sequence code for Tegra210

In reply to Thierry Reding

From: Joseph Lo <[email protected]>

This patch includes the sequence for clock tuning and the dynamic training mechanism for the clock above 800MHz.

And historically there have been different sequences to change the EMC clock. The sequence to be used is specified in the EMC table. However, for the currently supported upstreaming platform, only the most recent sequence is used. So only support that in this patch.

Based on the work of Peter De Schrijver <[email protected]>.

---
Changes in v6:
- factor some code out into the core driver

Changes in v5:
- major rework and cleanup

 drivers/memory/tegra/Makefile                 |    2 +-
 drivers/memory/tegra/tegra210-emc-cc-r21021.c | 1744 +++++++++++++++++
 drivers/memory/tegra/tegra210-emc-core.c      |    1 +
 drivers/memory/tegra/tegra210-emc.h           |  102 +
 4 files changed, 1848 insertions(+), 1 deletion(-)
 create mode 100644 drivers/memory/tegra/tegra210-emc-cc-r21021.c
drivers/memory/tegra/Makefile +1 -1
index ad9406c0829b..6c1a2ecc6628 100644
@@ -18,4 +18,4 @@ obj-$(CONFIG_TEGRA210_EMC) += tegra210-emc.o
 obj-$(CONFIG_ARCH_TEGRA_186_SOC) += tegra186.o tegra186-emc.o
 obj-$(CONFIG_ARCH_TEGRA_194_SOC) += tegra186.o tegra186-emc.o
 
-tegra210-emc-y := tegra210-emc-core.o
+tegra210-emc-y := tegra210-emc-core.o tegra210-emc-cc-r21021.o
drivers/memory/tegra/tegra210-emc-cc-r21021.c new file +1744 -0

1,744 lines not on this page · raw message

drivers/memory/tegra/tegra210-emc-core.c +1 -0
index 5aa08ce4c11b..080209bffe64 100644
@@ -82,6 +82,7 @@
 		(((value) & 0xffff0000) | ((value) & 0xffff) * (speedup))
 
 static const struct tegra210_emc_sequence *tegra210_emc_sequences[] = {
+	&tegra210_emc_r21021,
 };
 
 static const struct tegra210_emc_table_register_offsets
drivers/memory/tegra/tegra210-emc.h +102 -0

229 lines not on this page · raw message

Signature · 1 line
2.24.1
#45 lore raw

Re: [PATCH v6 10/14] memory: tegra: Add EMC scaling sequence code for Tegra210

09.04.2020 20:52, Thierry Reding пишет:
...

Quoted 26 lines
drivers/memory/tegra/tegra210-emc-cc-r21021.c new file +26 -0
+static void tegra210_emc_r21021_set_clock(struct tegra210_emc *emc, u32 clksrc)
+{
+	/*
+	 * This is the timing table for the source frequency. It does _not_
+	 * necessarily correspond to the actual timing values in the EMC at the
+	 * moment. If the boot BCT differs from the table then this can happen.
+	 * However, we need it for accessing the dram_timings (which are not
+	 * really registers) array for the current frequency.
+	 */
+	u32 tmp, cya_allow_ref_cc = 0, ref_b4_sref_en = 0, cya_issue_pc_ref = 0;
+	struct tegra210_emc_timing *fake, *last = emc->last, *next = emc->next;
+	u32 bg_regulator_switch_complete_wait_clks, bg_regulator_mode_change;
+	u32 opt_zcal_en_cc, opt_do_sw_qrst = 1, opt_dvfs_mode, opt_dll_mode;
+	u32 emc_zcal_wait_cnt_old, emc_zcal_wait_cnt_new, emc_dbg_active;
+	u32 opt_cc_short_zcal = 1, opt_short_zcal = 1, opt_war_200024907;
+	u32 tRTM, RP_war, R2P_war, TRPab_war, deltaTWATM, W2P_war, tRPST;
+	u32 adel = 0, compensate_trimmer_applicable = 0, mrw_req, value;
+	unsigned long next_timing_rate_mhz = next->rate / 1000, delay;
+	u32 tZQCAL_lpddr4 = 1000000, zq_wait_long, shared_zq_resistor;
+	s32 zq_latch_dvfs_wait_time, tZQCAL_lpddr4_fc_adj, nRTP;
+	u32 tFC_lpddr4 = 1000 * next->dram_timings[T_FC_LPDDR4];
+	u32 emc_auto_cal_config, auto_cal_en, mr13_catr_enable;
+	u32 zq_op, zcal_wait_time_clocks, zcal_wait_time_ps;
+	u32 emc_cfg, emc_sel_dpd_ctrl, emc_zcal_interval;
+	int next_push, next_dq_e_ivref, next_dqs_e_ivref;
+	u32 mr13_flip_fspwr, mr13_flip_fspop, is_lpddr3;

drivers/memory/tegra/tegra210-emc-cc-r21021.c line 621

Quoted 10 lines
drivers/memory/tegra/tegra210-emc-cc-r21021.c new file +10 -0
+	u32 enable_bglp_regulator, enable_bg_regulator;
+	u32 emc_dbg_o, emc_cfg_pipe_clk_o, emc_pin_o;
+	u32 ramp_up_wait = 0, ramp_down_wait = 0;
+	u32 save_restore_clkstop_pd = 1, dll_out;
+	u32 ref_delay_mult, ref_delay, dram_type;
+	static u32 fsp_for_next_freq;
+	/* In picoseconds. */
+	u32 source_clock_period, destination_clock_period;
+	u32 zqcal_before_cc_cutoff = 2400;
+	unsigned int i;

What about to try to replace this massive egyptian construction with a single "u32 val;" ?

...

drivers/memory/tegra/tegra210-emc-cc-r21021.c line 646

Quoted 2 lines
drivers/memory/tegra/tegra210-emc-cc-r21021.c new file +2 -0
+	emc_readl(emc, EMC_CFG);
+	emc_auto_cal_config = emc_readl(emc, EMC_AUTO_CAL_CONFIG);

And remove all the "dummy" variable assigns in the code?

...

Quoted 1 line

emc_auto_cal_config = next->emc_auto_cal_config;

...> + emc_zcal_interval = 0;

And replace all "constant" variables with a raw value in place in the code?

#46 lore raw

Re: [PATCH v6 10/14] memory: tegra: Add EMC scaling sequence code for Tegra210

Quoted 33 lines · Dmitry Osipenko

09.04.2020 20:52, Thierry Reding пишет:
...

Quoted 31 lines
drivers/memory/tegra/tegra210-emc-cc-r21021.c new file +31 -0
+static void tegra210_emc_r21021_set_clock(struct tegra210_emc *emc, u32 clksrc)
+{
+	/*
+	 * This is the timing table for the source frequency. It does _not_
+	 * necessarily correspond to the actual timing values in the EMC at the
+	 * moment. If the boot BCT differs from the table then this can happen.
+	 * However, we need it for accessing the dram_timings (which are not
+	 * really registers) array for the current frequency.
+	 */
+	u32 tmp, cya_allow_ref_cc = 0, ref_b4_sref_en = 0, cya_issue_pc_ref = 0;
+	struct tegra210_emc_timing *fake, *last = emc->last, *next = emc->next;
+	u32 bg_regulator_switch_complete_wait_clks, bg_regulator_mode_change;
+	u32 opt_zcal_en_cc, opt_do_sw_qrst = 1, opt_dvfs_mode, opt_dll_mode;
+	u32 emc_zcal_wait_cnt_old, emc_zcal_wait_cnt_new, emc_dbg_active;
+	u32 opt_cc_short_zcal = 1, opt_short_zcal = 1, opt_war_200024907;
+	u32 tRTM, RP_war, R2P_war, TRPab_war, deltaTWATM, W2P_war, tRPST;
+	u32 adel = 0, compensate_trimmer_applicable = 0, mrw_req, value;
+	unsigned long next_timing_rate_mhz = next->rate / 1000, delay;
+	u32 tZQCAL_lpddr4 = 1000000, zq_wait_long, shared_zq_resistor;
+	s32 zq_latch_dvfs_wait_time, tZQCAL_lpddr4_fc_adj, nRTP;
+	u32 tFC_lpddr4 = 1000 * next->dram_timings[T_FC_LPDDR4];
+	u32 emc_auto_cal_config, auto_cal_en, mr13_catr_enable;
+	u32 zq_op, zcal_wait_time_clocks, zcal_wait_time_ps;
+	u32 emc_cfg, emc_sel_dpd_ctrl, emc_zcal_interval;
+	int next_push, next_dq_e_ivref, next_dqs_e_ivref;
+	u32 mr13_flip_fspwr, mr13_flip_fspop, is_lpddr3;
+	u32 enable_bglp_regulator, enable_bg_regulator;
+	u32 emc_dbg_o, emc_cfg_pipe_clk_o, emc_pin_o;
+	u32 ramp_up_wait = 0, ramp_down_wait = 0;
+	u32 save_restore_clkstop_pd = 1, dll_out;
+	u32 ref_delay_mult, ref_delay, dram_type;
Quoted 8 lines

drivers/memory/tegra/tegra210-emc-cc-r21021.c line 621

Quoted 5 lines
drivers/memory/tegra/tegra210-emc-cc-r21021.c new file +5 -0
+	static u32 fsp_for_next_freq;
+	/* In picoseconds. */
+	u32 source_clock_period, destination_clock_period;
+	u32 zqcal_before_cc_cutoff = 2400;
+	unsigned int i;

What about to try to replace this massive egyptian construction with a single "u32 val;" ?

I actually tried that after condensing what this used to look like into the above. The result was a huge failure because some of these temporary values end up being reused, so I ended up writing bogus values into some of these registers.

Quoted 10 lines

drivers/memory/tegra/tegra210-emc-cc-r21021.c line 646

Quoted 2 lines
drivers/memory/tegra/tegra210-emc-cc-r21021.c new file +2 -0
+	emc_readl(emc, EMC_CFG);
+	emc_auto_cal_config = emc_readl(emc, EMC_AUTO_CAL_CONFIG);

And remove all the "dummy" variable assigns in the code?

...

Quoted 1 line

emc_auto_cal_config = next->emc_auto_cal_config;

...> + emc_zcal_interval = 0;

And replace all "constant" variables with a raw value in place in the code?

Okay, I'll give this another try, hopefully this time I won't run into the same problems as earlier.

Thierry

#47 lore raw

Re: [PATCH v6 10/14] memory: tegra: Add EMC scaling sequence code for Tegra210

14.04.2020 18:45, Thierry Reding пишет:
...

Quoted 7 lines
Quoted 2 lines

What about to try to replace this massive egyptian construction with a single "u32 val;" ?

I actually tried that after condensing what this used to look like into the above. The result was a huge failure because some of these temporary values end up being reused, so I ended up writing bogus values into some of these registers.

It should be fine to keep those variables that are getting re-used. It looks like there are much more variables that are never re-used, and thus, they could be replaced.

#48 lore raw

Re: [PATCH v6 10/14] memory: tegra: Add EMC scaling sequence code for Tegra210

Quoted 5 lines · Dmitry Osipenko

14.04.2020 18:45, Thierry Reding пишет:
...

Quoted 3 lines
Quoted 2 lines

What about to try to replace this massive egyptian construction with a single "u32 val;" ?

Quoted 8 lines
Quoted 4 lines

I actually tried that after condensing what this used to look like into the above. The result was a huge failure because some of these temporary values end up being reused, so I ended up writing bogus values into some of these registers.

It should be fine to keep those variables that are getting re-used. It looks like there are much more variables that are never re-used, and thus, they could be replaced.

Okay, I made another pass over it and it looks slightly better now. I've kept a couple of the "option"-type variables that are constant but in my opinion make the code more readable compared to hard-coding them. In the cases where I kept them, I declared them constants, so the compiler will hopefully be able to optimize the code and their purpose should also be clearer.

Thierry

#49 lore raw

PATCH v6 11/14 memory: tegra: Support derated timings on Tegra210

In reply to Thierry Reding

From: Thierry Reding <[email protected]>

Derated timings are used to ensure that the memory chips keep operating correctly at high temperatures. This adds code to support polling of the chip operating state when high temperatures are measured on the chip and change the refresh mode accordingly. Under very high temperatures, the driver will switch to the derated tables to ensure proper operation of the memory chips.

---
Changes in v6:
- new patch

 drivers/memory/tegra/tegra210-emc-cc-r21021.c |   2 +-
 drivers/memory/tegra/tegra210-emc-core.c      | 283 ++++++++++++++++--
 drivers/memory/tegra/tegra210-emc-table.c     |  45 ++-
 drivers/memory/tegra/tegra210-emc.h           |  35 ++-
 4 files changed, 333 insertions(+), 32 deletions(-)
drivers/memory/tegra/tegra210-emc-cc-r21021.c +1 -1
index 048cf2102eaa..8487b402f8bf 100644
@@ -1061,7 +1061,7 @@ static void tegra210_emc_r21021_set_clock(struct tegra210_emc *emc, u32 clksrc)
 	}
 
 	/* SW addition: do EMC refresh adjustment here. */
-	tegra210_emc_set_over_temp_timing(emc, next);
+	tegra210_emc_adjust_timing(emc, next);
 
 	if (dram_type == DRAM_TYPE_LPDDR4) {
 		mrw_req = (23 << EMC_MRW_MRW_MA_SHIFT) |
drivers/memory/tegra/tegra210-emc-core.c +266 -17

388 lines not on this page · raw message

drivers/memory/tegra/tegra210-emc-table.c +39 -6

70 lines not on this page · raw message

drivers/memory/tegra/tegra210-emc.h +27 -8
index 7e2fdee44c8d..59fba3085f62 100644
@@ -82,6 +82,7 @@
 #define EMC_EMRS						0xd0
 #define EMC_EMRS_USE_EMRS_LONG_CNT				BIT(26)
 #define EMC_REF							0xd4
+#define  EMC_REF_REF_CMD					BIT(0)
 #define EMC_SELF_REF						0xe0
 #define EMC_MRW							0xe8
 #define EMC_MRW_MRW_OP_SHIFT					0
@@ -877,18 +878,29 @@ struct tegra210_emc_timing {
 	u32 latency;
 };
 
-enum tegra210_emc_dram_over_temp_state {
-	TEGRA210_EMC_DRAM_OVER_TEMP_NONE = 0,
-	TEGRA210_EMC_DRAM_OVER_TEMP_REFRESH_X2,
-	TEGRA210_EMC_DRAM_OVER_TEMP_REFRESH_X4,
-	TEGRA210_EMC_DRAM_OVER_TEMP_THROTTLE, /* 4x Refresh + derating. */
+enum tegra210_emc_refresh {
+	TEGRA210_EMC_REFRESH_NOMINAL = 0,
+	TEGRA210_EMC_REFRESH_2X,
+	TEGRA210_EMC_REFRESH_4X,
+	TEGRA210_EMC_REFRESH_THROTTLE, /* 4x Refresh + derating. */
 };
 
+#define DRAM_TYPE_DDR3		0
+#define DRAM_TYPE_LPDDR4	1
+#define DRAM_TYPE_LPDDR2	2
+#define DRAM_TYPE_DDR2		3
+
 struct tegra210_emc {
 	struct tegra_mc *mc;
 	struct device *dev;
 	struct clk *clk;
 
+	/* nominal EMC frequency table */
+	struct tegra210_emc_timing *nominal;
+	/* derated EMC frequency table */
+	struct tegra210_emc_timing *derated;
+
+	/* currently selected table (nominal or derated) */
 	struct tegra210_emc_timing *timings;
 	unsigned int num_timings;
 
@@ -908,7 +920,11 @@ struct tegra210_emc {
 	unsigned int training_interval;
 	struct timer_list training;
 
-	enum tegra210_emc_dram_over_temp_state state;
+	enum tegra210_emc_refresh refresh;
+	unsigned int refresh_poll_interval;
+	struct timer_list refresh_timer;
+	unsigned int temperature;
+	atomic_t refresh_poll;
 
 	ktime_t clkchange_time;
 	int clkchange_delay;
@@ -919,6 +935,7 @@ struct tegra210_emc {
 		struct dentry *root;
 		unsigned long min_rate;
 		unsigned long max_rate;
+		unsigned int temperature;
 	} debugfs;
 
 	struct tegra210_clk_emc_provider provider;
@@ -977,6 +994,8 @@ static inline u32 div_o3(u32 a, u32 b)
 /* from tegra210-emc-r21021.c */
 extern const struct tegra210_emc_sequence tegra210_emc_r21021;
 
+int tegra210_emc_set_refresh(struct tegra210_emc *emc,
+			     enum tegra210_emc_refresh refresh);
 u32 tegra210_emc_mrr_read(struct tegra210_emc *emc, unsigned int chip,
 			  unsigned int address);
 void tegra210_emc_do_clock_change(struct tegra210_emc *emc, u32 clksrc);
@@ -985,8 +1004,8 @@ void tegra210_emc_timing_update(struct tegra210_emc *emc);
 u32 tegra210_emc_get_dll_state(struct tegra210_emc_timing *next);
 struct tegra210_emc_timing *tegra210_emc_find_timing(struct tegra210_emc *emc,
 						     unsigned long rate);
-void tegra210_emc_set_over_temp_timing(struct tegra210_emc *emc,
-			      struct tegra210_emc_timing *timing);
+void tegra210_emc_adjust_timing(struct tegra210_emc *emc,
+				struct tegra210_emc_timing *timing);
 int tegra210_emc_wait_for_update(struct tegra210_emc *emc, unsigned int channel,
 				 unsigned int offset, u32 bit_mask, bool state);
 unsigned long tegra210_emc_actual_osc_clocks(u32 in);
Signature · 1 line
2.24.1
#50 lore raw

Re: [PATCH v6 11/14] memory: tegra: Support derated timings on Tegra210

09.04.2020 20:52, Thierry Reding пишет:
...

drivers/memory/tegra/tegra210-emc-core.c static int tegra210_emc_probe(struct platform_device *pdev)

Quoted 10 lines
drivers/memory/tegra/tegra210-emc-core.c +7 -0
 	tegra210_emc_debugfs_init(emc);
 
+	cd = devm_thermal_of_cooling_device_register(emc->dev, np, "emc", emc,
+						     &tegra210_emc_cd_ops);
+	if (IS_ERR(cd)) {
+		err = PTR_ERR(cd);
+		dev_err(emc->dev, "failed to register cooling device: %d\n",
+			err);
 
+		goto detach;

I think it's not really worthwhile to fail whole EMC driver because of the failed CDEV.

#51 lore raw

Re: [PATCH v6 11/14] memory: tegra: Support derated timings on Tegra210

Quoted 11 lines · Dmitry Osipenko

09.04.2020 20:52, Thierry Reding пишет:
...

Quoted 8 lines
drivers/memory/tegra/tegra210-emc-core.c +6 -0
 	tegra210_emc_debugfs_init(emc);
 
+	cd = devm_thermal_of_cooling_device_register(emc->dev, np, "emc", emc,
+						     &tegra210_emc_cd_ops);
+	if (IS_ERR(cd)) {
+		err = PTR_ERR(cd);
+		dev_err(emc->dev, "failed to register cooling device: %d\n",
+			err);
Quoted 4 lines

drivers/memory/tegra/tegra210-emc-core.c static int tegra210_emc_probe(struct platform_device *pdev) · line 2007

Quoted 1 line
drivers/memory/tegra/tegra210-emc-core.c +1 -0
+		goto detach;

I think it's not really worthwhile to fail whole EMC driver because of the failed CDEV.

Well, we do kind of need this cooling device mechanism in order for the memory to continue to operate properly at high temperatures. It's also very unlikely that this will ever fail, so I don't see any harm in making this mandatory.

Thierry

_______________________________________________
linux-arm-kernel mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

#52 lore raw

Re: [PATCH v6 11/14] memory: tegra: Support derated timings on Tegra210

14.04.2020 18:47, Thierry Reding пишет:

Quoted 17 lines · Dmitry Osipenko
Quoted 11 lines

09.04.2020 20:52, Thierry Reding пишет:
...

Quoted 8 lines
drivers/memory/tegra/tegra210-emc-core.c +6 -0
 	tegra210_emc_debugfs_init(emc);
 
+	cd = devm_thermal_of_cooling_device_register(emc->dev, np, "emc", emc,
+						     &tegra210_emc_cd_ops);
+	if (IS_ERR(cd)) {
+		err = PTR_ERR(cd);
+		dev_err(emc->dev, "failed to register cooling device: %d\n",
+			err);
Quoted 4 lines

drivers/memory/tegra/tegra210-emc-core.c static int tegra210_emc_probe(struct platform_device *pdev) · line 2007

Quoted 1 line
drivers/memory/tegra/tegra210-emc-core.c +1 -0
+		goto detach;

I think it's not really worthwhile to fail whole EMC driver because of the failed CDEV.

Quoted 4 lines

Well, we do kind of need this cooling device mechanism in order for the memory to continue to operate properly at high temperatures. It's also very unlikely that this will ever fail, so I don't see any harm in making this mandatory.

Fair enough.

#53 lore raw

Re: [PATCH v6 11/14] memory: tegra: Support derated timings on Tegra210

In reply to Thierry Reding

09.04.2020 20:52, Thierry Reding пишет:

drivers/memory/tegra/tegra210-emc.h struct tegra210_emc_timing { · line 886

Quoted 11 lines
drivers/memory/tegra/tegra210-emc.h +5 -5
-enum tegra210_emc_dram_over_temp_state {
-	TEGRA210_EMC_DRAM_OVER_TEMP_NONE = 0,
-	TEGRA210_EMC_DRAM_OVER_TEMP_REFRESH_X2,
-	TEGRA210_EMC_DRAM_OVER_TEMP_REFRESH_X4,
-	TEGRA210_EMC_DRAM_OVER_TEMP_THROTTLE, /* 4x Refresh + derating. */
+enum tegra210_emc_refresh {
+	TEGRA210_EMC_REFRESH_NOMINAL = 0,
+	TEGRA210_EMC_REFRESH_2X,
+	TEGRA210_EMC_REFRESH_4X,
+	TEGRA210_EMC_REFRESH_THROTTLE, /* 4x Refresh + derating. */
 };

What about to avoid all the unnecessary renamings?

#54 lore raw

Re: [PATCH v6 11/14] memory: tegra: Support derated timings on Tegra210

Quoted 14 lines · Dmitry Osipenko

09.04.2020 20:52, Thierry Reding пишет:

drivers/memory/tegra/tegra210-emc.h struct tegra210_emc_timing { · line 886

Quoted 11 lines
drivers/memory/tegra/tegra210-emc.h +5 -5
-enum tegra210_emc_dram_over_temp_state {
-	TEGRA210_EMC_DRAM_OVER_TEMP_NONE = 0,
-	TEGRA210_EMC_DRAM_OVER_TEMP_REFRESH_X2,
-	TEGRA210_EMC_DRAM_OVER_TEMP_REFRESH_X4,
-	TEGRA210_EMC_DRAM_OVER_TEMP_THROTTLE, /* 4x Refresh + derating. */
+enum tegra210_emc_refresh {
+	TEGRA210_EMC_REFRESH_NOMINAL = 0,
+	TEGRA210_EMC_REFRESH_2X,
+	TEGRA210_EMC_REFRESH_4X,
+	TEGRA210_EMC_REFRESH_THROTTLE, /* 4x Refresh + derating. */
 };

What about to avoid all the unnecessary renamings?

Looks like I forgot to move the addition of this enum to a later patch.

Thierry

#55 lore raw

Re: [PATCH v6 11/14] memory: tegra: Support derated timings on Tegra210

In reply to Thierry Reding

09.04.2020 20:52, Thierry Reding пишет:

drivers/memory/tegra/tegra210-emc-core.c static int tegra210_emc_probe(struct platform_device *pdev) · line 1756

Quoted 1 line
drivers/memory/tegra/tegra210-emc-core.c +0 -1
-	/* EMC training timer */

Guess this comment isn't really needed from the start, or should it be kept?

Quoted 4 lines
drivers/memory/tegra/tegra210-emc-core.c +4 -0
+	timer_setup(&emc->refresh_timer, tegra210_emc_poll_refresh,
+		    TIMER_DEFERRABLE);
+	atomic_set(&emc->refresh_poll, 0);
+	emc->refresh_poll_interval = 1000;
#56 lore raw

Re: [PATCH v6 11/14] memory: tegra: Support derated timings on Tegra210

Quoted 4 lines · Dmitry Osipenko

09.04.2020 20:52, Thierry Reding пишет:

drivers/memory/tegra/tegra210-emc-core.c static int tegra210_emc_probe(struct platform_device *pdev) · line 1756

Quoted 1 line
drivers/memory/tegra/tegra210-emc-core.c +0 -1
-	/* EMC training timer */

Guess this comment isn't really needed from the start, or should it be kept?

Nope, I'll remove it since the code is already pretty explicit.

Thierry

#57 lore raw

PATCH v6 12/14 arm64: tegra: Add external memory controller node for Tegra210

In reply to Thierry Reding

From: Joseph Lo <[email protected]>

Add external memory controller (EMC) node for Tegra210

---
Changes in v5:
- drop list of clocks because we need very strict ordering that DT can't guarantee
- drop hard-coded EMC table, bootloaders should add it dynamically

 arch/arm64/boot/dts/nvidia/tegra210.dtsi | 11 +++++++++++
 1 file changed, 11 insertions(+)
arch/arm64/boot/dts/nvidia/tegra210.dtsi +11 -0
index 64c46ce3849d..3fa92dd8350b 100644
@@ -895,6 +895,17 @@ mc: memory-controller@70019000 {
 		#iommu-cells = <1>;
 	};
 
+	external-memory-controller@7001b000 {
+		compatible = "nvidia,tegra210-emc";
+		reg = <0x0 0x7001b000 0x0 0x1000>,
+		      <0x0 0x7001e000 0x0 0x1000>,
+		      <0x0 0x7001f000 0x0 0x1000>;
+		clocks = <&tegra_car TEGRA210_CLK_EMC>;
+		clock-names = "emc";
+		interrupts = <GIC_SPI 78 IRQ_TYPE_LEVEL_HIGH>;
+		nvidia,memory-controller = <&mc>;
+	};
+
 	sata@70020000 {
 		compatible = "nvidia,tegra210-ahci";
 		reg = <0x0 0x70027000 0x0 0x2000>, /* AHCI */
Signature · 1 line
2.24.1
#58 lore raw

PATCH v6 13/14 arm64: tegra: Hook up EMC cooling device

In reply to Thierry Reding

From: Thierry Reding <[email protected]>

The external memory controller can be used as a cooling device for the LPDDR chips. Hook it up to the "mem" thermal zone of the SOCTHERM block so that temperature polling can be enabled on the EMC when a given temperature is exceeded.

---
Changes in v6:
- new patch

 arch/arm64/boot/dts/nvidia/tegra210.dtsi | 28 +++++++++++++++++++-----
 1 file changed, 23 insertions(+), 5 deletions(-)
arch/arm64/boot/dts/nvidia/tegra210.dtsi +23 -5
index 3fa92dd8350b..a550e7b828e6 100644
@@ -895,7 +895,7 @@ mc: memory-controller@70019000 {
 		#iommu-cells = <1>;
 	};
 
-	external-memory-controller@7001b000 {
+	emc: external-memory-controller@7001b000 {
 		compatible = "nvidia,tegra210-emc";
 		reg = <0x0 0x7001b000 0x0 0x1000>,
 		      <0x0 0x7001e000 0x0 0x1000>,
@@ -904,6 +904,7 @@ external-memory-controller@7001b000 {
 		clock-names = "emc";
 		interrupts = <GIC_SPI 78 IRQ_TYPE_LEVEL_HIGH>;
 		nvidia,memory-controller = <&mc>;
+		#cooling-cells = <2>;
 	};
 
 	sata@70020000 {
@@ -1561,6 +1562,18 @@ mem {
 				<&soctherm TEGRA124_SOCTHERM_SENSOR_MEM>;
 
 			trips {
+				dram_nominal: mem-nominal-trip {
+					temperature = <50000>;
+					hysteresis = <1000>;
+					type = "passive";
+				};
+
+				dram_throttle: mem-throttle-trip {
+					temperature = <70000>;
+					hysteresis = <1000>;
+					type = "active";
+				};
+
 				mem-shutdown-trip {
 					temperature = <103000>;
 					hysteresis = <0>;
@@ -1569,10 +1582,15 @@ mem-shutdown-trip {
 			};
 
 			cooling-maps {
-				/*
-				 * There are currently no cooling maps,
-				 * because there are no cooling devices.
-				 */
+				dram-passive {
+					cooling-device = <&emc 0 0>;
+					trip = <&dram_nominal>;
+				};
+
+				dram-active {
+					cooling-device = <&emc 1 1>;
+					trip = <&dram_throttle>;
+				};
 			};
 		};
 
Signature · 1 line
2.24.1
#59 lore raw

PATCH v6 14/14 clk: tegra: Remove the old emc_mux clock for Tegra210

In reply to Thierry Reding

From: Joseph Lo <[email protected]>

Remove the old emc_mux clock and don't use the common EMC clock definition. This will be replaced by a new clock defined in the EMC driver.

---
 drivers/clk/tegra/clk-tegra210.c | 50 ++++++++++++++++++++------------
 1 file changed, 31 insertions(+), 19 deletions(-)
drivers/clk/tegra/clk-tegra210.c +31 -19
index 798920ec50e9..f2bb188fbc6a 100644
@@ -319,12 +319,6 @@ static unsigned long tegra210_input_freq[] = {
 	[8] = 12000000,
 };
 
-static const char *mux_pllmcp_clkm[] = {
-	"pll_m", "pll_c", "pll_p", "clk_m", "pll_m_ud", "pll_mb", "pll_mb",
-	"pll_p",
-};
-#define mux_pllmcp_clkm_idx NULL
-
 #define PLL_ENABLE			(1 << 30)
 
 #define PLLCX_MISC1_IDDQ		(1 << 27)
@@ -2336,7 +2330,6 @@ static struct tegra_clk tegra210_clks[tegra_clk_max] __initdata = {
 	[tegra_clk_i2c2] = { .dt_id = TEGRA210_CLK_I2C2, .present = true },
 	[tegra_clk_uartc_8] = { .dt_id = TEGRA210_CLK_UARTC, .present = true },
 	[tegra_clk_mipi_cal] = { .dt_id = TEGRA210_CLK_MIPI_CAL, .present = true },
-	[tegra_clk_emc] = { .dt_id = TEGRA210_CLK_EMC, .present = true },
 	[tegra_clk_usb2] = { .dt_id = TEGRA210_CLK_USB2, .present = true },
 	[tegra_clk_bsev] = { .dt_id = TEGRA210_CLK_BSEV, .present = true },
 	[tegra_clk_uartd_8] = { .dt_id = TEGRA210_CLK_UARTD, .present = true },
@@ -2979,6 +2972,27 @@ static const char * const sor1_parents[] = {
 
 static u32 sor1_parents_idx[] = { 0, 2, 5, 6 };
 
+static const struct clk_div_table mc_div_table_tegra210[] = {
+	{ .val = 0, .div = 2 },
+	{ .val = 1, .div = 4 },
+	{ .val = 2, .div = 1 },
+	{ .val = 3, .div = 2 },
+	{ .val = 0, .div = 0 },
+};
+
+static void tegra210_clk_register_mc(const char *name,
+				     const char *parent_name)
+{
+	struct clk *clk;
+
+	clk = clk_register_divider_table(NULL, name, parent_name,
+					 CLK_IS_CRITICAL,
+					 clk_base + CLK_SOURCE_EMC,
+					 15, 2, CLK_DIVIDER_READ_ONLY,
+					 mc_div_table_tegra210, &emc_lock);
+	clks[TEGRA210_CLK_MC] = clk;
+}
+
 static const char * const sor1_out_parents[] = {
 	/*
 	 * Bit 0 of the mux selects sor1_pad_clkout, irrespective of bit 1, so
@@ -3021,7 +3035,8 @@ static const char * const la_parents[] = {
 static struct tegra_clk_periph tegra210_la =
 	TEGRA_CLK_PERIPH(29, 7, 9, 0, 8, 1, TEGRA_DIVIDER_ROUND_UP, 76, 0, NULL, NULL);
 
-static __init void tegra210_periph_clk_init(void __iomem *clk_base,
+static __init void tegra210_periph_clk_init(struct device_node *np,
+					    void __iomem *clk_base,
 					    void __iomem *pmc_base)
 {
 	struct clk *clk;
@@ -3067,16 +3082,6 @@ static __init void tegra210_periph_clk_init(void __iomem *clk_base,
 			CLK_SOURCE_LA, 0);
 	clks[TEGRA210_CLK_LA] = clk;
 
-	/* emc mux */
-	clk = clk_register_mux(NULL, "emc_mux", mux_pllmcp_clkm,
-			       ARRAY_SIZE(mux_pllmcp_clkm), 0,
-			       clk_base + CLK_SOURCE_EMC,
-			       29, 3, 0, &emc_lock);
-
-	clk = tegra_clk_register_mc("mc", "emc_mux", clk_base + CLK_SOURCE_EMC,
-				    &emc_lock);
-	clks[TEGRA210_CLK_MC] = clk;
-
 	/* cml0 */
 	clk = clk_register_gate(NULL, "cml0", "pll_e", 0, clk_base + PLLE_AUX,
 				0, 0, &pll_e_lock);
@@ -3119,6 +3124,13 @@ static __init void tegra210_periph_clk_init(void __iomem *clk_base,
 	}
 
 	tegra_periph_clk_init(clk_base, pmc_base, tegra210_clks, &pll_p_params);
+
+	/* emc */
+	clk = tegra210_clk_register_emc(np, clk_base);
+	clks[TEGRA210_CLK_EMC] = clk;
+
+	/* mc */
+	tegra210_clk_register_mc("mc", "emc");
 }
 
 static void __init tegra210_pll_init(void __iomem *clk_base,
@@ -3717,7 +3729,7 @@ static void __init tegra210_clock_init(struct device_node *np)
 
 	tegra_fixed_clk_init(tegra210_clks);
 	tegra210_pll_init(clk_base, pmc_base);
-	tegra210_periph_clk_init(clk_base, pmc_base);
+	tegra210_periph_clk_init(np, clk_base, pmc_base);
 	tegra_audio_clk_init(clk_base, pmc_base, tegra210_clks,
 			     tegra210_audio_plls,
 			     ARRAY_SIZE(tegra210_audio_plls), 24576000);
Signature · 1 line
2.24.1