summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAidan MacDonald <amachronic@protonmail.com>2021-12-27 12:26:59 +0000
committerAidan MacDonald <amachronic@protonmail.com>2021-12-28 15:20:27 +0000
commit90dd2f84a9174c38dbfb07d582ec6ee7697b1939 (patch)
tree7425bde40ee4af568a48c243028411d67a3d8bd2
parent2d891439623bb76d38b98202ca5f3eea3c01c5f0 (diff)
downloadrockbox-90dd2f84a9174c38dbfb07d582ec6ee7697b1939.tar.gz
rockbox-90dd2f84a9174c38dbfb07d582ec6ee7697b1939.zip
x1000: Correctly limit USB charging current
The way this was done before was wrong - limiting the charge current is not enough since the device will draw additional power to run. Use the AXP192's vbus current limit control to stay compliant with the USB specification. Change-Id: I91b84e3480a432e49bec53cf2a17e4e3444404a4
-rw-r--r--firmware/target/mips/ingenic_x1000/erosqnative/power-erosqnative.c24
-rw-r--r--firmware/target/mips/ingenic_x1000/fiiom3k/power-fiiom3k.c21
-rw-r--r--firmware/target/mips/ingenic_x1000/shanlingq1/power-shanlingq1.c23
3 files changed, 63 insertions, 5 deletions
diff --git a/firmware/target/mips/ingenic_x1000/erosqnative/power-erosqnative.c b/firmware/target/mips/ingenic_x1000/erosqnative/power-erosqnative.c
index 17cdb4d645..7ad9479a96 100644
--- a/firmware/target/mips/ingenic_x1000/erosqnative/power-erosqnative.c
+++ b/firmware/target/mips/ingenic_x1000/erosqnative/power-erosqnative.c
@@ -62,7 +62,8 @@ void power_init(void)
62 /* FIXME: Copy paste from M3K. Probably not necessary */ 62 /* FIXME: Copy paste from M3K. Probably not necessary */
63 axp_modify(AXP_REG_DCDCMODE, 0, 0xc0); 63 axp_modify(AXP_REG_DCDCMODE, 0, 0xc0);
64 64
65 /* Power on required supplies */ 65 /* Power on required supplies
66 * TODO: This should be checked, though likely all but EXTEN are needed */
66 axp_set_enabled_supplies( 67 axp_set_enabled_supplies(
67 (1 << AXP_SUPPLY_EXTEN) | 68 (1 << AXP_SUPPLY_EXTEN) |
68 (1 << AXP_SUPPLY_DCDC1) | 69 (1 << AXP_SUPPLY_DCDC1) |
@@ -81,6 +82,10 @@ void power_init(void)
81 (1 << AXP_ADC_INTERNAL_TEMP) | 82 (1 << AXP_ADC_INTERNAL_TEMP) |
82 (1 << AXP_ADC_APS_VOLTAGE)); 83 (1 << AXP_ADC_APS_VOLTAGE));
83 84
85 /* Configure USB charging */
86 axp_set_vhold_level(4400);
87 usb_charging_maxcurrent_change(100);
88
84 /* Delay to give power outputs time to stabilize. 89 /* Delay to give power outputs time to stabilize.
85 * With the power thread delay, this can apparently go as low as 50, 90 * With the power thread delay, this can apparently go as low as 50,
86 * Keeping a higher value here just to ensure the bootloader works 91 * Keeping a higher value here just to ensure the bootloader works
@@ -91,7 +96,22 @@ void power_init(void)
91#ifdef HAVE_USB_CHARGING_ENABLE 96#ifdef HAVE_USB_CHARGING_ENABLE
92void usb_charging_maxcurrent_change(int maxcurrent) 97void usb_charging_maxcurrent_change(int maxcurrent)
93{ 98{
94 axp_set_charge_current(maxcurrent); 99 int vbus_limit;
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_100mA;
107 charge_current = 550;
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);
95} 115}
96#endif 116#endif
97 117
diff --git a/firmware/target/mips/ingenic_x1000/fiiom3k/power-fiiom3k.c b/firmware/target/mips/ingenic_x1000/fiiom3k/power-fiiom3k.c
index 53451ffa6c..c8498c4dbc 100644
--- a/firmware/target/mips/ingenic_x1000/fiiom3k/power-fiiom3k.c
+++ b/firmware/target/mips/ingenic_x1000/fiiom3k/power-fiiom3k.c
@@ -78,6 +78,10 @@ void power_init(void)
78 (1 << AXP_ADC_INTERNAL_TEMP) | 78 (1 << AXP_ADC_INTERNAL_TEMP) |
79 (1 << AXP_ADC_APS_VOLTAGE)); 79 (1 << AXP_ADC_APS_VOLTAGE));
80 80
81 /* Configure USB charging */
82 axp_set_vhold_level(4400);
83 usb_charging_maxcurrent_change(100);
84
81 /* Short delay to give power outputs time to stabilize */ 85 /* Short delay to give power outputs time to stabilize */
82 mdelay(200); 86 mdelay(200);
83} 87}
@@ -85,7 +89,22 @@ void power_init(void)
85#ifdef HAVE_USB_CHARGING_ENABLE 89#ifdef HAVE_USB_CHARGING_ENABLE
86void usb_charging_maxcurrent_change(int maxcurrent) 90void usb_charging_maxcurrent_change(int maxcurrent)
87{ 91{
88 axp_set_charge_current(maxcurrent); 92 int vbus_limit;
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_100mA;
100 charge_current = 550;
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);
89} 108}
90#endif 109#endif
91 110
diff --git a/firmware/target/mips/ingenic_x1000/shanlingq1/power-shanlingq1.c b/firmware/target/mips/ingenic_x1000/shanlingq1/power-shanlingq1.c
index 65d1bc163f..9637ceef2f 100644
--- a/firmware/target/mips/ingenic_x1000/shanlingq1/power-shanlingq1.c
+++ b/firmware/target/mips/ingenic_x1000/shanlingq1/power-shanlingq1.c
@@ -86,7 +86,7 @@ void power_init(void)
86 (1 << AXP_SUPPLY_DCDC2) | /* LCD (1.2 V) */ 86 (1 << AXP_SUPPLY_DCDC2) | /* LCD (1.2 V) */
87 (1 << AXP_SUPPLY_DCDC3) | /* CPU (1.8 V) */ 87 (1 << AXP_SUPPLY_DCDC3) | /* CPU (1.8 V) */
88 (1 << AXP_SUPPLY_LDO2) | /* Touchscreen (3.3 V) */ 88 (1 << AXP_SUPPLY_LDO2) | /* Touchscreen (3.3 V) */
89 (1 << AXP_SUPPLY_LDO3)); /* not sure (2.5 V) */ 89 (1 << AXP_SUPPLY_LDO3)); /* USB analog (2.5 V) */
90 90
91 /* Enable required ADCs */ 91 /* Enable required ADCs */
92 axp_set_enabled_adcs( 92 axp_set_enabled_adcs(
@@ -98,6 +98,10 @@ void power_init(void)
98 (1 << AXP_ADC_INTERNAL_TEMP) | 98 (1 << AXP_ADC_INTERNAL_TEMP) |
99 (1 << AXP_ADC_APS_VOLTAGE)); 99 (1 << AXP_ADC_APS_VOLTAGE));
100 100
101 /* Configure USB charging */
102 axp_set_vhold_level(4400);
103 usb_charging_maxcurrent_change(100);
104
101 /* Delay to give power output time to stabilize */ 105 /* Delay to give power output time to stabilize */
102 mdelay(20); 106 mdelay(20);
103} 107}
@@ -105,7 +109,22 @@ void power_init(void)
105#ifdef HAVE_USB_CHARGING_ENABLE 109#ifdef HAVE_USB_CHARGING_ENABLE
106void usb_charging_maxcurrent_change(int maxcurrent) 110void usb_charging_maxcurrent_change(int maxcurrent)
107{ 111{
108 axp_set_charge_current(maxcurrent); 112 int vbus_limit;
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_100mA;
120 charge_current = 550;
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);
109} 128}
110#endif 129#endif
111 130