Linux创建platform驱动:

1、platform总线:

虚拟总线,主线用于描述SOC片上外设,所有直接通过内存寻址的设备都映射到这条总线上;

无dts节点,platform_driver_register后不进probe

# 预编译dts文件:
cpp -nostdinc -I./ -undef -x assembler-with-cpp vexpress-v2p-ca9.dts > vexpress-v2p-ca9.dts-cpp
# 编译dts文件:
~/code/linux/linux-4.18/scripts/dtc/dtc -I dts -O dtb -i ./ -o vexpress-v2p-ca9.dtb vexpress-v2p-ca9.dts-cpp

# 反编译dtb:
./dtc -I dtb -O dts test.dtb  > test.dts

2、sysfs文件:

/*
 * 创建sysfs文件: linux/sysfs.h
 * kobj: 内核对象
 * attr: sysfs属性
 */
static inline int __must_check sysfs_create_file(struct kobject *kobj, const struct attribute *attr)

/*
 * 删除sysfs文件: linux/sysfs.h
 * kobj: 内核对象
 * attr: sysfs属性
 */
static inline void sysfs_remove_file(struct kobject *kobj, const struct attribute *attr)

/*
 * 创建sysfs符号链接: linux/sysfs.h
 * kobj: 内核对象
 * target: 被链接的内核对象
 * name: 符号链接文件名称
 */
int __must_check sysfs_create_link(struct kobject *kobj, struct kobject *target, const char *name);
  • 例:

posted @ 2020-11-27 21:42  hug567  阅读(195)  评论(0)    收藏  举报