1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
|
/*
* linux/device.h compatibility header
*/
/*
Copyright (C) 2004-2006 Frank Mori Hess <fmhess@users.sourceforge.net>
Copyright (C) 2005-2006 Ian Abbott
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __COMPAT_LINUX_DEVICE_H_
#define __COMPAT_LINUX_DEVICE_H_
#include <linux/version.h>
/*
* Notes:
*
* The 'struct device *' returned by the device_create() compatibility
* functions (assuming the return value is not an error pointer for which
* 'IS_ERR(ptr)' is true) is not really a 'struct device *' and should not
* be treated as such. For kernel versions 2.5.0 to 2.6.17, the return
* value is actually a 'struct class_device *' in disguise and we assume
* the 'parent' parameter of device_create() is also a 'struct class_device *'
* in disguise from a previous call to device_create().
*
* The main limitation is that we cannot use a *real* 'struct device *' as
* the parent parameter of device_create(), only a pointer from a previous
* call to device_create().
*
* Call COMEDI_DEVICE_CREATE() instead of device_create() for compatibility
* with kernel versions prior to 2.6.27.
*
* We do not currently support 'dev_get_drvdata()' and 'dev_set_drvdata()'
* for kernel versions prior to 2.6.26, so the 'drvdata' parameter of
* COMEDI_DEVICE_CREATE() is pretty useless.
*/
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
#include <pcmcia/cs_types.h>
struct device_driver {
char *name;
};
struct class;
struct device;
static inline struct class *class_create(struct module *owner, char *name)
{
return NULL;
}
static inline void class_destroy(struct class *cs)
{
}
static inline struct device *device_create(struct class *cls,
struct device *parent, dev_t devt, void *drvdata, char *fmt, ...)
{
return NULL;
}
static inline void device_destroy(struct class *cs, dev_t devt)
{
}
#else
#include_next <linux/device.h>
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,13)
#define class_create(owner, name) \
(struct class *)class_simple_create(owner, name)
#define class_destroy(cs) \
class_simple_destroy((struct class_simple *)(cs))
#define COMEDI_DEVICE_CREATE(cs, parent, devt, drvdata, fmt...) \
(struct device *)class_simple_device_add((struct class_simple *)(cs), \
devt, NULL, fmt)
#define device_destroy(cs, devt) \
class_simple_device_remove(devt)
#else
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15)
#define COMEDI_DEVICE_CREATE(cs, parent, devt, drvdata, fmt...) \
(struct device *)class_device_create(cs, devt, NULL, fmt)
#define device_destroy(cs, devt) \
class_device_destroy(cs, devt)
#else
/* device_create does not work for NULL parent with 2.6.18, not sure
exactly which kernel version it was fixed in. */
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
#define COMEDI_DEVICE_CREATE(cs, parent, devt, drvdata, fmt...) \
(struct device *)class_device_create( \
cs, (struct class_device *)parent, devt, NULL, fmt)
#define device_destroy(cs, devt) \
class_device_destroy(cs, devt)
#else
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26)
#define COMEDI_DEVICE_CREATE(cs, parent, devt, drvdata, fmt...) \
device_create(cs, parent, devt, fmt)
#else
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27)
#define COMEDI_DEVICE_CREATE(cs, parent, devt, drvdata, fmt...) \
device_create_drvdata(cs, parent, devt, drvdata, fmt)
#else
#define COMEDI_DEVICE_CREATE(cs, parent, devt, drvdata, fmt...) \
device_create(cs, parent, devt, drvdata, fmt)
#endif // LINUX_VERSION_CODE < KERNEL_VERSION(2,6,27)
#endif // LINUX_VERSION_CODE < KERNEL_VERSION(2,6,26)
#endif // LINUX_VERSION_CODE < KERNEL_VERSION(2,6,18)
#endif // LINUX_VERSION_CODE < KERNEL_VERSION(2,6,15)
#endif // LINUX_VERSION_CODE < KERNEL_VERSION(2,6,13)
#endif // LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
#endif // __COMPAT_LINUX_DEVICE_H_
|