bd82x6x: Move calling of finalize() on resume to southbridge code

Change-Id: I6416cd5780fbda0b3c2e236ce98a9f9a508e70c6
Signed-off-by: Vladimir Serbinenko <phcoder@gmail.com>
Reviewed-on: http://review.coreboot.org/10293
Tested-by: build bot (Jenkins)
Reviewed-by: Nicolas Reinecke <nr@das-labor.org>
diff --git a/src/mainboard/gigabyte/ga-b75m-d3h/mainboard.c b/src/mainboard/gigabyte/ga-b75m-d3h/mainboard.c
index 142907a..6828330 100644
--- a/src/mainboard/gigabyte/ga-b75m-d3h/mainboard.c
+++ b/src/mainboard/gigabyte/ga-b75m-d3h/mainboard.c
@@ -36,12 +36,6 @@
 #include <device/pci.h>
 #include <cbfs.h>
 
-void mainboard_suspend_resume(void)
-{
-	/* Call SMM finalize() handlers before resume */
-	outb(0xcb, 0xb2);
-}
-
 static void mainboard_init(device_t dev)
 {
 	RCBA32(0x38c8) = 0x00002005;
diff --git a/src/mainboard/gigabyte/ga-b75m-d3v/mainboard.c b/src/mainboard/gigabyte/ga-b75m-d3v/mainboard.c
index 142907a..6828330 100644
--- a/src/mainboard/gigabyte/ga-b75m-d3v/mainboard.c
+++ b/src/mainboard/gigabyte/ga-b75m-d3v/mainboard.c
@@ -36,12 +36,6 @@
 #include <device/pci.h>
 #include <cbfs.h>
 
-void mainboard_suspend_resume(void)
-{
-	/* Call SMM finalize() handlers before resume */
-	outb(0xcb, 0xb2);
-}
-
 static void mainboard_init(device_t dev)
 {
 	RCBA32(0x38c8) = 0x00002005;
diff --git a/src/mainboard/google/butterfly/mainboard.c b/src/mainboard/google/butterfly/mainboard.c
index e09336d..1c1814d 100644
--- a/src/mainboard/google/butterfly/mainboard.c
+++ b/src/mainboard/google/butterfly/mainboard.c
@@ -183,14 +183,6 @@
 	ec_mem_write(EC_KBID_REG, kbd_type);
 }
 
-void mainboard_suspend_resume(void)
-{
-	/* Call SMM finalize() handlers before resume */
-	outb(0xcb, 0xb2);
-}
-
-
-
 static void mainboard_init(device_t dev)
 {
 	u32 search_address = 0x0;
diff --git a/src/mainboard/google/link/mainboard.c b/src/mainboard/google/link/mainboard.c
index 01ac22c..fc95f59 100644
--- a/src/mainboard/google/link/mainboard.c
+++ b/src/mainboard/google/link/mainboard.c
@@ -54,12 +54,6 @@
 	 */
 }
 
-void mainboard_suspend_resume(void)
-{
-	/* Call SMM finalize() handlers before resume */
-	outb(0xcb, 0xb2);
-}
-
 #if CONFIG_VGA_ROM_RUN
 static int int15_handler(void)
 {
diff --git a/src/mainboard/google/parrot/mainboard.c b/src/mainboard/google/parrot/mainboard.c
index 998cb3c..3f29312 100644
--- a/src/mainboard/google/parrot/mainboard.c
+++ b/src/mainboard/google/parrot/mainboard.c
@@ -39,15 +39,11 @@
 
 void mainboard_suspend_resume(void)
 {
-	/* Call SMM finalize() handlers before resume */
-	outb(0xcb, 0xb2);
-
 	/* Enable ACPI mode before OS resume */
 	outb(0xe1, 0xb2);
 }
 
 
-
 static void mainboard_init(device_t dev)
 {
 	/* Initialize the Embedded Controller */
diff --git a/src/mainboard/google/stout/mainboard.c b/src/mainboard/google/stout/mainboard.c
index fcae6e1..0d3d8e0 100644
--- a/src/mainboard/google/stout/mainboard.c
+++ b/src/mainboard/google/stout/mainboard.c
@@ -39,9 +39,6 @@
 
 void mainboard_suspend_resume(void)
 {
-	/* Call SMM finalize() handlers before resume */
-	outb(0xcb, 0xb2);
-
 	/* Stout EC needs to be put back in ACPI mode */
 	ec_write_cmd(EC_CMD_NOTIFY_ACPI_ENTER);
 }
diff --git a/src/mainboard/intel/emeraldlake2/mainboard.c b/src/mainboard/intel/emeraldlake2/mainboard.c
index 19158d6..2e1ed36 100644
--- a/src/mainboard/intel/emeraldlake2/mainboard.c
+++ b/src/mainboard/intel/emeraldlake2/mainboard.c
@@ -33,14 +33,6 @@
 #include <boot/coreboot_tables.h>
 #include <southbridge/intel/bd82x6x/pch.h>
 
-void mainboard_suspend_resume(void)
-{
-	/* Call SMM finalize() handlers before resume */
-	outb(0xcb, 0xb2);
-}
-
-
-
 // mainboard_enable is executed as first thing after
 // enumerate_buses().
 
diff --git a/src/mainboard/kontron/ktqm77/mainboard.c b/src/mainboard/kontron/ktqm77/mainboard.c
index 3594749..9999e2e 100644
--- a/src/mainboard/kontron/ktqm77/mainboard.c
+++ b/src/mainboard/kontron/ktqm77/mainboard.c
@@ -35,12 +35,6 @@
 #include <boot/coreboot_tables.h>
 #include <southbridge/intel/bd82x6x/pch.h>
 
-void mainboard_suspend_resume(void)
-{
-	/* Call SMM finalize() handlers before resume */
-	outb(0xcb, 0xb2);
-}
-
 #if CONFIG_VGA_ROM_RUN
 static int int15_handler(void)
 {
diff --git a/src/mainboard/lenovo/t420s/mainboard.c b/src/mainboard/lenovo/t420s/mainboard.c
index acebcae..96180ec 100644
--- a/src/mainboard/lenovo/t420s/mainboard.c
+++ b/src/mainboard/lenovo/t420s/mainboard.c
@@ -33,12 +33,6 @@
 #include <pc80/keyboard.h>
 #include <ec/lenovo/h8/h8.h>
 
-void mainboard_suspend_resume(void)
-{
-	/* Call SMM finalize() handlers before resume */
-	outb(0xcb, 0xb2);
-}
-
 static void mainboard_init(device_t dev)
 {
 	/* init spi */
diff --git a/src/mainboard/lenovo/t430s/mainboard.c b/src/mainboard/lenovo/t430s/mainboard.c
index 2bbb8bd..a5cd083 100644
--- a/src/mainboard/lenovo/t430s/mainboard.c
+++ b/src/mainboard/lenovo/t430s/mainboard.c
@@ -33,12 +33,6 @@
 #include <pc80/keyboard.h>
 #include <ec/lenovo/h8/h8.h>
 
-void mainboard_suspend_resume(void)
-{
-	/* Call SMM finalize() handlers before resume */
-	outb(0xcb, 0xb2);
-}
-
 static void mainboard_init(device_t dev)
 {
 	/* init spi */
diff --git a/src/mainboard/lenovo/t520/mainboard.c b/src/mainboard/lenovo/t520/mainboard.c
index 2bfe543..a67459d 100644
--- a/src/mainboard/lenovo/t520/mainboard.c
+++ b/src/mainboard/lenovo/t520/mainboard.c
@@ -38,12 +38,6 @@
 #include <pc80/keyboard.h>
 #include <ec/lenovo/h8/h8.h>
 
-void mainboard_suspend_resume(void)
-{
-	/* Call SMM finalize() handlers before resume */
-	outb(0xcb, 0xb2);
-}
-
 static void mainboard_init(device_t dev)
 {
 	RCBA32(0x38c8) = 0x00002005;
diff --git a/src/mainboard/lenovo/t530/mainboard.c b/src/mainboard/lenovo/t530/mainboard.c
index fe99afa..c258731 100644
--- a/src/mainboard/lenovo/t530/mainboard.c
+++ b/src/mainboard/lenovo/t530/mainboard.c
@@ -38,12 +38,6 @@
 #include <pc80/keyboard.h>
 #include <ec/lenovo/h8/h8.h>
 
-void mainboard_suspend_resume(void)
-{
-	/* Call SMM finalize() handlers before resume */
-	outb(0xcb, 0xb2);
-}
-
 static void mainboard_init(device_t dev)
 {
 	RCBA32(0x38c8) = 0x00002005;
diff --git a/src/mainboard/lenovo/x220/mainboard.c b/src/mainboard/lenovo/x220/mainboard.c
index 04b8e7f..c557031 100644
--- a/src/mainboard/lenovo/x220/mainboard.c
+++ b/src/mainboard/lenovo/x220/mainboard.c
@@ -33,12 +33,6 @@
 #include <pc80/keyboard.h>
 #include <ec/lenovo/h8/h8.h>
 
-void mainboard_suspend_resume(void)
-{
-	/* Call SMM finalize() handlers before resume */
-	outb(0xcb, 0xb2);
-}
-
 static void mainboard_init(device_t dev)
 {
 	RCBA32(0x38c8) = 0x00002005;
diff --git a/src/mainboard/lenovo/x230/mainboard.c b/src/mainboard/lenovo/x230/mainboard.c
index 09b8d69..285020f 100644
--- a/src/mainboard/lenovo/x230/mainboard.c
+++ b/src/mainboard/lenovo/x230/mainboard.c
@@ -34,12 +34,6 @@
 #include <pc80/keyboard.h>
 #include <ec/lenovo/h8/h8.h>
 
-void mainboard_suspend_resume(void)
-{
-	/* Call SMM finalize() handlers before resume */
-	outb(0xcb, 0xb2);
-}
-
 static void mainboard_init(device_t dev)
 {
 	RCBA32(0x38c8) = 0x00002005;
diff --git a/src/mainboard/samsung/lumpy/mainboard.c b/src/mainboard/samsung/lumpy/mainboard.c
index e439d73b..f34f887 100644
--- a/src/mainboard/samsung/lumpy/mainboard.c
+++ b/src/mainboard/samsung/lumpy/mainboard.c
@@ -38,9 +38,6 @@
 
 void mainboard_suspend_resume(void)
 {
-	/* Call SMM finalize() handlers before resume */
-	outb(0xcb, 0xb2);
-
 	/* Enable EC ACPI mode for the OS before resume */
 	send_ec_command(EC_SMI_DISABLE);
 	send_ec_command(EC_ACPI_ENABLE);
diff --git a/src/mainboard/samsung/stumpy/mainboard.c b/src/mainboard/samsung/stumpy/mainboard.c
index 19158d6..2e1ed36 100644
--- a/src/mainboard/samsung/stumpy/mainboard.c
+++ b/src/mainboard/samsung/stumpy/mainboard.c
@@ -33,14 +33,6 @@
 #include <boot/coreboot_tables.h>
 #include <southbridge/intel/bd82x6x/pch.h>
 
-void mainboard_suspend_resume(void)
-{
-	/* Call SMM finalize() handlers before resume */
-	outb(0xcb, 0xb2);
-}
-
-
-
 // mainboard_enable is executed as first thing after
 // enumerate_buses().
 
diff --git a/src/southbridge/intel/bd82x6x/lpc.c b/src/southbridge/intel/bd82x6x/lpc.c
index 842d9d9..c1bc45f 100644
--- a/src/southbridge/intel/bd82x6x/lpc.c
+++ b/src/southbridge/intel/bd82x6x/lpc.c
@@ -805,6 +805,14 @@
 	intel_acpi_pcie_hotplug_generator(chip->pcie_hotplug_map, 8);
 }
 
+static void lpc_final(struct device *dev)
+{
+	if (CONFIG_HAVE_SMI_HANDLER && acpi_is_wakeup_s3()) {
+		/* Call SMM finalize() handlers before resume */
+		outb(0xcb, 0xb2);
+	}
+}
+
 static struct pci_operations pci_ops = {
 	.set_subsystem = set_subsystem,
 };
@@ -817,6 +825,7 @@
 	.acpi_inject_dsdt_generator = southbridge_inject_dsdt,
 	.acpi_fill_ssdt_generator = southbridge_fill_ssdt,
 	.init			= lpc_init,
+	.final			= lpc_final,
 	.enable			= pch_lpc_enable,
 	.scan_bus		= scan_static_bus,
 	.ops_pci		= &pci_ops,