i2c: add support for offset overflow in to chip address
Subsystems (2)
cover i2c: add support for offset overflow in to chip address
Add support for devices that can overflow the offset in to the chip address. This makes the devices effectively steal consecutive chip addresses.
Also improve i2c testing and add new test for this new addressing mode.
Robert Beckett (3):
i2c: add support for offset overflow in to address
dm: i2c: EEPROM simulator allow tests visibility of addr and offset
dm: i2c: EEPROM simulator add tests for addr offset mask
arch/sandbox/include/asm/test.h | 7 ++ drivers/i2c/i2c-uclass.c | 34 ++++++++-- drivers/misc/i2c_eeprom_emul.c | 80 +++++++++++++++++------ include/i2c.h | 33 ++++++++++ test/dm/i2c.c | 112 ++++++++++++++++++++++++++++---- 5 files changed, 226 insertions(+), 40 deletions(-)
Signature · 1 line
2.20.1
PATCH 1/3 i2c: add support for offset overflow in to address
Some devices (2 wire eeproms for example) use some bits from the chip address to represent the high bits of the offset instead of or as well as using multiple bytes for the offset, effectively stealing chip addresses on the bus.
Add a chip offset mask that can be set for any i2c chip which gets filled with the offset overflow during offset setup.
---
drivers/i2c/i2c-uclass.c | 34 +++++++++++++++++++++++++++------- include/i2c.h | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 7 deletions(-)
drivers/i2c/i2c-uclass.c +27 -7
@@ -52,16 +52,19 @@ void i2c_dump_msgs(struct i2c_msg *msg, int nmsgs)static int i2c_setup_offset (struct dm_i2c_chip *chip,uint offset,uint8_t offset_buf[],struct i2c_msg *msg) { -int offset_len; +int offset_len = chip->offset_len; msg->addr = chip->chip_addr; +if (chip->chip_addr_offset_mask) + msg->addr |= (offset >> (8 * offset_len)) & + chip->chip_addr_offset_mask; msg->flags = chip->flags &DM_I2C_CHIP_10BIT ?I2C_M_TEN :0 ; msg->len = chip->offset_len; msg->buf = offset_buf; -if (!chip->offset_len) +if (!offset_len)return -EADDRNOTAVAIL ; -assert (chip->offset_len <=I2C_MAX_OFFSET_LEN ); - offset_len = chip->offset_len; +assert (offset_len <=I2C_MAX_OFFSET_LEN ); +while (offset_len--) *offset_buf++ = offset >> (8 * offset_len);
@@ -83,7 +86,7 @@ static int i2c_read_bytewise(struct udevice *dev, uint offset,if (i2c_setup_offset (chip, offset + i, offset_buf, msg))return -EINVAL ; ptr = msg +1 ; - ptr->addr = chip->chip_addr; + ptr->addr = msg->addr; ptr->flags = msg->flags |I2C_M_RD ; ptr->len =1 ; ptr->buf = &buffer[i];
@@ -139,7 +142,7 @@ int dm_i2c_read(struct udevice *dev, uint offset, uint8_t *buffer, int len) ptr++;if (len) { - ptr->addr = chip->chip_addr; + ptr->addr = msg->addr; ptr->flags = chip->flags &DM_I2C_CHIP_10BIT ?I2C_M_TEN :0 ; ptr->flags |=I2C_M_RD ; ptr->len = len;
@@ -323,7 +326,8 @@ int i2c_get_chip(struct udevice *bus, uint chip_addr, uint offset_len,struct dm_i2c_chip *chip =dev_get_parent_platdata (dev);int ret; -if (chip->chip_addr == chip_addr) { +if (chip->chip_addr == (chip_addr & + ~chip->chip_addr_offset_mask)) { ret =device_probe (dev);debug ("found, ret=%d\n" , ret);if (ret)
@@ -465,6 +469,22 @@ int i2c_get_chip_offset_len(struct udevice *dev)return chip->offset_len; } +int i2c_set_chip_addr_offset_mask (struct udevice *dev,uint mask) +{ +struct dm_i2c_chip *chip =dev_get_parent_platdata (dev); + + chip->chip_addr_offset_mask = mask; + +return 0 ; +} + +uint i2c_get_chip_addr_offset_mask (struct udevice *dev) +{ +struct dm_i2c_chip *chip =dev_get_parent_platdata (dev); + +return chip->chip_addr_offset_mask; +} +#ifdef CONFIG_DM_GPIO static void i2c_gpio_set_pin (struct gpio_desc *pin,int bit) {
include/i2c.h +33 -0
@@ -45,12 +45,26 @@ struct udevice;* represent up to 256 bytes. A value larger than 1 may be * needed for larger devices. * @flags: Flags for this chip (dm_i2c_chip_flags) +* @chip_addr_offset_mask: Mask of offset bits within chip_addr. Used for +* devices which steal addresses as part of offset. +* If offset_len is zero, then the offset is encoded +* completely within the chip address itself. +* e.g. a devce with chip address of 0x2c with 512 +* registers might use the bottom bit of the address +* to indicate which half of the address space is being +* accessed while still only using 1 byte offset. +* This means it will respond to chip address 0x2c and +* 0x2d. +* A real world example is the Atmel AT24C04. It's +* datasheet explains it's usage of this addressing +* mode. * @emul: Emulator for this chip address (only used for emulation) */ struct dm_i2c_chip {uint chip_addr;uint offset_len;uint flags; +uint chip_addr_offset_mask;#ifdef CONFIG_SANDBOX struct udevice *emul;bool test_mode;
@@ -261,6 +275,25 @@ int i2c_set_chip_offset_len(struct udevice *dev, uint offset_len);*/ int i2c_get_chip_offset_len (struct udevice *dev); +/** +* i2c_set_chip_addr_offset_mask() - set mask of address bits usable by offset +* +* Some devices listen on multiple chip addresses to achieve larger offsets +* than their single or multiple byte offsets would allow for. You can use this +* function to set the bits that are valid to be used for offset overflow. +* +* @mask: The mask to be used for high offset bits within address +* @return 0 if OK, other -ve value on error +*/ +int i2c_set_chip_addr_offset_mask (struct udevice *dev,uint mask); + +/* +* i2c_get_chip_addr_offset_mask() - get mask of address bits usable by offset +* +* @return current chip addr offset mask +*/ +uint i2c_get_chip_addr_offset_mask (struct udevice *dev); +/** * i2c_deblock() - recover a bus that is in an unknown state *
Signature · 1 line
2.20.1
PATCH 2/3 dm: i2c: EEPROM simulator allow tests visibility of addr and offset
Improve i2c EEPROM simulator testing by providing access functions to check the previous chip addr and offset.
Given that we can now directly test the offsets, also simplified the offset mapping and allow for wrapping acceses.
---
arch/sandbox/include/asm/test.h | 4 +++ drivers/misc/i2c_eeprom_emul.c | 61 +++++++++++++++++++++++++-------- test/dm/i2c.c | 50 +++++++++++++++++++-------- 3 files changed, 86 insertions(+), 29 deletions(-)
arch/sandbox/include/asm/test.h +4 -0
@@ -72,6 +72,10 @@ void sandbox_i2c_eeprom_set_test_mode(struct udevice *dev,void sandbox_i2c_eeprom_set_offset_len (struct udevice *dev,int offset_len); +uint sanbox_i2c_eeprom_get_prev_addr (struct udevice *dev); + +uint sanbox_i2c_eeprom_get_prev_offset (struct udevice *dev); +/** * sandbox_i2c_rtc_set_offset() - set the time offset from system/base time *
drivers/misc/i2c_eeprom_emul.c +47 -14
98 lines not on this page · raw message
test/dm/i2c.c +35 -15
76 lines not on this page · raw message
Signature · 1 line
2.20.1
PATCH 3/3 dm: i2c: EEPROM simulator add tests for addr offset mask
Add support for setting the chip address offset mask to EEPROM sumulator and add tests to test it.
---
arch/sandbox/include/asm/test.h | 3 ++ drivers/misc/i2c_eeprom_emul.c | 19 +++++++--- test/dm/i2c.c | 64 +++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+), 5 deletions(-)
arch/sandbox/include/asm/test.h +3 -0
@@ -72,6 +72,9 @@ void sandbox_i2c_eeprom_set_test_mode(struct udevice *dev,void sandbox_i2c_eeprom_set_offset_len (struct udevice *dev,int offset_len); +void sandbox_i2c_eeprom_set_chip_addr_offset_mask (struct udevice *dev, +uint mask); +uint sanbox_i2c_eeprom_get_prev_addr (struct udevice *dev);uint sanbox_i2c_eeprom_get_prev_offset (struct udevice *dev);
drivers/misc/i2c_eeprom_emul.c +14 -5
@@ -23,6 +23,7 @@ struct sandbox_i2c_flash_plat_data {const char *filename;int offset_len;/* Length of an offset in bytes */ int size;/* Size of data buffer */ +uint chip_addr_offset_mask;/* mask of addr bits used for offset */ };struct sandbox_i2c_flash {
@@ -46,6 +47,14 @@ void sandbox_i2c_eeprom_set_offset_len(struct udevice *dev, int offset_len) plat->offset_len = offset_len; } +void sandbox_i2c_eeprom_set_chip_addr_offset_mask (struct udevice *dev, +uint mask) +{ +struct sandbox_i2c_flash_plat_data *plat =dev_get_platdata (dev); + + plat->chip_addr_offset_mask = mask; +} +uint sanbox_i2c_eeprom_get_prev_addr (struct udevice *dev) {struct sandbox_i2c_flash *priv =dev_get_priv (dev);
@@ -64,7 +73,8 @@ static int sandbox_i2c_eeprom_xfer(struct udevice *emul, struct i2c_msg *msg, int nmsgs) {struct sandbox_i2c_flash *priv =dev_get_priv (emul); -uint offset =0 ; +struct sandbox_i2c_flash_plat_data *plat =dev_get_platdata (emul); +uint offset = msg->addr & plat->chip_addr_offset_mask;debug ("\n%s\n" , __func__);debug_buffer (0 , priv->data,1 ,16 ,0 );
@@ -73,17 +83,15 @@ static int sandbox_i2c_eeprom_xfer(struct udevice *emul, struct i2c_msg *msg, priv->prev_addr = msg->addr;for (; nmsgs >0 ; nmsgs--, msg++) { -struct sandbox_i2c_flash_plat_data *plat = -dev_get_platdata (emul);int len;u8 *ptr;if (!plat->size)return -ENODEV ; len = msg->len; -debug (" %s: msg->len=%d" , +debug (" %s: msg->addr=%x msg->len=%d" , msg->flags &I2C_M_RD ?"read" :"write" , - msg->len); + msg->addr, msg->len);if (msg->flags &I2C_M_RD ) {if (plat->test_mode ==SIE_TEST_MODE_SINGLE_BYTE ) len =1 ;
@@ -153,6 +161,7 @@ static int sandbox_i2c_eeprom_ofdata_to_platdata(struct udevice *dev) } plat->test_mode =SIE_TEST_MODE_NONE ; plat->offset_len =1 ; + plat->chip_addr_offset_mask =0 ;return 0 ; }
test/dm/i2c.c +64 -0
67 lines not on this page · raw message
Signature · 1 line
2.20.1
PATCH 3/3 dm: i2c: EEPROM simulator add tests for addr offset mask
Hello Robert,
Am 28.10.2019 um 18:44 schrieb Robert Beckett:
Quoted 10 lines
Add support for setting the chip address offset mask to EEPROM sumulator and add tests to test it.
Signed-off-by Robert Beckett <[email protected]>---
arch/sandbox/include/asm/test.h | 3 ++ drivers/misc/i2c_eeprom_emul.c | 19 +++++++--- test/dm/i2c.c | 64 +++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+), 5 deletions(-)
Thanks for adding al this testing stuff!
bye,
Heiko
Signature · 3 lines
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: +49-8142-66989-52 Fax: +49-8142-66989-80 Email: hs at denx.de
PATCH 3/3 dm: i2c: EEPROM simulator add tests for addr offset mask
In reply to Robert BeckettHello Robert,
Am 28.10.2019 um 18:44 schrieb Robert Beckett:
Quoted 10 lines
Add support for setting the chip address offset mask to EEPROM sumulator and add tests to test it.
Signed-off-by Robert Beckett <[email protected]>---
arch/sandbox/include/asm/test.h | 3 ++ drivers/misc/i2c_eeprom_emul.c | 19 +++++++--- test/dm/i2c.c | 64 +++++++++++++++++++++++++++++++++ 3 files changed, 81 insertions(+), 5 deletions(-)
Applied to u-boot-i2c next branch.
Thanks!
bye,
Heiko
Signature · 3 lines
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: +49-8142-66989-52 Fax: +49-8142-66989-80 Email: hs at denx.de
PATCH 2/3 dm: i2c: EEPROM simulator allow tests visibility of addr and offset
In reply to Robert BeckettHello Robert,
Am 28.10.2019 um 18:44 schrieb Robert Beckett:
Quoted 6 lines
Improve i2c EEPROM simulator testing by providing access functions to check the previous chip addr and offset.
Given that we can now directly test the offsets, also simplified the offset mapping and allow for wrapping acceses.
Quoted 7 lines
Signed-off-by Robert Beckett <[email protected]>---
arch/sandbox/include/asm/test.h | 4 +++ drivers/misc/i2c_eeprom_emul.c | 61 +++++++++++++++++++++++++-------- test/dm/i2c.c | 50 +++++++++++++++++++-------- 3 files changed, 86 insertions(+), 29 deletions(-)
Thanks!
bye,
Heiko
Signature · 3 lines
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: +49-8142-66989-52 Fax: +49-8142-66989-80 Email: hs at denx.de
PATCH 2/3 dm: i2c: EEPROM simulator allow tests visibility of addr and offset
In reply to Robert BeckettHello Robert,
Am 28.10.2019 um 18:44 schrieb Robert Beckett:
Quoted 6 lines
Improve i2c EEPROM simulator testing by providing access functions to check the previous chip addr and offset.
Given that we can now directly test the offsets, also simplified the offset mapping and allow for wrapping acceses.
Quoted 7 lines
Signed-off-by Robert Beckett <[email protected]>---
arch/sandbox/include/asm/test.h | 4 +++ drivers/misc/i2c_eeprom_emul.c | 61 +++++++++++++++++++++++++-------- test/dm/i2c.c | 50 +++++++++++++++++++-------- 3 files changed, 86 insertions(+), 29 deletions(-)
Applied to u-boot-i2c next branch.
Thanks!
bye,
Heiko
Signature · 3 lines
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: +49-8142-66989-52 Fax: +49-8142-66989-80 Email: hs at denx.de
PATCH 1/3 i2c: add support for offset overflow in to address
In reply to Robert BeckettHello Robert
Am 28.10.2019 um 18:44 schrieb Robert Beckett:
Quoted 8 lines
Some devices (2 wire eeproms for example) use some bits from the chip address to represent the high bits of the offset instead of or as well as using multiple bytes for the offset, effectively stealing chip addresses on the bus.
Add a chip offset mask that can be set for any i2c chip which gets filled with the offset overflow during offset setup.
Quoted 7 lines
Signed-off-by Robert Beckett <[email protected]>Signed-off-by Ian Ray <[email protected]>---
drivers/i2c/i2c-uclass.c | 34 +++++++++++++++++++++++++++------- include/i2c.h | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 7 deletions(-)
Thanks!
bye,
Heiko
Signature · 3 lines
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: +49-8142-66989-52 Fax: +49-8142-66989-80 Email: hs at denx.de
PATCH 1/3 i2c: add support for offset overflow in to address
In reply to Robert BeckettHello Robert,
Am 28.10.2019 um 18:44 schrieb Robert Beckett:
Quoted 8 lines
Some devices (2 wire eeproms for example) use some bits from the chip address to represent the high bits of the offset instead of or as well as using multiple bytes for the offset, effectively stealing chip addresses on the bus.
Add a chip offset mask that can be set for any i2c chip which gets filled with the offset overflow during offset setup.
Quoted 7 lines
Signed-off-by Robert Beckett <[email protected]>Signed-off-by Ian Ray <[email protected]>---
drivers/i2c/i2c-uclass.c | 34 +++++++++++++++++++++++++++------- include/i2c.h | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 7 deletions(-)
Applied to u-boot-i2c next branch.
Thanks!
bye,
Heiko
Signature · 3 lines
DENX Software Engineering GmbH, Managing Director: Wolfgang Denk HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: +49-8142-66989-52 Fax: +49-8142-66989-80 Email: hs at denx.de