SoC时钟系统提供的功能包括:使能控制、倍频、分频、复用等。因此,在软件代码中按照SoC时钟系统提供的功能来组织Clock provider的结构,方便用户使用。
1. Clock provider数据结构CCF是common clock framework的缩写,意为通用时钟框架。在内核中通过宏定义CONFIG_COMMON_CLK打开CCF,打开相关宏开启CFG框架的通用功能,具体如下:
CONFIG_COMMON_CLK=y CONFIG_CLKDEV_LOOKUP=y CONFIG_HAVE_CLK_PREPARE=y CONFIG_COMMON_CLK_DEBUG=y
在详细说明CCF框架之前,以直观的方式了解一下CCF架构中几个重要数据结构之间的关系。
对于数据结构struct clk,目前已经整合到了CCF框架中,而某些平台具有自己的struct clk。
struct clk {
struct clk_core *core;
const char *dev_id;
const char *con_id;
unsigned long min_rate;
unsigned long max_rate;
struct hlist_node clks_node;
};
这其中,struct clk_core是代码层面的时钟树的体现,包含了时钟树的层次包含关系。
struct clk_core {
const char *name;
const struct clk_ops *ops;
struct clk_hw *hw;
struct module *owner;
struct clk_core *parent;
const char **parent_names;
struct clk_core **parents;
u8 num_parents;
u8 new_parent_index;
...
};
需要由SoC时钟驱动例化的数据结构struct clk_ops,注册关键的操作函数。例如:
const struct clk_ops clk_regmap_divider_ops = {
.recalc_rate = clk_regmap_divider_recalc_rate,
.round_rate = clk_regmap_divider_round_rate,
.set_rate = clk_regmap_divider_set_rate,
};
EXPORT_SYMBOL_GPL(clk_regmap_divider_ops);
2. Clock provider功能
源码文件结构如下所示:
drivers/clk/ ├── clk-bulk.c-----------------------获取批量时钟信息 ├── clk.c----------------------------CCF架构核心代码 ├── clk-composite.c------------------时钟注册 ├── clk-conf.c-----------------------时钟频率设置 ├── clkdev.c-------------------------时钟设备查找表 ├── clk-devres.c---------------------获取时钟资源信息 ├── clk-divider.c--------------------时钟分频 ├── clk-fixed-factor.c---------------固定系数的时钟注册 ├── clk-fixed-rate.c-----------------固定频率的时钟注册 ├── clk-fractional-divider.c---------浮点分频 ├── clk-gate.c-----------------------时钟门控 ├── clk-gpio.c-----------------------GPIO控制的时钟 ├── clk-multiplier.c-----------------时钟倍频 ├── clk-mux.c------------------------时钟复用 ├──────────────────────
CCF架构下提供的时钟控制相关函数如下图所示:



