This is an automated email from the ASF dual-hosted git repository.
xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git
The following commit(s) were added to refs/heads/master by this push:
new f93a1b34e5f eeprom/spi_xx25xx: Add IOCTL to set Block Protect
f93a1b34e5f is described below
commit f93a1b34e5f2a02c28d7a2ba5a521be6e4810da3
Author: Jiri Vlasak <[email protected]>
AuthorDate: Wed Dec 3 14:24:09 2025 +0100
eeprom/spi_xx25xx: Add IOCTL to set Block Protect
Add IOCTL to set Block Protect, because we need a way to set Block
Protect of an EEPROM.
Signed-off-by: Jiri Vlasak <[email protected]>
---
.../components/drivers/character/eeprom.rst | 11 ++++
drivers/eeprom/i2c_xx24xx.c | 2 +
drivers/eeprom/spi_xx25xx.c | 67 ++++++++++++++++++++++
include/nuttx/eeprom/eeprom.h | 5 ++
4 files changed, 85 insertions(+)
diff --git a/Documentation/components/drivers/character/eeprom.rst
b/Documentation/components/drivers/character/eeprom.rst
index f0aed64b797..04501434f28 100644
--- a/Documentation/components/drivers/character/eeprom.rst
+++ b/Documentation/components/drivers/character/eeprom.rst
@@ -184,6 +184,17 @@ The full list of ``ioctl()`` commands can be found in
Erase the full EEPROM, a dedicated command is used if supported by the
device.
+- ``EEPIOC_BLOCKPROTECT``
+ *Argument:* ``uint8_t``
+
+ Set EEPROM's Block Protect bits. For 25AA160-compatible EEPROM with
+ two Block Protect bits in Status Register, the argument may be:
+
+ - ``0`` for no write protect,
+ - ``1`` to set Block Protection 0 bit of Status Register,
+ - ``2`` to set Block Protection 1 bit of Status Register,
+ - ``3`` to set both Block Protection bits 0 and 1.
+
File Systems
============
diff --git a/drivers/eeprom/i2c_xx24xx.c b/drivers/eeprom/i2c_xx24xx.c
index 06850ebb21f..f3c7558c6d8 100644
--- a/drivers/eeprom/i2c_xx24xx.c
+++ b/drivers/eeprom/i2c_xx24xx.c
@@ -964,6 +964,8 @@ static int ee24xx_ioctl(FAR struct file *filep, int cmd,
unsigned long arg)
ret = ee24xx_eraseall(eedev);
break;
+ /* TODO: add "case EEPIOC_BLOCKPROTECT:" */
+
default:
ret = -ENOTTY;
}
diff --git a/drivers/eeprom/spi_xx25xx.c b/drivers/eeprom/spi_xx25xx.c
index aab8c1ba07c..9c336e8d63c 100644
--- a/drivers/eeprom/spi_xx25xx.c
+++ b/drivers/eeprom/spi_xx25xx.c
@@ -731,6 +731,50 @@ static int ee25xx_erasesector(FAR struct ee25xx_dev_s
*eedev,
return ret;
}
+/****************************************************************************
+ * Name: ee25xx_rdsr
+ *
+ * Description: Read status register.
+ *
+ ****************************************************************************/
+
+static uint8_t ee25xx_rdsr(FAR struct ee25xx_dev_s *eedev)
+{
+ uint8_t tx[2];
+ uint8_t rx[2];
+
+ tx[0] = EE25XX_CMD_RDSR;
+ tx[1] = EE25XX_DUMMY;
+
+ ee25xx_lock(eedev);
+ SPI_SELECT(eedev->spi, SPIDEV_EEPROM(eedev->devid), true);
+ SPI_EXCHANGE(eedev->spi, tx, rx, 2);
+ SPI_SELECT(eedev->spi, SPIDEV_EEPROM(eedev->devid), false);
+ ee25xx_unlock(eedev);
+ return rx[1];
+}
+
+/****************************************************************************
+ * Name: ee25xx_wrsr
+ *
+ * Description: Write status register.
+ *
+ ****************************************************************************/
+
+static void ee25xx_wrsr(FAR struct ee25xx_dev_s *eedev, uint8_t what)
+{
+ uint8_t tx[2];
+
+ tx[0] = EE25XX_CMD_WRSR;
+ tx[1] = what;
+
+ ee25xx_lock(eedev);
+ SPI_SELECT(eedev->spi, SPIDEV_EEPROM(eedev->devid), true);
+ SPI_EXCHANGE(eedev->spi, tx, NULL, 2);
+ SPI_SELECT(eedev->spi, SPIDEV_EEPROM(eedev->devid), false);
+ ee25xx_unlock(eedev);
+}
+
/****************************************************************************
* Driver Functions
****************************************************************************/
@@ -1094,6 +1138,29 @@ static int ee25xx_ioctl(FAR struct file *filep, int cmd,
unsigned long arg)
ret = ee25xx_eraseall(eedev);
break;
+ case EEPIOC_BLOCKPROTECT:
+ {
+ /* Get current value of status register. */
+
+ ret = ee25xx_rdsr(eedev);
+
+ /* Clear Block Protection bits. */
+
+ ret &= ~(EE25XX_SR_BP0 | EE25XX_SR_BP1);
+
+ /* Set Block Protection bits. */
+
+ ret |= ((uint8_t)arg << 2) & (EE25XX_SR_BP0 | EE25XX_SR_BP1);
+
+ /* Write status register. */
+
+ ee25xx_writeenable(eedev, true);
+ ee25xx_wrsr(eedev, ret);
+ ee25xx_waitwritecomplete(eedev);
+ ret = OK;
+ }
+ break;
+
default:
ret = -ENOTTY;
}
diff --git a/include/nuttx/eeprom/eeprom.h b/include/nuttx/eeprom/eeprom.h
index 4d7dccfe0cf..a9f50b12b0a 100644
--- a/include/nuttx/eeprom/eeprom.h
+++ b/include/nuttx/eeprom/eeprom.h
@@ -84,6 +84,11 @@
* provides success/failure
* indication). */
+#define EEPIOC_BLOCKPROTECT _EEPIOC(0x005) /* Set which memory blocks to
+ * protect.
+ * IN: Which blocks as integer.
+ * OUT: OK (0) on success. */
+
/************************************************************************************
* Type Definitions
************************************************************************************/