Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp4126996pxk; Tue, 29 Sep 2020 15:23:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxeg9eBoaZogq8C6mHBAxo0QnrxHCssJnotN8Z4Aib/h8kjYD/OEwFvBk2V8Z9dEi/mBRTj X-Received: by 2002:a50:fb15:: with SMTP id d21mr5886787edq.150.1601418191001; Tue, 29 Sep 2020 15:23:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1601418190; cv=none; d=google.com; s=arc-20160816; b=DuVankhFov6KE5iuzYEFMNPjO13EFG+7azrMpAHzdjiR/6C6byFaG4VQWVfOCMoVQF Bduu8O75E2BCfNEezRlqxW24LaPKSDfIRV6IUxnAuXd/zKtwHsNfD0UzJ0frUhYkDULl imBWO6Pfl/wLn/O4eyI5fko0GHyn8cAFF8kYADFX6mhOjJg24lJz6PI94sa/XiGOe4Vm CF40tplmTMpmj7TwVMDaZYlXh8ystzS/M5Of3cXI72DfA1+0jM4QdleLQrx37/oBAwb3 EFbxsU11YX2XVbZOawz5k1rv4UhRafk9UmG5P+cdI/M+LO0DWelUk4gEAtJ/LYm0p1+d K+5Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=YJWx3Ne9wYycfjWCgp2dPiCIqnywl3wstu8oh1kRz7c=; b=b9ak9DDoN8a6Wi8Er4ZwyqZ2OACOJfNUTFCzBuX1U2yi2ycCsbIVFaMsUjRfYi3W7l sYGaIe1iBqH4JOuHETcYJtks2YayCy7nkhWa3UJG7FAAF08eiu6gWbHqfmnFwU0+rvCU nKlfgqDg6sbsujo9UyCkJWjqIboeFRGeC5/RHDPs7q9k1Ah6dFFiFctSAVJE3nI4fifh EUuxkVa/JCPjsgK2uBGCH48kyPhTdC2/f/Lo72juaKWrZmyyrRjs9+s3EegwPTl9dwOU h7CmaMD8Sw4uOdtJFFIZKu8bU4Dt6wpn33TNbWrr7nuQmyaAodLy4mMhYo7wNk3bS7+D B/6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=PbAByzyb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id t23si3748533ejs.552.2020.09.29.15.22.47; Tue, 29 Sep 2020 15:23:10 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20161025 header.b=PbAByzyb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729478AbgI2WVQ (ORCPT + 99 others); Tue, 29 Sep 2020 18:21:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53686 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729225AbgI2WVA (ORCPT ); Tue, 29 Sep 2020 18:21:00 -0400 Received: from mail-lj1-x243.google.com (mail-lj1-x243.google.com [IPv6:2a00:1450:4864:20::243]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E8028C0613D3; Tue, 29 Sep 2020 15:20:59 -0700 (PDT) Received: by mail-lj1-x243.google.com with SMTP id w3so5339041ljo.5; Tue, 29 Sep 2020 15:20:59 -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=YJWx3Ne9wYycfjWCgp2dPiCIqnywl3wstu8oh1kRz7c=; b=PbAByzyb+uzxDfsfNMf//ASgVTahA7iIrMtaQOHZu4xeQ6ps9wKJLZ4GhzgAM6QuXT XANt58OgEP5IhbWH+4huKGjWKMtVcF9wwaEOXOQbBf6H6gATQZ6JAkviz+LQg8O9m02M 4ti7Rl0jhWFUQH3ou0b9iAxv1Wx8K7pBC913OX26nt+yNR5FxfestvpTOefXg7RX0xag KyCA8c0r/58h8C5Ir8dELcmpc5DFRpI7U3i4LadM87exfk4Y3lYvc8br06B1ce6bwu90 5O4QSpgJu+t927IiLldhwMWRuR2OsFKyJ5JAXqDTjf6jNR0D8TZh3y7E36iitu+oJHXy XwLg== 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=YJWx3Ne9wYycfjWCgp2dPiCIqnywl3wstu8oh1kRz7c=; b=E5IrRKlWve3NzYLcgpXX7KhQyJWOzn8PWhzxOXerPs8MbxWvpTvQnIzTDsfhq3n+qb kQU7731+fXJNkl6rNzk7tTi3KQn2lLGjN7livlAXbbafowQ15Kdf0mnvrBJwftOs/Cry x/x9F4Awnr3+siwU0CaCk00oMfno1t6QDRjp8Kbq2ldgGnuym3MdDXw+eyF3RZvndzpu 7gJ92DLL2sHX8MmaampRANflnf2JuKK0/dg70ZlnByFoWB+FLzo3Rnlo8q49b3Ecit9f b8bNAph+cw40f2pWQfmZnk6KMo8/8H5mL5/qaCxOA4hkMmtKyzPjUNV8vjQ9HP4dnTKE aiXw== X-Gm-Message-State: AOAM530JAvaPB5XZmC8mIP+iS1ktdq9Ayx2vpHtcWujsNvlBtaEFaSYu aQxqyYdUdsHGJUAT+PU16rU= X-Received: by 2002:a2e:8906:: with SMTP id d6mr1692118lji.354.1601418058378; Tue, 29 Sep 2020 15:20:58 -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 q18sm3379750lfr.138.2020.09.29.15.20.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 29 Sep 2020 15:20:57 -0700 (PDT) From: Dmitry Osipenko To: Thierry Reding , Jonathan Hunter , Laxman Dewangan , Wolfram Sang , =?UTF-8?q?Micha=C5=82=20Miros=C5=82aw?= , Andy Shevchenko Cc: linux-i2c@vger.kernel.org, linux-tegra@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v9 23/32] i2c: tegra: Factor out packet header setup from tegra_i2c_xfer_msg() Date: Wed, 30 Sep 2020 01:19:06 +0300 Message-Id: <20200929221915.10979-24-digetx@gmail.com> X-Mailer: git-send-email 2.27.0 In-Reply-To: <20200929221915.10979-1-digetx@gmail.com> References: <20200929221915.10979-1-digetx@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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. Reviewed-by: Michał Mirosław Reviewed-by: Andy Shevchenko Acked-by: Thierry Reding Tested-by: Thierry Reding Signed-off-by: Dmitry Osipenko --- drivers/i2c/busses/i2c-tegra.c | 95 ++++++++++++++++++++-------------- 1 file changed, 55 insertions(+), 40 deletions(-) diff --git a/drivers/i2c/busses/i2c-tegra.c b/drivers/i2c/busses/i2c-tegra.c index 95d257cbd800..fbeae872ece1 100644 --- a/drivers/i2c/busses/i2c-tegra.c +++ b/drivers/i2c/busses/i2c-tegra.c @@ -281,7 +281,7 @@ struct tegra_i2c_dev { struct dma_chan *tx_dma_chan; struct dma_chan *rx_dma_chan; dma_addr_t dma_phys; - u32 *dma_buf; + void *dma_buf; unsigned int dma_buf_size; bool is_curr_dma_xfer; struct completion dma_complete; @@ -1105,6 +1105,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) { @@ -1135,11 +1186,9 @@ static int tegra_i2c_xfer_msg(struct tegra_i2c_dev *i2c_dev, struct i2c_msg *msg, enum msg_end_type end_state) { - u32 packet_header; u32 int_mask; unsigned long time_left; size_t xfer_size; - u32 *buffer = NULL; int err = 0; u16 xfer_time = 100; @@ -1192,49 +1241,15 @@ 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 + I2C_PACKET_HEADER_SIZE, + msg->buf, msg->len); dma_sync_single_for_device(i2c_dev->dev, i2c_dev->dma_phys, xfer_size, -- 2.27.0