clock时钟框架称为common clock framework
从图中我们可以看出时钟提供者(clock provider)和时钟使用者(clock consumer)是通过common clock framework来通信的,而通信的基础都是设备树
provider侧:解析设备树的的#clock-cells(必须有,若属性值为0,表示provider就提供一个clock output输出,若属性值为1,表示provider就提供多个clock output输出)和#clock-output-names(非必须有)属性,通过clk_register等一系列注册函数把硬件时钟树注册,然后调用of_clk_add_provider接口(这是provider和consumer连接的桥梁)组成时钟链表供时钟使用者查询使用
consumer侧:解析设备树#clocks ,#clock-names 等属性,调用clk_get,devm_clk_get,clk_enable,clk_set_rate等一系列接口函数从provider侧组织好的时钟链表中获取匹配的时钟句柄(struct clk类型)
对我们使用者(device driver)来说,struct clk只是访问clock的一个句柄,不用关心它内部的具体形态。所以只需知道以下常用接口就可以:
clock获取有关的API:device driver在操作设备的clock之前,需要先获取和该clock关联的struct clk指针,获取的接口如下:
struct clk *clk_get(struct device *dev, const char *id);
struct clk *devm_clk_get(struct device *dev, const char *id);
void clk_put(struct clk *clk);
void devm_clk_put(struct device *dev, struct clk *clk);
struct clk *clk_get_sys(const char *dev_id, const char *con_id);
struct clk *of_clk_get(struct device_node *np, int index);
struct clk *of_clk_get_by_name(struct device_node *np, const char *name);
struct clk *of_clk_get_from_provider(struct of_phandle_args *clkspec);
clock控制有关的API:
int clk_prepare(struct clk *clk)
void clk_unprepare(struct clk *clk)
static inline int clk_enable(struct clk *clk)
static inline void clk_disable(struct clk *clk)
static inline unsigned long clk_get_rate(struct clk *clk)
static inline int clk_set_rate(struct clk *clk, unsigned long rate)
static inline long clk_round_rate(struct clk *clk, unsigned long rate)
static inline int clk_set_parent(struct clk *clk, struct clk *parent)
static inline struct clk *clk_get_parent(struct clk *clk)
--------------------------------------------------------------------------------------------------------------------