[U-Boot] [PATCH] Move ICS CLK chip frequenty calculation code into a common board library

Timur Tabi
2010-05-21T15:57:07Z

On Fri, May 21, 2010 at 4:18 AM, Kumar Gala <galak@kernel.crashing.org> wrote:

> +#ifdef CONFIG_FSL_NGPIXIS
> +#include "ngpixis.h"
> +#define PIXIS_VSYSCLK0 ? ? ? ? offsetof(struct ngpixis, sclk[0])
> +#define PIXIS_VSYSCLK1 ? ? ? ? offsetof(struct ngpixis, sclk[1])
> +#define PIXIS_VSYSCLK2 ? ? ? ? offsetof(struct ngpixis, sclk[2])
> +#define PIXIS_VDDRCLK0 ? ? ? ? offsetof(struct ngpixis, dclk[0])
> +#define PIXIS_VDDRCLK1 ? ? ? ? offsetof(struct ngpixis, dclk[1])
> +#define PIXIS_VDDRCLK2 ? ? ? ? offsetof(struct ngpixis, dclk[2])
> +#endif

Yuck. I specifically created the ngpixis_t structure because Wolfgang
objected to the use of macros for offsets.

But I understand why you did it. It's the easiest way to maintain
compatibility between pixis and ngpixis.

> +/* decode S[0-2] to Output Divider (OD) */
> +static unsigned char ics307_s_to_od[] = {
> + ? ? ? 10, 2, 8, 4, 5, 7, 3, 6
> +};

Can you make this a u8 instead?

> +static unsigned long
> +ics307_clk_freq(unsigned char cw0, unsigned char cw1, unsigned char cw2)

u8's here, also. You might then be able to make this one line.

> +{
> + ? ? ? const unsigned long input_freq = CONFIG_ICS307_REFCLK_HZ;
> + ? ? ? unsigned long VDW = ((cw1 << 1) & 0x1FE) + ((cw2 >> 7) & 1);
> + ? ? ? unsigned long RDW = cw2 & 0x7F;
> + ? ? ? unsigned long OD = ics307_s_to_od[cw0 & 0x7];
> + ? ? ? unsigned long freq;

Wolfgang just asked me not to use camel caps.

> +#ifndef __ASSEMBLY__
> +extern unsigned long get_board_sys_clk(void);
> +extern unsigned long get_board_ddr_clk(void);
> +#endif

I don't think we need the "#ifndef __ASSEMBLY__" here.

--
Timur Tabi
Linux kernel developer at Freescale