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 | 80 |
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 @@ | |||
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 "axp192.h" | 29 | #include "axp-pmu.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,33 +54,27 @@ const unsigned short percent_to_volt_charge[11] = | |||
54 | 54 | ||
55 | void power_init(void) | 55 | void power_init(void) |
56 | { | 56 | { |
57 | /* Configure I2C bus */ | 57 | /* Initialize driver */ |
58 | i2c_x1000_set_freq(AXP_PMU_BUS, I2C_FREQ_400K); | 58 | i2c_x1000_set_freq(2, I2C_FREQ_400K); |
59 | 59 | axp_init(); | |
60 | /* Set DCDC1 and DCDC2 to fixed PWM mode to match OF settings. */ | 60 | |
61 | axp_modify(AXP_REG_DCDCMODE, 0, 0x0c); | 61 | /* Set lowest sample rate */ |
62 | 62 | axp_adc_set_rate(AXP_ADC_RATE_25HZ); | |
63 | /* Power on required supplies */ | 63 | |
64 | axp_set_enabled_supplies( | 64 | /* Ensure battery voltage ADC is enabled */ |
65 | (1 << AXP_SUPPLY_DCDC1) | /* not sure (3.3 V) */ | 65 | int bits = axp_adc_get_enabled(); |
66 | (1 << AXP_SUPPLY_DCDC2) | /* not sure (1.4 V) */ | 66 | bits |= (1 << ADC_BATTERY_VOLTAGE); |
67 | (1 << AXP_SUPPLY_DCDC3) | /* for CPU (1.8 V) */ | 67 | axp_adc_set_enabled(bits); |
68 | (1 << AXP_SUPPLY_LDO2) | /* LCD controller (3.3 V) */ | 68 | |
69 | (1 << AXP_SUPPLY_LDO3)); /* SD bus (3.3 V) */ | 69 | /* Turn on all power outputs */ |
70 | 70 | i2c_reg_modify1(AXP_PMU_BUS, AXP_PMU_ADDR, | |
71 | /* Enable required ADCs */ | 71 | AXP_REG_PWROUTPUTCTRL2, 0, 0x5f, NULL); |
72 | axp_set_enabled_adcs( | 72 | i2c_reg_modify1(AXP_PMU_BUS, AXP_PMU_ADDR, |
73 | (1 << AXP_ADC_BATTERY_VOLTAGE) | | 73 | AXP_REG_DCDCWORKINGMODE, 0, 0xc0, NULL); |
74 | (1 << AXP_ADC_CHARGE_CURRENT) | | 74 | |
75 | (1 << AXP_ADC_DISCHARGE_CURRENT) | | 75 | /* Set the default charging current. This is the same as the |
76 | (1 << AXP_ADC_VBUS_VOLTAGE) | | 76 | * OF's setting, although it's not strictly within the USB spec. */ |
77 | (1 << AXP_ADC_VBUS_CURRENT) | | 77 | axp_set_charge_current(780); |
78 | (1 << AXP_ADC_INTERNAL_TEMP) | | ||
79 | (1 << AXP_ADC_APS_VOLTAGE)); | ||
80 | |||
81 | /* Configure USB charging */ | ||
82 | axp_set_vhold_level(4400); | ||
83 | usb_charging_maxcurrent_change(100); | ||
84 | 78 | ||
85 | /* Short delay to give power outputs time to stabilize */ | 79 | /* Short delay to give power outputs time to stabilize */ |
86 | mdelay(200); | 80 | mdelay(200); |
@@ -89,22 +83,7 @@ void power_init(void) | |||
89 | #ifdef HAVE_USB_CHARGING_ENABLE | 83 | #ifdef HAVE_USB_CHARGING_ENABLE |
90 | void usb_charging_maxcurrent_change(int maxcurrent) | 84 | void usb_charging_maxcurrent_change(int maxcurrent) |
91 | { | 85 | { |
92 | int vbus_limit; | 86 | axp_set_charge_current(maxcurrent); |
93 | int charge_current; | ||
94 | |||
95 | /* Note that the charge current setting is a maximum: it will be | ||
96 | * reduced dynamically by the AXP192 so the combined load is less | ||
97 | * than the set VBUS current limit. */ | ||
98 | if(maxcurrent <= 100) { | ||
99 | vbus_limit = AXP_VBUS_LIMIT_500mA; | ||
100 | charge_current = 100; | ||
101 | } else { | ||
102 | vbus_limit = AXP_VBUS_LIMIT_500mA; | ||
103 | charge_current = 550; | ||
104 | } | ||
105 | |||
106 | axp_set_vbus_limit(vbus_limit); | ||
107 | axp_set_charge_current(charge_current); | ||
108 | } | 87 | } |
109 | #endif | 88 | #endif |
110 | 89 | ||
@@ -120,25 +99,20 @@ void power_off(void) | |||
120 | 99 | ||
121 | bool charging_state(void) | 100 | bool charging_state(void) |
122 | { | 101 | { |
123 | return axp_is_charging(); | 102 | return axp_battery_status() == AXP_BATT_CHARGING; |
124 | } | ||
125 | |||
126 | unsigned int power_input_status(void) | ||
127 | { | ||
128 | return axp_power_input_status(); | ||
129 | } | 103 | } |
130 | 104 | ||
131 | int _battery_voltage(void) | 105 | int _battery_voltage(void) |
132 | { | 106 | { |
133 | return axp_read_adc(AXP_ADC_BATTERY_VOLTAGE); | 107 | return axp_adc_read(ADC_BATTERY_VOLTAGE); |
134 | } | 108 | } |
135 | 109 | ||
136 | #if CONFIG_BATTERY_MEASURE & CURRENT_MEASURE | 110 | #if CONFIG_BATTERY_MEASURE & CURRENT_MEASURE |
137 | int _battery_current(void) | 111 | int _battery_current(void) |
138 | { | 112 | { |
139 | if(charging_state()) | 113 | if(charging_state()) |
140 | return axp_read_adc(AXP_ADC_CHARGE_CURRENT); | 114 | return axp_adc_read(ADC_CHARGE_CURRENT); |
141 | else | 115 | else |
142 | return axp_read_adc(AXP_ADC_DISCHARGE_CURRENT); | 116 | return axp_adc_read(ADC_DISCHARGE_CURRENT); |
143 | } | 117 | } |
144 | #endif | 118 | #endif |