当前位置:网站首页>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
边栏推荐
- Leetcode simple question ring and rod
- 科技云报道荣膺全球云计算大会“云鼎奖”2013-2022十周年特别贡献奖
- 从零开始实现lmax-Disruptor队列(四)多线程生产者MultiProducerSequencer原理解析
- Granularity of blocking of concurrency control
- 微服务入门(RestTemplate、Eureka、Nacos、Feign、Gateway)
- 854. String BFS with similarity K
- MySQL actual combat 45 lecture learning (I)
- Poj3414广泛搜索
- Two stage locking protocol for concurrency control
- Type of fault
猜你喜欢
随机推荐
How to use tensorflow2 for cat and dog classification and recognition
Lightweight dynamic monitorable thread pool based on configuration center - dynamictp
数据泄露怎么办?'华生·K'7招消灭安全威胁
Code bug correction, char is converted to int high-order symbol extension, resulting in changes in positivity and negativity and values. Int num = (int) (unsigned int) a, which will occur in older com
Implementing Lmax disruptor queue from scratch (IV) principle analysis of multithreaded producer multiproducersequencer
AD637使用笔记
从零开始实现lmax-Disruptor队列(四)多线程生产者MultiProducerSequencer原理解析
Leetcode simple question check whether all characters appear the same number of times
微服务链路风险分析
Learning of mall permission module
Common interview questions of redis factory
SecureCRT使用提示
Codeforces 12D Ball 树形阵列模拟3排序元素
微服務鏈路風險分析
Regular expressions and re Libraries
Overview of database recovery
Deeply convinced plan X - network protocol basic DNS
EL与JSTL注意事项汇总
Matlab draws a cute fat doll
Database tuning solution









