xref: /freebsd/sys/dev/acpica/acpiio.h (revision 95ee2897e98f5d444f26ed2334cc7c439f9c16c6)
115e32d5dSMike Smith /*-
2f09e4e87STakanori Watanabe  * Copyright (c) 1999 Takanori Watanabe <takawata@jp.freebsd.org>
315e32d5dSMike Smith  * Copyright (c) 1999 Mitsuru IWASAKI <iwasaki@FreeBSD.org>
415e32d5dSMike Smith  * All rights reserved.
515e32d5dSMike Smith  *
615e32d5dSMike Smith  * Redistribution and use in source and binary forms, with or without
715e32d5dSMike Smith  * modification, are permitted provided that the following conditions
815e32d5dSMike Smith  * are met:
915e32d5dSMike Smith  * 1. Redistributions of source code must retain the above copyright
1015e32d5dSMike Smith  *    notice, this list of conditions and the following disclaimer.
1115e32d5dSMike Smith  * 2. Redistributions in binary form must reproduce the above copyright
1215e32d5dSMike Smith  *    notice, this list of conditions and the following disclaimer in the
1315e32d5dSMike Smith  *    documentation and/or other materials provided with the distribution.
1415e32d5dSMike Smith  *
1515e32d5dSMike Smith  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
1615e32d5dSMike Smith  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
1715e32d5dSMike Smith  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
1815e32d5dSMike Smith  * ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
1915e32d5dSMike Smith  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2015e32d5dSMike Smith  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2115e32d5dSMike Smith  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2215e32d5dSMike Smith  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2315e32d5dSMike Smith  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2415e32d5dSMike Smith  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
2515e32d5dSMike Smith  * SUCH DAMAGE.
2615e32d5dSMike Smith  */
2715e32d5dSMike Smith 
28a885159fSNate Lawson #ifndef _ACPIIO_H_
29a885159fSNate Lawson #define _ACPIIO_H_
30a885159fSNate Lawson 
310ae55423SMike Smith /*
320ae55423SMike Smith  * Core ACPI subsystem ioctls
330ae55423SMike Smith  */
3400a30448SNate Lawson #define ACPIIO_SETSLPSTATE	_IOW('P', 3, int) /* DEPRECATED */
3500a30448SNate Lawson 
3600a30448SNate Lawson /* Request S1-5 sleep state. User is notified and then sleep proceeds. */
3700a30448SNate Lawson #define ACPIIO_REQSLPSTATE	_IOW('P', 4, int)
3800a30448SNate Lawson 
3900a30448SNate Lawson /* Allow suspend to continue (0) or abort it (errno). */
4000a30448SNate Lawson #define ACPIIO_ACKSLPSTATE	_IOW('P', 5, int)
4115e32d5dSMike Smith 
424eb77744SMitsuru IWASAKI struct acpi_battinfo {
434eb77744SMitsuru IWASAKI     int	 cap;				/* percent */
448f764959SNate Lawson     int	 min;				/* remaining time (in minutes) */
454eb77744SMitsuru IWASAKI     int	 state;				/* battery state */
4676f6fe4fSNate Lawson     int	 rate;				/* emptying rate */
474eb77744SMitsuru IWASAKI };
484eb77744SMitsuru IWASAKI 
49*294de6bbSHiroki Sato /*
50*294de6bbSHiroki Sato  * Battery Information object.  Note that this object is deprecated in
51*294de6bbSHiroki Sato  * ACPI 4.0
52*294de6bbSHiroki Sato  */
53d8c616aeSTakanori Watanabe #define ACPI_CMBAT_MAXSTRLEN 32
54d8c616aeSTakanori Watanabe struct acpi_bif {
55*294de6bbSHiroki Sato     uint32_t units;			/* Power Unit (mW or mA). */
569aa72f74SNate Lawson #define ACPI_BIF_UNITS_MW	0	/* Capacity in mWh, rate in mW. */
579aa72f74SNate Lawson #define ACPI_BIF_UNITS_MA	1	/* Capacity in mAh, rate in mA. */
5876f6fe4fSNate Lawson     uint32_t dcap;			/* Design Capacity */
5976f6fe4fSNate Lawson     uint32_t lfcap;			/* Last Full capacity */
6076f6fe4fSNate Lawson     uint32_t btech;			/* Battery Technology */
6176f6fe4fSNate Lawson     uint32_t dvol;			/* Design voltage (mV) */
6276f6fe4fSNate Lawson     uint32_t wcap;			/* WARN capacity */
6376f6fe4fSNate Lawson     uint32_t lcap;			/* Low capacity */
6476f6fe4fSNate Lawson     uint32_t gra1;			/* Granularity 1 (Warn to Low) */
6576f6fe4fSNate Lawson     uint32_t gra2;			/* Granularity 2 (Full to Warn) */
66d8c616aeSTakanori Watanabe     char model[ACPI_CMBAT_MAXSTRLEN];	/* model identifier */
67d8c616aeSTakanori Watanabe     char serial[ACPI_CMBAT_MAXSTRLEN];	/* Serial number */
68d8c616aeSTakanori Watanabe     char type[ACPI_CMBAT_MAXSTRLEN];	/* Type */
69453130d9SPedro F. Giffuni     char oeminfo[ACPI_CMBAT_MAXSTRLEN];	/* OEM information */
70d8c616aeSTakanori Watanabe };
71d8c616aeSTakanori Watanabe 
72*294de6bbSHiroki Sato /*
73*294de6bbSHiroki Sato  * Members in acpi_bix are reordered so that the first part is compatible
74*294de6bbSHiroki Sato  * with acpi_bif.
75*294de6bbSHiroki Sato  */
76*294de6bbSHiroki Sato struct acpi_bix {
77*294de6bbSHiroki Sato /* _BIF-compatible */
78*294de6bbSHiroki Sato     uint32_t units;			/* Power Unit (mW or mA). */
79*294de6bbSHiroki Sato #define ACPI_BIX_UNITS_MW	0	/* Capacity in mWh, rate in mW. */
80*294de6bbSHiroki Sato #define ACPI_BIX_UNITS_MA	1	/* Capacity in mAh, rate in mA. */
81*294de6bbSHiroki Sato     uint32_t dcap;			/* Design Capacity */
82*294de6bbSHiroki Sato     uint32_t lfcap;			/* Last Full capacity */
83*294de6bbSHiroki Sato     uint32_t btech;			/* Battery Technology */
84*294de6bbSHiroki Sato     uint32_t dvol;			/* Design voltage (mV) */
85*294de6bbSHiroki Sato     uint32_t wcap;			/* WARN capacity */
86*294de6bbSHiroki Sato     uint32_t lcap;			/* Low capacity */
87*294de6bbSHiroki Sato     uint32_t gra1;			/* Granularity 1 (Warn to Low) */
88*294de6bbSHiroki Sato     uint32_t gra2;			/* Granularity 2 (Full to Warn) */
89*294de6bbSHiroki Sato     char model[ACPI_CMBAT_MAXSTRLEN];	/* model identifier */
90*294de6bbSHiroki Sato     char serial[ACPI_CMBAT_MAXSTRLEN];	/* Serial number */
91*294de6bbSHiroki Sato     char type[ACPI_CMBAT_MAXSTRLEN];	/* Type */
92*294de6bbSHiroki Sato     char oeminfo[ACPI_CMBAT_MAXSTRLEN];	/* OEM information */
93*294de6bbSHiroki Sato     /* ACPI 4.0 or later */
94*294de6bbSHiroki Sato     uint16_t rev;			/* Revision */
95*294de6bbSHiroki Sato #define	ACPI_BIX_REV_0		0	/* ACPI 4.0 _BIX */
96*294de6bbSHiroki Sato #define	ACPI_BIX_REV_1		1	/* ACPI 6.0 _BIX */
97*294de6bbSHiroki Sato #define	ACPI_BIX_REV_BIF	0xffff	/* _BIF */
98*294de6bbSHiroki Sato #define	ACPI_BIX_REV_MIN_CHECK(x, min)	\
99*294de6bbSHiroki Sato 	(((min) == ACPI_BIX_REV_BIF) ? ((x) == ACPI_BIX_REV_BIF) : \
100*294de6bbSHiroki Sato 	    (((x) == ACPI_BIX_REV_BIF) ? 0 : ((x) >= (min))))
101*294de6bbSHiroki Sato     uint32_t cycles;			/* Cycle Count */
102*294de6bbSHiroki Sato     uint32_t accuracy;			/* Measurement Accuracy */
103*294de6bbSHiroki Sato     uint32_t stmax;			/* Max Sampling Time */
104*294de6bbSHiroki Sato     uint32_t stmin;			/* Min Sampling Time */
105*294de6bbSHiroki Sato     uint32_t aimax;			/* Max Average Interval */
106*294de6bbSHiroki Sato     uint32_t aimin;			/* Min Average Interval */
107*294de6bbSHiroki Sato     /* ACPI 6.0 or later */
108*294de6bbSHiroki Sato     uint32_t scap;			/* Battery Swapping Capability */
109*294de6bbSHiroki Sato #define	ACPI_BIX_SCAP_NO	0x00000000
110*294de6bbSHiroki Sato #define	ACPI_BIX_SCAP_COLD	0x00000001
111*294de6bbSHiroki Sato #define	ACPI_BIX_SCAP_HOT	0x00000010
112*294de6bbSHiroki Sato     uint8_t bix_reserved[58];		/* padding */
113*294de6bbSHiroki Sato };
114*294de6bbSHiroki Sato 
115*294de6bbSHiroki Sato #if 0
116*294de6bbSHiroki Sato /* acpi_bix in the original order just for reference */
117*294de6bbSHiroki Sato struct acpi_bix {
118*294de6bbSHiroki Sato     uint16_t rev;			/* Revision */
119*294de6bbSHiroki Sato     uint32_t units;			/* Power Unit (mW or mA). */
120*294de6bbSHiroki Sato     uint32_t dcap;			/* Design Capacity */
121*294de6bbSHiroki Sato     uint32_t lfcap;			/* Last Full capacity */
122*294de6bbSHiroki Sato     uint32_t btech;			/* Battery Technology */
123*294de6bbSHiroki Sato     uint32_t dvol;			/* Design voltage (mV) */
124*294de6bbSHiroki Sato     uint32_t wcap;			/* Design Capacity of Warning */
125*294de6bbSHiroki Sato     uint32_t lcap;			/* Design Capacity of Low */
126*294de6bbSHiroki Sato     uint32_t cycles;			/* Cycle Count */
127*294de6bbSHiroki Sato     uint32_t accuracy;			/* Measurement Accuracy */
128*294de6bbSHiroki Sato     uint32_t stmax;			/* Max Sampling Time */
129*294de6bbSHiroki Sato     uint32_t stmin;			/* Min Sampling Time */
130*294de6bbSHiroki Sato     uint32_t aimax;			/* Max Average Interval */
131*294de6bbSHiroki Sato     uint32_t aimin;			/* Min Average Interval */
132*294de6bbSHiroki Sato     uint32_t gra1;			/* Granularity 1 (Warn to Low) */
133*294de6bbSHiroki Sato     uint32_t gra2;			/* Granularity 2 (Full to Warn) */
134*294de6bbSHiroki Sato     char model[ACPI_CMBAT_MAXSTRLEN];	/* model identifier */
135*294de6bbSHiroki Sato     char serial[ACPI_CMBAT_MAXSTRLEN];	/* Serial number */
136*294de6bbSHiroki Sato     char type[ACPI_CMBAT_MAXSTRLEN];	/* Type */
137*294de6bbSHiroki Sato     char oeminfo[ACPI_CMBAT_MAXSTRLEN];	/* OEM information */
138*294de6bbSHiroki Sato     uint32_t scap;			/* Battery Swapping Capability */
139*294de6bbSHiroki Sato };
140*294de6bbSHiroki Sato #endif
141*294de6bbSHiroki Sato 
142d8c616aeSTakanori Watanabe struct acpi_bst {
14376f6fe4fSNate Lawson     uint32_t state;			/* Battery State */
14476f6fe4fSNate Lawson     uint32_t rate;			/* Present Rate */
14576f6fe4fSNate Lawson     uint32_t cap;			/* Remaining Capacity */
14676f6fe4fSNate Lawson     uint32_t volt;			/* Present Voltage */
147d8c616aeSTakanori Watanabe };
148d8c616aeSTakanori Watanabe 
149766d7e65SAndriy Gapon /*
150766d7e65SAndriy Gapon  * Note that the following definitions represent status bits for internal
151766d7e65SAndriy Gapon  * driver state.  The first three of them (charging, discharging and critical)
152766d7e65SAndriy Gapon  * conveninetly conform to ACPI specification of status returned by _BST
153766d7e65SAndriy Gapon  * method.  Other definitions (not present, etc) are synthetic.
154766d7e65SAndriy Gapon  * Also note that according to the specification the charging and discharging
155766d7e65SAndriy Gapon  * status bits must not be set at the same time.
156766d7e65SAndriy Gapon  */
1574eb77744SMitsuru IWASAKI #define ACPI_BATT_STAT_DISCHARG		0x0001
1584eb77744SMitsuru IWASAKI #define ACPI_BATT_STAT_CHARGING		0x0002
1594eb77744SMitsuru IWASAKI #define ACPI_BATT_STAT_CRITICAL		0x0004
160766d7e65SAndriy Gapon #define ACPI_BATT_STAT_INVALID					\
161766d7e65SAndriy Gapon     (ACPI_BATT_STAT_DISCHARG | ACPI_BATT_STAT_CHARGING)
162766d7e65SAndriy Gapon #define ACPI_BATT_STAT_BST_MASK					\
163766d7e65SAndriy Gapon     (ACPI_BATT_STAT_INVALID | ACPI_BATT_STAT_CRITICAL)
164766d7e65SAndriy Gapon #define ACPI_BATT_STAT_NOT_PRESENT	ACPI_BATT_STAT_BST_MASK
1654eb77744SMitsuru IWASAKI 
166*294de6bbSHiroki Sato /* For backward compatibility */
167*294de6bbSHiroki Sato union acpi_battery_ioctl_arg_v1 {
16876f6fe4fSNate Lawson     int			 unit;	/* Device unit or ACPI_BATTERY_ALL_UNITS. */
1694eb77744SMitsuru IWASAKI 
1704eb77744SMitsuru IWASAKI     struct acpi_battinfo battinfo;
1714eb77744SMitsuru IWASAKI 
1728f764959SNate Lawson     struct acpi_bif	 bif;
1738f764959SNate Lawson     struct acpi_bst	 bst;
174917d44c8SMitsuru IWASAKI };
175*294de6bbSHiroki Sato union acpi_battery_ioctl_arg {
176*294de6bbSHiroki Sato     int			 unit;	/* Device unit or ACPI_BATTERY_ALL_UNITS. */
177*294de6bbSHiroki Sato 
178*294de6bbSHiroki Sato     struct acpi_battinfo battinfo;
179*294de6bbSHiroki Sato 
180*294de6bbSHiroki Sato     struct acpi_bix	 bix;
181*294de6bbSHiroki Sato     struct acpi_bif	 bif;
182*294de6bbSHiroki Sato     struct acpi_bst	 bst;
183*294de6bbSHiroki Sato };
184917d44c8SMitsuru IWASAKI 
18576f6fe4fSNate Lawson #define ACPI_BATTERY_ALL_UNITS 	(-1)
186*294de6bbSHiroki Sato #define ACPI_BATT_UNKNOWN 	0xffffffff /* _BST or _BI[FX] value unknown. */
18776f6fe4fSNate Lawson 
1888f764959SNate Lawson /* Common battery ioctls */
1894eb77744SMitsuru IWASAKI #define ACPIIO_BATT_GET_UNITS	  _IOR('B', 0x01, int)
1904eb77744SMitsuru IWASAKI #define ACPIIO_BATT_GET_BATTINFO _IOWR('B', 0x03, union acpi_battery_ioctl_arg)
191*294de6bbSHiroki Sato #define ACPIIO_BATT_GET_BATTINFO_V1 _IOWR('B', 0x03, union acpi_battery_ioctl_arg_v1)
192*294de6bbSHiroki Sato #define ACPIIO_BATT_GET_BIF	 _IOWR('B', 0x10, union acpi_battery_ioctl_arg_v1)
193*294de6bbSHiroki Sato #define ACPIIO_BATT_GET_BIX	 _IOWR('B', 0x10, union acpi_battery_ioctl_arg)
1948f764959SNate Lawson #define ACPIIO_BATT_GET_BST	 _IOWR('B', 0x11, union acpi_battery_ioctl_arg)
195*294de6bbSHiroki Sato #define ACPIIO_BATT_GET_BST_V1	 _IOWR('B', 0x11, union acpi_battery_ioctl_arg_v1)
1964eb77744SMitsuru IWASAKI 
1978f764959SNate Lawson /* Control Method battery ioctls (deprecated) */
1988f764959SNate Lawson #define ACPIIO_CMBAT_GET_BIF	 ACPIIO_BATT_GET_BIF
1998f764959SNate Lawson #define ACPIIO_CMBAT_GET_BST	 ACPIIO_BATT_GET_BST
200917d44c8SMitsuru IWASAKI 
201a885159fSNate Lawson /* Get AC adapter status. */
202917d44c8SMitsuru IWASAKI #define ACPIIO_ACAD_GET_STATUS	  _IOR('A', 1, int)
203917d44c8SMitsuru IWASAKI 
2040ae55423SMike Smith #ifdef _KERNEL
205be2b1797SNate Lawson typedef int	(*acpi_ioctl_fn)(u_long cmd, caddr_t addr, void *arg);
206be2b1797SNate Lawson extern int	acpi_register_ioctl(u_long cmd, acpi_ioctl_fn fn, void *arg);
207be2b1797SNate Lawson extern void	acpi_deregister_ioctl(u_long cmd, acpi_ioctl_fn fn);
2080ae55423SMike Smith #endif
209a885159fSNate Lawson 
210a885159fSNate Lawson #endif /* !_ACPIIO_H_ */
211