|Linux| How to create a device node?

How to create a device in /dev automatically

Ans: device_create

- Include the header file linux/device.h and linux/kdev_t.h

    static struct class c_dev;
    static struct dev_t dev;

- Add the below API 's inside __init fuction of the driver

    cl = class_create(THIS_MODULE ,"x");

    where x - Name to be displayed inside /sys/class/ when driver is loaded.

 - Use device_create () kernel api with device_create(cl, NULL, dev, NULL, "d");

    where d - device file to be created under /dev.

 - Use cdev_init to initialize

 - Use cdev_add to add the device to the /dev list


Advance:
What does “cat sys/bus/msm_subsys/devices/subsys2/state” mean ?
 It means that asking the type of bus.
 The Basic Device Driver-Model Structures


Ref.
udev-強大的device node管理系統
Dynamic Kernel Device Management with udev
How to create an event# device for a virtual input device (/dev/input/js3) in linux kernel module?

Next:
Linux Driver Tutorial: How to Write a Simple Linux Device Driver
HelloDriverSource