1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*******************************************************************************
6 * Copyright (C) 2015-2018 Ondrej Ille <ondrej.ille@gmail.com> FEE CTU
7 * Copyright (C) 2018-2021 Ondrej Ille <ondrej.ille@gmail.com> self-funded
8 * Copyright (C) 2018-2019 Martin Jerabek <martin.jerabek01@gmail.com> FEE CTU
9 * Copyright (C) 2018-2022 Pavel Pisa <pisa@cmp.felk.cvut.cz> FEE CTU/self-funded
12 * Jiri Novak <jnovak@fel.cvut.cz>
13 * Pavel Pisa <pisa@cmp.felk.cvut.cz>
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 ******************************************************************************/
20 #include <linux/module.h>
21 #include <linux/netdevice.h>
23 #include <linux/platform_device.h>
24 #include <linux/pm_runtime.h>
28 #define DRV_NAME "ctucanfd"
30 static void ctucan_platform_set_drvdata(struct device
*dev
,
31 struct net_device
*ndev
)
33 struct platform_device
*pdev
= container_of(dev
, struct platform_device
,
36 platform_set_drvdata(pdev
, ndev
);
40 * ctucan_platform_probe - Platform registration call
41 * @pdev: Handle to the platform device structure
43 * This function does all the memory allocation and registration for the CAN
46 * Return: 0 on success and failure value on error
48 static int ctucan_platform_probe(struct platform_device
*pdev
)
50 struct device
*dev
= &pdev
->dev
;
56 /* Get the virtual base address for the device */
57 addr
= devm_platform_ioremap_resource(pdev
, 0);
62 irq
= platform_get_irq(pdev
, 0);
68 /* Number of tx bufs might be change in HW for future. If so,
69 * it will be passed as property via device tree
72 ret
= ctucan_probe_common(dev
, addr
, irq
, ntxbufs
, 0,
73 1, ctucan_platform_set_drvdata
);
76 platform_set_drvdata(pdev
, NULL
);
83 * ctucan_platform_remove - Unregister the device after releasing the resources
84 * @pdev: Handle to the platform device structure
86 * This function frees all the resources allocated to the device.
89 static void ctucan_platform_remove(struct platform_device
*pdev
)
91 struct net_device
*ndev
= platform_get_drvdata(pdev
);
92 struct ctucan_priv
*priv
= netdev_priv(ndev
);
94 netdev_dbg(ndev
, "ctucan_remove");
96 unregister_candev(ndev
);
97 pm_runtime_disable(&pdev
->dev
);
98 netif_napi_del(&priv
->napi
);
102 static SIMPLE_DEV_PM_OPS(ctucan_platform_pm_ops
, ctucan_suspend
, ctucan_resume
);
104 /* Match table for OF platform binding */
105 static const struct of_device_id ctucan_of_match
[] = {
106 { .compatible
= "ctu,ctucanfd-2", },
107 { .compatible
= "ctu,ctucanfd", },
108 { /* end of list */ },
110 MODULE_DEVICE_TABLE(of
, ctucan_of_match
);
112 static struct platform_driver ctucanfd_driver
= {
113 .probe
= ctucan_platform_probe
,
114 .remove
= ctucan_platform_remove
,
117 .pm
= &ctucan_platform_pm_ops
,
118 .of_match_table
= ctucan_of_match
,
122 module_platform_driver(ctucanfd_driver
);
124 MODULE_LICENSE("GPL");
125 MODULE_AUTHOR("Martin Jerabek");
126 MODULE_DESCRIPTION("CTU CAN FD for platform");