Linux设备驱动之clk驱动:注册clk-provider和clk-consumer到kernel

QEMU仿真Linux regulator supplier 和 consumer注册_蓝牙先生的博客-CSDN博客uregulator_consumer.c#include <linux/init.h>#include <linux/module.h>#include <linux/kernel.h>#include <linux/platform_device.h>#include <linux/mod_devicetable.h>#include <linux/of.h>#include <linux/regmap..https://blog.csdn.net/m0_37132481/article/details/123709759

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);
}<

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值