free_irq(IRQ_ADC, &adcdev); //;释放中断 iounmap(adc_base); /*释放虚拟地址映射空间*/ if (adc_clk) /*屏蔽和销毁时钟*/ {
clk_disable(adc_clk);
clk_put(adc_clk);
adc_clk = NULL;
}
misc_deregister(&adc_miscdev);
} //;导出信号量“ADC_LOCK”,以便触摸屏驱动使用 EXPORT_SYMBOL(ADC_LOCK);
module_init(dev_init);
module_exit(dev_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("singleboy");
MODULE_DESCRIPTION("Mini2440 ADC Driver");说明:杂项设备(misc device)
杂项设备也是在嵌入式系统中用得比较多的一种设备驱动。在 Linux 内核的include/linux 目录下有Miscdevice.h 文件,要把自己定义的misc device 从设备定义在这里。其实是因为这些字符设备不符合预先确定的字符设备范畴,所有这些设备采用主编号10,一起归于misc device,其实misc_register 就是用主标号10 调用register_chrdev()的。也就是说,misc设备其实也就是特殊的字符设备。然后打开drivers/char/Makefile 文件,在大概24 行加入ADC 驱动程序目标模块obj-$(CONFIG_EP93XX_PWM) += ep93xx_pwm.o
obj-$(CONFIG_C2PORT) += c2port/ obj-$(CONFIG_MINI2440_ADC) += mini2440_adc.o obj-y += eeprom/
obj-y += cb710/再打开drivers/char/Kconfig 文件,定位到16行附近,加入ADC 驱动配置选项:menuconfig MISC_DEVICES
bool "Misc devices"
default y
---help---
Say Y here to get to see options for device drivers from various
different categories. This option alone does not add any kernel code. If you say N, all options in this submenu will be skipped and disabled.if MISC_DEVICESconfig MINI2440_ADC
bool "ADC driver for FriendlyARM Mini2440 development boards"
depends on MACH_MINI2440
default y if MACH_MINI2440
help
this is ADC driver for FriendlyARM Mini2440 development boards
Notes: the touch-screen-driver required this optionconfig ATMEL_PWM
tristate "Atmel AT32/AT91 PWM support"
depends on AVR32 || ARCH_AT91SAM9263 || ARCH_AT91SAM9RL || ARCH_AT91CAP9
help
This option enables device driver support for the PWM channels
on certain Atmel processors. Pulse Width Modulation is used for
purposes including software controlled power-efficient backlights
on LCD displays, motor control, and waveform generation.这样,我们就在内核中添加了ADC 驱动。【3】确认配置选项现在内核源代码目录的命令行执行:make menuconfig,依次选择如下子菜单项,找到刚刚添加的ADC 驱动配置选项:
Device Drivers --->
[*] Misc devices ---> 如图所示,按空格键选中 ADC 配置选项 然后退出保存所选配置, 在命令行执行: make zImage , 将会生成arch/arm/boot/zImage,brd: module loaded adc initialized! S3C24XX NAND Driver, (c) 2004 Simtec Electronics... ...说明ADC设备加载成功。 “adc-test” 测试程序已经集成到我们的文件系统中, 因此在开发板的命令行终端输入:adc-test,旋转开发板上的 W1可调电阻,可以看到 ADC 转换的结果也在变动,按下触摸屏时,会输出“-1” ,这和我们在驱动程序中设置的结果是一样的,如图:接下来,将进行触摸屏驱动移植