Received: by 2002:a05:6500:1b41:b0:1fb:d597:ff75 with SMTP id cz1csp414496lqb; Tue, 4 Jun 2024 15:44:36 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUwl0X3xccGQAfcKikNle4KiTRrzlbnApuBXpoFPKMiw10Huvbsed1KRS4YzWweE/gwCBWrUc1nTQtrrFTfLih74JHQyhSzEV0FsSxLqg== X-Google-Smtp-Source: AGHT+IHckFiw9ldqu1w0Y0YcMJe9lx3gsxH6+sknKiIg8lzbFFjvxUgdKm/KEW2lmWO0LwaJVFjd X-Received: by 2002:a81:e20e:0:b0:61a:d372:8767 with SMTP id 00721157ae682-62cbb5d9164mr6467527b3.51.1717541075893; Tue, 04 Jun 2024 15:44:35 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717541075; cv=pass; d=google.com; s=arc-20160816; b=JBtw/q57ce7SSRvbxZ6wPCpnjbpWC4Wvk3s93MMeE5eN7PSWLSAAaw8qZZ2jfyHC4g yVyhz/zDV6jklUcw86oOjj0HLpxbuRKJXwQrPatWRYy2WMzIlzO+P9JdQvVTZ7NAcWx/ KcTSH+ngi8jFMBH7ZJtR/X0tkJmxqaNluuJHFFMkRO6Vv+yI3mbQ500KljStWvwtPVR+ gYvyzqln77dUtm2fSi88ZTtnw5UQkWjsZswcgPTayTI0XaB48ULznh/ZR51nDwv8sqbd e9ga6NtKWFh5LL7ph5A0pKSE6S5OmSW8OUmVKS3veYeNGPThyIAY+z/CT4K2nIxfc4ZE s7zg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=O9U8PJcD5IDk0qYWP994r3AXI1cEINGKghFuxXmAI2Y=; fh=yiyhowXsdmjdsRMxtNs14ebKrjK5yzXbB3teBSdOs0w=; b=K/qHWe7Jqxach+gQ+qUaj+2f8UyEtQMDPgHSzNGuaIfWmcBYoNdg6uReQzXaomTuVT 4ip7N/O09kwNkB6iVSfS5/5IYODvqUHDVbblKMeLXUutrQXjkgye1jhCKXcBrV4Lx2qF POvi5Bn5d4hOazNUf03gWH2VhU7eSizAv9/le7Lz2Mpa3dk7xYI9ng3EknKsi/WupU4e eIk46vH7ohZ3AOvs4KLW77jEgrysIxYlSf1MnkeNXgeG0p1FDef4GKeb0rESC0ERH+t2 zpQYsfiMzJFPMDSf0h9zYCkyJFOYAIgtEJO22HKNKyxJV7VoKACcvEX85xEkPloHH4WJ Kh5g==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@analog.com header.s=DKIM header.b="Rh0W9/sD"; arc=pass (i=1 spf=pass spfdomain=analog.com dkim=pass dkdomain=analog.com dmarc=pass fromdomain=analog.com); spf=pass (google.com: domain of linux-kernel+bounces-201503-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-201503-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=analog.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [2604:1380:45d1:ec00::1]) by mx.google.com with ESMTPS id 6a1803df08f44-6ae4a7423a2si12263166d6.152.2024.06.04.15.44.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Jun 2024 15:44:35 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-201503-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) client-ip=2604:1380:45d1:ec00::1; Authentication-Results: mx.google.com; dkim=pass header.i=@analog.com header.s=DKIM header.b="Rh0W9/sD"; arc=pass (i=1 spf=pass spfdomain=analog.com dkim=pass dkdomain=analog.com dmarc=pass fromdomain=analog.com); spf=pass (google.com: domain of linux-kernel+bounces-201503-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45d1:ec00::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-201503-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=analog.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 ny.mirrors.kernel.org (Postfix) with ESMTPS id 717421C2270E for ; Tue, 4 Jun 2024 22:43:05 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 4AAF614C5A7; Tue, 4 Jun 2024 22:42:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=analog.com header.i=@analog.com header.b="Rh0W9/sD" Received: from mx0a-00128a01.pphosted.com (mx0a-00128a01.pphosted.com [148.163.135.77]) (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 CE495146D78; Tue, 4 Jun 2024 22:42:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=148.163.135.77 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717540976; cv=none; b=J9ojv008vgrh5WJyhi0qi7rqeODiUX95Z59OTZLyyf6IhRg4UZ2WWKhE5w+E3y1W/rzGun1DBYUvI2DP3XS8jvKxblOwgLsDc88/fjN9wSE1B0n/RUS30LN2dWCB6nhCnflwWqYONUfw6UGmferAsbHEP6hQ6HRpYSxhUoMq1xs= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717540976; c=relaxed/simple; bh=3tG0AJ54V/5Ge91oaKIU30K3m3EKpg0kyY8NFuqZLls=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=BwTO20XsW4I8oVJmxbnzSM7ITVBIf69BjPB5uslVO0tilHgkZCeq/GiCp6N1H1oFbZNV8Q/uJi6RlL2JoXA+7Shj3UnZ6ehUWMBg5bjhCSg/4NU2d3ZI5YLo0ZWYchmdIh3BXQ3ptBtV/tLWuavJx2gUqZMEcymMyyUmfqiNTiA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=analog.com; spf=pass smtp.mailfrom=analog.com; dkim=pass (2048-bit key) header.d=analog.com header.i=@analog.com header.b=Rh0W9/sD; arc=none smtp.client-ip=148.163.135.77 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=analog.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=analog.com Received: from pps.filterd (m0167089.ppops.net [127.0.0.1]) by mx0a-00128a01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 454KLAGr030415; Tue, 4 Jun 2024 18:42:39 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=analog.com; h=cc :content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to; s=DKIM; bh=O9U8P JcD5IDk0qYWP994r3AXI1cEINGKghFuxXmAI2Y=; b=Rh0W9/sDOBSr8aq/cR+5y IZszR0KKxLlle4O5BGAfL+0Ie50gwHt741MJbMxD2o+rpODsNfV2dNxqipl/drB3 f58fG06UsxHQU+AsJNuAQhma3RIdkQ5htdcJMVEy9SbvMoiM65g9C0ptSB7hZvKe XAEzl9gJ/7XJ77jShHxK8dbvPKNRLLR1FN6rol/4nIEI1YXOsnzXrdpAuUgd9dmZ nPv+yi8LNnTVN4BSantLjI3p0JHL6jYlCaUs5RTAF9HAm3mgNtzdYfvayLmhimCg 2/A1V2d4n/JvfpQh7DbtPaSK7+YSNdftBS0qutkln1UGNFc7GFOSTBjdlffJuen1 Q== Received: from nwd2mta3.analog.com ([137.71.173.56]) by mx0a-00128a01.pphosted.com (PPS) with ESMTPS id 3yg0j1ms0y-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 04 Jun 2024 18:42:39 -0400 (EDT) Received: from ASHBMBX9.ad.analog.com (ASHBMBX9.ad.analog.com [10.64.17.10]) by nwd2mta3.analog.com (8.14.7/8.14.7) with ESMTP id 454Mgcod011020 (version=TLSv1/SSLv3 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Tue, 4 Jun 2024 18:42:38 -0400 Received: from ASHBCASHYB4.ad.analog.com (10.64.17.132) by ASHBMBX9.ad.analog.com (10.64.17.10) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.14; Tue, 4 Jun 2024 18:42:37 -0400 Received: from ASHBMBX9.ad.analog.com (10.64.17.10) by ASHBCASHYB4.ad.analog.com (10.64.17.132) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.986.14; Tue, 4 Jun 2024 18:42:37 -0400 Received: from zeus.spd.analog.com (10.66.68.11) by ashbmbx9.ad.analog.com (10.64.17.10) with Microsoft SMTP Server id 15.2.986.14 via Frontend Transport; Tue, 4 Jun 2024 18:42:36 -0400 Received: from work.ad.analog.com (HYB-hERzalRezfV.ad.analog.com [10.65.205.129]) by zeus.spd.analog.com (8.15.1/8.15.1) with ESMTP id 454MgNiC001185; Tue, 4 Jun 2024 18:42:25 -0400 From: Marcelo Schmitt To: , , , , , , , , , CC: , , , Subject: [PATCH v3 2/6] spi: bitbang: Implement support for MOSI idle state configuration Date: Tue, 4 Jun 2024 19:42:21 -0300 Message-ID: <811a2771d93c16b48fb37286e648a03171c8d2bc.1717539384.git.marcelo.schmitt@analog.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ADIRuleOP-NewSCL: Rule Triggered X-Proofpoint-ORIG-GUID: 74Ay1pOxbiNWrZiqDog6XX2t6ko0SQaD X-Proofpoint-GUID: 74Ay1pOxbiNWrZiqDog6XX2t6ko0SQaD X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1039,Hydra:6.0.680,FMLib:17.12.28.16 definitions=2024-06-04_11,2024-06-04_02,2024-05-17_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 suspectscore=0 bulkscore=0 spamscore=0 clxscore=1015 mlxlogscore=999 phishscore=0 malwarescore=0 priorityscore=1501 mlxscore=0 lowpriorityscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2405170001 definitions=main-2406040183 Some SPI peripherals may require strict MOSI line state when the controller is not clocking out data. Implement support for MOSI idle state configuration (low or high) by setting the data output line level on controller setup and after transfers. Bitbang operations now call controller specific set_mosi_idle() call back to set MOSI to its idle state. The MOSI line is kept at its idle state if no tx buffer is provided. Signed-off-by: Marcelo Schmitt --- drivers/spi/spi-bitbang.c | 24 ++++++++++++++++++++++++ include/linux/spi/spi_bitbang.h | 1 + 2 files changed, 25 insertions(+) diff --git a/drivers/spi/spi-bitbang.c b/drivers/spi/spi-bitbang.c index ca5cc67555c5..3dee085d3570 100644 --- a/drivers/spi/spi-bitbang.c +++ b/drivers/spi/spi-bitbang.c @@ -63,21 +63,28 @@ static unsigned bitbang_txrx_8( unsigned flags ) { + struct spi_bitbang *bitbang; unsigned bits = t->bits_per_word; unsigned count = t->len; const u8 *tx = t->tx_buf; u8 *rx = t->rx_buf; + bitbang = spi_controller_get_devdata(spi->controller); while (likely(count > 0)) { u8 word = 0; if (tx) word = *tx++; + else + word = (spi->mode & SPI_MOSI_IDLE_HIGH) ? 0xFF : 0; word = txrx_word(spi, ns, word, bits, flags); if (rx) *rx++ = word; count -= 1; } + if (bitbang->set_mosi_idle) + bitbang->set_mosi_idle(spi); + return t->len - count; } @@ -92,21 +99,28 @@ static unsigned bitbang_txrx_16( unsigned flags ) { + struct spi_bitbang *bitbang; unsigned bits = t->bits_per_word; unsigned count = t->len; const u16 *tx = t->tx_buf; u16 *rx = t->rx_buf; + bitbang = spi_controller_get_devdata(spi->controller); while (likely(count > 1)) { u16 word = 0; if (tx) word = *tx++; + else + word = (spi->mode & SPI_MOSI_IDLE_HIGH) ? 0xFFFF : 0; word = txrx_word(spi, ns, word, bits, flags); if (rx) *rx++ = word; count -= 2; } + if (bitbang->set_mosi_idle) + bitbang->set_mosi_idle(spi); + return t->len - count; } @@ -121,21 +135,28 @@ static unsigned bitbang_txrx_32( unsigned flags ) { + struct spi_bitbang *bitbang; unsigned bits = t->bits_per_word; unsigned count = t->len; const u32 *tx = t->tx_buf; u32 *rx = t->rx_buf; + bitbang = spi_controller_get_devdata(spi->controller); while (likely(count > 3)) { u32 word = 0; if (tx) word = *tx++; + else + word = (spi->mode & SPI_MOSI_IDLE_HIGH) ? 0xFFFFFFFF : 0; word = txrx_word(spi, ns, word, bits, flags); if (rx) *rx++ = word; count -= 4; } + if (bitbang->set_mosi_idle) + bitbang->set_mosi_idle(spi); + return t->len - count; } @@ -211,6 +232,9 @@ int spi_bitbang_setup(struct spi_device *spi) goto err_free; } + if (bitbang->set_mosi_idle) + bitbang->set_mosi_idle(spi); + dev_dbg(&spi->dev, "%s, %u nsec/bit\n", __func__, 2 * cs->nsecs); return 0; diff --git a/include/linux/spi/spi_bitbang.h b/include/linux/spi/spi_bitbang.h index b930eca2ef7b..1a54b593c691 100644 --- a/include/linux/spi/spi_bitbang.h +++ b/include/linux/spi/spi_bitbang.h @@ -22,6 +22,7 @@ struct spi_bitbang { #define BITBANG_CS_ACTIVE 1 /* normally nCS, active low */ #define BITBANG_CS_INACTIVE 0 + void (*set_mosi_idle)(struct spi_device *spi); /* txrx_bufs() may handle dma mapping for transfers that don't * already have one (transfer.{tx,rx}_dma is zero), or use PIO */ -- 2.43.0