summaryrefslogtreecommitdiffstats
path: root/firmware/target
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/target
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/target')
-rw-r--r--firmware/target/mips/ingenic_x1000/erosqnative/button-erosqnative.c10
-rw-r--r--firmware/target/mips/ingenic_x1000/erosqnative/power-erosqnative.c82
-rw-r--r--firmware/target/mips/ingenic_x1000/fiiom3k/button-fiiom3k.c8
-rw-r--r--firmware/target/mips/ingenic_x1000/fiiom3k/power-fiiom3k.c80
-rw-r--r--firmware/target/mips/ingenic_x1000/shanlingq1/button-shanlingq1.c8
-rw-r--r--firmware/target/mips/ingenic_x1000/shanlingq1/power-shanlingq1.c70
6 files changed, 87 insertions, 171 deletions
diff --git a/firmware/target/mips/ingenic_x1000/erosqnative/button-erosqnative.c b/firmware/target/mips/ingenic_x1000/erosqnative/button-erosqnative.c
index 64041795a3..1583db175a 100644
--- a/firmware/target/mips/ingenic_x1000/erosqnative/button-erosqnative.c
+++ b/firmware/target/mips/ingenic_x1000/erosqnative/button-erosqnative.c
@@ -24,7 +24,7 @@
#include "backlight.h"
#include "powermgmt.h"
#include "panic.h"
-#include "axp192.h"
+#include "axp-pmu.h"
#include "gpio-x1000.h"
#include "irq-x1000.h"
#include "i2c-x1000.h"
@@ -89,7 +89,7 @@ static int hp_detect_tmo_cb(struct timeout* tmo)
static void hp_detect_init(void)
{
static struct timeout tmo;
- static const uint8_t gpio_reg = AXP_REG_GPIOLEVEL1;
+ static const uint8_t gpio_reg = AXP192_REG_GPIOSTATE1;
static i2c_descriptor desc = {
.slave_addr = AXP_PMU_ADDR,
.bus_cond = I2C_START | I2C_STOP,
@@ -105,11 +105,11 @@ static void hp_detect_init(void)
/* Headphone and LO detects are wired to AXP192 GPIOs 0 and 1,
* set them to inputs. */
- axp_set_gpio_function(0, AXP_GPIO_INPUT); /* HP detect */
- axp_set_gpio_function(1, AXP_GPIO_INPUT); /* LO detect */
+ i2c_reg_write1(AXP_PMU_BUS, AXP_PMU_ADDR, AXP192_REG_GPIO0FUNCTION, 0x01); /* HP detect */
+ i2c_reg_write1(AXP_PMU_BUS, AXP_PMU_ADDR, AXP192_REG_GPIO1FUNCTION, 0x01); /* LO detect */
/* Get an initial reading before startup */
- int r = axp_read(gpio_reg);
+ int r = i2c_reg_read1(AXP_PMU_BUS, AXP_PMU_ADDR, gpio_reg);
if(r >= 0)
{
hp_detect_reg = r;
diff --git a/firmware/target/mips/ingenic_x1000/erosqnative/power-erosqnative.c b/firmware/target/mips/ingenic_x1000/erosqnative/power-erosqnative.c
index 9cf64cee01..a1a4d2c2b2 100644
--- a/firmware/target/mips/ingenic_x1000/erosqnative/power-erosqnative.c
+++ b/firmware/target/mips/ingenic_x1000/erosqnative/power-erosqnative.c
@@ -28,7 +28,7 @@
#ifdef HAVE_USB_CHARGING_ENABLE
# include "usb_core.h"
#endif
-#include "axp192.h"
+#include "axp-pmu.h"
#include "i2c-x1000.h"
const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] =
@@ -56,35 +56,27 @@ const unsigned short percent_to_volt_charge[11] =
void power_init(void)
{
- /* Configure I2C bus */
- i2c_x1000_set_freq(AXP_PMU_BUS, I2C_FREQ_400K);
-
- /* FIXME: Copy paste from M3K. Probably not necessary */
- axp_modify(AXP_REG_DCDCMODE, 0, 0xc0);
-
- /* Power on required supplies
- * TODO: This should be checked, though likely all but EXTEN are needed */
- axp_set_enabled_supplies(
- (1 << AXP_SUPPLY_EXTEN) |
- (1 << AXP_SUPPLY_DCDC1) |
- (1 << AXP_SUPPLY_DCDC2) |
- (1 << AXP_SUPPLY_DCDC3) |
- (1 << AXP_SUPPLY_LDO2) |
- (1 << AXP_SUPPLY_LDO3));
-
- /* Enable required ADCs */
- axp_set_enabled_adcs(
- (1 << AXP_ADC_BATTERY_VOLTAGE) |
- (1 << AXP_ADC_CHARGE_CURRENT) |
- (1 << AXP_ADC_DISCHARGE_CURRENT) |
- (1 << AXP_ADC_VBUS_VOLTAGE) |
- (1 << AXP_ADC_VBUS_CURRENT) |
- (1 << AXP_ADC_INTERNAL_TEMP) |
- (1 << AXP_ADC_APS_VOLTAGE));
-
- /* Configure USB charging */
- axp_set_vhold_level(4400);
- usb_charging_maxcurrent_change(100);
+ /* Initialize driver */
+ i2c_x1000_set_freq(2, I2C_FREQ_400K);
+ axp_init();
+
+ /* Set lowest sample rate */
+ axp_adc_set_rate(AXP_ADC_RATE_25HZ);
+
+ /* Ensure battery voltage ADC is enabled */
+ int bits = axp_adc_get_enabled();
+ bits |= (1 << ADC_BATTERY_VOLTAGE);
+ axp_adc_set_enabled(bits);
+
+ /* Turn on all power outputs */
+ i2c_reg_modify1(AXP_PMU_BUS, AXP_PMU_ADDR,
+ AXP_REG_PWROUTPUTCTRL2, 0, 0x5f, NULL);
+ i2c_reg_modify1(AXP_PMU_BUS, AXP_PMU_ADDR,
+ AXP_REG_DCDCWORKINGMODE, 0, 0xc0, NULL);
+
+ /* Set the default charging current. This is the same as the
+ * OF's setting, although it's not strictly within the USB spec. */
+ axp_set_charge_current(780);
/* Delay to give power outputs time to stabilize.
* With the power thread delay, this can apparently go as low as 50,
@@ -96,22 +88,7 @@ void power_init(void)
#ifdef HAVE_USB_CHARGING_ENABLE
void usb_charging_maxcurrent_change(int maxcurrent)
{
- int vbus_limit;
- int charge_current;
-
- /* Note that the charge current setting is a maximum: it will be
- * reduced dynamically by the AXP192 so the combined load is less
- * than the set VBUS current limit. */
- if(maxcurrent <= 100) {
- vbus_limit = AXP_VBUS_LIMIT_500mA;
- charge_current = 100;
- } else {
- vbus_limit = AXP_VBUS_LIMIT_500mA;
- charge_current = 550;
- }
-
- axp_set_vbus_limit(vbus_limit);
- axp_set_charge_current(charge_current);
+ axp_set_charge_current(maxcurrent);
}
#endif
@@ -127,25 +104,20 @@ void power_off(void)
bool charging_state(void)
{
- return axp_is_charging();
-}
-
-unsigned int power_input_status(void)
-{
- return axp_power_input_status();
+ return axp_battery_status() == AXP_BATT_CHARGING;
}
int _battery_voltage(void)
{
- return axp_read_adc(AXP_ADC_BATTERY_VOLTAGE);
+ return axp_adc_read(ADC_BATTERY_VOLTAGE);
}
#if CONFIG_BATTERY_MEASURE & CURRENT_MEASURE
int _battery_current(void)
{
if(charging_state())
- return axp_read_adc(AXP_ADC_CHARGE_CURRENT);
+ return axp_adc_read(ADC_CHARGE_CURRENT);
else
- return axp_read_adc(AXP_ADC_DISCHARGE_CURRENT);
+ return axp_adc_read(ADC_DISCHARGE_CURRENT);
}
#endif
diff --git a/firmware/target/mips/ingenic_x1000/fiiom3k/button-fiiom3k.c b/firmware/target/mips/ingenic_x1000/fiiom3k/button-fiiom3k.c
index 0ef7bd2f64..24daf2ef69 100644
--- a/firmware/target/mips/ingenic_x1000/fiiom3k/button-fiiom3k.c
+++ b/firmware/target/mips/ingenic_x1000/fiiom3k/button-fiiom3k.c
@@ -24,7 +24,7 @@
#include "backlight.h"
#include "powermgmt.h"
#include "panic.h"
-#include "axp192.h"
+#include "axp-pmu.h"
#include "ft6x06.h"
#include "gpio-x1000.h"
#include "irq-x1000.h"
@@ -393,7 +393,7 @@ static int hp_detect_tmo_cb(struct timeout* tmo)
static void hp_detect_init(void)
{
static struct timeout tmo;
- static const uint8_t gpio_reg = AXP_REG_GPIOLEVEL1;
+ static const uint8_t gpio_reg = AXP192_REG_GPIOSTATE1;
static i2c_descriptor desc = {
.slave_addr = AXP_PMU_ADDR,
.bus_cond = I2C_START | I2C_STOP,
@@ -408,10 +408,10 @@ static void hp_detect_init(void)
};
/* Headphone detect is wired to AXP192 GPIO: set it to input state */
- axp_set_gpio_function(2, AXP_GPIO_INPUT);
+ i2c_reg_write1(AXP_PMU_BUS, AXP_PMU_ADDR, AXP192_REG_GPIO2FUNCTION, 0x01);
/* Get an initial reading before startup */
- int r = axp_read(gpio_reg);
+ int r = i2c_reg_read1(AXP_PMU_BUS, AXP_PMU_ADDR, gpio_reg);
if(r >= 0)
hp_detect_reg = r;
diff --git a/firmware/target/mips/ingenic_x1000/fiiom3k/power-fiiom3k.c b/firmware/target/mips/ingenic_x1000/fiiom3k/power-fiiom3k.c
index b20bbd9e8c..2d28ad0975 100644
--- a/firmware/target/mips/ingenic_x1000/fiiom3k/power-fiiom3k.c
+++ b/firmware/target/mips/ingenic_x1000/fiiom3k/power-fiiom3k.c
@@ -26,7 +26,7 @@
#ifdef HAVE_USB_CHARGING_ENABLE
# include "usb_core.h"
#endif
-#include "axp192.h"
+#include "axp-pmu.h"
#include "i2c-x1000.h"
const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] =
@@ -54,33 +54,27 @@ const unsigned short percent_to_volt_charge[11] =
void power_init(void)
{
- /* Configure I2C bus */
- i2c_x1000_set_freq(AXP_PMU_BUS, I2C_FREQ_400K);
-
- /* Set DCDC1 and DCDC2 to fixed PWM mode to match OF settings. */
- axp_modify(AXP_REG_DCDCMODE, 0, 0x0c);
-
- /* Power on required supplies */
- axp_set_enabled_supplies(
- (1 << AXP_SUPPLY_DCDC1) | /* not sure (3.3 V) */
- (1 << AXP_SUPPLY_DCDC2) | /* not sure (1.4 V) */
- (1 << AXP_SUPPLY_DCDC3) | /* for CPU (1.8 V) */
- (1 << AXP_SUPPLY_LDO2) | /* LCD controller (3.3 V) */
- (1 << AXP_SUPPLY_LDO3)); /* SD bus (3.3 V) */
-
- /* Enable required ADCs */
- axp_set_enabled_adcs(
- (1 << AXP_ADC_BATTERY_VOLTAGE) |
- (1 << AXP_ADC_CHARGE_CURRENT) |
- (1 << AXP_ADC_DISCHARGE_CURRENT) |
- (1 << AXP_ADC_VBUS_VOLTAGE) |
- (1 << AXP_ADC_VBUS_CURRENT) |
- (1 << AXP_ADC_INTERNAL_TEMP) |
- (1 << AXP_ADC_APS_VOLTAGE));
-
- /* Configure USB charging */
- axp_set_vhold_level(4400);
- usb_charging_maxcurrent_change(100);
+ /* Initialize driver */
+ i2c_x1000_set_freq(2, I2C_FREQ_400K);
+ axp_init();
+
+ /* Set lowest sample rate */
+ axp_adc_set_rate(AXP_ADC_RATE_25HZ);
+
+ /* Ensure battery voltage ADC is enabled */
+ int bits = axp_adc_get_enabled();
+ bits |= (1 << ADC_BATTERY_VOLTAGE);
+ axp_adc_set_enabled(bits);
+
+ /* Turn on all power outputs */
+ i2c_reg_modify1(AXP_PMU_BUS, AXP_PMU_ADDR,
+ AXP_REG_PWROUTPUTCTRL2, 0, 0x5f, NULL);
+ i2c_reg_modify1(AXP_PMU_BUS, AXP_PMU_ADDR,
+ AXP_REG_DCDCWORKINGMODE, 0, 0xc0, NULL);
+
+ /* Set the default charging current. This is the same as the
+ * OF's setting, although it's not strictly within the USB spec. */
+ axp_set_charge_current(780);
/* Short delay to give power outputs time to stabilize */
mdelay(200);
@@ -89,22 +83,7 @@ void power_init(void)
#ifdef HAVE_USB_CHARGING_ENABLE
void usb_charging_maxcurrent_change(int maxcurrent)
{
- int vbus_limit;
- int charge_current;
-
- /* Note that the charge current setting is a maximum: it will be
- * reduced dynamically by the AXP192 so the combined load is less
- * than the set VBUS current limit. */
- if(maxcurrent <= 100) {
- vbus_limit = AXP_VBUS_LIMIT_500mA;
- charge_current = 100;
- } else {
- vbus_limit = AXP_VBUS_LIMIT_500mA;
- charge_current = 550;
- }
-
- axp_set_vbus_limit(vbus_limit);
- axp_set_charge_current(charge_current);
+ axp_set_charge_current(maxcurrent);
}
#endif
@@ -120,25 +99,20 @@ void power_off(void)
bool charging_state(void)
{
- return axp_is_charging();
-}
-
-unsigned int power_input_status(void)
-{
- return axp_power_input_status();
+ return axp_battery_status() == AXP_BATT_CHARGING;
}
int _battery_voltage(void)
{
- return axp_read_adc(AXP_ADC_BATTERY_VOLTAGE);
+ return axp_adc_read(ADC_BATTERY_VOLTAGE);
}
#if CONFIG_BATTERY_MEASURE & CURRENT_MEASURE
int _battery_current(void)
{
if(charging_state())
- return axp_read_adc(AXP_ADC_CHARGE_CURRENT);
+ return axp_adc_read(ADC_CHARGE_CURRENT);
else
- return axp_read_adc(AXP_ADC_DISCHARGE_CURRENT);
+ return axp_adc_read(ADC_DISCHARGE_CURRENT);
}
#endif
diff --git a/firmware/target/mips/ingenic_x1000/shanlingq1/button-shanlingq1.c b/firmware/target/mips/ingenic_x1000/shanlingq1/button-shanlingq1.c
index 1976dde793..13b0cdd078 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 @@
#include "button.h"
#include "touchscreen.h"
#include "ft6x06.h"
-#include "axp192.h"
+#include "axp-pmu.h"
#include "kernel.h"
#include "backlight.h"
#include "powermgmt.h"
@@ -57,7 +57,7 @@ static void hp_detect_init(void)
{
/* TODO: replace this copy paste cruft with an API in axp-pmu */
static struct timeout tmo;
- static const uint8_t gpio_reg = AXP_REG_GPIOLEVEL1;
+ static const uint8_t gpio_reg = AXP192_REG_GPIOSTATE1;
static i2c_descriptor desc = {
.slave_addr = AXP_PMU_ADDR,
.bus_cond = I2C_START | I2C_STOP,
@@ -72,10 +72,10 @@ static void hp_detect_init(void)
};
/* Headphone detect is wired to AXP192 GPIO: set it to input state */
- axp_set_gpio_function(1, AXP_GPIO_INPUT);
+ i2c_reg_write1(AXP_PMU_BUS, AXP_PMU_ADDR, AXP192_REG_GPIO1FUNCTION, 0x01);
/* Get an initial reading before startup */
- int r = axp_read(gpio_reg);
+ int r = i2c_reg_read1(AXP_PMU_BUS, AXP_PMU_ADDR, gpio_reg);
if(r >= 0)
hp_detect_reg = r;
diff --git a/firmware/target/mips/ingenic_x1000/shanlingq1/power-shanlingq1.c b/firmware/target/mips/ingenic_x1000/shanlingq1/power-shanlingq1.c
index 86ee84c37a..75f8031dd9 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 @@
#include "power.h"
#include "adc.h"
#include "system.h"
-#include "axp192.h"
+#include "axp-pmu.h"
#ifdef HAVE_CW2015
# include "cw2015.h"
#endif
@@ -73,34 +73,24 @@ const unsigned short percent_to_volt_charge[11] =
void power_init(void)
{
i2c_x1000_set_freq(AXP_PMU_BUS, I2C_FREQ_400K);
+ axp_init();
#ifdef HAVE_CW2015
cw2015_init();
#endif
- /* Set DCDC2 to 1.2 V to match OF settings. */
- axp_set_supply_voltage(AXP_SUPPLY_DCDC2, 1200);
-
- /* Power on required supplies */
- axp_set_enabled_supplies(
- (1 << AXP_SUPPLY_DCDC1) | /* SD bus (3.3 V) */
- (1 << AXP_SUPPLY_DCDC2) | /* LCD (1.2 V) */
- (1 << AXP_SUPPLY_DCDC3) | /* CPU (1.8 V) */
- (1 << AXP_SUPPLY_LDO2) | /* Touchscreen (3.3 V) */
- (1 << AXP_SUPPLY_LDO3)); /* USB analog (2.5 V) */
-
- /* Enable required ADCs */
- axp_set_enabled_adcs(
- (1 << AXP_ADC_BATTERY_VOLTAGE) |
- (1 << AXP_ADC_CHARGE_CURRENT) |
- (1 << AXP_ADC_DISCHARGE_CURRENT) |
- (1 << AXP_ADC_VBUS_VOLTAGE) |
- (1 << AXP_ADC_VBUS_CURRENT) |
- (1 << AXP_ADC_INTERNAL_TEMP) |
- (1 << AXP_ADC_APS_VOLTAGE));
-
- /* Configure USB charging */
- axp_set_vhold_level(4400);
- usb_charging_maxcurrent_change(100);
+ /* Change supply voltage from the default of 1250 mV to 1200 mV,
+ * this matches the original firmware's settings. Didn't observe
+ * any obviously bad behavior at 1250 mV, but better to be safe. */
+ axp_supply_set_voltage(AXP_SUPPLY_DCDC2, 1200);
+
+ /* For now, just turn everything on... definitely the touchscreen
+ * is powered by one of the outputs */
+ i2c_reg_modify1(AXP_PMU_BUS, AXP_PMU_ADDR,
+ AXP_REG_PWROUTPUTCTRL1, 0, 0x05, NULL);
+ i2c_reg_modify1(AXP_PMU_BUS, AXP_PMU_ADDR,
+ AXP_REG_PWROUTPUTCTRL2, 0, 0x0f, NULL);
+ i2c_reg_modify1(AXP_PMU_BUS, AXP_PMU_ADDR,
+ AXP_REG_DCDCWORKINGMODE, 0, 0xc0, NULL);
/* Delay to give power output time to stabilize */
mdelay(20);
@@ -109,22 +99,7 @@ void power_init(void)
#ifdef HAVE_USB_CHARGING_ENABLE
void usb_charging_maxcurrent_change(int maxcurrent)
{
- int vbus_limit;
- int charge_current;
-
- /* Note that the charge current setting is a maximum: it will be
- * reduced dynamically by the AXP192 so the combined load is less
- * than the set VBUS current limit. */
- if(maxcurrent <= 100) {
- vbus_limit = AXP_VBUS_LIMIT_500mA;
- charge_current = 100;
- } else {
- vbus_limit = AXP_VBUS_LIMIT_500mA;
- charge_current = 550;
- }
-
- axp_set_vbus_limit(vbus_limit);
- axp_set_charge_current(charge_current);
+ axp_set_charge_current(maxcurrent);
}
#endif
@@ -136,28 +111,23 @@ void power_off(void)
bool charging_state(void)
{
- return axp_is_charging();
-}
-
-unsigned int power_input_status(void)
-{
- return axp_power_input_status();
+ return axp_battery_status() == AXP_BATT_CHARGING;
}
int _battery_voltage(void)
{
/* CW2015 can also read battery voltage, but the AXP consistently
* reads ~20-30 mV higher so I suspect it's the "real" voltage. */
- return axp_read_adc(AXP_ADC_BATTERY_VOLTAGE);
+ return axp_adc_read(ADC_BATTERY_VOLTAGE);
}
#if CONFIG_BATTERY_MEASURE & CURRENT_MEASURE
int _battery_current(void)
{
if(charging_state())
- return axp_read_adc(AXP_ADC_CHARGE_CURRENT);
+ return axp_adc_read(ADC_CHARGE_CURRENT);
else
- return axp_read_adc(AXP_ADC_DISCHARGE_CURRENT);
+ return axp_adc_read(ADC_DISCHARGE_CURRENT);
}
#endif