CLK_OF_DECLARE 解析

Linux下系统时钟在初始化时经常用到 CLK_OF_DECLARE 这个宏,现在以 6ul为列做分析:

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();
    ............
}

  • 0
    点赞
  • 4
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值