From mboxrd@z Thu Jan 1 00:00:00 1970 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 41CF8C54EBC for ; Wed, 4 Jan 2023 13:10:44 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id EFD9385573; Wed, 4 Jan 2023 14:09:57 +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 1F94285573; Wed, 4 Jan 2023 08:21:01 +0100 (CET) Received: from ex01.ufhost.com (ex01.ufhost.com [61.152.239.75]) by phobos.denx.de (Postfix) with ESMTP id 04BA585560 for ; Wed, 4 Jan 2023 08:20:58 +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 EXMBX165.cuchost.com (unknown [175.102.18.54]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client CN "EXMBX165", Issuer "EXMBX165" (not verified)) by ex01.ufhost.com (Postfix) with ESMTP id C2FE224E1B7 for ; Wed, 4 Jan 2023 15:20:55 +0800 (CST) Received: from EXMBX173.cuchost.com (172.16.6.93) by EXMBX165.cuchost.com (172.16.6.75) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Wed, 4 Jan 2023 15:20:55 +0800 Received: from ubuntu.localdomain (202.188.176.82) by EXMBX173.cuchost.com (172.16.6.93) with Microsoft SMTP Server (TLS) id 15.0.1497.42; Wed, 4 Jan 2023 15:20:52 +0800 From: Pei Yue Ho To: CC: , , Subject: [PATCH 2/2] i2c: i2c-cdns.c: Update driver to read fifo-depth from device tree Date: Tue, 3 Jan 2023 23:20:05 -0800 Message-ID: <20230104072005.7812-3-peiyue.ho@starfivetech.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230104072005.7812-1-peiyue.ho@starfivetech.com> References: <20230104072005.7812-1-peiyue.ho@starfivetech.com> MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [202.188.176.82] X-ClientProxiedBy: EXCAS064.cuchost.com (172.16.6.24) To EXMBX173.cuchost.com (172.16.6.93) X-YovoleRuleAgent: yovoleflag Content-Transfer-Encoding: quoted-printable X-Mailman-Approved-At: Wed, 04 Jan 2023 14:09:34 +0100 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 | 26 ++++++++++++++++---------- 1 file changed, 16 insertions(+), 10 deletions(-) diff --git a/drivers/i2c/i2c-cdns.c b/drivers/i2c/i2c-cdns.c index 0da9f6f35a..65a0c76a2a 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); @@ -365,20 +367,20 @@ static int cdns_i2c_read_data(struct i2c_cdns_bus *= i2c_bus, u32 addr, u8 *data, if (cdns_is_hold_quirk(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