From patchwork Sat Sep 5 20:41:42 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 254824 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=-12.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH, MAILING_LIST_MULTI, SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable 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 EFA12C43461 for ; Sat, 5 Sep 2020 20:43:03 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AF84220760 for ; Sat, 5 Sep 2020 20:43:03 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Z+0v/6nR" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728787AbgIEUm6 (ORCPT ); Sat, 5 Sep 2020 16:42:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55474 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728758AbgIEUms (ORCPT ); Sat, 5 Sep 2020 16:42:48 -0400 Received: from mail-lf1-x142.google.com (mail-lf1-x142.google.com [IPv6:2a00:1450:4864:20::142]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 73A8AC061247; Sat, 5 Sep 2020 13:42:46 -0700 (PDT) Received: by mail-lf1-x142.google.com with SMTP id z17so5581342lfi.12; Sat, 05 Sep 2020 13:42:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3KS8oso7xw2Kqf6psNafzD7AGG/eXNfR4CiTjMdd6I0=; b=Z+0v/6nRRBQRAjtVHPUFURbCMwCl8DzFQME0ZvlHZq4IX38HqUGO/bvJt6es4fUNSc lITAFL4dDyywRd2HyNtWfCqCQ2pbttqYkYAs42N4VEbSAniY5t1Vklyh9hP7Fh/Mk1rh jpdpVfH8AXOYryKFDHDr+PSy6CWqbeAM5njcW/VCrDUJPvZmJOQ53eJRHZtTeJSEn+wK tTzRoCKCe3gpAVEIkTrGA5ybHAY/f2sMgC+sjdRi0Qub+fZqFffw6SfjZ5Wq2VqyHigY r0yGJztbBCiTNpzidNqaKgTV60PEv7KQ8GsZ93NaaTDDZvMxtirHdDxbe+LpRMNplKRl 1jhw== 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:mime-version:content-transfer-encoding; bh=3KS8oso7xw2Kqf6psNafzD7AGG/eXNfR4CiTjMdd6I0=; b=Q4ICO1kkKKafz5XzA16N98J9Kh77sbdrqhWmSeBScomuEoTfZdwKa7y8E9Ri7jXsYq K+7k7NIV1DN0eixoxXBrfw0mDAXUD+v3OityiAV2l59dGa3JBs7m+0oJsKwqdficlpbT NeXyRTIu7po7vbMXujqbfjS44qtg3oOuOiYWkzWYGWuM27oB+LyFPvAhaaPWwKVE3lzr JFEyOjdB2wjUzmi45Jc0kytWK6/PI/7/MQiEvt8EIs113WkW2uR6DmM/UltFgMhESFiZ ylLl4XVY2ZuZL6Hlk4DjicLsbvob7zo+NUDlX28VOg9AEAy88N/kyneQa1G2Rc2Zku0L gEmQ== X-Gm-Message-State: AOAM532rI1TncsMiUTw8O+zsuehmR7Y15uVseo053mrMUvebdCpqBo/i N2EIoL4zmQ8J/6aADy9opD3b8k8AJII= X-Google-Smtp-Source: ABdhPJygqzydOHv3dMep7S0qiiifdQqn5LnINZ1zvbIVm3nS9wR6iuD8MLNVI2UikpIhZyT3fXkuIg== X-Received: by 2002:a19:6a08:: with SMTP id u8mr6784465lfu.51.1599338564710; Sat, 05 Sep 2020 13:42:44 -0700 (PDT) Received: from localhost.localdomain (109-252-170-211.dynamic.spd-mgts.ru. [109.252.170.211]) by smtp.gmail.com with ESMTPSA id e17sm1677763ljn.18.2020.09.05.13.42.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 05 Sep 2020 13:42:44 -0700 (PDT) From: Dmitry Osipenko To: Thierry Reding , Jonathan Hunter , Laxman Dewangan , Wolfram Sang , =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= , Andy Shevchenko Cc: linux-i2c@vger.kernel.org, linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v4 22/31] i2c: tegra: Factor out packet header setup from tegra_i2c_xfer_msg() Date: Sat, 5 Sep 2020 23:41:42 +0300 Message-Id: <20200905204151.25343-23-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200905204151.25343-1-digetx@gmail.com> References: <20200905204151.25343-1-digetx@gmail.com> MIME-Version: 1.0 Sender: linux-i2c-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-i2c@vger.kernel.org The code related to packet header setting up is a bit messy and makes tegra_i2c_xfer_msg() more difficult to read than it could be. Let's factor the packet header setup from tegra_i2c_xfer_msg() into separate function in order to make code easier to read and follow. Signed-off-by: Dmitry Osipenko --- drivers/i2c/busses/i2c-tegra.c | 93 ++++++++++++++++++++-------------- 1 file changed, 54 insertions(+), 39 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index aa7adf8df668..129ca5a6cb85 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -1134,6 +1134,57 @@ static int tegra_i2c_issue_bus_clear(struct i2c_adapter *adap) return -EAGAIN; } +static void tegra_i2c_push_packet_header(struct tegra_i2c_dev *i2c_dev, + struct i2c_msg *msg, + enum msg_end_type end_state) +{ + u32 *dma_buf = i2c_dev->dma_buf; + u32 packet_header; + + packet_header = FIELD_PREP(PACKET_HEADER0_HEADER_SIZE, 0) | + FIELD_PREP(PACKET_HEADER0_PROTOCOL, + PACKET_HEADER0_PROTOCOL_I2C) | + FIELD_PREP(PACKET_HEADER0_CONT_ID, i2c_dev->cont_id) | + FIELD_PREP(PACKET_HEADER0_PACKET_ID, 1); + + if (i2c_dev->is_curr_dma_xfer && !i2c_dev->msg_read) + *dma_buf++ = packet_header; + else + i2c_writel(i2c_dev, packet_header, I2C_TX_FIFO); + + packet_header = msg->len - 1; + + if (i2c_dev->is_curr_dma_xfer && !i2c_dev->msg_read) + *dma_buf++ = packet_header; + else + i2c_writel(i2c_dev, packet_header, I2C_TX_FIFO); + + packet_header = I2C_HEADER_IE_ENABLE; + + if (end_state == MSG_END_CONTINUE) + packet_header |= I2C_HEADER_CONTINUE_XFER; + else if (end_state == MSG_END_REPEAT_START) + packet_header |= I2C_HEADER_REPEAT_START; + + if (msg->flags & I2C_M_TEN) { + packet_header |= msg->addr; + packet_header |= I2C_HEADER_10BIT_ADDR; + } else { + packet_header |= msg->addr << I2C_HEADER_SLAVE_ADDR_SHIFT; + } + + if (msg->flags & I2C_M_IGNORE_NAK) + packet_header |= I2C_HEADER_CONT_ON_NAK; + + if (msg->flags & I2C_M_RD) + packet_header |= I2C_HEADER_READ; + + if (i2c_dev->is_curr_dma_xfer && !i2c_dev->msg_read) + *dma_buf++ = packet_header; + else + i2c_writel(i2c_dev, packet_header, I2C_TX_FIFO); +} + static int tegra_i2c_error_recover(struct tegra_i2c_dev *i2c_dev, struct i2c_msg *msg) { @@ -1165,9 +1216,8 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, enum msg_end_type end_state) { unsigned long time_left, xfer_time = 100; - u32 packet_header, int_mask; - u32 *buffer = NULL; size_t xfer_size; + u32 int_mask; int err; err = tegra_i2c_flush_fifos(i2c_dev); @@ -1219,49 +1269,14 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, i2c_dev->dma_phys, xfer_size, DMA_TO_DEVICE); - buffer = i2c_dev->dma_buf; } } - packet_header = FIELD_PREP(PACKET_HEADER0_HEADER_SIZE, 0) | - FIELD_PREP(PACKET_HEADER0_PROTOCOL, - PACKET_HEADER0_PROTOCOL_I2C) | - FIELD_PREP(PACKET_HEADER0_CONT_ID, i2c_dev->cont_id) | - FIELD_PREP(PACKET_HEADER0_PACKET_ID, 1); - if (i2c_dev->is_curr_dma_xfer && !i2c_dev->msg_read) - *buffer++ = packet_header; - else - i2c_writel(i2c_dev, packet_header, I2C_TX_FIFO); - - packet_header = msg->len - 1; - if (i2c_dev->is_curr_dma_xfer && !i2c_dev->msg_read) - *buffer++ = packet_header; - else - i2c_writel(i2c_dev, packet_header, I2C_TX_FIFO); - - packet_header = I2C_HEADER_IE_ENABLE; - if (end_state == MSG_END_CONTINUE) - packet_header |= I2C_HEADER_CONTINUE_XFER; - else if (end_state == MSG_END_REPEAT_START) - packet_header |= I2C_HEADER_REPEAT_START; - if (msg->flags & I2C_M_TEN) { - packet_header |= msg->addr; - packet_header |= I2C_HEADER_10BIT_ADDR; - } else { - packet_header |= msg->addr << I2C_HEADER_SLAVE_ADDR_SHIFT; - } - if (msg->flags & I2C_M_IGNORE_NAK) - packet_header |= I2C_HEADER_CONT_ON_NAK; - if (msg->flags & I2C_M_RD) - packet_header |= I2C_HEADER_READ; - if (i2c_dev->is_curr_dma_xfer && !i2c_dev->msg_read) - *buffer++ = packet_header; - else - i2c_writel(i2c_dev, packet_header, I2C_TX_FIFO); + tegra_i2c_push_packet_header(i2c_dev, msg, end_state); if (!i2c_dev->msg_read) { if (i2c_dev->is_curr_dma_xfer) { - memcpy(buffer, msg->buf, msg->len); + memcpy(i2c_dev->dma_buf, msg->buf, msg->len); dma_sync_single_for_device(i2c_dev->dev, i2c_dev->dma_phys, xfer_size,