Skip to content

VLSIFacts

Let's Program the Transistors

  • Home
  • DHD
    • Digital Electronics
    • Fault Tolerant System Design
    • TLM
    • Verification
    • Verilog
    • VHDL
    • Xilinx
  • Embedded System
    • 8085 uP
    • 8086 uP
    • 8051 uC
  • VLSI Technology
    • Analog Electronics
    • Memory Devices
    • VLSI Circuits
  • Interview
    • Interview Experience
    • Training Experience
    • Question Bank
  • Notifications
  • QUIZ
  • Community
  • Job Board
  • Contact Us

Components of Device Driver

Posted on December 8, 2017June 17, 2025 By Gautam No Comments on Components of Device Driver

To interact with the hardware, driver needs to communicate with the kernel and before that, it must notify the kernel about its presence. This is achieved by the “init” call by which the driver is registered with the kernel and allocated the memory it wants. At the time of system shut down, the driver is unregistered using the “exit” call that also frees all the resources occupied by the driver. The calls that are used to define the “init” and “exit” functions are:
module_init(init_function_name);
module_exit(exit_function_name);

We can write our own init and exit functions while writing a device driver that would be called by the above two calls respectively. The simplest init function could be as follows:
static int init_function_name(void)
{
printk(KERN_ALERT “Hello”);
return 0;
}

Similarly, we can write the exit function as well. As you can see, for getting the kernel logs, we use the printk() function that is similar to the C function printf() but requires an optional special log level string (here KERN_ALERT – log level 1) to indicate the type of severity of the error message. There are eight log levels in total and the default is KERN_WARNING(log level 4).

One of the most important component in the device driver is the file operations(“fops” in short) structure. This structure specifies the capability of the device for which the driver is being written. It contains the pointers to the functions written for the operations to be supported by the device. The basic fops structure can be described as below:
static struct file_operations fops=
{
.read=my_read;
.write=my_write;
.open=my_open;
.release=my_release;
}

The above defines that whenever the device has to read something, my_read function(written by the developer) will be called. Similarly, the pointers to the other functions are the corresponding names of the functions mentioned against them.

If the device for which the driver is being written supports the interrupt facility, the driver must register the Interrupt Service Routine(ISR) in the init function that would be called whenever an interrupt is received in the device. This is achieved by using the kernel function request_irq() that requires the interrupt handler and then enables the interrupt line for receiving the interrupts. On the other side, free_irq() kernel function is used to free the interrupt handler and the interrupt line when the driver unloads. We will address them in our future posts in detail.

(…Previous Article)                                                      (…Next Article)

Spread the Word

  • Click to share on Facebook (Opens in new window) Facebook
  • Click to share on X (Opens in new window) X
  • Click to share on LinkedIn (Opens in new window) LinkedIn
  • Click to share on Pinterest (Opens in new window) Pinterest
  • Click to share on Tumblr (Opens in new window) Tumblr
  • Click to share on Pocket (Opens in new window) Pocket
  • Click to share on Reddit (Opens in new window) Reddit
  • Click to email a link to a friend (Opens in new window) Email
  • Click to print (Opens in new window) Print

Like this:

Like Loading...

Related posts:

  1. Device Drivers : Role & Types
  2. Device Drivers and Linux Architecture
  3. Kernel Modules, Major Number and Minor Number
  4. L&T Emsys Interview Question Bank – Part 1
Embedded System Tags:Communication, Device Driver, ECE, Electronics, Electronics & Communication Engineering, Embedded Systems, Linux, Microcontroller

Post navigation

Previous Post: VLSI Design Flow
Next Post: Kernel Modules, Major Number and Minor Number

Leave a Reply Cancel reply

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

Top Posts & Pages

  • ASCII Code
  • Circuit Design of a 4-bit Binary Counter Using D Flip-flops
  • NAND and NOR gate using CMOS Technology
  • Binary to Gray Code Conversion and Vice Versa
  • AND and OR gate using CMOS Technology

Copyright © 2025 VLSIFacts.

Powered by PressBook WordPress theme

Subscribe to Our Newsletter

%d