]> rtime.felk.cvut.cz Git - lisovros/linux_canprio.git/blob - drivers/net/can/old/hal/iomux.c
Added socketcan from SVN r903
[lisovros/linux_canprio.git] / drivers / net / can / old / hal / iomux.c
1 /*
2  * iomux.c - multiplex 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 and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  * 3. Neither the name of Volkswagen nor the names of its contributors
20  *    may be used to endorse or promote products derived from this software
21  *    without specific prior written permission.
22  *
23  * Alternatively, provided that this notice is retained in full, this
24  * software may be distributed under the terms of the GNU General
25  * Public License ("GPL") version 2, in which case the provisions of the
26  * GPL apply INSTEAD OF those given above.
27  *
28  * The provided data structures and external interfaces from this code
29  * are not restricted to be used by modules with a GPL compatible license.
30  *
31  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
32  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
33  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
34  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
35  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
36  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
37  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
38  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
39  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
40  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
41  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
42  * DAMAGE.
43  *
44  * Send feedback to <socketcan-users@lists.berlios.de>
45  *
46  */
47
48 #include <linux/netdevice.h>
49 #include <linux/ioport.h>
50 #include <asm/io.h>
51 #include "hal.h"
52
53 /* init the HAL - call at driver module init */
54 int hal_init(void) { return 0; }
55
56 /* exit the HAL - call at driver module exit */
57 int hal_exit(void) { return 0; }
58
59 /* get name of this CAN HAL */
60 char *hal_name(void) { return "iomux"; }
61
62 /* fill arrays base[] and irq[] with HAL specific defaults */
63 void hal_use_defaults(void)
64 {
65         extern unsigned long base[];
66         extern unsigned int  irq[];
67
68         base[0]         = 0x300UL;
69         irq[0]          = 5;
70 }
71
72 /* request controller register access space */
73 int hal_request_region(int dev_num,
74                        unsigned int num_regs,
75                        char *drv_name)
76 {
77         extern unsigned long base[];
78         extern unsigned long rbase[];
79
80         /* set for device base_addr */
81         rbase[dev_num] = base[dev_num];
82
83         /* ignore num_regs and create the 2 register region:  */
84         /* address register = base / data register = base + 1 */
85         return (request_region(base[dev_num], 2, drv_name))? 1 : 0;
86 }
87
88 /* release controller register access space */
89 void hal_release_region(int dev_num,
90                         unsigned int num_regs)
91 {
92         extern unsigned long base[];
93
94         /* ignore num_regs and create the 2 register region:  */
95         /* address register = base / data register = base + 1 */
96         release_region(base[dev_num], 2);
97 }
98
99 /* enable non controller hardware (e.g. irq routing, etc.) */
100 int hw_attach(int dev_num) { return 0; }
101
102 /* disable non controller hardware (e.g. irq routing, etc.) */
103 int hw_detach(int dev_num) { return 0; }
104
105 /* reset controller hardware (with specific non controller hardware) */
106 int hw_reset_dev(int dev_num) { return 0; }
107
108 /* read from controller register */
109 u8 hw_readreg(unsigned long base, int reg) {
110
111         outb(reg, base);        /* address */
112         return inb(base + 1);   /* data */
113 }
114
115 /* write to controller register */
116 void hw_writereg(unsigned long base, int reg, u8 val) {
117
118         outb(reg, base);        /* address */
119         outb(val, base + 1);    /* data */
120 }
121
122 /* hardware specific work to do at start of irq handler */
123 void hw_preirq(struct net_device *dev) { return; }
124
125 /* hardware specific work to do at end of irq handler */
126 void hw_postirq(struct net_device *dev) { return; }
127