[coreboot-gerrit] Change in coreboot[master]: drvs/intel/gma/acpi: Add methods to use MBOX3

Patrick Rudolph (Code Review) gerrit at coreboot.org
Sun Jul 29 10:57:22 CEST 2018


Patrick Rudolph has uploaded this change for review. ( https://review.coreboot.org/27711


Change subject: drvs/intel/gma/acpi: Add methods to use MBOX3
......................................................................

drvs/intel/gma/acpi: Add methods to use MBOX3

* Add Mailbox 3 driver
* Request brightness change through Mailbox 3
* Return Ones on error or if unsupported
* Mark existing code as legacy
  (still required if no GMA driver is running)
* Call legacy code if Mailbox 3 is unsupported, on error or
  if gma driver isn't running

Tested on Lenovo T430:
* Brightness control still works
* Brightness is the same on S3 resume

Change-Id: I51554c819148336b204d28972cbf775a10c3fb8a
Signed-off-by: Patrick Rudolph <siro at das-labor.org>
---
M src/drivers/intel/gma/acpi/common.asl
M src/drivers/intel/gma/acpi/configure_brightness_levels.asl
M src/drivers/intel/gma/acpi/non-pch.asl
M src/drivers/intel/gma/acpi/pch.asl
4 files changed, 152 insertions(+), 21 deletions(-)



  git pull ssh://review.coreboot.org:29418/coreboot refs/changes/11/27711/1

diff --git a/src/drivers/intel/gma/acpi/common.asl b/src/drivers/intel/gma/acpi/common.asl
index 7415859..009e3a5 100644
--- a/src/drivers/intel/gma/acpi/common.asl
+++ b/src/drivers/intel/gma/acpi/common.asl
@@ -44,8 +44,11 @@
 		Store (And(Arg0, 7), DSEN)
 	}
 
-	/* Using Notify is the right way. But Windows doesn't handle
-	   it well. So use both method in a way to avoid double action.
+	/*
+	 * Decrement display brightness.
+	 *
+	 * Using Notify is the right way. But Windows doesn't handle
+	 * it well. So use both method in a way to avoid double action.
 	 */
 	Method (DECB, 0, NotSerialized)
 	{
@@ -62,6 +65,9 @@
 		}
 	}
 
