blob: d1299d48f0b2466edfcfadf500563f408a310ffa [file] [log] [blame]
Ido Shayevitzef72ddd2012-03-28 18:55:55 +02001/* Copyright (c) 2012, Code Aurora Forum. 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
14#include <linux/module.h>
15#include <linux/kernel.h>
16#include <linux/slab.h>
17#include <linux/platform_device.h>
18#include <linux/dma-mapping.h>
19#include <linux/ioport.h>
20#include <linux/io.h>
21#include <linux/module.h>
22#include <linux/types.h>
23#include <linux/usb/msm_hsusb.h>
24#include <linux/delay.h>
25#include <linux/of.h>
26
27#define DBM_MAX_EPS 4
28
29struct dwc3_msm {
30 struct platform_device *dwc3;
31 struct device *dev;
32 void __iomem *base;
33 u32 resource_size;
34 int dbm_num_eps;
35};
36
37static int __devinit dwc3_msm_probe(struct platform_device *pdev)
38{
39 struct device_node *node = pdev->dev.of_node;
40 struct platform_device *dwc3;
41 struct dwc3_msm *msm;
42 struct resource *res;
43 int ret = 0;
44
45 msm = devm_kzalloc(&pdev->dev, sizeof(*msm), GFP_KERNEL);
46 if (!msm) {
47 dev_err(&pdev->dev, "not enough memory\n");
48 return -ENOMEM;
49 }
50
51 platform_set_drvdata(pdev, msm);
52
53 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
54 if (!res) {
55 dev_err(&pdev->dev, "missing memory base resource\n");
56 return -ENODEV;
57 }
58
59 msm->base = devm_ioremap_nocache(&pdev->dev, res->start,
60 resource_size(res));
61 if (!msm->base) {
62 dev_err(&pdev->dev, "ioremap failed\n");
63 return -ENODEV;
64 }
65
66 dwc3 = platform_device_alloc("dwc3-msm", -1);
67 if (!dwc3) {
68 dev_err(&pdev->dev, "couldn't allocate dwc3 device\n");
69 return -ENOMEM;
70 }
71
72 dma_set_coherent_mask(&dwc3->dev, pdev->dev.coherent_dma_mask);
73
74 dwc3->dev.parent = &pdev->dev;
75 dwc3->dev.dma_mask = pdev->dev.dma_mask;
76 dwc3->dev.dma_parms = pdev->dev.dma_parms;
77 msm->resource_size = resource_size(res);
78 msm->dev = &pdev->dev;
79 msm->dwc3 = dwc3;
80
81 if (of_property_read_u32(node, "qcom,dwc-usb3-msm-dbm-eps",
82 &msm->dbm_num_eps)) {
83 dev_err(&pdev->dev,
84 "unable to read platform data num of dbm eps\n");
85 msm->dbm_num_eps = DBM_MAX_EPS;
86 }
87
88 if (msm->dbm_num_eps > DBM_MAX_EPS) {
89 dev_err(&pdev->dev,
90 "Driver doesn't support number of DBM EPs. "
91 "max: %d, dbm_num_eps: %d\n",
92 DBM_MAX_EPS, msm->dbm_num_eps);
93 ret = -ENODEV;
94 goto err1;
95 }
96
97 ret = platform_device_add_resources(dwc3, pdev->resource,
98 pdev->num_resources);
99 if (ret) {
100 dev_err(&pdev->dev, "couldn't add resources to dwc3 device\n");
101 goto err1;
102 }
103
104 ret = platform_device_add(dwc3);
105 if (ret) {
106 dev_err(&pdev->dev, "failed to register dwc3 device\n");
107 goto err1;
108 }
109
110 return 0;
111
112err1:
113 platform_device_put(dwc3);
114
115 return ret;
116}
117
118static int __devexit dwc3_msm_remove(struct platform_device *pdev)
119{
120 struct dwc3_msm *msm = platform_get_drvdata(pdev);
121
122 platform_device_unregister(msm->dwc3);
123
124 return 0;
125}
126
127static const struct of_device_id of_dwc3_matach[] = {
128 {
129 .compatible = "qcom,dwc-usb3-msm",
130 },
131 { },
132};
133MODULE_DEVICE_TABLE(of, of_dwc3_matach);
134
135static struct platform_driver dwc3_msm_driver = {
136 .probe = dwc3_msm_probe,
137 .remove = __devexit_p(dwc3_msm_remove),
138 .driver = {
139 .name = "msm-dwc3",
140 .of_match_table = of_dwc3_matach,
141 },
142};
143
144MODULE_LICENSE("GPLV2");
145MODULE_DESCRIPTION("DesignWare USB3 MSM Glue Layer");
146
147static int __devinit dwc3_msm_init(void)
148{
149 return platform_driver_register(&dwc3_msm_driver);
150}
151module_init(dwc3_msm_init);
152
153static void __exit dwc3_msm_exit(void)
154{
155 platform_driver_unregister(&dwc3_msm_driver);
156}
157module_exit(dwc3_msm_exit);