1 // Copyright 2016 The Fuchsia Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef ZIRCON_SYSTEM_DEV_BUS_ACPI_INCLUDE_POWER_H_
6 #define ZIRCON_SYSTEM_DEV_BUS_ACPI_INCLUDE_POWER_H_
7 
8 #include <zircon/types.h>
9 
10 typedef struct {
11     uint32_t type;
12 #define POWER_TYPE_AC 0
13 #define POWER_TYPE_BATTERY 1
14 
15     uint32_t state;
16     // state is a bitmask
17 #define POWER_STATE_ONLINE (1 << 0)
18     // online means the power source is online for POWER_TYPE_AC and the battery
19     // is present for POWER_TYPE_BATTERY
20 
21     // below 3 states are only valid for POWER_TYPE_BATTERY
22     // a battery may be discharging, charging, or neither discharging nor charging.
23     // it is illegal for both POWER_STATE_DISCHARGING and POWER_STATE_CHARGING
24     // to be set. POWER_STATE_CRITICAL is set when the battery reaches an
25     // OEM-defined critical level and the system should perform a shutdown.
26 #define POWER_STATE_DISCHARGING (1 << 1)
27 #define POWER_STATE_CHARGING (1 << 2)
28 #define POWER_STATE_CRITICAL (1 << 3)
29 } power_info_t;
30 
31 // The remaining battery percentage is calculated using the following formula:
32 // remaining battery percentage [%] = remaining_capacity / last_full_capacity * 100
33 //
34 // The remaining battery life is calculated using the following formula:
35 // remaining_battery_life [h] = remaining_capacity / present_rate
36 
37 typedef struct {
38     uint32_t unit;
39     // capacity unit. all voltage fields are in millivolts
40 #define BATTERY_UNIT_MW 0
41 #define BATTERY_UNIT_MA 1
42 
43     uint32_t design_capacity;
44     // nominal capacity of a new battery
45     uint32_t last_full_capacity;
46     // predicted battery capacity when fully charged
47     uint32_t design_voltage;
48     // nominal voltage of a new battery
49     uint32_t capacity_warning;
50     // capacity when the device will generate a warning notification
51     uint32_t capacity_low;
52     // capacity when the device will generate a low battery notification
53     uint32_t capacity_granularity_low_warning;
54     // the smallest increment the battery is capable of measuring between the
55     // low and warning capacities
56     uint32_t capacity_granularity_warning_full;
57     // the smallest increment the battery is capable of measuring between the low
58     // and warning capacities
59 
60     // below fields are in units specified in battery_info_t
61     int32_t present_rate;
62     // charging/discharging rate in the capacity unit. positive is charging,
63     // negative is discharging
64     uint32_t remaining_capacity;
65     uint32_t present_voltage;
66 } battery_info_t;
67 
68 void poweroff(void);
69 void reboot(void);
70 zx_status_t suspend_to_ram(void);
71 
72 #endif  // ZIRCON_SYSTEM_DEV_BUS_ACPI_INCLUDE_POWER_H_
73