DENX . Training2 . LddDeviceRegistration

5.3.3. Registering a character driver

API: Character driver registration


struct cdev

allocate at runtime: (need to add fops by hand)

struct cdev* cdev_alloc(void);
my_cdev->ops = &my_fops;

allocate statically and only initalize at runtime:

void cdev_init (struct cdev* cdev, const struct file_operations *fops);

for both cases initalize owner field to THIS_MODULE:

my_cdev.owner = THIS_MODULE;

register the character driver with the kernel:

int cdev_add(struct cdev *dev, dev_t num, unsigned int count);

remove (and if necessary free memory):

void cdev_del(struct cdev *dev);


old way (do not use anymore):

int register_chrdev(unsigned int major, const char *name, struct file_operations *fops);
void unregister_chrdev(unsigned int major, const char *name);

----- Revision r1.5 - 14 Feb 2008 - 16:13 - MarkusKlotzbuecher
Copyright © 2002-2021 by DENX Software Engineering