CLK_OF_DECLARE解析

2154 ワード

Linuxの下でシステムクロックは初期化時にCLK_をよく使うOF_DECLAREというマクロは、6 ulで分析されています.
CLK_OF_DECLARE(imx6ul, "fsl,imx6ul-ccm", imx6ul_clocks_init);

CLK_OF_DECLAREの定義:
#define CLK_OF_DECLARE(name, compat, fn) OF_DECLARE_1(clk, name, compat, fn)

OF_DECLARE_1の定義:
typedef void (*of_init_fn_1)(struct device_node *); //    

#define OF_DECLARE_1(table, name, compat, fn) \
		_OF_DECLARE(table, name, compat, fn, of_init_fn_1)

_OF_DECLAREの定義:
/*
 * Struct used for matching a device
 */
struct of_device_id {
	char	name[32];
	char	type[32];
	char	compatible[128];
	const void *data;
};

#ifdef CONFIG_OF                                        //CONFIG_OF   
#define _OF_DECLARE(table, name, compat, fn, fn_type)			\
	static const struct of_device_id __of_table_##name		\
		__used __section(__##table##_of_table)			\
		 = { .compatible = compat,				\
		     .data = (fn == (fn_type)NULL) ? fn : fn  }
#else
#define _OF_DECLARE(table, name, compat, fn, fn_type)			\
	static const struct of_device_id __of_table_##name		\
		__attribute__((unused))					\
		 = { .compatible = compat,				\
		     .data = (fn == (fn_type)NULL) ? fn : fn }
#endif


      struct of_device_id       

CONFIG_を定義した場合OF、struct of_device_id変数を__に置くclk_of_tableの下;
__clk_of_tableはclkにあります.cファイルの下のof_clk_Init()関数で呼び出されます.
void __init of_clk_init(const struct of_device_id *matches)
{
.......
	if (!matches)
		matches = &__clk_of_table;
.......
}


of_clk_initは./arch/arm/kernel/time.c:121:           of_clk_init(NULL); time_Init()関数で呼び出されます.

void __init time_init(void)
{
        if (machine_desc->init_time) {
                machine_desc->init_time();
        } else {
#ifdef CONFIG_COMMON_CLK
                of_clk_init(NULL);
#endif
                clocksource_of_init();
        }
}

time_initはstart_kernel()関数で呼び出されます./init/main.c:587:      time_init();

asmlinkage __visible void __init start_kernel(void)
{
    ............
    time_init();
    ............
}