• Home
  • Help
  • Search
  • Login
  • Register
Pages: [1]
Author Topic: how to write a driver to control pogoplug'led?  (Read 2775 times)
victor
Newbie
*

Karma: 0
Posts: 11



View Profile
« on: May 24, 2009, 06:51:16 AM »

Hi,guys,I use linux-2.6.30.rc6 kernel source,and this version include leds class driver,but I just driver leds using char driver, class driver is complex,more depency, and confuse me,I like directly driver leds by ioctl function,simply.
     I try to write a driver for leds this weekend,and steps as following:
step 1, change kirkwood_defconfig file about led like this

CONFIG_NEW_LEDS=no
CONFIG_LEDS_CLASS=no

#
# LED drivers
#
# CONFIG_LEDS_PCA9532 is not set
CONFIG_LEDS_GPIO=no
CONFIG_LEDS_GPIO_PLATFORM=no
# CONFIG_LEDS_LP5521 is not set
# CONFIG_LEDS_PCA955X is not set
# CONFIG_LEDS_DAC124S085 is not set
# CONFIG_LEDS_BD2802 is not set

#
# LED Triggers
#
CONFIG_LEDS_TRIGGERS=no
CONFIG_LEDS_TRIGGER_HEARTBEAT=no
# CONFIG_LEDS_TRIGGER_BACKLIGHT is not set
CONFIG_LEDS_TRIGGER_DEFAULT_ON=no

step 2, write a driver for driving leds,mainly ioctl function in driver,like this,

static int globalmem_ioctl(struct inode *inodep, struct file *filp, unsigned
  int cmd, unsigned long arg)
{
    int ret=0;

  switch (cmd)
  {

       case LED_OF:
       case LED_ON:
     if (arg > GPIO_MAX) {
         return -EINVAL;
      }
     ret=gpio_direction_output(arg,cmd);//arg is pin number,rang frome 0 to GPIO_MAX-1=50-1
     break;   
   case GPIO_REQUEST:
     ret=gpio_request(arg, GPIO_REQUEST+0x30);
     break;
    default:
      ret =  - EINVAL;
  }
  return ret;
}

step 3,test my driver,

int main(int argc, char **argv)
{
   int i;
   int fd;
   char c;
   int rt=0;
   char record[IO_MAXNUM];

   fd = open("/dev/led_drv", 0);
   if (fd < 0)
   {
      perror("Failed to open leds");
      exit(1);
   }


      for(i=0;i<GPIO_MAX;i++)
      {
         rt=ioctl(fd, 1,  i); 
         if(rt!=0)
         {
            printf("GPIO%d request failure,continue next.",i);
            continue;
         }
         else { printf("GPIO%d request sucess.",i); getchar();}              
         
                                  }
                 close(fd);
                 return 0;
}

result:rt=ioctl(fd, 1,  i); return not 0,which should be caused by  ret=gpio_direction_output(arg,cmd);in driver,but why?
how to control GPIO,how to write GPIO register?

any body point me ? thanks.
Logged

Pages: [1]
Print
Jump to: