Merge remote-tracking branch 'stable/linux-3.0.y' into develop-3.0
[firefly-linux-kernel-4.4.55.git] / drivers / cmmb / siano / compat.h
1 /*
2  * $Id: compat.h,v 1.44 2006/01/15 09:35:16 mchehab Exp $
3  */
4
5 #ifndef _COMPAT_H
6 #define _COMPAT_H
7
8 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
9 #define KERN_CONT       ""
10 #endif
11
12 /* To allow I2C compatibility code to work */
13 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 24)
14 #include <linux/i2c-dev.h>
15 #endif
16
17 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 26)
18 #ifdef CONFIG_PROC_FS
19 #include <linux/module.h>
20 #include <linux/proc_fs.h>
21 #endif
22 #endif
23
24 /* To allow alsa code to work */
25 #ifdef NEED_SOUND_DRIVER_H
26 #include <sound/driver.h>
27 #endif
28
29 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,23)
30 #define set_freezable()
31 #define cancel_delayed_work_sync cancel_rearming_delayed_work
32 #endif
33
34 #ifndef __pure
35 #  define __pure __attribute__((pure))
36 #endif
37
38 #ifndef I2C_M_IGNORE_NAK
39 # define I2C_M_IGNORE_NAK 0x1000
40 #endif
41
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)
47 #endif
48
49 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18)
50 #define IRQF_SHARED             SA_SHIRQ
51 #define IRQF_DISABLED           SA_INTERRUPT
52 #endif
53
54 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
55 # define PCIAGP_FAIL 0
56
57 #define vmalloc_32_user(a) vmalloc_32(a)
58
59 #endif
60
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)
63 typedef int bool;
64 #define true 1
65 #define false 0
66 #endif
67
68 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,22)
69 #define sony_pic_camera_command(a,b) sonypi_camera_command(a,b)
70
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
79 #endif
80
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; }
88 #endif
89
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)
93 {
94         static const unsigned int rates[] = { 5512, 8000, 11025, 16000, 22050,
95                 32000, 44100, 48000, 64000, 88200, 96000, 176400, 192000 };
96         unsigned int i;
97
98         for (i = 0; i < ARRAY_SIZE(rates); i++)
99                 if (rates[i] == rate)
100                         return 1u << i;
101         return SNDRV_PCM_RATE_KNOT;
102 }
103 #endif
104
105 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,24)
106 # define task_pid_nr(current) ((current)->pid)
107
108 # define sg_init_table(a,b)
109 # define sg_page(p) (sg->page)
110 # define sg_set_page(sglist,pg,sz,off)                                  \
111 do {                                                                    \
112         struct scatterlist *p=sglist;                                   \
113         p->page   = pg;                                                 \
114         p->length = sz;                                                 \
115         p->offset = off;                                                \
116 } while (0)
117
118 #define pr_err(fmt, arg...) \
119         printk(KERN_ERR fmt, ##arg)
120 #endif
121
122 #ifndef BIT_MASK
123 # define BIT_MASK(nr)            (1UL << ((nr) % BITS_PER_LONG))
124 # define BIT_WORD(nr)            ((nr) / BITS_PER_LONG)
125 #endif
126
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)
133 #endif
134
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)
142 #endif
143
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)))
165 #endif
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)
170 {
171         struct proc_dir_entry *e;
172
173         e = create_proc_entry(a, b, c);
174         if (e) {
175                 e->owner = THIS_MODULE;
176 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 17)
177                 e->proc_fops = d;
178 #else
179                 e->proc_fops = (struct file_operations *)d;
180 #endif
181         }
182         return e;
183 }
184 #endif
185 #endif
186
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,
191         void *f)
192 {
193         struct proc_dir_entry *e;
194
195         e = create_proc_entry(a, b, c);
196         if (e) {
197                 e->owner = THIS_MODULE;
198 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 17)
199                 e->proc_fops = d;
200 #else
201                 e->proc_fops = (struct file_operations *)d;
202 #endif
203                 e->data = f;
204         }
205         return e;
206 }
207 #endif
208 #endif
209
210 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 17)
211 #define hweight64(x)  generic_hweight64(x)
212 #endif
213
214 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 26)
215 #define div64_u64(a,b) div64_64(a,b)
216
217 #define clamp( x, l, h )        max_t( __typeof__( x ),         \
218                                       ( l ),                    \
219                                       min_t( __typeof__( x ),   \
220                                              ( h ),             \
221                                              ( x ) ) )
222
223 #define dev_name(dev)   ((dev)->bus_id)
224
225 #endif
226
227 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 24)
228 typedef unsigned long uintptr_t;
229 #endif
230
231 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 26)
232 static inline int list_is_singular(const struct list_head *head)
233 {
234         return !list_empty(head) && (head->next == head->prev);
235 }
236 #endif
237
238 #endif