Difference between Character Device, Platform Driver and Kernel Module

I am a newbie to Linux Kernel device driver codes. One question up on the other: which is the difference between:

  • Character Device
  • Platform Driver
  • Kernel Module

I am writing this question because, within the same code I am examining, there are three section: one for each.


  • Platform Device Driver: A platform device driver is generally written for on-chip components/devices and on-chip/off-chip unspeakable/un-discoverable devices.

    If there is a device on-chip/off-chip, which doesn't have a self-identifying capability, like say i2x devices, GPIO line based, or in-circuit (on-chip) timers, etc. Then such devices need to be identified by the drivers because the devices don't have self-ID, or capability to identify themselves. This generally happens with bus lines and on-chip components.

    Here is a detailed explanation.

    Example platform Devices: i2c devices, kernel/Documentation/i2c/instantiating-devices states:

    Basically, all device drivers can be categorized into character, or block; based on the data transaction size.

    Though there are many sub-classifications like network devices drivers and X device drivers, they too can be brought into devices, which carry data transactions (operations) in terms of few bytes that undergo tr

    Typically, a platform device driver can fit into character device driver section, as they generally involve on-chip operations, for initialization and to transfer a few bytes, whenever needed, but not in terms of blocks (KB, MB, GB) of data.

    Kernel Module?

    Now, a driver can be either compiled (to be integrated) into kernel image (zImage/bzImage/...) OR can be compiled (off-the kernel) to be optionally invokable modular driver, which is not part of kernel image, but is part of filesystem as a .ko (kernel object) file (find /lib/modules/`uname -r`/ -name "*.ko"), that stays off the kernel image, but can be inserted (using modprobe/insmod) or removed (using rmmod/modprobe -r) as necessary.

    On the other hand, a built-in driver can't be removed dynamically, even if we don't need it momentarily. A built-in driver would remain in the kernel and hence on RAM, as long as the system is running, even if the respective device is "not found"/"not necessary/"shutdown"), just wasting memory space (on RAM).

    The Module (or modular driver), would only step-in, when necessary, from secondary storage to RAM, and can be removed if the device is removed or not-in-action. This saves RAM and helps dynamic allocation of resources.