当前位置:网站首页>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
边栏推荐
- Database tuning solution
- 每日刷题记录 (十四)
- Tips for using SecureCRT
- Oracle hint understanding
- Common interview questions of JVM manufacturers
- Learning of mall permission module
- 阿龙的感悟
- MySQL服务莫名宕机的解决方案
- PyGame practical project: write Snake games with 300 lines of code
- 从零开始实现lmax-Disruptor队列(四)多线程生产者MultiProducerSequencer原理解析
猜你喜欢
Pl/sql basic case
[Yugong series] go teaching course in July 2022 004 go code Notes
Server optimization of performance tuning methodology
Interview questions for famous enterprises: Coins represent a given value
AD637使用筆記
装饰器学习01
The difference between MVVM and MVC
Win11运行cmd提示“请求的操作需要提升”的解决方法
Talking about MySQL index
Experienced inductance manufacturers tell you what makes the inductance noisy. Inductance noise is a common inductance fault. If the used inductance makes noise, you don't have to worry. You just need
随机推荐
如何开发引入小程序插件
Official clarification statement of Jihu company
Web3为互联网带来了哪些改变?
The American Championship is about to start. Are you ready?
Oracle views the data size of a table
How to organize an actual attack and defense drill
The difference between MVVM and MVC
Text组件新增内容通过tag_config设置前景色、背景色
Performance testing of software testing
Ad637 notes d'utilisation
Oracle hint understanding
Pl/sql basic syntax
Regular expressions and re Libraries
Leetcode simple question ring and rod
Bitbucket installation configuration
Leetcode simple question: find the nearest point with the same X or Y coordinate
What about data leakage? " Watson k'7 moves to eliminate security threats
Concurrency control of performance tuning methodology
[Yugong series] go teaching course in July 2022 004 go code Notes
Huawei cloud modelarts text classification - takeout comments