[Galaxy Y GT-S5360 Android Development] ZakooZ:
I used this post to dump information I was getting and save it in somewhere that is not in the middle of thousands of lines of code... So It's a bit messy

I've been doing some searching and it looks like all thing referencing find_n_m() are only defined and never actually used to set any frequencies... So I don't know if that's the way to go... It may still use n and m values but calculated elsewhere

bcm21553_arm11_set_rate() and bcm21553_arm11_round_rate()

People have been using these for frequencies for a long time, it works for 156mhz and 624mhz which is interesting... Why wouldn't it work for freqs over 832mhz?

bcm21553_arm11_set_rate() imports a *clk pointer but never uses it... All it does is set the mode for the frequency with bcm215xx_set_armahb_mode()... I'm not discussing it now as im inspecting other parts

bcm21553_arm11_round_rate(clk *clk, long desired_val) also imports *clk but never uses it. It returns bcm21553_generic_round_rate(desired_val,arm11_freq,2);

I don't know where they get desired_val, but that's important for the return

arm11_freq is the frequencies developers defined

2 is the count of arm11_freq arrays... could use sizeof(arm11_freq)/sizeof(u32) i suppose

int bcm21553_arm11_set_rate(struct clk *clk, unsigned long val)
{
u32 mode;
u32 arm11_freq[2];
u32 apps_pll_freq = bcm21553_apps_pll_get_rate();

arm11_freq[0] = FREQ_MHZ(312);
arm11_freq[1] = (apps_pll_freq*2)/3;

/*we support only two modes - 0xC & 0xF*/
if (val == arm11_freq[0])
{
mode = 0x0C;
}
else if (val == arm11_freq[1])
{
mode = 0x0F;
} else
{
return -EINVAL;
}
//writel(mode, ADDR_CLKPWR_CLK_ARMAHB_MODE);
bcm215xx_set_armahb_mode(mode);
return 0;
}

long bcm21553_arm11_round_rate(struct clk *clk, unsigned long desired_val)
{
u32 arm11_freq[2];
u32 apps_pll_freq = bcm21553_apps_pll_get_rate();

/*we support only two freq - 312Mhz & appPll/1.5*/
arm11_freq[0] = FREQ_MHZ(312);
arm11_freq[1] = (apps_pll_freq*2)/3;

return (long)bcm21553_generic_round_rate(desired_val,
arm11_freq,
2);
}

u32 bcm21553_generic_round_rate(u32 desired_val, const u32 *supportedFreqList,
u8 count)
{
u32 i = 0;
const u32 *ppossible_freqs = supportedFreqList;
u32 closest_freq = 0xFFFFFFFF;	/* Set it to some highest value. */
u32 greatest_freq_in_array = 0;

while (i < count) {
if (desired_val == *ppossible_freqs) {
return desired_val;
} else {
if ((*ppossible_freqs > desired_val)
&& (*ppossible_freqs <= closest_freq)) {
closest_freq = *ppossible_freqs;
}
if (*ppossible_freqs > greatest_freq_in_array) {
greatest_freq_in_array = *ppossible_freqs;
}
}
i++;
ppossible_freqs++;
}

/* This means that desired_val is greater than the maximum possible values */
if (closest_freq == 0xFFFFFFFF) {
/* This means the desired_val is greater than the greatest element */
/* So lets return with the greatest freq in array. */
return greatest_freq_in_array;
} else {
return closest_freq;
}
}

It seems that people are just giving a list of the supported frequencies, but those are not the desired frequency that this last function tries to search for... maybe it wont search for anything higher than 832mhz, it will always return something lower

Meanwhile arm11_set_rate doesn't seem to be connected to this at all, and arm11_round_rate seems to be returning the frequencies to some place that gives them a desired frequency

Anyway I can't seem to find any implementation of bcm215xx_set_armahb_mode(), only a "extern void bcm215xx_set_armahb_mode(u32 mode);" line Looks like it's implemented in Assembly! Fun! Either that is normal for low level stuff or broadcom wants to "encrypt" us out of how this works

I'll edit this post later because at the moment I don't feel like looking at this :rolleyes: