赞
踩
/ {
...
rst: reset-controller {
compatible = "xxxxxx,reset";
reg = <0x0 0x03003000 0x0 0x10>;
};
...
}
#include <dt-bindings/reset/xxx-resets.h>
/{
...
watchdog0: wd@0x3010000 {
...
resets = <&rst RST_WDT>;
reset-names = "rst_wdt";
};
...
}
#define RST_MAINRST_AP 0
#define RST_SECONDRST_AP 1
#define RST_DDR 2
#define RST_H264C 3
#define RST_WDT 4
resets = <&rst 4>;
file: u-boot-2021.10/include/dt-bindings/reset/xxx-resets.h
file: u-boot-2021.10/drivers/reset/reset-xxx.c
//file: linux_5.10/include/dt-bindings/reset/xxx-resets.h
struct reset_control_ops{
int (*reset)(struct reset_controller_dev *rcdev, unsigned long id);//复位+解复位
int (*assert)(struct reset_controller_dev *rcdev, unsigned long id);//复位
int (*deassert)(struct reset_controller_dev *rcdev, unsigned long id);//解复位
int (*status)(struct reset_controller_dev *rcdev, unsigned long id);//复位状态查询
}
//file: linux_5.10/drivers/reset/reset-xxx.c static int xx_reset_assert(struct reset_controller_dev *rcdev, unsigned long id) { // 将reset id转换为对应的 寄存器和bit,对该bit写0。 // soc xx181x实现 int bank = id / 32; int offset = id % 32; spin_lock_irqsave(&data->lock, flags); // 将该bit置 0 reg = readl(data->membase + (bank * 4)); writel(reg & ~BIT(offset), data->membase + (bank * 4)); spin_unlock_irqrestore(&data->lock, flags); return 0; } static int xx_reset_deassert(struct reset_controller_dev *rcdev, unsigned long id) { // 将reset id转换为对应的 寄存器和bit,对该bit写1。 // soc xx181x实现同上,置0改为置1 return 0; } static const struct reset_control_ops bm_reset_ops = { .assert = xxx_reset_assert, .deassert = xxx_reset_deassert, };
// file: drivers/reset/core.c
struct reset_control {
struct reset_controller_dev *rcdev;
struct list_head list;
unsigned int id;
struct kref refcnt;
bool shared;
bool array;
atomic_t deassert_count;
atomic_t triggered_count;
};
...
// file: include/linux/reset.h // 获取reset handle struct reset_control *devm_reset_control_get(struct device *dev, const char *id); devm_reset_control_get_exclusive:查找并获取reset_control的独占引用(不能与其他驱动程序共享)。 devm_reset_control_get_shared:查找并获取reset_control的共享引用(可以与另一个驱动程序共享)。 devm_reset_control_get:与 devm_reset_control_get_exclusive 相同。 devm_reset_control_get_optional:与 devm_reset_control_get 相同,只是引用名称是可选的。 devm_reset_control_get_optional_exclusive:与devm_reset_control_get_exclusive 相同,只是引用名称是可选的。 devm_reset_control_get_optional_shared:与devm_reset_control_get_shared 相同,只是引用名称是可选 // reset 操作 int reset_control_reset(struct reset_control *rstc); //复位 + 解复位操作 int reset_control_assert(struct reset_control *rstc); //复位 int reset_control_deassert(struct reset_control *rstc); //解复位
struct reset_control *reset; int ret; // 1. get handle reset = devm_reset_control_get_exclusive(&pdev->dev, NULL); if (IS_ERR(reset)) { … } // 2. 复位 ret = reset_control_assert(reset); if (ret) { … } udelay(2); // 3. 解复位 reset_control_deassert(reset);
reset = devm_reset_control_get(&pdev->dev, "rst_wdt");
if (IS_ERR(reset)) {
…
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。