diff options
author | Gregory Nutt <gnutt@nuttx.org> | 2013-05-03 14:32:08 -0600 |
---|---|---|
committer | Gregory Nutt <gnutt@nuttx.org> | 2013-05-03 14:32:08 -0600 |
commit | 0d40d1bd1474f04984320a650148d66095a8ff9c (patch) | |
tree | ac4f2e6df2a6fd5a7050f567704beafc2c4bca8b /nuttx/drivers/mtd | |
parent | 1092e4b16395d945517b9bcbc2c48828fbe9303c (diff) | |
download | px4-nuttx-0d40d1bd1474f04984320a650148d66095a8ff9c.tar.gz px4-nuttx-0d40d1bd1474f04984320a650148d66095a8ff9c.tar.bz2 px4-nuttx-0d40d1bd1474f04984320a650148d66095a8ff9c.zip |
Replace CONFIG_MTD_SMART in MTD drivers with other conditions
Diffstat (limited to 'nuttx/drivers/mtd')
-rw-r--r-- | nuttx/drivers/mtd/Kconfig | 8 | ||||
-rw-r--r-- | nuttx/drivers/mtd/m25px.c | 12 | ||||
-rw-r--r-- | nuttx/drivers/mtd/rammtd.c | 66 |
3 files changed, 46 insertions, 40 deletions
diff --git a/nuttx/drivers/mtd/Kconfig b/nuttx/drivers/mtd/Kconfig index 4754fbeb7..e4107949b 100644 --- a/nuttx/drivers/mtd/Kconfig +++ b/nuttx/drivers/mtd/Kconfig @@ -135,6 +135,14 @@ config M25P_MEMORY_TYPE memory type for "F" series parts from EON is 0x31. The 4K sector erase size will automatically be enabled when filessytems that can use it are enabled, such as SMART. +config M25P_SUBSECTOR_ERASE + bool "Sub-Sector Erase" + default n + ---help--- + Some devices (such as the EON EN25F80) support a smaller erase block + size (4K vs 64K). This option enables support for sub-sector erase. + The SMART file system can take advantage of this option if it is enabled. + endif config MTD_SMART diff --git a/nuttx/drivers/mtd/m25px.c b/nuttx/drivers/mtd/m25px.c index 17f7a0672..7dc26b3ee 100644 --- a/nuttx/drivers/mtd/m25px.c +++ b/nuttx/drivers/mtd/m25px.c @@ -204,7 +204,7 @@ struct m25p_dev_s uint8_t pageshift; /* 8 */ uint16_t nsectors; /* 128 or 64 */ uint32_t npages; /* 32,768 or 65,536 */ -#ifdef CONFIG_MTD_SMART +#ifdef CONFIG_M25P_SUBSECTOR_ERASE uint8_t subsectorshift; /* 0, 12 or 13 (4K or 8K) */ #endif }; @@ -322,7 +322,7 @@ static inline int m25p_readid(struct m25p_dev_s *priv) { /* Okay.. is it a FLASH capacity that we understand? */ -#ifdef CONFIG_MTD_SMART +#ifdef CONFIG_M25P_SUBSECTOR_ERASE priv->subsectorshift = 0; #endif @@ -344,7 +344,7 @@ static inline int m25p_readid(struct m25p_dev_s *priv) priv->npages = M25P_EN25F80_NPAGES; priv->sectorshift = M25P_EN25F80_SECTOR_SHIFT; priv->nsectors = M25P_EN25F80_NSECTORS; -#ifdef CONFIG_MTD_SMART +#ifdef CONFIG_M25P_SUBSECTOR_ERASE priv->subsectorshift = M25P_EN25F80_SUBSECT_SHIFT; #endif return OK; @@ -486,7 +486,7 @@ static void m25p_sectorerase(struct m25p_dev_s *priv, off_t sector, uint8_t type { off_t offset; -#ifdef CONFIG_MTD_SMART +#ifdef CONFIG_M25P_SUBSECTOR_ERASE if (priv->subsectorshift > 0) { offset = sector << priv->subsectorshift; @@ -681,7 +681,7 @@ static int m25p_erase(FAR struct mtd_dev_s *dev, off_t startblock, size_t nblock m25p_lock(priv->dev); while (blocksleft > 0) { -#ifdef CONFIG_MTD_SMART +#ifdef CONFIG_M25P_SUBSECTOR_ERASE size_t sectorboundry; size_t blkper; @@ -928,7 +928,7 @@ static int m25p_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg) */ geo->blocksize = (1 << priv->pageshift); -#ifdef CONFIG_MTD_SMART +#ifdef CONFIG_M25P_SUBSECTOR_ERASE if (priv->subsectorshift > 0) { geo->erasesize = (1 << priv->subsectorshift); diff --git a/nuttx/drivers/mtd/rammtd.c b/nuttx/drivers/mtd/rammtd.c index 137f91f73..575c3fb31 100644 --- a/nuttx/drivers/mtd/rammtd.c +++ b/nuttx/drivers/mtd/rammtd.c @@ -121,6 +121,12 @@ static ssize_t ram_bread(FAR struct mtd_dev_s *dev, off_t startblock, size_t nbl FAR uint8_t *buf); static ssize_t ram_bwrite(FAR struct mtd_dev_s *dev, off_t startblock, size_t nblocks, FAR const uint8_t *buf); +static ssize_t ram_byteread(FAR struct mtd_dev_s *dev, off_t offset, + size_t nbytes, FAR uint8_t *buf); +#ifdef CONFIG_MTD_BYTE_WRITE +static ssize_t ram_bytewrite(FAR struct mtd_dev_s *dev, off_t offset, + size_t nbytes, FAR const uint8_t *buf); +#endif static int ram_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg); /**************************************************************************** @@ -160,7 +166,7 @@ static void *ram_write(FAR void *dest, FAR const void *src, size_t len) #endif /* Report any attempt to change the value of bits that are not in the - * erased state. + * erased state. */ #ifdef CONFIG_DEBUG @@ -225,30 +231,6 @@ static int ram_erase(FAR struct mtd_dev_s *dev, off_t startblock, size_t nblocks } /**************************************************************************** - * Name: ram_readbytes - ****************************************************************************/ - -#ifdef CONFIG_MTD_SMART -static ssize_t ram_read_bytes(FAR struct mtd_dev_s *dev, off_t offset, - size_t nbytes, FAR uint8_t *buf) -{ - FAR struct ram_dev_s *priv = (FAR struct ram_dev_s *)dev; - - DEBUGASSERT(dev && buf); - - /* Don't let read read past end of buffer */ - - if (offset + nbytes > priv->nblocks * CONFIG_RAMMTD_ERASESIZE) - { - return 0; - } - - ram_read(buf, &priv->start[offset], nbytes); - return nbytes; -} -#endif - -/**************************************************************************** * Name: ram_bread ****************************************************************************/ @@ -329,12 +311,34 @@ static ssize_t ram_bwrite(FAR struct mtd_dev_s *dev, off_t startblock, } /**************************************************************************** + * Name: ram_byteread + ****************************************************************************/ + +static ssize_t ram_byteread(FAR struct mtd_dev_s *dev, off_t offset, + size_t nbytes, FAR uint8_t *buf) +{ + FAR struct ram_dev_s *priv = (FAR struct ram_dev_s *)dev; + + DEBUGASSERT(dev && buf); + + /* Don't let read read past end of buffer */ + + if (offset + nbytes > priv->nblocks * CONFIG_RAMMTD_ERASESIZE) + { + return 0; + } + + ram_read(buf, &priv->start[offset], nbytes); + return nbytes; +} + +/**************************************************************************** * Name: ram_bytewrite ****************************************************************************/ #ifdef CONFIG_MTD_BYTE_WRITE static ssize_t ram_bytewrite(FAR struct mtd_dev_s *dev, off_t offset, - size_t nbytes, FAR const uint8_t *buf) + size_t nbytes, FAR const uint8_t *buf) { FAR struct ram_dev_s *priv = (FAR struct ram_dev_s *)dev; off_t maxaddr; @@ -462,17 +466,11 @@ FAR struct mtd_dev_s *rammtd_initialize(FAR uint8_t *start, size_t size) priv->mtd.erase = ram_erase; priv->mtd.bread = ram_bread; priv->mtd.bwrite = ram_bwrite; - priv->mtd.ioctl = ram_ioctl; - priv->mtd.erase = ram_erase; + priv->mtd.read = ram_byteread; #ifdef CONFIG_MTD_BYTE_WRITE priv->mtd.write = ram_bytewrite; #endif - -#ifdef CONFIG_MTD_SMART - priv->mtd.read = ram_read_bytes; -#else - priv->mtd.read = NULL; -#endif + priv->mtd.ioctl = ram_ioctl; priv->start = start; priv->nblocks = nblocks; |