diff options
author | Aidan MacDonald <amachronic@protonmail.com> | 2021-12-05 14:30:03 +0000 |
---|---|---|
committer | Aidan MacDonald <amachronic@protonmail.com> | 2021-12-28 15:20:27 +0000 |
commit | 2d891439623bb76d38b98202ca5f3eea3c01c5f0 (patch) | |
tree | 50e52529843835d057bd07b4797545da2b0e4d9e /firmware/target/mips/ingenic_x1000/shanlingq1 | |
parent | b774699560dc37db272d122cb140e73dd08b643b (diff) | |
download | rockbox-2d891439623bb76d38b98202ca5f3eea3c01c5f0.tar.gz rockbox-2d891439623bb76d38b98202ca5f3eea3c01c5f0.zip |
AXP PMU rewrite (again)
I noticed a few mistakes in the old driver code and it was in
need of an overhaul anyway... I decided to scale things back,
simplify the code and remove most of the debug menus, netting
a nice code size savings.
One new feature is an advanced debug menu which is accessible
by recompiling the code with AXP_EXTRA_DEBUG. It adds quite a
bit of code size and isn't useful other than for development
so it must be manually enabled by editing the source.
Change-Id: I30e17c1194c14823decd726a574ed14451d4cb2d
Diffstat (limited to 'firmware/target/mips/ingenic_x1000/shanlingq1')
-rw-r--r-- | firmware/target/mips/ingenic_x1000/shanlingq1/button-shanlingq1.c | 8 | ||||
-rw-r--r-- | firmware/target/mips/ingenic_x1000/shanlingq1/power-shanlingq1.c | 49 |
2 files changed, 34 insertions, 23 deletions
diff --git a/firmware/target/mips/ingenic_x1000/shanlingq1/button-shanlingq1.c b/firmware/target/mips/ingenic_x1000/shanlingq1/button-shanlingq1.c index 13b0cdd078..1976dde793 100644 --- a/firmware/target/mips/ingenic_x1000/shanlingq1/button-shanlingq1.c +++ b/firmware/target/mips/ingenic_x1000/shanlingq1/button-shanlingq1.c | |||
@@ -23,7 +23,7 @@ | |||
23 | #include "button.h" | 23 | #include "button.h" |
24 | #include "touchscreen.h" | 24 | #include "touchscreen.h" |
25 | #include "ft6x06.h" | 25 | #include "ft6x06.h" |
26 | #include "axp-pmu.h" | 26 | #include "axp192.h" |
27 | #include "kernel.h" | 27 | #include "kernel.h" |
28 | #include "backlight.h" | 28 | #include "backlight.h" |
29 | #include "powermgmt.h" | 29 | #include "powermgmt.h" |
@@ -57,7 +57,7 @@ static void hp_detect_init(void) | |||
57 | { | 57 | { |
58 | /* TODO: replace this copy paste cruft with an API in axp-pmu */ | 58 | /* TODO: replace this copy paste cruft with an API in axp-pmu */ |
59 | static struct timeout tmo; | 59 | static struct timeout tmo; |
60 | static const uint8_t gpio_reg = AXP192_REG_GPIOSTATE1; | 60 | static const uint8_t gpio_reg = AXP_REG_GPIOLEVEL1; |
61 | static i2c_descriptor desc = { | 61 | static i2c_descriptor desc = { |
62 | .slave_addr = AXP_PMU_ADDR, | 62 | .slave_addr = AXP_PMU_ADDR, |
63 | .bus_cond = I2C_START | I2C_STOP, | 63 | .bus_cond = I2C_START | I2C_STOP, |
@@ -72,10 +72,10 @@ static void hp_detect_init(void) | |||
72 | }; | 72 | }; |
73 | 73 | ||
74 | /* Headphone detect is wired to AXP192 GPIO: set it to input state */ | 74 | /* Headphone detect is wired to AXP192 GPIO: set it to input state */ |
75 | i2c_reg_write1(AXP_PMU_BUS, AXP_PMU_ADDR, AXP192_REG_GPIO1FUNCTION, 0x01); | 75 | axp_set_gpio_function(1, AXP_GPIO_INPUT); |
76 | 76 | ||
77 | /* Get an initial reading before startup */ | 77 | /* Get an initial reading before startup */ |
78 | int r = i2c_reg_read1(AXP_PMU_BUS, AXP_PMU_ADDR, gpio_reg); | 78 | int r = axp_read(gpio_reg); |
79 | if(r >= 0) | 79 | if(r >= 0) |
80 | hp_detect_reg = r; | 80 | hp_detect_reg = r; |
81 | 81 | ||
diff --git a/firmware/target/mips/ingenic_x1000/shanlingq1/power-shanlingq1.c b/firmware/target/mips/ingenic_x1000/shanlingq1/power-shanlingq1.c index 75f8031dd9..65d1bc163f 100644 --- a/firmware/target/mips/ingenic_x1000/shanlingq1/power-shanlingq1.c +++ b/firmware/target/mips/ingenic_x1000/shanlingq1/power-shanlingq1.c | |||
@@ -22,7 +22,7 @@ | |||
22 | #include "power.h" | 22 | #include "power.h" |
23 | #include "adc.h" | 23 | #include "adc.h" |
24 | #include "system.h" | 24 | #include "system.h" |
25 | #include "axp-pmu.h" | 25 | #include "axp192.h" |
26 | #ifdef HAVE_CW2015 | 26 | #ifdef HAVE_CW2015 |
27 | # include "cw2015.h" | 27 | # include "cw2015.h" |
28 | #endif | 28 | #endif |
@@ -73,24 +73,30 @@ const unsigned short percent_to_volt_charge[11] = | |||
73 | void power_init(void) | 73 | void power_init(void) |
74 | { | 74 | { |
75 | i2c_x1000_set_freq(AXP_PMU_BUS, I2C_FREQ_400K); | 75 | i2c_x1000_set_freq(AXP_PMU_BUS, I2C_FREQ_400K); |
76 | axp_init(); | ||
77 | #ifdef HAVE_CW2015 | 76 | #ifdef HAVE_CW2015 |
78 | cw2015_init(); | 77 | cw2015_init(); |
79 | #endif | 78 | #endif |
80 | 79 | ||
81 | /* Change supply voltage from the default of 1250 mV to 1200 mV, | 80 | /* Set DCDC2 to 1.2 V to match OF settings. */ |
82 | * this matches the original firmware's settings. Didn't observe | 81 | axp_set_supply_voltage(AXP_SUPPLY_DCDC2, 1200); |
83 | * any obviously bad behavior at 1250 mV, but better to be safe. */ | 82 | |
84 | axp_supply_set_voltage(AXP_SUPPLY_DCDC2, 1200); | 83 | /* Power on required supplies */ |
85 | 84 | axp_set_enabled_supplies( | |
86 | /* For now, just turn everything on... definitely the touchscreen | 85 | (1 << AXP_SUPPLY_DCDC1) | /* SD bus (3.3 V) */ |
87 | * is powered by one of the outputs */ | 86 | (1 << AXP_SUPPLY_DCDC2) | /* LCD (1.2 V) */ |
88 | i2c_reg_modify1(AXP_PMU_BUS, AXP_PMU_ADDR, | 87 | (1 << AXP_SUPPLY_DCDC3) | /* CPU (1.8 V) */ |
89 | AXP_REG_PWROUTPUTCTRL1, 0, 0x05, NULL); | 88 | (1 << AXP_SUPPLY_LDO2) | /* Touchscreen (3.3 V) */ |
90 | i2c_reg_modify1(AXP_PMU_BUS, AXP_PMU_ADDR, | 89 | (1 << AXP_SUPPLY_LDO3)); /* not sure (2.5 V) */ |
91 | AXP_REG_PWROUTPUTCTRL2, 0, 0x0f, NULL); | 90 | |
92 | i2c_reg_modify1(AXP_PMU_BUS, AXP_PMU_ADDR, | 91 | /* Enable required ADCs */ |
93 | AXP_REG_DCDCWORKINGMODE, 0, 0xc0, NULL); | 92 | axp_set_enabled_adcs( |
93 | (1 << AXP_ADC_BATTERY_VOLTAGE) | | ||
94 | (1 << AXP_ADC_CHARGE_CURRENT) | | ||
95 | (1 << AXP_ADC_DISCHARGE_CURRENT) | | ||
96 | (1 << AXP_ADC_VBUS_VOLTAGE) | | ||
97 | (1 << AXP_ADC_VBUS_CURRENT) | | ||
98 | (1 << AXP_ADC_INTERNAL_TEMP) | | ||
99 | (1 << AXP_ADC_APS_VOLTAGE)); | ||
94 | 100 | ||
95 | /* Delay to give power output time to stabilize */ | 101 | /* Delay to give power output time to stabilize */ |
96 | mdelay(20); | 102 | mdelay(20); |
@@ -111,23 +117,28 @@ void power_off(void) | |||
111 | 117 | ||
112 | bool charging_state(void) | 118 | bool charging_state(void) |
113 | { | 119 | { |
114 | return axp_battery_status() == AXP_BATT_CHARGING; | 120 | return axp_is_charging(); |
121 | } | ||
122 | |||
123 | unsigned int power_input_status(void) | ||
124 | { | ||
125 | return axp_power_input_status(); | ||
115 | } | 126 | } |
116 | 127 | ||
117 | int _battery_voltage(void) | 128 | int _battery_voltage(void) |
118 | { | 129 | { |
119 | /* CW2015 can also read battery voltage, but the AXP consistently | 130 | /* CW2015 can also read battery voltage, but the AXP consistently |
120 | * reads ~20-30 mV higher so I suspect it's the "real" voltage. */ | 131 | * reads ~20-30 mV higher so I suspect it's the "real" voltage. */ |
121 | return axp_adc_read(ADC_BATTERY_VOLTAGE); | 132 | return axp_read_adc(AXP_ADC_BATTERY_VOLTAGE); |
122 | } | 133 | } |
123 | 134 | ||
124 | #if CONFIG_BATTERY_MEASURE & CURRENT_MEASURE | 135 | #if CONFIG_BATTERY_MEASURE & CURRENT_MEASURE |
125 | int _battery_current(void) | 136 | int _battery_current(void) |
126 | { | 137 | { |
127 | if(charging_state()) | 138 | if(charging_state()) |
128 | return axp_adc_read(ADC_CHARGE_CURRENT); | 139 | return axp_read_adc(AXP_ADC_CHARGE_CURRENT); |
129 | else | 140 | else |
130 | return axp_adc_read(ADC_DISCHARGE_CURRENT); | 141 | return axp_read_adc(AXP_ADC_DISCHARGE_CURRENT); |
131 | } | 142 | } |
132 | #endif | 143 | #endif |
133 | 144 | ||