Fix 16 bit address byte order for i2c transactions #16
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Why the change?
When setting the read/write pointer for an EEPROM that uses 16 bit addressing to access the internal memory, the bytes are sent [high byte] [low byte]. This commit fixes the byte ordering when sending the address to the device.
Problem example
I used an I2C EEPROM with 16 bit addressing and stored a string into the memory for recall within u-boot. Here is the information stored in the eeprom, and being read out again from within linux to show that is stored correctly:
but, when I read it from u-boot, the data was incorrect
using an i2c protocol analyzer to observe the transaction showed the problem. The code is reading 16 bytes at a time, and setting the address after each read of 16 bytes. The address is incorrect (high and low bytes are swapped)
I can further illustrate the problem by forcing the swap of the bytes manually in the command
The fix
As shown in the code, the fix is to properly send the address when doing a read or a write. After making the change, the data can be read correctly from the i2c device.