Received: by 2002:ac0:98c7:0:0:0:0:0 with SMTP id g7-v6csp5899837imd; Wed, 31 Oct 2018 03:59:59 -0700 (PDT) X-Google-Smtp-Source: AJdET5e2qJSjUJdknI/+M9L49+45r5xx8QHluiLJXuq43m6dzOujEZLfdE8YOiIYDXbQOR1kZXtV X-Received: by 2002:a62:6b41:: with SMTP id g62-v6mr2878726pfc.106.1540983599640; Wed, 31 Oct 2018 03:59:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1540983599; cv=none; d=google.com; s=arc-20160816; b=ql2SuGc1w/jgSLcg8IC0bTX/khjDyJKPz37OV93QArXcj+G0UTAIY3/DjoY8U18HFu 2q97b5z+OzsrXcP6b3C8AeD9CBOA6LzoSZHXDBXsOsGotyt+h3rsc6eHlzIwWkqR9K3x yAhgKQJVRHEKL1wmQWO+1o0HiqJRMFFYWn5VH3WRuhOutJapBm0TALDROKfBhdFL2cOL A2FBAjBK9KRA8fV7lI3FuNKvooV6QYKQK2cfDEdDld8V7dv0Cr4Qx0JqIKIx41c8YUXV c7aASQiIfLgUBsJT0Oo4tFNTga0uQfCxf0xI0aR2yEPlV4GbybgS2MlwYnxWlrYkU8hU 2oOA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=NM/pdnDnROXWun72O7MwXmRWKVMT3A9vxEBhsKr6Owo=; b=WpDPFrx2bc3Xspfl1BdDvVoQtUiIrX3UA1DJ3bFjMUJhcA6xpODuAE8yKkkYdvpejf Gj/MNly2Piy7HS5ep0QCdhcOVFo+7XaaA7ZyTsTKqV5TtvEMw9cDSGptLQ3c0q+tVEmi mQwELreuS9qyCRTBcBGC4lBBYS6gLOITQ4P9Qes4jHiOuLliA1WCy4IsEqnYblk3TW32 KzRqfHhJDefh9hHCnTB/rx+kKiED6vD4JKuel1yJ7M9X3pI/C7g+nYD+NdAAcaWDOISZ om0HfRf8VBnxA1prTQ6VUDTb9Z7xvBYYsz0oJivyAnSLk+C9+VNKzSLQATp+U/b7dofB 03Xg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=BxLfenX6; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i35-v6si14850450plg.252.2018.10.31.03.59.45; Wed, 31 Oct 2018 03:59:59 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=fail header.i=@gmail.com header.s=20161025 header.b=BxLfenX6; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728950AbeJaTzp (ORCPT + 99 others); Wed, 31 Oct 2018 15:55:45 -0400 Received: from mail-ed1-f66.google.com ([209.85.208.66]:35503 "EHLO mail-ed1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727980AbeJaTzn (ORCPT ); Wed, 31 Oct 2018 15:55:43 -0400 Received: by mail-ed1-f66.google.com with SMTP id d6-v6so5123871edi.2; Wed, 31 Oct 2018 03:58:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NM/pdnDnROXWun72O7MwXmRWKVMT3A9vxEBhsKr6Owo=; b=BxLfenX6EuHvHFiYIyzNLq4O7HDW31+Q2mP4QbINrAsbM4Y5En+mOqriP2L3rh9p8K ccBue/Jlfc2U7el7ZlHdbB3Q09AvqtxAGf+SyNnPzdSeiaN5cKlvTq4C/jAPLavTpy0t K4LAumY+68xW2yirdo32YnYh564atgvZRnfgK6QcwqHtQgO3GbC95OdkiIilsF+JqUbP aVDA4bJYzKVUYJQkCopdrNUzig5tCnPd3XAO+Lhk7kAhqYYpFLZRfo5ThrJ0dZdvUVA0 ZaXeSyBUBL3pURyKGZuPuca52HFVvB54SM39S/GMptxLxBp1x7rbBSt1H+aEm6oG2Dt1 EU8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:from:to:cc:subject:date:message-id :in-reply-to:references:mime-version:content-transfer-encoding; bh=NM/pdnDnROXWun72O7MwXmRWKVMT3A9vxEBhsKr6Owo=; b=OvTti8Shkm04LwiqyI6phO88WiPj5o58ZiSZwWsJ0O61AphWaC/7yXXEW1+rjX62be Yx7sgT/u1ulsSFKM8Vn2oXmbVRW2I8p8+TSguWoeFzYIUnKN+kYodUdvc/WS2FqSbK73 JLJK5QqGDRm2esRmabmv20I5P+2Vaa0Bx7ZKkrudX2Dq//79WEDjozDjbruu4Ss4Kojr GKlw1kr/9cMmyyRZZ9PZTwJ4InmMLr2qXF2Bys8iAIljyFk9Phet4FeSL9SvoedKY2t/ dmFbnuSEbhf+/F/ifGejTSlk8VfSzUADnshkEbTw0GVfWSYpDizKZwnZiparqrRz2rus zklA== X-Gm-Message-State: AGRZ1gL6jYAHIW8LfRtOmai7PtITy7nRu973cacFHLAklQmAj0U9h+L5 0rj6aZpCBS1XhZfUMLZAXnpECA9icCI= X-Received: by 2002:a50:c31b:: with SMTP id a27-v6mr1654288edb.160.1540983486081; Wed, 31 Oct 2018 03:58:06 -0700 (PDT) Received: from localhost.localdomain ([5.57.50.195]) by smtp.gmail.com with ESMTPSA id a40-v6sm9041108edd.61.2018.10.31.03.58.04 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 31 Oct 2018 03:58:05 -0700 (PDT) From: Emil Renner Berthing To: linux-spi@vger.kernel.org Cc: Emil Renner Berthing , Addy Ke , Mark Brown , Heiko Stuebner , linux-arm-kernel@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org Subject: [PATCH v1 06/14] spi: rockchip: read transfer info directly Date: Wed, 31 Oct 2018 11:57:03 +0100 Message-Id: <20181031105711.19575-7-esmil@mailme.dk> X-Mailer: git-send-email 2.19.1 In-Reply-To: <20181031105711.19575-1-esmil@mailme.dk> References: <20181031105711.19575-1-esmil@mailme.dk> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Emil Renner Berthing Just read transfer info directly from the spi device and transfer structures rather than storing it in driver data first. Signed-off-by: Emil Renner Berthing --- drivers/spi/spi-rockchip.c | 70 +++++++++++++------------------------- 1 file changed, 24 insertions(+), 46 deletions(-) diff --git a/drivers/spi/spi-rockchip.c b/drivers/spi/spi-rockchip.c index 5729e6071729..5edc51820d35 100644 --- a/drivers/spi/spi-rockchip.c +++ b/drivers/spi/spi-rockchip.c @@ -178,12 +178,8 @@ struct rockchip_spi { /* max bus freq supported */ u32 max_freq; - u16 mode; - u8 tmode; - u8 bpw; u8 n_bytes; u32 rsd_nsecs; - unsigned len; u32 speed; const void *tx; @@ -194,8 +190,6 @@ struct rockchip_spi { bool cs_asserted[ROCKCHIP_SPI_MAX_CS_NUM]; bool use_dma; - struct sg_table tx_sg; - struct sg_table rx_sg; struct rockchip_spi_dma_data dma_rx; struct rockchip_spi_dma_data dma_tx; }; @@ -282,17 +276,6 @@ static void rockchip_spi_set_cs(struct spi_device *spi, bool enable) rs->cs_asserted[spi->chip_select] = cs_asserted; } -static int rockchip_spi_prepare_message(struct spi_master *master, - struct spi_message *msg) -{ - struct rockchip_spi *rs = spi_master_get_devdata(master); - struct spi_device *spi = msg->spi; - - rs->mode = spi->mode; - - return 0; -} - static void rockchip_spi_handle_err(struct spi_master *master, struct spi_message *msg) { @@ -397,14 +380,15 @@ static void rockchip_spi_dma_txcb(void *data) spi_finalize_current_transfer(rs->master); } -static int rockchip_spi_prepare_dma(struct rockchip_spi *rs) +static int rockchip_spi_prepare_dma(struct rockchip_spi *rs, + struct spi_transfer *xfer) { struct dma_async_tx_descriptor *rxdesc, *txdesc; atomic_set(&rs->state, 0); rxdesc = NULL; - if (rs->rx) { + if (xfer->rx_buf) { struct dma_slave_config rxconf = { .direction = DMA_DEV_TO_MEM, .src_addr = rs->dma_rx.addr, @@ -416,7 +400,7 @@ static int rockchip_spi_prepare_dma(struct rockchip_spi *rs) rxdesc = dmaengine_prep_slave_sg( rs->dma_rx.ch, - rs->rx_sg.sgl, rs->rx_sg.nents, + xfer->rx_sg.sgl, xfer->rx_sg.nents, DMA_DEV_TO_MEM, DMA_PREP_INTERRUPT); if (!rxdesc) return -EINVAL; @@ -426,7 +410,7 @@ static int rockchip_spi_prepare_dma(struct rockchip_spi *rs) } txdesc = NULL; - if (rs->tx) { + if (xfer->tx_buf) { struct dma_slave_config txconf = { .direction = DMA_MEM_TO_DEV, .dst_addr = rs->dma_tx.addr, @@ -438,7 +422,7 @@ static int rockchip_spi_prepare_dma(struct rockchip_spi *rs) txdesc = dmaengine_prep_slave_sg( rs->dma_tx.ch, - rs->tx_sg.sgl, rs->tx_sg.nents, + xfer->tx_sg.sgl, xfer->tx_sg.nents, DMA_MEM_TO_DEV, DMA_PREP_INTERRUPT); if (!txdesc) { if (rxdesc) @@ -469,7 +453,8 @@ static int rockchip_spi_prepare_dma(struct rockchip_spi *rs) return 1; } -static void rockchip_spi_config(struct rockchip_spi *rs) +static void rockchip_spi_config(struct rockchip_spi *rs, + struct spi_device *spi, struct spi_transfer *xfer) { u32 div = 0; u32 dmacr = 0; @@ -481,13 +466,19 @@ static void rockchip_spi_config(struct rockchip_spi *rs) | CR0_EM_BIG << CR0_EM_OFFSET; cr0 |= (rs->n_bytes << CR0_DFS_OFFSET); - cr0 |= ((rs->mode & 0x3) << CR0_SCPH_OFFSET); - cr0 |= (rs->tmode << CR0_XFM_OFFSET); + cr0 |= (spi->mode & 0x3U) << CR0_SCPH_OFFSET; + + if (xfer->rx_buf && xfer->tx_buf) + cr0 |= CR0_XFM_TR << CR0_XFM_OFFSET; + else if (xfer->rx_buf) + cr0 |= CR0_XFM_RO << CR0_XFM_OFFSET; + else + cr0 |= CR0_XFM_TO << CR0_XFM_OFFSET; if (rs->use_dma) { - if (rs->tx) + if (xfer->tx_buf) dmacr |= TF_DMA_EN; - if (rs->rx) + if (xfer->rx_buf) dmacr |= RF_DMA_EN; } @@ -521,11 +512,11 @@ static void rockchip_spi_config(struct rockchip_spi *rs) writel_relaxed(cr0, rs->regs + ROCKCHIP_SPI_CTRLR0); if (rs->n_bytes == 1) - writel_relaxed(rs->len - 1, rs->regs + ROCKCHIP_SPI_CTRLR1); + writel_relaxed(xfer->len - 1, rs->regs + ROCKCHIP_SPI_CTRLR1); else if (rs->n_bytes == 2) - writel_relaxed((rs->len / 2) - 1, rs->regs + ROCKCHIP_SPI_CTRLR1); + writel_relaxed((xfer->len / 2) - 1, rs->regs + ROCKCHIP_SPI_CTRLR1); else - writel_relaxed((rs->len * 2) - 1, rs->regs + ROCKCHIP_SPI_CTRLR1); + writel_relaxed((xfer->len * 2) - 1, rs->regs + ROCKCHIP_SPI_CTRLR1); writel_relaxed(rs->fifo_len / 2 - 1, rs->regs + ROCKCHIP_SPI_TXFTLR); writel_relaxed(rs->fifo_len / 2 - 1, rs->regs + ROCKCHIP_SPI_RXFTLR); @@ -565,24 +556,12 @@ static int rockchip_spi_transfer_one( } rs->speed = xfer->speed_hz; - rs->bpw = xfer->bits_per_word; - rs->n_bytes = rs->bpw >> 3; + rs->n_bytes = xfer->bits_per_word >> 3; rs->tx = xfer->tx_buf; rs->tx_end = rs->tx + xfer->len; rs->rx = xfer->rx_buf; rs->rx_end = rs->rx + xfer->len; - rs->len = xfer->len; - - rs->tx_sg = xfer->tx_sg; - rs->rx_sg = xfer->rx_sg; - - if (rs->tx && rs->rx) - rs->tmode = CR0_XFM_TR; - else if (rs->tx) - rs->tmode = CR0_XFM_TO; - else if (rs->rx) - rs->tmode = CR0_XFM_RO; /* we need prepare dma before spi was enabled */ if (master->can_dma && master->can_dma(master, spi, xfer)) @@ -590,10 +569,10 @@ static int rockchip_spi_transfer_one( else rs->use_dma = false; - rockchip_spi_config(rs); + rockchip_spi_config(rs, spi, xfer); if (rs->use_dma) - return rockchip_spi_prepare_dma(rs); + return rockchip_spi_prepare_dma(rs, xfer); return rockchip_spi_pio_transfer(rs); } @@ -685,7 +664,6 @@ static int rockchip_spi_probe(struct platform_device *pdev) master->bits_per_word_mask = SPI_BPW_MASK(16) | SPI_BPW_MASK(8); master->set_cs = rockchip_spi_set_cs; - master->prepare_message = rockchip_spi_prepare_message; master->transfer_one = rockchip_spi_transfer_one; master->max_transfer_size = rockchip_spi_max_transfer_size; master->handle_err = rockchip_spi_handle_err; -- 2.19.1