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 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
)
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
->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
);
106 dev_err(&pdev
->dev
, "registering %s failed (err=%d)\n",
111 dev_info(&pdev
->dev
, "%s device registered (reg_base=%p, irq=%d)\n",
112 DRV_NAME
, priv
->reg_base
, 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 sja1000_priv
*priv
= netdev_priv(dev
);
129 struct resource
*res
;
131 unregister_sja1000dev(dev
);
132 dev_set_drvdata(&pdev
->dev
, NULL
);
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
);
145 static struct platform_driver sp_driver
= {
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
);