[Armadeus-commitlog] armadeus branch, master, updated. release-3.4-130-gd0bcdfd
Brought to you by:
sszy
|
From: Julien B a. A. <ar...@us...> - 2011-05-16 12:32:57
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "armadeus".
The branch, master has been updated
via d0bcdfd0c7914788ec4c7ccc6909fa8fd236ad18 (commit)
via 15825935c65f011451f49c88de2d1f956848716c (commit)
via 8a09bc863e3a44f485da20513e4cb6305bf6cb13 (commit)
from e1822083461afa622a4c03887084095a80576c5b (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit d0bcdfd0c7914788ec4c7ccc6909fa8fd236ad18
Merge: 15825935c65f011451f49c88de2d1f956848716c e1822083461afa622a4c03887084095a80576c5b
Author: Julien Boibessot <jul...@ar...>
Date: Mon May 16 14:30:43 2011 +0200
Merge branch 'master' of ssh://artemys@armadeus.git.sourceforge.net/gitroot/armadeus/armadeus
commit 15825935c65f011451f49c88de2d1f956848716c
Author: Julien Boibessot <jul...@ar...>
Date: Mon May 16 14:29:10 2011 +0200
[LINUX] Cleanup wishbone_example/wb_button and make it work for APF51
commit 8a09bc863e3a44f485da20513e4cb6305bf6cb13
Author: Julien Boibessot <jul...@ar...>
Date: Fri May 6 12:35:39 2011 +0200
Indentation, cleanup and remove uneeded comments in target/linux/modules/fpga/wishbone_example/wb_button/gbutton.c
-----------------------------------------------------------------------
Summary of changes:
.../wishbone_example/wb_button/board_buttons.c | 38 ++-
.../fpga/wishbone_example/wb_button/button.c | 260 --------------------
.../fpga/wishbone_example/wb_button/button.h | 14 +-
.../wishbone_example/wb_button/button_specific.h | 14 -
.../fpga/wishbone_example/wb_button/gbutton.c | 244 +++++++++----------
5 files changed, 144 insertions(+), 426 deletions(-)
delete mode 100644 target/linux/modules/fpga/wishbone_example/wb_button/button.c
delete mode 100644 target/linux/modules/fpga/wishbone_example/wb_button/button_specific.h
diff --git a/target/linux/modules/fpga/wishbone_example/wb_button/board_buttons.c b/target/linux/modules/fpga/wishbone_example/wb_button/board_buttons.c
index 345130d..d530265 100644
--- a/target/linux/modules/fpga/wishbone_example/wb_button/board_buttons.c
+++ b/target/linux/modules/fpga/wishbone_example/wb_button/board_buttons.c
@@ -1,7 +1,7 @@
/*
- * Specific button driver for generic button driver
+ * Platform data for generic button IP driver
*
- * (c) Copyright 2008 Armadeus project
+ * (c) Copyright 2008-2011 The Armadeus Project - ARMadeus Systems
* Fabien Marteau <fab...@ar...>
*
* This program is free software; you can redistribute it and/or modify
@@ -24,7 +24,7 @@
#include <linux/module.h>
#include <linux/platform_device.h>
#include <mach/hardware.h>
-#ifdef CONFIG_MACH_APF27 /* To remove when MX1 platform merged */
+#ifndef CONFIG_MACH_APF9328 /* To remove when MX1 platform is merged */
#include <mach/fpga.h>
#endif
@@ -32,25 +32,36 @@
#define BUTTON0_IRQ IRQ_FPGA(0)
+static struct resource button0_resources[] = {
+ [0] = {
+ .start = ARMADEUS_FPGA_BASE_ADDR + 0xc,
+ .end = ARMADEUS_FPGA_BASE_ADDR + 0xc + 0x4,
+ .flags = IORESOURCE_MEM,
+ },
+ [1] = {
+ .start = BUTTON0_IRQ,
+ .end = BUTTON0_IRQ,
+ .flags = IORESOURCE_IRQ,
+ }
+};
static struct plat_button_port plat_button0_data = {
- .name = "BUTTON0",
- .interrupt_number = BUTTON0_IRQ,
- .num = 0,
- .membase = (void *)(ARMADEUS_FPGA_BASE_ADDR_VIRT + 0xc),
- .idnum = 3,
- .idoffset = 0x00 * (16 / 8)
+ .name = "BUTTON0",
+ .num = 0,
+ .idnum = 3,
+ .idoffset = 0x00 * (16 / 8)
};
static struct platform_device plat_button0_device = {
- .name = "button",
- .id = 0,
- .dev = {
+ .name = "button",
+ .id = 0,
+ .dev = {
.platform_data = &plat_button0_data
},
+ .num_resources = ARRAY_SIZE(button0_resources),
+ .resource = button0_resources,
};
-
static int __init board_button_init(void)
{
return platform_device_register(&plat_button0_device);
@@ -67,4 +78,3 @@ module_exit(board_button_exit);
MODULE_AUTHOR("Fabien Marteau <fab...@ar...>");
MODULE_DESCRIPTION("Board specific button driver");
MODULE_LICENSE("GPL");
-
diff --git a/target/linux/modules/fpga/wishbone_example/wb_button/button.c b/target/linux/modules/fpga/wishbone_example/wb_button/button.c
deleted file mode 100644
index 1e43ee0..0000000
--- a/target/linux/modules/fpga/wishbone_example/wb_button/button.c
+++ /dev/null
@@ -1,260 +0,0 @@
-/*
- ***********************************************************************
- *
- * (c) Copyright 2007 Armadeus project
- * Fabien Marteau <fab...@ar...>
- * Driver for Wb_button IP
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2, or (at your option)
- * any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- **********************************************************************
- */
-
-#include <linux/version.h>
-#include <linux/init.h>
-#include <linux/module.h>
-#include <linux/fs.h>
-#include <linux/cdev.h>
-#include <linux/semaphore.h>
-#include <linux/ioport.h> /* request_mem_region */
-#include <linux/jiffies.h>
-#include <linux/interrupt.h>
-#include <linux/wait.h>
-
-#include <asm/uaccess.h> /* copy_to_user function */
-#include <asm/io.h> /* readw() writew() */
-#include <mach/hardware.h>
-#include <asm/irq.h>
-
-/*#define BUTTON_DEBUG*/
-
-#undef PDEBUG
-#ifdef BUTTON_DEBUG
-# ifdef __KERNEL__
- /* for kernel spage */
-# define PDEBUG(fmt,args...) printk(KERN_INFO "button : " fmt, ##args)
-# else
- /* for user space */
-# define PDEBUG(fmt,args...) printk(stderr, fmt, ##args)
-# endif
-#else
-# define PDEBUG(fmt,args...) /* no debugging message */
-#endif
-
-#include "button.h"
-
-/* Internal read/write helpers */
-
-static ssize_t button_fpga_read(void * addr, u16 *data, struct button_dev *dev)
-{
- *data = ioread16(addr); /* read the button value */
-
- return 2;
-}
-
-static ssize_t button_fpga_write(void * addr, u16 *data, struct button_dev *dev)
-{
- ssize_t retval;
-
- iowrite16(*data, addr); /* write the button value */
- retval = 2;
-
- return retval;
-}
-
-/* irq management; awake read process */
-static irqreturn_t fpga_interrupt(int irq, void *dev_id, struct pt_regs *reg)
-{
- struct button_dev *ldev = dev_id;
- u16 data;
-
- button_fpga_read(ldev->fpga_virtual_base_address + FPGA_IRQ_PEND, &data, ldev);
- PDEBUG("Interrupt raised %x\n", data);
-
- if (data & WB_BUTTON_IRQ) {
- /* wake up reading process */
- if (ldev->reading)
- up(&ldev->sem);
- /* acknowledge irq_mngr */
- button_fpga_write(ldev->fpga_virtual_base_address + FPGA_IRQ_ACK, &data, ldev);
- return IRQ_HANDLED;
- } else {
- return IRQ_NONE;
- }
-}
-
-/***********************************
- * characters file /dev operations
- * *********************************/
-ssize_t button_read(struct file *fildes, char __user *buff, size_t count, loff_t *offp)
-{
- struct button_dev *ldev = fildes->private_data;
- u16 data = 0;
- ssize_t retval = 0;
- DEFINE_WAIT(wait);
-
- ldev->reading = 1;
-
- if (*offp + count >= 1) /* Only one word can be read */
- count = 1 - *offp;
-
- if ((retval=down_interruptible(&ldev->sem)) < 0)
- goto out;
-
- if ((retval = button_fpga_read(ldev->fpga_virtual_base_address + FPGA_BUTTON, &data, ldev)) < 0)
- goto out;
-
- /* return data for user */
- if (copy_to_user(buff, &data, 2)) {
- printk(KERN_WARNING "read : copy to user data error\n");
- retval = -EFAULT;
- goto out;
- }
-
- *offp = *offp + count;
- retval = 1;
-
-out:
- PDEBUG("read : Return value %d\n", (int)retval);
- ldev->reading = 0;
-
- return retval;
-}
-
-int button_open(struct inode *inode, struct file *filp)
-{
- /* Allocate and fill any data structure to be put in filp->private_data */
- filp->private_data = container_of(inode->i_cdev, struct button_dev, cdev);
- PDEBUG("file opened\n");
-
- return 0;
-}
-
-int button_release(struct inode *inode, struct file *filp)
-{
- PDEBUG("released\n");
-
- return 0;
-}
-
-/**********************************
- * Module management
- **********************************/
-static int __init button_init(void)
-{
- int result;
- int button_major, button_minor;
- u16 data;
- struct button_dev *sdev;
-
- button_major = 252;
- button_minor = 0;
-
- /* Allocate a private structure and reference it as driver's data */
- sdev = (struct button_dev *)kmalloc(sizeof(struct button_dev), GFP_KERNEL);
- if (sdev == NULL) {
- printk(KERN_WARNING "button: unable to allocate private structure\n");
- return -ENOMEM;
- }
-
- /* initiate mutex locked */
- sdev->reading = 0;
- init_MUTEX_LOCKED(&sdev->sem);
-
- /* Get the major and minor device numbers */
- PDEBUG("Get the major and minor device numbers\n");
- if (button_major) {
- devno = MKDEV(button_major, button_minor);
- result = register_chrdev_region(devno, N_DEV,BUTTON_NAME);
- } else {
- result = alloc_chrdev_region(&devno, button_minor, N_DEV, BUTTON_NAME);
- button_major = MAJOR(devno);
- }
- printk(KERN_INFO "button: MAJOR: %d MINOR: %d\n", MAJOR(devno), MINOR(devno));
- if (result < 0) {
- printk(KERN_WARNING "button: can't get major %d\n", button_major);
- }
-
- /* Init the cdev structure */
- PDEBUG("Init the cdev structure\n");
- cdev_init(&sdev->cdev, &button_fops);
- sdev->cdev.owner = THIS_MODULE;
-
- /* Add the device to the kernel, connecting cdev to major/minor number */
- PDEBUG("Add the device to the kernel, connecting cdev to major/minor number\n");
- result = cdev_add(&sdev->cdev, devno, 1);
- if (result < 0)
- printk(KERN_WARNING "button: can't add cdev\n");
-
- /* Requested I/O memory */
- sdev->fpga_virtual_base_address = (void*)IMX_CS1_VIRT;
-
- /* irq unmask */
- data = 1 | ioread16(sdev->fpga_virtual_base_address + FPGA_IRQ_MASK);
- if ((result=button_fpga_write(sdev->fpga_virtual_base_address + FPGA_IRQ_MASK, &data, sdev)) < 0)
- goto error;
-
- /* irq acknowledge */
- data = 1;
- if ((result=button_fpga_write(sdev->fpga_virtual_base_address + FPGA_IRQ_ACK, &data, sdev)) < 0)
- goto error;
-
- /* irq registering */
- printk(KERN_INFO "button: fpga irq shared gpioa 1\n");
- if (request_irq(IRQ_GPIOA(1), (irq_handler_t)fpga_interrupt, IRQF_SHARED,BUTTON_IRQ_NAME, sdev) < 0) {
- printk(KERN_ERR "Can't request fpga irq\n");
- goto error;
- }
-
- /* OK driver ready ! */
- buttondev = sdev;
- printk(KERN_INFO "button module loaded\n");
- return 0;
-
-error:
- printk(KERN_ERR "%s: not loaded\n", BUTTON_NAME);
- free_all();
-
- return result;
-}
-
-static void __exit button_exit(void)
-{
- free_all();
-}
-
-static void free_all(void)
-{
- struct button_dev *sdev = buttondev;
-
- /* free irq*/
- free_irq(IRQ_GPIOA(1), sdev);
-
- /* delete the cdev structure */
- cdev_del(&sdev->cdev);
-
- /* Free the allocated memory */
- kfree(sdev);
-
- /* Release I/O memories */
- release_mem_region(FPGA_BASE_ADDR, FPGA_MEM_SIZE);
-
- /* free major and minor number */
- unregister_chrdev_region(devno, N_DEV);
- printk(KERN_INFO "button module unloaded\n");
-}
-
-module_init(button_init);
-module_exit(button_exit);
-
diff --git a/target/linux/modules/fpga/wishbone_example/wb_button/button.h b/target/linux/modules/fpga/wishbone_example/wb_button/button.h
index 7135e2d..590b9a7 100644
--- a/target/linux/modules/fpga/wishbone_example/wb_button/button.h
+++ b/target/linux/modules/fpga/wishbone_example/wb_button/button.h
@@ -1,9 +1,8 @@
/*
- ***********************************************************************
+ * Platform data for generic button IP driver
*
- * (c) Copyright 2007 Armadeus project
+ * (c) Copyright 2007-2011 The Armadeus Project - ARMadeus Systems
* Fabien Marteau <fab...@ar...>
- * Driver for Wb_button IP
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -18,27 +17,22 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- **********************************************************************
*/
-
#ifndef __BUTTON_H__
#define __BUTTON_H__
#define BUTTON_NUMBER 1
-
#define BUTTON_REG_OFFSET (0x02)
#define BUTTON_ID_OFFSET (0x00)
/* platform device */
struct plat_button_port {
- const char *name; /*instance name */
- int interrupt_number; /* interrupt_number */
+ const char *name; /* instance name */
int num; /* instance number */
- void *membase; /* ioremap base address */
int idnum; /* identity number */
int idoffset; /* identity relative address */
- struct button_dev *sdev;/* struct for main device structure*/
+ struct button_dev *sdev;/* struct for main device structure */
};
#endif /* __BUTTON_H__ */
diff --git a/target/linux/modules/fpga/wishbone_example/wb_button/button_specific.h b/target/linux/modules/fpga/wishbone_example/wb_button/button_specific.h
deleted file mode 100644
index fb7d9a2..0000000
--- a/target/linux/modules/fpga/wishbone_example/wb_button/button_specific.h
+++ /dev/null
@@ -1,14 +0,0 @@
-#define BUTTON_NAME "button"
-#define FPGA_BUTTON 8
-#define FPGA_IRQ_MASK 0
-#define FPGA_IRQ_PEND 2
-#define FPGA_IRQ_ACK 2
-
-/* Fpga base address for led */
-#define FPGA_BASE_ADDR IMX_CS1_PHYS
-#define FPGA_MEM_SIZE IMX_CS1_SIZE
-#define BUTTON_IRQ_NAME "button"
-
-/* interrupt position in irq_mngr */
-#define WB_BUTTON_IRQ 0x0001
-
diff --git a/target/linux/modules/fpga/wishbone_example/wb_button/gbutton.c b/target/linux/modules/fpga/wishbone_example/wb_button/gbutton.c
index 6eb9122..a2ba158 100644
--- a/target/linux/modules/fpga/wishbone_example/wb_button/gbutton.c
+++ b/target/linux/modules/fpga/wishbone_example/wb_button/gbutton.c
@@ -1,9 +1,8 @@
/*
- ***********************************************************************
+ * Generic driver for Wishbone button IP
*
- * (c) Copyright 2008 Armadeus project
+ * (c) Copyright 2008-2011 The Armadeus Project - ARMadeus Systems
* Fabien Marteau <fab...@ar...>
- * Generic driver for Wishbone button IP
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
@@ -18,7 +17,6 @@
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- **********************************************************************
*/
#include <linux/version.h>
@@ -36,29 +34,11 @@
#include <asm/uaccess.h> /* copy_to_user function */
#include <asm/io.h> /* readw() writew() */
#include <mach/hardware.h>
+#include <mach/fpga.h>
#include "button.h"
-/* for debugging messages*/
-//#define BUTTON_DEBUG
-
-#undef PDEBUG
-#ifdef BUTTON_DEBUG
-# ifdef __KERNEL__
-/* for kernel space */
-# define PDEBUG(fmt,args...) printk(KERN_DEBUG "BUTTON : " fmt, ##args)
-# else
-/* for user space */
-# define PDEBUG(fmt,args...) printk(stderr, fmt, ##args)
-# endif
-#else
-# define PDEBUG(fmt,args...) /* no debbuging message */
-#endif
-
-/********************************
- * main device structure
- * ******************************/
struct button_dev {
char *name; /* name of the instance */
struct cdev cdev; /* char device structure */
@@ -66,16 +46,15 @@ struct button_dev {
void * membase; /* base address for instance */
dev_t devno; /* to store Major and minor numbers */
u8 read_in_wait; /* user is waiting for value to read */
+ struct resource *mem_res;
+ struct resource *irq_res;
};
-/***********************************
- * characters file /dev operations
- * *********************************/
ssize_t button_read(struct file *fildes, char __user *buff,
size_t count, loff_t *offp)
{
struct button_dev *ldev = fildes->private_data;
- u16 data=0;
+ u16 data = 0;
ssize_t retval = 0;
ldev->read_in_wait = 1;
@@ -83,12 +62,12 @@ ssize_t button_read(struct file *fildes, char __user *buff,
if (*offp + count >= 1) /* Only one word can be read */
count = 1 - *offp;
- if ((retval=down_interruptible(&ldev->sem)) < 0) {
+ if ((retval = down_interruptible(&ldev->sem)) < 0) {
goto out;
}
- data=ioread16(ldev->membase+BUTTON_REG_OFFSET);
- PDEBUG("Read %d at 0x%x\n",data,(unsigned int)ldev->membase+BUTTON_REG_OFFSET);
+ data = readw(ldev->membase + BUTTON_REG_OFFSET);
+ pr_debug("Read %d at 0x%x\n", data, (unsigned int)ldev->membase + BUTTON_REG_OFFSET);
/* return data for user */
if (copy_to_user(buff, &data, 2)) {
@@ -105,11 +84,10 @@ out:
return retval;
}
-
int button_open(struct inode *inode, struct file *filp)
{
/* Allocate and fill any data structure to be put in filp->private_data */
- filp->private_data = container_of(inode->i_cdev,struct button_dev, cdev);
+ filp->private_data = container_of(inode->i_cdev, struct button_dev, cdev);
return 0;
}
@@ -119,12 +97,11 @@ int button_release(struct inode *inode, struct file *filp)
struct button_dev *dev;
dev = container_of(inode->i_cdev, struct button_dev, cdev);
- filp->private_data=NULL;
+ filp->private_data = NULL;
return 0;
}
-
static struct file_operations button_fops = {
.owner = THIS_MODULE,
.read = button_read,
@@ -132,11 +109,6 @@ static struct file_operations button_fops = {
.release = button_release,
};
-/**********************************
- * irq management
- * awake read process
- * ********************************/
-
static irqreturn_t button_interrupt(int irq, void *dev_id)
{
struct button_dev *ldev = dev_id;
@@ -148,63 +120,94 @@ static irqreturn_t button_interrupt(int irq, void *dev_id)
return IRQ_HANDLED;
}
-/**********************************
- * driver probe
- **********************************/
static int button_probe(struct platform_device *pdev)
{
- struct plat_button_port *dev = pdev->dev.platform_data;
-
- int result = 0; /* error return */
- int button_major,button_minor;
- u16 data;
+ struct plat_button_port *pdata = pdev->dev.platform_data;
+ int ret = 0;
+ int button_major, button_minor;
+ u16 ip_id;
struct button_dev *sdev;
-
- PDEBUG("Button probing\n");
- PDEBUG("Register %s num %d\n",dev->name,dev->num);
+ struct resource *mem_res;
+ struct resource *irq_res;
- /* check if ID is correct */
- data = ioread16(dev->membase+BUTTON_ID_OFFSET);
- if (data != dev->idnum) {
- result = -1;
- printk(KERN_WARNING "For %s id:%d doesn't match "
- "with id read %d,\n is device present ?\n",
- dev->name,dev->idnum,data);
- goto error_id;
+ pr_debug("Button probing\n");
+ pr_debug("Register %s num %d\n", pdata->name, pdata->num);
+
+ if (!pdata) {
+ dev_err(&pdev->dev, "Platform data required !\n");
+ return -ENODEV;
+ }
+
+ /* get resources */
+ mem_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+ if (!mem_res) {
+ dev_err(&pdev->dev, "can't find mem resource\n");
+ return -EINVAL;
+ }
+ irq_res = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
+ if (!irq_res) {
+ dev_err(&pdev->dev, "can't find irq resource\n");
+ return -EINVAL;
}
- /* allocate memory for sdev structure */
- sdev = kmalloc(sizeof(struct button_dev),GFP_KERNEL);
+ mem_res = request_mem_region(mem_res->start, resource_size(mem_res), pdev->name);
+ if (!mem_res) {
+ dev_err(&pdev->dev, "iomem already in use\n");
+ return -EBUSY;
+ }
+
+ /* allocate memory for private structure */
+ sdev = kmalloc(sizeof(struct button_dev), GFP_KERNEL);
if (!sdev) {
- result = -ENOMEM;
- goto error_sdev_alloc;
+ ret = -ENOMEM;
+ goto out_release_mem;
+ }
+
+ sdev->membase = ioremap(mem_res->start, resource_size(mem_res));
+ if (!sdev->membase) {
+ dev_err(&pdev->dev, "ioremap failed\n");
+ ret = -ENOMEM;
+ goto out_dev_free;
+ }
+ sdev->mem_res = mem_res;
+ sdev->irq_res = irq_res;
+
+ /* check if ID is correct */
+ ip_id = readw(sdev->membase + BUTTON_ID_OFFSET);
+ if (ip_id != pdata->idnum) {
+ ret = -ENODEV;
+ dev_warn(&pdev->dev, "For %s id:%d doesn't match "
+ "with id read %d,\n is device present ?\n",
+ pdata->name, pdata->idnum, ip_id);
+ goto out_iounmap;
}
- dev->sdev = sdev;
- sdev->membase = dev->membase;
- sdev->name = (char *)kmalloc((1+strlen(dev->name))*sizeof(char),
+
+ pdata->sdev = sdev;
+
+ sdev->name = (char *)kmalloc((1+strlen(pdata->name))*sizeof(char),
GFP_KERNEL);
if (sdev->name == NULL) {
- printk("Kmalloc name space error\n");
- goto error_name_alloc;
+ dev_err(&pdev->dev, "Kmalloc name space error\n");
+ goto out_iounmap;
}
- if (strncpy(sdev->name, dev->name, 1+strlen(dev->name)) < 0) {
+ if (strncpy(sdev->name, pdata->name, 1 + strlen(pdata->name)) < 0) {
printk("copy error");
- goto error_name_copy;
+ goto out_name_free;
}
/* Get the major and minor device numbers */
button_major = 251;
- button_minor = dev->num;
+ button_minor = pdata->num;
sdev->devno = MKDEV(button_major, button_minor);
- result = alloc_chrdev_region(&(sdev->devno), button_minor, 1,dev->name);
- if (result < 0) {
- printk(KERN_WARNING "%s: can't get major %d\n",
- dev->name,button_major);
- goto error_devno;
+ ret = alloc_chrdev_region(&(sdev->devno), button_minor, 1, pdata->name);
+ if (ret < 0) {
+ dev_warn(&pdev->dev, "%s: can't get major %d\n",
+ pdata->name, button_major);
+ goto out_name_free;
}
- printk(KERN_INFO "%s: MAJOR: %d MINOR: %d\n",
- dev->name,
+ dev_info(&pdev->dev, "%s: MAJOR: %d MINOR: %d\n",
+ pdata->name,
MAJOR(sdev->devno),
MINOR(sdev->devno));
@@ -213,108 +216,94 @@ static int button_probe(struct platform_device *pdev)
sema_init(&sdev->sem, 0);
/* Init the cdev structure */
- PDEBUG("Init the cdev structure\n");
- cdev_init(&sdev->cdev,&button_fops);
+ cdev_init(&sdev->cdev, &button_fops);
sdev->cdev.owner = THIS_MODULE;
sdev->cdev.ops = &button_fops;
- PDEBUG("%s: Add the device to the kernel, "
- "connecting cdev to major/minor number \n",dev->name);
- result = cdev_add(&sdev->cdev, sdev->devno, 1);
- if (result < 0) {
- printk(KERN_WARNING "%s: can't add cdev\n", dev->name);
- goto error_cdev_add;
+ pr_debug("%s: Add the device to the kernel, "
+ "connecting cdev to major/minor number \n", pdata->name);
+ ret = cdev_add(&sdev->cdev, sdev->devno, 1);
+ if (ret < 0) {
+ dev_warn(&pdev->dev, "%s: can't add cdev\n", pdata->name);
+ goto out_cdev_free;
}
/* irq registering */
- result = request_irq(dev->interrupt_number,
+ ret = request_irq(sdev->irq_res->start,
button_interrupt,
IRQF_SAMPLE_RANDOM,
sdev->name,
sdev);
- if (result < 0) {
+ if (ret < 0) {
printk(KERN_ERR "Can't register irq %d\n",
- dev->interrupt_number);
+ sdev->irq_res->start);
goto request_irq_error;
}
- printk(KERN_INFO "button: irq registered : %d\n",
- dev->interrupt_number);
/* OK driver ready ! */
- printk(KERN_INFO "%s loaded\n", dev->name);
+ printk(KERN_INFO "%s loaded\n", pdata->name);
return 0;
- /*********************/
- /* Errors management */
- /*********************/
- /* freeing irq */
- free_irq(dev->interrupt_number, sdev);
+ free_irq(sdev->irq_res->start, sdev);
request_irq_error:
- /* delete the cdev structure */
cdev_del(&sdev->cdev);
- PDEBUG("%s:cdev deleted\n", dev->name);
-error_cdev_add:
- /* free major and minor number */
+ pr_debug("%s:cdev deleted\n", pdata->name);
+out_cdev_free:
unregister_chrdev_region(sdev->devno, 1);
- printk(KERN_INFO "%s: button deleted\n", dev->name);
-error_devno:
-error_name_copy:
+ printk(KERN_INFO "%s: button deleted\n", pdata->name);
+out_name_free:
kfree(sdev->name);
-error_name_alloc:
+out_iounmap:
+ iounmap(sdev->membase);
+out_dev_free:
kfree(sdev);
-error_sdev_alloc:
- printk(KERN_ERR "%s: not loaded\n", dev->name);
-error_id:
- return result;
+out_release_mem:
+ release_mem_region(mem_res->start, resource_size(mem_res));
+
+ return ret;
}
static int __devexit button_remove(struct platform_device *pdev)
{
- struct plat_button_port *dev = pdev->dev.platform_data;
- struct button_dev *sdev = (*dev).sdev;
+ struct plat_button_port *pdata = pdev->dev.platform_data;
+ struct button_dev *sdev = (*pdata).sdev;
- /* freeing irq */
- free_irq(dev->interrupt_number, sdev);
+ free_irq(sdev->irq_res->start, sdev);
- /* delete the cdev structure */
cdev_del(&sdev->cdev);
- PDEBUG("%s:cdev deleted\n",dev->name);
+ pr_debug("%s:cdev deleted\n", pdata->name);
- /* free major and minor number */
unregister_chrdev_region(sdev->devno, 1);
- printk(KERN_INFO "%s: button deleted\n", dev->name);
+ printk(KERN_INFO "%s: button deleted\n", pdata->name);
kfree(sdev->name);
+ iounmap(sdev->membase);
kfree(sdev);
- printk(KERN_INFO "%s: deleted with success\n", dev->name);
+ release_mem_region(sdev->mem_res->start, resource_size(sdev->mem_res));
+ printk(KERN_INFO "%s: deleted with success\n", pdata->name);
return 0;
-
}
static struct platform_driver plat_button_driver =
{
.probe = button_probe,
.remove = __devexit_p(button_remove),
- .driver =
- {
+ .driver = {
.name = "button",
.owner = THIS_MODULE,
},
};
-/**********************************
- * Module management
- **********************************/
static int __init button_init(void)
{
int ret;
- PDEBUG("Platform driver name %s", plat_button_driver.driver.name);
+ pr_debug("Platform driver name %s", plat_button_driver.driver.name);
ret = platform_driver_register(&plat_button_driver);
if (ret) {
printk(KERN_ERR "Platform driver register error\n");
- return ret;
+ return ret;
}
return 0;
@@ -329,7 +318,6 @@ module_init(button_init);
module_exit(button_exit);
MODULE_LICENSE("GPL");
-MODULE_AUTHOR("Fabien Marteau <fab...@ar...> "
- "- ARMadeus Systems");
-MODULE_DESCRIPTION("button device generic driver");
+MODULE_AUTHOR("Fabien Marteau <fab...@ar...>");
+MODULE_DESCRIPTION("Wishbone button IP generic driver");
hooks/post-receive
--
armadeus
|