Forum Discussion
Altera_Forum
Honored Contributor
12 years agoI've "THINK" I have properly requested four minor numbers for my driver.
When I open "/dev/mine1" and try and do the mmap from user space the mmap function IS NOT entered!! So, I'm figuring I have done something incorrectly when doing the cdev_add and the driver funtions are not properly being pointed to --- but it looks like what Rubini has... Can anyone see anything wrong with what I've done? Thanks in advance. ********************************************************************************************************** Here are the important parts of my driver code: # define MINOR_COUNT 4 struct driver_dev { int anyNumber; struct cdev cdev; }; static struct driver_dev * my_devices; dev_t dev; // contains major and first minor# static int dev_is_open = 0; static struct file_operations fops_mine = { .read = mine_sleepy_read, .write = mine_write, .open = mine_open, .release= mine_close, .unlocked_ioctl = mine_ioctl, ////////////.ioctl = mine_ioctl, .mmap = mine_mmap, .owner = THIS_MODULE, }; ///////////////////////////// struct file_operations *driver_fops_array[]={ &fops_mine }; static int __devinit mine_drv_probe( struct platform_device *op) { struct resource *res; int ret; int i; printk("######################### IN PROBE \n"); if (!of_match_device(mine_of_match, &op->dev)) return -ENODEV; res = platform_get_resource( op, IORESOURCE_MEM, 0); if (!res) return -ENODEV; if (!request_mem_region(res->start, resource_size(res), "mine")) return -ENODEV; myVertAddr = of_iomap(op->dev.of_node, 0); if (!myVertAddr) return -ENODEV; ////////////////////////////// if( register_chrdev_region( MKDEV(DEV_MAJOR,0) , MINOR_COUNT, "mine" ) ) { printk(KERN_ALERT "register_chrdev_region of mineDriver failed!\n"); return -EIO; } dev = MKDEV( DEV_MAJOR, 0 ); /// ALLOCATE MEMORY for COUNT my_devices my_devices = kmalloc( MINOR_COUNT* sizeof(struct driver_dev), GFP_KERNEL ); if ( my_devices == NULL ) { res = -ENOMEM; goto fail; } /// fill the my_devices region with ZEROS /////// SKIP FOR NOW /// Initialize the devices for ( i=0; i < MINOR_COUNT; i++ ) { cdev_init( &my_devices.cdev, &fops_mine);my_devices.cdev.owner = THIS_MODULE; my_devices.cdev.ops = &fops_mine;
res = cdev_add( &my_devices.cdev, MKDEV( MAJOR(dev), MINOR(dev)+i ), 1 ); if ( res ) { printk( KERN_ALERT "Error %d adding mine%d\n", res, i ); } else printk( KERN_ALERT "mine%d added\n",i ); } ///////////////////////////// /// / REQUEST IRQ ---> MOVED TO PROBE ---> irq = irq_of_parse_and_map( op->dev.of_node, 0 ); printk( "IRQ %d \n", irq ); if ( (ret = request_irq( irq, mine_ReadInterrupt, 0, "mine", op-dev ) )) { printk(KERN_ALERT ": Can't request Board IRQ %d RET:%i\n", irq, ret ); if ( ret == -EBUSY ) printk(KERN_ALERT "IRQ busy\n"); } printk( KERN_ALERT "IRQ requested %d successfully \n",irq ); printk("**************************** - probe complete\n"); return 0; fail: return ret; }