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