All of lore.kernel.org
 help / color / mirror / Atom feed
From: Masahiro Yamada <yamada.m@jp.panasonic.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 1/2] dm: i2c: add DM_I2C_REQ_ALIAS to make sequence number optional
Date: Fri, 20 Feb 2015 20:38:07 +0900	[thread overview]
Message-ID: <1424432288-13252-2-git-send-email-yamada.m@jp.panasonic.com> (raw)
In-Reply-To: <1424432288-13252-1-git-send-email-yamada.m@jp.panasonic.com>

For I2C (and some other uclasses), all the devices are required to
have their own request sequence numbers to use them.  Otherwise,
uclass_get_device_by_seq() fails to get them.  To specify those
numbers, we have to add aliases to device trees.  As a result, the
"aliases" nodes grow bigger and bigger as we support more and more
drivers in driver model.
(See arch/arm/dts/uniphier-ph1-pro4-ref.dts for example.)

It is true that the sequence number is useful for identifying a
device with the same number independently of the binding order, but
it is painful to add an alias to every device.

This commit intends to make this feature optional.
If CONFIG_DM_I2C_SEQ_ALIAS is not defined, uclass_get_device() is
called instead of uclass_get_device_by_seq().  So we do not have to
add aliases of I2C devices.

In most cases, this should work well enough because device trees are
scanned from top to bottom and we usually describe device nodes in
the order we expect for binding.

Signed-off-by: Masahiro Yamada <yamada.m@jp.panasonic.com>
---

 common/cmd_i2c.c                |  2 +-
 drivers/i2c/Kconfig             | 10 ++++++++++
 drivers/i2c/i2c-uclass-compat.c |  2 +-
 drivers/i2c/i2c-uclass.c        |  4 +++-
 include/i2c.h                   | 17 +++++++++++++++++
 5 files changed, 32 insertions(+), 3 deletions(-)

diff --git a/common/cmd_i2c.c b/common/cmd_i2c.c
index fe8f77a..5fc927a 100644
--- a/common/cmd_i2c.c
+++ b/common/cmd_i2c.c
@@ -138,7 +138,7 @@ static int cmd_i2c_set_bus_num(unsigned int busnum)
 	struct udevice *bus;
 	int ret;
 
-	ret = uclass_get_device_by_seq(UCLASS_I2C, busnum, &bus);
+	ret = i2c_get_bus(busnum, &bus);
 	if (ret) {
 		debug("%s: No bus %d\n", __func__, busnum);
 		return ret;
diff --git a/drivers/i2c/Kconfig b/drivers/i2c/Kconfig
index 2cc776c..5c778ec 100644
--- a/drivers/i2c/Kconfig
+++ b/drivers/i2c/Kconfig
@@ -13,6 +13,16 @@ config DM_I2C
 	  enabled together (it is not possible to use driver model
 	  for one and not the other).
 
+config DM_I2C_SEQ_ALIAS
+	bool "Use aliases for numbering I2C buses"
+	depends on DM_I2C
+	default y
+	help
+	  If this option is enabled, each I2C bus is numbered base on its
+	  alias in the device tree to identify a device with the same number
+	  all the time.  Otherwise, I2C buses are numbered as they are scanned
+	  at binding.
+
 config SYS_I2C_UNIPHIER
 	bool "UniPhier I2C driver"
 	depends on ARCH_UNIPHIER && DM_I2C
diff --git a/drivers/i2c/i2c-uclass-compat.c b/drivers/i2c/i2c-uclass-compat.c
index 223f238..35736e8 100644
--- a/drivers/i2c/i2c-uclass-compat.c
+++ b/drivers/i2c/i2c-uclass-compat.c
@@ -35,7 +35,7 @@ int i2c_probe(uint8_t chip_addr)
 	struct udevice *bus, *dev;
 	int ret;
 
-	ret = uclass_get_device_by_seq(UCLASS_I2C, cur_busnum, &bus);
+	ret = i2c_get_bus(UCLASS_I2C, cur_busnum, &bus);
 	if (ret) {
 		debug("Cannot find I2C bus %d: err=%d\n", cur_busnum, ret);
 		return ret;
diff --git a/drivers/i2c/i2c-uclass.c b/drivers/i2c/i2c-uclass.c
index a6991bf..0992737 100644
--- a/drivers/i2c/i2c-uclass.c
+++ b/drivers/i2c/i2c-uclass.c
@@ -289,7 +289,7 @@ int i2c_get_chip_for_busnum(int busnum, int chip_addr, uint offset_len,
 	struct udevice *bus;
 	int ret;
 
-	ret = uclass_get_device_by_seq(UCLASS_I2C, busnum, &bus);
+	ret = i2c_get_bus(busnum, &bus);
 	if (ret) {
 		debug("Cannot find I2C bus %d\n", busnum);
 		return ret;
@@ -457,7 +457,9 @@ static int i2c_child_post_bind(struct udevice *dev)
 UCLASS_DRIVER(i2c) = {
 	.id		= UCLASS_I2C,
 	.name		= "i2c",
+#ifdef CONFIG_DM_I2C_SEQ_ALIAS
 	.flags		= DM_UC_FLAG_SEQ_ALIAS,
+#endif
 	.post_bind	= i2c_post_bind,
 	.post_probe	= i2c_post_probe,
 	.per_device_auto_alloc_size = sizeof(struct dm_i2c_bus),
diff --git a/include/i2c.h b/include/i2c.h
index 31b0389..6941df6 100644
--- a/include/i2c.h
+++ b/include/i2c.h
@@ -410,6 +410,23 @@ int i2c_get_chip(struct udevice *bus, uint chip_addr, uint offset_len,
 		 struct udevice **devp);
 
 /**
+ * i2c_get_bus() - get an I2C bus
+ *
+ * This returns the bus for the given bus number.
+ *
+ * @busnum:	Bus number.  If CONFIG_DM_I2C_SEQ_ALIAS is enabled, this is a
+ *		sequence number.  Otherwise, it is a simple index.
+ * @devp:	Stores pointer to a new bus if found
+ */
+#ifdef CONFIG_DM_I2C_SEQ_ALIAS
+#define i2c_get_bus(busnum, devp) \
+			uclass_get_device_by_seq(UCLASS_I2C, busnum, devp)
+#else
+#define i2c_get_bus(busnum, devp) \
+			uclass_get_device(UCLASS_I2C, busnum, devp)
+#endif
+
+/**
  * i2c_get_chip() - get a device to use to access a chip on a bus number
  *
  * This returns the device for the given chip address on a particular bus
-- 
1.9.1

  reply	other threads:[~2015-02-20 11:38 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-02-20 11:38 [U-Boot] [PATCH 0/2] dm: i2c: make request sequence number optional and disable it for UniPhier Masahiro Yamada
2015-02-20 11:38 ` Masahiro Yamada [this message]
2015-02-23 18:01   ` [U-Boot] [PATCH 1/2] dm: i2c: add DM_I2C_REQ_ALIAS to make sequence number optional Simon Glass
2015-02-24  3:16     ` Masahiro Yamada
2015-02-24  4:48       ` Simon Glass
2015-02-20 11:38 ` [U-Boot] [PATCH 2/2] ARM: UniPhier: disable DM_I2C_REQ_ALIAS to drop I2C aliases Masahiro Yamada

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=1424432288-13252-2-git-send-email-yamada.m@jp.panasonic.com \
    --to=yamada.m@jp.panasonic.com \
    --cc=u-boot@lists.denx.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.