]> Devoid-pointer.net GitWeb - omnibook.git/commitdiff
Add support for kernel from 2.6.8 to 2.6.17-rc1
authorMathieu Bérard <mathieu.berard@crans.org>
Tue, 18 Apr 2006 20:28:36 +0000 (20:28 +0000)
committerMathieu Bérard <mathieu.berard@crans.org>
Tue, 18 Apr 2006 20:28:36 +0000 (20:28 +0000)
Makefile
ec.c
info.c
init.c
init.h
omnibook.h

index 738e7605b08341c8948b580efe1f7f5cd14e1961..888239ef1503223bff65b700362b5eaceffba764 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -32,8 +32,6 @@ BDIR  = $(shell pwd)
 TODAY  = $(shell date +%Y%m%d)
 KERNEL = $(shell uname -r | cut -c 1-3)
 
-CC     = gcc
-LD     = ld
 DEPMOD = depmod -a
 RMMOD  = modprobe -r
 INSMOD = modprobe
diff --git a/ec.c b/ec.c
index f821074353fedde184f15f889e42e211aa009245..f14ba207c810947ac0274135ee8b0c43c3d0909d 100644 (file)
--- a/ec.c
+++ b/ec.c
 #include <linux/config.h>
 #include <linux/spinlock.h>
 #include <linux/acpi.h>
+#include <linux/version.h>
 
 #include <asm/io.h>
-
 #include "ec.h"
 
+/*
+ * For (dumb) compatibility with kernel older than 2.6.9
+ */
+
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,9))
+#define ioread8(addr)          readb(addr)
+#define iowrite8(val,addr)     writeb(val,addr)
+#endif
+
+/*
+ * For compatibility with kernel older than 2.6.11
+ */
+
+#ifndef DEFINE_SPINLOCK
+#define DEFINE_SPINLOCK(s)              spinlock_t s = SPIN_LOCK_UNLOCKED
+#endif
+
+
 /*
  *     Interrupt control
  */
 
+
+
 static DEFINE_SPINLOCK(omnibook_ec_lock);
 
 
diff --git a/info.c b/info.c
index a1e0b939d2ae35d92e66820d3abe0d66fb431d94..31b721e832a216b0e1c1d6a15dca07ad00b891e8 100644 (file)
--- a/info.c
+++ b/info.c
@@ -21,6 +21,7 @@
 #endif
 
 #include <linux/dmi.h>
+#include <linux/version.h>
 
 static int omnibook_version_read(char *buffer)
 {
@@ -53,9 +54,11 @@ static int omnibook_dmi_read(char *buffer)
        len +=
            sprintf(buffer + len, "Version:       %s\n",
                    dmi_get_system_info(DMI_PRODUCT_VERSION));
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,15))     
        len +=
            sprintf(buffer + len, "Serial Number: %s\n",
                    dmi_get_system_info(DMI_PRODUCT_SERIAL));
+#endif
        len +=
            sprintf(buffer + len, "Board Vendor:  %s\n",
                    dmi_get_system_info(DMI_BOARD_VENDOR));
diff --git a/init.c b/init.c
index bd50b408bf277f00b091112693d369a03b3dc89d..a9eb4a1eda559ef5d349dde7f727c7488d520698 100644 (file)
--- a/init.c
+++ b/init.c
 #include <linux/proc_fs.h>
 #include <linux/dmi.h>
 #include <linux/version.h>
-#include <linux/platform_device.h>
 #include <asm/uaccess.h>
 
-#include "init.h"
-#include "ec.h"
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,15))
+#include <linux/platform_device.h>
+#else
+#include <linux/device.h>
+#endif
 
 
+#include "ec.h"
+#include "init.h"
+
 static struct proc_dir_entry *omnibook_proc_root = NULL;
 
 int omnibook_ectype = NONE;
 static int omnibook_userset = 0;
 
+/*
+ * The platform_driver interface was added in linux 2.6.15
+ */
+
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,15))
+
 static struct platform_device *omnibook_device;
 
 static struct platform_driver omnibook_driver = {
@@ -50,6 +61,26 @@ static struct platform_driver omnibook_driver = {
                   },
 };
 
+#else /* 2.6.15 */
+
+static struct device_driver omnibook_driver = {
+       .name   = OMNIBOOK_MODULE_NAME,
+       .bus    = &platform_bus_type,
+       .probe = compat_omnibook_probe,
+       .remove = compat_omnibook_remove,
+#ifdef CONFIG_PM
+       .suspend = compat_omnibook_suspend,
+       .resume = compat_omnibook_resume,
+#endif
+};
+static struct platform_device omnibook_device = {
+       .name   = OMNIBOOK_MODULE_NAME,
+};
+
+#endif /* 2.6.15 */
+
+
 /* Linked list of all enabled features */
 static struct omnibook_feature *omnibook_available_feature;
 
