X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=test%2Fdm%2Fi2c.c;h=e2688bfbe9c06d29cf7806253adc5d5e8ba18ec2;hb=94b13bbae90bfb94204b8fe9c531bc163e746a9f;hp=4823b0c6483655c4cd112e736f08c25965b49d32;hpb=f9a4c2da72d04e13b05deecb800f232d2948eb85;p=u-boot diff --git a/test/dm/i2c.c b/test/dm/i2c.c index 4823b0c648..e2688bfbe9 100644 --- a/test/dm/i2c.c +++ b/test/dm/i2c.c @@ -10,19 +10,19 @@ #include #include #include +#include +#include #include #include #include -#include #include -#include -#include +#include static const int busnum; static const int chip = 0x2c; /* Test that we can find buses and chips */ -static int dm_test_i2c_find(struct dm_test_state *dms) +static int dm_test_i2c_find(struct unit_test_state *uts) { struct udevice *bus, *dev; const int no_chip = 0x10; @@ -31,8 +31,8 @@ static int dm_test_i2c_find(struct dm_test_state *dms) false, &bus)); /* - * i2c_post_bind() will bind devices to chip selects. Check this then - * remove the emulation and the slave device. + * The post_bind() method will bind devices to chip selects. Check + * this then remove the emulation and the slave device. */ ut_assertok(uclass_get_device_by_seq(UCLASS_I2C, busnum, &bus)); ut_assertok(dm_i2c_probe(bus, chip, 0, &dev)); @@ -43,13 +43,13 @@ static int dm_test_i2c_find(struct dm_test_state *dms) } DM_TEST(dm_test_i2c_find, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); -static int dm_test_i2c_read_write(struct dm_test_state *dms) +static int dm_test_i2c_read_write(struct unit_test_state *uts) { struct udevice *bus, *dev; uint8_t buf[5]; ut_assertok(uclass_get_device_by_seq(UCLASS_I2C, busnum, &bus)); - ut_assertok(i2c_get_chip(bus, chip, &dev)); + ut_assertok(i2c_get_chip(bus, chip, 1, &dev)); ut_assertok(dm_i2c_read(dev, 0, buf, 5)); ut_assertok(memcmp(buf, "\0\0\0\0\0", sizeof(buf))); ut_assertok(dm_i2c_write(dev, 2, (uint8_t *)"AB", 2)); @@ -60,31 +60,35 @@ static int dm_test_i2c_read_write(struct dm_test_state *dms) } DM_TEST(dm_test_i2c_read_write, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); -static int dm_test_i2c_speed(struct dm_test_state *dms) +static int dm_test_i2c_speed(struct unit_test_state *uts) { struct udevice *bus, *dev; uint8_t buf[5]; ut_assertok(uclass_get_device_by_seq(UCLASS_I2C, busnum, &bus)); - ut_assertok(i2c_get_chip(bus, chip, &dev)); - ut_assertok(i2c_set_bus_speed(bus, 100000)); + + /* Use test mode so we create the required errors for invalid speeds */ + sandbox_i2c_set_test_mode(bus, true); + ut_assertok(i2c_get_chip(bus, chip, 1, &dev)); + ut_assertok(dm_i2c_set_bus_speed(bus, 100000)); ut_assertok(dm_i2c_read(dev, 0, buf, 5)); - ut_assertok(i2c_set_bus_speed(bus, 400000)); - ut_asserteq(400000, i2c_get_bus_speed(bus)); + ut_assertok(dm_i2c_set_bus_speed(bus, 400000)); + ut_asserteq(400000, dm_i2c_get_bus_speed(bus)); ut_assertok(dm_i2c_read(dev, 0, buf, 5)); ut_asserteq(-EINVAL, dm_i2c_write(dev, 0, buf, 5)); + sandbox_i2c_set_test_mode(bus, false); return 0; } DM_TEST(dm_test_i2c_speed, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); -static int dm_test_i2c_offset_len(struct dm_test_state *dms) +static int dm_test_i2c_offset_len(struct unit_test_state *uts) { struct udevice *bus, *dev; uint8_t buf[5]; ut_assertok(uclass_get_device_by_seq(UCLASS_I2C, busnum, &bus)); - ut_assertok(i2c_get_chip(bus, chip, &dev)); + ut_assertok(i2c_get_chip(bus, chip, 1, &dev)); ut_assertok(i2c_set_chip_offset_len(dev, 1)); ut_assertok(dm_i2c_read(dev, 0, buf, 5)); @@ -95,25 +99,29 @@ static int dm_test_i2c_offset_len(struct dm_test_state *dms) } DM_TEST(dm_test_i2c_offset_len, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); -static int dm_test_i2c_probe_empty(struct dm_test_state *dms) +static int dm_test_i2c_probe_empty(struct unit_test_state *uts) { struct udevice *bus, *dev; ut_assertok(uclass_get_device_by_seq(UCLASS_I2C, busnum, &bus)); + + /* Use test mode so that this chip address will always probe */ + sandbox_i2c_set_test_mode(bus, true); ut_assertok(dm_i2c_probe(bus, SANDBOX_I2C_TEST_ADDR, 0, &dev)); + sandbox_i2c_set_test_mode(bus, false); return 0; } DM_TEST(dm_test_i2c_probe_empty, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); -static int dm_test_i2c_bytewise(struct dm_test_state *dms) +static int dm_test_i2c_bytewise(struct unit_test_state *uts) { struct udevice *bus, *dev; struct udevice *eeprom; uint8_t buf[5]; ut_assertok(uclass_get_device_by_seq(UCLASS_I2C, busnum, &bus)); - ut_assertok(i2c_get_chip(bus, chip, &dev)); + ut_assertok(i2c_get_chip(bus, chip, 1, &dev)); ut_assertok(dm_i2c_read(dev, 0, buf, 5)); ut_assertok(memcmp(buf, "\0\0\0\0\0", sizeof(buf))); @@ -161,13 +169,13 @@ static int dm_test_i2c_bytewise(struct dm_test_state *dms) } DM_TEST(dm_test_i2c_bytewise, DM_TESTF_SCAN_PDATA | DM_TESTF_SCAN_FDT); -static int dm_test_i2c_offset(struct dm_test_state *dms) +static int dm_test_i2c_offset(struct unit_test_state *uts) { struct udevice *eeprom; struct udevice *dev; uint8_t buf[5]; - ut_assertok(i2c_get_chip_for_busnum(busnum, chip, &dev)); + 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));