Received: by 2002:ab2:6d45:0:b0:1fb:d597:ff75 with SMTP id d5csp268991lqr; Wed, 5 Jun 2024 05:47:13 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCVqfhMoBkzHTquW0ZOWHNq/Y/PBCBU9hQCotWJwwD1KeUcTehdUfanGaG9xFeBDcoBBkacOxwyJ3khCT2nBSI00UDAkJyaapJJFKcxBUw== X-Google-Smtp-Source: AGHT+IESBZqbS/ZleJv1bq67rCoqz77KwjcxOVkFgrHAbA54li09rogBxlsXUNOiJiaOQmVFX4Qh X-Received: by 2002:a05:6a00:2da1:b0:6ea:df65:ff7d with SMTP id d2e1a72fcca58-703e597a59amr2693650b3a.10.1717591633171; Wed, 05 Jun 2024 05:47:13 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1717591633; cv=pass; d=google.com; s=arc-20160816; b=ZCdZWAZp+sKiFtskR/pEaxG3OqQur7V5vTdufIlBO9a5OVhL+/ta7nSJ/e2Y+y0feR o/tFFsWr8J6CzfefgXpNUzMmL9QUwgTLtHWpgYBmihbGKZczUbFQrgfE+vB0RiLZYn3e NTdVs3AXJkYC+8clcG9gxge0DERgT178D52B0JUVV/NX+nYbHtDHQM/mXuQhy+ec557r 80VrWmZ5fUrejhwIkvtr8zMJFvWEVP1R5Kd2HNyLA3dgqTMv1V6DfMWCuooMWm75lv+f V4AwmtvsTepNDYwey3o41OaPc2F4MxBwUFhQRhdwmptA6Q/XZjDTfjNwsdWB1M4o8T5Y S3Jw== 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=/TTfPDcDM7eWCEDJnErjsKg7Ks2KuATfPqRxZP9Bwi4=; fh=srJwOi1zWvrMgPs3L80QV/aWjEWmvND1C6LR5ho25jI=; b=FgINSOnQygAcjMTv9Z4axJLD6OB5y7wcAc++hlT6m+o1vy3MtxdiXBYmGHdMAEIXHr 25UgBrShP4ipTz51fn8D1shCRW6eD7k7s+E68zGzrakeY7bfL2IkJZ3qU6LXsph0PniN Rsz/Z5yKAfdFpMJwhLcA5nKAmXUJ6z2xpokjTQN3xOeKqWtWMIDM6ykay5usgaktXl7i CYeuVByhvmhvHXnLTPa2wKVvImqcEErD7+umTURKrw1gnz6tG6NZyr/b1nw+6r7wdcQb hwU01CtqgXEH4A3dJGVV77ZoTmAHS5/DaLSRRcUBkOVtuiwQ52PZelBzSzcTbacIprHi KeCQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=iiaU9VjM; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-202488-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-202488-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id 41be03b00d2f7-6c3540fb193si10487328a12.63.2024.06.05.05.47.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Jun 2024 05:47:13 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-202488-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=iiaU9VjM; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-kernel+bounces-202488-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-202488-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org 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 5B2D428573A for ; Wed, 5 Jun 2024 12:38:00 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id F16001C4B79; Wed, 5 Jun 2024 12:03:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="iiaU9VjM" Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (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 0FF7E1C4B5F; Wed, 5 Jun 2024 12:03:41 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717589021; cv=none; b=lGwLfJc57Ol4D+uP0T6+5/fvo1xW76dEI+T8wScJzl2ZZGMHSX/F1EX60ZvqNg2T4nukOv4qiXtcEJ0itWc/igQYTPiqdk/tI9k+o5stDoB8cQ4L2pDLPkLpjKYDiyc3n9okzRVwAvJjqhLZi9IhwROhsQuWsQi+P6NThHjDppQ= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717589021; c=relaxed/simple; bh=miWF0EhdzQHWTZJygReqmuJhFVGFLmr1odB17pUnQiI=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JwXxMzVEc+47q68rmggRpP3G/MJKCSrraxWm3uw49UIBwYmPa/AnNxzWaU/K7eXNmNvkdg0rXYi///GK39Fx1naRI32UEt4mtCE2482iDEWwWItiJYG9kKfLonfBo+gq9WCVPcAXnnip4p1thWKv6eY+65+YR8SN2cYIr4sDoKk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=iiaU9VjM; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id 31CDEC3277B; Wed, 5 Jun 2024 12:03:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1717589020; bh=miWF0EhdzQHWTZJygReqmuJhFVGFLmr1odB17pUnQiI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=iiaU9VjMp+z24bAtserjnpD2IuJQHd+78Mm2fXJrgJkQNE2SMey2CaPVxWZ0oZqhB wF+NxMEZrp+5xmH5x8Lbz83vYEIDkMZD/IaWbmVJAR6JGiDML4/M65Jx51vaxxDd4p HZCqpqeoFjOG/lyYW+Ka2iSlScaBJ3l/3EIZs98dCGUjFmzyn0fBcph/y1QuuIIu3L SOx+r1M9SF9/wAzI2QHFn1Habjpl4yCWpUkkThOJO0Oz6HcqbJ9T5Qv9+FIC8WW+II yeXpEr4Fe9BZcmcgeeA8orsKSWuh75EWAazynJOBl02idz4XFG2OEcY1dUDfhmFVPg RBzIstqpAV4rQ== From: Sasha Levin To: linux-kernel@vger.kernel.org, stable@vger.kernel.org Cc: Witold Sadowski , Mark Brown , Sasha Levin , linux-spi@vger.kernel.org Subject: [PATCH AUTOSEL 6.8 13/18] spi: cadence: Ensure data lines set to low during dummy-cycle period Date: Wed, 5 Jun 2024 08:03:03 -0400 Message-ID: <20240605120319.2966627-13-sashal@kernel.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240605120319.2966627-1-sashal@kernel.org> References: <20240605120319.2966627-1-sashal@kernel.org> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-stable: review X-Patchwork-Hint: Ignore X-stable-base: Linux 6.8.12 Content-Transfer-Encoding: 8bit From: Witold Sadowski [ Upstream commit 4a69c1264ff41bc5bf7c03101ada0454fbf08868 ] During dummy-cycles xSPI will switch GPIO into Hi-Z mode. In that dummy period voltage on data lines will slowly drop, what can cause unintentional modebyte transmission. Value send to SPI memory chip will depend on last address, and clock frequency. To prevent unforeseen consequences of that behaviour, force send single modebyte(0x00). Modebyte will be send only if number of dummy-cycles is not equal to 0. Code must also reduce dummycycle byte count by one - as one byte is send as modebyte. Signed-off-by: Witold Sadowski Link: https://msgid.link/r/20240529074037.1345882-2-wsadowski@marvell.com Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- drivers/spi/spi-cadence-xspi.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/drivers/spi/spi-cadence-xspi.c b/drivers/spi/spi-cadence-xspi.c index 8648b8eb080dc..cdce2e280f663 100644 --- a/drivers/spi/spi-cadence-xspi.c +++ b/drivers/spi/spi-cadence-xspi.c @@ -145,6 +145,9 @@ #define CDNS_XSPI_STIG_DONE_FLAG BIT(0) #define CDNS_XSPI_TRD_STATUS 0x0104 +#define MODE_NO_OF_BYTES GENMASK(25, 24) +#define MODEBYTES_COUNT 1 + /* Helper macros for filling command registers */ #define CDNS_XSPI_CMD_FLD_P1_INSTR_CMD_1(op, data_phase) ( \ FIELD_PREP(CDNS_XSPI_CMD_INSTR_TYPE, (data_phase) ? \ @@ -157,9 +160,10 @@ FIELD_PREP(CDNS_XSPI_CMD_P1_R2_ADDR3, ((op)->addr.val >> 24) & 0xFF) | \ FIELD_PREP(CDNS_XSPI_CMD_P1_R2_ADDR4, ((op)->addr.val >> 32) & 0xFF)) -#define CDNS_XSPI_CMD_FLD_P1_INSTR_CMD_3(op) ( \ +#define CDNS_XSPI_CMD_FLD_P1_INSTR_CMD_3(op, modebytes) ( \ FIELD_PREP(CDNS_XSPI_CMD_P1_R3_ADDR5, ((op)->addr.val >> 40) & 0xFF) | \ FIELD_PREP(CDNS_XSPI_CMD_P1_R3_CMD, (op)->cmd.opcode) | \ + FIELD_PREP(MODE_NO_OF_BYTES, modebytes) | \ FIELD_PREP(CDNS_XSPI_CMD_P1_R3_NUM_ADDR_BYTES, (op)->addr.nbytes)) #define CDNS_XSPI_CMD_FLD_P1_INSTR_CMD_4(op, chipsel) ( \ @@ -173,12 +177,12 @@ #define CDNS_XSPI_CMD_FLD_DSEQ_CMD_2(op) \ FIELD_PREP(CDNS_XSPI_CMD_DSEQ_R2_DCNT_L, (op)->data.nbytes & 0xFFFF) -#define CDNS_XSPI_CMD_FLD_DSEQ_CMD_3(op) ( \ +#define CDNS_XSPI_CMD_FLD_DSEQ_CMD_3(op, dummybytes) ( \ FIELD_PREP(CDNS_XSPI_CMD_DSEQ_R3_DCNT_H, \ ((op)->data.nbytes >> 16) & 0xffff) | \ FIELD_PREP(CDNS_XSPI_CMD_DSEQ_R3_NUM_OF_DUMMY, \ (op)->dummy.buswidth != 0 ? \ - (((op)->dummy.nbytes * 8) / (op)->dummy.buswidth) : \ + (((dummybytes) * 8) / (op)->dummy.buswidth) : \ 0)) #define CDNS_XSPI_CMD_FLD_DSEQ_CMD_4(op, chipsel) ( \ @@ -351,6 +355,7 @@ static int cdns_xspi_send_stig_command(struct cdns_xspi_dev *cdns_xspi, u32 cmd_regs[6]; u32 cmd_status; int ret; + int dummybytes = op->dummy.nbytes; ret = cdns_xspi_wait_for_controller_idle(cdns_xspi); if (ret < 0) @@ -365,7 +370,12 @@ static int cdns_xspi_send_stig_command(struct cdns_xspi_dev *cdns_xspi, memset(cmd_regs, 0, sizeof(cmd_regs)); cmd_regs[1] = CDNS_XSPI_CMD_FLD_P1_INSTR_CMD_1(op, data_phase); cmd_regs[2] = CDNS_XSPI_CMD_FLD_P1_INSTR_CMD_2(op); - cmd_regs[3] = CDNS_XSPI_CMD_FLD_P1_INSTR_CMD_3(op); + if (dummybytes != 0) { + cmd_regs[3] = CDNS_XSPI_CMD_FLD_P1_INSTR_CMD_3(op, 1); + dummybytes--; + } else { + cmd_regs[3] = CDNS_XSPI_CMD_FLD_P1_INSTR_CMD_3(op, 0); + } cmd_regs[4] = CDNS_XSPI_CMD_FLD_P1_INSTR_CMD_4(op, cdns_xspi->cur_cs); @@ -375,7 +385,7 @@ static int cdns_xspi_send_stig_command(struct cdns_xspi_dev *cdns_xspi, cmd_regs[0] = CDNS_XSPI_STIG_DONE_FLAG; cmd_regs[1] = CDNS_XSPI_CMD_FLD_DSEQ_CMD_1(op); cmd_regs[2] = CDNS_XSPI_CMD_FLD_DSEQ_CMD_2(op); - cmd_regs[3] = CDNS_XSPI_CMD_FLD_DSEQ_CMD_3(op); + cmd_regs[3] = CDNS_XSPI_CMD_FLD_DSEQ_CMD_3(op, dummybytes); cmd_regs[4] = CDNS_XSPI_CMD_FLD_DSEQ_CMD_4(op, cdns_xspi->cur_cs); -- 2.43.0