[U-Boot] [PATCH] arm: imx8: factor out uart init code

Peng Fan peng.fan at nxp.com
Tue Jun 11 08:35:09 UTC 2019


> Subject: [PATCH] arm: imx8: factor out uart init code
> 
> New imx8 boards started adding duplicated UART init code.
> Factor out this to common function sc_pm_setup_uart().
> 
> Signed-off-by: Anatolij Gustschin <agust at denx.de>
> Cc: Peng Fan <peng.fan at nxp.com>
> ---
>  arch/arm/include/asm/arch-imx8/sys_proto.h |  2 ++
>  arch/arm/mach-imx/imx8/Makefile            |  2 +-
>  arch/arm/mach-imx/imx8/misc.c              | 26
> ++++++++++++++++++++++
>  board/freescale/imx8qm_mek/imx8qm_mek.c    | 16 +++----------
>  board/freescale/imx8qxp_mek/imx8qxp_mek.c  | 16 +++----------
>  5 files changed, 35 insertions(+), 27 deletions(-)  create mode 100644
> arch/arm/mach-imx/imx8/misc.c
> 
> diff --git a/arch/arm/include/asm/arch-imx8/sys_proto.h
> b/arch/arm/include/asm/arch-imx8/sys_proto.h
> index 73ffaba7d5..3f5bbe9dcc 100644
> --- a/arch/arm/include/asm/arch-imx8/sys_proto.h
> +++ b/arch/arm/include/asm/arch-imx8/sys_proto.h
> @@ -3,6 +3,7 @@
>   * Copyright 2018 NXP
>   */
> 
> +#include <asm/arch/sci/sci.h>
>  #include <asm/mach-imx/sys_proto.h>
>  #include <linux/types.h>
> 
> @@ -17,3 +18,4 @@ struct pass_over_info_t {
> 
>  enum boot_device get_boot_device(void);  int print_bootinfo(void);
> +int sc_pm_setup_uart(sc_rsrc_t uart_rsrc, sc_pm_clock_rate_t clk_rate);
> diff --git a/arch/arm/mach-imx/imx8/Makefile
> b/arch/arm/mach-imx/imx8/Makefile index 31ad169ccf..92b5c56acb 100644
> --- a/arch/arm/mach-imx/imx8/Makefile
> +++ b/arch/arm/mach-imx/imx8/Makefile
> @@ -4,4 +4,4 @@
>  # SPDX-License-Identifier:	GPL-2.0+
>  #
> 
> -obj-y += cpu.o iomux.o
> +obj-y += cpu.o iomux.o misc.o
> diff --git a/arch/arm/mach-imx/imx8/misc.c
> b/arch/arm/mach-imx/imx8/misc.c new file mode 100644 index
> 0000000000..5fe23d2080
> --- /dev/null
> +++ b/arch/arm/mach-imx/imx8/misc.c
> @@ -0,0 +1,26 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +#include <common.h>
> +#include <asm/arch/sci/sci.h>
> +
> +int sc_pm_setup_uart(sc_rsrc_t uart_rsrc, sc_pm_clock_rate_t clk_rate)
> +{
> +	sc_pm_clock_rate_t rate = clk_rate;
> +	int ret;
> +
> +	/* Power up UARTn */
> +	ret = sc_pm_set_resource_power_mode(-1, uart_rsrc,
> SC_PM_PW_MODE_ON);
> +	if (ret)
> +		return ret;
> +
> +	/* Set UARTn clock root to 'rate' MHz */
> +	ret = sc_pm_set_clock_rate(-1, uart_rsrc, 2, &rate);
> +	if (ret)
> +		return ret;
> +
> +	/* Enable UARTn clock root */
> +	ret = sc_pm_clock_enable(-1, uart_rsrc, 2, true, false);
> +	if (ret)
> +		return ret;
> +
> +	return 0;
> +}
> diff --git a/board/freescale/imx8qm_mek/imx8qm_mek.c
> b/board/freescale/imx8qm_mek/imx8qm_mek.c
> index e69efc4dd6..249c29e0f2 100644
> --- a/board/freescale/imx8qm_mek/imx8qm_mek.c
> +++ b/board/freescale/imx8qm_mek/imx8qm_mek.c
> @@ -34,21 +34,11 @@ static void setup_iomux_uart(void)
> 
>  int board_early_init_f(void)
>  {
> +	sc_pm_clock_rate_t rate = SC_80MHZ;
>  	int ret;
> -	/* Set UART0 clock root to 80 MHz */
> -	sc_pm_clock_rate_t rate = 80000000;
> -
> -	/* Power up UART0 */
> -	ret = sc_pm_set_resource_power_mode(-1, SC_R_UART_0,
> SC_PM_PW_MODE_ON);
> -	if (ret)
> -		return ret;
> 
> -	ret = sc_pm_set_clock_rate(-1, SC_R_UART_0, 2, &rate);
> -	if (ret)
> -		return ret;
> -
> -	/* Enable UART0 clock root */
> -	ret = sc_pm_clock_enable(-1, SC_R_UART_0, 2, true, false);
> +	/* Set UART0 clock root to 80 MHz */
> +	ret = sc_pm_setup_uart(SC_R_UART_0, rate);
>  	if (ret)
>  		return ret;
> 
> diff --git a/board/freescale/imx8qxp_mek/imx8qxp_mek.c
> b/board/freescale/imx8qxp_mek/imx8qxp_mek.c
> index 63cd605b6a..1038f26d69 100644
> --- a/board/freescale/imx8qxp_mek/imx8qxp_mek.c
> +++ b/board/freescale/imx8qxp_mek/imx8qxp_mek.c
> @@ -40,21 +40,11 @@ static void setup_iomux_uart(void)
> 
>  int board_early_init_f(void)
>  {
> +	sc_pm_clock_rate_t rate = SC_80MHZ;
>  	int ret;
> -	/* Set UART0 clock root to 80 MHz */
> -	sc_pm_clock_rate_t rate = 80000000;
> -
> -	/* Power up UART0 */
> -	ret = sc_pm_set_resource_power_mode(-1, SC_R_UART_0,
> SC_PM_PW_MODE_ON);
> -	if (ret)
> -		return ret;
> 
> -	ret = sc_pm_set_clock_rate(-1, SC_R_UART_0, 2, &rate);
> -	if (ret)
> -		return ret;
> -
> -	/* Enable UART0 clock root */
> -	ret = sc_pm_clock_enable(-1, SC_R_UART_0, 2, true, false);
> +	/* Set UART0 clock root to 80 MHz */
> +	ret = sc_pm_setup_uart(SC_R_UART_0, rate);
>  	if (ret)
>  		return ret;
> 

Reviewed-by: Peng Fan <peng.fan at nxp.com>

> --
> 2.17.1



More information about the U-Boot mailing list