soc/amd: factor out common eMMC code

Signed-off-by: Felix Held <felix-coreboot@felixheld.de>
Change-Id: If5447f9272183f83bc422520ada93d3cfd96551e
Reviewed-on: https://review.coreboot.org/c/coreboot/+/68415
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Martin Roth <martin.roth@amd.corp-partner.google.com>
diff --git a/src/soc/amd/cezanne/Kconfig b/src/soc/amd/cezanne/Kconfig
index 35b9215..b8209f8 100644
--- a/src/soc/amd/cezanne/Kconfig
+++ b/src/soc/amd/cezanne/Kconfig
@@ -46,6 +46,7 @@
 	select SOC_AMD_COMMON_BLOCK_APOB
 	select SOC_AMD_COMMON_BLOCK_BANKED_GPIOS
 	select SOC_AMD_COMMON_BLOCK_DATA_FABRIC
+	select SOC_AMD_COMMON_BLOCK_EMMC
 	select SOC_AMD_COMMON_BLOCK_GRAPHICS
 	select SOC_AMD_COMMON_BLOCK_HAS_ESPI
 	select SOC_AMD_COMMON_BLOCK_I2C
diff --git a/src/soc/amd/cezanne/Makefile.inc b/src/soc/amd/cezanne/Makefile.inc
index 95ab4ed..dc97c1f 100644
--- a/src/soc/amd/cezanne/Makefile.inc
+++ b/src/soc/amd/cezanne/Makefile.inc
@@ -33,7 +33,6 @@
 ramstage-y	+= chip.c
 ramstage-y	+= cpu.c
 ramstage-y	+= data_fabric.c
-ramstage-y	+= emmc.c
 ramstage-y	+= fch.c
 ramstage-y	+= fsp_s_params.c
 ramstage-y	+= gpio.c
diff --git a/src/soc/amd/cezanne/chipset.cb b/src/soc/amd/cezanne/chipset.cb
index a9bc256..e717fd4 100644
--- a/src/soc/amd/cezanne/chipset.cb
+++ b/src/soc/amd/cezanne/chipset.cb
@@ -113,5 +113,5 @@
 	device mmio 0xfedc5000 alias i2c_3 off ops soc_amd_i2c_mmio_ops end
 	device mmio 0xfedc9000 alias uart_0 off ops cezanne_uart_mmio_ops end
 	device mmio 0xfedca000 alias uart_1 off ops cezanne_uart_mmio_ops end
-	device mmio 0xfedd5000 alias emmc off ops cezanne_emmc_mmio_ops end
+	device mmio 0xfedd5000 alias emmc off ops amd_emmc_mmio_ops end
 end
diff --git a/src/soc/amd/common/block/emmc/Kconfig b/src/soc/amd/common/block/emmc/Kconfig
new file mode 100644
index 0000000..96bbada
--- /dev/null
+++ b/src/soc/amd/common/block/emmc/Kconfig
@@ -0,0 +1,4 @@
+config SOC_AMD_COMMON_BLOCK_EMMC
+	bool
+	help
+	  Select this option to use AMD common EMMC driver support.
diff --git a/src/soc/amd/common/block/emmc/Makefile.inc b/src/soc/amd/common/block/emmc/Makefile.inc
new file mode 100644
index 0000000..ed68ab2
--- /dev/null
+++ b/src/soc/amd/common/block/emmc/Makefile.inc
@@ -0,0 +1 @@
+ramstage-$(CONFIG_SOC_AMD_COMMON_BLOCK_EMMC) += emmc.c
diff --git a/src/soc/amd/cezanne/emmc.c b/src/soc/amd/common/block/emmc/emmc.c
similarity index 90%
rename from src/soc/amd/cezanne/emmc.c
rename to src/soc/amd/common/block/emmc/emmc.c
index a699b20..ee612e4 100644
--- a/src/soc/amd/cezanne/emmc.c
+++ b/src/soc/amd/common/block/emmc/emmc.c
@@ -15,7 +15,7 @@
 		power_off_aoac_device(FCH_AOAC_DEV_EMMC);
 }
 
