-
Notifications
You must be signed in to change notification settings - Fork 0
/
edge_platform.c
345 lines (287 loc) · 7.9 KB
/
edge_platform.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
// SPDX-License-Identifier: GPL-2.0
/* TTTech EDGE/DE-IP Linux driver
* Copyright(c) 2018 TTTech Computertechnik AG.
*
* This program is free software; you can redistribute it and/or modify it
* under the terms and conditions of the GNU General Public License,
* version 2, as published by the Free Software Foundation.
*
* This program is distributed in the hope it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program; if not, see <http://www.gnu.org/licenses/>.
*
* The full GNU General Public License is included in this distribution in
* the file called "COPYING".
*
* Contact Information:
* TTTech Computertechnik AG, Schoenbrunnerstrasse 7, 1040 Vienna, Austria
*/
#include <linux/io.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/of_device.h>
#include <linux/slab.h>
#include <linux/interrupt.h>
#include "edge_bridge.h"
#include "edge_mdio.h"
#include "altera_pio.h"
#define PFX "EDGX-PLATFORM: "
static const struct of_device_id flx_pio_dt_ids[] = {
{ .compatible = "flx,pio" },
{ /* sentinel */ },
};
static const struct of_device_id edgx_sw_dt_ids[] = {
{ .compatible = "ttt,deip-sw",
},
{ .compatible = "ttt,es",
},
{ /* sentinel */ },
};
static const struct of_device_id edgx_mdio_dt_ids[] = {
{ .compatible = "flx,eth-mdio",
},
{ /* sentinel */ },
};
static int bridge_id;
static int mdio_id;
static int pio_id;
static int flx_pio_pfm_probe(struct platform_device *pdev);
static int flx_pio_pfm_remove(struct platform_device *pdev);
static int edgx_sw_pfm_probe(struct platform_device *pdev);
static int edgx_sw_pfm_remove(struct platform_device *pdev);
static int edgx_mdio_pfm_probe(struct platform_device *pdev);
static int edgx_mdio_pfm_remove(struct platform_device *pdev);
static struct platform_driver flx_pio_pfm_driver = {
.driver = {
.name = "flx-pio",
.of_match_table = flx_pio_dt_ids,
},
.probe = &flx_pio_pfm_probe,
.remove = &flx_pio_pfm_remove,
};
static struct platform_driver edgx_sw_pfm_driver = {
.driver = {
.name = "edgx-pfm",
.of_match_table = edgx_sw_dt_ids,
},
.probe = edgx_sw_pfm_probe,
.remove = edgx_sw_pfm_remove,
};
struct edgx_sw_pfm_drv {
struct edgx_br *br;
struct edgx_br_irq irq;
};
static struct platform_driver edgx_mdio_pfm_driver = {
.driver = {
.name = "edgx-mdio",
.of_match_table = edgx_mdio_dt_ids,
},
.probe = edgx_mdio_pfm_probe,
.remove = edgx_mdio_pfm_remove,
};
static int edgx_get_mem_res(struct platform_device *pdev, void **base)
{
struct resource *mem;
mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
if (!mem) {
dev_err(&pdev->dev, "No I/O memory defined on dev '%s'\n",
dev_name(&pdev->dev));
return -ENODEV;
}
*base = ioremap_nocache(mem->start, resource_size(mem));
if (!*base) {
dev_err(&pdev->dev,
"I/O remapping failed for dev '%s' 0x%llx/0x%llx\n",
dev_name(&pdev->dev),
(long long unsigned int)mem->start,
(long long unsigned int)resource_size(mem));
return -ENODEV;
}
dev_info(&pdev->dev, "MEM-resource '%s' 0x%llx/0x%llx -> 0x%px\n",
mem->name, (long long unsigned int)mem->start,
(long long unsigned int)resource_size(mem), *base);
return 0;
}
static int flx_pio_pfm_probe(struct platform_device *pdev)
{
int ret;
void *base;
struct flx_pio_dev_priv *pio;
ret = edgx_get_mem_res(pdev, &base);
if (ret)
return ret;
ret = flx_pio_probe_one(pio_id, &pdev->dev, base, &pio);
if (ret) {
iounmap(base);
return ret;
}
dev_set_drvdata(&pdev->dev, pio);
pio_id++;
return 0;
}
static int flx_pio_pfm_remove(struct platform_device *pdev)
{
void *base;
struct flx_pio_dev_priv *pio;
pio = dev_get_drvdata(&pdev->dev);
if (!pio)
return -ENODEV;
base = flx_pio_get_base(pio);
if (!base)
return -ENODEV;
flx_pio_shutdown(pio);
iounmap(base);
dev_info(&pdev->dev, "Removed device '%s'\n",
dev_name(&pdev->dev));
return 0;
}
static int edgx_sw_pfm_get_irq(struct platform_device *pdev,
struct edgx_br_irq *sw_irq)
{
int ret, i;
struct resource *irq;
ret = platform_irq_count(pdev);
if ((ret != 1) && (ret != EDGX_IRQ_CNT)) {
dev_err(&pdev->dev, "Invalid IRQ count = %d!\n", ret);
return -ENODEV;
}
sw_irq->shared = (ret == 1);
for (i = 0; i < ret; i++) {
irq = platform_get_resource(pdev, IORESOURCE_IRQ, i);
if (!irq) {
dev_err(&pdev->dev, "Get IRQ resource %d failed!\n", i);
return ret;
}
sw_irq->irq_vec[i] = irq->start;
if (i == 0) {
if ((irq->flags & IORESOURCE_IRQ_HIGHLEVEL) ||
(irq->flags & IORESOURCE_IRQ_LOWLEVEL))
sw_irq->trig = EDGX_IRQ_LEVEL_TRIG;
else
sw_irq->trig = EDGX_IRQ_EDGE_TRIG;
}
dev_info(&pdev->dev, "IRQ-resource: %pr\n", irq);
}
return 0;
}
static int edgx_sw_pfm_probe(struct platform_device *pdev)
{
int ret;
void *base;
struct edgx_sw_pfm_drv *sw_pfm_drv;
ret = edgx_get_mem_res(pdev, &base);
if (ret)
return ret;
sw_pfm_drv = kzalloc(sizeof(*sw_pfm_drv), GFP_KERNEL);
if (!sw_pfm_drv) {
ret = -ENOMEM;
goto sw_pfm_probe_out_alloc;
}
ret = edgx_sw_pfm_get_irq(pdev, &sw_pfm_drv->irq);
if (ret)
goto sw_pfm_probe_out_irq;
ret = edgx_br_probe_one(bridge_id, &pdev->dev, base, &sw_pfm_drv->irq,
&sw_pfm_drv->br);
if (ret)
goto sw_pfm_probe_out_br_probe;
dev_set_drvdata(&pdev->dev, sw_pfm_drv);
bridge_id++;
return 0;
sw_pfm_probe_out_br_probe:
sw_pfm_probe_out_irq:
kfree(sw_pfm_drv);
sw_pfm_probe_out_alloc:
iounmap(base);
return ret;
}
static int edgx_sw_pfm_remove(struct platform_device *pdev)
{
void *base;
struct edgx_sw_pfm_drv *sw_pfm_drv;
sw_pfm_drv = dev_get_drvdata(&pdev->dev);
if (!sw_pfm_drv)
return -ENODEV;
base = edgx_br_get_base(sw_pfm_drv->br);
if (!base)
return -ENODEV;
edgx_br_shutdown(sw_pfm_drv->br);
iounmap(base);
dev_info(&pdev->dev, "Removed device '%s'\n",
dev_name(&pdev->dev));
return 0;
}
static int edgx_mdio_pfm_probe(struct platform_device *pdev)
{
int ret;
void *base;
struct edgx_mdio *mdio;
ret = edgx_get_mem_res(pdev, &base);
if (ret)
return ret;
ret = edgx_mdio_probe_one(mdio_id, &pdev->dev, base, &mdio);
if (ret) {
iounmap(base);
return ret;
}
dev_set_drvdata(&pdev->dev, mdio);
mdio_id++;
return 0;
}
static int edgx_mdio_pfm_remove(struct platform_device *pdev)
{
void *base;
struct edgx_mdio *mdio;
mdio = dev_get_drvdata(&pdev->dev);
if (!mdio)
return -ENODEV;
base = edgx_mdio_get_base(mdio);
if (!base)
return -ENODEV;
edgx_mdio_shutdown(mdio);
iounmap(base);
dev_info(&pdev->dev, "Removed device '%s'\n",
dev_name(&pdev->dev));
return 0;
}
static int __init edgx_pfm_init(void)
{
int ret;
pr_info(PFX "Registering pio platform device driver\n");
ret = platform_driver_register(&flx_pio_pfm_driver);
if (ret)
return ret;
pr_info(PFX "Registering mdio platform device driver\n");
ret = platform_driver_register(&edgx_mdio_pfm_driver);
if (ret)
goto out_pfm_init_mdio;
pr_info(PFX "Registering switch platform device driver\n");
ret = platform_driver_register(&edgx_sw_pfm_driver);
if (ret)
goto out_pfm_init_sw;
return ret;
out_pfm_init_sw:
platform_driver_unregister(&edgx_mdio_pfm_driver);
out_pfm_init_mdio:
platform_driver_unregister(&flx_pio_pfm_driver);
return ret;
}
static void __exit edgx_pfm_exit(void)
{
pr_info(PFX "Unregistering sw platform device driver\n");
platform_driver_unregister(&edgx_sw_pfm_driver);
pr_info(PFX "Unregistering mdio platform device driver\n");
platform_driver_unregister(&edgx_mdio_pfm_driver);
pr_info(PFX "Unregistering pio platform device driver\n");
platform_driver_unregister(&flx_pio_pfm_driver);
}
module_init(edgx_pfm_init);
module_exit(edgx_pfm_exit);
MODULE_LICENSE("GPL v2");
MODULE_AUTHOR("TTTech Industrial Automation AG <[email protected]>");
MODULE_DESCRIPTION("EDGE Platform Host Interface Driver");
MODULE_VERSION(EDGX_SW_CORE_VERSION);