Skip to content

Commit fd5ecef

Browse files
GTLin08fabiobaltieri
authored andcommitted
drivers/i2c: it8xxx2: Add a property for maximum time allowed I2C transfer
Add a property of the maximum time allowed for an I2C transfer. Signed-off-by: Tim Lin <[email protected]>
1 parent 7b8beea commit fd5ecef

File tree

3 files changed

+13
-5
lines changed

3 files changed

+13
-5
lines changed

drivers/i2c/i2c_ite_enhance.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ struct i2c_enhance_config {
7373
uint8_t prescale_scl_low;
7474
uint8_t data_hold_time;
7575
uint32_t clock_gate_offset;
76+
int transfer_timeout_ms;
7677
bool target_enable;
7778
bool target_pio_mode;
7879
bool push_pull_recovery;
@@ -626,8 +627,7 @@ static int i2c_enhance_pio_transfer(const struct device *dev,
626627
irq_enable(config->i2c_irq_base);
627628
}
628629
/* Wait for the transfer to complete */
629-
/* TODO: the timeout should be adjustable */
630-
res = k_sem_take(&data->device_sync_sem, K_MSEC(100));
630+
res = k_sem_take(&data->device_sync_sem, K_MSEC(config->transfer_timeout_ms));
631631
/*
632632
* The irq will be enabled at the condition of start or
633633
* repeat start of I2C. If timeout occurs without being
@@ -838,7 +838,7 @@ static int i2c_enhance_cq_transfer(const struct device *dev,
838838
irq_enable(config->i2c_irq_base);
839839
}
840840
/* Wait for the transfer to complete */
841-
res = k_sem_take(&data->device_sync_sem, K_MSEC(100));
841+
res = k_sem_take(&data->device_sync_sem, K_MSEC(config->transfer_timeout_ms));
842842

843843
irq_disable(config->i2c_irq_base);
844844

@@ -1495,6 +1495,7 @@ BUILD_ASSERT(IS_ENABLED(CONFIG_I2C_TARGET_BUFFER_MODE),
14951495
.prescale_scl_low = DT_INST_PROP_OR(inst, prescale_scl_low, 0), \
14961496
.data_hold_time = DT_INST_PROP_OR(inst, data_hold_time, 0), \
14971497
.clock_gate_offset = DT_INST_PROP(inst, clock_gate_offset), \
1498+
.transfer_timeout_ms = DT_INST_PROP(inst, transfer_timeout_ms), \
14981499
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(inst), \
14991500
.target_enable = DT_INST_PROP(inst, target_enable), \
15001501
.target_pio_mode = DT_INST_PROP(inst, target_pio_mode), \

drivers/i2c/i2c_ite_it8xxx2.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ struct i2c_it8xxx2_config {
5252
/* I2C alternate configuration */
5353
const struct pinctrl_dev_config *pcfg;
5454
uint32_t clock_gate_offset;
55+
int transfer_timeout_ms;
5556
bool fifo_enable;
5657
bool push_pull_recovery;
5758
};
@@ -1008,8 +1009,7 @@ static int i2c_it8xxx2_transfer(const struct device *dev, struct i2c_msg *msgs,
10081009
}
10091010
}
10101011
/* Wait for the transfer to complete */
1011-
/* TODO: the timeout should be adjustable */
1012-
res = k_sem_take(&data->device_sync_sem, K_MSEC(100));
1012+
res = k_sem_take(&data->device_sync_sem, K_MSEC(config->transfer_timeout_ms));
10131013
/*
10141014
* The irq will be enabled at the condition of start or
10151015
* repeat start of I2C. If timeout occurs without being
@@ -1306,6 +1306,7 @@ DT_INST_FOREACH_STATUS_OKAY(I2C_IT8XXX2_CHECK_SUPPORTED_CLOCK)
13061306
.scl_gpios = GPIO_DT_SPEC_INST_GET(inst, scl_gpios), \
13071307
.sda_gpios = GPIO_DT_SPEC_INST_GET(inst, sda_gpios), \
13081308
.clock_gate_offset = DT_INST_PROP(inst, clock_gate_offset), \
1309+
.transfer_timeout_ms = DT_INST_PROP(inst, transfer_timeout_ms), \
13091310
.pcfg = PINCTRL_DT_INST_DEV_CONFIG_GET(inst), \
13101311
.fifo_enable = DT_INST_PROP(inst, fifo_enable), \
13111312
.push_pull_recovery = DT_INST_PROP(inst, push_pull_recovery), \

dts/bindings/i2c/ite,common-i2c.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@ properties:
9797
The clock gate offsets combine the register offset from
9898
ECPM_BASE and the mask within that register into one value.
9999
100+
transfer-timeout-ms:
101+
type: int
102+
default: 100
103+
description: |
104+
Maximum time allowed for an I2C transfer.
105+
100106
pinctrl-0:
101107
required: true
102108

0 commit comments

Comments
 (0)