0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020 #include <linux/module.h>
0021 #include <linux/netdevice.h>
0022 #include <linux/of.h>
0023 #include <linux/platform_device.h>
0024 #include <linux/pm_runtime.h>
0025
0026 #include "ctucanfd.h"
0027
0028 #define DRV_NAME "ctucanfd"
0029
0030 static void ctucan_platform_set_drvdata(struct device *dev,
0031 struct net_device *ndev)
0032 {
0033 struct platform_device *pdev = container_of(dev, struct platform_device,
0034 dev);
0035
0036 platform_set_drvdata(pdev, ndev);
0037 }
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
0048 static int ctucan_platform_probe(struct platform_device *pdev)
0049 {
0050 struct resource *res;
0051 struct device *dev = &pdev->dev;
0052 void __iomem *addr;
0053 int ret;
0054 unsigned int ntxbufs;
0055 int irq;
0056
0057
0058 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
0059 addr = devm_ioremap_resource(dev, res);
0060 if (IS_ERR(addr)) {
0061 dev_err(dev, "Cannot remap address.\n");
0062 ret = PTR_ERR(addr);
0063 goto err;
0064 }
0065 irq = platform_get_irq(pdev, 0);
0066 if (irq < 0) {
0067 ret = irq;
0068 goto err;
0069 }
0070
0071
0072
0073
0074 ntxbufs = 4;
0075 ret = ctucan_probe_common(dev, addr, irq, ntxbufs, 0,
0076 1, ctucan_platform_set_drvdata);
0077
0078 if (ret < 0)
0079 platform_set_drvdata(pdev, NULL);
0080
0081 err:
0082 return ret;
0083 }
0084
0085
0086
0087
0088
0089
0090
0091
0092 static int ctucan_platform_remove(struct platform_device *pdev)
0093 {
0094 struct net_device *ndev = platform_get_drvdata(pdev);
0095 struct ctucan_priv *priv = netdev_priv(ndev);
0096
0097 netdev_dbg(ndev, "ctucan_remove");
0098
0099 unregister_candev(ndev);
0100 pm_runtime_disable(&pdev->dev);
0101 netif_napi_del(&priv->napi);
0102 free_candev(ndev);
0103
0104 return 0;
0105 }
0106
0107 static SIMPLE_DEV_PM_OPS(ctucan_platform_pm_ops, ctucan_suspend, ctucan_resume);
0108
0109
0110 static const struct of_device_id ctucan_of_match[] = {
0111 { .compatible = "ctu,ctucanfd-2", },
0112 { .compatible = "ctu,ctucanfd", },
0113 { },
0114 };
0115 MODULE_DEVICE_TABLE(of, ctucan_of_match);
0116
0117 static struct platform_driver ctucanfd_driver = {
0118 .probe = ctucan_platform_probe,
0119 .remove = ctucan_platform_remove,
0120 .driver = {
0121 .name = DRV_NAME,
0122 .pm = &ctucan_platform_pm_ops,
0123 .of_match_table = ctucan_of_match,
0124 },
0125 };
0126
0127 module_platform_driver(ctucanfd_driver);
0128
0129 MODULE_LICENSE("GPL");
0130 MODULE_AUTHOR("Martin Jerabek");
0131 MODULE_DESCRIPTION("CTU CAN FD for platform");