drivers/mtd/at25ee: Multi-device SPI bus support

Adds a device ID to at25ee_initialize, which is stored in the
at25ee_dev_s structure. This ID is used when calling SPI_SELECT.

The implementation is based on the handling of the chip select in
mtd/ramtron.c

This change is NOT backward compatible: the function signature has changed

Signed-off-by: Antoine Juckler <6445757+ajuckler@users.noreply.github.com>
This commit is contained in:
Antoine Juckler
2025-11-11 15:06:10 +09:00
committed by Alan C. Assis
parent 34febea2df
commit 81550800d4
2 changed files with 18 additions and 12 deletions

View File

@@ -115,6 +115,7 @@ struct at25ee_dev_s
{
struct mtd_dev_s mtd; /* MTD interface */
struct spi_dev_s *spi; /* SPI device where the EEPROM is attached */
uint16_t devid; /* SPI device ID to manage CS lines in board */
uint32_t size; /* in bytes, expanded from geometry */
uint16_t pgsize; /* write block size, in bytes, expanded from
* geometry
@@ -370,7 +371,7 @@ static void at25ee_waitwritecomplete(struct at25ee_dev_s *priv)
/* Select this FLASH part */
at25ee_lock(priv->spi);
SPI_SELECT(priv->spi, SPIDEV_EEPROM(0), true);
SPI_SELECT(priv->spi, SPIDEV_EEPROM(priv->devid), true);
/* Send "Read Status Register (RDSR)" command */
@@ -384,7 +385,7 @@ static void at25ee_waitwritecomplete(struct at25ee_dev_s *priv)
/* Deselect the FLASH */
SPI_SELECT(priv->spi, SPIDEV_EEPROM(0), false);
SPI_SELECT(priv->spi, SPIDEV_EEPROM(priv->devid), false);
at25ee_unlock(priv->spi);
/* Given that writing could take up to a few milliseconds,
@@ -420,11 +421,11 @@ static void at25ee_waitwritecomplete(struct at25ee_dev_s *priv)
static void at25ee_writeenable(FAR struct at25ee_dev_s *priv, int enable)
{
at25ee_lock(priv->spi);
SPI_SELECT(priv->spi, SPIDEV_EEPROM(0), true);
SPI_SELECT(priv->spi, SPIDEV_EEPROM(priv->devid), true);
SPI_SEND(priv->spi, enable ? AT25EE_CMD_WREN : AT25EE_CMD_WRDIS);
SPI_SELECT(priv->spi, SPIDEV_EEPROM(0), false);
SPI_SELECT(priv->spi, SPIDEV_EEPROM(priv->devid), false);
at25ee_unlock(priv->spi);
}
@@ -449,12 +450,12 @@ static void at25ee_writepage(FAR struct at25ee_dev_s *priv, uint32_t devaddr,
FAR const uint8_t *data, size_t len)
{
at25ee_lock(priv->spi);
SPI_SELECT(priv->spi, SPIDEV_EEPROM(0), true);
SPI_SELECT(priv->spi, SPIDEV_EEPROM(priv->devid), true);
at25ee_sendcmd(priv->spi, AT25EE_CMD_WRITE, priv->addrlen, devaddr);
SPI_SNDBLOCK(priv->spi, data, len);
SPI_SELECT(priv->spi, SPIDEV_EEPROM(0), false);
SPI_SELECT(priv->spi, SPIDEV_EEPROM(priv->devid), false);
at25ee_unlock(priv->spi);
}
@@ -617,7 +618,7 @@ static ssize_t at25ee_read(FAR struct mtd_dev_s *dev, off_t offset,
at25ee_lock(priv->spi);
SPI_SELECT(priv->spi, SPIDEV_EEPROM(0), true);
SPI_SELECT(priv->spi, SPIDEV_EEPROM(priv->devid), true);
/* STM32F4Disco: There is a 25 us delay here */
@@ -625,7 +626,7 @@ static ssize_t at25ee_read(FAR struct mtd_dev_s *dev, off_t offset,
SPI_RECVBLOCK(priv->spi, buf, nbytes);
SPI_SELECT(priv->spi, SPIDEV_EEPROM(0), false);
SPI_SELECT(priv->spi, SPIDEV_EEPROM(priv->devid), false);
at25ee_unlock(priv->spi);
@@ -1007,16 +1008,18 @@ static int at25ee_ioctl(FAR struct mtd_dev_s *dev,
*
* Input Parameters:
* dev - a reference to the spi device structure
* spi_devid - SPI device ID to manage CS lines in board
* devtype - device type, from include/nuttx/eeprom/spi_xx25xx.h
* readonly - sets block driver to be readonly
*
* Returned Value:
* Initialised device instance (success) or NULL (fail)
* Initialised device structure (success) of NULL (fail)
*
****************************************************************************/
FAR struct mtd_dev_s *at25ee_initialize(FAR struct spi_dev_s *dev,
int devtype, int readonly)
uint16_t spi_devid, int devtype,
int readonly)
{
FAR struct at25ee_dev_s *priv;
@@ -1042,6 +1045,7 @@ FAR struct mtd_dev_s *at25ee_initialize(FAR struct spi_dev_s *dev,
nxmutex_init(&priv->lock);
priv->spi = dev;
priv->devid = spi_devid;
priv->size = 128 << g_at25ee_devices[devtype].bytes;
priv->pgsize = 8 << g_at25ee_devices[devtype].pagesize;
priv->addrlen = g_at25ee_devices[devtype].addrlen << 3;

View File

@@ -418,7 +418,7 @@ FAR struct mtd_dev_s *at24c_initialize(FAR struct i2c_master_s *dev);
#endif
/****************************************************************************
* Name: at25xx_initialize
* Name: at25ee_initialize
*
* Description:
* Create an initialized MTD device instance for an AT25 SPI EEPROM
@@ -428,6 +428,7 @@ FAR struct mtd_dev_s *at24c_initialize(FAR struct i2c_master_s *dev);
*
* Input Parameters:
* dev - a reference to the spi device structure
* spi_devid - SPI device ID to manage CS lines in board
* devtype - device type, from include/nuttx/eeprom/spi_xx25xx.h
* readonly - sets block driver to be readonly
*
@@ -437,7 +438,8 @@ FAR struct mtd_dev_s *at24c_initialize(FAR struct i2c_master_s *dev);
****************************************************************************/
FAR struct mtd_dev_s *at25ee_initialize(FAR struct spi_dev_s *dev,
int devtype, int readonly);
uint16_t spi_devid, int devtype,
int readonly);
/****************************************************************************
* Name: at24c_uninitialize