当前位置:网站首页>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
边栏推荐
- Granularity of blocking of concurrency control
- Shell script, awk condition judgment and logic comparison &||
- Unique occurrence times of leetcode simple questions
- 极狐公司官方澄清声明
- Official clarification statement of Jihu company
- MMAP learning
- Meituan dynamic thread pool practice ideas, open source
- Type of fault
- The difference between MVVM and MVC
- AD637使用筆記
猜你喜欢

Oracle triggers

Storage optimization of performance tuning methodology

极狐公司官方澄清声明

Interview questions for famous enterprises: Coins represent a given value

Oracle checkpoint queue - Analysis of the principle of instance crash recovery

Web3为互联网带来了哪些改变?

Leetcode simple question ring and rod

Shell script, awk uses if, for process control

2022-07-05:给定一个数组,想随时查询任何范围上的最大值。 如果只是根据初始数组建立、并且以后没有修改, 那么RMQ方法比线段树方法好实现,时间复杂度O(N*logN),额外空间复杂度O(N*

Leetcode simple question: the minimum cost of buying candy at a discount
随机推荐
【愚公系列】2022年7月 Go教学课程 004-Go代码注释
Bitbucket installation configuration
阿龙的感悟
Storage optimization of performance tuning methodology
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
Leetcode simple question: the minimum cost of buying candy at a discount
Blocking protocol for concurrency control
Overview of database recovery
Performance monitoring of database tuning solutions
Search: Future Vision (moving sword)
Regular expressions and re Libraries
SecureCRT使用提示
Interview questions for basic software testing
How to add new fields to mongodb with code (all)
How can Bluetooth in notebook computer be used to connect headphones
How to develop and introduce applet plug-ins
【愚公系列】2022年7月 Go教学课程 003-IDE的安装和基本使用
How to view Apache log4j 2 remote code execution vulnerability?
Matlab | app designer · I used Matlab to make a real-time editor of latex formula
A substring with a length of three and different characters in the leetcode simple question