[ARM] pxa: update defconfig for Verdex Pro
[linux-2.6/verdex.git] / drivers / net / can / sja1000 / sja1000_platform.c
blob628374c2a05f728b7d05f25d016e12ba7312e8c3
1 /*
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>
30 #include <linux/io.h>
32 #include "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 sja1000_priv *priv, int reg)
42 return ioread8(priv->reg_base + reg);
45 static void sp_write_reg(const struct sja1000_priv *priv, int reg, u8 val)
47 iowrite8(val, priv->reg_base + reg);
50 static int sp_probe(struct platform_device *pdev)
52 int err;
53 void __iomem *addr;
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;
60 if (!pdata) {
61 dev_err(&pdev->dev, "No platform data provided!\n");
62 err = -ENODEV;
63 goto exit;
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) {
69 err = -ENODEV;
70 goto exit;
73 if (!request_mem_region(res_mem->start, resource_size(res_mem),
74 DRV_NAME)) {
75 err = -EBUSY;
76 goto exit;
79 addr = ioremap_nocache(res_mem->start, resource_size(res_mem));
80 if (!addr) {
81 err = -ENOMEM;
82 goto exit_release;
85 dev = alloc_sja1000dev(0);
86 if (!dev) {
87 err = -ENOMEM;
88 goto exit_iounmap;
90 priv = netdev_priv(dev);
92 dev->irq = res_irq->start;
93 priv->irq_flags = res_irq->flags & IRQF_TRIGGER_MASK;
94 priv->reg_base = addr;
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);
105 if (err) {
106 dev_err(&pdev->dev, "registering %s failed (err=%d)\n",
107 DRV_NAME, err);
108 goto exit_free;
111 dev_info(&pdev->dev, "%s device registered (reg_base=%p, irq=%d)\n",
112 DRV_NAME, priv->reg_base, dev->irq);
113 return 0;
115 exit_free:
116 free_sja1000dev(dev);
117 exit_iounmap:
118 iounmap(addr);
119 exit_release:
120 release_mem_region(res_mem->start, resource_size(res_mem));
121 exit:
122 return err;
125 static int sp_remove(struct platform_device *pdev)
127 struct net_device *dev = dev_get_drvdata(&pdev->dev);
128 struct sja1000_priv *priv = netdev_priv(dev);
129 struct resource *res;
131 unregister_sja1000dev(dev);
132 dev_set_drvdata(&pdev->dev, NULL);
134 if (priv->reg_base)
135 iounmap(priv->reg_base);
137 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
138 release_mem_region(res->start, resource_size(res));
140 free_sja1000dev(dev);
142 return 0;
145 static struct platform_driver sp_driver = {
146 .probe = sp_probe,
147 .remove = sp_remove,
148 .driver = {
149 .name = DRV_NAME,
150 .owner = THIS_MODULE,
154 static int __init sp_init(void)
156 return platform_driver_register(&sp_driver);
159 static void __exit sp_exit(void)
161 platform_driver_unregister(&sp_driver);
164 module_init(sp_init);
165 module_exit(sp_exit);