diff options
Diffstat (limited to 'firmware/target/mips')
6 files changed, 87 insertions, 171 deletions
diff --git a/firmware/target/mips/ingenic_x1000/erosqnative/button-erosqnative.c b/firmware/target/mips/ingenic_x1000/erosqnative/button-erosqnative.c index 64041795a3..1583db175a 100644 --- a/firmware/target/mips/ingenic_x1000/erosqnative/button-erosqnative.c +++ b/firmware/target/mips/ingenic_x1000/erosqnative/button-erosqnative.c | |||
@@ -24,7 +24,7 @@ | |||
24 | #include "backlight.h" | 24 | #include "backlight.h" |
25 | #include "powermgmt.h" | 25 | #include "powermgmt.h" |
26 | #include "panic.h" | 26 | #include "panic.h" |
27 | #include "axp192.h" | 27 | #include "axp-pmu.h" |
28 | #include "gpio-x1000.h" | 28 | #include "gpio-x1000.h" |
29 | #include "irq-x1000.h" | 29 | #include "irq-x1000.h" |
30 | #include "i2c-x1000.h" | 30 | #include "i2c-x1000.h" |
@@ -89,7 +89,7 @@ static int hp_detect_tmo_cb(struct timeout* tmo) | |||
89 | static void hp_detect_init(void) | 89 | static void hp_detect_init(void) |
90 | { | 90 | { |
91 | static struct timeout tmo; | 91 | static struct timeout tmo; |
92 | static const uint8_t gpio_reg = AXP_REG_GPIOLEVEL1; | 92 | static const uint8_t gpio_reg = AXP192_REG_GPIOSTATE1; |
93 | static i2c_descriptor desc = { | 93 | static i2c_descriptor desc = { |
94 | .slave_addr = AXP_PMU_ADDR, | 94 | .slave_addr = AXP_PMU_ADDR, |
95 | .bus_cond = I2C_START | I2C_STOP, | 95 | .bus_cond = I2C_START | I2C_STOP, |
@@ -105,11 +105,11 @@ static void hp_detect_init(void) | |||
105 | 105 | ||
106 | /* Headphone and LO detects are wired to AXP192 GPIOs 0 and 1, | 106 | /* Headphone and LO detects are wired to AXP192 GPIOs 0 and 1, |
107 | * set them to inputs. */ | 107 | * set them to inputs. */ |
108 | axp_set_gpio_function(0, AXP_GPIO_INPUT); /* HP detect */ | 108 | i2c_reg_write1(AXP_PMU_BUS, AXP_PMU_ADDR, AXP192_REG_GPIO0FUNCTION, 0x01); /* HP detect */ |
109 | axp_set_gpio_function(1, AXP_GPIO_INPUT); /* LO detect */ | 109 | i2c_reg_write1(AXP_PMU_BUS, AXP_PMU_ADDR, AXP192_REG_GPIO1FUNCTION, 0x01); /* LO detect */ |
110 | 110 | ||
111 | /* Get an initial reading before startup */ | 111 | /* Get an initial reading before startup */ |
112 | int r = axp_read(gpio_reg); | 112 | int r = i2c_reg_read1(AXP_PMU_BUS, AXP_PMU_ADDR, gpio_reg); |
113 | if(r >= 0) | 113 | if(r >= 0) |
114 | { | 114 | { |
115 | hp_detect_reg = r; | 115 | hp_detect_reg = r; |
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 |
diff --git a/firmware/target/mips/ingenic_x1000/fiiom3k/button-fiiom3k.c b/firmware/target/mips/ingenic_x1000/fiiom3k/button-fiiom3k.c index 0ef7bd2f64..24daf2ef69 100644 --- a/firmware/target/mips/ingenic_x1000/fiiom3k/button-fiiom3k.c +++ b/firmware/target/mips/ingenic_x1000/fiiom3k/button-fiiom3k.c | |||
@@ -24,7 +24,7 @@ | |||
24 | #include "backlight.h" | 24 | #include "backlight.h" |
25 | #include "powermgmt.h" | 25 | #include "powermgmt.h" |
26 | #include "panic.h" | 26 | #include "panic.h" |
27 | #include "axp192.h" | 27 | #include "axp-pmu.h" |
28 | #include "ft6x06.h" | 28 | #include "ft6x06.h" |
29 | #include "gpio-x1000.h" | 29 | #include "gpio-x1000.h" |
30 | #include "irq-x1000.h" | 30 | #include "irq-x1000.h" |
@@ -393,7 +393,7 @@ static int hp_detect_tmo_cb(struct timeout* tmo) | |||
393 | static void hp_detect_init(void) | 393 | static void hp_detect_init(void) |
394 | { | 394 | { |
395 | static struct timeout tmo; | 395 | static struct timeout tmo; |
396 | static const uint8_t gpio_reg = AXP_REG_GPIOLEVEL1; | 396 | static const uint8_t gpio_reg = AXP192_REG_GPIOSTATE1; |
397 | static i2c_descriptor desc = { | 397 | static i2c_descriptor desc = { |
398 | .slave_addr = AXP_PMU_ADDR, | 398 | .slave_addr = AXP_PMU_ADDR, |
399 | .bus_cond = I2C_START | I2C_STOP, | 399 | .bus_cond = I2C_START | I2C_STOP, |
@@ -408,10 +408,10 @@ static void hp_detect_init(void) | |||
408 | }; | 408 | }; |
409 | 409 | ||
410 | /* Headphone detect is wired to AXP192 GPIO: set it to input state */ | 410 | /* Headphone detect is wired to AXP192 GPIO: set it to input state */ |
411 | axp_set_gpio_function(2, AXP_GPIO_INPUT); | 411 | i2c_reg_write1(AXP_PMU_BUS, AXP_PMU_ADDR, AXP192_REG_GPIO2FUNCTION, 0x01); |
412 | 412 | ||
413 | /* Get an initial reading before startup */ | 413 | /* Get an initial reading before startup */ |
414 | int r = axp_read(gpio_reg); | 414 | int r = i2c_reg_read1(AXP_PMU_BUS, AXP_PMU_ADDR, gpio_reg); |
415 | if(r >= 0) | 415 | if(r >= 0) |
416 | hp_detect_reg = r; | 416 | hp_detect_reg = r; |
417 | 417 | ||
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 |
diff --git a/firmware/target/mips/ingenic_x1000/shanlingq1/button-shanlingq1.c b/firmware/target/mips/ingenic_x1000/shanlingq1/button-shanlingq1.c index 1976dde793..13b0cdd078 100644 --- a/firmware/target/mips/ingenic_x1000/shanlingq1/button-shanlingq1.c +++ b/firmware/target/mips/ingenic_x1000/shanlingq1/button-shanlingq1.c | |||
@@ -23,7 +23,7 @@ | |||
23 | #include "button.h" | 23 | #include "button.h" |
24 | #include "touchscreen.h" | 24 | #include "touchscreen.h" |
25 | #include "ft6x06.h" | 25 | #include "ft6x06.h" |
26 | #include "axp192.h" | 26 | #include "axp-pmu.h" |
27 | #include "kernel.h" | 27 | #include "kernel.h" |
28 | #include "backlight.h" | 28 | #include "backlight.h" |
29 | #include "powermgmt.h" | 29 | #include "powermgmt.h" |
@@ -57,7 +57,7 @@ static void hp_detect_init(void) | |||
57 | { | 57 | { |
58 | /* TODO: replace this copy paste cruft with an API in axp-pmu */ | 58 | /* TODO: replace this copy paste cruft with an API in axp-pmu */ |
59 | static struct timeout tmo; | 59 | static struct timeout tmo; |
60 | static const uint8_t gpio_reg = AXP_REG_GPIOLEVEL1; | 60 | static const uint8_t gpio_reg = AXP192_REG_GPIOSTATE1; |
61 | static i2c_descriptor desc = { | 61 | static i2c_descriptor desc = { |
62 | .slave_addr = AXP_PMU_ADDR, | 62 | .slave_addr = AXP_PMU_ADDR, |
63 | .bus_cond = I2C_START | I2C_STOP, | 63 | .bus_cond = I2C_START | I2C_STOP, |
@@ -72,10 +72,10 @@ static void hp_detect_init(void) | |||
72 | }; | 72 | }; |
73 | 73 | ||
74 | /* Headphone detect is wired to AXP192 GPIO: set it to input state */ | 74 | /* Headphone detect is wired to AXP192 GPIO: set it to input state */ |
75 | axp_set_gpio_function(1, AXP_GPIO_INPUT); | 75 | i2c_reg_write1(AXP_PMU_BUS, AXP_PMU_ADDR, AXP192_REG_GPIO1FUNCTION, 0x01); |
76 | 76 | ||
77 | /* Get an initial reading before startup */ | 77 | /* Get an initial reading before startup */ |
78 | int r = axp_read(gpio_reg); | 78 | int r = i2c_reg_read1(AXP_PMU_BUS, AXP_PMU_ADDR, gpio_reg); |
79 | if(r >= 0) | 79 | if(r >= 0) |
80 | hp_detect_reg = r; | 80 | hp_detect_reg = r; |
81 | 81 | ||
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] = | |||
73 | void power_init(void) | 73 | void 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 |
110 | void usb_charging_maxcurrent_change(int maxcurrent) | 100 | void 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 | ||
137 | bool charging_state(void) | 112 | bool charging_state(void) |
138 | { | 113 | { |
139 | return axp_is_charging(); | 114 | return axp_battery_status() == AXP_BATT_CHARGING; |
140 | } | ||
141 | |||
142 | unsigned int power_input_status(void) | ||
143 | { | ||
144 | return axp_power_input_status(); | ||
145 | } | 115 | } |
146 | 116 | ||
147 | int _battery_voltage(void) | 117 | int _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 |
155 | int _battery_current(void) | 125 | int _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 | ||