diff options
author | Keith Short <keithshort@chromium.org> | 2020-08-13 09:13:25 -0600 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2020-08-21 00:57:17 +0000 |
commit | 863a28e1c874d95853ae50900f3226e11b05cec9 (patch) | |
tree | 21d92185e70be52f434630afbb17eb32ecbec9a6 | |
parent | 95ef179b4776aabbef0ff438849aa99537889f52 (diff) | |
download | chrome-ec-863a28e1c874d95853ae50900f3226e11b05cec9.tar.gz |
bmi260: back out support for compressed config file
Now that the BMI260 config file can be moved to the .init_rom section,
the simple compression scheme is no longer needed.
BUG=b:160330682
BRANCH=none
TEST=make buildall
TEST=Verify BMI260 operation on both volteer and volteer_tcpmv1 builds
using "ectool motionsense lid_angle".
Signed-off-by: Keith Short <keithshort@chromium.org>
Change-Id: I83bbaadcd3dade2d585b771b6b9ebae7e9fdc0cb
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2354194
Reviewed-by: Jett Rink <jettrink@chromium.org>
Reviewed-by: caveh jalali <caveh@chromium.org>
-rw-r--r-- | driver/accelgyro_bmi260.c | 171 | ||||
-rw-r--r-- | include/config.h | 10 |
2 files changed, 6 insertions, 175 deletions
diff --git a/driver/accelgyro_bmi260.c b/driver/accelgyro_bmi260.c index 6e5fcda86a..6eeb80cb04 100644 --- a/driver/accelgyro_bmi260.c +++ b/driver/accelgyro_bmi260.c @@ -380,8 +380,11 @@ static int irq_handler(struct motion_sensor_t *s, uint32_t *event) } #endif /* CONFIG_ACCEL_INTERRUPTS */ -#if defined(CONFIG_ACCELGYRO_BMI160_COMPRESSED_CONFIG) || \ - defined(CONFIG_CHIP_INIT_ROM_REGION) +/* + * If the .init_rom section is not memory mapped, we need a static + * buffer in RAM to access the BMI configuration data. + */ +#ifdef CONFIG_CHIP_INIT_ROM_REGION #define BMI_RAM_BUFFER_SIZE 256 static uint8_t bmi_ram_buffer[BMI_RAM_BUFFER_SIZE]; #else @@ -389,163 +392,6 @@ static uint8_t bmi_ram_buffer[BMI_RAM_BUFFER_SIZE]; static uint8_t *bmi_ram_buffer; #endif -/* - * TODO(b/160330682): Eliminate or reduce size of BMI260 initialization file. - * Remove this option once the BMI260 initialization file is moved to the - * kernel rootfs. - */ -#ifdef CONFIG_ACCELGYRO_BMI160_COMPRESSED_CONFIG - -#define INCBIN_STYLE INCBIN_STYLE_SNAKE -#define INCBIN_PREFIX -#include "third_party/incbin/incbin.h" -INCBIN(bmi260_config, - "third_party/bmi260/accelgyro_bmi260_config_compressed.bin"); - -#define COMPRESS_KEY 0xE9EA -static int bmi_buffer_bytes; -static int bmi_config_offset; - -static int write_bmi_data(const struct motion_sensor_t *s) -{ - uint8_t addr[2]; - int ret; - - if (bmi_buffer_bytes == 0) - return EC_SUCCESS; - - addr[0] = (bmi_config_offset / 2) & 0xF; - addr[1] = (bmi_config_offset / 2) >> 4; - ret = bmi_write_n(s->port, s->i2c_spi_addr_flags, - BMI260_INIT_ADDR_0, addr, 2); - if (ret) - return ret; - - ret = bmi_write_n(s->port, s->i2c_spi_addr_flags, - BMI260_INIT_DATA, bmi_ram_buffer, - bmi_buffer_bytes); - if (ret) - return ret; - - bmi_config_offset += bmi_buffer_bytes; - bmi_buffer_bytes = 0; - - return EC_SUCCESS; -} - -/* - * Stores 4 bytes of BMI configuration data into a static buffer. If the buffer - * is filled, write the buffer contents over I2C. - */ -static int enqueue_bmi_data(const struct motion_sensor_t *s, uint32_t *data) -{ - int ret; - - memcpy(&bmi_ram_buffer[bmi_buffer_bytes], data, 4); - bmi_buffer_bytes += 4; - - if (bmi_buffer_bytes >= BMI_RAM_BUFFER_SIZE) { - ret = write_bmi_data(s); - if (ret) - return ret; - } - - return EC_SUCCESS; -} - -/* - * Load the BMI configuration data from a compressed buffer. - * - * Compression scheme: - * Repeated 32-bit words are replaced by a 16-bit key, 16-bit count, and - * the 32-bit data word. All values stored big-endian. - * - * For example, if the uncompressed file had the following data words: - * 0x89ABCDEF 0x89ABCDEF 0x89ABCDEF - * - * This is represented compressed as (key 0xE9EA): - * 0xE9EA0003 0x89ABCDEF - * - * Key value (0xE9EA) chosen as it wasn't found in the BMI configuration - * data. - */ -int bmi_compressed_config_load(const struct motion_sensor_t *s) -{ - uint32_t *bmi_compressed_config = (uint32_t *)bmi260_config_data; - int length = bmi260_config_size; - int i; - int output_offset; - uint16_t *buf16; - uint16_t key; - uint16_t repeat_count; - uint32_t *data32; - int ret; - - length /= sizeof(uint32_t); - - bmi_buffer_bytes = 0; - bmi_config_offset = 0; - - output_offset = 0; - - for (i = 0; i < length; i++) { - buf16 = (uint16_t *)&bmi_compressed_config[i]; - key = be16toh(*buf16); - - if (key == COMPRESS_KEY) { - repeat_count = be16toh(*++buf16); - - if (repeat_count == 0) { - CPRINTF("BMI260 config: invalid repeat count " - "found at word offset %d\n", - i); - return EC_ERROR_UNKNOWN; - } - - /* - * Advance to the next word in the buffer, which - * contains the actual data to write. - */ - if (++i >= length) { - CPRINTF("BMI260 config: " - "Unexpected end of file\n"); - return EC_ERROR_UNKNOWN; - } - - data32 = &bmi_compressed_config[i]; - - while (repeat_count-- > 0) { - ret = enqueue_bmi_data(s, data32); - if (ret) - return ret; - - output_offset += 4; - } - } else { - data32 = &bmi_compressed_config[i]; - ret = enqueue_bmi_data(s, data32); - if (ret) - return ret; - - output_offset += 4; - } - } - - ret = write_bmi_data(s); - - return ret; -} - -static int bmi_config_load(const struct motion_sensor_t *s) -{ - return EC_ERROR_UNKNOWN; -} -#else /* !CONFIG_ACCELGYRO_BMI160_COMPRESSED_CONFIG */ -static int bmi_compressed_config_load(const struct motion_sensor_t *s) -{ - return EC_ERROR_UNKNOWN; -} - static int bmi_config_load(const struct motion_sensor_t *s) { int ret = EC_SUCCESS; @@ -621,8 +467,6 @@ static int bmi_config_load(const struct motion_sensor_t *s) return ret; } -#endif /* CONFIG_ACCELGYRO_BMI160_COMPRESSED_CONFIG */ - static int init_config(const struct motion_sensor_t *s) { int init_status, ret; @@ -635,10 +479,7 @@ static int init_config(const struct motion_sensor_t *s) bmi_write8(s->port, s->i2c_spi_addr_flags, BMI260_INIT_CTRL, 0); /* load config file to INIT_DATA */ - if (IS_ENABLED(CONFIG_ACCELGYRO_BMI160_COMPRESSED_CONFIG)) - ret = bmi_compressed_config_load(s); - else - ret = bmi_config_load(s); + ret = bmi_config_load(s); /* finish config load */ bmi_write8(s->port, s->i2c_spi_addr_flags, BMI260_INIT_CTRL, 1); diff --git a/include/config.h b/include/config.h index 18c377faf1..8ea8c2c24c 100644 --- a/include/config.h +++ b/include/config.h @@ -193,16 +193,6 @@ #undef CONFIG_ACCELGYRO_BMI160_INT2_OUTPUT #undef CONFIG_ACCELGYRO_BMI260_INT2_OUTPUT -/* - * If defined, use a compressed version of the BMI260 configuration file. - * Saves a net of about 900 bytes of flash space. - * - * TODO(b/160330682): Eliminate or reduce size of BMI260 initialization file. - * Remove this option once the BMI260 initialization file is moved to the - * kernel rootfs. - */ -#undef CONFIG_ACCELGYRO_BMI160_COMPRESSED_CONFIG - /* Specify type of Gyrometers attached. */ #undef CONFIG_GYRO_L3GD20H |