Received: by 2002:ac0:a5a6:0:0:0:0:0 with SMTP id m35-v6csp4458188imm; Mon, 17 Sep 2018 14:24:35 -0700 (PDT) X-Google-Smtp-Source: ANB0VdYmajP2n12Lpctm3T2nADAeP6yvJ3LJp1SnBojJX4UdvlCX4dPodV4o/IbISk+Tspd9KDB3 X-Received: by 2002:a63:3c5c:: with SMTP id i28-v6mr24864718pgn.415.1537219475278; Mon, 17 Sep 2018 14:24:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1537219475; cv=none; d=google.com; s=arc-20160816; b=CGS0ayGBkK+aJJqQUBl8DWilbq2fOSx/TjPP8a3EnbmPm/b0Ju26RQFa7mnjHqW2vK lTex/bWWcDOvxgxCUKW4RTkGPJVSlq76lZMDmx1lcEPGXf3gdZx01GozvHaz6fis7M7e b5VyaYFGQMsmWj5kT4LhgGZvxT8kRrlI3PCOig+3vRASJm+bLpVReHAQpmtskrNOWnW0 Si6M3jNWVEANyuuAnfbt4dkkeX3ms6FvMtwg+MdCPFBfne9gDcMF4irRMBTyCi/8xjug lCT8PRhfTeUadufy2Bs3dhFOlDOcTOoR2+CCSQ+Or8PXWnTD2dJjjGVIw84nXMROFgV9 hjnA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:date:message-id:in-reply-to:subject:cc:to :from:dkim-signature; bh=lpxRl4lfcEj3mFGEkyL8txqqlmOEI4IENjKywm+todE=; b=YZxnHOg8PsRqQsMYjpZTlmRzU8jxP48NjCuqsyPQx/+Tayvk+p6VwipBV32tLNGVIO 7lNbFedWNrwnigLUYc2wPNnUinmQV2yaumCXFOMxXKDhus73VsKCqqDjIjlQWdtdyTbP XZM0z2KSp/pVBOAFXiTUkN/INsc1L76nHqD+6topsHgdyOoRYPNLLCRtdqrJhHr/fjsq YXScb2sS2LwCnkzO0ac7Ffg/7pl8TPrTBw/7imvHJYVYead6tXVAvamIKszAZInnx+/l CbU+rskwQo1/M33uHYiICn57nS9wWsD0oJ08OmJAkK5vljdKTFN0TxQ8jNG6iCCRxQQr runw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@sirena.org.uk header.s=20170815-heliosphere header.b=NHaLbDvj; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bd3-v6si16421350plb.382.2018.09.17.14.24.20; Mon, 17 Sep 2018 14:24:35 -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=@sirena.org.uk header.s=20170815-heliosphere header.b=NHaLbDvj; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728561AbeIRCwB (ORCPT + 99 others); Mon, 17 Sep 2018 22:52:01 -0400 Received: from heliosphere.sirena.org.uk ([172.104.155.198]:42328 "EHLO heliosphere.sirena.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726844AbeIRCwB (ORCPT ); Mon, 17 Sep 2018 22:52:01 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sirena.org.uk; s=20170815-heliosphere; h=Date:Message-Id:In-Reply-To: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:References: List-Id:List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner: List-Archive; bh=lpxRl4lfcEj3mFGEkyL8txqqlmOEI4IENjKywm+todE=; b=NHaLbDvjSjLU pfc2O1+OnmAPQM+E5s/2SqTZTSE+PoqgIBBRP6gk94sQqbmSApXNoYv/kUXrKff7sxAyNkFKivD8j ZlwbCsKYzY2lswgvB7azaO7olaufbC/kDTtAE8lK9E5RaApw4R+PKrM9Svn8TN6uCR0lIIsME6Iab LHJwI=; Received: from [209.121.128.187] (helo=finisterre.ee.mobilebroadband) by heliosphere.sirena.org.uk with esmtpsa (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.89) (envelope-from ) id 1g20yT-0000l2-Fy; Mon, 17 Sep 2018 21:22:29 +0000 Received: by finisterre.ee.mobilebroadband (Postfix, from userid 1000) id 9D661440079; Mon, 17 Sep 2018 22:22:27 +0100 (BST) From: Mark Brown To: David Lechner Cc: Jonathan Cameron , Mark Brown , linux-spi@vger.kernel.org, linux-iio@vger.kernel.org, Jonathan Cameron , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , Mark Brown , linux-kernel@vger.kernel.org, linux-spi@vger.kernel.org Subject: Applied "spi: add software implementation for SPI_CS_WORD" to the spi tree In-Reply-To: <20180913003920.30600-3-david@lechnology.com> Message-Id: <20180917212227.9D661440079@finisterre.ee.mobilebroadband> Date: Mon, 17 Sep 2018 22:22:27 +0100 (BST) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The patch spi: add software implementation for SPI_CS_WORD has been applied to the spi tree at https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git All being well this means that it will be integrated into the linux-next tree (usually sometime in the next 24 hours) and sent to Linus during the next merge window (or sooner if it is a bug fix), however if problems are discovered then the patch may be dropped or reverted. You may get further e-mails resulting from automated or manual testing and review of the tree, please engage with people reporting problems and send followup patches addressing any issues that are reported if needed. If any updates are required or you are submitting further changes they should be sent as incremental updates against current git, existing patches will not be replaced. Please add any relevant lists and maintainers to the CCs when replying to this mail. Thanks, Mark From cbaa62e0094a840fecc853910e0c0454529cec03 Mon Sep 17 00:00:00 2001 From: David Lechner Date: Wed, 12 Sep 2018 19:39:18 -0500 Subject: [PATCH] spi: add software implementation for SPI_CS_WORD This adds a default software implementation for the SPI_CS_WORD flag for controllers that don't have such a feature. The SPI_CS_WORD flag indicates that the CS line should be toggled between each word sent, not just between each transfer. The implementation works by using existing functions to split transfers into one-word-sized transfers and sets the cs_change bit for each of the new transfers. Signed-off-by: David Lechner Acked-by: Jonathan Cameron Signed-off-by: Mark Brown --- drivers/spi/spi.c | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index ec395a6baf9c..be73d236919f 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -2774,8 +2774,10 @@ int spi_setup(struct spi_device *spi) return -EINVAL; /* help drivers fail *cleanly* when they need options * that aren't supported with their current controller + * SPI_CS_WORD has a fallback software implementation, + * so it is ignored here. */ - bad_bits = spi->mode & ~spi->controller->mode_bits; + bad_bits = spi->mode & ~(spi->controller->mode_bits | SPI_CS_WORD); ugly_bits = bad_bits & (SPI_TX_DUAL | SPI_TX_QUAD | SPI_RX_DUAL | SPI_RX_QUAD); if (ugly_bits) { @@ -2829,6 +2831,33 @@ static int __spi_validate(struct spi_device *spi, struct spi_message *message) if (list_empty(&message->transfers)) return -EINVAL; + /* If an SPI controller does not support toggling the CS line on each + * transfer (indicated by the SPI_CS_WORD flag), we can emulate it by + * splitting transfers into one-word transfers and ensuring that + * cs_change is set for each transfer. + */ + if ((spi->mode & SPI_CS_WORD) && !(ctlr->mode_bits & SPI_CS_WORD)) { + size_t maxsize; + int ret; + + maxsize = (spi->bits_per_word + 7) / 8; + + /* spi_split_transfers_maxsize() requires message->spi */ + message->spi = spi; + + ret = spi_split_transfers_maxsize(ctlr, message, maxsize, + GFP_KERNEL); + if (ret) + return ret; + + list_for_each_entry(xfer, &message->transfers, transfer_list) { + /* don't change cs_change on the last entry in the list */ + if (list_is_last(&xfer->transfer_list, &message->transfers)) + break; + xfer->cs_change = 1; + } + } + /* Half-duplex links include original MicroWire, and ones with * only one data pin like SPI_3WIRE (switches direction) or where * either MOSI or MISO is missing. They can also be caused by -- 2.19.0