summaryrefslogtreecommitdiff
path: root/src/mainboard/purism/librem_jsl/acpi/battery.asl
blob: 73d5d65c97d6a2ac0c6f0182a6b49d43acf0af42 (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
/* SPDX-License-Identifier: GPL-2.0-only */

Device (BAT0)
{
	Name (_HID, EisaId ("PNP0C0A") /* Control Method Battery */)  // _HID: Hardware ID
	Name (_UID, Zero)  // _UID: Unique ID
	Name (_PCL, Package (0x01)  // _PCL: Power Consumer List
	{
		_SB
	})

	Name (BTEX, Zero)

	// Test if EC0 is ready, and if it is, if the battery is present
	Method (BTOK, 0, NotSerialized)
	{
		If (^^ECOK) {
			If (BTEX) {
				Return (One)
			}
		}

		Return (Zero)
	}

	Method (_STA, 0, NotSerialized)  // _STA: Status
	{
		If (BTOK ()) {
			Printf ("BAT0: _STA: present")
			Return (0x1F)
		}

		Printf ("BAT0: _STA: not present")
		Return (0x0F)
	}

	Name (PBIF, Package (0x0D)	// Persistent battery information
	{
		One, // 0 - Power Unit - mA/mAh
		0xFFFFFFFF, // 1 - Design Capacity
		0xFFFFFFFF, // 2 - Last Full Charge Capacity
		One, // 3 - Battery Technology
		0xFFFFFFFF, // 4 - Design Voltage
		Zero, // 5 - Design Capacity of Warning
		Zero, // 6 - Design Capacity of Low
		Zero, // 7 - Battery Capacity Granularity 1
		Zero, // 8 - Battery Capacity Granularity 2
		"", // 9 - Model Number
		"", // 10 - Serial Number
		"", // 11 - Battery Type
		"" // 12 - OEM Information
	})

	Method (IVBI, 0, NotSerialized)	// Set invalid battery information
	{
		PBIF [1] = 0xFFFFFFFF
		PBIF [2] = 0xFFFFFFFF
		PBIF [5] = Zero
		PBIF [6] = Zero
		PBIF [7] = Zero
		PBIF [8] = Zero
		PBIF [9] = ""
		PBIF [10] = ""
		PBIF [11] = ""
	}

	Method (UPBI, 0, Serialized)	// Update battery information
	{
		If (BTOK ()) {
			Local0 = ^^BTDC // design cap
			Local1 = ^^BTFC // last full capacity
			// Design capacity
			PBIF [1] = Local0
			// Last full charge capacity
			PBIF [2] = Local1
			// Warn/low capacities - 15% and 10% of design capacity
			PBIF [5] = Local1 * 15 / 100
			PBIF [6] = Local1 * 10 / 100
			// Granularity is 1% of design capacity
			PBIF [7] = Local0 / 100
			PBIF [8] = Local0 / 100
			PBIF [9] = "BAT"
			PBIF [10] = "0001"
			PBIF [11] = "LION"
		}
		Else {
			IVBI ()
		}
	}

	Method (_BIF, 0, NotSerialized)  // _BIF: Battery Information
	{
		UPBI ()
		Return (PBIF)
	}

	Name (PBST, Package (0x04)	// Persistent battery state
	{
		Zero, // 0 - Battery state
		0xFFFFFFFF, // 1 - Battery present rate
		0xFFFFFFFF, // 2 - Battery remaining capacity
		0xFFFFFFFF // 3 - Battery present voltage
	})

	Method (IVBS, 0, NotSerialized)	// Invalid battery state
	{
		PBST [0] = Zero
		PBST [1] = 0xFFFFFFFF
		PBST [2] = 0xFFFFFFFF
		PBST [3] = 0xFFFFFFFF
	}

	Method (UPBS, 0, Serialized)
	{
		If (BTOK ()) {
			// Status flags - 3 bits; this EC does not report the
			// charge limiting state
			PBST [0] = ^^BTST
			// Present rate
			PBST [1] = ^^BTCR
			// Remaining capacity
			PBST [2] = ^^BTRC
			// Present voltage
			PBST [3] = ^^BTVT
		}
		Else {
			IVBS ()
		}
	}

	Method (_BST, 0, NotSerialized)  // _BST: Battery Status
	{
		UPBS ()
		Return (PBST)
	}
}