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.c49
1 files changed, 30 insertions, 19 deletions
diff --git a/firmware/target/mips/ingenic_x1000/shanlingq1/power-shanlingq1.c b/firmware/target/mips/ingenic_x1000/shanlingq1/power-shanlingq1.c
index 75f8031dd9..65d1bc163f 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 "axp-pmu.h" 25#include "axp192.h"
26#ifdef HAVE_CW2015 26#ifdef HAVE_CW2015
27# include "cw2015.h" 27# include "cw2015.h"
28#endif 28#endif
@@ -73,24 +73,30 @@ 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();
77#ifdef HAVE_CW2015 76#ifdef HAVE_CW2015
78 cw2015_init(); 77 cw2015_init();
79#endif 78#endif
80 79
81 /* Change supply voltage from the default of 1250 mV to 1200 mV, 80 /* Set DCDC2 to 1.2 V to match OF settings. */
82 * this matches the original firmware's settings. Didn't observe 81 axp_set_supply_voltage(AXP_SUPPLY_DCDC2, 1200);
83 * any obviously bad behavior at 1250 mV, but better to be safe. */ 82
84 axp_supply_set_voltage(AXP_SUPPLY_DCDC2, 1200); 83 /* Power on required supplies */
85 84 axp_set_enabled_supplies(
86 /* For now, just turn everything on... definitely the touchscreen 85 (1 << AXP_SUPPLY_DCDC1) | /* SD bus (3.3 V) */
87 * is powered by one of the outputs */ 86 (1 << AXP_SUPPLY_DCDC2) | /* LCD (1.2 V) */
88 i2c_reg_modify1(AXP_PMU_BUS, AXP_PMU_ADDR, 87 (1 << AXP_SUPPLY_DCDC3) | /* CPU (1.8 V) */
89 AXP_REG_PWROUTPUTCTRL1, 0, 0x05, NULL); 88 (1 << AXP_SUPPLY_LDO2) | /* Touchscreen (3.3 V) */
90 i2c_reg_modify1(AXP_PMU_BUS, AXP_PMU_ADDR, 89 (1 << AXP_SUPPLY_LDO3)); /* not sure (2.5 V) */
91 AXP_REG_PWROUTPUTCTRL2, 0, 0x0f, NULL); 90
92 i2c_reg_modify1(AXP_PMU_BUS, AXP_PMU_ADDR, 91 /* Enable required ADCs */
93 AXP_REG_DCDCWORKINGMODE, 0, 0xc0, NULL); 92 axp_set_enabled_adcs(
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));
94 100
95 /* Delay to give power output time to stabilize */ 101 /* Delay to give power output time to stabilize */
96 mdelay(20); 102 mdelay(20);
@@ -111,23 +117,28 @@ void power_off(void)
111 117
112bool charging_state(void) 118bool charging_state(void)
113{ 119{
114 return axp_battery_status() == AXP_BATT_CHARGING; 120 return axp_is_charging();
121}
122
123unsigned int power_input_status(void)
124{
125 return axp_power_input_status();
115} 126}
116 127
117int _battery_voltage(void) 128int _battery_voltage(void)
118{ 129{
119 /* CW2015 can also read battery voltage, but the AXP consistently 130 /* CW2015 can also read battery voltage, but the AXP consistently
120 * reads ~20-30 mV higher so I suspect it's the "real" voltage. */ 131 * reads ~20-30 mV higher so I suspect it's the "real" voltage. */
121 return axp_adc_read(ADC_BATTERY_VOLTAGE); 132 return axp_read_adc(AXP_ADC_BATTERY_VOLTAGE);
122} 133}
123 134
124#if CONFIG_BATTERY_MEASURE & CURRENT_MEASURE 135#if CONFIG_BATTERY_MEASURE & CURRENT_MEASURE
125int _battery_current(void) 136int _battery_current(void)
126{ 137{
127 if(charging_state()) 138 if(charging_state())
128 return axp_adc_read(ADC_CHARGE_CURRENT); 139 return axp_read_adc(AXP_ADC_CHARGE_CURRENT);
129 else 140 else
130 return axp_adc_read(ADC_DISCHARGE_CURRENT); 141 return axp_read_adc(AXP_ADC_DISCHARGE_CURRENT);
131} 142}
132#endif 143#endif
133 144