device.h 4.4 KB

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