Received: by 10.223.164.202 with SMTP id h10csp137423wrb; Thu, 16 Nov 2017 20:44:02 -0800 (PST) X-Google-Smtp-Source: AGs4zMaFUwFwEGgN1Kzk30iZ+e/DoU5mJ+RuvZGYQ8x6rjiSRKiaoSEmV0STqQ9Q1dbzXr4d6CiE X-Received: by 10.101.78.210 with SMTP id w18mr3847295pgq.337.1510893842024; Thu, 16 Nov 2017 20:44:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510893841; cv=none; d=google.com; s=arc-20160816; b=kBvqSuqyNkS4UZGolWrNSk2SO5yORvXuCm0zhSuosj9HvO3I1iNNV5gHqz7FSuisAy zj/0z6SAI4zLHxMICdSQn0g1q3IC3XjVvKIWXRQ/FP4ZdsedDFmgFYhqqtT9K2tf7Nm9 95hGVRl3kmJteA5aKw5L3ZzTglkecbr20/belm3VY5WgcD1icwkvRlT7NN6woiNaH9Hu jE79c3sVd+e8H7dZnLeZR8fm/mo1sbKCXifnwOaRjLzglRrp6GLNtJGXOH/RDDcwmWFr dDf41pfMZf1E5lD6YjuZipTmxCSLZbqYORypxwi1XSJm/5oFoOwYmQBcpMYbyDQVmkq0 2uMw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:references:in-reply-to:date :subject:cc:to:from:arc-authentication-results; bh=lvsNNryRMTQtA8OViVIoOzzS7hAvqtQdoqmcEfACZkg=; b=KDms8OkI0g0q6ENJ7RuzuZbMJYbhO0Bqk1HatOsXvFDdsOcf/FJsRZH59j/MqMNt9P O5+1J5v1P9s0e7Ju+47XYHxOapxdHA93uA/FWkYxkbUCscrFxutbvZjBUyhvoibk1Y42 Y8NC3VF6M4ZE4IY+0Y07w1r9KJVw4yRBfD6HJzpKZ6mIDiv1WrZYOngSRLATI6zZq/RN T+A7AGHqthDxv/UIgamn/TXsPL2/EhHadE90kX/GukMzpFAcjLAa7zwMTtE/st2zkxb3 bUnW7V3R9Uu17BW5AB9UlrB/S49ARAX7Wt52PbIPcuIuA1HH4bgUy2PfmxbIS+Fc4YlK wO6Q== ARC-Authentication-Results: i=1; mx.google.com; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i89si2275598pfi.153.2017.11.16.20.43.49; Thu, 16 Nov 2017 20:44:01 -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; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933278AbdKPTyn (ORCPT + 92 others); Thu, 16 Nov 2017 14:54:43 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:41354 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1758080AbdKPTyR (ORCPT ); Thu, 16 Nov 2017 14:54:17 -0500 Received: from pps.filterd (m0098421.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vAGJsHsB011671 for ; Thu, 16 Nov 2017 14:54:17 -0500 Received: from e33.co.us.ibm.com (e33.co.us.ibm.com [32.97.110.151]) by mx0a-001b2d01.pphosted.com with ESMTP id 2e9gqc1exv-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 16 Nov 2017 14:54:16 -0500 Received: from localhost by e33.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 16 Nov 2017 12:54:15 -0700 Received: from b03cxnp07028.gho.boulder.ibm.com (9.17.130.15) by e33.co.us.ibm.com (192.168.1.133) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 16 Nov 2017 12:54:12 -0700 Received: from b03ledav004.gho.boulder.ibm.com (b03ledav004.gho.boulder.ibm.com [9.17.130.235]) by b03cxnp07028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id vAGJsBqV786836; Thu, 16 Nov 2017 12:54:11 -0700 Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 929AA78037; Thu, 16 Nov 2017 12:54:11 -0700 (MST) Received: from oc3016140333.ibm.com (unknown [9.85.131.228]) by b03ledav004.gho.boulder.ibm.com (Postfix) with ESMTP id 692347803F; Thu, 16 Nov 2017 12:54:10 -0700 (MST) From: Eddie James To: linux-kernel@vger.kernel.org Cc: linux-i2c@vger.kernel.org, devicetree@vger.kernel.org, wsa@the-dreams.de, robh+dt@kernel.org, joel@jms.id.au, eajames@linux.vnet.ibm.com, "Edward A. James" Subject: [PATCH v6 4/7] drivers/i2c: Add abort and hardware reset procedures Date: Thu, 16 Nov 2017 13:53:49 -0600 X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1510862032-12394-1-git-send-email-eajames@linux.vnet.ibm.com> References: <1510862032-12394-1-git-send-email-eajames@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17111619-0008-0000-0000-000008E09C61 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008076; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000240; SDB=6.00946833; UDB=6.00477975; IPR=6.00727126; BA=6.00005695; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00018049; XFM=3.00000015; UTC=2017-11-16 19:54:13 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17111619-0009-0000-0000-000044C97375 Message-Id: <1510862032-12394-5-git-send-email-eajames@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-11-16_06:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1011 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1711160266 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Edward A. James" Add abort procedure for failed transfers. Add engine and bus reset procedures to recover from as many faults as possible. Signed-off-by: Edward A. James --- drivers/i2c/busses/i2c-fsi.c | 186 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 186 insertions(+) diff --git a/drivers/i2c/busses/i2c-fsi.c b/drivers/i2c/busses/i2c-fsi.c index 4ad5d68..61609bce 100644 --- a/drivers/i2c/busses/i2c-fsi.c +++ b/drivers/i2c/busses/i2c-fsi.c @@ -9,14 +9,18 @@ * 2 of the License, or (at your option) any later version. */ +#include #include #include #include #include +#include #include #include #include #include +#include +#include #define FSI_ENGID_I2C 0x7 @@ -129,10 +133,18 @@ #define I2C_ESTAT_SELF_BUSY 0x00000040 #define I2C_ESTAT_VERSION 0x0000001f +#define I2C_PORT_BUSY_RESET 0x80000000 + +#define I2C_LOCAL_WAIT_TIMEOUT 2 /* jiffies */ + +/* choose timeout length from legacy driver; it's well tested */ +#define I2C_ABORT_TIMEOUT msecs_to_jiffies(100) + struct fsi_i2c_master { struct fsi_device *fsi; u8 fifo_size; struct list_head ports; + spinlock_t reset_lock; }; struct fsi_i2c_port { @@ -224,6 +236,179 @@ static int fsi_i2c_set_port(struct fsi_i2c_port *port) return rc; } +static int fsi_i2c_reset_bus(struct fsi_i2c_master *i2c) +{ + int i, rc; + u32 mode, stat, ext, dummy = 0; + + rc = fsi_i2c_read_reg(i2c->fsi, I2C_FSI_MODE, &mode); + if (rc) + return rc; + + mode |= I2C_MODE_DIAG; + rc = fsi_i2c_write_reg(i2c->fsi, I2C_FSI_MODE, &mode); + if (rc) + return rc; + + for (i = 0; i < 9; ++i) { + rc = fsi_i2c_write_reg(i2c->fsi, I2C_FSI_RESET_SCL, &dummy); + if (rc) + return rc; + + rc = fsi_i2c_write_reg(i2c->fsi, I2C_FSI_SET_SCL, &dummy); + if (rc) + return rc; + } + + rc = fsi_i2c_write_reg(i2c->fsi, I2C_FSI_RESET_SCL, &dummy); + if (rc) + return rc; + + rc = fsi_i2c_write_reg(i2c->fsi, I2C_FSI_RESET_SDA, &dummy); + if (rc) + return rc; + + rc = fsi_i2c_write_reg(i2c->fsi, I2C_FSI_SET_SCL, &dummy); + if (rc) + return rc; + + rc = fsi_i2c_write_reg(i2c->fsi, I2C_FSI_SET_SDA, &dummy); + if (rc) + return rc; + + mode &= ~I2C_MODE_DIAG; + rc = fsi_i2c_write_reg(i2c->fsi, I2C_FSI_MODE, &mode); + if (rc) + return rc; + + rc = fsi_i2c_read_reg(i2c->fsi, I2C_FSI_STAT, &stat); + if (rc) + return rc; + + /* check for hardware fault */ + if (!(stat & I2C_STAT_SCL_IN) || !(stat & I2C_STAT_SDA_IN)) { + rc = fsi_i2c_read_reg(i2c->fsi, I2C_FSI_ESTAT, &ext); + if (rc) + return rc; + + dev_err(&i2c->fsi->dev, "bus stuck status[%08X] ext[%08X]\n", + stat, ext); + } + + return 0; +} + +static int fsi_i2c_reset(struct fsi_i2c_master *i2c, u16 port) +{ + int rc; + u32 mode, stat, dummy = 0; + unsigned long flags; + + /* disable pre-emption; bus won't get left in a bad state for long */ + spin_lock_irqsave(&i2c->reset_lock, flags); + + /* reset engine */ + rc = fsi_i2c_write_reg(i2c->fsi, I2C_FSI_RESET_I2C, &dummy); + if (rc) + goto done; + + /* re-init engine */ + rc = fsi_i2c_dev_init(i2c); + if (rc) + goto done; + + rc = fsi_i2c_read_reg(i2c->fsi, I2C_FSI_MODE, &mode); + if (rc) + goto done; + + /* set port; default after reset is 0 */ + if (port) { + mode = SETFIELD(I2C_MODE_PORT, mode, port); + rc = fsi_i2c_write_reg(i2c->fsi, I2C_FSI_MODE, &mode); + if (rc) + goto done; + } + + /* reset busy register; hw workaround */ + dummy = I2C_PORT_BUSY_RESET; + rc = fsi_i2c_write_reg(i2c->fsi, I2C_FSI_PORT_BUSY, &dummy); + if (rc) + goto done; + + /* force bus reset */ + rc = fsi_i2c_reset_bus(i2c); + if (rc) + goto done; + + /* reset errors */ + dummy = 0; + rc = fsi_i2c_write_reg(i2c->fsi, I2C_FSI_RESET_ERR, &dummy); + if (rc) + goto done; + + /* wait for command complete; time from legacy driver */ + udelay(1000); + + rc = fsi_i2c_read_reg(i2c->fsi, I2C_FSI_STAT, &stat); + if (rc) + goto done; + + if (stat & I2C_STAT_CMD_COMP) + goto done; + + /* failed to get command complete; reset engine again */ + rc = fsi_i2c_write_reg(i2c->fsi, I2C_FSI_RESET_I2C, &dummy); + if (rc) + goto done; + + /* re-init engine again */ + rc = fsi_i2c_dev_init(i2c); + +done: + spin_unlock_irqrestore(&i2c->reset_lock, flags); + return rc; +} + +static int fsi_i2c_abort(struct fsi_i2c_port *port, u32 status) +{ + int rc; + unsigned long start; + u32 cmd = I2C_CMD_WITH_STOP; + struct fsi_device *fsi = port->master->fsi; + + rc = fsi_i2c_reset(port->master, port->port); + if (rc) + return rc; + + /* skip final stop command for these errors */ + if (status & (I2C_STAT_PARITY | I2C_STAT_LOST_ARB | I2C_STAT_STOP_ERR)) + return 0; + + /* write stop command */ + rc = fsi_i2c_write_reg(fsi, I2C_FSI_CMD, &cmd); + if (rc) + return rc; + + /* wait until we see command complete in the master */ + start = jiffies; + + do { + rc = fsi_i2c_read_reg(fsi, I2C_FSI_STAT, &status); + if (rc) + return rc; + + if (status & I2C_STAT_CMD_COMP) + return 0; + + set_current_state(TASK_INTERRUPTIBLE); + if (schedule_timeout(I2C_LOCAL_WAIT_TIMEOUT) > 0) + return -EINTR; + + } while (time_after(start + I2C_ABORT_TIMEOUT, jiffies)); + + return -ETIME; +} + static int fsi_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num) { @@ -260,6 +445,7 @@ static int fsi_i2c_probe(struct device *dev) if (!i2c) return -ENOMEM; + spin_lock_init(&i2c->reset_lock); i2c->fsi = to_fsi_dev(dev); INIT_LIST_HEAD(&i2c->ports); -- 1.8.3.1 From 1583798945223456642@xxx Sat Nov 11 19:26:16 +0000 2017 X-GM-THRID: 1583798945223456642 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread