Linux Documentation
 help / color / mirror / Atom feed
From: Miquel Raynal <miquel.raynal@bootlin.com>
To: Tudor Ambarus <tudor.ambarus@linaro.org>
Cc: Pratyush Yadav <pratyush@kernel.org>,
	 Michael Walle <mwalle@kernel.org>,
	 Takahiro Kuwano <takahiro.kuwano@infineon.com>,
	Richard Weinberger <richard@nod.at>,
	 Vignesh Raghavendra <vigneshr@ti.com>,
	 Jonathan Corbet <corbet@lwn.net>,
	 Shuah Khan <skhan@linuxfoundation.org>,
	 Sean Anderson <sean.anderson@linux.dev>,
	Thomas Petazzoni <thomas.petazzoni@bootlin.com>,
	 Steam Lin <STLin2@winbond.com>,
	 linux-mtd@lists.infradead.org, linux-kernel@vger.kernel.org,
	 linux-doc@vger.kernel.org
Subject: Re: [PATCH v5 14/28] mtd: spi-nor: swp: Create helpers for building the SR register
Date: Fri, 22 May 2026 18:35:52 +0200	[thread overview]
Message-ID: <87tsrzo107.fsf@bootlin.com> (raw)
In-Reply-To: <0640ef90-52f4-443b-90c9-ac4acb48d59f@linaro.org> (Tudor Ambarus's message of "Fri, 22 May 2026 12:56:55 +0300")

On 22/05/2026 at 12:56:55 +03, Tudor Ambarus <tudor.ambarus@linaro.org> wrote:

> On 5/7/26 7:46 PM, Miquel Raynal wrote:
>> The status register contains 3 or 4 BP (Block Protect) bits, 0 or 1
>> TB (Top/Bottom) bit, soon 0 or 1 CMP (Complement) bit. The last BP bit
>> and the TB bit locations change between vendors. The whole logic of
>> buildling the content of the status register based on some input
>> conditions is used two times and soon will be used 4 times.
>> 
>> Create dedicated helpers for these steps.
>> 
>> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
>> ---
>>  drivers/mtd/spi-nor/swp.c | 83 +++++++++++++++++++++++++++++------------------
>>  1 file changed, 51 insertions(+), 32 deletions(-)
>> 
>> diff --git a/drivers/mtd/spi-nor/swp.c b/drivers/mtd/spi-nor/swp.c
>> index 540cd221c455..8aa0fe297188 100644
>> --- a/drivers/mtd/spi-nor/swp.c
>> +++ b/drivers/mtd/spi-nor/swp.c
>> @@ -125,6 +125,43 @@ static bool spi_nor_is_unlocked_sr(struct spi_nor *nor, loff_t ofs, u64 len,
>>  	return spi_nor_check_lock_status_sr(nor, ofs, len, sr, false);
>>  }
>>  
>> +static int spi_nor_sr_set_bp_mask(struct spi_nor *nor, u8 *sr, u8 pow)
>> +{
>> +	u8 mask = spi_nor_get_sr_bp_mask(nor);
>> +	u8 val = pow << SR_BP_SHIFT;
>> +
>> +	if (nor->flags & SNOR_F_HAS_SR_BP3_BIT6 && val & SR_BP3)
>> +		val = (val & ~SR_BP3) | SR_BP3_BIT6;
>> +
>> +	if (val & ~mask)
>> +		return -EINVAL;
>> +
>> +	sr[0] = val;
>
> As sashiko already noticed, I think too this should have been sr[0] |= val

Yes indeed, that is a very good catch. Doesn't bug with my chips which
carry the QE bit in the second register, but it's unintended. Fixed on
my side, I will continue with Sashiko's feedback and send a v6.

Thanks,
Miquèl

  reply	other threads:[~2026-05-22 16:36 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-05-07 16:46 [PATCH v5 00/28] mtd: spi-nor: Enhance software protection Miquel Raynal
2026-05-07 16:46 ` [PATCH v5 01/28] mtd: spi-nor: Drop duplicate Kconfig dependency Miquel Raynal
2026-05-07 16:46 ` [PATCH v5 02/28] mtd: spi-nor: debugfs: Fix the flags list Miquel Raynal
2026-05-07 16:46 ` [PATCH v5 03/28] mtd: spi-nor: Make sure the QE bit is kept enabled if useful Miquel Raynal
2026-05-07 16:46 ` [PATCH v5 04/28] mtd: spi-nor: swp: Improve locking user experience Miquel Raynal
2026-05-22  9:10   ` Tudor Ambarus
2026-05-22 15:55     ` Miquel Raynal
2026-05-22 16:07       ` Tudor Ambarus
2026-05-22 16:39         ` Miquel Raynal
2026-05-07 16:46 ` [PATCH v5 05/28] mtd: spi-nor: Improve opcodes documentation Miquel Raynal
2026-05-07 16:46 ` [PATCH v5 06/28] mtd: spi-nor: debugfs: Align variable access with the rest of the file Miquel Raynal
2026-05-07 16:46 ` [PATCH v5 07/28] mtd: spi-nor: debugfs: Enhance output Miquel Raynal
2026-05-07 16:46 ` [PATCH v5 08/28] mtd: spi-nor: swp: Explain the MEMLOCK ioctl implementation behaviour Miquel Raynal
2026-05-07 16:46 ` [PATCH v5 09/28] mtd: spi-nor: swp: Clarify a comment Miquel Raynal
2026-05-07 16:46 ` [PATCH v5 10/28] mtd: spi-nor: swp: Use a pointer for SR instead of a single byte Miquel Raynal
2026-05-07 16:46 ` [PATCH v5 11/28] mtd: spi-nor: swp: Create a helper that writes SR, CR and checks Miquel Raynal
2026-05-07 16:46 ` [PATCH v5 12/28] mtd: spi-nor: swp: Rename a mask Miquel Raynal
2026-05-22  9:37   ` Tudor Ambarus
2026-05-07 16:46 ` [PATCH v5 13/28] mtd: spi-nor: swp: Create a TB intermediate variable Miquel Raynal
2026-05-22  9:39   ` Tudor Ambarus
2026-05-22 16:06     ` Miquel Raynal
2026-05-22 16:19       ` Tudor Ambarus
2026-05-07 16:46 ` [PATCH v5 14/28] mtd: spi-nor: swp: Create helpers for building the SR register Miquel Raynal
2026-05-22  9:56   ` Tudor Ambarus
2026-05-22 16:35     ` Miquel Raynal [this message]
2026-05-07 16:46 ` [PATCH v5 15/28] mtd: spi-nor: swp: Simplify checking the locked/unlocked range Miquel Raynal
2026-05-07 16:46 ` [PATCH v5 16/28] mtd: spi-nor: swp: Cosmetic changes Miquel Raynal
2026-05-07 16:46 ` [PATCH v5 17/28] mtd: spi-nor: Create a local SR cache Miquel Raynal
2026-05-07 16:46 ` [PATCH v5 18/28] mtd: spi-nor: debugfs: Add locking support Miquel Raynal
2026-05-07 16:47 ` [PATCH v5 19/28] mtd: spi-nor: debugfs: Add a locked sectors map Miquel Raynal
2026-05-07 16:47 ` [PATCH v5 20/28] mtd: spi-nor: Add steps for testing locking support Miquel Raynal
2026-05-07 16:47 ` [PATCH v5 21/28] mtd: spi-nor: swp: Add support for the complement feature Miquel Raynal
2026-05-07 16:47 ` [PATCH v5 22/28] mtd: spi-nor: Add steps for testing locking with CMP Miquel Raynal
2026-05-07 16:47 ` [PATCH v5 23/28] mtd: spi-nor: winbond: Add W25H512NWxxAM CMP locking support Miquel Raynal
2026-05-07 16:47 ` [PATCH v5 24/28] mtd: spi-nor: winbond: Add W25H01NWxxAM " Miquel Raynal
2026-05-07 16:47 ` [PATCH v5 25/28] mtd: spi-nor: winbond: Add W25H02NWxxAM " Miquel Raynal
2026-05-07 16:47 ` [PATCH v5 26/28] mtd: spi-nor: winbond: Add W25H01NWxxIQ " Miquel Raynal
2026-05-07 16:47 ` [PATCH v5 27/28] mtd: spi-nor: winbond: Add W25Q01NWxxIM " Miquel Raynal
2026-05-07 16:47 ` [PATCH v5 28/28] mtd: spi-nor: winbond: Add W25Q02NWxxIM " Miquel Raynal
2026-05-22  9:07 ` [PATCH v5 00/28] mtd: spi-nor: Enhance software protection Tudor Ambarus

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=87tsrzo107.fsf@bootlin.com \
    --to=miquel.raynal@bootlin.com \
    --cc=STLin2@winbond.com \
    --cc=corbet@lwn.net \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mtd@lists.infradead.org \
    --cc=mwalle@kernel.org \
    --cc=pratyush@kernel.org \
    --cc=richard@nod.at \
    --cc=sean.anderson@linux.dev \
    --cc=skhan@linuxfoundation.org \
    --cc=takahiro.kuwano@infineon.com \
    --cc=thomas.petazzoni@bootlin.com \
    --cc=tudor.ambarus@linaro.org \
    --cc=vigneshr@ti.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox