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.
- # Include
- # Include
- # Include
- # Include /* Create a device node */
- # Include
- # Include /* Define DECLARE_WAIT_QUEUE_HEAD */
- # Include /* Defines irqreturn_t and so on */
- # Include /* Request_irq disable_irq enable_irq */
- # Include
- # Include
- # Include/* contains # include "mach/irqs. h "*/
- # Include
- # Include
- # Define ADC_MAJOR 102
- # Define ADC_NAME "my_adc"
- # Define SUCCESS 0
- Static IntAdc_open (StructInode *,StructFile *);
- Static IntAdc_release (StructInode *,StructFile *);
- Static Int_ Init adc_init (Void);
- Static Int_ Exit adc_exit (Void);
- StaticSsize_t adc_read (StructFile *,Char*,Size_t, Loff_t *);
- VolatileUnsignedLongAdc_con;
- UnsignedLongAdc_dat0;
- IntFlag;// Wait for the task to complete
- UnsignedLongBuf;// Store the converted data
- // Declare the waiting queue
- DECLARE_WAIT_QUEUE_HEAD (adc_wait );
- StructClk * adc_clk;
- StaticIrqreturn_t adc_interrupt (IntIrq,Void* Dev_id)// Interrupt handling program
- {
- If(Flag = 0)
- {
- Buf = (readw (adc_dat0) & 0x3ff );// Read the converted data
- Flag = 1;
- Wake_up_interruptible (& adc_wait );// Wake up the process waiting for it
- Printk ("Read value is % ld \ n", Buf );
- }
- ReturnIRQ_HANDLED;
- }
- Static StructFile_operations adc_ops =
- {
- . Owner = THIS_MODULE,
- . Read = adc_read,
- . Open = adc_open,
- . Release = adc_release,
- };
- Static StructMiscdevice adc_misc =
- {
- . Name = ADC_NAME,
- . Minor = ADC_MAJOR,
- . Fops = & adc_ops,
- };
- Static Int_ Init adc_init (Void)
- {
- IntRet;
- Adc_clk = clk_get (NULL,"Adc");// Get the clock
- Clk_enable (adc_clk );// Enable clock
-
- Ret = misc_register (& adc_misc );// Register the device
- If(Ret <0)
- {
- Printk ("Register device fail \ n");
- ReturnRet;
- }
- Adc_con = (unsignedLong) Ioremap (0x5821300,4 );
- Adc_dat0 = (VolatileUnsignedLong) Ioremap (0x58000000 + S3C2410_ADCDAT0, 4 );
- If(! (Adc_con & adc_dat0 ))
- {
- Printk ("Failed to ioremap \ n");
- GotoHandle;
- }
- Printk ("Initialized... \ n");
- ReturnSUCCESS;
- Handle:
- Misc_deregister (& adc_misc );
- Return-1;
- }
- Static IntAdc_open (StructInode * inode,StructFile * file)// Enable the device function
- {
- // Registration interrupted
- IntRet;
- // Disable_irq (IRQ_ADC );
- // Enable_irq (IRQ_ADC );
- Ret = request_irq (IRQ_ADC, adc_interrupt, ir1__shared, ADC_NAME, 1 );// Registration interrupt IRQ_ADC defined in mach/irqs. h
- If(Ret <0)
- {
- Printk ("IRQ % d can not request \ n", IRQ_ADC );
- ReturnRet;
- }
- ReturnSUCCESS;
- }
- Static IntAdc_release (StructInode * inode,StructFile * file)// Disable the device function
- {
- Free_irq (IRQ_ADC, 1 );// Release interrupted
- ReturnSUCCESS;
- }
- StaticSsize_t adc_read (StructFile * file,
- Char* Buffer,
- Size_tLength,
- Loff_t * offset)// Device read Function
- {
-
- Writew (1 <14) | (0x31 <6), adc_con );// Set ADCCON
- Writew (readw (adc_con) | 0x1), adc_con );// Start ad ing
- Wait_event_interruptible (adc_wait, flag );
- Flag = 0;
- }
- Static Int_ Exit adc_exit (Void)// Driver uninstall Function
- {
- Iounmap (adc_con );
- Iounmap (adc_dat0 );
- Misc_deregister (& adc_misc );
- Clk_disable (adc_clk );
- Clk_put (adc_clk );
- Printk ("The adc is unintialized \ n");
- ReturnSUCCESS;
- }
- Module_init (adc_init );
- Module_exit (adc_exit );
- MODULE_LICENSE ("GPL");