X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=drivers%2Fi2c%2Fimx_lpi2c.c;h=d2e11b411babf0d969dc55f67fe75a84e5277b94;hb=a32effd2838a62a5d1dcc01f613508f1d90b5667;hp=e7ec17fe9e1b1c83d3021fadcb0968955fa2f3c9;hpb=2ee87b0c1a5439e4ad6467cb8d5e8fb58922ca4b;p=u-boot diff --git a/drivers/i2c/imx_lpi2c.c b/drivers/i2c/imx_lpi2c.c index e7ec17fe9e..d2e11b411b 100644 --- a/drivers/i2c/imx_lpi2c.c +++ b/drivers/i2c/imx_lpi2c.c @@ -1,7 +1,6 @@ +// SPDX-License-Identifier: GPL-2.0+ /* * Copyright 2016 Freescale Semiconductors, Inc. - * - * SPDX-License-Identifier: GPL-2.0+ */ #include @@ -9,14 +8,14 @@ #include #include #include -#include +#include #include #include #include #include -DECLARE_GLOBAL_DATA_PTR; #define LPI2C_FIFO_SIZE 4 +#define LPI2C_NACK_TOUT_MS 1 #define LPI2C_TIMEOUT_MS 100 /* Weak linked function for overridden by some SoC power function */ @@ -156,7 +155,7 @@ static int bus_i2c_receive(struct imx_lpi2c_reg *regs, u8 *rxbuf, int len) static int bus_i2c_start(struct imx_lpi2c_reg *regs, u8 addr, u8 dir) { - lpi2c_status_t result = LPI2C_SUCESS; + lpi2c_status_t result; u32 val; result = imx_lpci2c_check_busy_bus(regs); @@ -184,8 +183,9 @@ static int bus_i2c_start(struct imx_lpi2c_reg *regs, u8 addr, u8 dir) static int bus_i2c_stop(struct imx_lpi2c_reg *regs) { - lpi2c_status_t result = LPI2C_SUCESS; + lpi2c_status_t result; u32 status; + ulong start_time; result = bus_i2c_wait_for_tx_ready(regs); if (result) { @@ -196,7 +196,8 @@ static int bus_i2c_stop(struct imx_lpi2c_reg *regs) /* send stop command */ writel(LPI2C_MTDR_CMD(0x2), ®s->mtdr); - while (result == LPI2C_SUCESS) { + start_time = get_timer(0); + while (1) { status = readl(®s->msr); result = imx_lpci2c_check_clear_error(regs); /* stop detect flag */ @@ -206,6 +207,11 @@ static int bus_i2c_stop(struct imx_lpi2c_reg *regs) writel(status, ®s->msr); break; } + + if (get_timer(start_time) > LPI2C_NACK_TOUT_MS) { + debug("stop timeout\n"); + return -ETIMEDOUT; + } } return result; @@ -213,7 +219,7 @@ static int bus_i2c_stop(struct imx_lpi2c_reg *regs) static int bus_i2c_read(struct imx_lpi2c_reg *regs, u32 chip, u8 *buf, int len) { - lpi2c_status_t result = LPI2C_SUCESS; + lpi2c_status_t result; result = bus_i2c_start(regs, chip, 1); if (result) @@ -230,7 +236,7 @@ static int bus_i2c_read(struct imx_lpi2c_reg *regs, u32 chip, u8 *buf, int len) static int bus_i2c_write(struct imx_lpi2c_reg *regs, u32 chip, u8 *buf, int len) { - lpi2c_status_t result = LPI2C_SUCESS; + lpi2c_status_t result; result = bus_i2c_start(regs, chip, 0); if (result) @@ -258,7 +264,7 @@ static int bus_i2c_set_bus_speed(struct udevice *bus, int speed) int i; regs = (struct imx_lpi2c_reg *)devfdt_get_addr(bus); - clock_rate = imx_get_i2cclk(bus->seq + 4); + clock_rate = imx_get_i2cclk(bus->seq); if (!clock_rate) return -EPERM; @@ -354,7 +360,7 @@ static int imx_lpi2c_probe_chip(struct udevice *bus, u32 chip, u32 chip_flags) { struct imx_lpi2c_reg *regs; - lpi2c_status_t result = LPI2C_SUCESS; + lpi2c_status_t result; regs = (struct imx_lpi2c_reg *)devfdt_get_addr(bus); result = bus_i2c_start(regs, chip, 0); @@ -365,10 +371,8 @@ static int imx_lpi2c_probe_chip(struct udevice *bus, u32 chip, } result = bus_i2c_stop(regs); - if (result) { + if (result) bus_i2c_init(bus, 100000); - return -result; - } return result; } @@ -419,14 +423,14 @@ static int imx_lpi2c_probe(struct udevice *bus) i2c_bus->bus = bus; /* power up i2c resource */ - ret = init_i2c_power(bus->seq + 4); + ret = init_i2c_power(bus->seq); if (ret) { debug("init_i2c_power err = %d\n", ret); return ret; } - /* Enable clk, only i2c4-7 can be handled by A7 core */ - ret = enable_i2c_clk(1, bus->seq + 4); + /* To i.MX7ULP, only i2c4-7 can be handled by A7 core */ + ret = enable_i2c_clk(1, bus->seq); if (ret < 0) return ret; @@ -449,6 +453,7 @@ static const struct dm_i2c_ops imx_lpi2c_ops = { static const struct udevice_id imx_lpi2c_ids[] = { { .compatible = "fsl,imx7ulp-lpi2c", }, + { .compatible = "fsl,imx8qm-lpi2c", }, {} };