Skip to contentSkip to conversation

memory: mediatek emi: add MediaTek EMI driver

PATCH New EastL Lee 2 participants 5 messages Jan 27, 2021 – May 4, 2021

Subsystems (4)
lore
Share & tools
lore
author
#1 lore raw

PATCH 1/3 memory: Add support for MediaTek External Memory Interface driver

MediaTek External Memory Interface(emi) on MT6779 SoC controls all the transitions from master to dram, there are emi-cen & emi-mpu drivers.

emi-cen driver provides phy addr to dram rank, bank, column and other information, as well as the currently used dram channel number, rank number, rank size.

emi-mpu (memory protect unit) driver provides an interface to set emi regions, need to enter the secure world setting and the violation irq isr will collect mpu violation information, after all regions have protected their respective regions, emi-mpu will set the ap region to protect all the remaining dram.

---
 drivers/memory/Kconfig                   |    1 +
 drivers/memory/Makefile                  |    1 +
 drivers/memory/mediatek/Kconfig          |   23 +
 drivers/memory/mediatek/Makefile         |    4 +
 drivers/memory/mediatek/emi-cen.c        | 1305 ++++++++++++++++++++++++++++++
 drivers/memory/mediatek/emi-mpu.c        |  908 +++++++++++++++++++++
 include/linux/soc/mediatek/mtk_sip_svc.h |    3 +
 include/soc/mediatek/emi.h               |  101 +++
 8 files changed, 2346 insertions(+)
 create mode 100644 drivers/memory/mediatek/Kconfig
 create mode 100644 drivers/memory/mediatek/Makefile
 create mode 100644 drivers/memory/mediatek/emi-cen.c
 create mode 100644 drivers/memory/mediatek/emi-mpu.c
 create mode 100644 include/soc/mediatek/emi.h
drivers/memory/Kconfig +1 -0
index 00e013b..1339884 100644
@@ -218,5 +218,6 @@ config STM32_FMC2_EBI
 
 source "drivers/memory/samsung/Kconfig"
 source "drivers/memory/tegra/Kconfig"
+source "drivers/memory/mediatek/Kconfig"
 
 endif
drivers/memory/Makefile +1 -0
index e71cf7b..e3ac040 100644
@@ -26,6 +26,7 @@ obj-$(CONFIG_RENESAS_RPCIF)	+= renesas-rpc-if.o
 obj-$(CONFIG_STM32_FMC2_EBI)	+= stm32-fmc2-ebi.o
 
 obj-$(CONFIG_SAMSUNG_MC)	+= samsung/
+obj-$(CONFIG_HAVE_MTK_MC)       += mediatek/
 obj-$(CONFIG_TEGRA_MC)		+= tegra/
 obj-$(CONFIG_TI_EMIF_SRAM)	+= ti-emif-sram.o
 ti-emif-sram-objs		:= ti-emif-pm.o ti-emif-sram-pm.o
drivers/memory/mediatek/Kconfig new file +23 -0
new file mode 100644
index 0000000..37535bb
@@ -0,0 +1,23 @@
+# SPDX-License-Identifier: GPL-2.0
+
+config HAVE_MTK_MC
+	bool "MediaTek Memory Controller support"
+	select MTK_EMI
+	help
+	  Support for the Memory Controller (MC) devices found on
+	  MediaTek(R) SoCs.
+	  This config enables MTK_EMI and MTK_DRAMC for EMI and
+	  DRAMC drivers.
+
+if HAVE_MTK_MC
+
+config MTK_EMI
+	tristate "MediaTek External Memory Interface driver"
+	depends on HAVE_MTK_MC
+	help
+	  This selects the MediaTek(R) EMI driver.
+	  Provide the API for MPU registration, EMI MPU violation handling,
+	  the API for EMI information, the BWL golden setting,
+	  and the sysfs for EMI ISU control.
+
+endif
drivers/memory/mediatek/Makefile new file +4 -0
new file mode 100644
index 0000000..22947c1
@@ -0,0 +1,4 @@
+# SPDX-License-Identifier: GPL-2.0
+obj-$(CONFIG_MTK_EMI) += emi.o
+emi-objs := emi-cen.o
+obj-$(CONFIG_MTK_EMI) += emi-mpu.o
drivers/memory/mediatek/emi-cen.c new file +1305 -0

1,305 lines not on this page · raw message

drivers/memory/mediatek/emi-mpu.c new file +908 -0

908 lines not on this page · raw message

include/linux/soc/mediatek/mtk_sip_svc.h +3 -0
index 082398e..65a959a 100644
@@ -21,5 +21,8 @@
 #define MTK_SIP_SMC_CMD(fn_id) \
 	ARM_SMCCC_CALL_VAL(ARM_SMCCC_FAST_CALL, MTK_SIP_SMC_CONVENTION, \
 			   ARM_SMCCC_OWNER_SIP, fn_id)
