• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1/* SPDX-License-Identifier: GPL-2.0-only */
2
3/*
4 * This defines the battery charging thresholds setting methods tpacpi-bat can
5 * use. This implements what the vendor defines but is rather ugly...
6 */
7
8/* SetBatteryCharge Start/Stop Capacity Threshold
9 * In Parameter:
10 * DWORD
11 * Bit 7-0: Charge stop capacity (Unit:%)
12 *     =0: Use battery default setting
13 *     =1-99: Threshold to stop charging battery (Relative capacity)
14 * Bit 9-8:BatteryID
15 *    = 0: Any battery
16 *    = 1: Primary battery
17 *    = 2: Secondary battery
18 *    = Others: Reserved (0)
19 * Bit 31-10: Reserved (0)
20 *     Must be 0
21 *
22 * Out Parameter:
23 * DWORD
24 * Bit 30-0: Reserved (0)
25 * Bit 31:     Error status
26 *  0 ... Success
27 *  1 ... Fail
28 */
29
30#define START_THRESH_ARG 0
31#define STOP_THRESH_ARG 1
32
33// Set stop threshold
34Method (BCSS, 1, NotSerialized)
35{
36	Local0 = Arg0 & 0xff        // Percentage
37	Local1 = (Arg0 >> 8) & 0x3  // Battery ID
38
39	// Any battery
40	If (Local1 == 0)
41	{
42		\_SB.PCI0.LPCB.EC.BAT0.SETT(STOP_THRESH_ARG, Local0)
43		\_SB.PCI0.LPCB.EC.BAT1.SETT(STOP_THRESH_ARG, Local0)
44
45		Local2 = Local0 != \_SB.PCI0.LPCB.EC.BAT0.GETT(STOP_THRESH_ARG)
46		Local3 = Local0 != \_SB.PCI0.LPCB.EC.BAT1.GETT(STOP_THRESH_ARG)
47
48		Return ((Local2 && Local3) << 31)
49	}
50
51	// Battery1
52	If (Local1 == 1)
53	{
54		\_SB.PCI0.LPCB.EC.BAT0.SETT(STOP_THRESH_ARG, Local0)
55		Return ((Local0 !=
56			\_SB.PCI0.LPCB.EC.BAT0.GETT(STOP_THRESH_ARG)) << 31)
57	}
58
59	// Battery2
60	If (Local1 == 2)
61	{
62		\_SB.PCI0.LPCB.EC.BAT1.SETT(STOP_THRESH_ARG, Local0)
63		Return ((Local0 !=
64			\_SB.PCI0.LPCB.EC.BAT1.GETT(STOP_THRESH_ARG)) << 31)
65	}
66
67	Return (1 << 31) /* Should not be reached */
68}
69
70// Set start threshold
71Method (BCCS, 1, NotSerialized)
72{
73	Local0 = Arg0 & 0xff        // Percentage
74	Local1 = (Arg0 >> 8) & 0x3  // Battery ID
75
76	// Any battery
77	If (Local1 == 0)
78	{
79		\_SB.PCI0.LPCB.EC.BAT0.SETT(START_THRESH_ARG, Local0)
80		\_SB.PCI0.LPCB.EC.BAT1.SETT(START_THRESH_ARG, Local0)
81
82		Local2 = Local0 != \_SB.PCI0.LPCB.EC.BAT0.GETT(START_THRESH_ARG)
83		Local3 = Local0 != \_SB.PCI0.LPCB.EC.BAT1.GETT(START_THRESH_ARG)
84
85		Return ((Local2 && Local3) << 31)
86	}
87
88	// Battery1
89	If (Local1 == 1)
90	{
91		\_SB.PCI0.LPCB.EC.BAT0.SETT(START_THRESH_ARG, Local0)
92		Return ((Local0 !=
93			\_SB.PCI0.LPCB.EC.BAT0.GETT(START_THRESH_ARG)) << 31)
94	}
95
96	// Battery2
97	If (Local1 == 2)
98	{
99		\_SB.PCI0.LPCB.EC.BAT1.SETT(START_THRESH_ARG, Local0)
100		Return ((Local0 !=
101			\_SB.PCI0.LPCB.EC.BAT1.GETT(START_THRESH_ARG)) << 31)
102	}
103
104	Return (1 << 31) /* Should not be reached */
105}
106
107/*
108 * GetBatteryCharge Start/Stop Capacity Threshold
109 * In Parameter:
110 * DWORD
111 * Bit 7-0:BatteryID
112 * Bit 31-8: Reserved (0)
113 *     Must be 0
114 *
115 * Out Parameter:
116 * DWORD
117 * Bit 7-0: Charge stop capacity (Unit:%)
118 *     =0: Use battery default setting
119 *     =1-99: Threshold to stop charging battery (Relative capacity)
120 *     =Others: Reserved (0)
121 * Bit 9-8: Capability of BatteryCharge Stop Capacity Threshold
122 * Bit 8:Batterycharge stop capacity threshold
123 *     (0:Not support   1:Support)
124 * Bit 9: Specify every battery parameter
125 *     (0:Not support(apply parameter for all battery)
126 *      1:Support(apply parameter for all battery))
127 * Bit 30-10: Reserved (0)
128 * Bit 31:     Error status
129 *     0 ... Success
130 *     1 ... Fail
131*/
132
133// Get stop threshold
134Method (BCSG, 1, NotSerialized)
135{
136	// Battery1
137	If (Arg0 == 1)
138	{
139		Return (0x300 | \_SB.PCI0.LPCB.EC.BAT0.GETT(STOP_THRESH_ARG))
140	}
141
142	// Battery2
143	If (Arg0 == 2)
144	{
145		Return (0x300 | \_SB.PCI0.LPCB.EC.BAT1.GETT(STOP_THRESH_ARG))
146	}
147
148	Return (1 << 31)
149}
150
151// Get start threshold
152Method (BCTG, 1, NotSerialized)
153{
154	// Battery 1
155	If (Arg0 == 1)
156	{
157		Return (0x300 | \_SB.PCI0.LPCB.EC.BAT0.GETT(START_THRESH_ARG))
158	}
159
160	// Battery 2
161	If (Arg0 == 2)
162	{
163		Return (0x300 | \_SB.PCI0.LPCB.EC.BAT1.GETT(START_THRESH_ARG))
164	}
165
166	Return (1 << 31)
167}
168