@@ -2536,6 +2536,48 @@ trace:
}
EXPORT_SYMBOL(i2c_smbus_xfer);
+int i2c_slave_register(struct i2c_client *client,
+ int (*slave_cb)(struct i2c_client *, enum i2c_slave_event, u8 *))
+{
+ u16 addr = client->addr;
+ int ret;
+
+ if (!slave_cb)
+ return -EINVAL;
+
+ ret = i2c_check_addr_validity(addr);
+ if (ret)
+ return ret;
+
+ if (!client->adapter->algo->reg_slave)
+ return -EOPNOTSUPP;
+
+ client->slave_cb = slave_cb;
+
+ ret = client->adapter->algo->reg_slave(client);
+ 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;
+
+ ret = client->adapter->algo->unreg_slave(client);
+
+ 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");
new file mode 100644
@@ -0,0 +1,28 @@
+/*
+ * i2c-slave.h - Linux I2C slave support
+ *
+ * Copyright (C) 2014 by Wolfram Sang
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; version 2 of the License.
+ */
+
+#include <linux/i2c.h>
+
+#ifndef _LINUX_I2C_SLAVE_H
+#define _LINUX_I2C_SLAVE_H
+
+enum i2c_slave_event {
+ I2C_SLAVE_REQ_READ,
+ I2C_SLAVE_REQ_WRITE,
+ I2C_SLAVE_STOP,
+};
+
+extern int i2c_slave_register(struct i2c_client *client, int (*slave_cb)(struct i2c_client *, enum i2c_slave_event, u8 *));
+extern int i2c_slave_unregister(struct i2c_client *client);
+
+#define i2c_slave_event(__client, __event, __value) \
+ client->slave_cb(__client, __event, __value)
+
+#endif
@@ -46,6 +46,7 @@ struct i2c_client;
struct i2c_driver;
union i2c_smbus_data;
struct i2c_board_info;
+enum i2c_slave_event;
struct module;
@@ -224,6 +225,7 @@ struct i2c_client {
struct device dev; /* the device structure */
int irq; /* irq issued by device */
struct list_head detected;
+ int (*slave_cb)(struct i2c_client *, enum i2c_slave_event, u8 *);
};
#define to_i2c_client(d) container_of(d, struct i2c_client, dev)
@@ -377,6 +379,9 @@ struct i2c_algorithm {
/* To determine what the adapter supports */
u32 (*functionality) (struct i2c_adapter *);
+
+ int (*reg_slave)(struct i2c_client *client);
+ int (*unreg_slave)(struct i2c_client *client);
};
/**