From mboxrd@z Thu Jan 1 00:00:00 1970 From: Reinhard Meyer Date: Mon, 04 Oct 2010 16:58:16 +0200 Subject: [U-Boot] AT91 clock and timer cleanups In-Reply-To: <4CA99A63.402@emk-elektronik.de> References: <4CA49746.2050301@emk-elektronik.de> <4CA4AEFF.3050101@denx.de> <20100930174308.070ECD2B48C@gemini.denx.de> <4CA570D3.9040406@denx.de> <4CA57468.6090702@free.fr> <4CA57762.3000201@denx.de> <4CA5821E.3070108@emk-elektronik.de> <4CA5873B.6040907@free.fr> <4CA590E6.6070701@emk-elektronik.de> <4CA59B89.6090207@denx.de> <4CA5BB7A.8050304@emk-elektronik.de> <20101001105506.A64D41539A0@gemini.denx.de> <4CA5BFEF.3090208@emk-elektronik.de> <20101001112125.4076E153A7E@gemini.denx.de> <4CA5C7DE.6010300@emk-elektronik.de> <20101001115908.A34411539A0@gemini.denx.de> <4CA5D26D.2090505@emk-elektronik.de> <20101001124946.7DE29153A7E@gemini.denx.de> <4CA5F4CE.8050002@emk-elektronik.de> <4CA985DC.4000208@emk-elektronik.de> <20101004083231.508F51539A0@gemini.denx.de> <4CA99373.7020704@emk-elektronik.de> <20101004084945.C99DE153A7E@gemini.denx.de> <4CA995D7.5010008@emk-elektronik.de> <20101004090325.87A921539A0@gemini.denx.de> <4CA99A63.402@emk-elektronik.de> Message-ID: <4CA9EB88.5000203@emk-elektronik.de> List-Id: MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit To: u-boot@lists.denx.de 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