ARMLinux automatically creates a device Node

Source: Internet
Author: User
Hardware Platform: FL2440 kernel version: 2.6.28 host platform: Ubuntu11.04 kernel version: 2.6.391. First, configure busyboxbusyboxLinuxSystemUtilities --- & gt; [*] mdev [*] Support/etc/mdev. conf & nbsp

Hardware Platform: FL2440

Kernel version: 2.6.28

Host platform: Ubuntu 11.04

Kernel version: 2.6.39

1. Configure busybox first

Busybox
Linux System Utilities --->
[*] Mdev
[*] Support/etc/mdev. conf
[*] Support command execution at device addition/removal

 

2. Configure the kernel

3. Modify/etc/init. d/rcS in the file system.

Vi./etc/init. d/rcS
Mount-
Mkdir/dev/pts
Mount-t devpts/dev/pts
Echo/sbin/mdev>/proc/sys/kernel/hotplug
Mdev-s

4. Modify/etcfstab

Vi./etc/fstab
# Device mount-point type options dump fsck order
Proc/proc defaults 0 0
Tmpfs/tmp tmpfs defaults 0 0
Sysfs/sys sysfs defaults 0 0
Tmpfs/dev tmpfs defaults 0 0

In this way, you do not need to manually create the device node file when writing the driver.

The following is a modified ADC Driver that uses a Hybrid device. This allows you to automatically create and delete device nodes.

  1. # Include
  2. # Include
  3. # Include
  4. # Include /* Create a device node */
  5. # Include
  6. # Include /* Define DECLARE_WAIT_QUEUE_HEAD */
  7. # Include /* Defines irqreturn_t and so on */
  8. # Include /* Request_irq disable_irq enable_irq */
  9. # Include
  10. # Include
  11. # Include/* contains # include "mach/irqs. h "*/
  12. # Include
  13. # Include
  14. # Define ADC_MAJOR 102
  15. # Define ADC_NAME "my_adc"
  16. # Define SUCCESS 0
  17. Static IntAdc_open (StructInode *,StructFile *);
  18. Static IntAdc_release (StructInode *,StructFile *);
  19. Static Int_ Init adc_init (Void);
  20. Static Int_ Exit adc_exit (Void);
  21. StaticSsize_t adc_read (StructFile *,Char*,Size_t, Loff_t *);
  22. VolatileUnsignedLongAdc_con;
  23. UnsignedLongAdc_dat0;
  24. IntFlag;// Wait for the task to complete
  25. UnsignedLongBuf;// Store the converted data
  26. // Declare the waiting queue
  27. DECLARE_WAIT_QUEUE_HEAD (adc_wait );
  28. StructClk * adc_clk;
  29. StaticIrqreturn_t adc_interrupt (IntIrq,Void* Dev_id)// Interrupt handling program
  30. {
  31. If(Flag = 0)
  32. {
  33. Buf = (readw (adc_dat0) & 0x3ff );// Read the converted data
  34. Flag = 1;
  35. Wake_up_interruptible (& adc_wait );// Wake up the process waiting for it
  36. Printk ("Read value is % ld \ n", Buf );
  37. }
  38. ReturnIRQ_HANDLED;
  39. }
  40. Static StructFile_operations adc_ops =
  41. {
  42. . Owner = THIS_MODULE,
  43. . Read = adc_read,
  44. . Open = adc_open,
  45. . Release = adc_release,
  46. };
  47. Static StructMiscdevice adc_misc =
  48. {
  49. . Name = ADC_NAME,
  50. . Minor = ADC_MAJOR,
  51. . Fops = & adc_ops,
  52. };
  53. Static Int_ Init adc_init (Void)
  54. {
  55. IntRet;
  56. Adc_clk = clk_get (NULL,"Adc");// Get the clock
  57. Clk_enable (adc_clk );// Enable clock
  58. Ret = misc_register (& adc_misc );// Register the device
  59. If(Ret <0)
  60. {
  61. Printk ("Register device fail \ n");
  62. ReturnRet;
  63. }
  64. Adc_con = (unsignedLong) Ioremap (0x5821300,4 );
  65. Adc_dat0 = (VolatileUnsignedLong) Ioremap (0x58000000 + S3C2410_ADCDAT0, 4 );
  66. If(! (Adc_con & adc_dat0 ))
  67. {
  68. Printk ("Failed to ioremap \ n");
  69. GotoHandle;
  70. }
  71. Printk ("Initialized... \ n");
  72. ReturnSUCCESS;
  73. Handle:
  74. Misc_deregister (& adc_misc );
  75. Return-1;
  76. }
  77. Static IntAdc_open (StructInode * inode,StructFile * file)// Enable the device function
  78. {
  79. // Registration interrupted
  80. IntRet;
  81. // Disable_irq (IRQ_ADC );
  82. // Enable_irq (IRQ_ADC );
  83. Ret = request_irq (IRQ_ADC, adc_interrupt, ir1__shared, ADC_NAME, 1 );// Registration interrupt IRQ_ADC defined in mach/irqs. h
  84. If(Ret <0)
  85. {
  86. Printk ("IRQ % d can not request \ n", IRQ_ADC );
  87. ReturnRet;
  88. }
  89. ReturnSUCCESS;
  90. }
  91. Static IntAdc_release (StructInode * inode,StructFile * file)// Disable the device function
  92. {
  93. Free_irq (IRQ_ADC, 1 );// Release interrupted
  94. ReturnSUCCESS;
  95. }
  96. StaticSsize_t adc_read (StructFile * file,
  97. Char* Buffer,
  98. Size_tLength,
  99. Loff_t * offset)// Device read Function
  100. {
  101. Writew (1 <14) | (0x31 <6), adc_con );// Set ADCCON
  102. Writew (readw (adc_con) | 0x1), adc_con );// Start ad ing
  103. Wait_event_interruptible (adc_wait, flag );
  104. Flag = 0;
  105. }
  106. Static Int_ Exit adc_exit (Void)// Driver uninstall Function
  107. {
  108. Iounmap (adc_con );
  109. Iounmap (adc_dat0 );
  110. Misc_deregister (& adc_misc );
  111. Clk_disable (adc_clk );
  112. Clk_put (adc_clk );
  113. Printk ("The adc is unintialized \ n");
  114. ReturnSUCCESS;
  115. }
  116. Module_init (adc_init );
  117. Module_exit (adc_exit );
  118. MODULE_LICENSE ("GPL");

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.