1 /* $OpenBSD: acpidev.h,v 1.33 2012/07/13 10:37:40 pirofti Exp $ */ 2 /* 3 * Copyright (c) 2005 Marco Peereboom <marco@openbsd.org> 4 * Copyright (c) 2005 Thorsten Lockert <tholo@sigmasoft.com> 5 * 6 * Permission to use, copy, modify, and distribute this software for any 7 * purpose with or without fee is hereby granted, provided that the above 8 * copyright notice and this permission notice appear in all copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 11 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 12 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 13 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 14 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 15 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 16 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 17 */ 18 19 #ifndef __DEV_ACPI_ACPIDEV_H__ 20 #define __DEV_ACPI_ACPIDEV_H__ 21 22 #include <sys/sensors.h> 23 #include <sys/rwlock.h> 24 #include <dev/acpi/acpireg.h> 25 26 #define DEVNAME(s) ((s)->sc_dev.dv_xname) 27 28 #define ACPIDEV_NOPOLL 0 29 #define ACPIDEV_POLL 1 30 31 /* 32 * _BIF (Battery InFormation) 33 * Arguments: none 34 * Results : package _BIF (Battery InFormation) 35 * Package { 36 * // ASCIIZ is ASCII character string terminated with a 0x00. 37 * Power Unit //DWORD 38 * Design Capacity //DWORD 39 * Last Full Charge Capacity //DWORD 40 * Battery Technology //DWORD 41 * Design Voltage //DWORD 42 * Design Capacity of Warning //DWORD 43 * Design Capacity of Low //DWORD 44 * Battery Capacity Granularity 1 //DWORD 45 * Battery Capacity Granularity 2 //DWORD 46 * Model Number //ASCIIZ 47 * Serial Number //ASCIIZ 48 * Battery Type //ASCIIZ 49 * OEM Information //ASCIIZ 50 * } 51 */ 52 struct acpibat_bif { 53 u_int32_t bif_power_unit; 54 #define BIF_POWER_MW 0x00 55 #define BIF_POWER_MA 0x01 56 u_int32_t bif_capacity; 57 #define BIF_UNKNOWN 0xffffffff 58 u_int32_t bif_last_capacity; 59 u_int32_t bif_technology; 60 #define BIF_TECH_PRIMARY 0x00 61 #define BIF_TECH_SECONDARY 0x01 62 u_int32_t bif_voltage; 63 u_int32_t bif_warning; 64 u_int32_t bif_low; 65 u_int32_t bif_cap_granu1; 66 u_int32_t bif_cap_granu2; 67 char bif_model[20]; 68 char bif_serial[20]; 69 char bif_type[20]; 70 char bif_oem[20]; 71 }; 72 73 /* 74 * _OSC Definition for Control Method Battery 75 * Arguments: none 76 * Results : DWORD flags 77 */ 78 #define CMB_OSC_UUID "f18fc78b-0f15-4978-b793-53f833a1d35b" 79 #define CMB_OSC_GRANULARITY 0x01 80 #define CMB_OSC_WAKE_ON_LOW 0x02 81 82 /* 83 * _BST (Battery STatus) 84 * Arguments: none 85 * Results : package _BST (Battery STatus) 86 * Package { 87 * Battery State //DWORD 88 * Battery Present Rate //DWORD 89 * Battery Remaining Capacity //DWORD 90 * Battery Present Voltage //DWORD 91 * } 92 * 93 * Per the spec section 10.2.2.3 94 * Remaining Battery Percentage[%] = (Battery Remaining Capacity [=0 ~ 100] / 95 * Last Full Charged Capacity[=100]) * 100 96 * 97 * Remaining Battery Life [h] = Battery Remaining Capacity [mAh/mWh] / 98 * Battery Present Rate [=0xFFFFFFFF] = unknown 99 */ 100 struct acpibat_bst { 101 u_int32_t bst_state; 102 #define BST_DISCHARGE 0x01 103 #define BST_CHARGE 0x02 104 #define BST_CRITICAL 0x04 105 u_int32_t bst_rate; 106 #define BST_UNKNOWN 0xffffffff 107 u_int32_t bst_capacity; 108 u_int32_t bst_voltage; 109 }; 110 111 /* 112 * _BTP (Battery Trip Point) 113 * Arguments: DWORD level 114 * Results : none 115 */ 116 #define BTP_CLEAR_TRIP_POINT 0x00 117 118 /* 119 * _BTM (Battery TiMe) 120 * Arguments: DWORD rate of discharge 121 * Results : DWORD time in seconds or error/unknown 122 */ 123 #define BTM_CURRENT_RATE 0x00 124 125 #define BTM_RATE_TOO_LARGE 0x00 126 #define BTM_CRITICAL 0x00 127 #define BTM_UNKNOWN 0xffffffff 128 129 /* 130 * _BMD (Battery Maintenance Data) 131 * Arguments: none 132 * Results : package _BMD (Battery Maintenance Data) 133 * Package { 134 * Status Flags //DWORD 135 * Capability Flags //DWORD 136 * Recalibrate Count //DWORD 137 * Quick Recalibrate Time //DWORD 138 * Slow Recalibrate Time //DWORD 139 * } 140 */ 141 struct acpibat_bmd { 142 u_int32_t bmd_status; 143 #define BMD_AML_CALIBRATE_CYCLE 0x01 144 #define BMD_CHARGING_DISABLED 0x02 145 #define BMD_DISCHARGE_WHILE_AC 0x04 146 #define BMD_RECALIBRATE_BAT 0x08 147 #define BMD_GOTO_STANDBY_SPEED 0x10 148 u_int32_t bmd_capability; 149 #define BMD_CB_AML_CALIBRATION 0x01 150 #define BMD_CB_DISABLE_CHARGER 0x02 151 #define BMD_CB_DISCH_WHILE_AC 0x04 152 #define BMD_CB_AFFECT_ALL_BATT 0x08 153 #define BMD_CB_FULL_CHRG_FIRST 0x10 154 u_int32_t bmd_recalibrate_count; 155 #define BMD_ONLY_CALIB_IF_ST3 0x00 /* only recal when status bit 3 set */ 156 u_int32_t bmd_quick_recalibrate_time; 157 #define BMD_UNKNOWN 0xffffffff 158 u_int32_t bmd_slow_recalibrate_time; 159 }; 160 161 /* 162 * _BMC (Battery Maintenance Control) 163 * Arguments: DWORD flags 164 * Results : none 165 */ 166 #define BMC_AML_CALIBRATE 0x01 167 #define BMC_DISABLE_CHARGING 0x02 168 #define BMC_ALLOW_AC_DISCHARGE 0x04 169 170 /* AC device */ 171 /* 172 * _PSR (Power Source) 173 * Arguments: none 174 * Results : DWORD status 175 */ 176 #define PSR_OFFLINE 0x00 177 #define PSR_ONLINE 0x01 178 179 /* 180 * _PCL (Power Consumer List) 181 * Arguments: none 182 * Results : LIST of Power Class pointers 183 */ 184 185 /* hpet device */ 186 #define HPET_REG_SIZE 1024 187 188 #define HPET_CAPABILITIES 0x000 189 #define HPET_CONFIGURATION 0x010 190 #define HPET_INTERRUPT_STATUS 0x020 191 #define HPET_MAIN_COUNTER 0x0F0 192 #define HPET_TIMER0_CONFIG 0x100 193 #define HPET_TIMER0_COMPARE 0x108 194 #define HPET_TIMER0_INTERRUPT 0x110 195 #define HPET_TIMER1_CONFIG 0x200 196 #define HPET_TIMER1_COMPARE 0x208 197 #define HPET_TIMER1_INTERRUPT 0x310 198 #define HPET_TIMER2_CONFIG 0x400 199 #define HPET_TIMER2_COMPARE 0x408 200 #define HPET_TIMER2_INTERRUPT 0x510 201 202 #define STA_PRESENT (1L << 0) 203 #define STA_ENABLED (1L << 1) 204 #define STA_SHOW_UI (1L << 2) 205 #define STA_DEV_OK (1L << 3) 206 #define STA_BATTERY (1L << 4) 207 208 /* 209 * _PSS (Performance Supported States) 210 * Arguments: none 211 * Results : package _PSS (Performance Supported States) 212 * Package { 213 * CoreFreq //DWORD 214 * Power //DWORD 215 * TransitionLatency //DWORD 216 * BusMasterLatency //DWORD 217 * Control //DWORD 218 * Status //DWORD 219 * } 220 */ 221 struct acpicpu_pss { 222 u_int32_t pss_core_freq; 223 u_int32_t pss_power; 224 u_int32_t pss_trans_latency; 225 u_int32_t pss_bus_latency; 226 u_int32_t pss_ctrl; 227 u_int32_t pss_status; 228 }; 229 230 int acpicpu_fetch_pss(struct acpicpu_pss **); 231 void acpicpu_set_notify(void (*)(struct acpicpu_pss *, int)); 232 /* 233 * XXX this is returned in a buffer and is not a "natural" type. 234 * 235 * GRD (Generic Register Descriptor ) 236 * 237 */ 238 struct acpi_grd { 239 u_int8_t grd_descriptor; 240 u_int16_t grd_length; 241 struct acpi_gas grd_gas; 242 } __packed; 243 244 /* 245 * _PCT (Performance Control ) 246 * Arguments: none 247 * Results : package _PCT (Performance Control) 248 * Package { 249 * Perf_Ctrl_register //Register 250 * Perf_Status_register //Register 251 * } 252 */ 253 struct acpicpu_pct { 254 struct acpi_grd pct_ctrl; 255 struct acpi_grd pct_status; 256 }; 257 258 /* softc for fake apm devices */ 259 struct acpiac_softc { 260 struct device sc_dev; 261 262 struct acpi_softc *sc_acpi; 263 struct aml_node *sc_devnode; 264 265 int sc_ac_stat; 266 267 struct ksensor sc_sens[1]; 268 struct ksensordev sc_sensdev; 269 }; 270 271 struct acpibat_softc { 272 struct device sc_dev; 273 274 struct acpi_softc *sc_acpi; 275 struct aml_node *sc_devnode; 276 277 struct acpibat_bif sc_bif; 278 struct acpibat_bst sc_bst; 279 volatile int sc_bat_present; 280 281 struct ksensor sc_sens[8]; 282 struct ksensordev sc_sensdev; 283 }; 284 285 TAILQ_HEAD(aml_nodelisth, aml_nodelist); 286 287 struct acpidock_softc { 288 struct device sc_dev; 289 290 struct acpi_softc *sc_acpi; 291 struct aml_node *sc_devnode; 292 293 struct aml_nodelisth sc_deps_h; 294 struct aml_nodelist *sc_deps; 295 296 struct ksensor sc_sens; 297 struct ksensordev sc_sensdev; 298 299 int sc_docked; 300 int sc_sta; 301 302 #define ACPIDOCK_STATUS_UNKNOWN -1 303 #define ACPIDOCK_STATUS_UNDOCKED 0 304 #define ACPIDOCK_STATUS_DOCKED 1 305 }; 306 307 #define ACPIDOCK_EVENT_INSERT 0 308 #define ACPIDOCK_EVENT_DEVCHECK 1 309 #define ACPIDOCK_EVENT_EJECT 3 310 311 #define ACPIEC_MAX_EVENTS 256 312 313 struct acpiec_event { 314 struct aml_node *event; 315 }; 316 317 struct acpiec_softc { 318 struct device sc_dev; 319 320 int sc_ecbusy; 321 322 /* command/status register */ 323 bus_space_tag_t sc_cmd_bt; 324 bus_space_handle_t sc_cmd_bh; 325 326 /* data register */ 327 bus_space_tag_t sc_data_bt; 328 bus_space_handle_t sc_data_bh; 329 330 struct acpi_softc *sc_acpi; 331 struct aml_node *sc_devnode; 332 u_int32_t sc_gpe; 333 struct acpiec_event sc_events[ACPIEC_MAX_EVENTS]; 334 int sc_gotsci; 335 int sc_glk; 336 }; 337 338 void acpibtn_disable_psw(void); 339 void acpibtn_enable_psw(void); 340 #endif /* __DEV_ACPI_ACPIDEV_H__ */ 341