@@ -576,15 +607,21 @@ static int __init omnibook_module_init(void)
                return -ENOENT;
        }
 
+/*
+ * The platform_driver interface was added in linux 2.6.15
+ */
+
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,15))
+
        retval = platform_driver_register(&omnibook_driver);
-       if (retval < 0)
-               return retval;
+       if (retval < 0) return retval;
 
        omnibook_device = platform_device_alloc(OMNIBOOK_MODULE_NAME, -1);
        if (!omnibook_device) {
                platform_driver_unregister(&omnibook_driver);
                return -ENOMEM;
        }
+       
        retval = platform_device_add(omnibook_device);
        if (retval) {
                platform_device_put(omnibook_device);
@@ -592,13 +629,36 @@ static int __init omnibook_module_init(void)
                return retval;
        }
 
+#else /* 2.6.15 */
+
+       retval = driver_register(&omnibook_driver);
+       if (retval < 0) return retval;
+        
+        retval = platform_device_register(&omnibook_device);
+        
+        if (retval) {
+               driver_unregister(&omnibook_driver);    
+               return retval;
+       }
+
+#endif
        return 0;
 }
 
 static void __exit omnibook_module_cleanup(void)
 {
+
+/*
+ * The platform_driver interface was added in linux 2.6.15
+ */
+
+#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,15))
        platform_device_unregister(omnibook_device);
        platform_driver_unregister(&omnibook_driver);
+#else
+       platform_device_unregister(&omnibook_device);
+       driver_unregister(&omnibook_driver);
+#endif
 
        if (omnibook_proc_root)
                remove_proc_entry("omnibook", NULL);
diff --git a/init.h b/init.h
index 3ab490e6137922fe61b389bbbbb4a9aaf3a3f66a..b915c698112874fe0bdc4e44797550023fb7ba71 100644 (file)
--- a/init.h
+++ b/init.h
  * Written by Soós Péter <sp@osb.hu>, 2002-2004
  */
 
+/*
+ * For compatibility with kernel older than 2.6.11
+ */
 
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,11))
+typedef u32 pm_message_t;
+#endif
 
-struct omnibook_feature;
-
-static int __init omnibook_init(struct omnibook_feature *feature);
 static int __init omnibook_probe(struct platform_device *dev);
 static int __exit omnibook_remove(struct platform_device *dev);
 static int omnibook_suspend(struct platform_device *dev, pm_message_t state);
 static int omnibook_resume(struct platform_device *dev);
 
+/*
+ * For compatibility with kernel older than 2.6.15
+ */
+
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15))
+
+#define to_platform_device(x) container_of((x), struct platform_device, dev)
+
+static int __init compat_omnibook_probe(struct device *dev)
+{
+       struct platform_device *pdev = to_platform_device(dev);
+       return omnibook_probe(pdev);
+}
+
+static int __exit compat_omnibook_remove(struct device *dev)
+{
+       struct platform_device *pdev = to_platform_device(dev);
+       return omnibook_remove(pdev);
+}
+
+static int compat_omnibook_suspend(struct device *dev, pm_message_t state, u32 level)
+{
+       struct platform_device *pdev = to_platform_device(dev);
+       return omnibook_suspend(pdev, state);
+}
+
+static int compat_omnibook_resume(struct device *dev, u32 level)
+{
+       struct platform_device *pdev = to_platform_device(dev);
+       return omnibook_resume(pdev);
+}
+
+#endif
+
+
+/*
+ * For compatibility with kernel older than 2.6.14
+ */
+
+#if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,14))
+void inline *kzalloc(size_t size, int flags)
+{
+       void *ret = kmalloc(size, flags);
+       if (ret)
+               memset(ret, 0, size);
+       return ret;
+}
+#endif
+
+struct omnibook_feature;
+
+static int __init omnibook_init(struct omnibook_feature *feature);
+
 extern struct omnibook_feature ac_feature;
 extern struct omnibook_feature apmemu_feature;
 extern struct omnibook_feature battery_feature;
index 2b7562deca6f3bc50b0f063e4b153cf528165c94..711cebaa4651a829c71095a9887d3e60ea6b2e21 100644 (file)
@@ -92,7 +92,11 @@ extern int omnibook_get_ac(void);
 extern int omnibook_get_battery_status(int num, struct omnibook_battery_state *battstat);
 extern int set_omnibook_param(const char *val, struct kernel_param *kp);
 
-/* Configuration for standalone compilation */
+/* 
+ * Configuration for standalone compilation: 
+ * -Register as backlight depends on kernel config
+ * -APM emulation is disabled by default
+ */
 
 #ifdef  OMNIBOOK_STANDALONE
 #ifdef  CONFIG_BACKLIGHT_CLASS_DEVICE