1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110
| static int __init led_init(void) { u32 val; int ret;
led_ioremap();
val = readl(aper_clk_ctrl_addr); val |= (0x1U << 22); writel(val, aper_clk_ctrl_addr);
val |= (0x1U << 7); writel(val, intdis_addr);
val = readl(dirm_addr); val |= (0x1U << 7); writel(val, dirm_addr);
val = readl(outen_addr); val |= (0x1U << 7); writel(val, outen_addr);
val = readl(data_addr); val &= ~(0x1U << 7); writel(val, data_addr);
if (newchrled.major) { newchrled.devid = MKDEV(newchrled.major, 0);
ret = register_chrdev_region(newchrled.devid, NEWCHRLED_CNT, NEWCHRLED_NAME); if (ret) goto out1; } else { ret = alloc_chrdev_region(&newchrled.devid, 0, NEWCHRLED_CNT, NEWCHRLED_NAME); if (ret) goto out1;
newchrled.major = MAJOR(newchrled.devid); newchrled.minor = MINOR(newchrled.devid); }
printk("newcheled major=%d,minor=%d\r\n",newchrled.major, newchrled.minor);
newchrled.cdev.owner = THIS_MODULE; cdev_init(&newchrled.cdev, &newchrled_fops);
ret = cdev_add(&newchrled.cdev, newchrled.devid, NEWCHRLED_CNT); if (ret) goto out2;
newchrled.class = class_create(THIS_MODULE, NEWCHRLED_NAME); if (IS_ERR(newchrled.class)) { ret = PTR_ERR(newchrled.class); goto out3; }
newchrled.device = device_create(newchrled.class, NULL, newchrled.devid, NULL, NEWCHRLED_NAME); if (IS_ERR(newchrled.device)) { ret = PTR_ERR(newchrled.device); goto out4; }
return 0;
out4: class_destroy(newchrled.class);
out3: cdev_del(&newchrled.cdev);
out2: unregister_chrdev_region(newchrled.devid, NEWCHRLED_CNT);
out1: led_iounmap();
return ret; }
static void __exit led_exit(void) { device_destroy(newchrled.class, newchrled.devid);
class_destroy(newchrled.class);
cdev_del(&newchrled.cdev);
unregister_chrdev_region(newchrled.devid, NEWCHRLED_CNT);
led_iounmap(); }
|