2021-01-27 16:48:40 +01:00
|
|
|
/****************************************************************************
|
2011-12-17 21:07:22 +01:00
|
|
|
* drivers/mtd/ramtron.c
|
|
|
|
*
|
2021-03-31 13:42:08 +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
|
2021-01-27 16:48:40 +01:00
|
|
|
*
|
2021-03-31 13:42:08 +02:00
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
2011-12-17 21:07:22 +01:00
|
|
|
*
|
2021-03-31 13:42:08 +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.
|
2011-12-17 21:07:22 +01:00
|
|
|
*
|
2021-01-27 16:48:40 +01:00
|
|
|
****************************************************************************/
|
2011-12-17 21:07:22 +01:00
|
|
|
|
|
|
|
/* OPTIONS:
|
2014-04-13 22:32:20 +02:00
|
|
|
* - additional non-jedec standard device: FM25H20
|
2011-12-17 21:07:22 +01:00
|
|
|
* must be enabled with the CONFIG_RAMTRON_FRAM_NON_JEDEC=y
|
2014-04-13 22:32:20 +02:00
|
|
|
*
|
2011-12-17 21:07:22 +01:00
|
|
|
* NOTE:
|
2021-01-27 16:48:40 +01:00
|
|
|
* - frequency is fixed to desired max by RAMTRON_INIT_CLK_MAX if new
|
|
|
|
* devices with different speed arrive, use the table to handle freq
|
|
|
|
* change and to fit all devices. Note that STM32_SPI driver is prone
|
|
|
|
* to too high freq. parameters and limit it within physical constraints.
|
|
|
|
* The speed may be changed through ioctl MTDIOC_SETSPEED
|
2014-04-13 22:32:20 +02:00
|
|
|
*
|
2011-12-17 21:07:22 +01:00
|
|
|
* TODO:
|
|
|
|
* - add support for sleep
|
|
|
|
* - add support for faster read FSTRD command
|
|
|
|
*/
|
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
/****************************************************************************
|
2011-12-17 21:07:22 +01:00
|
|
|
* Included Files
|
2021-01-27 16:48:40 +01:00
|
|
|
****************************************************************************/
|
2011-12-17 21:07:22 +01:00
|
|
|
|
|
|
|
#include <nuttx/config.h>
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
2021-04-20 17:16:19 +02:00
|
|
|
#include <inttypes.h>
|
2011-12-17 21:07:22 +01:00
|
|
|
#include <stdint.h>
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <errno.h>
|
|
|
|
#include <debug.h>
|
|
|
|
#include <assert.h>
|
|
|
|
|
|
|
|
#include <nuttx/kmalloc.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>
|
2011-12-17 21:07:22 +01:00
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
/****************************************************************************
|
2011-12-17 21:07:22 +01:00
|
|
|
* Pre-processor Definitions
|
2021-01-27 16:48:40 +01:00
|
|
|
****************************************************************************/
|
2011-12-17 21:07:22 +01:00
|
|
|
|
2014-12-26 14:59:09 +01:00
|
|
|
/* Used to abort the write wait */
|
|
|
|
|
|
|
|
#ifndef CONFIG_MTD_RAMTRON_WRITEWAIT_COUNT
|
|
|
|
# define CONFIG_MTD_RAMTRON_WRITEWAIT_COUNT 100
|
|
|
|
#endif
|
|
|
|
|
2011-12-17 21:07:22 +01:00
|
|
|
/* RAMTRON devices are flat!
|
2021-01-27 16:48:40 +01:00
|
|
|
* For purpose of the VFAT file system we emulate the following
|
|
|
|
* configuration:
|
2011-12-17 21:07:22 +01:00
|
|
|
*/
|
|
|
|
|
2023-02-07 13:31:12 +01:00
|
|
|
#define RAMTRON_EMULATE_SECTOR_SHIFT CONFIG_RAMTRON_EMULATE_SECTOR_SHIFT
|
|
|
|
#define RAMTRON_EMULATE_PAGE_SHIFT CONFIG_RAMTRON_EMULATE_PAGE_SHIFT
|
2017-08-04 16:49:07 +02:00
|
|
|
#define RAMTRON_EMULATE_PAGE_SIZE (1 << RAMTRON_EMULATE_PAGE_SHIFT)
|
2011-12-17 21:07:22 +01:00
|
|
|
|
2014-12-26 14:59:09 +01:00
|
|
|
/* RAMTRON Identification register values */
|
2011-12-17 21:07:22 +01:00
|
|
|
|
2017-08-04 16:49:07 +02:00
|
|
|
#define RAMTRON_MANUFACTURER 0x7f
|
|
|
|
#define RAMTRON_MEMORY_TYPE 0xc2
|
2011-12-17 21:07:22 +01:00
|
|
|
|
|
|
|
/* Instructions:
|
2021-01-27 16:48:40 +01:00
|
|
|
* Command Value N Description Addr Dummy Data
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define RAMTRON_WREN 0x06 /* 1 Write Enable 0 0 0 */
|
|
|
|
#define RAMTRON_WRDI 0x04 /* 1 Write Disable 0 0 0 */
|
|
|
|
#define RAMTRON_RDSR 0x05 /* 1 Read Status Register 0 0 >=1 */
|
|
|
|
#define RAMTRON_WRSR 0x01 /* 1 Write Status Register 0 0 1 */
|
|
|
|
#define RAMTRON_READ 0x03 /* 1 Read Data Bytes A 0 >=1 */
|
|
|
|
#define RAMTRON_FSTRD 0x0b /* 1 Higher speed read A 1 >=1 */
|
|
|
|
#define RAMTRON_WRITE 0x02 /* 1 Write A 0 1-256 */
|
2014-12-26 14:59:09 +01:00
|
|
|
#define RAMTRON_SLEEP 0xb9 /* TODO: */
|
2021-01-27 16:48:40 +01:00
|
|
|
#define RAMTRON_RDID 0x9f /* 1 Read Identification 0 0 1-3 */
|
2014-12-26 14:59:09 +01:00
|
|
|
#define RAMTRON_SN 0xc3 /* TODO: */
|
2011-12-17 21:07:22 +01:00
|
|
|
|
|
|
|
/* Status register bit definitions */
|
|
|
|
|
2021-11-25 14:26:56 +01:00
|
|
|
/* Bit 0: Res 0 */
|
2021-01-27 16:48:40 +01:00
|
|
|
#define RAMTRON_SR_WEL (1 << 1) /* Bit 1: Write enable latch bit */
|
|
|
|
#define RAMTRON_SR_BP_SHIFT (2) /* Bits 2-4: Block protect bits */
|
2021-11-25 14:26:56 +01:00
|
|
|
#define RAMTRON_SR_BP_MASK (3 << RAMTRON_SR_BP_SHIFT)
|
2021-01-27 16:48:40 +01:00
|
|
|
#define RAMTRON_SR_BP_NONE (0 << RAMTRON_SR_BP_SHIFT) /* Unprotected */
|
2021-11-25 14:26:56 +01:00
|
|
|
#define RAMTRON_SR_BP_UPPERQTR (1 << RAMTRON_SR_BP_SHIFT) /* Upper quarter */
|
|
|
|
#define RAMTRON_SR_BP_UPPERHALF (2 << RAMTRON_SR_BP_SHIFT) /* Upper half */
|
|
|
|
#define RAMTRON_SR_BP_ALL (3 << RAMTRON_SR_BP_SHIFT) /* All sectors */
|
|
|
|
#define RAMTRON_SR_BP_SHIFT (2) /* Bits 4-6: Reserved Always 0 */
|
|
|
|
#define RAMTRON_SR_WPEN (1 << 7) /* Bit 7: Status register write protect */
|
2011-12-17 21:07:22 +01:00
|
|
|
|
|
|
|
#define RAMTRON_DUMMY 0xa5
|
|
|
|
|
2017-08-04 16:49:07 +02:00
|
|
|
/* Defines the initial speed compatible with all devices. In case of RAMTRON
|
|
|
|
* the defined devices within the part list have all the same speed.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#define RAMTRON_INIT_CLK_MAX 40000000UL
|
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
/****************************************************************************
|
2011-12-17 21:07:22 +01:00
|
|
|
* Private Types
|
2021-01-27 16:48:40 +01:00
|
|
|
****************************************************************************/
|
2011-12-17 21:07:22 +01:00
|
|
|
|
|
|
|
struct ramtron_parts_s
|
|
|
|
{
|
2017-08-04 16:49:07 +02:00
|
|
|
FAR const char *name;
|
|
|
|
uint8_t id1;
|
|
|
|
uint8_t id2;
|
|
|
|
uint32_t size;
|
|
|
|
uint8_t addr_len;
|
|
|
|
uint32_t speed;
|
|
|
|
#ifdef CONFIG_RAMTRON_CHUNKING
|
|
|
|
bool chunked; /* True: write buffer size limitations */
|
|
|
|
uint16_t chunksize; /* Write chunk Size */
|
|
|
|
#endif
|
2011-12-17 21:07:22 +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 ramtron_dev_s.
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct ramtron_dev_s
|
|
|
|
{
|
2014-05-13 02:43:06 +02:00
|
|
|
struct mtd_dev_s mtd; /* MTD interface */
|
|
|
|
FAR struct spi_dev_s *dev; /* Saved SPI interface instance */
|
|
|
|
uint8_t sectorshift;
|
|
|
|
uint8_t pageshift;
|
2023-02-17 11:50:05 +01:00
|
|
|
uint32_t nsectors;
|
2011-12-17 21:07:22 +01:00
|
|
|
uint32_t npages;
|
2014-12-26 14:59:09 +01:00
|
|
|
uint32_t speed; /* Overridable via ioctl */
|
2014-05-13 02:43:06 +02:00
|
|
|
FAR const struct ramtron_parts_s *part; /* Part instance */
|
2011-12-17 21:07:22 +01:00
|
|
|
};
|
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
/****************************************************************************
|
2011-12-17 21:07:22 +01:00
|
|
|
* Supported Part Lists
|
2021-01-27 16:48:40 +01:00
|
|
|
****************************************************************************/
|
2011-12-17 21:07:22 +01:00
|
|
|
|
2014-05-13 02:43:06 +02:00
|
|
|
static const struct ramtron_parts_s g_ramtron_parts[] =
|
2011-12-17 21:07:22 +01:00
|
|
|
{
|
2013-04-19 00:12:37 +02:00
|
|
|
{
|
|
|
|
"FM25V01", /* name */
|
|
|
|
0x21, /* id1 */
|
|
|
|
0x00, /* id2 */
|
2021-01-27 16:48:40 +01:00
|
|
|
16L * 1024L, /* size */
|
2013-04-19 00:12:37 +02:00
|
|
|
2, /* addr_len */
|
2014-12-26 15:15:59 +01:00
|
|
|
RAMTRON_INIT_CLK_MAX /* speed */
|
2017-08-04 16:49:07 +02:00
|
|
|
#ifdef CONFIG_RAMTRON_CHUNKING
|
|
|
|
, false, /* chunked */
|
|
|
|
RAMTRON_EMULATE_PAGE_SIZE /* chunksize */
|
|
|
|
#endif
|
2013-04-19 00:12:37 +02:00
|
|
|
},
|
2015-08-10 19:30:37 +02:00
|
|
|
{
|
|
|
|
"FM25V01A", /* name */
|
|
|
|
0x21, /* id1 */
|
|
|
|
0x08, /* id2 */
|
2021-01-27 16:48:40 +01:00
|
|
|
16L * 1024L, /* size */
|
2015-08-10 19:30:37 +02:00
|
|
|
2, /* addr_len */
|
|
|
|
RAMTRON_INIT_CLK_MAX /* speed */
|
2017-08-04 16:49:07 +02:00
|
|
|
#ifdef CONFIG_RAMTRON_CHUNKING
|
|
|
|
, false, /* chunked */
|
|
|
|
RAMTRON_EMULATE_PAGE_SIZE /* chunksize */
|
|
|
|
#endif
|
2015-08-10 19:30:37 +02:00
|
|
|
},
|
2012-10-06 16:50:37 +02:00
|
|
|
{
|
|
|
|
"FM25V02", /* name */
|
|
|
|
0x22, /* id1 */
|
|
|
|
0x00, /* id2 */
|
2021-01-27 16:48:40 +01:00
|
|
|
32L * 1024L, /* size */
|
2012-10-06 16:50:37 +02:00
|
|
|
2, /* addr_len */
|
2014-12-26 15:15:59 +01:00
|
|
|
RAMTRON_INIT_CLK_MAX /* speed */
|
2017-08-04 16:49:07 +02:00
|
|
|
#ifdef CONFIG_RAMTRON_CHUNKING
|
|
|
|
, false, /* chunked */
|
|
|
|
RAMTRON_EMULATE_PAGE_SIZE /* chunksize */
|
|
|
|
#endif
|
2012-10-06 16:50:37 +02:00
|
|
|
},
|
2015-08-10 19:30:37 +02:00
|
|
|
{
|
|
|
|
"FM25V02A", /* name */
|
|
|
|
0x22, /* id1 */
|
|
|
|
0x08, /* id2 */
|
2021-01-27 16:48:40 +01:00
|
|
|
32L * 1024L, /* size */
|
2015-08-10 19:30:37 +02:00
|
|
|
2, /* addr_len */
|
|
|
|
RAMTRON_INIT_CLK_MAX /* speed */
|
2017-08-04 16:49:07 +02:00
|
|
|
#ifdef CONFIG_RAMTRON_CHUNKING
|
|
|
|
, false, /* chunked */
|
|
|
|
RAMTRON_EMULATE_PAGE_SIZE /* chunksize */
|
2023-06-08 14:27:54 +02:00
|
|
|
#endif
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"FM25V02A-DGQ", /* name */
|
|
|
|
0x22, /* id1 */
|
|
|
|
0x48, /* id2 */
|
|
|
|
32L * 1024L, /* size */
|
|
|
|
2, /* addr_len */
|
|
|
|
RAMTRON_INIT_CLK_MAX /* speed */
|
|
|
|
#ifdef CONFIG_RAMTRON_CHUNKING
|
|
|
|
, false, /* chunked */
|
|
|
|
RAMTRON_EMULATE_PAGE_SIZE /* chunksize */
|
2017-08-04 16:49:07 +02:00
|
|
|
#endif
|
2015-08-10 19:30:37 +02:00
|
|
|
},
|
2012-10-06 16:50:37 +02:00
|
|
|
{
|
2014-05-13 02:43:06 +02:00
|
|
|
"FM25VN02", /* name */
|
|
|
|
0x22, /* id1 */
|
|
|
|
0x01, /* id2 */
|
2021-01-27 16:48:40 +01:00
|
|
|
32L * 1024L, /* size */
|
2014-05-13 02:43:06 +02:00
|
|
|
2, /* addr_len */
|
2014-12-26 15:15:59 +01:00
|
|
|
RAMTRON_INIT_CLK_MAX /* speed */
|
2017-08-04 16:49:07 +02:00
|
|
|
#ifdef CONFIG_RAMTRON_CHUNKING
|
|
|
|
, false, /* chunked */
|
|
|
|
RAMTRON_EMULATE_PAGE_SIZE /* chunksize */
|
|
|
|
#endif
|
2012-10-06 16:50:37 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"FM25V05", /* name */
|
|
|
|
0x23, /* id1 */
|
|
|
|
0x00, /* id2 */
|
2021-01-27 16:48:40 +01:00
|
|
|
64L * 1024L, /* size */
|
2012-10-06 16:50:37 +02:00
|
|
|
2, /* addr_len */
|
2014-12-26 15:15:59 +01:00
|
|
|
RAMTRON_INIT_CLK_MAX /* speed */
|
2017-08-04 16:49:07 +02:00
|
|
|
#ifdef CONFIG_RAMTRON_CHUNKING
|
|
|
|
, false, /* chunked */
|
|
|
|
RAMTRON_EMULATE_PAGE_SIZE /* chunksize */
|
|
|
|
#endif
|
2012-10-06 16:50:37 +02:00
|
|
|
},
|
|
|
|
{
|
2014-05-13 02:43:06 +02:00
|
|
|
"FM25VN05", /* name */
|
|
|
|
0x23, /* id1 */
|
|
|
|
0x01, /* id2 */
|
2021-01-27 16:48:40 +01:00
|
|
|
64L * 1024L, /* size */
|
2014-05-13 02:43:06 +02:00
|
|
|
2, /* addr_len */
|
2014-12-26 15:15:59 +01:00
|
|
|
RAMTRON_INIT_CLK_MAX /* speed */
|
2017-08-04 16:49:07 +02:00
|
|
|
#ifdef CONFIG_RAMTRON_CHUNKING
|
|
|
|
, false, /* chunked */
|
|
|
|
RAMTRON_EMULATE_PAGE_SIZE /* chunksize */
|
|
|
|
#endif
|
2012-10-06 16:50:37 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"FM25V10", /* name */
|
|
|
|
0x24, /* id1 */
|
|
|
|
0x00, /* id2 */
|
2021-01-27 16:48:40 +01:00
|
|
|
128L * 1024L, /* size */
|
2012-10-06 16:50:37 +02:00
|
|
|
3, /* addr_len */
|
2014-12-26 15:15:59 +01:00
|
|
|
RAMTRON_INIT_CLK_MAX /* speed */
|
2017-08-04 16:49:07 +02:00
|
|
|
#ifdef CONFIG_RAMTRON_CHUNKING
|
|
|
|
, false, /* chunked */
|
|
|
|
RAMTRON_EMULATE_PAGE_SIZE /* chunksize */
|
|
|
|
#endif
|
2012-10-06 16:50:37 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"FM25VN10", /* name */
|
|
|
|
0x24, /* id1 */
|
|
|
|
0x01, /* id2 */
|
2021-01-27 16:48:40 +01:00
|
|
|
128L * 1024L, /* size */
|
2012-10-06 16:50:37 +02:00
|
|
|
3, /* addr_len */
|
2014-12-26 15:15:59 +01:00
|
|
|
RAMTRON_INIT_CLK_MAX /* speed */
|
2017-08-04 16:49:07 +02:00
|
|
|
#ifdef CONFIG_RAMTRON_CHUNKING
|
|
|
|
, false, /* chunked */
|
|
|
|
RAMTRON_EMULATE_PAGE_SIZE /* chunksize */
|
|
|
|
#endif
|
2012-10-06 16:50:37 +02:00
|
|
|
},
|
2015-08-10 19:30:37 +02:00
|
|
|
{
|
|
|
|
"FM25V20A", /* name */
|
|
|
|
0x25, /* id1 */
|
|
|
|
0x08, /* id2 */
|
2021-01-27 16:48:40 +01:00
|
|
|
256L * 1024L, /* size */
|
2015-08-10 19:30:37 +02:00
|
|
|
3, /* addr_len */
|
|
|
|
RAMTRON_INIT_CLK_MAX /* speed */
|
2017-08-04 16:49:07 +02:00
|
|
|
#ifdef CONFIG_RAMTRON_CHUNKING
|
|
|
|
, false, /* chunked */
|
|
|
|
RAMTRON_EMULATE_PAGE_SIZE /* chunksize */
|
|
|
|
#endif
|
2015-08-10 19:30:37 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"CY15B104Q", /* name */
|
|
|
|
0x26, /* id1 */
|
|
|
|
0x08, /* id2 */
|
2021-01-27 16:48:40 +01:00
|
|
|
512L * 1024L, /* size */
|
2015-08-10 19:30:37 +02:00
|
|
|
3, /* addr_len */
|
|
|
|
RAMTRON_INIT_CLK_MAX /* speed */
|
2017-08-04 16:49:07 +02:00
|
|
|
#ifdef CONFIG_RAMTRON_CHUNKING
|
|
|
|
, false, /* chunked */
|
|
|
|
RAMTRON_EMULATE_PAGE_SIZE /* chunksize */
|
|
|
|
#endif
|
2015-08-10 19:30:37 +02:00
|
|
|
},
|
2014-05-13 02:43:06 +02:00
|
|
|
{
|
|
|
|
"MB85RS1MT", /* name */
|
|
|
|
0x27, /* id1 */
|
|
|
|
0x03, /* id2 */
|
2021-01-27 16:48:40 +01:00
|
|
|
128L * 1024L, /* size */
|
2014-05-13 02:43:06 +02:00
|
|
|
3, /* addr_len */
|
2016-08-23 20:27:04 +02:00
|
|
|
25000000 /* speed */
|
2017-08-04 16:49:07 +02:00
|
|
|
#ifdef CONFIG_RAMTRON_CHUNKING
|
|
|
|
, false, /* chunked */
|
|
|
|
RAMTRON_EMULATE_PAGE_SIZE /* chunksize */
|
2022-06-17 00:04:26 +02:00
|
|
|
#endif
|
|
|
|
},
|
|
|
|
{
|
|
|
|
"MB85RS2MT", /* name */
|
|
|
|
0x48, /* id1 */
|
|
|
|
0x03, /* id2 */
|
|
|
|
256L * 1024L, /* size */
|
|
|
|
3, /* addr_len */
|
|
|
|
25000000 /* speed */
|
|
|
|
#ifdef CONFIG_RAMTRON_CHUNKING
|
|
|
|
, false, /* chunked */
|
|
|
|
RAMTRON_EMULATE_PAGE_SIZE /* chunksize */
|
2017-08-04 16:49:07 +02:00
|
|
|
#endif
|
2016-08-23 20:27:04 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
"MB85RS256B", /* name */
|
|
|
|
0x05, /* id1 */
|
|
|
|
0x09, /* id2 */
|
2021-01-27 16:48:40 +01:00
|
|
|
32L * 1024L, /* size */
|
2024-09-12 03:36:57 +02:00
|
|
|
2, /* addr_len */
|
2014-05-13 02:43:06 +02:00
|
|
|
25000000 /* speed */
|
2017-08-04 16:49:07 +02:00
|
|
|
#ifdef CONFIG_RAMTRON_CHUNKING
|
|
|
|
, false, /* chunked */
|
|
|
|
RAMTRON_EMULATE_PAGE_SIZE /* chunksize */
|
|
|
|
#endif
|
2014-05-13 02:43:06 +02:00
|
|
|
},
|
2017-08-04 16:49:07 +02:00
|
|
|
#ifdef CONFIG_RAMTRON_CHUNKING
|
2017-08-04 16:12:59 +02:00
|
|
|
{
|
|
|
|
"MB85AS4MT", /* name */
|
|
|
|
0xc9, /* id1 */
|
|
|
|
0x03, /* id2 */
|
2021-01-27 16:48:40 +01:00
|
|
|
512L * 1024L, /* size */
|
2017-08-04 16:12:59 +02:00
|
|
|
3, /* addr_len */
|
2017-08-04 16:49:07 +02:00
|
|
|
RAMTRON_INIT_CLK_MAX, /* speed */
|
|
|
|
true, /* chunked */
|
|
|
|
256 /* chunksize */
|
2017-08-04 16:12:59 +02:00
|
|
|
},
|
2017-08-04 16:49:07 +02:00
|
|
|
#endif
|
2011-12-17 21:07:22 +01:00
|
|
|
#ifdef CONFIG_RAMTRON_FRAM_NON_JEDEC
|
2012-10-06 16:50:37 +02:00
|
|
|
{
|
|
|
|
"FM25H20", /* name */
|
|
|
|
0xff, /* id1 */
|
|
|
|
0xff, /* id2 */
|
2021-01-27 16:48:40 +01:00
|
|
|
256L * 1024L, /* size */
|
2012-10-06 16:50:37 +02:00
|
|
|
3, /* addr_len */
|
2014-12-26 15:15:59 +01:00
|
|
|
RAMTRON_INIT_CLK_MAX /* speed */
|
2017-08-04 16:49:07 +02:00
|
|
|
#ifdef CONFIG_RAMTRON_CHUNKING
|
|
|
|
, false, /* chunked */
|
|
|
|
RAMTRON_EMULATE_PAGE_SIZE /* chunksize */
|
|
|
|
#endif
|
2012-10-06 16:50:37 +02:00
|
|
|
},
|
2015-02-09 23:35:58 +01:00
|
|
|
#endif
|
2012-10-06 16:50:37 +02:00
|
|
|
{
|
|
|
|
NULL, /* name */
|
|
|
|
0, /* id1 */
|
|
|
|
0, /* id2 */
|
|
|
|
0, /* size */
|
|
|
|
0, /* addr_len */
|
|
|
|
0 /* speed */
|
2017-08-04 16:49:07 +02:00
|
|
|
#ifdef CONFIG_RAMTRON_CHUNKING
|
|
|
|
, false, /* chunked */
|
|
|
|
0, /* chunksize */
|
|
|
|
#endif
|
2012-10-06 16:50:37 +02:00
|
|
|
}
|
2011-12-17 21:07:22 +01:00
|
|
|
};
|
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
/****************************************************************************
|
2011-12-17 21:07:22 +01:00
|
|
|
* Private Function Prototypes
|
2021-01-27 16:48:40 +01:00
|
|
|
****************************************************************************/
|
2011-12-17 21:07:22 +01:00
|
|
|
|
|
|
|
/* Helpers */
|
|
|
|
|
2014-12-26 14:59:09 +01:00
|
|
|
static void ramtron_lock(FAR struct ramtron_dev_s *priv);
|
2011-12-17 21:07:22 +01:00
|
|
|
static inline void ramtron_unlock(FAR struct spi_dev_s *dev);
|
|
|
|
static inline int ramtron_readid(struct ramtron_dev_s *priv);
|
|
|
|
static void ramtron_writeenable(struct ramtron_dev_s *priv);
|
2014-12-26 14:59:09 +01:00
|
|
|
static inline int ramtron_pagewrite(struct ramtron_dev_s *priv,
|
2021-01-27 16:48:40 +01:00
|
|
|
FAR const uint8_t *buffer,
|
|
|
|
off_t offset,
|
2017-08-04 16:12:59 +02:00
|
|
|
size_t pagesize);
|
2011-12-17 21:07:22 +01:00
|
|
|
|
|
|
|
/* MTD driver methods */
|
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
static int ramtron_erase(FAR struct mtd_dev_s *dev,
|
|
|
|
off_t startblock,
|
|
|
|
size_t nblocks);
|
|
|
|
static ssize_t ramtron_bread(FAR struct mtd_dev_s *dev,
|
|
|
|
off_t startblock,
|
2012-10-06 16:50:37 +02:00
|
|
|
size_t nblocks, FAR uint8_t *buf);
|
2017-08-04 16:49:07 +02:00
|
|
|
#ifdef CONFIG_RAMTRON_CHUNKING
|
2021-01-27 16:48:40 +01:00
|
|
|
static ssize_t ramtron_bwrite_nonchunked(FAR struct mtd_dev_s *dev,
|
|
|
|
off_t startblock,
|
|
|
|
size_t nblocks,
|
|
|
|
FAR const uint8_t *buffer);
|
|
|
|
static ssize_t ramtron_bwrite_chunked(FAR struct mtd_dev_s *dev,
|
|
|
|
off_t startblock,
|
|
|
|
size_t nblocks,
|
|
|
|
FAR const uint8_t *buf);
|
2017-08-04 16:49:07 +02:00
|
|
|
#endif
|
2021-01-27 16:48:40 +01:00
|
|
|
static ssize_t ramtron_bwrite(FAR struct mtd_dev_s *dev,
|
|
|
|
off_t startblock,
|
|
|
|
size_t nblocks,
|
|
|
|
FAR const uint8_t *buf);
|
|
|
|
static ssize_t ramtron_read(FAR struct mtd_dev_s *dev,
|
|
|
|
off_t offset,
|
|
|
|
size_t nbytes,
|
2012-10-06 16:50:37 +02:00
|
|
|
FAR uint8_t *buffer);
|
2021-01-27 16:48:40 +01:00
|
|
|
static int ramtron_ioctl(FAR struct mtd_dev_s *dev,
|
|
|
|
int cmd,
|
|
|
|
unsigned long arg);
|
2011-12-17 21:07:22 +01:00
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
/****************************************************************************
|
2011-12-17 21:07:22 +01:00
|
|
|
* Private Functions
|
2021-01-27 16:48:40 +01:00
|
|
|
****************************************************************************/
|
2011-12-17 21:07:22 +01:00
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
/****************************************************************************
|
2011-12-17 21:07:22 +01:00
|
|
|
* Name: ramtron_lock
|
2021-01-27 16:48:40 +01:00
|
|
|
****************************************************************************/
|
2011-12-17 21:07:22 +01:00
|
|
|
|
2014-12-26 14:59:09 +01:00
|
|
|
static void ramtron_lock(FAR struct ramtron_dev_s *priv)
|
2011-12-17 21:07:22 +01:00
|
|
|
{
|
2014-12-26 14:59:09 +01:00
|
|
|
FAR struct spi_dev_s *dev = priv->dev;
|
|
|
|
|
2014-05-13 02:43:06 +02: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
|
2011-12-17 21:07:22 +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.
|
2011-12-17 21:07:22 +01:00
|
|
|
*/
|
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
SPI_LOCK(dev, true);
|
2011-12-17 21:07:22 +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.
|
2011-12-17 21:07:22 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
SPI_SETMODE(dev, SPIDEV_MODE3);
|
|
|
|
SPI_SETBITS(dev, 8);
|
2020-01-02 17:49:34 +01:00
|
|
|
SPI_HWFEATURES(dev, 0);
|
|
|
|
SPI_SETFREQUENCY(dev, priv->speed);
|
2011-12-17 21:07:22 +01:00
|
|
|
}
|
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
/****************************************************************************
|
2011-12-17 21:07:22 +01:00
|
|
|
* Name: ramtron_unlock
|
2021-01-27 16:48:40 +01:00
|
|
|
****************************************************************************/
|
2011-12-17 21:07:22 +01:00
|
|
|
|
|
|
|
static inline void ramtron_unlock(FAR struct spi_dev_s *dev)
|
|
|
|
{
|
2020-01-02 17:49:34 +01:00
|
|
|
SPI_LOCK(dev, false);
|
2011-12-17 21:07:22 +01:00
|
|
|
}
|
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
/****************************************************************************
|
2011-12-17 21:07:22 +01:00
|
|
|
* Name: ramtron_readid
|
2021-01-27 16:48:40 +01:00
|
|
|
****************************************************************************/
|
2011-12-17 21:07:22 +01:00
|
|
|
|
|
|
|
static inline int ramtron_readid(struct ramtron_dev_s *priv)
|
|
|
|
{
|
2014-03-27 00:04:13 +01:00
|
|
|
uint16_t manufacturer;
|
|
|
|
uint16_t memory;
|
|
|
|
uint16_t capacity;
|
|
|
|
uint16_t part;
|
2011-12-17 21:07:22 +01:00
|
|
|
int i;
|
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
finfo("priv: %p\n", priv);
|
2011-12-17 21:07:22 +01:00
|
|
|
|
|
|
|
/* Lock the SPI bus, configure the bus, and select this FLASH part. */
|
|
|
|
|
2014-12-26 14:59:09 +01:00
|
|
|
ramtron_lock(priv);
|
2017-04-29 20:26:52 +02:00
|
|
|
SPI_SELECT(priv->dev, SPIDEV_FLASH(0), true);
|
2011-12-17 21:07:22 +01:00
|
|
|
|
2014-05-13 05:42:06 +02:00
|
|
|
/* Send the "Read ID (RDID)" command */
|
2011-12-17 21:07:22 +01:00
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
SPI_SEND(priv->dev, RAMTRON_RDID);
|
2014-05-13 05:42:06 +02:00
|
|
|
|
|
|
|
/* Read the first six manufacturer ID bytes. */
|
|
|
|
|
2012-10-06 16:50:37 +02:00
|
|
|
for (i = 0; i < 6; i++)
|
|
|
|
{
|
2014-05-13 05:42:06 +02:00
|
|
|
/* Read the next manufacturer byte */
|
|
|
|
|
2012-10-06 16:50:37 +02:00
|
|
|
manufacturer = SPI_SEND(priv->dev, RAMTRON_DUMMY);
|
2014-05-13 02:43:06 +02:00
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
/* Fujitsu parts such as MB85RS1MT only have 1-byte for the
|
|
|
|
* manufacturer ID. The manufacturer code is "0x4".
|
2014-05-13 02:43:06 +02:00
|
|
|
*/
|
|
|
|
|
2014-05-13 05:42:06 +02:00
|
|
|
if (i == 0 && manufacturer == 0x04)
|
2014-05-13 02:43:06 +02:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2012-10-06 16:50:37 +02:00
|
|
|
}
|
|
|
|
|
2014-05-13 18:38:46 +02:00
|
|
|
memory = SPI_SEND(priv->dev, RAMTRON_DUMMY);
|
|
|
|
capacity = SPI_SEND(priv->dev, RAMTRON_DUMMY); /* fram.id1 */
|
|
|
|
part = SPI_SEND(priv->dev, RAMTRON_DUMMY); /* fram.id2 */
|
2011-12-17 21:07:22 +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);
|
2011-12-17 21:07:22 +01:00
|
|
|
ramtron_unlock(priv->dev);
|
2014-04-13 22:32:20 +02:00
|
|
|
|
2012-10-06 16:50:37 +02:00
|
|
|
/* Select part from the part list */
|
2014-04-13 22:32:20 +02:00
|
|
|
|
2014-05-13 02:43:06 +02:00
|
|
|
for (priv->part = g_ramtron_parts;
|
|
|
|
priv->part->name != NULL &&
|
|
|
|
!(priv->part->id1 == capacity && priv->part->id2 == part);
|
|
|
|
priv->part++);
|
2014-04-13 22:32:20 +02:00
|
|
|
|
2017-08-04 16:49:07 +02:00
|
|
|
if (priv->part->name != NULL)
|
2012-10-06 16:50:37 +02:00
|
|
|
{
|
2014-03-30 15:58:58 +02:00
|
|
|
UNUSED(manufacturer); /* Eliminate warnings when debug is off */
|
|
|
|
UNUSED(memory); /* Eliminate warnings when debug is off */
|
2014-03-27 00:04:13 +01:00
|
|
|
|
2021-04-20 17:16:19 +02:00
|
|
|
finfo("RAMTRON %s of size %" PRIu32 " bytes (mf:%02" PRIx16 " mem:%02"
|
|
|
|
PRIx16 " cap:%02" PRIx16 " part:%02" PRIx16 ")\n",
|
|
|
|
priv->part->name, priv->part->size, manufacturer, memory,
|
|
|
|
capacity, part);
|
2012-10-06 16:50:37 +02:00
|
|
|
|
|
|
|
priv->sectorshift = RAMTRON_EMULATE_SECTOR_SHIFT;
|
2021-01-27 16:48:40 +01:00
|
|
|
priv->nsectors = priv->part->size /
|
|
|
|
(1 << RAMTRON_EMULATE_SECTOR_SHIFT);
|
2012-10-06 16:50:37 +02:00
|
|
|
priv->pageshift = RAMTRON_EMULATE_PAGE_SHIFT;
|
2021-01-27 16:48:40 +01:00
|
|
|
priv->npages = priv->part->size /
|
|
|
|
(1 << RAMTRON_EMULATE_PAGE_SHIFT);
|
2014-12-26 14:59:09 +01:00
|
|
|
priv->speed = priv->part->speed;
|
2012-10-06 16:50:37 +02:00
|
|
|
return OK;
|
|
|
|
}
|
2014-04-13 22:32:20 +02:00
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
finfo("RAMTRON device not found\n");
|
2011-12-17 21:07:22 +01:00
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
/****************************************************************************
|
2011-12-17 21:07:22 +01:00
|
|
|
* Name: ramtron_writeenable
|
2021-01-27 16:48:40 +01:00
|
|
|
****************************************************************************/
|
2011-12-17 21:07:22 +01:00
|
|
|
|
|
|
|
static void ramtron_writeenable(struct ramtron_dev_s *priv)
|
|
|
|
{
|
|
|
|
/* Select this FLASH part */
|
|
|
|
|
2017-04-29 20:26:52 +02:00
|
|
|
SPI_SELECT(priv->dev, SPIDEV_FLASH(0), true);
|
2011-12-17 21:07:22 +01:00
|
|
|
|
|
|
|
/* Send "Write Enable (WREN)" command */
|
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
SPI_SEND(priv->dev, RAMTRON_WREN);
|
2014-04-13 22:32:20 +02:00
|
|
|
|
2011-12-17 21:07:22 +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("Enabled\n");
|
2011-12-17 21:07:22 +01:00
|
|
|
}
|
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
/****************************************************************************
|
2011-12-17 21:07:22 +01:00
|
|
|
* Name: ramtron_sendaddr
|
2021-01-27 16:48:40 +01:00
|
|
|
****************************************************************************/
|
2011-12-17 21:07:22 +01:00
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
static inline void ramtron_sendaddr(const struct ramtron_dev_s *priv,
|
|
|
|
uint32_t addr)
|
2011-12-17 21:07:22 +01:00
|
|
|
{
|
|
|
|
DEBUGASSERT(priv->part->addr_len == 3 || priv->part->addr_len == 2);
|
2014-04-13 22:32:20 +02:00
|
|
|
|
2011-12-17 21:07:22 +01:00
|
|
|
if (priv->part->addr_len == 3)
|
2012-10-06 16:50:37 +02:00
|
|
|
{
|
2020-01-02 17:49:34 +01:00
|
|
|
SPI_SEND(priv->dev, (addr >> 16) & 0xff);
|
2012-10-06 16:50:37 +02:00
|
|
|
}
|
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
SPI_SEND(priv->dev, (addr >> 8) & 0xff);
|
|
|
|
SPI_SEND(priv->dev, addr & 0xff);
|
2011-12-17 21:07:22 +01:00
|
|
|
}
|
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
/****************************************************************************
|
2011-12-17 21:07:22 +01:00
|
|
|
* Name: ramtron_pagewrite
|
2021-01-27 16:48:40 +01:00
|
|
|
****************************************************************************/
|
2011-12-17 21:07:22 +01:00
|
|
|
|
2017-06-12 17:51:42 +02:00
|
|
|
static inline int ramtron_pagewrite(struct ramtron_dev_s *priv,
|
2017-08-04 16:12:59 +02:00
|
|
|
FAR const uint8_t *buffer, off_t page,
|
|
|
|
size_t pagesize)
|
2011-12-17 21:07:22 +01:00
|
|
|
{
|
2017-08-04 16:12:59 +02:00
|
|
|
off_t offset = page * pagesize;
|
2011-12-17 21:07:22 +01:00
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
finfo("page: %08lx offset: %08lx\n", (long)page, (long)offset);
|
2011-12-17 21:07:22 +01:00
|
|
|
|
|
|
|
/* Enable the write access to the FLASH */
|
|
|
|
|
|
|
|
ramtron_writeenable(priv);
|
2014-04-13 22:32:20 +02:00
|
|
|
|
2011-12-17 21:07:22 +01:00
|
|
|
/* Select this FLASH part */
|
|
|
|
|
2017-04-29 20:26:52 +02:00
|
|
|
SPI_SELECT(priv->dev, SPIDEV_FLASH(0), true);
|
2011-12-17 21:07:22 +01:00
|
|
|
|
|
|
|
/* Send "Page Program (PP)" command */
|
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
SPI_SEND(priv->dev, RAMTRON_WRITE);
|
2011-12-17 21:07:22 +01:00
|
|
|
|
|
|
|
/* Send the page offset high byte first. */
|
|
|
|
|
|
|
|
ramtron_sendaddr(priv, offset);
|
|
|
|
|
|
|
|
/* Then write the specified number of bytes */
|
|
|
|
|
2017-08-04 16:12:59 +02:00
|
|
|
SPI_SNDBLOCK(priv->dev, buffer, pagesize);
|
2014-04-13 22:32:20 +02:00
|
|
|
|
2011-12-17 21:07:22 +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");
|
2014-12-26 14:59:09 +01:00
|
|
|
|
|
|
|
return OK;
|
2011-12-17 21:07:22 +01:00
|
|
|
}
|
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
/****************************************************************************
|
2011-12-17 21:07:22 +01:00
|
|
|
* Name: ramtron_erase
|
2021-01-27 16:48:40 +01:00
|
|
|
****************************************************************************/
|
2011-12-17 21:07:22 +01:00
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
static int ramtron_erase(FAR struct mtd_dev_s *dev,
|
|
|
|
off_t startblock,
|
|
|
|
size_t nblocks)
|
2011-12-17 21:07:22 +01:00
|
|
|
{
|
2021-01-27 16:48:40 +01:00
|
|
|
finfo("startblock: %08lx nblocks: %d\n",
|
|
|
|
(unsigned long)startblock,
|
|
|
|
(int)nblocks);
|
2016-06-11 19:59:51 +02:00
|
|
|
finfo("On RAMTRON devices erasing makes no sense, returning as OK\n");
|
2011-12-17 21:07:22 +01:00
|
|
|
return (int)nblocks;
|
|
|
|
}
|
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
/****************************************************************************
|
2011-12-17 21:07:22 +01:00
|
|
|
* Name: ramtron_bread
|
2021-01-27 16:48:40 +01:00
|
|
|
****************************************************************************/
|
2011-12-17 21:07:22 +01:00
|
|
|
|
2014-05-13 02:43:06 +02:00
|
|
|
static ssize_t ramtron_bread(FAR struct mtd_dev_s *dev, off_t startblock,
|
|
|
|
size_t nblocks, FAR uint8_t *buffer)
|
2011-12-17 21:07:22 +01:00
|
|
|
{
|
|
|
|
FAR struct ramtron_dev_s *priv = (FAR struct ramtron_dev_s *)dev;
|
|
|
|
ssize_t nbytes;
|
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
finfo("startblock: %08lx nblocks: %d\n", (long)startblock, (int)nblocks);
|
2011-12-17 21:07:22 +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
|
|
|
|
*/
|
2011-12-17 21:07:22 +01:00
|
|
|
|
2014-05-13 02:43:06 +02:00
|
|
|
nbytes = ramtron_read(dev, startblock << priv->pageshift,
|
|
|
|
nblocks << priv->pageshift, buffer);
|
2011-12-17 21:07:22 +01:00
|
|
|
if (nbytes > 0)
|
|
|
|
{
|
2021-01-27 16:48:40 +01:00
|
|
|
return nbytes >> priv->pageshift;
|
2011-12-17 21:07:22 +01:00
|
|
|
}
|
2012-10-06 16:50:37 +02:00
|
|
|
|
2011-12-17 21:07:22 +01:00
|
|
|
return (int)nbytes;
|
|
|
|
}
|
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
/****************************************************************************
|
2017-08-04 16:49:07 +02:00
|
|
|
* Name: ramtron_bwrite/ramtron_bwrite_nonchunked
|
2021-01-27 16:48:40 +01:00
|
|
|
****************************************************************************/
|
2011-12-17 21:07:22 +01:00
|
|
|
|
2017-08-04 16:49:07 +02:00
|
|
|
#ifdef CONFIG_RAMTRON_CHUNKING
|
2021-01-27 16:48:40 +01:00
|
|
|
static ssize_t ramtron_bwrite_nonchunked(FAR struct mtd_dev_s *dev,
|
|
|
|
off_t startblock,
|
|
|
|
size_t nblocks,
|
|
|
|
FAR const uint8_t *buffer)
|
2017-08-04 16:49:07 +02:00
|
|
|
#else
|
2021-01-27 16:48:40 +01:00
|
|
|
static ssize_t ramtron_bwrite(FAR struct mtd_dev_s *dev,
|
|
|
|
off_t startblock,
|
|
|
|
size_t nblocks,
|
|
|
|
FAR const uint8_t *buffer)
|
2017-08-04 16:49:07 +02:00
|
|
|
#endif
|
2011-12-17 21:07:22 +01:00
|
|
|
{
|
|
|
|
FAR struct ramtron_dev_s *priv = (FAR struct ramtron_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);
|
2017-08-04 16:49:07 +02:00
|
|
|
DEBUGASSERT(priv != NULL && buffer != NULL);
|
2011-12-17 21:07:22 +01:00
|
|
|
|
|
|
|
/* Lock the SPI bus and write each page to FLASH */
|
|
|
|
|
2014-12-26 14:59:09 +01:00
|
|
|
ramtron_lock(priv);
|
2011-12-17 21:07:22 +01:00
|
|
|
while (blocksleft-- > 0)
|
|
|
|
{
|
2017-08-04 16:12:59 +02:00
|
|
|
if (ramtron_pagewrite(priv, buffer, startblock, 1 << priv->pageshift))
|
2014-12-26 14:59:09 +01:00
|
|
|
{
|
|
|
|
nblocks = 0;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2011-12-17 21:07:22 +01:00
|
|
|
startblock++;
|
2014-05-13 02:43:06 +02:00
|
|
|
}
|
2017-08-04 16:49:07 +02:00
|
|
|
|
2012-10-06 16:50:37 +02:00
|
|
|
ramtron_unlock(priv->dev);
|
2011-12-17 21:07:22 +01:00
|
|
|
return nblocks;
|
|
|
|
}
|
2017-08-04 16:12:59 +02:00
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
/****************************************************************************
|
2017-08-04 16:49:07 +02:00
|
|
|
* Name: ramtron_bwrite_chunked
|
2021-01-27 16:48:40 +01:00
|
|
|
****************************************************************************/
|
2017-08-04 16:12:59 +02:00
|
|
|
|
2017-08-04 16:49:07 +02:00
|
|
|
#ifdef CONFIG_RAMTRON_CHUNKING
|
2021-01-27 16:48:40 +01:00
|
|
|
static ssize_t ramtron_bwrite_chunked(FAR struct mtd_dev_s *dev,
|
|
|
|
off_t startblock,
|
|
|
|
size_t nblocks,
|
|
|
|
FAR const uint8_t *buffer)
|
2017-08-04 16:12:59 +02:00
|
|
|
{
|
|
|
|
FAR struct ramtron_dev_s *priv = (FAR struct ramtron_dev_s *)dev;
|
2017-08-04 16:49:07 +02:00
|
|
|
FAR const struct ramtron_parts_s *part;
|
2017-08-04 16:12:59 +02:00
|
|
|
size_t blocksleft = nblocks;
|
2021-01-27 16:48:40 +01:00
|
|
|
uint32_t p;
|
|
|
|
uint32_t writesplits;
|
2017-08-04 16:12:59 +02:00
|
|
|
off_t newstartblock;
|
|
|
|
|
|
|
|
finfo("startblock: %08lx nblocks: %d\n", (long)startblock, (int)nblocks);
|
|
|
|
|
2017-08-04 16:49:07 +02:00
|
|
|
DEBUGASSERT(priv != NULL && priv->part != NULL && buffer != NULL);
|
|
|
|
part = priv->part;
|
|
|
|
|
|
|
|
writesplits = (1 << priv->pageshift) / part->chunksize;
|
2017-08-04 16:12:59 +02:00
|
|
|
newstartblock = startblock * writesplits;
|
|
|
|
|
|
|
|
/* Lock the SPI bus and write each page to FLASH */
|
|
|
|
|
|
|
|
ramtron_lock(priv);
|
|
|
|
while (blocksleft-- > 0)
|
|
|
|
{
|
2017-08-04 16:49:07 +02:00
|
|
|
/* Split writes in chunksize chunks */
|
2017-08-04 16:12:59 +02:00
|
|
|
|
|
|
|
for (p = 0; p < writesplits; p++)
|
2021-01-27 16:48:40 +01:00
|
|
|
{
|
|
|
|
if (ramtron_pagewrite(priv,
|
|
|
|
buffer + p * part->chunksize,
|
|
|
|
newstartblock,
|
|
|
|
part->chunksize))
|
|
|
|
{
|
|
|
|
nblocks = 0;
|
|
|
|
goto out;
|
|
|
|
}
|
|
|
|
|
|
|
|
newstartblock++;
|
|
|
|
}
|
2017-08-04 16:12:59 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
out:
|
|
|
|
ramtron_unlock(priv->dev);
|
|
|
|
return nblocks;
|
|
|
|
}
|
|
|
|
#endif
|
2011-12-17 21:07:22 +01:00
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
/****************************************************************************
|
2017-08-04 16:49:07 +02:00
|
|
|
* Name: ramtron_bwrite
|
2021-01-27 16:48:40 +01:00
|
|
|
****************************************************************************/
|
2017-08-04 16:49:07 +02:00
|
|
|
|
|
|
|
#ifdef CONFIG_RAMTRON_CHUNKING
|
|
|
|
static ssize_t ramtron_bwrite(FAR struct mtd_dev_s *dev, off_t startblock,
|
|
|
|
size_t nblocks, FAR const uint8_t *buffer)
|
|
|
|
{
|
|
|
|
FAR struct ramtron_dev_s *priv = (FAR struct ramtron_dev_s *)dev;
|
|
|
|
FAR const struct ramtron_parts_s *part;
|
|
|
|
|
|
|
|
DEBUGASSERT(priv != NULL && priv->part != NULL && buffer != NULL);
|
|
|
|
part = priv->part;
|
|
|
|
|
|
|
|
/* Handle parts that require chunked output differently */
|
|
|
|
|
|
|
|
if (part->chunked)
|
|
|
|
{
|
|
|
|
return ramtron_bwrite_chunked(dev, startblock, nblocks, buffer);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return ramtron_bwrite_nonchunked(dev, startblock, nblocks, buffer);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
/****************************************************************************
|
2011-12-17 21:07:22 +01:00
|
|
|
* Name: ramtron_read
|
2021-01-27 16:48:40 +01:00
|
|
|
****************************************************************************/
|
2011-12-17 21:07:22 +01:00
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
static ssize_t ramtron_read(FAR struct mtd_dev_s *dev,
|
|
|
|
off_t offset,
|
|
|
|
size_t nbytes,
|
2012-10-06 16:50:37 +02:00
|
|
|
FAR uint8_t *buffer)
|
2011-12-17 21:07:22 +01:00
|
|
|
{
|
|
|
|
FAR struct ramtron_dev_s *priv = (FAR struct ramtron_dev_s *)dev;
|
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
finfo("offset: %08lx nbytes: %d\n", (long)offset, (int)nbytes);
|
2011-12-17 21:07:22 +01:00
|
|
|
|
2017-06-12 17:51:42 +02:00
|
|
|
/* Lock the SPI bus NOW because the ramtron_waitwritecomplete call must be
|
|
|
|
* executed with the bus locked.
|
|
|
|
*/
|
|
|
|
|
|
|
|
ramtron_lock(priv);
|
|
|
|
|
|
|
|
/* Select this FLASH part */
|
2011-12-17 21:07:22 +01:00
|
|
|
|
2017-04-29 20:26:52 +02:00
|
|
|
SPI_SELECT(priv->dev, SPIDEV_FLASH(0), true);
|
2011-12-17 21:07:22 +01:00
|
|
|
|
|
|
|
/* Send "Read from Memory " instruction */
|
|
|
|
|
2020-01-02 17:49:34 +01:00
|
|
|
SPI_SEND(priv->dev, RAMTRON_READ);
|
2011-12-17 21:07:22 +01:00
|
|
|
|
|
|
|
/* Send the page offset high byte first. */
|
|
|
|
|
|
|
|
ramtron_sendaddr(priv, offset);
|
|
|
|
|
|
|
|
/* 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);
|
2011-12-17 21:07:22 +01:00
|
|
|
ramtron_unlock(priv->dev);
|
2014-05-13 02:43:06 +02:00
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
finfo("return nbytes: %d\n", (int)nbytes);
|
2011-12-17 21:07:22 +01:00
|
|
|
return nbytes;
|
|
|
|
}
|
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
/****************************************************************************
|
2011-12-17 21:07:22 +01:00
|
|
|
* Name: ramtron_ioctl
|
2021-01-27 16:48:40 +01:00
|
|
|
****************************************************************************/
|
2011-12-17 21:07:22 +01:00
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
static int ramtron_ioctl(FAR struct mtd_dev_s *dev,
|
|
|
|
int cmd,
|
|
|
|
unsigned long arg)
|
2011-12-17 21:07:22 +01:00
|
|
|
{
|
|
|
|
FAR struct ramtron_dev_s *priv = (FAR struct ramtron_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);
|
2011-12-17 21:07:22 +01: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);
|
2011-12-17 21:07:22 +01:00
|
|
|
if (geo)
|
|
|
|
{
|
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.
|
2011-12-17 21:07:22 +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.
|
2011-12-17 21:07:22 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
geo->blocksize = (1 << priv->pageshift);
|
|
|
|
geo->erasesize = (1 << priv->sectorshift);
|
|
|
|
geo->neraseblocks = priv->nsectors;
|
|
|
|
ret = OK;
|
|
|
|
|
2021-04-20 17:16:19 +02:00
|
|
|
finfo("blocksize: %ld erasesize: %ld neraseblocks: %ld\n",
|
2011-12-17 21:07:22 +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;
|
|
|
|
|
2011-12-17 21:07:22 +01:00
|
|
|
case MTDIOC_BULKERASE:
|
2021-01-27 16:48:40 +01:00
|
|
|
finfo("BULDERASE: Makes no sense in ramtron.\n");
|
|
|
|
finfo("BULDERASE: Let's confirm operation as OK\n");
|
2011-12-17 21:07:22 +01:00
|
|
|
ret = OK;
|
|
|
|
break;
|
2014-04-13 22:32:20 +02:00
|
|
|
|
2014-12-26 14:59:09 +01:00
|
|
|
#ifdef CONFIG_RAMTRON_SETSPEED
|
|
|
|
case MTDIOC_SETSPEED:
|
|
|
|
{
|
|
|
|
if (arg > 0 && arg <= RAMTRON_INIT_CLK_MAX)
|
|
|
|
{
|
|
|
|
priv->speed = arg;
|
2016-06-11 19:59:51 +02:00
|
|
|
finfo("set bus speed to %lu\n", priv->speed);
|
2014-12-26 14:59:09 +01:00
|
|
|
ret = OK;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
2011-12-17 21:07:22 +01:00
|
|
|
default:
|
|
|
|
ret = -ENOTTY; /* Bad command */
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
finfo("return %d\n", ret);
|
2011-12-17 21:07:22 +01:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
/****************************************************************************
|
2011-12-17 21:07:22 +01:00
|
|
|
* Public Functions
|
2021-01-27 16:48:40 +01:00
|
|
|
****************************************************************************/
|
2011-12-17 21:07:22 +01:00
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
/****************************************************************************
|
2011-12-17 21:07:22 +01:00
|
|
|
* Name: ramtron_initialize
|
|
|
|
*
|
|
|
|
* Description:
|
2021-01-27 16:48:40 +01:00
|
|
|
* Create an initialize MTD device instance.
|
|
|
|
* MTD devices are not registered 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).
|
2011-12-17 21:07:22 +01:00
|
|
|
*
|
2021-01-27 16:48:40 +01:00
|
|
|
****************************************************************************/
|
2011-12-17 21:07:22 +01:00
|
|
|
|
|
|
|
FAR struct mtd_dev_s *ramtron_initialize(FAR struct spi_dev_s *dev)
|
|
|
|
{
|
|
|
|
FAR struct ramtron_dev_s *priv;
|
|
|
|
|
2016-06-11 19:59:51 +02:00
|
|
|
finfo("dev: %p\n", dev);
|
2011-12-17 21:07:22 +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.
|
2011-12-17 21:07:22 +01:00
|
|
|
*/
|
|
|
|
|
2021-01-27 16:48:40 +01:00
|
|
|
priv = (FAR struct ramtron_dev_s *)
|
|
|
|
kmm_zalloc(sizeof(struct ramtron_dev_s));
|
2011-12-17 21:07:22 +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
|
|
|
*/
|
2011-12-17 21:07:22 +01:00
|
|
|
|
|
|
|
priv->mtd.erase = ramtron_erase;
|
|
|
|
priv->mtd.bread = ramtron_bread;
|
|
|
|
priv->mtd.bwrite = ramtron_bwrite;
|
|
|
|
priv->mtd.read = ramtron_read;
|
|
|
|
priv->mtd.ioctl = ramtron_ioctl;
|
2018-11-08 16:46:11 +01:00
|
|
|
priv->mtd.name = "ramtron";
|
2011-12-17 21:07:22 +01:00
|
|
|
priv->dev = dev;
|
|
|
|
|
|
|
|
/* Deselect the FLASH */
|
|
|
|
|
2017-04-29 20:26:52 +02:00
|
|
|
SPI_SELECT(dev, SPIDEV_FLASH(0), false);
|
2011-12-17 21:07:22 +01:00
|
|
|
|
|
|
|
/* Identify the FLASH chip and get its capacity */
|
|
|
|
|
|
|
|
if (ramtron_readid(priv) != OK)
|
|
|
|
{
|
2021-01-27 16:48:40 +01:00
|
|
|
/* Unrecognized! Discard all of that work we just did and
|
|
|
|
* return NULL
|
|
|
|
*/
|
2012-10-06 16:50:37 +02:00
|
|
|
|
2014-09-01 01:04:02 +02:00
|
|
|
kmm_free(priv);
|
2016-07-01 01:49:53 +02:00
|
|
|
return NULL;
|
2011-12-17 21:07:22 +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);
|
2011-12-17 21:07:22 +01:00
|
|
|
return (FAR struct mtd_dev_s *)priv;
|
|
|
|
}
|