+	/*
+	 * Increment display brightness.
+	 */
 	Method (INCB, 0, NotSerialized)
 	{
 		If (BRCT)
diff --git a/src/drivers/intel/gma/acpi/configure_brightness_levels.asl b/src/drivers/intel/gma/acpi/configure_brightness_levels.asl
index 38eb116..5f19e97 100644
--- a/src/drivers/intel/gma/acpi/configure_brightness_levels.asl
+++ b/src/drivers/intel/gma/acpi/configure_brightness_levels.asl
@@ -1,24 +1,141 @@
+
+	/*
+	 * Pseudo device that contains methods to modify Opregion
+	 * "Mailbox 3 BIOS to Driver Notification"
+	 * The BIOS to Driver Notification mailbox is intended to support
+	 * BIOS to Driver event notification or data storage for BIOS to
+	 * Driver data synchronization purpose.
+	*/
+	Device (BOX3)
+	{
+		Name (_ADR, 0)
+
+		OperationRegion (OPRG, SystemMemory, ASLS, 0x2000)
+		Field (OPRG, DWordAcc, NoLock, Preserve)
+		{
+			// OpRegion Header
+			Offset (0x58),
+			MBOX, 32,
+
+			// Mailbox 3
+			Offset (0x300),
+			ARDY, 32,	/* Offset 0   Driver readiness */
+			ASLC, 32,	/* Offset 4   ASLE interrupt command / status */
+			TCHE, 32,	/* Offset 8   Technology enabled indicator */
+			ALSI, 32,	/* Offset 12  Current ALS illuminance reading */
+			BCLP, 32,	/* Offset 16  Backlight britness to set */
+			PFIT, 32,	/* Offset 20  Panel fitting Request */
+			CBLV, 32,	/* Offset 24  Brightness Current State */
+		}
+
+		/*
+		 * Request back-light brightness change through mailbox 3
+		 *
+		 * @param Arg0 The brightness level to set in percent
+		 * @Return Ones on failure
+		 */
+		Method (XBCM, 1, NotSerialized)
+		{
+			If (LEqual(And(MBOX, 0x4), Zero))
+			{
+				Return (Ones)
+			}
+			If (LEqual(ARDY, Zero))
+			{
+				Return (Ones)
+			}
+
+			Store (Or (Arg0, 0x80000000), BCLP)
+			/* Request back-light change */
+			Store (0x2, ASLC)
+			/* Trigger IRQ */
+			Store (0x1, ASLE)
+
+			Store (0x20, Local0)
+			While (LGreater(Local0, Zero))
+			{
+				Sleep (1)
+				If (LEqual(And(ShiftRight(ASLC, 12), 0x3), Zero))
+				{
+					Return (Zero)
+				}
+				Decrement (Local0)
+			}
+
+			Return (Ones)
+		}
+
+		/*
+		 * Get current back-light brightness through mailbox 3
+		 *
+		 * @Return The current brightness or Ones on error
+		 */
+		Method (XBQC, 0, NotSerialized)
+		{
+			If (LEqual(And(MBOX, 0x4), Zero))
+			{
+				Return (Ones)
+			}
+			If (LEqual(ARDY, Zero))
+			{
+				Return (Ones)
+			}
+			If (LEqual(And (CBLV, 0x80000000), Zero))
+			{
+				Return (Ones)
+			}
+			Return (And (CBLV, 0xff))
+		}
+	}
+
+	/*
+	 * Pseudo device that contains methods to operate on PCI registers
+	 */
+	Device (LEGA)
+	{
+		Name (_ADR, 0)
+
+		Method (XBCM, 1, NotSerialized)
+		{
+			Store (Divide (Multiply (Arg0, BCLM), 100), BCLV)
+		}
+
+		Method (XBQC, 0, NotSerialized)
+		{
+			/* Find value close to BCLV in BRIG (which must be ordered) */
+			Store (BCLV, Local0)			// Current value
+			Store (BCLM, Local1)			// For calculations
+			Store (2, Local2)			// Loop index
+			While (LLess (Local2, Subtract (SizeOf (BRIG), 1))) {
+				Store (DeRefOf (Index (BRIG, Local2)), Local3)
+				/* Use same calculation as XBCM, to get exact matches */
+				Store (Divide (Multiply (Local3, Local1), 100), Local3)
+
+				If (LLessEqual (Local0, Local3)) {
+					Return (DeRefOf (Index (BRIG, Local2)))
+				}
+				Add (Local2, 1, Local2)
+			}
+			/* Didn't find greater/equal value: use the last */
+			Return (DeRefOf (Index (BRIG, Local2)))
+		}
+	}
+
 	Method (XBCM, 1, NotSerialized)
 	{
-		Store (Divide (Multiply (Arg0, BCLM), 100), BCLV)
+		If (LEqual(^BOX3.XBCM (Arg0), Ones))
+		{
+			//LEGA.XBCM (Arg0)
+		}
 	}
 
 	Method (XBQC, 0, NotSerialized)
 	{
-		/* Find value close to BCLV in BRIG (which must be ordered) */
-		Store (BCLV, Local0)			// Current value
-		Store (BCLM, Local1)			// For calculations
-		Store (2, Local2)			// Loop index
-		While (LLess (Local2, Subtract (SizeOf (BRIG), 1))) {
-			Store (DeRefOf (Index (BRIG, Local2)), Local3)
-			/* Use same calculation as XBCM, to get exact matches */
-			Store (Divide (Multiply (Local3, Local1), 100), Local3)
+		Store (^BOX3.XBQC (), Local0)
+		//If (LEqual(Local0, Ones))
+		//{
+		//	Store (LEGA.XBCM (Arg0), Local0)
+		//}
 
-			If (LLessEqual (Local0, Local3)) {
-				Return (DeRefOf (Index (BRIG, Local2)))
-			}
-			Add (Local2, 1, Local2)
-		}
-		/* Didn't find greater/equal value: use the last */
-		Return (DeRefOf (Index (BRIG, Local2)))
-	}
+		Return (Local0)
+	}
\ No newline at end of file
diff --git a/src/drivers/intel/gma/acpi/non-pch.asl b/src/drivers/intel/gma/acpi/non-pch.asl
index ef8f3ff..c35d251 100644
--- a/src/drivers/intel/gma/acpi/non-pch.asl
+++ b/src/drivers/intel/gma/acpi/non-pch.asl
@@ -22,7 +22,11 @@
 	Field (GFXC, DWordAcc, NoLock, Preserve)
 	{
 		Offset (0x10),
-		BAR0, 64
+		BAR0, 64,
+		Offset (0xe4),
+		ASLE, 32,
+		Offset (0xfc),
+		ASLS, 32,
 	}
 
 	OperationRegion (GFRG, SystemMemory, And (BAR0, 0xfffffffffffffff0), 0x400000)
diff --git a/src/drivers/intel/gma/acpi/pch.asl b/src/drivers/intel/gma/acpi/pch.asl
index 3191196..b7bb324 100644
--- a/src/drivers/intel/gma/acpi/pch.asl
+++ b/src/drivers/intel/gma/acpi/pch.asl
@@ -22,7 +22,11 @@
 	Field (GFXC, DWordAcc, NoLock, Preserve)
 	{
 		Offset (0x10),
-		BAR0, 64
+		BAR0, 64,
+		Offset (0xe4),
+		ASLE, 32,
+		Offset (0xfc),
+		ASLS, 32,
 	}
 
 	OperationRegion (GFRG, SystemMemory, And (BAR0, 0xfffffffffffffff0), 0x400000)

-- 
To view, visit https://review.coreboot.org/27711
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings

Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I51554c819148336b204d28972cbf775a10c3fb8a
Gerrit-Change-Number: 27711
Gerrit-PatchSet: 1
Gerrit-Owner: Patrick Rudolph <siro at das-labor.org>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.coreboot.org/pipermail/coreboot-gerrit/attachments/20180729/56f4839e/attachment-0001.html>


More information about the coreboot-gerrit mailing list