clock子系統(tǒng)
Linux的時鐘子系統(tǒng)由CCF(common clock framework)框架管理, CCF向上給用戶提供了通用的時鐘接口,向下給驅(qū)動開發(fā)者提供硬件操作的接口 。各結構體關系如下:
CCF框架比較簡單,只有這幾個結構體。CCF框架分為了consumer、ccf和provider三部分。
consumer :
時鐘的使用者,clock子系統(tǒng)向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時,必須先調(diào)用devm_clk_get()
或clk_get()
獲取一個struct clk *
指針句柄,后續(xù)都通過傳入該句柄來操作,struct clk相當于實例化一個時鐘。
ccf :
clock子系統(tǒng)的核心,用一個struct clk_core
結構體表示,每個注冊設備都對應一個struct clk_core
。
provider(時鐘的提供者) :
struct clk_hw
:表示一個具體的硬件時鐘。
struct clk_init_data
:struct clk_hw結構體成員,用于表示該時鐘下的初始化數(shù)據(jù),如時鐘名字name、操作函數(shù)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; //時鐘硬件操作函數(shù)集合
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
:時鐘硬件操作的函數(shù)集合,定義了操作硬件的回調(diào)函數(shù),consumer在調(diào)用clk_set_rate()
等API時會調(diào)用到struct clk_ops
具體指向的函數(shù),這個需要芯片廠商開發(fā)clock驅(qū)動時去實現(xiàn)。
//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中每個函數(shù)功能在include/linux/clk-provider.h
都有具體的說明,在開發(fā)clock驅(qū)動時,這些函數(shù)并不需要全部實現(xiàn)。
-
接口
+關注
關注
33文章
8949瀏覽量
153218 -
Linux
+關注
關注
87文章
11465瀏覽量
212817 -
子系統(tǒng)
+關注
關注
0文章
115瀏覽量
12677
發(fā)布評論請先 登錄
Linux下輸入子系統(tǒng)上報觸摸屏坐標

Linux clock子系統(tǒng)及驅(qū)動實例

Linux reset子系統(tǒng)及驅(qū)動實例

如何使用Linux內(nèi)核中的input子系統(tǒng)
基于Linux內(nèi)核輸入子系統(tǒng)的驅(qū)動研究
Linux時間子系統(tǒng)之一:clock source(時鐘源)
詳細了解Linux設備模型中的input子系統(tǒng)

Linux系統(tǒng)中NFC子系統(tǒng)架構分析
PTP Clock Manager for Linux Message Log 手冊

PTP Clock Manager for Linux Message Log 手冊

Linux reset子系統(tǒng)有什么功能

時鐘子系統(tǒng)中clock驅(qū)動實例

評論