diff options
Diffstat (limited to 'firmware/export/axp-pmu.h')
-rw-r--r-- | firmware/export/axp-pmu.h | 151 |
1 files changed, 151 insertions, 0 deletions
diff --git a/firmware/export/axp-pmu.h b/firmware/export/axp-pmu.h new file mode 100644 index 0000000000..457f746e8c --- /dev/null +++ b/firmware/export/axp-pmu.h | |||
@@ -0,0 +1,151 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2021 Aidan MacDonald | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #ifndef __AXP_PMU_H__ | ||
23 | #define __AXP_PMU_H__ | ||
24 | |||
25 | #include "config.h" | ||
26 | #include <stdbool.h> | ||
27 | #include <stdint.h> | ||
28 | |||
29 | /* ADC channels */ | ||
30 | #define ADC_ACIN_VOLTAGE 0 | ||
31 | #define ADC_ACIN_CURRENT 1 | ||
32 | #define ADC_VBUS_VOLTAGE 2 | ||
33 | #define ADC_VBUS_CURRENT 3 | ||
34 | #define ADC_INTERNAL_TEMP 4 | ||
35 | #define ADC_TS_INPUT 5 | ||
36 | #define ADC_BATTERY_VOLTAGE 6 | ||
37 | #define ADC_CHARGE_CURRENT 7 | ||
38 | #define ADC_DISCHARGE_CURRENT 8 | ||
39 | #define ADC_APS_VOLTAGE 9 | ||
40 | #define ADC_BATTERY_POWER 10 | ||
41 | #define NUM_ADC_CHANNELS 11 | ||
42 | |||
43 | /* ADC sampling rates */ | ||
44 | #define AXP_ADC_RATE_25HZ 0 | ||
45 | #define AXP_ADC_RATE_50HZ 1 | ||
46 | #define AXP_ADC_RATE_100HZ 2 | ||
47 | #define AXP_ADC_RATE_200HZ 3 | ||
48 | |||
49 | /* Return values of axp_battery_status() */ | ||
50 | #define AXP_BATT_DISCHARGING 0 | ||
51 | #define AXP_BATT_CHARGING 1 | ||
52 | #define AXP_BATT_FULL 2 | ||
53 | |||
54 | /* Bits returned by axp_input_status() */ | ||
55 | #define AXP_INPUT_AC (1 << 0) | ||
56 | #define AXP_INPUT_USB (1 << 1) | ||
57 | #define AXP_INPUT_BATTERY (1 << 2) | ||
58 | #define AXP_INPUT_EXTERNAL (AXP_INPUT_AC|AXP_INPUT_USB) | ||
59 | |||
60 | /* Power supplies known by this driver. Not every chip has all supplies! */ | ||
61 | #define AXP_SUPPLY_DCDC1 0 | ||
62 | #define AXP_SUPPLY_DCDC2 1 | ||
63 | #define AXP_SUPPLY_DCDC3 2 | ||
64 | #define AXP_SUPPLY_LDO1 3 | ||
65 | #define AXP_SUPPLY_LDO2 4 | ||
66 | #define AXP_SUPPLY_LDO3 5 | ||
67 | #define AXP_SUPPLY_LDO_IO0 6 | ||
68 | #define AXP_NUM_SUPPLIES 7 | ||
69 | |||
70 | /* Special values returned by axp_supply_get_voltage */ | ||
71 | #define AXP_SUPPLY_NOT_PRESENT INT_MIN | ||
72 | #define AXP_SUPPLY_DISABLED (-1) | ||
73 | |||
74 | /* Registers -- common to AXP173 and AXP192 (incomplete listing) */ | ||
75 | #define AXP_REG_POWERSTATUS 0x00 | ||
76 | #define AXP_REG_CHARGESTATUS 0x01 | ||
77 | #define AXP_REG_CHIP_ID 0x03 | ||
78 | #define AXP_REG_PWROUTPUTCTRL1 0x10 | ||
79 | #define AXP_REG_PWROUTPUTCTRL2 0x12 | ||
80 | #define AXP_REG_SHUTDOWNLEDCTRL 0x32 | ||
81 | #define AXP_REG_CHARGECONTROL1 0x33 | ||
82 | #define AXP_REG_DCDCWORKINGMODE 0x80 | ||
83 | #define AXP_REG_ADCENABLE1 0x82 | ||
84 | #define AXP_REG_ADCENABLE2 0x83 | ||
85 | #define AXP_REG_ADCSAMPLERATE 0x84 | ||
86 | #define AXP_REG_COULOMBCOUNTERBASE 0xb0 | ||
87 | #define AXP_REG_COULOMBCOUNTERCTRL 0xb8 | ||
88 | |||
89 | /* AXP192-only registers (incomplete listing) */ | ||
90 | #define AXP192_REG_GPIO0FUNCTION 0x90 | ||
91 | #define AXP192_REG_GPIO1FUNCTION 0x92 | ||
92 | #define AXP192_REG_GPIO2FUNCTION 0x93 | ||
93 | #define AXP192_REG_GPIOSTATE1 0x94 | ||
94 | |||
95 | /* Must be called from power_init() to initialize the driver state */ | ||
96 | extern void axp_init(void); | ||
97 | |||
98 | /* - axp_supply_set_voltage(): set a supply voltage to the given value | ||
99 | * in millivolts. Pass a voltage of AXP_SUPPLY_DISABLED to shut off | ||
100 | * the supply. Any invalid supply or voltage will make the call a no-op. | ||
101 | * | ||
102 | * - axp_supply_get_voltage() returns a supply voltage in millivolts. | ||
103 | * If the supply is powered off, returns AXP_SUPPLY_DISABLED. | ||
104 | * If the chip does not have the supply, returns AXP_SUPPLY_NOT_PRESENT. | ||
105 | */ | ||
106 | extern void axp_supply_set_voltage(int supply, int voltage); | ||
107 | extern int axp_supply_get_voltage(int supply); | ||
108 | |||
109 | /* Basic battery and power supply status */ | ||
110 | extern int axp_battery_status(void); | ||
111 | extern int axp_input_status(void); | ||
112 | |||
113 | /* ADC access -- ADCs which are not enabled will return INT_MIN if read. | ||
114 | * The output of axp_adc_read() is normalized to appropriate units: | ||
115 | * | ||
116 | * - for voltages, the scale is millivolts | ||
117 | * - for currents, the scale is milliamps | ||
118 | * - for temperatures, the scale is tenths of a degree Celsius | ||
119 | * - for power, the scale is microwatts | ||
120 | * | ||
121 | * See the comment in axp_adc_conv_raw() for raw value precision/scale. | ||
122 | */ | ||
123 | extern int axp_adc_read(int adc); | ||
124 | extern int axp_adc_read_raw(int adc); | ||
125 | extern int axp_adc_conv_raw(int adc, int value); | ||
126 | extern int axp_adc_get_enabled(void); | ||
127 | extern void axp_adc_set_enabled(int adc_bits); | ||
128 | extern int axp_adc_get_rate(void); | ||
129 | extern void axp_adc_set_rate(int rate); | ||
130 | |||
131 | /* - axp_cc_read() reads the coulomb counters | ||
132 | * - axp_cc_clear() resets both counters to zero | ||
133 | * - axp_cc_enable() will stop/start the counters running | ||
134 | * - axp_cc_is_enabled() returns true if the counters are running | ||
135 | */ | ||
136 | extern void axp_cc_read(uint32_t* charge, uint32_t* discharge); | ||
137 | extern void axp_cc_clear(void); | ||
138 | extern void axp_cc_enable(bool en); | ||
139 | extern bool axp_cc_is_enabled(void); | ||
140 | |||
141 | /* Set/get maximum charging current in milliamps */ | ||
142 | extern void axp_set_charge_current(int maxcurrent); | ||
143 | extern int axp_get_charge_current(void); | ||
144 | |||
145 | /* Set the shutdown bit */ | ||
146 | extern void axp_power_off(void); | ||
147 | |||
148 | /* Debug menu */ | ||
149 | extern bool axp_debug_menu(void); | ||
150 | |||
151 | #endif /* __AXP_PMU_H__ */ | ||