linux 入口时,在start_kernel()中调用 setup_arch(), 会进行平台体系相关初始化:
- smdk_2440_map_io() --> s3c24xx_init_io() --> s3c_init_cpu() -> s3c244x_init_clocks()
- void __init s3c244x_init_clocks(int xtal)
- {
- /* initialise the clocks here, to allow other things like the
- * console to use them, and to add new ones after the initialisation
- */
- s3c24xx_register_baseclocks(xtal); //向系统注册基本时钟: FCLK,HCLK, PCLK
- s3c244x_setup_clocks(); //设置基本时钟的参数
- s3c2410_baseclk_add(); //添加其他外设的时钟
- }
系统将所有外设的时钟通过一个叫做struct clk的结构体来进行描述:
- struct clk {
- struct list_head list;
- struct module *owner;
- struct clk *parent;
- const char *name;
- int id;
- int usage;
- unsigned long rate;
- unsigned long ctrlbit;
- int (*enable)(struct clk *, int enable);
- int (*set_rate)(struct clk *c, unsigned long rate);
- unsigned long (*get_rate)(struct clk *c);
- unsigned long (*round_rate)(struct clk *c, unsigned long rate);
- int (*set_parent)(struct clk *c, struct clk *parent);
- };
将所有时钟分成两类,一类是开启,一类关闭; 分别至于 两个数组中
- struct clk init_clocks[]; struct clk init_clocks_disable[];
最后一一注册
注册时钟是通过这个函数注册的
- /* initialise the clock system */
- int s3c24xx_register_clock(struct clk *clk)
- {
- if (clk->enable == NULL)
- clk->enable = clk_null_enable;
- /* add to the list of available clocks */
- /* Quick check to see if this clock has already been registered. */
- BUG_ON(clk->list.prev != clk->list.next);
- spin_lock(&clocks_lock);
- list_add(&clk->list, &clocks);
- spin_unlock(&clocks_lock);
- return 0;
- }
