Driver
#include <linux/module.h>
#include <linux/fs.h>
#include <linux/init.h>
#include <linux/cdev.h>
#include <linux/slab.h>
#include <linux/uaccess.h>
#include <linux/platform_device.h>
static int my_platform_test_probe(struct platform_device *pdev)
{
int *buf = (int *)(pdev->dev.platform_data);
printk("%d %d %d %d %d\n", buf[0],buf[1],buf[2],buf[3],buf[4]);
printk("%s:success\n", __func__);
return 0;
}
static int my_platform_test_remove(struct platform_device *pdev)
{
printk("%s:success\n", __func__);
return 0;
}
static struct platform_driver my_platform_test_driver = {
.driver = {
.name = "my_platform_test",
.owner = THIS_MODULE,
},
.probe = my_platform_test_probe,
.remove = my_platform_test_remove,
};
module_platform_driver(my_platform_test_driver);
MODULE_LICENSE("GPL v2");
Device
#include <linux/kernel.h>
#include <linux/init.h>
#include <linux/io.h>
#include <linux/string.h>
#include <linux/module.h>
#include <linux/platform_device.h>
static int test_data[10] = {1,2,3,4,5,6,7,8,9,10};
void my_release(struct device *dev)
{
printk("%s:success\n", __func__);
}
static struct platform_device my_platform_test_dev = {
.name = "my_platform_test",
.id = 1,
.dev = {
.platform_data = test_data,
.release = my_release,
}
};
static struct platform_device *my_platform_devs[] __initdata = {
&my_platform_test_dev,
};
static int __init my_platform_device_init(void)
{
platform_add_devices(my_platform_devs, ARRAY_SIZE(my_platform_devs));
return 0;
}
module_init(my_platform_device_init);
static void __exit my_platform_device_exit(void)
{
platform_device_unregister(&my_platform_test_dev);
}
module_exit(my_platform_device_exit);
MODULE_LICENSE("GPL v2");
Makefile
export ARCH=arm64
export CROSS_COMPILE=aarch64-linux-gnu-
obj-m :=platform_driver_test.o
obj-m +=platform_device_test.o
KDIR :=${kernel_dir}
all:
make -C $(KDIR) M=$(PWD) modules
clean:
rm -f *.ko *.o *.mod.o *.mod.c *.symvers *.order