diff options
Diffstat (limited to 'firmware/target/mips/ingenic_x1000/erosqnative/power-erosqnative.c')
-rw-r--r-- | firmware/target/mips/ingenic_x1000/erosqnative/power-erosqnative.c | 60 |
1 files changed, 34 insertions, 26 deletions
diff --git a/firmware/target/mips/ingenic_x1000/erosqnative/power-erosqnative.c b/firmware/target/mips/ingenic_x1000/erosqnative/power-erosqnative.c index a1a4d2c2b2..17cdb4d645 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 @@ | |||
28 | #ifdef HAVE_USB_CHARGING_ENABLE | 28 | #ifdef HAVE_USB_CHARGING_ENABLE |
29 | # include "usb_core.h" | 29 | # include "usb_core.h" |
30 | #endif | 30 | #endif |
31 | #include "axp-pmu.h" | 31 | #include "axp192.h" |
32 | #include "i2c-x1000.h" | 32 | #include "i2c-x1000.h" |
33 | 33 | ||
34 | const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] = | 34 | const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] = |
@@ -56,27 +56,30 @@ const unsigned short percent_to_volt_charge[11] = | |||
56 | 56 | ||
57 | void power_init(void) | 57 | void power_init(void) |
58 | { | 58 | { |
59 | /* Initialize driver */ | 59 | /* Configure I2C bus */ |
60 | i2c_x1000_set_freq(2, I2C_FREQ_400K); | 60 | i2c_x1000_set_freq(AXP_PMU_BUS, I2C_FREQ_400K); |
61 | axp_init(); | 61 | |
62 | 62 | /* FIXME: Copy paste from M3K. Probably not necessary */ | |
63 | /* Set lowest sample rate */ | 63 | axp_modify(AXP_REG_DCDCMODE, 0, 0xc0); |
64 | axp_adc_set_rate(AXP_ADC_RATE_25HZ); | 64 | |
65 | 65 | /* Power on required supplies */ | |
66 | /* Ensure battery voltage ADC is enabled */ | 66 | axp_set_enabled_supplies( |
67 | int bits = axp_adc_get_enabled(); | 67 | (1 << AXP_SUPPLY_EXTEN) | |
68 | bits |= (1 << ADC_BATTERY_VOLTAGE); | 68 | (1 << AXP_SUPPLY_DCDC1) | |
69 | axp_adc_set_enabled(bits); | 69 | (1 << AXP_SUPPLY_DCDC2) | |
70 | 70 | (1 << AXP_SUPPLY_DCDC3) | | |
71 | /* Turn on all power outputs */ | 71 | (1 << AXP_SUPPLY_LDO2) | |
72 | i2c_reg_modify1(AXP_PMU_BUS, AXP_PMU_ADDR, | 72 | (1 << AXP_SUPPLY_LDO3)); |
73 | AXP_REG_PWROUTPUTCTRL2, 0, 0x5f, NULL); | 73 | |
74 | i2c_reg_modify1(AXP_PMU_BUS, AXP_PMU_ADDR, | 74 | /* Enable required ADCs */ |
75 | AXP_REG_DCDCWORKINGMODE, 0, 0xc0, NULL); | 75 | axp_set_enabled_adcs( |
76 | 76 | (1 << AXP_ADC_BATTERY_VOLTAGE) | | |
77 | /* Set the default charging current. This is the same as the | 77 | (1 << AXP_ADC_CHARGE_CURRENT) | |
78 | * OF's setting, although it's not strictly within the USB spec. */ | 78 | (1 << AXP_ADC_DISCHARGE_CURRENT) | |
79 | axp_set_charge_current(780); | 79 | (1 << AXP_ADC_VBUS_VOLTAGE) | |
80 | (1 << AXP_ADC_VBUS_CURRENT) | | ||
81 | (1 << AXP_ADC_INTERNAL_TEMP) | | ||
82 | (1 << AXP_ADC_APS_VOLTAGE)); | ||
80 | 83 | ||
81 | /* Delay to give power outputs time to stabilize. | 84 | /* Delay to give power outputs time to stabilize. |
82 | * With the power thread delay, this can apparently go as low as 50, | 85 | * With the power thread delay, this can apparently go as low as 50, |
@@ -104,20 +107,25 @@ void power_off(void) | |||
104 | 107 | ||
105 | bool charging_state(void) | 108 | bool charging_state(void) |
106 | { | 109 | { |
107 | return axp_battery_status() == AXP_BATT_CHARGING; | 110 | return axp_is_charging(); |
111 | } | ||
112 | |||
113 | unsigned int power_input_status(void) | ||
114 | { | ||
115 | return axp_power_input_status(); | ||
108 | } | 116 | } |
109 | 117 | ||
110 | int _battery_voltage(void) | 118 | int _battery_voltage(void) |
111 | { | 119 | { |
112 | return axp_adc_read(ADC_BATTERY_VOLTAGE); | 120 | return axp_read_adc(AXP_ADC_BATTERY_VOLTAGE); |
113 | } | 121 | } |
114 | 122 | ||
115 | #if CONFIG_BATTERY_MEASURE & CURRENT_MEASURE | 123 | #if CONFIG_BATTERY_MEASURE & CURRENT_MEASURE |
116 | int _battery_current(void) | 124 | int _battery_current(void) |
117 | { | 125 | { |
118 | if(charging_state()) | 126 | if(charging_state()) |
119 | return axp_adc_read(ADC_CHARGE_CURRENT); | 127 | return axp_read_adc(AXP_ADC_CHARGE_CURRENT); |
120 | else | 128 | else |
121 | return axp_adc_read(ADC_DISCHARGE_CURRENT); | 129 | return axp_read_adc(AXP_ADC_DISCHARGE_CURRENT); |
122 | } | 130 | } |
123 | #endif | 131 | #endif |