<pstyle='text-align: justify;'>In my last post, where I showed how to write a character gpio driver, I had used mknod for device node creation. Without mknod the device files would not have been created under /dev. So, we had to manually create the device node under /dev using mknod. Now, cannot this manual work be done away with? Of course, it can be done!!.</p>
<pstyle='text-align: justify;'>The automatic creation of device files can be handled with udev. One has to ensure that the major and minor numbers assigned to a device controlled by the driver are exported to user space through the sysfs interface. To know more about this, read "The Linux Device Module" chapter from the Linux Device Drivers book.</p>
<pstyle='text-align: justify;'>Below I am posting the source code for the driver module, the user space application and the Makefile. The user space application and Makefile remain the same. I have only changed the name of the device node under /dev from gpio to gpio_drv. So, the user space application code accordingly reflects this.</p>
<pstyle='text-align: justify;'>The path for your kernel source and path for the CodeSourcery toolchain can and mostly will be different. So change them, as per your environment.</p>
<pstyle='text-align: justify;'>After this, compile your kernel driver module by typing “sudo make” at the command line prompt. After this, cross compile your user space application by typing</p>
<pstyle='text-align: justify;'>I have assumed that the cross compiler path has been added to your path environment variable.</p>
<pstyle='text-align: justify;'>You will now have a gpio.ko file and a gpio_app executable. Transfer these files to your beagleboard. I use the “scp” command to transfer files to my board over the ssh connection.</p>
<pstyle='text-align: justify;'>On the command prompt of your beagleboard, do “insmod gpio.ko”.</p>
<pstyle='text-align: justify;'>**This time, you won't have to do the mknod for device node creation under /dev. You can cd to /sys/class and you will find the chardev entry there. Do ls /dev and you will find gpio_drv already present without having run mknod.**</p>
<pstyle='text-align: justify;'>By default, the user led’s 0 and 1 which are connected on GPIO 149 and 150, are used for indicating mmc card access activity and heartbeat.</p>
<pstyle='text-align: justify;'>You can turn these dafault behaviour off by first entering the /sys/class/gpio/beagleboard::usr0 and /sys/class/gpio/beagleboard::usr1 directory. After this, do “cat trigger”. You should see the default behaviour marked.</p>
<pstyle='text-align: justify;'>Now, change the default behaviour for both by doing “echo none > trigger” in their respective directories.</p>
<pstyle='text-align: justify;'>Now, run the user space application by typing ./gpio_app on the command line prompt. You will be prompted to enter the value “0″ or “1″ to turn off or turn on the led. You can observe the state of the led pin on your board after this.</p>
<pstyle='text-align: justify;'>Refer the Linux Device Drivers book by Corbet, Rubini and Greg Kroah Hartman. The second, third and fourteenth chapters are important for this tutorial.</p>
<pstyle='text-align: justify;'>Refer this link</p>