Received: by 10.223.185.116 with SMTP id b49csp4978251wrg; Tue, 27 Feb 2018 06:00:01 -0800 (PST) X-Google-Smtp-Source: AH8x22607bzrnKN61qgCjglLNtVQ2D5vftj+NvtRynyT/Ptq2gb1BImwGg9ftieLkniV4zrqlPVi X-Received: by 2002:a17:902:7f0b:: with SMTP id d11-v6mr14789060plm.350.1519740001013; Tue, 27 Feb 2018 06:00:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1519740000; cv=none; d=google.com; s=arc-20160816; b=PYqSQo98nWXupsimoiA4hQ430/DPI/xDkzBhMhxTslB6iTreXytrycsYZb2eUtHIBn 1f7HJcYiVrPXgc7/hMp6h6RtmPgTqonZIiw3a7vMza4s8t59kU3MlQ8ITvlUhERAWpvM 1MG5SBhGqBFdKJzBN1RhpgCWGhb4yny7phTJdfQSFKxTU0/PfwZI4A9XIwWJ4dLkcuNU Gjg1xjVEerBL2L8FBm3SstiL3ehuZ7X/lE5kF2YGDUf3PPVSFXmWEhmDBuqdAtBCB/Lu wl6fawRLmaRSJMq/BcddtwsnmXPuP/Qp+dqwNvJvx18Up3KWM1P90wbbtaEJuDiZ9njW N6Qg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:spamdiagnosticmetadata :spamdiagnosticoutput:mime-version:message-id:date:subject:cc:to :from:dkim-signature:arc-authentication-results; bh=f5QHiWUY5qpSfS8VxtN4hQ1kqr+ues6CJPRpxS55ZmE=; b=rnroLM/I/lo1OpNhoLtF5GDWmZW3vCJPkvgd1rtIvcmNlQf/5wru5WpghPTtFlv4CG ZyjgQ6Wd5dnRIz0bLQMfK7dTc1o1bVSC3gmYYx3pl1TxKXjSMKDaoNc/VfVMHFb+fVrw TOqYoiFHt6s0zyEc8JwhhcwKP8LJnGawgZE+43IAqtkZ5WZgWGarCnQoD2Jw9621zzhP 3mfy1Vsuu2c4A8DsjxdqgE3/Cti2rxfx77KNCjwBrzOfpurBwy+6700AGXwqZhBvFUO6 il0DjSd+WauXyzdGnsJTQuqoLPd6UFB9X6H1OaWo5n2YHYRDrAX3KEAMsqsCpfBgCNIJ fYxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@CAVIUMNETWORKS.onmicrosoft.com header.s=selector1-cavium-com header.b=QmQnolPU; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id l4-v6si8988278pln.121.2018.02.27.05.59.39; Tue, 27 Feb 2018 06:00:00 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@CAVIUMNETWORKS.onmicrosoft.com header.s=selector1-cavium-com header.b=QmQnolPU; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753304AbeB0N0r (ORCPT + 99 others); Tue, 27 Feb 2018 08:26:47 -0500 Received: from mail-co1nam03on0056.outbound.protection.outlook.com ([104.47.40.56]:49808 "EHLO NAM03-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753239AbeB0N0p (ORCPT ); Tue, 27 Feb 2018 08:26:45 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=CAVIUMNETWORKS.onmicrosoft.com; s=selector1-cavium-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=f5QHiWUY5qpSfS8VxtN4hQ1kqr+ues6CJPRpxS55ZmE=; b=QmQnolPURQrMalhV2N8wadhbQQ70GHfaD/gOsnQRdr7ocMGTQONLLc0E6DLoltoP0tGdJ5GT0Wht97vBs3WVECd9KXRdNKls8dBkp82cCeBmoy5MgaiUzjEpNN5bs5cT01hSKn/zsg2BzX6/Bo/AE4cInPLN46FGwACI1RKjvQ0= Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=George.Cherian@cavium.com; Received: from ubuntu.caveonetworks.com (111.93.218.67) by BY2PR07MB2328.namprd07.prod.outlook.com (10.166.114.142) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.527.15; Tue, 27 Feb 2018 13:26:39 +0000 From: George Cherian To: linux-i2c@vger.kernel.org, linux-kernel@vger.kernel.org Cc: wsa@the-dreams.de, George Cherian Subject: [PATCHv2 1/3] i2c: xlp9xx: Check for Bus state before every transfer Date: Tue, 27 Feb 2018 13:26:18 +0000 Message-Id: <1519737980-27997-1-git-send-email-george.cherian@cavium.com> X-Mailer: git-send-email 2.1.4 MIME-Version: 1.0 Content-Type: text/plain X-Originating-IP: [111.93.218.67] X-ClientProxiedBy: BM1PR01CA0086.INDPRD01.PROD.OUTLOOK.COM (10.174.208.154) To BY2PR07MB2328.namprd07.prod.outlook.com (10.166.114.142) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 14d5be77-5a0d-4712-fb41-08d57de5bcd4 X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:(7020095)(4652020)(4534165)(4627221)(201703031133081)(201702281549075)(5600026)(4604075)(2017052603307)(7153060)(7193020);SRVR:BY2PR07MB2328; X-Microsoft-Exchange-Diagnostics: 1;BY2PR07MB2328;3:7JuIeJfMpCoA8uTotTdbD3nw4iwsZjgU96MyUeCpqtrHgUaGkfgPQOqtxYVztxEy3XhHZinJbZch2xshyxqKo+EDxETRXaxGRO6QTKn3z2q8nSD5Hp0GFmz7KOB4PboRtJnBGNdtLv4eE23KGporNXqkoEEy00uPJ9PHxci/dm2y4K9HLVI7xlZ3s28UAi9zRlCI0xk+jim9/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Tm0cjMzSevjiTf5SyoNTtsQIh+2P9usyfbK4xOaVokze/Dl9IYt12VDSDB25LKHMNE9PFolnXsbuToYjVk2WI4v8ie6nfffXb9r7+MXTKlygxqAhdFJAyLYrTC5rAfY;4:2p2f3v9vmA+C35pFIQuRNvj8AaxnQOkdH5veOo5XRUI6CxCms5nsbSDiGOm2bUGoTAGgkGaRJ8jYJ8p9m1/NuPfeuv5J+Kaxb5Qbfu/3/vMEo3sQIF9E9UxNJAaD2FIteiEGt4SYMWZJ8rYMnqAM8yjtwAIP0R6EQyTM9KQY9sUtBZQnPqe4/2HRS3crSxIrfAK/DMCKVX84XpebXx0vuDXW6Tf0VimlXYT0qDc5P/UhnDb0OwnS+dqXcs4RcJPkIHRc1hbLrEasS8djIKfyFQ== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0;PCL:0;RULEID:(8211001083)(6040501)(2401047)(8121501046)(5005006)(3002001)(3231220)(944501198)(93006095)(93001095)(10201501046)(6041288)(20161123562045)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061406153)(20161123560045)(20161123558120)(6072148)(201708071742011);SRVR:BY2PR07MB2328;BCL:0;PCL:0;RULEID:;SRVR:BY2PR07MB2328; X-Forefront-PRVS: 05961EBAFC X-Forefront-Antispam-Report: SFV:NSPM;SFS:(10009020)(346002)(376002)(39380400002)(366004)(396003)(39860400002)(199004)(189003)(97736004)(51416003)(50466002)(86362001)(48376002)(36756003)(66066001)(305945005)(6486002)(7736002)(53416004)(26005)(386003)(68736007)(16526019)(478600001)(16586007)(6666003)(72206003)(316002)(52116002)(4326008)(106356001)(5009440100003)(25786009)(107886003)(551934003)(105586002)(186003)(6506007)(53936002)(6512007)(6116002)(3846002)(5660300001)(81166006)(50226002)(8676002)(2906002)(69596002)(81156014)(47776003)(8936002);DIR:OUT;SFP:1101;SCL:1;SRVR:BY2PR07MB2328;H:ubuntu.caveonetworks.com;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; Received-SPF: None (protection.outlook.com: cavium.com does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;BY2PR07MB2328;23:t/fDjQoPKwNkgBQmRyKd88uo+bQiwWU4JlBy3Ycn0?= =?us-ascii?Q?8YwUhncZ5IJ2MEzQ+voz5YBG/Woh3cbjxy0bg4RS80IrPgWb1XHPPieLWUuT?= =?us-ascii?Q?5wJXCAYAEgeIVp8mQL5+PSjCMIEQMy8PW6QXHwawRQ529CA/W1tp2l8evMjV?= =?us-ascii?Q?SP8fY+BGZuIiwCon4eArQlUKwjcVDZpbGfI5n4JCYJcuamGqwgIya3xllCT5?= =?us-ascii?Q?W0nwGBwaODf5bcPjd5z7eCoRwpxOXHvt38cItMYLcFmQBn58XOaAMk56j5Da?= =?us-ascii?Q?1qfOR5LKzTeTLlVNja3xglMOsdf8PmggxJoX87ZZsac/fVpQtddzhkmvzzLO?= =?us-ascii?Q?NoTjfaFJydHPG4YEHdl345jf4kyu3SholsnbfLyxXa61x7VOuT4uN/VCRuUb?= =?us-ascii?Q?AVZdDl9Fl7xEKvrfdhO5UYs1NOqipf95cm+09wgP3igJdY7DSR71B9ediT/8?= =?us-ascii?Q?pG6lyYk53e3+yL904N1aqeiSCK6jXHSTI4quLSjxvHYO8IPTVx6A8drJzMn+?= =?us-ascii?Q?oDEdSrh1h8RlAgbd/7GT/7OCYF4UZrHEcQQI9Y4jIqxWL3LqpwJtkEM7Pu1c?= =?us-ascii?Q?EfHElz30xd08NqgNyytNdybxFcvDvKC0ljgsn6JN9W7y9Q1xeL5pFLhNPIuh?= =?us-ascii?Q?bVVUS4m4LLrhdpVYpdpHcCxZPBfCI/MCfLXW8Hnt1Ess7WuYJfQiRbf6y4mZ?= =?us-ascii?Q?pFPERaXfY/eJ2zGm0hSWfndblkKcAkn5AMFGdxCKn184aDFUD8229IQBXWPv?= =?us-ascii?Q?ersb0A4fDZDK7EwU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eFWR1QKYXW3utfM0=;24:7kYptB+LnGTswjSEXAbgcSOwJAb20LCnDV94Lt9jjL/LXVagTFgj0H2LZdZGISNGnic/entTJj/+8WuID4awVJ30CxdPy4y9tKW3mSSgtf8=;7:941iA78SMKLe4q+NMxrZK6OyqZrJz9yWPpIQv1M1oGD7XUfZdPAm2chCXi17hPeUb2aASimbVeYLwPMDpgJxVdcXYnVrEJ9GvZZtf60wIey72j/g9FZoVZSVjnwLbdmgWK/D00gqlxJdeIe7qQPe4MekXagSay4DJjXOUwVIw9F/6V0SCDeZDfsobhhbAx2cpxjYXJ4vo7TQNPqb8Pqh0amty1ioSi0gApg/jfsBQog/SpZxTXP5mteBNlNKxan2 SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-OriginatorOrg: cavium.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 27 Feb 2018 13:26:39.5600 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 14d5be77-5a0d-4712-fb41-08d57de5bcd4 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 711e4ccf-2e9b-4bcf-a551-4094005b6194 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BY2PR07MB2328 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org I2C bus enters the STOP condition after the DATA_DONE interrupt is raised. Essentially the driver should be checking the bus state before sending any transaction. In case a transaction is initiated while the bus is busy, the prior transaction's stop condition is not achieved. Add the check to make sure the bus is not busy before every transaction. Signed-off-by: George Cherian --- drivers/i2c/busses/i2c-xlp9xx.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) diff --git a/drivers/i2c/busses/i2c-xlp9xx.c b/drivers/i2c/busses/i2c-xlp9xx.c index 1f6d780..42dd1fa 100644 --- a/drivers/i2c/busses/i2c-xlp9xx.c +++ b/drivers/i2c/busses/i2c-xlp9xx.c @@ -16,6 +16,7 @@ #include #include #include +#include #define XLP9XX_I2C_DIV 0x0 #define XLP9XX_I2C_CTRL 0x1 @@ -36,6 +37,8 @@ #define XLP9XX_I2C_TIMEOUT 0X10 #define XLP9XX_I2C_GENCALLADDR 0x11 +#define XLP9XX_I2C_STATUS_BUSY BIT(0) + #define XLP9XX_I2C_CMD_START BIT(7) #define XLP9XX_I2C_CMD_STOP BIT(6) #define XLP9XX_I2C_CMD_READ BIT(5) @@ -71,6 +74,7 @@ #define XLP9XX_I2C_HIGH_FREQ 400000 #define XLP9XX_I2C_FIFO_SIZE 0x80U #define XLP9XX_I2C_TIMEOUT_MS 1000 +#define XLP9XX_I2C_BUSY_TIMEOUT 50 #define XLP9XX_I2C_FIFO_WCNT_MASK 0xff #define XLP9XX_I2C_STATUS_ERRMASK (XLP9XX_I2C_INTEN_ARLOST | \ @@ -241,6 +245,26 @@ static irqreturn_t xlp9xx_i2c_isr(int irq, void *dev_id) return IRQ_HANDLED; } +static int xlp9xx_i2c_check_bus_status(struct xlp9xx_i2c_dev *priv) +{ + u32 status; + u32 busy_timeout = XLP9XX_I2C_BUSY_TIMEOUT; + + while (busy_timeout) { + status = xlp9xx_read_i2c_reg(priv, XLP9XX_I2C_STATUS); + if ((status & XLP9XX_I2C_STATUS_BUSY) == 0) + break; + + busy_timeout--; + usleep_range(1000, 1100); + } + + if (!busy_timeout) + return -EIO; + + return 0; +} + static int xlp9xx_i2c_init(struct xlp9xx_i2c_dev *priv) { u32 prescale; @@ -363,6 +387,14 @@ static int xlp9xx_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int i, ret; struct xlp9xx_i2c_dev *priv = i2c_get_adapdata(adap); + ret = xlp9xx_i2c_check_bus_status(priv); + if (ret) { + xlp9xx_i2c_init(priv); + ret = xlp9xx_i2c_check_bus_status(priv); + if (ret) + return ret; + } + for (i = 0; i < num; i++) { ret = xlp9xx_i2c_xfer_msg(priv, &msgs[i], i == num - 1); if (ret != 0) -- 2.1.4