Towards compiling on 2.4
authorMichael Brown <mbrown@fensystems.co.uk>
Tue, 14 Mar 2006 18:30:00 +0000 (18:30 +0000)
committerMichael Brown <mbrown@fensystems.co.uk>
Tue, 14 Mar 2006 18:30:00 +0000 (18:30 +0000)
kernel/kernel_compat.h [new file with mode: 0644]
kernel/quickusb.c

diff --git a/kernel/kernel_compat.h b/kernel/kernel_compat.h
new file mode 100644 (file)
index 0000000..6d357ac
--- /dev/null
@@ -0,0 +1,93 @@
+#ifndef QUICKUSB_KERNEL_COMPAT_H
+#define QUICKUSB_KERNEL_COMPAT_H
+
+#include <linux/version.h>
+
+#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)
+
+#include <asm/atomic.h>
+#include <linux/slab.h>
+#include <linux/usb.h>
+
+#define __user
+
+struct device;
+
+struct kref {
+       atomic_t refcount;
+};
+
+static inline void kref_init ( struct kref *kref ) {
+       atomic_set ( &kref->refcount, 1 );
+}
+
+static inline void kref_get ( struct kref *kref ) {
+       atomic_inc ( &kref->refcount );
+}
+
+static inline void kref_put ( struct kref *kref,
+                             void (*release) ( struct kref *kref ) ) {
+       if ( atomic_dec_and_test ( &kref->refcount ) )
+               release ( kref );
+}
+
+#define container_of(ptr, type, member) ( {                    \
+       const typeof( ((type *)0)->member ) *__mptr = (ptr);    \
+       (type *)( (char *)__mptr - offsetof(type,member) ); } )
+
+static inline struct usb_device *usb_get_dev ( struct usb_device *usb ) {
+       usb_inc_dev_use ( usb );
+       return usb;
+}
+
+static inline void usb_put_dev ( struct usb_device *usb ) {
+       usb_free_dev ( usb );
+}
+
+static inline unsigned iminor ( struct inode *inode ) {
+       return MINOR ( inode->i_rdev );
+}
+
+static inline struct class_simple *class_simple_create ( struct module *owner,
+                                                        const char *name ) {
+       return NULL;
+}
+
+static inline void class_simple_destroy ( struct class_simple *class ) {
+       /* Do nothing */
+}
+
+#define class_simple_device_add(...) NULL
+
+static inline void class_simple_device_remove ( dev_t dev ) {
+       /* Do nothing */
+}
+
+static devfs_handle_t devfs_handle;
+static struct file_operations quickusb_fops;
+
+static inline int devfs_mk_cdev ( dev_t dev, umode_t mode,
+                                 const char *name ) {
+       devfs_handle = devfs_register ( NULL, name, DEVFS_FL_DEFAULT,
+                                       MAJOR ( dev ), MINOR ( dev ),
+                                       mode, &quickusb_fops, NULL );
+       return ( devfs_handle == NULL ) ? -EIO : 0;
+}
+
+static inline void devfs_remove ( const char *name ) {
+       devfs_unregister ( devfs_handle );
+}
+
+#define module_param( name, type, perm ) MODULE_PARM ( name, "i" )
+
+#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0) */
+
+#endif /* QUICKUSB_KERNEL_COMPAT_H */
+
+/*
+ * Local variables:
+ *  c-basic-offset: 8
+ *  c-indent-level: 8
+ *  tab-width: 8
+ * End:
+ */
index a7c5a32..5862dac 100644 (file)
 #include <linux/module.h>
 #include <linux/fs.h>
 #include <linux/devfs_fs_kernel.h>
 #include <linux/module.h>
 #include <linux/fs.h>
 #include <linux/devfs_fs_kernel.h>
-#include <linux/kref.h>
 #include <linux/usb.h>
 #include <asm/uaccess.h>
 #include "quickusb.h"
 #include <linux/usb.h>
 #include <asm/uaccess.h>
 #include "quickusb.h"
+#include "kernel_compat.h"
 
 #define QUICKUSB_VENDOR_ID 0x0fbb
 #define QUICKUSB_DEVICE_ID 0x0001
 
 #define QUICKUSB_VENDOR_ID 0x0fbb
 #define QUICKUSB_DEVICE_ID 0x0001
@@ -350,7 +350,7 @@ static int quickusb_register_subdev ( struct quickusb_device *quickusb,
                                      void *private_data,
                                      const char *subdev_fmt, ... ) {
        struct quickusb_subdev *subdev = &quickusb->subdev[subdev_idx];
                                      void *private_data,
                                      const char *subdev_fmt, ... ) {
        struct quickusb_subdev *subdev = &quickusb->subdev[subdev_idx];
-       struct device *device = &quickusb->interface->dev;
+       struct usb_interface *interface = quickusb->interface;
        unsigned int dev_minor;
        va_list ap;
        int rc;
        unsigned int dev_minor;
        va_list ap;
        int rc;
@@ -377,7 +377,8 @@ static int quickusb_register_subdev ( struct quickusb_device *quickusb,
 
        /* Create class device */
        subdev->class_dev = class_simple_device_add ( quickusb_class,
 
        /* Create class device */
        subdev->class_dev = class_simple_device_add ( quickusb_class,
-                                                     subdev->dev, device,
+                                                     subdev->dev,
+                                                     &interface->dev,
                                                      subdev->name );
        if ( IS_ERR ( subdev->class_dev ) ) {
                rc = PTR_ERR ( subdev->class_dev );
                                                      subdev->name );
        if ( IS_ERR ( subdev->class_dev ) ) {
                rc = PTR_ERR ( subdev->class_dev );