blob: 21f0b2318ea350e80f1d5fb864ecfdbf498f9c87 [file] [log] [blame]
Patrick Rudolph6838aae2018-07-29 10:53:01 +02001/*
2 * This file is part of the coreboot project.
3 *
Patrick Rudolph6838aae2018-07-29 10:53:01 +02004 * 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 Huberc48d8832018-08-23 22:36:09 +020054 Method (XBCM, 1, Serialized)
Patrick Rudolph6838aae2018-07-29 10:53:01 +020055 {
56 If (LEqual(ASLS, Zero))
57 {
58 Return (Ones)
59 }
60 If (LEqual(And(MBOX, 0x4), Zero))
61 {
62 Return (Ones)
63 }
Patrick Rudolph6838aae2018-07-29 10:53:01 +020064
Nico Huber58344fc2018-08-23 21:52:05 +020065 /* Always keep BCLP up to date, even if driver is not ready.
66 It requires a full 8-bit brightness value. 255 = 100% */
Alexander Couzens661907c2018-08-23 16:40:55 +020067 Store (Divide (Multiply (Arg0, 255), 100), Local1)
68 If (LGreater(Local1, 255)) {
69 Store (255, Local1)
70 }
Nico Huber58344fc2018-08-23 21:52:05 +020071 /* also set valid bit */
Alexander Couzens661907c2018-08-23 16:40:55 +020072 Store (Or (Local1, 0x80000000), BCLP)
73
Nico Huber58344fc2018-08-23 21:52:05 +020074 If (LEqual(ARDY, Zero))
75 {
76 Return (Ones)
77 }
78
Patrick Rudolph6838aae2018-07-29 10:53:01 +020079 /* 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 Huberc48d8832018-08-23 22:36:09 +020088 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 Rudolph6838aae2018-07-29 10:53:01 +020096 }
97 Decrement (Local0)
98 }
99
100 Return (Ones)
101 }
Patrick Rudolph6838aae2018-07-29 10:53:01 +0200102 }
103
104 /*
105 * Pseudo device that contains methods to operate on GTT memory
106 */
107 Device (LEGA)
108 {
109 Name (_ADR, 0)
110
Nico Huberf26a7c72018-08-23 22:14:01 +0200111 /* Divide round closest */
112 Method (DRCL, 2)
Patrick Rudolph6838aae2018-07-29 10:53:01 +0200113 {
Nico Huberf26a7c72018-08-23 22:14:01 +0200114 Return (Divide (Add (Arg0, Divide (Arg1, 2)), Arg1))
Patrick Rudolph6838aae2018-07-29 10:53:01 +0200115 }
116
Nico Huberf26a7c72018-08-23 22:14:01 +0200117 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 Rudolph6838aae2018-07-29 10:53:01 +0200123 Method (XBQC, 0, NotSerialized)
124 {
Patrick Rudolph6dc488a2020-02-28 10:38:55 +0100125 /* Prevent DivideByZero if backlight control isn't enabled */
126 If (BCLM == 0)
127 {
128 Return (Zero)
129 }
Nico Huberf26a7c72018-08-23 22:14:01 +0200130 /* Local0: current percentage */
131 Store (DRCL (Multiply (BCLV, 100), BCLM), Local0)
Patrick Rudolph6838aae2018-07-29 10:53:01 +0200132
Nico Huberf26a7c72018-08-23 22:14:01 +0200133 /* 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 Rudolph6838aae2018-07-29 10:53:01 +0200148 }
Nico Huberf26a7c72018-08-23 22:14:01 +0200149
150 Increment (Local1)
Patrick Rudolph6838aae2018-07-29 10:53:01 +0200151 }
Nico Huberf26a7c72018-08-23 22:14:01 +0200152
Patrick Rudolph6838aae2018-07-29 10:53:01 +0200153 /* Didn't find greater/equal value: use the last */
Nico Huberf26a7c72018-08-23 22:14:01 +0200154 Return (Local3)
Patrick Rudolph6838aae2018-07-29 10:53:01 +0200155 }
156 }
157
Nico Huberd5842f52015-09-24 17:45:45 +0200158 Method (XBCM, 1, NotSerialized)
159 {
Patrick Rudolph6838aae2018-07-29 10:53:01 +0200160 If (LEqual(^BOX3.XBCM (Arg0), Ones))
161 {
162 ^LEGA.XBCM (Arg0)
163 }
Nico Huberd5842f52015-09-24 17:45:45 +0200164 }
165
166 Method (XBQC, 0, NotSerialized)
167 {
Nico Huberf26a7c72018-08-23 22:14:01 +0200168 /*
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 Huberd5842f52015-09-24 17:45:45 +0200174 }