mirror of
https://github.com/Telecominfraproject/OpenCellular.git
synced 2026-01-08 16:41:55 +00:00
To test drivers, we need a way to fake I2C periphrals. With this CL, a fake peripheral can be done by declaring its own I2C read/write functions. The fake I2C peripherals may return EC_ERROR_INVAL to indicate it's not responding. The emulator I2C read/write call scans through all registered I2C peripherals and uses the first response. BUG=chrome-os-partner:19235 TEST=Pass sbs_charging test with the next CL. BRANCH=None Change-Id: I9380dc40e147781b42e09eb6979c864bbd9f2ac4 Signed-off-by: Vic Yang <victoryang@chromium.org> Reviewed-on: https://chromium-review.googlesource.com/169511 Reviewed-by: Randall Spangler <rspangler@chromium.org>
77 lines
1.8 KiB
C
77 lines
1.8 KiB
C
/* Copyright (c) 2013 The Chromium OS Authors. All rights reserved.
|
|
* Use of this source code is governed by a BSD-style license that can be
|
|
* found in the LICENSE file.
|
|
*
|
|
* Dummy I2C driver for unit test.
|
|
*/
|
|
|
|
#include "i2c.h"
|
|
#include "link_defs.h"
|
|
#include "test_util.h"
|
|
|
|
int i2c_read16(int port, int slave_addr, int offset, int *data)
|
|
{
|
|
const struct test_i2c_read_dev *p;
|
|
int rv;
|
|
|
|
for (p = __test_i2c_read16; p < __test_i2c_read16_end; ++p) {
|
|
rv = p->routine(port, slave_addr, offset, data);
|
|
if (rv != EC_ERROR_INVAL)
|
|
return rv;
|
|
}
|
|
return EC_ERROR_UNKNOWN;
|
|
}
|
|
|
|
int i2c_write16(int port, int slave_addr, int offset, int data)
|
|
{
|
|
const struct test_i2c_write_dev *p;
|
|
int rv;
|
|
|
|
for (p = __test_i2c_write16; p < __test_i2c_write16_end; ++p) {
|
|
rv = p->routine(port, slave_addr, offset, data);
|
|
if (rv != EC_ERROR_INVAL)
|
|
return rv;
|
|
}
|
|
return EC_ERROR_UNKNOWN;
|
|
}
|
|
|
|
int i2c_read8(int port, int slave_addr, int offset, int *data)
|
|
{
|
|
const struct test_i2c_read_dev *p;
|
|
int rv;
|
|
|
|
for (p = __test_i2c_read8; p < __test_i2c_read8_end; ++p) {
|
|
rv = p->routine(port, slave_addr, offset, data);
|
|
if (rv != EC_ERROR_INVAL)
|
|
return rv;
|
|
}
|
|
return EC_ERROR_UNKNOWN;
|
|
}
|
|
|
|
int i2c_write8(int port, int slave_addr, int offset, int data)
|
|
{
|
|
const struct test_i2c_write_dev *p;
|
|
int rv;
|
|
|
|
for (p = __test_i2c_write8; p < __test_i2c_write8_end; ++p) {
|
|
rv = p->routine(port, slave_addr, offset, data);
|
|
if (rv != EC_ERROR_INVAL)
|
|
return rv;
|
|
}
|
|
return EC_ERROR_UNKNOWN;
|
|
}
|
|
|
|
int i2c_read_string(int port, int slave_addr, int offset, uint8_t *data,
|
|
int len)
|
|
{
|
|
const struct test_i2c_read_string_dev *p;
|
|
int rv;
|
|
|
|
for (p = __test_i2c_read_string; p < __test_i2c_read_string_end; ++p) {
|
|
rv = p->routine(port, slave_addr, offset, data, len);
|
|
if (rv != EC_ERROR_INVAL)
|
|
return rv;
|
|
}
|
|
return EC_ERROR_UNKNOWN;
|
|
}
|