0
  • 聊天消息
  • 系统消息
  • 评论与回复
登录后你可以
  • 下载海量资料
  • 学习在线课程
  • 观看技术视频
  • 写文章/发帖/加入社区
会员中心
创作中心

完善资料让更多小伙伴认识你,还能领取20积分哦,立即完善>

3天内不再提示

Linux clock子系统是什么

麦辣鸡腿堡 来源:嵌入式Linux充电站 作者:Vincent 2023-09-27 14:25 次阅读

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.h
struct 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.h

struct 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驱动时,这些函数并不需要全部实现。

声明:本文内容及配图由入驻作者撰写或者入驻合作网站授权转载。文章观点仅代表作者本人,不代表电子发烧友网立场。文章及其配图仅供工程师学习之用,如有内容侵权或者其他违规问题,请联系本站处理。 举报投诉
  • 接口
    +关注

    关注

    33

    文章

    7957

    浏览量

    149207
  • Linux
    +关注

    关注

    87

    文章

    11028

    浏览量

    207231
  • 子系统
    +关注

    关注

    0

    文章

    102

    浏览量

    12299
收藏 人收藏

    评论

    相关推荐

    Linux下输入子系统上报触摸屏坐标

      在 Linux 中,输入子系统是由输入子系统设备驱动层、输入子系统核心层(Input Core)和输入子系统事件处理层(Event Ha
    的头像 发表于 09-25 08:56 1962次阅读
    <b class='flag-5'>Linux</b>下输入<b class='flag-5'>子系统</b>上报触摸屏坐标

    Linux clock子系统及驱动实例

    Linux驱动中,操作时钟只需要简单调用内核提供的通用接口即可,clock驱动通常是由芯片厂商开发的,在Linux启动时clock驱动就已经初始化完成。
    发表于 05-31 16:10 547次阅读
    <b class='flag-5'>Linux</b> <b class='flag-5'>clock</b><b class='flag-5'>子系统</b>及驱动实例

    Linux reset子系统及驱动实例

    上篇讲了Linux clock驱动,今天说说Linux的reset驱动。
    发表于 05-31 16:16 704次阅读
    <b class='flag-5'>Linux</b> reset<b class='flag-5'>子系统</b>及驱动实例

    Linux LED子系统详解

    Linux LED子系统详解
    的头像 发表于 06-10 10:37 1132次阅读
    <b class='flag-5'>Linux</b> LED<b class='flag-5'>子系统</b>详解

    Windows10内置Linux子系统使用

    周围的同学都已经用win10内置的Linux子系统了,在坚持过几个Linux实验后,我也怀着好奇心试了一把。
    发表于 07-26 07:10

    如何使用Linux内核中的input子系统

    的 input 子系统下提供的 API 函数接口,完成设备的注册即可。在本章节中我们来学习一下如何使用 Linux内核中的 input 子系统
    发表于 12-29 07:20

    基于Linux内核输入子系统的驱动研究

    Linux因其完全开放的特性和稳定优良的性能深受欢迎,当推出了内核输入子系统后,更方便了嵌入式领域的驱动开放。介绍了Linux的设备驱动基础,详细阐述了基于Linux内核输入
    发表于 09-12 16:38 23次下载

    Linux内核输入子系统的驱动研究

    Linux内核输入子系统的驱动研究
    发表于 10-31 14:41 14次下载
    <b class='flag-5'>Linux</b>内核输入<b class='flag-5'>子系统</b>的驱动研究

    Linux时间子系统之一:clock source(时钟源)

    clock source用于为linux内核提供一个时间基线,如果你用linux的date命令获取当前时间,内核会读取当前的clock source,转换并返回合适的时间单位给用户空间
    发表于 05-10 14:36 1759次阅读

    详细了解Linux设备模型中的input子系统

    linux输入子系统linux input subsystem)从上到下由三层实现,分别为:输入子系统事件处理层(EventHandler)、输入
    发表于 05-12 09:04 969次阅读
    详细了解<b class='flag-5'>Linux</b>设备模型中的input<b class='flag-5'>子系统</b>

    Windows 子系统助力 Linux 2.0

    Windows 子系统助力 Linux 2.0
    的头像 发表于 01-04 11:17 465次阅读

    Linux系统中NFC子系统架构分析

    目前在Linux系统中,每个厂家都使用不同的方式实现NFC驱动,然后自己在应用层上面做适配。但是Linux也已经推出NFC子系统,很多厂家也逐步在统一。
    发表于 01-04 14:01 1553次阅读

    Linux内核之LED子系统(一)

    Linux内核的LED子系统是一种重要的框架,用于管理和控制设备上的LED指示灯。在嵌入式系统和物联网设备中,LED子系统发挥着关键作用,为开发者提供了一种统一的方式来控制和定制LED
    发表于 10-02 16:53 452次阅读
    <b class='flag-5'>Linux</b>内核之LED<b class='flag-5'>子系统</b>(一)

    Linux reset子系统有什么功能

    Linux reset子系统 reset子系统非常简单,与clock子系统非常类似,但在驱动实现上,reset驱动更简单。 因为
    的头像 发表于 09-27 14:06 445次阅读
    <b class='flag-5'>Linux</b> reset<b class='flag-5'>子系统</b>有什么功能

    时钟子系统clock驱动实例

    clock驱动实例 clock驱动在时钟子系统中属于provider,provider是时钟的提供者,即具体的clock驱动。 clock
    的头像 发表于 09-27 14:39 534次阅读
    时钟<b class='flag-5'>子系统</b>中<b class='flag-5'>clock</b>驱动实例