dts 描述clock provider和clock consumer,clock consumer 使用clock provider的服务
u_clks:uclk_provider {
compatible = "uclk-provider";
#clock-cells = <2>;
};uclk_consumer {
compatible = "uclk-consumer";
clock-names = "uclk";
clocks = <&u_clks 123 456>;
};
uclk_provider.c
#include <linux/module.h>
#include <linux/platform_device.h>
#include <linux/clk-provider.h>
#include <linux/slab.h>
#include <linux/list_sort.h>
#include <linux/bsearch.h>struct uclk;
struct uclk_ops {
int (*get_num_parents)(u32 did, u32 cid, u32 *num_parents);
};/**
* struct uclk_provider - u clock provider representation
* @dev: Device pointer for the clock provider
* @clocks: Clocks array for this device
* @num_clocks: Total number of clocks for this provider
*/
struct uclk_provider {
struct uclk_ops *ops;
struct device *dev;
struct uclk **clocks;
int num_clocks;
};/**
* struct uclk - u clock representation
* @hw: Hardware clock cookie for common clock framework
* @dev_id: Device index
* @clk_id: Clock index
* @num_parents: Number of parents for this clock
* @provider: Master clock provider
* @flags: Flags for the clock
* @node: Link for handling clocks probed via DT
* @cached_req: Cached requested freq for determine rate calls
* @cached_res: Cached result freq for determine rate calls
*/
struct uclk {
struct clk_hw hw;
u16 dev_id;
u32 clk_id;
u32 num_parents;
struct uclk_provider *provider;
u8 flags;
struct list_head node;
unsigned long cached_req;
unsigned long cached_res;
};
static int uclk_prepare(struct clk_hw *hw)
{
struct uclk *uclk = container_of(hw, struct uclk, hw);
return printk("%s call, \t\tdev_id,clk_id = %d,%d\n", __func__, uclk->dev_id, uclk->clk_id);
}
static void uclk_unprepare(struct clk_hw *hw)
{
struct uclk *uclk = container_of(hw, struct uclk, hw);
printk("%s call, \t\t\tdev_id,clk_id = %d,%d\n", __func__, uclk->dev_id, uclk->clk_id);
}
static int uclk_is_prepared(struct clk_hw *hw)
{
struct uclk *uclk = container_of(hw, struct uclk, hw);
return printk("%s call, \t\tdev_id,clk_id = %d,%d\n", __func__, uclk->dev_id, uclk->clk_id);
}
static unsigned long uclk_recalc_rate(struct clk_hw *hw, unsigned long parent_rate)
{
struct uclk *uclk = container_of(hw, struct uclk, hw);
return printk("%s call, \t\tdev_id,clk_id = %d,%d\n", __func__, uclk->dev_id, uclk->clk_id);
}<