diff options
author | Denis Brockus <dbrockus@chromium.org> | 2019-07-16 09:05:34 -0600 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2019-07-17 21:25:38 +0000 |
commit | 0e3dd9d2cc19b65654f8090aa02f8dac20358c2e (patch) | |
tree | 854d25ef2b0e9333fd69618fcbf258f23b620d72 | |
parent | 3811a28a607e40f5291e45d7c57da6b0700fb821 (diff) | |
download | chrome-ec-0e3dd9d2cc19b65654f8090aa02f8dac20358c2e.tar.gz |
common: remove CONFIG_SMBUS dead code
CONFIG_SMBUS is not used. Cleaning up the code by
removing this.
Added a comment to document the removal and why. This will
give a way to find the code if we ever needed to bring it back
BUG=chromium:982316
BRANCH=none
TEST=make buildall
Change-Id: I40703a95bc849538e1aee32f6f96beab811285bd
Signed-off-by: Denis Brockus <dbrockus@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1704279
Reviewed-by: Daisuke Nojiri <dnojiri@chromium.org>
-rw-r--r-- | common/build.mk | 1 | ||||
-rw-r--r-- | common/smbus.c | 162 | ||||
-rw-r--r-- | driver/battery/smart.c | 20 | ||||
-rw-r--r-- | include/config.h | 17 | ||||
-rw-r--r-- | include/smbus.h | 158 |
5 files changed, 16 insertions, 342 deletions
diff --git a/common/build.mk b/common/build.mk index 425a5ba4fc..61f64fca35 100644 --- a/common/build.mk +++ b/common/build.mk @@ -113,7 +113,6 @@ common-$(CONFIG_RWSIG_TYPE_RWSIG)+=vboot/vb21_lib.o common-$(CONFIG_MATH_UTIL)+=math_util.o common-$(CONFIG_SHA1)+= sha1.o common-$(CONFIG_SHA256)+=sha256.o -common-$(CONFIG_SMBUS)+= smbus.o common-$(CONFIG_SOFTWARE_CLZ)+=clz.o common-$(CONFIG_SOFTWARE_CTZ)+=ctz.o common-$(CONFIG_CMD_SPI_XFER)+=spi_commands.o diff --git a/common/smbus.c b/common/smbus.c deleted file mode 100644 index dfe0dcc964..0000000000 --- a/common/smbus.c +++ /dev/null @@ -1,162 +0,0 @@ -/* Copyright 2014 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. - * - * smbus cross-platform code for Chrome EC - * ref: http://smbus.org/specs/smbus20.pdf - */ - -#include "common.h" -#include "console.h" -#include "util.h" -#include "i2c.h" -#include "smbus.h" -#include "crc8.h" - -#define CPRINTF(format, args...) cprintf(CC_I2C, format, ## args) - -/* Write 2 bytes using smbus word access protocol */ -int smbus_write_word(uint8_t i2c_port, uint8_t slave_addr, - uint8_t smbus_cmd, uint16_t d16) -{ - uint8_t buf[5]; - - /* Command sequence for CRC calculation */ - buf[0] = slave_addr; - buf[1] = smbus_cmd; - buf[2] = d16 & 0xff; - buf[3] = (d16 >> 8) & 0xff; - buf[4] = crc8(buf, 4); - return i2c_xfer(i2c_port, slave_addr, buf + 1, 4, NULL, 0); -} - -/* Write up to SMBUS_MAX_BLOCK_SIZE bytes using smbus block access protocol */ -int smbus_write_block(uint8_t i2c_port, uint8_t slave_addr, - uint8_t smbus_cmd, uint8_t *data, uint8_t len) -{ - uint8_t buf[3]; - int rv; - - /* Command sequence for CRC calculation */ - buf[0] = slave_addr; - buf[1] = smbus_cmd; - buf[2] = len; - - i2c_lock(i2c_port, 1); - - /* Send command + length */ - rv = i2c_xfer_unlocked(i2c_port, slave_addr, - buf + 1, 2, NULL, 0, I2C_XFER_START); - if (rv != EC_SUCCESS) - goto smbus_write_block_done; - - /* Send data */ - rv = i2c_xfer_unlocked(i2c_port, slave_addr, data, len, NULL, 0, 0); - if (rv != EC_SUCCESS) - goto smbus_write_block_done; - - /* Send CRC */ - buf[0] = crc8(buf, 3); - buf[0] = crc8_arg(data, len, buf[0]); - rv = i2c_xfer_unlocked(i2c_port, slave_addr, buf, 1, NULL, 0, - I2C_XFER_STOP); - -smbus_write_block_done: - i2c_lock(i2c_port, 0); - return rv; -} - -/* Read 2 bytes using smbus word access protocol */ -int smbus_read_word(uint8_t i2c_port, uint8_t slave_addr, - uint8_t smbus_cmd, uint16_t *p16) -{ - uint8_t buf[3]; - int rv; - uint8_t crc; - - /* Command sequence for CRC calculation */ - buf[0] = slave_addr; - buf[1] = smbus_cmd; - buf[2] = slave_addr | 0x1; - crc = crc8(buf, 3); - - /* Read data bytes + CRC byte */ - rv = i2c_xfer(i2c_port, slave_addr, &smbus_cmd, 1, buf, 3); - - /* Verify CRC */ - if (crc8_arg(buf, 2, crc) != buf[2]) - rv = EC_ERROR_CRC; - - if (rv == EC_SUCCESS) - *p16 = (buf[1] << 8) | buf[0]; - else - *p16 = 0; - - return rv; -} - -/* Read up to SMBUS_MAX_BLOCK_SIZE bytes using smbus block access protocol */ -int smbus_read_block(uint8_t i2c_port, uint8_t slave_addr, - uint8_t smbus_cmd, uint8_t *data, uint8_t *plen) -{ - int rv, read_len; - uint8_t buf[4]; - uint8_t crc; - int do_crc = 1; - - /* Command sequence for CRC calculation */ - buf[0] = slave_addr; - buf[1] = smbus_cmd; - buf[2] = slave_addr | 0x1; - - i2c_lock(i2c_port, 1); - - /* First read size from slave */ - rv = i2c_xfer_unlocked(i2c_port, slave_addr, - &smbus_cmd, 1, buf + 3, 1, I2C_XFER_START); - if (rv != EC_SUCCESS) - goto smbus_read_block_done; - crc = crc8(buf, 4); - - /* - * If our input buffer isn't large enough to hold the entire input, - * don't bother verifying crc since it may require reading numerous - * data bytes that will be thrown away. - */ - read_len = MIN(buf[3], SMBUS_MAX_BLOCK_SIZE); - if (*plen < read_len) { - do_crc = 0; - read_len = *plen; - } - - /* Now read back all bytes */ - rv = i2c_xfer_unlocked(i2c_port, slave_addr, - NULL, 0, data, read_len, 0); - if (rv) - goto smbus_read_block_done; - - /* Read CRC + verify */ - rv = i2c_xfer_unlocked(i2c_port, slave_addr, - NULL, 0, buf, 1, I2C_XFER_STOP); - if (do_crc && crc8_arg(data, read_len, crc) != buf[0]) - rv = EC_ERROR_CRC; - -smbus_read_block_done: - if (rv != EC_SUCCESS) - memset(data, 0x0, *plen); - else - *plen = read_len; - - i2c_lock(i2c_port, 0); - return rv; -} - -int smbus_read_string(int i2c_port, uint8_t slave_addr, uint8_t smbus_cmd, - uint8_t *data, uint8_t len) -{ - int rv; - len -= 1; - rv = smbus_read_block(i2c_port, slave_addr, smbus_cmd, data, &len); - data[len] = '\0'; - return rv; -} diff --git a/driver/battery/smart.c b/driver/battery/smart.c index 4903b601fd..e42ebc726a 100644 --- a/driver/battery/smart.c +++ b/driver/battery/smart.c @@ -10,7 +10,6 @@ #include "console.h" #include "host_command.h" #include "i2c.h" -#include "smbus.h" #include "timer.h" #include "util.h" @@ -31,17 +30,7 @@ test_mockable int sb_read(int cmd, int *param) if (battery_is_cut_off()) return EC_RES_ACCESS_DENIED; #endif -#ifdef CONFIG_SMBUS - { - int rv; - uint16_t d16 = 0; - rv = smbus_read_word(I2C_PORT_BATTERY, BATTERY_ADDR, cmd, &d16); - *param = d16; - return rv; - } -#else return i2c_read16(I2C_PORT_BATTERY, BATTERY_ADDR, cmd, param); -#endif } test_mockable int sb_write(int cmd, int param) @@ -53,11 +42,7 @@ test_mockable int sb_write(int cmd, int param) if (battery_is_cut_off()) return EC_RES_ACCESS_DENIED; #endif -#ifdef CONFIG_SMBUS - return smbus_write_word(I2C_PORT_BATTERY, BATTERY_ADDR, cmd, param); -#else return i2c_write16(I2C_PORT_BATTERY, BATTERY_ADDR, cmd, param); -#endif } int sb_read_string(int offset, uint8_t *data, int len) @@ -69,13 +54,8 @@ int sb_read_string(int offset, uint8_t *data, int len) if (battery_is_cut_off()) return EC_RES_ACCESS_DENIED; #endif -#ifdef CONFIG_SMBUS - return smbus_read_string(I2C_PORT_BATTERY, BATTERY_ADDR, - offset, data, len); -#else return i2c_read_string(I2C_PORT_BATTERY, BATTERY_ADDR, offset, data, len); -#endif } int sb_read_mfgacc(int cmd, int block, uint8_t *data, int len) diff --git a/include/config.h b/include/config.h index 546833b26f..3eb6d671d6 100644 --- a/include/config.h +++ b/include/config.h @@ -3054,7 +3054,22 @@ #undef CONFIG_SOFTWARE_CTZ /* Support smbus interface */ -#undef CONFIG_SMBUS +/* + * Deprecated in + * https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1704279 + * + * It hasn't been used in over 2 years + * https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/452459/ + * and was only used by one board (pyro). + * + * I2C and SMBus are compatible at the physical layer. The data transfer + * paradigm is different. Some of our batteries are using SMbus style + * transfers now, they are just using i2cxfer directly to accomplish it. + * + * I doubt the SMBus code will get revived, but we do have it in revision + * history if we ever need it. + */ +/* #undef CONFIG_SMBUS */ /* Support SPI interfaces */ #undef CONFIG_SPI diff --git a/include/smbus.h b/include/smbus.h deleted file mode 100644 index 41c0287dab..0000000000 --- a/include/smbus.h +++ /dev/null @@ -1,158 +0,0 @@ -/* Copyright 2014 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. - * - * @file smbus.h - * @brief smbus interface APIs - * @see http://smbus.org/specs/smbus20.pdf - */ -#ifndef __CROS_EC_SMBUS_H -#define __CROS_EC_SMBUS_H - -/** Maximum transfer of a SMBUS block transfer */ -#define SMBUS_MAX_BLOCK_SIZE 32 - -/** - * smbus write word - * write 2 byte data + 1 byte pec - */ -struct smbus_wr_word { - uint8_t slave_addr;/**< i2c_addr << 1 */ - uint8_t smbus_cmd; /**< smbus cmd */ - uint8_t data[3]; /**< smbus data */ -} __packed; - -/** - * smbus write block data - * smbus write 1 byte size + 32 byte data + 1 byte pec - */ -struct smbus_wr_block { - uint8_t slave_addr;/**< i2c_addr << 1 */ - uint8_t smbus_cmd; /**< smbus cmd */ - uint8_t size; /**< write size */ - uint8_t data[SMBUS_MAX_BLOCK_SIZE+1]; -} __packed; - -/** - * smbus read word - * smbus read 2 byte + 1 pec - */ -struct smbus_rd_word { - uint8_t slave_addr; /**< i2c_addr << 1 */ - uint8_t smbus_cmd; /**< smbus cmd */ - uint8_t slave_addr_rd;/**< (i2c_addr << 1) | 0x1 */ - uint8_t data[3]; /**< smbus data */ -} __packed; - -/** - * smbus read block data - * smbus read 1 byte size + 32 byte data + 1 byte pec - */ -struct smbus_rd_block { - uint8_t slave_addr; /**< i2c_addr << 1 */ - uint8_t smbus_cmd; /**< smbus cmd */ - uint8_t slave_addr_rd;/**< (i2c_addr << 1) | 0x1 */ - uint8_t size; /**< read block size */ - uint8_t data[SMBUS_MAX_BLOCK_SIZE+1]; /**< smbus data */ -} __packed; - -/** - * smbus_write_word - * smbus write 2 bytes - * @param i2c_port uint8_t, i2c port address - * @param slave_addr uint8_t, i2c slave address:= (i2c_addr << 1) - * @param smbus_cmd uint8_t, smbus command - * @param d16 uint16_t, 2-bytes data - * @return error_code - * EC_SUCCESS if success; none-zero if fail - * EC_ERROR_BUSY if interface is bussy - * none zero error code if fail - */ -int smbus_write_word(uint8_t i2c_port, uint8_t slave_addr, - uint8_t smbus_cmd, uint16_t d16); - -/** - * smbus_write_block - * smbus write upto 32 bytes - * case 1: n-1 byte data, 1 byte PEC - * [S][i2c Address][Wr=0][A][cmd][A] ...[Di][Ai]... [PEC][A][P] - * - * case 2: 1 byte data-size, n -2 byte data, 1 byte PEC - * [S][i2c Address][Wr=0][A][cmd][A][size][A] ...[Di][Ai]... [PEC][A][P] - * - * @param i2c_port uint8_t, i2c port address - * @param slave_addr uint8_t, i2c slave address:= (i2c_addr << 1) - * @param smbus_cmd uint8_t, smbus command - * @param data uint8_t *, n-bytes data - * @param len uint8_t, data length - * @return error_code - * EC_SUCCESS if success; none-zero if fail - * EC_ERROR_BUSY if interface is bussy - * none zero error code if fail - */ -int smbus_write_block(uint8_t i2c_port, uint8_t slave_addr, - uint8_t smbus_cmd, uint8_t *data, uint8_t len); - -/** - * smbus_read_word - * smbus read 2 bytes - * @param i2c_port uint8_t, i2c port address - * @param slave_addr uint8_t, i2c slave address:= (i2c_addr << 1) - * @param smbus_cmd uint8_t, smbus command - * @param p16 uint16_t *, a pointer to 2-bytes data - * @return error_code - * EC_SUCCESS if success; none-zero if fail - * EC_ERROR_BUSY if interface is bussy - * none zero error code if fail - */ -int smbus_read_word(uint8_t i2c_port, uint8_t slave_addr, - uint8_t smbus_cmd, uint16_t *p16); - -/** - * smbus_read_block - * smbus read upto 32 bytes - * case 1: n-1 byte data, 1 byte PEC - * [S][i2c addr][Wr=0][A][cmd][A] - * [S][i2c addr][Rd=1][A]...[Di][Ai]...[PEC][A][P] - * - * case 2: 1 byte data-size, n - 2 byte data, 1 byte PEC - * [S][i2c addr][Wr=0][A][cmd][A] - * [S][i2c addr][Rd=1][A][size][A]...[Di][Ai]...[PEC][A][P] - * - * @param i2c_port uint8_t, i2c port address - * @param slave_addr uint8_t, i2c slave address:= (i2c_addr << 1) - * @param smbus_cmd uint8_t, smbus command - * @param data uint8_t *, n-bytes data - * @param plen uint8_t *, a pointer data length - * @return error_code - * EC_SUCCESS if success; none-zero if fail - * EC_ERROR_BUSY if interface is busy - * none zero error code if fail - */ -int smbus_read_block(uint8_t i2c_port, uint8_t slave_addr, - uint8_t smbus_cmd, uint8_t *data, uint8_t *plen); - -/** - * smbus_read_string - * smbus read ascii string (upto 32-byte data + 1-byte NULL) - * Read bytestream from <slaveaddr>:<smbus_cmd> with format: - * [length_N] [byte_0] [byte_1] ... [byte_N-1][byte_N='\0'] - * - * <len> : the max length of receiving buffer. to read N bytes - * ascii, len should be at least N+1 to include the - * terminating 0 (NULL). - * - * @param i2c_port uint8_t, i2c port address - * @param slave_addr uint8_t, i2c slave address:= (i2c_addr << 1) - * @param smbus_cmd uint8_t, smbus command - * @param data uint8_t *, n-bytes data - * @param len uint8_t, data length - * @return error_code - * EC_SUCCESS if success; none-zero if fail - * EC_ERROR_BUSY if interface is bussy - * none zero error code if fail - */ -int smbus_read_string(int i2c_port, uint8_t slave_addr, uint8_t smbus_cmd, - uint8_t *data, uint8_t len); - -#endif /* __CROS_EC_SMBUS_H */ |