2 * iomem.c - linear register access CAN hardware abstraction layer
6 * Inspired by the OCAN driver http://ar.linux.it/software/#ocan
8 * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions, the following disclaimer and
16 * the referenced file 'COPYING'.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. Neither the name of Volkswagen nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * Alternatively, provided that this notice is retained in full, this
25 * software may be distributed under the terms of the GNU General
26 * Public License ("GPL") version 2 as distributed in the 'COPYING'
27 * file from the main directory of the linux kernel source.
29 * The provided data structures and external interfaces from this code
30 * are not restricted to be used by modules with a GPL compatible license.
32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
35 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
37 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
38 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
39 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
40 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
41 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
42 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
45 * Send feedback to <socketcan-users@lists.berlios.de>
49 #include <linux/netdevice.h>
50 #include <linux/ioport.h>
54 /* init the HAL - call at driver module init */
55 int hal_init(void) { return 0; }
57 /* exit the HAL - call at driver module exit */
58 int hal_exit(void) { return 0; }
60 /* get name of this CAN HAL */
61 char *hal_name(void) { return "iomem"; }
63 /* fill arrays base[] and irq[] with HAL specific defaults */
64 void hal_use_defaults(void)
66 extern unsigned long base[];
67 extern unsigned int irq[];
76 /* request controller register access space */
77 int hal_request_region(int dev_num,
78 unsigned int num_regs,
81 extern unsigned long base[];
82 extern unsigned long rbase[];
84 /* creating the region for IOMEM is pretty easy */
85 if (!request_mem_region(base[dev_num], num_regs, drv_name))
86 return 0; /* failed */
88 /* set device base_addr */
89 rbase[dev_num] = (unsigned long)ioremap(base[dev_num], num_regs);
92 return 1; /* success */
94 /* cleanup due to failed ioremap() */
95 release_mem_region(base[dev_num], num_regs);
96 return 0; /* failed */
99 /* release controller register access space */
100 void hal_release_region(int dev_num,
101 unsigned int num_regs)
103 extern unsigned long base[];
104 extern unsigned long rbase[];
106 iounmap((void *)rbase[dev_num]);
107 release_mem_region(base[dev_num], num_regs);
110 /* enable non controller hardware (e.g. irq routing, etc.) */
111 int hw_attach(int dev_num) { return 0; }
113 /* disable non controller hardware (e.g. irq routing, etc.) */
114 int hw_detach(int dev_num) { return 0; }
116 /* reset controller hardware (with specific non controller hardware) */
117 int hw_reset_dev(int dev_num) { return 0; }
119 /* read from controller register */
120 u8 hw_readreg(unsigned long base, int reg) {
123 void __iomem *addr = (void __iomem *)base + reg;
125 val = (u8)readb(addr);
131 /* write to controller register */
132 void hw_writereg(unsigned long base, int reg, u8 val) {
134 void __iomem *addr = (void __iomem *)base + reg;
140 /* hardware specific work to do at start of irq handler */
141 void hw_preirq(struct net_device *dev) { return; }
143 /* hardware specific work to do at end of irq handler */
144 void hw_postirq(struct net_device *dev) { return; }