clock子系統(tǒng)
Linux的時(shí)鐘子系統(tǒng)由CCF(common clock framework)框架管理, CCF向上給用戶提供了通用的時(shí)鐘接口,向下給驅(qū)動(dòng)開(kāi)發(fā)者提供硬件操作的接口 。各結(jié)構(gòu)體關(guān)系如下:
CCF框架比較簡(jiǎn)單,只有這幾個(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ù)都通過(guò)傳入該句柄來(lái)操作,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è)需要芯片廠商開(kāi)發(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
都有具體的說(shuō)明,在開(kāi)發(fā)clock驅(qū)動(dòng)時(shí),這些函數(shù)并不需要全部實(shí)現(xiàn)。
-
接口
+關(guān)注
關(guān)注
33文章
8706瀏覽量
151987 -
Linux
+關(guān)注
關(guān)注
87文章
11350瀏覽量
210476 -
子系統(tǒng)
+關(guān)注
關(guān)注
0文章
110瀏覽量
12462
發(fā)布評(píng)論請(qǐng)先 登錄
相關(guān)推薦
Linux下輸入子系統(tǒng)上報(bào)觸摸屏坐標(biāo)
![<b class='flag-5'>Linux</b>下輸入<b class='flag-5'>子系統(tǒng)</b>上報(bào)觸摸屏坐標(biāo)](https://file.elecfans.com//web2/M00/6C/B4/pYYBAGMuvISABHEGAAUp7Zj3V_s861.png)
Linux clock子系統(tǒng)及驅(qū)動(dòng)實(shí)例
![<b class='flag-5'>Linux</b> <b class='flag-5'>clock</b><b class='flag-5'>子系統(tǒng)</b>及驅(qū)動(dòng)實(shí)例](https://file1.elecfans.com/web2/M00/88/EC/wKgZomR3AEiAHXG0AAOHp2Lqrws775.jpg)
Linux reset子系統(tǒng)及驅(qū)動(dòng)實(shí)例
![<b class='flag-5'>Linux</b> reset<b class='flag-5'>子系統(tǒng)</b>及驅(qū)動(dòng)實(shí)例](https://file1.elecfans.com/web2/M00/88/EB/wKgaomR3AjaAYMjWAAJfgWuA1Ac700.jpg)
如何使用Linux內(nèi)核中的input子系統(tǒng)
基于Linux內(nèi)核輸入子系統(tǒng)的驅(qū)動(dòng)研究
Linux內(nèi)核輸入子系統(tǒng)的驅(qū)動(dòng)研究
![<b class='flag-5'>Linux</b>內(nèi)核輸入<b class='flag-5'>子系統(tǒng)</b>的驅(qū)動(dòng)研究](https://file.elecfans.com/web2/M00/49/3D/poYBAGKhwJKAUdSaAABDpi3RHZo747.png)
Linux時(shí)間子系統(tǒng)之一:clock source(時(shí)鐘源)
詳細(xì)了解Linux設(shè)備模型中的input子系統(tǒng)
![詳細(xì)了解<b class='flag-5'>Linux</b>設(shè)備模型中的input<b class='flag-5'>子系統(tǒng)</b>](https://file.elecfans.com/web1/M00/91/DE/pIYBAFzVPpaAUS9dAAC5ovMfQhA395.png)
Linux系統(tǒng)中NFC子系統(tǒng)架構(gòu)分析
PTP Clock Manager for Linux Message Log 手冊(cè)
![PTP <b class='flag-5'>Clock</b> Manager for <b class='flag-5'>Linux</b> Message Log 手冊(cè)](https://file.elecfans.com/web1/M00/D9/4E/pIYBAF_1ac2Ac0EEAABDkS1IP1s689.png)
PTP Clock Manager for Linux Message Log 手冊(cè)
![PTP <b class='flag-5'>Clock</b> Manager for <b class='flag-5'>Linux</b> Message Log 手冊(cè)](https://file.elecfans.com/web1/M00/D9/4E/pIYBAF_1ac2Ac0EEAABDkS1IP1s689.png)
Linux reset子系統(tǒng)有什么功能
![<b class='flag-5'>Linux</b> reset<b class='flag-5'>子系統(tǒng)</b>有什么功能](https://file1.elecfans.com/web2/M00/88/EB/wKgaomR3AjaAYMjWAAJfgWuA1Ac700.jpg)
時(shí)鐘子系統(tǒng)中clock驅(qū)動(dòng)實(shí)例
![時(shí)鐘<b class='flag-5'>子系統(tǒng)</b>中<b class='flag-5'>clock</b>驅(qū)動(dòng)實(shí)例](https://file1.elecfans.com/web2/M00/88/EB/wKgaomR3AEiAZmUCAAA9O8KTcYs263.jpg)
評(píng)論