Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 59DCEC636D4 for ; Mon, 13 Feb 2023 08:04:25 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 74B8D85762; Mon, 13 Feb 2023 09:04:12 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=starfivetech.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id DD4258564B; Mon, 13 Feb 2023 09:03:35 +0100 (CET) Received: from fd01.gateway.ufhost.com (fd01.gateway.ufhost.com [61.152.239.71]) by phobos.denx.de (Postfix) with ESMTP id F0ADB85698 for ; Mon, 13 Feb 2023 09:03:26 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=starfivetech.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=peiyue.ho@starfivetech.com Received: from EXMBX166.cuchost.com (unknown [175.102.18.54]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "EXMBX166", Issuer "EXMBX166" (not verified)) by fd01.gateway.ufhost.com (Postfix) with ESMTP id 0C22424E2BA; Mon, 13 Feb 2023 16:03:25 +0800 (CST) Received: from EXMBX173.cuchost.com (172.16.6.93) by EXMBX166.cuchost.com (172.16.6.76) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Mon, 13 Feb 2023 16:03:24 +0800 Received: from ubuntu.localdomain (161.142.156.76) by EXMBX173.cuchost.com (172.16.6.93) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Mon, 13 Feb 2023 16:03:20 +0800 From: Pei Yue Ho To: CC: , , , Subject: [PATCH v2 2/2] i2c: i2c-cdns.c: Update driver to read fifo-depth from device tree Date: Mon, 13 Feb 2023 00:02:41 -0800 Message-ID: <20230213080241.194878-3-peiyue.ho@starfivetech.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230213080241.194878-1-peiyue.ho@starfivetech.com> References: <20230213080241.194878-1-peiyue.ho@starfivetech.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [161.142.156.76] X-ClientProxiedBy: EXCAS061.cuchost.com (172.16.6.21) To EXMBX173.cuchost.com (172.16.6.93) X-YovoleRuleAgent: yovoleflag Content-Transfer-Encoding: quoted-printable X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean Enable driver to fetch the optional parameter (fifo-depth) from device tree. If the parameter is not found in the device tree, it will use the default value declared in the driver. Signed-off-by: Pei Yue Ho Reviewed-by: Wei Liang Lim Reviewed-by: Eng Lee Teh --- drivers/i2c/i2c-cdns.c | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/drivers/i2c/i2c-cdns.c b/drivers/i2c/i2c-cdns.c index 0da9f6f35a..c1672ca18e 100644 --- a/drivers/i2c/i2c-cdns.c +++ b/drivers/i2c/i2c-cdns.c @@ -78,7 +78,7 @@ struct cdns_i2c_regs { CDNS_I2C_INTERRUPT_RXUNF | \ CDNS_I2C_INTERRUPT_ARBLOST) =20 -#define CDNS_I2C_FIFO_DEPTH 16 +#define CDNS_I2C_FIFO_DEPTH_DEFAULT 16 #define CDNS_I2C_TRANSFER_SIZE_MAX 255 /* Controller transfer limit */ #define CDNS_I2C_TRANSFER_SIZE (CDNS_I2C_TRANSFER_SIZE_MAX - 3) =20 @@ -135,6 +135,7 @@ struct i2c_cdns_bus { =20 int hold_flag; u32 quirks; + u32 fifo_depth; }; =20 struct cdns_i2c_platform_data { @@ -277,7 +278,7 @@ static int cdns_i2c_write_data(struct i2c_cdns_bus *i= 2c_bus, u32 addr, u8 *data, writel(addr, ®s->address); start =3D 0; } - if (len && readl(®s->transfer_size) =3D=3D CDNS_I2C_FIFO_DEPTH) { + if (len && readl(®s->transfer_size) =3D=3D i2c_bus->fifo_depth) { ret =3D cdns_i2c_wait(regs, CDNS_I2C_INTERRUPT_COMP | CDNS_I2C_INTERRUPT_ARBLOST); if (ret & CDNS_I2C_INTERRUPT_ARBLOST) @@ -310,9 +311,10 @@ static int cdns_i2c_write_data(struct i2c_cdns_bus *= i2c_bus, u32 addr, u8 *data, return 0; } =20 -static inline bool cdns_is_hold_quirk(int hold_quirk, int curr_recv_coun= t) +static inline bool cdns_is_hold_quirk(struct i2c_cdns_bus *i2c_bus, int = hold_quirk, + int curr_recv_count) { - return hold_quirk && (curr_recv_count =3D=3D CDNS_I2C_FIFO_DEPTH + 1); + return hold_quirk && (curr_recv_count =3D=3D i2c_bus->fifo_depth + 1); } =20 static int cdns_i2c_read_data(struct i2c_cdns_bus *i2c_bus, u32 addr, u8= *data, @@ -327,7 +329,7 @@ static int cdns_i2c_read_data(struct i2c_cdns_bus *i2= c_bus, u32 addr, u8 *data, curr_recv_count =3D recv_count; =20 /* Check for the message size against the FIFO depth */ - if (recv_count > CDNS_I2C_FIFO_DEPTH) + if (recv_count > i2c_bus->fifo_depth) setbits_le32(®s->control, CDNS_I2C_CONTROL_HOLD); =20 setbits_le32(®s->control, CDNS_I2C_CONTROL_CLR_FIFO | @@ -349,7 +351,7 @@ static int cdns_i2c_read_data(struct i2c_cdns_bus *i2= c_bus, u32 addr, u8 *data, =20 while (recv_count && !is_arbitration_lost(regs)) { while (readl(®s->status) & CDNS_I2C_STATUS_RXDV) { - if (recv_count < CDNS_I2C_FIFO_DEPTH && + if (recv_count < i2c_bus->fifo_depth && !i2c_bus->hold_flag) { clrbits_le32(®s->control, CDNS_I2C_CONTROL_HOLD); @@ -358,27 +360,27 @@ static int cdns_i2c_read_data(struct i2c_cdns_bus *= i2c_bus, u32 addr, u8 *data, recv_count--; curr_recv_count--; =20 - if (cdns_is_hold_quirk(hold_quirk, curr_recv_count)) + if (cdns_is_hold_quirk(i2c_bus, hold_quirk, curr_recv_count)) break; } =20 - if (cdns_is_hold_quirk(hold_quirk, curr_recv_count)) { + if (cdns_is_hold_quirk(i2c_bus, hold_quirk, curr_recv_count)) { /* wait while fifo is full */ while (readl(®s->transfer_size) !=3D - (curr_recv_count - CDNS_I2C_FIFO_DEPTH)) + (curr_recv_count - i2c_bus->fifo_depth)) ; /* * Check number of bytes to be received against maximum * transfer size and update register accordingly. */ - if ((recv_count - CDNS_I2C_FIFO_DEPTH) > + if ((recv_count - i2c_bus->fifo_depth) > CDNS_I2C_TRANSFER_SIZE) { writel(CDNS_I2C_TRANSFER_SIZE, ®s->transfer_size); curr_recv_count =3D CDNS_I2C_TRANSFER_SIZE + - CDNS_I2C_FIFO_DEPTH; + i2c_bus->fifo_depth; } else { - writel(recv_count - CDNS_I2C_FIFO_DEPTH, + writel(recv_count - i2c_bus->fifo_depth, ®s->transfer_size); curr_recv_count =3D recv_count; } @@ -496,6 +498,10 @@ static int cdns_i2c_of_to_plat(struct udevice *dev) return ret; } =20 + /* Update FIFO depth based on device tree entry */ + i2c_bus->fifo_depth =3D dev_read_u32_default(dev, "fifo-depth", + CDNS_I2C_FIFO_DEPTH_DEFAULT); + return 0; } =20 --=20 2.25.1