i2c changes in 2.6.15+
Attached is an informational (not meant to be applied as-is, but maybe
good for testing) patch for i2c changes in 2.6.15 and later kernels.
Compile-tested only on the latest FC5test2/Rawhide 2.6.16-rc1-something
kernel (which reports itself as 2.6.15, but that's outside of the scope
of this patch and not taken into account). I haven't actually used the
patched modules with any kernel. The patch also removes the
EM8300_I2C_FORCE_*_API flags for clarity, maybe they can be restored by
someone who groks the code and i2c versions better.
Notes:
i2c_driver.flags is gone in 2.6.16, apparently without a replacement.
i2c_driver.{name,owner} have moved to i2c_driver.driver.{name,owner} in
2.6.16. That change could apparently be done on some earlier kernels
too; at least many in-kernel drivers were changed like that in 2.6.15.
This patch however does that only for >= 2.6.16.
Documentation/i2c/writing-clients was changed in 2.6.15 to say this
about i2c_driver.name:
---
The name field must match the driver name, including the case. It must
not contain spaces, and may be up to 31 characters long.
---
For simplicity, this patch changes the name accordingly for all kernel
versions.
[em8300-i2c.patch]
Index: modules/adv717x.c
===================================================================
RCS file: /cvsroot/dxr3/em8300/modules/adv717x.c,v
retrieving revision 1.49
diff -u -r1.49 adv717x.c
--- modules/adv717x.c 5 Nov 2005 01:12:13 -0000 1.49
+++ modules/adv717x.c 21 Jan 2006 16:37:57 -0000
@@ -199,12 +199,19 @@
/* This is the driver that will be inserted */
static struct i2c_driver adv717x_driver = {
-#if defined(EM8300_I2C_FORCE_NEW_API) || (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,54) && !defined(EM8300_I2C_FORCE_OLD_API))
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,54)
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
+ .driver = {
+ .owner = THIS_MODULE,
+ .name = "adv717x",
+ },
+#else
.owner = THIS_MODULE,
+ .name = "adv717x",
+ .flags = I2C_DF_NOTIFY,
+#endif
#endif
- .name = "ADV717X video encoder driver",
.id = I2C_DRIVERID_ADV717X,
- .flags = I2C_DF_NOTIFY,
.attach_adapter = &adv717x_attach_adapter,
.detach_client = &adv717x_detach_client,
.command = &adv717x_command
Index: modules/bt865.c
===================================================================
RCS file: /cvsroot/dxr3/em8300/modules/bt865.c,v
retrieving revision 1.40
diff -u -r1.40 bt865.c
--- modules/bt865.c 15 Nov 2005 07:15:16 -0000 1.40
+++ modules/bt865.c 21 Jan 2006 16:37:57 -0000
@@ -87,12 +87,19 @@
/* This is the driver that will be inserted */
static struct i2c_driver bt865_driver = {
-#if defined(EM8300_I2C_FORCE_NEW_API) || (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,54) && !defined(EM8300_I2C_FORCE_OLD_API))
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,54)
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
+ .driver = {
+ .owner = THIS_MODULE,
+ .name = "bt865",
+ },
+#else
.owner = THIS_MODULE,
+ .name = "bt865",
+ .flags = I2C_DF_NOTIFY,
+#endif
#endif
- .name = "BT865 video encoder driver",
.id = I2C_DRIVERID_BT865,
- .flags = I2C_DF_NOTIFY,
.attach_adapter = &bt865_attach_adapter,
.detach_client = &bt865_detach_client,
.command = &bt865_command
Index: modules/em8300_i2c.c
===================================================================
RCS file: /cvsroot/dxr3/em8300/modules/em8300_i2c.c,v
retrieving revision 1.24
diff -u -r1.24 em8300_i2c.c
--- modules/em8300_i2c.c 18 Nov 2005 23:29:07 -0000 1.24
+++ modules/em8300_i2c.c 21 Jan 2006 16:37:57 -0000
@@ -77,8 +77,12 @@
static int em8300_i2c_lock_client(struct i2c_client *client)
{
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,54) && !defined(EM8300_I2C_FORCE_OLD_API))
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,54)
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
+ if (!try_module_get(client->driver->driver.owner)) {
+#else
if (!try_module_get(client->driver->owner)) {
+#endif
printk(KERN_ERR "em8300_i2c: Unable to lock client module\n");
return -ENODEV;
}
@@ -129,9 +133,13 @@
case I2C_DRIVERID_ADV717X:
case I2C_DRIVERID_BT865:
em->encoder = NULL;
-#if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,54) && !defined(EM8300_I2C_FORCE_OLD_API))
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,54)
+#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16)
+ module_put(client->driver->driver.owner);
+#else
module_put(client->driver->owner);
#endif
+#endif
break;
}