From: Wolfram Sang <wsa@the-dreams.de>
To: linux-i2c@vger.kernel.org
Cc: linux-sh@vger.kernel.org, Magnus Damm <magnus.damm@gmail.com>,
Simon Horman <horms@verge.net.au>,
Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
Geert Uytterhoeven <geert@linux-m68k.org>,
Wolfram Sang <wsa@the-dreams.de>,
Andrey Danin <danindrey@mail.ru>,
linux-tegra@vger.kernel.org
Subject: [RFC 4/9] i2c: apply address offset for slaves, too
Date: Fri, 17 Jul 2015 16:08:24 +0200 [thread overview]
Message-ID: <1437142109-31975-5-git-send-email-wsa@the-dreams.de> (raw)
In-Reply-To: <1437142109-31975-1-git-send-email-wsa@the-dreams.de>
From: Wolfram Sang <wsa+renesas@sang-engineering.com>
We want a separate address range for being an I2C slave. Add an offset
of 0x1000, so it can be combined with ten bit addresses as well. Add a
separate function to create the address value, we will need it later in
other places.
Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com>
---
drivers/i2c/i2c-core.c | 19 ++++++++++++++++---
1 file changed, 16 insertions(+), 3 deletions(-)
diff --git a/drivers/i2c/i2c-core.c b/drivers/i2c/i2c-core.c
index e6d4935161e490..a807e272e1fc2e 100644
--- a/drivers/i2c/i2c-core.c
+++ b/drivers/i2c/i2c-core.c
@@ -776,6 +776,21 @@ struct i2c_client *i2c_verify_client(struct device *dev)
EXPORT_SYMBOL(i2c_verify_client);
+/* Return a unique address which takes the flags of the client into account */
+static unsigned short i2c_encode_flags_to_addr(struct i2c_client *client)
+{
+ unsigned short addr = client->addr;
+
+ /* For some client flags, add an arbitrary offset to avoid collisions */
+ if (client->flags & I2C_CLIENT_TEN)
+ addr |= 0xa000;
+
+ if (client->flags & I2C_CLIENT_SLAVE)
+ addr |= 0x1000;
+
+ return addr;
+}
+
/* This is a permissive address validity check, I2C address map constraints
* are purposely not enforced, except for the general call address. */
static int i2c_check_client_addr_validity(const struct i2c_client *client)
@@ -921,10 +936,8 @@ static void i2c_dev_set_name(struct i2c_adapter *adap,
return;
}
- /* For 10-bit clients, add an arbitrary offset to avoid collisions */
dev_set_name(&client->dev, "%d-%04x", i2c_adapter_id(adap),
- client->addr | ((client->flags & I2C_CLIENT_TEN)
- ? 0xa000 : 0));
+ i2c_encode_flags_to_addr(client));
}
/**
--
2.1.4
next prev parent reply other threads:[~2015-07-17 14:08 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-07-17 14:08 [RFC 0/9] i2c: slave: improve i2c client address spaces and their DT support Wolfram Sang
2015-07-17 14:08 ` Wolfram Sang [this message]
2015-07-17 14:08 ` [RFC 5/9] i2c: rename address check functions Wolfram Sang
2015-07-17 14:08 ` [RFC 7/9] i2c: apply DT flags when probing Wolfram Sang
2015-07-20 7:23 ` [RFC 0/9] i2c: slave: improve i2c client address spaces and their DT support Andrey Danin
[not found] ` <55ACA1D8.6010403-JGs/UdohzUI@public.gmane.org>
2015-07-20 8:52 ` Wolfram Sang
2015-07-20 8:59 ` Andrey Danin
[not found] ` <1437142109-31975-1-git-send-email-wsa-z923LK4zBo2bacvFa/9K2g@public.gmane.org>
2015-07-17 14:08 ` [RFC 1/9] i2c: tegra: implement slave mode Wolfram Sang
2015-07-17 14:08 ` [RFC 2/9] dt-bindings: add header for generic I2C flags in bindings Wolfram Sang
2015-07-17 14:08 ` [RFC 3/9] i2c: add a flag to mark clients as slaves Wolfram Sang
2015-07-17 14:08 ` [RFC 6/9] i2c: make address check indpendent from client struct Wolfram Sang
2015-07-17 14:08 ` [RFC 8/9] i2c: take address space into account when checking for used addresses Wolfram Sang
2015-07-17 14:08 ` [RFC 9/9] dts: tegra: WIP: hack dts to test new dt flags for i2c Wolfram Sang
2015-07-17 14:11 ` Wolfram Sang
2015-07-20 7:28 ` Andrey Danin
2015-07-20 9:03 ` Wolfram Sang
[not found] ` <1437142109-31975-10-git-send-email-wsa-z923LK4zBo2bacvFa/9K2g@public.gmane.org>
2015-07-20 7:53 ` Laurent Pinchart
2015-07-20 8:45 ` Wolfram Sang
2015-07-20 16:10 ` Rob Herring
2015-07-20 22:09 ` Stephen Warren
[not found] ` <55AD71A6.4030105-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2015-07-21 6:55 ` Wolfram Sang
2015-07-20 22:13 ` [RFC 0/9] i2c: slave: improve i2c client address spaces and their DT support Stephen Warren
[not found] ` <55AD7279.5090203-3lzwWm7+Weoh9ZMKESR00Q@public.gmane.org>
2015-07-21 7:00 ` 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=1437142109-31975-5-git-send-email-wsa@the-dreams.de \
--to=wsa@the-dreams.de \
--cc=danindrey@mail.ru \
--cc=geert@linux-m68k.org \
--cc=horms@verge.net.au \
--cc=laurent.pinchart@ideasonboard.com \
--cc=linux-i2c@vger.kernel.org \
--cc=linux-sh@vger.kernel.org \
--cc=linux-tegra@vger.kernel.org \
--cc=magnus.damm@gmail.com \
/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).