Re: [PATCH v2 06/16] ARM: at91: import lowlevel clock initialization from at91bootstrap

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Tue, Feb 19, 2019 at 06:21:40PM +0100, Ahmad Fatoum wrote:
> For use by future at91 first stage bootloaders, this commit imports
> https://github.com/linux4sam/at91bootstrap/blob/v3.8.12/driver/pmc.c
> 
> Signed-off-by: Ahmad Fatoum <a.fatoum@xxxxxxxxxxxxxx>
> ---
>  arch/arm/mach-at91/Makefile                   |   1 +
>  .../include/mach/at91_lowlevel_clock.h        |  43 +++++
>  arch/arm/mach-at91/include/mach/at91_pmc.h    |  16 +-
>  arch/arm/mach-at91/lowlevel_clock.c           | 174 ++++++++++++++++++
>  4 files changed, 233 insertions(+), 1 deletion(-)
>  create mode 100644 arch/arm/mach-at91/include/mach/at91_lowlevel_clock.h
>  create mode 100644 arch/arm/mach-at91/lowlevel_clock.c
> 
> +void at91_lowlevel_clock_init(void __iomem *pmc_base)
> +{
> +	u32 tmp;
> +
> +	/*
> +	 * Switch the master clock to the slow clock without modifying other
> +	 * parameters. It is assumed that ROM code set H32MXDIV, PLLADIV2,
> +	 * PCK_DIV3.
> +	 */
> +	tmp = at91_pmc_read(AT91_PMC_MCKR);
> +	tmp &= ~AT91_PMC_ALT_PCKR_CSS;
> +	tmp |= AT91_PMC_CSS_SLOW;
> +	at91_pmc_write(AT91_PMC_MCKR, tmp);
> +
> +	while (!(at91_pmc_read(AT91_PMC_SR) & AT91_PMC_MCKRDY))
> +		;
> +
> +	if (IS_ENABLED(CONFIG_SOC_AT91SAM9X5) || IS_ENABLED(CONFIG_SOC_AT91SAM9N12)
> +	   || IS_ENABLED(CONFIG_SOC_SAMA5)) {

This doesn't work as expected. Consider a case where multiple SoCs are
selected then you can't decide at build time which code path to choose.

The trick is to move away from at91_lowlevel_clock_init() and create
multiple SoC specific functions in which you do the right stuff for each
SoC. The caller always knows the SoC type we are running on and thus
which function to call.

> +void at91_pmc_cfg_mck(void __iomem *pmc_base, u32 pmc_mckr)
> +{
> +	u32 tmp;
> +
> +	/*
> +	 * Program the PRES field in the AT91_PMC_MCKR register
> +	 */
> +	tmp = at91_pmc_read(AT91_PMC_MCKR);
> +	tmp &= ~(0x1 << 13);
> +	if (IS_ENABLED(CONFIG_SOC_AT91SAM9X5)
> +	    || IS_ENABLED(CONFIG_SOC_AT91SAM9N12)
> +	    || IS_ENABLED(CONFIG_SOC_SAMA5)) {
> +		tmp &= ~AT91_PMC_ALT_PRES;
> +		tmp |= pmc_mckr & AT91_PMC_ALT_PRES;
> +	} else {
> +		tmp &= ~AT91_PMC_PRES;
> +		tmp |= pmc_mckr & AT91_PMC_PRES;
> +	}

Same here.

Sascha

-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@xxxxxxxxxxxxxxxxxxx
http://lists.infradead.org/mailman/listinfo/barebox



[Index of Archives]     [Linux Embedded]     [Linux USB Devel]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]

  Powered by Linux