Gpio driver, ioctl inaccessible, always return error-1

Source: Internet
Author: User
Gpio driver, ioctl cannot be accessed, always return error-1 -- Linux general technology-Linux technology and application information, the following is read details. Today, I wrote an application to test linux and found that ioctl went wrong.-1 was returned. why?
What's more strange is that when the kernel-side gpio_ioctl is added to the printk mode, there is no output, which means that when the user program ioctl, gpio_ioctl will not be executed at all !!!
Ask for help. give me some advice on linux Cainiao! And the called write and read are all good.
Kernel Driver
Define GPIO_MAGIC 'M'
# Define GPIO_CMD1 _ IOR (GPIO_MAGIC, 0x1a, unsigned long)
# Define GPIO_CMD2 _ IOR (GPIO_MAGIC, 0x1b, unsigned long)

Static long gpio_ioctl (struct file * file, unsigned int cmd, unsigned long arg)
{
Int ret = 3;
Int val;
Printk (KERN_WARNING "wuwuwuwuwuw \ n ");
Printk (KERN_WARNING "cmd = % d \ n", cmd); ------- This place has not been printed
Switch (cmd ){
Case GPIO_CMD1:
Case GPIO_CMD2:
If (arg> 7 ){
Return 10;
}
_ Raw_writel (1 <val =__ raw_readl (gpdat );
Printk (KERN_WARNING "the value of % x \ n", val );
Printk (KERN_WARNING "the value is 1 \ n ");
Break;
Default:
Return 0;
}
Return ret;
}

Test procedure:
# Define GPIO_MAGIC 'M'
# Define GPIO_CMD1 _ IOR (GPIO_MAGIC, 0x1a, unsigned long)
# Define GPIO_CMD2 _ IOR (GPIO_MAGIC, 0X1b, unsigned long)

Int main (int argc, char ** argv)
{
Unsigned long on;
Int led_no;
Int fd;
Long int ret = 1;
If (argc! = 3 | sscanf (argv [1], "% d", & led_no )! = 1 | sscanf (argv [2], "% d", & on )! = 1 |
On <0 | on> 1 | led_no <0 | led_no> 3 ){
Fprintf (stderr, "Usage: leds led_no 0 | 1 \ n ");
/// Exit (1 );
}
// Fd = open ("/dev/leds", 0 );
Fd = open ("/dev/s3c-gpio", O_RDWR );
If (fd <0 ){
Perror ("open device leds ");
// Exit (1 );
}
If (on = 1)
Ret = ioctl (fd, GPIO_CMD1, & led_no );
Else
Ret = ioctl (fd, GPIO_CMD2, & led_no );
Printf ("ret = % d \ n", ret );

Close (fd );
Return 0;
Related Article

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.