2021-01-27 16:48:40 +01:00
|
|
|
|
/****************************************************************************
|
2010-09-12 04:22:13 +02:00
|
|
|
|
* drivers/mtd/at45db.c
|
|
|
|
|
* Driver for SPI-based AT45DB161D (16Mbit)
|
|
|
|
|
*
|
2014-09-25 14:48:04 +02:00
|
|
|
|
* Copyright (C) 2010-2011, 2013-2014 Gregory Nutt. All rights reserved.
|
2012-09-13 20:32:24 +02:00
|
|
|
|
* Author: Gregory Nutt <gnutt@nuttx.org>
|
2010-09-12 04:22:13 +02:00
|
|
|
|
*
|
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
|
* are met:
|
|
|
|
|
*
|
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
|
* notice, this list of conditions and the following disclaimer in
|
|
|
|
|
* the documentation and/or other materials provided with the
|
|
|
|
|
* distribution.
|
|
|
|
|
* 3. Neither the name NuttX nor the names of its contributors may be
|
|
|
|
|
* used to endorse or promote products derived from this software
|
|
|
|
|
* without specific prior written permission.
|
|
|
|
|
*
|
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
|
|
|
|
|
* FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
|
|
|
|
|
* COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
|
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
|
|
|
|
* BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
|
|
|
|
|
* OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
|
|
|
|
|
* AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
|
|
|
|
|
* ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
|
|
|
|
|
* POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
|
*
|
2021-01-27 16:48:40 +01:00
|
|
|
|
****************************************************************************/
|
2010-09-12 04:22:13 +02:00
|
|
|
|
|
|
|
|
|
/* Ordering Code Detail:
|
|
|
|
|
*
|
|
|
|
|
* AT 45DB 16 1 D <EFBFBD> SS U
|
|
|
|
|
* | | | | | | `- Device grade
|
|
|
|
|
* | | | | | `- Package Option
|
|
|
|
|
* | | | | `- Device revision
|
|
|
|
|
* | | | `- Interface: 1=serial
|
|
|
|
|
* | | `- Capacity: 16=16Mbit
|
|
|
|
|
* | `- Product family
|
|
|
|
|
* `- Atmel designator
|
|
|
|
|
*/
|
|
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
|
/****************************************************************************
|
2010-09-12 04:22:13 +02:00
|
|
|
|
* Included Files
|
2021-01-27 16:48:40 +01:00
|
|
|
|
****************************************************************************/
|
2010-09-12 04:22:13 +02:00
|
|
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
#include <stdint.h>
|
|
|
|
|
#include <stdbool.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <errno.h>
|
|
|
|
|
#include <debug.h>
|
|
|
|
|
|
2011-04-06 18:40:47 +02:00
|
|
|
|
#include <nuttx/kmalloc.h>
|
2010-09-12 04:22:13 +02:00
|
|
|
|
#include <nuttx/arch.h>
|
2012-03-21 19:01:07 +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>
|
2010-09-12 04:22:13 +02:00
|
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
|
/****************************************************************************
|
2010-09-12 04:22:13 +02:00
|
|
|
|
* Pre-processor Definitions
|
2021-01-27 16:48:40 +01:00
|
|
|
|
****************************************************************************/
|
2010-09-12 04:22:13 +02:00
|
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
|
/* Configuration ************************************************************/
|
|
|
|
|
|
|
|
|
|
/* CONFIG_AT45DB_PREWAIT enables higher performance write logic:
|
|
|
|
|
* We leave the chip busy after write and erase operations.
|
|
|
|
|
* This improves write and erase performance because we do not have to wait
|
|
|
|
|
* as long between transactions (other processing can occur while the chip
|
|
|
|
|
* is busy) but means that the chip must stay powered.
|
2010-09-13 17:57:14 +02:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#if defined(CONFIG_AT45DB_PWRSAVE) && defined(CONFIG_AT45DB_PREWAIT)
|
|
|
|
|
# error "Both CONFIG_AT45DB_PWRSAVE and CONFIG_AT45DB_PREWAIT are defined"
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* If the user has provided no frequency, use 1MHz */
|
2010-09-12 04:22:13 +02:00
|
|
|
|
|
|
|
|
|
#ifndef CONFIG_AT45DB_FREQUENCY
|
|
|
|
|
# define CONFIG_AT45DB_FREQUENCY 1000000
|
|
|
|
|
#endif
|
|
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
|
/* SPI Commands *************************************************************/
|
2010-09-12 04:22:13 +02:00
|
|
|
|
|
|
|
|
|
/* Read commands */
|
|
|
|
|
|
|
|
|
|
#define AT45DB_RDMN 0xd2 /* Main Memory Page Read */
|
|
|
|
|
#define AT45DB_RDARRY 0xe8 /* Continuous Array Read (Legacy Command) */
|
|
|
|
|
#define AT45DB_RDARRAYLF 0x03 /* Continuous Array Read (Low Frequency) */
|
|
|
|
|
#define AT45DB_RDARRAYHF 0x0b /* Continuous Array Read (High Frequency) */
|
|
|
|
|
#define AT45DB_RDBF1LF 0xd1 /* Buffer 1 Read (Low Frequency) */
|
|
|
|
|
#define AT45DB_RDBF2LF 0xd3 /* Buffer 2 Read (Low Frequency) */
|
|
|
|
|
#define AT45DB_RDBF1 0xd4 /* Buffer 1 Read */
|
|
|
|
|
#define AT45DB_RDBF2 0xd6 /* Buffer 2 Read */
|
|
|
|
|
|
|
|
|
|
/* Program and Erase Commands */
|
|
|
|
|
|
|
|
|
|
#define AT45DB_WRBF1 0x84 /* Buffer 1 Write */
|
|
|
|
|
#define AT45DB_WRBF2 0x87 /* Buffer 2 Write */
|
|
|
|
|
#define AT45DB_BF1TOMNE 0x83 /* Buffer 1 to Main Memory Page Program with Built-in Erase */
|
|
|
|
|
#define AT45DB_BF2TOMNE 0x86 /* Buffer 2 to Main Memory Page Program with Built-in Erase */
|
|
|
|
|
#define AT45DB_BF1TOMN 0x88 /* Buffer 1 to Main Memory Page Program without Built-in Erase */
|
|
|
|
|
#define AT45DB_BF2TOMN 0x89 /* Buffer 2 to Main Memory Page Program without Built-in Erase */
|
|
|
|
|
#define AT45DB_PGERASE 0x81 /* Page Erase */
|
|
|
|
|
#define AT45DB_BLKERASE 0x50 /* Block Erase */
|
|
|
|
|
#define AT45DB_SECTERASE 0x7c /* Sector Erase */
|
|
|
|
|
#define AT45DB_CHIPERASE1 0xc7 /* Chip Erase - byte 1 */
|
|
|
|
|
# define AT45DB_CHIPERASE2 0x94 /* Chip Erase - byte 2 */
|
|
|
|
|
# define AT45DB_CHIPERASE3 0x80 /* Chip Erase - byte 3 */
|
|
|
|
|
# define AT45DB_CHIPERASE4 0x9a /* Chip Erase - byte 4 */
|
|
|
|
|
#define AT45DB_MNTHRUBF1 0x82 /* Main Memory Page Program Through Buffer 1 */
|
|
|
|
|
#define AT45DB_MNTHRUBF2 0x85 /* Main Memory Page Program Through Buffer 2 */
|
|
|
|
|
|
|
|
|
|
/* Protection and Security Commands */
|
|
|
|
|
|
|
|
|
|
#define AT45DB_ENABPROT1 0x3d /* Enable Sector Protection - byte 1 */
|
|
|
|
|
# define AT45DB_ENABPROT2 0x2a /* Enable Sector Protection - byte 2 */
|
|
|
|
|
# define AT45DB_ENABPROT3 0x7f /* Enable Sector Protection - byte 3 */
|
|
|
|
|
# define AT45DB_ENABPROT4 0xa9 /* Enable Sector Protection - byte 4 */
|
|
|
|
|
#define AT45DB_DISABPROT1 0x3d /* Disable Sector Protection - byte 1 */
|
|
|
|
|
# define AT45DB_DISABPROT2 0x2a /* Disable Sector Protection - byte 2 */
|
|
|
|
|
# define AT45DB_DISABPROT3 0x7f /* Disable Sector Protection - byte 3 */
|
|
|
|
|
# define AT45DB_DISABPROT4 0x9a /* Disable Sector Protection - byte 4 */
|
|
|
|
|
#define AT45DB_ERASEPROT1 0x3d /* Erase Sector Protection Register - byte 1 */
|
|
|
|
|
# define AT45DB_ERASEPROT2 0x2a /* Erase Sector Protection Register - byte 2 */
|
|
|
|
|
# define AT45DB_ERASEPROT3 0x7f /* Erase Sector Protection Register - byte 3 */
|
|
|
|
|
# define AT45DB_ERASEPROT4 0xcf /* Erase Sector Protection Register - byte 4 */
|
|
|
|
|
#define AT45DB_PROGPROT1 0x3d /* Program Sector Protection Register - byte 1 */
|
|
|
|
|
# define AT45DB_PROGPROT2 0x2a /* Program Sector Protection Register - byte 2 */
|
|
|
|
|
# define AT45DB_PROGPROT3 0x7f /* Program Sector Protection Register - byte 3 */
|
|
|
|
|
# define AT45DB_PROGPROT4 0xfc /* Program Sector Protection Register - byte 4 */
|
|
|
|
|
#define AT45DB_RDPROT 0x32 /* Read Sector Protection Register */
|
|
|
|
|
#define AT45DB_LOCKDOWN1 0x3d /* Sector Lockdown - byte 1 */
|
|
|
|
|
# define AT45DB_LOCKDOWN2 0x2a /* Sector Lockdown - byte 2 */
|
|
|
|
|
# define AT45DB_LOCKDOWN3 0x7f /* Sector Lockdown - byte 3 */
|
|
|
|
|
# define AT45DB_LOCKDOWN4 0x30 /* Sector Lockdown - byte 4 */
|
|
|
|
|
#define AT45DB_RDLOCKDOWN 0x35 /* Read Sector Lockdown Register */
|
|
|
|
|
#define AT45DB_PROGSEC1 0x9b /* Program Security Register - byte 1 */
|
|
|
|
|
# define AT45DB_PROGSEC2 0x00 /* Program Security Register - byte 2 */
|
|
|
|
|
# define AT45DB_PROGSEC3 0x00 /* Program Security Register - byte 3 */
|
|
|
|
|
# define AT45DB_PROGSEC4 0x00 /* Program Security Register - byte 4 */
|
|
|
|
|
#define AT45DB_RDSEC 0x77 /* Read Security Register */
|
|
|
|
|
|
|
|
|
|
/* Additional commands */
|
|
|
|
|
|
|
|
|
|
#define AT45DB_MNTOBF1XFR 0x53 /* Main Memory Page to Buffer 1 Transfer */
|
|
|
|
|
#define AT45DB_MNTOBF2XFR 0x55 /* Main Memory Page to Buffer 2 Transfer */
|
|
|
|
|
#define AT45DB_MNBF1CMP 0x60 /* Main Memory Page to Buffer 1 Compare */
|
|
|
|
|
#define AT45DB_MNBF2CMP 0x61 /* Main Memory Page to Buffer 2 Compare */
|
|
|
|
|
#define AT45DB_AUTOWRBF1 0x58 /* Auto Page Rewrite through Buffer 1 */
|
|
|
|
|
#define AT45DB_AUTOWRBF2 0x59 /* Auto Page Rewrite through Buffer 2 */
|
|
|
|
|
#define AT45DB_PWRDOWN 0xb9 /* Deep Power-down */
|
|
|
|
|
#define AT45DB_RESUME 0xab /* Resume from Deep Power-down */
|
|
|
|
|
#define AT45DB_RDSR 0xd7 /* Status Register Read */
|
|
|
|
|
#define AT45DB_RDDEVID 0x9f /* Manufacturer and Device ID Read */
|
|
|
|
|
|
|
|
|
|
#define AT45DB_MANUFACTURER 0x1f /* Manufacturer ID: Atmel */
|
|
|
|
|
#define AT45DB_DEVID1_CAPMSK 0x1f /* Bits 0-4: Capacity */
|
2010-09-12 15:21:04 +02:00
|
|
|
|
#define AT45DB_DEVID1_1MBIT 0x02 /* xxx0 0010 = 1Mbit AT45DB011 */
|
|
|
|
|
#define AT45DB_DEVID1_2MBIT 0x03 /* xxx0 0012 = 2Mbit AT45DB021 */
|
|
|
|
|
#define AT45DB_DEVID1_4MBIT 0x04 /* xxx0 0100 = 4Mbit AT45DB041 */
|
|
|
|
|
#define AT45DB_DEVID1_8MBIT 0x05 /* xxx0 0101 = 8Mbit AT45DB081 */
|
|
|
|
|
#define AT45DB_DEVID1_16MBIT 0x06 /* xxx0 0110 = 16Mbit AT45DB161 */
|
|
|
|
|
#define AT45DB_DEVID1_32MBIT 0x07 /* xxx0 0111 = 32Mbit AT45DB321 */
|
2010-09-12 15:28:21 +02:00
|
|
|
|
#define AT45DB_DEVID1_64MBIT 0x08 /* xxx0 1000 = 32Mbit AT45DB641 */
|
2010-09-12 04:22:13 +02:00
|
|
|
|
#define AT45DB_DEVID1_FAMMSK 0xe0 /* Bits 5-7: Family */
|
|
|
|
|
#define AT45DB_DEVID1_DFLASH 0x20 /* 001x xxxx = Dataflash */
|
2010-09-12 15:21:04 +02:00
|
|
|
|
#define AT45DB_DEVID1_AT26DF 0x40 /* 010x xxxx = AT26DFxxx series (Not supported) */
|
2010-09-12 04:22:13 +02:00
|
|
|
|
#define AT45DB_DEVID2_VERMSK 0x1f /* Bits 0-4: MLC mask */
|
|
|
|
|
#define AT45DB_DEVID2_MLCMSK 0xe0 /* Bits 5-7: MLC mask */
|
|
|
|
|
|
|
|
|
|
/* Status register bit definitions */
|
|
|
|
|
|
|
|
|
|
#define AT45DB_SR_RDY (1 << 7) /* Bit 7: RDY/ Not BUSY */
|
|
|
|
|
#define AT45DB_SR_COMP (1 << 6) /* Bit 6: COMP */
|
|
|
|
|
#define AT45DB_SR_PROTECT (1 << 1) /* Bit 1: PROTECT */
|
|
|
|
|
#define AT45DB_SR_PGSIZE (1 << 0) /* Bit 0: PAGE_SIZE */
|
|
|
|
|
|
|
|
|
|
/* 1 Block = 16 pages; 1 sector = 256 pages */
|
|
|
|
|
|
|
|
|
|
#define PG_PER_BLOCK (16)
|
|
|
|
|
#define PG_PER_SECTOR (256)
|
|
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
|
/****************************************************************************
|
2010-09-12 04:22:13 +02:00
|
|
|
|
* Private Types
|
2021-01-27 16:48:40 +01:00
|
|
|
|
****************************************************************************/
|
2010-09-12 04:22:13 +02: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 at45db_dev_s.
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
struct at45db_dev_s
|
|
|
|
|
{
|
|
|
|
|
struct mtd_dev_s mtd; /* MTD interface */
|
|
|
|
|
FAR struct spi_dev_s *spi; /* Saved SPI interface instance */
|
|
|
|
|
uint8_t pageshift; /* log2 of the page size (eg. 1 << 9 = 512) */
|
|
|
|
|
uint32_t npages; /* Number of pages in the device */
|
|
|
|
|
};
|
|
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
|
/****************************************************************************
|
2010-09-12 04:22:13 +02:00
|
|
|
|
* Private Function Prototypes
|
2021-01-27 16:48:40 +01:00
|
|
|
|
****************************************************************************/
|
2010-09-12 04:22:13 +02:00
|
|
|
|
|
2010-09-13 20:27:19 +02:00
|
|
|
|
/* Lock and per-transaction configuration */
|
2010-09-12 04:22:13 +02:00
|
|
|
|
|
2014-09-25 14:48:04 +02:00
|
|
|
|
static void at45db_lock(FAR struct at45db_dev_s *priv);
|
|
|
|
|
static inline void at45db_unlock(FAR struct at45db_dev_s *priv);
|
2010-09-13 17:35:59 +02:00
|
|
|
|
|
|
|
|
|
/* Power management */
|
|
|
|
|
|
|
|
|
|
#ifdef CONFIG_AT45DB_PWRSAVE
|
2014-09-25 14:48:04 +02:00
|
|
|
|
static void at45db_pwrdown(FAR struct at45db_dev_s *priv);
|
|
|
|
|
static void at45db_resume(FAR struct at45db_dev_s *priv);
|
2010-09-13 17:35:59 +02:00
|
|
|
|
#else
|
|
|
|
|
# define at45db_pwrdown(priv)
|
|
|
|
|
# define at45db_resume(priv)
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
/* Low-level AT45DB Helpers */
|
|
|
|
|
|
2014-09-25 14:48:04 +02:00
|
|
|
|
static inline int at45db_rdid(FAR struct at45db_dev_s *priv);
|
|
|
|
|
static inline uint8_t at45db_rdsr(FAR struct at45db_dev_s *priv);
|
|
|
|
|
static uint8_t at45db_waitbusy(FAR struct at45db_dev_s *priv);
|
2021-01-27 16:48:40 +01:00
|
|
|
|
static inline void at45db_pgerase(FAR struct at45db_dev_s *priv,
|
|
|
|
|
off_t offset);
|
2018-12-13 01:21:27 +01:00
|
|
|
|
static inline int at45db_chiperase(FAR struct at45db_dev_s *priv);
|
2014-09-25 14:48:04 +02:00
|
|
|
|
static inline void at45db_pgwrite(FAR struct at45db_dev_s *priv,
|
2021-01-27 16:48:40 +01:00
|
|
|
|
FAR const uint8_t *buffer,
|
|
|
|
|
off_t offset);
|
2010-09-12 04:22:13 +02:00
|
|
|
|
|
|
|
|
|
/* MTD driver methods */
|
|
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
|
static int at45db_erase(FAR struct mtd_dev_s *mtd,
|
|
|
|
|
off_t startblock,
|
|
|
|
|
size_t nblocks);
|
|
|
|
|
static ssize_t at45db_bread(FAR struct mtd_dev_s *mtd,
|
|
|
|
|
off_t startblock,
|
|
|
|
|
size_t nblocks,
|
|
|
|
|
FAR uint8_t *buf);
|
|
|
|
|
static ssize_t at45db_bwrite(FAR struct mtd_dev_s *mtd,
|
|
|
|
|
off_t startblock,
|
|
|
|
|
size_t nblocks,
|
|
|
|
|
FAR const uint8_t *buf);
|
|
|
|
|
static ssize_t at45db_read(FAR struct mtd_dev_s *mtd,
|
|
|
|
|
off_t offset,
|
|
|
|
|
size_t nbytes,
|
2014-09-25 14:48:04 +02:00
|
|
|
|
FAR uint8_t *buffer);
|
2021-01-27 16:48:40 +01:00
|
|
|
|
static int at45db_ioctl(FAR struct mtd_dev_s *mtd,
|
|
|
|
|
int cmd,
|
|
|
|
|
unsigned long arg);
|
2010-09-12 04:22:13 +02:00
|
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
|
/****************************************************************************
|
2010-09-12 04:22:13 +02:00
|
|
|
|
* Private Data
|
2021-01-27 16:48:40 +01:00
|
|
|
|
****************************************************************************/
|
2010-09-12 04:22:13 +02:00
|
|
|
|
|
|
|
|
|
/* Chip erase sequence */
|
|
|
|
|
|
|
|
|
|
#define CHIP_ERASE_SIZE 4
|
2015-10-10 18:41:00 +02:00
|
|
|
|
static const uint8_t g_chiperase[CHIP_ERASE_SIZE] =
|
|
|
|
|
{
|
|
|
|
|
0xc7, 0x94, 0x80, 0x9a
|
|
|
|
|
};
|
2010-09-12 04:22:13 +02:00
|
|
|
|
|
2010-09-12 15:28:21 +02:00
|
|
|
|
/* Sequence to program the device to binary page sizes{256, 512, 1024} */
|
2010-09-12 04:22:13 +02:00
|
|
|
|
|
2010-09-12 15:28:21 +02:00
|
|
|
|
#define BINPGSIZE_SIZE 4
|
2015-10-10 18:41:00 +02:00
|
|
|
|
static const uint8_t g_binpgsize[BINPGSIZE_SIZE] =
|
|
|
|
|
{
|
|
|
|
|
0x3d, 0x2a, 0x80, 0xa6
|
|
|
|
|
};
|
2010-09-12 04:22:13 +02:00
|
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
|
/****************************************************************************
|
2010-09-12 04:22:13 +02:00
|
|
|
|
* Private Functions
|
2021-01-27 16:48:40 +01:00
|
|
|
|
****************************************************************************/
|
2010-09-12 04:22:13 +02:00
|
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
|
/****************************************************************************
|
2010-09-12 04:22:13 +02:00
|
|
|
|
* Name: at45db_lock
|
2021-01-27 16:48:40 +01:00
|
|
|
|
****************************************************************************/
|
2010-09-12 04:22:13 +02:00
|
|
|
|
|
2014-09-25 14:48:04 +02:00
|
|
|
|
static void at45db_lock(FAR struct at45db_dev_s *priv)
|
2010-09-12 04:22:13 +02:00
|
|
|
|
{
|
2021-01-27 16:48:40 +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
|
|
|
|
|
* transfers. The bus should be locked before the chip is selected.
|
2010-09-12 04:22:13 +02:00
|
|
|
|
*
|
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.
|
2010-09-12 04:22:13 +02:00
|
|
|
|
*/
|
|
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
|
SPI_LOCK(priv->spi, true);
|
2010-09-12 04:22:13 +02: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.
|
2010-09-12 04:22:13 +02:00
|
|
|
|
*/
|
|
|
|
|
|
2010-09-12 18:38:02 +02:00
|
|
|
|
SPI_SETMODE(priv->spi, SPIDEV_MODE0);
|
2010-09-12 04:22:13 +02:00
|
|
|
|
SPI_SETBITS(priv->spi, 8);
|
2020-01-02 17:49:34 +01:00
|
|
|
|
SPI_HWFEATURES(priv->spi, 0);
|
|
|
|
|
SPI_SETFREQUENCY(priv->spi, CONFIG_AT45DB_FREQUENCY);
|
2010-09-12 04:22:13 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
|
/****************************************************************************
|
2010-09-12 04:22:13 +02:00
|
|
|
|
* Name: at45db_unlock
|
2021-01-27 16:48:40 +01:00
|
|
|
|
****************************************************************************/
|
2010-09-12 04:22:13 +02:00
|
|
|
|
|
2014-09-25 14:48:04 +02:00
|
|
|
|
static inline void at45db_unlock(FAR struct at45db_dev_s *priv)
|
2010-09-12 04:22:13 +02:00
|
|
|
|
{
|
2020-01-02 17:49:34 +01:00
|
|
|
|
SPI_LOCK(priv->spi, false);
|
2010-09-12 04:22:13 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
|
/****************************************************************************
|
2010-09-12 04:22:13 +02:00
|
|
|
|
* Name: at45db_pwrdown
|
2021-01-27 16:48:40 +01:00
|
|
|
|
****************************************************************************/
|
2010-09-12 04:22:13 +02:00
|
|
|
|
|
2010-09-13 17:35:59 +02:00
|
|
|
|
#ifdef CONFIG_AT45DB_PWRSAVE
|
2014-09-25 14:48:04 +02:00
|
|
|
|
static void at45db_pwrdown(FAR struct at45db_dev_s *priv)
|
2010-09-12 04:22:13 +02:00
|
|
|
|
{
|
2017-04-29 20:26:52 +02:00
|
|
|
|
SPI_SELECT(priv->spi, SPIDEV_FLASH(0), true);
|
2010-09-12 04:22:13 +02:00
|
|
|
|
SPI_SEND(priv->spi, AT45DB_PWRDOWN);
|
2017-04-29 20:26:52 +02:00
|
|
|
|
SPI_SELECT(priv->spi, SPIDEV_FLASH(0), false);
|
2010-09-12 04:22:13 +02:00
|
|
|
|
}
|
2010-09-13 17:35:59 +02:00
|
|
|
|
#endif
|
2010-09-12 04:22:13 +02:00
|
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
|
/****************************************************************************
|
2010-09-12 04:22:13 +02:00
|
|
|
|
* Name: at45db_resume
|
2021-01-27 16:48:40 +01:00
|
|
|
|
****************************************************************************/
|
2010-09-12 04:22:13 +02:00
|
|
|
|
|
2010-09-13 17:35:59 +02:00
|
|
|
|
#ifdef CONFIG_AT45DB_PWRSAVE
|
2014-09-25 14:48:04 +02:00
|
|
|
|
static void at45db_resume(FAR struct at45db_dev_s *priv)
|
2010-09-12 04:22:13 +02:00
|
|
|
|
{
|
2017-04-29 20:26:52 +02:00
|
|
|
|
SPI_SELECT(priv->spi, SPIDEV_FLASH(0), true);
|
2010-09-12 04:22:13 +02:00
|
|
|
|
SPI_SEND(priv->spi, AT45DB_RESUME);
|
2017-04-29 20:26:52 +02:00
|
|
|
|
SPI_SELECT(priv->spi, SPIDEV_FLASH(0), false);
|
2010-09-12 04:22:13 +02:00
|
|
|
|
up_udelay(50);
|
|
|
|
|
}
|
2010-09-13 17:35:59 +02:00
|
|
|
|
#endif
|
2010-09-12 04:22:13 +02:00
|
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
|
/****************************************************************************
|
2010-09-12 04:22:13 +02:00
|
|
|
|
* Name: at45db_rdid
|
2021-01-27 16:48:40 +01:00
|
|
|
|
****************************************************************************/
|
2010-09-12 04:22:13 +02:00
|
|
|
|
|
2014-09-25 14:48:04 +02:00
|
|
|
|
static inline int at45db_rdid(FAR struct at45db_dev_s *priv)
|
2010-09-12 04:22:13 +02:00
|
|
|
|
{
|
2010-10-01 04:51:45 +02:00
|
|
|
|
uint8_t capacity;
|
|
|
|
|
uint8_t devid[3];
|
2010-09-12 04:22:13 +02:00
|
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
|
finfo("priv: %p\n", priv);
|
2010-09-12 04:22:13 +02:00
|
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
|
/* Configure the bus, and select this FLASH part. (The caller should
|
|
|
|
|
* already have locked the bus for exclusive access)
|
2010-09-12 16:35:25 +02:00
|
|
|
|
*/
|
2010-09-12 04:22:13 +02:00
|
|
|
|
|
2017-04-29 20:26:52 +02:00
|
|
|
|
SPI_SELECT(priv->spi, SPIDEV_FLASH(0), true);
|
2010-09-12 04:22:13 +02:00
|
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
|
/* Send the "Manufacturer and Device ID Read" command and read the
|
|
|
|
|
* next three ID bytes from the FLASH.
|
2010-09-12 04:22:13 +02:00
|
|
|
|
*/
|
|
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
|
SPI_SEND(priv->spi, AT45DB_RDDEVID);
|
2010-10-01 04:51:45 +02:00
|
|
|
|
SPI_RECVBLOCK(priv->spi, devid, 3);
|
2010-09-12 04:22:13 +02:00
|
|
|
|
|
2010-10-01 04:51:45 +02:00
|
|
|
|
/* Deselect the FLASH */
|
2010-09-12 04:22:13 +02:00
|
|
|
|
|
2017-04-29 20:26:52 +02:00
|
|
|
|
SPI_SELECT(priv->spi, SPIDEV_FLASH(0), false);
|
2010-09-12 04:22:13 +02:00
|
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
|
finfo("manufacturer: %02x devid1: %02x devid2: %02x\n",
|
2010-10-01 04:51:45 +02:00
|
|
|
|
devid[0], devid[1], devid[2]);
|
2014-04-13 22:32:20 +02:00
|
|
|
|
|
2010-09-12 04:22:13 +02:00
|
|
|
|
/* Check for a valid manufacturer and memory family */
|
|
|
|
|
|
2010-10-01 04:51:45 +02:00
|
|
|
|
if (devid[0] == AT45DB_MANUFACTURER &&
|
|
|
|
|
(devid[1] & AT45DB_DEVID1_FAMMSK) == AT45DB_DEVID1_DFLASH)
|
2010-09-12 04:22:13 +02:00
|
|
|
|
{
|
|
|
|
|
/* Okay.. is it a FLASH capacity that we understand? */
|
|
|
|
|
|
2010-10-01 04:51:45 +02:00
|
|
|
|
capacity = devid[1] & AT45DB_DEVID1_CAPMSK;
|
2010-09-12 15:21:04 +02:00
|
|
|
|
switch (capacity)
|
2010-09-12 04:22:13 +02:00
|
|
|
|
{
|
2010-09-12 15:21:04 +02:00
|
|
|
|
case AT45DB_DEVID1_1MBIT:
|
2021-01-27 16:48:40 +01:00
|
|
|
|
|
2010-09-12 15:21:04 +02:00
|
|
|
|
/* Save the FLASH geometry for the 16Mbit AT45DB011 */
|
2010-09-12 04:22:13 +02:00
|
|
|
|
|
2010-09-12 15:21:04 +02:00
|
|
|
|
priv->pageshift = 8; /* Page size = 256 bytes */
|
|
|
|
|
priv->npages = 512; /* 512 pages */
|
|
|
|
|
return OK;
|
|
|
|
|
|
|
|
|
|
case AT45DB_DEVID1_2MBIT:
|
2021-01-27 16:48:40 +01:00
|
|
|
|
|
2010-09-12 15:21:04 +02:00
|
|
|
|
/* Save the FLASH geometry for the 16Mbit AT45DB021 */
|
|
|
|
|
|
2010-09-12 15:28:21 +02:00
|
|
|
|
priv->pageshift = 8; /* Page size = 256/264 bytes */
|
2010-09-12 15:21:04 +02:00
|
|
|
|
priv->npages = 1024; /* 1024 pages */
|
|
|
|
|
return OK;
|
|
|
|
|
|
|
|
|
|
case AT45DB_DEVID1_4MBIT:
|
2021-01-27 16:48:40 +01:00
|
|
|
|
|
2010-09-12 15:21:04 +02:00
|
|
|
|
/* Save the FLASH geometry for the 16Mbit AT45DB041 */
|
|
|
|
|
|
2010-09-12 15:28:21 +02:00
|
|
|
|
priv->pageshift = 8; /* Page size = 256/264 bytes */
|
2010-09-12 15:21:04 +02:00
|
|
|
|
priv->npages = 2048; /* 2048 pages */
|
|
|
|
|
return OK;
|
2010-09-12 04:22:13 +02:00
|
|
|
|
|
2010-09-12 15:21:04 +02:00
|
|
|
|
case AT45DB_DEVID1_8MBIT:
|
2021-01-27 16:48:40 +01:00
|
|
|
|
|
2010-09-12 15:21:04 +02:00
|
|
|
|
/* Save the FLASH geometry for the 16Mbit AT45DB081 */
|
|
|
|
|
|
2010-09-12 15:28:21 +02:00
|
|
|
|
priv->pageshift = 8; /* Page size = 256/264 bytes */
|
2010-09-12 15:21:04 +02:00
|
|
|
|
priv->npages = 4096; /* 4096 pages */
|
|
|
|
|
return OK;
|
|
|
|
|
|
|
|
|
|
case AT45DB_DEVID1_16MBIT:
|
2021-01-27 16:48:40 +01:00
|
|
|
|
|
2010-09-12 15:21:04 +02:00
|
|
|
|
/* Save the FLASH geometry for the 16Mbit AT45DB161 */
|
|
|
|
|
|
2010-09-12 15:28:21 +02:00
|
|
|
|
priv->pageshift = 9; /* Page size = 512/528 bytes */
|
2010-09-12 15:21:04 +02:00
|
|
|
|
priv->npages = 4096; /* 4096 pages */
|
|
|
|
|
return OK;
|
|
|
|
|
|
|
|
|
|
case AT45DB_DEVID1_32MBIT:
|
2021-01-27 16:48:40 +01:00
|
|
|
|
|
2010-09-12 15:21:04 +02:00
|
|
|
|
/* Save the FLASH geometry for the 16Mbit AT45DB321 */
|
|
|
|
|
|
2010-09-12 15:28:21 +02:00
|
|
|
|
priv->pageshift = 9; /* Page size = 512/528 bytes */
|
|
|
|
|
priv->npages = 8192; /* 8192 pages */
|
|
|
|
|
return OK;
|
|
|
|
|
|
|
|
|
|
case AT45DB_DEVID1_64MBIT:
|
2021-01-27 16:48:40 +01:00
|
|
|
|
|
2010-09-12 15:28:21 +02:00
|
|
|
|
/* Save the FLASH geometry for the 16Mbit AT45DB321 */
|
|
|
|
|
|
|
|
|
|
priv->pageshift = 10; /* Page size = 1024/1056 bytes */
|
2010-09-12 15:21:04 +02:00
|
|
|
|
priv->npages = 8192; /* 8192 pages */
|
|
|
|
|
return OK;
|
|
|
|
|
|
|
|
|
|
default:
|
|
|
|
|
return -ENODEV;
|
2010-09-12 04:22:13 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return -ENODEV;
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
|
/****************************************************************************
|
2010-09-12 04:22:13 +02:00
|
|
|
|
* Name: at45db_rdsr
|
2021-01-27 16:48:40 +01:00
|
|
|
|
****************************************************************************/
|
2010-09-12 04:22:13 +02:00
|
|
|
|
|
2014-09-25 14:48:04 +02:00
|
|
|
|
static inline uint8_t at45db_rdsr(FAR struct at45db_dev_s *priv)
|
2010-09-12 04:22:13 +02:00
|
|
|
|
{
|
|
|
|
|
uint8_t retval;
|
|
|
|
|
|
2017-04-29 20:26:52 +02:00
|
|
|
|
SPI_SELECT(priv->spi, SPIDEV_FLASH(0), true);
|
2010-09-12 04:22:13 +02:00
|
|
|
|
SPI_SEND(priv->spi, AT45DB_RDSR);
|
|
|
|
|
retval = SPI_SEND(priv->spi, 0xff);
|
2017-04-29 20:26:52 +02:00
|
|
|
|
SPI_SELECT(priv->spi, SPIDEV_FLASH(0), false);
|
2010-09-12 04:22:13 +02:00
|
|
|
|
return retval;
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
|
/****************************************************************************
|
2010-09-12 04:22:13 +02:00
|
|
|
|
* Name: at45db_waitbusy
|
2021-01-27 16:48:40 +01:00
|
|
|
|
****************************************************************************/
|
2010-09-12 04:22:13 +02:00
|
|
|
|
|
2014-09-25 14:48:04 +02:00
|
|
|
|
static uint8_t at45db_waitbusy(FAR struct at45db_dev_s *priv)
|
2010-09-12 04:22:13 +02:00
|
|
|
|
{
|
|
|
|
|
uint8_t sr;
|
|
|
|
|
|
|
|
|
|
/* Poll the device, waiting for it to report that it is ready */
|
|
|
|
|
|
|
|
|
|
do
|
2014-09-25 14:48:04 +02:00
|
|
|
|
{
|
|
|
|
|
up_udelay(10);
|
|
|
|
|
sr = (uint8_t)at45db_rdsr(priv);
|
|
|
|
|
}
|
2010-09-12 04:22:13 +02:00
|
|
|
|
while ((sr & AT45DB_SR_RDY) == 0);
|
2014-09-25 14:48:04 +02:00
|
|
|
|
|
2010-09-12 04:22:13 +02:00
|
|
|
|
return sr;
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
|
/****************************************************************************
|
2010-09-12 04:22:13 +02:00
|
|
|
|
* Name: at45db_pgerase
|
2021-01-27 16:48:40 +01:00
|
|
|
|
****************************************************************************/
|
2010-09-12 04:22:13 +02:00
|
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
|
static inline void at45db_pgerase(FAR struct at45db_dev_s *priv,
|
|
|
|
|
off_t sector)
|
2010-09-12 04:22:13 +02:00
|
|
|
|
{
|
|
|
|
|
uint8_t erasecmd[4];
|
|
|
|
|
off_t offset = sector << priv->pageshift;
|
|
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
|
finfo("sector: %08lx\n", (long)sector);
|
2010-09-12 04:22:13 +02:00
|
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
|
/* Higher performance write logic: We leave the chip busy after write and
|
|
|
|
|
* erase operations. This improves write and erase performance because we
|
|
|
|
|
* do not have to wait as long between transactions (other processing can
|
|
|
|
|
* occur while the chip is busy) but means that the chip must stay powered
|
|
|
|
|
* and that we must check if the chip is still busy on each entry point.
|
2010-09-13 17:35:59 +02:00
|
|
|
|
*/
|
|
|
|
|
|
2010-09-13 17:57:14 +02:00
|
|
|
|
#ifdef CONFIG_AT45DB_PREWAIT
|
2010-09-13 17:35:59 +02:00
|
|
|
|
at45db_waitbusy(priv);
|
|
|
|
|
#endif
|
|
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
|
/* "The Page Erase command can be used to individually erase any page in
|
|
|
|
|
* the main memory array allowing the Buffer to Main Memory Page Program
|
|
|
|
|
* to be utilized at a later time. ... To perform a page erase in the
|
|
|
|
|
* binary page size ..., the opcode 81H must be loaded into the device,
|
|
|
|
|
* followed by three address bytes ... When a low-to-high transition
|
|
|
|
|
* occurs on the CS pin, the part will erase the selected page (the
|
|
|
|
|
* erased state is a logical 1). ... the status register and the
|
|
|
|
|
* RDY/BUSY pin will indicate that the part is busy."
|
2010-09-12 04:22:13 +02:00
|
|
|
|
*/
|
|
|
|
|
|
2014-09-25 14:48:04 +02:00
|
|
|
|
erasecmd[0] = AT45DB_PGERASE; /* Page erase command */
|
2010-09-12 04:22:13 +02:00
|
|
|
|
erasecmd[1] = (offset >> 16) & 0xff; /* 24-bit offset MS bytes */
|
|
|
|
|
erasecmd[2] = (offset >> 8) & 0xff; /* 24-bit offset middle bytes */
|
|
|
|
|
erasecmd[3] = offset & 0xff; /* 24-bit offset LS bytes */
|
|
|
|
|
|
|
|
|
|
/* Erase the page */
|
|
|
|
|
|
2017-04-29 20:26:52 +02:00
|
|
|
|
SPI_SELECT(priv->spi, SPIDEV_FLASH(0), true);
|
2010-09-12 04:22:13 +02:00
|
|
|
|
SPI_SNDBLOCK(priv->spi, erasecmd, 4);
|
2017-04-29 20:26:52 +02:00
|
|
|
|
SPI_SELECT(priv->spi, SPIDEV_FLASH(0), false);
|
2010-09-12 04:22:13 +02:00
|
|
|
|
|
2010-09-13 17:57:14 +02:00
|
|
|
|
/* Wait for any erase to complete if we are not trying to improve write
|
|
|
|
|
* performance. (see comments above).
|
2010-09-13 17:35:59 +02:00
|
|
|
|
*/
|
2010-09-12 04:22:13 +02:00
|
|
|
|
|
2010-09-13 17:57:14 +02:00
|
|
|
|
#ifndef CONFIG_AT45DB_PREWAIT
|
2010-09-12 04:22:13 +02:00
|
|
|
|
at45db_waitbusy(priv);
|
2010-09-13 17:35:59 +02:00
|
|
|
|
#endif
|
2016-06-11 19:59:51 +02:00
|
|
|
|
finfo("Erased\n");
|
2010-09-12 04:22:13 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
|
/****************************************************************************
|
2018-12-13 01:21:27 +01:00
|
|
|
|
* Name: at45db_chiperase
|
2021-01-27 16:48:40 +01:00
|
|
|
|
****************************************************************************/
|
2010-09-12 04:22:13 +02:00
|
|
|
|
|
2018-12-13 01:21:27 +01:00
|
|
|
|
static inline int at45db_chiperase(FAR struct at45db_dev_s *priv)
|
2010-09-12 04:22:13 +02:00
|
|
|
|
{
|
2016-06-11 19:59:51 +02:00
|
|
|
|
finfo("priv: %p\n", priv);
|
2010-09-12 04:22:13 +02:00
|
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
|
/* Higher performance write logic: We leave the chip busy after write and
|
|
|
|
|
* erase operations. This improves write and erase performance because we
|
|
|
|
|
* do not have to wait as long between transactions (other processing can
|
|
|
|
|
* occur while the chip is busy) but means that the chip must stay powered
|
|
|
|
|
* and that we must check if the chip is still busy on each entry point.
|
2010-09-13 17:35:59 +02:00
|
|
|
|
*/
|
|
|
|
|
|
2010-09-13 17:57:14 +02:00
|
|
|
|
#ifdef CONFIG_AT45DB_PREWAIT
|
2010-09-13 17:35:59 +02:00
|
|
|
|
at45db_waitbusy(priv);
|
|
|
|
|
#endif
|
|
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
|
/* "The entire main memory can be erased at one time by using the Chip
|
|
|
|
|
* Erase command. To execute the Chip Erase command, a 4-byte command
|
|
|
|
|
* sequence C7H, 94H, 80H and 9AH must be clocked into the device. ...
|
|
|
|
|
* After the last bit of the opcode sequence has been clocked in, the CS
|
|
|
|
|
* pin can be deasserted to start theerase process. ... the Status
|
|
|
|
|
* Register will indicate that the device is busy.
|
|
|
|
|
* The Chip Erase command will not affect sectors that are protected or
|
|
|
|
|
* locked down...
|
2010-09-12 04:22:13 +02:00
|
|
|
|
*/
|
|
|
|
|
|
2017-04-29 20:26:52 +02:00
|
|
|
|
SPI_SELECT(priv->spi, SPIDEV_FLASH(0), true);
|
2010-09-12 04:22:13 +02:00
|
|
|
|
SPI_SNDBLOCK(priv->spi, g_chiperase, CHIP_ERASE_SIZE);
|
2017-04-29 20:26:52 +02:00
|
|
|
|
SPI_SELECT(priv->spi, SPIDEV_FLASH(0), false);
|
2010-09-12 04:22:13 +02:00
|
|
|
|
|
2010-09-13 17:57:14 +02:00
|
|
|
|
/* Wait for any erase to complete if we are not trying to improve write
|
|
|
|
|
* performance. (see comments above).
|
2010-09-13 17:35:59 +02:00
|
|
|
|
*/
|
2010-09-12 04:22:13 +02:00
|
|
|
|
|
2010-09-13 17:57:14 +02:00
|
|
|
|
#ifndef CONFIG_AT45DB_PREWAIT
|
2010-09-12 04:22:13 +02:00
|
|
|
|
at45db_waitbusy(priv);
|
2010-09-13 17:35:59 +02:00
|
|
|
|
#endif
|
2010-09-12 04:22:13 +02:00
|
|
|
|
return OK;
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
|
/****************************************************************************
|
2010-09-12 04:22:13 +02:00
|
|
|
|
* Name: at45db_pgwrite
|
2021-01-27 16:48:40 +01:00
|
|
|
|
****************************************************************************/
|
2010-09-12 04:22:13 +02:00
|
|
|
|
|
2014-09-25 14:48:04 +02:00
|
|
|
|
static inline void at45db_pgwrite(FAR struct at45db_dev_s *priv,
|
|
|
|
|
FAR const uint8_t *buffer, off_t page)
|
2010-09-12 04:22:13 +02:00
|
|
|
|
{
|
|
|
|
|
uint8_t wrcmd [4];
|
|
|
|
|
off_t offset = page << priv->pageshift;
|
|
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
|
finfo("page: %08lx offset: %08lx\n", (long)page, (long)offset);
|
2010-09-12 04:22:13 +02:00
|
|
|
|
|
|
|
|
|
/* We assume that sectors are not write protected */
|
|
|
|
|
|
|
|
|
|
wrcmd[0] = AT45DB_MNTHRUBF1; /* To main memory through buffer 1 */
|
|
|
|
|
wrcmd[1] = (offset >> 16) & 0xff; /* 24-bit address MS byte */
|
|
|
|
|
wrcmd[2] = (offset >> 8) & 0xff; /* 24-bit address middle byte */
|
|
|
|
|
wrcmd[3] = offset & 0xff; /* 24-bit address LS byte */
|
|
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
|
/* Higher performance write logic: We leave the chip busy after write and
|
|
|
|
|
* erase operations. This improves write and erase performance because we
|
|
|
|
|
* do not have to wait as long between transactions (other processing can
|
|
|
|
|
* occur while the chip is busy) but means that the chip must stay powered
|
|
|
|
|
* and that we must check if the chip is still busy on each entry point.
|
2010-09-13 17:35:59 +02:00
|
|
|
|
*/
|
|
|
|
|
|
2010-09-13 17:57:14 +02:00
|
|
|
|
#ifdef CONFIG_AT45DB_PREWAIT
|
2010-09-13 17:35:59 +02:00
|
|
|
|
at45db_waitbusy(priv);
|
|
|
|
|
#endif
|
|
|
|
|
|
2017-04-29 20:26:52 +02:00
|
|
|
|
SPI_SELECT(priv->spi, SPIDEV_FLASH(0), true);
|
2010-09-12 04:22:13 +02:00
|
|
|
|
SPI_SNDBLOCK(priv->spi, wrcmd, 4);
|
|
|
|
|
SPI_SNDBLOCK(priv->spi, buffer, 1 << priv->pageshift);
|
2017-04-29 20:26:52 +02:00
|
|
|
|
SPI_SELECT(priv->spi, SPIDEV_FLASH(0), false);
|
2010-09-12 04:22:13 +02:00
|
|
|
|
|
2010-09-13 17:57:14 +02:00
|
|
|
|
/* Wait for any erase to complete if we are not trying to improve write
|
|
|
|
|
* performance. (see comments above).
|
2010-09-13 17:35:59 +02:00
|
|
|
|
*/
|
2010-09-12 04:22:13 +02:00
|
|
|
|
|
2010-09-13 17:57:14 +02:00
|
|
|
|
#ifndef CONFIG_AT45DB_PREWAIT
|
2010-09-12 04:22:13 +02:00
|
|
|
|
at45db_waitbusy(priv);
|
2010-09-13 17:35:59 +02:00
|
|
|
|
#endif
|
2016-06-11 19:59:51 +02:00
|
|
|
|
finfo("Written\n");
|
2010-09-12 04:22:13 +02:00
|
|
|
|
}
|
|
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
|
/****************************************************************************
|
2010-09-12 04:22:13 +02:00
|
|
|
|
* Name: at45db_erase
|
2021-01-27 16:48:40 +01:00
|
|
|
|
****************************************************************************/
|
2010-09-12 04:22:13 +02:00
|
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
|
static int at45db_erase(FAR struct mtd_dev_s *mtd, off_t startblock,
|
|
|
|
|
size_t nblocks)
|
2010-09-12 04:22:13 +02:00
|
|
|
|
{
|
|
|
|
|
FAR struct at45db_dev_s *priv = (FAR struct at45db_dev_s *)mtd;
|
|
|
|
|
size_t pgsleft = nblocks;
|
|
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
|
finfo("startblock: %08lx nblocks: %d\n", (long)startblock, (int)nblocks);
|
2010-09-12 04:22:13 +02:00
|
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
|
/* Take the lock so that we have exclusive access to the bus, then power
|
|
|
|
|
* up the FLASH device.
|
2010-09-12 04:22:13 +02:00
|
|
|
|
*/
|
2014-04-13 22:32:20 +02:00
|
|
|
|
|
2010-09-12 04:22:13 +02:00
|
|
|
|
at45db_lock(priv);
|
|
|
|
|
at45db_resume(priv);
|
|
|
|
|
|
|
|
|
|
/* Then erase each page */
|
|
|
|
|
|
|
|
|
|
while (pgsleft-- > 0)
|
|
|
|
|
{
|
|
|
|
|
/* Erase each sector */
|
|
|
|
|
|
|
|
|
|
at45db_pgerase(priv, startblock);
|
|
|
|
|
startblock++;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
at45db_pwrdown(priv);
|
|
|
|
|
at45db_unlock(priv);
|
|
|
|
|
return (int)nblocks;
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
|
/****************************************************************************
|
2010-09-12 04:22:13 +02:00
|
|
|
|
* Name: at45db_bread
|
2021-01-27 16:48:40 +01:00
|
|
|
|
****************************************************************************/
|
2010-09-12 04:22:13 +02:00
|
|
|
|
|
2014-09-25 14:48:04 +02:00
|
|
|
|
static ssize_t at45db_bread(FAR struct mtd_dev_s *mtd, off_t startblock,
|
|
|
|
|
size_t nblocks, FAR uint8_t *buffer)
|
2010-09-12 04:22:13 +02:00
|
|
|
|
{
|
|
|
|
|
FAR struct at45db_dev_s *priv = (FAR struct at45db_dev_s *)mtd;
|
|
|
|
|
ssize_t nbytes;
|
|
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
|
/* On this device, we can handle the block read just like the byte-oriented
|
|
|
|
|
* read
|
|
|
|
|
*/
|
2010-09-12 04:22:13 +02:00
|
|
|
|
|
2014-09-25 14:48:04 +02:00
|
|
|
|
nbytes = at45db_read(mtd, startblock << priv->pageshift,
|
|
|
|
|
nblocks << priv->pageshift, buffer);
|
2010-09-12 04:22:13 +02:00
|
|
|
|
if (nbytes > 0)
|
|
|
|
|
{
|
|
|
|
|
return nbytes >> priv->pageshift;
|
|
|
|
|
}
|
2014-09-25 14:48:04 +02:00
|
|
|
|
|
2010-09-12 04:22:13 +02:00
|
|
|
|
return nbytes;
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
|
/****************************************************************************
|
2010-09-12 04:22:13 +02:00
|
|
|
|
* Name: at45db_bwrite
|
2021-01-27 16:48:40 +01:00
|
|
|
|
****************************************************************************/
|
2010-09-12 04:22:13 +02:00
|
|
|
|
|
2014-09-25 14:48:04 +02:00
|
|
|
|
static ssize_t at45db_bwrite(FAR struct mtd_dev_s *mtd, off_t startblock,
|
|
|
|
|
size_t nblocks, FAR const uint8_t *buffer)
|
2010-09-12 04:22:13 +02:00
|
|
|
|
{
|
|
|
|
|
FAR struct at45db_dev_s *priv = (FAR struct at45db_dev_s *)mtd;
|
|
|
|
|
size_t pgsleft = nblocks;
|
|
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
|
finfo("startblock: %08lx nblocks: %d\n", (long)startblock, (int)nblocks);
|
2010-09-12 04:22:13 +02:00
|
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
|
/* Take the lock so that we have exclusive access to the bus, then power
|
|
|
|
|
* up the FLASH device.
|
2010-09-12 04:22:13 +02:00
|
|
|
|
*/
|
2014-04-13 22:32:20 +02:00
|
|
|
|
|
2010-09-12 04:22:13 +02:00
|
|
|
|
at45db_lock(priv);
|
|
|
|
|
at45db_resume(priv);
|
|
|
|
|
|
|
|
|
|
/* Write each page to FLASH */
|
|
|
|
|
|
|
|
|
|
while (pgsleft-- > 0)
|
|
|
|
|
{
|
|
|
|
|
at45db_pgwrite(priv, buffer, startblock);
|
|
|
|
|
startblock++;
|
2014-09-25 14:48:04 +02:00
|
|
|
|
buffer += (1 << priv->pageshift);
|
2021-01-27 16:48:40 +01:00
|
|
|
|
}
|
2010-09-13 17:35:59 +02:00
|
|
|
|
|
|
|
|
|
at45db_pwrdown(priv);
|
2010-09-12 04:22:13 +02:00
|
|
|
|
at45db_unlock(priv);
|
|
|
|
|
|
|
|
|
|
return nblocks;
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
|
/****************************************************************************
|
2010-09-12 04:22:13 +02:00
|
|
|
|
* Name: at45db_read
|
2021-01-27 16:48:40 +01:00
|
|
|
|
****************************************************************************/
|
2010-09-12 04:22:13 +02:00
|
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
|
static ssize_t at45db_read(FAR struct mtd_dev_s *mtd,
|
|
|
|
|
off_t offset,
|
|
|
|
|
size_t nbytes,
|
2014-09-25 14:48:04 +02:00
|
|
|
|
FAR uint8_t *buffer)
|
2010-09-12 04:22:13 +02:00
|
|
|
|
{
|
|
|
|
|
FAR struct at45db_dev_s *priv = (FAR struct at45db_dev_s *)mtd;
|
|
|
|
|
uint8_t rdcmd [5];
|
|
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
|
finfo("offset: %08lx nbytes: %d\n", (long)offset, (int)nbytes);
|
2010-09-12 04:22:13 +02:00
|
|
|
|
|
|
|
|
|
/* Set up for the read */
|
|
|
|
|
|
|
|
|
|
rdcmd[0] = AT45DB_RDARRAYHF; /* FAST_READ is safe at all supported SPI speeds. */
|
|
|
|
|
rdcmd[1] = (offset >> 16) & 0xff; /* 24-bit address upper byte */
|
|
|
|
|
rdcmd[2] = (offset >> 8) & 0xff; /* 24-bit address middle byte */
|
|
|
|
|
rdcmd[3] = offset & 0xff; /* 24-bit address least significant byte */
|
|
|
|
|
rdcmd[4] = 0; /* Dummy byte */
|
|
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
|
/* Take the lock so that we have exclusive access to the bus, then power up
|
|
|
|
|
* the FLASH device.
|
2010-09-12 04:22:13 +02:00
|
|
|
|
*/
|
2014-04-13 22:32:20 +02:00
|
|
|
|
|
2010-09-12 04:22:13 +02:00
|
|
|
|
at45db_lock(priv);
|
2010-09-13 20:27:19 +02:00
|
|
|
|
at45db_resume(priv);
|
2014-04-13 22:32:20 +02:00
|
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
|
/* Higher performance write logic: We leave the chip busy after write and
|
|
|
|
|
* erase operations. This improves write and erase performance because we
|
|
|
|
|
* do not have to wait as long between transactions (other processing can
|
|
|
|
|
* occur while the chip is busy) but means that the chip must stay powered
|
|
|
|
|
* and that we must check if the chip is still busy on each entry point.
|
2010-09-13 17:35:59 +02:00
|
|
|
|
*/
|
|
|
|
|
|
2010-09-13 17:57:14 +02:00
|
|
|
|
#ifdef CONFIG_AT45DB_PREWAIT
|
2010-09-13 17:35:59 +02:00
|
|
|
|
at45db_waitbusy(priv);
|
|
|
|
|
#endif
|
2010-09-12 04:22:13 +02:00
|
|
|
|
|
|
|
|
|
/* Perform the read */
|
|
|
|
|
|
2017-04-29 20:26:52 +02:00
|
|
|
|
SPI_SELECT(priv->spi, SPIDEV_FLASH(0), true);
|
2010-09-12 04:22:13 +02:00
|
|
|
|
SPI_SNDBLOCK(priv->spi, rdcmd, 5);
|
|
|
|
|
SPI_RECVBLOCK(priv->spi, buffer, nbytes);
|
2017-04-29 20:26:52 +02:00
|
|
|
|
SPI_SELECT(priv->spi, SPIDEV_FLASH(0), false);
|
2010-09-12 04:22:13 +02:00
|
|
|
|
|
|
|
|
|
at45db_pwrdown(priv);
|
|
|
|
|
at45db_unlock(priv);
|
2010-09-13 17:35:59 +02:00
|
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
|
finfo("return nbytes: %d\n", (int)nbytes);
|
2010-09-12 04:22:13 +02:00
|
|
|
|
return nbytes;
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
|
/****************************************************************************
|
2010-09-12 04:22:13 +02:00
|
|
|
|
* Name: at45db_ioctl
|
2021-01-27 16:48:40 +01:00
|
|
|
|
****************************************************************************/
|
2010-09-12 04:22:13 +02:00
|
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
|
static int at45db_ioctl(FAR struct mtd_dev_s *mtd,
|
|
|
|
|
int cmd,
|
|
|
|
|
unsigned long arg)
|
2010-09-12 04:22:13 +02:00
|
|
|
|
{
|
|
|
|
|
FAR struct at45db_dev_s *priv = (FAR struct at45db_dev_s *)mtd;
|
|
|
|
|
int ret = -EINVAL; /* Assume good command with bad parameters */
|
|
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
|
finfo("cmd: %d \n", cmd);
|
2010-09-12 04:22:13 +02:00
|
|
|
|
|
|
|
|
|
switch (cmd)
|
|
|
|
|
{
|
|
|
|
|
case MTDIOC_GEOMETRY:
|
|
|
|
|
{
|
2021-01-27 16:48:40 +01:00
|
|
|
|
FAR struct mtd_geometry_s *geo =
|
|
|
|
|
(FAR struct mtd_geometry_s *)((uintptr_t)arg);
|
2010-09-12 04:22:13 +02:00
|
|
|
|
if (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.
|
2010-09-12 04:22:13 +02: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 clientwill expect the
|
|
|
|
|
* device logic to do whatever is necessary to make it appear
|
|
|
|
|
* so.
|
2010-09-12 04:22:13 +02:00
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
geo->blocksize = (1 << priv->pageshift);
|
|
|
|
|
geo->erasesize = geo->blocksize;
|
|
|
|
|
geo->neraseblocks = priv->npages;
|
|
|
|
|
ret = OK;
|
|
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
|
finfo("blocksize: %d erasesize: %d neraseblocks: %d\n",
|
2010-09-12 04:22:13 +02:00
|
|
|
|
geo->blocksize, geo->erasesize, geo->neraseblocks);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
case MTDIOC_BULKERASE:
|
|
|
|
|
{
|
2018-12-13 01:21:27 +01:00
|
|
|
|
/* Take the lock so that we have exclusive access to the bus, then
|
|
|
|
|
* power up the FLASH device.
|
|
|
|
|
*/
|
2014-04-13 22:32:20 +02:00
|
|
|
|
|
2018-12-13 01:21:27 +01:00
|
|
|
|
at45db_lock(priv);
|
|
|
|
|
at45db_resume(priv);
|
2010-09-12 04:22:13 +02:00
|
|
|
|
|
2018-12-13 01:21:27 +01:00
|
|
|
|
/* Erase the entire device */
|
2010-09-12 04:22:13 +02:00
|
|
|
|
|
2018-12-13 01:21:27 +01:00
|
|
|
|
ret = at45db_chiperase(priv);
|
|
|
|
|
at45db_pwrdown(priv);
|
|
|
|
|
at45db_unlock(priv);
|
2010-09-12 04:22:13 +02:00
|
|
|
|
}
|
|
|
|
|
break;
|
2014-04-13 22:32:20 +02:00
|
|
|
|
|
2010-09-12 04:22:13 +02:00
|
|
|
|
case MTDIOC_XIPBASE:
|
|
|
|
|
default:
|
|
|
|
|
ret = -ENOTTY; /* Bad command */
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
|
finfo("return %d\n", ret);
|
2010-09-12 04:22:13 +02:00
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
|
/****************************************************************************
|
2010-09-12 04:22:13 +02:00
|
|
|
|
* Public Functions
|
2021-01-27 16:48:40 +01:00
|
|
|
|
****************************************************************************/
|
2010-09-12 04:22:13 +02:00
|
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
|
/****************************************************************************
|
2010-09-12 04:22:13 +02:00
|
|
|
|
* Name: at45db_initialize
|
|
|
|
|
*
|
|
|
|
|
* Description:
|
2021-01-27 16:48:40 +01:00
|
|
|
|
* Create an initialize MTD device instance. MTD devices are not registered
|
2010-09-12 04:22:13 +02: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
|
|
|
|
****************************************************************************/
|
2010-09-12 04:22:13 +02:00
|
|
|
|
|
|
|
|
|
FAR struct mtd_dev_s *at45db_initialize(FAR struct spi_dev_s *spi)
|
|
|
|
|
{
|
|
|
|
|
FAR struct at45db_dev_s *priv;
|
|
|
|
|
uint8_t sr;
|
|
|
|
|
int ret;
|
|
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
|
finfo("spi: %p\n", spi);
|
2010-09-12 04:22:13 +02:00
|
|
|
|
|
2021-01-27 16:48:40 +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
|
|
|
|
|
* 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.
|
2010-09-12 04:22:13 +02:00
|
|
|
|
*/
|
|
|
|
|
|
2014-09-01 01:34:44 +02:00
|
|
|
|
priv = (FAR struct at45db_dev_s *)kmm_zalloc(sizeof(struct at45db_dev_s));
|
2010-09-12 04:22:13 +02: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
|
|
|
|
*/
|
2010-09-12 04:22:13 +02:00
|
|
|
|
|
|
|
|
|
priv->mtd.erase = at45db_erase;
|
|
|
|
|
priv->mtd.bread = at45db_bread;
|
|
|
|
|
priv->mtd.bwrite = at45db_bwrite;
|
|
|
|
|
priv->mtd.read = at45db_read;
|
|
|
|
|
priv->mtd.ioctl = at45db_ioctl;
|
2018-11-08 16:46:11 +01:00
|
|
|
|
priv->mtd.name = "at45db";
|
2010-09-12 04:22:13 +02:00
|
|
|
|
priv->spi = spi;
|
|
|
|
|
|
|
|
|
|
/* Deselect the FLASH */
|
|
|
|
|
|
2017-04-29 20:26:52 +02:00
|
|
|
|
SPI_SELECT(spi, SPIDEV_FLASH(0), false);
|
2010-09-12 04:22:13 +02:00
|
|
|
|
|
|
|
|
|
/* Lock and configure the SPI bus. */
|
|
|
|
|
|
|
|
|
|
at45db_lock(priv);
|
2010-09-13 20:27:19 +02:00
|
|
|
|
at45db_resume(priv);
|
2010-09-12 04:22:13 +02:00
|
|
|
|
|
|
|
|
|
/* Identify the FLASH chip and get its capacity */
|
|
|
|
|
|
|
|
|
|
ret = at45db_rdid(priv);
|
|
|
|
|
if (ret != OK)
|
|
|
|
|
{
|
2021-01-27 16:48:40 +01:00
|
|
|
|
/* Unrecognized!
|
|
|
|
|
* Discard all of that work we just did and return NULL
|
|
|
|
|
*/
|
2010-09-12 04:22:13 +02:00
|
|
|
|
|
2016-06-12 16:31:22 +02:00
|
|
|
|
ferr("ERROR: Unrecognized\n");
|
2010-09-12 04:22:13 +02:00
|
|
|
|
goto errout;
|
|
|
|
|
}
|
|
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
|
/* Get the value of the status register
|
|
|
|
|
* (as soon as the device is ready)
|
|
|
|
|
*/
|
2010-09-12 04:22:13 +02:00
|
|
|
|
|
|
|
|
|
sr = at45db_waitbusy(priv);
|
|
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
|
/* Check if the device is configured as 256, 512 or 1024
|
|
|
|
|
* bytes-per-page device.
|
2014-09-25 14:48:04 +02:00
|
|
|
|
*/
|
2010-09-12 04:22:13 +02:00
|
|
|
|
|
|
|
|
|
if ((sr & AT45DB_SR_PGSIZE) == 0)
|
|
|
|
|
{
|
2021-01-27 16:48:40 +01:00
|
|
|
|
/* No, re-program it for the binary page size.
|
|
|
|
|
* NOTE:
|
|
|
|
|
* A power cycle is required after the device has be re-programmed.
|
2010-09-12 04:22:13 +02:00
|
|
|
|
*/
|
|
|
|
|
|
2016-06-12 16:31:22 +02:00
|
|
|
|
fwarn("WARNING: Reprogramming page size\n");
|
|
|
|
|
|
2017-04-29 20:26:52 +02:00
|
|
|
|
SPI_SELECT(priv->spi, SPIDEV_FLASH(0), true);
|
2010-09-12 15:28:21 +02:00
|
|
|
|
SPI_SNDBLOCK(priv->spi, g_binpgsize, BINPGSIZE_SIZE);
|
2017-04-29 20:26:52 +02:00
|
|
|
|
SPI_SELECT(priv->spi, SPIDEV_FLASH(0), false);
|
2010-09-12 04:22:13 +02:00
|
|
|
|
goto errout;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Release the lock and power down the device */
|
|
|
|
|
|
|
|
|
|
at45db_pwrdown(priv);
|
|
|
|
|
at45db_unlock(priv);
|
2014-04-13 22:32:20 +02:00
|
|
|
|
}
|
2010-09-12 04:22:13 +02:00
|
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
|
finfo("Return %p\n", priv);
|
2010-09-12 04:22:13 +02:00
|
|
|
|
return (FAR struct mtd_dev_s *)priv;
|
|
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
|
/* On any failure, we need free memory allocations and release the lock
|
|
|
|
|
* that we hold on the SPI bus. On failures, assume that we cannot talk
|
|
|
|
|
* to the device to do any more.
|
2014-09-25 14:48:04 +02:00
|
|
|
|
*/
|
2010-09-12 04:22:13 +02:00
|
|
|
|
|
|
|
|
|
errout:
|
|
|
|
|
at45db_unlock(priv);
|
2014-09-01 01:04:02 +02:00
|
|
|
|
kmm_free(priv);
|
2010-09-12 04:22:13 +02:00
|
|
|
|
return NULL;
|
|
|
|
|
}
|