From 80f914546119b1a8ec474059b0c7073ddb649139 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Mathieu=20B=C3=A9rard?= Date: Tue, 18 Apr 2006 20:28:36 +0000 Subject: [PATCH] Add support for kernel from 2.6.8 to 2.6.17-rc1 --- Makefile | 2 -- ec.c | 22 ++++++++++++++++- info.c | 3 +++ init.c | 70 ++++++++++++++++++++++++++++++++++++++++++++++++++---- init.h | 62 ++++++++++++++++++++++++++++++++++++++++++++--- omnibook.h | 6 ++++- 6 files changed, 153 insertions(+), 12 deletions(-) diff --git a/Makefile b/Makefile index 738e760..888239e 100644 --- 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 f821074..f14ba20 100644 --- a/ec.c +++ b/ec.c @@ -21,15 +21,35 @@ #include #include #include +#include #include - #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 a1e0b93..31b721e 100644 --- a/info.c +++ b/info.c @@ -21,6 +21,7 @@ #endif #include +#include 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 bd50b40..a9eb4a1 100644 --- a/init.c +++ b/init.c @@ -23,18 +23,29 @@ #include #include #include -#include #include -#include "init.h" -#include "ec.h" +#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,15)) +#include +#else +#include +#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 3ab490e..b915c69 100644 --- a/init.h +++ b/init.h @@ -14,16 +14,72 @@ * Written by Soós Péter , 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; diff --git a/omnibook.h b/omnibook.h index 2b7562d..711ceba 100644 --- a/omnibook.h +++ b/omnibook.h @@ -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 -- 2.43.5