[U-Boot] AT91 clock and timer cleanups

Reinhard Meyer u-boot at emk-elektronik.de
Mon Oct 4 16:58:16 CEST 2010


Dear Wolfgang Denk,
> 
> I see the misunderstanding here:
> 
>> It will be needed to replace the "#if defined(CONFIG_AT91SAM9260) ||
>> defined(CONFIG_AT91SAM9XE)" in global_data.h and a ton of similar
>> ocurrences like these:
> 
> That does not exist yet (its only in my local tree so far!)
> 
>> arch/arm/cpu/arm926ejs/at91/clock.c:#if defined(CONFIG_AT91SAM9G45) || defined(CONFIG_AT91SAM9M10G45)
>> arch/arm/cpu/arm926ejs/at91/clock.c:#elif defined(CONFIG_AT91SAM9G45) || defined(CONFIG_AT91SAM9M10G45)

>> Careful here, the ones here are distinguishing between different "family" members!
>> See the abundance of #elif's there!

The actual example code:
#if defined(CONFIG_AT91RM9200)
	/* mdiv */
	gd->mck_rate_hz = freq / (1 + ((mckr & AT91_PMC_MCKR_MDIV_MASK) >> 8));
#elif defined(CONFIG_AT91SAM9G20)
	/* mdiv ; (x >> 7) = ((x >> 8) * 2) */
	gd->mck_rate_hz = (mckr & AT91_PMC_MCKR_MDIV_MASK) ?
		freq / ((mckr & AT91_PMC_MCKR_MDIV_MASK) >> 7) : freq;
	if (mckr & AT91_PMC_MCKR_MDIV_MASK)
		freq /= 2;			/* processor clock division */
#elif defined(CONFIG_AT91SAM9G45) || defined(CONFIG_AT91SAM9M10G45)
	gd->mck_rate_hz = (mckr & AT91_PMC_MCKR_MDIV_MASK) ==
		(AT91_PMC_MCKR_MDIV_2 | AT91_PMC_MCKR_MDIV_4)
		? freq / 3
		: freq / (1 << ((mckr & AT91_PMC_MCKR_MDIV_MASK) >> 8));
#else
	gd->mck_rate_hz = freq / (1 << ((mckr & AT91_PMC_MCKR_MDIV_MASK) >> 8));
#endif

Note: I did not write that code, and I am sure it could be made to look less
obfuscated. But that's not my problem right now.

I looked at common.h which is already overcrowded by arch and even
board specifics. I don't want to add anything there. In my tree I have
solved the issue as follows:

1. The board's config file defines "CONFIG_AT91FAMILY" like this:
/* SoC */
#define CONFIG_ARM926EJS	1	/* ARM926EJS Core	*/
#define	CONFIG_AT91FAMILY	1	/* it's a member of AT91 */
#define CONFIG_AT91SAM9260	1	/* Atmel AT91SAM9260 based SoC */
#define CONFIG_AT91SAM9XE	1	/* more specific: AT91SAM9XE */

2. both at91 clock.c and timer.c contain the statements:
#if !defined(CONFIG_AT91FAMILY)
# error You need to define CONFIG_AT91FAMILY in your board config!
#endif
This will catch all boards that are affected. Since all ARM/AT91 boards
are broken right now anyway and need fixing their config file that
should work fine.

3. arm/global_data.h has now:
...
#endif
#ifdef CONFIG_AT91FAMILY
	/* "static data" needed by at91's clock.c */
 	unsigned long	cpu_clk_rate_hz;
	unsigned long	main_clk_rate_hz;
	unsigned long	mck_rate_hz;
	unsigned long	plla_rate_hz;
	unsigned long	pllb_rate_hz;
	unsigned long	at91_pllb_usb_init;
	/* "static data" needed by at91's timer.c */
	unsigned long	timer_rate_hz;
	unsigned long	tbl;
	unsigned long	tbu;
	unsigned long long	timer_reset_value;
#endif
#if !defined(CONFIG_SYS_ARM_WITHOUT_RELOC)
...

I can now post this as a patch.

Best Regards
Reinhard



More information about the U-Boot mailing list