问题:
在下面驱动程序里,gpio_open、gpio_release、gpio_ctl_ioctl函数都返回0;
以gpio_open函数为例,因为返回 0,所以调用gpio_open应该得到返回值0,所以在测试程序里调用open函数时,它会调用gpio_open,调用open后得到的返回值应该是0,可我怎么得到的返回值为3?这说明gpio_open返回的0与测试程序调用gpio_open得到的值不是一样的,说明他们没关系。于是我把gpio_open中的返回值改为-35,则应用程序找不到设备。不知这该作何解释?
但是我把gpio_release中的返回值改为负值后,应用程序却能正常的调用gpio_release。这是怎么回事?
望各位指点!
附(驱动程序):
#include <linux/fs.h>
#include <linux/iobuf.h>
#include <linux/major.h>
#include <linux/blkdev.h>
#include <linux/capability.h>
#include <linux/smp_lock.h>
#include <asm/uaccess.h>
#include <asm/hardware.h>
#include <asm/arch/cpu_s3c2410.h>
#include <asm/io.h>
#include "gpio_test.h"
#include <linux/vmalloc.h>
#define dprintk(x...)
#define IOPORT_MAJOR 220
/*define the ppcflash major node is 220*/
typedef char ioport_device_t;
static ioport_device_t gpio_devices[256];
long port_addr;
int gpio_open(struct inode *, struct file *);
int gpio_release(struct inode *, struct file *);
int gpio_ctl_ioctl(struct inode *, struct file *, unsigned int, unsigned long);
static struct file_operations gpio_fops = {
open: gpio_open,
release: gpio_release,
};
static struct file_operations gpio_ctl_fops = {
ioctl: gpio_ctl_ioctl,
open: gpio_open,
release: gpio_release,
};
int __init gpio_init(void)
{
int i;
register_chrdev(IOPORT_MAJOR, "gpiotest", &gpio_ctl_fops);
return 0;
}
__initcall(gpio_init);
int gpio_open(struct inode *inode, struct file *filp)
{
int minor;
minor = MINOR(inode->i_rdev);
set_gpio_ctrl(GPIO_MODE_OUT | GPIO_C8);
printk("open ok\n");
gpio_devices[minor]++;
return 0;
}
int gpio_release(struct inode *inode, struct file *filp)
{
int minor;
minor = MINOR(inode->i_rdev);
if (gpio_devices[minor])
gpio_devices[minor]--;
printk("release ok\n");
return 0;
}
int gpio_ctl_ioctl(struct inode *inode,
struct file *flip,
unsigned int command,
unsigned long arg)
{
int err = 0;
int minor = MINOR(inode->i_rdev);
switch (command) {
case IOWRITE:
write_gpio_bit(GPIO_MODE_OUT | GPIO_C8,1);
printk("write ok\n");
return 0;
case IOCLEAR:
write_gpio_bit(GPIO_MODE_OUT | GPIO_C8,0);
printk("clear ok\n");
return 0;
default:
err = -EINVAL;
}
return err;
}
------解决方案--------------------
未试过这种情况 mark