Linux驱动三要素之——总线

张开发
2026/6/8 6:10:18 15 分钟阅读
Linux驱动三要素之——总线
linux驱动三要素总线、设备、驱动我们讲一下总线的由来。历史原因Linux 不想为 “无总线设备” 再发明一套新框架早期 Linux 驱动模型I2C 设备 → 走 I2C 总线PCI 设备 → 走 PCI 总线USB 设备 → 走 USB 总线UART、GPIO、TIMER、NPU、ISP 这类 内存映射控制器 → 没硬件总线内核开发者不想为内存映射设备再写一套独立框架再搞一套匹配、注册、电源管理逻辑于是直接复用已有的总线框架创建了一条虚拟的、软件 - only 的总线让这些设备也能挂上去被统一管理和驱动匹配。官方文档原文如下Platform Devices and DriversSee linux/platform_device.h for the driver model interface to the platform bus: platform_device, and platform_driver. This pseudo-bus is used to connect devices on buses with minimal infrastructure, like those used to integrate peripherals on many system-on-chip processors, or some “legacy” PC interconnects; as opposed to large formally specified ones like PCI or USB.Linux kernel官方文档路径https://docs.kernel.org/driver-api/driver-model/platform.html 一、内核官方文档 https://docs.kernel.org 结构就是API 使用手册查 platform、pinctrl、clock、reset、dma、i2c、spi、regulator 一应俱全 每个接口怎么用、结构体含义、例子都有版本跟内核同步不会过时 二、Linux 内核邮件列表 https://lkml.org/lkml/2011/3/17/283 全球 Linux 内核开发者最核心、最原始、最权威的公开讨论社区 三、驱动开发小抄式手册 https://lwn.net/Kernel/LDD3/ 经典到所有驱动框架逻辑都讲透字符设备、ioctl、mmap、poll、proc、sysfs 全套模板 可以当框架模板手册用语言直白不像内核文档那么生硬有些接口老了但思想和框架永不过时 四、内核源码在线浏览 https://git.kernel.org/ 写驱动最终都要查 platform_bus_type 定义 of_match_ptr 是啥 devm_xxx 函数实现 结构体成员

更多文章