Skip to content

Commit

Permalink
drivers/i2c: it8xxx2: Add a property for maximum time allowed I2C tra…
Browse files Browse the repository at this point in the history
…nsfer

Add a property of the maximum time allowed for an I2C transfer.

Signed-off-by: Tim Lin <tim2.lin@ite.corp-partner.google.com>
  • Loading branch information
GTLin08 authored and fabiobaltieri committed Sep 18, 2024
1 parent 7b8beea commit fd5ecef
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
7 changes: 4 additions & 3 deletions drivers/i2c/i2c_ite_enhance.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ struct i2c_enhance_config {
uint8_t prescale_scl_low;
uint8_t data_hold_time;
uint32_t clock_gate_offset;
int transfer_timeout_ms;
bool target_enable;
bool target_pio_mode;
bool push_pull_recovery;
Expand Down Expand Up @@ -626,8 +627,7 @@ static int i2c_enhance_pio_transfer(const struct device *dev,
irq_enable(config->i2c_irq_base);
}
/* Wait for the transfer to complete */
/* TODO: the timeout should be adjustable */
res = k_sem_take(&data->device_sync_sem, K_MSEC(100));
res = k_sem_take(&data->device_sync_sem, K_MSEC(config->transfer_timeout_ms));
/*
* The irq will be enabled at the condition of start or
* repeat start of I2C. If timeout occurs without being
Expand Down Expand Up @@ -838,7 +838,7 @@ static int i2c_enhance_cq_transfer(const struct device *dev,
irq_enable(config->i2c_irq_base);
}
/* Wait for the transfer to complete */
res = k_sem_take(&data->device_sync_sem, K_MSEC(100));
res = k_sem_take(&data->device_sync_sem, K_MSEC(config->transfer_timeout_ms));

irq_disable(config->i2c_irq_base);

Expand Down Expand Up @@ -1495,6 +1495,7 @@ BUILD_ASSERT(IS_ENABLED(CONFIG_I2C_TARGET_BUFFER_MODE),
.prescale_scl_low = DT_INST_PROP_OR(inst, prescale_scl_low, 0), \
.data_hold_time = DT_INST_PROP_OR(inst, data_hold_time, 0), \
.clock_gate_offset = DT_INST_PROP(inst, clock_gate_offset), \
.transfer_timeout_ms = DT_INST_PROP(inst, transfer_timeout_ms), \
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(inst), \
.target_enable = DT_INST_PROP(inst, target_enable), \
.target_pio_mode = DT_INST_PROP(inst, target_pio_mode), \
Expand Down
5 changes: 3 additions & 2 deletions drivers/i2c/i2c_ite_it8xxx2.c
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ struct i2c_it8xxx2_config {
/* I2C alternate configuration */
const struct pinctrl_dev_config *pcfg;
uint32_t clock_gate_offset;
int transfer_timeout_ms;
bool fifo_enable;
bool push_pull_recovery;
};
Expand Down Expand Up @@ -1008,8 +1009,7 @@ static int i2c_it8xxx2_transfer(const struct device *dev, struct i2c_msg *msgs,
}
}
/* Wait for the transfer to complete */
/* TODO: the timeout should be adjustable */
res = k_sem_take(&data->device_sync_sem, K_MSEC(100));
res = k_sem_take(&data->device_sync_sem, K_MSEC(config->transfer_timeout_ms));
/*
* The irq will be enabled at the condition of start or
* repeat start of I2C. If timeout occurs without being
Expand Down Expand Up @@ -1306,6 +1306,7 @@ DT_INST_FOREACH_STATUS_OKAY(I2C_IT8XXX2_CHECK_SUPPORTED_CLOCK)
.scl_gpios = GPIO_DT_SPEC_INST_GET(inst, scl_gpios), \
.sda_gpios = GPIO_DT_SPEC_INST_GET(inst, sda_gpios), \
.clock_gate_offset = DT_INST_PROP(inst, clock_gate_offset), \
.transfer_timeout_ms = DT_INST_PROP(inst, transfer_timeout_ms), \
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(inst), \
.fifo_enable = DT_INST_PROP(inst, fifo_enable), \
.push_pull_recovery = DT_INST_PROP(inst, push_pull_recovery), \
Expand Down
6 changes: 6 additions & 0 deletions dts/bindings/i2c/ite,common-i2c.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,12 @@ properties:
The clock gate offsets combine the register offset from
ECPM_BASE and the mask within that register into one value.
transfer-timeout-ms:
type: int
default: 100
description: |
Maximum time allowed for an I2C transfer.
pinctrl-0:
required: true

Expand Down

0 comments on commit fd5ecef

Please sign in to comment.