当前位置: 首页 > news >正文

qcom ucsi probe

ucsi glink 注册一个ucsi 设备,和pmic glink进行通信,ucsi作为pmic glink的一个client。

lkml的patch  https://lkml.org/lkml/2023/1/30/233

dtsi中一般会定义 qcom,ucsi-glink 信息,用于和驱动进行匹配

static const struct of_device_id ucsi_match_table[] = {
    {.compatible = "qcom,ucsi-glink"},
    {},
};

static struct platform_driver ucsi_driver = {
    .driver    = {
        .name = "ucsi_glink",
        .of_match_table = ucsi_match_table,
    },
    .probe    = ucsi_probe,
    .remove    = ucsi_remove,
};

module_platform_driver(ucsi_driver);

MODULE_DESCRIPTION("QTI UCSI Glink driver");
MODULE_LICENSE("GPL v2");
 

ucsi probe都进行了哪些工作呢

ucsi_dev 结构解析

struct ucsi_dev {struct device			*dev;struct ucsi			*ucsi;//用于与 UCSI 核心逻辑进行交互。负责处理相关的连接和协议逻辑struct pmic_glink_client	*client;//指向 PMIC GLink 客户端结构体的指针,用于与 PMIC GLink 通信接口进行交互,实现电源管理和通信struct completion		read_ack;struct completion		write_ack;struct completion		sync_write_ack;struct mutex			read_lock;struct mutex			write_lock;struct mutex			notify_lock;struct mutex			state_lock;struct ucsi_read_buf_resp_msg	rx_buf;//存储从设备接收到的数据缓冲区响应消息unsigned long			flags;atomic_t			rx_valid;unsigned long			cmd_requested_flags;struct list_head		constat_info_list;//head ,node is constat_info_entrystruct work_struct		notify_work;//ucsi_qti_notify_workstruct work_struct		setup_work;//ucsi_qti_setup_workstruct work_struct		unregister_work;atomic_t			state;
};

 

static int ucsi_probe(struct platform_device *pdev)
{struct device *dev = &pdev->dev;struct pmic_glink_client_data client_data;struct ucsi_dev *udev;int rc;udev = devm_kzalloc(dev, sizeof(*udev), GFP_KERNEL);//创建并进行初始化if (!udev)return -ENOMEM;INIT_LIST_HEAD(&udev->constat_info_list);INIT_WORK(&udev->notify_work, ucsi_qti_notify_work);INIT_WORK(&udev->setup_work, ucsi_qti_setup_work);INIT_WORK(&udev->unregister_work, ucsi_qti_unregister_work);//注销?销毁mutex_init(&udev->read_lock);mutex_init(&udev->write_lock);mutex_init(&udev->notify_lock);mutex_init(&udev->state_lock);init_completion(&udev->read_ack);init_completion(&udev->write_ack);init_completion(&udev->sync_write_ack);atomic_set(&udev->rx_valid, 0);atomic_set(&udev->state, PMIC_GLINK_STATE_UP);client_data.id = MSG_OWNER_UC;client_data.name = "ucsi";client_data.msg_cb = ucsi_callback;client_data.priv = udev;client_data.state_cb = ucsi_qti_state_cb;udev->client = pmic_glink_register_client(dev, &client_data);//client data->clientif (IS_ERR(udev->client)) {rc = PTR_ERR(udev->client);if (rc != -EPROBE_DEFER)dev_err(dev, "Error in registering with pmic_glink rc=%d\n",rc);return rc;}platform_set_drvdata(pdev, udev);udev->dev = dev;ucsi_ipc_log = ipc_log_context_create(NUM_LOG_PAGES, "ucsi", 0);if (!ucsi_ipc_log)dev_warn(dev, "Error in creating ipc_log_context\n");rc = ucsi_setup(udev);if (rc) {ipc_log_context_destroy(ucsi_ipc_log);ucsi_ipc_log = NULL;pmic_glink_unregister_client(udev->client);}return rc;
}

