4 #include <linux/version.h>
6 #if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 16)
7 #error This driver is for kernel versions 2.6.16 and later
10 #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 12, 0)
11 static int sysfs_create_groups(struct kobject *kobj,
12 const struct attribute_group **groups)
20 for (i = 0; groups[i]; i++) {
21 error = sysfs_create_group(kobj, groups[i]);
24 sysfs_remove_group(kobj, groups[i]);
31 static void sysfs_remove_groups(struct kobject *kobj,
32 const struct attribute_group **groups)
38 for (i = 0; groups[i]; i++)
39 sysfs_remove_group(kobj, groups[i]);
44 #if LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 21)
45 #if !(defined RHEL_MAJOR && RHEL_MAJOR == 5 && RHEL_MINOR >= 6)
46 /* Simplified version for compatibility */
47 struct i2c_board_info {
48 char type[I2C_NAME_SIZE];
55 #if LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 25)
56 /* Some older kernels have a different, useless struct i2c_device_id */
57 #define i2c_device_id i2c_device_id_compat
58 struct i2c_device_id {
59 char name[I2C_NAME_SIZE];
60 kernel_ulong_t driver_data /* Data private to the driver */
61 __attribute__((aligned(sizeof(kernel_ulong_t))));
65 #if LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 32)
66 static unsigned short empty_i2c[] = { I2C_CLIENT_END };
67 static struct i2c_client_address_data addr_data = {
68 .normal_i2c = normal_i2c,
74 /* Red Hat EL5 includes backports of these functions, so we can't redefine
76 #if LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 24)
77 #if !(defined RHEL_MAJOR && RHEL_MAJOR == 5 && RHEL_MINOR >= 5)
78 static inline int strict_strtoul(const char *cp, unsigned int base,
81 *res = simple_strtoul(cp, NULL, base);
85 static inline int strict_strtol(const char *cp, unsigned int base, long *res)
87 *res = simple_strtol(cp, NULL, base);
93 #if LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 28)
95 * Divide positive or negative dividend by positive divisor and round
96 * to closest integer. Result is undefined for negative divisors and
97 * for negative dividends if the divisor variable type is unsigned.
99 #define DIV_ROUND_CLOSEST(x, divisor)( \
102 typeof(divisor) __d = divisor; \
103 (((typeof(x))-1) > 0 || \
104 ((typeof(divisor))-1) > 0 || (__x) > 0) ? \
105 (((__x) + ((__d) / 2)) / (__d)) : \
106 (((__x) - ((__d) / 2)) / (__d)); \
111 #if LINUX_VERSION_CODE < KERNEL_VERSION(3, 2, 0)
113 i2c_smbus_read_word_swapped(const struct i2c_client *client, u8 command)
115 s32 value = i2c_smbus_read_word_data(client, command);
117 return (value < 0) ? value : swab16(value);
121 i2c_smbus_write_word_swapped(const struct i2c_client *client,
122 u8 command, u16 value)
124 return i2c_smbus_write_word_data(client, command, swab16(value));
128 #ifndef module_driver
130 * module_driver() - Helper macro for drivers that don't do anything
131 * special in module init/exit. This eliminates a lot of boilerplate.
132 * Each module may only use this macro once, and calling it replaces
133 * module_init() and module_exit().
135 * @__driver: driver name
136 * @__register: register function for this driver type
137 * @__unregister: unregister function for this driver type
138 * @...: Additional arguments to be passed to __register and __unregister.
140 * Use this macro to construct bus specific macros for registering
141 * drivers, and do not use it on its own.
143 #define module_driver(__driver, __register, __unregister, ...) \
144 static int __init __driver##_init(void) \
146 return __register(&(__driver) , ##__VA_ARGS__); \
148 module_init(__driver##_init); \
149 static void __exit __driver##_exit(void) \
151 __unregister(&(__driver) , ##__VA_ARGS__); \
153 module_exit(__driver##_exit);
156 #ifndef module_i2c_driver
158 * module_i2c_driver() - Helper macro for registering a I2C driver
159 * @__i2c_driver: i2c_driver struct
161 * Helper macro for I2C drivers which do not do anything special in module
162 * init/exit. This eliminates a lot of boilerplate. Each module may only
163 * use this macro once, and calling it replaces module_init() and module_exit()
165 #define module_i2c_driver(__i2c_driver) \
166 module_driver(__i2c_driver, i2c_add_driver, \
171 #define clamp_val SENSORS_LIMIT
175 #define kstrtol strict_strtol
178 #define kstrtoul strict_strtoul
181 #ifndef request_muxed_region
182 #define request_muxed_region(a, b, c) (true)
183 #define release_region(a, b)
186 #endif /* __COMPAT_H */