From: Wolfram Sang <wsa-z923LK4zBo2bacvFa/9K2g@public.gmane.org>
To: linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Cc: linux-sh-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
Wolfram Sang <wsa-z923LK4zBo2bacvFa/9K2g@public.gmane.org>
Subject: [PATCH 1/3] WIP: i2c core changes for slave support
Date: Tue, 2 Sep 2014 20:02:39 +0200 [thread overview]
Message-ID: <1409680961-12632-2-git-send-email-wsa@the-dreams.de> (raw)
In-Reply-To: <1409680961-12632-1-git-send-email-wsa-z923LK4zBo2bacvFa/9K2g@public.gmane.org>
From: Wolfram Sang <wsa+renesas-jBu1N2QxHDJrcw3mvpCnnVaTQe2KTcn/@public.gmane.org>
Not for upstream yet.
Signed-off-by: Wolfram Sang <wsa+renesas-jBu1N2QxHDJrcw3mvpCnnVaTQe2KTcn/@public.gmane.org>
---
drivers/i2c/i2c-core.c | 42 ++++++++++++++++++++++++++++++++++++++++++
include/linux/i2c-slave.h | 28 ++++++++++++++++++++++++++++
include/linux/i2c.h | 5 +++++
3 files changed, 75 insertions(+)
create mode 100644 include/linux/i2c-slave.h
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index 632057a44615..63ea70e5c274 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -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-nD9nYVNVf00W+b/DJNNodF6hYfS7NtTn@public.gmane.org>");
MODULE_DESCRIPTION("I2C-Bus main module");
MODULE_LICENSE("GPL");
diff --git a/include/linux/i2c-slave.h b/include/linux/i2c-slave.h
new file mode 100644
index 000000000000..ddc9493cb5e7
--- /dev/null
+++ b/include/linux/i2c-slave.h
@@ -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
diff --git a/include/linux/i2c.h b/include/linux/i2c.h
index a95efeb53a8b..8541aa6b0178 100644
--- a/include/linux/i2c.h
+++ b/include/linux/i2c.h
@@ -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);
};
/**
--
2.0.0
next prev parent reply other threads:[~2014-09-02 18:02 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2014-09-02 18:02 [PATCH 0/3] WIP: i2c slave support Wolfram Sang
[not found] ` <1409680961-12632-1-git-send-email-wsa-z923LK4zBo2bacvFa/9K2g@public.gmane.org>
2014-09-02 18:02 ` Wolfram Sang [this message]
2014-09-02 18:02 ` [PATCH 2/3] WIP: sketch of an slave-eeprom simulator Wolfram Sang
2014-09-02 18:02 ` [PATCH 3/3] WIP: adapt dts for i2c slave use Wolfram Sang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1409680961-12632-2-git-send-email-wsa@the-dreams.de \
--to=wsa-z923lk4zbo2bacvfa/9k2g@public.gmane.org \
--cc=linux-i2c-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
--cc=linux-sh-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).