/* driver/char/gpio_drv.c
*
* This file provide IO reading and writing from user space.
* Pls create some device file in diretory /dev/ppcflash whose major is 218.
* This driver support 0-255 devices. In user space user can read and write
* IO through open and ioctl function provided by glibc.
*
* Any problem pls contact support@hhcn.com
*/
#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_drv.h"
#include <linux/vmalloc.h>
#include <linux/module.h> //wpq insmod gpio
#define dprintk(x...)
#define IOPORT_MAJOR 220
//#define gpio_devfs_dir
/*define the ppcflash major node is 220*/
typedef char ioport_device_t;
devfs_handle_t gpio_devfs_dir;
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);
//#################################################################
//wpq mod
/*
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)
{
register_chrdev(IOPORT_MAJOR, "gpiotest", &gpio_ctl_fops);
return 0;
*/
/*
* Open/close code for raw IO.
*/
gpio_open(struct inode *inode, struct file *filp)
{
int minor;
minor = MINOR(inode->i_rdev);
/* if (ioport_devices[minor].io_lock) {
printk("Device is busy\n");
return -1;
}*/
set_gpio_ctrl(GPIO_MODE_OUT | GPIO_C6);
#if 0
(void *)(port_addr) = ioremap(0x56000020,0x8);
printk("port addr is %x\n",port_addr);
printk("port addr is %x\n", GPCON(GPIO_MODE_OUT | GPIO_C6));
// *(volatile unsigned int *)(port_addr)|=0x00008000;
// set_gpio_ctrl(GPIO_MODE_VD);
// *(volatile unsigned int *)(0x56000020)|=0x00008000;
#endif
printk("open ok\n");
gpio_devices[minor]++;
return 0;
}
//__ioremap
int gpio_release(struct inode *inode, struct file *filp)
{
int minor;
minor = MINOR(inode->i_rdev);
if (gpio_devices[minor])
gpio_devices[minor]--;
// *(volatile unsigned int *)(0x56000020)&=~0x00008000;
printk("release ok\n");
return 0;
}
/*
* Deal with ioctls against the raw-device control interface, to bind
* and unbind other raw devices.
*/
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:
// *(volatile unsigned int *)(port_addr+1)|=0x00000080;
write_gpio_bit(GPIO_MODE_OUT | GPIO_C6,1);
printk("HHTECH: here write ok1111\n");
return 0;
case IOCLEAR:
write_gpio_bit(GPIO_MODE_OUT | GPIO_C6,0);
// *(volatile unsigned int *)(port_addr+1)&=~0x00000080;
printk("clear ok\n");
return 0;
default:
err = -EINVAL;
}
return err;
}
//##########################################################
//hhtech add it by wpq ,2005 01 28
//
static int __init
gpio_init (void)
{
// gpio_devfs_dir = devfs_mk_dir(NULL, "gpiotest", NULL);
// if(!gpio_devfs_dir)
// return -EBUSY;
// register_chrdev(IOPORT_MAJOR, "gpiotest", &gpio_ctl_fops);
//devfs_register(IOPORT_MAJOR, "gpiotest", &gpio_ctl_fops);
//############################################################################
//
//hhtech add it by wpq
//date:20050128
//The" devfs"is very important!!!register file command
//note:devfs and register ;but ,devfs= register+mknod
//Here isn't use :mknod /dev/gpiotest c 220 0
gpio_devfs_dir= devfs_register(NULL,"gpiotest",DEVFS_FL_DEFAULT,IOPORT_MAJOR,
0, S_IFCHR |S_IRUSR |S_IWUSR |S_IRGRP |S_IWGRP,
&gpio_ctl_fops, NULL);
printk ("gpio driver installed OK\n");
printk ("Test is starting!\n");
return 0;
}
static void __exit
gpio_exit(void)
{
devfs_unregister(gpio_devfs_dir);
printk("gpio driver uninstalled OK\n");
}
module_init(gpio_init);
module_exit(gpio_exit);
MODULE_LICENSE("GPL");
MODULE_AUTHOR("wpq");
MODULE_DESCRIPTION("gpio Driver for arm9_edu");