Skip to content

Commit 8dacd0f

Browse files
GTLin08cfriedt
authored andcommitted
ITE: drivers/i2c: returning negative values for error
Fixes: #38959 Currently, the I2C driver returns I2C status register value as error code when error happen. This PR fixes returning system number and the return values is negative for error. Signed-off-by: Tim Lin <[email protected]>
1 parent 2d0d093 commit 8dacd0f

File tree

1 file changed

+28
-1
lines changed

1 file changed

+28
-1
lines changed

drivers/i2c/i2c_ite_it8xxx2.c

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,33 @@ static const struct i2c_pin i2c_pin_regs[] = {
164164
{ &GPDMRA, &GPDMRA, 0x10, 0x20},
165165
};
166166

167+
static int i2c_parsing_return_value(const struct device *dev)
168+
{
169+
struct i2c_it8xxx2_data *data = DEV_DATA(dev);
170+
const struct i2c_it8xxx2_config *config = DEV_CFG(dev);
171+
172+
if (!data->err)
173+
return 0;
174+
175+
/* Connection timed out */
176+
if (data->err == ETIMEDOUT)
177+
return -ETIMEDOUT;
178+
179+
if (config->port < I2C_STANDARD_PORT_COUNT) {
180+
/* The device does not respond ACK */
181+
if (data->err == HOSTA_NACK)
182+
return -ENXIO;
183+
else
184+
return -EIO;
185+
} else {
186+
/* The device does not respond ACK */
187+
if (data->err == E_HOSTA_ACK)
188+
return -ENXIO;
189+
else
190+
return -EIO;
191+
}
192+
}
193+
167194
static int i2c_get_line_levels(const struct device *dev)
168195
{
169196
const struct i2c_it8xxx2_config *config = DEV_CFG(dev);
@@ -835,7 +862,7 @@ static int i2c_it8xxx2_transfer(const struct device *dev, struct i2c_msg *msgs,
835862
/* Unlock mutex of i2c controller */
836863
k_mutex_unlock(&data->mutex);
837864

838-
return data->err;
865+
return i2c_parsing_return_value(dev);
839866
}
840867

841868
static void i2c_it8xxx2_isr(void *arg)

0 commit comments

Comments
 (0)