Received: by 2002:a05:7412:798b:b0:fc:a2b0:25d7 with SMTP id fb11csp845599rdb; Fri, 23 Feb 2024 01:33:18 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVoPrLG8rjQHmi8yr2JJE+2cuY9a+th4++2VHB1cV5tHTkLjkTgamW7WCDOvnlgxSl7g71JZgdXQPLIJ6z1lzl2jmc1Hz4NKNn84zkPyg== X-Google-Smtp-Source: AGHT+IE+kyaNd1BpzCBEWQT/Up0mpbmEaH5lsHTxNRir2WsnB67/L8/maSXJF1NuJLW3PnNHjZU9 X-Received: by 2002:a05:6870:55d4:b0:21e:6e02:2793 with SMTP id qk20-20020a05687055d400b0021e6e022793mr1491562oac.47.1708680798359; Fri, 23 Feb 2024 01:33:18 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1708680798; cv=pass; d=google.com; s=arc-20160816; b=y/XFZJXgloOw4Z5jqhhFq01KgKAs9sHxl4DA5ZGuLxAGoHzcJfhXoOXTsLJWV0a0GL 4G9dAS1oUoUxhzfk/EHnb+90iV+tZEczzK7e3TjIWpv3Gz4dJOtNIIa3UnnBQl+cGyC5 77CrHOc7HpH6U9JM5mzK1nDVkCHIdcClUrtdF1TAeDCT8TOp2Ub/op+wPEKM1iA6bpTj zOarxKFq89+vQ1QEG+KXzb27Mf/5InicfjWqars66CAjBCsnyqaWYfoBXfVhCWyRJFa9 l3G1xeCyIR+SIsyJs28SH5vGpB2ep4L479u/ytJFcI8kAb24phqOgT0WWWGCJ1U9HpaM VR8g== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=cc:to:in-reply-to:references:message-id:content-transfer-encoding :mime-version:list-unsubscribe:list-subscribe:list-id:precedence :subject:date:from:dkim-signature; bh=18CMWR936xnkrAvlSXRbSNlRO5ba3pEra3S0AcHTwKg=; fh=eI8HjExr0WsH9IWVPxvbaDTOw70phhIumkj8bsjnk/U=; b=CJT3AhyWG1nQ+0NMzEucE4t6/Dveqn6x+ohcVbxCakdPjfp9rWBUD+w9sBy/7w6SKP nwajSKYWnAUnk6mia4YogbK7521eLzGKxNdIP9pIvTUivdKDkPH0IUCnSNXxtaAqLJ38 7hchiBGiqaQj7wHRApFpySM2BHkmqySQvvLQdEM54/guQP7RTnhnYAq4N4eJR9RaaPI3 d6t2coJBe4G1ent+e2PKmrj9VBVTo1pfyRLPkYR1ImYdjxGk30gqKnyBlFIhrvv5lfdM d3gfAkxWeXRmC+gsRayVtS7EmyQ+A66Y4rfuuwrN6yoC7mQD42n2GY9t4SVZj1idzGj8 ty/w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=Sa9FhaQb; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-78019-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-78019-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id l25-20020a63ba59000000b005dc4e7d879csi12052984pgu.66.2024.02.23.01.33.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 23 Feb 2024 01:33:18 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-78019-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=Sa9FhaQb; arc=pass (i=1 spf=pass spfdomain=bootlin.com dkim=pass dkdomain=bootlin.com dmarc=pass fromdomain=bootlin.com); spf=pass (google.com: domain of linux-kernel+bounces-78019-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-78019-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 0B0272863DA for ; Fri, 23 Feb 2024 09:33:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id D5F3F17BAC; Fri, 23 Feb 2024 09:32:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="Sa9FhaQb" Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [217.70.183.200]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A0A6D5C8FE; Fri, 23 Feb 2024 09:32:55 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.200 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708680777; cv=none; b=GeJwK+syPlwB7o/VDGpHui9jbX9ItvazbBuHyMa2226vW2Lg6/+Acer0U/0HFd7I9lDa9RgbZQlRp4vJ/ATV+sXS5sMVTovYBFCZ4amfaFoaekTMaKisza0u336a2M0jFLgzwqk/VbUrQx/CcPYlYMGDDjJ3Gr8BTlx2Ukm8+eA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708680777; c=relaxed/simple; bh=REkJW6D+RJj2jvyMJPDaFLG/dTj5svrfGt9foiTBjY8=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=b50VGpie0QdV98iUMmh2Gn1Mhou7vz2v8hT928RWFTCkBN8dDjuvPtEwZ1OEistrduNuviEpoL1mlZuau8eKHnqQ6SVwamoeGvdyfrjxRyxaPpkWBMuXjDlsyLOodJ05OtawSkb+6s7NLrg6deVC3WtfKBvwoglTGYMztgunQ8M= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com; spf=pass smtp.mailfrom=bootlin.com; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b=Sa9FhaQb; arc=none smtp.client-ip=217.70.183.200 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=bootlin.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=bootlin.com Received: by mail.gandi.net (Postfix) with ESMTPSA id C576720007; Fri, 23 Feb 2024 09:32:47 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1708680768; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=18CMWR936xnkrAvlSXRbSNlRO5ba3pEra3S0AcHTwKg=; b=Sa9FhaQbqqqrmjHHaac/7v6EuFYGJ+hgOm/wYhunzDVXtP446su8rwD0jG64kpSji8fstq WVNgvxXmp5aiSLCpktDgXcosvgYfIqt059Nsu227QlJawU/mboKTWaF1WmcH77ESpUKVAX 3mTuBkjrAvuzrHKn770M2Ejw+xz834iQNt8YM05vaZpVMdMFsf0uplTACAwgPH4pDE1HbC AgrkU6GtGfa0NM8OOOSyNLDKlorbn+4XB+koCoIybL5ZDjQC1Itle+Euu4mw+5c9DwSdzq sl34i61DkZ76pbmNSyh4MFLaCnnl1LahhdzdowJgPAPw867+7EGJFHKmVCc8kQ== From: Louis Chauvet Date: Fri, 23 Feb 2024 10:32:12 +0100 Subject: [PATCH v2 2/3] spi: omap2-mcspi: Add support for MULTI-mode Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: <20240223-spi-omap2-mcspi-multi-mode-v2-2-afe94476b9c3@bootlin.com> References: <20240223-spi-omap2-mcspi-multi-mode-v2-0-afe94476b9c3@bootlin.com> In-Reply-To: <20240223-spi-omap2-mcspi-multi-mode-v2-0-afe94476b9c3@bootlin.com> To: Mark Brown Cc: linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, thomas.petazzoni@bootlin.com, Miquel Raynal , yen-mei.goh@keysight.com, koon-kee.lie@keysight.com, jeremie.dautheribes@bootlin.com, Louis Chauvet X-Mailer: b4 0.13.0 X-Developer-Signature: v=1; a=openpgp-sha256; l=4770; i=louis.chauvet@bootlin.com; h=from:subject:message-id; bh=REkJW6D+RJj2jvyMJPDaFLG/dTj5svrfGt9foiTBjY8=; b=owEBbQKS/ZANAwAIASCtLsZbECziAcsmYgBl2GY3p7zkPy+VwQpD9XFH8rnxtAdeFSf8ySDohptW w4uVlYSJAjMEAAEIAB0WIQRPj7g/vng8MQxQWQQgrS7GWxAs4gUCZdhmNwAKCRAgrS7GWxAs4k50EA Ce0IEV895NOdDJXW+ddeg26Z9nT6amZJM74O/1Bq+bRck82AaZRcqiPWn5Rp+fVWAI1NVZdPoG0m6j nqzzvhB6aSxonbFKRRZye7Aj0qTTW9vSPsu3xg02o/p48QrKKvFpRfdTZPYI3jMpaBuhcohA3yKhp2 IyoV3Prgjj3GD2KL5BnddbjqWJc+M6ShWICTQSQiTUHjbXSXz42SykIrGLAdoEp32D/BAi9/epA6T/ 52/mo9J2mkZDqNiaYhxEJlxFWe/wPk7oaSerzhYDm2lQV37WuXDeWBPKvBB5VyKR2hqvTcDRWOA7R+ OfV+gGXG5JgTXgH2oS+08ySxPqDqIZV8uludN32aqsIL7ufdlhXofUHkjBhjn7xNZjkN1TEgNWVn42 VWzIhEBt+dUDZfsQIWYpsSI2vrgKqvdHHqgxhNcPmHkH9IupgW+Esh/skE5lb9uRf4tObVhRTvY8kk 9CGa3/37jWtBc7cmasfErDHDDG5nyC9KMbK9SQHf5yJoFxk0+6u+A3yYXUHG/CpRxE3hFdDSqholtQ pvXyjzxCeGBwQIA4aF7p1pEMgM7FV7EfLImyFWxznSYLyBhDhldl0gZDLfNnUk+eYj/4z3p1k/hd+i TrSJ1YTLxB7jwI7hMuQRus+oIosgR/gkkPNWr7XuROpeZ/aVjxTvEiTP+5qg== X-Developer-Key: i=louis.chauvet@bootlin.com; a=openpgp; fpr=8B7104AE9A272D6693F527F2EC1883F55E0B40A5 X-GND-Sasl: louis.chauvet@bootlin.com Introduce support for MULTI-mode in the OMAP2 MCSPI driver. Currently, the driver always uses SINGLE mode to handle the chip select (CS). With this enhancement, MULTI-mode is enabled for specific messages, allowing for a shorter delay between CS enable and the message (some FPGA devices are sensitive to this delay). The OMAP2 MCSPI device can use two different mode to send messages, SINGLE and MULTI: In SINGLE mode, the controller only leverages one single FIFO, and the host system has to manually select the CS it wants to enable. In MULTI mode, each CS is bound to a FIFO, the host system then writes the data to the relevant FIFO, as the hardware will take care of the CS The drawback of multi-mode is that it's not possible to keep the CS enabled between each words. Therefore, this patch enables multi-mode only for specific messages: the spi_message must contain only spi_transfer of 1 word (of any size) with cs_change enabled. A new member is introduced in the omap2_mcspi structure to keep track of the current used mode. Signed-off-by: Louis Chauvet --- drivers/spi/spi-omap2-mcspi.c | 67 +++++++++++++++++++++++++++++++++++++++---- 1 file changed, 62 insertions(+), 5 deletions(-) diff --git a/drivers/spi/spi-omap2-mcspi.c b/drivers/spi/spi-omap2-mcspi.c index fc7f69973334..36075c4416d5 100644 --- a/drivers/spi/spi-omap2-mcspi.c +++ b/drivers/spi/spi-omap2-mcspi.c @@ -133,6 +133,7 @@ struct omap2_mcspi { unsigned int pin_dir:1; size_t max_xfer_len; u32 ref_clk_hz; + bool use_multi_mode; }; struct omap2_mcspi_cs { @@ -258,10 +259,15 @@ static void omap2_mcspi_set_cs(struct spi_device *spi, bool enable) l = mcspi_cached_chconf0(spi); - if (enable) + /* Only enable chip select manually if single mode is used */ + if (mcspi->use_multi_mode) { l &= ~OMAP2_MCSPI_CHCONF_FORCE; - else - l |= OMAP2_MCSPI_CHCONF_FORCE; + } else { + if (enable) + l &= ~OMAP2_MCSPI_CHCONF_FORCE; + else + l |= OMAP2_MCSPI_CHCONF_FORCE; + } mcspi_write_chconf0(spi, l); @@ -285,7 +291,12 @@ static void omap2_mcspi_set_mode(struct spi_controller *ctlr) l |= (OMAP2_MCSPI_MODULCTRL_MS); } else { l &= ~(OMAP2_MCSPI_MODULCTRL_MS); - l |= OMAP2_MCSPI_MODULCTRL_SINGLE; + + /* Enable single mode if needed */ + if (mcspi->use_multi_mode) + l &= ~OMAP2_MCSPI_MODULCTRL_SINGLE; + else + l |= OMAP2_MCSPI_MODULCTRL_SINGLE; } mcspi_write_reg(ctlr, OMAP2_MCSPI_MODULCTRL, l); @@ -1371,15 +1382,61 @@ static int omap2_mcspi_prepare_message(struct spi_controller *ctlr, struct omap2_mcspi *mcspi = spi_controller_get_devdata(ctlr); struct omap2_mcspi_regs *ctx = &mcspi->ctx; struct omap2_mcspi_cs *cs; + struct spi_transfer *tr; + bool word_delay_is_zero; + u8 bits_per_word; + + /* + * The conditions are strict, it is mandatory to check each transfer of the list to see if + * multi-mode is applicable. + */ + mcspi->use_multi_mode = true; + list_for_each_entry(tr, &msg->transfers, transfer_list) { + if (!tr->bits_per_word) + bits_per_word = msg->spi->bits_per_word; + else + bits_per_word = tr->bits_per_word; /* Only a single channel can have the FORCE bit enabled + /* + * Check if this transfer contains only one word; + */ + if (bits_per_word < 8 && tr->len == 1) { + /* multi-mode is applicable, only one word (1..7 bits) */ + } else if (bits_per_word >= 8 && tr->len == bits_per_word / 8) { + /* multi-mode is applicable, only one word (8..32 bits) */ + } else { + /* multi-mode is not applicable: more than one word in the transfer */ + mcspi->use_multi_mode = false; + } + + /* Check if transfer asks to change the CS status after the transfer */ + if (!tr->cs_change) + mcspi->use_multi_mode = false; + + /* + * If at least one message is not compatible, switch back to single mode + * + * The bits_per_word of certain transfer can be different, but it will have no + * impact on the signal itself. + */ + if (!mcspi->use_multi_mode) + break; + } + + omap2_mcspi_set_mode(ctlr); + + /* In single mode only a single channel can have the FORCE bit enabled * in its chconf0 register. * Scan all channels and disable them except the current one. * A FORCE can remain from a last transfer having cs_change enabled + * + * In multi mode all FORCE bits must be disabled. */ list_for_each_entry(cs, &ctx->cs, node) { - if (msg->spi->controller_state == cs) + if (msg->spi->controller_state == cs && !mcspi->use_multi_mode) { continue; + } if ((cs->chconf0 & OMAP2_MCSPI_CHCONF_FORCE)) { cs->chconf0 &= ~OMAP2_MCSPI_CHCONF_FORCE; -- 2.43.0