Linux runtime--电源管理
一 简介
linux内核电源管理模型主要有两种,suspend和runtime电源管理模型,suspend系统睡眠模型是将整个系统进行休眠,但如果需要在系统运行时,单独对某个模块进行休眠 ,就需要Runtime电源管理模型,那这篇文章主要讲解runtime电源管理的知识
二 runtime电源管理模型框架
Runtime电源管理模型的原理比较简单,就是计数,
当该设备驱动被使用时就加1,放弃使用时就减1,
计数大于1时,就打开该设备的电源,等于0时就关闭电源。调用我们注册的回调函数
Runtime PM相关的函数:
a. 使能/禁止 Runtime PM:pm_runtime_enable / pm_runtime_disable (修改disable_depth变量),这个变量的初始化值是1,默认是disable的状态
b. 增加计数/减少计数:pm_runtime_get_sync / pm_runtime_put_sync (修改usage_count变量),并判断是否进入suspend/resume
c. 回调函数 暂停/恢复/空闲:runtime_suspend / runtime_resume / runtime_idle
上面4个函数不会直接导致runtime_suspend,runtime_resume,runtime_idle被调用,只是使能和修改计数值,当引用计数减为0,调用suspend,从0变为大于0调用resume。
对于runtime PM,默认状态下设备的状态是suspend,如果硬件上它是运行状态,需要调用pm_runtime_set_active()来修改它的状态,然后调用pm_runtime_enable()来使能runtime PM。一般是在probe()的结尾处使用,以为它可能导致runtime的suspend/resume函数立即调用。一般在驱动remove中调用pm_runtime_disable()
三 linux驱动中如何使用runtime
下面我们以摄像头imx307的驱动代码来分析
3.1 在i2c_driver里的driver里添加pm结构体,代码如下
static struct i2c_driver imx307_i2c_driver = {.driver = {.name = IMX307_NAME,.pm = &imx307_pm_ops,.of_match_table = of_match_ptr(imx307_of_match),},.probe = &imx307_probe,.remove = &imx307_remove,.id_table = imx307_match_id,
};
3.2 设置pm结构体成员函数
static const struct dev_pm_ops imx307_pm_ops = {SET_RUNTIME_PM_OPS(imx307_runtime_suspend,imx307_runtime_resume, NULL)
};
3.3 使能runtime
对于Runtime PM,默认状态下设备的状态是Suspended,
如果硬件上它是运行状态,需要调用pm_runtime_set_active()来修改它的状态,
然后调用pm_runtime_enable()来使能Runtime PM。
static int imx307_probe(struct i2c_client *client,const struct i2c_device_id *id)
{struct device *dev = &client->dev;....................................pm_runtime_set_active(dev);pm_runtime_enable(dev);pm_runtime_idle(dev);dev_err(dev, "v4l2 async register subdev success\n");return 0;}
3.3 禁止 runtime
static int imx307_remove(struct i2c_client *client)
{struct v4l2_subdev *sd = i2c_get_clientdata(client);struct imx307 *imx307 = to_imx307(sd);pm_runtime_disable(&client->dev);if (!pm_runtime_status_suspended(&client->dev))__imx307_power_off(imx307);pm_runtime_set_suspended(&client->dev);return 0;
}
3.4 runtime pm ops实现
static int imx307_runtime_resume(struct device *dev)
{struct i2c_client *client = to_i2c_client(dev);struct v4l2_subdev *sd = i2c_get_clientdata(client);struct imx307 *imx307 = to_imx307(sd);return __imx307_power_on(imx307);
}static int imx307_runtime_suspend(struct device *dev)
{struct i2c_client *client = to_i2c_client(dev);struct v4l2_subdev *sd = i2c_get_clientdata(client);struct imx307 *imx307 = to_imx307(sd);__imx307_power_off(imx307);return 0;
}
3.5 启动调用imx307_runtime_resume/imx307_runtime_suspend代码
static int imx307_s_power(struct v4l2_subdev *sd, int on)
{struct imx307 *imx307 = to_imx307(sd);struct i2c_client *client = imx307->client;int ret = 0;mutex_lock(&imx307->mutex);/* If the power state is not modified - no work to do. */if (imx307->power_on == !!on)goto unlock_and_return;if (on) {//引用计数加1,执行后会调用到imx307_runtime_resume函数ret = pm_runtime_get_sync(&client->dev);if (ret < 0) {pm_runtime_put_noidle(&client->dev);goto unlock_and_return;}ret = imx307_write_array(imx307->client, imx307_global_regs);if (ret) {v4l2_err(sd, "could not set init registers\n");pm_runtime_put_noidle(&client->dev);goto unlock_and_return;}imx307->power_on = true;} else {//引用计数减1,执行后会调用到imx307_runtime_suspend函数pm_runtime_put(&client->dev);imx307->power_on = false;}unlock_and_return:mutex_unlock(&imx307->mutex);return ret;
}
四 通过节点来控制
4.1 resume
echo on > /sys/devices/platform/ff4a0000.rk_isp/power/control
4.2 suspend
echo auto > /sys/devices/platform/ff4a0000.rk_isp/power/control
Linux runtime--电源管理相关推荐
- 翻译:Linux的电源管理架构
设备电源管理 Copyright (c) 2010 Rafael J. Wysocki<rjw@sisk.pl>, Novell Inc. Copyright (c) 2010 Alan ...
- linux 电源管理 regulator,Linux内核电源管理综述
资料: http://blog.csdn.net/bingqingsuimeng/article/category/1228414 http://os.chinaunix.net/a2006/0519 ...
- Linux的电源管理-休眠与唤醒
写在前面 为了理清新平台系统休眠和唤醒的流程,通过学习其他平台的电源管理方法,曲径通幽, 达到目的. 刚接手新平台,且相应的资料不多,很容易让人力不从心;我在网上寻找了学习资源,发现韦东山对S3C24 ...
- linux查看电源模块,基于LINUX的电源管理cpuidle模块研究及应用
赵婉芳 摘 要:本文主要针对LINUX嵌入式系统的电源管理部分,分析了目前存在的主要的电源管理技术,重点研究了LINUX系统中当系统处于空闲状态时负责电源管理的CPUIDLE模块结构特点以及接口核心编 ...
- linux acpi 电源管理,ACPI电源管理
S1,S2:待机.只关闭CPU.S1是完全加电:S2是如果CPU不活动就进入待机状态. S3:挂起到内存,关闭硬盘,其它设备处于加电等待状态. S4:休眠,内存写入硬盘后,关闭所有设备. S5:关机: ...
- 关闭linux服务器电源,linux关闭ACPI电源管理模块
一.运行环境 # cat /etc/redhat-release CentOS release 6.2 (Final) # uname -a Linux web-server- 2.6.-.el6.x ...
- Linux 电源管理子系统
Linux 在消费电子领域的应用已经相当普遍,而对于消费电子产品而言,省电是一个重要的议题. Linux 电源管理非常复杂,牵扯到系统级的待机.频率电压变换.系统空闲时的处理以及每个设备驱动对系统待机 ...
- Linux内核学习--电源管理
目录 一.引言 二.电源管理 ------> 2.1.电源管理的两种模型 三.系统Suspend ------> 3.1.系统睡眠模型Suspend ------> 3.2.开启su ...
- 高通msm8996平台上的pa电源管理(wsa881x)
高通msm8996平台上的pa电源管理(wsa881x) 高通msm8996平台上的pa电源管理(wsa881x) 1 相关dts定义 2 swr_master设备加载 3 swr_master电源管 ...
- linux runtime pm机制的深入理解
一:runtime机制说明 何为runtime机制?也就是系统在非睡眠状态,设备在空闲时可以进入runtime suspend状态同时不依赖系统wake_lock机制,非空闲时执行runtime re ...
最新文章
- chrono 使用备注
- 同步电机调速matlab,基于matlab的永磁同步电机调速系统的仿真word格式
- 举例分析Linux动态库和静态库
- 多通道图像的通道分享和合成函数-split、merge
- Boost:bind绑定作为一个组合的测试程序
- 配置 Windows 环境变量的方法
- Linux历史,安装,分区,版本
- DOCX%20是什么格式
- ZJOI2019 线段树
- phpStudy启动失败时的解决方法 提示缺vc9运行库
- 图像识别从零写出dnf脚本关键要点
- 日语中的-简体与敬体
- 【车间调度】遗传算法求解柔性作业车间调度问题
- WinForm 随手记
- Maya Python 第七章 使用Maya命令创建基本工具 7.1-7.3
- 大魔王程序员生成记#01#C语言基础
- HTML基础知识整理
- 简单步骤实现wordpress添加og协议
- 一文读懂TDengine的窗口查询功能
- oracle v diag info,V$DIAG_INFO及V$DIAG_CRITICAL_ERROR视图