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>
14 #include <linux/module.h>
15 #include <linux/slab.h>
17 #define DRIVER_NAME "uio_pdrv"
20 struct uio_info
*uioinfo
;
23 static int uio_pdrv_probe(struct platform_device
*pdev
)
25 struct uio_info
*uioinfo
= pdev
->dev
.platform_data
;
26 struct uio_platdata
*pdata
;
27 struct uio_mem
*uiomem
;
31 if (!uioinfo
|| !uioinfo
->name
|| !uioinfo
->version
) {
32 dev_dbg(&pdev
->dev
, "%s: err_uioinfo\n", __func__
);
36 pdata
= kzalloc(sizeof(*pdata
), GFP_KERNEL
);
39 dev_dbg(&pdev
->dev
, "%s: err_alloc_pdata\n", __func__
);
43 pdata
->uioinfo
= uioinfo
;
45 uiomem
= &uioinfo
->mem
[0];
47 for (i
= 0; i
< pdev
->num_resources
; ++i
) {
48 struct resource
*r
= &pdev
->resource
[i
];
50 if (r
->flags
!= IORESOURCE_MEM
)
53 if (uiomem
>= &uioinfo
->mem
[MAX_UIO_MAPS
]) {
54 dev_warn(&pdev
->dev
, "device has more than "
55 __stringify(MAX_UIO_MAPS
)
56 " I/O memory resources.\n");
60 uiomem
->memtype
= UIO_MEM_PHYS
;
61 uiomem
->addr
= r
->start
;
62 uiomem
->size
= resource_size(r
);
66 while (uiomem
< &uioinfo
->mem
[MAX_UIO_MAPS
]) {
71 pdata
->uioinfo
->priv
= pdata
;
73 ret
= uio_register_device(&pdev
->dev
, pdata
->uioinfo
);
82 platform_set_drvdata(pdev
, pdata
);
87 static int uio_pdrv_remove(struct platform_device
*pdev
)
89 struct uio_platdata
*pdata
= platform_get_drvdata(pdev
);
91 uio_unregister_device(pdata
->uioinfo
);
98 static struct platform_driver uio_pdrv
= {
99 .probe
= uio_pdrv_probe
,
100 .remove
= uio_pdrv_remove
,
103 .owner
= THIS_MODULE
,
107 static int __init
uio_pdrv_init(void)
109 return platform_driver_register(&uio_pdrv
);
112 static void __exit
uio_pdrv_exit(void)
114 platform_driver_unregister(&uio_pdrv
);
116 module_init(uio_pdrv_init
);
117 module_exit(uio_pdrv_exit
);
119 MODULE_AUTHOR("Uwe Kleine-Koenig");
120 MODULE_DESCRIPTION("Userspace I/O platform driver");
121 MODULE_LICENSE("GPL v2");
122 MODULE_ALIAS("platform:" DRIVER_NAME
);