From patchwork Mon May 31 13:19:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raviteja Narayanam X-Patchwork-Id: 450621 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 74E46C47082 for ; Mon, 31 May 2021 13:22:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5184F613F1 for ; Mon, 31 May 2021 13:22:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231986AbhEaNYb (ORCPT ); Mon, 31 May 2021 09:24:31 -0400 Received: from mail-co1nam11on2045.outbound.protection.outlook.com ([40.107.220.45]:53825 "EHLO NAM11-CO1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S232262AbhEaNWd (ORCPT ); Mon, 31 May 2021 09:22:33 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=J/jYxuSIYXfqfSX36YCdmjJPfshOEaaeBiXClrypT2syVRkLjXAh72NIw7i+X9TLmscbYP/4jF4pM/m/bHrPI++qvtQ1lC6hvXllhoPbJr63PlmPneqKEeuSP9r2Es57kuzs3FSGfwYMWbUCPIsUeG1WKrgC/xuNNDGKpH6O1EvzUIs9tVMxwf0CcEPaEgecGspwKes4BTlETM+ApXSvc5uKJuNVMLVP06u0uWoMb/4HcJqkvlSMKswSd30UOR3zg6lSvcUtxRuzKp9JhArSDj9wfKv0QcEfmBSE1Kx93yIP8FuNhZEGlaVko6KkuqH9+aUAiTB8ZdQQxWUdkAddGA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=jxNuL0P9T2L9KMIk59oDrl7+ZpGxbGt8ik5LshPLkpQ=; b=DJyUZYGYpBgUFHWXC08fJkOuDnpE+rburRGVoC3Wd9IjNSVQqJGaKa7+L3/bWdRQGiH10xDnOEzDl0GOZWabVlNzkarxV47n1gTJPFTsMKSaBdQEag1U72HRe5s90ESNKe5h18xoWV2J9yLxZ81awzGBXwb/bzSN3Mm+TrEPu5Br5lguGxXLiji3xe/iN7jXY4/oA3fddModtjvCeWno8bvfKLc8AbveaSHJSO+7GPm6VFA+hB12HEM0z4msb4S+aP1OT1/IcjAx5E0u5zorSF0phey3BCiUnWw3ZUOe+PzOEfuLebeEZ/72mNprfeOWj+5fEzrbD3FLekkBPUynug== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.62.198) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=xilinx.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=xilinx.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=jxNuL0P9T2L9KMIk59oDrl7+ZpGxbGt8ik5LshPLkpQ=; b=K6EWCggYiORgwn2oHO+GD78rdtTH+w1+Uu/IPymLeHYzWzjk9uuaD4fXfWZ7wYYPUeJcD9R5mM01jsBVlK90vaulsTjTCtnd1kSHjo9IzOvBJkDlKwuF3iPS/2buvJxoEplcIxTegmD4xWhS7SyLUQO/LyjRnavloKL73k6RiSY= Received: from SN7PR04CA0193.namprd04.prod.outlook.com (2603:10b6:806:126::18) by MWHPR02MB2750.namprd02.prod.outlook.com (2603:10b6:300:110::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4173.22; Mon, 31 May 2021 13:20:48 +0000 Received: from SN1NAM02FT0034.eop-nam02.prod.protection.outlook.com (2603:10b6:806:126:cafe::1b) by SN7PR04CA0193.outlook.office365.com (2603:10b6:806:126::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4173.22 via Frontend Transport; Mon, 31 May 2021 13:20:48 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.62.198) smtp.mailfrom=xilinx.com; vger.kernel.org; dkim=none (message not signed) header.d=none; vger.kernel.org; dmarc=pass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.62.198 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.62.198; helo=xsj-pvapexch02.xlnx.xilinx.com; Received: from xsj-pvapexch02.xlnx.xilinx.com (149.199.62.198) by SN1NAM02FT0034.mail.protection.outlook.com (10.97.5.90) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4150.30 via Frontend Transport; Mon, 31 May 2021 13:20:48 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Mon, 31 May 2021 06:20:30 -0700 Received: from smtp.xilinx.com (172.19.127.95) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server id 15.1.2176.2 via Frontend Transport; Mon, 31 May 2021 06:20:30 -0700 Envelope-to: git@xilinx.com, linux-i2c@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, marex@denx.de Received: from [10.140.6.25] (port=53014 helo=xhdnagasure40.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1lnhqH-0004GE-1S; Mon, 31 May 2021 06:20:29 -0700 From: Raviteja Narayanam To: , CC: , , , , Raviteja Narayanam Subject: [PATCH 02/10] i2c: xiic: Add standard mode support for > 255 byte read transfers Date: Mon, 31 May 2021 07:19:40 -0600 Message-ID: <20210531131948.19477-3-raviteja.narayanam@xilinx.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210531131948.19477-1-raviteja.narayanam@xilinx.com> References: <20210531131948.19477-1-raviteja.narayanam@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: cfc95f72-ce2e-4213-cb95-08d92436e78f X-MS-TrafficTypeDiagnostic: MWHPR02MB2750: X-Microsoft-Antispam-PRVS: X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-MS-Oob-TLC-OOBClassifiers: OLM:232; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: VG1ZjKuxTE/IsVzCets9gFp8a9Nl5vKm06R/3+5EvU9vaDVygIAj7AC3cQiGRvag5N7eSMjSRB3U+BGcdUyuBIf8dbArlVSCYwjHGV45WPYCgjDivhUKe11Q1wK18lxmkK3wb9qCwKDMgKTJAdcclSzb650GfPCYZIPMldLgBXniMYy6JeqixZZWUpCPucmoo7JwVvkS90DEyIBmPyOLgnNPOruAJE+nl34g5ANwNgndI7IE/rcSX0vCuJKS/WKY83LlonAgSA46vKjNwl3QkTXFH/XbZREkIisFWtYsXcAhF4ikBz43eEQGLz6hMKqjgovvGm+OVJF8uD71jVCttl1AXsiQAC7SaGsth+JRYDrFNfcAq0p/zHJZKIu2Q4dMGvkcdUxJRxp3GAc6WdQ1pHVtQofsSb3jCncGfJctsCXrg128pF5kb34FVBortfGu1IAryfIDohWQbB5+lGB53CFtSUkG7G7mZxzQeaQU5hhjSx5zcI/VKt+CWkB6Zyzk/BnY+ph7xBq+nB2Tb0+9cwG9GPoSkEfAyl6x7Fo6OVimmoOEl+jC+C1nfSQJiCdQPHh7ZxkN8UBWHFPzAzY6ZjYr14ZkuEhiXuCMI+0qT5ggVoB5+mIoSZRfTlFgTYq09ZJElS6e9hq4liTDbYp3DQZx2P1tRtYaEqNgLMLWD+YcUgZzy3sRnEEsuRZmlZ9I X-Forefront-Antispam-Report: CIP:149.199.62.198; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:xsj-pvapexch02.xlnx.xilinx.com; PTR:unknown-62-198.xilinx.com; CAT:NONE; SFS:(4636009)(136003)(396003)(346002)(39860400002)(376002)(36840700001)(46966006)(1076003)(2616005)(5660300002)(6636002)(478600001)(4326008)(70206006)(7636003)(7696005)(356005)(9786002)(336012)(2906002)(186003)(70586007)(110136005)(107886003)(44832011)(82740400003)(36756003)(8936002)(6666004)(82310400003)(54906003)(26005)(8676002)(426003)(83380400001)(47076005)(30864003)(36860700001)(316002)(102446001); DIR:OUT; SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 May 2021 13:20:48.0620 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: cfc95f72-ce2e-4213-cb95-08d92436e78f X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c; Ip=[149.199.62.198]; Helo=[xsj-pvapexch02.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-AuthSource: SN1NAM02FT0034.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: MWHPR02MB2750 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org In the current driver implementation, there is a limit of read transfer size to 255 bytes as it is using AXI I2C dynamic mode. But the IP supports this transfer through standard mode. So added AXI I2C standard mode support to enable read transfers of size more than 255 bytes. The driver scans through the message request from user space and selects AXI I2C standard mode if there is a read request of more than 255 bytes. Then the whole message goes through standard mode Tx and Rx paths. Signed-off-by: Raviteja Narayanam --- drivers/i2c/busses/i2c-xiic.c | 367 +++++++++++++++++++++++++++++----- 1 file changed, 319 insertions(+), 48 deletions(-) diff --git a/drivers/i2c/busses/i2c-xiic.c b/drivers/i2c/busses/i2c-xiic.c index b0cfd9d15467..004103267e9c 100644 --- a/drivers/i2c/busses/i2c-xiic.c +++ b/drivers/i2c/busses/i2c-xiic.c @@ -60,6 +60,8 @@ enum xiic_endian { * @clk: Pointer to AXI4-lite input clock * @state: See STATE_ * @singlemaster: Indicates bus is single master + * @dynamic: Mode of controller + * @prev_msg_tx: Previous message is Tx */ struct xiic_i2c { struct device *dev; @@ -76,6 +78,8 @@ struct xiic_i2c { struct clk *clk; enum xilinx_i2c_state state; bool singlemaster; + bool dynamic; + bool prev_msg_tx; }; @@ -144,6 +148,9 @@ struct xiic_i2c { #define XIIC_TX_DYN_START_MASK 0x0100 /* 1 = Set dynamic start */ #define XIIC_TX_DYN_STOP_MASK 0x0200 /* 1 = Set dynamic stop */ +/* Dynamic mode constants */ +#define MAX_READ_LENGTH_DYNAMIC 255 /* Max length for dynamic read */ + /* * The following constants define the register offsets for the Interrupt * registers. There are some holes in the memory map for reserved addresses @@ -270,6 +277,24 @@ static int xiic_clear_rx_fifo(struct xiic_i2c *i2c) return 0; } +static int xiic_wait_tx_empty(struct xiic_i2c *i2c) +{ + u8 isr; + unsigned long timeout; + + timeout = jiffies + XIIC_I2C_TIMEOUT; + for (isr = xiic_getreg32(i2c, XIIC_IISR_OFFSET); + !(isr & XIIC_INTR_TX_EMPTY_MASK); + isr = xiic_getreg32(i2c, XIIC_IISR_OFFSET)) { + if (time_after(jiffies, timeout)) { + dev_err(i2c->dev, "Timeout waiting at Tx empty\n"); + return -ETIMEDOUT; + } + } + + return 0; +} + static int xiic_reinit(struct xiic_i2c *i2c) { int ret; @@ -311,13 +336,14 @@ static void xiic_deinit(struct xiic_i2c *i2c) static void xiic_read_rx(struct xiic_i2c *i2c) { - u8 bytes_in_fifo; + u8 bytes_in_fifo, cr = 0, bytes_to_read = 0; + u32 bytes_rem = 0; int i; bytes_in_fifo = xiic_getreg8(i2c, XIIC_RFO_REG_OFFSET) + 1; dev_dbg(i2c->adap.dev.parent, - "%s entry, bytes in fifo: %d, msg: %d, SR: 0x%x, CR: 0x%x\n", + "%s entry, bytes in fifo: %d, rem: %d, SR: 0x%x, CR: 0x%x\n", __func__, bytes_in_fifo, xiic_rx_space(i2c), xiic_getreg8(i2c, XIIC_SR_REG_OFFSET), xiic_getreg8(i2c, XIIC_CR_REG_OFFSET)); @@ -325,13 +351,53 @@ static void xiic_read_rx(struct xiic_i2c *i2c) if (bytes_in_fifo > xiic_rx_space(i2c)) bytes_in_fifo = xiic_rx_space(i2c); - for (i = 0; i < bytes_in_fifo; i++) + bytes_to_read = bytes_in_fifo; + + if (!i2c->dynamic) { + bytes_rem = xiic_rx_space(i2c) - bytes_in_fifo; + + if (bytes_rem > IIC_RX_FIFO_DEPTH) { + bytes_to_read = bytes_in_fifo; + } else if (bytes_rem > 1) { + bytes_to_read = bytes_rem - 1; + } else if (bytes_rem == 1) { + bytes_to_read = 1; + /* Set NACK in CR to indicate slave transmitter */ + cr = xiic_getreg8(i2c, XIIC_CR_REG_OFFSET); + xiic_setreg8(i2c, XIIC_CR_REG_OFFSET, cr | + XIIC_CR_NO_ACK_MASK); + } else if (bytes_rem == 0) { + bytes_to_read = bytes_in_fifo; + + /* Generate stop on the bus if it is last message */ + if (i2c->nmsgs == 1) { + cr = xiic_getreg8(i2c, XIIC_CR_REG_OFFSET); + xiic_setreg8(i2c, XIIC_CR_REG_OFFSET, cr & + ~XIIC_CR_MSMS_MASK); + } + + /* Make TXACK=0, clean up for next transaction */ + cr = xiic_getreg8(i2c, XIIC_CR_REG_OFFSET); + xiic_setreg8(i2c, XIIC_CR_REG_OFFSET, cr & + ~XIIC_CR_NO_ACK_MASK); + } + } + + /* Read the fifo */ + for (i = 0; i < bytes_to_read; i++) { i2c->rx_msg->buf[i2c->rx_pos++] = xiic_getreg8(i2c, XIIC_DRR_REG_OFFSET); + } - xiic_setreg8(i2c, XIIC_RFD_REG_OFFSET, - (xiic_rx_space(i2c) > IIC_RX_FIFO_DEPTH) ? - IIC_RX_FIFO_DEPTH - 1 : xiic_rx_space(i2c) - 1); + if (i2c->dynamic) { + u8 bytes; + + /* Receive remaining bytes if less than fifo depth */ + bytes = min_t(u8, xiic_rx_space(i2c), IIC_RX_FIFO_DEPTH); + bytes--; + + xiic_setreg8(i2c, XIIC_RFD_REG_OFFSET, bytes); + } } static int xiic_tx_fifo_space(struct xiic_i2c *i2c) @@ -361,6 +427,62 @@ static void xiic_fill_tx_fifo(struct xiic_i2c *i2c) } } +static void xiic_std_fill_tx_fifo(struct xiic_i2c *i2c) +{ + u8 fifo_space = xiic_tx_fifo_space(i2c); + u16 data = 0; + int len = xiic_tx_space(i2c); + + dev_dbg(i2c->adap.dev.parent, "%s entry, len: %d, fifo space: %d\n", + __func__, len, fifo_space); + + if (len > fifo_space) + len = fifo_space; + else if (len && !(i2c->nmsgs > 1)) + len--; + + while (len--) { + data = i2c->tx_msg->buf[i2c->tx_pos++]; + xiic_setreg16(i2c, XIIC_DTR_REG_OFFSET, data); + } +} + +static void xiic_send_tx(struct xiic_i2c *i2c) +{ + dev_dbg(i2c->adap.dev.parent, + "%s entry, rem: %d, SR: 0x%x, CR: 0x%x\n", + __func__, xiic_tx_space(i2c), + xiic_getreg8(i2c, XIIC_SR_REG_OFFSET), + xiic_getreg8(i2c, XIIC_CR_REG_OFFSET)); + + if (xiic_tx_space(i2c) > 1) { + xiic_std_fill_tx_fifo(i2c); + return; + } + + if ((xiic_tx_space(i2c) == 1)) { + u16 data; + + if (i2c->nmsgs == 1) { + u8 cr; + int status; + + /* Wait till FIFO is empty so STOP is sent last */ + status = xiic_wait_tx_empty(i2c); + if (status) + return; + + /* Write to CR to stop */ + cr = xiic_getreg8(i2c, XIIC_CR_REG_OFFSET); + xiic_setreg8(i2c, XIIC_CR_REG_OFFSET, cr & + ~XIIC_CR_MSMS_MASK); + } + /* Send last byte */ + data = i2c->tx_msg->buf[i2c->tx_pos++]; + xiic_setreg16(i2c, XIIC_DTR_REG_OFFSET, data); + } +} + static void xiic_wakeup(struct xiic_i2c *i2c, int code) { i2c->tx_msg = NULL; @@ -391,7 +513,9 @@ static irqreturn_t xiic_process(int irq, void *dev_id) dev_dbg(i2c->adap.dev.parent, "%s: SR: 0x%x, msg: %p, nmsgs: %d\n", __func__, xiic_getreg8(i2c, XIIC_SR_REG_OFFSET), i2c->tx_msg, i2c->nmsgs); - + dev_dbg(i2c->adap.dev.parent, "%s, ISR: 0x%x, CR: 0x%x\n", + __func__, xiic_getreg32(i2c, XIIC_IISR_OFFSET), + xiic_getreg8(i2c, XIIC_CR_REG_OFFSET)); /* Service requesting interrupt */ if ((pend & XIIC_INTR_ARB_LOST_MASK) || @@ -465,7 +589,10 @@ static irqreturn_t xiic_process(int irq, void *dev_id) goto out; } - xiic_fill_tx_fifo(i2c); + if (i2c->dynamic) + xiic_fill_tx_fifo(i2c); + else + xiic_send_tx(i2c); /* current message sent and there is space in the fifo */ if (!xiic_tx_space(i2c) && xiic_tx_fifo_space(i2c) >= 2) { @@ -554,35 +681,113 @@ static int xiic_busy(struct xiic_i2c *i2c) static void xiic_start_recv(struct xiic_i2c *i2c) { - u8 rx_watermark; + u16 rx_watermark; + u8 cr = 0, rfd_set = 0; struct i2c_msg *msg = i2c->rx_msg = i2c->tx_msg; unsigned long flags; - /* Clear and enable Rx full interrupt. */ - xiic_irq_clr_en(i2c, XIIC_INTR_RX_FULL_MASK | XIIC_INTR_TX_ERROR_MASK); + dev_dbg(i2c->adap.dev.parent, "%s entry, ISR: 0x%x, CR: 0x%x\n", + __func__, xiic_getreg32(i2c, XIIC_IISR_OFFSET), + xiic_getreg8(i2c, XIIC_CR_REG_OFFSET)); + + /* Disable Tx interrupts */ + xiic_irq_dis(i2c, XIIC_INTR_TX_HALF_MASK | XIIC_INTR_TX_EMPTY_MASK); - /* we want to get all but last byte, because the TX_ERROR IRQ is used - * to inidicate error ACK on the address, and negative ack on the last - * received byte, so to not mix them receive all but last. - * In the case where there is only one byte to receive - * we can check if ERROR and RX full is set at the same time - */ - rx_watermark = msg->len; - if (rx_watermark > IIC_RX_FIFO_DEPTH) - rx_watermark = IIC_RX_FIFO_DEPTH; - xiic_setreg8(i2c, XIIC_RFD_REG_OFFSET, rx_watermark - 1); - - local_irq_save(flags); - if (!(msg->flags & I2C_M_NOSTART)) - /* write the address */ + if (i2c->dynamic) { + u8 bytes; + u16 val; + + /* Clear and enable Rx full interrupt. */ + xiic_irq_clr_en(i2c, XIIC_INTR_RX_FULL_MASK | + XIIC_INTR_TX_ERROR_MASK); + + /* + * We want to get all but last byte, because the TX_ERROR IRQ + * is used to indicate error ACK on the address, and + * negative ack on the last received byte, so to not mix + * them receive all but last. + * In the case where there is only one byte to receive + * we can check if ERROR and RX full is set at the same time + */ + rx_watermark = msg->len; + bytes = min_t(u8, rx_watermark, IIC_RX_FIFO_DEPTH); + bytes--; + + xiic_setreg8(i2c, XIIC_RFD_REG_OFFSET, bytes); + + local_irq_save(flags); + if (!(msg->flags & I2C_M_NOSTART)) + /* write the address */ + xiic_setreg16(i2c, XIIC_DTR_REG_OFFSET, + i2c_8bit_addr_from_msg(msg) | + XIIC_TX_DYN_START_MASK); + + xiic_irq_clr_en(i2c, XIIC_INTR_BNB_MASK); + + /* If last message, include dynamic stop bit with length */ + val = (i2c->nmsgs == 1) ? XIIC_TX_DYN_STOP_MASK : 0; + val |= msg->len; + + xiic_setreg16(i2c, XIIC_DTR_REG_OFFSET, val); + local_irq_restore(flags); + } else { + /* + * If previous message is Tx, make sure that Tx FIFO is empty + * before starting a new transfer as the repeated start in + * standard mode can corrupt the transaction if there are + * still bytes to be transmitted in FIFO + */ + if (i2c->prev_msg_tx) { + int status; + + status = xiic_wait_tx_empty(i2c); + if (status) + return; + } + + cr = xiic_getreg8(i2c, XIIC_CR_REG_OFFSET); + + /* Set Receive fifo depth */ + rx_watermark = msg->len; + if (rx_watermark > IIC_RX_FIFO_DEPTH) { + rfd_set = IIC_RX_FIFO_DEPTH - 1; + } else if ((rx_watermark == 1) || (rx_watermark == 0)) { + rfd_set = rx_watermark - 1; + /* Handle single byte transfer separately */ + cr |= XIIC_CR_NO_ACK_MASK; + } else { + rfd_set = rx_watermark - 2; + } + + /* Check if RSTA should be set */ + if (cr & XIIC_CR_MSMS_MASK) { + /* Already a master, RSTA should be set */ + xiic_setreg8(i2c, XIIC_CR_REG_OFFSET, (cr | + XIIC_CR_REPEATED_START_MASK) & + ~(XIIC_CR_DIR_IS_TX_MASK)); + } + + xiic_setreg8(i2c, XIIC_RFD_REG_OFFSET, rfd_set); + + /* Clear and enable Rx full and transmit complete interrupts */ + xiic_irq_clr_en(i2c, XIIC_INTR_RX_FULL_MASK | + XIIC_INTR_TX_ERROR_MASK); + + /* Write the address */ xiic_setreg16(i2c, XIIC_DTR_REG_OFFSET, - i2c_8bit_addr_from_msg(msg) | XIIC_TX_DYN_START_MASK); + i2c_8bit_addr_from_msg(msg)); - xiic_irq_clr_en(i2c, XIIC_INTR_BNB_MASK); + /* Write to Control Register,to start transaction in Rx mode */ + if ((cr & XIIC_CR_MSMS_MASK) == 0) { + xiic_setreg8(i2c, XIIC_CR_REG_OFFSET, (cr | + XIIC_CR_MSMS_MASK) + & ~(XIIC_CR_DIR_IS_TX_MASK)); + } - xiic_setreg16(i2c, XIIC_DTR_REG_OFFSET, - msg->len | ((i2c->nmsgs == 1) ? XIIC_TX_DYN_STOP_MASK : 0)); - local_irq_restore(flags); + dev_dbg(i2c->adap.dev.parent, "%s end, ISR: 0x%x, CR: 0x%x\n", + __func__, xiic_getreg32(i2c, XIIC_IISR_OFFSET), + xiic_getreg8(i2c, XIIC_CR_REG_OFFSET)); + } if (i2c->nmsgs == 1) /* very last, enable bus not busy as well */ @@ -590,10 +795,17 @@ static void xiic_start_recv(struct xiic_i2c *i2c) /* the message is tx:ed */ i2c->tx_pos = msg->len; + + /* Enable interrupts */ + xiic_setreg32(i2c, XIIC_DGIER_OFFSET, XIIC_GINTR_ENABLE_MASK); + + i2c->prev_msg_tx = false; } static void xiic_start_send(struct xiic_i2c *i2c) { + u8 cr = 0; + u16 data; struct i2c_msg *msg = i2c->tx_msg; xiic_irq_clr(i2c, XIIC_INTR_TX_ERROR_MASK); @@ -604,22 +816,71 @@ static void xiic_start_send(struct xiic_i2c *i2c) __func__, xiic_getreg32(i2c, XIIC_IISR_OFFSET), xiic_getreg8(i2c, XIIC_CR_REG_OFFSET)); - if (!(msg->flags & I2C_M_NOSTART)) { - /* write the address */ - u16 data = i2c_8bit_addr_from_msg(msg) | - XIIC_TX_DYN_START_MASK; - if ((i2c->nmsgs == 1) && msg->len == 0) - /* no data and last message -> add STOP */ - data |= XIIC_TX_DYN_STOP_MASK; + if (i2c->dynamic) { + if (!(msg->flags & I2C_M_NOSTART)) { + /* write the address */ + data = i2c_8bit_addr_from_msg(msg) | + XIIC_TX_DYN_START_MASK; + + if (i2c->nmsgs == 1 && msg->len == 0) + /* no data and last message -> add STOP */ + data |= XIIC_TX_DYN_STOP_MASK; + + xiic_setreg16(i2c, XIIC_DTR_REG_OFFSET, data); + } + + xiic_fill_tx_fifo(i2c); + + /* Clear any pending Tx empty, Tx Error and then enable them */ + xiic_irq_clr_en(i2c, (XIIC_INTR_TX_EMPTY_MASK | + XIIC_INTR_TX_ERROR_MASK | + XIIC_INTR_BNB_MASK)); + } else { + /* + * If previous message is Tx, make sure that Tx FIFO is empty + * before starting a new transfer as the repeated start in + * standard mode can corrupt the transaction if there are + * still bytes to be transmitted in FIFO + */ + if (i2c->prev_msg_tx) { + int status; + + status = xiic_wait_tx_empty(i2c); + if (status) + return; + } + /* Check if RSTA should be set */ + cr = xiic_getreg8(i2c, XIIC_CR_REG_OFFSET); + if (cr & XIIC_CR_MSMS_MASK) { + /* Already a master, RSTA should be set */ + xiic_setreg8(i2c, XIIC_CR_REG_OFFSET, (cr | + XIIC_CR_REPEATED_START_MASK | + XIIC_CR_DIR_IS_TX_MASK) & + ~(XIIC_CR_NO_ACK_MASK)); + } + + /* Write address to FIFO */ + data = i2c_8bit_addr_from_msg(msg); xiic_setreg16(i2c, XIIC_DTR_REG_OFFSET, data); - } + /* Fill fifo */ + xiic_std_fill_tx_fifo(i2c); - xiic_fill_tx_fifo(i2c); + if ((cr & XIIC_CR_MSMS_MASK) == 0) { - /* Clear any pending Tx empty, Tx Error and then enable them. */ - xiic_irq_clr_en(i2c, XIIC_INTR_TX_EMPTY_MASK | XIIC_INTR_TX_ERROR_MASK | - XIIC_INTR_BNB_MASK); + /* Start Tx by writing to CR */ + cr = xiic_getreg8(i2c, XIIC_CR_REG_OFFSET); + xiic_setreg8(i2c, XIIC_CR_REG_OFFSET, cr | + XIIC_CR_MSMS_MASK | + XIIC_CR_DIR_IS_TX_MASK); + } + + /* Clear any pending Tx empty, Tx Error and then enable them */ + xiic_irq_clr_en(i2c, XIIC_INTR_TX_EMPTY_MASK | + XIIC_INTR_TX_ERROR_MASK | + XIIC_INTR_BNB_MASK); + } + i2c->prev_msg_tx = true; } static irqreturn_t xiic_isr(int irq, void *dev_id) @@ -703,7 +964,7 @@ static int xiic_start_xfer(struct xiic_i2c *i2c) static int xiic_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num) { struct xiic_i2c *i2c = i2c_get_adapdata(adap); - int err; + int err, count; dev_dbg(adap->dev.parent, "%s entry SR: 0x%x\n", __func__, xiic_getreg8(i2c, XIIC_SR_REG_OFFSET)); @@ -719,6 +980,21 @@ static int xiic_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num) i2c->tx_msg = msgs; i2c->nmsgs = num; + /* Decide standard mode or Dynamic mode */ + i2c->dynamic = true; + + /* Initialize prev message type */ + i2c->prev_msg_tx = false; + + /* Enter standard mode only when read length is > 255 bytes */ + for (count = 0; count < i2c->nmsgs; count++) { + if ((i2c->tx_msg[count].flags & I2C_M_RD) && + i2c->tx_msg[count].len > MAX_READ_LENGTH_DYNAMIC) { + i2c->dynamic = false; + break; + } + } + err = xiic_start_xfer(i2c); if (err < 0) { dev_err(adap->dev.parent, "Error xiic_start_xfer\n"); @@ -752,16 +1028,11 @@ static const struct i2c_algorithm xiic_algorithm = { .functionality = xiic_func, }; -static const struct i2c_adapter_quirks xiic_quirks = { - .max_read_len = 255, -}; - static const struct i2c_adapter xiic_adapter = { .owner = THIS_MODULE, .name = DRIVER_NAME, .class = I2C_CLASS_DEPRECATED, .algo = &xiic_algorithm, - .quirks = &xiic_quirks, }; From patchwork Mon May 31 13:19:41 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raviteja Narayanam X-Patchwork-Id: 450620 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-13.9 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,UNWANTED_LANGUAGE_BODY, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5AB95C47080 for ; Mon, 31 May 2021 13:23:01 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 33AE861421 for ; Mon, 31 May 2021 13:23:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232111AbhEaNYf (ORCPT ); Mon, 31 May 2021 09:24:35 -0400 Received: from mail-mw2nam10on2061.outbound.protection.outlook.com ([40.107.94.61]:56449 "EHLO NAM10-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231936AbhEaNWi (ORCPT ); Mon, 31 May 2021 09:22:38 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=dKK+Jl0txPi8qItH6O3tcjhicbt+exx1L94bscoTXuegjKquQB9aKLN/byYVaGKNrzSTgFiHbMZ3gqFDXyrJWrMQ+7Ayexc8z16J0QZgRbIUpdbgN1SrWN+pgOGqGBRCOsKka9ooOQxuPISiwOsJvxczbv9ogEUCo8z3i092YvACmGy75voLX4k/QXRCFX7pA4H4oWvH6cJcDp6pcj2VckxFPiS1j+hgclZRgVqEVFH0nPmerZ2aS7IjMn+uHM2Yq8cSg+D6GLDwA9U2ZaTsZvR4t144y+PpBvQZ5yTYGw80UMdg+p7PmpZP/Dk45TAFD62ViGnHLOno+1Fnp/NkcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=373GpPjz4g+kjhHnXEviX5o+TUs9c11/a2JtL2KfzAo=; b=IdkOo/3CySOiS6+/rgvZEXPYPZYPtvvgjjen+mIwORaH0rl/j5OANr/e9CroIZcNAIAN65AyYferaY0qYSSuDzf9pvXJcPmcLvWvbO7RDUqfXuoJGCsLX/vdSrKEqvpRelPQxOZkjcL7elaoiP49fUEPvqkAZnZhP2UABP6YWpAgSfIDjBA+hL05uFSHBQUYOTqHDl4jI1iGDjt18yuHG4pXUpFcW5CVoD/KJ6Ik6ub6gL0t2Mf2WoU1ZaUdFV3LSH5tYVPcv/67Qo1qQykg/lC7fqF7z6duIUveWD6tozVzPxiX2vaWJ/r5kqEUqIykQcsFqQB8LbpTlnYR7IH6fQ== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.62.198) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=xilinx.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=xilinx.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=373GpPjz4g+kjhHnXEviX5o+TUs9c11/a2JtL2KfzAo=; b=DD/rZaG2rrEmHSVUPyL0Jbf3J22qE3V9NLLh624waKAx80h6RFrD5y7mUtsNMVJddwWZDMp51XgS+oozpM3F7tjShASmOyQsqxhEGsqFNun5vOmgII7piVJDtfds7q1wvQzbyxKIR+dMdTpIDg0Hlhy+rL+nI0j3p5C04PNzWhg= Received: from SN6PR2101CA0012.namprd21.prod.outlook.com (2603:10b6:805:106::22) by BN6PR02MB2660.namprd02.prod.outlook.com (2603:10b6:404:fd::17) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4173.24; Mon, 31 May 2021 13:20:54 +0000 Received: from SN1NAM02FT0060.eop-nam02.prod.protection.outlook.com (2603:10b6:805:106:cafe::10) by SN6PR2101CA0012.outlook.office365.com (2603:10b6:805:106::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4219.3 via Frontend Transport; Mon, 31 May 2021 13:20:54 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.62.198) smtp.mailfrom=xilinx.com; vger.kernel.org; dkim=none (message not signed) header.d=none; vger.kernel.org; dmarc=pass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.62.198 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.62.198; helo=xsj-pvapexch02.xlnx.xilinx.com; Received: from xsj-pvapexch02.xlnx.xilinx.com (149.199.62.198) by SN1NAM02FT0060.mail.protection.outlook.com (10.97.4.134) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4150.30 via Frontend Transport; Mon, 31 May 2021 13:20:53 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Mon, 31 May 2021 06:20:37 -0700 Received: from smtp.xilinx.com (172.19.127.95) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server id 15.1.2176.2 via Frontend Transport; Mon, 31 May 2021 06:20:37 -0700 Envelope-to: git@xilinx.com, linux-i2c@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, marex@denx.de Received: from [10.140.6.25] (port=53014 helo=xhdnagasure40.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1lnhqN-0004GE-C6; Mon, 31 May 2021 06:20:35 -0700 From: Raviteja Narayanam To: , CC: , , , , Raviteja Narayanam Subject: [PATCH 03/10] i2c: xiic: Fix coding style issues Date: Mon, 31 May 2021 07:19:41 -0600 Message-ID: <20210531131948.19477-4-raviteja.narayanam@xilinx.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210531131948.19477-1-raviteja.narayanam@xilinx.com> References: <20210531131948.19477-1-raviteja.narayanam@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3a7227ed-ec0a-480d-cd18-08d92436eb0d X-MS-TrafficTypeDiagnostic: BN6PR02MB2660: X-Microsoft-Antispam-PRVS: X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-MS-Oob-TLC-OOBClassifiers: OLM:133; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: V1XjK7SsJX1edCaSwYHGoWLk9aG+B1l/DQ7kxjmPyRFTwzU3O+zSFZglFeI2MsuguK5UoZ1UE4iipUiD4qNxjM5cswqXzCfWu3oyDDCqg6PyJFfOb/kYEv94JYiUmwsXTNgr15bixx5rL0txZFUbzhgUzwavV4rL/R+dEKJ3fFrqjRWw0+bfbsyZ0F9eGWjiGuKDwXhbaDRMTJB5O6uoyqyhT47iGljrRgiRmu5ncAL9QhZ6dt/xXh03tfTeGj5lF3FiLVLH6gQhcRoXZIcRO0e0Bm0NHQqymW1J5odE1MCyxsVZ9ljUNsgBFmlEeYVbRMm0jqcO1v782+Se4iYhJd0afYmY/0aV97eyIf6iAf9B7tLVxSssdE3NY3jj0eRE/7DLUJd/uP/Ip2YnYAkjgkszS9lnixB1PviEs4L4mEpEbpGMbuTWibIflbpKr6W12XbZ4x3QDqPYXxZUzKTRRoR5hDSh/HNV9LItYdmYHMp92e83v/YGBbWfkx0UmhuzXFJ7jIg5kzze99yGQEianZsdkJwW0TZQ7ln76ZNYkNKpfRuFfxXpF3EKdND/3dHb/rXbyC1jmj58OJYpqfe6WcpQRLI/zIbqsBnkFN6m5oNkgQLUttozs8GuaeSNunThLbcxekoVpJfC6ULgbK1EjnH1ZpXnvqrsslV+ONs7cmx6cEBygddNN5iCQA1JLxvY X-Forefront-Antispam-Report: CIP:149.199.62.198; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:xsj-pvapexch02.xlnx.xilinx.com; PTR:unknown-62-198.xilinx.com; CAT:NONE; SFS:(4636009)(39860400002)(376002)(396003)(136003)(346002)(36840700001)(46966006)(4326008)(186003)(44832011)(1076003)(6636002)(2906002)(47076005)(36756003)(478600001)(82310400003)(36860700001)(5660300002)(107886003)(2616005)(426003)(336012)(83380400001)(7696005)(110136005)(356005)(316002)(7636003)(9786002)(26005)(70206006)(8676002)(8936002)(82740400003)(70586007)(6666004)(54906003)(102446001); DIR:OUT; SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 May 2021 13:20:53.9220 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3a7227ed-ec0a-480d-cd18-08d92436eb0d X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c; Ip=[149.199.62.198]; Helo=[xsj-pvapexch02.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-AuthSource: SN1NAM02FT0060.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN6PR02MB2660 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org From: Michal Simek Most of these stuff are reported by checkpatch. But fixes are: - Incorrect indetation - Missing blank line after variable declaration - Additional () - Missing spaces around + - Else after if with return - Missing parenthesis when if has them - Newlines - Remove MODULE_ALIAS - none is really using it - Changing msleep to usleep_range - Other trivial fixes Signed-off-by: Michal Simek Signed-off-by: Raviteja Narayanam --- drivers/i2c/busses/i2c-xiic.c | 69 +++++++++++++++++------------------ 1 file changed, 34 insertions(+), 35 deletions(-) diff --git a/drivers/i2c/busses/i2c-xiic.c b/drivers/i2c/busses/i2c-xiic.c index 004103267e9c..fa2eef9e622f 100644 --- a/drivers/i2c/busses/i2c-xiic.c +++ b/drivers/i2c/busses/i2c-xiic.c @@ -69,7 +69,7 @@ struct xiic_i2c { wait_queue_head_t wait; struct i2c_adapter adap; struct i2c_msg *tx_msg; - struct mutex lock; + struct mutex lock; /* Locking between isr and new xfer */ unsigned int tx_pos; unsigned int nmsgs; struct i2c_msg *rx_msg; @@ -82,24 +82,23 @@ struct xiic_i2c { bool prev_msg_tx; }; - #define XIIC_MSB_OFFSET 0 -#define XIIC_REG_OFFSET (0x100+XIIC_MSB_OFFSET) +#define XIIC_REG_OFFSET (0x100 + XIIC_MSB_OFFSET) /* * Register offsets in bytes from RegisterBase. Three is added to the * base offset to access LSB (IBM style) of the word */ -#define XIIC_CR_REG_OFFSET (0x00+XIIC_REG_OFFSET) /* Control Register */ -#define XIIC_SR_REG_OFFSET (0x04+XIIC_REG_OFFSET) /* Status Register */ -#define XIIC_DTR_REG_OFFSET (0x08+XIIC_REG_OFFSET) /* Data Tx Register */ -#define XIIC_DRR_REG_OFFSET (0x0C+XIIC_REG_OFFSET) /* Data Rx Register */ -#define XIIC_ADR_REG_OFFSET (0x10+XIIC_REG_OFFSET) /* Address Register */ -#define XIIC_TFO_REG_OFFSET (0x14+XIIC_REG_OFFSET) /* Tx FIFO Occupancy */ -#define XIIC_RFO_REG_OFFSET (0x18+XIIC_REG_OFFSET) /* Rx FIFO Occupancy */ -#define XIIC_TBA_REG_OFFSET (0x1C+XIIC_REG_OFFSET) /* 10 Bit Address reg */ -#define XIIC_RFD_REG_OFFSET (0x20+XIIC_REG_OFFSET) /* Rx FIFO Depth reg */ -#define XIIC_GPO_REG_OFFSET (0x24+XIIC_REG_OFFSET) /* Output Register */ +#define XIIC_CR_REG_OFFSET (0x00 + XIIC_REG_OFFSET) /* Control Register */ +#define XIIC_SR_REG_OFFSET (0x04 + XIIC_REG_OFFSET) /* Status Register */ +#define XIIC_DTR_REG_OFFSET (0x08 + XIIC_REG_OFFSET) /* Data Tx Register */ +#define XIIC_DRR_REG_OFFSET (0x0C + XIIC_REG_OFFSET) /* Data Rx Register */ +#define XIIC_ADR_REG_OFFSET (0x10 + XIIC_REG_OFFSET) /* Address Register */ +#define XIIC_TFO_REG_OFFSET (0x14 + XIIC_REG_OFFSET) /* Tx FIFO Occupancy */ +#define XIIC_RFO_REG_OFFSET (0x18 + XIIC_REG_OFFSET) /* Rx FIFO Occupancy */ +#define XIIC_TBA_REG_OFFSET (0x1C + XIIC_REG_OFFSET) /* 10 Bit Address reg */ +#define XIIC_RFD_REG_OFFSET (0x20 + XIIC_REG_OFFSET) /* Rx FIFO Depth reg */ +#define XIIC_GPO_REG_OFFSET (0x24 + XIIC_REG_OFFSET) /* Output Register */ /* Control Register masks */ #define XIIC_CR_ENABLE_DEVICE_MASK 0x01 /* Device enable = 1 */ @@ -237,18 +236,21 @@ static inline int xiic_getreg32(struct xiic_i2c *i2c, int reg) static inline void xiic_irq_dis(struct xiic_i2c *i2c, u32 mask) { u32 ier = xiic_getreg32(i2c, XIIC_IIER_OFFSET); + xiic_setreg32(i2c, XIIC_IIER_OFFSET, ier & ~mask); } static inline void xiic_irq_en(struct xiic_i2c *i2c, u32 mask) { u32 ier = xiic_getreg32(i2c, XIIC_IIER_OFFSET); + xiic_setreg32(i2c, XIIC_IIER_OFFSET, ier | mask); } static inline void xiic_irq_clr(struct xiic_i2c *i2c, u32 mask) { u32 isr = xiic_getreg32(i2c, XIIC_IISR_OFFSET); + xiic_setreg32(i2c, XIIC_IISR_OFFSET, isr & mask); } @@ -418,7 +420,8 @@ static void xiic_fill_tx_fifo(struct xiic_i2c *i2c) while (len--) { u16 data = i2c->tx_msg->buf[i2c->tx_pos++]; - if ((xiic_tx_space(i2c) == 0) && (i2c->nmsgs == 1)) { + + if (!xiic_tx_space(i2c) && i2c->nmsgs == 1) { /* last message in transfer -> STOP */ data |= XIIC_TX_DYN_STOP_MASK; dev_dbg(i2c->adap.dev.parent, "%s TX STOP\n", __func__); @@ -519,8 +522,8 @@ static irqreturn_t xiic_process(int irq, void *dev_id) /* Service requesting interrupt */ if ((pend & XIIC_INTR_ARB_LOST_MASK) || - ((pend & XIIC_INTR_TX_ERROR_MASK) && - !(pend & XIIC_INTR_RX_FULL_MASK))) { + ((pend & XIIC_INTR_TX_ERROR_MASK) && + !(pend & XIIC_INTR_RX_FULL_MASK))) { /* bus arbritration lost, or... * Transmit error _OR_ RX completed * if this happens when RX_FULL is not set @@ -662,9 +665,8 @@ static int xiic_busy(struct xiic_i2c *i2c) * should ignore it, since bus will never be released and i2c will be * stuck forever. */ - if (i2c->singlemaster) { + 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 @@ -672,7 +674,7 @@ static int xiic_busy(struct xiic_i2c *i2c) */ err = xiic_bus_busy(i2c); while (err && tries--) { - msleep(1); + usleep_range(1000, 2000); err = xiic_bus_busy(i2c); } @@ -867,7 +869,6 @@ static void xiic_start_send(struct xiic_i2c *i2c) xiic_std_fill_tx_fifo(i2c); if ((cr & XIIC_CR_MSMS_MASK) == 0) { - /* Start Tx by writing to CR */ cr = xiic_getreg8(i2c, XIIC_CR_REG_OFFSET); xiic_setreg8(i2c, XIIC_CR_REG_OFFSET, cr | @@ -891,9 +892,6 @@ static irqreturn_t xiic_isr(int irq, void *dev_id) /* Do not processes a devices interrupts if the device has no * interrupts pending */ - - dev_dbg(i2c->adap.dev.parent, "%s entry\n", __func__); - isr = xiic_getreg32(i2c, XIIC_IISR_OFFSET); ier = xiic_getreg32(i2c, XIIC_IIER_OFFSET); pend = isr & ier; @@ -907,6 +905,7 @@ static void __xiic_start_xfer(struct xiic_i2c *i2c) { int first = 1; int fifo_space = xiic_tx_fifo_space(i2c); + dev_dbg(i2c->adap.dev.parent, "%s entry, msg: %p, fifos space: %d\n", __func__, i2c->tx_msg, fifo_space); @@ -921,19 +920,20 @@ static void __xiic_start_xfer(struct xiic_i2c *i2c) i2c->nmsgs--; i2c->tx_msg++; i2c->tx_pos = 0; - } else + } else { first = 0; + } if (i2c->tx_msg->flags & I2C_M_RD) { /* we dont date putting several reads in the FIFO */ xiic_start_recv(i2c); return; - } else { - xiic_start_send(i2c); - if (xiic_tx_space(i2c) != 0) { - /* the message could not be completely sent */ - break; - } + } + + xiic_start_send(i2c); + if (xiic_tx_space(i2c) != 0) { + /* the message could not be completely sent */ + break; } fifo_space = xiic_tx_fifo_space(i2c); @@ -944,12 +944,12 @@ static void __xiic_start_xfer(struct xiic_i2c *i2c) */ if (i2c->nmsgs > 1 || xiic_tx_space(i2c)) xiic_irq_clr_en(i2c, XIIC_INTR_TX_HALF_MASK); - } static int xiic_start_xfer(struct xiic_i2c *i2c) { int ret; + mutex_lock(&i2c->lock); ret = xiic_reinit(i2c); @@ -1001,8 +1001,8 @@ static int xiic_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num) goto out; } - if (wait_event_timeout(i2c->wait, (i2c->state == STATE_ERROR) || - (i2c->state == STATE_DONE), HZ)) { + if (wait_event_timeout(i2c->wait, i2c->state == STATE_ERROR || + i2c->state == STATE_DONE, HZ)) { err = (i2c->state == STATE_DONE) ? num : -EIO; goto out; } else { @@ -1035,7 +1035,6 @@ static const struct i2c_adapter xiic_adapter = { .algo = &xiic_algorithm, }; - static int xiic_i2c_probe(struct platform_device *pdev) { struct xiic_i2c *i2c; @@ -1195,6 +1194,7 @@ static const struct dev_pm_ops xiic_dev_pm_ops = { SET_RUNTIME_PM_OPS(xiic_i2c_runtime_suspend, xiic_i2c_runtime_resume, NULL) }; + static struct platform_driver xiic_i2c_driver = { .probe = xiic_i2c_probe, .remove = xiic_i2c_remove, @@ -1210,4 +1210,3 @@ module_platform_driver(xiic_i2c_driver); MODULE_AUTHOR("info@mocean-labs.com"); MODULE_DESCRIPTION("Xilinx I2C bus driver"); MODULE_LICENSE("GPL v2"); -MODULE_ALIAS("platform:"DRIVER_NAME); From patchwork Mon May 31 13:19:42 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raviteja Narayanam X-Patchwork-Id: 450619 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 53803C47082 for ; Mon, 31 May 2021 13:23:21 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 373F361423 for ; Mon, 31 May 2021 13:23:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231760AbhEaNY7 (ORCPT ); Mon, 31 May 2021 09:24:59 -0400 Received: from mail-bn8nam12on2088.outbound.protection.outlook.com ([40.107.237.88]:47584 "EHLO NAM12-BN8-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231975AbhEaNW5 (ORCPT ); Mon, 31 May 2021 09:22:57 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Ko4BbthXis4HWXsTW2mvkWFZGoQBp0P2aAseMPfEXTHcdvr/eheGxKD7emD5RjBHZ8T9gQEtm4aNLw/U4ge9jXivEu+p/7znFNhZQ2NuxuG+8XqatWTa0ZgGnOlFZcv+27gAPbEMuHVZ99gu8kAv2ZdPA5IZarzKz6wNkC3S8B5zWhiCy7dRtDMGNjyCcw7AGOwUuQY9Zd320xA37RBGzHVIP/N8WOWAfoLHriRECqMpbzgJSy5gWcx6WdQuEueWL7nCfB/Uw6wgwguofsL5XpmCDa2IsK+/BfFNTAMCggQ0KJ0rHJJZLjqGTBErjBJe4vDgtcDDVgIslg0cXf0AjA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=iumiq/0C8WuU8ugMFid/jCCxE70N8/gFak5ZMoT9yNM=; b=nBbapYqiYohd3LXh020cxPftfMSkjyVX8DOBWjxkPsB2eEcwi7/nJ1xkZsYcPedZpGTNZgJmexI8TltgvfDSiU+VxjLZPqO7iqndu3MBNDEyi4Y5VlLoVZHRszA+ZR+oQ+63/WRx4Wc1R2E+TNpxA8HzGHM0UIvDSfidhazg+uUlRuKFixY0tONEAVWrJ6jrscUSOCi60vcHcssqjH0ZLm80Zw4MvxXgr+aGichxDx2Q3ufZo+JphBGV15ON/UFe/x8D27TfcMsdOw+OWPgTOHEJ6n+N6UT/mtB+b3gdtmbLnQWG17cQpjPY4sRpvOZaAhO6H5RHRLGIwj6VX/R/rg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.62.198) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=xilinx.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=xilinx.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=iumiq/0C8WuU8ugMFid/jCCxE70N8/gFak5ZMoT9yNM=; b=K6FI9Qxg3o/x9CjJfCjlcz6Ms+VxsMyHctqAkWnwyhqWDM6ywulVEvtcMtyRDcHOUwEL+ys526YaMXgSLZOtxTKlFDYYorVN6z5r9K+6q61FLkW5UctNLaZhQCmgVs1Y5dZZYstHPcXtCkBlEkYN+LJNJrmshUCKfrUBr9pU1G4= Received: from SN2PR01CA0067.prod.exchangelabs.com (2603:10b6:800::35) by BN8PR02MB5730.namprd02.prod.outlook.com (2603:10b6:408:ae::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4173.21; Mon, 31 May 2021 13:21:16 +0000 Received: from SN1NAM02FT0013.eop-nam02.prod.protection.outlook.com (2603:10b6:800:0:cafe::91) by SN2PR01CA0067.outlook.office365.com (2603:10b6:800::35) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4173.21 via Frontend Transport; Mon, 31 May 2021 13:21:15 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.62.198) smtp.mailfrom=xilinx.com; vger.kernel.org; dkim=none (message not signed) header.d=none; vger.kernel.org; dmarc=pass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.62.198 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.62.198; helo=xsj-pvapexch01.xlnx.xilinx.com; Received: from xsj-pvapexch01.xlnx.xilinx.com (149.199.62.198) by SN1NAM02FT0013.mail.protection.outlook.com (10.97.4.188) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4150.30 via Frontend Transport; Mon, 31 May 2021 13:21:15 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) by xsj-pvapexch01.xlnx.xilinx.com (172.19.86.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Mon, 31 May 2021 06:20:42 -0700 Received: from smtp.xilinx.com (172.19.127.95) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server id 15.1.2176.2 via Frontend Transport; Mon, 31 May 2021 06:20:42 -0700 Envelope-to: git@xilinx.com, linux-i2c@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, marex@denx.de Received: from [10.140.6.25] (port=53014 helo=xhdnagasure40.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1lnhqS-0004GE-MU; Mon, 31 May 2021 06:20:41 -0700 From: Raviteja Narayanam To: , CC: , , , , Raviteja Narayanam Subject: [PATCH 04/10] i2c: xiic: Add smbus_block_read functionality Date: Mon, 31 May 2021 07:19:42 -0600 Message-ID: <20210531131948.19477-5-raviteja.narayanam@xilinx.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210531131948.19477-1-raviteja.narayanam@xilinx.com> References: <20210531131948.19477-1-raviteja.narayanam@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: a7d5f4b0-0d31-4f2e-a3cd-08d92436f7e7 X-MS-TrafficTypeDiagnostic: BN8PR02MB5730: X-Microsoft-Antispam-PRVS: X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-MS-Oob-TLC-OOBClassifiers: OLM:8273; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: ZG8lS9U15VKQOyn8HcOouHdDg0LQE51APXRUGz7vy3toitYSKELMsUNBvE/9AIWFJpBKos2CjbJvf9rtBHWkMfxwGkVaunDU4k/g9lBLGIkCWJwwgN1q5Uta75NjzqMd2uX/hiGVsIGdd+LektqWafEwzi1KTNLpZt27aKJ7t0pDA9RSZ5tm08KP21g+ehqhOo09soC6+/E+QYyxqUJKTpNvyJRQ6Rv+Y5yVgMdbXlv0EUKOjHvTgPWprDzUYiyzqwEMAEY6uTQYSAKuZ41qbkdcUca++QJN/JsRqciNxjKFdKkDR5fLi4Jag4JkUljX1L+9C12w7YvbMS8lQrAjZFEm+BAi6N7k5qMwdvBiFAwMTJ4dP5631yA5WEBQEErwS6T0gJ0ExBR/1VG5r/oH/4ajmPafJPJTtfWR2jr22jg72Pea/NXkcz+2cr2pf8hDWnoWeSM9WHhHGtNTCkBVEHXHQDH0m8YSQTQ3dS67kqsCMLkD0u5jrQg5/IOOfFNEc5P2gHHSkqHRFUbrb23aSnUqFrJZtRgT9ImxluaoDm9ucFtbRZkrHQjPw7HPICtXVBdk+l/D/GqxB43zJX31yM9G5W57D/zaIy1aFFrtyGT4W4StMZAGyWjUfkf8I7QAGLNqt3nXUMp/ucgAL+wK1P1IKB7w3Pv4jNxRTCKhXlzWw6UDEpfXeGESsdrB+I9hyIv8XYEhE2GB1NBlntsg6A== X-Forefront-Antispam-Report: CIP:149.199.62.198; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:xsj-pvapexch01.xlnx.xilinx.com; PTR:unknown-62-198.xilinx.com; CAT:NONE; SFS:(4636009)(396003)(39860400002)(376002)(346002)(136003)(36840700001)(46966006)(7696005)(5660300002)(36860700001)(26005)(426003)(110136005)(186003)(1076003)(2906002)(316002)(8676002)(478600001)(47076005)(8936002)(82310400003)(70206006)(4326008)(6636002)(2616005)(70586007)(43170500006)(82740400003)(7636003)(44832011)(36756003)(83380400001)(356005)(336012)(54906003)(107886003)(9786002)(102446001); DIR:OUT; SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 May 2021 13:21:15.4823 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: a7d5f4b0-0d31-4f2e-a3cd-08d92436f7e7 X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c; Ip=[149.199.62.198]; Helo=[xsj-pvapexch01.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-AuthSource: SN1NAM02FT0013.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN8PR02MB5730 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org smbus_block_read is added to xiic driver to read from few sensors which support this command. Since the number of bytes to read is not known prior to transfer, we are using xiic standard mode for low level control of IP. Signed-off-by: Raviteja Narayanam --- drivers/i2c/busses/i2c-xiic.c | 82 ++++++++++++++++++++++++++++++++--- 1 file changed, 76 insertions(+), 6 deletions(-) diff --git a/drivers/i2c/busses/i2c-xiic.c b/drivers/i2c/busses/i2c-xiic.c index fa2eef9e622f..51b5fd5768db 100644 --- a/drivers/i2c/busses/i2c-xiic.c +++ b/drivers/i2c/busses/i2c-xiic.c @@ -62,6 +62,7 @@ enum xiic_endian { * @singlemaster: Indicates bus is single master * @dynamic: Mode of controller * @prev_msg_tx: Previous message is Tx + * @smbus_block_read: Flag to handle block read */ struct xiic_i2c { struct device *dev; @@ -80,6 +81,7 @@ struct xiic_i2c { bool singlemaster; bool dynamic; bool prev_msg_tx; + bool smbus_block_read; }; #define XIIC_MSB_OFFSET 0 @@ -336,6 +338,54 @@ static void xiic_deinit(struct xiic_i2c *i2c) xiic_setreg8(i2c, XIIC_CR_REG_OFFSET, cr & ~XIIC_CR_ENABLE_DEVICE_MASK); } +static void xiic_smbus_block_read_setup(struct xiic_i2c *i2c) +{ + u8 rxmsg_len; + u8 rfd_set = 0; + + /* + * Clear the I2C_M_RECV_LEN flag to avoid setting + * message length again + */ + i2c->rx_msg->flags &= ~I2C_M_RECV_LEN; + + /* Set smbus_block_read flag to identify in isr */ + i2c->smbus_block_read = true; + + /* Read byte from rx fifo and set message length */ + rxmsg_len = xiic_getreg8(i2c, XIIC_DRR_REG_OFFSET); + + i2c->rx_msg->buf[i2c->rx_pos++] = rxmsg_len; + + /* Check if received length is valid */ + if (rxmsg_len <= I2C_SMBUS_BLOCK_MAX) { + /* Set Receive fifo depth */ + if (rxmsg_len > IIC_RX_FIFO_DEPTH) { + rfd_set = IIC_RX_FIFO_DEPTH - 1; + i2c->rx_msg->len = rxmsg_len + 1; + } else if ((rxmsg_len == 1) || + (rxmsg_len == 0)) { + /* + * Minimum of 3 bytes required to exit cleanly. 1 byte + * already received, Second byte is being received. Have + * to set NACK in read_rx before receiving the last byte + */ + i2c->rx_msg->len = 3; + } else { + rfd_set = rxmsg_len - 2; + i2c->rx_msg->len = rxmsg_len + 1; + } + xiic_setreg8(i2c, XIIC_RFD_REG_OFFSET, rfd_set); + + return; + } + + /* Invalid message length, trigger STATE_ERROR with tx_msg_len in ISR */ + i2c->tx_msg->len = 3; + i2c->smbus_block_read = false; + dev_err(i2c->adap.dev.parent, "smbus_block_read Invalid msg length\n"); +} + static void xiic_read_rx(struct xiic_i2c *i2c) { u8 bytes_in_fifo, cr = 0, bytes_to_read = 0; @@ -358,6 +408,12 @@ static void xiic_read_rx(struct xiic_i2c *i2c) if (!i2c->dynamic) { bytes_rem = xiic_rx_space(i2c) - bytes_in_fifo; + /* Set msg length if smbus_block_read */ + if (i2c->rx_msg->flags & I2C_M_RECV_LEN) { + xiic_smbus_block_read_setup(i2c); + return; + } + if (bytes_rem > IIC_RX_FIFO_DEPTH) { bytes_to_read = bytes_in_fifo; } else if (bytes_rem > 1) { @@ -627,6 +683,12 @@ static irqreturn_t xiic_process(int irq, void *dev_id) /* The bus is not busy, disable BusNotBusy interrupt */ xiic_irq_dis(i2c, XIIC_INTR_BNB_MASK); + if (i2c->tx_msg && i2c->smbus_block_read) { + i2c->smbus_block_read = false; + /* Set requested message len=1 to indicate STATE_DONE */ + i2c->tx_msg->len = 1; + } + if (!i2c->tx_msg) goto out; @@ -755,8 +817,12 @@ static void xiic_start_recv(struct xiic_i2c *i2c) rfd_set = IIC_RX_FIFO_DEPTH - 1; } else if ((rx_watermark == 1) || (rx_watermark == 0)) { rfd_set = rx_watermark - 1; - /* Handle single byte transfer separately */ - cr |= XIIC_CR_NO_ACK_MASK; + + /* Set No_ACK, except for smbus_block_read */ + if (!(i2c->rx_msg->flags & I2C_M_RECV_LEN)) { + /* Handle single byte transfer separately */ + cr |= XIIC_CR_NO_ACK_MASK; + } } else { rfd_set = rx_watermark - 2; } @@ -986,10 +1052,14 @@ static int xiic_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num) /* Initialize prev message type */ i2c->prev_msg_tx = false; - /* Enter standard mode only when read length is > 255 bytes */ + /* + * Enter standard mode only when read length is > 255 bytes or + * for smbus_block_read transaction + */ for (count = 0; count < i2c->nmsgs; count++) { - if ((i2c->tx_msg[count].flags & I2C_M_RD) && - i2c->tx_msg[count].len > MAX_READ_LENGTH_DYNAMIC) { + if (((i2c->tx_msg[count].flags & I2C_M_RD) && + i2c->tx_msg[count].len > MAX_READ_LENGTH_DYNAMIC) || + (i2c->tx_msg[count].flags & I2C_M_RECV_LEN)) { i2c->dynamic = false; break; } @@ -1020,7 +1090,7 @@ static int xiic_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num) static u32 xiic_func(struct i2c_adapter *adap) { - return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL; + return I2C_FUNC_I2C | I2C_FUNC_SMBUS_EMUL | I2C_FUNC_SMBUS_BLOCK_DATA; } static const struct i2c_algorithm xiic_algorithm = { From patchwork Mon May 31 13:19:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raviteja Narayanam X-Patchwork-Id: 450617 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 00D8BC47080 for ; Mon, 31 May 2021 13:23:35 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D2636613B6 for ; Mon, 31 May 2021 13:23:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232251AbhEaNZI (ORCPT ); Mon, 31 May 2021 09:25:08 -0400 Received: from mail-mw2nam08on2052.outbound.protection.outlook.com ([40.107.101.52]:9025 "EHLO NAM04-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S232323AbhEaNXD (ORCPT ); Mon, 31 May 2021 09:23:03 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=MCLjOS6/3YUfFPwISAjxcewjZ18mOkO0YvDVASpTGTM+KFL9qWoo6HX1ICOHHDUhyLGmJAgYDON25Ahq3RT1XQod/LBPxyTurWmCTh9P3XaUQzChN9IxFOg4pqA4skla76kKwZQwOvGxsDxhkEBYMA7FDYbeBFiO+sA2j4KJ3aZ0/PO3xIZN4Oysx1G5wFOaBStArMvkUVLiaSa4cRWMjBuc8wCkb6yRbjQ1mwaV4PbvlhDTwq7IuWuqzFZi+j8diOf3hDiO3V5ygzWqWNygR51Ji5oH0IoGVpcf5P4/puZOWlEFRtLB/d7QFMeJhNq9kC0CsEX7qUH24IDMhSDkuw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=olQ1kIRSGkHH5KiXTQs67sKPfMcfsrDpvuJOb37YkVI=; b=N9h8Z4DeAqpc05joslNh/D622yboy+nU851fCOgncGyW7LFkBpGpZ93YgqT47f6g3HHeRYsdv0HzJ24uvUolsygIRkgqO/MBmkC5lXYe/z36Qe9jbZSBhntqEVXgbY7+6YHoCT957UNtfxLYf42Gr0caZlBOXD320t4rN/R9Fb5lh/KT73Ah5ID08daD8Ln+H+mrlVswa2ICzZfcU0r15uxjtmt+DueL3O+EkTYjtCqpEWWj3Qhx91a6sKW9+kIybWOniw8RbodZQqKpes2rqLLFhW+kkWoEEnunsynHGF7o/e60/tkKw3Twj8d7svICVCko2LNGCseWUX0xeEP/iw== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.62.198) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=xilinx.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=xilinx.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=olQ1kIRSGkHH5KiXTQs67sKPfMcfsrDpvuJOb37YkVI=; b=eRX1TydGLle8PpDGExHFDLUKDallDxJa3qVU+FG8uIvZoZjPWhQcfMr+/mTIRIelBtuoepC3eHxIOdLbf2FZpOptgFbk7ukSfcwwhJyAqxVjHvhjGXs4U5h96Goo4UHaIXDSxVO7tS+NIXx3ciCBwFINelBsizx/3wDLQBvvSb8= Received: from SN6PR04CA0099.namprd04.prod.outlook.com (2603:10b6:805:f2::40) by SA2PR02MB7836.namprd02.prod.outlook.com (2603:10b6:806:140::10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4173.24; Mon, 31 May 2021 13:21:20 +0000 Received: from SN1NAM02FT0018.eop-nam02.prod.protection.outlook.com (2603:10b6:805:f2::4) by SN6PR04CA0099.outlook.office365.com (2603:10b6:805:f2::40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4173.20 via Frontend Transport; Mon, 31 May 2021 13:21:20 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.62.198) smtp.mailfrom=xilinx.com; vger.kernel.org; dkim=none (message not signed) header.d=none; vger.kernel.org; dmarc=pass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.62.198 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.62.198; helo=xsj-pvapexch01.xlnx.xilinx.com; Received: from xsj-pvapexch01.xlnx.xilinx.com (149.199.62.198) by SN1NAM02FT0018.mail.protection.outlook.com (10.97.5.8) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4150.30 via Frontend Transport; Mon, 31 May 2021 13:21:20 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) by xsj-pvapexch01.xlnx.xilinx.com (172.19.86.40) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Mon, 31 May 2021 06:20:50 -0700 Received: from smtp.xilinx.com (172.19.127.95) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server id 15.1.2176.2 via Frontend Transport; Mon, 31 May 2021 06:20:50 -0700 Envelope-to: git@xilinx.com, linux-i2c@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, marex@denx.de Received: from [10.140.6.25] (port=53014 helo=xhdnagasure40.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1lnhqb-0004GE-Me; Mon, 31 May 2021 06:20:50 -0700 From: Raviteja Narayanam To: , CC: , , , , Shubhrajyoti Datta , Raviteja Narayanam Subject: [PATCH 06/10] i2c: xiic: Fix the type check for xiic_wakeup Date: Mon, 31 May 2021 07:19:44 -0600 Message-ID: <20210531131948.19477-7-raviteja.narayanam@xilinx.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210531131948.19477-1-raviteja.narayanam@xilinx.com> References: <20210531131948.19477-1-raviteja.narayanam@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 3651d3a2-b365-4d4f-b4bf-08d92436fb0c X-MS-TrafficTypeDiagnostic: SA2PR02MB7836: X-Microsoft-Antispam-PRVS: X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-MS-Oob-TLC-OOBClassifiers: OLM:4125; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: i3oNDlnIPX7v64pkvEwZxYLaIUTjMo/4qWJhYev0ge5OhdVPVjszTkkf5GPdZqpGZ1E3MmSwFImxKoV/WescTjX/327laPOldKZHTDEEr1Up72p3m7/CXM5/Z0Hr427FX7PdR1I8BDTgypbh/1ZjljwhiPQGTvx4J4IiYnnGvg2S9XzkUCISPbIsVW5rAhhL6NAn44y7oUZRf036Ky6FtXJSdcIGynTyxBC9VZrCcvTFI/ANybzEPFhWixBAoC/+mIkjN5OCZfcE4QFV5ofsy/wu8dpUK5CsHQyZGo5pd7rcPGOyhVgabR3ydHpPYj+57WyjCH42VZ9T15k0xviffNaEatHazgMhe2uxMnOFVw+Q0P02pra7kJx7ICOXQdVEGgS+Vh7tprkB4Rwm0hs/xevNs2L8To9UxI/SYjUPcJyHHgW/p5SCH8o1bzFf5FP4fob1ulmTuNg5hMMdFWP1Eazu1ngE3WByyonTfOMMLWVB3EZZHC8H1wsJsCH6TycEf6VjtCFM7RP2h/9hVY+tcs2aZ0RJOTlGXBwh97ttzBuP3vGD8h7YzP9S0ooDtaEOQ4s20NB4u1cjMnlEm4GN5yOLvjfKskz54n1u9dQdA5TM6AJoUJeGb01U8N2dOQHGKTXB5+TijxWTJqlda91QdQxn7DK5nVKUAbWhcUZ2GsNYO/iNq2wahOm+ZBKfcReK X-Forefront-Antispam-Report: CIP:149.199.62.198; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:xsj-pvapexch01.xlnx.xilinx.com; PTR:unknown-62-198.xilinx.com; CAT:NONE; SFS:(4636009)(39860400002)(376002)(396003)(346002)(136003)(36840700001)(46966006)(6636002)(336012)(1076003)(316002)(36906005)(478600001)(110136005)(82740400003)(2906002)(54906003)(426003)(47076005)(4326008)(36860700001)(7696005)(186003)(107886003)(7636003)(36756003)(5660300002)(82310400003)(44832011)(83380400001)(2616005)(26005)(356005)(8936002)(70586007)(8676002)(70206006)(6666004)(9786002)(4744005)(102446001); DIR:OUT; SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 May 2021 13:21:20.7584 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 3651d3a2-b365-4d4f-b4bf-08d92436fb0c X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c; Ip=[149.199.62.198]; Helo=[xsj-pvapexch01.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-AuthSource: SN1NAM02FT0018.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SA2PR02MB7836 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org From: Shubhrajyoti Datta Fix the coverity warning mixed_enum_type: enumerated type mixed with another type We are passing an enum in the xiic_wakeup lets change the function parameters to reflect that. Signed-off-by: Shubhrajyoti Datta Signed-off-by: Raviteja Narayanam --- drivers/i2c/busses/i2c-xiic.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/i2c/busses/i2c-xiic.c b/drivers/i2c/busses/i2c-xiic.c index b2ac76d94212..1a26e5ebfc6c 100644 --- a/drivers/i2c/busses/i2c-xiic.c +++ b/drivers/i2c/busses/i2c-xiic.c @@ -542,7 +542,7 @@ static void xiic_send_tx(struct xiic_i2c *i2c) } } -static void xiic_wakeup(struct xiic_i2c *i2c, int code) +static void xiic_wakeup(struct xiic_i2c *i2c, enum xilinx_i2c_state code) { i2c->tx_msg = NULL; i2c->rx_msg = NULL; From patchwork Mon May 31 13:19:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raviteja Narayanam X-Patchwork-Id: 450618 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 32072C47080 for ; Mon, 31 May 2021 13:23:26 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 11985613B4 for ; Mon, 31 May 2021 13:23:26 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232243AbhEaNZD (ORCPT ); Mon, 31 May 2021 09:25:03 -0400 Received: from mail-mw2nam10on2051.outbound.protection.outlook.com ([40.107.94.51]:5409 "EHLO NAM10-MW2-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S232321AbhEaNXC (ORCPT ); Mon, 31 May 2021 09:23:02 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=bqXOoskScU7DL1myMJ/FJDIGDjEnSE3lR73o8ovqLkPtxayAqO54mdwNcO0jOX0ITmYVLWnavPyGlWa2TGYwg85MuI8gm8+YnZ16gEJvdp0wbWDOXFZh93DHgh1Z4bvoorljn8RJxFriAKYRgoN6LJqz2QhjJwyOg0TTD+BocEYG3GHlIM4MoouauA9fnWA+P6cUcHX3MOF3ngGDtkmDgXHp7u/jBUNdGLWRGdIvLaZuoRkwi7CAUyYGw6VXJI1h4Rv7hffEQg/c5WguiQfy2FGWFiClsF5QVsdgyjDSg27d+RL3Ttci4fGJQDkqcjHaNyK+Db++NZjVSAPMqL8l6g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=FwntOM4arWjrrTTBU/PsgkpjojDk5S2QwRFtIJeaNXQ=; b=DeQdG04n2n13rrZNlV4Sru1dGFIVr0rHoBngYEm4r+AwE1H7gZKRft5Usex3ik52SiE/SY9JUXiNJ6y0mRthSBcs6Y7YyOGztzQPA0Hte7jsHWwEz1nX2SIOTASo2eCannrtIFBtUPwIGaT0oULU0BhGeA8dbFi+E/0JCnDWpAAXvlMXRRx8yj4oKCti8/kagYW1ScBIvljSTXtcNNeI5o0v1BoZSwwFBG6j5b9jGvaeTYvanslAPk8zYDP8fTu/nD+7nZq3B1z0WXPDXWEXQH2wvnfIVjtGhQ85+awMz2CjvqUt8UZYQWZPzjQn+KUa/ADW4lxOQdNDdFML8N7ctA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.62.198) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=xilinx.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=xilinx.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=FwntOM4arWjrrTTBU/PsgkpjojDk5S2QwRFtIJeaNXQ=; b=XHIGJ95S5WKgShKxpmb2pmQWWXE+bKvBHl9TIxeZ3TXjpOv5Aa1Jw980q8I4tGsf9VcsRPFc4HKDOJDjjeZs8NkC7jgPR2gV8IPKQ7OFKJdO7C6QtfWKau1EcWowkD/c3TsfkpMaa32oEz7zSBrpK0rr03Y2CmRYoSMZNbOCKqk= Received: from SN6PR2101CA0022.namprd21.prod.outlook.com (2603:10b6:805:106::32) by DM6PR02MB5627.namprd02.prod.outlook.com (2603:10b6:5:36::26) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4173.22; Mon, 31 May 2021 13:21:21 +0000 Received: from SN1NAM02FT0060.eop-nam02.prod.protection.outlook.com (2603:10b6:805:106:cafe::77) by SN6PR2101CA0022.outlook.office365.com (2603:10b6:805:106::32) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4219.3 via Frontend Transport; Mon, 31 May 2021 13:21:20 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.62.198) smtp.mailfrom=xilinx.com; vger.kernel.org; dkim=none (message not signed) header.d=none; vger.kernel.org; dmarc=pass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.62.198 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.62.198; helo=xsj-pvapexch02.xlnx.xilinx.com; Received: from xsj-pvapexch02.xlnx.xilinx.com (149.199.62.198) by SN1NAM02FT0060.mail.protection.outlook.com (10.97.4.134) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4150.30 via Frontend Transport; Mon, 31 May 2021 13:21:20 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Mon, 31 May 2021 06:20:55 -0700 Received: from smtp.xilinx.com (172.19.127.95) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server id 15.1.2176.2 via Frontend Transport; Mon, 31 May 2021 06:20:55 -0700 Envelope-to: git@xilinx.com, linux-i2c@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, marex@denx.de Received: from [10.140.6.25] (port=53014 helo=xhdnagasure40.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1lnhqf-0004GE-Nq; Mon, 31 May 2021 06:20:54 -0700 From: Raviteja Narayanam To: , CC: , , , , Raviteja Narayanam Subject: [PATCH 07/10] i2c: xiic: Switch to Xiic standard mode for i2c-read Date: Mon, 31 May 2021 07:19:45 -0600 Message-ID: <20210531131948.19477-8-raviteja.narayanam@xilinx.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210531131948.19477-1-raviteja.narayanam@xilinx.com> References: <20210531131948.19477-1-raviteja.narayanam@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: db401ed1-4153-43b8-dfe4-08d92436fb18 X-MS-TrafficTypeDiagnostic: DM6PR02MB5627: X-Microsoft-Antispam-PRVS: X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-MS-Oob-TLC-OOBClassifiers: OLM:5236; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: TvjS478+vhI5KVnf0FqTwiHnlS7SOzm7CyPLRg1A6jy6PJQ2hsFUYOWxwGSFDSLWxDPw78X5MGMptzlLMRRR0aC6bJUrwrE28yLzcaIe44BKiQNcuGD6/MlRRJZUwS+w1G4XFDarr3dCotCBoqd8nIa7JRPthepfSOLvniHwKpAXDARE4P9Q9G1NB+txFoba0cAqsVboPxKLLJ4qTtY7ARLV5i4Lt0EglWQFj7OJNf7ma4PI3ay3ctKIen4r3unzObuIe/D7yyrDBAK8I7BfTfXWROPTN8vOi49X0Rxe4UjhlI26zBOihon/SxqtwxumJnhyryqmv+ieaRaiRz6fx9WJgVWxBgK0mOsf2NfvNJvRhMiSy96n0yV7RGQYDZvfQDbmK5HnOPlcQ2nfZMwmpF2ZnFm/m2BQtUMnYowHhI8XE7h44wpDbVohFUvKUuw/jElmvydEn64hoWnQ+fWZ6GRZhUsHMTIbxh/zNNqt4nOJZCEFqOcK0LicWA295xTAQ93Y+ifpkc7+vWjLdaaiI8KAdKRYwmqhl425iJSetLd0PO4nw8nEKxQxVs/Q0sFjV3TIe50lbC4vL40jjXrGdahcGeVL7ILWfloiH6p3s1OCaCYopWoYKxbaupvF79ft1o8d0rx7/fD4p1MxNysR6viEbE0x20RPFNA2KTUuK7ckXzeKKGkyo/ErZlIYtrPd X-Forefront-Antispam-Report: CIP:149.199.62.198; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:xsj-pvapexch02.xlnx.xilinx.com; PTR:unknown-62-198.xilinx.com; CAT:NONE; SFS:(4636009)(376002)(346002)(136003)(39860400002)(396003)(36840700001)(46966006)(478600001)(7636003)(9786002)(83380400001)(4326008)(54906003)(110136005)(36756003)(336012)(356005)(1076003)(2906002)(2616005)(5660300002)(6636002)(36906005)(426003)(44832011)(70206006)(70586007)(6666004)(82310400003)(47076005)(107886003)(7696005)(36860700001)(82740400003)(26005)(316002)(8936002)(186003)(8676002)(102446001); DIR:OUT; SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 May 2021 13:21:20.8381 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: db401ed1-4153-43b8-dfe4-08d92436fb18 X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c; Ip=[149.199.62.198]; Helo=[xsj-pvapexch02.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-AuthSource: SN1NAM02FT0060.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM6PR02MB5627 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org Xilinx I2C IP has two modes of operation, both of which implement I2C transactions. The only difference from sw perspective is the programming sequence for these modes. Dynamic mode -> Simple to program, less number of steps in sequence. Standard mode -> Gives flexibility, more number of steps in sequence. In dynamic mode, during the i2c-read transactions, if there is a delay(> 200us) between the register writes (address & byte count), read transaction fails. On a system with load, this scenario is occurring frequently. To avoid this, switch to standard mode if there is a read request. Added a quirk to identify the IP version effected by this and follow the standard mode. Signed-off-by: Raviteja Narayanam --- drivers/i2c/busses/i2c-xiic.c | 58 +++++++++++++++++++++++++++-------- 1 file changed, 45 insertions(+), 13 deletions(-) diff --git a/drivers/i2c/busses/i2c-xiic.c b/drivers/i2c/busses/i2c-xiic.c index 1a26e5ebfc6c..2f0808249ceb 100644 --- a/drivers/i2c/busses/i2c-xiic.c +++ b/drivers/i2c/busses/i2c-xiic.c @@ -33,6 +33,8 @@ #define DRIVER_NAME "xiic-i2c" +#define DYNAMIC_MODE_READ_BROKEN_BIT BIT(0) + enum xilinx_i2c_state { STATE_DONE, STATE_ERROR, @@ -63,6 +65,7 @@ enum xiic_endian { * @dynamic: Mode of controller * @prev_msg_tx: Previous message is Tx * @smbus_block_read: Flag to handle block read + * @quirks: To hold platform specific bug info */ struct xiic_i2c { struct device *dev; @@ -82,6 +85,11 @@ struct xiic_i2c { bool dynamic; bool prev_msg_tx; bool smbus_block_read; + u32 quirks; +}; + +struct xiic_version_data { + u32 quirks; }; #define XIIC_MSB_OFFSET 0 @@ -1032,6 +1040,7 @@ static int xiic_start_xfer(struct xiic_i2c *i2c) static int xiic_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num) { + bool broken_read, max_read_len, smbus_blk_read; struct xiic_i2c *i2c = i2c_get_adapdata(adap); int err, count; @@ -1056,13 +1065,22 @@ static int xiic_xfer(struct i2c_adapter *adap, struct i2c_msg *msgs, int num) i2c->prev_msg_tx = false; /* - * Enter standard mode only when read length is > 255 bytes or - * for smbus_block_read transaction + * Scan through nmsgs, use dynamic mode when none of the below three + * conditions occur. We need standard mode even if one condition holds + * true in the entire array of messages in a single transfer. + * If read transaction as dynamic mode is broken for delayed reads + * in xlnx,axi-iic-2.0 / xlnx,xps-iic-2.00.a IP versions. + * If read length is > 255 bytes. + * If smbus_block_read transaction. */ for (count = 0; count < i2c->nmsgs; count++) { - if (((i2c->tx_msg[count].flags & I2C_M_RD) && - i2c->tx_msg[count].len > MAX_READ_LENGTH_DYNAMIC) || - (i2c->tx_msg[count].flags & I2C_M_RECV_LEN)) { + broken_read = (i2c->quirks & DYNAMIC_MODE_READ_BROKEN_BIT) && + (i2c->tx_msg[count].flags & I2C_M_RD); + max_read_len = (i2c->tx_msg[count].flags & I2C_M_RD) && + (i2c->tx_msg[count].len > MAX_READ_LENGTH_DYNAMIC); + smbus_blk_read = (i2c->tx_msg[count].flags & I2C_M_RECV_LEN); + + if (broken_read || max_read_len || smbus_blk_read) { i2c->dynamic = false; break; } @@ -1108,10 +1126,23 @@ static const struct i2c_adapter xiic_adapter = { .algo = &xiic_algorithm, }; +static const struct xiic_version_data xiic_2_00 = { + .quirks = DYNAMIC_MODE_READ_BROKEN_BIT, +}; + +#if defined(CONFIG_OF) +static const struct of_device_id xiic_of_match[] = { + { .compatible = "xlnx,xps-iic-2.00.a", .data = &xiic_2_00 }, + {}, +}; +MODULE_DEVICE_TABLE(of, xiic_of_match); +#endif + static int xiic_i2c_probe(struct platform_device *pdev) { struct xiic_i2c *i2c; struct xiic_i2c_platform_data *pdata; + const struct of_device_id *match; struct resource *res; int ret, irq; u8 i; @@ -1121,6 +1152,13 @@ static int xiic_i2c_probe(struct platform_device *pdev) if (!i2c) return -ENOMEM; + match = of_match_node(xiic_of_match, pdev->dev.of_node); + if (match && match->data) { + const struct xiic_version_data *data = match->data; + + i2c->quirks = data->quirks; + } + res = platform_get_resource(pdev, IORESOURCE_MEM, 0); i2c->base = devm_ioremap_resource(&pdev->dev, res); if (IS_ERR(i2c->base)) @@ -1201,6 +1239,8 @@ static int xiic_i2c_probe(struct platform_device *pdev) i2c_new_client_device(&i2c->adap, pdata->devices + i); } + dev_info(&pdev->dev, "mmio %08lx irq %d\n", (unsigned long)res->start, irq); + return 0; err_clk_dis: @@ -1232,14 +1272,6 @@ static int xiic_i2c_remove(struct platform_device *pdev) return 0; } -#if defined(CONFIG_OF) -static const struct of_device_id xiic_of_match[] = { - { .compatible = "xlnx,xps-iic-2.00.a", }, - {}, -}; -MODULE_DEVICE_TABLE(of, xiic_of_match); -#endif - static int __maybe_unused xiic_i2c_runtime_suspend(struct device *dev) { struct xiic_i2c *i2c = dev_get_drvdata(dev); From patchwork Mon May 31 13:19:48 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Raviteja Narayanam X-Patchwork-Id: 450616 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-16.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER, INCLUDES_PATCH, MAILING_LIST_MULTI, SPF_HELO_NONE, SPF_PASS, URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5CD71C47083 for ; Mon, 31 May 2021 13:23:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2BF2C6143B for ; Mon, 31 May 2021 13:23:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232268AbhEaNZ3 (ORCPT ); Mon, 31 May 2021 09:25:29 -0400 Received: from mail-dm6nam11on2047.outbound.protection.outlook.com ([40.107.223.47]:50945 "EHLO NAM11-DM6-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S231863AbhEaNXW (ORCPT ); Mon, 31 May 2021 09:23:22 -0400 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=m/geMpUFZiXO1whXdsjF+N/OwKHs4MwRAFpJh+wKOAX54rz7eQd7sfB/aTEaSyFGTXYhP47RVEotT5gcLbgs54q+nPbftAdPn/lA4j3A+1/juWsaZ1+x54rq7+fFJrpWEUwA56I2Qjok/CXx1mShzT9vgHOG2Kje6j0h6ukaOvSxQKA/UfE/BLHhq70vNa8oEj9gso++vdR5RQsCbzi9+z5/Q1PzoKrN3Kcye/+pG4qhOftRU3YF5WaeKh2tzp3yqu37GwNcsdWTyQI2BUxpQUmVr3sh++lzCE20/8lVP+t19N6QqsMG8VvvLCP1sxCk4qpK9tPta6kzJBS/TWyk8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=fceQhCbbjjHjSbwTjg3JBB4MQnsiiMuBzljwTv3hnx0=; b=ca46etrM12Z91G5U/OBzX1d68oLouZvVl/cSqB+1/rN8NSrfI10Q+tcurOAc0h9Tc23DFMHKTKbCAyHzHqRZpYG9npfWgGRYhk39Kf0K3r6cROAr+SY+AWskEFWKOlaJP4hPDsOuJ8AUqYG8ID5xBAULTs0XuN0vNO+GQmi/D5LKGKRbNy1u9c7p1QqvS0yNmam+mnd4jkqc8iR91FUyoFH0h0HJ1gg8PdS+a/k770t5XPrGpDp2ipRol6N93pPJEGyPfwYIVk7WlgJ76HuSXKldx4y2B9ETRxYBVqQNaTk/yVoM6Bq4vIcmppJARC5h38AhCRTzSUuRGD1tTt6gew== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.62.198) smtp.rcpttodomain=vger.kernel.org smtp.mailfrom=xilinx.com; dmarc=pass (p=none sp=none pct=100) action=none header.from=xilinx.com; dkim=none (message not signed); arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=xilinx.onmicrosoft.com; s=selector2-xilinx-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=fceQhCbbjjHjSbwTjg3JBB4MQnsiiMuBzljwTv3hnx0=; b=qSDECWIoHr9kU1ipLipT9j4dT7+EF62Lfo9m2swsIDEfn0uhdQ19O8RynVCn54fj+LdTEO1hIEW9KF2Bp4TR39TF4VwlMA8ZG+As6RrpksKlxrQpgc3zt8eSmEbZy7W9BzAUKrU0Tuk0bgF/LMsJERx+xpKQp8z0h9DoN0WD7A0= Received: from BN9PR03CA0367.namprd03.prod.outlook.com (2603:10b6:408:f7::12) by BN7PR02MB5123.namprd02.prod.outlook.com (2603:10b6:408:22::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4173.20; Mon, 31 May 2021 13:21:39 +0000 Received: from BN1NAM02FT051.eop-nam02.prod.protection.outlook.com (2603:10b6:408:f7:cafe::b6) by BN9PR03CA0367.outlook.office365.com (2603:10b6:408:f7::12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4173.22 via Frontend Transport; Mon, 31 May 2021 13:21:39 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.62.198) smtp.mailfrom=xilinx.com; vger.kernel.org; dkim=none (message not signed) header.d=none; vger.kernel.org; dmarc=pass action=none header.from=xilinx.com; Received-SPF: Pass (protection.outlook.com: domain of xilinx.com designates 149.199.62.198 as permitted sender) receiver=protection.outlook.com; client-ip=149.199.62.198; helo=xsj-pvapexch02.xlnx.xilinx.com; Received: from xsj-pvapexch02.xlnx.xilinx.com (149.199.62.198) by BN1NAM02FT051.mail.protection.outlook.com (10.13.2.159) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.20.4150.30 via Frontend Transport; Mon, 31 May 2021 13:21:39 +0000 Received: from xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2176.2; Mon, 31 May 2021 06:21:18 -0700 Received: from smtp.xilinx.com (172.19.127.95) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server id 15.1.2176.2 via Frontend Transport; Mon, 31 May 2021 06:21:18 -0700 Envelope-to: git@xilinx.com, linux-i2c@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, marex@denx.de Received: from [10.140.6.25] (port=53014 helo=xhdnagasure40.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1lnhr2-0004GE-OO; Mon, 31 May 2021 06:21:17 -0700 From: Raviteja Narayanam To: , CC: , , , , Raviteja Narayanam Subject: [PATCH 10/10] i2c: xiic: Update compatible with new IP version Date: Mon, 31 May 2021 07:19:48 -0600 Message-ID: <20210531131948.19477-11-raviteja.narayanam@xilinx.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20210531131948.19477-1-raviteja.narayanam@xilinx.com> References: <20210531131948.19477-1-raviteja.narayanam@xilinx.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 603eb692-12d7-4846-4488-08d924370638 X-MS-TrafficTypeDiagnostic: BN7PR02MB5123: X-Microsoft-Antispam-PRVS: X-Auto-Response-Suppress: DR, RN, NRN, OOF, AutoReply X-MS-Oob-TLC-OOBClassifiers: OLM:1122; X-MS-Exchange-SenderADCheck: 1 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: vfIqXX1XVFhDp+vCjLBhFkcwAUYXwYMR6qMAnxaX/vaBYUU3mjjndYqUshw7wb9Rz8fHnCu9CnZ3ZlPPZaAVq/HtU6fuc/CE9YU8SF6yD6Ay7Nx97G9xnBfeilRrnyb5mwTVkXiRy8Lgk/+AcPebuVt99mX8XvYEFUDmtnqSV4YEh5J4JqAKV/AAahs+0j86oJTloHudtO9AQi5upHaxdqUF5WLCHeDRFgVOqJaFfFbuvq+BJQismpyYsup3etxRj7kimv2bNaU1HMhSCr4LJCj8bXEBBBoL3kAV60woD0Yz6MKenSQDXAYlBCTLyCzsq2YJfIUrd5quw4lgGkIMjl8p5+0ZljCGZNiutThxlGZCOLlisTRo45HP8yBFLlPVYgb4R6gBnF7/8CGBzQ0/0jqgeLG54IILC6vZtwLdEFV+eFJpX3EW1uLfif2IqifqWudvVnqRlakOpCRdaN2aGysYHqQ5KTWgFGx0AOBAexKUMUtEvRKjHRCqbAPg78T3iNEDoUHZSC0V9bwcgjaovuLQdprL/F7Qodog+kiSnhdqqplDme8lLevbFLrIVagxK4f9JGGQJrIwL8IgeG5LzRChEFLc/54xQneb6dyw5Rx2ql25l8WI1iiek+pGL2szDzZ+LkdqyD9Kl8iyOg3gB2G4VSZTwBG/3x1ptEZbUS0Q2LRejCoDy2WMzm0G+5SQ X-Forefront-Antispam-Report: CIP:149.199.62.198; CTRY:US; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:xsj-pvapexch02.xlnx.xilinx.com; PTR:unknown-62-198.xilinx.com; CAT:NONE; SFS:(4636009)(346002)(396003)(39860400002)(136003)(376002)(46966006)(36840700001)(356005)(82740400003)(47076005)(7636003)(2616005)(82310400003)(478600001)(5660300002)(83380400001)(26005)(1076003)(2906002)(186003)(6636002)(70206006)(6666004)(336012)(8676002)(44832011)(70586007)(9786002)(426003)(7696005)(110136005)(54906003)(4744005)(107886003)(36756003)(316002)(8936002)(36860700001)(15650500001)(4326008)(102446001); DIR:OUT; SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 31 May 2021 13:21:39.4228 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 603eb692-12d7-4846-4488-08d924370638 X-MS-Exchange-CrossTenant-Id: 657af505-d5df-48d0-8300-c31994686c5c X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=657af505-d5df-48d0-8300-c31994686c5c; Ip=[149.199.62.198]; Helo=[xsj-pvapexch02.xlnx.xilinx.com] X-MS-Exchange-CrossTenant-AuthSource: BN1NAM02FT051.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN7PR02MB5123 Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org Xilinx AXI I2C IP is updated with a bug fix for dynamic mode reads. Older IPs are handled with a workaround in which they are using xiic standard mode for all these effected use cases. Added the new IP version to compatible. Signed-off-by: Raviteja Narayanam --- drivers/i2c/busses/i2c-xiic.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/i2c/busses/i2c-xiic.c b/drivers/i2c/busses/i2c-xiic.c index f022a1885b6a..45bd3b1a4c22 100644 --- a/drivers/i2c/busses/i2c-xiic.c +++ b/drivers/i2c/busses/i2c-xiic.c @@ -1130,6 +1130,7 @@ static const struct xiic_version_data xiic_2_00 = { #if defined(CONFIG_OF) static const struct of_device_id xiic_of_match[] = { { .compatible = "xlnx,xps-iic-2.00.a", .data = &xiic_2_00 }, + { .compatible = "xlnx,axi-iic-2.1", }, {}, }; MODULE_DEVICE_TABLE(of, xiic_of_match);