当前位置:网站首页>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
边栏推荐
- MMAP learning
- 元宇宙中的三大“派系”
- Hysbz 2243 staining (tree chain splitting)
- Cross end solutions to improve development efficiency
- Matlab draws a cute fat doll
- Huawei cloud modelarts text classification - takeout comments
- C language knowledge points link
- AD637 usage notes
- Stored procedures and stored functions
- Multiplexing of Oracle control files
猜你喜欢
Performance monitoring of database tuning solutions
A trip to Suzhou during the Dragon Boat Festival holiday
Shell script, awk condition judgment and logic comparison &||
Win11运行cmd提示“请求的操作需要提升”的解决方法
What about data leakage? " Watson k'7 moves to eliminate security threats
[Yugong series] go teaching course in July 2022 004 go code Notes
科技云报道荣膺全球云计算大会“云鼎奖”2013-2022十周年特别贡献奖
MySQL disconnection reports an error MySQL ldb_ exceptions. OperationalError 4031, The client was disconnected by the server
Granularity of blocking of concurrency control
The American Championship is about to start. Are you ready?
随机推荐
Concurrency control of performance tuning methodology
About the writing method of SQL field "this includes" and "included in" strings
Leetcode simple question ring and rod
Win11缺少dll文件怎么办?Win11系统找不到dll文件修复方法
Form artifact
Interview questions for basic software testing
Blocking protocol for concurrency control
poj 3237 Tree(樹鏈拆分)
Implementing Lmax disruptor queue from scratch (IV) principle analysis of multithreaded producer multiproducersequencer
K210学习笔记(四) K210同时运行多个模型
装饰器学习01
Sub total of Pico development
U盘的文件无法删除文件怎么办?Win11无法删除U盘文件解决教程
Oracle advanced query
ICMP 介绍
Poj3414广泛搜索
Alternating merging strings of leetcode simple questions
Matlab | app designer · I used Matlab to make a real-time editor of latex formula
Bitbucket installation configuration
NET中小型企业项目开发框架系列(一个)