summaryrefslogtreecommitdiff
path: root/firmware/export
diff options
context:
space:
mode:
authorAidan MacDonald <amachronic@protonmail.com>2022-01-09 16:03:30 +0000
committerAidan MacDonald <amachronic@protonmail.com>2022-01-09 19:58:34 +0000
commiteaee5e7339aec46b4b67f06b139b8708810a4c2e (patch)
tree28bac18b6a68caae4689c712b4b7d2ab80fed583 /firmware/export
parent8f063d49c2e1dffb5548e40b69782963e18b1171 (diff)
downloadrockbox-eaee5e7339aec46b4b67f06b139b8708810a4c2e.tar.gz
rockbox-eaee5e7339aec46b4b67f06b139b8708810a4c2e.zip
Revert "AXP PMU rewrite (again)"
This caused LCD problems on the ErosQ, where the screen would go white until being put through a sleep/wake cycle. The exact reason for this isn't obvious, but the problem didn't exist prior to the AXP driver rewrite. The two dependent changes, 42999913ba - x1000: Increase USB current limit to 500 mA at all times 90dd2f84a9 - x1000: Correctly limit USB charging current ended up bringing the USB charging situation back to where it was prior to the rewrite, so the cleanest option is to revert the whole lot. This reverts commit 42999913ba3a76221fceb04b1f935ed4e0e71476. This reverts commit 90dd2f84a9174c38dbfb07d582ec6ee7697b1939. This reverts commit 2d891439623bb76d38b98202ca5f3eea3c01c5f0. Change-Id: I1cff2bfdd1b189df14bcf8cce42db725caa470d7
Diffstat (limited to 'firmware/export')
-rw-r--r--firmware/export/axp-pmu.h151
-rw-r--r--firmware/export/axp192-defs.h308
-rw-r--r--firmware/export/axp192.h131
3 files changed, 151 insertions, 439 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 */
96extern 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 */
106extern void axp_supply_set_voltage(int supply, int voltage);
107extern int axp_supply_get_voltage(int supply);
108
109/* Basic battery and power supply status */
110extern int axp_battery_status(void);
111extern 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 */
123extern int axp_adc_read(int adc);
124extern int axp_adc_read_raw(int adc);
125extern int axp_adc_conv_raw(int adc, int value);
126extern int axp_adc_get_enabled(void);
127extern void axp_adc_set_enabled(int adc_bits);
128extern int axp_adc_get_rate(void);
129extern 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 */
136extern void axp_cc_read(uint32_t* charge, uint32_t* discharge);
137extern void axp_cc_clear(void);
138extern void axp_cc_enable(bool en);
139extern bool axp_cc_is_enabled(void);
140
141/* Set/get maximum charging current in milliamps */
142extern void axp_set_charge_current(int maxcurrent);
143extern int axp_get_charge_current(void);
144
145/* Set the shutdown bit */
146extern void axp_power_off(void);
147
148/* Debug menu */
149extern 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
deleted file mode 100644
index 13b465351b..0000000000
--- a/firmware/export/axp192-defs.h
+++ /dev/null
@@ -1,308 +0,0 @@
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
13DEFREG(PWRSTS, 0x00)
14DEFREG(CHGSTS, 0x01)
15DEFREG(CHIPID, 0x03)
16DEFREG(VBUSSTS, 0x04)
17DEFREG(DATA0, 0x06)
18DEFREG(DATA1, 0x07)
19DEFREG(DATA2, 0x08)
20DEFREG(DATA3, 0x09)
21DEFREG(DATA4, 0x0a)
22DEFREG(DATA5, 0x0b)
23DEFREG(PWRCTL1, 0x10)
24DEFREG(PWRCTL2, 0x12)
25DEFREG(DCDC2VOLT, 0x23)
26DEFREG(DCDC2RAMP, 0x25)
27DEFREG(DCDC1VOLT, 0x26)
28DEFREG(DCDC3VOLT, 0x27)
29DEFREG(LDO2LDO3VOLT, 0x28)
30DEFREG(VBUSIPSOUT, 0x30)
31DEFREG(VOFF, 0x31)
32DEFREG(PWROFF, 0x32)
33DEFREG(CHGCTL1, 0x33)
34DEFREG(CHGCTL2, 0x34)
35DEFREG(BKPCHGCTL, 0x35)
36DEFREG(PEKPARAM, 0x36)
37DEFREG(DCDCFREQ, 0x37)
38DEFREG(VLTFCHG, 0x38)
39DEFREG(VHTFCHG, 0x39)
40DEFREG(APSLOW1, 0x3a)
41DEFREG(APSLOW2, 0x3b)
42DEFREG(VLTFDCHG, 0x3c)
43DEFREG(VHTFDCHG, 0x3d)
44DEFREG(IRQEN1, 0x40)
45DEFREG(IRQEN2, 0x41)
46DEFREG(IRQEN3, 0x42)
47DEFREG(IRQEN4, 0x43)
48DEFREG(IRQSTS1, 0x44)
49DEFREG(IRQSTS2, 0x45)
50DEFREG(IRQSTS3, 0x46)
51DEFREG(IRQSTS4, 0x47)
52DEFREG(IRQEN5, 0x4a)
53DEFREG(IRQSTS5, 0x4d)
54DEFREG(DCDCMODE, 0x80)
55DEFREG(ADCEN1, 0x82)
56DEFREG(ADCEN2, 0x83)
57DEFREG(ADCCTL, 0x84)
58DEFREG(ADCRANGE, 0x85)
59DEFREG(TIMERCTL, 0x8a)
60DEFREG(VBUSSRP, 0x8b)
61DEFREG(OTPOWEROFF, 0x8f)
62DEFREG(GPIO0FUNC, 0x90)
63DEFREG(GPIO0LDO, 0x91)
64DEFREG(GPIO1FUNC, 0x92)
65DEFREG(GPIO2FUNC, 0x93)
66DEFREG(GPIOLEVEL1, 0x94)
67DEFREG(GPIO3GPIO4FUNC, 0x95)
68DEFREG(GPIOLEVEL2, 0x96)
69DEFREG(GPIOPULL, 0x97)
70DEFREG(PWM1X, 0x98)
71DEFREG(PWM1Y1, 0x99)
72DEFREG(PWM1Y2, 0x9a)
73DEFREG(PWM2X, 0x9b)
74DEFREG(PWM2Y1, 0x9c)
75DEFREG(PWM2Y2, 0x9d)
76DEFREG(NRSTO, 0x9e)
77DEFREG(CC_CTL, 0xb8)
78
79DEFBIT(PWRSTS, ACIN_PRESENT, 7)
80DEFBIT(PWRSTS, ACIN_VALID, 6)
81DEFBIT(PWRSTS, VBUS_PRESENT, 5)
82DEFBIT(PWRSTS, VBUS_VALID, 4)
83DEFBIT(PWRSTS, VBUS_VHOLD, 3)
84DEFBIT(PWRSTS, BATT_CURR_DIR, 2)
85DEFBIT(PWRSTS, PCB_SHORTED, 1)
86DEFBIT(PWRSTS, BOOT_TRIG, 0)
87
88DEFBIT(VBUSSTS, VALID, 2)
89DEFBIT(VBUSSTS, SESS_AB_VALID, 1)
90DEFBIT(VBUSSTS, SESS_END, 0)
91
92DEFBIT(CHGSTS, OVER_TEMP, 7)
93DEFBIT(CHGSTS, CHARGING, 6)
94DEFBIT(CHGSTS, BATT_PRESENT, 5)
95DEFBIT(CHGSTS, BATT_ERROR, 3)
96DEFBIT(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. */
101DEFBIT(PWRCTL1, EXTEN_SW, 2)
102DEFBIT(PWRCTL1, DCDC2_SW, 0)
103
104DEFBIT(PWRCTL2, EXTEN_SW, 6)
105DEFBIT(PWRCTL2, DCDC2_SW, 4)
106DEFBIT(PWRCTL2, LDO3_SW, 3)
107DEFBIT(PWRCTL2, LDO2_SW, 2)
108DEFBIT(PWRCTL2, DCDC3_SW, 1)
109DEFBIT(PWRCTL2, DCDC1_SW, 0)
110
111DEFFLD(DCDC2VOLT, VALUE, 5, 0)
112
113DEFBIT(DCDC2RAMP, ENABLE, 2)
114DEFBIT(DCDC2RAMP, SLOPE, 0)
115
116DEFFLD(DCDC1VOLT, VALUE, 6, 0)
117DEFFLD(DCDC3VOLT, VALUE, 6, 0)
118
119DEFFLD(LDO2LDO3VOLT, LDO2_VALUE, 7, 4)
120DEFFLD(LDO2LDO3VOLT, LDO3_VALUE, 3, 0)
121
122DEFBIT(VBUSIPSOUT, ACCESS, 7)
123DEFBIT(VBUSIPSOUT, VHOLD_LIM, 6)
124DEFFLD(VBUSIPSOUT, VHOLD_LEV, 5, 3)
125DEFBIT(VBUSIPSOUT, VBUS_LIM, 1)
126DEFBIT(VBUSIPSOUT, LIM_100mA, 0)
127
128DEFFLD(VOFF, VALUE, 3, 0)
129
130DEFBIT(PWROFF, SHUTDOWN, 7)
131DEFBIT(PWROFF, MON_EN, 6)
132DEFFLD(PWROFF, LEDFUNC, 5, 4)
133DEFBIT(PWROFF, LEDCTL, 3)
134DEFBIT(PWROFF, DELAY, 1, 0)
135
136DEFBIT(CHGCTL1, CHARGE_EN, 7)
137DEFFLD(CHGCTL1, CHARGE_TGT, 6, 5)
138DEFBIT(CHGCTL1, CHARGE_ENDCURR, 4)
139DEFFLD(CHGCTL1, CHARGE_CURRENT, 3, 0)
140
141DEFFLD(CHGCTL2, PRECHARGE_OT, 7, 6)
142DEFFLD(CHGCTL2, EACCESS_CURRENT, 5, 3)
143DEFBIT(CHGCTL2, EACCESS_CHG_EN, 2)
144DEFFLD(CHGCTL2, CONST_CURR_OT, 1, 0)
145
146DEFBIT(BKPCHGCTL, ENABLE, 7)
147DEFFLD(BKPCHGCTL, TGT_VOLTAGE, 6, 5)
148DEFFLD(BKPCHGCTL, CHARGE_CURRENT, 1, 0)
149
150DEFFLD(PEKPARAM, POWER_ON_TIME, 7, 6)
151DEFFLD(PEKPARAM, LONG_TIME, 5, 4)
152DEFBIT(PEKPARAM, POWEROFF_EN, 3)
153DEFBIT(PEKPARAM, PWROK_DELAY, 2)
154DEFFLD(PEKPARAM, POWEROFF_TIME, 1, 0)
155
156DEFFLD(DCDCFREQ, VALUE, 3, 0)
157DEFFLD(VLTFCHG, VALUE, 7, 0)
158DEFFLD(VHTFCHG, VALUE, 7, 0)
159DEFFLD(APSLOW1, VALUE, 7, 0)
160DEFFLD(APSLOW2, VALUE, 7, 0)
161DEFFLD(VLTFDCHG, VALUE, 7, 0)
162DEFFLD(VHTFDCHG, VALUE, 7, 0)
163
164DEFBIT(IRQEN1, ACIN_OVER_VOLTAGE, 7)
165DEFBIT(IRQEN1, ACIN_INSERT, 6)
166DEFBIT(IRQEN1, ACIN_REMOVE, 5)
167DEFBIT(IRQEN1, VBUS_OVER_VOLTAGE, 4)
168DEFBIT(IRQEN1, VBUS_INSERT, 3)
169DEFBIT(IRQEN1, VBUS_REMOVE, 2)
170DEFBIT(IRQEN1, VBUS_BELOW_VHOLD, 1)
171DEFBIT(IRQEN2, BATTERY_INSERT, 7)
172DEFBIT(IRQEN2, BATTERY_REMOVE, 6)
173DEFBIT(IRQEN2, BATTERY_ERROR, 5)
174DEFBIT(IRQEN2, BATTERY_ERROR_CLR, 4)
175DEFBIT(IRQEN2, CHARGING_STARTED, 3)
176DEFBIT(IRQEN2, CHARGING_COMPLETE, 2)
177DEFBIT(IRQEN2, BATTERY_OVER_TEMP, 1)
178DEFBIT(IRQEN2, BATTERY_UNDER_TEMP, 0)
179DEFBIT(IRQEN3, INTERNAL_OVER_TEMP, 7)
180DEFBIT(IRQEN3, LOW_CHARGE_CURRENT, 6)
181DEFBIT(IRQEN3, DCDC1_UNDER_VOLT, 5)
182DEFBIT(IRQEN3, DCDC2_UNDER_VOLT, 4)
183DEFBIT(IRQEN3, DCDC3_UNDER_VOLT, 3)
184DEFBIT(IRQEN3, SHORT_PRESS, 1)
185DEFBIT(IRQEN3, LONG_PRESS, 0)
186DEFBIT(IRQEN4, POWER_ON_N_OE, 7)
187DEFBIT(IRQEN4, POWER_OFF_N_OE, 6)
188DEFBIT(IRQEN4, VBUS_VALID, 5)
189DEFBIT(IRQEN4, VBUS_INVALID, 4)
190DEFBIT(IRQEN4, VBUS_SESS_AB, 3)
191DEFBIT(IRQEN4, VBUS_SESS_END, 2)
192DEFBIT(IRQEN4, APS_UNDER_VOLT, 0)
193
194DEFBIT(IRQSTS1, ACIN_OVER_VOLTAGE, 7)
195DEFBIT(IRQSTS1, ACIN_INSERT, 6)
196DEFBIT(IRQSTS1, ACIN_REMOVE, 5)
197DEFBIT(IRQSTS1, VBUS_OVER_VOLTAGE, 4)
198DEFBIT(IRQSTS1, VBUS_INSERT, 3)
199DEFBIT(IRQSTS1, VBUS_REMOVE, 2)
200DEFBIT(IRQSTS1, VBUS_BELOW_VHOLD, 1)
201DEFBIT(IRQSTS2, BATTERY_INSERT, 7)
202DEFBIT(IRQSTS2, BATTERY_REMOVE, 6)
203DEFBIT(IRQSTS2, BATTERY_ERROR, 5)
204DEFBIT(IRQSTS2, BATTERY_ERROR_CLR, 4)
205DEFBIT(IRQSTS2, CHARGING_STARTED, 3)
206DEFBIT(IRQSTS2, CHARGING_STOPPED, 2)
207DEFBIT(IRQSTS2, BATTERY_OVER_TEMP, 1)
208DEFBIT(IRQSTS2, BATTERY_UNDER_TEMP, 0)
209DEFBIT(IRQSTS3, INTERNAL_OVER_TEMP, 7)
210DEFBIT(IRQSTS3, LOW_CHARGE_CURRENT, 6)
211DEFBIT(IRQSTS3, DCDC1_UNDER_VOLT, 5)
212DEFBIT(IRQSTS3, DCDC2_UNDER_VOLT, 4)
213DEFBIT(IRQSTS3, DCDC3_UNDER_VOLT, 3)
214DEFBIT(IRQSTS3, SHORT_PRESS, 1)
215DEFBIT(IRQSTS3, LONG_PRESS, 0)
216DEFBIT(IRQSTS4, POWER_ON_N_OE, 7)
217DEFBIT(IRQSTS4, POWER_OFF_N_OE, 6)
218DEFBIT(IRQSTS4, VBUS_VALID, 5)
219DEFBIT(IRQSTS4, VBUS_INVALID, 4)
220DEFBIT(IRQSTS4, VBUS_SESS_AB, 3)
221DEFBIT(IRQSTS4, VBUS_SESS_END, 2)
222DEFBIT(IRQSTS4, APS_UNDER_VOLT, 0)
223
224/* NOTE: IRQEN5 and IRQSTS5 are only listed on the Chinese datasheet. */
225DEFBIT(IRQEN5, TIME_OUT, 7)
226DEFBIT(IRQEN5, GPIO2_CHANGE, 2)
227DEFBIT(IRQEN5, GPIO1_CHANGE, 1)
228DEFBIT(IRQEN5, GPIO0_CHANGE, 0)
229
230DEFBIT(IRQSTS5, TIME_OUT, 7)
231DEFBIT(IRQSTS5, GPIO2_CHANGE, 2)
232DEFBIT(IRQSTS5, GPIO1_CHANGE, 1)
233DEFBIT(IRQSTS5, GPIO0_CHANGE, 0)
234
235DEFFLD(DCDCMODE, VALUE, 3, 1)
236
237DEFBIT(ADCEN1, BATTERY_VOLTAGE, 7)
238DEFBIT(ADCEN1, BATTERY_CURRENT, 6)
239DEFBIT(ADCEN1, ACIN_VOLTAGE, 5)
240DEFBIT(ADCEN1, ACIN_CURRENT, 4)
241DEFBIT(ADCEN1, VBUS_VOLTAGE, 3)
242DEFBIT(ADCEN1, VBUS_CURRENT, 2)
243DEFBIT(ADCEN1, APS_VOLTAGE, 1)
244DEFBIT(ADCEN1, TS_PIN, 0)
245
246DEFBIT(ADCEN2, INTERNAL_TEMP, 7)
247DEFBIT(ADCEN2, GPIO0, 3)
248DEFBIT(ADCEN2, GPIO1, 2)
249DEFBIT(ADCEN2, GPIO2, 1)
250DEFBIT(ADCEN2, GPIO3, 0)
251
252DEFFLD(ADCCTL, SAMPLE_RATE, 7, 6)
253DEFFLD(ADCCTL, TS_OUT_CURR, 5, 4)
254DEFBIT(ADCCTL, TS_FUNCTION, 2)
255DEFFLD(ADCCTL, TS_OUT_MODE, 1, 0)
256
257DEFBIT(ADCRANGE, GPIO3HIGH, 3)
258DEFBIT(ADCRANGE, GPIO2HIGH, 2)
259DEFBIT(ADCRANGE, GPIO1HIGH, 1)
260DEFBIT(ADCRANGE, GPIO0HIGH, 0)
261
262DEFBIT(TIMERCTL, TIMEOUT, 7)
263DEFFLD(TIMERCTL, DURATION, 6, 0)
264
265DEFFLD(VBUSSRP, VBUSVALID_VOLTAGE, 5, 4)
266DEFBIT(VBUSSRP, VBUSVALID_MONITOR, 3)
267DEFBIT(VBUSSRP, VBUS_SESS_MONITOR, 2)
268DEFBIT(VBUSSRP, VBUS_DCHG_RESISTOR, 1)
269DEFBIT(VBUSSRP, VBUS_CHG_RESISTOR, 0)
270
271DEFBIT(OTPOWEROFF, ENABLE, 2)
272
273DEFFLD(GPIO0FUNC, VALUE, 2, 0)
274DEFFLD(GPIO0LDO, VALUE, 7, 4)
275DEFFLD(GPIO1FUNC, VALUE, 2, 0)
276DEFFLD(GPIO2FUNC, VALUE, 2, 0)
277
278DEFBIT(GPIOLEVEL1, IN2, 6)
279DEFBIT(GPIOLEVEL1, IN1, 5)
280DEFBIT(GPIOLEVEL1, IN0, 4)
281DEFBIT(GPIOLEVEL1, OUT2, 2)
282DEFBIT(GPIOLEVEL1, OUT1, 1)
283DEFBIT(GPIOLEVEL1, OUT0, 0)
284
285DEFFLD(GPIO3GPIO4FUNC, FUNC3, 3, 2)
286DEFFLD(GPIO3GPIO4FUNC, FUNC4, 1, 0)
287
288DEFBIT(GPIOLEVEL2, IN4, 5)
289DEFBIT(GPIOLEVEL2, IN3, 4)
290DEFBIT(GPIOLEVEL2, OUT4, 1)
291DEFBIT(GPIOLEVEL2, OUT3, 0)
292
293DEFBIT(GPIOPULL, PULL2, 2)
294DEFBIT(GPIOPULL, PULL1, 1)
295DEFBIT(GPIOPULL, PULL0, 0)
296
297DEFBIT(NRSTO, FUNC, 7)
298DEFBIT(NRSTO, GPIO_DIR, 6)
299DEFBIT(NRSTO, GPIO_OUT, 5)
300DEFBIT(NRSTO, GPIO_IN, 4)
301
302DEFBIT(CC_CTL, OPEN, 7)
303DEFBIT(CC_CTL, PAUSE, 6)
304DEFBIT(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
deleted file mode 100644
index 6ed278d086..0000000000
--- a/firmware/export/axp192.h
+++ /dev/null
@@ -1,131 +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 __AXP192_H__
23#define __AXP192_H__
24
25#include <stdint.h>
26#include <stdbool.h>
27
28enum {
29#define DEFREG(regname, addr) AXP_REG_##regname = addr,
30#include "axp192-defs.h"
31};
32
33enum {
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
40enum {
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
51enum {
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
69enum {
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
78enum {
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
103extern int axp_read(uint8_t reg);
104extern int axp_write(uint8_t reg, uint8_t value);
105extern int axp_modify(uint8_t reg, uint8_t clr, uint8_t set);
106
107extern void axp_enable_supply(int supply, bool enable);
108extern void axp_set_enabled_supplies(unsigned int supply_mask);
109extern void axp_set_supply_voltage(int supply, int output_mV);
110
111extern void axp_enable_adc(int adc, bool enable);
112extern void axp_set_enabled_adcs(unsigned int adc_mask);
113extern int axp_read_adc_raw(int adc);
114extern int axp_conv_adc(int adc, int value);
115extern int axp_read_adc(int adc);
116
117extern void axp_set_gpio_function(int gpio, int function);
118extern void axp_set_gpio_pulldown(int gpio, bool enable);
119extern int axp_get_gpio(int gpio);
120extern void axp_set_gpio(int gpio, bool enable);
121
122extern void axp_set_charge_current(int current_mA);
123extern int axp_get_charge_current(void);
124extern void axp_set_vbus_limit(int vbus_limit);
125extern void axp_set_vhold_level(int vhold_mV);
126extern bool axp_is_charging(void);
127extern unsigned int axp_power_input_status(void);
128
129extern void axp_power_off(void);
130
131#endif /* __AXP192_H__ */