From patchwork Thu Nov 16 19:53:46 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eddie James X-Patchwork-Id: 838766 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3ydBn203plz9s7C for ; Fri, 17 Nov 2017 06:55:34 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758136AbdKPTyT (ORCPT ); Thu, 16 Nov 2017 14:54:19 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:49906 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1757577AbdKPTyG (ORCPT ); Thu, 16 Nov 2017 14:54:06 -0500 Received: from pps.filterd (m0098420.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vAGJpa0D067633 for ; Thu, 16 Nov 2017 14:54:06 -0500 Received: from e31.co.us.ibm.com (e31.co.us.ibm.com [32.97.110.149]) by mx0b-001b2d01.pphosted.com with ESMTP id 2e9fspcqkn-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 16 Nov 2017 14:54:05 -0500 Received: from localhost by e31.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 16 Nov 2017 12:54:05 -0700 Received: from b03cxnp07028.gho.boulder.ibm.com (9.17.130.15) by e31.co.us.ibm.com (192.168.1.131) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 16 Nov 2017 12:54:02 -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 vAGJs1Xc64421970; Thu, 16 Nov 2017 12:54:01 -0700 Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id AAE2E78051; Thu, 16 Nov 2017 12:54:01 -0700 (MST) Received: from oc3016140333.ibm.com (unknown [9.85.131.228]) by b03ledav004.gho.boulder.ibm.com (Postfix) with ESMTP id 853407803F; Thu, 16 Nov 2017 12:54:00 -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 1/7] dt-bindings: i2c: Add FSI-attached I2C master dt binding documentation Date: Thu, 16 Nov 2017 13:53:46 -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-8235-0000-0000-00000C938A4C 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.00946834; UDB=6.00477975; IPR=6.00727125; 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:03 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17111619-8236-0000-0000-00003E788A28 Message-Id: <1510862032-12394-2-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=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1711160265 Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org From: "Edward A. James" Document the bindings. Signed-off-by: Edward A. James Acked-by: Rob Herring --- Documentation/devicetree/bindings/i2c/i2c-fsi.txt | 40 +++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 Documentation/devicetree/bindings/i2c/i2c-fsi.txt diff --git a/Documentation/devicetree/bindings/i2c/i2c-fsi.txt b/Documentation/devicetree/bindings/i2c/i2c-fsi.txt new file mode 100644 index 0000000..b1be2ce --- /dev/null +++ b/Documentation/devicetree/bindings/i2c/i2c-fsi.txt @@ -0,0 +1,40 @@ +Device-tree bindings for FSI-attached I2C master and busses +----------------------------------------------------------- + +Required properties: + - compatible = "ibm,i2c-fsi"; + - reg = < address size >; : The FSI CFAM address and address + space size. + - #address-cells = <1>; : Number of address cells in child + nodes. + - #size-cells = <0>; : Number of size cells in child nodes. + - child nodes : Nodes to describe busses off the I2C + master. + +Child node required properties: + - reg = < port number > : The port number on the I2C master. + +Child node optional properties: + - child nodes : Nodes to describe devices on the I2C + bus. + +Examples: + + i2c@1800 { + compatible = "ibm,i2c-fsi"; + reg = < 0x1800 0x400 >; + #address-cells = <1>; + #size-cells = <0>; + + i2c-bus@0 { + reg = <0>; + }; + + i2c-bus@1 { + reg = <1>; + + eeprom@50 { + compatible = "vendor,dev-name"; + }; + }; + }; From patchwork Thu Nov 16 19:53:47 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eddie James X-Patchwork-Id: 838768 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3ydBnQ5Dqzz9s5L for ; Fri, 17 Nov 2017 06:55:54 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933892AbdKPTzu (ORCPT ); Thu, 16 Nov 2017 14:55:50 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:33640 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S933702AbdKPTzi (ORCPT ); Thu, 16 Nov 2017 14:55:38 -0500 Received: from pps.filterd (m0098416.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vAGJtc9d158487 for ; Thu, 16 Nov 2017 14:55:38 -0500 Received: from e31.co.us.ibm.com (e31.co.us.ibm.com [32.97.110.149]) by mx0b-001b2d01.pphosted.com with ESMTP id 2e9d6hdrph-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 16 Nov 2017 14:54:09 -0500 Received: from localhost by e31.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 16 Nov 2017 12:54:09 -0700 Received: from b03cxnp08025.gho.boulder.ibm.com (9.17.130.17) by e31.co.us.ibm.com (192.168.1.131) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 16 Nov 2017 12:54:05 -0700 Received: from b03ledav004.gho.boulder.ibm.com (b03ledav004.gho.boulder.ibm.com [9.17.130.235]) by b03cxnp08025.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id vAGJs55N1966576; Thu, 16 Nov 2017 12:54:05 -0700 Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 099BF78059; Thu, 16 Nov 2017 12:54:05 -0700 (MST) Received: from oc3016140333.ibm.com (unknown [9.85.131.228]) by b03ledav004.gho.boulder.ibm.com (Postfix) with ESMTP id DE31C78043; Thu, 16 Nov 2017 12:54:03 -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 2/7] drivers/i2c: Add FSI-attached I2C master algorithm Date: Thu, 16 Nov 2017 13:53:47 -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-8235-0000-0000-00000C938A52 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.00946834; UDB=6.00477975; IPR=6.00727125; 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:07 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17111619-8236-0000-0000-00003E788A36 Message-Id: <1510862032-12394-3-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=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1711160266 Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org From: "Edward A. James" Add register definitions for FSI-attached I2C master and functions to access those registers over FSI. Add an FSI driver so that our I2C bus is probed up during an FSI scan. Signed-off-by: Edward A. James --- drivers/i2c/busses/Kconfig | 11 ++ drivers/i2c/busses/Makefile | 1 + drivers/i2c/busses/i2c-fsi.c | 244 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 256 insertions(+) create mode 100644 drivers/i2c/busses/i2c-fsi.c diff --git a/drivers/i2c/busses/Kconfig b/drivers/i2c/busses/Kconfig index 009345d..4db3f44 100644 --- a/drivers/i2c/busses/Kconfig +++ b/drivers/i2c/busses/Kconfig @@ -1331,4 +1331,15 @@ config I2C_ZX2967 This driver can also be built as a module. If so, the module will be called i2c-zx2967. +config I2C_FSI + tristate "FSI I2C driver" + depends on FSI + help + Driver for FSI bus attached I2C masters. These are I2C masters that + are connected to the system over a FSI bus, instead of the more + common PCI or MMIO interface. + + This driver can also be built as a module. If so, the module will be + called as i2c-fsi. + endmenu diff --git a/drivers/i2c/busses/Makefile b/drivers/i2c/busses/Makefile index 2ce8576..f0ddead 100644 --- a/drivers/i2c/busses/Makefile +++ b/drivers/i2c/busses/Makefile @@ -136,5 +136,6 @@ obj-$(CONFIG_I2C_PCA_ISA) += i2c-pca-isa.o obj-$(CONFIG_I2C_SIBYTE) += i2c-sibyte.o obj-$(CONFIG_I2C_XGENE_SLIMPRO) += i2c-xgene-slimpro.o obj-$(CONFIG_SCx200_ACB) += scx200_acb.o +obj-$(CONFIG_I2C_FSI) += i2c-fsi.o ccflags-$(CONFIG_I2C_DEBUG_BUS) := -DDEBUG diff --git a/drivers/i2c/busses/i2c-fsi.c b/drivers/i2c/busses/i2c-fsi.c new file mode 100644 index 0000000..79475f8 --- /dev/null +++ b/drivers/i2c/busses/i2c-fsi.c @@ -0,0 +1,244 @@ +/* + * Copyright 2017 IBM Corporation + * + * Eddie James + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version + * 2 of the License, or (at your option) any later version. + */ + +#include +#include +#include +#include +#include +#include + +#define FSI_ENGID_I2C 0x7 + +/* Find left shift from first set bit in m */ +#define MASK_TO_LSH(m) (__builtin_ffsll(m) - 1ULL) + +/* Extract field m from v */ +#define GETFIELD(m, v) (((v) & (m)) >> MASK_TO_LSH(m)) + +/* Set field m of v to val */ +#define SETFIELD(m, v, val) \ + (((v) & ~(m)) | ((((typeof(v))(val)) << MASK_TO_LSH(m)) & (m))) + +#define I2C_DEFAULT_CLK_DIV 6 + +/* i2c registers */ +#define I2C_FSI_FIFO 0x00 +#define I2C_FSI_CMD 0x04 +#define I2C_FSI_MODE 0x08 +#define I2C_FSI_WATER_MARK 0x0C +#define I2C_FSI_INT_MASK 0x10 +#define I2C_FSI_INT_COND 0x14 +#define I2C_FSI_OR_INT_MASK 0x14 +#define I2C_FSI_INTS 0x18 +#define I2C_FSI_AND_INT_MASK 0x18 +#define I2C_FSI_STAT 0x1C +#define I2C_FSI_RESET_I2C 0x1C +#define I2C_FSI_ESTAT 0x20 +#define I2C_FSI_RESET_ERR 0x20 +#define I2C_FSI_RESID_LEN 0x24 +#define I2C_FSI_SET_SCL 0x24 +#define I2C_FSI_PORT_BUSY 0x28 +#define I2C_FSI_RESET_SCL 0x2C +#define I2C_FSI_SET_SDA 0x30 +#define I2C_FSI_RESET_SDA 0x34 + +/* cmd register */ +#define I2C_CMD_WITH_START 0x80000000 +#define I2C_CMD_WITH_ADDR 0x40000000 +#define I2C_CMD_RD_CONT 0x20000000 +#define I2C_CMD_WITH_STOP 0x10000000 +#define I2C_CMD_FORCELAUNCH 0x08000000 +#define I2C_CMD_ADDR 0x00fe0000 +#define I2C_CMD_READ 0x00010000 +#define I2C_CMD_LEN 0x0000ffff + +/* mode register */ +#define I2C_MODE_CLKDIV 0xffff0000 +#define I2C_MODE_PORT 0x0000fc00 +#define I2C_MODE_ENHANCED 0x00000008 +#define I2C_MODE_DIAG 0x00000004 +#define I2C_MODE_PACE_ALLOW 0x00000002 +#define I2C_MODE_WRAP 0x00000001 + +/* watermark register */ +#define I2C_WATERMARK_HI 0x0000f000 +#define I2C_WATERMARK_LO 0x000000f0 + +#define I2C_FIFO_HI_LVL 4 +#define I2C_FIFO_LO_LVL 4 + +/* interrupt register */ +#define I2C_INT_INV_CMD 0x00008000 +#define I2C_INT_PARITY 0x00004000 +#define I2C_INT_BE_OVERRUN 0x00002000 +#define I2C_INT_BE_ACCESS 0x00001000 +#define I2C_INT_LOST_ARB 0x00000800 +#define I2C_INT_NACK 0x00000400 +#define I2C_INT_DAT_REQ 0x00000200 +#define I2C_INT_CMD_COMP 0x00000100 +#define I2C_INT_STOP_ERR 0x00000080 +#define I2C_INT_BUSY 0x00000040 +#define I2C_INT_IDLE 0x00000020 + +#define I2C_INT_ENABLE 0x0000ff80 +#define I2C_INT_ERR 0x0000fcc0 + +/* status register */ +#define I2C_STAT_INV_CMD 0x80000000 +#define I2C_STAT_PARITY 0x40000000 +#define I2C_STAT_BE_OVERRUN 0x20000000 +#define I2C_STAT_BE_ACCESS 0x10000000 +#define I2C_STAT_LOST_ARB 0x08000000 +#define I2C_STAT_NACK 0x04000000 +#define I2C_STAT_DAT_REQ 0x02000000 +#define I2C_STAT_CMD_COMP 0x01000000 +#define I2C_STAT_STOP_ERR 0x00800000 +#define I2C_STAT_MAX_PORT 0x000f0000 +#define I2C_STAT_ANY_INT 0x00008000 +#define I2C_STAT_SCL_IN 0x00000800 +#define I2C_STAT_SDA_IN 0x00000400 +#define I2C_STAT_PORT_BUSY 0x00000200 +#define I2C_STAT_SELF_BUSY 0x00000100 +#define I2C_STAT_FIFO_COUNT 0x000000ff + +#define I2C_STAT_ERR 0xfc800000 +#define I2C_STAT_ANY_RESP 0xff800000 + +/* extended status register */ +#define I2C_ESTAT_FIFO_SZ 0xff000000 +#define I2C_ESTAT_SCL_IN_SY 0x00008000 +#define I2C_ESTAT_SDA_IN_SY 0x00004000 +#define I2C_ESTAT_S_SCL 0x00002000 +#define I2C_ESTAT_S_SDA 0x00001000 +#define I2C_ESTAT_M_SCL 0x00000800 +#define I2C_ESTAT_M_SDA 0x00000400 +#define I2C_ESTAT_HI_WATER 0x00000200 +#define I2C_ESTAT_LO_WATER 0x00000100 +#define I2C_ESTAT_PORT_BUSY 0x00000080 +#define I2C_ESTAT_SELF_BUSY 0x00000040 +#define I2C_ESTAT_VERSION 0x0000001f + +struct fsi_i2c_master { + struct fsi_device *fsi; + u8 fifo_size; +}; + +static int fsi_i2c_read_reg(struct fsi_device *fsi, unsigned int reg, + u32 *data) +{ + int rc; + __be32 data_be; + + rc = fsi_device_read(fsi, reg, &data_be, sizeof(data_be)); + if (rc) + return rc; + + *data = be32_to_cpu(data_be); + + return 0; +} + +static int fsi_i2c_write_reg(struct fsi_device *fsi, unsigned int reg, + u32 *data) +{ + __be32 data_be = cpu_to_be32(*data); + + return fsi_device_write(fsi, reg, &data_be, sizeof(data_be)); +} + +static int fsi_i2c_dev_init(struct fsi_i2c_master *i2c) +{ + int rc; + u32 mode = I2C_MODE_ENHANCED, extended_status, watermark = 0; + u32 interrupt = 0; + + /* since we use polling, disable interrupts */ + rc = fsi_i2c_write_reg(i2c->fsi, I2C_FSI_INT_MASK, &interrupt); + if (rc) + return rc; + + mode = SETFIELD(I2C_MODE_CLKDIV, mode, I2C_DEFAULT_CLK_DIV); + rc = fsi_i2c_write_reg(i2c->fsi, I2C_FSI_MODE, &mode); + if (rc) + return rc; + + rc = fsi_i2c_read_reg(i2c->fsi, I2C_FSI_ESTAT, &extended_status); + if (rc) + return rc; + + i2c->fifo_size = GETFIELD(I2C_ESTAT_FIFO_SZ, extended_status); + watermark = SETFIELD(I2C_WATERMARK_HI, watermark, + i2c->fifo_size - I2C_FIFO_HI_LVL); + watermark = SETFIELD(I2C_WATERMARK_LO, watermark, + I2C_FIFO_LO_LVL); + + rc = fsi_i2c_write_reg(i2c->fsi, I2C_FSI_WATER_MARK, &watermark); + + return rc; +} + +static int fsi_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, + int num) +{ + return -EOPNOTSUPP; +} + +static u32 fsi_i2c_functionality(struct i2c_adapter *adap) +{ + return I2C_FUNC_I2C | I2C_FUNC_PROTOCOL_MANGLING | I2C_FUNC_10BIT_ADDR + | I2C_FUNC_SMBUS_EMUL | I2C_FUNC_SMBUS_BLOCK_DATA; +} + +static const struct i2c_algorithm fsi_i2c_algorithm = { + .master_xfer = fsi_i2c_xfer, + .functionality = fsi_i2c_functionality, +}; + +static int fsi_i2c_probe(struct device *dev) +{ + struct fsi_i2c_master *i2c; + int rc; + + i2c = devm_kzalloc(dev, sizeof(*i2c), GFP_KERNEL); + if (!i2c) + return -ENOMEM; + + i2c->fsi = to_fsi_dev(dev); + + rc = fsi_i2c_dev_init(i2c); + if (rc) + return rc; + + dev_set_drvdata(dev, i2c); + + return 0; +} + +static const struct fsi_device_id fsi_i2c_ids[] = { + { FSI_ENGID_I2C, FSI_VERSION_ANY }, + { 0 } +}; + +static struct fsi_driver fsi_i2c_driver = { + .id_table = fsi_i2c_ids, + .drv = { + .name = "i2c-fsi", + .bus = &fsi_bus_type, + .probe = fsi_i2c_probe, + }, +}; + +module_fsi_driver(fsi_i2c_driver); + +MODULE_AUTHOR("Eddie James "); +MODULE_DESCRIPTION("FSI attached I2C master"); +MODULE_LICENSE("GPL"); From patchwork Thu Nov 16 19:53:48 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eddie James X-Patchwork-Id: 838770 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3ydBns1hy7z9s5L for ; Fri, 17 Nov 2017 06:56:17 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933692AbdKPTzi (ORCPT ); Thu, 16 Nov 2017 14:55:38 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:58564 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1758345AbdKPTyW (ORCPT ); Thu, 16 Nov 2017 14:54:22 -0500 Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vAGJsJmc073427 for ; Thu, 16 Nov 2017 14:54:21 -0500 Received: from e32.co.us.ibm.com (e32.co.us.ibm.com [32.97.110.150]) by mx0a-001b2d01.pphosted.com with ESMTP id 2e9erm8dvp-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 16 Nov 2017 14:54:20 -0500 Received: from localhost by e32.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 16 Nov 2017 12:54:12 -0700 Received: from b03cxnp08027.gho.boulder.ibm.com (9.17.130.19) by e32.co.us.ibm.com (192.168.1.132) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 16 Nov 2017 12:54:08 -0700 Received: from b03ledav004.gho.boulder.ibm.com (b03ledav004.gho.boulder.ibm.com [9.17.130.235]) by b03cxnp08027.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id vAGJs82V64946372; Thu, 16 Nov 2017 12:54:08 -0700 Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 4D38C78037; Thu, 16 Nov 2017 12:54:08 -0700 (MST) Received: from oc3016140333.ibm.com (unknown [9.85.131.228]) by b03ledav004.gho.boulder.ibm.com (Postfix) with ESMTP id 39AB878056; Thu, 16 Nov 2017 12:54:07 -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 3/7] drivers/i2c: Add port structure to FSI algorithm Date: Thu, 16 Nov 2017 13:53:48 -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-0004-0000-0000-00001339A6B8 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.00946834; UDB=6.00477975; IPR=6.00727125; 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:10 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17111619-0005-0000-0000-000084E58C96 Message-Id: <1510862032-12394-4-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=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1711160266 Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org From: "Edward A. James" Add and initialize I2C adapters for each port on the FSI-attached I2C master. Ports for each master are defined in the devicetree. Signed-off-by: Edward A. James --- drivers/i2c/busses/i2c-fsi.c | 96 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 96 insertions(+) diff --git a/drivers/i2c/busses/i2c-fsi.c b/drivers/i2c/busses/i2c-fsi.c index 79475f8..4ad5d68 100644 --- a/drivers/i2c/busses/i2c-fsi.c +++ b/drivers/i2c/busses/i2c-fsi.c @@ -14,7 +14,9 @@ #include #include #include +#include #include +#include #define FSI_ENGID_I2C 0x7 @@ -130,6 +132,14 @@ struct fsi_i2c_master { struct fsi_device *fsi; u8 fifo_size; + struct list_head ports; +}; + +struct fsi_i2c_port { + struct list_head list; + struct i2c_adapter adapter; + struct fsi_i2c_master *master; + u16 port; }; static int fsi_i2c_read_reg(struct fsi_device *fsi, unsigned int reg, @@ -186,9 +196,44 @@ static int fsi_i2c_dev_init(struct fsi_i2c_master *i2c) return rc; } +static int fsi_i2c_set_port(struct fsi_i2c_port *port) +{ + int rc; + struct fsi_device *fsi = port->master->fsi; + u32 mode, dummy = 0; + u16 old_port; + + rc = fsi_i2c_read_reg(fsi, I2C_FSI_MODE, &mode); + if (rc) + return rc; + + old_port = GETFIELD(I2C_MODE_PORT, mode); + + if (old_port != port->port) { + mode = SETFIELD(I2C_MODE_PORT, mode, port->port); + rc = fsi_i2c_write_reg(fsi, I2C_FSI_MODE, &mode); + if (rc) + return rc; + + /* reset engine when port is changed */ + rc = fsi_i2c_write_reg(fsi, I2C_FSI_RESET_ERR, &dummy); + if (rc) + return rc; + } + + return rc; +} + static int fsi_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num) { + int rc; + struct fsi_i2c_port *port = adap->algo_data; + + rc = fsi_i2c_set_port(port); + if (rc) + return rc; + return -EOPNOTSUPP; } @@ -206,23 +251,73 @@ static u32 fsi_i2c_functionality(struct i2c_adapter *adap) static int fsi_i2c_probe(struct device *dev) { struct fsi_i2c_master *i2c; + struct fsi_i2c_port *port; + struct device_node *np; int rc; + u32 port_no; i2c = devm_kzalloc(dev, sizeof(*i2c), GFP_KERNEL); if (!i2c) return -ENOMEM; i2c->fsi = to_fsi_dev(dev); + INIT_LIST_HEAD(&i2c->ports); rc = fsi_i2c_dev_init(i2c); if (rc) return rc; + /* Add adapter for each i2c port of the master. */ + for_each_available_child_of_node(dev->of_node, np) { + rc = of_property_read_u32(np, "reg", &port_no); + if (rc || port_no > USHRT_MAX) + continue; + + port = devm_kzalloc(dev, sizeof(*port), GFP_KERNEL); + if (!port) + break; + + port->master = i2c; + port->port = port_no; + + port->adapter.owner = THIS_MODULE; + port->adapter.dev.of_node = np; + port->adapter.dev.parent = dev; + port->adapter.algo = &fsi_i2c_algorithm; + port->adapter.algo_data = port; + + snprintf(port->adapter.name, sizeof(port->adapter.name), + "i2c_bus-%u", port_no); + + rc = i2c_add_adapter(&port->adapter); + if (rc < 0) { + dev_err(dev, "Failed to register adapter: %d\n", rc); + devm_kfree(dev, port); + continue; + } + + list_add(&port->list, &i2c->ports); + } + dev_set_drvdata(dev, i2c); return 0; } +static int fsi_i2c_remove(struct device *dev) +{ + struct fsi_i2c_master *i2c = dev_get_drvdata(dev); + struct fsi_i2c_port *port; + + if (!list_empty(&i2c->ports)) { + list_for_each_entry(port, &i2c->ports, list) { + i2c_del_adapter(&port->adapter); + } + } + + return 0; +} + static const struct fsi_device_id fsi_i2c_ids[] = { { FSI_ENGID_I2C, FSI_VERSION_ANY }, { 0 } @@ -234,6 +329,7 @@ static int fsi_i2c_probe(struct device *dev) .name = "i2c-fsi", .bus = &fsi_bus_type, .probe = fsi_i2c_probe, + .remove = fsi_i2c_remove, }, }; From patchwork Thu Nov 16 19:53:49 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eddie James X-Patchwork-Id: 838765 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3ydBn01nHqz9s5L for ; Fri, 17 Nov 2017 06:55:32 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933493AbdKPTz3 (ORCPT ); Thu, 16 Nov 2017 14:55:29 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:46500 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933505AbdKPTzK (ORCPT ); Thu, 16 Nov 2017 14:55:10 -0500 Received: from pps.filterd (m0098410.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vAGJt7AP076993 for ; Thu, 16 Nov 2017 14:55:10 -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 2e9ew7fkkc-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 16 Nov 2017 14:55:07 -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=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1711160266 Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@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); From patchwork Thu Nov 16 19:53:50 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eddie James X-Patchwork-Id: 838769 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3ydBnp48gxz9s5L for ; Fri, 17 Nov 2017 06:56:14 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933860AbdKPTzp (ORCPT ); Thu, 16 Nov 2017 14:55:45 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:58250 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1758195AbdKPTyU (ORCPT ); Thu, 16 Nov 2017 14:54:20 -0500 Received: from pps.filterd (m0098417.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vAGJsH8t073208 for ; Thu, 16 Nov 2017 14:54:20 -0500 Received: from e36.co.us.ibm.com (e36.co.us.ibm.com [32.97.110.154]) by mx0a-001b2d01.pphosted.com with ESMTP id 2e9erm8e06-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 16 Nov 2017 14:54:19 -0500 Received: from localhost by e36.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 16 Nov 2017 12:54:18 -0700 Received: from b03cxnp08027.gho.boulder.ibm.com (9.17.130.19) by e36.co.us.ibm.com (192.168.1.136) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 16 Nov 2017 12:54:15 -0700 Received: from b03ledav004.gho.boulder.ibm.com (b03ledav004.gho.boulder.ibm.com [9.17.130.235]) by b03cxnp08027.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id vAGJsE8Q4391372; Thu, 16 Nov 2017 12:54:14 -0700 Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 9C41978043; Thu, 16 Nov 2017 12:54:14 -0700 (MST) Received: from oc3016140333.ibm.com (unknown [9.85.131.228]) by b03ledav004.gho.boulder.ibm.com (Postfix) with ESMTP id 6A74078047; Thu, 16 Nov 2017 12:54:13 -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 5/7] drivers/i2c: Add transfer implementation for FSI algorithm Date: Thu, 16 Nov 2017 13:53:50 -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-0020-0000-0000-00000D029DB9 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.00477976; IPR=6.00727125; 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:17 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17111619-0021-0000-0000-00005EEE4677 Message-Id: <1510862032-12394-6-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=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1711160266 Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org From: "Edward A. James" Execute I2C transfers from the FSI-attached I2C master. Use polling instead of interrupts as we have no hardware IRQ over FSI. Signed-off-by: Edward A. James --- drivers/i2c/busses/i2c-fsi.c | 214 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 212 insertions(+), 2 deletions(-) diff --git a/drivers/i2c/busses/i2c-fsi.c b/drivers/i2c/busses/i2c-fsi.c index 61609bce..5c312ef 100644 --- a/drivers/i2c/busses/i2c-fsi.c +++ b/drivers/i2c/busses/i2c-fsi.c @@ -152,6 +152,7 @@ struct fsi_i2c_port { struct i2c_adapter adapter; struct fsi_i2c_master *master; u16 port; + u16 xfrd; }; static int fsi_i2c_read_reg(struct fsi_device *fsi, unsigned int reg, @@ -236,6 +237,103 @@ static int fsi_i2c_set_port(struct fsi_i2c_port *port) return rc; } +static int fsi_i2c_start(struct fsi_i2c_port *port, struct i2c_msg *msg, + bool stop) +{ + int rc; + struct fsi_i2c_master *i2c = port->master; + u32 cmd = I2C_CMD_WITH_START | I2C_CMD_WITH_ADDR; + + port->xfrd = 0; + + if (msg->flags & I2C_M_RD) + cmd |= I2C_CMD_READ; + + if (stop || msg->flags & I2C_M_STOP) + cmd |= I2C_CMD_WITH_STOP; + + cmd = SETFIELD(I2C_CMD_ADDR, cmd, msg->addr >> 1); + cmd = SETFIELD(I2C_CMD_LEN, cmd, msg->len); + + rc = fsi_i2c_write_reg(i2c->fsi, I2C_FSI_CMD, &cmd); + + return rc; +} + +static int fsi_i2c_write_fifo(struct fsi_i2c_port *port, struct i2c_msg *msg, + u8 fifo_count) +{ + int write; + int rc = 0; + struct fsi_i2c_master *i2c = port->master; + int bytes_to_write = i2c->fifo_size - fifo_count; + int bytes_remaining = msg->len - port->xfrd; + + if (bytes_to_write > bytes_remaining) + bytes_to_write = bytes_remaining; + + while (bytes_to_write > 0) { + write = bytes_to_write; + /* fsi limited to max 4 byte aligned ops */ + if (bytes_to_write > 4) + write = 4; + else if (write == 3) + write = 2; + + rc = fsi_device_write(i2c->fsi, I2C_FSI_FIFO, + &msg->buf[port->xfrd], write); + if (rc) + return rc; + + port->xfrd += write; + bytes_to_write -= write; + } + + return rc; +} + +static int fsi_i2c_read_fifo(struct fsi_i2c_port *port, struct i2c_msg *msg, + u8 fifo_count) +{ + int read; + int rc = 0; + struct fsi_i2c_master *i2c = port->master; + int xfr_remaining = msg->len - port->xfrd; + u32 dummy; + + while (fifo_count) { + read = fifo_count; + /* fsi limited to max 4 byte aligned ops */ + if (fifo_count > 4) + read = 4; + else if (read == 3) + read = 2; + + if (xfr_remaining) { + if (xfr_remaining < read) + read = xfr_remaining; + + rc = fsi_device_read(i2c->fsi, I2C_FSI_FIFO, + &msg->buf[port->xfrd], read); + if (rc) + return rc; + + port->xfrd += read; + xfr_remaining -= read; + } else { + /* no more buffer but data in fifo, need to clear it */ + rc = fsi_device_read(i2c->fsi, I2C_FSI_FIFO, &dummy, + read); + if (rc) + return rc; + } + + fifo_count -= read; + } + + return rc; +} + static int fsi_i2c_reset_bus(struct fsi_i2c_master *i2c) { int i, rc; @@ -409,17 +507,129 @@ static int fsi_i2c_abort(struct fsi_i2c_port *port, u32 status) return -ETIME; } +static int fsi_i2c_handle_status(struct fsi_i2c_port *port, + struct i2c_msg *msg, u32 status) +{ + int rc; + u8 fifo_count; + + if (status & I2C_STAT_ERR) { + rc = fsi_i2c_abort(port, status); + if (rc) + return rc; + + if (status & I2C_STAT_INV_CMD) + return -EINVAL; + + if (status & (I2C_STAT_PARITY | I2C_STAT_BE_OVERRUN | + I2C_STAT_BE_ACCESS)) + return -EPROTO; + + if (status & I2C_STAT_NACK) + return -ENXIO; + + if (status & I2C_STAT_LOST_ARB) + return -EAGAIN; + + if (status & I2C_STAT_STOP_ERR) + return -EBADMSG; + + return -EIO; + } + + if (status & I2C_STAT_DAT_REQ) { + fifo_count = GETFIELD(I2C_STAT_FIFO_COUNT, status); + + if (msg->flags & I2C_M_RD) + rc = fsi_i2c_read_fifo(port, msg, fifo_count); + else + rc = fsi_i2c_write_fifo(port, msg, fifo_count); + + return rc; + } + + if (status & I2C_STAT_CMD_COMP) { + if (port->xfrd < msg->len) + rc = -ENODATA; + else + rc = msg->len; + + return rc; + } + + return 0; +} + +static int fsi_i2c_wait(struct fsi_i2c_port *port, struct i2c_msg *msg, + unsigned long timeout) +{ + u32 status = 0; + int rc, rc_abort; + unsigned long start = jiffies; + + do { + rc = fsi_i2c_read_reg(port->master->fsi, I2C_FSI_STAT, + &status); + if (rc) + return rc; + + if (status & I2C_STAT_ANY_RESP) { + rc = fsi_i2c_handle_status(port, msg, status); + if (rc < 0) + return rc; + + /* cmd complete and all data xfrd */ + if (rc == msg->len) + return 0; + + /* need to xfr more data, but maybe don't need wait */ + continue; + } + + set_current_state(TASK_INTERRUPTIBLE); + if (schedule_timeout(I2C_LOCAL_WAIT_TIMEOUT) > 0) { + rc = -EINTR; + goto abort; + } + } while (time_after(start + timeout, jiffies)); + + rc = -ETIME; + +abort: + rc_abort = fsi_i2c_abort(port, status); + if (rc_abort) + return rc_abort; + + return rc; +} + static int fsi_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num) { - int rc; + int i, rc; + unsigned long start_time; struct fsi_i2c_port *port = adap->algo_data; + struct i2c_msg *msg; rc = fsi_i2c_set_port(port); if (rc) return rc; - return -EOPNOTSUPP; + for (i = 0; i < num; ++i) { + msg = msgs + i; + start_time = jiffies; + + rc = fsi_i2c_start(port, msg, i == num - 1); + if (rc) + return rc; + + rc = fsi_i2c_wait(port, msg, + adap->timeout - (jiffies - start_time)); + if (rc) + return rc; + } + + return 0; } static u32 fsi_i2c_functionality(struct i2c_adapter *adap) From patchwork Thu Nov 16 19:53:51 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eddie James X-Patchwork-Id: 838767 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3ydBn313GNz9s5L for ; Fri, 17 Nov 2017 06:55:35 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S933592AbdKPTzd (ORCPT ); Thu, 16 Nov 2017 14:55:33 -0500 Received: from mx0b-001b2d01.pphosted.com ([148.163.158.5]:41378 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1758436AbdKPTyZ (ORCPT ); Thu, 16 Nov 2017 14:54:25 -0500 Received: from pps.filterd (m0098419.ppops.net [127.0.0.1]) by mx0b-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vAGJsJMC103665 for ; Thu, 16 Nov 2017 14:54:24 -0500 Received: from e34.co.us.ibm.com (e34.co.us.ibm.com [32.97.110.152]) by mx0b-001b2d01.pphosted.com with ESMTP id 2e9etu83kt-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 16 Nov 2017 14:54:23 -0500 Received: from localhost by e34.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 16 Nov 2017 12:54:22 -0700 Received: from b03cxnp08027.gho.boulder.ibm.com (9.17.130.19) by e34.co.us.ibm.com (192.168.1.134) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 16 Nov 2017 12:54:18 -0700 Received: from b03ledav004.gho.boulder.ibm.com (b03ledav004.gho.boulder.ibm.com [9.17.130.235]) by b03cxnp08027.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id vAGJsHAF6095200; Thu, 16 Nov 2017 12:54:17 -0700 Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 86A3278038; Thu, 16 Nov 2017 12:54:17 -0700 (MST) Received: from oc3016140333.ibm.com (unknown [9.85.131.228]) by b03ledav004.gho.boulder.ibm.com (Postfix) with ESMTP id 6883378043; Thu, 16 Nov 2017 12:54:16 -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 6/7] drivers/i2c: Add I2C master locking to FSI algorithm Date: Thu, 16 Nov 2017 13:53:51 -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-0016-0000-0000-000007D1AD35 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.00477976; 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:20 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17111619-0017-0000-0000-00003C478692 Message-Id: <1510862032-12394-7-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=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1711160266 Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org From: "Edward A. James" Since there are many ports per master, each with it's own adapter and chardev, we need some locking to prevent transfers from changing the master state while other transfers are in progress. Signed-off-by: Edward A. James --- drivers/i2c/busses/i2c-fsi.c | 43 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 39 insertions(+), 4 deletions(-) diff --git a/drivers/i2c/busses/i2c-fsi.c b/drivers/i2c/busses/i2c-fsi.c index 5c312ef..1751c44 100644 --- a/drivers/i2c/busses/i2c-fsi.c +++ b/drivers/i2c/busses/i2c-fsi.c @@ -20,7 +20,9 @@ #include #include #include +#include #include +#include #define FSI_ENGID_I2C 0x7 @@ -144,6 +146,8 @@ struct fsi_i2c_master { struct fsi_device *fsi; u8 fifo_size; struct list_head ports; + wait_queue_head_t wait; + struct semaphore lock; spinlock_t reset_lock; }; @@ -178,6 +182,29 @@ static int fsi_i2c_write_reg(struct fsi_device *fsi, unsigned int reg, return fsi_device_write(fsi, reg, &data_be, sizeof(data_be)); } +static int fsi_i2c_lock_master(struct fsi_i2c_master *i2c, int timeout) +{ + int rc; + + rc = down_trylock(&i2c->lock); + if (!rc) + return 0; + + rc = wait_event_interruptible_timeout(i2c->wait, + !down_trylock(&i2c->lock), + timeout); + if (rc > 0) + return 0; + + return -EBUSY; +} + +static void fsi_i2c_unlock_master(struct fsi_i2c_master *i2c) +{ + up(&i2c->lock); + wake_up(&i2c->wait); +} + static int fsi_i2c_dev_init(struct fsi_i2c_master *i2c) { int rc; @@ -611,25 +638,31 @@ static int fsi_i2c_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, struct fsi_i2c_port *port = adap->algo_data; struct i2c_msg *msg; - rc = fsi_i2c_set_port(port); + rc = fsi_i2c_lock_master(port->master, adap->timeout); if (rc) return rc; + rc = fsi_i2c_set_port(port); + if (rc) + goto unlock; + for (i = 0; i < num; ++i) { msg = msgs + i; start_time = jiffies; rc = fsi_i2c_start(port, msg, i == num - 1); if (rc) - return rc; + goto unlock; rc = fsi_i2c_wait(port, msg, adap->timeout - (jiffies - start_time)); if (rc) - return rc; + goto unlock; } - return 0; +unlock: + fsi_i2c_unlock_master(port->master); + return rc; } static u32 fsi_i2c_functionality(struct i2c_adapter *adap) @@ -655,6 +688,8 @@ static int fsi_i2c_probe(struct device *dev) if (!i2c) return -ENOMEM; + init_waitqueue_head(&i2c->wait); + sema_init(&i2c->lock, 1); spin_lock_init(&i2c->reset_lock); i2c->fsi = to_fsi_dev(dev); INIT_LIST_HEAD(&i2c->ports); From patchwork Thu Nov 16 19:53:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eddie James X-Patchwork-Id: 838764 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=linux-i2c-owner@vger.kernel.org; receiver=) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3ydBlw1CpHz9s72 for ; Fri, 17 Nov 2017 06:54:36 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1758599AbdKPTy3 (ORCPT ); Thu, 16 Nov 2017 14:54:29 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:40972 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758467AbdKPTy1 (ORCPT ); Thu, 16 Nov 2017 14:54:27 -0500 Received: from pps.filterd (m0098396.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vAGJsNiQ002687 for ; Thu, 16 Nov 2017 14:54:26 -0500 Received: from e35.co.us.ibm.com (e35.co.us.ibm.com [32.97.110.153]) by mx0a-001b2d01.pphosted.com with ESMTP id 2e9gwm8xvu-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Thu, 16 Nov 2017 14:54:26 -0500 Received: from localhost by e35.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 16 Nov 2017 12:54:24 -0700 Received: from b03cxnp08028.gho.boulder.ibm.com (9.17.130.20) by e35.co.us.ibm.com (192.168.1.135) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 16 Nov 2017 12:54:20 -0700 Received: from b03ledav004.gho.boulder.ibm.com (b03ledav004.gho.boulder.ibm.com [9.17.130.235]) by b03cxnp08028.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id vAGJsK2X66125850; Thu, 16 Nov 2017 12:54:20 -0700 Received: from b03ledav004.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 6C1BE78038; Thu, 16 Nov 2017 12:54:20 -0700 (MST) Received: from oc3016140333.ibm.com (unknown [9.85.131.228]) by b03ledav004.gho.boulder.ibm.com (Postfix) with ESMTP id 45E0178037; Thu, 16 Nov 2017 12:54:19 -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 7/7] drivers/i2c: Add bus recovery for FSI algorithm Date: Thu, 16 Nov 2017 13:53:52 -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-0012-0000-0000-0000154E9FBC 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:23 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17111619-0013-0000-0000-0000504B6D56 Message-Id: <1510862032-12394-8-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-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org From: "Edward A. James" Bus recovery should reset the engine and force clock the bus 9 times to recover most situations. Signed-off-by: Edward A. James --- drivers/i2c/busses/i2c-fsi.c | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/drivers/i2c/busses/i2c-fsi.c b/drivers/i2c/busses/i2c-fsi.c index 1751c44..10f693f 100644 --- a/drivers/i2c/busses/i2c-fsi.c +++ b/drivers/i2c/busses/i2c-fsi.c @@ -671,6 +671,27 @@ static u32 fsi_i2c_functionality(struct i2c_adapter *adap) | I2C_FUNC_SMBUS_EMUL | I2C_FUNC_SMBUS_BLOCK_DATA; } +static int fsi_i2c_recover_bus(struct i2c_adapter *adap) +{ + int rc; + struct fsi_i2c_port *port = adap->algo_data; + struct fsi_i2c_master *master = port->master; + + rc = fsi_i2c_lock_master(master, adap->timeout); + if (rc) + return rc; + + rc = fsi_i2c_reset(master, port->port); + + fsi_i2c_unlock_master(master); + + return rc; +} + +static struct i2c_bus_recovery_info fsi_i2c_bus_recovery_info = { + .recover_bus = fsi_i2c_recover_bus, +}; + static const struct i2c_algorithm fsi_i2c_algorithm = { .master_xfer = fsi_i2c_xfer, .functionality = fsi_i2c_functionality, @@ -715,6 +736,7 @@ static int fsi_i2c_probe(struct device *dev) port->adapter.dev.of_node = np; port->adapter.dev.parent = dev; port->adapter.algo = &fsi_i2c_algorithm; + port->adapter.bus_recovery_info = &fsi_i2c_bus_recovery_info; port->adapter.algo_data = port; snprintf(port->adapter.name, sizeof(port->adapter.name),