summaryrefslogtreecommitdiffstats
path: root/cpukit
diff options
context:
space:
mode:
authorSebastian Huber <sebastian.huber@embedded-brains.de>2017-10-02 13:06:59 +0200
committerSebastian Huber <sebastian.huber@embedded-brains.de>2017-10-02 13:34:00 +0200
commit2e1d5959720ff9f3738513202531576cf1403112 (patch)
tree8d9267f2d64e578f67dae6a02e423cc475f9e930 /cpukit
parentf9fbb3336ff4e9044795e02b2847bbc1206674f5 (diff)
downloadrtems-2e1d5959720ff9f3738513202531576cf1403112.tar.bz2
i2c: Send MSB of address first for EEPROMs
Update #3161.
Diffstat (limited to 'cpukit')
-rw-r--r--cpukit/dev/i2c/eeprom.c33
1 files changed, 21 insertions, 12 deletions
diff --git a/cpukit/dev/i2c/eeprom.c b/cpukit/dev/i2c/eeprom.c
index 39cff951cb..74f2d8c9aa 100644
--- a/cpukit/dev/i2c/eeprom.c
+++ b/cpukit/dev/i2c/eeprom.c
@@ -48,6 +48,23 @@ static uint16_t eeprom_i2c_addr(eeprom *dev, uint32_t off)
| ((off >> dev->i2c_address_shift) & dev->i2c_address_mask);
}
+static void eeprom_set_addr(
+ const eeprom *dev,
+ uint32_t off,
+ uint8_t addr[EEPROM_MAX_ADDRESS_BYTES]
+)
+{
+ int shift = 24 - (4 - dev->address_bytes) * 8;
+
+ addr[0] = (uint8_t) (off >> shift);
+ shift -= 8;
+ addr[1] = (uint8_t) (off >> shift);
+ shift -= 8;
+ addr[2] = (uint8_t) (off >> shift);
+ shift -= 8;
+ addr[3] = (uint8_t) (off >> shift);
+}
+
static ssize_t eeprom_read(
i2c_dev *base,
void *buf,
@@ -80,12 +97,7 @@ static ssize_t eeprom_read(
*/
uint16_t cur = (uint16_t) (todo < 255 ? todo : 255);
- uint8_t addr[EEPROM_MAX_ADDRESS_BYTES] = {
- (uint8_t) off,
- (uint8_t) (off >> 8),
- (uint8_t) (off >> 16),
- (uint8_t) (off >> 24)
- };
+ uint8_t addr[EEPROM_MAX_ADDRESS_BYTES];
i2c_msg msgs[2] = {
{
.addr = i2c_addr,
@@ -101,6 +113,7 @@ static ssize_t eeprom_read(
};
int err;
+ eeprom_set_addr(dev, off, addr);
err = i2c_bus_transfer(dev->base.bus, &msgs[0], RTEMS_ARRAY_SIZE(msgs));
if (err != 0) {
return err;
@@ -141,12 +154,7 @@ static ssize_t eeprom_write(
uint16_t i2c_addr = eeprom_i2c_addr(dev, off);
uint16_t rem = dev->page_size - (off & (dev->page_size - 1));
uint16_t cur = (uint16_t) (todo < rem ? todo : rem);
- uint8_t addr[EEPROM_MAX_ADDRESS_BYTES] = {
- (uint8_t) off,
- (uint8_t) (off >> 8),
- (uint8_t) (off >> 16),
- (uint8_t) (off >> 24)
- };
+ uint8_t addr[EEPROM_MAX_ADDRESS_BYTES];
i2c_msg msgs[2] = {
{
.addr = i2c_addr,
@@ -165,6 +173,7 @@ static ssize_t eeprom_write(
ssize_t m;
rtems_interval timeout;
+ eeprom_set_addr(dev, off, addr);
err = i2c_bus_transfer(dev->base.bus, &msgs[0], RTEMS_ARRAY_SIZE(msgs));
if (err != 0) {
return err;