summaryrefslogtreecommitdiffstats
path: root/firmware/target/mips/ingenic_x1000/fiiom3k/power-fiiom3k.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/mips/ingenic_x1000/fiiom3k/power-fiiom3k.c')
-rw-r--r--firmware/target/mips/ingenic_x1000/fiiom3k/power-fiiom3k.c80
1 files changed, 27 insertions, 53 deletions
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