platform devices创建实例

来看一个cortina Gemini ethernet driver的例子。

DTS file路径 /arch/arm/boot/dts/gemini/gemini.dtsi.

Driver 路径 drivers/net/ethernet/cortina/gemini.c

 {soc {#address-cells = <1>;#size-cells = <1>;ranges;compatible = "simple-bus";....ethernet: ethernet@60000000 {compatible = "cortina,gemini-ethernet";reg = <0x60000000 0x4000>, /* Global registers, queue */<0x60004000 0x2000>, /* V-bit */<0x60006000 0x2000>; /* A-bit */pinctrl-names = "default";pinctrl-0 = <&gmii_default_pins>;status = "disabled";#address-cells = <1>;#size-cells = <1>;ranges;gmac0: ethernet-port@0 {compatible = "cortina,gemini-ethernet-port";reg = <0x60008000 0x2000>, /* Port 0 DMA/TOE */<0x6000a000 0x2000>; /* Port 0 GMAC */interrupt-parent = <&intcon>;interrupts = <1 IRQ_TYPE_LEVEL_HIGH>;resets = <&syscon GEMINI_RESET_GMAC0>;clocks = <&syscon GEMINI_CLK_GATE_GMAC0>;clock-names = "PCLK";};gmac1: ethernet-port@1 {compatible = "cortina,gemini-ethernet-port";reg = <0x6000c000 0x2000>, /* Port 1 DMA/TOE */<0x6000e000 0x2000>; /* Port 1 GMAC */interrupt-parent = <&intcon>;interrupts = <2 IRQ_TYPE_LEVEL_HIGH>;resets = <&syscon GEMINI_RESET_GMAC1>;clocks = <&syscon GEMINI_CLK_GATE_GMAC1>;clock-names = "PCLK";};};};};

有之前的博文分析, 根节点下的含有compatible属性的节点在内核启动时会为其创建platform device, 因此 soc节点会有一个platform device与其对应。而soc节点的compatible为已知的特殊属性“simple-bus”, 因此也会为其下面的子节点创建platform device, 故 “ethernet”也会有platform device 与其对应。那么“ethernet”厂商驱动只需写自己的平台设备驱动即可。对应以太网驱动,“ethernet”下的子节点 “gmac0” 通常是在ethernet 驱动下解析子节点然后为其创建netdevice。

但是我们看gemini driver, 其对于每个ethernet port 即“gmac”子节点也单独设计的platform driver. 那么ethernet port子节点是如何创建成平台devices的呢?

我们看其处理, 在“ethernet” driver probe函数的结尾使用 devm_of_platform_populate 为其子节点创建platfrom device.

static int gemini_ethernet_port_probe(struct platform_device *pdev)
{struct gemini_ethernet_port *port;struct gemini_ethernet *geth;parent = dev->parent; //获取其parent “ethernet”devicegeth = dev_get_drvdata(parent);  // 获取 “etherent” private data.....port = netdev_priv(netdev);SET_NETDEV_DEV(netdev, dev);port->netdev = netdev;port->id = id;port->geth = geth; // ethernet port private与 ethernet private建立关系
}static int gemini_ethernet_probe(struct platform_device *pdev)
{..../* Spawn child devices for the two ports */return devm_of_platform_populate(dev); //为 ethernet port 子节点创建平台devices}static struct platform_driver gemini_ethernet_driver = {.driver = {.name = DRV_NAME,.of_match_table = gemini_ethernet_of_match,},.probe = gemini_ethernet_probe,.remove_new = gemini_ethernet_remove,
};static int __init gemini_ethernet_module_init(void)
{int ret;ret = platform_driver_register(&gemini_ethernet_port_driver);if (ret)return ret;ret = platform_driver_register(&gemini_ethernet_driver);if (ret) {platform_driver_unregister(&gemini_ethernet_port_driver);return ret;}return 0;
}

 思考: 如果dts设计成如下, 如何将ethernet-port 节点创建成platform devices呢?

             ethernet: ethernet@60000000 {compatible = "cortina,gemini-ethernet";......ethernet-ports {#address-cells = <1>#size-cells = <0>;gmac0: ethernet-port@0 {compatible = "cortina,gemini-ethernet-port";reg = <0x60008000 0x2000>, /* Port 0 DMA/TOE */<0x6000a000 0x2000>; /* Port 0 GMAC */...};gmac1: ethernet-port@1 {compatible = "cortina,gemini-ethernet-port";reg = <0x6000c000 0x2000>, /* Port 1 DMA/TOE */<0x6000e000 0x2000>; /* Port 1 GMAC */...};};};

方法一:为“ethernet-ports”创建平台device

const struct of_device_id of_ethernet_ports_match_table[] = {

        {.compatible = "cortina,gemini-ethernet-ports", },

        {}

};
of_platform_populate(pdev->dev.of_node, of_ethernet_ports_match_table, NULL, &pdev->dev);

在 ethernet probe 函数结尾使用上述, 同时DTS中为“ethernet-ports” 节点添加compatible 属性“cortina,gemini-ethernet-ports

这样 of_platform_populate(pdev->dev.of_node, of_ethernet_ports_match_table, NULL, &pdev->dev)函数会为其子节点“ethernet-ports” 创建platform device. 同时为“ethernet-ports”的子节点“ethernet-port”创建platform device.

# cat /sys/devices/platform/soc/60000000.ethernet/60000000.ethernet:ethernet-ports/
60000000.ethernet:ethernet-ports:ethernet-port@0/
60000000.ethernet:ethernet-ports:ethernet-port@1/

方法二: 绕过 “ethernet-ports” 为 “etherne-port”创建平台device


ethernet_ports_node = of_get_child_by_name(ppe->dev->of_node, "ethernet-ports");
of_platform_populate(ethernet_ports_node, NULL, NULL, &pdev->dev ); 

在ethernet driver probe结尾使用上述,即 ethernet driver中parse “ethernet-ports”自己点然后调用populate函数为 “ethernet-ports”自己点创建平台设备。注意这里parent device参数仍然使用ethernet devie, 因为“ethernet-ports”并没有创建任何device, “ethernet-port” device hook在 “ethernet” device上。

# cat /sys/devices/platform/soc/60000000.ethernet/
60000000.ethernet:ethernet-ports:ethernet-port@0/
60000000.ethernet:ethernet-ports:ethernet-port@1/ 

 再回顾popuate相关函数的实现, 可以看出最终都归结到of_platform_populate函数,第一个参数root为device node类型, 表示要为改device node下的node穿件平台device, 如果为NULL表示根节点(kernel 启动时就是指定的NULL)。第二个参数 matches 可以指定compatible属性,表示 root的子节点如果有子节点match该属性列表就位子节点的子节点继续创建平台device,为NULL则只会创建一级device。最后一个参数struct device *parent表示 root下第一级子节点device的parent device.

/*** of_platform_populate() - Populate platform_devices from device tree data* @root: parent of the first level to probe or NULL for the root of the tree* @matches: match table, NULL to use the default* @lookup: auxdata table for matching id and platform_data with device nodes* @parent: parent to hook devices from, NULL for toplevel** Similar to of_platform_bus_probe(), this function walks the device tree* and creates devices from nodes.  It differs in that it follows the modern* convention of requiring all device nodes to have a 'compatible' property,* and it is suitable for creating devices which are children of the root* node (of_platform_bus_probe will only create children of the root which* are selected by the @matches argument).** New board support should be using this function instead of* of_platform_bus_probe().** Return: 0 on success, < 0 on failure.*/
int of_platform_populate(struct device_node *root,const struct of_device_id *matches,const struct of_dev_auxdata *lookup,struct device *parent)
{......
}const struct of_device_id of_default_bus_match_table[] = {{ .compatible = "simple-bus", },{ .compatible = "simple-mfd", },{ .compatible = "isa", },
#ifdef CONFIG_ARM_AMBA{ .compatible = "arm,amba-bus", },
#endif /* CONFIG_ARM_AMBA */{} /* Empty terminated list */
};int of_platform_default_populate(struct device_node *root,const struct of_dev_auxdata *lookup,struct device *parent)
{return of_platform_populate(root, of_default_bus_match_table, lookup,parent);
}static int __init of_platform_default_populate_init(void)
{/* Populate everything else. */of_platform_default_populate(NULL, NULL, NULL);
}int devm_of_platform_populate(struct device *dev)
{struct device **ptr;int ret;if (!dev)return -EINVAL;ptr = devres_alloc(devm_of_platform_populate_release,sizeof(*ptr), GFP_KERNEL);if (!ptr)return -ENOMEM;ret = of_platform_populate(dev->of_node, NULL, NULL, dev);if (ret) {devres_free(ptr);} else {*ptr = dev;devres_add(dev, ptr);}return ret;
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/767045.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

双系统安装03--在已有麒麟KOS基础上安装Windows10

原文链接&#xff1a;双系统安装03–在已有麒麟KOS基础上安装Windows10 Hello&#xff0c;大家好啊&#xff01;继我们之前讨论的关于双系统安装的系列文章之后&#xff0c;今天我将带给大家这个系列的第三篇——在已有的麒麟桌面操作系统上安装Windows 10。对于想要在使用麒麟…

OpenCV支持哪些类型的文件格式读写?

OpenCV支持多种类型的文件格式读写&#xff0c;包括但不限于以下格式&#xff1a; Windows位图文件&#xff1a;包括BMP和DIB格式。JPEG文件&#xff1a;支持JPEG、JPG和JPE三种扩展名。便携式网络图片&#xff1a;即PNG格式。便携式图像格式&#xff1a;包括PBM、PGM和PPM三种…

Kafka系列之:Exactly-once support

Kafka系列之:Exactly-once support 一、Sink connectors二、Source connectors三、Worker configuration四、ACL requirementsKafka Connect 能够为接收器连接器(从版本 0.11.0 开始)和源连接器(从版本 3.3.0 开始)提供一次性语义。请注意,对一次语义的支持高度依赖于您运…

关于Mysql表中使用‘utf8mb4_unicode_ci’字符集问题

业务场景&#xff1a;需求点项目excel数据导入&#xff0c;会对重复名称校验拦截&#xff0c;如&#xff1a;之前已插入名称为-半角括号“&#xff08;a&#xff09;”,再次插入一条名称为-全角括号项目“(a)”,校验通过&#xff0c;但是插入数据库报错。 原因&#xff1a;由于…

docker安装ES7.1.1(单机版)+ik分词器+es-head可视化

系列文章目录 文章目录 系列文章目录前言 前言 前些天发现了一个巨牛的人工智能学习网站&#xff0c;通俗易懂&#xff0c;风趣幽默&#xff0c;忍不住分享一下给大家。点击跳转到网站&#xff0c;这篇文章男女通用&#xff0c;看懂了就去分享给你的码吧。 Elasticsearch 是一…

力扣236 二叉树的最近公共祖先 Java版本

文章目录 题目描述代码 题目描述 给定一个二叉树, 找到该树中两个指定节点的最近公共祖先。 百度百科中最近公共祖先的定义为&#xff1a;“对于有根树 T 的两个节点 p、q&#xff0c;最近公共祖先表示为一个节点 x&#xff0c;满足 x 是 p、q 的祖先且 x 的深度尽可能大&…

滑动窗口(尺取法)

滑动窗口&#xff08;尺取法&#xff09; 算法含义&#xff1a; 在解决关于区间特性的题目时保存搜索区间左右端点&#xff0c;然后根据实际要求不断更新左右端点位置的算法 时间复杂度&#xff1a; O ( n ) O(n) O(n) 空间复杂度&#xff1a; O ( 1 ) O(1) O(1) 在历年真题…

【React】在 JSX 中通过大括号使用 JavaScript

在 JSX 中使用大括号可以执行各种 JavaScript 操作&#xff0c;包括传递字符串、引用变量、调用函数以及使用对象。下面是一些具体的例子&#xff1a; 使用引号传递字符串 在 JSX 中&#xff0c;如果你想直接输出一个字符串&#xff0c;你可以直接在花括号内使用双引号或单引…

FlyControls 是 THREE.js 中用于实现飞行控制的类,它用于控制摄像机在三维空间中的飞行。

demo演示地址 FlyControls 是 THREE.js 中用于实现飞行控制的类&#xff0c;它用于控制摄像机在三维空间中的飞行。 入参&#xff1a; object&#xff1a;摄像机对象&#xff0c;即要控制的摄像机。domElement&#xff1a;用于接收用户输入事件的 HTML 元素&#xff0c;通常…

C++函数参数传递

目录 传值参数 指针形参 传引用参数 使用引用避免拷贝 使用引用形参返回额外信息 const形参和实参 指针或引用形参与const 数组形参 管理指针形参 使用标记指定数组长度 使用标准库规范 显式传递一个表示数组大小的形参 数组形参和const 数组引用形参 传递多维数…

Django缓存(一)

一、缓存的介绍 官网:Django 缓存框架 | Django 文档 | Django 为什么要什么缓存? 为了减少服务器的计算开销 Django框架自带有一个强大的缓存系统,可以保存动态页面,因此不必为每个请求计算它们。为了方便,Django提供不同级别的缓存粒度:可以缓存特定视图的输出,可以只…

Web核心简介

简介 web&#xff1a;全球广域网&#xff0c;也称万维网(www)&#xff0c;能够通过浏览器访问的网站 JavaWeb&#xff1a;是用Java技术来解决相关web互联网领域的技术栈 JavaWeb技术栈 B/S架构&#xff1a;Browser/Server&#xff0c;浏览器/服务器架构模式&#xff0c;它的…

走迷宫----bfs再矩阵图里的应用模版

对于之前走迷宫的那个题 回忆一下dfs的代码 #include <bits/stdc.h> using namespace std; int a[110][110]; bool check[110][110]; int n,m; int ans1e9; int nxt[4][2]{{1,0},{0,-1},{-1,0},{0,1}}; void dfs(int x,int y,int step){if(xn&&ym){ansmin(ans,…

IntelliJ IDEA集成git配置账号密码

1 背景说明 刚使用IDEA,本地也安装Git,在提交和拉取代码的时候,总提示登录框,而且登录框还不能输入账号密码,只能输入登录Token。如下: 从而无法正常使用IDEA的Git功能,很苦恼。 2 解决方法 2.1 安装Git 进入官网地址 https://git-scm.com/,点击下载: 浏览器直接…

python中的IO流及其对象序列化

IO流input output stream的缩写 侠义&#xff1a;常见的IO操作是指内存与磁盘之间的输入和输出的操作 io流的操作是一种持久化操作。将数据持久化到磁盘上 open全局函数&#xff1a; 第一个参数file&#xff1a;代表的是打开或者操作的文件的文件名或者路径 第二个参数mod…

机器学习算法那些事 | 使用Transformer模型进行时间序列预测实战

本文来源公众号“机器学习算法那些事”&#xff0c;仅用于学术分享&#xff0c;侵权删&#xff0c;干货满满。 原文链接&#xff1a;使用Transformer模型进行时间序列预测实战 时间序列预测是一个经久不衰的主题&#xff0c;受自然语言处理领域的成功启发&#xff0c;transfo…

WPS制作甘特图

“ 甘特图&#xff08;Gantt chart&#xff09;又称为横道图、条状图&#xff08;Bar chart&#xff09;&#xff0c;通过条状图来显示项目、进度和其他时间相关的系统进展的内在关系随着时间进展的情况。” 设置基础样式 设置行高 设置宽度 准备基础数据 计算持续时间 …

轻松引流几百精准粉丝,抖音自动爆粉秘籍揭秘

对于做互联网的朋友们来说&#xff0c;引流是一个必不可少的环节。 掌握一种优秀的引流方法至关重要&#xff0c;这也可以视为我们的生计之源。 今天&#xff0c;我将向大家介绍一款全自动的引流工具——抖音全自动引流脚本软件。 这款软件的效果非常显著&#xff0c;它可以替…

R-CNN笔记

目标检测之R-CNN论文精讲&#xff0c;RCNN_哔哩哔哩_bilibili 论文背景 在该论文提出之前&#xff0c;主流的目标检测思路是&#xff1a; 将一幅图片划分成很多个区域&#xff0c;单独提取出来 对于每个区域使用传统的特征提取方法提取 提取结束后可以使用以为特征向量表示 可以…

计算方法实验2:列主元消元法和Gauss-Seidel迭代法解线性方程组

Task 即已知 y 0 0 , y 100 1 y_00,y_{100}1 y0​0,y100​1&#xff0c;解线性方程组 A y b \mathbf{A}\mathbf{y} \mathbf{b} Ayb&#xff0c;其中 A 99 99 [ − ( 2 ϵ h ) ϵ h 0 ⋯ 0 ϵ − ( 2 ϵ h ) ϵ h ⋯ 0 0 ϵ − ( 2 ϵ h ) ⋯ 0 ⋮ ⋮ ⋱ ⋱ ⋮ 0 0 ⋯…