]> rtime.felk.cvut.cz Git - socketcan-devel.git/blob - kernel/2.6/drivers/net/can/hal/iomem.c
Moved the work from branches/ha/candrv to trunk.
[socketcan-devel.git] / kernel / 2.6 / drivers / net / can / hal / iomem.c
1 /*
2  * iomem.c - linear register access CAN hardware abstraction layer
3  *
4  * $Id$
5  *
6  * Inspired by the OCAN driver http://ar.linux.it/software/#ocan
7  *
8  * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
9  * All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
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.
23  *
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.
28  *
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.
31  *
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
43  * DAMAGE.
44  *
45  * Send feedback to <socketcan-users@lists.berlios.de>
46  *
47  */
48
49 #include <linux/netdevice.h>
50 #include <linux/ioport.h>
51 #include <asm/io.h>
52 #include "hal.h"
53
54 /* init the HAL - call at driver module init */
55 int hal_init(void) { return 0; }
56
57 /* exit the HAL - call at driver module exit */
58 int hal_exit(void) { return 0; }
59
60 /* get name of this CAN HAL */
61 char *hal_name(void) { return "iomem"; }
62
63 /* fill arrays base[] and irq[] with HAL specific defaults */
64 void hal_use_defaults(void)
65 {
66         extern unsigned long base[];
67         extern unsigned int  irq[];
68
69         base[0]         = 0xd8000UL;
70         irq[0]          = 5;
71
72         base[1]         = 0xd8100UL;
73         irq[1]          = 15;
74 }
75
76 /* request controller register access space */
77 int hal_request_region(int dev_num,
78                        unsigned int num_regs,
79                        char *drv_name)
80 {
81         extern unsigned long base[];
82         extern unsigned long rbase[];
83
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 */
87
88         /* set device base_addr */
89         rbase[dev_num] = (unsigned long)ioremap(base[dev_num], num_regs);
90
91         if (rbase[dev_num])
92                 return 1; /* success */
93
94         /* cleanup due to failed ioremap() */
95         release_mem_region(base[dev_num], num_regs);
96         return 0; /* failed */
97 }
98
99 /* release controller register access space */
100 void hal_release_region(int dev_num,
101                         unsigned int num_regs)
102 {
103         extern unsigned long base[];
104         extern unsigned long rbase[];
105
106         iounmap((void *)rbase[dev_num]);
107         release_mem_region(base[dev_num], num_regs);
108 }
109
110 /* enable non controller hardware (e.g. irq routing, etc.) */
111 int hw_attach(int dev_num) { return 0; }
112
113 /* disable non controller hardware (e.g. irq routing, etc.) */
114 int hw_detach(int dev_num) { return 0; }
115
116 /* reset controller hardware (with specific non controller hardware) */
117 int hw_reset_dev(int dev_num) { return 0; }
118
119 /* read from controller register */
120 u8 hw_readreg(unsigned long base, int reg) {
121
122         static u8 val;
123         void __iomem *addr = (void __iomem *)base + reg;
124
125         val = (u8)readb(addr);
126         rmb();
127
128         return val;
129 }
130
131 /* write to controller register */
132 void hw_writereg(unsigned long base, int reg, u8 val) {
133
134         void __iomem *addr = (void __iomem *)base + reg;
135
136         writeb(val, addr);
137         wmb();
138 }
139
140 /* hardware specific work to do at start of irq handler */
141 void hw_preirq(struct net_device *dev) { return; }
142
143 /* hardware specific work to do at end of irq handler */
144 void hw_postirq(struct net_device *dev) { return; }
145