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

Peng Fan peng.fan at nxp.com
Wed Jun 12 12:17:04 UTC 2019


> Subject: [PATCH 1/2] 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>
> Cc: Marcel Ziswiler <marcel.ziswiler at toradex.com>
> Reviewed-by: Peng Fan <peng.fan at nxp.com>
> ---
> Rebased version of patch
> https://eur01.safelinks.protection.outlook.com/?url=http%3A%2F%2Fpatchw
> ork.ozlabs.org%2Fpatch%2F1111283&data=02%7C01%7Cpeng.fan%40n
> xp.com%7C21d6f876a59548128d6608d6ef2a125f%7C686ea1d3bc2b4c6fa92
> cd99c5c301635%7C0%7C0%7C636959361314983172&sdata=94dpwCC
> 1b6cW2ACPFiqz3dE3CO7ingGMB1WVHpWpXWk%3D&reserved=0
> to address apalis-imx8/colibri-imx8x boards.
> 
>  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 +++----------
>  board/toradex/apalis-imx8/apalis-imx8.c     | 17 +++-----------
>  board/toradex/colibri-imx8x/colibri-imx8x.c | 16 +++----------
>  7 files changed, 41 insertions(+), 54 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..fb92362bbf
> --- /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, SC_PM_CLK_PER, &rate);
> +	if (ret)
> +		return ret;
> +
> +	/* Enable UARTn clock root */
> +	ret = sc_pm_clock_enable(-1, uart_rsrc, SC_PM_CLK_PER, 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;
> 
> diff --git a/board/toradex/apalis-imx8/apalis-imx8.c
> b/board/toradex/apalis-imx8/apalis-imx8.c
> index f516e546a8..4243b0e174 100644
> --- a/board/toradex/apalis-imx8/apalis-imx8.c
> +++ b/board/toradex/apalis-imx8/apalis-imx8.c
> @@ -37,22 +37,11 @@ static void setup_iomux_uart(void)
> 
>  int board_early_init_f(void)
>  {
> -	sc_pm_clock_rate_t rate;
> +	sc_pm_clock_rate_t rate = SC_80MHZ;
>  	sc_err_t err = 0;
> 
> -	/* Power up UART1 */
> -	err = sc_pm_set_resource_power_mode(-1, SC_R_UART_1,
> SC_PM_PW_MODE_ON);
> -	if (err != SC_ERR_NONE)
> -		return 0;
> -
> -	/* Set UART3 clock root to 80 MHz */
> -	rate = 80000000;
> -	err = sc_pm_set_clock_rate(-1, SC_R_UART_1, SC_PM_CLK_PER, &rate);
> -	if (err != SC_ERR_NONE)
> -		return 0;
> -
> -	/* Enable UART1 clock root */
> -	err = sc_pm_clock_enable(-1, SC_R_UART_1, SC_PM_CLK_PER, true,
> false);
> +	/* Set UART1 clock root to 80 MHz and enable it */
> +	err = sc_pm_setup_uart(SC_R_UART_1, rate);
>  	if (err != SC_ERR_NONE)
>  		return 0;
> 
> diff --git a/board/toradex/colibri-imx8x/colibri-imx8x.c
> b/board/toradex/colibri-imx8x/colibri-imx8x.c
> index aa8eaa0ea1..a146148556 100644
> --- a/board/toradex/colibri-imx8x/colibri-imx8x.c
> +++ b/board/toradex/colibri-imx8x/colibri-imx8x.c
> @@ -51,19 +51,9 @@ int board_early_init_f(void)
>  	if (err != SC_ERR_NONE)
>  		return 0;
> 
> -	/* Power up UART3 */
> -	err = sc_pm_set_resource_power_mode(-1, SC_R_UART_3,
> SC_PM_PW_MODE_ON);
> -	if (err != SC_ERR_NONE)
> -		return 0;
> -
> -	/* Set UART3 clock root to 80 MHz */
> -	rate = 80000000;
> -	err = sc_pm_set_clock_rate(-1, SC_R_UART_3, SC_PM_CLK_PER, &rate);
> -	if (err != SC_ERR_NONE)
> -		return 0;
> -
> -	/* Enable UART3 clock root */
> -	err = sc_pm_clock_enable(-1, SC_R_UART_3, SC_PM_CLK_PER, true,
> false);
> +	/* Set UART3 clock root to 80 MHz and enable it */
> +	rate = SC_80MHZ;
> +	err = sc_pm_setup_uart(SC_R_UART_3, rate);
>  	if (err != SC_ERR_NONE)
>  		return 0;

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

> 
> --
> 2.17.1



More information about the U-Boot mailing list