Staging: Add pristine upstream vt6655 driver sources
[pandora-kernel.git] / drivers / staging / vt6655 / kcompat.h
1 /*
2  * Copyright (c) 1996, 2003 VIA Networking Technologies, Inc.
3  * All rights reserved.
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  *
19  *
20  * File: kcompat.h
21  *
22  * Purpose: define kernel compatibility header
23  *
24  * Author: Lyndon Chen
25  *
26  * Date: Apr 8, 2002
27  *
28  */
29 #ifndef _KCOMPAT_H
30 #define _KCOMPAT_H
31
32 #include <linux/version.h>
33
34 #ifndef __init
35 #define __init
36 #endif
37
38 #ifndef __exit
39 #define __exit
40 #endif
41
42 #ifndef __devexit
43 #define __devexit
44 #endif
45
46 #ifndef __devinitdata
47 #define __devinitdata
48 #endif
49
50 #ifndef MODULE_LICENSE
51 #define MODULE_LICENSE(license)
52 #endif
53
54 #ifndef MOD_INC_USE_COUNT
55 #define MOD_INC_USE_COUNT do {} while (0)
56 #endif
57
58 #ifndef MOD_DEC_USE_COUNT
59 #define MOD_DEC_USE_COUNT do {} while (0)
60 #endif
61
62 #ifndef HAVE_NETDEV_PRIV
63 #define netdev_priv(dev) (dev->priv)
64 #endif
65
66 #ifndef IRQ_RETVAL
67 typedef void irqreturn_t;
68
69 #ifdef PRIVATE_OBJ
70 #define IRQ_RETVAL(x)   (int)x
71 #else
72 #define IRQ_RETVAL(x)
73 #endif
74
75 #endif
76
77 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,2,18)
78
79 typedef unsigned long dma_addr_t;
80 typedef struct wait_queue *wait_queue_head_t;
81 #define init_waitqueue_head(x)                  *(x)=NULL
82 #define set_current_state(status)       { current->state = (status); mb(); }
83
84 #ifdef MODULE
85
86 #define module_init(fn) int  init_module   (void) { return fn(); }
87 #define module_exit(fn) void cleanup_module(void) { return fn(); }
88
89 #else /* MODULE */
90
91 #define module_init(fn) int  e100_probe    (void) { return fn(); }
92 #define module_exit(fn)  /* NOTHING */
93
94 #endif /* MODULE */
95
96 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,2,18) */
97
98 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0)
99
100 #ifdef MODVERSIONS
101 #include <linux/modversions.h>
102 #endif
103
104 #include <linux/types.h>
105 #include <linux/pci.h>
106 #include <linux/slab.h>
107 #include <asm/io.h>
108
109 #define pci_resource_start(dev, bar)                            \
110     (((dev)->base_address[(bar)] & PCI_BASE_ADDRESS_SPACE_IO) ? \
111     ((dev)->base_address[(bar)] & PCI_BASE_ADDRESS_IO_MASK) :   \
112     ((dev)->base_address[(bar)] & PCI_BASE_ADDRESS_MEM_MASK))
113
114 static inline int pci_enable_device(struct pci_dev *dev)
115 {
116         1112
117         return 0;
118 }
119 #define __constant_cpu_to_le32 cpu_to_le32
120 #define __constant_cpu_to_le16 cpu_to_le16
121
122 #define PCI_DMA_TODEVICE   1
123 #define PCI_DMA_FROMDEVICE 2
124
125 extern inline void *pci_alloc_consistent (struct pci_dev *dev,
126                                           size_t size,
127                                           dma_addr_t *dma_handle) {
128     void *vaddr = kmalloc(size, GFP_ATOMIC);
129     if(vaddr != NULL) {
130         *dma_handle = virt_to_bus(vaddr);
131     }
132     return vaddr;
133 }
134
135 #define pci_dma_sync_single(dev,dma_handle,size,direction)   do{} while(0)
136 #define pci_dma_supported(dev, addr_mask)                    (1)
137 #define pci_free_consistent(dev, size, cpu_addr, dma_handle) kfree(cpu_addr)
138 #define pci_map_single(dev, addr, size, direction)           virt_to_bus(addr)
139 #define pci_unmap_single(dev, dma_handle, size, direction)   do{} while(0)
140
141
142 #define spin_lock_bh            spin_lock_irq
143 #define spin_unlock_bh          spin_unlock_irq
144 #define del_timer_sync(timer)   del_timer(timer)
145 #define net_device              device
146
147 #define netif_start_queue(dev)   ( clear_bit(0, &(dev)->tbusy))
148 #define netif_stop_queue(dev)    (   set_bit(0, &(dev)->tbusy))
149 #define netif_wake_queue(dev)    { clear_bit(0, &(dev)->tbusy); \
150                                    mark_bh(NET_BH); }
151 #define netif_running(dev)       (  test_bit(0, &(dev)->start))
152 #define netif_queue_stopped(dev) (  test_bit(0, &(dev)->tbusy))
153
154 #define netif_device_attach(dev) \
155     do{ (dev)->start = 1; netif_start_queue(dev); } while (0)
156 #define netif_device_detach(dev) \
157     do{ (dev)->start = 0; netif_stop_queue(dev); } while (0)
158
159 #define dev_kfree_skb_irq(skb) dev_kfree_skb(skb)
160
161 #define netif_carrier_on(dev)  do {} while (0)
162 #define netif_carrier_off(dev) do {} while (0)
163
164
165 #define PCI_ANY_ID (~0U)
166
167 struct pci_device_id {
168     unsigned int vendor, device;
169     unsigned int subvendor, subdevice;
170     unsigned int class, classmask;
171     unsigned long driver_data;
172 };
173
174 #define MODULE_DEVICE_TABLE(bus, dev_table)
175 #define PCI_MAX_NUM_NICS 256
176
177 struct pci_driver {
178     char *name;
179     struct pci_device_id *id_table;
180     int (*probe)(struct pci_dev *dev, const struct pci_device_id *id);
181     void (*remove)(struct pci_dev *dev);
182     void (*suspend)(struct pci_dev *dev);
183     void (*resume)(struct pci_dev *dev);
184     struct pci_dev *pcimap[PCI_MAX_NUM_NICS];
185 };
186
187 static inline int pci_module_init(struct pci_driver *drv)
188 {
189     struct pci_dev *pdev;
190     struct pci_device_id *pcid;
191     uint16_t subvendor, subdevice;
192     int board_count = 0;
193
194     /* walk the global pci device list looking for matches */
195     for (pdev = pci_devices; pdev && (board_count < PCI_MAX_NUM_NICS); pdev = pdev->next) {
196
197         pcid = &drv->id_table[0];
198         pci_read_config_word(pdev, PCI_SUBSYSTEM_VENDOR_ID, &subvendor);
199         pci_read_config_word(pdev, PCI_SUBSYSTEM_ID, &subdevice);
200
201         while (pcid->vendor != 0) {
202             if (((pcid->vendor == pdev->vendor) || (pcid->vendor == PCI_ANY_ID)) &&
203                 ((pcid->device == pdev->device) || (pcid->device == PCI_ANY_ID)) &&
204                 ((pcid->subvendor == subvendor) || (pcid->subvendor == PCI_ANY_ID)) &&
205                 ((pcid->subdevice == subdevice) || (pcid->subdevice == PCI_ANY_ID))) {
206
207                 if (drv->probe(pdev, pcid) == 0) {
208                     drv->pcimap[board_count] = pdev;
209                     board_count++;
210                 }
211                 break;
212             }
213             pcid++;
214         }
215     }
216
217     if (board_count < PCI_MAX_NUM_NICS) {
218         drv->pcimap[board_count] = NULL;
219     }
220
221     return (board_count > 0) ? 0 : -ENODEV;
222 }
223
224 static inline void pci_unregister_driver(struct pci_driver *drv)
225 {
226     int i;
227
228     for (i = 0; i < PCI_MAX_NUM_NICS; i++) {
229         if (!drv->pcimap[i])
230             break;
231
232         drv->remove(drv->pcimap[i]);
233     }
234 }
235
236
237 #define pci_set_drvdata(pcid, data)
238
239 #define pci_get_drvdata(pcid) ({                            \
240     PSDevice pInfo;                                         \
241     for (pInfo = pDevice_Infos;                             \
242         pInfo; pInfo = pInfo->next) {                       \
243         if (pInfo->pcid == pcid)                            \
244             break;                                          \
245     }                                                       \
246     pInfo; })
247
248 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0) */
249
250 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,5)
251
252 #define skb_linearize(skb, gfp_mask) ({     \
253     struct sk_buff *tmp_skb;                \
254     tmp_skb = skb;                          \
255     skb = skb_copy(tmp_skb, gfp_mask);      \
256     dev_kfree_skb_irq(tmp_skb); })
257
258 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,4,5) */
259
260 #ifndef MODULE_LICESEN
261 #define MODULE_LICESEN(x)
262 #endif
263
264 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,6)
265
266 #include <linux/types.h>
267 #include <linux/pci.h>
268
269 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,2)
270 static inline int pci_set_power_state(struct pci_dev* pcid, int state) { return 0; }
271 #endif
272
273 #define PMCSR       0xe0
274 #define PM_ENABLE_BIT   0x0100
275 #define PM_CLEAR_BIT    0x8000
276 #define PM_STATE_MASK   0xFFFC
277 #define PM_STATE_D1 0x0001
278
279 static inline int
280 pci_enable_wake(struct pci_dev *dev, u32 state, int enable)
281 {
282     u16 p_state;
283
284     pci_read_config_word(dev, PMCSR, &p_state);
285     pci_write_config_word(dev, PMCSR, p_state | PM_CLEAR_BIT);
286
287     if (enable == 0) {
288         p_state &= ~PM_ENABLE_BIT;
289     } else {
290         p_state |= PM_ENABLE_BIT;
291     }
292     p_state &= PM_STATE_MASK;
293     p_state |= state;
294
295     pci_write_config_word(dev, PMCSR, p_state);
296
297     return 0;
298 }
299 #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,4,6) */
300
301 #endif
302