Linux clock子系统是什么

clock子系统linux的时钟子系统由ccf(common clock framework)框架管理, ccf向上给用户提供了通用的时钟接口,向下给驱动开发者提供硬件操作的接口 。各结构体关系如下:
ccf框架比较简单,只有这几个结构体。ccf框架分为了consumer、ccf和provider三部分。
consumer :
时钟的使用者,clock子系统向consumer的提供通用的时钟api接口,使其可以屏蔽底层硬件差异。提供给consumer操作的api如下:
struct clk *clk_get(struct device *dev, const char *id);struct clk *devm_clk_get(struct device *dev, const char *id);int clk_enable(struct clk *clk);//使能时钟,不会睡眠void clk_disable(struct clk *clk);//使能时钟,不会睡眠unsigned long clk_get_rate(struct clk *clk);void clk_put(struct clk *clk);long clk_round_rate(struct clk *clk, unsigned long rate);int clk_set_rate(struct clk *clk, unsigned long rate);int clk_set_parent(struct clk *clk, struct clk *parent);struct clk *clk_get_parent(struct clk *clk);int clk_prepare(struct clk *clk);void clk_unprepare(struct clk *clk);int clk_prepare_enable(struct clk *clk) //使能时钟,可能会睡眠void clk_disable_unprepare(struct clk *clk) //禁止时钟,可能会睡眠unsigned long clk_get_rate(struct clk *clk) //获取时钟频率consumer在使用这些api时,必须先调用devm_clk_get()或clk_get()获取一个struct clk *指针句柄,后续都通过传入该句柄来操作,struct clk相当于实例化一个时钟。
ccf :
clock子系统的核心,用一个struct clk_core结构体表示,每个注册设备都对应一个struct clk_core。
provider(时钟的提供者) :
struct clk_hw:表示一个具体的硬件时钟。
struct clk_init_data:struct clk_hw结构体成员,用于表示该时钟下的初始化数据,如时钟名字name、操作函数ops等。
// include/linux/clk-provider.hstruct clk_hw{ struct clk_core *core; struct clk *clk; const struct clk_init_data *init;}struct clk_init_data{ const char *name; //时钟名字 const struct clk_ops *ops; //时钟硬件操作函数集合 const char *const *parent_names; //父时钟名字 const struct clk_parent_data *parent_data; const struct clk_hw **parent_hws; u8 num_parents; unsigned long flags;}struct clk_ops:时钟硬件操作的函数集合,定义了操作硬件的回调函数,consumer在调用clk_set_rate()等api时会调用到struct clk_ops具体指向的函数,这个需要芯片厂商开发clock驱动时去实现。
//include/linux/clk-provider.hstruct clk_ops { int (*prepare)(struct clk_hw *hw); void (*unprepare)(struct clk_hw *hw); int (*is_prepared)(struct clk_hw *hw); void (*unprepare_unused)(struct clk_hw *hw); int (*enable)(struct clk_hw *hw); void (*disable)(struct clk_hw *hw); int (*is_enabled)(struct clk_hw *hw); void (*disable_unused)(struct clk_hw *hw); int (*save_context)(struct clk_hw *hw); void (*restore_context)(struct clk_hw *hw); unsigned long (*recalc_rate)(struct clk_hw *hw, unsigned long parent_rate); long (*round_rate)(struct clk_hw *hw, unsigned long rate, unsigned long *parent_rate); int (*determine_rate)(struct clk_hw *hw, struct clk_rate_request *req); int (*set_parent)(struct clk_hw *hw, u8 index); u8 (*get_parent)(struct clk_hw *hw); int (*set_rate)(struct clk_hw *hw, unsigned long rate, unsigned long parent_rate); int (*set_rate_and_parent)(struct clk_hw *hw, unsigned long rate, unsigned long parent_rate, u8 index); unsigned long (*recalc_accuracy)(struct clk_hw *hw, unsigned long parent_accuracy); int (*get_phase)(struct clk_hw *hw); int (*set_phase)(struct clk_hw *hw, int degrees); int (*get_duty_cycle)(struct clk_hw *hw, struct clk_duty *duty); int (*set_duty_cycle)(struct clk_hw *hw, struct clk_duty *duty); int (*init)(struct clk_hw *hw); void (*terminate)(struct clk_hw *hw); void (*debug_init)(struct clk_hw *hw, struct dentry *dentry);};struct clk_ops中每个函数功能在include/linux/clk-provider.h都有具体的说明,在开发clock驱动时,这些函数并不需要全部实现。

中国5G发展已取得明显成效并具备了商用的现实基础
助力上海城市数字化转型体验馆建成落地,罗克韦尔自动化获运营方感谢信
北汽和知豆纯电动汽车这些车的最终归属地在哪里?
阿里二面:了解MySQL事务底层原理吗
6DoF视频分发与呈现中存在的关键问题解析
Linux clock子系统是什么
Vishay发布内置熔丝的低ESR固钽贴片电容器TF3
这个可以有:英特尔与瑞芯微达成战略合作
助力信息安全,富士通展示识别人体掌纹的平板电脑
华为用案例分析5G在各行各业中承担的作用
带你了解12个物联网商业化应用场景
iOS版饿了么使用的开源项目
博通被美国贸易委员会调查 或存在反竞争行为
苹果拟加强汽车医疗移动支付等领域
关于远程医疗行业发展概况趋势以及发展过程中遇到的困难分析详解
LGG6高清拆解图集
基于ffmpeg的推流示例
推拉力测试机也很合适在多个行业中使用
华为鸿蒙系统完成华丽转身,迎来重大更新
创新打造行业领头羊 上海铭控勇攀智能传感器巅峰