当前位置:网站首页>Driver Architecture & platform platform bus driver model
Driver Architecture & platform platform bus driver model
2022-06-23 08:25:00 【Be good to me】
1、 Driver Architecture
1.1 bus Bus
struct bus_type platform_bus_type = {
.name = "platform",
.dev_groups = platform_dev_groups,
.match = platform_match,
...
};
int __init platform_bus_init(void)
{
...
// register platform_bus, Its type I bus_type
error = bus_register(&platform_bus_type);
...
}
1.2 device equipment
struct device {
struct kobject kobj;
struct device *parent;
struct device_private *p;
const char *init_name; /* initial name of the device */
const struct device_type *type;
struct bus_type *bus; /* type of bus device is on */
struct device_driver *driver; /* which driver has allocated this device */
void *platform_data; /* Platform specific data, device core doesn't touch it */
void *driver_data; /* Driver data, set and get with dev_set_drvdata/dev_get_drvdata */
}
int of_device_add(struct platform_device *ofdev)
{
// register platform_device It's really just the platform_device Of device register
return device_add(&ofdev->dev);
}
static struct platform_device *of_platform_device_create_pdata(
struct device_node *np,
const char *bus_id,
void *platform_data,
struct device *parent)
{
struct platform_device *dev;
// Definition platform_device Bus type of , Indicates that it is hung on platform_bus below
dev->dev.bus = &platform_bus_type;
// register platform_device
if (of_device_add(dev) != 0) {
platform_device_put(dev);
goto err_clear_flag;
}
...
}
1.3 driver drive
static struct platform_driver onboard_hub_driver = {
.probe = onboard_hub_probe,
.remove = onboard_hub_remove,
.driver = {
.name = "onboard-usb-hub",
.of_match_table = onboard_hub_match,
.pm = pm_ptr(&onboard_hub_pm_ops),
.dev_groups = onboard_hub_groups,
},
};
int __platform_driver_register(struct platform_driver *drv,
struct module *owner)
{
drv->driver.owner = owner;
// Definition platform_driver Bus type of , Indicates that it is hung on platform_bus below
drv->driver.bus = &platform_bus_type;
drv->driver.probe = platform_drv_probe;
drv->driver.remove = platform_drv_remove;
drv->driver.shutdown = platform_drv_shutdown;
// register platform_driver It's actually registration platform_driver Of device_driver
return driver_register(&drv->driver);
}
static int __init onboard_hub_init(void)
{
...
// register platform_driver
ret = platform_driver_register(&onboard_hub_driver);
...
}
2、platform Drive model
platform The bus is kernel 2.6 A virtual bus introduced in , Mainly used for management CPU On chip resources , It has good portability . be relative to USB、PCI、I2C And so on , The platform bus is Linux The device driver model is a virtual bus designed to maintain the unity of device drivers .
usb、i2c、pci And other devices are directly connected to the corresponding bus cpu For data interaction , But in embedded systems , Not all devices can belong to these common bus types . Such as SoC Independent peripheral controller integrated in the system 、 Hang on to SoC Peripherals of memory space, etc , Are not attached to such a bus .
In general, as long as the kernel itself and run less dependent on peripheral devices , Relatively independent , Have their own independent resources ( Address bus and IRQs), Both can be used. platform driver To manage , and timer,irq It's better not to use the equipment in the small system platfrom driver Mechanism .
2.1 platform_device
struct platform_device {
const char *name; // Define the name of the platform device , Consistent with the corresponding driver name
struct device dev;
struct resource *resource; // Define resources for platform devices
};
It's encapsulated in this structure struct device And struct resource. You know :platform_device from device Derived from , It's a special kind device.
Register device :
int platform_device_register(struct platform_device *pdev);
2.2 platform_driver
struct platform_driver {
int (*probe)(struct platform_device *);
const char *name;
const struct platform_device_id *id_table;
int (*remove)(struct platform_device *);
int (*suspend)(struct platform_device *, pm_message_t state);
int (*resume)(struct platform_device *);
struct device_driver driver;
};
so ,platform_driver It contains several function functions for equipment operation , It also contains a device_driver structure , explain device_driver yes platform_driver Base class of . Registration drive :
int platform_driver_register(struct platform_driver *drv);
2.3 platform_bus
struct bus_type platform_bus_type = {
.name = "platform",
.dev_groups = platform_dev_groups,
.match = platform_match,
.uevent = platform_uevent,
.dma_configure = platform_dma_configure,
.pm = &platform_dev_pm_ops,
};
Platform driver adopt platform bus obtain platform_device.
2.4 Match method
(1) Priority matching driver Medium id_table, It contains names that support different platforms ;
(2) Direct match driver Name and device The name of .
2.5 platform_driver Member functions
platform_driver And platform_device Enter after matching driver Of probe function , When entering probe After the function , You need to implement a series of function interfaces , Include :
(1) Registration drive :
int platform_driver_register(struct platform_driver *drv);
Add driver to platform Bus linked list ( Namely registration ), Wait for the device to appear , And the bus completes the matching and correlation process between the device and the driver .
(2) Get the resource information of the device :
platform_get_resource(struct platform_device * dev, unsigned int type, unsigned int num);
(3) Get the interrupt number in the resource :
struct int platform_get_irq(struct platform_device *dev, unsigned int num);
(4)driver adopt file_operations The member function realizes the communication with the user space .
static const struct file_operations i2cdev_fops = {
.owner = THIS_MODULE,
.llseek = no_llseek,
.read = i2cdev_read,
.write = i2cdev_write,
.ioctl = i2cdev_ioctl,
.open = i2cdev_open,
.release = i2cdev_release,
};
边栏推荐
- Open source technology exchange batch stream integrated data synchronization engine Chunjun data restore DDL function module analysis
- Go 数据类型篇(二)之Go 支持的数据类型概述及布尔类型
- 7-调色板-CALayer和触摸
- RTSP/ONVIF协议视频平台EasyNVR启动服务报错“service not found”,该如何解决?
- How to start Jupiter notebook in CONDA virtual environment
- Production environment server environment setup + project release process
- Integers and operators in go data types (3)
- GTEST death test
- 爬虫框架
- View the file once a second and send the result of the last line of the file to the syslog server
猜你喜欢

Commonly used bypass methods for SQL injection -ctf

最常用的5中流ETL模式

Ignore overlength parameter violation

PHP serialization and deserialization CTF

目标检测中的多尺度特征结合方式

开源软件、自由软件、Copyleft、CC都是啥,傻傻分不清楚?

自组织映射神经网络(SOM)

Open source technology exchange batch stream integrated data synchronization engine Chunjun data restore DDL function module analysis

Image segmentation - improved network structure

Why use growth neural gas network (GNG)?
随机推荐
jmeter压测结果分析
点云库pcl从入门到精通 第十章
C Advanced Learning -- extended method (this)
驱动架构 & platform平台总线驱动模型
Integers and operators in go data types (3)
kibana 重建index后,如何恢复Visualizations和 Dashboards
Copy image bitmap by C # memory method
目标检测中的多尺度特征结合方式
What are open source software, free software, copyleft and CC? Can't you tell them clearly?
Azure Active Directory brute force attack
Regular expression use cases
Focus! Ten minutes to master Newton convex optimization
Location of firewalld configuration file
【云计算】GFS思想优势以及架构
Markdown learning
usb peripheral 驱动 - debug
You have a string of code, but do not support the lower version of go; Judge the go version number, you deserve it!
Map接口及其子实现类
Open source technology exchange batch stream integrated data synchronization engine Chunjun data restore DDL function module analysis
MySQL小册子笔记 5 InnoDB 记录存储结构