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