abhi
unread,Jan 10, 2011, 7:28:31 AM1/10/11Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to hawkboard
Hi,
I am trying to write the driver for the GPIO. I write the code but I
am not understading the multiplexing configuration how can I use the
bank 5 i.e. GPIO5 port please help
here is the code(I am interested only in writing so don't include the
read routine)
/*
HEADER FILES
*/
MODULE_LICENSE("GPL");
char *ker_buf;
dev_t devid;
struct cdev ab_cdev;
unsigned int *GPIO54;
static int ab_open(struct inode *inode, struct file *file);
static int ab_release(struct inode *inode, struct file *file);
static ssize_t ab_read(struct file *file, char __user *buf, size_t
count, loff_t *ppos);
static ssize_t ab_write(struct file *file, const char __user *buf,
size_t count, loff_t *ppos);
struct file_operations ab_fops = {
.owner = THIS_MODULE,
.read = ab_read,
.write = ab_write,
.open = ab_open,
.release = ab_release,
};
static int ab_open(struct inode *inode, struct file *file)
{
unsigned int tmp;
int ret;
printk(KERN_INFO "Opening the device\n");
tmp = readb(GPIO54+3);
printk("GPIO Banks 4 and 5 Direction Register: 0x%x\n",tmp);
ret = writeb((tmp & 0xf0),GPIO54+3);
if(ret < 0) printk(" failed to write to data register\n");
else printk("GPIO5 8,9,10,11 set as output\n");
return 0;
}
static int ab_release(struct inode *inode, struct file *file)
{
unsigned int tmp;
int ret;
printk(KERN_INFO "Closing the device\n");
tmp = readb(GPIO54+3);
printk("GPIO Banks 4 and 5 Direction Register: 0x%x\n",tmp);
ret = writeb((tmp & 0xff),GPIO54+3);
if(ret < 0) printk(" failed to write to data register\n");
else printk("GPIO5 8,9,10,11 set as default\n");
return 0;
}
static ssize_t ab_read(struct file *file, char __user *buf, size_t
count, loff_t *ppos)
{
printk(KERN_INFO "Reading the device\n");
return 0;
}
static ssize_t ab_write(struct file *file, const char __user *buf,
size_t count, loff_t *ppos)
{
unsigned int tmp;
int ret;
char data = *buf;
printk(KERN_INFO "Writing the device\n");
tmp = readb(GPIO54+4+3);
printk("Current GPIO54 status: 0x%x\n",tmp);
if(count == 1 && data == 0x01)
{
tmp = readb(GPIO54+8+3);
printk("data 0x%x\n",tmp);
ret = writeb((0xff),GPIO54+8+3);
if(ret < 0) printk(" failed to write to data register\n");
else
{
tmp = readb(GPIO54+8+3);
printk("GPIO5 8,9,10,11 set to high: 0x%x\n",tmp);
tmp = readb(GPIO54+4+3);
printk("GPIO5 Status: 0x%x\n",tmp);
}
}
else
{
tmp = readb(GPIO54+12+3);
ret = writeb((0xff),GPIO54+12+3);
if(ret < 0) printk(" failed to write to data register\n");
else
{
tmp = readb(GPIO54+12+3);
printk("GPIO5 8,9,10,11 set to low: 0x%x\n",tmp);
tmp = readb(GPIO54+4+3);
printk("GPIO5 Status: 0x%x\n",tmp);
}
}
return 0;
}
static int hello_init(void)
{
unsigned short int major,minor;
unsigned int tmp;
void *ret;
printk(KERN_ALERT "Here we GO .............\nStarting GPIO\n");
ret = request_mem_region(0x01e26060,24,"GPIO_region");
// ret = request_region(0x01e26000,16,"GPIO_region");
if(!ret){ printk("request region failed\n"); return -1; }
GPIO54 = ioremap(0x01e26060,24+4);
if(alloc_chrdev_region(&devid, 0, 1,"GPIO_B1"))
{
printk("failed to register\n");
return -1;
}
major = MAJOR(devid);
minor = MINOR(devid);
printk(KERN_INFO"Major no. : %d MInor no. : %d\n",major,minor);
cdev_init(&ab_cdev, &ab_fops);
ab_cdev.owner = THIS_MODULE;
ab_cdev.ops = &ab_fops;
kobject_set_name(&ab_cdev.kobj,"GPIO");
if (cdev_add(&ab_cdev, devid, 1))
{
kobject_put(&ab_cdev.kobj);
unregister_chrdev_region(devid, 1);
return -1;
}
printk(KERN_INFO"GPIO INITIALISED\n");
return 0;
}
static void hello_exit(void)
{
printk(KERN_ALERT "Goodbye, cruel world\n");
iounmap(GPIO54);
release_mem_region(0x01e26060,24);
printk("Realising memory region\n");
cdev_del(&ab_cdev);
unregister_chrdev_region(devid, 1);
printk("Unregistered the device");
printk(KERN_ALERT "abhijit Exiting\n");
}
module_init(hello_init);
module_exit(hello_exit);