diff options
author | Jett Rink <jettrink@chromium.org> | 2019-07-08 14:12:23 -0600 |
---|---|---|
committer | Commit Bot <commit-bot@chromium.org> | 2019-07-09 16:45:44 +0000 |
commit | 8034b2f86690daf458e8881621556a28e5b59a1a (patch) | |
tree | 78de569fea80bcb13b9b8f38d545e447347f0c38 | |
parent | 48765c68fc17b84902afc0a3bd5926e5721e669f (diff) | |
download | chrome-ec-8034b2f86690daf458e8881621556a28e5b59a1a.tar.gz |
ish: cleanup i2c constants
Rename i2c constants to expose the speed they represent.
BRANCH=none
BUG=none
TEST=builds. arcada i2c bus speed is correct
Change-Id: If26f4868053f5df0a83bf1f06b62b6969dd5a44f
Signed-off-by: Jett Rink <jettrink@chromium.org>
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/1691310
Commit-Queue: Jack Rosenthal <jrosenth@chromium.org>
Reviewed-by: Jack Rosenthal <jrosenth@chromium.org>
-rw-r--r-- | chip/ish/i2c.c | 32 | ||||
-rw-r--r-- | chip/ish/ish_i2c.h | 15 |
2 files changed, 26 insertions, 21 deletions
diff --git a/chip/ish/i2c.c b/chip/ish/i2c.c index 9099c983b9..f6c0cf3d0b 100644 --- a/chip/ish/i2c.c +++ b/chip/ish/i2c.c @@ -50,9 +50,6 @@ static uint16_t default_lcnt_scl_1000[] = { static uint16_t default_hcnt_scl_hs[] = { 160, 300, 160, 166, 175, 150, 162 }; static uint16_t default_lcnt_scl_hs[] = { 320, 340, 320, 325, 325, 300, 297 }; -static uint8_t speed_val_arr[] = { - STD_SPEED_VAL, FAST_SPEED_VAL, FAST_PLUS_SPEED_VAL, HIGH_SPEED_VAL -}; static uint8_t bus_freq[ISH_I2C_PORT_COUNT] = { I2C_FREQ_120, I2C_FREQ_120, I2C_FREQ_120 @@ -62,19 +59,19 @@ static struct i2c_context i2c_ctxs[ISH_I2C_PORT_COUNT] = { { .bus = 0, .base = (uint32_t *) ISH_I2C0_BASE, - .speed = I2C_SPEED_FAST, + .speed = I2C_SPEED_400KHZ, .int_pin = ISH_I2C0_IRQ, }, { .bus = 1, .base = (uint32_t *) ISH_I2C1_BASE, - .speed = I2C_SPEED_FAST, + .speed = I2C_SPEED_400KHZ, .int_pin = ISH_I2C1_IRQ, }, { .bus = 2, .base = (uint32_t *) ISH_I2C2_BASE, - .speed = I2C_SPEED_FAST, + .speed = I2C_SPEED_400KHZ, .int_pin = ISH_I2C2_IRQ, }, }; @@ -174,7 +171,7 @@ static void i2c_init_transaction(struct i2c_context *ctx, /* set Clock SCL Count */ switch (ctx->speed) { - case I2C_SPEED_STD: + case I2C_SPEED_100KHZ: i2c_mmio_write(base, IC_SS_SCL_HCNT, NS_2_COUNTERS(bus_info->std_speed.hcnt, clk_in_val)); @@ -186,7 +183,7 @@ static void i2c_init_transaction(struct i2c_context *ctx, clk_in_val)); break; - case I2C_SPEED_FAST: + case I2C_SPEED_400KHZ: i2c_mmio_write(base, IC_FS_SCL_HCNT, NS_2_COUNTERS(bus_info->fast_speed.hcnt, clk_in_val)); @@ -198,7 +195,7 @@ static void i2c_init_transaction(struct i2c_context *ctx, clk_in_val)); break; - case I2C_SPEED_FAST_PLUS: + case I2C_SPEED_1MHZ: i2c_mmio_write(base, IC_FS_SCL_HCNT, NS_2_COUNTERS(bus_info->fast_plus_speed.hcnt, clk_in_val)); @@ -210,7 +207,7 @@ static void i2c_init_transaction(struct i2c_context *ctx, clk_in_val)); break; - case I2C_SPEED_HIGH: + case I2C_SPEED_3M4HZ: i2c_mmio_write(base, IC_HS_SCL_HCNT, NS_2_COUNTERS(bus_info->high_speed.hcnt, clk_in_val)); @@ -469,18 +466,25 @@ static void i2c_config_speed(struct i2c_context *ctx, int kbps) { if (kbps > 1000) - ctx->speed = I2C_SPEED_HIGH; + ctx->speed = I2C_SPEED_3M4HZ; else if (kbps > 400) - ctx->speed = I2C_SPEED_FAST_PLUS; + ctx->speed = I2C_SPEED_1MHZ; else if (kbps > 100) - ctx->speed = I2C_SPEED_FAST; + ctx->speed = I2C_SPEED_400KHZ; else - ctx->speed = I2C_SPEED_STD; + ctx->speed = I2C_SPEED_100KHZ; } static void i2c_init_hardware(struct i2c_context *ctx) { + static const uint8_t speed_val_arr[] = { + [I2C_SPEED_100KHZ] = STD_SPEED_VAL, + [I2C_SPEED_400KHZ] = FAST_SPEED_VAL, + [I2C_SPEED_1MHZ] = FAST_SPEED_VAL, + [I2C_SPEED_3M4HZ] = HIGH_SPEED_VAL, + }; + uint32_t *base = ctx->base; /* disable interrupts */ diff --git a/chip/ish/ish_i2c.h b/chip/ish/ish_i2c.h index b9b284c7c5..5b30de775c 100644 --- a/chip/ish/ish_i2c.h +++ b/chip/ish/ish_i2c.h @@ -27,11 +27,6 @@ enum { - /* speed mode values */ - I2C_SPEED_STD = 0, - I2C_SPEED_FAST = 1, - I2C_SPEED_FAST_PLUS = 2, - I2C_SPEED_HIGH = 3, /* freq mode values */ I2C_FREQ_25 = 0, I2C_FREQ_50 = 1, @@ -117,7 +112,6 @@ enum { MASTER_MODE_VAL = (MASTER_MODE << MASTER_MODE_OFFSET), STD_SPEED_VAL = (STD_SPEED << SPEED_OFFSET), FAST_SPEED_VAL = (FAST_SPEED << SPEED_OFFSET), - FAST_PLUS_SPEED_VAL = (FAST_SPEED << SPEED_OFFSET), HIGH_SPEED_VAL = (HIGH_SPEED << SPEED_OFFSET), SPEED_MASK = (0x3 << SPEED_OFFSET), IC_RESTART_EN_VAL = (IC_RESTART_EN << IC_RESTART_EN_OFFSET), @@ -188,12 +182,19 @@ struct i2c_bus_info { struct i2c_bus_data high_speed; } __attribute__ ((__packed__)); +enum i2c_speed { + I2C_SPEED_100KHZ, /* 100kHz */ + I2C_SPEED_400KHZ, /* 400kHz */ + I2C_SPEED_1MHZ, /* 1MHz */ + I2C_SPEED_3M4HZ, /* 3.4MHz */ +}; + struct i2c_context { uint32_t *base; uint8_t max_rx_depth; uint8_t max_tx_depth; uint8_t bus; - uint8_t speed; + enum i2c_speed speed; uint32_t interrupts; uint32_t reason; uint32_t int_pin; |