blob: 438f002b979b8899145bcead617454a3f4c94482 [file] [log] [blame]
Pratibhasagar V52fa2822013-11-06 12:16:28 +05301/* Copyright (c) 2013, The Linux Foundation. All rights reserved.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 */
12
13#define pr_fmt(fmt) "%s: " fmt, __func__
14
15#include <linux/uio_driver.h>
16#include <linux/module.h>
17#include <linux/platform_device.h>
18#include <linux/err.h>
19
20#define DRIVER_NAME "msm_sharedmem"
21
22static int msm_sharedmem_probe(struct platform_device *pdev)
23{
24 int ret = 0;
25 struct uio_info *info = NULL;
26 struct resource *clnt_res = NULL;
27
28 /* Get the addresses from platform-data */
29 if (!pdev->dev.of_node) {
30 pr_err("Node not found\n");
31 ret = -ENODEV;
32 goto out;
33 }
34 clnt_res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
35 if (!clnt_res) {
36 pr_err("resource not found\n");
37 return -ENODEV;
38 }
39
40 info = devm_kzalloc(&pdev->dev, sizeof(struct uio_info), GFP_KERNEL);
41 if (!info)
42 return -ENOMEM;
43
44 info->name = clnt_res->name;
45 info->version = "1.0";
46 info->mem[0].addr = clnt_res->start;
47 info->mem[0].size = resource_size(clnt_res);
48 info->mem[0].memtype = UIO_MEM_PHYS;
49
50 /* Setup device */
51 ret = uio_register_device(&pdev->dev, info);
52 if (ret)
53 goto out;
54
55 dev_set_drvdata(&pdev->dev, info);
56 pr_debug("Device created for client '%s'\n", clnt_res->name);
57out:
58 return ret;
59}
60
61static int msm_sharedmem_remove(struct platform_device *pdev)
62{
63 struct uio_info *info = dev_get_drvdata(&pdev->dev);
64
65 uio_unregister_device(info);
66
67 return 0;
68}
69
70static struct of_device_id msm_sharedmem_of_match[] = {
71 {.compatible = "qcom,sharedmem-uio",},
72 {},
73};
74MODULE_DEVICE_TABLE(of, msm_sharedmem_of_match);
75
76static struct platform_driver msm_sharedmem_driver = {
77 .probe = msm_sharedmem_probe,
78 .remove = msm_sharedmem_remove,
79 .driver = {
80 .name = DRIVER_NAME,
81 .owner = THIS_MODULE,
82 .of_match_table = msm_sharedmem_of_match,
83 },
84};
85
86module_platform_driver(msm_sharedmem_driver);
87MODULE_LICENSE("GPL v2");