diff mbox series

[4/4] stm32mp: stm32prog: replace alias by serial device sequence number

Message ID 20210225133652.4.I05f314a38edb990c76933a71b0d050e386c6926e@changeid
State Accepted
Commit f49eb16c17e2c45e5be712ded316ebcb17d29d17
Delegated to: Patrice Chotard
Headers show
Series [1/4] stm32mp: stm32prog: Add Kconfig file for stm32prog command | expand

Commit Message

Patrick DELAUNAY Feb. 25, 2021, 12:37 p.m. UTC
The command "stm32prog serial <dev>" can directly use the device sequence
number of serial uclass as this sequence number is egual to alias when it
exist; this assumption simplify the code and avoid access to gd->fdt_blob
and the device tree parsing.

Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
---

 .../cmd_stm32prog/stm32prog_serial.c          | 29 ++++---------------
 arch/arm/mach-stm32mp/cpu.c                   | 11 +++----
 2 files changed, 10 insertions(+), 30 deletions(-)

Comments

Patrice CHOTARD March 9, 2021, 1:14 p.m. UTC | #1
Hi Patrick

On 2/25/21 1:37 PM, Patrick Delaunay wrote:
> The command "stm32prog serial <dev>" can directly use the device sequence
> number of serial uclass as this sequence number is egual to alias when it
> exist; this assumption simplify the code and avoid access to gd->fdt_blob
> and the device tree parsing.
> 
> Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
> ---
> 
>  .../cmd_stm32prog/stm32prog_serial.c          | 29 ++++---------------
>  arch/arm/mach-stm32mp/cpu.c                   | 11 +++----
>  2 files changed, 10 insertions(+), 30 deletions(-)
> 
> diff --git a/arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog_serial.c b/arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog_serial.c
> index 373ca20886..a51e5e3ec8 100644
> --- a/arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog_serial.c
> +++ b/arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog_serial.c
> @@ -187,36 +187,19 @@ static int stm32prog_read(struct stm32prog_data *data, u8 phase, u32 offset,
>  int stm32prog_serial_init(struct stm32prog_data *data, int link_dev)
>  {
>  	struct udevice *dev = NULL;
> -	int node;
> -	char alias[10];
> -	const char *path;
>  	struct dm_serial_ops *ops;
>  	/* no parity, 8 bits, 1 stop */
>  	u32 serial_config = SERIAL_DEFAULT_CONFIG;
>  
>  	down_serial_dev = NULL;
>  
> -	sprintf(alias, "serial%d", link_dev);
> -	path = fdt_get_alias(gd->fdt_blob, alias);
> -	if (!path) {
> -		log_err("%s alias not found", alias);
> -		return -ENODEV;
> -	}
> -	node = fdt_path_offset(gd->fdt_blob, path);
> -	if (!uclass_get_device_by_of_offset(UCLASS_SERIAL, node,
> -					    &dev)) {
> -		down_serial_dev = dev;
> -	} else if (node > 0 &&
> -		   !lists_bind_fdt(gd->dm_root, offset_to_ofnode(node),
> -				   &dev, false)) {
> -		if (!device_probe(dev))
> -			down_serial_dev = dev;
> -	}
> -	if (!down_serial_dev) {
> -		log_err("%s = %s device not found", alias, path);
> +	if (uclass_get_device_by_seq(UCLASS_SERIAL, link_dev, &dev)) {
> +		log_err("serial %d device not found\n", link_dev);
>  		return -ENODEV;
>  	}
>  
> +	down_serial_dev = dev;
> +
>  	/* force silent console on uart only when used */
>  	if (gd->cur_serial_dev == down_serial_dev)
>  		gd->flags |= GD_FLG_DISABLE_CONSOLE | GD_FLG_SILENT;
> @@ -226,11 +209,11 @@ int stm32prog_serial_init(struct stm32prog_data *data, int link_dev)
>  	ops = serial_get_ops(down_serial_dev);
>  
>  	if (!ops) {
> -		log_err("%s = %s missing ops", alias, path);
> +		log_err("serial %d = %s missing ops\n", link_dev, dev->name);
>  		return -ENODEV;
>  	}
>  	if (!ops->setconfig) {
> -		log_err("%s = %s missing setconfig", alias, path);
> +		log_err("serial %d = %s missing setconfig\n", link_dev, dev->name);
>  		return -ENODEV;
>  	}
>  
> diff --git a/arch/arm/mach-stm32mp/cpu.c b/arch/arm/mach-stm32mp/cpu.c
> index 527b6290de..9a76b5633b 100644
> --- a/arch/arm/mach-stm32mp/cpu.c
> +++ b/arch/arm/mach-stm32mp/cpu.c
> @@ -466,7 +466,6 @@ static void setup_boot_mode(void)
>  	unsigned int instance = (boot_mode & TAMP_BOOT_INSTANCE_MASK) - 1;
>  	u32 forced_mode = (boot_ctx & TAMP_BOOT_FORCED_MASK);
>  	struct udevice *dev;
> -	int alias;
>  
>  	log_debug("%s: boot_ctx=0x%x => boot_mode=%x, instance=%d forced=%x\n",
>  		  __func__, boot_ctx, boot_mode, instance, forced_mode);
> @@ -474,20 +473,18 @@ static void setup_boot_mode(void)
>  	case BOOT_SERIAL_UART:
>  		if (instance > ARRAY_SIZE(serial_addr))
>  			break;
> -		/* serial : search associated alias in devicetree */
> +		/* serial : search associated node in devicetree */
>  		sprintf(cmd, "serial@%x", serial_addr[instance]);
> -		if (uclass_get_device_by_name(UCLASS_SERIAL, cmd, &dev) ||
> -		    fdtdec_get_alias_seq(gd->fdt_blob, "serial",
> -					 dev_of_offset(dev), &alias)) {
> +		if (uclass_get_device_by_name(UCLASS_SERIAL, cmd, &dev)) {
>  			/* restore console on error */
>  			if (IS_ENABLED(CONFIG_CMD_STM32PROG_SERIAL))
>  				gd->flags &= ~(GD_FLG_SILENT |
>  					       GD_FLG_DISABLE_CONSOLE);
> -			printf("serial%d = %s not found in device tree!\n",
> +			printf("uart%d = %s not found in device tree!\n",
>  			       instance, cmd);
>  			break;
>  		}
> -		sprintf(cmd, "%d", alias);
> +		sprintf(cmd, "%d", dev_seq(dev));
>  		env_set("boot_device", "serial");
>  		env_set("boot_instance", cmd);
>  
> 

Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com>

Thanks
Patrice
Patrice CHOTARD March 12, 2021, 12:28 p.m. UTC | #2
Hi

On 3/9/21 2:14 PM, Patrice CHOTARD wrote:
> Hi Patrick
> 
> On 2/25/21 1:37 PM, Patrick Delaunay wrote:
>> The command "stm32prog serial <dev>" can directly use the device sequence
>> number of serial uclass as this sequence number is egual to alias when it
>> exist; this assumption simplify the code and avoid access to gd->fdt_blob
>> and the device tree parsing.
>>
>> Signed-off-by: Patrick Delaunay <patrick.delaunay@foss.st.com>
>> ---
>>
>>  .../cmd_stm32prog/stm32prog_serial.c          | 29 ++++---------------
>>  arch/arm/mach-stm32mp/cpu.c                   | 11 +++----
>>  2 files changed, 10 insertions(+), 30 deletions(-)
>>
>> diff --git a/arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog_serial.c b/arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog_serial.c
>> index 373ca20886..a51e5e3ec8 100644
>> --- a/arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog_serial.c
>> +++ b/arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog_serial.c
>> @@ -187,36 +187,19 @@ static int stm32prog_read(struct stm32prog_data *data, u8 phase, u32 offset,
>>  int stm32prog_serial_init(struct stm32prog_data *data, int link_dev)
>>  {
>>  	struct udevice *dev = NULL;
>> -	int node;
>> -	char alias[10];
>> -	const char *path;
>>  	struct dm_serial_ops *ops;
>>  	/* no parity, 8 bits, 1 stop */
>>  	u32 serial_config = SERIAL_DEFAULT_CONFIG;
>>  
>>  	down_serial_dev = NULL;
>>  
>> -	sprintf(alias, "serial%d", link_dev);
>> -	path = fdt_get_alias(gd->fdt_blob, alias);
>> -	if (!path) {
>> -		log_err("%s alias not found", alias);
>> -		return -ENODEV;
>> -	}
>> -	node = fdt_path_offset(gd->fdt_blob, path);
>> -	if (!uclass_get_device_by_of_offset(UCLASS_SERIAL, node,
>> -					    &dev)) {
>> -		down_serial_dev = dev;
>> -	} else if (node > 0 &&
>> -		   !lists_bind_fdt(gd->dm_root, offset_to_ofnode(node),
>> -				   &dev, false)) {
>> -		if (!device_probe(dev))
>> -			down_serial_dev = dev;
>> -	}
>> -	if (!down_serial_dev) {
>> -		log_err("%s = %s device not found", alias, path);
>> +	if (uclass_get_device_by_seq(UCLASS_SERIAL, link_dev, &dev)) {
>> +		log_err("serial %d device not found\n", link_dev);
>>  		return -ENODEV;
>>  	}
>>  
>> +	down_serial_dev = dev;
>> +
>>  	/* force silent console on uart only when used */
>>  	if (gd->cur_serial_dev == down_serial_dev)
>>  		gd->flags |= GD_FLG_DISABLE_CONSOLE | GD_FLG_SILENT;
>> @@ -226,11 +209,11 @@ int stm32prog_serial_init(struct stm32prog_data *data, int link_dev)
>>  	ops = serial_get_ops(down_serial_dev);
>>  
>>  	if (!ops) {
>> -		log_err("%s = %s missing ops", alias, path);
>> +		log_err("serial %d = %s missing ops\n", link_dev, dev->name);
>>  		return -ENODEV;
>>  	}
>>  	if (!ops->setconfig) {
>> -		log_err("%s = %s missing setconfig", alias, path);
>> +		log_err("serial %d = %s missing setconfig\n", link_dev, dev->name);
>>  		return -ENODEV;
>>  	}
>>  
>> diff --git a/arch/arm/mach-stm32mp/cpu.c b/arch/arm/mach-stm32mp/cpu.c
>> index 527b6290de..9a76b5633b 100644
>> --- a/arch/arm/mach-stm32mp/cpu.c
>> +++ b/arch/arm/mach-stm32mp/cpu.c
>> @@ -466,7 +466,6 @@ static void setup_boot_mode(void)
>>  	unsigned int instance = (boot_mode & TAMP_BOOT_INSTANCE_MASK) - 1;
>>  	u32 forced_mode = (boot_ctx & TAMP_BOOT_FORCED_MASK);
>>  	struct udevice *dev;
>> -	int alias;
>>  
>>  	log_debug("%s: boot_ctx=0x%x => boot_mode=%x, instance=%d forced=%x\n",
>>  		  __func__, boot_ctx, boot_mode, instance, forced_mode);
>> @@ -474,20 +473,18 @@ static void setup_boot_mode(void)
>>  	case BOOT_SERIAL_UART:
>>  		if (instance > ARRAY_SIZE(serial_addr))
>>  			break;
>> -		/* serial : search associated alias in devicetree */
>> +		/* serial : search associated node in devicetree */
>>  		sprintf(cmd, "serial@%x", serial_addr[instance]);
>> -		if (uclass_get_device_by_name(UCLASS_SERIAL, cmd, &dev) ||
>> -		    fdtdec_get_alias_seq(gd->fdt_blob, "serial",
>> -					 dev_of_offset(dev), &alias)) {
>> +		if (uclass_get_device_by_name(UCLASS_SERIAL, cmd, &dev)) {
>>  			/* restore console on error */
>>  			if (IS_ENABLED(CONFIG_CMD_STM32PROG_SERIAL))
>>  				gd->flags &= ~(GD_FLG_SILENT |
>>  					       GD_FLG_DISABLE_CONSOLE);
>> -			printf("serial%d = %s not found in device tree!\n",
>> +			printf("uart%d = %s not found in device tree!\n",
>>  			       instance, cmd);
>>  			break;
>>  		}
>> -		sprintf(cmd, "%d", alias);
>> +		sprintf(cmd, "%d", dev_seq(dev));
>>  		env_set("boot_device", "serial");
>>  		env_set("boot_instance", cmd);
>>  
>>
> 
> Reviewed-by: Patrice Chotard <patrice.chotard@foss.st.com>
> 
> Thanks
> Patrice
> 
Applied to u-boot-stm/next

Thanks

Patrice
diff mbox series

Patch

diff --git a/arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog_serial.c b/arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog_serial.c
index 373ca20886..a51e5e3ec8 100644
--- a/arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog_serial.c
+++ b/arch/arm/mach-stm32mp/cmd_stm32prog/stm32prog_serial.c
@@ -187,36 +187,19 @@  static int stm32prog_read(struct stm32prog_data *data, u8 phase, u32 offset,
 int stm32prog_serial_init(struct stm32prog_data *data, int link_dev)
 {
 	struct udevice *dev = NULL;
-	int node;
-	char alias[10];
-	const char *path;
 	struct dm_serial_ops *ops;
 	/* no parity, 8 bits, 1 stop */
 	u32 serial_config = SERIAL_DEFAULT_CONFIG;
 
 	down_serial_dev = NULL;
 
-	sprintf(alias, "serial%d", link_dev);
-	path = fdt_get_alias(gd->fdt_blob, alias);
-	if (!path) {
-		log_err("%s alias not found", alias);
-		return -ENODEV;
-	}
-	node = fdt_path_offset(gd->fdt_blob, path);
-	if (!uclass_get_device_by_of_offset(UCLASS_SERIAL, node,
-					    &dev)) {
-		down_serial_dev = dev;
-	} else if (node > 0 &&
-		   !lists_bind_fdt(gd->dm_root, offset_to_ofnode(node),
-				   &dev, false)) {
-		if (!device_probe(dev))
-			down_serial_dev = dev;
-	}
-	if (!down_serial_dev) {
-		log_err("%s = %s device not found", alias, path);
+	if (uclass_get_device_by_seq(UCLASS_SERIAL, link_dev, &dev)) {
+		log_err("serial %d device not found\n", link_dev);
 		return -ENODEV;
 	}
 
+	down_serial_dev = dev;
+
 	/* force silent console on uart only when used */
 	if (gd->cur_serial_dev == down_serial_dev)
 		gd->flags |= GD_FLG_DISABLE_CONSOLE | GD_FLG_SILENT;
@@ -226,11 +209,11 @@  int stm32prog_serial_init(struct stm32prog_data *data, int link_dev)
 	ops = serial_get_ops(down_serial_dev);
 
 	if (!ops) {
-		log_err("%s = %s missing ops", alias, path);
+		log_err("serial %d = %s missing ops\n", link_dev, dev->name);
 		return -ENODEV;
 	}
 	if (!ops->setconfig) {
-		log_err("%s = %s missing setconfig", alias, path);
+		log_err("serial %d = %s missing setconfig\n", link_dev, dev->name);
 		return -ENODEV;
 	}
 
diff --git a/arch/arm/mach-stm32mp/cpu.c b/arch/arm/mach-stm32mp/cpu.c
index 527b6290de..9a76b5633b 100644
--- a/arch/arm/mach-stm32mp/cpu.c
+++ b/arch/arm/mach-stm32mp/cpu.c
@@ -466,7 +466,6 @@  static void setup_boot_mode(void)
 	unsigned int instance = (boot_mode & TAMP_BOOT_INSTANCE_MASK) - 1;
 	u32 forced_mode = (boot_ctx & TAMP_BOOT_FORCED_MASK);
 	struct udevice *dev;
-	int alias;
 
 	log_debug("%s: boot_ctx=0x%x => boot_mode=%x, instance=%d forced=%x\n",
 		  __func__, boot_ctx, boot_mode, instance, forced_mode);
@@ -474,20 +473,18 @@  static void setup_boot_mode(void)
 	case BOOT_SERIAL_UART:
 		if (instance > ARRAY_SIZE(serial_addr))
 			break;
-		/* serial : search associated alias in devicetree */
+		/* serial : search associated node in devicetree */
 		sprintf(cmd, "serial@%x", serial_addr[instance]);
-		if (uclass_get_device_by_name(UCLASS_SERIAL, cmd, &dev) ||
-		    fdtdec_get_alias_seq(gd->fdt_blob, "serial",
-					 dev_of_offset(dev), &alias)) {
+		if (uclass_get_device_by_name(UCLASS_SERIAL, cmd, &dev)) {
 			/* restore console on error */
 			if (IS_ENABLED(CONFIG_CMD_STM32PROG_SERIAL))
 				gd->flags &= ~(GD_FLG_SILENT |
 					       GD_FLG_DISABLE_CONSOLE);
-			printf("serial%d = %s not found in device tree!\n",
+			printf("uart%d = %s not found in device tree!\n",
 			       instance, cmd);
 			break;
 		}
-		sprintf(cmd, "%d", alias);
+		sprintf(cmd, "%d", dev_seq(dev));
 		env_set("boot_device", "serial");
 		env_set("boot_instance", cmd);