Debian Codegraph @

src/drivers/intel/gma/acpi/configure_brightness_levels.asl

raw
1 /* SPDX-License-Identifier: GPL-2.0-only */
2
3 /*
4 * Pseudo device that contains methods to modify Opregion
5 * "Mailbox 3 BIOS to Driver Notification"
6 * The BIOS to Driver Notification mailbox is intended to support
7 * BIOS to Driver event notification or data storage for BIOS to
8 * Driver data synchronization purpose.
9 */
10 Device (BOX3)
11 {
12 Name (_ADR, 0)
13 /*
14 * Only cover MBOX3 since Windows 10/11 doesn't like
15 * when the full (MBOX4/MBOX5 as well) OpRegion is covered.
16 */
17 OperationRegion (OPRG, SystemMemory, ASLS, 0x400)
18 Field (OPRG, DWordAcc, NoLock, Preserve)
19 {
20 // OpRegion Header
21 Offset (0x58),
22 MBOX, 32,
23
24 // Mailbox 3
25 Offset (0x300),
26 ARDY, 1, /* Offset 0 Driver readiness */
27 , 31,
28 ASLC, 32, /* Offset 4 ASLE interrupt command / status */
29 TCHE, 32, /* Offset 8 Technology enabled indicator */
30 ALSI, 32, /* Offset 12 Current ALS illuminance reading */
31 BCLP, 32, /* Offset 16 Backlight britness to set */
32 PFIT, 32, /* Offset 20 Panel fitting Request */
33 CBLV, 32, /* Offset 24 Brightness Current State */
34 }
35
36 /*
37 * Request back-light brightness change through mailbox 3
38 *
39 * @param Arg0 The brightness level to set in percent
40 * @Return 0 on success, Ones on failure
41 * Errors: * ASLS is zero
42 * * Mailbox 3 support not advertised
43 * * Driver not loaded or not ready
44 * * Driver reported an error during ASLE IRQ
45 */
46 Method (XBCM, 1, Serialized)
47 {
48 If (ASLS == 0)
49 {
50 Return (Ones)
51 }
52 If ((MBOX & 4) == 0)
53 {
54 Return (Ones)
55 }
56
57 /* Always keep BCLP up to date, even if driver is not ready.
58 It requires a full 8-bit brightness value. 255 = 100% */
59 Local1 = Arg0 * 255 / 100
60 If (Local1 > 255) {
61 Local1 = 255
62 }
63 /* also set valid bit */
64 BCLP = Local1 | 0x80000000
65
66 If (ARDY == 0)
67 {
68 Return (Ones)
69 }
70
71 /* Request back-light change */
72 ASLC = 0x2
73 /* Trigger IRQ */
74 ASLE = 0x1
75
76 Local0 = 0x20
77 While (Local0 > 0)
78 {
79 Sleep (1)
80 If ((ASLC & 2) == 0) {
81 /* Request has been processed, check status: */
82 Local1 = (ASLC >> 12) & 3
83 If (Local1 == 0) {
84 Return (0)
85 } Else {
86 Return (Ones)
87 }
88 }
89 Local0--
90 }
91
92 Return (Ones)
93 }
94 }
95
96 /*
97 * Pseudo device that contains methods to operate on GTT memory
98 */
99 Device (LEGA)
100 {
101 Name (_ADR, 0)
102
103 /* Divide round closest */
104 Method (DRCL, 2)
105 {
106 Return ((Arg0 + Arg1 / 2) / Arg1)
107 }
108
109 Method (XBCM, 1, NotSerialized)
110 {
111 BCLV = DRCL (Arg0 * BCLM, 100)
112 }
113
114 /* Find value closest to BCLV in BRIG (which must be ordered) */
115 Method (XBQC, 0, NotSerialized)
116 {
117 /* Prevent DivideByZero if backlight control isn't enabled */
118 If (BCLM == 0)
119 {
120 Return (0)
121 }
122 /* Local0: current percentage */
123 Local0 = DRCL (BCLV * 100, BCLM)
124
125 /* Local1: loop index (selectable values start at 2 in BRIG) */
126 Local1 = 2
127 While (Local1 < SizeOf (BRIG) - 1) {
128 /* Local[23]: adjacent values in BRIG */
129 Local2 = DeRefOf (BRIG[Local1])
130 Local3 = DeRefOf (BRIG[Local1 + 1])
131
132 If (Local0 < Local3) {
133 If (Local0 < Local2 || Local0 - Local2 < Local3 - Local0) {
134 Return (Local2)
135 } Else {
136 Return (Local3)
137 }
138 }
139
140 Local1++
141 }
142
143 /* Didn't find greater/equal value: use the last */
144 Return (Local3)
145 }
146 }
147
148 Method (XBCM, 1, NotSerialized)
149 {
150 If (^BOX3.XBCM (Arg0) == Ones)
151 {
152 ^LEGA.XBCM (Arg0)
153 }
154 }
155
156 Method (XBQC, 0, NotSerialized)
157 {
158 /*
159 * Always query the hardware directly. Not all OS drivers
160 * keep CBLV up to date (one is Linux' i915). Some years
161 * after that is fixed we can probably use CBLV?
162 */
163 Return (^LEGA.XBQC ())
164 }