summaryrefslogtreecommitdiff
path: root/v4l/compat.h
diff options
context:
space:
mode:
Diffstat (limited to 'v4l/compat.h')
-rw-r--r--v4l/compat.h88
1 files changed, 85 insertions, 3 deletions
diff --git a/v4l/compat.h b/v4l/compat.h
index 8e778d7f5..465b3ae8b 100644
--- a/v4l/compat.h
+++ b/v4l/compat.h
@@ -9,7 +9,7 @@
* non-delayed work and struct delayed_work was created for delayed work. This
* will rename the structures. Hopefully no one will decide to name something
* delayed_work in the same context as something named work_struct. */
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 20)
+#ifdef NEED_DELAYED_WORK
#define delayed_work work_struct
#define INIT_DELAYED_WORK(a,b,c) INIT_WORK(a,b,c)
#endif
@@ -36,6 +36,10 @@
#include <sound/driver.h>
#endif
+#ifdef NEED_SND_CARD_CREATE
+#include <sound/core.h>
+#endif
+
#ifdef NEED_ALGO_CONTROL
#include <linux/i2c.h>
#endif
@@ -68,6 +72,15 @@
#define vmalloc_32_user(a) vmalloc_32(a)
#endif
+#ifndef DIV_ROUND_CLOSEST
+#define DIV_ROUND_CLOSEST(x, divisor)( \
+{ \
+ typeof(divisor) __divisor = divisor; \
+ (((x) + ((__divisor) / 2)) / (__divisor)); \
+} \
+)
+#endif
+
#ifdef NEED_BOOL_TYPE
/* bool type and enum-based definition of true and false was added in 2.6.19 */
typedef int bool;
@@ -142,6 +155,12 @@ do { \
((dev->bus && 0 == strcmp(dev->bus->name, "i2c")) ? to_i2c_client(dev) : NULL)
#endif
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 31)
+/* Construct an I2C_CLIENT_END-terminated array of i2c addresses */
+#define I2C_ADDRS(addr, addrs...) \
+ ((const unsigned short []){ addr, ## addrs, I2C_CLIENT_END })
+#endif
+
#ifndef USB_DEVICE_AND_INTERFACE_INFO
# define USB_DEVICE_AND_INTERFACE_INFO(vend,prod,cl,sc,pr) \
.match_flags = USB_DEVICE_ID_MATCH_INT_INFO \
@@ -279,10 +298,14 @@ static inline int dummy_algo_control(struct i2c_adapter *adapter,
})
#endif
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 28)
+#ifdef NEED_SND_BUG_ON
#define snd_BUG_ON(cond) WARN((cond), "BUG? (%s)\n", __stringify(cond))
#endif
+#ifdef NEED_BITOPS
+#define BIT(x) (1UL<<((x)%BITS_PER_LONG))
+#endif
+
#ifndef PCI_DEVICE_ID_MARVELL_88ALP01_CCIC
#define PCI_DEVICE_ID_MARVELL_88ALP01_CCIC 0x4102
#endif
@@ -423,7 +446,7 @@ static inline int usb_endpoint_type(const struct usb_endpoint_descriptor *epd)
pci_resource_len(pdev, bar))
#endif
-#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 29)
+#ifdef NEED_POLL_SCHEDULE
#define poll_schedule(pwq, task) \
do { \
set_current_state(task); \
@@ -432,4 +455,63 @@ static inline int usb_endpoint_type(const struct usb_endpoint_descriptor *epd)
} while (0)
#endif
+#ifdef NEED_SND_CARD_CREATE
+static inline int snd_card_create(int idx, const char *id,
+ struct module *module, int extra_size,
+ struct snd_card **card)
+{
+ *card = snd_card_new(idx, id, module, extra_size);
+
+ if (*card == NULL)
+ return -ENOMEM;
+ return 0;
+}
+#endif
+
+/* This macro was added in commit v2.6.23-5792-g34c6538 */
+#ifndef DMA_BIT_MASK
+#define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
#endif
+
+/* __fls() was added for generic code in 2.6.29, existed for just 64-bit arches
+ * since 2.6.26 (v2.6.25-5228-g56a6b1e), and was x86-64 only before then. We
+ * only want this compat code when __fls doesn't exist, which 2.6.29 or later,
+ * non x86-64, and non 64-bit that's 2.6.26 or later. */
+#if !(LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 29) || \
+ defined(__x86_64__) || \
+ (BITS_PER_LONG == 64 && LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 26)))
+/* This define will prevent breakage if __fls was already defined. */
+#undef __fls
+#define __fls v4l_compat_fls
+static inline unsigned long v4l_compat_fls(unsigned long x)
+{
+ return fls(x) - 1;
+}
+#endif
+
+/*
+ * Compatibility code for hrtimer API
+ * This will make hrtimer usable for kernels 2.6.22 and later.
+ * For earlier kernels, not all required functions are exported
+ * so there's nothing we can do.
+ */
+
+#ifdef _LINUX_HRTIMER_H
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 25) && \
+ LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 22)
+/* Forward a hrtimer so it expires after the hrtimer's current now */
+static inline unsigned long hrtimer_forward_now(struct hrtimer *timer,
+ ktime_t interval)
+{
+ return hrtimer_forward(timer, timer->base->get_time(), interval);
+}
+#endif
+#endif /* _LINUX_HRTIMER_H */
+
+#ifndef PCI_VDEVICE
+#define PCI_VDEVICE(vendor, device) \
+ PCI_VENDOR_ID_##vendor, (device), \
+ PCI_ANY_ID, PCI_ANY_ID, 0, 0
+#endif
+
+#endif /* _COMPAT_H */