+/* EMI MPU */
+#define MTK_SIP_EMIMPU_CONTROL \
+	MTK_SIP_SMC_CMD(0x50B)
 
 #endif
include/soc/mediatek/emi.h new file +101 -0

101 lines not on this page · raw message

Signature · 5 lines
1.9.1
_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek
#2 lore raw

Re: [PATCH v1 1/3] memory: Add support for MediaTek External Memory Interface driver

Quoted 14 lines · EastL Lee

MediaTek External Memory Interface(emi) on MT6779 SoC controls all the transitions from master to dram, there are emi-cen & emi-mpu drivers.

emi-cen driver provides phy addr to dram rank, bank, column and other information, as well as the currently used dram channel number, rank number, rank size.

emi-mpu (memory protect unit) driver provides an interface to set emi regions, need to enter the secure world setting and the violation irq isr will collect mpu violation information, after all regions have protected their respective regions, emi-mpu will set the ap region to protect all the remaining dram.

Quoted 16 lines
---
 drivers/memory/Kconfig                   |    1 +
 drivers/memory/Makefile                  |    1 +
 drivers/memory/mediatek/Kconfig          |   23 +
 drivers/memory/mediatek/Makefile         |    4 +
 drivers/memory/mediatek/emi-cen.c        | 1305 ++++++++++++++++++++++++++++++
 drivers/memory/mediatek/emi-mpu.c        |  908 +++++++++++++++++++++
 include/linux/soc/mediatek/mtk_sip_svc.h |    3 +
 include/soc/mediatek/emi.h               |  101 +++
 8 files changed, 2346 insertions(+)
 create mode 100644 drivers/memory/mediatek/Kconfig
 create mode 100644 drivers/memory/mediatek/Makefile
 create mode 100644 drivers/memory/mediatek/emi-cen.c
 create mode 100644 drivers/memory/mediatek/emi-mpu.c
 create mode 100644 include/soc/mediatek/emi.h

Use scripts/get_maintainers.pl to get list of people you need to Cc.

Run checkpatch, smatch, sparse and coccinelle on your new driver. I can easily see that some of these steps were missing (e.g. OWNER field...).

Best regards,
Krzysztof

author
#3 lore raw

PATCH 2/3 arm64: dts: mt6779: add emi node

In reply to EastL Lee

add emicen & emichn & emimpu node

---
 arch/arm64/boot/dts/mediatek/mt6779.dtsi | 34 ++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)
arch/arm64/boot/dts/mediatek/mt6779.dtsi +34 -0
index 370f309..bb34537 100644
@@ -267,5 +267,39 @@
 			#clock-cells = <1>;
 		};
 
+		emichn: emichn@10235000 {
+			compatible = "mediatek,mt6779-emichn",
+				"mediatek,common-emichn";
+			reg = <0 0x10235000 0 0x1000>,
+				<0 0x10245000 0 0x1000>;
+		};
+
+		emicen: emicen@10219000 {
+			compatible = "mediatek,mt6779-emicen",
+				"mediatek,common-emicen";
+			reg = <0 0x10219000 0 0x1000>;
+			mediatek,emi-reg = <&emichn>;
+		};
+
+		emimpu:emimpu@10226000 {
+			compatible = "mediatek,mt6779-emimpu",
+				"mediatek,common-emimpu";
+			reg = <0 0x10226000 0 0x1000>;
+			mediatek,emi-reg = <&emicen>;
+			interrupts = <GIC_SPI 189 IRQ_TYPE_LEVEL_HIGH 0>;
+			region_cnt = <32>;
+			domain_cnt = <16>;
+			addr_align = <16>;
+			ap_region = <31>;
+			ap_apc = <0 5 5 5 0 0 6 5>,
+				<0 0 5 0 0 1 5 5>;
+			dump = <0x1f0 0x1f8 0x1fc>;
+			clear = <0x160 0xffffffff 16>,
+				<0x200 0x00000003 16>,
+				<0x1f0 0x80000000 1>;
+			clear_md = <0x1fc 0x80000000 1>;
+			ctrl_intf = <1>;
+			slverr = <0>;
+		};
 	};
 };
Signature · 5 lines
1.9.1
_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek
author
#4 lore raw

PATCH 3/3 arm64: configs: mt6779: enable HAVE_MTK_MC config

In reply to EastL Lee

enable HAVE_MTK_MC config

---
 arch/arm64/configs/defconfig | 1 +
 1 file changed, 1 insertion(+)
arch/arm64/configs/defconfig +1 -0
index 17a2df6..f4de260 100644
@@ -1091,3 +1091,4 @@ CONFIG_DEBUG_KERNEL=y
 # CONFIG_DEBUG_PREEMPT is not set
 # CONFIG_FTRACE is not set
 CONFIG_MEMTEST=y
+CONFIG_HAVE_MTK_MC=y
Signature · 5 lines
1.9.1
_______________________________________________
Linux-mediatek mailing list
[email protected]
http://lists.infradead.org/mailman/listinfo/linux-mediatek