2 * Copyright (C) 2005 Sascha Hauer, Pengutronix
3 * Copyright (C) 2007 Wolfgang Grandegger <wg@grandegger.com>
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the version 2 of the GNU General Public License
7 * as published by the Free Software Foundation
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 #include <linux/kernel.h>
20 #include <linux/module.h>
21 #include <linux/interrupt.h>
22 #include <linux/netdevice.h>
23 #include <linux/delay.h>
24 #include <linux/pci.h>
25 #include <linux/platform_device.h>
26 #include <linux/irq.h>
27 #include <linux/can.h>
28 #include <linux/can/dev.h>
29 #include <linux/can/platform/sja1000.h>
34 #define DRV_NAME "sja1000_platform"
36 MODULE_AUTHOR("Sascha Hauer <s.hauer@pengutronix.de>");
37 MODULE_DESCRIPTION("Socket-CAN driver for SJA1000 on the platform bus");
38 MODULE_LICENSE("GPL v2");
40 static u8 sp_read_reg(const struct net_device *dev, int reg)
42 return ioread8((void __iomem *)(dev->base_addr + reg));
45 static void sp_write_reg(const struct net_device *dev, int reg, u8 val)
47 iowrite8(val, (void __iomem *)(dev->base_addr + reg));
50 static int sp_probe(struct platform_device *pdev)
54 struct net_device *dev;
55 struct sja1000_priv *priv;
56 struct resource *res_mem, *res_irq;
57 struct sja1000_platform_data *pdata;
59 pdata = pdev->dev.platform_data;
61 dev_err(&pdev->dev, "No platform data provided!\n");
66 res_mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
67 res_irq = platform_get_resource(pdev, IORESOURCE_IRQ, 0);
68 if (!res_mem || !res_irq) {
73 if (!request_mem_region(res_mem->start, resource_size(res_mem),
79 addr = ioremap_nocache(res_mem->start, resource_size(res_mem));
85 dev = alloc_sja1000dev(0);
90 priv = netdev_priv(dev);
92 dev->base_addr = (unsigned long)addr;
93 dev->irq = res_irq->start;
94 priv->irq_flags = res_irq->flags & IRQF_TRIGGER_MASK;
95 priv->read_reg = sp_read_reg;
96 priv->write_reg = sp_write_reg;
97 priv->can.clock.freq = pdata->clock;
98 priv->ocr = pdata->ocr;
99 priv->cdr = pdata->cdr;
101 dev_set_drvdata(&pdev->dev, dev);
102 SET_NETDEV_DEV(dev, &pdev->dev);
104 err = register_sja1000dev(dev);
106 dev_err(&pdev->dev, "registering %s failed (err=%d)\n",
111 dev_info(&pdev->dev, "%s device registered (base_addr=%#lx, irq=%d)\n",
112 DRV_NAME, dev->base_addr, dev->irq);
116 free_sja1000dev(dev);
120 release_mem_region(res_mem->start, resource_size(res_mem));
125 static int sp_remove(struct platform_device *pdev)
127 struct net_device *dev = dev_get_drvdata(&pdev->dev);
128 struct resource *res;
130 unregister_sja1000dev(dev);
131 dev_set_drvdata(&pdev->dev, NULL);
134 iounmap((void __iomem *)dev->base_addr);
136 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
137 release_mem_region(res->start, resource_size(res));
139 free_sja1000dev(dev);
144 static struct platform_driver sp_driver = {
149 .owner = THIS_MODULE,
153 static int __init sp_init(void)
155 return platform_driver_register(&sp_driver);
158 static void __exit sp_exit(void)
160 platform_driver_unregister(&sp_driver);
163 module_init(sp_init);
164 module_exit(sp_exit);