diff options
Diffstat (limited to 'firmware/export')
-rw-r--r-- | firmware/export/axp-pmu.h | 151 | ||||
-rw-r--r-- | firmware/export/axp192-defs.h | 308 | ||||
-rw-r--r-- | firmware/export/axp192.h | 131 |
3 files changed, 439 insertions, 151 deletions
diff --git a/firmware/export/axp-pmu.h b/firmware/export/axp-pmu.h deleted file mode 100644 index 457f746e8c..0000000000 --- a/firmware/export/axp-pmu.h +++ /dev/null | |||
@@ -1,151 +0,0 @@ | |||
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__ */ | ||
diff --git a/firmware/export/axp192-defs.h b/firmware/export/axp192-defs.h new file mode 100644 index 0000000000..13b465351b --- /dev/null +++ b/firmware/export/axp192-defs.h | |||
@@ -0,0 +1,308 @@ | |||
1 | /* Internal header for axp192 driver - not for general inclusion */ | ||
2 | |||
3 | #ifndef DEFREG | ||
4 | # define DEFREG(...) | ||
5 | #endif | ||
6 | #ifndef DEFFLD | ||
7 | # define DEFFLD(...) | ||
8 | #endif | ||
9 | |||
10 | #define DEFBIT(regname, fldname, bitpos, ...) \ | ||
11 | DEFFLD(regname, fldname, bitpos, bitpos, __VA_ARGS__) | ||
12 | |||
13 | DEFREG(PWRSTS, 0x00) | ||
14 | DEFREG(CHGSTS, 0x01) | ||
15 | DEFREG(CHIPID, 0x03) | ||
16 | DEFREG(VBUSSTS, 0x04) | ||
17 | DEFREG(DATA0, 0x06) | ||
18 | DEFREG(DATA1, 0x07) | ||
19 | DEFREG(DATA2, 0x08) | ||
20 | DEFREG(DATA3, 0x09) | ||
21 | DEFREG(DATA4, 0x0a) | ||
22 | DEFREG(DATA5, 0x0b) | ||
23 | DEFREG(PWRCTL1, 0x10) | ||
24 | DEFREG(PWRCTL2, 0x12) | ||
25 | DEFREG(DCDC2VOLT, 0x23) | ||
26 | DEFREG(DCDC2RAMP, 0x25) | ||
27 | DEFREG(DCDC1VOLT, 0x26) | ||
28 | DEFREG(DCDC3VOLT, 0x27) | ||
29 | DEFREG(LDO2LDO3VOLT, 0x28) | ||
30 | DEFREG(VBUSIPSOUT, 0x30) | ||
31 | DEFREG(VOFF, 0x31) | ||
32 | DEFREG(PWROFF, 0x32) | ||
33 | DEFREG(CHGCTL1, 0x33) | ||
34 | DEFREG(CHGCTL2, 0x34) | ||
35 | DEFREG(BKPCHGCTL, 0x35) | ||
36 | DEFREG(PEKPARAM, 0x36) | ||
37 | DEFREG(DCDCFREQ, 0x37) | ||
38 | DEFREG(VLTFCHG, 0x38) | ||
39 | DEFREG(VHTFCHG, 0x39) | ||
40 | DEFREG(APSLOW1, 0x3a) | ||
41 | DEFREG(APSLOW2, 0x3b) | ||
42 | DEFREG(VLTFDCHG, 0x3c) | ||
43 | DEFREG(VHTFDCHG, 0x3d) | ||
44 | DEFREG(IRQEN1, 0x40) | ||
45 | DEFREG(IRQEN2, 0x41) | ||
46 | DEFREG(IRQEN3, 0x42) | ||
47 | DEFREG(IRQEN4, 0x43) | ||
48 | DEFREG(IRQSTS1, 0x44) | ||
49 | DEFREG(IRQSTS2, 0x45) | ||
50 | DEFREG(IRQSTS3, 0x46) | ||
51 | DEFREG(IRQSTS4, 0x47) | ||
52 | DEFREG(IRQEN5, 0x4a) | ||
53 | DEFREG(IRQSTS5, 0x4d) | ||
54 | DEFREG(DCDCMODE, 0x80) | ||
55 | DEFREG(ADCEN1, 0x82) | ||
56 | DEFREG(ADCEN2, 0x83) | ||
57 | DEFREG(ADCCTL, 0x84) | ||
58 | DEFREG(ADCRANGE, 0x85) | ||
59 | DEFREG(TIMERCTL, 0x8a) | ||
60 | DEFREG(VBUSSRP, 0x8b) | ||
61 | DEFREG(OTPOWEROFF, 0x8f) | ||
62 | DEFREG(GPIO0FUNC, 0x90) | ||
63 | DEFREG(GPIO0LDO, 0x91) | ||
64 | DEFREG(GPIO1FUNC, 0x92) | ||
65 | DEFREG(GPIO2FUNC, 0x93) | ||
66 | DEFREG(GPIOLEVEL1, 0x94) | ||
67 | DEFREG(GPIO3GPIO4FUNC, 0x95) | ||
68 | DEFREG(GPIOLEVEL2, 0x96) | ||
69 | DEFREG(GPIOPULL, 0x97) | ||
70 | DEFREG(PWM1X, 0x98) | ||
71 | DEFREG(PWM1Y1, 0x99) | ||
72 | DEFREG(PWM1Y2, 0x9a) | ||
73 | DEFREG(PWM2X, 0x9b) | ||
74 | DEFREG(PWM2Y1, 0x9c) | ||
75 | DEFREG(PWM2Y2, 0x9d) | ||
76 | DEFREG(NRSTO, 0x9e) | ||
77 | DEFREG(CC_CTL, 0xb8) | ||
78 | |||
79 | DEFBIT(PWRSTS, ACIN_PRESENT, 7) | ||
80 | DEFBIT(PWRSTS, ACIN_VALID, 6) | ||
81 | DEFBIT(PWRSTS, VBUS_PRESENT, 5) | ||
82 | DEFBIT(PWRSTS, VBUS_VALID, 4) | ||
83 | DEFBIT(PWRSTS, VBUS_VHOLD, 3) | ||
84 | DEFBIT(PWRSTS, BATT_CURR_DIR, 2) | ||
85 | DEFBIT(PWRSTS, PCB_SHORTED, 1) | ||
86 | DEFBIT(PWRSTS, BOOT_TRIG, 0) | ||
87 | |||
88 | DEFBIT(VBUSSTS, VALID, 2) | ||
89 | DEFBIT(VBUSSTS, SESS_AB_VALID, 1) | ||
90 | DEFBIT(VBUSSTS, SESS_END, 0) | ||
91 | |||
92 | DEFBIT(CHGSTS, OVER_TEMP, 7) | ||
93 | DEFBIT(CHGSTS, CHARGING, 6) | ||
94 | DEFBIT(CHGSTS, BATT_PRESENT, 5) | ||
95 | DEFBIT(CHGSTS, BATT_ERROR, 3) | ||
96 | DEFBIT(CHGSTS, LOW_CHARGE, 2) | ||
97 | |||
98 | /* NOTE: These two bits are mirrored in the upper nibble of PWRCTL2. | ||
99 | * Modifications through one register will immediately reflect in the | ||
100 | * other register. */ | ||
101 | DEFBIT(PWRCTL1, EXTEN_SW, 2) | ||
102 | DEFBIT(PWRCTL1, DCDC2_SW, 0) | ||
103 | |||
104 | DEFBIT(PWRCTL2, EXTEN_SW, 6) | ||
105 | DEFBIT(PWRCTL2, DCDC2_SW, 4) | ||
106 | DEFBIT(PWRCTL2, LDO3_SW, 3) | ||
107 | DEFBIT(PWRCTL2, LDO2_SW, 2) | ||
108 | DEFBIT(PWRCTL2, DCDC3_SW, 1) | ||
109 | DEFBIT(PWRCTL2, DCDC1_SW, 0) | ||
110 | |||
111 | DEFFLD(DCDC2VOLT, VALUE, 5, 0) | ||
112 | |||
113 | DEFBIT(DCDC2RAMP, ENABLE, 2) | ||
114 | DEFBIT(DCDC2RAMP, SLOPE, 0) | ||
115 | |||
116 | DEFFLD(DCDC1VOLT, VALUE, 6, 0) | ||
117 | DEFFLD(DCDC3VOLT, VALUE, 6, 0) | ||
118 | |||
119 | DEFFLD(LDO2LDO3VOLT, LDO2_VALUE, 7, 4) | ||
120 | DEFFLD(LDO2LDO3VOLT, LDO3_VALUE, 3, 0) | ||
121 | |||
122 | DEFBIT(VBUSIPSOUT, ACCESS, 7) | ||
123 | DEFBIT(VBUSIPSOUT, VHOLD_LIM, 6) | ||
124 | DEFFLD(VBUSIPSOUT, VHOLD_LEV, 5, 3) | ||
125 | DEFBIT(VBUSIPSOUT, VBUS_LIM, 1) | ||
126 | DEFBIT(VBUSIPSOUT, LIM_100mA, 0) | ||
127 | |||
128 | DEFFLD(VOFF, VALUE, 3, 0) | ||
129 | |||
130 | DEFBIT(PWROFF, SHUTDOWN, 7) | ||
131 | DEFBIT(PWROFF, MON_EN, 6) | ||
132 | DEFFLD(PWROFF, LEDFUNC, 5, 4) | ||
133 | DEFBIT(PWROFF, LEDCTL, 3) | ||
134 | DEFBIT(PWROFF, DELAY, 1, 0) | ||
135 | |||
136 | DEFBIT(CHGCTL1, CHARGE_EN, 7) | ||
137 | DEFFLD(CHGCTL1, CHARGE_TGT, 6, 5) | ||
138 | DEFBIT(CHGCTL1, CHARGE_ENDCURR, 4) | ||
139 | DEFFLD(CHGCTL1, CHARGE_CURRENT, 3, 0) | ||
140 | |||
141 | DEFFLD(CHGCTL2, PRECHARGE_OT, 7, 6) | ||
142 | DEFFLD(CHGCTL2, EACCESS_CURRENT, 5, 3) | ||
143 | DEFBIT(CHGCTL2, EACCESS_CHG_EN, 2) | ||
144 | DEFFLD(CHGCTL2, CONST_CURR_OT, 1, 0) | ||
145 | |||
146 | DEFBIT(BKPCHGCTL, ENABLE, 7) | ||
147 | DEFFLD(BKPCHGCTL, TGT_VOLTAGE, 6, 5) | ||
148 | DEFFLD(BKPCHGCTL, CHARGE_CURRENT, 1, 0) | ||
149 | |||
150 | DEFFLD(PEKPARAM, POWER_ON_TIME, 7, 6) | ||
151 | DEFFLD(PEKPARAM, LONG_TIME, 5, 4) | ||
152 | DEFBIT(PEKPARAM, POWEROFF_EN, 3) | ||
153 | DEFBIT(PEKPARAM, PWROK_DELAY, 2) | ||
154 | DEFFLD(PEKPARAM, POWEROFF_TIME, 1, 0) | ||
155 | |||
156 | DEFFLD(DCDCFREQ, VALUE, 3, 0) | ||
157 | DEFFLD(VLTFCHG, VALUE, 7, 0) | ||
158 | DEFFLD(VHTFCHG, VALUE, 7, 0) | ||
159 | DEFFLD(APSLOW1, VALUE, 7, 0) | ||
160 | DEFFLD(APSLOW2, VALUE, 7, 0) | ||
161 | DEFFLD(VLTFDCHG, VALUE, 7, 0) | ||
162 | DEFFLD(VHTFDCHG, VALUE, 7, 0) | ||
163 | |||
164 | DEFBIT(IRQEN1, ACIN_OVER_VOLTAGE, 7) | ||
165 | DEFBIT(IRQEN1, ACIN_INSERT, 6) | ||
166 | DEFBIT(IRQEN1, ACIN_REMOVE, 5) | ||
167 | DEFBIT(IRQEN1, VBUS_OVER_VOLTAGE, 4) | ||
168 | DEFBIT(IRQEN1, VBUS_INSERT, 3) | ||
169 | DEFBIT(IRQEN1, VBUS_REMOVE, 2) | ||
170 | DEFBIT(IRQEN1, VBUS_BELOW_VHOLD, 1) | ||
171 | DEFBIT(IRQEN2, BATTERY_INSERT, 7) | ||
172 | DEFBIT(IRQEN2, BATTERY_REMOVE, 6) | ||
173 | DEFBIT(IRQEN2, BATTERY_ERROR, 5) | ||
174 | DEFBIT(IRQEN2, BATTERY_ERROR_CLR, 4) | ||
175 | DEFBIT(IRQEN2, CHARGING_STARTED, 3) | ||
176 | DEFBIT(IRQEN2, CHARGING_COMPLETE, 2) | ||
177 | DEFBIT(IRQEN2, BATTERY_OVER_TEMP, 1) | ||
178 | DEFBIT(IRQEN2, BATTERY_UNDER_TEMP, 0) | ||
179 | DEFBIT(IRQEN3, INTERNAL_OVER_TEMP, 7) | ||
180 | DEFBIT(IRQEN3, LOW_CHARGE_CURRENT, 6) | ||
181 | DEFBIT(IRQEN3, DCDC1_UNDER_VOLT, 5) | ||
182 | DEFBIT(IRQEN3, DCDC2_UNDER_VOLT, 4) | ||
183 | DEFBIT(IRQEN3, DCDC3_UNDER_VOLT, 3) | ||
184 | DEFBIT(IRQEN3, SHORT_PRESS, 1) | ||
185 | DEFBIT(IRQEN3, LONG_PRESS, 0) | ||
186 | DEFBIT(IRQEN4, POWER_ON_N_OE, 7) | ||
187 | DEFBIT(IRQEN4, POWER_OFF_N_OE, 6) | ||
188 | DEFBIT(IRQEN4, VBUS_VALID, 5) | ||
189 | DEFBIT(IRQEN4, VBUS_INVALID, 4) | ||
190 | DEFBIT(IRQEN4, VBUS_SESS_AB, 3) | ||
191 | DEFBIT(IRQEN4, VBUS_SESS_END, 2) | ||
192 | DEFBIT(IRQEN4, APS_UNDER_VOLT, 0) | ||
193 | |||
194 | DEFBIT(IRQSTS1, ACIN_OVER_VOLTAGE, 7) | ||
195 | DEFBIT(IRQSTS1, ACIN_INSERT, 6) | ||
196 | DEFBIT(IRQSTS1, ACIN_REMOVE, 5) | ||
197 | DEFBIT(IRQSTS1, VBUS_OVER_VOLTAGE, 4) | ||
198 | DEFBIT(IRQSTS1, VBUS_INSERT, 3) | ||
199 | DEFBIT(IRQSTS1, VBUS_REMOVE, 2) | ||
200 | DEFBIT(IRQSTS1, VBUS_BELOW_VHOLD, 1) | ||
201 | DEFBIT(IRQSTS2, BATTERY_INSERT, 7) | ||
202 | DEFBIT(IRQSTS2, BATTERY_REMOVE, 6) | ||
203 | DEFBIT(IRQSTS2, BATTERY_ERROR, 5) | ||
204 | DEFBIT(IRQSTS2, BATTERY_ERROR_CLR, 4) | ||
205 | DEFBIT(IRQSTS2, CHARGING_STARTED, 3) | ||
206 | DEFBIT(IRQSTS2, CHARGING_STOPPED, 2) | ||
207 | DEFBIT(IRQSTS2, BATTERY_OVER_TEMP, 1) | ||
208 | DEFBIT(IRQSTS2, BATTERY_UNDER_TEMP, 0) | ||
209 | DEFBIT(IRQSTS3, INTERNAL_OVER_TEMP, 7) | ||
210 | DEFBIT(IRQSTS3, LOW_CHARGE_CURRENT, 6) | ||
211 | DEFBIT(IRQSTS3, DCDC1_UNDER_VOLT, 5) | ||
212 | DEFBIT(IRQSTS3, DCDC2_UNDER_VOLT, 4) | ||
213 | DEFBIT(IRQSTS3, DCDC3_UNDER_VOLT, 3) | ||
214 | DEFBIT(IRQSTS3, SHORT_PRESS, 1) | ||
215 | DEFBIT(IRQSTS3, LONG_PRESS, 0) | ||
216 | DEFBIT(IRQSTS4, POWER_ON_N_OE, 7) | ||
217 | DEFBIT(IRQSTS4, POWER_OFF_N_OE, 6) | ||
218 | DEFBIT(IRQSTS4, VBUS_VALID, 5) | ||
219 | DEFBIT(IRQSTS4, VBUS_INVALID, 4) | ||
220 | DEFBIT(IRQSTS4, VBUS_SESS_AB, 3) | ||
221 | DEFBIT(IRQSTS4, VBUS_SESS_END, 2) | ||
222 | DEFBIT(IRQSTS4, APS_UNDER_VOLT, 0) | ||
223 | |||
224 | /* NOTE: IRQEN5 and IRQSTS5 are only listed on the Chinese datasheet. */ | ||
225 | DEFBIT(IRQEN5, TIME_OUT, 7) | ||
226 | DEFBIT(IRQEN5, GPIO2_CHANGE, 2) | ||
227 | DEFBIT(IRQEN5, GPIO1_CHANGE, 1) | ||
228 | DEFBIT(IRQEN5, GPIO0_CHANGE, 0) | ||
229 | |||
230 | DEFBIT(IRQSTS5, TIME_OUT, 7) | ||
231 | DEFBIT(IRQSTS5, GPIO2_CHANGE, 2) | ||
232 | DEFBIT(IRQSTS5, GPIO1_CHANGE, 1) | ||
233 | DEFBIT(IRQSTS5, GPIO0_CHANGE, 0) | ||
234 | |||
235 | DEFFLD(DCDCMODE, VALUE, 3, 1) | ||
236 | |||
237 | DEFBIT(ADCEN1, BATTERY_VOLTAGE, 7) | ||
238 | DEFBIT(ADCEN1, BATTERY_CURRENT, 6) | ||
239 | DEFBIT(ADCEN1, ACIN_VOLTAGE, 5) | ||
240 | DEFBIT(ADCEN1, ACIN_CURRENT, 4) | ||
241 | DEFBIT(ADCEN1, VBUS_VOLTAGE, 3) | ||
242 | DEFBIT(ADCEN1, VBUS_CURRENT, 2) | ||
243 | DEFBIT(ADCEN1, APS_VOLTAGE, 1) | ||
244 | DEFBIT(ADCEN1, TS_PIN, 0) | ||
245 | |||
246 | DEFBIT(ADCEN2, INTERNAL_TEMP, 7) | ||
247 | DEFBIT(ADCEN2, GPIO0, 3) | ||
248 | DEFBIT(ADCEN2, GPIO1, 2) | ||
249 | DEFBIT(ADCEN2, GPIO2, 1) | ||
250 | DEFBIT(ADCEN2, GPIO3, 0) | ||
251 | |||
252 | DEFFLD(ADCCTL, SAMPLE_RATE, 7, 6) | ||
253 | DEFFLD(ADCCTL, TS_OUT_CURR, 5, 4) | ||
254 | DEFBIT(ADCCTL, TS_FUNCTION, 2) | ||
255 | DEFFLD(ADCCTL, TS_OUT_MODE, 1, 0) | ||
256 | |||
257 | DEFBIT(ADCRANGE, GPIO3HIGH, 3) | ||
258 | DEFBIT(ADCRANGE, GPIO2HIGH, 2) | ||
259 | DEFBIT(ADCRANGE, GPIO1HIGH, 1) | ||
260 | DEFBIT(ADCRANGE, GPIO0HIGH, 0) | ||
261 | |||
262 | DEFBIT(TIMERCTL, TIMEOUT, 7) | ||
263 | DEFFLD(TIMERCTL, DURATION, 6, 0) | ||
264 | |||
265 | DEFFLD(VBUSSRP, VBUSVALID_VOLTAGE, 5, 4) | ||
266 | DEFBIT(VBUSSRP, VBUSVALID_MONITOR, 3) | ||
267 | DEFBIT(VBUSSRP, VBUS_SESS_MONITOR, 2) | ||
268 | DEFBIT(VBUSSRP, VBUS_DCHG_RESISTOR, 1) | ||
269 | DEFBIT(VBUSSRP, VBUS_CHG_RESISTOR, 0) | ||
270 | |||
271 | DEFBIT(OTPOWEROFF, ENABLE, 2) | ||
272 | |||
273 | DEFFLD(GPIO0FUNC, VALUE, 2, 0) | ||
274 | DEFFLD(GPIO0LDO, VALUE, 7, 4) | ||
275 | DEFFLD(GPIO1FUNC, VALUE, 2, 0) | ||
276 | DEFFLD(GPIO2FUNC, VALUE, 2, 0) | ||
277 | |||
278 | DEFBIT(GPIOLEVEL1, IN2, 6) | ||
279 | DEFBIT(GPIOLEVEL1, IN1, 5) | ||
280 | DEFBIT(GPIOLEVEL1, IN0, 4) | ||
281 | DEFBIT(GPIOLEVEL1, OUT2, 2) | ||
282 | DEFBIT(GPIOLEVEL1, OUT1, 1) | ||
283 | DEFBIT(GPIOLEVEL1, OUT0, 0) | ||
284 | |||
285 | DEFFLD(GPIO3GPIO4FUNC, FUNC3, 3, 2) | ||
286 | DEFFLD(GPIO3GPIO4FUNC, FUNC4, 1, 0) | ||
287 | |||
288 | DEFBIT(GPIOLEVEL2, IN4, 5) | ||
289 | DEFBIT(GPIOLEVEL2, IN3, 4) | ||
290 | DEFBIT(GPIOLEVEL2, OUT4, 1) | ||
291 | DEFBIT(GPIOLEVEL2, OUT3, 0) | ||
292 | |||
293 | DEFBIT(GPIOPULL, PULL2, 2) | ||
294 | DEFBIT(GPIOPULL, PULL1, 1) | ||
295 | DEFBIT(GPIOPULL, PULL0, 0) | ||
296 | |||
297 | DEFBIT(NRSTO, FUNC, 7) | ||
298 | DEFBIT(NRSTO, GPIO_DIR, 6) | ||
299 | DEFBIT(NRSTO, GPIO_OUT, 5) | ||
300 | DEFBIT(NRSTO, GPIO_IN, 4) | ||
301 | |||
302 | DEFBIT(CC_CTL, OPEN, 7) | ||
303 | DEFBIT(CC_CTL, PAUSE, 6) | ||
304 | DEFBIT(CC_CTL, CLEAR, 5) | ||
305 | |||
306 | #undef DEFBIT | ||
307 | #undef DEFFLD | ||
308 | #undef DEFREG | ||
diff --git a/firmware/export/axp192.h b/firmware/export/axp192.h new file mode 100644 index 0000000000..6ed278d086 --- /dev/null +++ b/firmware/export/axp192.h | |||
@@ -0,0 +1,131 @@ | |||
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 __AXP192_H__ | ||
23 | #define __AXP192_H__ | ||
24 | |||
25 | #include <stdint.h> | ||
26 | #include <stdbool.h> | ||
27 | |||
28 | enum { | ||
29 | #define DEFREG(regname, addr) AXP_REG_##regname = addr, | ||
30 | #include "axp192-defs.h" | ||
31 | }; | ||
32 | |||
33 | enum { | ||
34 | #define DEFFLD(regname, fldname, msb, lsb, ...) \ | ||
35 | BM_AXP_##regname##_##fldname = ((1 << ((msb) - (lsb) + 1)) - 1) << lsb, \ | ||
36 | BP_AXP_##regname##_##fldname = lsb, | ||
37 | #include "axp192-defs.h" | ||
38 | }; | ||
39 | |||
40 | enum { | ||
41 | AXP_SUPPLY_EXTEN, | ||
42 | AXP_SUPPLY_DCDC1, | ||
43 | AXP_SUPPLY_DCDC2, | ||
44 | AXP_SUPPLY_DCDC3, | ||
45 | AXP_SUPPLY_LDO2, | ||
46 | AXP_SUPPLY_LDO3, | ||
47 | AXP_SUPPLY_LDOIO0, | ||
48 | AXP_NUM_SUPPLIES, | ||
49 | }; | ||
50 | |||
51 | enum { | ||
52 | AXP_ADC_ACIN_VOLTAGE, | ||
53 | AXP_ADC_ACIN_CURRENT, | ||
54 | AXP_ADC_VBUS_VOLTAGE, | ||
55 | AXP_ADC_VBUS_CURRENT, | ||
56 | AXP_ADC_INTERNAL_TEMP, | ||
57 | AXP_ADC_TS_INPUT, | ||
58 | AXP_ADC_GPIO0, | ||
59 | AXP_ADC_GPIO1, | ||
60 | AXP_ADC_GPIO2, | ||
61 | AXP_ADC_GPIO3, | ||
62 | AXP_ADC_BATTERY_VOLTAGE, | ||
63 | AXP_ADC_CHARGE_CURRENT, | ||
64 | AXP_ADC_DISCHARGE_CURRENT, | ||
65 | AXP_ADC_APS_VOLTAGE, | ||
66 | AXP_NUM_ADCS, | ||
67 | }; | ||
68 | |||
69 | enum { | ||
70 | AXP_GPIO_OPEN_DRAIN_OUTPUT = 0x0, | ||
71 | AXP_GPIO_INPUT = 0x1, | ||
72 | AXP_GPIO_SPECIAL = 0x2, | ||
73 | AXP_GPIO_ADC_IN = 0x4, | ||
74 | AXP_GPIO_LOW_OUTPUT = 0x5, | ||
75 | AXP_GPIO_FLOATING = 0x7, | ||
76 | }; | ||
77 | |||
78 | enum { | ||
79 | /* Limit USB current consumption to 100 mA. */ | ||
80 | AXP_VBUS_LIMIT_100mA = (1 << BP_AXP_VBUSIPSOUT_VHOLD_LIM) | | ||
81 | (1 << BP_AXP_VBUSIPSOUT_VBUS_LIM) | | ||
82 | (1 << BP_AXP_VBUSIPSOUT_LIM_100mA), | ||
83 | |||
84 | /* Limit USB current consumption to 500 mA. */ | ||
85 | AXP_VBUS_LIMIT_500mA = (1 << BP_AXP_VBUSIPSOUT_VHOLD_LIM) | | ||
86 | (1 << BP_AXP_VBUSIPSOUT_VBUS_LIM) | | ||
87 | (0 << BP_AXP_VBUSIPSOUT_LIM_100mA), | ||
88 | |||
89 | /* No upper bound on USB current, but the current will still | ||
90 | * be reduced to maintain the bus voltage above V_hold. */ | ||
91 | AXP_VBUS_UNLIMITED = (1 << BP_AXP_VBUSIPSOUT_VHOLD_LIM) | | ||
92 | (0 << BP_AXP_VBUSIPSOUT_VBUS_LIM) | | ||
93 | (0 << BP_AXP_VBUSIPSOUT_LIM_100mA), | ||
94 | |||
95 | /* Unlimited USB current consumption. Voltage is allowed to drop | ||
96 | * below V_hold, which may interfere with normal USB operation. | ||
97 | * This mode is really only useful with AC charging adapters. */ | ||
98 | AXP_VBUS_FULLY_UNLIMITED = (0 << BP_AXP_VBUSIPSOUT_VHOLD_LIM) | | ||
99 | (0 << BP_AXP_VBUSIPSOUT_VBUS_LIM) | | ||
100 | (0 << BP_AXP_VBUSIPSOUT_LIM_100mA), | ||
101 | }; | ||
102 | |||
103 | extern int axp_read(uint8_t reg); | ||
104 | extern int axp_write(uint8_t reg, uint8_t value); | ||
105 | extern int axp_modify(uint8_t reg, uint8_t clr, uint8_t set); | ||
106 | |||
107 | extern void axp_enable_supply(int supply, bool enable); | ||
108 | extern void axp_set_enabled_supplies(unsigned int supply_mask); | ||
109 | extern void axp_set_supply_voltage(int supply, int output_mV); | ||
110 | |||
111 | extern void axp_enable_adc(int adc, bool enable); | ||
112 | extern void axp_set_enabled_adcs(unsigned int adc_mask); | ||
113 | extern int axp_read_adc_raw(int adc); | ||
114 | extern int axp_conv_adc(int adc, int value); | ||
115 | extern int axp_read_adc(int adc); | ||
116 | |||
117 | extern void axp_set_gpio_function(int gpio, int function); | ||
118 | extern void axp_set_gpio_pulldown(int gpio, bool enable); | ||
119 | extern int axp_get_gpio(int gpio); | ||
120 | extern void axp_set_gpio(int gpio, bool enable); | ||
121 | |||
122 | extern void axp_set_charge_current(int current_mA); | ||
123 | extern int axp_get_charge_current(void); | ||
124 | extern void axp_set_vbus_limit(int vbus_limit); | ||
125 | extern void axp_set_vhold_level(int vhold_mV); | ||
126 | extern bool axp_is_charging(void); | ||
127 | extern unsigned int axp_power_input_status(void); | ||
128 | |||
129 | extern void axp_power_off(void); | ||
130 | |||
131 | #endif /* __AXP192_H__ */ | ||