Commit 2bb5095a authored by Jean Delvare's avatar Jean Delvare

i2c: Provide compatibility links for i2c adapters

Some user-space applications may be relying on i2c adapters showing up
as class devices in sysfs. Provide compatibility links for them for
the time being. We will remove them after a long transition period.
Signed-off-by: default avatarJean Delvare <khali@linux-fr.org>
Cc: Kay Sievers <kay.sievers@vrfy.org>
parent 4f8cf824
...@@ -27,6 +27,14 @@ config I2C_BOARDINFO ...@@ -27,6 +27,14 @@ config I2C_BOARDINFO
boolean boolean
default y default y
config I2C_COMPAT
boolean "Enable compatibility bits for old user-space"
default y
help
Say Y here if you intend to run lm-sensors 3.1.1 or older, or any
other user-space package which expects i2c adapters to be class
devices. If you don't know, say Y.
config I2C_CHARDEV config I2C_CHARDEV
tristate "I2C device interface" tristate "I2C device interface"
help help
......
...@@ -538,6 +538,10 @@ static struct device_type i2c_adapter_type = { ...@@ -538,6 +538,10 @@ static struct device_type i2c_adapter_type = {
.release = i2c_adapter_dev_release, .release = i2c_adapter_dev_release,
}; };
#ifdef CONFIG_I2C_COMPAT
static struct class_compat *i2c_adapter_compat_class;
#endif
static void i2c_scan_static_board_info(struct i2c_adapter *adapter) static void i2c_scan_static_board_info(struct i2c_adapter *adapter)
{ {
struct i2c_devinfo *devinfo; struct i2c_devinfo *devinfo;
...@@ -595,6 +599,14 @@ static int i2c_register_adapter(struct i2c_adapter *adap) ...@@ -595,6 +599,14 @@ static int i2c_register_adapter(struct i2c_adapter *adap)
dev_dbg(&adap->dev, "adapter [%s] registered\n", adap->name); dev_dbg(&adap->dev, "adapter [%s] registered\n", adap->name);
#ifdef CONFIG_I2C_COMPAT
res = class_compat_create_link(i2c_adapter_compat_class, &adap->dev,
adap->dev.parent);
if (res)
dev_warn(&adap->dev,
"Failed to create compatibility class link\n");
#endif
/* create pre-declared device nodes */ /* create pre-declared device nodes */
if (adap->nr < __i2c_first_dynamic_bus_num) if (adap->nr < __i2c_first_dynamic_bus_num)
i2c_scan_static_board_info(adap); i2c_scan_static_board_info(adap);
...@@ -773,6 +785,11 @@ int i2c_del_adapter(struct i2c_adapter *adap) ...@@ -773,6 +785,11 @@ int i2c_del_adapter(struct i2c_adapter *adap)
checking the returned value. */ checking the returned value. */
res = device_for_each_child(&adap->dev, NULL, __unregister_client); res = device_for_each_child(&adap->dev, NULL, __unregister_client);
#ifdef CONFIG_I2C_COMPAT
class_compat_remove_link(i2c_adapter_compat_class, &adap->dev,
adap->dev.parent);
#endif
/* clean up the sysfs representation */ /* clean up the sysfs representation */
init_completion(&adap->dev_released); init_completion(&adap->dev_released);
device_unregister(&adap->dev); device_unregister(&adap->dev);
...@@ -978,12 +995,23 @@ static int __init i2c_init(void) ...@@ -978,12 +995,23 @@ static int __init i2c_init(void)
retval = bus_register(&i2c_bus_type); retval = bus_register(&i2c_bus_type);
if (retval) if (retval)
return retval; return retval;
#ifdef CONFIG_I2C_COMPAT
i2c_adapter_compat_class = class_compat_register("i2c-adapter");
if (!i2c_adapter_compat_class) {
retval = -ENOMEM;
goto bus_err;
}
#endif
retval = i2c_add_driver(&dummy_driver); retval = i2c_add_driver(&dummy_driver);
if (retval) if (retval)
goto bus_err; goto class_err;
return 0; return 0;
class_err:
#ifdef CONFIG_I2C_COMPAT
class_compat_unregister(i2c_adapter_compat_class);
bus_err: bus_err:
#endif
bus_unregister(&i2c_bus_type); bus_unregister(&i2c_bus_type);
return retval; return retval;
} }
...@@ -991,6 +1019,9 @@ static int __init i2c_init(void) ...@@ -991,6 +1019,9 @@ static int __init i2c_init(void)
static void __exit i2c_exit(void) static void __exit i2c_exit(void)
{ {
i2c_del_driver(&dummy_driver); i2c_del_driver(&dummy_driver);
#ifdef CONFIG_I2C_COMPAT
class_compat_unregister(i2c_adapter_compat_class);
#endif
bus_unregister(&i2c_bus_type); bus_unregister(&i2c_bus_type);
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment