跟着老师视频走的,但是insmod我的驱动不能挂在dev下,而且我rmmod后class还有残留,不能再次insmod

下面是我的代码,大佬们帮我看看。

#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/slab.h>
#include <linux/init.h>
#include <linux/fs.h>
#include <linux/delay.h>
#include <linux/poll.h>
#include <linux/mutex.h>
#include <linux/wait.h>
#include <asm/uaccess.h>
#include <asm/io.h>
#include <linux/device.h>

static int major = 0;
static struct class *led_class;

//IOMUXC_SNVS_SW_MUX_CTL_PAD_SNVS_TAMPER3 Address: 229_0000h base + 14h offset = 229_0014h
static volatile unsigned int *IOMUXC_SNVS_SW_MUX_CTL_PAD_SNVS_TAMPER3;

//GPIO pad status register (GPIOx_PSR) Address: Base address + 4h offset
//GPIO5_GDIR Address : 0x020AC004
static volatile unsigned int *GPIO5_GDIR;

//GPIO5_DR Address : 0x020AC000
static volatile unsigned int *GPIO5_DR;

static ssize_t led_write(struct file *filp, const char __user *buf, size_t count, loff_t *ppos)
{
char val;
int ret;
/copy_from_user : get data from app/
ret = copy_from_user(&val, buf, 1);

/*to set gpio register : out 1/0*/
if (val == 1)
{
	/* set gpio to let led on */
	*GPIO5_DR &= ~(1<<3);
}
else 
{
	/* set gpio to let led off */
	*GPIO5_DR |= (1<<3);
}
return 1;

}

static int led_open(struct inode *inode, struct file *filp)
{
/*enable gpio
*configure pin as gpio
*configure gpio as output
*/
*IOMUXC_SNVS_SW_MUX_CTL_PAD_SNVS_TAMPER3 &= ~0xf;
*IOMUXC_SNVS_SW_MUX_CTL_PAD_SNVS_TAMPER3 |= 0x5;

*GPIO5_GDIR |= (1<<3);
return 0;

}

static struct file_operations led_fops = {
.owner = THIS_MODULE,
.write = led_write,
.open = led_open,
};

/入口函数/
static int __init led_init(void)
{
printk(“%s %s %d\n”, FILE, FUNCTION, LINE);

major = register_chrdev(0, "ijiang_led", &led_fops);

/*ioremap*/
IOMUXC_SNVS_SW_MUX_CTL_PAD_SNVS_TAMPER3 = ioremap(0x02290000 + 0x14, 4);

GPIO5_GDIR = ioremap(0x020AC004, 4);

GPIO5_DR = ioremap(0x020AC000, 4);


led_class = class_create(THIS_MODULE, "myled");
device_create(led_class, NULL, MKDEV(major, 0), NULL, "myled"); /* /dev/myled */

return 0;

}

static void __exit led_exit(void)
{
iounmap(IOMUXC_SNVS_SW_MUX_CTL_PAD_SNVS_TAMPER3);
iounmap(GPIO5_GDIR);
iounmap(GPIO5_DR);

device_destroy(led_class, MKDEV(major, 0));
class_destroy(led_class);

unregister_chrdev(0, "ijiang_led");

}

module_init(led_init);
module_exit(led_exit);
MODULE_LICENSE(“GPL”);

没事了,是我粗心大意 :scream: