summaryrefslogtreecommitdiff
path: root/firmware/target/mips/ingenic_x1000/shanlingq1/power-shanlingq1.c
diff options
context:
space:
mode:
Diffstat (limited to 'firmware/target/mips/ingenic_x1000/shanlingq1/power-shanlingq1.c')
-rw-r--r--firmware/target/mips/ingenic_x1000/shanlingq1/power-shanlingq1.c70
1 files changed, 20 insertions, 50 deletions
diff --git a/firmware/target/mips/ingenic_x1000/shanlingq1/power-shanlingq1.c b/firmware/target/mips/ingenic_x1000/shanlingq1/power-shanlingq1.c
index 86ee84c37a..75f8031dd9 100644
--- a/firmware/target/mips/ingenic_x1000/shanlingq1/power-shanlingq1.c
+++ b/firmware/target/mips/ingenic_x1000/shanlingq1/power-shanlingq1.c
@@ -22,7 +22,7 @@
22#include "power.h" 22#include "power.h"
23#include "adc.h" 23#include "adc.h"
24#include "system.h" 24#include "system.h"
25#include "axp192.h" 25#include "axp-pmu.h"
26#ifdef HAVE_CW2015 26#ifdef HAVE_CW2015
27# include "cw2015.h" 27# include "cw2015.h"
28#endif 28#endif
@@ -73,34 +73,24 @@ const unsigned short percent_to_volt_charge[11] =
73void power_init(void) 73void power_init(void)
74{ 74{
75 i2c_x1000_set_freq(AXP_PMU_BUS, I2C_FREQ_400K); 75 i2c_x1000_set_freq(AXP_PMU_BUS, I2C_FREQ_400K);
76 axp_init();
76#ifdef HAVE_CW2015 77#ifdef HAVE_CW2015
77 cw2015_init(); 78 cw2015_init();
78#endif 79#endif
79 80
80 /* Set DCDC2 to 1.2 V to match OF settings. */ 81 /* Change supply voltage from the default of 1250 mV to 1200 mV,
81 axp_set_supply_voltage(AXP_SUPPLY_DCDC2, 1200); 82 * this matches the original firmware's settings. Didn't observe
82 83 * any obviously bad behavior at 1250 mV, but better to be safe. */
83 /* Power on required supplies */ 84 axp_supply_set_voltage(AXP_SUPPLY_DCDC2, 1200);
84 axp_set_enabled_supplies( 85
85 (1 << AXP_SUPPLY_DCDC1) | /* SD bus (3.3 V) */ 86 /* For now, just turn everything on... definitely the touchscreen
86 (1 << AXP_SUPPLY_DCDC2) | /* LCD (1.2 V) */ 87 * is powered by one of the outputs */
87 (1 << AXP_SUPPLY_DCDC3) | /* CPU (1.8 V) */ 88 i2c_reg_modify1(AXP_PMU_BUS, AXP_PMU_ADDR,
88 (1 << AXP_SUPPLY_LDO2) | /* Touchscreen (3.3 V) */ 89 AXP_REG_PWROUTPUTCTRL1, 0, 0x05, NULL);
89 (1 << AXP_SUPPLY_LDO3)); /* USB analog (2.5 V) */ 90 i2c_reg_modify1(AXP_PMU_BUS, AXP_PMU_ADDR,
90 91 AXP_REG_PWROUTPUTCTRL2, 0, 0x0f, NULL);
91 /* Enable required ADCs */ 92 i2c_reg_modify1(AXP_PMU_BUS, AXP_PMU_ADDR,
92 axp_set_enabled_adcs( 93 AXP_REG_DCDCWORKINGMODE, 0, 0xc0, NULL);
93 (1 << AXP_ADC_BATTERY_VOLTAGE) |
94 (1 << AXP_ADC_CHARGE_CURRENT) |
95 (1 << AXP_ADC_DISCHARGE_CURRENT) |
96 (1 << AXP_ADC_VBUS_VOLTAGE) |
97 (1 << AXP_ADC_VBUS_CURRENT) |
98 (1 << AXP_ADC_INTERNAL_TEMP) |
99 (1 << AXP_ADC_APS_VOLTAGE));
100
101 /* Configure USB charging */
102 axp_set_vhold_level(4400);
103 usb_charging_maxcurrent_change(100);
104 94
105 /* Delay to give power output time to stabilize */ 95 /* Delay to give power output time to stabilize */
106 mdelay(20); 96 mdelay(20);
@@ -109,22 +99,7 @@ void power_init(void)
109#ifdef HAVE_USB_CHARGING_ENABLE 99#ifdef HAVE_USB_CHARGING_ENABLE
110void usb_charging_maxcurrent_change(int maxcurrent) 100void usb_charging_maxcurrent_change(int maxcurrent)
111{ 101{
112 int vbus_limit; 102 axp_set_charge_current(maxcurrent);
113 int charge_current;
114
115 /* Note that the charge current setting is a maximum: it will be
116 * reduced dynamically by the AXP192 so the combined load is less
117 * than the set VBUS current limit. */
118 if(maxcurrent <= 100) {
119 vbus_limit = AXP_VBUS_LIMIT_500mA;
120 charge_current = 100;
121 } else {
122 vbus_limit = AXP_VBUS_LIMIT_500mA;
123 charge_current = 550;
124 }
125
126 axp_set_vbus_limit(vbus_limit);
127 axp_set_charge_current(charge_current);
128} 103}
129#endif 104#endif
130 105
@@ -136,28 +111,23 @@ void power_off(void)
136 111
137bool charging_state(void) 112bool charging_state(void)
138{ 113{
139 return axp_is_charging(); 114 return axp_battery_status() == AXP_BATT_CHARGING;
140}
141
142unsigned int power_input_status(void)
143{
144 return axp_power_input_status();
145} 115}
146 116
147int _battery_voltage(void) 117int _battery_voltage(void)
148{ 118{
149 /* CW2015 can also read battery voltage, but the AXP consistently 119 /* CW2015 can also read battery voltage, but the AXP consistently
150 * reads ~20-30 mV higher so I suspect it's the "real" voltage. */ 120 * reads ~20-30 mV higher so I suspect it's the "real" voltage. */
151 return axp_read_adc(AXP_ADC_BATTERY_VOLTAGE); 121 return axp_adc_read(ADC_BATTERY_VOLTAGE);
152} 122}
153 123
154#if CONFIG_BATTERY_MEASURE & CURRENT_MEASURE 124#if CONFIG_BATTERY_MEASURE & CURRENT_MEASURE
155int _battery_current(void) 125int _battery_current(void)
156{ 126{
157 if(charging_state()) 127 if(charging_state())
158 return axp_read_adc(AXP_ADC_CHARGE_CURRENT); 128 return axp_adc_read(ADC_CHARGE_CURRENT);
159 else 129 else
160 return axp_read_adc(AXP_ADC_DISCHARGE_CURRENT); 130 return axp_adc_read(ADC_DISCHARGE_CURRENT);
161} 131}
162#endif 132#endif
163 133