diff options
Diffstat (limited to 'firmware/target/mips/ingenic_x1000/fiiom3k/power-fiiom3k.c')
-rw-r--r-- | firmware/target/mips/ingenic_x1000/fiiom3k/power-fiiom3k.c | 59 |
1 files changed, 33 insertions, 26 deletions
diff --git a/firmware/target/mips/ingenic_x1000/fiiom3k/power-fiiom3k.c b/firmware/target/mips/ingenic_x1000/fiiom3k/power-fiiom3k.c index 2d28ad0975..53451ffa6c 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 @@ | |||
26 | #ifdef HAVE_USB_CHARGING_ENABLE | 26 | #ifdef HAVE_USB_CHARGING_ENABLE |
27 | # include "usb_core.h" | 27 | # include "usb_core.h" |
28 | #endif | 28 | #endif |
29 | #include "axp-pmu.h" | 29 | #include "axp192.h" |
30 | #include "i2c-x1000.h" | 30 | #include "i2c-x1000.h" |
31 | 31 | ||
32 | const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] = | 32 | const unsigned short battery_level_dangerous[BATTERY_TYPES_COUNT] = |
@@ -54,27 +54,29 @@ const unsigned short percent_to_volt_charge[11] = | |||
54 | 54 | ||
55 | void power_init(void) | 55 | void power_init(void) |
56 | { | 56 | { |
57 | /* Initialize driver */ | 57 | /* Configure I2C bus */ |
58 | i2c_x1000_set_freq(2, I2C_FREQ_400K); | 58 | i2c_x1000_set_freq(AXP_PMU_BUS, I2C_FREQ_400K); |
59 | axp_init(); | 59 | |
60 | 60 | /* Set DCDC1 and DCDC2 to fixed PWM mode to match OF settings. */ | |
61 | /* Set lowest sample rate */ | 61 | axp_modify(AXP_REG_DCDCMODE, 0, 0x0c); |
62 | axp_adc_set_rate(AXP_ADC_RATE_25HZ); | 62 | |
63 | 63 | /* Power on required supplies */ | |
64 | /* Ensure battery voltage ADC is enabled */ | 64 | axp_set_enabled_supplies( |
65 | int bits = axp_adc_get_enabled(); | 65 | (1 << AXP_SUPPLY_DCDC1) | /* not sure (3.3 V) */ |
66 | bits |= (1 << ADC_BATTERY_VOLTAGE); | 66 | (1 << AXP_SUPPLY_DCDC2) | /* not sure (1.4 V) */ |
67 | axp_adc_set_enabled(bits); | 67 | (1 << AXP_SUPPLY_DCDC3) | /* for CPU (1.8 V) */ |
68 | 68 | (1 << AXP_SUPPLY_LDO2) | /* LCD controller (3.3 V) */ | |
69 | /* Turn on all power outputs */ | 69 | (1 << AXP_SUPPLY_LDO3)); /* SD bus (3.3 V) */ |
70 | i2c_reg_modify1(AXP_PMU_BUS, AXP_PMU_ADDR, | 70 | |
71 | AXP_REG_PWROUTPUTCTRL2, 0, 0x5f, NULL); | 71 | /* Enable required ADCs */ |
72 | i2c_reg_modify1(AXP_PMU_BUS, AXP_PMU_ADDR, | 72 | axp_set_enabled_adcs( |
73 | AXP_REG_DCDCWORKINGMODE, 0, 0xc0, NULL); | 73 | (1 << AXP_ADC_BATTERY_VOLTAGE) | |
74 | 74 | (1 << AXP_ADC_CHARGE_CURRENT) | | |
75 | /* Set the default charging current. This is the same as the | 75 | (1 << AXP_ADC_DISCHARGE_CURRENT) | |
76 | * OF's setting, although it's not strictly within the USB spec. */ | 76 | (1 << AXP_ADC_VBUS_VOLTAGE) | |
77 | axp_set_charge_current(780); | 77 | (1 << AXP_ADC_VBUS_CURRENT) | |
78 | (1 << AXP_ADC_INTERNAL_TEMP) | | ||
79 | (1 << AXP_ADC_APS_VOLTAGE)); | ||
78 | 80 | ||
79 | /* Short delay to give power outputs time to stabilize */ | 81 | /* Short delay to give power outputs time to stabilize */ |
80 | mdelay(200); | 82 | mdelay(200); |
@@ -99,20 +101,25 @@ void power_off(void) | |||
99 | 101 | ||
100 | bool charging_state(void) | 102 | bool charging_state(void) |
101 | { | 103 | { |
102 | return axp_battery_status() == AXP_BATT_CHARGING; | 104 | return axp_is_charging(); |
105 | } | ||
106 | |||
107 | unsigned int power_input_status(void) | ||
108 | { | ||
109 | return axp_power_input_status(); | ||
103 | } | 110 | } |
104 | 111 | ||
105 | int _battery_voltage(void) | 112 | int _battery_voltage(void) |
106 | { | 113 | { |
107 | return axp_adc_read(ADC_BATTERY_VOLTAGE); | 114 | return axp_read_adc(AXP_ADC_BATTERY_VOLTAGE); |
108 | } | 115 | } |
109 | 116 | ||
110 | #if CONFIG_BATTERY_MEASURE & CURRENT_MEASURE | 117 | #if CONFIG_BATTERY_MEASURE & CURRENT_MEASURE |
111 | int _battery_current(void) | 118 | int _battery_current(void) |
112 | { | 119 | { |
113 | if(charging_state()) | 120 | if(charging_state()) |
114 | return axp_adc_read(ADC_CHARGE_CURRENT); | 121 | return axp_read_adc(AXP_ADC_CHARGE_CURRENT); |
115 | else | 122 | else |
116 | return axp_adc_read(ADC_DISCHARGE_CURRENT); | 123 | return axp_read_adc(AXP_ADC_DISCHARGE_CURRENT); |
117 | } | 124 | } |
118 | #endif | 125 | #endif |