| #include <linux/miscdevice.h> #include <linux/input.h> #include <linux/clk.h> #include <linux/delay.h> #include <asm/io.h> #include <asm/uaccess.h> #include <mach/map.h> #include <mach/gpio.h> //#include <mach/gpio-bank.h> #include <mach/regs-gpio.h> #include <plat/gpio-core.h> #include <plat/gpio-cfg.h> #include <plat/gpio-cfg-helpers.h> #define DEVICE_NAME "led" /* 应用程序执行ioctl(fd, cmd, arg)时的第2个参数 */ /*the second parameter that application program execute*/ #define IOCTL_GPIO_ON         1 #define IOCTL_GPIO_OFF        0 /* 用来指定LED所用的GPIO引脚 */ /*appoint the pin the LED will use*/ static unsigned long gpio_table [] = {          S5PV210_GPC0(3),          S5PV210_GPC0(4), }; /* 用来指定GPIO引脚的功能:输出 */ /*appoint the function of the pin:out put*/ static unsigned int gpio_cfg_table [] = {          S3C_GPIO_SFN(1),          S3C_GPIO_SFN(1), }; //static char gpio_name[][]={{"GPC0_3"},{"GPC0_4"}}; #ifdef CONFIG_TQ210_DEBUG_LEDS static void tq210_debug_leds(unsigned int cmd,unsigned long arg) {          gpio_direction_output(gpio_table[arg], cmd);          //s3c_gpio_setpin(gpio_table[arg], cmd); } static void toggle_led(unsigned int cmd,unsigned long arg) {          int loop=0;          printk("%s : led %ld toggle now: \n",__func__,arg);          for(;loop<11;loop++)          {        cmd = loop%2;                   printk("leds %d %s \n",arg+1,(cmd)?"on":"o   ff");                    tq210_debug_leds(cmd,arg);                    mdelay(1000);          } } #endif /** *函数功能:打开/dev/led设备,设备名是:/dev/led *fuction:open /dev/led device ,devce name: /dev/led **/ static int tq210_gpio_open(struct inode *inode, struct file *file) {          int i;          int err;          err = gpio_request(gpio_table[0], "GPC0_3");          if(err)          {                    printk(KERN_ERR "failed to request GPC0_3 for LVDS PWDN pin\n");         return err;          }          err = gpio_request(gpio_table[1], "GPC0_4");          if(err)          {                    printk(KERN_ERR "failed to request GPC0_4 for LVDS PWDN pin\n");         return err;          }          printk(KERN_INFO " leds opened\n");          for (i = 0; i < sizeof(gpio_table)/sizeof(unsigned long); i++)          {                    s3c_gpio_cfgpin(gpio_table, gpio_cfg_table);                    gpio_direction_output(gpio_table, 0);                    //s3c_gpio_setpin(gpio_table, 0);          } #ifdef CONFIG_TQ210_DEBUG_LEDS          for (i = 0; i < sizeof(gpio_table)/sizeof(unsigned long); i++)          {                    toggle_led(1,i);          } #endif          return 0; } /** *函数功能:用于控制led的亮灭 *fuction:control the led /turn on & turn off *控制字为cmd,arg为控制哪个灯的亮灭取值范围为0-1:cmd为IOCTL_GPIO_ON时亮,cmd为IOCTL_GPIO_OFF为灭 *control byte is cmd; arg appointed which led wile be turn on or off,it can be 0 and 1;IOCTL_GPIO_ON:turn on,IOCTL_GPIO_OFF:turn off. **/ static long tq210_gpio_ioctl(          struct inode *inode,          struct file *file,          unsigned int cmd,          unsigned long arg) {          arg -= 1;          if (arg > sizeof(gpio_table)/sizeof(unsigned long))          {                    return -EINVAL;          }          switch(cmd)          {                    case IOCTL_GPIO_ON:                             // 设置指定引脚的输出电平为1                             gpio_direction_output(gpio_table[arg], 1);                             //s3c_gpio_setpin(gpio_table[arg], 1);                             return 0;                    case IOCTL_GPIO_OFF:                             // 设置指定引脚的输出电平为0                             gpio_direction_output(gpio_table[arg], 0);                             //s3c_gpio_setpin(gpio_table[arg], 0);                             return 0;                    default:                             return -EINVAL;          } } static int tq210_gpio_close(struct inode *inode, struct file *file) {          gpio_free(gpio_table[0]);          gpio_free(gpio_table[1]);          printk(KERN_INFO "TQ210 LEDs driver successfully close\n");          return 0; } /*驱动接口设置*/ /*setting the interface of the driver*/ static struct file_operations dev_fops = {          .owner     =       THIS_MODULE,          .ioctl         =       tq210_gpio_ioctl,          .open =   tq210_gpio_open,          .release =        tq210_gpio_close, }; 
 
 |