From nobody Tue Feb 10 01:35:20 2026 Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [217.70.183.199]) (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 4BB65212B28; Fri, 10 Jan 2025 14:45:36 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=217.70.183.199 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736520339; cv=none; b=OaLhBd3lU6HxIw9GxAqQoax0KI4NtrA/A3yl1At/2yXIIodHonaDCmCkwwtyZTldh8PFrA9a6NeDlrU1Uqi5jXxnV13oiYEC6gv6Oaz06SdtYqZROhtxPdlFk4DZUhATWDnct/C5a9gVQc2DiI6g96xnvagSObRymv21lFPYWhU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1736520339; c=relaxed/simple; bh=OehQ7sFx1F2fRMosXHjnvZDLjWaZ/vvA9IwbmftJIvw=; h=From:Date:Subject:MIME-Version:Content-Type:Message-Id:References: In-Reply-To:To:Cc; b=bSVhuL/UNvynm6i3p2FeHlA2+/T9C5FSoaxhaAYyqRhguDca+KEy/d0hjKFdDAXG5zaJPM6i+wZN5iZqoLHM+377gW7BjX5nHW+n+g5ZCLN5c17kVnkk3rhQsXSZgMpp3ZNbesAf64edFJ+qWM/bMw6cVuqRiXTvikimxe4omyY= 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=QUn2HxYY; arc=none smtp.client-ip=217.70.183.199 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 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=bootlin.com header.i=@bootlin.com header.b="QUn2HxYY" Received: by mail.gandi.net (Postfix) with ESMTPSA id B0B53FF80E; Fri, 10 Jan 2025 14:45:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1736520335; 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=y8cSrYQE/5lZoSPtcr0B2aeBjkjg2ZNQ2fjZw3v1pDQ=; b=QUn2HxYYpXHzBUUQGFzw5CGFjm1mZXXTWJ41aFPg8sbXlUkse+ZsntwleUTKfbNS5EyysD juZhCK5l5FeDs7HRV23fT3CvZGeuXcdEKB7UgbLidckGhKI74rDX83gVklykbh3ArOXfUl saItcUGf5z3LqB4JRAwu5Cr0zWk0evBhDTKp/jtNDzx2ZEEzv//c+htDYI1x/ZX2eA5PNC RGsXz8QgcMZM2YLZ9Sm4pe9p1LsrniCqSGS/99f8j/CtQqRMVe+WDwgoF833kEMKnE06/c GkgTU07BB+ytJ1XpuckVJH59o34lIM6wWOP4bjBeGn1MpYHrc4StKbTkbZbLbg== From: Miquel Raynal Date: Fri, 10 Jan 2025 15:45:11 +0100 Subject: [PATCH v3 09/27] spi: microchip-core-qspi: Support per spi-mem operation frequency switches 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: quoted-printable Message-Id: <20250110-winbond-6-11-rc1-quad-support-v3-9-7ab4bd56cf6e@bootlin.com> References: <20250110-winbond-6-11-rc1-quad-support-v3-0-7ab4bd56cf6e@bootlin.com> In-Reply-To: <20250110-winbond-6-11-rc1-quad-support-v3-0-7ab4bd56cf6e@bootlin.com> To: Mark Brown , Sanjay R Mehta , Serge Semin , Han Xu , Conor Dooley , Daire McNamara , Matthias Brugger , AngeloGioacchino Del Regno , Haibo Chen , Yogesh Gaur , Heiko Stuebner , Michal Simek , Miquel Raynal , Richard Weinberger , Vignesh Raghavendra , Jacky Huang , Shan-Chun Hung , Chin-Ting Kuo , =?utf-8?q?C=C3=A9dric_Le_Goater?= , Joel Stanley , Andrew Jeffery , Avi Fishman , Tomer Maimon , Tali Perry , Patrick Venture , Nancy Yuen , Benjamin Fair , Maxime Coquelin , Alexandre Torgue , Raju Rangoju Cc: Thomas Petazzoni , Steam Lin , linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org, imx@lists.linux.dev, linux-riscv@lists.infradead.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-rockchip@lists.infradead.org, linux-mtd@lists.infradead.org, linux-aspeed@lists.ozlabs.org, openbmc@lists.ozlabs.org, linux-stm32@st-md-mailman.stormreply.com X-Mailer: b4 0.15-dev X-GND-Sasl: miquel.raynal@bootlin.com Every ->exec_op() call correctly configures the spi bus speed to the maximum allowed frequency for the memory using the constant spi default parameter. Since we can now have per-operation constraints, let's use the value that comes from the spi-mem operation structure instead. In case there is no specific limitation for this operation, the default spi device value will be given anyway. This controller however performed a frequency check, which is also observed during the ->check_op() phase. The per-operation frequency capability is thus advertised to the spi-mem core. Cc: Conor Dooley Cc: Daire McNamara Signed-off-by: Miquel Raynal --- drivers/spi/spi-microchip-core-qspi.c | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/drivers/spi/spi-microchip-core-qspi.c b/drivers/spi/spi-microc= hip-core-qspi.c index ad2b5ffa6153433490f09bdd4c362273a0218432..fa828fcaaef2d4b44c21e08c09e= 6afbb7ba3de3d 100644 --- a/drivers/spi/spi-microchip-core-qspi.c +++ b/drivers/spi/spi-microchip-core-qspi.c @@ -265,7 +265,8 @@ static irqreturn_t mchp_coreqspi_isr(int irq, void *dev= _id) return ret; } =20 -static int mchp_coreqspi_setup_clock(struct mchp_coreqspi *qspi, struct sp= i_device *spi) +static int mchp_coreqspi_setup_clock(struct mchp_coreqspi *qspi, struct sp= i_device *spi, + const struct spi_mem_op *op) { unsigned long clk_hz; u32 control, baud_rate_val =3D 0; @@ -274,11 +275,11 @@ static int mchp_coreqspi_setup_clock(struct mchp_core= qspi *qspi, struct spi_devi if (!clk_hz) return -EINVAL; =20 - baud_rate_val =3D DIV_ROUND_UP(clk_hz, 2 * spi->max_speed_hz); + baud_rate_val =3D DIV_ROUND_UP(clk_hz, 2 * op->max_freq); if (baud_rate_val > MAX_DIVIDER || baud_rate_val < MIN_DIVIDER) { dev_err(&spi->dev, "could not configure the clock for spi clock %d Hz & system clock %ld H= z\n", - spi->max_speed_hz, clk_hz); + op->max_freq, clk_hz); return -EINVAL; } =20 @@ -399,7 +400,7 @@ static int mchp_coreqspi_exec_op(struct spi_mem *mem, c= onst struct spi_mem_op *o if (err) goto error; =20 - err =3D mchp_coreqspi_setup_clock(qspi, mem->spi); + err =3D mchp_coreqspi_setup_clock(qspi, mem->spi, op); if (err) goto error; =20 @@ -457,6 +458,10 @@ static int mchp_coreqspi_exec_op(struct spi_mem *mem, = const struct spi_mem_op *o =20 static bool mchp_coreqspi_supports_op(struct spi_mem *mem, const struct sp= i_mem_op *op) { + struct mchp_coreqspi *qspi =3D spi_controller_get_devdata(mem->spi->contr= oller); + unsigned long clk_hz; + u32 baud_rate_val; + if (!spi_mem_default_supports_op(mem, op)) return false; =20 @@ -479,6 +484,14 @@ static bool mchp_coreqspi_supports_op(struct spi_mem *= mem, const struct spi_mem_ return false; } =20 + clk_hz =3D clk_get_rate(qspi->clk); + if (!clk_hz) + return false; + + baud_rate_val =3D DIV_ROUND_UP(clk_hz, 2 * op->max_freq); + if (baud_rate_val > MAX_DIVIDER || baud_rate_val < MIN_DIVIDER) + return false; + return true; } =20 @@ -498,6 +511,10 @@ static const struct spi_controller_mem_ops mchp_coreqs= pi_mem_ops =3D { .exec_op =3D mchp_coreqspi_exec_op, }; =20 +static const struct spi_controller_mem_caps mchp_coreqspi_mem_caps =3D { + .per_op_freq =3D true, +}; + static int mchp_coreqspi_probe(struct platform_device *pdev) { struct spi_controller *ctlr; @@ -540,6 +557,7 @@ static int mchp_coreqspi_probe(struct platform_device *= pdev) =20 ctlr->bits_per_word_mask =3D SPI_BPW_MASK(8); ctlr->mem_ops =3D &mchp_coreqspi_mem_ops; + ctlr->mem_caps =3D &mchp_coreqspi_mem_caps; ctlr->setup =3D mchp_coreqspi_setup_op; ctlr->mode_bits =3D SPI_CPOL | SPI_CPHA | SPI_RX_DUAL | SPI_RX_QUAD | SPI_TX_DUAL | SPI_TX_QUAD; --=20 2.47.0