From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=pass header.oldest-pass=0 smtp.remote-ip=40.107.159.70 ARC-Seal: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=pass; t=1796036393; b=ICCxw7BWexHIJ7AReaBmUajxPOnj1SVhoI3HUg9rXIaSWofFhnLZmlw0dtc8qlif/yk0 6hBWhcWyIIIJJcfn/kH01jj1z3gYnApQiRE4UzPU2fkt/dhqCT6MBFBTGPE/FaVxImp5l Y/50cUyTTQnydNqQDPRuRr2spaorxBkvakz/zSS6K/H7rbatozYwvPI+KcG2HKyOeUlel aUjDg6m8N5TmPaO2AozRODatQfLTByJV0IfNy+fC2WyG78DbMTBAu7uIIWq0i7CuXwLWx PvfkHWFynOjrGXbe60dS3DA5iQebnyo8ApO0gIPY262hLNDNLjp2+9PIH0TgtdtzpCQ== ARC-Message-Signature: i=2; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796036393; h=DMARC-Filter:DKIM-Signature:Received:Received:Date:From:To:Cc: Subject:Message-ID:References:Content-Type:Content-Disposition: In-Reply-To:X-ClientProxiedBy:MIME-Version:X-MS-PublicTrafficType: X-MS-TrafficTypeDiagnostic:X-MS-Office365-Filtering-Correlation-Id: X-MS-Exchange-SenderADCheck:X-MS-Exchange-AntiSpam-Relay: X-Microsoft-Antispam:X-Microsoft-Antispam-Message-Info: X-Forefront-Antispam-Report: X-MS-Exchange-AntiSpam-MessageData-ChunkCount: X-MS-Exchange-AntiSpam-MessageData-0:X-OriginatorOrg: X-MS-Exchange-CrossTenant-Network-Message-Id: X-MS-Exchange-CrossTenant-AuthSource:X-MS-Exchange-CrossTenant-AuthAs: X-MS-Exchange-CrossTenant-OriginalArrivalTime: X-MS-Exchange-CrossTenant-FromEntityHeader: X-MS-Exchange-CrossTenant-Id:X-MS-Exchange-CrossTenant-MailboxType: X-MS-Exchange-CrossTenant-UserPrincipalName: X-MS-Exchange-Transport-CrossTenantHeadersStamped; bh=w9OT0iVhNNyLYnHNbKs9hUw6RMa3XrlOht/CFZjz35Q=; b=5sENOVc/9cwp/lgMF1o0VE8goeETDzcM1Zgfd5sfgGqvl6ieULjGZRM5O8iV6DF5z1eZ aW+cOEDkMpgcPTrWErpv3c8NOH8YZwjWBbFvYmoe0LwGXIh1iZHb3ukCUHRXYvwSdSIGE A/2JVhE5nKCZ8mEu791FrLLNL50tXVseT0su4y6amEHpW5n+mX1jzXDLzTOoGRG7aCuYX vTp1X5mVoqmCf3/Kxr8PFwDn1cDIhj9U73TxVxmVhPcI8f5krqPsD3VzartJkHUjxv/SY 72zZPASsAbcjlmGsjAPOibGrkaNV80UlBrPEZRbkyOhEZt3TKlnBr9IS9XrE46YaKqg== ARC-Authentication-Results: i=2; smtp.subspace.kernel.org; dmarc=pass header.from=oss.nxp.com; spf=pass smtp.mailfrom=oss.nxp.com; dkim=pass header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.a=rsa-sha256 header.s=selector1-NXP1-onmicrosoft-com header.b=j29LR7ZZ; arc=pass header.oldest-pass=0 smtp.remote-ip=40.107.159.70 Received: from OSPPR02CU001.outbound.protection.outlook.com (mail-norwayeastazon11013070.outbound.protection.outlook.com [40.107.159.70]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (secp384r1) server-signature ECDSA (prime256v1) server-digest SHA256) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 25184606A31C; Mon, 30 Nov 2026 10:59:51 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.2 smtp.subspace.kernel.org 25184606A31C Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=oss.nxp.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.nxp.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=NXP1.onmicrosoft.com header.i=@NXP1.onmicrosoft.com header.a=rsa-sha256 header.s=selector1-NXP1-onmicrosoft-com header.b=j29LR7ZZ ARC-Seal: i=1; a=rsa-sha256; s=arcselector10001; d=microsoft.com; cv=none; b=rtThfdBF6ukXaWvC5eboKVnh5ijLc7ht5qpE6ddoMdFl+dSQhr0cAZjqy1OfqxYXWI4fkV6AV6lN5WY9iEy2mrd1EDJrMiFWnuxjESeF1v+Wt1U3vAdFprgtOvR1iy4RwhAju+kr+XSLGrInhBkS+GZo4DBdA1xmhby1sWfI9PMsNqcKM5gfFEn0odKrr8uZqcjC+oWsk6PXHbko0wAU/xrxWoS3yk8dwYF0DqKwGrDiu4hlyWLgbdfw4An8zLALHJ1h1+1jRdcwamxb8fB+Ph6toTS+f3bEHPoaz+ISbHZ03En1YZ7rHZg0fFixIA1fhdP7ILbEOymk+SddyUMgaw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector10001; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=w9OT0iVhNNyLYnHNbKs9hUw6RMa3XrlOht/CFZjz35Q=; b=E6oM3G+J3ghe0OEsdXTV44WC8IxReEX6qvFWo0HlUFh9p/S7kcsaAMwnPP5Bx1wZFrIBTgsZX8rR3wGDzdlyY/Nt6fSFoyGIkYQyrCSgSLO6Qs8I58cbTQKMwnwOWB76XWHGXXQMM9oHiqLfJWFsSS0awKFqKjVGgrlI3D+OO28PdAVdI231q7RBj3PQtrMQSSqf0/gDtMTX/vg6Ay32YpCpSLfQx6UrjjRBcWxgwBcTc7/2hYX3y9bAaXKdpUSRGQqHjpy+HyzK+yrqbBzFo2VFlHip/pM2y63bz1KP0+nuKLKQe65g5ohh5MWb0JeGJ15l6QEfm1c8tH8uP8VAiA== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=oss.nxp.com; dmarc=pass action=none header.from=oss.nxp.com; dkim=pass header.d=oss.nxp.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=NXP1.onmicrosoft.com; s=selector1-NXP1-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=w9OT0iVhNNyLYnHNbKs9hUw6RMa3XrlOht/CFZjz35Q=; b=j29LR7ZZQ+I1vovnNJ5OISY1kklamb8xPJx01p5i8NaTSE54yOGCH3l5I6UiWN4hqiBeqrVKkNr4Zr+H8w0/my3nxuyMs3XgjuTWkWA1j+YHqSCnjPTNK05s9irWUlnJ8dC63BY8fNjdQyzbreLnXObjp7BHb66PT5YnuoRKh4PnOGGAUStuaHg/cgzY4vlShTl7wXh6Yn7kJpylbbRyaBigT6YsMGXwgnFlvqgg2k5FmFh0OKZHxhHXG1UanZMzyKaFlso3Z8scIGWUKYZQW3gik9IrnUAM0IWDoouWFdbdAF7kmUshjtRjsPu529lQh8zvcfgTOJOCwBQwY/ppnw== Authentication-Results: mx.microsoft.com 1; dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=oss.nxp.com; Received: from PA6PR04MB11909.eurprd04.prod.outlook.com (2603:10a6:102:51c::22) by BR0PR04MB389215.eurprd04.prod.outlook.com (2603:10a6:2c8:2b::5) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.21.662.12; Mon, 30 Nov 2026 10:59:49 +0000 Received: from PA6PR04MB11909.eurprd04.prod.outlook.com ([fe80::a4b:fa4e:7fe7:e6a2]) by PA6PR04MB11909.eurprd04.prod.outlook.com ([fe80::a4b:fa4e:7fe7:e6a2%7]) with mapi id 15.21.0662.007; Mon, 30 Nov 2026 10:59:49 +0000 Date: Mon, 30 Nov 2026 19:04:58 +0800 From: Bough Chen To: Miquel Raynal Cc: Mark Brown , Liang Yang , Feng Chen , Xianwei Zhao , Han Xu , Conor Dooley , Valentina Fernandez , Daire McNamara , Haibo Chen , Jyan Chou , Yu-Chun Lin , Maxime Coquelin , Alexandre Torgue , Pratyush Yadav , Michael Walle , Takahiro Kuwano , Richard Weinberger , Vignesh Raghavendra , Tudor Ambarus , Steven Rostedt , Masami Hiramatsu , Mathieu Desnoyers , Nicolas Ferre , Alexandre Belloni , Claudiu Beznea , Matthias Brugger , AngeloGioacchino Del Regno , Yogesh Gaur , Chris Packham , Jonathan =?utf-8?Q?Neusch=C3=A4fer?= , Michal Simek , Thomas Petazzoni , Alvin Zhou , Cheng Ming Lin , linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-amlogic@lists.infradead.org, imx@lists.linux.dev, linux-riscv@lists.infradead.org, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, linux-mtd@lists.infradead.org, linux-trace-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, openbmc@lists.ozlabs.org Subject: Re: [PATCH RFC v2 06/35] spi: spi-mem: Add support for dummy cycles Message-ID: <20261130110458.3eyipbw45jqkwlux@shlinux89> References: <20261127-macronix-upstreaming-spi-mem-cycles-v2-0-5c93f5e5d630@bootlin.com> <20261127-macronix-upstreaming-spi-mem-cycles-v2-6-5c93f5e5d630@bootlin.com> Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20261127-macronix-upstreaming-spi-mem-cycles-v2-6-5c93f5e5d630@bootlin.com> X-ClientProxiedBy: SI2PR02CA0008.apcprd02.prod.outlook.com (2603:1096:4:194::12) To PA6PR04MB11909.eurprd04.prod.outlook.com (2603:10a6:102:51c::22) X-Mailing-List: linux-trace-kernel@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 X-MS-PublicTrafficType: Email X-MS-TrafficTypeDiagnostic: PA6PR04MB11909:EE_|BR0PR04MB389215:EE_ X-MS-Office365-Filtering-Correlation-Id: 098efbee-1537-4320-818b-08df4ed10d20 X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0;ARA:13230040|19092799006|376014|7416014|1800799024|366016|23010399003|5023799004|4143699003|11063799006|6133799003|261009223027099003|18002099003|22082099003|13003099007|10067099003|56012099006|261102130727099003|261028144727099003|261026121527099003|261026140227099003|261022105027099003|261022075727099003|261102123227099003|261021121427099003|261021123027099003; X-Microsoft-Antispam-Message-Info: m38q0XJL/aAjm+D12/Q0KQIJnFKaBFKdVX87/4F8dy/l/YEL5sck7+CKqIgRUO3Q4k9rd1XQvUfDyl0tMkqvVpTInAL/PlU0ebY9dBZmCvXywHkasWlzvKE08GgXawJrAwLTiQyTc3sR0tggUUehOr1UF+vv5hDH2lcCfJOeLd+2DHlGRgbBYfVqrGascbXHiWEzwblMONKDViWYhKQQX+yzaEkObszcf3XKCn5wC4+6MRT128T7CL2qiAA6X5Hrrl9mKVK1HU32pxlaru5IRLkq+YQzj2/Q0RsjlZl4NHFo0/w6FFBdBr565KXsrDBWZEMhCOlXNQVn2yIEk9VbnChWvPL1qdHlXWGrzIDK+D+n7wALMBQx3pZJCHh1sx9C5/e+9n3h4x9cnjHdUooGZ4fgK6VjaMGlu3VtkSXSmbVpWWuZWz3OPMBEu+GFLdV5it1yM20LPfOsc++UBNC80CANZAHjtA0oS0HPGIl0sPqxPazODaU+L3taUgqmFdu4L6lWzTJJW/I8feo1E4BtMCaicWE8nJXJpnAq4plsgNlklRIUMtxbvQm7gclnQazsJJ+BarTw+BLWRJahuCpexahhyA1+eeuPcR6HGjdCAlSX3/k/gtDdY03sf8hIvEbj X-Forefront-Antispam-Report: CIP:255.255.255.255;CTRY:;LANG:en;SCL:1;SRV:;IPV:NLI;SFV:NSPM;H:PA6PR04MB11909.eurprd04.prod.outlook.com;PTR:;CAT:NONE;SFS:(13230040)(19092799006)(376014)(7416014)(1800799024)(366016)(23010399003)(5023799004)(4143699003)(11063799006)(6133799003)(261009223027099003)(18002099003)(22082099003)(13003099007)(10067099003)(56012099006)(261102130727099003)(261028144727099003)(261026121527099003)(261026140227099003)(261022105027099003)(261022075727099003)(261102123227099003)(261021121427099003)(261021123027099003);DIR:OUT;SFP:1101; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: =?us-ascii?Q?yRjernZBmjT9PryhGTKWYbw6N7PhcEhwQcKVZ8SMobzn6C5S3yN2zDZ5eS4x?= =?us-ascii?Q?dOclYIwoKoAh6waPyTVjCG+B1pYZUi+AwTTk3v/jGAJWoLyONSVqst3bX9D9?= =?us-ascii?Q?PZ0rvdN8W/Ijrl4FsdsGQquZ5FxszPwE8UUpIGbWwW1bzEm1Vd71OiLakeWm?= =?us-ascii?Q?hz+kV6rvlbVoZSHh04sl6DjZ+/DRBictTH7Wg4WjmDrd/JyamZ5woRT7Z1Uf?= =?us-ascii?Q?cDKpVOg/nGAVWyhFlJBwoaGev71VM2I4wE8GOcFErZFEC7xxRrvVJO0LEtAf?= =?us-ascii?Q?/eMjkZzi4qYnM8KrhuGzGjHo8grKh0c63rw90pdKN4djfJuI2k8dOzZYD93k?= =?us-ascii?Q?t0sF+1l2ptX7OWT5zG9DERTWORrRYBV2m+GVzVtfazDQruvLevex5VodomJJ?= =?us-ascii?Q?wtMJkUwDLijdiBaZgRcy4f7kga04XseP1JzFVta7/PGg9qPpnonsYLZUT2uW?= =?us-ascii?Q?gXaCK/yobh98TiH+rtOSH1zUuJ7ZQ/nR+cjGT0v0IxvsbZdyerl6FsbYhwis?= =?us-ascii?Q?3/LUBX4zewNzSrrWOmB2R/Kl0+BL3tBaN49MqgQU2//Et2xfKoYIosWBSsl8?= =?us-ascii?Q?SdpuHhsZcEEb0Cyp3KaFIkNHIsFWE9KphE+fwTLh3DKiGv66N/8Jko6if3sV?= =?us-ascii?Q?om1tt5l2R/jwBwLG7FJIOlT23YFLqrwlsd1ybkMJrnrgBx6MmNoRw1+28fw8?= =?us-ascii?Q?Bvyp1OUzqDuB0wr7dHaiENjslK8RdLytPVvtabk9RdAUQ8djU21CtToFWAWo?= =?us-ascii?Q?9cGOlo1S+dEEVkv0L+hkvBRodY64O9GUZs8OmEPe3Ts8rupGNbiP/ndlr4d0?= =?us-ascii?Q?W6ZhGpcHMbo5g3DZVdXcY939y+rDNLiRnS18teLFX96ZY155mM8WTCrH1TDm?= =?us-ascii?Q?tk8Cwy/jZ6+WOFdjJgmJQf4KzoES1f5ZvtXN/iPXudKJf33PaFXWXjCXTDJf?= =?us-ascii?Q?nGUfs/l8LHSVORXfdMV8gdxMLSAZ/8WTFp7DT6FSnc4WW/506BLpidbUZsJQ?= =?us-ascii?Q?TwQYI+lCObxekQFTP6fbtUV662T4slWE8JtB0qtkcjHSDgiCHseKyaL2T1jd?= =?us-ascii?Q?6WE6FzFmAl1jhLvafPauDVKwbmG+1d4sWLPIaCeRYYYW8/cooQQNnfoqtpTN?= =?us-ascii?Q?ubZsZZY7bMdz3Gcovv3ASYmcCzpQr1GCDNN4e8eQ3kBSkyphR6f8JHepf9PL?= =?us-ascii?Q?jKBdaD+99m37BEoHoGL44rvbmuUMEqWw6CQr8sJepENeIx2ro2MBHuqHfrE/?= =?us-ascii?Q?NwzcOmkPGCxp8v/hH3xDoLeEb0fYty5/jnZdfb40J6hE0pd4fUvSyY9UYe+m?= =?us-ascii?Q?8ZlYm5xKYONbMPsROgO32mRH2yivH7h4SN0AY1Q2z3Gskd5Q2Arb2d2PwqQY?= =?us-ascii?Q?3vHureV6CrUFACrT3by325DVQkbhYCC2TRPe3GUtf4FFWVyNhyAeoIfJnwEd?= =?us-ascii?Q?S7o5z5JbiC0uTmEBIXb1/OilQ8uiXOAbnNRzDd9qo/Okpx+pFEF1MoV57T4E?= =?us-ascii?Q?OB0k9+koimzDH50a1K2It6nPsRQok1aKeL9bXr6RleQiS8ZIdBhzZ/VMFOzf?= =?us-ascii?Q?FAaf5XDPEOworkVQPkdj0lOJKgjceFJdYrZxoQIrSGVzqdvp64LAaIeeLqtV?= =?us-ascii?Q?vaI4r2x51np7ymQb8bQ6HXruU0U46zFWxSDQOmmM7NGLq7vTKASeR724zlKi?= =?us-ascii?Q?6K/Y+f1EBkm8mMVeWs8W0j5bcAH4WTafCzjoFhtYylWfxtLtorMVCxurEJi3?= =?us-ascii?Q?TSWxtIX6DfNQjVqqrH5z4VM3jcMiD5K1jt+RhFQZh66XBbyW9jEf?= X-OriginatorOrg: oss.nxp.com X-MS-Exchange-CrossTenant-Network-Message-Id: 098efbee-1537-4320-818b-08df4ed10d20 X-MS-Exchange-CrossTenant-AuthSource: PA6PR04MB11909.eurprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Nov 2026 10:59:48.9098 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 686ea1d3-bc2b-4c6f-a92c-d99c5c301635 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: zXFg6HWiZZE9hBhDAaVDlglmjPq8MTnnwfy4j7ktFT4GRrvbB/ZTQcFiKY5YuTksfedrEuRCUpWOJfCk9jOV68R+NS5GBfys9SuCnCmFf+H08fNukeBfrrsZu1W4dWHf X-MS-Exchange-Transport-CrossTenantHeadersStamped: BR0PR04MB389215 On Fri, Nov 27, 2026 at 03:22:28PM +0100, Miquel Raynal wrote: > The dummy phase is a number of clock cycles, not a number of bytes. SPI > NOR flashes commonly require a number of dummy cycles that is not a > multiple of 8, and the byte-based representation cannot express it. > > Add a dummy.ncycles field and make it the primary representation. Keep > dummy.nbytes for the legacy byte-oriented controllers and users. The two > fields are mutually exclusive and spi_mem_check_op() enforces that rule. > > Controllers that can program an arbitrary number of cycles advertise the > dummy_cycles capability and consume dummy.ncycles directly. The core > converts the legacy dummy.nbytes to cycles for them, so the users that > still describe the dummy phase in bytes keep working. If the byte count > cannot be expressed as a whole number of cycles, the operation is > rejected. > > For the other controllers the core converts dummy.ncycles to the legacy > dummy.nbytes representation using the usual maths. If the cycle count > cannot be represented exactly, the operation is rejected instead of > being silently truncated. > > Link: https://lore.kernel.org/all/20220911174551.653599-1-sergiu.moga@microchip.com/ > Link: https://lore.kernel.org/all/20250115134158.19908-1-pratyush@kernel.org/ > > Link: https://lore.kernel.org/all/20220911174551.653599-1-sergiu.moga@microchip.com/ > Link: https://lore.kernel.org/all/20250115134158.19908-1-pratyush@kernel.org/ > Signed-off-by: Miquel Raynal Apply this patch on linux-next meet conflict. Because your another patch already accepted: https://lore.kernel.org/all/20260810-winbond-nand-next-phy-tuning-v3-1-a97c3a61e675@bootlin.com/ You should re-write this patch based on Mark Brown's spi tree. Regards Haibo Chen > --- > drivers/spi/spi-mem.c | 224 ++++++++++++++++++++++++++++++++++++++--- > include/linux/spi/spi-mem.h | 39 ++++++- > include/trace/events/spi-mem.h | 5 +- > 3 files changed, 245 insertions(+), 23 deletions(-) > > diff --git a/drivers/spi/spi-mem.c b/drivers/spi/spi-mem.c > index a1f129c47698..1642388b7004 100644 > --- a/drivers/spi/spi-mem.c > +++ b/drivers/spi/spi-mem.c > @@ -12,6 +12,24 @@ > #include > #include > > +static unsigned int > +spi_mem_get_dummy_nbytes(const struct spi_mem_op *op) > +{ > + u32 bits; > + > + if (!op->dummy.ncycles) > + return op->dummy.nbytes; > + > + if (!op->dummy.buswidth) > + return 0; > + > + bits = (u32)op->dummy.ncycles * op->dummy.buswidth; > + if (op->dummy.dtr) > + bits *= 2; > + > + return DIV_ROUND_UP(bits, 8); > +} > + > #define CREATE_TRACE_POINTS > #include > > @@ -252,6 +270,111 @@ static bool spi_mem_buswidth_is_valid(u8 buswidth) > return true; > } > > +/** > + * spi_mem_dummy_cycles_to_bytes() - Convert the dummy phase cycles to bytes > + * @op: the SPI memory operation > + * > + * Return: the number of dummy bytes on success, a negative error code if the > + * dummy phase cannot be represented as a whole number of bytes. > + * If @op->dummy.ncycles is zero, @op->dummy.nbytes is returned. > + * > + * This helper can be used to convert dummy cycles into dummy bytes for > + * controllers that can only insert a whole number of dummy bytes. > + */ > +static int spi_mem_dummy_cycles_to_bytes(const struct spi_mem_op *op) > +{ > + u32 bits; > + > + if (!op->dummy.ncycles) > + return op->dummy.nbytes; > + > + if (!op->dummy.buswidth) > + return -EOPNOTSUPP; > + > + bits = (u32)op->dummy.ncycles * op->dummy.buswidth; > + if (op->dummy.dtr) > + bits *= 2; > + > + if (bits % 8 || bits / 8 > U8_MAX) > + return -EOPNOTSUPP; > + > + return bits / 8; > +} > + > +/** > + * spi_mem_dummy_bytes_to_cycles() - Convert the dummy phase bytes to cycles > + * @op: the SPI memory operation > + * > + * Return: the number of dummy clock cycles on success, a negative error code > + * if the dummy phase cannot be represented as a whole number of clock > + * cycles. If @op->dummy.nbytes is zero, @op->dummy.ncycles is returned. > + * > + * This helper can be used to convert inlet operations using dummy bytes > + * into operations using dummy cycles. > + */ > +static int spi_mem_dummy_bytes_to_cycles(const struct spi_mem_op *op) > +{ > + u32 bits, bits_per_cycle; > + > + if (!op->dummy.nbytes) > + return op->dummy.ncycles; > + > + bits_per_cycle = op->dummy.buswidth; > + if (op->dummy.dtr) > + bits_per_cycle *= 2; > + if (!bits_per_cycle) > + return -EOPNOTSUPP; > + > + bits = (u32)op->dummy.nbytes * 8; > + if (bits % bits_per_cycle) > + return -EOPNOTSUPP; > + > + bits /= bits_per_cycle; > + if (bits > U8_MAX) > + return -EOPNOTSUPP; > + > + return bits; > +} > + > +/* > + * Controllers either program the dummy phase in clock cycles or in whole > + * bytes. Convert the representation used by the operation to the one the > + * controller expects. > + * > + * Return: 0 if the operation is lossless, -EOPNOTSUPP otherwise. > + */ > +static int spi_mem_convert_dummy(struct spi_mem *mem, struct spi_mem_op *op) > +{ > + struct spi_controller *ctlr = mem->spi->controller; > + int n; > + > + if (op->dummy.ncycles) { > + if (spi_mem_controller_is_capable(ctlr, dummy_cycles)) > + return 0; > + > + n = spi_mem_dummy_cycles_to_bytes(op); > + if (n < 0) > + return n; > + > + op->dummy.nbytes = n; > + op->dummy.ncycles = 0; > + } else if (op->dummy.nbytes) { > + if (!spi_mem_controller_is_capable(ctlr, dummy_cycles)) > + return 0; > + > + n = spi_mem_dummy_bytes_to_cycles(op); > + if (n < 0) > + return n; > + > + op->dummy.ncycles = n; > + op->dummy.nbytes = 0; > + > + return 0; > + } > + > + return 0; > +} > + > static int spi_mem_check_op(const struct spi_mem_op *op) > { > if (!op->cmd.buswidth || !op->cmd.nbytes) > @@ -259,9 +382,13 @@ static int spi_mem_check_op(const struct spi_mem_op *op) > > if ((op->addr.nbytes && !op->addr.buswidth) || > (op->dummy.nbytes && !op->dummy.buswidth) || > + (op->dummy.ncycles && !op->dummy.buswidth) || > (op->data.nbytes && !op->data.buswidth)) > return -EINVAL; > > + if (op->dummy.nbytes && op->dummy.ncycles) > + return -EINVAL; > + > if (!spi_mem_buswidth_is_valid(op->cmd.buswidth) || > !spi_mem_buswidth_is_valid(op->addr.buswidth) || > !spi_mem_buswidth_is_valid(op->dummy.buswidth) || > @@ -321,6 +448,9 @@ bool spi_mem_supports_op(struct spi_mem *mem, const struct spi_mem_op *op) > if (spi_mem_check_op(&eval_op)) > return false; > > + if (spi_mem_convert_dummy(mem, &eval_op)) > + return false; > + > return spi_mem_internal_supports_op(mem, &eval_op); > } > EXPORT_SYMBOL_GPL(spi_mem_supports_op); > @@ -366,6 +496,7 @@ static void spi_mem_access_end(struct spi_mem *mem) > static void spi_mem_add_op_stats(struct spi_statistics __percpu *pcpu_stats, > const struct spi_mem_op *op, int exec_op_ret) > { > + int dummy_nbytes = spi_mem_get_dummy_nbytes(op); > struct spi_statistics *stats; > u64 len, l2len; > > @@ -382,7 +513,7 @@ static void spi_mem_add_op_stats(struct spi_statistics __percpu *pcpu_stats, > > /* Use the sum of all lengths as bytes count and histogram value. */ > len = op->cmd.nbytes + op->addr.nbytes; > - len += op->dummy.nbytes + op->data.nbytes; > + len += dummy_nbytes + op->data.nbytes; > u64_stats_add(&stats->bytes, len); > l2len = min(fls(len), SPI_STATISTICS_HISTO_SIZE) - 1; > u64_stats_inc(&stats->transfer_bytes_histo[l2len]); > @@ -409,31 +540,41 @@ static void spi_mem_add_op_stats(struct spi_statistics __percpu *pcpu_stats, > /** > * spi_mem_exec_op() - Execute a memory operation > * @mem: the SPI memory > - * @op: the memory operation to execute > + * @ro_op: the memory operation to execute (shall not be edited) > * > * Executes a memory operation. > * > - * This function first checks that @op is supported and then tries to execute > - * it. > + * This function first checks that @ro_op is supported and then tries to > + * execute it. > * > * Return: 0 in case of success, a negative error code otherwise. > */ > -int spi_mem_exec_op(struct spi_mem *mem, const struct spi_mem_op *op) > +int spi_mem_exec_op(struct spi_mem *mem, const struct spi_mem_op *ro_op) > { > unsigned int tmpbufsize, xferpos = 0, totalxferlen = 0; > struct spi_controller *ctlr = mem->spi->controller; > + struct spi_mem_op wr_op = *ro_op, *op = &wr_op; > struct spi_transfer xfers[4] = { }; > struct spi_message msg; > u8 *tmpbuf; > int ret; > > /* Make sure the operation frequency is correct before going futher */ > - spi_mem_adjust_op_freq(mem, (struct spi_mem_op *)op); > + spi_mem_adjust_op_freq(mem, op); > + > + ret = spi_mem_check_op(op); > + if (ret) > + return ret; > + > + /* Also make sure the dummy phase can be consumed by the controller */ > + ret = spi_mem_convert_dummy(mem, op); > + if (ret) > + return ret; > > dev_vdbg(&mem->spi->dev, "[cmd: 0x%02x][%dB addr: %#8llx][%2dB dummy][%4dB data %s] %d%c-%d%c-%d%c-%d%c @ %uHz\n", > op->cmd.opcode, > op->addr.nbytes, (op->addr.nbytes ? op->addr.val : 0), > - op->dummy.nbytes, > + spi_mem_get_dummy_nbytes(op), > op->data.nbytes, (op->data.nbytes ? (op->data.dir == SPI_MEM_DATA_IN ? " read" : "write") : " "), > op->cmd.buswidth, op->cmd.dtr ? 'D' : 'S', > op->addr.buswidth, op->addr.dtr ? 'D' : 'S', > @@ -441,10 +582,6 @@ int spi_mem_exec_op(struct spi_mem *mem, const struct spi_mem_op *op) > op->data.buswidth, op->data.dtr ? 'D' : 'S', > op->max_freq ? op->max_freq : mem->spi->max_speed_hz); > > - ret = spi_mem_check_op(op); > - if (ret) > - return ret; > - > if (!spi_mem_internal_supports_op(mem, op)) > return -EOPNOTSUPP; > > @@ -472,6 +609,22 @@ int spi_mem_exec_op(struct spi_mem *mem, const struct spi_mem_op *op) > } > } > > + /* > + * spi_mem_convert_dummy() converted the dummy phase to cycles because > + * the controller advertised the dummy_cycles capability. The regular > + * SPI transfer path below builds spi_transfer segments and can only > + * express the dummy phase in bytes, so convert it back. Reject the > + * operation if the cycle count cannot be represented exactly. > + */ > + if (op->dummy.ncycles) { > + ret = spi_mem_dummy_cycles_to_bytes(op); > + if (ret < 0) > + return ret; > + > + op->dummy.nbytes = ret; > + op->dummy.ncycles = 0; > + } > + > tmpbufsize = op->cmd.nbytes + op->addr.nbytes + op->dummy.nbytes; > > /* > @@ -625,12 +778,22 @@ int spi_mem_adjust_op_size(struct spi_mem *mem, struct spi_mem_op *op) > { > struct spi_controller *ctlr = mem->spi->controller; > size_t len; > + int ret; > + > + ret = spi_mem_convert_dummy(mem, op); > + if (ret) > + return ret; > > if (ctlr->mem_ops && ctlr->mem_ops->adjust_op_size) > return ctlr->mem_ops->adjust_op_size(mem, op); > > if (!ctlr->mem_ops || !ctlr->mem_ops->exec_op) { > - len = op->cmd.nbytes + op->addr.nbytes + op->dummy.nbytes; > + int dummy_nbytes = spi_mem_dummy_cycles_to_bytes(op); > + > + if (dummy_nbytes < 0) > + return dummy_nbytes; > + > + len = op->cmd.nbytes + op->addr.nbytes + dummy_nbytes; > > if (len > spi_max_transfer_size(mem->spi)) > return -EINVAL; > @@ -701,9 +864,12 @@ u64 spi_mem_calc_op_duration(struct spi_mem *mem, struct spi_mem_op *op) > ncycles += ((op->cmd.nbytes * 8) / op->cmd.buswidth) / (op->cmd.dtr ? 2 : 1); > ncycles += ((op->addr.nbytes * 8) / op->addr.buswidth) / (op->addr.dtr ? 2 : 1); > > - /* Dummy bytes are optional for some SPI flash memory operations */ > - if (op->dummy.nbytes) > - ncycles += ((op->dummy.nbytes * 8) / op->dummy.buswidth) / (op->dummy.dtr ? 2 : 1); > + /* Dummy cycles are optional for some SPI flash memory operations */ > + if (op->dummy.ncycles) > + ncycles += op->dummy.ncycles; > + else if (op->dummy.nbytes) > + ncycles += ((op->dummy.nbytes * 8) / op->dummy.buswidth) / > + (op->dummy.dtr ? 2 : 1); > > ncycles += ((op->data.nbytes * 8) / op->data.buswidth) / (op->data.dtr ? 2 : 1); > > @@ -809,6 +975,21 @@ spi_mem_dirmap_create(struct spi_mem *mem, > desc->mem = mem; > desc->info = *info; > desc->info.op_tmpl = &desc->info.primary_op_tmpl; > + > + ret = spi_mem_convert_dummy(mem, &desc->info.primary_op_tmpl); > + if (ret) { > + kfree(desc); > + return ERR_PTR(ret); > + } > + > + if (desc->info.secondary_op_tmpl.cmd.opcode) { > + ret = spi_mem_convert_dummy(mem, &desc->info.secondary_op_tmpl); > + if (ret) { > + kfree(desc); > + return ERR_PTR(ret); > + } > + } > + > if (ctlr->mem_ops && ctlr->mem_ops->dirmap_create) { > ret = spi_mem_access_start(mem); > if (ret) { > @@ -819,6 +1000,8 @@ spi_mem_dirmap_create(struct spi_mem *mem, > ret = ctlr->mem_ops->dirmap_create(desc); > > spi_mem_access_end(mem); > + } else { > + ret = -EOPNOTSUPP; > } > > if (ret) { > @@ -1065,6 +1248,7 @@ int spi_mem_poll_status(struct spi_mem *mem, > u16 timeout_ms) > { > struct spi_controller *ctlr = mem->spi->controller; > + struct spi_mem_op eval_op = *op; > int ret = -EOPNOTSUPP; > int read_status_ret; > u16 status; > @@ -1074,11 +1258,19 @@ int spi_mem_poll_status(struct spi_mem *mem, > return -EINVAL; > > if (ctlr->mem_ops && ctlr->mem_ops->poll_status && !spi_get_csgpiod(mem->spi, 0)) { > + ret = spi_mem_check_op(&eval_op); > + if (ret) > + return ret; > + > + ret = spi_mem_convert_dummy(mem, &eval_op); > + if (ret) > + return ret; > + > ret = spi_mem_access_start(mem); > if (ret) > return ret; > > - ret = ctlr->mem_ops->poll_status(mem, op, mask, match, > + ret = ctlr->mem_ops->poll_status(mem, &eval_op, mask, match, > initial_delay_us, polling_delay_us, > timeout_ms); > > diff --git a/include/linux/spi/spi-mem.h b/include/linux/spi/spi-mem.h > index 0cce6b57242a..fc9f75c0609f 100644 > --- a/include/linux/spi/spi-mem.h > +++ b/include/linux/spi/spi-mem.h > @@ -11,6 +11,7 @@ > #ifndef __LINUX_SPI_MEM_H > #define __LINUX_SPI_MEM_H > > +#include > #include > > #define SPI_MEM_OP_CMD(__opcode, __buswidth) \ > @@ -75,6 +76,12 @@ > .buswidth = __buswidth, \ > } > > +#define SPI_MEM_OP_DUMMY_CYCLES(__ncycles, __buswidth) \ > + { \ > + .ncycles = __ncycles, \ > + .buswidth = __buswidth, \ > + } > + > #define SPI_MEM_DTR_OP_DUMMY(__nbytes, __buswidth) \ > { \ > .nbytes = __nbytes, \ > @@ -82,6 +89,13 @@ > .dtr = true, \ > } > > +#define SPI_MEM_DTR_OP_DUMMY_CYCLES(__ncycles, __buswidth) \ > + { \ > + .ncycles = __ncycles, \ > + .buswidth = __buswidth, \ > + .dtr = true, \ > + } > + > #define SPI_MEM_OP_NO_DUMMY { } > > #define SPI_MEM_OP_DATA_IN(__nbytes, __buf, __buswidth) \ > @@ -154,10 +168,18 @@ enum spi_mem_data_dir { > * address value, so users should make sure the value fits in the > * assigned number of bytes. > * @dummy: data for dummy operation > - * @dummy.nbytes: number of dummy bytes to send after an opcode or address. Can > - * be zero if the operation does not require dummy bytes > - * @dummy.buswidth: number of IO lanes used to transmit the dummy bytes > - * @dummy.dtr: whether the dummy bytes should be sent in DTR mode or not > + * @dummy.ncycles: number of dummy clock cycles to insert after an opcode or > + * address. Can be zero if the operation does not require > + * dummy cycles. Mutually exclusive with @dummy.nbytes. > + * @dummy.nbytes: legacy number of dummy bytes to send after an opcode or > + * address. Can be zero if the operation does not require dummy > + * bytes. Mutually exclusive with @dummy.ncycles. > + * @dummy.buswidth: number of IO lanes used during the dummy phase. It is > + * also used to convert @dummy.ncycles to bytes for controllers > + * that can only insert a whole number of dummy bytes. > + * @dummy.dtr: whether the dummy phase is clocked in DTR mode. This only > + * describes the pin state and does not change the number of > + * clock cycles. > * @data: the data attributes > * @data.buswidth: number of IO lanes used to send/receive the data > * @data.dtr: whether the data should be sent in DTR mode or not > @@ -191,6 +213,7 @@ struct spi_mem_op { > } addr; > > struct { > + u8 ncycles; > u8 nbytes; > u8 buswidth; > u8 dtr : 1; > @@ -392,6 +415,11 @@ struct spi_controller_mem_ops { > * is a pause in the transfer (eg. internal bus contention or > * DMA arbitration on an interconnect). Features such as NAND > * continuous reads shall not be leveraged. > + * @dummy_cycles: Supports programming the exact number of dummy clock cycles. > + * When set, the core converts the legacy @dummy.nbytes to clock > + * cycles. When unset, the core converts @dummy.ncycles to whole > + * dummy bytes for the controller and rejects operations that > + * cannot be converted exactly. > */ > struct spi_controller_mem_caps { > bool dtr; > @@ -400,6 +428,7 @@ struct spi_controller_mem_caps { > bool per_op_freq; > bool secondary_op_tmpl; > bool no_cs_assertion; > + bool dummy_cycles; > }; > > #define spi_mem_controller_is_capable(ctlr, cap) \ > @@ -473,7 +502,7 @@ bool spi_mem_supports_op(struct spi_mem *mem, > const struct spi_mem_op *op); > > int spi_mem_exec_op(struct spi_mem *mem, > - const struct spi_mem_op *op); > + const struct spi_mem_op *ro_op); > > const char *spi_mem_get_name(struct spi_mem *mem); > > diff --git a/include/trace/events/spi-mem.h b/include/trace/events/spi-mem.h > index d13f0bcff5e7..9df571d7799d 100644 > --- a/include/trace/events/spi-mem.h > +++ b/include/trace/events/spi-mem.h > @@ -22,7 +22,8 @@ TRACE_EVENT(spi_mem_start_op, > > TP_STRUCT__entry( > __string(name, mem->name) > - __dynamic_array(u8, op, 1 + op->addr.nbytes + op->dummy.nbytes) > + __dynamic_array(u8, op, 1 + op->addr.nbytes + > + spi_mem_get_dummy_nbytes(op)) > __dynamic_array(u8, data, op->data.dir == SPI_MEM_DATA_OUT ? > min(op->data.nbytes, 64) : 0) > __field(u32, data_len) > @@ -53,7 +54,7 @@ TRACE_EVENT(spi_mem_start_op, > op->addr.val >> (8 * (op->addr.nbytes - i - 1)); > > memset(((u8 *)__get_dynamic_array(op)) + op->addr.nbytes + 1, > - 0xff, op->dummy.nbytes); > + 0xff, spi_mem_get_dummy_nbytes(op)); > > __entry->data_len = op->data.nbytes; > __entry->data_buswidth = op->data.buswidth; > > -- > 2.56.0 >