From patchwork Mon Dec 9 18:16:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Auchter X-Patchwork-Id: 1206483 X-Patchwork-Delegate: hs@denx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=ni.com Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=nio365.onmicrosoft.com header.i=@nio365.onmicrosoft.com header.b="pyyK2HyU"; dkim-atps=neutral Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47Ws0T2CyXz9sPJ for ; Tue, 10 Dec 2019 05:19:17 +1100 (AEDT) Received: from phobos.denx.de (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 56C0F80E97; Mon, 9 Dec 2019 19:19:09 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=fail (p=none dis=none) header.from=ni.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (1024-bit key; unprotected) header.d=nio365.onmicrosoft.com header.i=@nio365.onmicrosoft.com header.b="pyyK2HyU"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 30C02815E1; Mon, 9 Dec 2019 19:16:30 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=DKIM_SIGNED,DKIM_VALID, SPF_HELO_NONE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.2 Received: from mx0b-00010702.pphosted.com (mx0b-00010702.pphosted.com [148.163.158.57]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 9AA56808E5 for ; Mon, 9 Dec 2019 19:16:25 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=ni.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=prvs=324685f4e6=michael.auchter@ni.com Received: from pps.filterd (m0098779.ppops.net [127.0.0.1]) by mx0b-00010702.pphosted.com (8.16.0.42/8.16.0.42) with SMTP id xB9IARi5004546; Mon, 9 Dec 2019 12:16:19 -0600 Received: from nam02-cy1-obe.outbound.protection.outlook.com (mail-cys01nam02lp2053.outbound.protection.outlook.com [104.47.37.53]) by mx0b-00010702.pphosted.com with ESMTP id 2wrasacn76-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Mon, 09 Dec 2019 12:16:18 -0600 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=mNi604qPeUDaZX2cWmXlCu4+XRFqB7+xpAIk6yU8WE/sV0pqjfKIo/fQc4a5jsaj3NR4zvigbnOXNK56ZUmzaD2rwR3UkmVQk9o9qyz4F5BwEB+w5ypMw+Sm6BtdPv8WfJTuKq425j5TelTaSwOqHNxinyoQJJoFmC4fMBOv9oS6yj5PCEL88CX2JXB2XLK4cPITDljsBp5LJNYOxhqCQWtAACjWFRAr0/TrF25a4vXFa7Ukr+74bvBJcR9kFPtbCHiJStnGpaZ4uPeoY+Tn0kLnIf1kXcRyjQPp/6biv3SGbIlGLrMp3p53sckMnNpo0hh0cyw55pyZH9KEOXIB0g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=UJF1yiD9KwFxX0brCALtSQQqycD1aXttpO+i71vsXhE=; b=MJKdbRjk7Nk0PgyElav4089km3s4BUfC3LN3RoeXgVWpEHVYo9wKktJ2HjLmAefGRmXA7bxaM82yakbFONRAa4DDAiChaRhhxvlfMTQZV2cAdmiA73TuKdHZh40QYGYCWGqXS3Aj+KDRkG/JpckpJyRErk+Rxk135aC9Zu+Y4TKPTdw56a0pJisIBJlywbzebfNe38Jx+Vp3cqKGLze8Ps/kjmqL5Oz+joYaPZgVPtMmbRJah3t0QU+O7V3aGBcQ5RCX9IZYw7WX+8uo3X9Fxk4BkwfdP52IbKP90wofyY32amaHcAWOy/VwlfFNvozRWFKWNkyprZbPQxfTLtJM5A== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=ni.com; dmarc=pass action=none header.from=ni.com; dkim=pass header.d=ni.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=nio365.onmicrosoft.com; s=selector2-nio365-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=UJF1yiD9KwFxX0brCALtSQQqycD1aXttpO+i71vsXhE=; b=pyyK2HyU4O263uGLH9PX2ZvVaPR3+M5xkPKVO4ms7m9quyyr56HhMF/sZ8qlTr4pMDc981AhCh6f4kKn+n3CVWLmZ+IPG5JXwgVgQZrmVHhxxB17xrLmtcmBJYMlltpQ1wz1y/i1wFj/pQONeJkTQPXY/9jFNoy6MxjATuTz+xY= Received: from DM6PR04MB4553.namprd04.prod.outlook.com (20.176.107.93) by DM6PR04MB6140.namprd04.prod.outlook.com (20.178.227.28) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2516.17; Mon, 9 Dec 2019 18:16:17 +0000 Received: from DM6PR04MB4553.namprd04.prod.outlook.com ([fe80::3185:e1d7:38c8:9403]) by DM6PR04MB4553.namprd04.prod.outlook.com ([fe80::3185:e1d7:38c8:9403%5]) with mapi id 15.20.2516.015; Mon, 9 Dec 2019 18:16:17 +0000 From: Michael Auchter To: "u-boot@lists.denx.de" , "hs@denx.de" Subject: [PATCH] i2c: i2c_cdns: fix write timeout on fifo boundary Thread-Topic: [PATCH] i2c: i2c_cdns: fix write timeout on fifo boundary Thread-Index: AQHVrry/upym3Wen10achJdWVonnSg== Date: Mon, 9 Dec 2019 18:16:16 +0000 Message-ID: <20191209181546.23061-1-michael.auchter@ni.com> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-clientproxiedby: DM6PR13CA0037.namprd13.prod.outlook.com (2603:10b6:5:134::14) To DM6PR04MB4553.namprd04.prod.outlook.com (2603:10b6:5:21::29) x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: git-send-email 2.23.0 x-originating-ip: [130.164.62.96] x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: cae7ae75-c5cd-4db9-4f66-08d77cd3e1f7 x-ms-traffictypediagnostic: DM6PR04MB6140: x-ms-exchange-transport-forked: True x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:8882; x-forefront-prvs: 02462830BE x-forefront-antispam-report: SFV:NSPM; SFS:(10019020)(39860400002)(366004)(376002)(346002)(396003)(136003)(189003)(199004)(81156014)(66946007)(66556008)(66476007)(5660300002)(2906002)(64756008)(8936002)(305945005)(66446008)(81166006)(86362001)(8676002)(6486002)(186003)(478600001)(71190400001)(6506007)(52116002)(26005)(2616005)(36756003)(71200400001)(6512007)(1076003)(110136005)(316002)(44832011)(4326008); DIR:OUT; SFP:1102; SCL:1; SRVR:DM6PR04MB6140; H:DM6PR04MB4553.namprd04.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:1; received-spf: None (protection.outlook.com: ni.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: 5sZ5vX3Jm6GU81VppOZUo3pHUVTYdf6VaneIanUPqxo1p0qK3kdfhkJwID3bLa599BIIGTsf0D97CGOMB+W2KG/jkqpzPmYI4y+tVtGuP5RfduS90FvpSbjaBbNYbvPynu9TySz99Z2/kDBJv4DvyK0Kz/aIeRJogejfo1EfgJx9irY/tNBJOhJtHILYH++xjT83/P8GemZRN35aIZDJuBJcZaLI5BzVi/CzEUpmpia9Yxo9K2ukf1h2EdHFBdapAghbG5kYTup8GVJzG1t68CLSnVx4q2RYBUDHqcH3WB+3J2TmG0QaB8csL5yAGIzIlCMNyO7Cw249UqJi6Gvqw4fQJbF16JDrSIb//66Rf3Iz9E3uWS2+I6oJd96qeAwN1tzzhGFhN+RueR9uJ/TrDVa6LcjvsXJl4iEbFEvAUutIlNi92ZSv1gzciv/cRU4p MIME-Version: 1.0 X-OriginatorOrg: ni.com X-MS-Exchange-CrossTenant-Network-Message-Id: cae7ae75-c5cd-4db9-4f66-08d77cd3e1f7 X-MS-Exchange-CrossTenant-originalarrivaltime: 09 Dec 2019 18:16:17.0207 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 87ba1f9a-44cd-43a6-b008-6fdb45a5204e X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: kOw3RvA0fi/dcgt02dq6zPIFOryQ18gRFRhfl/jIqy8wW5TXwY9Yvo4tRKCrOMzTwtMmFEk9GbaRgc4wyFxQVQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR04MB6140 X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:6.0.95, 18.0.572 definitions=2019-12-09_04:2019-12-09, 2019-12-09 signatures=0 X-Proofpoint-Spam-Details: rule=inbound_policy_notspam policy=inbound_policy score=30 lowpriorityscore=0 mlxlogscore=999 priorityscore=1501 phishscore=0 impostorscore=0 mlxscore=0 suspectscore=0 malwarescore=0 clxscore=1011 spamscore=0 adultscore=0 bulkscore=0 classifier=spam adjust=30 reason=mlx scancount=1 engine=8.12.0-1910280000 definitions=main-1912090145 X-Mailman-Approved-At: Mon, 09 Dec 2019 19:19:07 +0100 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.26 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Michael Auchter Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.101.4 at phobos.denx.de X-Virus-Status: Clean This fixes an issue that would cause I2C writes to timeout when the number of bytes is a multiple of the FIFO depth (i.e. 16 bytes). Within the transfer loop, after writing the data register with a new byte to transfer, if the transfer size equals the FIFO depth, the loop pauses until the INTERRUPT_COMP bit asserts to indicate data has been sent. This same check is performed after the loop as well to ensure data has been transferred prior to returning. In the case where the amount of data to be written is a multiple of the FIFO depth, the transfer loop would wait for the INTERRUPT_COMP bit to assert after writing the final byte, and then wait for this bit to assert once more. However, since the transfer has finished at this point, no new data has been written to the data register, and hence INTERRUPT_COMP will never assert. Fix this by only waiting for INTERRUPT_COMP in the transfer loop if there's still data to be written. Signed-off-by: Michael Auchter Reviewed-by: Simon Glass --- drivers/i2c/i2c-cdns.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/i2c/i2c-cdns.c b/drivers/i2c/i2c-cdns.c index 2c0301ad08..ff3956d8c2 100644 --- a/drivers/i2c/i2c-cdns.c +++ b/drivers/i2c/i2c-cdns.c @@ -265,7 +265,7 @@ static int cdns_i2c_write_data(struct i2c_cdns_bus *i2c_bus, u32 addr, u8 *data, while (len-- && !is_arbitration_lost(regs)) { writel(*(cur_data++), ®s->data); - if (readl(®s->transfer_size) == CDNS_I2C_FIFO_DEPTH) { + if (len && readl(®s->transfer_size) == CDNS_I2C_FIFO_DEPTH) { ret = cdns_i2c_wait(regs, CDNS_I2C_INTERRUPT_COMP | CDNS_I2C_INTERRUPT_ARBLOST); if (ret & CDNS_I2C_INTERRUPT_ARBLOST)