EmbLogic's Blog

character driver

Could any body try his guts to tell  me the algorithm of character driver and the meaning of each function…………….like init,alloc,add  etc. My knowledge base about char  driver upto registration, of module in 2.6.x kernel

One Response to character driver

  1. kamran says:

    Following are the api along with the parameter and what is achieved from it,on executing.

    int register_chrdev_region(dev_t first, unsigned int count,char *name);

    register_chrdev_region works well if you know ahead of time exactly which device numbers you want. Often, however, you will not know which major numbers your device will use; to move over to the use of dynamicly-allocated device numbers on the fly, use the following:

    int alloc_chrdev_region(dev_t *dev, unsigned int firstminor,unsigned int count, char *name);

    cdev_alloc:
    struct cdev * cdev_alloc (void);
    Allocates and returns a cdev structure, or NULL on failure.

    cdev_init:
    void cdev_init (struct cdev *cdev,const struct file_operations *fops);
    Initializes cdev, remembering fops, making it ready to add to the system with cdev_add.

    cdev_add
    int cdev_add (struct cdev *p,dev_t dev,unsigned count);
    cdev_add adds the device represented by p to the system, making it live immediately, and can be used by the user.

    cdev_del
    void cdev_del ( struct cdev *p);
    cdev_del removes p from the system, possibly freeing the structure itself.

    Hope it will clear the doubts.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>