From patchwork Wed Apr 3 01:18:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ray Jui X-Patchwork-Id: 10882509 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AF91117E0 for ; Wed, 3 Apr 2019 01:19:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 8AEFE289DC for ; Wed, 3 Apr 2019 01:19:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7E549289E2; Wed, 3 Apr 2019 01:19:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id EB502289DC for ; Wed, 3 Apr 2019 01:18:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=0T0Ywaqt2oZSHnJz3wEwn2Rq/fIr3QvkKpMozWsAJ8Y=; b=aKjjyILpTrs+NxlkuLfM9R2NuE c0QJvU5fI8BYivmZ6u8g/QmAEOrjX9jbgPpBJWK+8A3LQp2xuFzWoteu1d/dVt/BKUZ5pEY/0uDvs TpPn3U6ez2NIrnJK3njpXuALXY34eO+nBQn2IqdOwb9lz7alTCg9kDh4zhSsSx3AsB2QtahejeoFf UXGy30Irof1Hk6WFIbi8vv9W0OUYlDna2MoJN8/i+uqEf6cTomRCPEJpHYgykMV80//wpudof8tYg W1lu8lABpJWq4BZjzMlQv7djv5xoJ1SuDBC4g8gzgxW1FpVTngbmNS6ElwzUknAs/rYJ+qTq5Cz67 Qc6a6YWA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1hBUYL-0008MJ-QS; Wed, 03 Apr 2019 01:18:57 +0000 Received: from mail-pf1-x442.google.com ([2607:f8b0:4864:20::442]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1hBUYG-0008Fl-4b for linux-arm-kernel@lists.infradead.org; Wed, 03 Apr 2019 01:18:54 +0000 Received: by mail-pf1-x442.google.com with SMTP id 9so7246602pfj.13 for ; Tue, 02 Apr 2019 18:18:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=broadcom.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=qRxo844csM8qt8Jpp70FLL5ovMkDKynzyu7Nlt6AgVI=; b=UOx9XdIX6zBMFJZ5jjVYXgOsXRLp9BmEpXLnZX5OXGYKBgWI9yCjn0U/QdG5RB8gao CIud1ztME4yJEOYNJMd+9N5h+xnSd1uVVdmgGzKaODfMS8v2knjL7BQtApqNFnvdcP1D uvNlWqFAsn8NjO2AZihgq0hTmJBqCaBlkD2Wk= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=qRxo844csM8qt8Jpp70FLL5ovMkDKynzyu7Nlt6AgVI=; b=smWTn3ICkhczcCtSyVhhAPlqkL30pIMkti0IL9QumVKNyGV5Q404DsNccHmHBv8zHq NPOZiB4CYT2XL0dluAoWBN+BbpDdTcAIZiNVsBAUCHwiZxKJOJPhcU3rY1yid5G2nqjj D4An59N0ktKgMKIjDBflJzChvb/M7mXoR5aaIGiHxTA5VSEPw67Nxl3mBneVUdHFRBTd KPk2mvCNw5qJg6+nLQ0BecPqUvoQyQXoBEwzU69EBMraMEc7ycGEp2cFQ8digsOOoBtY rpD5cbHwNKcYiH7RChOtyZDOrpd/2V5ZlHvxT/4/w0W9xjC7uM3dXWNeAKGAOzaZe8Yf c5Sw== X-Gm-Message-State: APjAAAXAtrrIeJ4J2BP5FMrL1A1gPtiRq7CSkL77IttyaYWnRgOu0+tg H8/ZhY8dZIrHkVUAsTvmzAYPvQ== X-Google-Smtp-Source: APXvYqyMmP9RBfPRc7Noc6e2hz7lzubGgAusYA/3KshJwX1RyHfiAZlOvHlAuYinRZgi4tfAHNb6bA== X-Received: by 2002:a63:6f0a:: with SMTP id k10mr47268652pgc.78.1554254331462; Tue, 02 Apr 2019 18:18:51 -0700 (PDT) Received: from rj-aorus.ric.broadcom.com ([192.19.228.250]) by smtp.gmail.com with ESMTPSA id 4sm19589046pfn.159.2019.04.02.18.18.48 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 02 Apr 2019 18:18:50 -0700 (PDT) From: Ray Jui To: Wolfram Sang , Rob Herring , Mark Rutland Subject: [PATCH v6 1/9] i2c: iproc: Extend I2C read up to 255 bytes Date: Tue, 2 Apr 2019 18:18:22 -0700 Message-Id: <20190403011830.3254-2-ray.jui@broadcom.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190403011830.3254-1-ray.jui@broadcom.com> References: <20190403011830.3254-1-ray.jui@broadcom.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190402_181852_750908_0CC7F5FE X-CRM114-Status: GOOD ( 21.39 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, Shreesha Rajashekar , Rayagonda Kokatanur , linux-kernel@vger.kernel.org, bcm-kernel-feedback-list@broadcom.com, linux-i2c@vger.kernel.org, Ray Jui , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP From: Shreesha Rajashekar Add support to allow I2C master read transfer up to 255 bytes. Signed-off-by: Shreesha Rajashekar Signed-off-by: Rayagonda Kokatanur Signed-off-by: Ray Jui --- drivers/i2c/busses/i2c-bcm-iproc.c | 96 +++++++++++++++++++++++------- 1 file changed, 74 insertions(+), 22 deletions(-) diff --git a/drivers/i2c/busses/i2c-bcm-iproc.c b/drivers/i2c/busses/i2c-bcm-iproc.c index 4c8c3bc4669c..4c31f4e178b6 100644 --- a/drivers/i2c/busses/i2c-bcm-iproc.c +++ b/drivers/i2c/busses/i2c-bcm-iproc.c @@ -80,6 +80,10 @@ #define I2C_TIMEOUT_MSEC 50000 #define M_TX_RX_FIFO_SIZE 64 +#define M_RX_FIFO_MAX_THLD_VALUE (M_TX_RX_FIFO_SIZE - 1) + +#define M_RX_MAX_READ_LEN 255 +#define M_RX_FIFO_THLD_VALUE 50 enum bus_speed_index { I2C_SPD_100K = 0, @@ -102,17 +106,39 @@ struct bcm_iproc_i2c_dev { /* bytes that have been transferred */ unsigned int tx_bytes; + /* bytes that have been read */ + unsigned int rx_bytes; + unsigned int thld_bytes; }; /* * Can be expanded in the future if more interrupt status bits are utilized */ -#define ISR_MASK (BIT(IS_M_START_BUSY_SHIFT) | BIT(IS_M_TX_UNDERRUN_SHIFT)) +#define ISR_MASK (BIT(IS_M_START_BUSY_SHIFT) | BIT(IS_M_TX_UNDERRUN_SHIFT)\ + | BIT(IS_M_RX_THLD_SHIFT)) + +static void bcm_iproc_i2c_read_valid_bytes(struct bcm_iproc_i2c_dev *iproc_i2c) +{ + struct i2c_msg *msg = iproc_i2c->msg; + + /* Read valid data from RX FIFO */ + while (iproc_i2c->rx_bytes < msg->len) { + if (!((readl(iproc_i2c->base + M_FIFO_CTRL_OFFSET) >> M_FIFO_RX_CNT_SHIFT) + & M_FIFO_RX_CNT_MASK)) + break; + + msg->buf[iproc_i2c->rx_bytes] = + (readl(iproc_i2c->base + M_RX_OFFSET) >> + M_RX_DATA_SHIFT) & M_RX_DATA_MASK; + iproc_i2c->rx_bytes++; + } +} static irqreturn_t bcm_iproc_i2c_isr(int irq, void *data) { struct bcm_iproc_i2c_dev *iproc_i2c = data; u32 status = readl(iproc_i2c->base + IS_OFFSET); + u32 tmp; status &= ISR_MASK; @@ -136,8 +162,6 @@ static irqreturn_t bcm_iproc_i2c_isr(int irq, void *data) /* mark the last byte */ if (idx == msg->len - 1) { - u32 tmp; - val |= BIT(M_TX_WR_STATUS_SHIFT); /* @@ -156,6 +180,32 @@ static irqreturn_t bcm_iproc_i2c_isr(int irq, void *data) iproc_i2c->tx_bytes += tx_bytes; } + if (status & BIT(IS_M_RX_THLD_SHIFT)) { + struct i2c_msg *msg = iproc_i2c->msg; + u32 bytes_left; + + bcm_iproc_i2c_read_valid_bytes(iproc_i2c); + bytes_left = msg->len - iproc_i2c->rx_bytes; + if (bytes_left == 0) { + /* finished reading all data, disable rx thld event */ + tmp = readl(iproc_i2c->base + IE_OFFSET); + tmp &= ~BIT(IS_M_RX_THLD_SHIFT); + writel(tmp, iproc_i2c->base + IE_OFFSET); + } else if (bytes_left < iproc_i2c->thld_bytes) { + /* set bytes left as threshold */ + tmp = readl(iproc_i2c->base + M_FIFO_CTRL_OFFSET); + tmp &= ~(M_FIFO_RX_THLD_MASK << M_FIFO_RX_THLD_SHIFT); + tmp |= (bytes_left << M_FIFO_RX_THLD_SHIFT); + writel(tmp, iproc_i2c->base + M_FIFO_CTRL_OFFSET); + iproc_i2c->thld_bytes = bytes_left; + } + /* + * bytes_left >= iproc_i2c->thld_bytes, + * hence no need to change the THRESHOLD SET. + * It will remain as iproc_i2c->thld_bytes itself + */ + } + if (status & BIT(IS_M_START_BUSY_SHIFT)) { iproc_i2c->xfer_is_done = 1; complete(&iproc_i2c->done); @@ -253,7 +303,7 @@ static int bcm_iproc_i2c_xfer_single_msg(struct bcm_iproc_i2c_dev *iproc_i2c, { int ret, i; u8 addr; - u32 val; + u32 val, tmp, val_intr_en; unsigned int tx_bytes; unsigned long time_left = msecs_to_jiffies(I2C_TIMEOUT_MSEC); @@ -298,7 +348,7 @@ static int bcm_iproc_i2c_xfer_single_msg(struct bcm_iproc_i2c_dev *iproc_i2c, * transaction is done, i.e., the internal start_busy bit, transitions * from 1 to 0. */ - val = BIT(IE_M_START_BUSY_SHIFT); + val_intr_en = BIT(IE_M_START_BUSY_SHIFT); /* * If TX data size is larger than the TX FIFO, need to enable TX @@ -307,9 +357,7 @@ static int bcm_iproc_i2c_xfer_single_msg(struct bcm_iproc_i2c_dev *iproc_i2c, */ if (!(msg->flags & I2C_M_RD) && msg->len > iproc_i2c->tx_bytes) - val |= BIT(IE_M_TX_UNDERRUN_SHIFT); - - writel(val, iproc_i2c->base + IE_OFFSET); + val_intr_en |= BIT(IE_M_TX_UNDERRUN_SHIFT); /* * Now we can activate the transfer. For a read operation, specify the @@ -317,11 +365,27 @@ static int bcm_iproc_i2c_xfer_single_msg(struct bcm_iproc_i2c_dev *iproc_i2c, */ val = BIT(M_CMD_START_BUSY_SHIFT); if (msg->flags & I2C_M_RD) { + iproc_i2c->rx_bytes = 0; + if (msg->len > M_RX_FIFO_MAX_THLD_VALUE) + iproc_i2c->thld_bytes = M_RX_FIFO_THLD_VALUE; + else + iproc_i2c->thld_bytes = msg->len; + + /* set threshold value */ + tmp = readl(iproc_i2c->base + M_FIFO_CTRL_OFFSET); + tmp &= ~(M_FIFO_RX_THLD_MASK << M_FIFO_RX_THLD_SHIFT); + tmp |= iproc_i2c->thld_bytes << M_FIFO_RX_THLD_SHIFT; + writel(tmp, iproc_i2c->base + M_FIFO_CTRL_OFFSET); + + /* enable the RX threshold interrupt */ + val_intr_en |= BIT(IE_M_RX_THLD_SHIFT); + val |= (M_CMD_PROTOCOL_BLK_RD << M_CMD_PROTOCOL_SHIFT) | (msg->len << M_CMD_RD_CNT_SHIFT); } else { val |= (M_CMD_PROTOCOL_BLK_WR << M_CMD_PROTOCOL_SHIFT); } + writel(val_intr_en, iproc_i2c->base + IE_OFFSET); writel(val, iproc_i2c->base + M_CMD_OFFSET); time_left = wait_for_completion_timeout(&iproc_i2c->done, time_left); @@ -353,17 +417,6 @@ static int bcm_iproc_i2c_xfer_single_msg(struct bcm_iproc_i2c_dev *iproc_i2c, return ret; } - /* - * For a read operation, we now need to load the data from FIFO - * into the memory buffer - */ - if (msg->flags & I2C_M_RD) { - for (i = 0; i < msg->len; i++) { - msg->buf[i] = (readl(iproc_i2c->base + M_RX_OFFSET) >> - M_RX_DATA_SHIFT) & M_RX_DATA_MASK; - } - } - return 0; } @@ -395,9 +448,8 @@ static const struct i2c_algorithm bcm_iproc_algo = { .functionality = bcm_iproc_i2c_functionality, }; -static const struct i2c_adapter_quirks bcm_iproc_i2c_quirks = { - /* need to reserve one byte in the FIFO for the slave address */ - .max_read_len = M_TX_RX_FIFO_SIZE - 1, +static struct i2c_adapter_quirks bcm_iproc_i2c_quirks = { + .max_read_len = M_RX_MAX_READ_LEN, }; static int bcm_iproc_i2c_cfg_speed(struct bcm_iproc_i2c_dev *iproc_i2c)