board: stm32mp1: Update power supply check via USB TYPE-C
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@st.com>
			
			
This commit is contained in:
		
							parent
							
								
									ca9c5dccb7
								
							
						
					
					
						commit
						28c064e66b
					
				|  | @ -62,9 +62,10 @@ | ||||||
|  */ |  */ | ||||||
| DECLARE_GLOBAL_DATA_PTR; | DECLARE_GLOBAL_DATA_PTR; | ||||||
| 
 | 
 | ||||||
|  | #define USB_LOW_THRESHOLD_UV		200000 | ||||||
| #define USB_WARNING_LOW_THRESHOLD_UV	660000 | #define USB_WARNING_LOW_THRESHOLD_UV	660000 | ||||||
| #define USB_START_LOW_THRESHOLD_UV	1230000 | #define USB_START_LOW_THRESHOLD_UV	1230000 | ||||||
| #define USB_START_HIGH_THRESHOLD_UV	2100000 | #define USB_START_HIGH_THRESHOLD_UV	2150000 | ||||||
| 
 | 
 | ||||||
| int checkboard(void) | int checkboard(void) | ||||||
| { | { | ||||||
|  | @ -265,9 +266,10 @@ static int board_check_usb_power(void) | ||||||
| 	ofnode node; | 	ofnode node; | ||||||
| 	unsigned int raw; | 	unsigned int raw; | ||||||
| 	int max_uV = 0; | 	int max_uV = 0; | ||||||
|  | 	int min_uV = USB_START_HIGH_THRESHOLD_UV; | ||||||
| 	int ret, uV, adc_count; | 	int ret, uV, adc_count; | ||||||
| 	u8 i, nb_blink; | 	u32 nb_blink; | ||||||
| 
 | 	u8 i; | ||||||
| 	node = ofnode_path("/config"); | 	node = ofnode_path("/config"); | ||||||
| 	if (!ofnode_valid(node)) { | 	if (!ofnode_valid(node)) { | ||||||
| 		debug("%s: no /config node?\n", __func__); | 		debug("%s: no /config node?\n", __func__); | ||||||
|  | @ -319,6 +321,8 @@ static int board_check_usb_power(void) | ||||||
| 		if (!adc_raw_to_uV(adc, raw, &uV)) { | 		if (!adc_raw_to_uV(adc, raw, &uV)) { | ||||||
| 			if (uV > max_uV) | 			if (uV > max_uV) | ||||||
| 				max_uV = uV; | 				max_uV = uV; | ||||||
|  | 			if (uV < min_uV) | ||||||
|  | 				min_uV = uV; | ||||||
| 			pr_debug("%s: %s[%02d] = %u, %d uV\n", __func__, | 			pr_debug("%s: %s[%02d] = %u, %d uV\n", __func__, | ||||||
| 				 adc->name, adc_args.args[0], raw, uV); | 				 adc->name, adc_args.args[0], raw, uV); | ||||||
| 		} else { | 		} else { | ||||||
|  | @ -333,27 +337,66 @@ static int board_check_usb_power(void) | ||||||
| 	 * continue. | 	 * continue. | ||||||
| 	 */ | 	 */ | ||||||
| 	if (max_uV > USB_START_LOW_THRESHOLD_UV && | 	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; | 		return 0; | ||||||
| 
 | 
 | ||||||
| 	/* Display warning message and make u-boot,error-led blinking */ | 	pr_err("****************************************************\n"); | ||||||
| 	pr_err("\n*******************************************\n"); |  | ||||||
| 
 | 
 | ||||||
| 	if (max_uV < USB_WARNING_LOW_THRESHOLD_UV) { | 	/*
 | ||||||
| 		pr_err("*   WARNING 500mA power supply detected   *\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_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; | 		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; | 		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"); | 	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; | 		return ret; | ||||||
|  | 	} | ||||||
| 
 | 
 | ||||||
|  | 	/* make u-boot,error-led blinking */ | ||||||
| 	for (i = 0; i < nb_blink * 2; i++) { | 	for (i = 0; i < nb_blink * 2; i++) { | ||||||
| 		led_set_state(led, LEDST_TOGGLE); | 		led_set_state(led, LEDST_TOGGLE); | ||||||
| 		mdelay(125); | 		mdelay(125); | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue