以Freesclae的i.MX51为基础进行分析。
先分析下面的代码:
arch/arm/kernel/setup.c
extern struct sys_timer *system_timer;
672 void __init setup_arch(char **cmdline_p)
673 {
...
675 struct machine_desc *mdesc;
...
681 mdesc = setup_machine(machine_arch_type);
...
741 system_timer = mdesc->timer;
...
752 }
arch/arm/kernel/time.c
161 void __init time_init(void)
162 {
163 system_timer->init();
164 }
init/main.c
539 asmlinkage void __init start_kernel(void)
{
...
573 setup_arch(&command_line);
...
623 time_init();
...
}
arch/arm/mach-mx5/mx51_babbage.c
1367 static void __init mx51_babbage_timer_init(void)
1368 {
...
1378 mx51_clocks_init(32768, 24000000, 22579200, 24576000);
...
1382 }
1384 static struct sys_timer mxc_timer = {
1385 .init = mx51_babbage_timer_init,
1386 };
1470 MACHINE_START(MX51_BABBAGE, "Freescale MX51 Babbage Board")
..
1482 .timer = &mxc_timer,
1483 MACHINE_END
在arch/arm/mach-mx5/mx51_babbage.c中完成对结构体struct machine_desc *中timer成员的赋值。
在内核初始化的时候执行start_kernel(),该函数先调用setup_arch(),完成对system_timer的赋值。再后执行time_init(),最终执行mx51_babbage_timer_init()函数,完成对i.MX51的clocks的初始化。