Skip to content

Commit e8f0c23

Browse files
ppisamarckleinebudde
authored andcommitted
can: ctucanfd: CTU CAN FD open-source IP core - platform/SoC support.
Platform bus adaptation for CTU CAN FD open-source IP core. The core has been tested together with OpenCores SJA1000 modified to be CAN FD frames tolerant on MicroZed Zynq based MZ_APO education kits designed by Petr Porazil from PiKRON.com company. FPGA design https://gitlab.fel.cvut.cz/canbus/zynq/zynq-can-sja1000-top. The kit description at the Computer Architectures course pages https://cw.fel.cvut.cz/wiki/courses/b35apo/documentation/mz_apo/start . Kit carrier board and mechanics design source files https://gitlab.com/pikron/projects/mz_apo/microzed_apo The work is documented in Martin Jeřábek's diploma theses Open-source and Open-hardware CAN FD Protocol Support https://dspace.cvut.cz/handle/10467/80366 . Link: https://lore.kernel.org/all/4d5c53499bafe7717815f948801bd5aedaa05c12.1647904780.git.pisa@cmp.felk.cvut.cz Signed-off-by: Pavel Pisa <[email protected]> Signed-off-by: Martin Jerabek <[email protected]> Signed-off-by: Ondrej Ille <[email protected]> Signed-off-by: Marc Kleine-Budde <[email protected]>
1 parent 792a5b6 commit e8f0c23

File tree

3 files changed

+145
-0
lines changed

3 files changed

+145
-0
lines changed

drivers/net/can/ctucanfd/Kconfig

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,15 @@ config CAN_CTUCANFD_PCI
2020
The project providing FPGA design for Intel EP4CGX15 based DB4CGX15
2121
PCIe board with PiKRON.com designed transceiver riser shield is available
2222
at https://gitlab.fel.cvut.cz/canbus/pcie-ctucanfd .
23+
24+
config CAN_CTUCANFD_PLATFORM
25+
tristate "CTU CAN-FD IP core platform (FPGA, SoC) driver"
26+
depends on CAN_CTUCANFD
27+
depends on OF || COMPILE_TEST
28+
help
29+
The core has been tested together with OpenCores SJA1000
30+
modified to be CAN FD frames tolerant on MicroZed Zynq based
31+
MZ_APO education kits designed by Petr Porazil from PiKRON.com
32+
company. FPGA design https://gitlab.fel.cvut.cz/canbus/zynq/zynq-can-sja1000-top.
33+
The kit description at the Computer Architectures course pages
34+
https://cw.fel.cvut.cz/wiki/courses/b35apo/documentation/mz_apo/start .

drivers/net/can/ctucanfd/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ obj-$(CONFIG_CAN_CTUCANFD) := ctucanfd.o
77
ctucanfd-y := ctucanfd_base.o
88

