xref: /titanic_50/usr/src/uts/common/sys/acpi_drv.h (revision 28b6fd27d5ff75fe6fdeb119a21575b0652a7e70)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License (the "License").
6  * You may not use this file except in compliance with the License.
7  *
8  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9  * or http://www.opensolaris.org/os/licensing.
10  * See the License for the specific language governing permissions
11  * and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL HEADER in each
14  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15  * If applicable, add the following below this CDDL HEADER, with the
16  * fields enclosed by brackets "[]" replaced with your own identifying
17  * information: Portions Copyright [yyyy] [name of copyright owner]
18  *
19  * CDDL HEADER END
20  */
21 
22 /*
23  * Copyright 2009 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 /*
28  * Copyright 2015 Hans Rosenfeld <rosenfeld@grumpf.hope-2000.org>
29  */
30 
31 #ifndef _ACPI_DRV_H
32 #define	_ACPI_DRV_H
33 
34 #ifdef	__cplusplus
35 extern "C" {
36 #endif
37 
38 #include <sys/param.h>
39 #include <sys/kstat.h>
40 
41 enum acpi_drv_ioctl {
42 	ACPI_DRV_IOC_BAY,
43 	ACPI_DRV_IOC_INFO,
44 	ACPI_DRV_IOC_STATUS,
45 	ACPI_DRV_IOC_AC_COUNT,
46 	ACPI_DRV_IOC_POWER_STATUS,
47 	ACPI_DRV_IOC_SET_WARNING,
48 	ACPI_DRV_IOC_GET_WARNING,
49 	ACPI_DRV_IOC_LID_STATUS,
50 	ACPI_DRV_IOC_LID_UPDATE,
51 	ACPI_DRV_IOC_LEVELS,
52 	ACPI_DRV_IOC_SET_BRIGHTNESS
53 };
54 
55 #define	ACPI_DRV_BST_CHARGING		2
56 #define	ACPI_DRV_BST_DISCHARGING	1
57 
58 typedef struct batt_bay {
59 	/* Total number of bays in the system */
60 	int bay_number;
61 
62 	/*
63 	 * Bitmap for each bay and its battery.
64 	 * battery_map bit i:
65 	 *    1 -- battery inserted to bay i
66 	 *    0 -- bay i empty
67 	 */
68 	uint64_t battery_map;
69 } batt_bay_t;
70 
71 typedef	struct acpi_bif {
72 	uint32_t	bif_unit;
73 
74 	/*
75 	 * 0x00000000 - 0x7fffffff
76 	 * 0xffffffff - Unknown design capacity in [mWh] or [mAh]
77 	 */
78 	uint32_t	bif_design_cap;
79 
80 	/*
81 	 * 0x00000000 - 0x7fffffff
82 	 * 0xffffffff - Unknown last full charge capacity in [mWh] or [mAh]
83 	 */
84 	uint32_t	bif_last_cap;
85 
86 	uint32_t	bif_tech;
87 
88 	/*
89 	 * 0x00000000 - 0x7fffffff
90 	 * 0xffffffff - Unknown design voltage in [mV]
91 	 */
92 	uint32_t	bif_voltage;
93 
94 	/*
95 	 * 0x00000000 - 0x7fffffff in [mWh] or [mAh]
96 	 */
97 	uint32_t	bif_warn_cap;
98 
99 	/*
100 	 * 0x00000000 - 0x7fffffff in [mWh] or [mAh]
101 	 */
102 	uint32_t	bif_low_cap;
103 
104 	uint32_t	bif_gran1_cap;
105 	uint32_t	bif_gran2_cap;
106 	char		bif_model[MAXNAMELEN];
107 	char		bif_serial[MAXNAMELEN];
108 	char		bif_type[MAXNAMELEN];
109 	char		bif_oem_info[MAXNAMELEN];
110 } acpi_bif_t;
111 
112 typedef	struct acpi_bst {
113 	uint32_t	bst_state;
114 
115 	/*
116 	 * 0x00000000 - 0x7fffffff in [mW] or [mA]
117 	 * 0xffffffff - Unknown rate
118 	 */
119 	uint32_t	bst_rate;
120 
121 	/*
122 	 * 0x00000000 - 0x7fffffff in [mWh] or [mAh]
123 	 * 0xffffffff - Unknown capacity
124 	 */
125 	uint32_t	bst_rem_cap;
126 
127 	/*
128 	 * 0x00000000 - 0x7fffffff in [mV]
129 	 * 0xffffffff - Unknown voltage
130 	 */
131 	uint32_t	bst_voltage;
132 } acpi_bst_t;
133 
134 /* Battery warnning levels in percentage */
135 typedef struct acpi_drv_warn {
136 	uint32_t	bw_enabled;	/* Enabled */
137 	uint32_t	bw_charge_warn;	/* charge warn threshold */
138 	uint32_t	bw_charge_low;	/* charge low threshold */
139 } acpi_drv_warn_t;
140 
141 #define	ACPI_DRV_NAME		"acpi_drv"
142 #define	ACPI_DRV_POWER_KSTAT_NAME	"power"
143 #define	ACPI_DRV_BTWARN_KSTAT_NAME	"battery warning"
144 #define	ACPI_DRV_BIF_KSTAT_NAME		"battery BIF"
145 #define	ACPI_DRV_BST_KSTAT_NAME		"battery BST"
146 
147 #define	AC			"AC"
148 #define	BATTERY			"battery"
149 #define	SYSTEM_POWER		"system power"
150 #define	SUPPORTED_BATTERY_COUNT	"supported_battery_count"
151 
152 #define	BW_ENABLED		"enabled"
153 #define	BW_POWEROFF_THRESHOLD	"warn capacity threshold"
154 #define	BW_SHUTDOWN_THRESHOLD	"low capacity threshold"
155 
156 #define	BIF_UNIT		"bif_unit"
157 #define	BIF_DESIGN_CAP		"bif_design_cap"
158 #define	BIF_LAST_CAP		"bif_last_cap"
159 #define	BIF_TECH		"bif_tech"
160 #define	BIF_VOLTAGE		"bif_voltage"
161 #define	BIF_WARN_CAP		"bif_warn_cap"
162 #define	BIF_LOW_CAP		"bif_low_cap"
163 #define	BIF_GRAN1_CAP		"bif_gran1_cap"
164 #define	BIF_GRAN2_CAP		"bif_gran2_cap"
165 #define	BIF_MODEL		"bif_model"
166 #define	BIF_SERIAL		"bif_serial"
167 #define	BIF_TYPE		"bif_type"
168 #define	BIF_OEM_INFO		"bif_oem_info"
169 
170 #define	BST_STATE		"bst_state"
171 #define	BST_RATE		"bst_rate"
172 #define	BST_REM_CAP		"bst_rem_cap"
173 #define	BST_VOLTAGE		"bst_voltage"
174 
175 #define	PSR_AC_PRESENT		"psr_ac_present"
176 
177 typedef struct acpi_drv_power_kstat_s {
178 	struct kstat_named	acpi_drv_power;
179 	struct kstat_named	acpi_drv_supported_battery_count;
180 } acpi_drv_power_kstat_t;
181 
182 typedef struct acpi_drv_warn_kstat_s {
183 	struct kstat_named	acpi_drv_bw_enabled;
184 	struct kstat_named	acpi_drv_bw_charge_warn;
185 	struct kstat_named	acpi_drv_bw_charge_low;
186 } acpi_drv_warn_kstat_t;
187 
188 /* BIF kstat */
189 typedef struct acpi_drv_bif_kstat_s {
190 	struct kstat_named	acpi_drv_bif_unit;
191 	struct kstat_named	acpi_drv_bif_design_cap;
192 	struct kstat_named	acpi_drv_bif_last_cap;
193 	struct kstat_named	acpi_drv_bif_tech;
194 	struct kstat_named	acpi_drv_bif_voltage;
195 	struct kstat_named	acpi_drv_bif_warn_cap;
196 	struct kstat_named	acpi_drv_bif_low_cap;
197 	struct kstat_named	acpi_drv_bif_gran1_cap;
198 	struct kstat_named	acpi_drv_bif_gran2_cap;
199 	struct kstat_named	acpi_drv_bif_model;
200 	struct kstat_named	acpi_drv_bif_serial;
201 	struct kstat_named	acpi_drv_bif_type;
202 	struct kstat_named	acpi_drv_bif_oem_info;
203 } acpi_drv_bif_kstat_t;
204 
205 /* BST kstat */
206 typedef struct acpi_drv_bst_kstat_s {
207 	struct kstat_named	acpi_drv_bst_state;
208 	struct kstat_named	acpi_drv_bst_rate;
209 	struct kstat_named	acpi_drv_bst_rem_cap;
210 	struct kstat_named	acpi_drv_bst_voltage;
211 } acpi_drv_bst_kstat_t;
212 
213 /* acpi device types */
214 enum acpi_drv_type {
215 	ACPI_DRV_TYPE_UNKNOWN,
216 	ACPI_DRV_TYPE_CBAT,
217 	ACPI_DRV_TYPE_AC,
218 	ACPI_DRV_TYPE_LID,
219 	ACPI_DRV_TYPE_DISPLAY,
220 	ACPI_DRV_TYPE_HOTKEY
221 };
222 
223 struct acpi_drv_output_info {
224 	uint32_t adr; /* unique ID for this output device */
225 	int nlev; /* number of brightness levels */
226 };
227 
228 struct acpi_drv_output_status {
229 	int state;
230 	int num_levels;
231 	int cur_level;
232 	int cur_level_index;
233 };
234 
235 #define	ACPI_DRV_OK			0
236 #define	ACPI_DRV_ERR			-1
237 
238 #ifdef _KERNEL
239 
240 #define	MINOR_SHIFT			8
241 #define	IDX_MASK			((1 << MINOR_SHIFT) - 1)
242 #define	MINOR_BATT(idx)			(ACPI_DRV_TYPE_CBAT << MINOR_SHIFT | \
243 					(idx))
244 #define	MINOR_AC(idx)			(ACPI_DRV_TYPE_AC << MINOR_SHIFT | \
245 					(idx))
246 #define	MINOR_LID(idx)			(ACPI_DRV_TYPE_LID << MINOR_SHIFT | \
247 					(idx))
248 #define	MINOR_HOTKEY(idx)		(ACPI_DRV_TYPE_HOTKEY << MINOR_SHIFT \
249 					| (idx))
250 #define	MINOR2IDX(minor)		((minor) & IDX_MASK)
251 #define	MINOR2TYPE(minor)		((minor) >> MINOR_SHIFT)
252 
253 #endif /* _KERNEL */
254 
255 #ifdef	__cplusplus
256 }
257 #endif
258 
259 #endif /* _ACPI_DRV_H */
260