我尝试制作 WS2812B led 设备驱动程序。 在驱动程序加载时,我从 platform_driver_probe 函数中得到错误 -19(没有这样的设备)。
我的代码:
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/platform_device.h>
#include <linux/pwm.h>
static int ws2812b_probe(struct platform_device *pdev) {
printk("Probed");
return 0;
}
static int ws2812b_remove(struct platform_device *dev) {
printk("Removed");
return 0;
}
static struct of_device_id my_match_table[] = {
{
.compatible = "worldsemi,ws2812b",
},
{},
};
MODULE_DEVICE_TABLE(of, my_match_table);
static struct platform_driver my_platform_driver = {
.probe = ws2812b_probe,
.remove = ws2812b_remove,
.driver = {
.name = "ws2812b",
.of_match_table = my_match_table,
},
};
static int __init ws2812b_init(void) {
printk("ws2812b init\n");
int ret;
printk (KERN_ALERT "%s\n", __FUNCTION__);
ret = platform_driver_probe(&my_platform_driver, ws2812b_probe);
printk(KERN_ALERT "ret = %d\n", ret);
pr_info("ret = %d\n", ret);
return ret;
}
static void ws2812b_exit(void) {
printk("ws2812b exit\n");
platform_driver_unregister(&my_platform_driver);
}
module_init(ws2812b_init);
module_exit(ws2812b_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("123");
MODULE_DESCRIPTION("WS2812b linux driver");
MODULE_VERSION("0.01");
MODULE_ALIAS("platform:ws2812");
生成文件:
ARCH := arm
MODULE_NAME=ws2812b
CROSS_COMPILE=/home/user/buildroot-mangopi-r/output/host/bin/arm-buildroot-linux-gnueabi-
KERNEL=/home/user/buildroot-mangopi-r/output/build/linux-5.4.99/
PWD := $(shell pwd)
obj-m += $(MODULE_NAME).o
all:
make ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) -C $(KERNEL) M=$(PWD) modules
clean:
rm -rf *.o *.ko
make ARCH=$(ARCH) CROSS_COMPILE=$(CROSS_COMPILE) -C $(KERNEL) M=$(PWD) clean
DeviceTree驱动节点:
&pwm {
pinctrl-names = "default";
pinctrl-0 = <&pwm1_pe_pins>;
status = "okay";
ws2812b {
compatible = "worldsemi,ws2812b";
status = "okay";
};
};
离线
这个pwm的用法不对,建议去看看内核的文档,pwm不像spi他并没有实现类bus方法,
节点写这里是没有设备的,把它放到根路径下去就行了
谢谢! 那是作品!
我的设备树:
ws2812b {
compatible = "ws2812b";
pwms = <&pwm 1 1000000 1>;
status = "okay";
};
离线