99
obj-$(CONFIG_CAN_CTUCANFD_PCI) += ctucanfd_pci.o
10+
obj-$(CONFIG_CAN_CTUCANFD_PLATFORM) += ctucanfd_platform.o
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
// SPDX-License-Identifier: GPL-2.0-or-later
2+
/*******************************************************************************
3+
*
4+
* CTU CAN FD IP Core
5+
*
6+
* Copyright (C) 2015-2018 Ondrej Ille <[email protected]> FEE CTU
7+
* Copyright (C) 2018-2021 Ondrej Ille <[email protected]> self-funded
8+
* Copyright (C) 2018-2019 Martin Jerabek <[email protected]> FEE CTU
9+
* Copyright (C) 2018-2022 Pavel Pisa <[email protected]> FEE CTU/self-funded
10+
*
11+
* Project advisors:
12+
* Jiri Novak <[email protected]>
13+
* Pavel Pisa <[email protected]>
14+
*
15+
* Department of Measurement (http://meas.fel.cvut.cz/)
16+
* Faculty of Electrical Engineering (http://www.fel.cvut.cz)
17+
* Czech Technical University (http://www.cvut.cz/)
18+
******************************************************************************/
19+
20+
#include <linux/module.h>
21+
#include <linux/netdevice.h>
22+
#include <linux/of.h>
23+
#include <linux/platform_device.h>
24+
#include <linux/pm_runtime.h>
25+
26+
#include "ctucanfd.h"
27+
28+
#define DRV_NAME "ctucanfd"
29+
30+
static void ctucan_platform_set_drvdata(struct device *dev,
31+
struct net_device *ndev)
32+
{
33+
struct platform_device *pdev = container_of(dev, struct platform_device,
34+
dev);
35+
36+
platform_set_drvdata(pdev, ndev);
37+
}
38+
39+
/**
40+
* ctucan_platform_probe - Platform registration call
41+
* @pdev: Handle to the platform device structure
42+
*
43+
* This function does all the memory allocation and registration for the CAN
44+
* device.
45+
*
46+
* Return: 0 on success and failure value on error
47+
*/
48+
static int ctucan_platform_probe(struct platform_device *pdev)
49+
{
50+
struct resource *res; /* IO mem resources */
51+
struct device *dev = &pdev->dev;
52+
void __iomem *addr;
53+
int ret;
54+
unsigned int ntxbufs;
55+
int irq;
56+
57+
/* Get the virtual base address for the device */
58+
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
59+
addr = devm_ioremap_resource(dev, res);
60+
if (IS_ERR(addr)) {
61+
dev_err(dev, "Cannot remap address.\n");
62+
ret = PTR_ERR(addr);
63+
goto err;
64+
}
65+
irq = platform_get_irq(pdev, 0);
66+
if (irq < 0) {
67+
dev_err(dev, "Cannot find interrupt.\n");
68+
ret = irq;
69+
goto err;
70+
}
71+
72+
/* Number of tx bufs might be change in HW for future. If so,
73+
* it will be passed as property via device tree
74+
*/
75+
ntxbufs = 4;
76+
ret = ctucan_probe_common(dev, addr, irq, ntxbufs, 0,
77+
1, ctucan_platform_set_drvdata);
78+
79+
if (ret < 0)
80+
platform_set_drvdata(pdev, NULL);
81+
82+
err:
83+
return ret;
84+
}
85+
86+
/**
87+
* ctucan_platform_remove - Unregister the device after releasing the resources
88+
* @pdev: Handle to the platform device structure
89+
*
90+
* This function frees all the resources allocated to the device.
91+
* Return: 0 always
92+
*/
93+
static int ctucan_platform_remove(struct platform_device *pdev)
94+
{
95+
struct net_device *ndev = platform_get_drvdata(pdev);
96+
struct ctucan_priv *priv = netdev_priv(ndev);
97+
98+
netdev_dbg(ndev, "ctucan_remove");
99+
100+
unregister_candev(ndev);
101+
pm_runtime_disable(&pdev->dev);
102+
netif_napi_del(&priv->napi);
103+
free_candev(ndev);
104+
105+
return 0;
106+
}
107+
108+
static SIMPLE_DEV_PM_OPS(ctucan_platform_pm_ops, ctucan_suspend, ctucan_resume);
109+
110+
/* Match table for OF platform binding */
111+
static const struct of_device_id ctucan_of_match[] = {
112+
{ .compatible = "ctu,ctucanfd-2", },
113+
{ .compatible = "ctu,ctucanfd", },
114+
{ /* end of list */ },
115+
};
116+
MODULE_DEVICE_TABLE(of, ctucan_of_match);
117+
118+
static struct platform_driver ctucanfd_driver = {
119+
.probe = ctucan_platform_probe,
120+
.remove = ctucan_platform_remove,
121+
.driver = {
122+
.name = DRV_NAME,
123+
.pm = &ctucan_platform_pm_ops,
124+
.of_match_table = ctucan_of_match,
125+
},
126+
};
127+
128+
module_platform_driver(ctucanfd_driver);
129+
130+
MODULE_LICENSE("GPL");
131+
MODULE_AUTHOR("Martin Jerabek");
132+
MODULE_DESCRIPTION("CTU CAN FD for platform");

0 commit comments

Comments
 (0)