summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoralf Trønnes <noralf@tronnes.org>2015-04-30 23:33:43 +0200
committerpopcornmix <popcornmix@gmail.com>2015-05-18 14:13:07 +0100
commit9a65fa46d15cb9ea653af6c8dd14831a47cfbc8a (patch)
treed57950a2fe6a304174dcae51cc009d0c26467d3e
parent28d0e06ef3f53a3b0db2da3de428431e49043ba4 (diff)
downloadlinux-9a65fa46d15cb9ea653af6c8dd14831a47cfbc8a.tar.gz
BCM2708: vcio: Use device resources
Use device resources instead of hardcoding them. Use devm_* functions where possible. Merge dev_mbox_register() with probe function. Add Device Tree support. Signed-off-by: Noralf Trønnes <noralf@tronnes.org>
-rw-r--r--arch/arm/mach-bcm2708/vcio.c122
1 files changed, 61 insertions, 61 deletions
diff --git a/arch/arm/mach-bcm2708/vcio.c b/arch/arm/mach-bcm2708/vcio.c
index ff50ebdc795d..c4c2bcdb4bba 100644
--- a/arch/arm/mach-bcm2708/vcio.c
+++ b/arch/arm/mach-bcm2708/vcio.c
@@ -21,13 +21,10 @@
#include <linux/interrupt.h>
#include <linux/io.h>
#include <linux/ioctl.h>
-#include <linux/irq.h>
#include <linux/platform_device.h>
-#include <linux/slab.h>
#include <linux/uaccess.h>
#include <mach/vcio.h>
-#include <mach/platform.h>
#define DRIVER_NAME "bcm2708_vcio"
#define DEVICE_FILE_NAME "vcio"
@@ -60,13 +57,10 @@ struct vc_mailbox {
uint32_t magic;
};
-static void mbox_init(struct vc_mailbox *mbox_out, struct device *dev,
- uint32_t addr_mbox)
+static void mbox_init(struct vc_mailbox *mbox_out)
{
int i;
- mbox_out->regs = __io_address(addr_mbox);
-
for (i = 0; i < MBOX_CHAN_COUNT; i++) {
mbox_out->msg[i] = 0;
sema_init(&mbox_out->sema[i], 0);
@@ -104,7 +98,7 @@ static int mbox_read(struct vc_mailbox *mbox, unsigned chan, uint32_t *data28)
return 0;
}
-static irqreturn_t mbox_irq(int irq, void *dev_id)
+static irqreturn_t mbox_irq_handler(int irq, void *dev_id)
{
/* wait for the mailbox FIFO to have some data in it */
struct vc_mailbox *mbox = (struct vc_mailbox *)dev_id;
@@ -134,12 +128,6 @@ static irqreturn_t mbox_irq(int irq, void *dev_id)
return ret;
}
-static struct irqaction mbox_irqaction = {
- .name = "ARM Mailbox IRQ",
- .flags = IRQF_DISABLED | IRQF_IRQPOLL,
- .handler = mbox_irq,
-};
-
/* Mailbox Methods */
static struct device *mbox_dev; /* we assume there's only one! */
@@ -186,11 +174,6 @@ extern int bcm_mailbox_read(unsigned chan, uint32_t *data28)
}
EXPORT_SYMBOL_GPL(bcm_mailbox_read);
-static void dev_mbox_register(const char *dev_name, struct device *dev)
-{
- mbox_dev = dev;
-}
-
static int mbox_copy_from_user(void *dst, const void *src, int size)
{
if ((uint32_t)src < TASK_SIZE)
@@ -329,61 +312,71 @@ const struct file_operations fops = {
static int bcm_vcio_probe(struct platform_device *pdev)
{
- int ret = 0;
+ struct device *dev = &pdev->dev;
+ struct device *vdev;
struct vc_mailbox *mailbox;
+ struct resource *res;
+ int irq, ret;
+
+ mailbox = devm_kzalloc(dev, sizeof(*mailbox), GFP_KERNEL);
+ if (!mailbox)
+ return -ENOMEM;
+
+ res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+ mailbox->regs = devm_ioremap_resource(dev, res);
+ if (IS_ERR(mailbox->regs))
+ return PTR_ERR(mailbox->regs);
+
+ irq = platform_get_irq(pdev, 0);
+ ret = devm_request_irq(dev, irq, mbox_irq_handler,
+ IRQF_DISABLED | IRQF_IRQPOLL,
+ dev_name(dev), mailbox);
+ if (ret) {
+ dev_err(dev, "Interrupt request failed %d\n", ret);
+ return ret;
+ }
- mailbox = kzalloc(sizeof(*mailbox), GFP_KERNEL);
- if (!mailbox) {
- ret = -ENOMEM;
- } else {
- struct resource *res;
-
- res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
- if (!res) {
- pr_err(DRIVER_NAME
- ": failed to obtain memory resource\n");
- ret = -ENODEV;
- kfree(mailbox);
- } else {
- /* should be based on the registers from res really */
- mbox_init(mailbox, &pdev->dev, ARM_0_MAIL0_RD);
-
- platform_set_drvdata(pdev, mailbox);
- dev_mbox_register(DRIVER_NAME, &pdev->dev);
+ ret = register_chrdev(MAJOR_NUM, DEVICE_FILE_NAME, &fops);
+ if (ret < 0) {
+ pr_err("Character device registration failed %d\n", ret);
+ return ret;
+ }
- mbox_irqaction.dev_id = mailbox;
- setup_irq(IRQ_ARM_MAILBOX, &mbox_irqaction);
- dev_info(&pdev->dev, "mailbox at %p\n",
- __io_address(ARM_0_MAIL0_RD));
- }
+ vcio_class = class_create(THIS_MODULE, DRIVER_NAME);
+ if (IS_ERR(vcio_class)) {
+ ret = PTR_ERR(vcio_class);
+ pr_err("Class creation failed %d\n", ret);
+ goto err_class;
}
- if (ret == 0) {
- ret = register_chrdev(MAJOR_NUM, DEVICE_FILE_NAME, &fops);
- if (ret < 0) {
- pr_err(DRIVER_NAME
- "Failed registering the character device %d\n",
- ret);
- return ret;
- }
- vcio_class = class_create(THIS_MODULE, DRIVER_NAME);
- if (IS_ERR(vcio_class)) {
- ret = PTR_ERR(vcio_class);
- return ret;
- }
- device_create(vcio_class, NULL, MKDEV(MAJOR_NUM, 0), NULL,
- "vcio");
+ vdev = device_create(vcio_class, NULL, MKDEV(MAJOR_NUM, 0), NULL,
+ "vcio");
+ if (IS_ERR(vdev)) {
+ ret = PTR_ERR(vdev);
+ pr_err("Device creation failed %d\n", ret);
+ goto err_dev;
}
+
+ mbox_init(mailbox);
+ platform_set_drvdata(pdev, mailbox);
+ mbox_dev = dev;
+
+ dev_info(dev, "mailbox at %p\n", mailbox->regs);
+
+ return 0;
+
+err_dev:
+ class_destroy(vcio_class);
+err_class:
+ unregister_chrdev(MAJOR_NUM, DEVICE_FILE_NAME);
+
return ret;
}
static int bcm_vcio_remove(struct platform_device *pdev)
{
- struct vc_mailbox *mailbox = platform_get_drvdata(pdev);
-
mbox_dev = NULL;
platform_set_drvdata(pdev, NULL);
- kfree(mailbox);
device_destroy(vcio_class, MKDEV(MAJOR_NUM, 0));
class_destroy(vcio_class);
unregister_chrdev(MAJOR_NUM, DEVICE_FILE_NAME);
@@ -391,6 +384,12 @@ static int bcm_vcio_remove(struct platform_device *pdev)
return 0;
}
+static const struct of_device_id bcm_vcio_of_match_table[] = {
+ { .compatible = "brcm,bcm2708-vcio", },
+ {},
+};
+MODULE_DEVICE_TABLE(of, bcm_vcio_of_match_table);
+
static struct platform_driver bcm_mbox_driver = {
.probe = bcm_vcio_probe,
.remove = bcm_vcio_remove,
@@ -398,6 +397,7 @@ static struct platform_driver bcm_mbox_driver = {
.driver = {
.name = DRIVER_NAME,
.owner = THIS_MODULE,
+ .of_match_table = bcm_vcio_of_match_table,
},
};