diff options
author | Arun Murthy <arun.murthy@stericsson.com> | 2011-09-29 13:11:25 +0530 |
---|---|---|
committer | Robert Marklund <robert.marklund@stericsson.com> | 2011-10-05 13:01:48 +0200 |
commit | 607f87e0bf6d8999e2699b76ffdbaad0305fc4b6 (patch) | |
tree | 530e82526c7a85bbc97819e07f16ad1fba3ff240 | |
parent | b692974f7f483ace41df70a0a4848f339ec8e1eb (diff) |
u5500-mbox: Add platform driver remove
Also correct the improper usage of platform data.
ST-Ericsson Linux next: NA
ST-Ericsson ID: 341807
ST-Ericsson FOSS-OUT ID: Trivial
Change-Id: I9468996195c3652e94fc908f90ce85c66a5db519
Signed-off-by: Arun Murthy <arun.murthy@stericsson.com>
Reviewed-on: http://gerrit.lud.stericsson.com/gerrit/32490
Reviewed-by: Srinidhi KASAGAR <srinidhi.kasagar@stericsson.com>
-rw-r--r-- | drivers/misc/mbox.c | 37 |
1 files changed, 22 insertions, 15 deletions
diff --git a/drivers/misc/mbox.c b/drivers/misc/mbox.c index 5f5a457b277..73f34069d84 100644 --- a/drivers/misc/mbox.c +++ b/drivers/misc/mbox.c @@ -32,6 +32,7 @@ #include <linux/interrupt.h> #include <linux/spinlock.h> #include <linux/errno.h> +#include <linux/slab.h> #include <linux/io.h> #include <linux/irq.h> #include <linux/platform_device.h> @@ -130,7 +131,8 @@ static ssize_t mbox_write_fifo(struct device *dev, char *token; char *val; - struct mbox *mbox = (struct mbox *) dev->platform_data; + struct platform_device *pdev = to_platform_device(dev); + struct mbox *mbox = platform_get_drvdata(pdev); strncpy((char *) &int_buf, buf, sizeof(int_buf)); token = (char *) &int_buf; @@ -158,7 +160,8 @@ static ssize_t mbox_read_fifo(struct device *dev, char *buf) { int mbox_value; - struct mbox *mbox = (struct mbox *) dev->platform_data; + struct platform_device *pdev = to_platform_device(dev); + struct mbox *mbox = platform_get_drvdata(pdev); if ((readl(mbox->virtbase_local + MBOX_FIFO_STATUS) & 0x7) <= 0) return sprintf(buf, "Mailbox is empty\n"); @@ -515,24 +518,18 @@ EXPORT_SYMBOL(mbox_setup); int __init mbox_probe(struct platform_device *pdev) { - struct mbox local_mbox; struct mbox *mbox; int res = 0; dev_dbg(&(pdev->dev), "Probing mailbox (pdev = 0x%X)...\n", (u32) pdev); - memset(&local_mbox, 0x0, sizeof(struct mbox)); - - /* Associate our mbox data with the platform device */ - res = platform_device_add_data(pdev, - (void *) &local_mbox, - sizeof(struct mbox)); - if (res != 0) { - dev_err(&(pdev->dev), - "Unable to allocate driver platform data!\n"); - goto exit; + mbox = kzalloc(sizeof(struct mbox), GFP_KERNEL); + if (mbox == NULL) { + dev_err(&pdev->dev, + "Could not allocate memory for struct mbox\n"); + return -ENOMEM; } - mbox = (struct mbox *) pdev->dev.platform_data; + mbox->pdev = pdev; mbox->write_index = 0; mbox->read_index = 0; @@ -543,13 +540,23 @@ int __init mbox_probe(struct platform_device *pdev) sprintf(mbox->name, "%s", MBOX_NAME); spin_lock_init(&mbox->lock); + platform_set_drvdata(pdev, mbox); dev_info(&(pdev->dev), "Mailbox driver loaded\n"); -exit: return res; } +static int __exit mbox_remove(struct platform_device *pdev) +{ + struct mbox *mbox = platform_get_drvdata(pdev); + + list_del(&mbox->list); + kfree(mbox); + return 0; +} + static struct platform_driver mbox_driver = { + .remove = __exit_p(mbox_remove), .driver = { .name = MBOX_NAME, .owner = THIS_MODULE, |