十、编写LED混杂设备驱动

时间:2023-03-09 23:13:52
十、编写LED混杂设备驱动

led.c修改为:

 #include <linux/init.h>
#include <linux/module.h>
#include <linux/miscdevice.h>
#include <linux/fs.h>
#include <linux/io.h> #define GPMCON 0x7F008820
#define GPMDAT 0x7F008824 static int * __gp_gpmdat; static int led_open (struct inode *p_inode, struct file *p_file)
{
int *p_gpmcon = NULL; p_gpmcon = ioremap(GPMCON, );
writel(0x1111, p_gpmcon); __gp_gpmdat = ioremap(GPMDAT, ); return ;
} static long led_ioctl (struct file *p_file, unsigned int cmd, unsigned long arg)
{
switch (cmd) {
case :
writel(0x0, __gp_gpmdat);
break; case :
writel(0xF, __gp_gpmdat);
break; default:
return -;
}
return ;
} static struct file_operations fops = {
.owner = THIS_MODULE,
.open = led_open,
.unlocked_ioctl = led_ioctl,
}; static struct miscdevice led_dev = {
.minor = MISC_DYNAMIC_MINOR,
.name = "myled",
.fops = &fops,
}; static __init int led_init (void)
{
misc_register(&led_dev); return ;
} static __exit void led_exit (void)
{
misc_deregister(&led_dev);
} module_init(led_init);
module_exit(led_exit); MODULE_LICENSE("GPL");

其他文件同上一章一样,但是使用led时只需要先insmod led.ko,不需要再创建设备节点便可以使用led_app控制led