* [PATCH 1/2] i2c: Create for_each_i2c_adapter() @ 2015-11-11 16:05 Sascha Hauer 2015-11-11 16:05 ` [PATCH 2/2] i2c_probe: Make command easier to work with Sascha Hauer 0 siblings, 1 reply; 2+ messages in thread From: Sascha Hauer @ 2015-11-11 16:05 UTC (permalink / raw) To: Barebox List This can be used by the i2c_probe command to iterate over i2c adapters. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> --- drivers/i2c/i2c.c | 8 ++++---- include/i2c/i2c.h | 4 ++++ 2 files changed, 8 insertions(+), 4 deletions(-) diff --git a/drivers/i2c/i2c.c b/drivers/i2c/i2c.c index 52aaea8..9ed96da 100644 --- a/drivers/i2c/i2c.c +++ b/drivers/i2c/i2c.c @@ -42,7 +42,7 @@ struct boardinfo { }; static LIST_HEAD(board_list); -static LIST_HEAD(adapter_list); +LIST_HEAD(i2c_adapter_list); /** * i2c_transfer - execute a single or combined I2C message @@ -529,7 +529,7 @@ struct i2c_adapter *i2c_get_adapter(int busnum) { struct i2c_adapter *adap; - list_for_each_entry(adap, &adapter_list, list) + for_each_i2c_adapter(adap) if (adap->nr == busnum) return adap; return NULL; @@ -539,7 +539,7 @@ struct i2c_adapter *of_find_i2c_adapter_by_node(struct device_node *node) { struct i2c_adapter *adap; - list_for_each_entry(adap, &adapter_list, list) + for_each_i2c_adapter(adap) if (adap->dev.device_node == node) return adap; @@ -584,7 +584,7 @@ int i2c_add_numbered_adapter(struct i2c_adapter *adapter) if (ret) return ret; - list_add_tail(&adapter->list, &adapter_list); + list_add_tail(&adapter->list, &i2c_adapter_list); /* populate children from any i2c device tables */ scan_boardinfo(adapter); diff --git a/include/i2c/i2c.h b/include/i2c/i2c.h index 12e4827..3fab76d9 100644 --- a/include/i2c/i2c.h +++ b/include/i2c/i2c.h @@ -235,6 +235,10 @@ extern int i2c_add_numbered_adapter(struct i2c_adapter *adapter); struct i2c_adapter *i2c_get_adapter(int busnum); struct i2c_adapter *of_find_i2c_adapter_by_node(struct device_node *node); +extern struct list_head i2c_adapter_list; +#define for_each_i2c_adapter(adap) \ + list_for_each_entry(adap, &i2c_adapter_list, list) + /* For devices that use several addresses, use i2c_new_dummy() to make * client handles for the extra addresses. */ -- 2.6.1 _______________________________________________ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox ^ permalink raw reply [flat|nested] 2+ messages in thread
* [PATCH 2/2] i2c_probe: Make command easier to work with 2015-11-11 16:05 [PATCH 1/2] i2c: Create for_each_i2c_adapter() Sascha Hauer @ 2015-11-11 16:05 ` Sascha Hauer 0 siblings, 0 replies; 2+ messages in thread From: Sascha Hauer @ 2015-11-11 16:05 UTC (permalink / raw) To: Barebox List Instead of insisting on multiple parameters just use sane defaults. This allows us to scan all addresses on all busses which is normally what one wants to get an overview over devices on i2c busses. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de> --- commands/i2c.c | 56 +++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 37 insertions(+), 19 deletions(-) diff --git a/commands/i2c.c b/commands/i2c.c index d6c5412..f4ffc99 100644 --- a/commands/i2c.c +++ b/commands/i2c.c @@ -22,30 +22,16 @@ #include <getopt.h> #include <i2c/i2c.h> -static int do_i2c_probe(int argc, char *argv[]) +static void i2c_probe_range(struct i2c_adapter *adapter, int startaddr, int stopaddr) { - struct i2c_adapter *adapter; - struct i2c_client client; - int startaddr = -1, stopaddr = -1, addr, ret; + struct i2c_client client = {}; + int addr; + int ret; u8 reg; - if (argc < 4) - return COMMAND_ERROR_USAGE; - - adapter = i2c_get_adapter(simple_strtoul(argv[1], NULL, 0)); - if (!adapter) - return -ENODEV; client.adapter = adapter; - startaddr = simple_strtol(argv[2], NULL, 0); - stopaddr = simple_strtol(argv[3], NULL, 0); - if ((startaddr == -1) || (stopaddr == -1) || (startaddr > stopaddr)) - return COMMAND_ERROR_USAGE; - - if (stopaddr > 0x7F) - stopaddr = 0x7F; - - printf("probing i2c range 0x%02x - 0x%02x :\n", startaddr, stopaddr); + printf("probing i2c%d range 0x%02x-0x%02x: ", adapter->nr, startaddr, stopaddr); for (addr = startaddr; addr <= stopaddr; addr++) { client.addr = addr; ret = i2c_write_reg(&client, 0x00, ®, 0); @@ -53,6 +39,38 @@ static int do_i2c_probe(int argc, char *argv[]) printf("0x%02x ", addr); } printf("\n"); +} + +static int do_i2c_probe(int argc, char *argv[]) +{ + struct i2c_adapter *adapter = NULL; + int startaddr = 0, stopaddr = 0x7f; + + if (argc > 1) { + adapter = i2c_get_adapter(simple_strtoul(argv[1], NULL, 0)); + if (!adapter) + return -ENODEV; + } + + if (argc > 2) + startaddr = simple_strtol(argv[2], NULL, 0); + if (argc > 3) + startaddr = simple_strtol(argv[3], NULL, 0); + + + if (startaddr > stopaddr) + return COMMAND_ERROR_USAGE; + + if (stopaddr > 0x7F) + stopaddr = 0x7F; + + if (adapter) { + i2c_probe_range(adapter, startaddr, stopaddr); + } else { + for_each_i2c_adapter(adapter) + i2c_probe_range(adapter, startaddr, stopaddr); + } + return 0; } -- 2.6.1 _______________________________________________ barebox mailing list barebox@lists.infradead.org http://lists.infradead.org/mailman/listinfo/barebox ^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-11-11 16:05 UTC | newest] Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2015-11-11 16:05 [PATCH 1/2] i2c: Create for_each_i2c_adapter() Sascha Hauer 2015-11-11 16:05 ` [PATCH 2/2] i2c_probe: Make command easier to work with Sascha Hauer
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox