diff options
author | Wolfram Sang <wsa+renesas@sang-engineering.com> | 2014-11-18 19:04:53 +0300 |
---|---|---|
committer | Wolfram Sang <wsa@the-dreams.de> | 2014-12-12 00:25:53 +0300 |
commit | 4b1acc43331d6c716c331a61477660dc20c8b59c (patch) | |
tree | bf4138594b8e48384972f56c499c895ec9fe0de5 /drivers/i2c | |
parent | 40ed1b4caf76e27807a49d42a41f43e8393a7607 (diff) | |
download | linux-4b1acc43331d6c716c331a61477660dc20c8b59c.tar.xz |
i2c: core changes for slave support
Finally(!), make Linux support being an I2C slave. Most of the existing
infrastructure is reused. We mainly add i2c_slave_register/unregister()
calls which tells i2c bus drivers to activate the slave mode. Then, they
also get a callback to report slave events to.
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
Diffstat (limited to 'drivers/i2c')
-rw-r--r-- | drivers/i2c/i2c-core.c | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c index 3105bd273f70..c09d06bf4d9b 100644 --- a/drivers/i2c/i2c-core.c +++ b/drivers/i2c/i2c-core.c @@ -24,6 +24,7 @@ (c) 2013 Wolfram Sang <wsa@the-dreams.de> I2C ACPI code Copyright (C) 2014 Intel Corp Author: Lan Tianyu <tianyu.lan@intel.com> + I2C slave support (c) 2014 by Wolfram Sang <wsa@sang-engineering.com> */ #include <linux/module.h> @@ -2911,6 +2912,54 @@ trace: } EXPORT_SYMBOL(i2c_smbus_xfer); +int i2c_slave_register(struct i2c_client *client, i2c_slave_cb_t slave_cb) +{ + int ret; + + if (!client || !slave_cb) + return -EINVAL; + + if (!(client->flags & I2C_CLIENT_TEN)) { + /* Enforce stricter address checking */ + ret = i2c_check_addr_validity(client->addr); + if (ret) + return ret; + } + + if (!client->adapter->algo->reg_slave) + return -EOPNOTSUPP; + + client->slave_cb = slave_cb; + + i2c_lock_adapter(client->adapter); + ret = client->adapter->algo->reg_slave(client); + i2c_unlock_adapter(client->adapter); + + if (ret) + client->slave_cb = NULL; + + return ret; +} +EXPORT_SYMBOL_GPL(i2c_slave_register); + +int i2c_slave_unregister(struct i2c_client *client) +{ + int ret; + + if (!client->adapter->algo->unreg_slave) + return -EOPNOTSUPP; + + i2c_lock_adapter(client->adapter); + ret = client->adapter->algo->unreg_slave(client); + i2c_unlock_adapter(client->adapter); + + if (ret == 0) + client->slave_cb = NULL; + + return ret; +} +EXPORT_SYMBOL_GPL(i2c_slave_unregister); + MODULE_AUTHOR("Simon G. Vogl <simon@tk.uni-linz.ac.at>"); MODULE_DESCRIPTION("I2C-Bus main module"); MODULE_LICENSE("GPL"); |