ucsi_setup的过程如下

static int ucsi_setup(struct ucsi_dev *udev)
{int rc;if (udev->ucsi) {dev_err(udev->dev, "ucsi is not NULL\n");return -EINVAL;//已经有了,不需要创建了}mutex_lock(&udev->state_lock);udev->ucsi = ucsi_create(udev->dev, &ucsi_qti_ops);//createif (IS_ERR(udev->ucsi)) {rc = PTR_ERR(udev->ucsi);dev_err(udev->dev, "ucsi_create failed rc=%d\n", rc);udev->ucsi = NULL;mutex_unlock(&udev->state_lock);return rc;}ucsi_set_drvdata(udev->ucsi, udev);rc = ucsi_register(udev->ucsi);//then 注册if (rc) {dev_err(udev->dev, "ucsi_register failed rc=%d\n", rc);ucsi_destroy(udev->ucsi);udev->ucsi = NULL;mutex_unlock(&udev->state_lock);return rc;}mutex_unlock(&udev->state_lock);return 0;
}

 其中的static const struct ucsi_operations ucsi_qti_ops = {
    .read = ucsi_qti_read,
    .sync_write = ucsi_qti_sync_write,
    .async_write = ucsi_qti_async_write
};

 

/*** ucsi_create - Allocate UCSI instance* @dev: Device interface to the PPM (Platform Policy Manager)* @ops: I/O routines*/
struct ucsi *ucsi_create(struct device *dev, const struct ucsi_operations *ops)
{struct ucsi *ucsi;if (!ops || !ops->read || !ops->sync_write || !ops->async_write)return ERR_PTR(-EINVAL);ucsi = kzalloc(sizeof(*ucsi), GFP_KERNEL);//new ucsiif (!ucsi)return ERR_PTR(-ENOMEM);INIT_WORK(&ucsi->resume_work, ucsi_resume_work);INIT_DELAYED_WORK(&ucsi->work, ucsi_init_work);mutex_init(&ucsi->ppm_lock);ucsi->dev = dev;ucsi->ops = ops;//ucsi_qti_opsreturn ucsi;
}

 

*** ucsi_register - Register UCSI interface* @ucsi: UCSI instance*/
int ucsi_register(struct ucsi *ucsi)
{int ret;ret = ucsi->ops->read(ucsi, UCSI_VERSION, &ucsi->version, //read ucsi版本号sizeof(ucsi->version));//ucsi_qti_readif (ret)return ret;if (!ucsi->version)return -ENODEV;queue_delayed_work(system_long_wq, &ucsi->work, 0);//ucsi_init_workreturn 0;
}
static void ucsi_init_work(struct work_struct *work)
{struct ucsi *ucsi = container_of(work, struct ucsi, work.work);int ret;ret = ucsi_init(ucsi);//initif (ret)dev_err(ucsi->dev, "PPM init failed (%d)\n", ret);if (ret == -EPROBE_DEFER) {if (ucsi->work_count++ > UCSI_ROLE_SWITCH_WAIT_COUNT)return;queue_delayed_work(system_long_wq, &ucsi->work,UCSI_ROLE_SWITCH_INTERVAL);}
}
/*** ucsi_init - Initialize UCSI interface* @ucsi: UCSI to be initialized** Registers all ports @ucsi has and enables all notification events.*/
static int ucsi_init(struct ucsi *ucsi)
{struct ucsi_connector *con, *connector;u64 command, ntfy;int ret;int i;/* Reset the PPM */ret = ucsi_reset_ppm(ucsi);if (ret) {dev_err(ucsi->dev, "failed to reset PPM!\n");goto err;}/* Enable basic notifications */ntfy = UCSI_ENABLE_NTFY_CMD_COMPLETE | UCSI_ENABLE_NTFY_ERROR;command = UCSI_SET_NOTIFICATION_ENABLE | ntfy;ret = ucsi_send_command(ucsi, command, NULL, 0);if (ret < 0)goto err_reset;/* Get PPM capabilities */command = UCSI_GET_CAPABILITY;ret = ucsi_send_command(ucsi, command, &ucsi->cap, sizeof(ucsi->cap));//get cap dataif (ret < 0)goto err_reset;if (!ucsi->cap.num_connectors) {ret = -ENODEV;goto err_reset;}/* Allocate the connectors. Released in ucsi_unregister() */connector = kcalloc(ucsi->cap.num_connectors + 1, sizeof(*connector), GFP_KERNEL);if (!connector) {ret = -ENOMEM;goto err_reset;}//创建connector/* Register all connectors */for (i = 0; i < ucsi->cap.num_connectors; i++) {connector[i].num = i + 1;ret = ucsi_register_port(ucsi, &connector[i]);if (ret)goto err_unregister;}/* Enable all notifications */ntfy = UCSI_ENABLE_NTFY_ALL;command = UCSI_SET_NOTIFICATION_ENABLE | ntfy;ret = ucsi_send_command(ucsi, command, NULL, 0);if (ret < 0)goto err_unregister;ucsi->connector = connector;//connetor数组ucsi->ntfy = ntfy;return 0;err_unregister:for (con = connector; con->port; con++) {ucsi_unregister_partner(con);ucsi_unregister_altmodes(con, UCSI_RECIPIENT_CON);ucsi_unregister_port_psy(con);if (con->wq)destroy_workqueue(con->wq);typec_unregister_port(con->port);con->port = NULL;}kfree(connector);
err_reset:memset(&ucsi->cap, 0, sizeof(ucsi->cap));ucsi_reset_ppm(ucsi);
err:return ret;
}

 

 ucsi_send_command是一个发送命令返回数据的函数,遵循ucsi协议发送命令后读取状态和数据。ppm执行命令后,opm发送ack确认命令收到并正确进行了处理

  • 功能ucsi_send_command 函数主要负责发送一个 UCSI 命令,并在需要时从设备读取响应数据,然后确认命令完成。
  • 锁机制:使用互斥锁 ppm_lock 确保对 UCSI 设备的操作是线程安全的。
  • 命令执行:首先执行命令,并获取命令的长度或相关信息。
  • 数据读取:如果需要,从设备读取数据。
  • 确认命令:执行完命令后确认命令完成。
  • 错误处理:函数通过 goto out 跳转到错误处理标签,确保在发生错误时能够适当释放锁。
  • 返回值:返回命令的长度或其他相关信息,或在出现错误时返回错误代码。

 

int ucsi_send_command(struct ucsi *ucsi, u64 command,void *data, size_t size)
{u8 length;int ret;mutex_lock(&ucsi->ppm_lock);//互斥锁ret = ucsi_exec_command(ucsi, command);if (ret < 0)goto out;length = ret;if (data) {ret = ucsi->ops->read(ucsi, UCSI_MESSAGE_IN, data, size);if (ret)goto out;}ret = ucsi_acknowledge_command(ucsi);if (ret)goto out;ret = length;
out:mutex_unlock(&ucsi->ppm_lock);return ret;
}

 

 

相关文章:

qcom ucsi probe

ucsi glink 注册一个ucsi 设备&#xff0c;和pmic glink进行通信&#xff0c;ucsi作为pmic glink的一个client。 lkml的patch https://lkml.org/lkml/2023/1/30/233 dtsi中一般会定义 qcom,ucsi-glink 信息&#xff0c;用于和驱动进行匹配 static const struct of_device_id …...

flask和redis配合

对于涉及数据提交的场景&#xff0c;比如更新用户信息&#xff0c;你可能会使用POST或PUT请求。但是&#xff0c;这些操作通常与直接从Redis缓存中检索数据不同&#xff0c;因为它们可能涉及到对后端数据库或其他存储系统的修改。并且可能需要将更新后的数据同步回Redis缓存&am…...

深度学习中的早停法

早停法&#xff08;Early Stopping&#xff09;是一种用于防止模型过拟合的技术&#xff0c;在训练过程中监视验证集&#xff08;或者测试集&#xff09;上的损失值。具体设立早停的限制包括两个主要参数&#xff1a; Patience&#xff08;耐心&#xff09;&#xff1a;这是指验…...

科普文:JUC系列之多线程门闩同步器CountDownLatch的使用和源码

CountDownLatch类位于java.util.concurrent包下&#xff0c;利用它可以实现类似计数器的功能。比如有一个任务A&#xff0c;它要等待其他10个线程的任务执行完毕之后才能执行&#xff0c;此时就可以利用CountDownLatch来实现这种功能了。 CountDownLatch是通过一个计数器来实现…...

foreach循环和for循环在PHP中各有什么优势

在PHP中&#xff0c;foreach循环和for循环都是用来遍历数组的常用结构&#xff0c;但它们各有其优势和使用场景。 foreach循环的优势 简化代码&#xff1a;foreach循环提供了一种更简洁的方式来遍历数组&#xff0c;不需要手动控制索引或指针。易于阅读&#xff1a;对于简单的…...

巧用casaos共享挂载自己的外接硬盘为局域网共享

最近入手了个魔改机顶盒&#xff0c;已经刷好了的armbian&#xff0c;虽然是原生的&#xff0c;但是我觉得挺强大的&#xff0c;内置了很多 常用的docker和应用&#xff0c;只需要armbian-software 安装就行&#xff0c;缺点就是emmc太小了。 买到之后第一时间装上了casaos和1p…...

标题:解码“八股文”:助力、阻力,还是空谈?

标题&#xff1a;解码“八股文”&#xff1a;助力、阻力&#xff0c;还是空谈&#xff1f; 在程序员的面试与职场发展中&#xff0c;“八股文”一直是一个备受争议的话题。它既是求职者展示自己技术功底的途径&#xff0c;也是一些公司筛选人才的标准之一。但“八股文”在实际…...

语言无界,沟通无限:2024年好用在线翻译工具推荐

随着技术的发展现在的翻译在线工具从基础词句翻译到复杂的文章翻译都不在话下。为了防止你被五花八门的工具挑花眼&#xff0c;我给你介绍几款我用过的便捷、高效、准确的翻译工具吧。 1.福晰翻译端 链接直通&#xff1a;https://www.foxitsoftware.cn/fanyi/ 这个软件支持…...

【Golang 面试 - 进阶题】每日 3 题(十八)

✍个人博客&#xff1a;Pandaconda-CSDN博客 &#x1f4e3;专栏地址&#xff1a;http://t.csdnimg.cn/UWz06 &#x1f4da;专栏简介&#xff1a;在这个专栏中&#xff0c;我将会分享 Golang 面试中常见的面试题给大家~ ❤️如果有收获的话&#xff0c;欢迎点赞&#x1f44d;收藏…...

二分+dp,CF 1993D - Med-imize

一、题目 1、题目描述 2、输入输出 2.1输入 2.2输出 3、原题链接 D - Med-imize 二、解题报告 1、思路分析 对于n < k的情况直接排序就行 对于n > k的情况 最终的序列长度一定是 (n - 1) % k 1 这个序列是原数组的一个子序列 对于该序列的第一个元素&#xff0…...

三十种未授权访问漏洞复现 合集( 三)

未授权访问漏洞介绍 未授权访问可以理解为需要安全配置或权限认证的地址、授权页面存在缺陷&#xff0c;导致其他用户可以直接访问&#xff0c;从而引发重要权限可被操作、数据库、网站目录等敏感信息泄露。---->目录遍历 目前主要存在未授权访问漏洞的有:NFS服务&a…...

数据湖和数据仓库核心概念与对比

随着近几年数据湖概念的兴起&#xff0c;业界对于数据仓库和数据湖的对比甚至争论就一直不断。有人说数据湖是下一代大数据平台&#xff0c;各大云厂商也在纷纷的提出自己的数据湖解决方案&#xff0c;一些云数仓产品也增加了和数据湖联动的特性。但是数据仓库和数据湖的区别到…...

探索WebKit的奥秘:打造高效、兼容的现代网页应用

1. 简介 1.1. 主要特点 WebKit 是一个开源的浏览器引擎,它允许开发者构建高性能、功能丰富的 web 应用程序。WebKit 与 Mozilla Firefox 等使用的 Gecko 引擎、Internet Explorer 使用的 Trident 引擎以及 EdgeHTML 引擎共同构成了现代 web 浏览器的核心技术。 1.2. 学习资…...

【leetcode】平衡二叉树、对称二叉树、二叉树的层序遍历(广度优先遍历)(详解)

Hi~&#xff01;这里是奋斗的明志&#xff0c;很荣幸您能阅读我的文章&#xff0c;诚请评论指点&#xff0c;欢迎欢迎 ~~ &#x1f331;&#x1f331;个人主页&#xff1a;奋斗的明志 &#x1f331;&#x1f331;所属专栏&#xff1a;数据结构、LeetCode专栏 &#x1f4da;本系…...

最短路径算法:Floyd-Warshall算法

引言 在图论中&#xff0c;Floyd-Warshall算法是一种用于计算任意两点之间最短路径的动态规划算法。它适用于加权有向图和无向图&#xff0c;可以处理带有负权重边的图&#xff0c;但要求图中不能有负权重环。本文将详细介绍Floyd-Warshall算法的定义、步骤及其实现。 Floyd-…...

3DM游戏运行库合集离线安装包2024最新版

3DM游戏运行库合集离线安装包是一款由国内最大的游戏玩家论坛社区3DM推出的集成式游戏运行库合集软件&#xff0c;旨在解决玩家在玩游戏时遇到的运行库缺失或错误问题。该软件包含多种常用的系统运行库组件&#xff0c;支持32位和64位操作系统&#xff0c;能够自动识别系统版本…...

【Bigdata】什么是混合型联机分析处理

这是我父亲 日记里的文字 这是他的生命 留下留下来的散文诗 几十年后 我看着泪流不止 可我的父亲已经 老得像一个影子 &#x1f3b5; 许飞《父亲写的散文诗》 混合型联机分析处理&#xff08;Hybrid OLAP&#xff0c;简称 HOLAP&#xff09;是一种结合了多…...

Java 并发编程:volatile 关键字介绍与使用

大家好&#xff0c;我是栗筝i&#xff0c;这篇文章是我的 “栗筝i 的 Java 技术栈” 专栏的第 026 篇文章&#xff0c;在 “栗筝i 的 Java 技术栈” 这个专栏中我会持续为大家更新 Java 技术相关全套技术栈内容。专栏的主要目标是已经有一定 Java 开发经验&#xff0c;并希望进…...

【Spark计算引擎----第三篇(RDD)---《深入理解 RDD:依赖、Spark 流程、Shuffle 与缓存》】

前言&#xff1a; &#x1f49e;&#x1f49e;大家好&#xff0c;我是书生♡&#xff0c;本阶段和大家一起分享和探索大数据技术Spark—RDD&#xff0c;本篇文章主要讲述了&#xff1a;RDD的依赖、Spark 流程、Shuffle 与缓存等等。欢迎大家一起探索讨论&#xff01;&#xff0…...

四、日志收集loki+ promtail+grafana

一、简介 Loki是受Prometheus启发由Grafana Labs团队开源的水平可扩展&#xff0c;高度可用的多租户日志聚合系统。 开发语言: Google Go。它的设计具有很高的成本效益&#xff0c;并且易于操作。使用标签来作为索引&#xff0c;而不是对全文进行检索&#xff0c;也就是说&…...

IDEA运行Tomcat出现乱码问题解决汇总

最近正值期末周&#xff0c;有很多同学在写期末Java web作业时&#xff0c;运行tomcat出现乱码问题&#xff0c;经过多次解决与研究&#xff0c;我做了如下整理&#xff1a; 原因&#xff1a; IDEA本身编码与tomcat的编码与Windows编码不同导致&#xff0c;Windows 系统控制台…...

Golang dig框架与GraphQL的完美结合

将 Go 的 Dig 依赖注入框架与 GraphQL 结合使用&#xff0c;可以显著提升应用程序的可维护性、可测试性以及灵活性。 Dig 是一个强大的依赖注入容器&#xff0c;能够帮助开发者更好地管理复杂的依赖关系&#xff0c;而 GraphQL 则是一种用于 API 的查询语言&#xff0c;能够提…...

Java - Mysql数据类型对应

Mysql数据类型java数据类型备注整型INT/INTEGERint / java.lang.Integer–BIGINTlong/java.lang.Long–––浮点型FLOATfloat/java.lang.FloatDOUBLEdouble/java.lang.Double–DECIMAL/NUMERICjava.math.BigDecimal字符串型CHARjava.lang.String固定长度字符串VARCHARjava.lang…...

React19源码系列之 事件插件系统

事件类别 事件类型 定义 文档 Event Event 接口表示在 EventTarget 上出现的事件。 Event - Web API | MDN UIEvent UIEvent 接口表示简单的用户界面事件。 UIEvent - Web API | MDN KeyboardEvent KeyboardEvent 对象描述了用户与键盘的交互。 KeyboardEvent - Web…...

华为OD机试-食堂供餐-二分法

import java.util.Arrays; import java.util.Scanner;public class DemoTest3 {public static void main(String[] args) {Scanner in new Scanner(System.in);// 注意 hasNext 和 hasNextLine 的区别while (in.hasNextLine()) { // 注意 while 处理多个 caseint a in.nextIn…...

WordPress插件:AI多语言写作与智能配图、免费AI模型、SEO文章生成

厌倦手动写WordPress文章&#xff1f;AI自动生成&#xff0c;效率提升10倍&#xff01; 支持多语言、自动配图、定时发布&#xff0c;让内容创作更轻松&#xff01; AI内容生成 → 不想每天写文章&#xff1f;AI一键生成高质量内容&#xff01;多语言支持 → 跨境电商必备&am…...

k8s业务程序联调工具-KtConnect

概述 原理 工具作用是建立了一个从本地到集群的单向VPN&#xff0c;根据VPN原理&#xff0c;打通两个内网必然需要借助一个公共中继节点&#xff0c;ktconnect工具巧妙的利用k8s原生的portforward能力&#xff0c;简化了建立连接的过程&#xff0c;apiserver间接起到了中继节…...

在鸿蒙HarmonyOS 5中使用DevEco Studio实现录音机应用

1. 项目配置与权限设置 1.1 配置module.json5 {"module": {"requestPermissions": [{"name": "ohos.permission.MICROPHONE","reason": "录音需要麦克风权限"},{"name": "ohos.permission.WRITE…...

uniapp中使用aixos 报错

问题&#xff1a; 在uniapp中使用aixos&#xff0c;运行后报如下错误&#xff1a; AxiosError: There is no suitable adapter to dispatch the request since : - adapter xhr is not supported by the environment - adapter http is not available in the build 解决方案&…...

OpenLayers 分屏对比(地图联动)

注&#xff1a;当前使用的是 ol 5.3.0 版本&#xff0c;天地图使用的key请到天地图官网申请&#xff0c;并替换为自己的key 地图分屏对比在WebGIS开发中是很常见的功能&#xff0c;和卷帘图层不一样的是&#xff0c;分屏对比是在各个地图中添加相同或者不同的图层进行对比查看。…...