From patchwork Tue Nov 21 18:11:16 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Hancock X-Patchwork-Id: 13463448 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 545CAC61D85 for ; Tue, 21 Nov 2023 18:12:04 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:In-Reply-To:References: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=E8YSyJ3aKZtJf90DUCMdY3w54j0AZtVwItywpP3++Xs=; b=dIyMo/xyXrxrjy OB8EYICwv8Fq+97xNekGJgt79nlHWtAeuKBTTiaFc9VImXxGWQ9hDhu6zZOSKhe1IPXzZURfkNWWd i53d6tqWxF3DmpL1ufUlilAk5f7Rvik7N0M7IKNsGLe41D3spf0eE+vUCitPZlFbEHdLhLlAmPmPa aakI0raOhMCzR3bWRV1oStEmN9dgnIgHHfBQxSdsxNVP5EfkxP+hRjCznCj8PkurvcYYh6fSbLddN gljAwx1FyLeKnk73dGv4AQvJ9/4db4QYVjGq78gx4GJOV7cG63jJ+HGlYRKH1Lab0aWnW3jpm77z1 +6x8nEwzcZXcueKcJ+MA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r5VDk-00HSPQ-1W; Tue, 21 Nov 2023 18:11:36 +0000 Received: from mx0d-0054df01.pphosted.com ([67.231.150.19]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1r5VDh-00HSOS-2I for linux-arm-kernel@lists.infradead.org; Tue, 21 Nov 2023 18:11:35 +0000 Received: from pps.filterd (m0209000.ppops.net [127.0.0.1]) by mx0c-0054df01.pphosted.com (8.17.1.22/8.17.1.22) with ESMTP id 3ALGjfjk008745; Tue, 21 Nov 2023 13:11:18 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=calian.com; h= from:to:cc:subject:date:message-id:references:in-reply-to :content-type:content-transfer-encoding:mime-version; s= selector2; bh=5mGu5VrTZ1uxhDkQbpjBnmRqw6c/pX66NcJSf0+xmS4=; b=EY wRqnNnpRII7q8+Eugpk+Uz8QtKZJzX4qPZWst1HBpSMXufh9smz+u53f7vcWR6m9 U8/6KTZ2ZtHon6GvMttqhfV1zTTJSnMpwogGPLY3vB1bAaoSc2mNG8We35Z3gKt2 rBAqkznLZkNuOvV+yaWaXG+1yelotOjkxjh3yS381B3F1BDFPNtwGrJAOGC7XMjn ZQ9nNC6oP8WW8VlN5Fo1vFypuSWxuI510MJ1gZGQcQghUSaITzwddGx/nqZhPP+o PseWgRW45wvdqUiRnUYxlJv9/fCac69Wg6zpgAgVtUP7wUKmREao91izbnGqdcXb Vaov2+DehUof8//lGXYw== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=calian.com; h= from:to:cc:subject:date:message-id:references:in-reply-to :content-type:content-transfer-encoding:mime-version; s= selector1; bh=5mGu5VrTZ1uxhDkQbpjBnmRqw6c/pX66NcJSf0+xmS4=; b=e6 FsFpOgO2ASBO0QmsRrWVL2WGyLrONvcb09K8NJnr7wpELPARSNiLJlTQQ6c3MFL3 MlwrO7ZUsa++GrAbsIG0YCvDxG95FfgcdtZjiKygqAIXBQJuuFyp1amIM54RcaKt 4J5Drwuizh+edFrjiS88XOHB8J/wjoqnh1mH4zjOi5tW0SYhvaveTL8O4Lc6Em/w Ajxf3NiQsPJ3zsHw/Krc/4dxxrFk/mTS8ZOfVwXIMTDbbTgpO2lriXr+wd4X4GMb kICK5d1SGLXQh9YZU57eoHdl23eO4oAfwZ2cbJoeP0PmqHGFY/TFT05+ttZoFz/S Lphw2oDs0wu+R8nuFyWA== Received: from can01-yqb-obe.outbound.protection.outlook.com (mail-yqbcan01lp2232.outbound.protection.outlook.com [104.47.75.232]) by mx0c-0054df01.pphosted.com (PPS) with ESMTPS id 3ueu25adec-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 21 Nov 2023 13:11:18 -0500 (EST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=PY7huSQCtM38mnsUeEVqx2nt1WnmPkOxneuyfY/A3tEctpxZFL+EUY9CB5K0OlD6Cz/pvO0XSIXsIpKbCVaTIOCvldCu8V0hkEs/PgzhCnWZTw+eK4Ji+0imq5P2pGFCkp1xjWXCAqxwjRp6uLGga7STFzv+2oXI2PS2Xv7D/JmgCvVQIhgdazUYlvQ4Q0G1CCeEtYo5GvB36kUbe11kF0z8Ahbpuetqjuv9I4ZTbambrAlucRNgTgXP8lh2ldWPvjnbqjpVC5gRDtWck2hYM+VAW54CnxG4MkthqXf1WUiG+LH9ULi1G7rZC7e0DiEwkFjtRE9Ne3akSmdGM/cbNg== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=5mGu5VrTZ1uxhDkQbpjBnmRqw6c/pX66NcJSf0+xmS4=; b=k5D4/laRAfZ7Yfi1qGIaZsyrEz2ywsJ1DKR3mSNYOdYEyXnfrBArEWpd6dBCsZml0kaEM472ScZB6MUn7hwhno5z+iVaWpPLrYkRUzj1+cymjHq9hZGbI/AdBEE5+WLtGy5DPdXMl+PYjLca4C9W3301rxsrqtuKoz6Bk3wsL1UKytGrPJOF1ZjPcv5z02frsRJgTYMhGi0Y5Pjek9qQJQL5UyBOljNKD49hFQBUBso7n4PYkJ4jdpzo7avDpv2/XovkU3dC0YMgoJpOzGifvVFZvtQDPecefD4u6n2IPozmHNlHAkdxsgyH8+3RciGlzdmzkcN/vuWSZMI2YxEu7g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=calian.com; dmarc=pass action=none header.from=calian.com; dkim=pass header.d=calian.com; arc=none Received: from YT2PR01MB8838.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:b9::6) by YT3PR01MB9202.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:7f::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7025.18; Tue, 21 Nov 2023 18:11:16 +0000 Received: from YT2PR01MB8838.CANPRD01.PROD.OUTLOOK.COM ([fe80::8e4a:d951:9c01:a8af]) by YT2PR01MB8838.CANPRD01.PROD.OUTLOOK.COM ([fe80::8e4a:d951:9c01:a8af%5]) with mapi id 15.20.7025.017; Tue, 21 Nov 2023 18:11:16 +0000 From: Robert Hancock To: "michal.simek@amd.com" , "ben-linux@fluff.org" , "andi.shyti@kernel.org" CC: "linux-arm-kernel@lists.infradead.org" , "linux-i2c@vger.kernel.org" , Robert Hancock Subject: [PATCH v2 1/2] i2c: xiic: Wait for TX empty to avoid missed TX NAKs Thread-Topic: [PATCH v2 1/2] i2c: xiic: Wait for TX empty to avoid missed TX NAKs Thread-Index: AQHaHKYehxqHQRxHX0um/MNCnhIwPA== Date: Tue, 21 Nov 2023 18:11:16 +0000 Message-ID: <20231121180855.1278717-2-robert.hancock@calian.com> References: <20231121180855.1278717-1-robert.hancock@calian.com> In-Reply-To: <20231121180855.1278717-1-robert.hancock@calian.com> Accept-Language: en-CA, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.42.0 user-agent: Evolution 3.48.4 (3.48.4-1.fc38) x-ms-publictraffictype: Email x-ms-traffictypediagnostic: YT2PR01MB8838:EE_|YT3PR01MB9202:EE_ x-ms-office365-filtering-correlation-id: ec6c836f-4141-4463-9f37-08dbeabd40ef x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: lc6/5Ou5VF3Nez3o7SrI+aP2mmE0mXIk5lrUTwq51AKA8to0oTANtYRddC63sUfwRiKFtoxZdnFRDQK6PIAGUKOCClSTWgh02nZBgwYy5OUXQYVbx0+SEK3+6rKORtHkhmu5F5dQONRYgopqjC04OeZ2BIFG6jJ8PkhjU2tgDBouEyxQW1f1ShYrMWO+HHI3EBkfzksz3wZdpETNiw/qaSFCNVnK3Ru6B6iIyOZEhySzmZtwa54eQsz2VJiwBRRfCvQP1wcXjX5/T9+iL4xRtwwwXJh4bULZs52Sk9WF/Fhoa7rDt39QYveXdACaJOjHJFmT/+ACyF0ROg6iLkhdsXErxPTW2FbZRpWJjQuVnvCee6Zck1TLuS3+lzSF9NDAsuYJUONVLPIUAcxQiIx8vDC14vrYB7d6owFqCNQG8uz4FqCjq/TVJDzLUoqKYsARkjzWPOyXHkF5c5Z8exRSOpnaeD9kWs95HnMivOUD+/od3LvNQaJgK4i/Ax5UUpJHqMnIZmM9rNtmkABFtaI+XKvJ8/r3T7YsXEbk6sa89cOq45fTKXx0ikY9mRinTko68RVpYczxev8lyRaH/c+uHFN9/nya13E1R/zfVc39dV+CS+NNSYzylfDeJdG9wy6j x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:YT2PR01MB8838.CANPRD01.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(13230031)(136003)(376002)(396003)(346002)(366004)(39860400002)(230922051799003)(186009)(451199024)(64100799003)(1800799012)(6512007)(71200400001)(6486002)(478600001)(122000001)(6506007)(316002)(8936002)(8676002)(4326008)(26005)(38100700002)(66476007)(2616005)(110136005)(91956017)(76116006)(66946007)(66446008)(66556008)(64756008)(54906003)(83380400001)(107886003)(1076003)(44832011)(5660300002)(2906002)(41300700001)(86362001)(36756003)(38070700009);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?dma8K+JIxYldP3hspeV7b99?= =?iso-8859-1?q?/9xmuaSzJUu8iGibZ0vZt/XMyChAkri3LuKCNXrwjMykAS5AWxiZWbkO6ajg?= =?iso-8859-1?q?4LrLXKD5gv1dG2sGD0XGfNJ8GLb5gtp5GHfde20ZAWMxkqUD45awmL5q2ezI?= =?iso-8859-1?q?z0r4nG1SRSkDYDYBSCgDWAQMSq0JZIaAw1FZbHtA42PUm9Q54MT1bkjNLnRr?= =?iso-8859-1?q?/BsCL7AVhH9joEVWdZxKPlL91NC/TGPXvoVVC7Q0tO47r5UaJ7Dfydv5x0w3?= =?iso-8859-1?q?eE5rdRSNEtmXqBWnTjyqbK7aKRLPzzKGr07LoN0d2pRDD1kTBtx49/JkDaAG?= =?iso-8859-1?q?q+he/+03L5bosEVBMiIqMfCMN70ewd1humaA7s8xBFhQl/PM4DJgXUmxv31g?= =?iso-8859-1?q?fliCi8Vx3wDs9FTQxxEc4iVXngrkqBsAVJqQK4qRR3wxRPWc4ilNGn0E9xc8?= =?iso-8859-1?q?iEyuR5KjQle3tnQE4ONgIva/IP+GkAk9Z0ovMURoW67CQVXiFxDJhlnyjy+R?= =?iso-8859-1?q?WzCW497Ztug5pGEsMaPk/3HxXtTSGdV1vaIPrittWKQbEILrmsJAIuw8WjX2?= =?iso-8859-1?q?cxZG09MipdDtTS7C1WwUuw8URoRBq4mBkwUlSybWerfAwJIywYjiQ8pux8kR?= =?iso-8859-1?q?CLJN2zaB+czgfhFFacdRQfzMsMSnuG0gPXofffcTkSDZK2PkriwO03p3OgcR?= =?iso-8859-1?q?eQhJ20u656NRZ9s3zPyjzmG0EbJoQudtGX+hU0dA5AIiOICeANFnJNov3uke?= =?iso-8859-1?q?M7xro71ioIs5YkWPQW1IXLWxjxuwueMFFTdEDqtKUFbrUTNrSWM1ngvrDTmU?= =?iso-8859-1?q?ts46jNmI048BkGhscZeq/wdTfA1qL56bj4nxijiQJJY7VM4BMBXCFHVujf/L?= =?iso-8859-1?q?rwo9vPNlVC0DxBl7wcgqxUNwzENIqj0qEjz352skOxhHWzbVUhazGQhSXLtk?= =?iso-8859-1?q?pW4OixQHJYvjeDdqa+4egu8A5yVSe/aC1TasfF+0f69cq32l6b4loh9e1N5h?= =?iso-8859-1?q?kWArRVdXEYKrOxVemhyGl9eNAgh0WNGB7l1FwDZsAj1wGZE5yUiJavImm0ci?= =?iso-8859-1?q?fQuEYfrZGDd+kwsDontkPOAsy9yqYzPCYUsFIHdcdOtVMmb96OLwFIy3p/38?= =?iso-8859-1?q?9CLlzDujcWrI6LTLR4MXliLmP17gm5mOVUMupKbnNgfY6YqNyUmeJ9DAPYcj?= =?iso-8859-1?q?0ex0REg3bZUwljBq8mDgM+hP5KKxxTw1mOWliiEIpqho6B76dIZ3HnBUylGU?= =?iso-8859-1?q?OhNHO0NAsNS7E5g03G7+JjPRDwbO5LBA+qroW0GG09GoblL3GQ+7tKqLW+8h?= =?iso-8859-1?q?JMsswyKH0Zew2ihRbOf6kGUNNk/nncSp6yUcNgaQW88kGL5Wtd0RQa/BHIN7?= =?iso-8859-1?q?Hmajcb1nIPC1z5wkElvy0u+vSEw6MxM4POQgvJdak+t5+bw9eZKJbpbKFpMh?= =?iso-8859-1?q?ckNrODkdmDAY+GNmHXDM+TcQihT6BT41wIfYzJNlJX32u4KmR9TnSnPMPYWr?= =?iso-8859-1?q?sjNjb5O9oKRLCKPC6BWrO3+yozw5e/jPXR+0Fmn2FiYDo4MIG5h+bWZsOnED?= =?iso-8859-1?q?eXukY9gc2/S1AiYd+bJCeXjCmJCIxXGxslIgaPsPJWjbGvAPbVkqDYT6qykx?= =?iso-8859-1?q?WLKvBPywmCqKlTxbjXLyWlB7MWe0QQB+rB/eOtw=3D=3D?= MIME-Version: 1.0 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: wfQgVTJPhZ6pAkJyHBW6FxoEFb536tQ3yZXwiA1aeShhhnWTzEQxzDyqSgXZBOVceDNAaxAXj8FNBzUUnygnICzATKab2O9RQ/z6ce8R8ixxbD5QVFNvdkRPrzcaJkg1Qr3gtbOrA2J7QmyWYfS3/n8lygWNfom+QXXw4YT2UN0cPRRdWxR4UM6M4LLhlKPNi/1t4cdyiWyQvAjUrv3oTCnesM9xNEVjmztK+WvisnxWiazw1Natf7KnS8w2RedK2Lq92ilPuNJEFenwEA1WPfklXYb7xbqNy3/5V66hT7AN3bgozVo2I3/tt98/xosMIHSV0KVSmoRgFM09usflxIgLGJliF7ob7ozbeU5KjAmzoa6dwh+IBvFj+qrdPlEJrXGa9xZ2mZDeFHTeTLCzc99MZ2mnOIBxUxvtVFKSLm30X2TbcQAfU05+O/3DRtybjRUqy0ZqKIKRuGREEp/1jiZHNLIl2GQf7rrofDQF+dudVuFnB5Wil2/ciznQAkoq/+LkftgW8pSvJSBd+U+ab66hGVXxWnNt1VXH6q73csQ3UwaRX2bR+Qd1p4Gg171mfXRKmzygEl2KP+TqquMuUnrg/u6eCMIcQTmC+OsPOrVyyy3ODWUmCiHVwCLwZryca2upvzpdQ4DRLRQleetqbdeUiMM6yBglfahV9tU1Gk1JfW5CVpbOVNgsCxRKwdKk3KBJdJyqL/3E2OkSzdQuFlTZ8WSToet+QinWFTfmMqmDcF1EmoC+OWG5BiS2EfY3n0X0Qgkr02ajfaVW2vIOaBIKN9kwDWh8ZpMGfBFuxGsMWRCoaTMU6VrNfeh2fyjJESI6EJtwPc/NAAcMVyxtixBY6ERAQw47LJ1uqoI5Ixxl1O8bnhtG+FL91267TdjVPL1E48ImlDusMpOhRGGrUrW/oG0yvObYb4tvZcT7xmk= X-OriginatorOrg: calian.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: YT2PR01MB8838.CANPRD01.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-Network-Message-Id: ec6c836f-4141-4463-9f37-08dbeabd40ef X-MS-Exchange-CrossTenant-originalarrivaltime: 21 Nov 2023 18:11:16.1658 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 23b57807-562f-49ad-92c4-3bb0f07a1fdf X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: HBCYTJrDPRCjaWSH8IGCxIbOtLnteVKlmZSV6uOIujR5t+Mnht60wusEcCH2kTHE9IldQk0ZHdwBKERWwgCBtWApSzjv0CZ+x45Ii1IpLWQ= X-MS-Exchange-Transport-CrossTenantHeadersStamped: YT3PR01MB9202 X-Proofpoint-GUID: MJzUipbv880W3moQ340ANXeg4CeYtoUs X-Proofpoint-ORIG-GUID: MJzUipbv880W3moQ340ANXeg4CeYtoUs X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.987,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-11-21_10,2023-11-21_01,2023-05-22_02 X-Proofpoint-Spam-Reason: orgsafe X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231121_101133_869335_FF61613E X-CRM114-Status: GOOD ( 19.15 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Frequently an I2C write will be followed by a read, such as a register address write followed by a read of the register value. In this driver, when the TX FIFO half empty interrupt was raised and it was determined that there was enough space in the TX FIFO to send the following read command, it would do so without waiting for the TX FIFO to actually empty. Unfortunately it appears that in some cases this can result in a NAK that was raised by the target device on the write, such as due to an unsupported register address, being ignored and the subsequent read being done anyway. This can potentially put the I2C bus into an invalid state and/or result in invalid read data being processed. To avoid this, once a message has been fully written to the TX FIFO, wait for the TX FIFO empty interrupt before moving on to the next message, to ensure NAKs are handled properly. Fixes: e1d5b6598cdc ("i2c: Add support for Xilinx XPS IIC Bus Interface") Signed-off-by: Robert Hancock --- drivers/i2c/busses/i2c-xiic.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/drivers/i2c/busses/i2c-xiic.c b/drivers/i2c/busses/i2c-xiic.c index 71391b590ada..fd623e8ad08a 100644 --- a/drivers/i2c/busses/i2c-xiic.c +++ b/drivers/i2c/busses/i2c-xiic.c @@ -772,14 +772,17 @@ static irqreturn_t xiic_process(int irq, void *dev_id) goto out; } - xiic_fill_tx_fifo(i2c); - - /* current message sent and there is space in the fifo */ - if (!xiic_tx_space(i2c) && xiic_tx_fifo_space(i2c) >= 2) { + if (xiic_tx_space(i2c)) { + xiic_fill_tx_fifo(i2c); + } else { + /* current message fully written */ dev_dbg(i2c->adap.dev.parent, "%s end of message sent, nmsgs: %d\n", __func__, i2c->nmsgs); - if (i2c->nmsgs > 1) { + /* Don't move onto the next message until the TX FIFO empties, + * to ensure that a NAK is not missed. + */ + if (i2c->nmsgs > 1 && (pend & XIIC_INTR_TX_EMPTY_MASK)) { i2c->nmsgs--; i2c->tx_msg++; xfer_more = 1; @@ -790,11 +793,7 @@ static irqreturn_t xiic_process(int irq, void *dev_id) "%s Got TX IRQ but no more to do...\n", __func__); } - } else if (!xiic_tx_space(i2c) && (i2c->nmsgs == 1)) - /* current frame is sent and is last, - * make sure to disable tx half - */ - xiic_irq_dis(i2c, XIIC_INTR_TX_HALF_MASK); + } } if (pend & XIIC_INTR_BNB_MASK) { From patchwork Tue Nov 21 18:11:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Robert Hancock X-Patchwork-Id: 13463449 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 98BAAC61D90 for ; Tue, 21 Nov 2023 18:12:20 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:In-Reply-To:References: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=5E1xmYitaRCcDXA56kjthnMRgbgyrVdR7R1IcUztUfM=; b=bpXfcfkOztwLdC HrKEx3HnF7kZAT1ElyJ9LB3yeOvEj6I6Xsk2Ws5xot4Lqvf0gvFQOX61G6dxkRT8s0bXWUpNlDcB8 Qsaoq+BUkZS+FfKEbwHZ9m+dF75WIBCgEAQA72VhbhTtY8co9PVKbmXN3vOELcG8Y4b1iP2bda1lw vnSjRPKgKkL1ha9qR0HtQI6DPS1C1+HyG+AKd/BgRj0R8muSBGyPKpUTPM9D6MsTLE73zQMRRId9s v/KmmwzbB7Le7vYjal/wK/4vbmUSXLHRRPOwK/+UtbjRwOXJqh1vpylITPKLW65u/8uk3gkbN1a6v v+vyIr8P6GPbeZBXOz/A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r5VE0-00HSTz-0G; Tue, 21 Nov 2023 18:11:52 +0000 Received: from mx0d-0054df01.pphosted.com ([67.231.150.19]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1r5VDw-00HSSm-2e for linux-arm-kernel@lists.infradead.org; Tue, 21 Nov 2023 18:11:50 +0000 Received: from pps.filterd (m0209000.ppops.net [127.0.0.1]) by mx0c-0054df01.pphosted.com (8.17.1.22/8.17.1.22) with ESMTP id 3ALGnCri016324; Tue, 21 Nov 2023 13:11:42 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=calian.com; h= from:to:cc:subject:date:message-id:references:in-reply-to :content-type:content-transfer-encoding:mime-version; s= selector2; bh=Ctk4/1SGNEo9jbIdbG0Ka3GzY01ED/7Ve8LUg38n5qA=; b=V/ XU6pM+/sXhAt6eRC8bUqOLvNXa42cIWQvbKDgGNaH0WlNl9fFRN3hQNjSTgzO3KW A+cy6LELafed7jqGGuLhk44omx7/7P+7/Fus5wHRs0XwITMv4F0rKbxU6FH8cKqX iAwn50HTdONlseoxs8A8CY9r6q34tLPAzTzVkyflwSfISsLgoh+3SoJkvkRF120G AD3u6QscvrOgweBPzUpi/zmMArtNIB9qitR6Uv1k0/PTaD+tPM7/YQBDKLHVg1/e GB17EEWUCLIM3Ohl4Ik/W2iuJ4GSvlQtyZ2T6bRN84raoAojRZbtUlQO3LshWpQI qCdhSCwD+sU+96HuBtwQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=calian.com; h= from:to:cc:subject:date:message-id:references:in-reply-to :content-type:content-transfer-encoding:mime-version; s= selector1; bh=Ctk4/1SGNEo9jbIdbG0Ka3GzY01ED/7Ve8LUg38n5qA=; b=rg kI3fIxH/Pk+NsRmy/EcxGl1OraV6szqtcENG1/MbTfVOvY9VzKRSjwhiTpJLNyvz gn/plW7Llzlo4xkjU8VV55CFeK8KGxdxgV2gWWmcvjpqNLIxqHBEi7DNdw8i9XXj 8zhJnqkTS+dWZ373rucM9gLAu2r+Y6Rg4Vkpo/j0ay23EunURouHtlYQuSNGdbc2 xsAdA3IHvOFqUlaHhBc7b74WL5jXtfPz7kP7wHXJqEYUaJt1oZ0R1cG3eAIZu//O ZVqEqFxttYXaUmiMviBU5z63GMXxYs6XQwRsPhKEQHgrolhNxn7Wrbt6Ri3jzD7y o/WdM0bjukpSLYrYiffQ== Received: from can01-yqb-obe.outbound.protection.outlook.com (mail-yqbcan01lp2232.outbound.protection.outlook.com [104.47.75.232]) by mx0c-0054df01.pphosted.com (PPS) with ESMTPS id 3ueu25adeq-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 21 Nov 2023 13:11:41 -0500 (EST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Hjrqpj7V69fBpL9nU41bMz07UGl7TLcRg0OWgs8tFX2x+9zP5SkomRmxxP4wg9Bp3fb9XIwOPy9z+oA5VaS3QElHelyqElJOyTZQyvrmhWdiH/zgpxeG1Q3g0WF4Zp2h8lVpecRfUyGivdmcTPnYBtdIZchjW5Ifxs9BT4VpTYLRwQ5plbIqC60rk4zETBVlpigheA8QDPPjYa9qcoD/pmsZotatvwAUCgbfTpUbUet8i/K5fNS0ogzuTnxI3Yrt3il2S8EGomLBgrFy3sqhCekOQzkMGs6uZY07DsKHfr14i+vHoeqLpp/nRLfAPaczPJHMqiCO8H67l/VRzyi19w== 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-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Ctk4/1SGNEo9jbIdbG0Ka3GzY01ED/7Ve8LUg38n5qA=; b=AuyKwK4Q/bHQ/lK0p4bTu9ciaVfgyeSDvmFg4e8cOTuIBbzxz4kHW6YLXUD4jlab1TlHYdBcP1fwtxUvQ6EgWQZDqcqSYlDJb/B5V2vHTugKNHbOPAi/bzbOCAxvgojdWf+57iGECwQCYCxYNvdPg2mWjyhfwpdK2O+sHBGQ/0FRIc3JXIRrw6Fu/0feBeRPYP7X1MOkYEQgGZ9IgETOGaJnFXHz/ZjjmunXfZ78GxyBC7LqtaxwRU1gWoAAZFDazAYnde1nC4XD9KaaqSgemBDhI+mOXkHp4xTm1McJR7ldL1cnuP8cU5j9F0saYI/5rtfJ//HoQZbmXbXnxIAYqg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=calian.com; dmarc=pass action=none header.from=calian.com; dkim=pass header.d=calian.com; arc=none Received: from YT2PR01MB8838.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:b9::6) by YT3PR01MB9202.CANPRD01.PROD.OUTLOOK.COM (2603:10b6:b01:7f::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.7025.18; Tue, 21 Nov 2023 18:11:40 +0000 Received: from YT2PR01MB8838.CANPRD01.PROD.OUTLOOK.COM ([fe80::8e4a:d951:9c01:a8af]) by YT2PR01MB8838.CANPRD01.PROD.OUTLOOK.COM ([fe80::8e4a:d951:9c01:a8af%5]) with mapi id 15.20.7025.017; Tue, 21 Nov 2023 18:11:40 +0000 From: Robert Hancock To: "michal.simek@amd.com" , "ben-linux@fluff.org" , "andi.shyti@kernel.org" CC: "linux-arm-kernel@lists.infradead.org" , "linux-i2c@vger.kernel.org" , Robert Hancock Subject: [PATCH v2 2/2] i2c: xiic: Try re-initialization on bus busy timeout Thread-Topic: [PATCH v2 2/2] i2c: xiic: Try re-initialization on bus busy timeout Thread-Index: AQHaHKYsDs5uhos3i0Gs2OVv35zHkA== Date: Tue, 21 Nov 2023 18:11:40 +0000 Message-ID: <20231121180855.1278717-3-robert.hancock@calian.com> References: <20231121180855.1278717-1-robert.hancock@calian.com> In-Reply-To: <20231121180855.1278717-1-robert.hancock@calian.com> Accept-Language: en-CA, en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-mailer: git-send-email 2.42.0 user-agent: Evolution 3.48.4 (3.48.4-1.fc38) x-ms-publictraffictype: Email x-ms-traffictypediagnostic: YT2PR01MB8838:EE_|YT3PR01MB9202:EE_ x-ms-office365-filtering-correlation-id: e849c788-af0b-4dee-d32a-08dbeabd4f6f x-ms-exchange-senderadcheck: 1 x-ms-exchange-antispam-relay: 0 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: oWEHPnN0nWJxp52gj4grZ04C07R2wmaJzO02KPOwXhoG3MLDkvEFBInk9tOJ0ve86Rrdq4PLMIw4H2ppVQStsYeFAN2nqUvlSDIndYcd28WR8v6FB+oRJUX7f140HqGYHrTvqsMlIiVvnwoZckYzBpMTud4AOwHdPu0gul/5GKQz8x8TP0ZKMzZ8nmK/RwRPgrMWtGuMq8Y+W0w4m+XynTeQqHrotEP2RCHi1agxamol+3putOgzOQ9DgaR7cs1Chz8ppQZJXzvTTroQvq49u+rskezkVao3cXAXAlwWTJZgoq2HBKFggTr3a7Eh3AabLqWNXCM3sJ4xXVher16NWmFaYF/W4REjKPCQzUdIaS5jdJ13bLRzkwut+1lz+4nx+7rJpQeRLMkGUhtwr0tvNN+rIp1KB9HoG0JaK87shNPFtH3Ao0IGadYJy0MVpMBpizzf4coq36uukGAvJHtgwxclu1961XSyKvq7lPJO4gOGyagGMhrOJHtFuVXtyePAB3DvNhhc5uGho4r/oA3WWzM6AQlF7J/zP7brwRehhaibWvhSCD3LDldNxwoKLlfZVb91ZTD16xWdrvF62V5X+alJ5frbcGbF+g387vu0LwrGvYgNltXNg+E7guYLYWi2 x-forefront-antispam-report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:YT2PR01MB8838.CANPRD01.PROD.OUTLOOK.COM;PTR:;CAT:NONE;SFS:(13230031)(136003)(376002)(396003)(346002)(366004)(39860400002)(230922051799003)(186009)(451199024)(64100799003)(1800799012)(6512007)(71200400001)(6486002)(478600001)(122000001)(6506007)(316002)(8936002)(8676002)(4326008)(26005)(38100700002)(66476007)(2616005)(110136005)(91956017)(76116006)(66946007)(66446008)(66556008)(64756008)(54906003)(83380400001)(107886003)(1076003)(44832011)(5660300002)(2906002)(41300700001)(86362001)(36756003)(38070700009);DIR:OUT;SFP:1101; x-ms-exchange-antispam-messagedata-chunkcount: 1 x-ms-exchange-antispam-messagedata-0: =?iso-8859-1?q?XvaOw7Q5X6V5++V7aVZv8jZ?= =?iso-8859-1?q?eGrY8YT2AgoKnVNYove9hpDGMnNdbbbDKIKxPJkstxNeoy85o1cUVb+EHgIV?= =?iso-8859-1?q?GVnLgcwNS9JziaGB9rvh/9U+NwsLUnNwNcE3JOqifX1jiJbG/OiiyNQs0s2O?= =?iso-8859-1?q?GFS1isfZ2u2lYfAf7FmLRhNzLyBFihiV5Vztvf0W+G/OT5UgAUxRZfWZn2AV?= =?iso-8859-1?q?nZteKn2olH7F3aUSfLjdkvL8arMmxa9yCMpyI9qrANxvoCD6bY0cCjrm0UVf?= =?iso-8859-1?q?gXsn+ZZ6063M4mNfukIs7SGALr4hDma3QYOIGT7V5VLcm/ZdEDv4ji2IgYfK?= =?iso-8859-1?q?THkI2hQYZ/QiwjUJLGsTKjcB5kZucctUEWBETwXbXtTdcigbuuNc07W3qtbB?= =?iso-8859-1?q?deoEfq9vxmTZnpA5TLzbB8krerby1vboiQdMthS5VKP1bc4vZLyj9OzY78Kd?= =?iso-8859-1?q?Qmm4hnIptIvE2QC9ah0ecbArQuE/CW34AYU4NURyjDzgbDoMn7SAxmkj6iOU?= =?iso-8859-1?q?ghc3u7lzQBtw8yI9x27Wu8h/CBglHU9cN8Bp4ny5ecFRlnXxcbfeI/heasjM?= =?iso-8859-1?q?Q7NurP5HO44HQMMw3qKSIXPtIPXFCR0sDywe1zztX17dsQI7TjKSeZbN4Rlv?= =?iso-8859-1?q?mWmsaWc571w1N/HXJOoEKMt0WYzLzPjBT6299bYfN//K/FV/oCaqczvvcpZf?= =?iso-8859-1?q?hNG4wTUA4BePZnY81oWEvLPz96a5F6yMJJqCBr4NT881rfpZySbDKqTrkB+h?= =?iso-8859-1?q?nbzSQ2gB888ZQGtFZe+bXK4BYkLi0XxcUnVHUc93nzSVDNbxgpnf24QbQsRx?= =?iso-8859-1?q?8XSf0KQ8dbWyl1Qt7b6F6pgE2J1jR0tT8bNsrAKPnmveHyxo3wXNwjB/SPSr?= =?iso-8859-1?q?/AUD+b1xm/w1H1ZLMT1DJ6wc2PCai9Ea3m2WduLOFwgHG3BFeaTuOEiQbuTR?= =?iso-8859-1?q?Bp0VwaQJ/wT1smO1hHxKMFsNeesORtHHl/8PHM9dQRxfP/FfPetEY52e/4/e?= =?iso-8859-1?q?+52hIO0cxer6D5VindBgYjwLabstprUtOlTY/ytdRL7kh/p+kWSlutGKI/XE?= =?iso-8859-1?q?a/6QE7XrCzURBkC1wHPddaDPrDskoYMDsuL9IPVmuk1smSrXYaHChIpvTwpP?= =?iso-8859-1?q?WxSqMnYSglGHWNWtN0VqhYxjlfH505jSwSVGIxDQGKAk1xGO/rbOpGOPlCHW?= =?iso-8859-1?q?YHY087e1f8iReZDhxwSacNYnqQ4yKhaPHpbHcveRCNDwvL8HjSm+yf9CvfLX?= =?iso-8859-1?q?8PlFQ+VTVSjetoAsezHYUoSKCIjVVDXSxjDjo6oeuj6ufV9+gZrlvGXSZt9F?= =?iso-8859-1?q?GOpq0Xj92yydy+RiEuwLxsTdyobkVtcwUWJ7f07d/RykDHgPu29jaAKbDyxy?= =?iso-8859-1?q?/+zyKlTcZIdLBdaxqvxGW4KBOX5nUjhIOh4T0kZ+KoK+VXs2foOQo8/Pa+U8?= =?iso-8859-1?q?/jGAIGzeL71zFUVxZibZGeWnEGPdcdQIUY0cb4awiAHhZ5IhVOkEW0bf6c7Q?= =?iso-8859-1?q?eNGOJpsDXZixUjoUh0Zz6oLlloQaA9xWOIJdxwG1Z4QFgnwv+09N8Xn/3rot?= =?iso-8859-1?q?2/kio6CMUQY7mWc8zTUg2l7SO829BMRRAU4vBykxApTuFJpQWHVQQN7Ql1Zs?= =?iso-8859-1?q?x1ZQa0cgkbETqyQaCZVIf9f5iwxhyStHm0rfOLQ=3D=3D?= MIME-Version: 1.0 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-ExternalHop-MessageData-0: DYKunyqUm65SS5tjr5C2lw/EcrGICNZboUz91KMBT6PDu+dpvMX7Vr2HYiLj8MyCDsid9McsfhOE5D+9kZthBn1VSC0MARG/JsMq6cp/aI3QQ/Znj9Y3UKiU82tkd9I+Zqw4TNAebZzzO9NmpvaJTwBN035XYlo54CTy9O2SwVAmX1zOxCJrYXRo/qzm6xeXWEihQNXOp4L8BC1OY67CvJQHQx6EkBFo93CG2/JMi6KtyT3lfy40wDyjPdOP6EkR0Irq+jM5k9OILc8lHGlnaDQMapRmTMC+Yjal5//kEdRdv9tonJ3+KEwgvGwzXNDz691xs/FVwh8zm0Qau1JlDQIIMo8h/+9xamwvit0UkDh5gbc7p8owTBadisIqHMAGtJRggOYe7w1wJg5ysnLV3bMVedVXudhkfouMPdGjAvepK+z9aPSbxGzdgAMmhGHJ9bplLKObAkMFoD86366dFMPCSIi+9dzs73q/7eeyVI6NAgb9rrBPJFQHCK7bziyYgsyob7DKOAtfj4yJHreYDY4yFLjgr8SdOvHLsZZIhAAM/+8xR2GEpktSesL8DXmKrcY1y15pkkg/OVAJOen1fKG3BTeXa4mOVWhL1FrVwSoQYLucSzPCANzoQIpM8WysgpVMbDkCglok96XaSv5eRyPRO6NsMSREizOoCl0sy1ht5sxwwY0pNRPAlGg71FMe3MO8/4Cp5FqzWQKhoW8V8Udz6kQq/wd9NTs1BKUDHgzZAYQUzu6m71OISvDwH4+bm/kzNkByjbJdtZoEDnviI7LjPlIrgAtdcu0AU5lz7gO3wpaiNFf0l0ZO2ZA/Ag9mIPm9ZkZv4zX24reqX/nvFfNAc/TkfFhFXUVsfLko7n4kyUZ4KqAdWPnLLMDpJEqMr5nWhdB9LVCP5IFMb2xmaLIifxoqozbLj3EQrUrOQWY= X-OriginatorOrg: calian.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-AuthSource: YT2PR01MB8838.CANPRD01.PROD.OUTLOOK.COM X-MS-Exchange-CrossTenant-Network-Message-Id: e849c788-af0b-4dee-d32a-08dbeabd4f6f X-MS-Exchange-CrossTenant-originalarrivaltime: 21 Nov 2023 18:11:40.5409 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 23b57807-562f-49ad-92c4-3bb0f07a1fdf X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: I8FEAk7HuEeUUBSme6Bxiwkv4na4DqyRRrdGx/BozvuqrbgY9rA3i2StFK/pZTx0689zQZoUphGOdsY8sOvJMwk/ppYh6RsdqqoLo+0nqak= X-MS-Exchange-Transport-CrossTenantHeadersStamped: YT3PR01MB9202 X-Proofpoint-GUID: fX_Z6wvyCKpfZ_TZZu-DQzi0CJrORJfn X-Proofpoint-ORIG-GUID: fX_Z6wvyCKpfZ_TZZu-DQzi0CJrORJfn X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.987,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2023-11-21_10,2023-11-21_01,2023-05-22_02 X-Proofpoint-Spam-Reason: orgsafe X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231121_101148_993424_C68B0296 X-CRM114-Status: GOOD ( 20.30 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org In the event that the I2C bus was powered down when the I2C controller driver loads, or some spurious pulses occur on the I2C bus, it's possible that the controller detects a spurious I2C "start" condition. In this situation it may continue to report the bus is busy indefinitely and block the controller from working. The "single-master" DT flag can be specified to disable bus busy checks entirely, but this may not be safe to use in situations where other I2C masters may potentially exist. In the event that the controller reports "bus busy" for too long when starting a transaction, we can try reinitializing the controller to see if the busy condition clears. This allows recovering from this scenario. Fixes: e1d5b6598cdc ("i2c: Add support for Xilinx XPS IIC Bus Interface") Signed-off-by: Robert Hancock --- drivers/i2c/busses/i2c-xiic.c | 42 ++++++++++++++++++++++------------- 1 file changed, 27 insertions(+), 15 deletions(-) diff --git a/drivers/i2c/busses/i2c-xiic.c b/drivers/i2c/busses/i2c-xiic.c index fd623e8ad08a..0950fced2f91 100644 --- a/drivers/i2c/busses/i2c-xiic.c +++ b/drivers/i2c/busses/i2c-xiic.c @@ -843,23 +843,11 @@ static int xiic_bus_busy(struct xiic_i2c *i2c) return (sr & XIIC_SR_BUS_BUSY_MASK) ? -EBUSY : 0; } -static int xiic_busy(struct xiic_i2c *i2c) +static int xiic_wait_not_busy(struct xiic_i2c *i2c) { int tries = 3; int err; - if (i2c->tx_msg || i2c->rx_msg) - return -EBUSY; - - /* In single master mode bus can only be busy, when in use by this - * driver. If the register indicates bus being busy for some reason we - * should ignore it, since bus will never be released and i2c will be - * stuck forever. - */ - if (i2c->singlemaster) { - return 0; - } - /* for instance if previous transfer was terminated due to TX error * it might be that the bus is on it's way to become available * give it at most 3 ms to wake @@ -1103,9 +1091,33 @@ static int xiic_start_xfer(struct xiic_i2c *i2c, struct i2c_msg *msgs, int num) mutex_lock(&i2c->lock); - ret = xiic_busy(i2c); - if (ret) + if (i2c->tx_msg || i2c->rx_msg) { + ret = -EBUSY; goto out; + } + + /* In single master mode bus can only be busy, when in use by this + * driver. If the register indicates bus being busy for some reason we + * should ignore it, since bus will never be released and i2c will be + * stuck forever. + */ + if (!i2c->singlemaster) { + ret = xiic_wait_not_busy(i2c); + if (ret) { + /* If the bus is stuck in a busy state, such as due to spurious low + * pulses on the bus causing a false start condition to be detected, + * then try to recover by re-initializing the controller and check + * again if the bus is still busy. + */ + dev_warn(i2c->adap.dev.parent, "I2C bus busy timeout, reinitializing\n"); + ret = xiic_reinit(i2c); + if (ret) + goto out; + ret = xiic_wait_not_busy(i2c); + if (ret) + goto out; + } + } i2c->tx_msg = msgs; i2c->rx_msg = NULL;