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 | 82 |
1 files changed, 27 insertions, 55 deletions
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 @@ | |||
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 "axp192.h" | 31 | #include "axp-pmu.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,35 +56,27 @@ const unsigned short percent_to_volt_charge[11] = | |||
56 | 56 | ||
57 | void power_init(void) | 57 | void power_init(void) |
58 | { | 58 | { |
59 | /* Configure I2C bus */ | 59 | /* Initialize driver */ |
60 | i2c_x1000_set_freq(AXP_PMU_BUS, I2C_FREQ_400K); | 60 | i2c_x1000_set_freq(2, I2C_FREQ_400K); |
61 | 61 | axp_init(); | |
62 | /* FIXME: Copy paste from M3K. Probably not necessary */ | 62 | |
63 | axp_modify(AXP_REG_DCDCMODE, 0, 0xc0); | 63 | /* Set lowest sample rate */ |
64 | 64 | axp_adc_set_rate(AXP_ADC_RATE_25HZ); | |
65 | /* Power on required supplies | 65 | |
66 | * TODO: This should be checked, though likely all but EXTEN are needed */ | 66 | /* Ensure battery voltage ADC is enabled */ |
67 | axp_set_enabled_supplies( | 67 | int bits = axp_adc_get_enabled(); |
68 | (1 << AXP_SUPPLY_EXTEN) | | 68 | bits |= (1 << ADC_BATTERY_VOLTAGE); |
69 | (1 << AXP_SUPPLY_DCDC1) | | 69 | axp_adc_set_enabled(bits); |
70 | (1 << AXP_SUPPLY_DCDC2) | | 70 | |
71 | (1 << AXP_SUPPLY_DCDC3) | | 71 | /* Turn on all power outputs */ |
72 | (1 << AXP_SUPPLY_LDO2) | | 72 | i2c_reg_modify1(AXP_PMU_BUS, AXP_PMU_ADDR, |
73 | (1 << AXP_SUPPLY_LDO3)); | 73 | AXP_REG_PWROUTPUTCTRL2, 0, 0x5f, NULL); |
74 | 74 | i2c_reg_modify1(AXP_PMU_BUS, AXP_PMU_ADDR, | |
75 | /* Enable required ADCs */ | 75 | AXP_REG_DCDCWORKINGMODE, 0, 0xc0, NULL); |
76 | axp_set_enabled_adcs( | 76 | |
77 | (1 << AXP_ADC_BATTERY_VOLTAGE) | | 77 | /* Set the default charging current. This is the same as the |
78 | (1 << AXP_ADC_CHARGE_CURRENT) | | 78 | * OF's setting, although it's not strictly within the USB spec. */ |
79 | (1 << AXP_ADC_DISCHARGE_CURRENT) | | 79 | axp_set_charge_current(780); |
80 | (1 << AXP_ADC_VBUS_VOLTAGE) | | ||
81 | (1 << AXP_ADC_VBUS_CURRENT) | | ||
82 | (1 << AXP_ADC_INTERNAL_TEMP) | | ||
83 | (1 << AXP_ADC_APS_VOLTAGE)); | ||
84 | |||
85 | /* Configure USB charging */ | ||
86 | axp_set_vhold_level(4400); | ||
87 | usb_charging_maxcurrent_change(100); | ||
88 | 80 | ||
89 | /* Delay to give power outputs time to stabilize. | 81 | /* Delay to give power outputs time to stabilize. |
90 | * With the power thread delay, this can apparently go as low as 50, | 82 | * With the power thread delay, this can apparently go as low as 50, |
@@ -96,22 +88,7 @@ void power_init(void) | |||
96 | #ifdef HAVE_USB_CHARGING_ENABLE | 88 | #ifdef HAVE_USB_CHARGING_ENABLE |
97 | void usb_charging_maxcurrent_change(int maxcurrent) | 89 | void usb_charging_maxcurrent_change(int maxcurrent) |
98 | { | 90 | { |
99 | int vbus_limit; | 91 | axp_set_charge_current(maxcurrent); |
100 | int charge_current; | ||
101 | |||
102 | /* Note that the charge current setting is a maximum: it will be | ||
103 | * reduced dynamically by the AXP192 so the combined load is less | ||
104 | * than the set VBUS current limit. */ | ||
105 | if(maxcurrent <= 100) { | ||
106 | vbus_limit = AXP_VBUS_LIMIT_500mA; | ||
107 | charge_current = 100; | ||
108 | } else { | ||
109 | vbus_limit = AXP_VBUS_LIMIT_500mA; | ||
110 | charge_current = 550; | ||
111 | } | ||
112 | |||
113 | axp_set_vbus_limit(vbus_limit); | ||
114 | axp_set_charge_current(charge_current); | ||
115 | } | 92 | } |
116 | #endif | 93 | #endif |
117 | 94 | ||
@@ -127,25 +104,20 @@ void power_off(void) | |||
127 | 104 | ||
128 | bool charging_state(void) | 105 | bool charging_state(void) |
129 | { | 106 | { |
130 | return axp_is_charging(); | 107 | return axp_battery_status() == AXP_BATT_CHARGING; |
131 | } | ||
132 | |||
133 | unsigned int power_input_status(void) | ||
134 | { | ||
135 | return axp_power_input_status(); | ||
136 | } | 108 | } |
137 | 109 | ||
138 | int _battery_voltage(void) | 110 | int _battery_voltage(void) |
139 | { | 111 | { |
140 | return axp_read_adc(AXP_ADC_BATTERY_VOLTAGE); | 112 | return axp_adc_read(ADC_BATTERY_VOLTAGE); |
141 | } | 113 | } |
142 | 114 | ||
143 | #if CONFIG_BATTERY_MEASURE & CURRENT_MEASURE | 115 | #if CONFIG_BATTERY_MEASURE & CURRENT_MEASURE |
144 | int _battery_current(void) | 116 | int _battery_current(void) |
145 | { | 117 | { |
146 | if(charging_state()) | 118 | if(charging_state()) |
147 | return axp_read_adc(AXP_ADC_CHARGE_CURRENT); | 119 | return axp_adc_read(ADC_CHARGE_CURRENT); |
148 | else | 120 | else |
149 | return axp_read_adc(AXP_ADC_DISCHARGE_CURRENT); | 121 | return axp_adc_read(ADC_DISCHARGE_CURRENT); |
150 | } | 122 | } |
151 | #endif | 123 | #endif |