clock子系統(tǒng)
Linux的時(shí)鐘子系統(tǒng)由CCF(common clock framework)框架管理, CCF向上給用戶提供了通用的時(shí)鐘接口,向下給驅(qū)動(dòng)開發(fā)者提供硬件操作的接口 。各結(jié)構(gòu)體關(guān)系如下:

CCF框架比較簡單,只有這幾個(gè)結(jié)構(gòu)體。CCF框架分為了consumer、ccf和provider三部分。
consumer :
時(shí)鐘的使用者,clock子系統(tǒng)向consumer的提供通用的時(shí)鐘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);//使能時(shí)鐘,不會(huì)睡眠
void clk_disable(struct clk *clk);//使能時(shí)鐘,不會(huì)睡眠
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) //使能時(shí)鐘,可能會(huì)睡眠
void clk_disable_unprepare(struct clk *clk) //禁止時(shí)鐘,可能會(huì)睡眠
unsigned long clk_get_rate(struct clk *clk) //獲取時(shí)鐘頻率
consumer在使用這些API時(shí),必須先調(diào)用devm_clk_get()或clk_get()獲取一個(gè)struct clk *指針句柄,后續(xù)都通過傳入該句柄來操作,struct clk相當(dāng)于實(shí)例化一個(gè)時(shí)鐘。
ccf :
clock子系統(tǒng)的核心,用一個(gè)struct clk_core結(jié)構(gòu)體表示,每個(gè)注冊(cè)設(shè)備都對(duì)應(yīng)一個(gè)struct clk_core。
provider(時(shí)鐘的提供者) :
struct clk_hw:表示一個(gè)具體的硬件時(shí)鐘。
struct clk_init_data:struct clk_hw結(jié)構(gòu)體成員,用于表示該時(shí)鐘下的初始化數(shù)據(jù),如時(shí)鐘名字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; //時(shí)鐘名字
const struct clk_ops *ops; //時(shí)鐘硬件操作函數(shù)集合
const char *const *parent_names; //父時(shí)鐘名字
const struct clk_parent_data *parent_data;
const struct clk_hw **parent_hws;
u8 num_parents;
unsigned long flags;
}
struct clk_ops:時(shí)鐘硬件操作的函數(shù)集合,定義了操作硬件的回調(diào)函數(shù),consumer在調(diào)用clk_set_rate()等API時(shí)會(huì)調(diào)用到struct clk_ops具體指向的函數(shù),這個(gè)需要芯片廠商開發(fā)clock驅(qū)動(dòng)時(shí)去實(shí)現(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中每個(gè)函數(shù)功能在include/linux/clk-provider.h都有具體的說明,在開發(fā)clock驅(qū)動(dòng)時(shí),這些函數(shù)并不需要全部實(shí)現(xiàn)。
-
接口
+關(guān)注
關(guān)注
33文章
9525瀏覽量
157096 -
Linux
+關(guān)注
關(guān)注
88文章
11767瀏覽量
219100 -
子系統(tǒng)
+關(guān)注
關(guān)注
0文章
116瀏覽量
13509
發(fā)布評(píng)論請(qǐng)先 登錄
Linux下輸入子系統(tǒng)上報(bào)觸摸屏坐標(biāo)
Linux clock子系統(tǒng)及驅(qū)動(dòng)實(shí)例
Linux reset子系統(tǒng)及驅(qū)動(dòng)實(shí)例
如何使用Linux內(nèi)核中的input子系統(tǒng)
基于Linux內(nèi)核輸入子系統(tǒng)的驅(qū)動(dòng)研究
Linux內(nèi)核輸入子系統(tǒng)的驅(qū)動(dòng)研究
Linux時(shí)間子系統(tǒng)之一:clock source(時(shí)鐘源)
詳細(xì)了解Linux設(shè)備模型中的input子系統(tǒng)
Linux系統(tǒng)中NFC子系統(tǒng)架構(gòu)分析
PTP Clock Manager for Linux Message Log 手冊(cè)
PTP Clock Manager for Linux Message Log 手冊(cè)
Linux reset子系統(tǒng)有什么功能
時(shí)鐘子系統(tǒng)中clock驅(qū)動(dòng)實(shí)例
Linux clock子系統(tǒng)是什么
評(píng)論