#ifndef __KERNEL__
#define __KERNEL__
#endif
#ifndef MODULE
#define MODULE
#endif
#include<linux/fs.h>
#include<linux/module.h>
#include<asm/hardware.h>
#include<linux/kernel.h>
#include<asm/arch/S3C2410.h>
MODULE_LICENSE("GPL");
#define IOPORT_MAJOR 220
typedef char ioport_device_t;
long port_addr;
static ioport_device_t gpio_devices[257];
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_ctl_fops=
{
ioctl: gpio_ctl_ioctl,
open: gpio_open,
release: gpio_release,
};
int gpio_open(struct inode *inode, struct file *filp)
{
int minor;
minor = MINOR(inode->i_rdev);
set_gpio_ctrl(GPIO_MODE_OUT|GPIO_F6);
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]--;
return 0;
}
int gpio_ctl_ioctl(struct inode *inode,struct file *flip,unsigned int command,unsigned long arg)
{
int err=0;
switch(command)
{
case 0:
write_gpio_bit(GPIO_MODE_OUT|GPIO_F6,1);
return 0;
case 1:
write_gpio_bit(GPIO_MODE_OUT|GPIO_F6,0);
return 0;
}
return err;
}
static devfs_handle_t devfs_handle;
int init_module(void)
{
int ret;
printk("hello \n");
ret=register_chrdev(IOPORT_MAJOR,"gpiotest",&gpio_ctl_fops);
devfs_handle = devfs_register(NULL,"gpiotest", DEVFS_FL_DEFAULT,
IOPORT_MAJOR,0,S_IFCHR|S_IRUSR|S_IWUSR,&gpio_ctl_fops,NULL);
return 0;
}
void cleanup_module(void)
{
devfs_unregister(devfs_handle);
unregister_chrdev(IOPORT_MAJOR,"gpiotest");
}
|