Nico Huber | 53ec8c5 | 2020-03-21 19:50:26 +0100 | [diff] [blame^] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | /* This file is part of the coreboot project. */ |
Patrick Rudolph | 6838aae | 2018-07-29 10:53:01 +0200 | [diff] [blame] | 3 | |
| 4 | /* |
| 5 | * Pseudo device that contains methods to modify Opregion |
| 6 | * "Mailbox 3 BIOS to Driver Notification" |
| 7 | * The BIOS to Driver Notification mailbox is intended to support |
| 8 | * BIOS to Driver event notification or data storage for BIOS to |
| 9 | * Driver data synchronization purpose. |
| 10 | */ |
| 11 | Device (BOX3) |
| 12 | { |
| 13 | Name (_ADR, 0) |
| 14 | |
| 15 | OperationRegion (OPRG, SystemMemory, ASLS, 0x2000) |
| 16 | Field (OPRG, DWordAcc, NoLock, Preserve) |
| 17 | { |
| 18 | // OpRegion Header |
| 19 | Offset (0x58), |
| 20 | MBOX, 32, |
| 21 | |
| 22 | // Mailbox 3 |
| 23 | Offset (0x300), |
| 24 | ARDY, 1, /* Offset 0 Driver readiness */ |
| 25 | , 31, |
| 26 | ASLC, 32, /* Offset 4 ASLE interrupt command / status */ |
| 27 | TCHE, 32, /* Offset 8 Technology enabled indicator */ |
| 28 | ALSI, 32, /* Offset 12 Current ALS illuminance reading */ |
| 29 | BCLP, 32, /* Offset 16 Backlight britness to set */ |
| 30 | PFIT, 32, /* Offset 20 Panel fitting Request */ |
| 31 | CBLV, 32, /* Offset 24 Brightness Current State */ |
| 32 | } |
| 33 | |
| 34 | /* |
| 35 | * Request back-light brightness change through mailbox 3 |
| 36 | * |
| 37 | * @param Arg0 The brightness level to set in percent |
| 38 | * @Return Zero on success, Ones on failure |
| 39 | * Errors: * ASLS is zero |
| 40 | * * Mailbox 3 support not advertised |
| 41 | * * Driver not loaded or not ready |
| 42 | * * Driver reported an error during ASLE IRQ |
| 43 | */ |
Nico Huber | c48d883 | 2018-08-23 22:36:09 +0200 | [diff] [blame] | 44 | Method (XBCM, 1, Serialized) |
Patrick Rudolph | 6838aae | 2018-07-29 10:53:01 +0200 | [diff] [blame] | 45 | { |
| 46 | If (LEqual(ASLS, Zero)) |
| 47 | { |
| 48 | Return (Ones) |
| 49 | } |
| 50 | If (LEqual(And(MBOX, 0x4), Zero)) |
| 51 | { |
| 52 | Return (Ones) |
| 53 | } |
Patrick Rudolph | 6838aae | 2018-07-29 10:53:01 +0200 | [diff] [blame] | 54 | |
Nico Huber | 58344fc | 2018-08-23 21:52:05 +0200 | [diff] [blame] | 55 | /* Always keep BCLP up to date, even if driver is not ready. |
| 56 | It requires a full 8-bit brightness value. 255 = 100% */ |
Alexander Couzens | 661907c | 2018-08-23 16:40:55 +0200 | [diff] [blame] | 57 | Store (Divide (Multiply (Arg0, 255), 100), Local1) |
| 58 | If (LGreater(Local1, 255)) { |
| 59 | Store (255, Local1) |
| 60 | } |
Nico Huber | 58344fc | 2018-08-23 21:52:05 +0200 | [diff] [blame] | 61 | /* also set valid bit */ |
Alexander Couzens | 661907c | 2018-08-23 16:40:55 +0200 | [diff] [blame] | 62 | Store (Or (Local1, 0x80000000), BCLP) |
| 63 | |
Nico Huber | 58344fc | 2018-08-23 21:52:05 +0200 | [diff] [blame] | 64 | If (LEqual(ARDY, Zero)) |
| 65 | { |
| 66 | Return (Ones) |
| 67 | } |
| 68 | |
Patrick Rudolph | 6838aae | 2018-07-29 10:53:01 +0200 | [diff] [blame] | 69 | /* Request back-light change */ |
| 70 | Store (0x2, ASLC) |
| 71 | /* Trigger IRQ */ |
| 72 | Store (0x1, ASLE) |
| 73 | |
| 74 | Store (0x20, Local0) |
| 75 | While (LGreater(Local0, Zero)) |
| 76 | { |
| 77 | Sleep (1) |
Nico Huber | c48d883 | 2018-08-23 22:36:09 +0200 | [diff] [blame] | 78 | If (LEqual (And (ASLC, 0x2), 0)) { |
| 79 | /* Request has been processed, check status: */ |
| 80 | And (ShiftRight (ASLC, 12), 0x3, Local1) |
| 81 | If (LEqual (Local1, 0)) { |
| 82 | Return (Zero) |
| 83 | } Else { |
| 84 | Return (Ones) |
| 85 | } |
Patrick Rudolph | 6838aae | 2018-07-29 10:53:01 +0200 | [diff] [blame] | 86 | } |
| 87 | Decrement (Local0) |
| 88 | } |
| 89 | |
| 90 | Return (Ones) |
| 91 | } |
Patrick Rudolph | 6838aae | 2018-07-29 10:53:01 +0200 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | /* |
| 95 | * Pseudo device that contains methods to operate on GTT memory |
| 96 | */ |
| 97 | Device (LEGA) |
| 98 | { |
| 99 | Name (_ADR, 0) |
| 100 | |
Nico Huber | f26a7c7 | 2018-08-23 22:14:01 +0200 | [diff] [blame] | 101 | /* Divide round closest */ |
| 102 | Method (DRCL, 2) |
Patrick Rudolph | 6838aae | 2018-07-29 10:53:01 +0200 | [diff] [blame] | 103 | { |
Nico Huber | f26a7c7 | 2018-08-23 22:14:01 +0200 | [diff] [blame] | 104 | Return (Divide (Add (Arg0, Divide (Arg1, 2)), Arg1)) |
Patrick Rudolph | 6838aae | 2018-07-29 10:53:01 +0200 | [diff] [blame] | 105 | } |
| 106 | |
Nico Huber | f26a7c7 | 2018-08-23 22:14:01 +0200 | [diff] [blame] | 107 | Method (XBCM, 1, NotSerialized) |
| 108 | { |
| 109 | Store (DRCL (Multiply (Arg0, BCLM), 100), BCLV) |
| 110 | } |
| 111 | |
| 112 | /* Find value closest to BCLV in BRIG (which must be ordered) */ |
Patrick Rudolph | 6838aae | 2018-07-29 10:53:01 +0200 | [diff] [blame] | 113 | Method (XBQC, 0, NotSerialized) |
| 114 | { |
Patrick Rudolph | 6dc488a | 2020-02-28 10:38:55 +0100 | [diff] [blame] | 115 | /* Prevent DivideByZero if backlight control isn't enabled */ |
| 116 | If (BCLM == 0) |
| 117 | { |
| 118 | Return (Zero) |
| 119 | } |
Nico Huber | f26a7c7 | 2018-08-23 22:14:01 +0200 | [diff] [blame] | 120 | /* Local0: current percentage */ |
| 121 | Store (DRCL (Multiply (BCLV, 100), BCLM), Local0) |
Patrick Rudolph | 6838aae | 2018-07-29 10:53:01 +0200 | [diff] [blame] | 122 | |
Nico Huber | f26a7c7 | 2018-08-23 22:14:01 +0200 | [diff] [blame] | 123 | /* Local1: loop index (selectable values start at 2 in BRIG) */ |
| 124 | Store (2, Local1) |
| 125 | While (LLess (Local1, Subtract (SizeOf (BRIG), 1))) { |
| 126 | /* Local[23]: adjacent values in BRIG */ |
| 127 | Store (DeRefOf (Index (BRIG, Local1)), Local2) |
| 128 | Store (DeRefOf (Index (BRIG, Add (Local1, 1))), Local3) |
| 129 | |
| 130 | If (LLess (Local0, Local3)) { |
| 131 | If (LOr (LLess (Local0, Local2), |
| 132 | LLess (Subtract (Local0, Local2), |
| 133 | Subtract (Local3, Local0)))) { |
| 134 | Return (Local2) |
| 135 | } Else { |
| 136 | Return (Local3) |
| 137 | } |
Patrick Rudolph | 6838aae | 2018-07-29 10:53:01 +0200 | [diff] [blame] | 138 | } |
Nico Huber | f26a7c7 | 2018-08-23 22:14:01 +0200 | [diff] [blame] | 139 | |
| 140 | Increment (Local1) |
Patrick Rudolph | 6838aae | 2018-07-29 10:53:01 +0200 | [diff] [blame] | 141 | } |
Nico Huber | f26a7c7 | 2018-08-23 22:14:01 +0200 | [diff] [blame] | 142 | |
Patrick Rudolph | 6838aae | 2018-07-29 10:53:01 +0200 | [diff] [blame] | 143 | /* Didn't find greater/equal value: use the last */ |
Nico Huber | f26a7c7 | 2018-08-23 22:14:01 +0200 | [diff] [blame] | 144 | Return (Local3) |
Patrick Rudolph | 6838aae | 2018-07-29 10:53:01 +0200 | [diff] [blame] | 145 | } |
| 146 | } |
| 147 | |
Nico Huber | d5842f5 | 2015-09-24 17:45:45 +0200 | [diff] [blame] | 148 | Method (XBCM, 1, NotSerialized) |
| 149 | { |
Patrick Rudolph | 6838aae | 2018-07-29 10:53:01 +0200 | [diff] [blame] | 150 | If (LEqual(^BOX3.XBCM (Arg0), Ones)) |
| 151 | { |
| 152 | ^LEGA.XBCM (Arg0) |
| 153 | } |
Nico Huber | d5842f5 | 2015-09-24 17:45:45 +0200 | [diff] [blame] | 154 | } |
| 155 | |
| 156 | Method (XBQC, 0, NotSerialized) |
| 157 | { |
Nico Huber | f26a7c7 | 2018-08-23 22:14:01 +0200 | [diff] [blame] | 158 | /* |
| 159 | * Always query the hardware directly. Not all OS drivers |
| 160 | * keep CBLV up to date (one is Linux' i915). Some years |
| 161 | * after that is fixed we can probably use CBLV? |
| 162 | */ |
| 163 | Return (^LEGA.XBQC ()) |
Nico Huber | d5842f5 | 2015-09-24 17:45:45 +0200 | [diff] [blame] | 164 | } |