linux 设备树 otg,linux下充电IC OTG设备供电控制
linux下充电IC OTG设备供电控制
备注:下面提到的充电IC 用charger表示
1. OTG VBUS 5V供电
接入OTG设备,比如U盘,具体是怎么通过charger驱动来给U盘供电5V的
2. 设备树
charger:xxx@6B{
regulator-name = " xxx_otg_vreg";
…
};
&usb_otg {
…
vbus_otg-supply = ;
};
3. 调用流程
3.1 usb otg驱动
对应phy-msm-usb.c文件,usb otg驱动加载的时候,调用msm_otg_set_host(),此函数通过:
vbus_otg =devm_regulator_get(motg->phy.dev, "vbus_otg");
通过supply name,这里是vbus_otg-supply,找到regulator设备节点,这里是xxx_otg_supply,调用之后让vbus_otg指向给otg vbus供电的regulator,
devm_regulator_get的调用流程:
devm_regulator_get(motg->phy.dev,"vbus_otg")--->regulator_get()
--->_regulator_get()--->regulator_dev_lookup()--->of_get_regulator()
/**
*of_get_regulator - get a regulator device node based on supply name
*@dev: Device pointer for the consumer (of regulator) device
*@supply: regulator supply name
*
*Extract the regulator device node corresponding to the supply name.
*returns the device node corresponding to the regulator if found, else
*returns NULL.
*/
static struct device_node*of_get_regulator(struct device *dev, const char *supply)
{
structdevice_node *regnode = NULL;
charprop_name[32]; /* 32 is max size of property name */
dev_dbg(dev,"Looking up %s-supply from device tree\n", supply);
snprintf(prop_name,32, "%s-supply", supply);
regnode= of_parse_phandle(dev->of_node, prop_name, 0);
if(!regnode) {
dev_dbg(dev,"Looking up %s property in node %s failed",
prop_name,dev->of_node->full_name);
returnNULL;
}
returnregnode;
}
通过节点xxx下的regulator-name找到regulator的名字为xxx_otg_vreg,
Usb otg驱动找到xxx_otg_vreg这个regulator后,在接入OTG设备时,会调用其对应的regulator_desc(描述regulator的静态信息,包括:名字、supply regulator的名字、中断号、操作函数集(structregulator_ops))下的操作表ops下的enable(),拔出OTG设备时调用disable()
msm_hsusb_vbus_power()--->regulator_enable(vbus_otg)
那enable()和disable()具体在charger驱动中实现。
3.2 charger驱动
(1) 驱动初始化
调用regulator_register()向regulator框架层注册一个regulator设备,用regulator_dev结构体表示。
struct regulator_ops xxx_otg_reg_ops = {
.enable = xxx_otg_regulator_enable,
.disable = xxx_otg_regulator_disable,
.is_enabled = xxx_otg_regulator_is_enable,
};
static int xxx_regulator_init(struct xxx_device_info*chip)
{
intrc = 0;
structregulator_init_data *init_data;
structregulator_config cfg = {};
init_data= of_get_regulator_init_data(chip->dev, chip->dev->of_node);
if(!init_data) {
dev_err(chip->dev,"Unable to allocate memory\n");
return-ENOMEM;
}
if(init_data->constraints.name) {
chip->otg_vreg.rdesc.owner= THIS_MODULE;
chip->otg_vreg.rdesc.type= REGULATOR_VOLTAGE;
chip->otg_vreg.rdesc.ops= &xxx_otg_reg_ops;
chip->otg_vreg.rdesc.name= init_data->constraints.name;
cfg.dev= chip->dev;
cfg.init_data= init_data;
cfg.driver_data= chip;
cfg.of_node= chip->dev->of_node;
init_data->constraints.valid_ops_mask
|=REGULATOR_CHANGE_STATUS;
chip->otg_vreg.rdev= regulator_register(
&chip->otg_vreg.rdesc,&cfg);
if(IS_ERR(chip->otg_vreg.rdev)) {
rc= PTR_ERR(chip->otg_vreg.rdev);
chip->otg_vreg.rdev= NULL;
if(rc != -EPROBE_DEFER)
dev_err(chip->dev,
"OTGreg failed, rc=%d\n", rc);
}
}
returnrc;
}
(2) 插拔OTG设备
比如插入OTG设备时,usb otg驱动通过调用名为xxx_otg_vreg的regulator的enable,来实现otg vbus的供电,对应调用xxx_otg_regulator_enable()。
linux 设备树 otg,linux下充电IC OTG设备供电控制相关推荐
- Linux设备树led,linux设备树下LED灯控制
linux设备树下LED灯控制 linux设备树下LED灯控制 原理图: 所以在设备树下子节点下插入gpioled节点: gpioled { #address-cells = <1>; # ...
- 高通平台msm8953 Linux DTS(Device Tree Source)设备树详解之二(DTS设备树匹配过程)
本系列导航: 高通平台8953 Linux DTS(Device Tree Source)设备树详解之一(背景基础知识篇) 高通平台8953 Linux DTS(Device Tree Source ...
- 使用错误的设备树导致linux,Petalinux工程中设备树的介绍
设备树是 Petalinux kernel 的关键组件,接下来以 2020.1 版本为例,为大家介绍一下在Xilinx Petalinux 工程中的设备树是如何产生,配置以及修改的. Petalinu ...
- 安卓(android)6.0高通平台下设备树专题视频讲解【全国独家+设备树视频教程】
安卓(android)6.0高通平台下设备树专题视频讲解[全国独家+设备树视频教程] 独家拥有 ...
- 设备树的引进与体验_使用设备树时的驱动编程
目录 1 驱动程序中的设备树机制 2 写代码 2.1 设备树文件 2.2 led_drv.c 2.3 ledtest.c 2.4 Makefile 3 代码优化改进 3.1 设备树文件 3.2 led ...
- linux 设备树_嵌入式系统砖家_初识设备树
目录: 一.加载Linux(有无设备树) 二.设备树入门知识 一.加载Linux(有无设备树) 没有设备树的时候(以ARM架构为例): - 内核在源码里记录了所有硬件相关的信息(芯片型号.内存大小,各 ...
- linux设备树sysfs,迅为-iMX6开发板-设备树内核-sys方式控制GPIO
本文档主要讲解迅为-iMX6 开发板,通过 sys 文件的方式来控制 GPIO. 要通过 sys 控制 GPIO,需要做以下几步操作: 1 开启内核中的"GPIO_SYSFS"驱动 ...
- linux 驱动 到 设备树,tree - Linux:设备树到acpi驱动程序 - 堆栈内存溢出
我需要帮助,我的驱动程序已经在设备树模式下工作,并且我想为其支持acpi模式,但我仍然无法创建分区: 设备树: &spi0 { status = "ok"; flash: ...
- Mtk android中的设备树,msm8909+android5.1 device tree(dt) 设备树组成和编译
1.Device tree设备树概述 设备树包含DTC(device treecompiler),DTS(device treesource和DTB(device treeblob).其对应关系如图1 ...
最新文章
- 支配vue框架模版语法之v-cloak
- android连接usb外设通讯_iOS App连接外设的几种方式
- No module named 'urlparse'
- 【Linux】一步一步学Linux——batch命令(134)
- html怎么使图片无法另存为,如何禁止图片另存为?禁止网页另存为到本地的方法...
- php fastcgi exp,nginx +phpfastcgi 环境下 导出excel文件,超时,数据被截断问题,解决...
- 通用职责分配软件原则之5-控制器原则
- ajax请求可以延时吗,延时校验AJAX请求
- SpringNote01.基于SpringMVC-Hibernate的Blog系统
- geotools 影像切片 缩放
- symbian的字体包
- 知识积累:wps宏 开发工具 vb代码 合并多个excel文件到一个excel文件,并去掉表头的方式,宏合并excel表格,多表格合并
- FileZilla 无法连接服务器 fzSftp started, protocol_version=11
- dw01均衡电路_电池平衡电路工作原理
- xftp无法显示远程文件夹
- 渝粤题库 国家开放大学 学前儿童艺术教育(音乐) 期末考试复习资料
- 基于wowchemy和hugo搭建个人网站
- 意识的哲学、生理及智能属性研究
- 中国数字商业核心产业链分布
- 大数据培训课程哪个好