2021-01-27 16:48:40 +01:00
|
|
|
/****************************************************************************
|
2012-12-07 17:00:56 +01:00
|
|
|
* drivers/mtd/at25.c
|
|
|
|
*
|
2021-05-27 11:12:43 +02:00
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one or more
|
|
|
|
* contributor license agreements. See the NOTICE file distributed with
|
|
|
|
* this work for additional information regarding copyright ownership. The
|
|
|
|
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance with the
|
|
|
|
* License. You may obtain a copy of the License at
|
2012-12-07 17:00:56 +01:00
|
|
|
*
|
2021-05-27 11:12:43 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2012-12-07 17:00:56 +01:00
|
|
|
*
|
2021-05-27 11:12:43 +02:00
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
|
|
|
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
|
|
|
* License for the specific language governing permissions and limitations
|
|
|
|
* under the License.
|
2012-12-07 17:00:56 +01:00
|
|
|
*
|
2021-01-27 16:48:40 +01:00
|
|
|
****************************************************************************/
|
2012-12-07 17:00:56 +01:00
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
/****************************************************************************
|
2012-12-07 17:00:56 +01:00
|
|
|
* Included Files
|
2021-01-27 16:48:40 +01:00
|
|
|
****************************************************************************/
|
2012-12-07 17:00:56 +01:00
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
2020-11-30 04:52:33 +01:00
|
|
|
#include <inttypes.h>
|
2012-12-07 17:00:56 +01:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <debug.h>
|
|
|
|
|
|
|
|
#include <nuttx/kmalloc.h>
|
2017-10-06 18:15:01 +02:00
|
|
|
#include <nuttx/signal.h>
|
2012-12-07 17:00:56 +01:00
|
|
|
#include <nuttx/fs/ioctl.h>
|
2013-07-01 16:11:54 +02:00
|
|
|
#include <nuttx/spi/spi.h>
|
2013-11-15 18:22:23 +01:00
|
|
|
#include <nuttx/mtd/mtd.h>
|
2012-12-07 17:00:56 +01:00
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
/****************************************************************************
|
2012-12-07 17:00:56 +01:00
|
|
|
* Pre-processor Definitions
|
2021-01-27 16:48:40 +01:00
|
|
|
****************************************************************************/
|
2018-12-12 13:46:22 +01:00
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
/* Configuration ************************************************************/
|
2012-12-07 17:00:56 +01:00
|
|
|
|
|
|
|
#ifndef CONFIG_AT25_SPIMODE
|
|
|
|
# define CONFIG_AT25_SPIMODE SPIDEV_MODE0
|
|
|
|
#endif
|
|
|
|
|
2013-08-05 16:24:39 +02:00
|
|
|
#ifndef CONFIG_AT25_SPIFREQUENCY
|
|
|
|
# define CONFIG_AT25_SPIFREQUENCY 20000000
|
|
|
|
#endif
|
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
/* AT25 Registers ***********************************************************/
|
2012-12-07 17:00:56 +01:00
|
|
|
|
2018-12-12 13:46:22 +01:00
|
|
|
/* Identification register values */
|
|
|
|
|
|
|
|
#define AT25_MANUFACTURER 0x1f
|
|
|
|
#define AT25_AT25DF081A_TYPE 0x45 /* 8 M-bit */
|
2012-12-07 17:00:56 +01:00
|
|
|
#define AT25_AT25DF321_TYPE 0x47 /* 32 M-bit */
|
|
|
|
|
2018-12-12 13:46:22 +01:00
|
|
|
/* AT25DF081A capacity is 1,048,575 bytes:
|
|
|
|
* (16 sectors) * (65,536 bytes per sector)
|
|
|
|
* (4096 pages) * (256 bytes per page)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define AT25_AT25DF081A_SECTOR_SHIFT 12 /* Sector size 1 << 12 = 4096 */
|
|
|
|
#define AT25_AT25DF081A_NSECTORS 256
|
|
|
|
#define AT25_AT25DF081A_PAGE_SHIFT 9 /* Page size 1 << 8 = 256 */
|
|
|
|
#define AT25_AT25DF081A_NPAGES 2048
|
|
|
|
|
2012-12-07 17:00:56 +01:00
|
|
|
/* AT25DF321 capacity is 4,194,304 bytes:
|
|
|
|
* (64 sectors) * (65,536 bytes per sector)
|
|
|
|
* (16384 pages) * (256 bytes per page)
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define AT25_AT25DF321_SECTOR_SHIFT 12 /* Sector size 1 << 12 = 4096 */
|
|
|
|
#define AT25_AT25DF321_NSECTORS 1024
|
|
|
|
#define AT25_AT25DF321_PAGE_SHIFT 9 /* Page size 1 << 9 = 512 */
|
|
|
|
#define AT25_AT25DF321_NPAGES 8192
|
|
|
|
|
|
|
|
/* Instructions */
|
2020-11-30 04:51:15 +01:00
|
|
|
|
2012-12-07 17:00:56 +01:00
|
|
|
/* Command Value N Description Addr Dummy Data */
|
|
|
|
#define AT25_WREN 0x06 /* 1 Write Enable 0 0 0 */
|
|
|
|
#define AT25_WRDI 0x04 /* 1 Write Disable 0 0 0 */
|
|
|
|
#define AT25_RDID 0x9f /* 1 Read Identification 0 0 1-3 */
|
|
|
|
#define AT25_RDSR 0x05 /* 1 Read Status Register 0 0 >=1 */
|
|
|
|
#define AT25_WRSR 0x01 /* 1 Write Status Register 0 0 1 */
|
|
|
|
#define AT25_READ 0x03 /* 1 Read Data Bytes 3 0 >=1 */
|
|
|
|
#define AT25_FAST_READ 0x0b /* 1 Higher speed read 3 1 >=1 */
|
|
|
|
#define AT25_PP 0x02 /* 1 Page Program 3 0 1-256 */
|
|
|
|
#define AT25_SE 0x20 /* 1 Sector Erase 3 0 0 */
|
|
|
|
#define AT25_BE 0xc7 /* 1 Bulk Erase 0 0 0 */
|
|
|
|
#define AT25_DP 0xb9 /* 2 Deep power down 0 0 0 */
|
|
|
|
#define AT25_RES 0xab /* 2 Read Electronic Signature 0 3 >=1 */
|
|
|
|
|
|
|
|
/* Status register bit definitions */
|
|
|
|
|
2014-03-13 21:07:35 +01:00
|
|
|
#define AT25_SR_BUSY (1 << 0) /* Bit 0: Ready/Busy Status */
|
|
|
|
#define AT25_SR_WEL (1 << 1) /* Bit 1: Write enable latch bit */
|
|
|
|
#define AT25_SR_SWP_SHIFT (2) /* Bits 2-3: Software protection */
|
|
|
|
#define AT25_SR_SWP_MASK (3 << AT25_SR_SWP_SHIFT)
|
|
|
|
#define AT25_SR_WPP (1 << 4) /* Bit 4: Write Protect (/WP) Pin Status */
|
|
|
|
#define AT25_SR_EPE (1 << 5) /* Bit 5: Erase/program error */
|
|
|
|
/* Bit 6: Reserved */
|
|
|
|
#define AT25_SR_SPRL (1 << 7) /* Bit 7: Sector Protection Registers Locked */
|
|
|
|
|
|
|
|
#define AT25_SR_UNPROT 0x00 /* Global unprotect command */
|
2012-12-07 17:00:56 +01:00
|
|
|
|
|
|
|
#define AT25_DUMMY 0xa5
|
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
/****************************************************************************
|
2012-12-07 17:00:56 +01:00
|
|
|
* Private Types
|
2021-01-27 16:48:40 +01:00
|
|
|
****************************************************************************/
|
2012-12-07 17:00:56 +01:00
|
|
|
|
|
|
|
/* This type represents the state of the MTD device. The struct mtd_dev_s
|
|
|
|
* must appear at the beginning of the definition so that you can freely
|
|
|
|
* cast between pointers to struct mtd_dev_s and struct at25_dev_s.
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct at25_dev_s
|
|
|
|
{
|
|
|
|
struct mtd_dev_s mtd; /* MTD interface */
|
|
|
|
FAR struct spi_dev_s *dev; /* Saved SPI interface instance */
|
|
|
|
uint8_t sectorshift; /* 16 or 18 */
|
|
|
|
uint8_t pageshift; /* 8 */
|
|
|
|
uint16_t nsectors; /* 128 or 64 */
|
|
|
|
uint32_t npages; /* 32,768 or 65,536 */
|
|
|
|
};
|
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
/****************************************************************************
|
2012-12-07 17:00:56 +01:00
|
|
|
* Private Function Prototypes
|
2021-01-27 16:48:40 +01:00
|
|
|
****************************************************************************/
|
2012-12-07 17:00:56 +01:00
|
|
|
|
|
|
|
/* Helpers */
|
|
|
|
|
|
|
|
static void at25_lock(FAR struct spi_dev_s *dev);
|
|
|
|
static inline void at25_unlock(FAR struct spi_dev_s *dev);
|
|
|
|
static inline int at25_readid(struct at25_dev_s *priv);
|
|
|
|
static void at25_waitwritecomplete(struct at25_dev_s *priv);
|
|
|
|
static void at25_writeenable(struct at25_dev_s *priv);
|
2021-01-27 16:48:40 +01:00
|
|
|
static inline void at25_sectorerase(struct at25_dev_s *priv,
|
|
|
|
off_t offset);
|
2012-12-07 17:00:56 +01:00
|
|
|
static inline int at25_bulkerase(struct at25_dev_s *priv);
|
2021-01-27 16:48:40 +01:00
|
|
|
static inline void at25_pagewrite(struct at25_dev_s *priv,
|
|
|
|
FAR const uint8_t *buffer,
|
2012-12-07 17:00:56 +01:00
|
|
|
off_t offset);
|
|
|
|
|
|
|
|
/* MTD driver methods */
|
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
static int at25_erase(FAR struct mtd_dev_s *dev,
|
|
|
|
off_t startblock,
|
|
|
|
size_t nblocks);
|
|
|
|
static ssize_t at25_bread(FAR struct mtd_dev_s *dev,
|
|
|
|
off_t startblock,
|
|
|
|
size_t nblocks,
|
|
|
|
FAR uint8_t *buf);
|
|
|
|
static ssize_t at25_bwrite(FAR struct mtd_dev_s *dev,
|
|
|
|
off_t startblock,
|
|
|
|
size_t nblocks,
|
|
|
|
FAR const uint8_t *buf);
|
|
|
|
static ssize_t at25_read(FAR struct mtd_dev_s *dev,
|
|
|
|
off_t offset,
|
|
|
|
size_t nbytes,
|
2012-12-07 17:00:56 +01:00
|
|
|
FAR uint8_t *buffer);
|
2021-01-27 16:48:40 +01:00
|
|
|
static int at25_ioctl(FAR struct mtd_dev_s *dev,
|
|
|
|
int cmd,
|
|
|
|
unsigned long arg);
|
2012-12-07 17:00:56 +01:00
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
/****************************************************************************
|
2012-12-07 17:00:56 +01:00
|
|
|
* Private Functions
|
2021-01-27 16:48:40 +01:00
|
|
|
****************************************************************************/
|
2012-12-07 17:00:56 +01:00
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
/****************************************************************************
|
2012-12-07 17:00:56 +01:00
|
|
|
* Name: at25_lock
|
2021-01-27 16:48:40 +01:00
|
|
|
****************************************************************************/
|
2012-12-07 17:00:56 +01:00
|
|
|
|
|
|
|
static void at25_lock(FAR struct spi_dev_s *dev)
|
|
|
|
{
|
2020-02-23 09:50:23 +01:00
|
|
|
/* On SPI buses where there are multiple devices, it will be necessary to
|
|
|
|
* lock SPI to have exclusive access to the buses for a sequence of
|
2012-12-07 17:00:56 +01:00
|
|
|
* transfers. The bus should be locked before the chip is selected.
|
|
|
|
*
|
2021-01-27 16:48:40 +01:00
|
|
|
* This is a blocking call and will not return until we have exclusive
|
|
|
|
* access to the SPI bus.
|
|
|
|
* We will retain that exclusive access until the bus is unlocked.
|
2012-12-07 17:00:56 +01:00
|
|
|
*/
|
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
SPI_LOCK(dev, true);
|
2012-12-07 17:00:56 +01:00
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
/* After locking the SPI bus, the we also need call the setfrequency,
|
|
|
|
* setbits, and setmode methods to make sure that the SPI is properly
|
|
|
|
* configured for the device.
|
|
|
|
* If the SPI bus is being shared, then it may have been left in an
|
|
|
|
* incompatible state.
|
2012-12-07 17:00:56 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
SPI_SETMODE(dev, CONFIG_AT25_SPIMODE);
|
|
|
|
SPI_SETBITS(dev, 8);
|
2020-01-02 17:49:34 +01:00
|
|
|
SPI_HWFEATURES(dev, 0);
|
|
|
|
SPI_SETFREQUENCY(dev, CONFIG_AT25_SPIFREQUENCY);
|
2012-12-07 17:00:56 +01:00
|
|
|
}
|
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
/****************************************************************************
|
2012-12-07 17:00:56 +01:00
|
|
|
* Name: at25_unlock
|
2021-01-27 16:48:40 +01:00
|
|
|
****************************************************************************/
|
2012-12-07 17:00:56 +01:00
|
|
|
|
|
|
|
static inline void at25_unlock(FAR struct spi_dev_s *dev)
|
|
|
|
{
|
2020-01-02 17:49:34 +01:00
|
|
|
SPI_LOCK(dev, false);
|
2012-12-07 17:00:56 +01:00
|
|
|
}
|
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
/****************************************************************************
|
2012-12-07 17:00:56 +01:00
|
|
|
* Name: at25_readid
|
2021-01-27 16:48:40 +01:00
|
|
|
****************************************************************************/
|
2012-12-07 17:00:56 +01:00
|
|
|
|
|
|
|
static inline int at25_readid(struct at25_dev_s *priv)
|
|
|
|
{
|
|
|
|
uint16_t manufacturer;
|
|
|
|
uint16_t memory;
|
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
finfo("priv: %p\n", priv);
|
2012-12-07 17:00:56 +01:00
|
|
|
|
|
|
|
/* Lock the SPI bus, configure the bus, and select this FLASH part. */
|
|
|
|
|
|
|
|
at25_lock(priv->dev);
|
2017-04-29 20:26:52 +02:00
|
|
|
SPI_SELECT(priv->dev, SPIDEV_FLASH(0), true);
|
2012-12-07 17:00:56 +01:00
|
|
|
|
|
|
|
/* Send the "Read ID (RDID)" command and read the first three ID bytes */
|
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
SPI_SEND(priv->dev, AT25_RDID);
|
2012-12-07 17:00:56 +01:00
|
|
|
manufacturer = SPI_SEND(priv->dev, AT25_DUMMY);
|
|
|
|
memory = SPI_SEND(priv->dev, AT25_DUMMY);
|
2014-04-13 22:32:20 +02:00
|
|
|
|
2012-12-07 17:00:56 +01:00
|
|
|
/* Deselect the FLASH and unlock the bus */
|
|
|
|
|
2017-04-29 20:26:52 +02:00
|
|
|
SPI_SELECT(priv->dev, SPIDEV_FLASH(0), false);
|
2012-12-07 17:00:56 +01:00
|
|
|
at25_unlock(priv->dev);
|
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
finfo("manufacturer: %02x memory: %02x\n",
|
2012-12-07 17:00:56 +01:00
|
|
|
manufacturer, memory);
|
|
|
|
|
|
|
|
/* Check for a valid manufacturer and memory type */
|
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
if (manufacturer == AT25_MANUFACTURER &&
|
|
|
|
memory == AT25_AT25DF081A_TYPE)
|
2018-12-12 13:46:22 +01:00
|
|
|
{
|
|
|
|
priv->sectorshift = AT25_AT25DF081A_SECTOR_SHIFT;
|
|
|
|
priv->nsectors = AT25_AT25DF081A_NSECTORS;
|
|
|
|
priv->pageshift = AT25_AT25DF081A_PAGE_SHIFT;
|
|
|
|
priv->npages = AT25_AT25DF081A_NPAGES;
|
|
|
|
return OK;
|
|
|
|
}
|
2021-01-27 16:48:40 +01:00
|
|
|
else if (manufacturer == AT25_MANUFACTURER &&
|
|
|
|
memory == AT25_AT25DF321_TYPE)
|
2012-12-07 17:00:56 +01:00
|
|
|
{
|
2018-12-12 13:46:22 +01:00
|
|
|
priv->sectorshift = AT25_AT25DF321_SECTOR_SHIFT;
|
|
|
|
priv->nsectors = AT25_AT25DF321_NSECTORS;
|
|
|
|
priv->pageshift = AT25_AT25DF321_PAGE_SHIFT;
|
|
|
|
priv->npages = AT25_AT25DF321_NPAGES;
|
|
|
|
return OK;
|
2012-12-07 17:00:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
/****************************************************************************
|
2012-12-07 17:00:56 +01:00
|
|
|
* Name: at25_waitwritecomplete
|
2021-01-27 16:48:40 +01:00
|
|
|
****************************************************************************/
|
2012-12-07 17:00:56 +01:00
|
|
|
|
|
|
|
static void at25_waitwritecomplete(struct at25_dev_s *priv)
|
|
|
|
{
|
|
|
|
uint8_t status;
|
|
|
|
|
|
|
|
/* Loop as long as the memory is busy with a write cycle */
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
/* Select this FLASH part */
|
|
|
|
|
2017-04-29 20:26:52 +02:00
|
|
|
SPI_SELECT(priv->dev, SPIDEV_FLASH(0), true);
|
2012-12-07 17:00:56 +01:00
|
|
|
|
|
|
|
/* Send "Read Status Register (RDSR)" command */
|
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
SPI_SEND(priv->dev, AT25_RDSR);
|
2012-12-07 17:00:56 +01:00
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
/* Send a dummy byte to generate the clock needed to shift out
|
|
|
|
* the status
|
|
|
|
*/
|
2012-12-07 17:00:56 +01:00
|
|
|
|
|
|
|
status = SPI_SEND(priv->dev, AT25_DUMMY);
|
|
|
|
|
|
|
|
/* Deselect the FLASH */
|
|
|
|
|
2017-04-29 20:26:52 +02:00
|
|
|
SPI_SELECT(priv->dev, SPIDEV_FLASH(0), false);
|
2012-12-07 17:00:56 +01:00
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
/* Given that writing could take up to few tens of milliseconds,
|
|
|
|
* and erasing could take more.
|
|
|
|
* The following short delay in the "busy" case will allow other
|
|
|
|
* peripherals to access the SPI bus.
|
2012-12-07 17:00:56 +01:00
|
|
|
*/
|
|
|
|
|
2014-03-13 21:07:35 +01:00
|
|
|
if ((status & AT25_SR_BUSY) != 0)
|
2012-12-07 17:00:56 +01:00
|
|
|
{
|
|
|
|
at25_unlock(priv->dev);
|
2017-10-06 18:15:01 +02:00
|
|
|
nxsig_usleep(10000);
|
2012-12-07 17:00:56 +01:00
|
|
|
at25_lock(priv->dev);
|
|
|
|
}
|
|
|
|
}
|
2014-03-13 21:07:35 +01:00
|
|
|
while ((status & AT25_SR_BUSY) != 0);
|
2012-12-07 17:00:56 +01:00
|
|
|
|
|
|
|
if (status & AT25_SR_EPE)
|
|
|
|
{
|
2016-06-11 23:50:49 +02:00
|
|
|
ferr("ERROR: Write error, status: 0x%02x\n", status);
|
2012-12-07 17:00:56 +01:00
|
|
|
}
|
2014-04-13 22:32:20 +02:00
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
finfo("Complete, status: 0x%02x\n", status);
|
2012-12-07 17:00:56 +01:00
|
|
|
}
|
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
/****************************************************************************
|
2012-12-07 17:00:56 +01:00
|
|
|
* Name: at25_writeenable
|
2021-01-27 16:48:40 +01:00
|
|
|
****************************************************************************/
|
2012-12-07 17:00:56 +01:00
|
|
|
|
|
|
|
static void at25_writeenable(struct at25_dev_s *priv)
|
|
|
|
{
|
2017-04-29 20:26:52 +02:00
|
|
|
SPI_SELECT(priv->dev, SPIDEV_FLASH(0), true);
|
2020-01-02 17:49:34 +01:00
|
|
|
SPI_SEND(priv->dev, AT25_WREN);
|
2017-04-29 20:26:52 +02:00
|
|
|
SPI_SELECT(priv->dev, SPIDEV_FLASH(0), false);
|
2016-06-11 19:59:51 +02:00
|
|
|
finfo("Enabled\n");
|
2012-12-07 17:00:56 +01:00
|
|
|
}
|
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
/****************************************************************************
|
2012-12-07 17:00:56 +01:00
|
|
|
* Name: at25_sectorerase
|
2021-01-27 16:48:40 +01:00
|
|
|
****************************************************************************/
|
2012-12-07 17:00:56 +01:00
|
|
|
|
|
|
|
static inline void at25_sectorerase(struct at25_dev_s *priv, off_t sector)
|
|
|
|
{
|
|
|
|
off_t offset = sector << priv->sectorshift;
|
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
finfo("sector: %08lx\n", (long)sector);
|
2012-12-07 17:00:56 +01:00
|
|
|
|
|
|
|
/* Wait for any preceding write to complete. We could simplify things by
|
|
|
|
* perform this wait at the end of each write operation (rather than at
|
|
|
|
* the beginning of ALL operations), but have the wait first will slightly
|
|
|
|
* improve performance.
|
|
|
|
*/
|
|
|
|
|
|
|
|
at25_waitwritecomplete(priv);
|
|
|
|
|
|
|
|
/* Send write enable instruction */
|
|
|
|
|
|
|
|
at25_writeenable(priv);
|
|
|
|
|
|
|
|
/* Select this FLASH part */
|
|
|
|
|
2017-04-29 20:26:52 +02:00
|
|
|
SPI_SELECT(priv->dev, SPIDEV_FLASH(0), true);
|
2012-12-07 17:00:56 +01:00
|
|
|
|
|
|
|
/* Send the "Sector Erase (SE)" instruction */
|
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
SPI_SEND(priv->dev, AT25_SE);
|
2012-12-07 17:00:56 +01:00
|
|
|
|
|
|
|
/* Send the sector offset high byte first. For all of the supported
|
|
|
|
* parts, the sector number is completely contained in the first byte
|
|
|
|
* and the values used in the following two bytes don't really matter.
|
|
|
|
*/
|
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
SPI_SEND(priv->dev, (offset >> 16) & 0xff);
|
|
|
|
SPI_SEND(priv->dev, (offset >> 8) & 0xff);
|
|
|
|
SPI_SEND(priv->dev, offset & 0xff);
|
2012-12-07 17:00:56 +01:00
|
|
|
|
|
|
|
/* Deselect the FLASH */
|
|
|
|
|
2017-04-29 20:26:52 +02:00
|
|
|
SPI_SELECT(priv->dev, SPIDEV_FLASH(0), false);
|
2016-06-11 19:59:51 +02:00
|
|
|
finfo("Erased\n");
|
2012-12-07 17:00:56 +01:00
|
|
|
}
|
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
/****************************************************************************
|
2012-12-07 17:00:56 +01:00
|
|
|
* Name: at25_bulkerase
|
2021-01-27 16:48:40 +01:00
|
|
|
****************************************************************************/
|
2012-12-07 17:00:56 +01:00
|
|
|
|
|
|
|
static inline int at25_bulkerase(struct at25_dev_s *priv)
|
|
|
|
{
|
2016-06-11 19:59:51 +02:00
|
|
|
finfo("priv: %p\n", priv);
|
2012-12-07 17:00:56 +01:00
|
|
|
|
|
|
|
/* Wait for any preceding write to complete. We could simplify things by
|
|
|
|
* perform this wait at the end of each write operation (rather than at
|
|
|
|
* the beginning of ALL operations), but have the wait first will slightly
|
|
|
|
* improve performance.
|
|
|
|
*/
|
|
|
|
|
|
|
|
at25_waitwritecomplete(priv);
|
|
|
|
|
|
|
|
/* Send write enable instruction */
|
|
|
|
|
|
|
|
at25_writeenable(priv);
|
|
|
|
|
|
|
|
/* Select this FLASH part */
|
|
|
|
|
2017-04-29 20:26:52 +02:00
|
|
|
SPI_SELECT(priv->dev, SPIDEV_FLASH(0), true);
|
2012-12-07 17:00:56 +01:00
|
|
|
|
|
|
|
/* Send the "Bulk Erase (BE)" instruction */
|
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
SPI_SEND(priv->dev, AT25_BE);
|
2012-12-07 17:00:56 +01:00
|
|
|
|
|
|
|
/* Deselect the FLASH */
|
|
|
|
|
2017-04-29 20:26:52 +02:00
|
|
|
SPI_SELECT(priv->dev, SPIDEV_FLASH(0), false);
|
2016-06-11 19:59:51 +02:00
|
|
|
finfo("Return: OK\n");
|
2012-12-07 17:00:56 +01:00
|
|
|
return OK;
|
|
|
|
}
|
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
/****************************************************************************
|
2012-12-07 17:00:56 +01:00
|
|
|
* Name: at25_pagewrite
|
2021-01-27 16:48:40 +01:00
|
|
|
****************************************************************************/
|
2012-12-07 17:00:56 +01:00
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
static inline void at25_pagewrite(struct at25_dev_s *priv,
|
|
|
|
FAR const uint8_t *buffer,
|
2012-12-07 17:00:56 +01:00
|
|
|
off_t page)
|
|
|
|
{
|
|
|
|
off_t offset = page << 8;
|
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
finfo("page: %08lx offset: %08lx\n", (long)page, (long)offset);
|
2012-12-07 17:00:56 +01:00
|
|
|
|
|
|
|
/* Wait for any preceding write to complete. We could simplify things by
|
|
|
|
* perform this wait at the end of each write operation (rather than at
|
|
|
|
* the beginning of ALL operations), but have the wait first will slightly
|
|
|
|
* improve performance.
|
|
|
|
*/
|
|
|
|
|
|
|
|
at25_waitwritecomplete(priv);
|
|
|
|
|
|
|
|
/* Enable the write access to the FLASH */
|
|
|
|
|
|
|
|
at25_writeenable(priv);
|
2014-04-13 22:32:20 +02:00
|
|
|
|
2012-12-07 17:00:56 +01:00
|
|
|
/* Select this FLASH part */
|
|
|
|
|
2017-04-29 20:26:52 +02:00
|
|
|
SPI_SELECT(priv->dev, SPIDEV_FLASH(0), true);
|
2012-12-07 17:00:56 +01:00
|
|
|
|
|
|
|
/* Send "Page Program (PP)" command */
|
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
SPI_SEND(priv->dev, AT25_PP);
|
2012-12-07 17:00:56 +01:00
|
|
|
|
|
|
|
/* Send the page offset high byte first. */
|
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
SPI_SEND(priv->dev, (offset >> 16) & 0xff);
|
|
|
|
SPI_SEND(priv->dev, (offset >> 8) & 0xff);
|
|
|
|
SPI_SEND(priv->dev, offset & 0xff);
|
2012-12-07 17:00:56 +01:00
|
|
|
|
|
|
|
/* Then write the specified number of bytes */
|
|
|
|
|
|
|
|
SPI_SNDBLOCK(priv->dev, buffer, 256);
|
2014-04-13 22:32:20 +02:00
|
|
|
|
2012-12-07 17:00:56 +01:00
|
|
|
/* Deselect the FLASH: Chip Select high */
|
|
|
|
|
2017-04-29 20:26:52 +02:00
|
|
|
SPI_SELECT(priv->dev, SPIDEV_FLASH(0), false);
|
2016-06-11 19:59:51 +02:00
|
|
|
finfo("Written\n");
|
2012-12-07 17:00:56 +01:00
|
|
|
}
|
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
/****************************************************************************
|
2012-12-07 17:00:56 +01:00
|
|
|
* Name: at25_erase
|
2021-01-27 16:48:40 +01:00
|
|
|
****************************************************************************/
|
2012-12-07 17:00:56 +01:00
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
static int at25_erase(FAR struct mtd_dev_s *dev,
|
|
|
|
off_t startblock,
|
|
|
|
size_t nblocks)
|
2012-12-07 17:00:56 +01:00
|
|
|
{
|
|
|
|
FAR struct at25_dev_s *priv = (FAR struct at25_dev_s *)dev;
|
|
|
|
size_t blocksleft = nblocks;
|
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
finfo("startblock: %08lx nblocks: %d\n", (long)startblock, (int)nblocks);
|
2012-12-07 17:00:56 +01:00
|
|
|
|
|
|
|
/* Lock access to the SPI bus until we complete the erase */
|
|
|
|
|
|
|
|
at25_lock(priv->dev);
|
|
|
|
while (blocksleft-- > 0)
|
|
|
|
{
|
|
|
|
/* Erase each sector */
|
|
|
|
|
|
|
|
at25_sectorerase(priv, startblock);
|
|
|
|
startblock++;
|
|
|
|
}
|
|
|
|
|
|
|
|
at25_unlock(priv->dev);
|
|
|
|
return (int)nblocks;
|
|
|
|
}
|
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
/****************************************************************************
|
2012-12-07 17:00:56 +01:00
|
|
|
* Name: at25_bread
|
2021-01-27 16:48:40 +01:00
|
|
|
****************************************************************************/
|
2012-12-07 17:00:56 +01:00
|
|
|
|
2020-11-30 04:51:15 +01:00
|
|
|
static ssize_t at25_bread(FAR struct mtd_dev_s *dev, off_t startblock,
|
|
|
|
size_t nblocks,
|
2012-12-07 17:00:56 +01:00
|
|
|
FAR uint8_t *buffer)
|
|
|
|
{
|
|
|
|
FAR struct at25_dev_s *priv = (FAR struct at25_dev_s *)dev;
|
|
|
|
ssize_t nbytes;
|
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
finfo("startblock: %08lx nblocks: %d\n", (long)startblock, (int)nblocks);
|
2012-12-07 17:00:56 +01:00
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
/* On this device, we can handle the block read just like the byte-oriented
|
|
|
|
* read
|
|
|
|
*/
|
2012-12-07 17:00:56 +01:00
|
|
|
|
2018-12-12 13:46:22 +01:00
|
|
|
nbytes = at25_read(dev, startblock << priv->pageshift,
|
|
|
|
nblocks << priv->pageshift, buffer);
|
2012-12-07 17:00:56 +01:00
|
|
|
if (nbytes > 0)
|
|
|
|
{
|
2020-11-30 04:51:15 +01:00
|
|
|
return nbytes >> priv->pageshift;
|
2012-12-07 17:00:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return (int)nbytes;
|
|
|
|
}
|
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
/****************************************************************************
|
2012-12-07 17:00:56 +01:00
|
|
|
* Name: at25_bwrite
|
2021-01-27 16:48:40 +01:00
|
|
|
****************************************************************************/
|
2012-12-07 17:00:56 +01:00
|
|
|
|
2018-12-12 13:46:22 +01:00
|
|
|
static ssize_t at25_bwrite(FAR struct mtd_dev_s *dev, off_t startblock,
|
|
|
|
size_t nblocks, FAR const uint8_t *buffer)
|
2012-12-07 17:00:56 +01:00
|
|
|
{
|
|
|
|
FAR struct at25_dev_s *priv = (FAR struct at25_dev_s *)dev;
|
|
|
|
size_t blocksleft = nblocks;
|
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
finfo("startblock: %08lx nblocks: %d\n", (long)startblock, (int)nblocks);
|
2012-12-07 17:00:56 +01:00
|
|
|
|
|
|
|
/* Lock the SPI bus and write each page to FLASH */
|
|
|
|
|
|
|
|
at25_lock(priv->dev);
|
|
|
|
while (blocksleft-- > 0)
|
|
|
|
{
|
|
|
|
at25_pagewrite(priv, buffer, startblock * 2);
|
|
|
|
at25_pagewrite(priv, buffer + 256, startblock * 2 + 1);
|
|
|
|
buffer += 1 << priv->pageshift;
|
|
|
|
startblock++;
|
2020-11-30 04:51:15 +01:00
|
|
|
}
|
2012-12-07 17:00:56 +01:00
|
|
|
|
|
|
|
at25_unlock(priv->dev);
|
|
|
|
return nblocks;
|
|
|
|
}
|
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
/****************************************************************************
|
2012-12-07 17:00:56 +01:00
|
|
|
* Name: at25_read
|
2021-01-27 16:48:40 +01:00
|
|
|
****************************************************************************/
|
2012-12-07 17:00:56 +01:00
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
static ssize_t at25_read(FAR struct mtd_dev_s *dev,
|
|
|
|
off_t offset,
|
|
|
|
size_t nbytes,
|
2012-12-07 17:00:56 +01:00
|
|
|
FAR uint8_t *buffer)
|
|
|
|
{
|
|
|
|
FAR struct at25_dev_s *priv = (FAR struct at25_dev_s *)dev;
|
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
finfo("offset: %08lx nbytes: %d\n", (long)offset, (int)nbytes);
|
2012-12-07 17:00:56 +01:00
|
|
|
|
2017-06-12 17:51:42 +02:00
|
|
|
/* Lock the SPI bus NOW because the following call must be executed with
|
|
|
|
* the bus locked.
|
|
|
|
*/
|
|
|
|
|
|
|
|
at25_lock(priv->dev);
|
|
|
|
|
2012-12-07 17:00:56 +01:00
|
|
|
/* Wait for any preceding write to complete. We could simplify things by
|
|
|
|
* perform this wait at the end of each write operation (rather than at
|
|
|
|
* the beginning of ALL operations), but have the wait first will slightly
|
|
|
|
* improve performance.
|
|
|
|
*/
|
|
|
|
|
|
|
|
at25_waitwritecomplete(priv);
|
|
|
|
|
2017-06-12 17:51:42 +02:00
|
|
|
/* Select this FLASH part */
|
2012-12-07 17:00:56 +01:00
|
|
|
|
2017-04-29 20:26:52 +02:00
|
|
|
SPI_SELECT(priv->dev, SPIDEV_FLASH(0), true);
|
2012-12-07 17:00:56 +01:00
|
|
|
|
|
|
|
/* Send "Read from Memory " instruction */
|
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
SPI_SEND(priv->dev, AT25_READ);
|
2012-12-07 17:00:56 +01:00
|
|
|
|
|
|
|
/* Send the page offset high byte first. */
|
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
SPI_SEND(priv->dev, (offset >> 16) & 0xff);
|
|
|
|
SPI_SEND(priv->dev, (offset >> 8) & 0xff);
|
|
|
|
SPI_SEND(priv->dev, offset & 0xff);
|
2012-12-07 17:00:56 +01:00
|
|
|
|
|
|
|
/* Then read all of the requested bytes */
|
|
|
|
|
|
|
|
SPI_RECVBLOCK(priv->dev, buffer, nbytes);
|
|
|
|
|
|
|
|
/* Deselect the FLASH and unlock the SPI bus */
|
|
|
|
|
2017-04-29 20:26:52 +02:00
|
|
|
SPI_SELECT(priv->dev, SPIDEV_FLASH(0), false);
|
2012-12-07 17:00:56 +01:00
|
|
|
at25_unlock(priv->dev);
|
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
finfo("return nbytes: %d\n", (int)nbytes);
|
2012-12-07 17:00:56 +01:00
|
|
|
return nbytes;
|
|
|
|
}
|
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
/****************************************************************************
|
2012-12-07 17:00:56 +01:00
|
|
|
* Name: at25_ioctl
|
2021-01-27 16:48:40 +01:00
|
|
|
****************************************************************************/
|
2012-12-07 17:00:56 +01:00
|
|
|
|
|
|
|
static int at25_ioctl(FAR struct mtd_dev_s *dev, int cmd, unsigned long arg)
|
|
|
|
{
|
|
|
|
FAR struct at25_dev_s *priv = (FAR struct at25_dev_s *)dev;
|
|
|
|
int ret = -EINVAL; /* Assume good command with bad parameters */
|
|
|
|
|
2021-12-26 23:18:22 +01:00
|
|
|
finfo("cmd: %d\n", cmd);
|
2012-12-07 17:00:56 +01:00
|
|
|
|
|
|
|
switch (cmd)
|
|
|
|
{
|
|
|
|
case MTDIOC_GEOMETRY:
|
|
|
|
{
|
2018-12-12 13:46:22 +01:00
|
|
|
FAR struct mtd_geometry_s *geo =
|
2018-12-13 19:35:39 +01:00
|
|
|
(FAR struct mtd_geometry_s *)((uintptr_t)arg);
|
2018-12-12 13:46:22 +01:00
|
|
|
|
|
|
|
if (geo != NULL)
|
2012-12-07 17:00:56 +01:00
|
|
|
{
|
2021-08-11 06:21:39 +02:00
|
|
|
memset(geo, 0, sizeof(*geo));
|
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
/* Populate the geometry structure with information need to
|
|
|
|
* know the capacity and how to access the device.
|
2012-12-07 17:00:56 +01:00
|
|
|
*
|
2021-01-27 16:48:40 +01:00
|
|
|
* NOTE:
|
|
|
|
* that the device is treated as though it where just an array
|
|
|
|
* of fixed size blocks.
|
|
|
|
* That is most likely not true, but the client will expect the
|
|
|
|
* device logic to do whatever is necessary to make it appear
|
|
|
|
* so.
|
2012-12-07 17:00:56 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
geo->blocksize = (1 << priv->pageshift);
|
|
|
|
geo->erasesize = (1 << priv->sectorshift);
|
|
|
|
geo->neraseblocks = priv->nsectors;
|
|
|
|
ret = OK;
|
|
|
|
|
2020-11-30 04:52:33 +01:00
|
|
|
finfo("blocksize: %" PRId32 " erasesize: %" PRId32
|
|
|
|
" neraseblocks: %" PRId32 "\n",
|
2012-12-07 17:00:56 +01:00
|
|
|
geo->blocksize, geo->erasesize, geo->neraseblocks);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2021-08-15 20:10:23 +02:00
|
|
|
case BIOC_PARTINFO:
|
|
|
|
{
|
|
|
|
FAR struct partition_info_s *info =
|
|
|
|
(FAR struct partition_info_s *)arg;
|
|
|
|
if (info != NULL)
|
|
|
|
{
|
|
|
|
info->numsectors = priv->nsectors <<
|
|
|
|
(priv->sectorshift - priv->pageshift);
|
|
|
|
info->sectorsize = 1 << priv->pageshift;
|
|
|
|
info->startsector = 0;
|
|
|
|
info->parent[0] = '\0';
|
|
|
|
ret = OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2012-12-07 17:00:56 +01:00
|
|
|
case MTDIOC_BULKERASE:
|
|
|
|
{
|
|
|
|
/* Erase the entire device */
|
|
|
|
|
|
|
|
at25_lock(priv->dev);
|
|
|
|
ret = at25_bulkerase(priv);
|
|
|
|
at25_unlock(priv->dev);
|
|
|
|
}
|
|
|
|
break;
|
2014-04-13 22:32:20 +02:00
|
|
|
|
2012-12-07 17:00:56 +01:00
|
|
|
default:
|
|
|
|
ret = -ENOTTY; /* Bad command */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
finfo("return %d\n", ret);
|
2012-12-07 17:00:56 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
/****************************************************************************
|
2012-12-07 17:00:56 +01:00
|
|
|
* Public Functions
|
2021-01-27 16:48:40 +01:00
|
|
|
****************************************************************************/
|
2012-12-07 17:00:56 +01:00
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
/****************************************************************************
|
2012-12-07 17:00:56 +01:00
|
|
|
* Name: at25_initialize
|
|
|
|
*
|
|
|
|
* Description:
|
2021-01-27 16:48:40 +01:00
|
|
|
* Create an initialize MTD device instance. MTD devices are not registered
|
2012-12-07 17:00:56 +01:00
|
|
|
* in the file system, but are created as instances that can be bound to
|
|
|
|
* other functions (such as a block or character driver front end).
|
|
|
|
*
|
2021-01-27 16:48:40 +01:00
|
|
|
****************************************************************************/
|
2012-12-07 17:00:56 +01:00
|
|
|
|
|
|
|
FAR struct mtd_dev_s *at25_initialize(FAR struct spi_dev_s *dev)
|
|
|
|
{
|
|
|
|
FAR struct at25_dev_s *priv;
|
|
|
|
int ret;
|
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
finfo("dev: %p\n", dev);
|
2012-12-07 17:00:56 +01:00
|
|
|
|
|
|
|
/* Allocate a state structure (we allocate the structure instead of using
|
|
|
|
* a fixed, static allocation so that we can handle multiple FLASH devices.
|
|
|
|
* The current implementation would handle only one FLASH part per SPI
|
2021-01-27 16:48:40 +01:00
|
|
|
* device (only because of the SPIDEV_FLASH(0) definition) and so would
|
|
|
|
* have to be extended to handle multiple FLASH parts on the same SPI bus.
|
2012-12-07 17:00:56 +01:00
|
|
|
*/
|
|
|
|
|
2023-08-28 09:39:47 +02:00
|
|
|
priv = kmm_zalloc(sizeof(struct at25_dev_s));
|
2012-12-07 17:00:56 +01:00
|
|
|
if (priv)
|
|
|
|
{
|
2013-05-01 18:59:57 +02:00
|
|
|
/* Initialize the allocated structure (unsupported methods were
|
2014-09-01 01:34:44 +02:00
|
|
|
* nullified by kmm_zalloc).
|
2013-05-01 18:59:57 +02:00
|
|
|
*/
|
2012-12-07 17:00:56 +01:00
|
|
|
|
|
|
|
priv->mtd.erase = at25_erase;
|
|
|
|
priv->mtd.bread = at25_bread;
|
|
|
|
priv->mtd.bwrite = at25_bwrite;
|
|
|
|
priv->mtd.read = at25_read;
|
|
|
|
priv->mtd.ioctl = at25_ioctl;
|
2018-11-08 16:46:11 +01:00
|
|
|
priv->mtd.name = "at25";
|
2012-12-07 17:00:56 +01:00
|
|
|
priv->dev = dev;
|
|
|
|
|
|
|
|
/* Deselect the FLASH */
|
|
|
|
|
2017-04-29 20:26:52 +02:00
|
|
|
SPI_SELECT(dev, SPIDEV_FLASH(0), false);
|
2012-12-07 17:00:56 +01:00
|
|
|
|
|
|
|
/* Identify the FLASH chip and get its capacity */
|
|
|
|
|
|
|
|
ret = at25_readid(priv);
|
|
|
|
if (ret != OK)
|
|
|
|
{
|
2021-01-27 16:48:40 +01:00
|
|
|
/* Unrecognized!
|
|
|
|
* Discard all of that work we just did and return NULL
|
|
|
|
*/
|
2012-12-07 17:00:56 +01:00
|
|
|
|
2016-06-11 23:50:49 +02:00
|
|
|
ferr("ERROR: Unrecognized\n");
|
2014-09-01 01:04:02 +02:00
|
|
|
kmm_free(priv);
|
2016-07-01 01:49:53 +02:00
|
|
|
return NULL;
|
2012-12-07 17:00:56 +01:00
|
|
|
}
|
2013-02-01 16:32:39 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
/* Unprotect all sectors */
|
2012-12-07 17:00:56 +01:00
|
|
|
|
2013-02-01 16:32:39 +01:00
|
|
|
at25_writeenable(priv);
|
2017-04-29 20:26:52 +02:00
|
|
|
SPI_SELECT(priv->dev, SPIDEV_FLASH(0), true);
|
2020-01-02 17:49:34 +01:00
|
|
|
SPI_SEND(priv->dev, AT25_WRSR);
|
|
|
|
SPI_SEND(priv->dev, AT25_SR_UNPROT);
|
2017-04-29 20:26:52 +02:00
|
|
|
SPI_SELECT(priv->dev, SPIDEV_FLASH(0), false);
|
2013-02-01 16:32:39 +01:00
|
|
|
}
|
2012-12-07 17:00:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Return the implementation-specific state structure as the MTD device */
|
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
finfo("Return %p\n", priv);
|
2012-12-07 17:00:56 +01:00
|
|
|
return (FAR struct mtd_dev_s *)priv;
|
|
|
|
}
|