当前位置:网站首页>Platform bus
Platform bus
2022-07-05 22:10:00 【wwwlyj123321】
platform The development steps of bus driver are :
1、 equipment
The structure to be implemented is :platform_device .
1) initialization resource Structural variable
2) initialization platform_device Structural variable
3) Register the device with the system :platform_device_register.( Registration means cancellation ,platform_device_unregister, It is usually called when unloading the driver )
Three steps above , It must be done before the device driver is loaded , The perform platform_driver_register() Before , The reason is that driver registration needs to match all registered device names in the kernel .platform_driver_register() Add device In the end, it's called by the kernel device_add function .Platform_device_add and device_add The main difference is one more step insert_resource(p, r), the platform resources (resource) Add to the kernel , Managed by the kernel .
struct platform_device {
const char *name;// Drive to match , load device It will be in sys/bus/platfrom/devices The name of the path is name Node file
int id; // equipment id, Give the same name The equipment is numbered , If there is only one device , Fill in -1 that will do
bool id_auto;
struct device dev;// General properties of equipment
u64 platform_dma_mask;
struct device_dma_parameters dma_parms;
u32 num_resources; // The amount of resources
struct resource *resource; //device Hardware resources in , Register address , Interrupt number , Clock and so on
const struct platform_device_id *id_entry;
char *driver_override; /* Driver name to force a match */
/* MFD cell pointer */
struct mfd_cell *mfd_cell;
/* arch specific additions */
struct pdev_archdata archdata;
};
linux/ioport.h
struct resource {
resource_size_t start;
resource_size_t end;
const char *name;
unsigned long flags;
struct resource *parent, *sibling, *child;
};
flags Bits can represent the type of resource , As follows :
#define IORESOURCE_BITS 0x000000ff /* Bus-specific bits */
#define IORESOURCE_TYPE_BITS 0x00001f00 /* Resource type */
#define IORESOURCE_IO 0x00000100 /* PCI/ISA I/O ports */
#define IORESOURCE_MEM 0x00000200 /* Represents a piece of physical memory */
#define IORESOURCE_REG 0x00000300 /* Register offsets */
#define IORESOURCE_IRQ 0x00000400 /* Interrupt number */
#define IORESOURCE_DMA 0x00000800
#define IORESOURCE_BUS 0x00001000 /* Bus , Such as IIC Bus ,SPI Bus etc. */
2、 drive
initialization platform_driver Structural variable , contain prober Functions, etc
call platform_driver_register Register the driver with the platform bus
Be careful :
1、 Load the driver first and load the device first , There is no order
2、platform_driver ->id_table->name and platform_driver->driver->name Are used to match the equipment , And platform_driver ->id_table->name Priority of . That is, when there are both , But inconsistent , With platform_driver ->id_table->name Subject to .
///include/linux/platform_device.h
struct platform_driver {
int (*probe)(struct platform_device *); //device and driver If the match is successful, this function will be executed
int (*remove)(struct platform_device *); //device and driver Any one rm This function will be executed when
void (*shutdown)(struct platform_device *); //device received shutdown Command to execute this function
int (*suspend)(struct platform_device *, pm_message_t state); //device After receiving the sleep command, execute this function
int (*resume)(struct platform_device *); //device After receiving the wake-up command, execute this function
struct device_driver driver; //
const struct platform_device_id *id_table; // There is also one in this structure Name member , Also used matching equipment , This priority is higher than device Medium name higher
bool prevent_deferred_probe;
};
///include/linux/device/driver.h
struct device_driver {
const char *name; // The name used in matching
struct bus_type *bus;
struct module *owner; // It's usually THIS_MODULE
const char *mod_name; /* used for built-in modules */
bool suppress_bind_attrs; /* disables bind/unbind via sysfs */
enum probe_type probe_type;
const struct of_device_id *of_match_table; // Combined with device tree , Set the matching table with the device tree
const struct acpi_device_id *acpi_match_table;
int (*probe) (struct device *dev);
void (*sync_state)(struct device *dev);
int (*remove) (struct device *dev);
void (*shutdown) (struct device *dev);
int (*suspend) (struct device *dev, pm_message_t state);
int (*resume) (struct device *dev);
const struct attribute_group **groups;
const struct attribute_group **dev_groups;
const struct dev_pm_ops *pm;
void (*coredump) (struct device *dev);
struct driver_private *p;
};
struct platform_device_id {
char name[PLATFORM_NAME_SIZE]; // It is also used to match the equipment , This has a high priority
kernel_ulong_t driver_data;
};
probe Function writing ideas :
from device.c Get hardware resources in
Method 1 :int (*probe)(struct platform_device *) The formal parameter in the function points to platform_device Structure , Directly access the formal parameter ( Not recommended )
Method 2 : Use API Function access ,struct resource *platform_get_resource(struct platform_device *dev,unsigned int type, unsigned int num),type It's the type of resource , and flags Corresponding ,num Said is similar Number of resources .
Register driver , perfect file_operation Structure , And generate device nodes
ref:
platform_device.h - include/linux/platform_device.h - Linux source code (v5.16.9) - Bootlin
ioport.h - include/linux/ioport.h - Linux source code (v5.16.9) - Bootlin
边栏推荐
- How to use tensorflow2 for cat and dog classification and recognition
- EL与JSTL注意事项汇总
- 如何组织一场实战攻防演练
- Matlab | app designer · I used Matlab to make a real-time editor of latex formula
- 装饰器学习01
- Stored procedures and stored functions
- 科技云报道荣膺全球云计算大会“云鼎奖”2013-2022十周年特别贡献奖
- 从零开始实现lmax-Disruptor队列(四)多线程生产者MultiProducerSequencer原理解析
- 等到产业互联网时代真正发展成熟,我们将会看待一系列的新产业巨头的出现
- MySQL连接断开报错MySQLdb._exceptions.OperationalError 4031, The client was disconnected by the server
猜你喜欢
Win11缺少dll文件怎么办?Win11系统找不到dll文件修复方法
K210 learning notes (IV) k210 runs multiple models at the same time
Calculation method of boundary IOU
Stored procedures and stored functions
Win11运行cmd提示“请求的操作需要提升”的解决方法
Interprocess communication in the "Chris Richardson microservice series" microservice architecture
2022-07-05:给定一个数组,想随时查询任何范围上的最大值。 如果只是根据初始数组建立、并且以后没有修改, 那么RMQ方法比线段树方法好实现,时间复杂度O(N*logN),额外空间复杂度O(N*
Oracle advanced query
boundary IoU 的计算方式
Lightweight dynamic monitorable thread pool based on configuration center - dynamictp
随机推荐
Cobaltstrike builds an intranet tunnel
HDU 4391 paint the wall segment tree (water
How can Bluetooth in notebook computer be used to connect headphones
What if the files on the USB flash disk cannot be deleted? Win11 unable to delete U disk file solution tutorial
Sub total of Pico development
Win11 runs CMD to prompt the solution of "the requested operation needs to be promoted"
What if win11 is missing a DLL file? Win11 system cannot find DLL file repair method
Leetcode simple question check whether all characters appear the same number of times
Performance monitoring of database tuning solutions
Cross end solutions to improve development efficiency
Net small and medium-sized enterprise project development framework series (one)
U盘的文件无法删除文件怎么办?Win11无法删除U盘文件解决教程
Ad637 notes d'utilisation
Decorator learning 01
Poj3414广泛搜索
每日刷题记录 (十四)
2022-07-05:给定一个数组,想随时查询任何范围上的最大值。 如果只是根据初始数组建立、并且以后没有修改, 那么RMQ方法比线段树方法好实现,时间复杂度O(N*logN),额外空间复杂度O(N*
Summary of concurrency control
[Yugong series] go teaching course 003-ide installation and basic use in July 2022
微服务入门(RestTemplate、Eureka、Nacos、Feign、Gateway)