5f47d5a94d4b9dfc66395dc49f924476deec4d98
[platform/kernel/linux-rpi.git] / drivers / staging / dt3155 / pci-compat.h
1
2 /* This header only makes send when included in a 2.0 compile */
3
4 #ifndef _PCI_COMPAT_H_
5 #define _PCI_COMPAT_H_
6
7 #ifdef __KERNEL__
8
9 #include <linux/bios32.h> /* pcibios_* */
10 #include <linux/pci.h> /* pcibios_* */
11 #include <linux/malloc.h> /* kmalloc */
12
13 /* fake the new pci interface based on the old one: encapsulate bus/devfn */
14 struct pci_fake_dev {
15     u8 bus;
16     u8 devfn;
17     int index;
18 };
19 #define pci_dev pci_fake_dev /* the other pci_dev is unused by 2.0 drivers */
20
21 extern inline struct pci_dev *pci_find_device(unsigned int vendorid,
22                                               unsigned int devid,
23                                               struct pci_dev *from)
24 {
25     struct pci_dev *pptr = kmalloc(sizeof(*pptr), GFP_KERNEL);
26     int index = 0;
27     int ret;
28
29     if (!pptr) return NULL;
30     if (from) index = pptr->index + 1;
31     ret = pcibios_find_device(vendorid, devid, index,
32                               &pptr->bus, &pptr->devfn);
33     if (ret) { kfree(pptr); return NULL; }
34     return pptr;
35 }
36
37 extern inline struct pci_dev *pci_find_class(unsigned int class,
38                                              struct pci_dev *from)
39 {
40     return NULL; /* FIXME */
41 }
42
43 extern inline void pci_release_device(struct pci_dev *dev)
44 {
45     kfree(dev);
46 }
47
48 /* struct pci_dev *pci_find_slot (unsigned int bus, unsigned int devfn); */
49
50 #define pci_present pcibios_present
51
52 extern inline int
53 pci_read_config_byte(struct pci_dev *dev, u8 where, u8 *val)
54 {
55     return pcibios_read_config_byte(dev->bus, dev->devfn, where, val);
56 }
57
58 extern inline int
59 pci_read_config_word(struct pci_dev *dev, u8 where, u16 *val)
60 {
61     return pcibios_read_config_word(dev->bus, dev->devfn, where, val);
62 }
63
64 extern inline int
65 pci_read_config_dword(struct pci_dev *dev, u8 where, u32 *val)
66 {
67     return pcibios_read_config_dword(dev->bus, dev->devfn, where, val);
68 }
69
70 extern inline int
71 pci_write_config_byte(struct pci_dev *dev, u8 where, u8 val)
72 {
73     return pcibios_write_config_byte(dev->bus, dev->devfn, where, val);
74 }
75
76 extern inline int
77 pci_write_config_word(struct pci_dev *dev, u8 where, u16 val)
78 {
79     return pcibios_write_config_word(dev->bus, dev->devfn, where, val);
80 }
81
82 extern inline int
83 pci_write_config_dword(struct pci_dev *dev, u8 where, u32 val)
84 {
85     return pcibios_write_config_dword(dev->bus, dev->devfn, where, val);
86 }
87
88 extern inline void pci_set_master(struct pci_dev *dev)
89 {
90     u16 cmd;
91     pcibios_read_config_word(dev->bus, dev->devfn, PCI_COMMAND, &cmd);
92     cmd |= PCI_COMMAND_MASTER;
93     pcibios_write_config_word(dev->bus, dev->devfn, PCI_COMMAND, cmd);
94 }
95
96 #endif /* __KERNEL__ */
97 #endif /* _PCI_COMPAT_H_ */