Rochchip --- 待机唤醒模式
文章目录
- (一)dts
- (二)内核
- (三)调试
- 1、目录内容
- (三)排查记录
(一)dts
rockchip-suspend 的节点,用于定义 Rockchip 平台的睡眠模式和电源管理配置。
rockchip_suspend: rockchip-suspend {
compatible = "rockchip,pm-config";
status = "disabled";
// 睡眠模式下调试功能是否启用
rockchip,sleep-debug-en = <0>;
// 睡眠模式配置
rockchip,sleep-mode-config = <
(0
| RKPM_SLP_ARMOFF_LOGOFF
| RKPM_SLP_PMU_PMUALIVE_32K
| RKPM_SLP_PMU_DIS_OSC
| RKPM_SLP_PMIC_LP
| RKPM_SLP_32K_EXT
)
>;
//启用GPIO唤醒功能
rockchip,wakeup-config = <
(0
| RKPM_GPIO_WKUP_EN
)
>;
//睡眠模式下IO保留配置
rockchip,sleep-io-ret-config = <
(0)
>;
//睡眠模式下引脚配置
rockchip,sleep-pin-config = <
(0
| RKPM_SLEEP_PIN0_EN
| RKPM_SLEEP_PIN1_EN
)
(0)
>;
//电源域相关配置
power-domains = <&power RK3576_PD_USB>, <&power RK3576_PD_PHP>;
};
(二)内核
驱动中需要初始化设备的唤醒功能并且添加唤醒源
int device_init_wakeup(struct device *dev, bool enable);
功能 :初始化设备的唤醒功能
参数:
@dev :指向设备的struct device结构体
@enable :表示是否启用设备的唤醒功能。true,启用;flase,禁用。
返回值:
成功,返回0
失败,返回非0
static int device_probe(struct i2c_client *client,
const struct i2c_device_id *id)
{
...
//注册中断
int ret;
device-> irq = gpiod_to_irq(gsv6127e->gpio_intp);
if (device-> irq < 0)
return -EINVAL;
ret = devm_request_threaded_irq(dev, device->irq, NULL, device_intp_threaded_handler, IRQF_TRIGGER_RISING | IRQF_TRIGGER_FALLING | IRQF_ONESHOT, "driver-intp", device);
if (ret) {
printk(KERN_ERR "Failed to request threaded IRQ: %d\n", ret);
return ret;
}
//添加唤醒源
ret = device_init_wakeup(&client->dev, true);
if (ret) {
printk(KERN_ERR "Failed to enable wakeup for device: %d\n", ret);
} else {
printk(KERN_INFO "Wakeup enabled for device.\n");
}
...
}
static int device_pm_suspend(struct device *dev)
{
struct i2c_client *client = to_i2c_client(dev);
if (device_may_wakeup(dev))
enable_irq_wake(client->irq);
else
disable_irq(client->irq);
return 0;
}
static int device_pm_resume(struct device *dev)
{
struct i2c_client *client = to_i2c_client(dev);
if (device_may_wakeup(dev))
disable_irq_wake(client->irq);
else
enable_irq(client->irq);
return 0;
}
static const struct dev_pm_ops device_pm_ops = {
.suspend = device_pm_suspend, //在系统进入低功耗模式时,保存设备的状态并关闭设备的电源。
.resume = device_pm_resume,
};
static struct i2c_driver device_driver = {
.probe = device_probe,
.remove = device_remove,
.shutdown = device_shutdown,
.driver = {
.name = "device",
.pm = &device_pm_ops,
.of_match_table = device_dt_ids,
},
};
(三)调试
/sys/power 目录 存放控制和监控电源管理功能的文件
1、目录内容
mem_sleep 控制内存休眠模式
pm_freeze_timeout 设置冻结模式(Freeze)的超时时间
pm_wakeup_irq 显示触发唤醒的中断号
sync_on_suspend 控制在进入休眠时是否同步文件系统
pm_async 控制电源管理异步操作 0 禁用/1 启用
pm_print_times 控制电源管理操作的时间打印
state 控制系统的电源状态
wakeup_count 显示系统唤醒的次数。
pm_debug_messages 控制电源管理相关的调试信息输出 0禁用/1启用
pm_test 测试电源管理功能
suspend_stats 显示休眠统计信息
/sys/power/state 控制系统电源状态
mem:内存休眠模式(Suspend-to-RAM)。系统会将当前状态保存到内存中,然后进入低功耗模式。
freeze:冻结模式。系统将当前状态冻结,但不会进入深度休眠。
(三)排查记录
cat /sys/power/pm_wakeup_irq //查看当前的唤醒源
echo mem > /sys/power/state //进入休眠