summaryrefslogtreecommitdiff
path: root/src/ec/quanta/it8518/acpi/battery.asl
blob: 4fcc30c82de79e7ef83ddbf3726b86c6f3f1b326 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
/* SPDX-License-Identifier: GPL-2.0-only */

// Scope (EC0)

Device (BATX)
{
	Name (_HID, EISAID ("PNP0C0A"))
	Name (_UID, 1)
	Name (_PCL, Package () { \_SB })

	//
	// Indicator of BATX attach/detach
	// Battery X Information
	// Battery X Status
	//
	Name (BXST, Zero)

	//
	// Default Static Battery Information
	//
	Name (PBIF, Package()
	{
		0,            //  0: Power Unit
		0xFFFFFFFF,   //  1: Design Capacity
		0xFFFFFFFF,   //  2: Last Full Charge Capacity
		1,            //  3: Battery Technology(Rechargeable)
		10800,        //  4: Design Voltage 10.8V
		0,            //  5: Design capacity of warning
		0,            //  6: Design capacity of low
		1,            //  7: Battery capacity granularity 1
		1,            //  8: Battery capacity granularity 2
		"",           //  9: Model Number
		"",           // 10: Serial Number
		"",           // 11: Battery Type
		""            // 12: OEM Infomration
	})

	Name (PBST, Package ()
	{
		0x00000000,  // Battery State
		0xFFFFFFFF,  // Battery Present Rate
		0xFFFFFFFF,  // Battery Remaining Capacity
		0xFFFFFFFF,  // Battery Present Voltage
	})

	// Workaround for full battery status, enabled by default
	Name (BFWK, One)

	// Method to enable full battery workaround
	Method (BFWE)
	{
		Store (One, BFWK)
	}

	// Method to disable full battery workaround
	Method (BFWD)
	{
		Store (Zero, BFWK)
	}

	// Method to wait for EC to be ready after changing the Battery Info ID
	// Selector
	Method (WAEC)
	{
		Store (20, Local0)	// Timeout 100 msec
		While (LEqual (HSID, Zero))
		{
			// EC Is not ready
			Sleep (5)
			Local0--
			If (LEqual (Local0, Zero))
			{
				Break
			}
		}
	}

	// Battery Slot Status
	Method (_STA, 0, Serialized)
	{
		Store (MBTS, BXST)
		If (BXST)
		{
			// Battery is present
			Return (0x1F)
		}
		Else
		{
			Return (0x0F)
		}
	}

	Method (_BIF, 0, Serialized)
	{
		// Update fields from EC

		//
		// Information ID 1 -
		//
		Store (One, HIID)
		WAEC ()

		//
		//  Power Unit
		//   SMART battery : 1 - 10mWh : 0 - mAh
		//   ACPI spec     : 0 - mWh   : 1 - mAh
		//
		Store(SBCM, Local7)
		XOr (Local7, One, PBIF[0])

		//
		// Information ID 0 -
		//
		Store (Zero, HIID)
		WAEC ()

		//
		//  Last Full Charge Capacity
		//
		If (Local7)
		{
			Multiply (SBFC, 10, PBIF[2])
		}
		Else
		{
			Store (SBFC, PBIF[2])
		}

		//
		// Information ID 2 -
		//
		Store (2, HIID)
		WAEC ()

		//
		//  Design capacity
		//
		If (Local7)
		{
			Multiply (SBDC, 10, Local0)
		}
		Else
		{
			Store (SBDC, Local0)
		}
		Store (Local0, PBIF[1])

		//
		//  Design capacity of High (5%)
		//  Design capacity of Low (1%)
		//
		Divide (Local0,  20, , PBIF[5])
		Divide (Local0, 100, , PBIF[6])

		//
		//  Design voltage
		//
		Store (SBDV, PBIF[4])

		//
		// Serial Number
		//
		Store (ToHexString (SBSN), PBIF[10])

		//
		// Information ID 4 -
		//
		Store (4, HIID)
		WAEC ()

		//
		//  Battery Type - Device Chemistry
		//
		Store (ToString (Concatenate(SBCH, 0x00)), PBIF[11])

		//
		// Information ID 5 -
		//
		Store (5, HIID)
		WAEC ()

		//
		// OEM Information - Manufacturer Name
		//
		Store (ToString (Concatenate(SBMN, 0x00)), PBIF[12])

		//
		// Information ID 6 -
		//
		Store (6, HIID)
		WAEC ()

		//
		// Model Number - Device Name
		//
		Store (ToString (Concatenate(SBDN, 0x00)), PBIF[9])

		Return (PBIF)
	}

	Method (_BST, 0, Serialized)
	{
		// Update Battery First Used Date, if requested
		If (BFUD)
		{
			// TODO: Handle First Used Date Request
			//\BFUD()
		}

		//
		// 0: BATTERY STATE
		//
		// bit 0 = discharging
		// bit 1 = charging
		// bit 2 = critical level
		//

		// Get battery state from EC
		If (And (HB0S, 0x20))
		{
			Store (2, Local0)
		}
		Else
		{
			if (And (HB0S, 0x40))
			{
				Store (One, Local0)
			}
			Else
			{
				Store (Zero, Local0)
			}
		}

		// Set critical flag if battery is empty
		If (LEqual (And (HB0S, 0x0F), 0))
		{
			Or (Local0, 4, Local0)
		}

		Store (Zero, Local1)

		// Check if AC is present
		If (ACPW)
		{
			// Set only charging/discharging bits
			And (Local0, 0x03, Local1)
		}
		Else
		{
			// Always discharging when on battery power
			Store (One, Local1)
		}

		// Flag if the battery level is critical
		And (Local0, 0x04, Local4)
		Or (Local1, Local4, Local1)
		Store (Local1, PBST[0])

		//
		// 1: BATTERY PRESENT RATE/CURRENT
		//
		Store (ECAC, Local1)
		If (LGreaterEqual (Local1, 0x8000))
		{
			If (And (Local0, 1))
			{
				Local1 = 0x10000 - Local1
			}
			Else
			{
				// Error
				Store (Zero, Local1)
			}
		}
		Else
		{
			If (!(AND (Local0, 2)))
			{
				// Battery is not charging
				Store (Zero, Local1)
			}
		}

		XOr (DerefOf (PBIF[0]), One, Local6)

		If (Local6)
		{
			Multiply (ECVO, Local1, Local1)
			Divide (Local1, 1000, , Local1)
		}
		Store (Local1, PBST[1])

		//
		// 2: BATTERY REMAINING CAPACITY
		//
		// Get Power unit from the battery static information
		//   SMART battery : 1 - 10mWh : 0 - mAh
		//   ACPI spec     : 0 - mWh   : 1 - mAh
		If (Local6)
		{
			Multiply (ECRC, 10, Local1)
		}
		Else
		{
			Store (ECRC, Local1)
		}

		If (BFWK && ACPW && !Local0)
		{
			// On AC power and battery is neither charging
			// nor discharging.  Linux expects a full battery
			// to report same capacity as last full charge.
			// https://bugzilla.kernel.org/show_bug.cgi?id=12632
			// TODO: Is SBRS the "battery gas gauge"?
			Store (SBRS, Local2)

			// See if within ~3% of full
			ShiftRight (Local2, 5, Local3)
			If (LGreater (Local1, Local2 - Local3) && LLess (Local1, Local2 + Local3))
			{
				Store (Local2, Local1)
			}
		}
		Store (Local1, PBST[2])

		//
		// 3: BATTERY PRESENT VOLTAGE
		//
		Store (ECVO, PBST[3])

		Return (PBST)
	}
}