blob: 23637b061297c2b20db566e67048c056056d6389 [file] [log] [blame]
Patrick Rudolph6838aae2018-07-29 10:53:01 +02001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2015 Nico Huber <nico.huber@secunet.com>
Nico Huber58344fc2018-08-23 21:52:05 +02005 * Copyright (C) 2018 Nico Huber <nico.h@gmx.de>
Patrick Rudolph6838aae2018-07-29 10:53:01 +02006 * 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 Huberc48d8832018-08-23 22:36:09 +020058 Method (XBCM, 1, Serialized)
Patrick Rudolph6838aae2018-07-29 10:53:01 +020059 {
60 If (LEqual(ASLS, Zero))
61 {
62 Return (Ones)
63 }
64 If (LEqual(And(MBOX, 0x4), Zero))
65 {
66 Return (Ones)
67 }
Patrick Rudolph6838aae2018-07-29 10:53:01 +020068
Nico Huber58344fc2018-08-23 21:52:05 +020069 /* Always keep BCLP up to date, even if driver is not ready.
70 It requires a full 8-bit brightness value. 255 = 100% */
Alexander Couzens661907c2018-08-23 16:40:55 +020071 Store (Divide (Multiply (Arg0, 255), 100), Local1)
72 If (LGreater(Local1, 255)) {
73 Store (255, Local1)
74 }
Nico Huber58344fc2018-08-23 21:52:05 +020075 /* also set valid bit */
Alexander Couzens661907c2018-08-23 16:40:55 +020076 Store (Or (Local1, 0x80000000), BCLP)
77
Nico Huber58344fc2018-08-23 21:52:05 +020078 If (LEqual(ARDY, Zero))
79 {
80 Return (Ones)
81 }
82
Patrick Rudolph6838aae2018-07-29 10:53:01 +020083 /* 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 Huberc48d8832018-08-23 22:36:09 +020092 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 Rudolph6838aae2018-07-29 10:53:01 +0200100 }
101 Decrement (Local0)
102 }
103
104 Return (Ones)
105 }
Patrick Rudolph6838aae2018-07-29 10:53:01 +0200106 }
107
108 /*
109 * Pseudo device that contains methods to operate on GTT memory
110 */
111 Device (LEGA)
112 {
113 Name (_ADR, 0)
114
Nico Huberf26a7c72018-08-23 22:14:01 +0200115 /* Divide round closest */
116 Method (DRCL, 2)
Patrick Rudolph6838aae2018-07-29 10:53:01 +0200117 {
Nico Huberf26a7c72018-08-23 22:14:01 +0200118 Return (Divide (Add (Arg0, Divide (Arg1, 2)), Arg1))
Patrick Rudolph6838aae2018-07-29 10:53:01 +0200119 }
120
Nico Huberf26a7c72018-08-23 22:14:01 +0200121 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 Rudolph6838aae2018-07-29 10:53:01 +0200127 Method (XBQC, 0, NotSerialized)
128 {
Nico Huberf26a7c72018-08-23 22:14:01 +0200129 /* Local0: current percentage */
130 Store (DRCL (Multiply (BCLV, 100), BCLM), Local0)
Patrick Rudolph6838aae2018-07-29 10:53:01 +0200131
Nico Huberf26a7c72018-08-23 22:14:01 +0200132 /* 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 Rudolph6838aae2018-07-29 10:53:01 +0200147 }
Nico Huberf26a7c72018-08-23 22:14:01 +0200148
149 Increment (Local1)
Patrick Rudolph6838aae2018-07-29 10:53:01 +0200150 }
Nico Huberf26a7c72018-08-23 22:14:01 +0200151
Patrick Rudolph6838aae2018-07-29 10:53:01 +0200152 /* Didn't find greater/equal value: use the last */
Nico Huberf26a7c72018-08-23 22:14:01 +0200153 Return (Local3)
Patrick Rudolph6838aae2018-07-29 10:53:01 +0200154 }
155 }
156
Nico Huberd5842f52015-09-24 17:45:45 +0200157 Method (XBCM, 1, NotSerialized)
158 {
Patrick Rudolph6838aae2018-07-29 10:53:01 +0200159 If (LEqual(^BOX3.XBCM (Arg0), Ones))
160 {
161 ^LEGA.XBCM (Arg0)
162 }
Nico Huberd5842f52015-09-24 17:45:45 +0200163 }
164
165 Method (XBQC, 0, NotSerialized)
166 {
Nico Huberf26a7c72018-08-23 22:14:01 +0200167 /*
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 Huberd5842f52015-09-24 17:45:45 +0200173 }