[U-Boot] [PATCH] board: stm32mp1: Update power supply check via USB TYPE-C
Patrice Chotard
patrice.chotard at st.com
Tue Apr 30 16:09:38 UTC 2019
Add 2 new checks:
- detect when USB TYPE-C cable is not plugged correctly.
In this case, GND and VBUS pins are connected but not CC1
and CC2 pins.
- detect is an USB Type-C charger supplies more than 3 Amps
which is not compliant with the USB Type-C specification
In these 2 situations, stop the boot process and let red led
blinks forever.
V cc1 | V cc2 | power supply | red led | console message
range (Volts) |range (Volts)| (Amps) | blinks |
--------------|-------------|--------------|---------|-----------------------------------
> 2.15 | < 0.2 | > 3 | for ever| USB TYPE-C charger not compliant with specification
[2.15 - 1.23[ | < 0.2 | 3 | NO | NO
[1.23 - 0.66[ | < 0.2 | 1.5 | 3 times | WARNING 1.5A power supply detected
[0.66 - 0] | < 0.2 | 0.5 | 2 times | WARNING 500mA power supply detected
< 0.2 | < 0.2 | | for ever| ERROR USB TYPE-C connection in unattached mode
> 0.2 | > 0.2 | | for ever| ERROR USB TYPE-C connection in unattached mode
Signed-off-by: Patrice Chotard <patrice.chotard at st.com>
---
board/st/stm32mp1/stm32mp1.c | 69 +++++++++++++++++++++++++++++++++++---------
1 file changed, 56 insertions(+), 13 deletions(-)
diff --git a/board/st/stm32mp1/stm32mp1.c b/board/st/stm32mp1/stm32mp1.c
index 76917b0..8c591a5 100644
--- a/board/st/stm32mp1/stm32mp1.c
+++ b/board/st/stm32mp1/stm32mp1.c
@@ -60,9 +60,10 @@
*/
DECLARE_GLOBAL_DATA_PTR;
+#define USB_LOW_THRESHOLD_UV 200000
#define USB_WARNING_LOW_THRESHOLD_UV 660000
#define USB_START_LOW_THRESHOLD_UV 1230000
-#define USB_START_HIGH_THRESHOLD_UV 2100000
+#define USB_START_HIGH_THRESHOLD_UV 2150000
int checkboard(void)
{
@@ -263,9 +264,10 @@ static int board_check_usb_power(void)
ofnode node;
unsigned int raw;
int max_uV = 0;
+ int min_uV = USB_START_HIGH_THRESHOLD_UV;
int ret, uV, adc_count;
- u8 i, nb_blink;
-
+ u32 nb_blink;
+ u8 i;
node = ofnode_path("/config");
if (!ofnode_valid(node)) {
debug("%s: no /config node?\n", __func__);
@@ -317,6 +319,8 @@ static int board_check_usb_power(void)
if (!adc_raw_to_uV(adc, raw, &uV)) {
if (uV > max_uV)
max_uV = uV;
+ if (uV < min_uV)
+ min_uV = uV;
pr_debug("%s: %s[%02d] = %u, %d uV\n", __func__,
adc->name, adc_args.args[0], raw, uV);
} else {
@@ -331,27 +335,66 @@ static int board_check_usb_power(void)
* continue.
*/
if (max_uV > USB_START_LOW_THRESHOLD_UV &&
- max_uV < USB_START_HIGH_THRESHOLD_UV)
+ max_uV <= USB_START_HIGH_THRESHOLD_UV &&
+ min_uV <= USB_LOW_THRESHOLD_UV)
return 0;
- /* Display warning message and make u-boot,error-led blinking */
- pr_err("\n*******************************************\n");
+ pr_err("****************************************************\n");
+
+ /*
+ * If highest and lowest value are either both below
+ * USB_LOW_THRESHOLD_UV or both above USB_LOW_THRESHOLD_UV, that
+ * means USB TYPE-C is in unattached mode, this is an issue, make
+ * u-boot,error-led blinking and stop boot process.
+ */
+ if ((max_uV > USB_LOW_THRESHOLD_UV &&
+ min_uV > USB_LOW_THRESHOLD_UV) ||
+ (max_uV <= USB_LOW_THRESHOLD_UV &&
+ min_uV <= USB_LOW_THRESHOLD_UV)) {
+ pr_err("* ERROR USB TYPE-C connection in unattached mode *\n");
+ pr_err("* Check that USB TYPE-C cable is correctly plugged *\n");
+ /* with 125ms interval, led will blink for 17.02 years ....*/
+ nb_blink = U32_MAX;
+ }
- if (max_uV < USB_WARNING_LOW_THRESHOLD_UV) {
- pr_err("* WARNING 500mA power supply detected *\n");
+ if (max_uV > USB_LOW_THRESHOLD_UV &&
+ max_uV <= USB_WARNING_LOW_THRESHOLD_UV &&
+ min_uV <= USB_LOW_THRESHOLD_UV) {
+ pr_err("* WARNING 500mA power supply detected *\n");
nb_blink = 2;
- } else {
- pr_err("* WARNING 1.5A power supply detected *\n");
+ }
+
+ if (max_uV > USB_WARNING_LOW_THRESHOLD_UV &&
+ max_uV <= USB_START_LOW_THRESHOLD_UV &&
+ min_uV <= USB_LOW_THRESHOLD_UV) {
+ pr_err("* WARNING 1.5mA power supply detected *\n");
nb_blink = 3;
}
- pr_err("* Current too low, use a 3A power supply! *\n");
- pr_err("*******************************************\n\n");
+ /*
+ * If highest value is above 2.15 Volts that means that the USB TypeC
+ * supplies more than 3 Amp, this is not compliant with TypeC specification
+ */
+ if (max_uV > USB_START_HIGH_THRESHOLD_UV) {
+ pr_err("* USB TYPE-C charger not compliant with *\n");
+ pr_err("* specification *\n");
+ pr_err("****************************************************\n\n");
+ /* with 125ms interval, led will blink for 17.02 years ....*/
+ nb_blink = U32_MAX;
+ } else {
+ pr_err("* Current too low, use a 3A power supply! *\n");
+ pr_err("****************************************************\n\n");
+ }
ret = get_led(&led, "u-boot,error-led");
- if (ret)
+ if (ret) {
+ /* in unattached case, the boot process must be stopped */
+ if (nb_blink == U32_MAX)
+ hang();
return ret;
+ }
+ /* make u-boot,error-led blinking */
for (i = 0; i < nb_blink * 2; i++) {
led_set_state(led, LEDST_TOGGLE);
mdelay(125);
--
1.9.1
More information about the U-Boot
mailing list