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