2 * $Id: compat.h,v 1.44 2006/01/15 09:35:16 mchehab Exp $
8 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
12 /* To allow I2C compatibility code to work */
13 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24)
14 #include <linux/i2c-dev.h>
17 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 26)
19 #include <linux/module.h>
20 #include <linux/proc_fs.h>
24 /* To allow alsa code to work */
25 #ifdef NEED_SOUND_DRIVER_H
26 #include <sound/driver.h>
29 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23)
30 #define set_freezable()
31 #define cancel_delayed_work_sync cancel_rearming_delayed_work
35 # define __pure __attribute__((pure))
38 #ifndef I2C_M_IGNORE_NAK
39 # define I2C_M_IGNORE_NAK 0x1000
42 /* device_create/destroy added in 2.6.18 */
43 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18)
44 /* on older kernels, class_device_create will in turn be a compat macro */
45 # define device_create(a, b, c, d, e, f, g) class_device_create(a, NULL, c, b, d, e, f, g)
46 # define device_destroy(a, b) class_device_destroy(a, b)
49 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18)
50 #define IRQF_SHARED SA_SHIRQ
51 #define IRQF_DISABLED SA_INTERRUPT
54 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
55 # define PCIAGP_FAIL 0
57 #define vmalloc_32_user(a) vmalloc_32(a)
61 /* bool type and enum-based definition of true and false was added in 2.6.19 */
62 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
68 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,22)
69 #define sony_pic_camera_command(a,b) sonypi_camera_command(a,b)
71 #define SONY_PIC_COMMAND_SETCAMERAAGC SONYPI_COMMAND_SETCAMERAAGC
72 #define SONY_PIC_COMMAND_SETCAMERABRIGHTNESS SONYPI_COMMAND_SETCAMERABRIGHTNESS
73 #define SONY_PIC_COMMAND_SETCAMERACOLOR SONYPI_COMMAND_SETCAMERACOLOR
74 #define SONY_PIC_COMMAND_SETCAMERACONTRAST SONYPI_COMMAND_SETCAMERACONTRAST
75 #define SONY_PIC_COMMAND_SETCAMERAHUE SONYPI_COMMAND_SETCAMERAHUE
76 #define SONY_PIC_COMMAND_SETCAMERAPICTURE SONYPI_COMMAND_SETCAMERAPICTURE
77 #define SONY_PIC_COMMAND_SETCAMERASHARPNESS SONYPI_COMMAND_SETCAMERASHARPNESS
78 #define SONY_PIC_COMMAND_SETCAMERA SONYPI_COMMAND_SETCAMERA
81 /* pci_dev got a new revision field in 2.6.23-rc1 */
82 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23) && defined(LINUX_PCI_H)
83 /* Just make it easier to subsitute pci_dev->revision with
84 * v4l_compat_pci_rev(pci_dev). It's too bad there isn't some kind of context
85 * sensitive macro in C that could do this for us. */
86 static inline u8 v4l_compat_pci_rev(struct pci_dev *pci)
87 { u8 rev; pci_read_config_byte(pci, PCI_REVISION_ID, &rev); return rev; }
90 #if defined(COMPAT_PCM_TO_RATE_BIT) && defined(__SOUND_PCM_H)
91 /* New alsa core utility function */
92 static inline unsigned int snd_pcm_rate_to_rate_bit(unsigned int rate)
94 static const unsigned int rates[] = { 5512, 8000, 11025, 16000, 22050,
95 32000, 44100, 48000, 64000, 88200, 96000, 176400, 192000 };
98 for (i = 0; i < ARRAY_SIZE(rates); i++)
101 return SNDRV_PCM_RATE_KNOT;
105 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
106 # define task_pid_nr(current) ((current)->pid)
108 # define sg_init_table(a,b)
109 # define sg_page(p) (sg->page)
110 # define sg_set_page(sglist,pg,sz,off) \
112 struct scatterlist *p=sglist; \
118 #define pr_err(fmt, arg...) \
119 printk(KERN_ERR fmt, ##arg)
123 # define BIT_MASK(nr) (1UL << ((nr) % BITS_PER_LONG))
124 # define BIT_WORD(nr) ((nr) / BITS_PER_LONG)
127 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
128 #define i2c_verify_client(dev) \
129 ((dev->bus == &i2c_bus_type) ? to_i2c_client(dev) : NULL)
130 #elif LINUX_VERSION_CODE < KERNEL_VERSION(2,6,25)
131 #define i2c_verify_client(dev) \
132 ((dev->bus && 0 == strcmp(dev->bus->name, "i2c")) ? to_i2c_client(dev) : NULL)
135 #ifndef USB_DEVICE_AND_INTERFACE_INFO
136 # define USB_DEVICE_AND_INTERFACE_INFO(vend,prod,cl,sc,pr) \
137 .match_flags = USB_DEVICE_ID_MATCH_INT_INFO \
138 | USB_DEVICE_ID_MATCH_DEVICE, \
139 .idVendor = (vend), .idProduct = (prod), \
140 .bInterfaceClass = (cl), \
141 .bInterfaceSubClass = (sc), .bInterfaceProtocol = (pr)
144 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 26)
145 #define get_unaligned_be16(a) \
146 be16_to_cpu(get_unaligned((unsigned short *)(a)))
147 #define put_unaligned_be16(r, a) \
148 put_unaligned(cpu_to_be16(r), ((unsigned short *)(a)))
149 #define get_unaligned_le16(a) \
150 le16_to_cpu(get_unaligned((unsigned short *)(a)))
151 #define put_unaligned_le16(r, a) \
152 put_unaligned(cpu_to_le16(r), ((unsigned short *)(a)))
153 #define get_unaligned_be32(a) \
154 be32_to_cpu(get_unaligned((u32 *)(a)))
155 #define put_unaligned_be32(r, a) \
156 put_unaligned(cpu_to_be32(r), ((u32 *)(a)))
157 #define get_unaligned_le32(a) \
158 le32_to_cpu(get_unaligned((u32 *)(a)))
159 #define put_unaligned_le32(r, a) \
160 put_unaligned(cpu_to_le32(r), ((u32 *)(a)))
161 #define get_unaligned_le64(a) \
162 le64_to_cpu(get_unaligned((u64 *)(a)))
163 #define put_unaligned_le64(r, a) \
164 put_unaligned(cpu_to_le64(r), ((u64 *)(a)))
166 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 25)
167 #ifdef CONFIG_PROC_FS
168 static inline struct proc_dir_entry *proc_create(const char *a,
169 mode_t b, struct proc_dir_entry *c, const struct file_operations *d)
171 struct proc_dir_entry *e;
173 e = create_proc_entry(a, b, c);
175 e->owner = THIS_MODULE;
176 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 17)
179 e->proc_fops = (struct file_operations *)d;
187 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 26)
188 #ifdef CONFIG_PROC_FS
189 static inline struct proc_dir_entry *proc_create_data(const char *a,
190 mode_t b, struct proc_dir_entry *c, const struct file_operations *d,
193 struct proc_dir_entry *e;
195 e = create_proc_entry(a, b, c);
197 e->owner = THIS_MODULE;
198 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 17)
201 e->proc_fops = (struct file_operations *)d;
210 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 17)
211 #define hweight64(x) generic_hweight64(x)
214 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 26)
215 #define div64_u64(a,b) div64_64(a,b)
217 #define clamp( x, l, h ) max_t( __typeof__( x ), \
219 min_t( __typeof__( x ), \
223 #define dev_name(dev) ((dev)->bus_id)
227 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
228 typedef unsigned long uintptr_t;
231 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 26)
232 static inline int list_is_singular(const struct list_head *head)
234 return !list_empty(head) && (head->next == head->prev);