diff mbox

[U-Boot] i2c: Set default I2C bus number

Message ID 1490094505-17929-1-git-send-email-lukma@denx.de
State Accepted
Commit e46f8a3309fb2628940d3e2806c954d84f910165
Delegated to: Heiko Schocher
Headers show

Commit Message

Lukasz Majewski March 21, 2017, 11:08 a.m. UTC
This patch allows using i2c commands (e.g. "i2c probe", "i2c md", etc)
without the need to first select the bus number with e.g. "i2c dev 0".

This is the "i2c" command behavior similar to the one from pre DM, where
by default bus 0 was immediately accessible.

Signed-off-by: Lukasz Majewski <lukma@denx.de>
---
 cmd/i2c.c           | 10 ++++++++++
 drivers/i2c/Kconfig | 14 ++++++++++++++
 2 files changed, 24 insertions(+)
diff mbox

Patch

diff --git a/cmd/i2c.c b/cmd/i2c.c
index 473153f..3dd7c6b 100644
--- a/cmd/i2c.c
+++ b/cmd/i2c.c
@@ -151,6 +151,16 @@  static int cmd_i2c_set_bus_num(unsigned int busnum)
 
 static int i2c_get_cur_bus(struct udevice **busp)
 {
+#ifdef CONFIG_I2C_SET_DEFAULT_BUS_NUM
+	if (!i2c_cur_bus) {
+		if (cmd_i2c_set_bus_num(CONFIG_I2C_DEFAULT_BUS_NUMBER)) {
+			printf("Default I2C bus %d not found\n",
+			       CONFIG_I2C_DEFAULT_BUS_NUMBER);
+			return -ENODEV;
+		}
+	}
+#endif
+
 	if (!i2c_cur_bus) {
 		puts("No I2C bus selected\n");
 		return -ENODEV;
diff --git a/drivers/i2c/Kconfig b/drivers/i2c/Kconfig
index 8ac7aaf..4e9afc1 100644
--- a/drivers/i2c/Kconfig
+++ b/drivers/i2c/Kconfig
@@ -49,6 +49,20 @@  config I2C_CROS_EC_LDO
 	avoid duplicating the logic in the TPS65090 regulator driver for
 	enabling/disabling an LDO.
 
+config I2C_SET_DEFAULT_BUS_NUM
+	bool "Set default I2C bus number"
+	depends on DM_I2C
+	help
+	  Set default number of I2C bus to be accessed. This option provides
+	  behaviour similar to old (i.e. pre DM) I2C bus driver.
+
+config I2C_DEFAULT_BUS_NUMBER
+	hex "I2C default bus number"
+	depends on I2C_SET_DEFAULT_BUS_NUM
+	default 0x0
+	help
+	  Number of default I2C bus to use
+
 config DM_I2C_GPIO
 	bool "Enable Driver Model for software emulated I2C bus driver"
 	depends on DM_I2C && DM_GPIO