OpenSource For You

Using a parallel port from a device driver

-

Now, let’s look at how to control devices connected to a parallel port from a device driver. If you have worked with char device and misc device, you will know that the latter is the easiest way to create a character device. For those who are new to device drivers, let me give you a few details. When you register a char driver, you will need to have a major number and minor number that you have to combine using MKDEV to get a dev_t value. Then you will need to register this dev_t with register_chrdev_region() and after that, you will need to call cdev_init() and cdev_add(). Finally, you have to create the device node in the /dev folder, manually. We can avoid all this hard work if we use misc_device. We just need to call misc_register() and all the tasks are done automatica­lly, including the device node creation in the /dev folder. But for that we need to define a structure_miscdevice.

Let’s look at the basic parts of our driver with just the header files, init and exit.

mydevice_attach and mydevice_detach are the entry and exit points for our driver. Whenever Linux detects any parallel port, it will call the drivers and attach a function where we register our device with the parallel port, and try to claim it. The remaining part of the code will work only if we claim it.

Assuming that we have claimed the parallel port successful­ly, let’s register miscdevice­s:

Newspapers in English

Newspapers from India