2 * drivers/uio/uio_pdrv.c
4 * Copyright (C) 2008 by Digi International Inc.
7 * This program is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License version 2 as published by
9 * the Free Software Foundation.
11 #include <linux/platform_device.h>
12 #include <linux/uio_driver.h>
13 #include <linux/stringify.h>
15 #define DRIVER_NAME "uio"
18 struct uio_info *uioinfo;
21 static int uio_pdrv_probe(struct platform_device *pdev)
23 struct uio_info *uioinfo = pdev->dev.platform_data;
24 struct uio_platdata *pdata;
25 struct uio_mem *uiomem;
29 if (!uioinfo || !uioinfo->name || !uioinfo->version) {
30 dev_dbg(&pdev->dev, "%s: err_uioinfo\n", __func__);
34 pdata = kzalloc(sizeof(*pdata), GFP_KERNEL);
37 dev_dbg(&pdev->dev, "%s: err_alloc_pdata\n", __func__);
41 pdata->uioinfo = uioinfo;
43 uiomem = &uioinfo->mem[0];
45 for (i = 0; i < pdev->num_resources; ++i) {
46 struct resource *r = &pdev->resource[i];
48 if (r->flags != IORESOURCE_MEM)
51 if (uiomem >= &uioinfo->mem[MAX_UIO_MAPS]) {
52 dev_warn(&pdev->dev, "device has more than "
53 __stringify(MAX_UIO_MAPS)
54 " I/O memory resources.\n");
58 uiomem->memtype = UIO_MEM_PHYS;
59 uiomem->addr = r->start;
60 uiomem->size = r->end - r->start + 1;
64 while (uiomem < &uioinfo->mem[MAX_UIO_MAPS]) {
69 pdata->uioinfo->priv = pdata;
71 ret = uio_register_device(&pdev->dev, pdata->uioinfo);
80 platform_set_drvdata(pdev, pdata);
85 static int uio_pdrv_remove(struct platform_device *pdev)
87 struct uio_platdata *pdata = platform_get_drvdata(pdev);
89 uio_unregister_device(pdata->uioinfo);
94 static struct platform_driver uio_pdrv = {
95 .probe = uio_pdrv_probe,
96 .remove = uio_pdrv_remove,
103 static int __init uio_pdrv_init(void)
105 return platform_driver_register(&uio_pdrv);
108 static void __exit uio_pdrv_exit(void)
110 platform_driver_unregister(&uio_pdrv);
112 module_init(uio_pdrv_init);
113 module_exit(uio_pdrv_exit);
115 MODULE_AUTHOR("Uwe Kleine-Koenig");
116 MODULE_DESCRIPTION("Userspace I/O platform driver");
117 MODULE_LICENSE("GPL");
118 MODULE_ALIAS("platform:" DRIVER_NAME);