2018-05-06 21:58:06 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
2014-12-10 15:55:55 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2013 Google, Inc
|
|
|
|
*
|
|
|
|
* Note: Test coverage does not include 10-bit addressing
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <dm.h>
|
|
|
|
#include <fdtdec.h>
|
|
|
|
#include <i2c.h>
|
2015-05-20 19:27:27 +00:00
|
|
|
#include <asm/state.h>
|
|
|
|
#include <asm/test.h>
|
2014-12-10 15:55:55 +00:00
|
|
|
#include <dm/device-internal.h>
|
|
|
|
#include <dm/test.h>
|
|
|
|
#include <dm/uclass-internal.h>
|
|
|
|
#include <dm/util.h>
|
2019-10-28 17:44:58 +00:00
|
|
|
#include <hexdump.h>
|
2020-07-19 16:15:37 +00:00
|
|
|
#include <test/test.h>
|
2015-05-20 19:27:27 +00:00
|
|
|
#include <test/ut.h>
|
2014-12-10 15:55:55 +00:00
|
|
|
|
|
|
|
static const int busnum;
|
|
|
|
static const int chip = 0x2c;
|
|
|
|
|
|
|
|
/* Test that we can find buses and chips */
|
2015-05-20 19:27:27 +00:00
|
|
|
static int dm_test_i2c_find(struct unit_test_state *uts)
|
2014-12-10 15:55:55 +00:00
|
|
|
{
|
|
|
|
struct udevice *bus, *dev;
|
|
|
|
const int no_chip = 0x10;
|
|
|
|
|
|
|
|
/*
|
2016-07-05 23:10:10 +00:00
|
|
|
* The post_bind() method will bind devices to chip selects. Check
|
|
|
|
* this then remove the emulation and the slave device.
|
2014-12-10 15:55:55 +00:00
|
|
|
*/
|
|
|
|
ut_assertok(uclass_get_device_by_seq(UCLASS_I2C, busnum, &bus));
|
2015-01-13 01:02:07 +00:00
|
|
|
ut_assertok(dm_i2c_probe(bus, chip, 0, &dev));
|
2018-11-18 15:14:34 +00:00
|
|
|
ut_asserteq(-ENOENT, dm_i2c_probe(bus, no_chip, 0, &dev));
|
2014-12-10 15:55:55 +00:00
|
|
|
ut_asserteq(-ENODEV, uclass_get_device_by_seq(UCLASS_I2C, 1, &bus));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2020-07-29 01:41:12 +00:00
|
|
|
DM_TEST(dm_test_i2c_find, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
|
2014-12-10 15:55:55 +00:00
|
|
|
|
2015-05-20 19:27:27 +00:00
|
|
|
static int dm_test_i2c_read_write(struct unit_test_state *uts)
|
2014-12-10 15:55:55 +00:00
|
|
|
{
|
|
|
|
struct udevice *bus, *dev;
|
|
|
|
uint8_t buf[5];
|
|
|
|
|
|
|
|
ut_assertok(uclass_get_device_by_seq(UCLASS_I2C, busnum, &bus));
|
2015-01-25 15:26:55 +00:00
|
|
|
ut_assertok(i2c_get_chip(bus, chip, 1, &dev));
|
2015-01-13 01:02:07 +00:00
|
|
|
ut_assertok(dm_i2c_read(dev, 0, buf, 5));
|
2020-05-10 18:52:45 +00:00
|
|
|
ut_asserteq_mem(buf, "\0\0\0\0\0", sizeof(buf));
|
2015-01-13 01:02:07 +00:00
|
|
|
ut_assertok(dm_i2c_write(dev, 2, (uint8_t *)"AB", 2));
|
|
|
|
ut_assertok(dm_i2c_read(dev, 0, buf, 5));
|
2020-05-10 18:52:45 +00:00
|
|
|
ut_asserteq_mem(buf, "\0\0AB\0", sizeof(buf));
|
2014-12-10 15:55:55 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2020-07-29 01:41:12 +00:00
|
|
|
DM_TEST(dm_test_i2c_read_write, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
|
2014-12-10 15:55:55 +00:00
|
|
|
|
2015-05-20 19:27:27 +00:00
|
|
|
static int dm_test_i2c_speed(struct unit_test_state *uts)
|
2014-12-10 15:55:55 +00:00
|
|
|
{
|
|
|
|
struct udevice *bus, *dev;
|
|
|
|
uint8_t buf[5];
|
|
|
|
|
|
|
|
ut_assertok(uclass_get_device_by_seq(UCLASS_I2C, busnum, &bus));
|
2015-04-20 18:37:15 +00:00
|
|
|
|
|
|
|
/* Use test mode so we create the required errors for invalid speeds */
|
|
|
|
sandbox_i2c_set_test_mode(bus, true);
|
2015-01-25 15:26:55 +00:00
|
|
|
ut_assertok(i2c_get_chip(bus, chip, 1, &dev));
|
2015-02-06 04:41:32 +00:00
|
|
|
ut_assertok(dm_i2c_set_bus_speed(bus, 100000));
|
2015-01-13 01:02:07 +00:00
|
|
|
ut_assertok(dm_i2c_read(dev, 0, buf, 5));
|
2015-02-06 04:41:32 +00:00
|
|
|
ut_assertok(dm_i2c_set_bus_speed(bus, 400000));
|
|
|
|
ut_asserteq(400000, dm_i2c_get_bus_speed(bus));
|
2015-01-13 01:02:07 +00:00
|
|
|
ut_assertok(dm_i2c_read(dev, 0, buf, 5));
|
|
|
|
ut_asserteq(-EINVAL, dm_i2c_write(dev, 0, buf, 5));
|
2015-04-20 18:37:15 +00:00
|
|
|
sandbox_i2c_set_test_mode(bus, false);
|
2014-12-10 15:55:55 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2020-07-29 01:41:12 +00:00
|
|
|
DM_TEST(dm_test_i2c_speed, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
|
2014-12-10 15:55:55 +00:00
|
|
|
|
2015-05-20 19:27:27 +00:00
|
|
|
static int dm_test_i2c_offset_len(struct unit_test_state *uts)
|
2014-12-10 15:55:55 +00:00
|
|
|
{
|
|
|
|
struct udevice *bus, *dev;
|
|
|
|
uint8_t buf[5];
|
|
|
|
|
|
|
|
ut_assertok(uclass_get_device_by_seq(UCLASS_I2C, busnum, &bus));
|
2015-01-25 15:26:55 +00:00
|
|
|
ut_assertok(i2c_get_chip(bus, chip, 1, &dev));
|
2014-12-10 15:55:55 +00:00
|
|
|
ut_assertok(i2c_set_chip_offset_len(dev, 1));
|
2015-01-13 01:02:07 +00:00
|
|
|
ut_assertok(dm_i2c_read(dev, 0, buf, 5));
|
2014-12-10 15:55:55 +00:00
|
|
|
|
|
|
|
/* This is not supported by the uclass */
|
|
|
|
ut_asserteq(-EINVAL, i2c_set_chip_offset_len(dev, 5));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2020-07-29 01:41:12 +00:00
|
|
|
DM_TEST(dm_test_i2c_offset_len, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
|
2014-12-10 15:55:55 +00:00
|
|
|
|
2015-05-20 19:27:27 +00:00
|
|
|
static int dm_test_i2c_probe_empty(struct unit_test_state *uts)
|
2014-12-10 15:55:55 +00:00
|
|
|
{
|
|
|
|
struct udevice *bus, *dev;
|
|
|
|
|
|
|
|
ut_assertok(uclass_get_device_by_seq(UCLASS_I2C, busnum, &bus));
|
2015-04-20 18:37:15 +00:00
|
|
|
|
|
|
|
/* Use test mode so that this chip address will always probe */
|
|
|
|
sandbox_i2c_set_test_mode(bus, true);
|
2015-01-13 01:02:07 +00:00
|
|
|
ut_assertok(dm_i2c_probe(bus, SANDBOX_I2C_TEST_ADDR, 0, &dev));
|
2015-04-20 18:37:15 +00:00
|
|
|
sandbox_i2c_set_test_mode(bus, false);
|
2014-12-10 15:55:55 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2020-07-29 01:41:12 +00:00
|
|
|
DM_TEST(dm_test_i2c_probe_empty, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
|
2014-12-10 15:55:55 +00:00
|
|
|
|
2015-05-20 19:27:27 +00:00
|
|
|
static int dm_test_i2c_bytewise(struct unit_test_state *uts)
|
2014-12-10 15:55:55 +00:00
|
|
|
{
|
|
|
|
struct udevice *bus, *dev;
|
|
|
|
struct udevice *eeprom;
|
|
|
|
uint8_t buf[5];
|
|
|
|
|
|
|
|
ut_assertok(uclass_get_device_by_seq(UCLASS_I2C, busnum, &bus));
|
2015-01-25 15:26:55 +00:00
|
|
|
ut_assertok(i2c_get_chip(bus, chip, 1, &dev));
|
2015-01-13 01:02:07 +00:00
|
|
|
ut_assertok(dm_i2c_read(dev, 0, buf, 5));
|
2020-05-10 18:52:45 +00:00
|
|
|
ut_asserteq_mem(buf, "\0\0\0\0\0", sizeof(buf));
|
2014-12-10 15:55:55 +00:00
|
|
|
|
|
|
|
/* Tell the EEPROM to only read/write one register at a time */
|
2022-10-12 19:57:59 +00:00
|
|
|
ut_assertok(uclass_first_device_err(UCLASS_I2C_EMUL, &eeprom));
|
2014-12-10 15:55:55 +00:00
|
|
|
ut_assertnonnull(eeprom);
|
|
|
|
sandbox_i2c_eeprom_set_test_mode(eeprom, SIE_TEST_MODE_SINGLE_BYTE);
|
|
|
|
|
|
|
|
/* Now we only get the first byte - the rest will be 0xff */
|
2015-01-13 01:02:07 +00:00
|
|
|
ut_assertok(dm_i2c_read(dev, 0, buf, 5));
|
2020-05-10 18:52:45 +00:00
|
|
|
ut_asserteq_mem(buf, "\0\xff\xff\xff\xff", sizeof(buf));
|
2014-12-10 15:55:55 +00:00
|
|
|
|
|
|
|
/* If we do a separate transaction for each byte, it works */
|
|
|
|
ut_assertok(i2c_set_chip_flags(dev, DM_I2C_CHIP_RD_ADDRESS));
|
2015-01-13 01:02:07 +00:00
|
|
|
ut_assertok(dm_i2c_read(dev, 0, buf, 5));
|
2020-05-10 18:52:45 +00:00
|
|
|
ut_asserteq_mem(buf, "\0\0\0\0\0", sizeof(buf));
|
2014-12-10 15:55:55 +00:00
|
|
|
|
|
|
|
/* This will only write A */
|
|
|
|
ut_assertok(i2c_set_chip_flags(dev, 0));
|
2015-01-13 01:02:07 +00:00
|
|
|
ut_assertok(dm_i2c_write(dev, 2, (uint8_t *)"AB", 2));
|
|
|
|
ut_assertok(dm_i2c_read(dev, 0, buf, 5));
|
2020-05-10 18:52:45 +00:00
|
|
|
ut_asserteq_mem(buf, "\0\xff\xff\xff\xff", sizeof(buf));
|
2014-12-10 15:55:55 +00:00
|
|
|
|
|
|
|
/* Check that the B was ignored */
|
|
|
|
ut_assertok(i2c_set_chip_flags(dev, DM_I2C_CHIP_RD_ADDRESS));
|
2015-01-13 01:02:07 +00:00
|
|
|
ut_assertok(dm_i2c_read(dev, 0, buf, 5));
|
2020-05-10 18:52:45 +00:00
|
|
|
ut_asserteq_mem(buf, "\0\0A\0\0\0", sizeof(buf));
|
2014-12-10 15:55:55 +00:00
|
|
|
|
|
|
|
/* Now write it again with the new flags, it should work */
|
|
|
|
ut_assertok(i2c_set_chip_flags(dev, DM_I2C_CHIP_WR_ADDRESS));
|
2015-01-13 01:02:07 +00:00
|
|
|
ut_assertok(dm_i2c_write(dev, 2, (uint8_t *)"AB", 2));
|
|
|
|
ut_assertok(dm_i2c_read(dev, 0, buf, 5));
|
2020-05-10 18:52:45 +00:00
|
|
|
ut_asserteq_mem(buf, "\0\xff\xff\xff\xff", sizeof(buf));
|
2014-12-10 15:55:55 +00:00
|
|
|
|
|
|
|
ut_assertok(i2c_set_chip_flags(dev, DM_I2C_CHIP_WR_ADDRESS |
|
|
|
|
DM_I2C_CHIP_RD_ADDRESS));
|
2015-01-13 01:02:07 +00:00
|
|
|
ut_assertok(dm_i2c_read(dev, 0, buf, 5));
|
2020-05-10 18:52:45 +00:00
|
|
|
ut_asserteq_mem(buf, "\0\0AB\0\0", sizeof(buf));
|
2014-12-10 15:55:55 +00:00
|
|
|
|
|
|
|
/* Restore defaults */
|
|
|
|
sandbox_i2c_eeprom_set_test_mode(eeprom, SIE_TEST_MODE_NONE);
|
|
|
|
ut_assertok(i2c_set_chip_flags(dev, 0));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2020-07-29 01:41:12 +00:00
|
|
|
DM_TEST(dm_test_i2c_bytewise, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
|
2014-12-10 15:55:55 +00:00
|
|
|
|
2015-05-20 19:27:27 +00:00
|
|
|
static int dm_test_i2c_offset(struct unit_test_state *uts)
|
2014-12-10 15:55:55 +00:00
|
|
|
{
|
|
|
|
struct udevice *eeprom;
|
|
|
|
struct udevice *dev;
|
|
|
|
uint8_t buf[5];
|
|
|
|
|
2015-01-25 15:26:55 +00:00
|
|
|
ut_assertok(i2c_get_chip_for_busnum(busnum, chip, 1, &dev));
|
2014-12-10 15:55:55 +00:00
|
|
|
|
|
|
|
/* Do a transfer so we can find the emulator */
|
2015-01-13 01:02:07 +00:00
|
|
|
ut_assertok(dm_i2c_read(dev, 0, buf, 5));
|
2022-10-12 19:57:59 +00:00
|
|
|
ut_assertok(uclass_first_device_err(UCLASS_I2C_EMUL, &eeprom));
|
2014-12-10 15:55:55 +00:00
|
|
|
|
|
|
|
/* Offset length 0 */
|
|
|
|
sandbox_i2c_eeprom_set_offset_len(eeprom, 0);
|
|
|
|
ut_assertok(i2c_set_chip_offset_len(dev, 0));
|
2015-01-13 01:02:07 +00:00
|
|
|
ut_assertok(dm_i2c_write(dev, 10 /* ignored */, (uint8_t *)"AB", 2));
|
|
|
|
ut_assertok(dm_i2c_read(dev, 0, buf, 5));
|
2019-10-28 17:44:58 +00:00
|
|
|
ut_asserteq_mem("AB\0\0\0\0", buf, sizeof(buf));
|
|
|
|
ut_asserteq(0, sanbox_i2c_eeprom_get_prev_offset(eeprom));
|
2014-12-10 15:55:55 +00:00
|
|
|
|
|
|
|
/* Offset length 1 */
|
|
|
|
sandbox_i2c_eeprom_set_offset_len(eeprom, 1);
|
|
|
|
ut_assertok(i2c_set_chip_offset_len(dev, 1));
|
2015-01-13 01:02:07 +00:00
|
|
|
ut_assertok(dm_i2c_write(dev, 2, (uint8_t *)"AB", 2));
|
2019-10-28 17:44:58 +00:00
|
|
|
ut_asserteq(2, sanbox_i2c_eeprom_get_prev_offset(eeprom));
|
2015-01-13 01:02:07 +00:00
|
|
|
ut_assertok(dm_i2c_read(dev, 0, buf, 5));
|
2019-10-28 17:44:58 +00:00
|
|
|
ut_asserteq_mem("ABAB\0", buf, sizeof(buf));
|
|
|
|
ut_asserteq(0, sanbox_i2c_eeprom_get_prev_offset(eeprom));
|
2014-12-10 15:55:55 +00:00
|
|
|
|
2019-10-28 17:44:58 +00:00
|
|
|
/* Offset length 2 boundary - check model wrapping */
|
2014-12-10 15:55:55 +00:00
|
|
|
sandbox_i2c_eeprom_set_offset_len(eeprom, 2);
|
|
|
|
ut_assertok(i2c_set_chip_offset_len(dev, 2));
|
2019-10-28 17:44:58 +00:00
|
|
|
ut_assertok(dm_i2c_write(dev, 0xFF, (uint8_t *)"A", 1));
|
|
|
|
ut_asserteq(0xFF, sanbox_i2c_eeprom_get_prev_offset(eeprom));
|
|
|
|
ut_assertok(dm_i2c_write(dev, 0x100, (uint8_t *)"B", 1));
|
|
|
|
ut_asserteq(0x100, sanbox_i2c_eeprom_get_prev_offset(eeprom));
|
|
|
|
ut_assertok(dm_i2c_write(dev, 0x101, (uint8_t *)"C", 1));
|
|
|
|
ut_asserteq(0x101, sanbox_i2c_eeprom_get_prev_offset(eeprom));
|
|
|
|
ut_assertok(dm_i2c_read(dev, 0xFF, buf, 5));
|
|
|
|
ut_asserteq_mem("ABCAB", buf, sizeof(buf));
|
|
|
|
ut_asserteq(0xFF, sanbox_i2c_eeprom_get_prev_offset(eeprom));
|
2014-12-10 15:55:55 +00:00
|
|
|
|
2019-10-28 17:44:58 +00:00
|
|
|
/* Offset length 2 */
|
2014-12-10 15:55:55 +00:00
|
|
|
sandbox_i2c_eeprom_set_offset_len(eeprom, 2);
|
|
|
|
ut_assertok(i2c_set_chip_offset_len(dev, 2));
|
2019-10-28 17:44:58 +00:00
|
|
|
ut_assertok(dm_i2c_write(dev, 0x2020, (uint8_t *)"AB", 2));
|
|
|
|
ut_assertok(dm_i2c_read(dev, 0x2020, buf, 5));
|
|
|
|
ut_asserteq_mem("AB\0\0\0", buf, sizeof(buf));
|
|
|
|
ut_asserteq(0x2020, sanbox_i2c_eeprom_get_prev_offset(eeprom));
|
|
|
|
|
|
|
|
/* Offset length 3 */
|
|
|
|
sandbox_i2c_eeprom_set_offset_len(eeprom, 3);
|
|
|
|
ut_assertok(i2c_set_chip_offset_len(dev, 3));
|
|
|
|
ut_assertok(dm_i2c_write(dev, 0x303030, (uint8_t *)"AB", 2));
|
|
|
|
ut_assertok(dm_i2c_read(dev, 0x303030, buf, 5));
|
|
|
|
ut_asserteq_mem("AB\0\0\0", buf, sizeof(buf));
|
|
|
|
ut_asserteq(0x303030, sanbox_i2c_eeprom_get_prev_offset(eeprom));
|
2014-12-10 15:55:55 +00:00
|
|
|
|
|
|
|
/* Offset length 4 */
|
2019-10-28 17:44:58 +00:00
|
|
|
sandbox_i2c_eeprom_set_offset_len(eeprom, 4);
|
|
|
|
ut_assertok(i2c_set_chip_offset_len(dev, 4));
|
|
|
|
ut_assertok(dm_i2c_write(dev, 0x40404040, (uint8_t *)"AB", 2));
|
|
|
|
ut_assertok(dm_i2c_read(dev, 0x40404040, buf, 5));
|
|
|
|
ut_asserteq_mem("AB\0\0\0", buf, sizeof(buf));
|
|
|
|
ut_asserteq(0x40404040, sanbox_i2c_eeprom_get_prev_offset(eeprom));
|
2014-12-10 15:55:55 +00:00
|
|
|
|
|
|
|
/* Restore defaults */
|
|
|
|
sandbox_i2c_eeprom_set_offset_len(eeprom, 1);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2020-07-29 01:41:12 +00:00
|
|
|
DM_TEST(dm_test_i2c_offset, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
|
2019-10-28 17:44:59 +00:00
|
|
|
|
|
|
|
static int dm_test_i2c_addr_offset(struct unit_test_state *uts)
|
|
|
|
{
|
|
|
|
struct udevice *eeprom;
|
|
|
|
struct udevice *dev;
|
|
|
|
u8 buf[5];
|
|
|
|
|
|
|
|
ut_assertok(i2c_get_chip_for_busnum(busnum, chip, 1, &dev));
|
|
|
|
|
|
|
|
/* Do a transfer so we can find the emulator */
|
|
|
|
ut_assertok(dm_i2c_read(dev, 0, buf, 5));
|
2022-10-12 19:57:59 +00:00
|
|
|
ut_assertok(uclass_first_device_err(UCLASS_I2C_EMUL, &eeprom));
|
2019-10-28 17:44:59 +00:00
|
|
|
|
|
|
|
/* Offset length 0 */
|
|
|
|
sandbox_i2c_eeprom_set_offset_len(eeprom, 0);
|
|
|
|
sandbox_i2c_eeprom_set_chip_addr_offset_mask(eeprom, 0x3);
|
|
|
|
ut_assertok(i2c_set_chip_offset_len(dev, 0));
|
|
|
|
ut_assertok(i2c_set_chip_addr_offset_mask(dev, 0x3));
|
|
|
|
ut_assertok(dm_i2c_write(dev, 0x3, (uint8_t *)"AB", 2));
|
|
|
|
ut_assertok(dm_i2c_read(dev, 0x3, buf, 5));
|
|
|
|
ut_asserteq_mem("AB\0\0\0\0", buf, sizeof(buf));
|
|
|
|
ut_asserteq(0x3, sanbox_i2c_eeprom_get_prev_offset(eeprom));
|
|
|
|
ut_asserteq(chip | 0x3, sanbox_i2c_eeprom_get_prev_addr(eeprom));
|
|
|
|
|
|
|
|
/* Offset length 1 */
|
|
|
|
sandbox_i2c_eeprom_set_offset_len(eeprom, 1);
|
|
|
|
sandbox_i2c_eeprom_set_chip_addr_offset_mask(eeprom, 0x3);
|
|
|
|
ut_assertok(i2c_set_chip_offset_len(dev, 1));
|
|
|
|
ut_assertok(i2c_set_chip_addr_offset_mask(dev, 0x3));
|
|
|
|
ut_assertok(dm_i2c_write(dev, 0x310, (uint8_t *)"AB", 2));
|
|
|
|
ut_assertok(dm_i2c_read(dev, 0x310, buf, 5));
|
|
|
|
ut_asserteq_mem("AB\0\0\0\0", buf, sizeof(buf));
|
|
|
|
ut_asserteq(0x310, sanbox_i2c_eeprom_get_prev_offset(eeprom));
|
|
|
|
ut_asserteq(chip | 0x3, sanbox_i2c_eeprom_get_prev_addr(eeprom));
|
|
|
|
|
|
|
|
/* Offset length 2 */
|
|
|
|
sandbox_i2c_eeprom_set_offset_len(eeprom, 2);
|
|
|
|
sandbox_i2c_eeprom_set_chip_addr_offset_mask(eeprom, 0x3);
|
|
|
|
ut_assertok(i2c_set_chip_offset_len(dev, 2));
|
|
|
|
ut_assertok(i2c_set_chip_addr_offset_mask(dev, 0x3));
|
|
|
|
ut_assertok(dm_i2c_write(dev, 0x32020, (uint8_t *)"AB", 2));
|
|
|
|
ut_assertok(dm_i2c_read(dev, 0x32020, buf, 5));
|
|
|
|
ut_asserteq_mem("AB\0\0\0\0", buf, sizeof(buf));
|
|
|
|
ut_asserteq(0x32020, sanbox_i2c_eeprom_get_prev_offset(eeprom));
|
|
|
|
ut_asserteq(chip | 0x3, sanbox_i2c_eeprom_get_prev_addr(eeprom));
|
|
|
|
|
|
|
|
/* Offset length 3 */
|
|
|
|
sandbox_i2c_eeprom_set_offset_len(eeprom, 3);
|
|
|
|
sandbox_i2c_eeprom_set_chip_addr_offset_mask(eeprom, 0x3);
|
|
|
|
ut_assertok(i2c_set_chip_offset_len(dev, 3));
|
|
|
|
ut_assertok(i2c_set_chip_addr_offset_mask(dev, 0x3));
|
|
|
|
ut_assertok(dm_i2c_write(dev, 0x3303030, (uint8_t *)"AB", 2));
|
|
|
|
ut_assertok(dm_i2c_read(dev, 0x3303030, buf, 5));
|
|
|
|
ut_asserteq_mem("AB\0\0\0\0", buf, sizeof(buf));
|
|
|
|
ut_asserteq(0x3303030, sanbox_i2c_eeprom_get_prev_offset(eeprom));
|
|
|
|
ut_asserteq(chip | 0x3, sanbox_i2c_eeprom_get_prev_addr(eeprom));
|
|
|
|
|
|
|
|
/* Restore defaults */
|
|
|
|
sandbox_i2c_eeprom_set_offset_len(eeprom, 1);
|
|
|
|
sandbox_i2c_eeprom_set_chip_addr_offset_mask(eeprom, 0);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-07-29 01:41:12 +00:00
|
|
|
DM_TEST(dm_test_i2c_addr_offset, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
|
2021-07-15 15:39:59 +00:00
|
|
|
|
|
|
|
static int dm_test_i2c_reg_clrset(struct unit_test_state *uts)
|
|
|
|
{
|
|
|
|
struct udevice *eeprom;
|
|
|
|
struct udevice *dev;
|
|
|
|
u8 buf[5];
|
|
|
|
|
|
|
|
ut_assertok(i2c_get_chip_for_busnum(busnum, chip, 1, &dev));
|
|
|
|
|
|
|
|
/* Do a transfer so we can find the emulator */
|
|
|
|
ut_assertok(dm_i2c_read(dev, 0, buf, 5));
|
2022-10-12 19:57:59 +00:00
|
|
|
ut_assertok(uclass_first_device_err(UCLASS_I2C_EMUL, &eeprom));
|
2021-07-15 15:39:59 +00:00
|
|
|
|
|
|
|
/* Dummy data for the test */
|
|
|
|
ut_assertok(dm_i2c_write(dev, 0, "\xff\x00\xff\x00\x10", 5));
|
|
|
|
|
|
|
|
/* Do some clrset tests */
|
|
|
|
ut_assertok(dm_i2c_reg_clrset(dev, 0, 0xff, 0x10));
|
|
|
|
ut_assertok(dm_i2c_reg_clrset(dev, 1, 0x00, 0x11));
|
|
|
|
ut_assertok(dm_i2c_reg_clrset(dev, 2, 0xed, 0x00));
|
|
|
|
ut_assertok(dm_i2c_reg_clrset(dev, 3, 0xff, 0x13));
|
|
|
|
ut_assertok(dm_i2c_reg_clrset(dev, 4, 0x00, 0x14));
|
|
|
|
|
|
|
|
ut_assertok(dm_i2c_read(dev, 0, buf, 5));
|
|
|
|
ut_asserteq_mem("\x10\x11\x12\x13\x14", buf, sizeof(buf));
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
DM_TEST(dm_test_i2c_reg_clrset, UT_TESTF_SCAN_PDATA | UT_TESTF_SCAN_FDT);
|