From patchwork Thu Feb 2 09:41:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Manikanta Guntupalli X-Patchwork-Id: 13125656 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 14F9BC61DA4 for ; Thu, 2 Feb 2023 09:44:51 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-ID:Date:Subject:CC:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=TsktyGv3NOVaIF+49HHwZ/Vi6i0KPeti/qXzGBBiLn0=; b=OlsCWAAkWAWP1H iSVCUfayCRbim7wiY+CiC5v57JPovbqM068Rkb/KEHIJSy087GkoPENbdYVW2lWq3POHIUF7BE5cw O3I53vX0kKpdUp0Y0SbW+qhZ98D14HqDp1NwjkqbeWt0+obSnBVNfa5IA+gEDfHIRP+7l6Jp+llQw zThdS7WoNEmEvPNqgKkhx+Y0bpg0c+3QdF4OL8+bQnbf1GD/29+fCplcaculngtTOrviF4ayi/uHy YXiPF5VyXQNNjYsImlhNa7hLhhXH0mQ8JjcTtr7vrc0/eOqS+5XyPR8i/mapG46Fr6lMFqk7GwzZm Nb/KqgFvXvpJoMSqK4Ow==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1pNW89-00FD44-DV; Thu, 02 Feb 2023 09:43:45 +0000 Received: from mail-bn8nam11on20601.outbound.protection.outlook.com ([2a01:111:f400:7eae::601] helo=NAM11-BN8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1pNW7x-00FD03-Tk for linux-arm-kernel@lists.infradead.org; Thu, 02 Feb 2023 09:43:35 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=OWrHMKk34GfECyHv3FK7hUHgYe8ByL5a17RX2Hue/NZ6JLzb4xhCXRjYVR/U0p+kwm1zs7tQaRXr41JKotPXFqF5uw5s2G531bwUO8Flp2a9nSjn+SPCt7y5jrCiYMtTrRqAzuLuF537yiNtXQyEZOWJI1PVkK3xPukW5hzpz6EAgtRb6+JCO61zn9b/vaaCi8e/70huudF6psqpjaOI8WoVFaKf0ACgmrg1NBJLAwVrd8xziIRuB+FreWhMeybDtMctD550Vqfswd2+qLTNjcVzgwWR/xabamI/YJfXKS4Dp/8IFMKfS2ZZe4oOz5zjToJfv+vef7BfWQVrBm97yQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=rCZLKqSFYYHdOKQrTutofbhVjZsqbIE+qYtqLXWGyPo=; b=hRdH1Ick+aSADzUD5yaPDGy7+yfhWhbTo5I+AuFsMMbWUi0RYVL6y60qxGR2kNCYK+tQ5+q59iantC3Fjor64ZYrWHcsJUmwubde47H1P20TzBBTi0+cAqcxS87pR1qwtOtOtz41sbbMCTMhbdZqfRwFPGc9tvYp3b5XzMab4czat9qfBgMCMJ5pCbi9z+DaCHLfVSF3fGCoQuxuadeF11RK3ypyQAPWy3G6A4+Yq1RkMBFhdix0SHY6xPP4cocb/t4US9+xojBrAM4vQ7GGDgGrz5r3r52z7abTblDanqLyoLDHgaBf7c0jUgzxwpuxWKi21AoZo3gZfe7/jHaW9Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass (sender ip is 149.199.62.198) smtp.rcpttodomain=amd.com smtp.mailfrom=xilinx.com; dmarc=fail (p=quarantine sp=quarantine pct=100) action=quarantine header.from=amd.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=rCZLKqSFYYHdOKQrTutofbhVjZsqbIE+qYtqLXWGyPo=; b=nR1UHb26uF9M5ePStiofOG8WiTO8usrH9a7mpXd5sNkdI487qQgtyMNpWulh6vM22kZFsryedOmEzCh5XyTq+W/Ys9yZtfn+LH1uyR8nw3z5pROQU8vs45rZm3znqugFrprme6EHLXJuLUobi3N2PeTwOS6Ek33NxnOP5v72Nec= Received: from SN7PR04CA0167.namprd04.prod.outlook.com (2603:10b6:806:125::22) by DM4PR02MB9240.namprd02.prod.outlook.com (2603:10b6:8:104::11) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6064.27; Thu, 2 Feb 2023 09:43:29 +0000 Received: from SN1NAM02FT0060.eop-nam02.prod.protection.outlook.com (2603:10b6:806:125:cafe::1c) by SN7PR04CA0167.outlook.office365.com (2603:10b6:806:125::22) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.6064.27 via Frontend Transport; Thu, 2 Feb 2023 09:43:29 +0000 X-MS-Exchange-Authentication-Results: spf=pass (sender IP is 149.199.62.198) smtp.mailfrom=xilinx.com; dkim=none (message not signed) header.d=none;dmarc=fail action=quarantine header.from=amd.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; pr=C Received: from xsj-pvapexch01.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.6064.27 via Frontend Transport; Thu, 2 Feb 2023 09:43:29 +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.2375.28; Thu, 2 Feb 2023 01:43:26 -0800 Received: from smtp.xilinx.com (172.19.127.96) by xsj-pvapexch02.xlnx.xilinx.com (172.19.86.41) with Microsoft SMTP Server id 15.1.2507.16 via Frontend Transport; Thu, 2 Feb 2023 01:43:26 -0800 Received: from [172.23.64.3] (port=37000 helo=xhdvnc103.xilinx.com) by smtp.xilinx.com with esmtp (Exim 4.90) (envelope-from ) id 1pNW7q-0003Sh-4J; Thu, 02 Feb 2023 01:43:26 -0800 Received: by xhdvnc103.xilinx.com (Postfix, from userid 90444) id 3FFE91055BE; Thu, 2 Feb 2023 15:12:25 +0530 (IST) From: Manikanta Guntupalli To: , , , , , , , , CC: , , , , , Raviteja Narayanam Subject: [PATCH V4 5/9] i2c: xiic: Add smbus_block_read functionality Date: Thu, 2 Feb 2023 15:11:34 +0530 Message-ID: <1675330898-563-6-git-send-email-manikanta.guntupalli@amd.com> X-Mailer: git-send-email 2.1.1 In-Reply-To: <1675330898-563-1-git-send-email-manikanta.guntupalli@amd.com> References: <1675330898-563-1-git-send-email-manikanta.guntupalli@amd.com> MIME-Version: 1.0 X-EOPAttributedMessage: 0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: SN1NAM02FT0060:EE_|DM4PR02MB9240:EE_ X-MS-Office365-Filtering-Correlation-Id: 67da98fd-bebb-4043-b7bb-08db0501f0b2 X-MS-Exchange-SenderADCheck: 0 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: EgFCxRhLh+htVKAWIjvjP8pJys9Wd+4R0QoHxzazBTqSIBgdnwApLwBE2Jb79Fph3xMTFj44OD07h5Qc/Yf086hZu8BbJFLuRoBEpWctEZCGzgrBaK/cQRFis9nwm8k2Qv9Ssl1WWnlw2X2Rz3Ao3eHYPIoxduSQFiUom7duYw+2C2OUz2hEmxcj0Jsy3Xv2IXHTavTKbHy2XDqApmO/Fv+SsYoF89LQF90bRROBo9pqVFV917TqC0/Z+CKMHhZRX42EZvo3Cn2Jjekn2O1MXUuredlpXcCRJEyZh1xZ9ST04B7ATC5Y6N6egXvA9qlqEb57+t+PChtuW+6VVz2BOz1ksEGh960nG5iRAmqeRnnbG2hefW7Z8mknG3LaI/a5+wFTp8yIqPjLBtF/U8CGosFkqQrzbSTAhz2W0hQQDsaXwXfacD11QzDjNTy/6VxYtE1KJ+IxUWqZbFQtQXk2Xow1yAHwmP/cNeIOuEtS4fIQE2oe2yRc3nb6JrYrHVHhDuC/5m6J7F4s0gqQIasqtMAwytuq4QkS0PvHJAjM6alXCH05VveSPhd1FRzcD//QwCwFGjSaC0aO5gAQb6YpFjeJbHUsTevIgXPZ4CkuPN/QkCK+cyQ967ZZ3SAD+3VNymCVbkBOe+CqbCSfO2Gu1CUU+qzcV7qAD0X/qbeqv7cYSuC+Do9ZRSypUqj5IxjMvx+yXZaaTeRtcoxSVuHvT6ZClcJeceGvox6U18+TAShQSz5L2nvUdTMcGB+dH+MualrkGaYPnzkwF+MzcUAICd2ofO+MtP3FkYzw5ttKobc= 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:(13230025)(396003)(39860400002)(346002)(136003)(376002)(451199018)(36840700001)(40470700004)(46966006)(36756003)(70586007)(47076005)(70206006)(83170400001)(4326008)(82310400005)(83380400001)(8676002)(36860700001)(110136005)(54906003)(7636003)(42186006)(316002)(82740400003)(478600001)(26005)(186003)(6266002)(107886003)(40460700003)(44832011)(6666004)(7416002)(5660300002)(41300700001)(356005)(40480700001)(2616005)(8936002)(336012)(43170500006)(42882007)(2906002)(102446001)(2101003);DIR:OUT;SFP:1101; X-OriginatorOrg: xilinx.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Feb 2023 09:43:29.3470 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 67da98fd-bebb-4043-b7bb-08db0501f0b2 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: SN1NAM02FT0060.eop-nam02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: DM4PR02MB9240 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20230202_014334_012188_3C40A46E X-CRM114-Status: GOOD ( 22.37 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org From: Raviteja Narayanam 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, xiic standard mode is being used for low level control of IP. Signed-off-by: Raviteja Narayanam Signed-off-by: Manikanta Guntupalli Acked-by: Michal Simek --- drivers/i2c/busses/i2c-xiic.c | 82 +++++++++++++++++++++++++++++++++-- 1 file changed, 78 insertions(+), 4 deletions(-) diff --git a/drivers/i2c/busses/i2c-xiic.c b/drivers/i2c/busses/i2c-xiic.c index 57084696429c..554f83e34a2a 100644 --- a/drivers/i2c/busses/i2c-xiic.c +++ b/drivers/i2c/busses/i2c-xiic.c @@ -33,6 +33,7 @@ #define DRIVER_NAME "xiic-i2c" #define DYNAMIC_MODE_READ_BROKEN_BIT BIT(0) +#define SMBUS_BLOCK_READ_MIN_LEN 3 enum xilinx_i2c_state { STATE_DONE, @@ -64,6 +65,7 @@ enum xiic_endian { * @dynamic: Mode of controller * @prev_msg_tx: Previous message is Tx * @quirks: To hold platform specific bug info + * @smbus_block_read: Flag to handle block read */ struct xiic_i2c { struct device *dev; @@ -83,6 +85,7 @@ struct xiic_i2c { bool dynamic; bool prev_msg_tx; u32 quirks; + bool smbus_block_read; }; struct xiic_version_data { @@ -346,6 +349,62 @@ 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, 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) { + /* + * When Rx msg len greater than or equal to Rx fifo capacity + * Receive fifo depth should set to Rx fifo capacity minus 1 + */ + 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 + */ + rfd_set = 0; + i2c->rx_msg->len = SMBUS_BLOCK_READ_MIN_LEN; + } else { + /* + * When Rx msg len less than Rx fifo capacity + * Receive fifo depth should set to Rx msg len minus 2 + */ + 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; @@ -368,6 +427,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) { @@ -601,6 +666,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; @@ -741,11 +812,14 @@ static void xiic_start_recv(struct xiic_i2c *i2c) rfd_set = IIC_RX_FIFO_DEPTH - 1; } else if (rx_watermark == 1) { 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 if (rx_watermark == 0) { rfd_set = rx_watermark; - cr |= XIIC_CR_NO_ACK_MASK; } else { rfd_set = rx_watermark - 2; } @@ -984,7 +1058,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 = {