-struct device_operations cezanne_emmc_mmio_ops = {
+struct device_operations amd_emmc_mmio_ops = {
 	.read_resources = emmc_read_resources,
 	.set_resources = noop_set_resources,
 	.scan_bus = scan_static_bus,
diff --git a/src/soc/amd/mendocino/Kconfig b/src/soc/amd/mendocino/Kconfig
index 9608e41..d31b29dd 100644
--- a/src/soc/amd/mendocino/Kconfig
+++ b/src/soc/amd/mendocino/Kconfig
@@ -61,6 +61,7 @@
 	select SOC_AMD_COMMON_BLOCK_APOB_HASH
 	select SOC_AMD_COMMON_BLOCK_BANKED_GPIOS	# TODO: Check if this is still correct
 	select SOC_AMD_COMMON_BLOCK_DATA_FABRIC
+	select SOC_AMD_COMMON_BLOCK_EMMC
 	select SOC_AMD_COMMON_BLOCK_ESPI_EXTENDED_DECODE_RANGES
 	select SOC_AMD_COMMON_BLOCK_GRAPHICS	# TODO: Check if this is still correct
 	select SOC_AMD_COMMON_BLOCK_HAS_ESPI
diff --git a/src/soc/amd/mendocino/Makefile.inc b/src/soc/amd/mendocino/Makefile.inc
index 2952d18..9549426 100644
--- a/src/soc/amd/mendocino/Makefile.inc
+++ b/src/soc/amd/mendocino/Makefile.inc
@@ -36,7 +36,6 @@
 ramstage-y	+= chip.c
 ramstage-y	+= cpu.c
 ramstage-y	+= data_fabric.c
-ramstage-y	+= emmc.c
 ramstage-y	+= fch.c
 ramstage-y	+= fsp_s_params.c
 ramstage-y	+= gpio.c
diff --git a/src/soc/amd/mendocino/chipset_mendocino.cb b/src/soc/amd/mendocino/chipset_mendocino.cb
index 2a8d187..5692d64 100644
--- a/src/soc/amd/mendocino/chipset_mendocino.cb
+++ b/src/soc/amd/mendocino/chipset_mendocino.cb
@@ -93,5 +93,5 @@
 	device mmio 0xfedce000 alias uart_2 off ops mendocino_uart_mmio_ops end
 	device mmio 0xfedcf000 alias uart_3 off ops mendocino_uart_mmio_ops end
 	device mmio 0xfedd1000 alias uart_4 off ops mendocino_uart_mmio_ops end
-	device mmio 0xfedd5000 alias emmc off ops mendocino_emmc_mmio_ops end
+	device mmio 0xfedd5000 alias emmc off ops amd_emmc_mmio_ops end
 end
diff --git a/src/soc/amd/mendocino/chipset_rembrandt.cb b/src/soc/amd/mendocino/chipset_rembrandt.cb
index 2a8d187..5692d64 100644
--- a/src/soc/amd/mendocino/chipset_rembrandt.cb
+++ b/src/soc/amd/mendocino/chipset_rembrandt.cb
@@ -93,5 +93,5 @@
 	device mmio 0xfedce000 alias uart_2 off ops mendocino_uart_mmio_ops end
 	device mmio 0xfedcf000 alias uart_3 off ops mendocino_uart_mmio_ops end
 	device mmio 0xfedd1000 alias uart_4 off ops mendocino_uart_mmio_ops end
-	device mmio 0xfedd5000 alias emmc off ops mendocino_emmc_mmio_ops end
+	device mmio 0xfedd5000 alias emmc off ops amd_emmc_mmio_ops end
 end
diff --git a/src/soc/amd/mendocino/emmc.c b/src/soc/amd/mendocino/emmc.c
deleted file mode 100644
index ae01a14..0000000
--- a/src/soc/amd/mendocino/emmc.c
+++ /dev/null
@@ -1,23 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-only */
-
-#include <amdblocks/aoac.h>
-#include <device/device.h>
-#include <soc/aoac_defs.h>
-
-static void emmc_read_resources(struct device *dev)
-{
-	mmio_resource_kb(dev, 0, dev->path.mmio.addr / KiB, 4);
-}
-
-static void emmc_enable(struct device *dev)
-{
-	if (!dev->enabled)
-		power_off_aoac_device(FCH_AOAC_DEV_EMMC);
-}
-
-struct device_operations mendocino_emmc_mmio_ops = {
-	.read_resources = emmc_read_resources,
-	.set_resources = noop_set_resources,
-	.scan_bus = scan_static_bus,
-	.enable = emmc_enable,
-};
diff --git a/src/soc/amd/morgana/Kconfig b/src/soc/amd/morgana/Kconfig
index 8c7d87c..f150d51 100644
--- a/src/soc/amd/morgana/Kconfig
+++ b/src/soc/amd/morgana/Kconfig
@@ -51,6 +51,7 @@
 	select SOC_AMD_COMMON_BLOCK_APOB_HASH
 	select SOC_AMD_COMMON_BLOCK_BANKED_GPIOS
 	select SOC_AMD_COMMON_BLOCK_DATA_FABRIC
+	select SOC_AMD_COMMON_BLOCK_EMMC
 	select SOC_AMD_COMMON_BLOCK_ESPI_EXTENDED_DECODE_RANGES
 	select SOC_AMD_COMMON_BLOCK_GRAPHICS
 	select SOC_AMD_COMMON_BLOCK_HAS_ESPI
diff --git a/src/soc/amd/morgana/Makefile.inc b/src/soc/amd/morgana/Makefile.inc
index e99fa27..6c80d23 100644
--- a/src/soc/amd/morgana/Makefile.inc
+++ b/src/soc/amd/morgana/Makefile.inc
@@ -37,7 +37,6 @@
 ramstage-y	+= chip.c
 ramstage-y	+= cpu.c
 ramstage-y	+= data_fabric.c
-ramstage-y	+= emmc.c
 ramstage-y	+= fch.c
 ramstage-y	+= fsp_s_params.c
 ramstage-y	+= gpio.c
diff --git a/src/soc/amd/morgana/chipset.cb b/src/soc/amd/morgana/chipset.cb
index 8510981..e710ffb 100644
--- a/src/soc/amd/morgana/chipset.cb
+++ b/src/soc/amd/morgana/chipset.cb
@@ -95,5 +95,5 @@
 	device mmio 0xfedce000 alias uart_2 off ops morgana_uart_mmio_ops end
 	device mmio 0xfedcf000 alias uart_3 off ops morgana_uart_mmio_ops end
 	device mmio 0xfedd1000 alias uart_4 off ops morgana_uart_mmio_ops end
-	device mmio 0xfedd5000 alias emmc off ops morgana_emmc_mmio_ops end
+	device mmio 0xfedd5000 alias emmc off ops amd_emmc_mmio_ops end
 end
diff --git a/src/soc/amd/morgana/emmc.c b/src/soc/amd/morgana/emmc.c
deleted file mode 100644
index 4b43536..0000000
--- a/src/soc/amd/morgana/emmc.c
+++ /dev/null
@@ -1,23 +0,0 @@
-/* SPDX-License-Identifier: GPL-2.0-only */
-
-#include <amdblocks/aoac.h>
-#include <device/device.h>
-#include <soc/aoac_defs.h>
-
-static void emmc_read_resources(struct device *dev)
-{
-	mmio_resource_kb(dev, 0, dev->path.mmio.addr / KiB, 4);
-}
-
-static void emmc_enable(struct device *dev)
-{
-	if (!dev->enabled)
-		power_off_aoac_device(FCH_AOAC_DEV_EMMC);
-}
-
-struct device_operations morgana_emmc_mmio_ops = {
-	.read_resources = emmc_read_resources,
-	.set_resources = noop_set_resources,
-	.scan_bus = scan_static_bus,
-	.enable = emmc_enable,
-};