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