Skip to content

Commit 1de6201

Browse files
committed
driver/mtd: ramtron multi-device spi bus support
Adds a device ID to ramtron_initialize, which is stored in the ramtron_dev_s structure. This ID is used when calling SPI_SELECT to board specific logic to allow chip select on the SPI bus. This change is NOT backwards compatible, as it changes the function signature of ramtron_initialize. This implementation is based on the handling of chip select in nuttx/drivers/mtd/sst26.c:sst26_initialize_spi(). Additional Changes: - Add MB85RS64V to ramtron supported parts list.
1 parent e0b0231 commit 1de6201

File tree

2 files changed

+34
-16
lines changed

2 files changed

+34
-16
lines changed

drivers/mtd/ramtron.c

Lines changed: 30 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ struct ramtron_dev_s
145145
FAR struct spi_dev_s *dev; /* Saved SPI interface instance */
146146
uint8_t sectorshift;
147147
uint8_t pageshift;
148+
uint16_t devid; /* SPI device ID to manage CS lines in board */
148149
uint32_t nsectors;
149150
uint32_t npages;
150151
uint32_t speed; /* Overridable via ioctl */
@@ -323,6 +324,18 @@ static const struct ramtron_parts_s g_ramtron_parts[] =
323324
#ifdef CONFIG_RAMTRON_CHUNKING
324325
, false, /* chunked */
325326
RAMTRON_EMULATE_PAGE_SIZE /* chunksize */
327+
#endif
328+
},
329+
{
330+
"MB85RS64V", /* name */
331+
0x03, /* id1 */
332+
0x02, /* id2 */
333+
8L * 1024L, /* size */
334+
2, /* addr_len */
335+
20000000 /* speed */
336+
#ifdef CONFIG_RAMTRON_CHUNKING
337+
, false, /* chunked */
338+
RAMTRON_EMULATE_PAGE_SIZE /* chunksize */
326339
#endif
327340
},
328341
{
@@ -484,7 +497,7 @@ static inline int ramtron_readid(struct ramtron_dev_s *priv)
484497
/* Lock the SPI bus, configure the bus, and select this FLASH part. */
485498

486499
ramtron_lock(priv);
487-
SPI_SELECT(priv->dev, SPIDEV_FLASH(0), true);
500+
SPI_SELECT(priv->dev, SPIDEV_FLASH(priv->devid), true);
488501

489502
/* Send the "Read ID (RDID)" command */
490503

@@ -514,7 +527,7 @@ static inline int ramtron_readid(struct ramtron_dev_s *priv)
514527

515528
/* Deselect the FLASH and unlock the bus */
516529

517-
SPI_SELECT(priv->dev, SPIDEV_FLASH(0), false);
530+
SPI_SELECT(priv->dev, SPIDEV_FLASH(priv->devid), false);
518531
ramtron_unlock(priv->dev);
519532

520533
/* Select part from the part list */
@@ -556,15 +569,15 @@ static void ramtron_writeenable(struct ramtron_dev_s *priv)
556569
{
557570
/* Select this FLASH part */
558571

559-
SPI_SELECT(priv->dev, SPIDEV_FLASH(0), true);
572+
SPI_SELECT(priv->dev, SPIDEV_FLASH(priv->devid), true);
560573

561574
/* Send "Write Enable (WREN)" command */
562575

563576
SPI_SEND(priv->dev, RAMTRON_WREN);
564577

565578
/* Deselect the FLASH */
566579

567-
SPI_SELECT(priv->dev, SPIDEV_FLASH(0), false);
580+
SPI_SELECT(priv->dev, SPIDEV_FLASH(priv->devid), false);
568581
finfo("Enabled\n");
569582
}
570583

@@ -604,7 +617,7 @@ static inline int ramtron_pagewrite(struct ramtron_dev_s *priv,
604617

605618
/* Select this FLASH part */
606619

607-
SPI_SELECT(priv->dev, SPIDEV_FLASH(0), true);
620+
SPI_SELECT(priv->dev, SPIDEV_FLASH(priv->devid), true);
608621

609622
/* Send "Page Program (PP)" command */
610623

@@ -620,7 +633,7 @@ static inline int ramtron_pagewrite(struct ramtron_dev_s *priv,
620633

621634
/* Deselect the FLASH: Chip Select high */
622635

623-
SPI_SELECT(priv->dev, SPIDEV_FLASH(0), false);
636+
SPI_SELECT(priv->dev, SPIDEV_FLASH(priv->devid), false);
624637
finfo("Written\n");
625638

626639
return OK;
@@ -808,7 +821,7 @@ static ssize_t ramtron_read(FAR struct mtd_dev_s *dev,
808821

809822
/* Select this FLASH part */
810823

811-
SPI_SELECT(priv->dev, SPIDEV_FLASH(0), true);
824+
SPI_SELECT(priv->dev, SPIDEV_FLASH(priv->devid), true);
812825

813826
/* Send "Read from Memory " instruction */
814827

@@ -824,7 +837,7 @@ static ssize_t ramtron_read(FAR struct mtd_dev_s *dev,
824837

825838
/* Deselect the FLASH and unlock the SPI bus */
826839

827-
SPI_SELECT(priv->dev, SPIDEV_FLASH(0), false);
840+
SPI_SELECT(priv->dev, SPIDEV_FLASH(priv->devid), false);
828841
ramtron_unlock(priv->dev);
829842

830843
finfo("return nbytes: %d\n", (int)nbytes);
@@ -932,19 +945,22 @@ static int ramtron_ioctl(FAR struct mtd_dev_s *dev,
932945
* as instances that can be bound to other functions
933946
* (such as a block or character driver front end).
934947
*
948+
* Note:
949+
* This implementation can handle multiple FLASH parts per SPI device by
950+
* using the spi_devid to handle chip select between devices. The spi_devid
951+
* passed to this function must be handled by the corresponding spi select
952+
* function in board files.
935953
****************************************************************************/
936954

937-
FAR struct mtd_dev_s *ramtron_initialize(FAR struct spi_dev_s *dev)
955+
FAR struct mtd_dev_s *ramtron_initialize(FAR struct spi_dev_s *dev,
956+
uint16_t spi_devid)
938957
{
939958
FAR struct ramtron_dev_s *priv;
940959

941960
finfo("dev: %p\n", dev);
942961

943962
/* Allocate a state structure (we allocate the structure instead of using
944963
* a fixed, static allocation so that we can handle multiple FLASH devices.
945-
* The current implementation would handle only one FLASH part per SPI
946-
* device (only because of the SPIDEV_FLASH(0) definition) and so would
947-
* have to be extended to handle multiple FLASH parts on the same SPI bus.
948964
*/
949965

950966
priv = (FAR struct ramtron_dev_s *)
@@ -962,10 +978,11 @@ FAR struct mtd_dev_s *ramtron_initialize(FAR struct spi_dev_s *dev)
962978
priv->mtd.ioctl = ramtron_ioctl;
963979
priv->mtd.name = "ramtron";
964980
priv->dev = dev;
981+
priv->devid = spi_devid;
965982

966983
/* Deselect the FLASH */
967984

968-
SPI_SELECT(dev, SPIDEV_FLASH(0), false);
985+
SPI_SELECT(dev, SPIDEV_FLASH(priv->devid), false);
969986

970987
/* Identify the FLASH chip and get its capacity */
971988

include/nuttx/mtd/mtd.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -510,12 +510,13 @@ void rammtd_uninitialize(FAR struct mtd_dev_s *dev);
510510
* Create and initialize a Ramtron MTD device instance.
511511
*
512512
* Input Parameters:
513-
* start - Address of the beginning of the allocated RAM regions.
514-
* size - The size in bytes of the allocated RAM region.
513+
* dev - Pointer to the SPI device instance.
514+
* spi_devid - SPI device ID to manage CS lines in board
515515
*
516516
****************************************************************************/
517517

518-
FAR struct mtd_dev_s *ramtron_initialize(FAR struct spi_dev_s *dev);
518+
FAR struct mtd_dev_s *ramtron_initialize(FAR struct spi_dev_s *dev,
519+
uint16_t spi_devid);
519520

520521
/****************************************************************************
521522
* Name: sst25_initialize

0 commit comments

Comments
 (0)