Creation of Cybook 2416 (actually Gen4) repository
This commit is contained in:
132
include/linux/mtd/bbm.h
Normal file
132
include/linux/mtd/bbm.h
Normal file
@@ -0,0 +1,132 @@
|
||||
/*
|
||||
* linux/include/linux/mtd/bbm.h
|
||||
*
|
||||
* NAND family Bad Block Management (BBM) header file
|
||||
* - Bad Block Table (BBT) implementation
|
||||
*
|
||||
* Copyright (c) 2005 Samsung Electronics
|
||||
* Kyungmin Park <kyungmin.park@samsung.com>
|
||||
*
|
||||
* Copyright (c) 2000-2005
|
||||
* Thomas Gleixner <tglx@linuxtronix.de>
|
||||
*
|
||||
*/
|
||||
#ifndef __LINUX_MTD_BBM_H
|
||||
#define __LINUX_MTD_BBM_H
|
||||
|
||||
/* The maximum number of NAND chips in an array */
|
||||
#define NAND_MAX_CHIPS 8
|
||||
|
||||
/**
|
||||
* struct nand_bbt_descr - bad block table descriptor
|
||||
* @options: options for this descriptor
|
||||
* @pages: the page(s) where we find the bbt, used with
|
||||
* option BBT_ABSPAGE when bbt is searched,
|
||||
* then we store the found bbts pages here.
|
||||
* Its an array and supports up to 8 chips now
|
||||
* @offs: offset of the pattern in the oob area of the page
|
||||
* @veroffs: offset of the bbt version counter in the oob area of the page
|
||||
* @version: version read from the bbt page during scan
|
||||
* @len: length of the pattern, if 0 no pattern check is performed
|
||||
* @maxblocks: maximum number of blocks to search for a bbt. This
|
||||
* number of blocks is reserved at the end of the device
|
||||
* where the tables are written.
|
||||
* @reserved_block_code: if non-0, this pattern denotes a reserved
|
||||
* (rather than bad) block in the stored bbt
|
||||
* @pattern: pattern to identify bad block table or factory marked
|
||||
* good / bad blocks, can be NULL, if len = 0
|
||||
*
|
||||
* Descriptor for the bad block table marker and the descriptor for the
|
||||
* pattern which identifies good and bad blocks. The assumption is made
|
||||
* that the pattern and the version count are always located in the oob area
|
||||
* of the first block.
|
||||
*/
|
||||
struct nand_bbt_descr {
|
||||
int options;
|
||||
int pages[NAND_MAX_CHIPS];
|
||||
int offs;
|
||||
int veroffs;
|
||||
uint8_t version[NAND_MAX_CHIPS];
|
||||
int len;
|
||||
int maxblocks;
|
||||
int reserved_block_code;
|
||||
uint8_t *pattern;
|
||||
};
|
||||
|
||||
/* Options for the bad block table descriptors */
|
||||
|
||||
/* The number of bits used per block in the bbt on the device */
|
||||
#define NAND_BBT_NRBITS_MSK 0x0000000F
|
||||
#define NAND_BBT_1BIT 0x00000001
|
||||
#define NAND_BBT_2BIT 0x00000002
|
||||
#define NAND_BBT_4BIT 0x00000004
|
||||
#define NAND_BBT_8BIT 0x00000008
|
||||
/* The bad block table is in the last good block of the device */
|
||||
#define NAND_BBT_LASTBLOCK 0x00000010
|
||||
/* The bbt is at the given page, else we must scan for the bbt */
|
||||
#define NAND_BBT_ABSPAGE 0x00000020
|
||||
/* The bbt is at the given page, else we must scan for the bbt */
|
||||
#define NAND_BBT_SEARCH 0x00000040
|
||||
/* bbt is stored per chip on multichip devices */
|
||||
#define NAND_BBT_PERCHIP 0x00000080
|
||||
/* bbt has a version counter at offset veroffs */
|
||||
#define NAND_BBT_VERSION 0x00000100
|
||||
/* Create a bbt if none axists */
|
||||
#define NAND_BBT_CREATE 0x00000200
|
||||
/* Search good / bad pattern through all pages of a block */
|
||||
#define NAND_BBT_SCANALLPAGES 0x00000400
|
||||
/* Scan block empty during good / bad block scan */
|
||||
#define NAND_BBT_SCANEMPTY 0x00000800
|
||||
/* Write bbt if neccecary */
|
||||
#define NAND_BBT_WRITE 0x00001000
|
||||
/* Read and write back block contents when writing bbt */
|
||||
#define NAND_BBT_SAVECONTENT 0x00002000
|
||||
/* Search good / bad pattern on the first and the second page */
|
||||
#define NAND_BBT_SCAN2NDPAGE 0x00004000
|
||||
|
||||
/* The maximum number of blocks to scan for a bbt */
|
||||
#define NAND_BBT_SCAN_MAXBLOCKS 4
|
||||
|
||||
/*
|
||||
* Constants for oob configuration
|
||||
*/
|
||||
#define ONENAND_BADBLOCK_POS 0
|
||||
|
||||
/*
|
||||
* Bad block scanning errors
|
||||
*/
|
||||
#define ONENAND_BBT_READ_ERROR 1
|
||||
#define ONENAND_BBT_READ_ECC_ERROR 2
|
||||
#define ONENAND_BBT_READ_FATAL_ERROR 4
|
||||
|
||||
/**
|
||||
* struct bbm_info - [GENERIC] Bad Block Table data structure
|
||||
* @bbt_erase_shift: [INTERN] number of address bits in a bbt entry
|
||||
* @badblockpos: [INTERN] position of the bad block marker in the oob area
|
||||
* @options: options for this descriptor
|
||||
* @bbt: [INTERN] bad block table pointer
|
||||
* @isbad_bbt: function to determine if a block is bad
|
||||
* @badblock_pattern: [REPLACEABLE] bad block scan pattern used for
|
||||
* initial bad block scan
|
||||
* @priv: [OPTIONAL] pointer to private bbm date
|
||||
*/
|
||||
struct bbm_info {
|
||||
int bbt_erase_shift;
|
||||
int badblockpos;
|
||||
int options;
|
||||
|
||||
uint8_t *bbt;
|
||||
|
||||
int (*isbad_bbt)(struct mtd_info *mtd, loff_t ofs, int allowbbt);
|
||||
|
||||
/* TODO Add more NAND specific fileds */
|
||||
struct nand_bbt_descr *badblock_pattern;
|
||||
|
||||
void *priv;
|
||||
};
|
||||
|
||||
/* OneNAND BBT interface */
|
||||
extern int onenand_scan_bbt(struct mtd_info *mtd, struct nand_bbt_descr *bd);
|
||||
extern int onenand_default_bbt(struct mtd_info *mtd);
|
||||
|
||||
#endif /* __LINUX_MTD_BBM_H */
|
||||
73
include/linux/mtd/blktrans.h
Normal file
73
include/linux/mtd/blktrans.h
Normal file
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* $Id: blktrans.h,v 1.1.1.1 2007/06/12 07:27:16 eyryu Exp $
|
||||
*
|
||||
* (C) 2003 David Woodhouse <dwmw2@infradead.org>
|
||||
*
|
||||
* Interface to Linux block layer for MTD 'translation layers'.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __MTD_TRANS_H__
|
||||
#define __MTD_TRANS_H__
|
||||
|
||||
#include <linux/mutex.h>
|
||||
|
||||
struct hd_geometry;
|
||||
struct mtd_info;
|
||||
struct mtd_blktrans_ops;
|
||||
struct file;
|
||||
struct inode;
|
||||
|
||||
struct mtd_blktrans_dev {
|
||||
struct mtd_blktrans_ops *tr;
|
||||
struct list_head list;
|
||||
struct mtd_info *mtd;
|
||||
struct mutex lock;
|
||||
int devnum;
|
||||
unsigned long size;
|
||||
int readonly;
|
||||
void *blkcore_priv; /* gendisk in 2.5, devfs_handle in 2.4 */
|
||||
};
|
||||
|
||||
struct blkcore_priv; /* Differs for 2.4 and 2.5 kernels; private */
|
||||
|
||||
struct mtd_blktrans_ops {
|
||||
char *name;
|
||||
int major;
|
||||
int part_bits;
|
||||
int blksize;
|
||||
int blkshift;
|
||||
|
||||
/* Access functions */
|
||||
int (*readsect)(struct mtd_blktrans_dev *dev,
|
||||
unsigned long block, char *buffer);
|
||||
int (*writesect)(struct mtd_blktrans_dev *dev,
|
||||
unsigned long block, char *buffer);
|
||||
|
||||
/* Block layer ioctls */
|
||||
int (*getgeo)(struct mtd_blktrans_dev *dev, struct hd_geometry *geo);
|
||||
int (*flush)(struct mtd_blktrans_dev *dev);
|
||||
|
||||
/* Called with mtd_table_mutex held; no race with add/remove */
|
||||
int (*open)(struct mtd_blktrans_dev *dev);
|
||||
int (*release)(struct mtd_blktrans_dev *dev);
|
||||
|
||||
/* Called on {de,}registration and on subsequent addition/removal
|
||||
of devices, with mtd_table_mutex held. */
|
||||
void (*add_mtd)(struct mtd_blktrans_ops *tr, struct mtd_info *mtd);
|
||||
void (*remove_dev)(struct mtd_blktrans_dev *dev);
|
||||
|
||||
struct list_head devs;
|
||||
struct list_head list;
|
||||
struct module *owner;
|
||||
|
||||
struct mtd_blkcore_priv *blkcore_priv;
|
||||
};
|
||||
|
||||
extern int register_mtd_blktrans(struct mtd_blktrans_ops *tr);
|
||||
extern int deregister_mtd_blktrans(struct mtd_blktrans_ops *tr);
|
||||
extern int add_mtd_blktrans_dev(struct mtd_blktrans_dev *dev);
|
||||
extern int del_mtd_blktrans_dev(struct mtd_blktrans_dev *dev);
|
||||
|
||||
|
||||
#endif /* __MTD_TRANS_H__ */
|
||||
491
include/linux/mtd/cfi.h
Normal file
491
include/linux/mtd/cfi.h
Normal file
@@ -0,0 +1,491 @@
|
||||
|
||||
/* Common Flash Interface structures
|
||||
* See http://support.intel.com/design/flash/technote/index.htm
|
||||
* $Id: cfi.h,v 1.1.1.1 2007/06/12 07:27:16 eyryu Exp $
|
||||
*/
|
||||
|
||||
#ifndef __MTD_CFI_H__
|
||||
#define __MTD_CFI_H__
|
||||
|
||||
#include <linux/delay.h>
|
||||
#include <linux/types.h>
|
||||
#include <linux/interrupt.h>
|
||||
#include <linux/mtd/flashchip.h>
|
||||
#include <linux/mtd/map.h>
|
||||
#include <linux/mtd/cfi_endian.h>
|
||||
|
||||
#ifdef CONFIG_MTD_CFI_I1
|
||||
#define cfi_interleave(cfi) 1
|
||||
#define cfi_interleave_is_1(cfi) (cfi_interleave(cfi) == 1)
|
||||
#else
|
||||
#define cfi_interleave_is_1(cfi) (0)
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_MTD_CFI_I2
|
||||
# ifdef cfi_interleave
|
||||
# undef cfi_interleave
|
||||
# define cfi_interleave(cfi) ((cfi)->interleave)
|
||||
# else
|
||||
# define cfi_interleave(cfi) 2
|
||||
# endif
|
||||
#define cfi_interleave_is_2(cfi) (cfi_interleave(cfi) == 2)
|
||||
#else
|
||||
#define cfi_interleave_is_2(cfi) (0)
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_MTD_CFI_I4
|
||||
# ifdef cfi_interleave
|
||||
# undef cfi_interleave
|
||||
# define cfi_interleave(cfi) ((cfi)->interleave)
|
||||
# else
|
||||
# define cfi_interleave(cfi) 4
|
||||
# endif
|
||||
#define cfi_interleave_is_4(cfi) (cfi_interleave(cfi) == 4)
|
||||
#else
|
||||
#define cfi_interleave_is_4(cfi) (0)
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_MTD_CFI_I8
|
||||
# ifdef cfi_interleave
|
||||
# undef cfi_interleave
|
||||
# define cfi_interleave(cfi) ((cfi)->interleave)
|
||||
# else
|
||||
# define cfi_interleave(cfi) 8
|
||||
# endif
|
||||
#define cfi_interleave_is_8(cfi) (cfi_interleave(cfi) == 8)
|
||||
#else
|
||||
#define cfi_interleave_is_8(cfi) (0)
|
||||
#endif
|
||||
|
||||
static inline int cfi_interleave_supported(int i)
|
||||
{
|
||||
switch (i) {
|
||||
#ifdef CONFIG_MTD_CFI_I1
|
||||
case 1:
|
||||
#endif
|
||||
#ifdef CONFIG_MTD_CFI_I2
|
||||
case 2:
|
||||
#endif
|
||||
#ifdef CONFIG_MTD_CFI_I4
|
||||
case 4:
|
||||
#endif
|
||||
#ifdef CONFIG_MTD_CFI_I8
|
||||
case 8:
|
||||
#endif
|
||||
return 1;
|
||||
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* NB: these values must represents the number of bytes needed to meet the
|
||||
* device type (x8, x16, x32). Eg. a 32 bit device is 4 x 8 bytes.
|
||||
* These numbers are used in calculations.
|
||||
*/
|
||||
#define CFI_DEVICETYPE_X8 (8 / 8)
|
||||
#define CFI_DEVICETYPE_X16 (16 / 8)
|
||||
#define CFI_DEVICETYPE_X32 (32 / 8)
|
||||
#define CFI_DEVICETYPE_X64 (64 / 8)
|
||||
|
||||
/* NB: We keep these structures in memory in HOST byteorder, except
|
||||
* where individually noted.
|
||||
*/
|
||||
|
||||
/* Basic Query Structure */
|
||||
struct cfi_ident {
|
||||
uint8_t qry[3];
|
||||
uint16_t P_ID;
|
||||
uint16_t P_ADR;
|
||||
uint16_t A_ID;
|
||||
uint16_t A_ADR;
|
||||
uint8_t VccMin;
|
||||
uint8_t VccMax;
|
||||
uint8_t VppMin;
|
||||
uint8_t VppMax;
|
||||
uint8_t WordWriteTimeoutTyp;
|
||||
uint8_t BufWriteTimeoutTyp;
|
||||
uint8_t BlockEraseTimeoutTyp;
|
||||
uint8_t ChipEraseTimeoutTyp;
|
||||
uint8_t WordWriteTimeoutMax;
|
||||
uint8_t BufWriteTimeoutMax;
|
||||
uint8_t BlockEraseTimeoutMax;
|
||||
uint8_t ChipEraseTimeoutMax;
|
||||
uint8_t DevSize;
|
||||
uint16_t InterfaceDesc;
|
||||
uint16_t MaxBufWriteSize;
|
||||
uint8_t NumEraseRegions;
|
||||
uint32_t EraseRegionInfo[0]; /* Not host ordered */
|
||||
} __attribute__((packed));
|
||||
|
||||
/* Extended Query Structure for both PRI and ALT */
|
||||
|
||||
struct cfi_extquery {
|
||||
uint8_t pri[3];
|
||||
uint8_t MajorVersion;
|
||||
uint8_t MinorVersion;
|
||||
} __attribute__((packed));
|
||||
|
||||
/* Vendor-Specific PRI for Intel/Sharp Extended Command Set (0x0001) */
|
||||
|
||||
struct cfi_pri_intelext {
|
||||
uint8_t pri[3];
|
||||
uint8_t MajorVersion;
|
||||
uint8_t MinorVersion;
|
||||
uint32_t FeatureSupport; /* if bit 31 is set then an additional uint32_t feature
|
||||
block follows - FIXME - not currently supported */
|
||||
uint8_t SuspendCmdSupport;
|
||||
uint16_t BlkStatusRegMask;
|
||||
uint8_t VccOptimal;
|
||||
uint8_t VppOptimal;
|
||||
uint8_t NumProtectionFields;
|
||||
uint16_t ProtRegAddr;
|
||||
uint8_t FactProtRegSize;
|
||||
uint8_t UserProtRegSize;
|
||||
uint8_t extra[0];
|
||||
} __attribute__((packed));
|
||||
|
||||
struct cfi_intelext_otpinfo {
|
||||
uint32_t ProtRegAddr;
|
||||
uint16_t FactGroups;
|
||||
uint8_t FactProtRegSize;
|
||||
uint16_t UserGroups;
|
||||
uint8_t UserProtRegSize;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct cfi_intelext_blockinfo {
|
||||
uint16_t NumIdentBlocks;
|
||||
uint16_t BlockSize;
|
||||
uint16_t MinBlockEraseCycles;
|
||||
uint8_t BitsPerCell;
|
||||
uint8_t BlockCap;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct cfi_intelext_regioninfo {
|
||||
uint16_t NumIdentPartitions;
|
||||
uint8_t NumOpAllowed;
|
||||
uint8_t NumOpAllowedSimProgMode;
|
||||
uint8_t NumOpAllowedSimEraMode;
|
||||
uint8_t NumBlockTypes;
|
||||
struct cfi_intelext_blockinfo BlockTypes[1];
|
||||
} __attribute__((packed));
|
||||
|
||||
struct cfi_intelext_programming_regioninfo {
|
||||
uint8_t ProgRegShift;
|
||||
uint8_t Reserved1;
|
||||
uint8_t ControlValid;
|
||||
uint8_t Reserved2;
|
||||
uint8_t ControlInvalid;
|
||||
uint8_t Reserved3;
|
||||
} __attribute__((packed));
|
||||
|
||||
/* Vendor-Specific PRI for AMD/Fujitsu Extended Command Set (0x0002) */
|
||||
|
||||
struct cfi_pri_amdstd {
|
||||
uint8_t pri[3];
|
||||
uint8_t MajorVersion;
|
||||
uint8_t MinorVersion;
|
||||
uint8_t SiliconRevision; /* bits 1-0: Address Sensitive Unlock */
|
||||
uint8_t EraseSuspend;
|
||||
uint8_t BlkProt;
|
||||
uint8_t TmpBlkUnprotect;
|
||||
uint8_t BlkProtUnprot;
|
||||
uint8_t SimultaneousOps;
|
||||
uint8_t BurstMode;
|
||||
uint8_t PageMode;
|
||||
uint8_t VppMin;
|
||||
uint8_t VppMax;
|
||||
uint8_t TopBottom;
|
||||
} __attribute__((packed));
|
||||
|
||||
/* Vendor-Specific PRI for Atmel chips (command set 0x0002) */
|
||||
|
||||
struct cfi_pri_atmel {
|
||||
uint8_t pri[3];
|
||||
uint8_t MajorVersion;
|
||||
uint8_t MinorVersion;
|
||||
uint8_t Features;
|
||||
uint8_t BottomBoot;
|
||||
uint8_t BurstMode;
|
||||
uint8_t PageMode;
|
||||
} __attribute__((packed));
|
||||
|
||||
struct cfi_pri_query {
|
||||
uint8_t NumFields;
|
||||
uint32_t ProtField[1]; /* Not host ordered */
|
||||
} __attribute__((packed));
|
||||
|
||||
struct cfi_bri_query {
|
||||
uint8_t PageModeReadCap;
|
||||
uint8_t NumFields;
|
||||
uint32_t ConfField[1]; /* Not host ordered */
|
||||
} __attribute__((packed));
|
||||
|
||||
#define P_ID_NONE 0x0000
|
||||
#define P_ID_INTEL_EXT 0x0001
|
||||
#define P_ID_AMD_STD 0x0002
|
||||
#define P_ID_INTEL_STD 0x0003
|
||||
#define P_ID_AMD_EXT 0x0004
|
||||
#define P_ID_WINBOND 0x0006
|
||||
#define P_ID_ST_ADV 0x0020
|
||||
#define P_ID_MITSUBISHI_STD 0x0100
|
||||
#define P_ID_MITSUBISHI_EXT 0x0101
|
||||
#define P_ID_SST_PAGE 0x0102
|
||||
#define P_ID_INTEL_PERFORMANCE 0x0200
|
||||
#define P_ID_INTEL_DATA 0x0210
|
||||
#define P_ID_RESERVED 0xffff
|
||||
|
||||
|
||||
#define CFI_MODE_CFI 1
|
||||
#define CFI_MODE_JEDEC 0
|
||||
|
||||
struct cfi_private {
|
||||
uint16_t cmdset;
|
||||
void *cmdset_priv;
|
||||
int interleave;
|
||||
int device_type;
|
||||
int cfi_mode; /* Are we a JEDEC device pretending to be CFI? */
|
||||
int addr_unlock1;
|
||||
int addr_unlock2;
|
||||
struct mtd_info *(*cmdset_setup)(struct map_info *);
|
||||
struct cfi_ident *cfiq; /* For now only one. We insist that all devs
|
||||
must be of the same type. */
|
||||
int mfr, id;
|
||||
int numchips;
|
||||
unsigned long chipshift; /* Because they're of the same type */
|
||||
const char *im_name; /* inter_module name for cmdset_setup */
|
||||
struct flchip chips[0]; /* per-chip data structure for each chip */
|
||||
};
|
||||
|
||||
/*
|
||||
* Returns the command address according to the given geometry.
|
||||
*/
|
||||
static inline uint32_t cfi_build_cmd_addr(uint32_t cmd_ofs, int interleave, int type)
|
||||
{
|
||||
return (cmd_ofs * type) * interleave;
|
||||
}
|
||||
|
||||
/*
|
||||
* Transforms the CFI command for the given geometry (bus width & interleave).
|
||||
* It looks too long to be inline, but in the common case it should almost all
|
||||
* get optimised away.
|
||||
*/
|
||||
static inline map_word cfi_build_cmd(u_long cmd, struct map_info *map, struct cfi_private *cfi)
|
||||
{
|
||||
map_word val = { {0} };
|
||||
int wordwidth, words_per_bus, chip_mode, chips_per_word;
|
||||
unsigned long onecmd;
|
||||
int i;
|
||||
|
||||
/* We do it this way to give the compiler a fighting chance
|
||||
of optimising away all the crap for 'bankwidth' larger than
|
||||
an unsigned long, in the common case where that support is
|
||||
disabled */
|
||||
if (map_bankwidth_is_large(map)) {
|
||||
wordwidth = sizeof(unsigned long);
|
||||
words_per_bus = (map_bankwidth(map)) / wordwidth; // i.e. normally 1
|
||||
} else {
|
||||
wordwidth = map_bankwidth(map);
|
||||
words_per_bus = 1;
|
||||
}
|
||||
|
||||
chip_mode = map_bankwidth(map) / cfi_interleave(cfi);
|
||||
chips_per_word = wordwidth * cfi_interleave(cfi) / map_bankwidth(map);
|
||||
|
||||
/* First, determine what the bit-pattern should be for a single
|
||||
device, according to chip mode and endianness... */
|
||||
switch (chip_mode) {
|
||||
default: BUG();
|
||||
case 1:
|
||||
onecmd = cmd;
|
||||
break;
|
||||
case 2:
|
||||
onecmd = cpu_to_cfi16(cmd);
|
||||
break;
|
||||
case 4:
|
||||
onecmd = cpu_to_cfi32(cmd);
|
||||
break;
|
||||
}
|
||||
|
||||
/* Now replicate it across the size of an unsigned long, or
|
||||
just to the bus width as appropriate */
|
||||
switch (chips_per_word) {
|
||||
default: BUG();
|
||||
#if BITS_PER_LONG >= 64
|
||||
case 8:
|
||||
onecmd |= (onecmd << (chip_mode * 32));
|
||||
#endif
|
||||
case 4:
|
||||
onecmd |= (onecmd << (chip_mode * 16));
|
||||
case 2:
|
||||
onecmd |= (onecmd << (chip_mode * 8));
|
||||
case 1:
|
||||
;
|
||||
}
|
||||
|
||||
/* And finally, for the multi-word case, replicate it
|
||||
in all words in the structure */
|
||||
for (i=0; i < words_per_bus; i++) {
|
||||
val.x[i] = onecmd;
|
||||
}
|
||||
|
||||
return val;
|
||||
}
|
||||
#define CMD(x) cfi_build_cmd((x), map, cfi)
|
||||
|
||||
|
||||
static inline unsigned long cfi_merge_status(map_word val, struct map_info *map,
|
||||
struct cfi_private *cfi)
|
||||
{
|
||||
int wordwidth, words_per_bus, chip_mode, chips_per_word;
|
||||
unsigned long onestat, res = 0;
|
||||
int i;
|
||||
|
||||
/* We do it this way to give the compiler a fighting chance
|
||||
of optimising away all the crap for 'bankwidth' larger than
|
||||
an unsigned long, in the common case where that support is
|
||||
disabled */
|
||||
if (map_bankwidth_is_large(map)) {
|
||||
wordwidth = sizeof(unsigned long);
|
||||
words_per_bus = (map_bankwidth(map)) / wordwidth; // i.e. normally 1
|
||||
} else {
|
||||
wordwidth = map_bankwidth(map);
|
||||
words_per_bus = 1;
|
||||
}
|
||||
|
||||
chip_mode = map_bankwidth(map) / cfi_interleave(cfi);
|
||||
chips_per_word = wordwidth * cfi_interleave(cfi) / map_bankwidth(map);
|
||||
|
||||
onestat = val.x[0];
|
||||
/* Or all status words together */
|
||||
for (i=1; i < words_per_bus; i++) {
|
||||
onestat |= val.x[i];
|
||||
}
|
||||
|
||||
res = onestat;
|
||||
switch(chips_per_word) {
|
||||
default: BUG();
|
||||
#if BITS_PER_LONG >= 64
|
||||
case 8:
|
||||
res |= (onestat >> (chip_mode * 32));
|
||||
#endif
|
||||
case 4:
|
||||
res |= (onestat >> (chip_mode * 16));
|
||||
case 2:
|
||||
res |= (onestat >> (chip_mode * 8));
|
||||
case 1:
|
||||
;
|
||||
}
|
||||
|
||||
/* Last, determine what the bit-pattern should be for a single
|
||||
device, according to chip mode and endianness... */
|
||||
switch (chip_mode) {
|
||||
case 1:
|
||||
break;
|
||||
case 2:
|
||||
res = cfi16_to_cpu(res);
|
||||
break;
|
||||
case 4:
|
||||
res = cfi32_to_cpu(res);
|
||||
break;
|
||||
default: BUG();
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
#define MERGESTATUS(x) cfi_merge_status((x), map, cfi)
|
||||
|
||||
|
||||
/*
|
||||
* Sends a CFI command to a bank of flash for the given geometry.
|
||||
*
|
||||
* Returns the offset in flash where the command was written.
|
||||
* If prev_val is non-null, it will be set to the value at the command address,
|
||||
* before the command was written.
|
||||
*/
|
||||
static inline uint32_t cfi_send_gen_cmd(u_char cmd, uint32_t cmd_addr, uint32_t base,
|
||||
struct map_info *map, struct cfi_private *cfi,
|
||||
int type, map_word *prev_val)
|
||||
{
|
||||
map_word val;
|
||||
uint32_t addr = base + cfi_build_cmd_addr(cmd_addr, cfi_interleave(cfi), type);
|
||||
|
||||
val = cfi_build_cmd(cmd, map, cfi);
|
||||
|
||||
if (prev_val)
|
||||
*prev_val = map_read(map, addr);
|
||||
|
||||
map_write(map, val, addr);
|
||||
|
||||
return addr - base;
|
||||
}
|
||||
|
||||
static inline uint8_t cfi_read_query(struct map_info *map, uint32_t addr)
|
||||
{
|
||||
map_word val = map_read(map, addr);
|
||||
|
||||
if (map_bankwidth_is_1(map)) {
|
||||
return val.x[0];
|
||||
} else if (map_bankwidth_is_2(map)) {
|
||||
return cfi16_to_cpu(val.x[0]);
|
||||
} else {
|
||||
/* No point in a 64-bit byteswap since that would just be
|
||||
swapping the responses from different chips, and we are
|
||||
only interested in one chip (a representative sample) */
|
||||
return cfi32_to_cpu(val.x[0]);
|
||||
}
|
||||
}
|
||||
|
||||
static inline uint16_t cfi_read_query16(struct map_info *map, uint32_t addr)
|
||||
{
|
||||
map_word val = map_read(map, addr);
|
||||
|
||||
if (map_bankwidth_is_1(map)) {
|
||||
return val.x[0] & 0xff;
|
||||
} else if (map_bankwidth_is_2(map)) {
|
||||
return cfi16_to_cpu(val.x[0]);
|
||||
} else {
|
||||
/* No point in a 64-bit byteswap since that would just be
|
||||
swapping the responses from different chips, and we are
|
||||
only interested in one chip (a representative sample) */
|
||||
return cfi32_to_cpu(val.x[0]);
|
||||
}
|
||||
}
|
||||
|
||||
static inline void cfi_udelay(int us)
|
||||
{
|
||||
if (us >= 1000) {
|
||||
msleep((us+999)/1000);
|
||||
} else {
|
||||
udelay(us);
|
||||
cond_resched();
|
||||
}
|
||||
}
|
||||
|
||||
struct cfi_extquery *cfi_read_pri(struct map_info *map, uint16_t adr, uint16_t size,
|
||||
const char* name);
|
||||
struct cfi_fixup {
|
||||
uint16_t mfr;
|
||||
uint16_t id;
|
||||
void (*fixup)(struct mtd_info *mtd, void* param);
|
||||
void* param;
|
||||
};
|
||||
|
||||
#define CFI_MFR_ANY 0xffff
|
||||
#define CFI_ID_ANY 0xffff
|
||||
|
||||
#define CFI_MFR_AMD 0x0001
|
||||
#define CFI_MFR_ATMEL 0x001F
|
||||
#define CFI_MFR_ST 0x0020 /* STMicroelectronics */
|
||||
|
||||
void cfi_fixup(struct mtd_info *mtd, struct cfi_fixup* fixups);
|
||||
|
||||
typedef int (*varsize_frob_t)(struct map_info *map, struct flchip *chip,
|
||||
unsigned long adr, int len, void *thunk);
|
||||
|
||||
int cfi_varsize_frob(struct mtd_info *mtd, varsize_frob_t frob,
|
||||
loff_t ofs, size_t len, void *thunk);
|
||||
|
||||
|
||||
#endif /* __MTD_CFI_H__ */
|
||||
57
include/linux/mtd/cfi_endian.h
Normal file
57
include/linux/mtd/cfi_endian.h
Normal file
@@ -0,0 +1,57 @@
|
||||
/*
|
||||
* $Id: cfi_endian.h,v 1.1.1.1 2007/06/12 07:27:16 eyryu Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
#include <asm/byteorder.h>
|
||||
|
||||
#ifndef CONFIG_MTD_CFI_ADV_OPTIONS
|
||||
|
||||
#define CFI_HOST_ENDIAN
|
||||
|
||||
#else
|
||||
|
||||
#ifdef CONFIG_MTD_CFI_NOSWAP
|
||||
#define CFI_HOST_ENDIAN
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_MTD_CFI_LE_BYTE_SWAP
|
||||
#define CFI_LITTLE_ENDIAN
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_MTD_CFI_BE_BYTE_SWAP
|
||||
#define CFI_BIG_ENDIAN
|
||||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(CFI_LITTLE_ENDIAN)
|
||||
#define cpu_to_cfi8(x) (x)
|
||||
#define cfi8_to_cpu(x) (x)
|
||||
#define cpu_to_cfi16(x) cpu_to_le16(x)
|
||||
#define cpu_to_cfi32(x) cpu_to_le32(x)
|
||||
#define cpu_to_cfi64(x) cpu_to_le64(x)
|
||||
#define cfi16_to_cpu(x) le16_to_cpu(x)
|
||||
#define cfi32_to_cpu(x) le32_to_cpu(x)
|
||||
#define cfi64_to_cpu(x) le64_to_cpu(x)
|
||||
#elif defined (CFI_BIG_ENDIAN)
|
||||
#define cpu_to_cfi8(x) (x)
|
||||
#define cfi8_to_cpu(x) (x)
|
||||
#define cpu_to_cfi16(x) cpu_to_be16(x)
|
||||
#define cpu_to_cfi32(x) cpu_to_be32(x)
|
||||
#define cpu_to_cfi64(x) cpu_to_be64(x)
|
||||
#define cfi16_to_cpu(x) be16_to_cpu(x)
|
||||
#define cfi32_to_cpu(x) be32_to_cpu(x)
|
||||
#define cfi64_to_cpu(x) be64_to_cpu(x)
|
||||
#elif defined (CFI_HOST_ENDIAN)
|
||||
#define cpu_to_cfi8(x) (x)
|
||||
#define cfi8_to_cpu(x) (x)
|
||||
#define cpu_to_cfi16(x) (x)
|
||||
#define cpu_to_cfi32(x) (x)
|
||||
#define cpu_to_cfi64(x) (x)
|
||||
#define cfi16_to_cpu(x) (x)
|
||||
#define cfi32_to_cpu(x) (x)
|
||||
#define cfi64_to_cpu(x) (x)
|
||||
#else
|
||||
#error No CFI endianness defined
|
||||
#endif
|
||||
10
include/linux/mtd/compatmac.h
Normal file
10
include/linux/mtd/compatmac.h
Normal file
@@ -0,0 +1,10 @@
|
||||
|
||||
#ifndef __LINUX_MTD_COMPATMAC_H__
|
||||
#define __LINUX_MTD_COMPATMAC_H__
|
||||
|
||||
/* Nothing to see here. We write 2.5-compatible code and this
|
||||
file makes it all OK in older kernels, but it's empty in _current_
|
||||
kernels. Include guard just to make GCC ignore it in future inclusions
|
||||
anyway... */
|
||||
|
||||
#endif /* __LINUX_MTD_COMPATMAC_H__ */
|
||||
23
include/linux/mtd/concat.h
Normal file
23
include/linux/mtd/concat.h
Normal file
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* MTD device concatenation layer definitions
|
||||
*
|
||||
* (C) 2002 Robert Kaiser <rkaiser@sysgo.de>
|
||||
*
|
||||
* This code is GPL
|
||||
*
|
||||
* $Id: concat.h,v 1.1.1.1 2007/06/12 07:27:16 eyryu Exp $
|
||||
*/
|
||||
|
||||
#ifndef MTD_CONCAT_H
|
||||
#define MTD_CONCAT_H
|
||||
|
||||
|
||||
struct mtd_info *mtd_concat_create(
|
||||
struct mtd_info *subdev[], /* subdevices to concatenate */
|
||||
int num_devs, /* number of subdevices */
|
||||
char *name); /* name for the new device */
|
||||
|
||||
void mtd_concat_destroy(struct mtd_info *mtd);
|
||||
|
||||
#endif
|
||||
|
||||
195
include/linux/mtd/doc2000.h
Normal file
195
include/linux/mtd/doc2000.h
Normal file
@@ -0,0 +1,195 @@
|
||||
/*
|
||||
* Linux driver for Disk-On-Chip devices
|
||||
*
|
||||
* Copyright (C) 1999 Machine Vision Holdings, Inc.
|
||||
* Copyright (C) 2001-2003 David Woodhouse <dwmw2@infradead.org>
|
||||
* Copyright (C) 2002-2003 Greg Ungerer <gerg@snapgear.com>
|
||||
* Copyright (C) 2002-2003 SnapGear Inc
|
||||
*
|
||||
* $Id: doc2000.h,v 1.1.1.1 2007/06/12 07:27:16 eyryu Exp $
|
||||
*
|
||||
* Released under GPL
|
||||
*/
|
||||
|
||||
#ifndef __MTD_DOC2000_H__
|
||||
#define __MTD_DOC2000_H__
|
||||
|
||||
#include <linux/mtd/mtd.h>
|
||||
#include <linux/mutex.h>
|
||||
|
||||
#define DoC_Sig1 0
|
||||
#define DoC_Sig2 1
|
||||
|
||||
#define DoC_ChipID 0x1000
|
||||
#define DoC_DOCStatus 0x1001
|
||||
#define DoC_DOCControl 0x1002
|
||||
#define DoC_FloorSelect 0x1003
|
||||
#define DoC_CDSNControl 0x1004
|
||||
#define DoC_CDSNDeviceSelect 0x1005
|
||||
#define DoC_ECCConf 0x1006
|
||||
#define DoC_2k_ECCStatus 0x1007
|
||||
|
||||
#define DoC_CDSNSlowIO 0x100d
|
||||
#define DoC_ECCSyndrome0 0x1010
|
||||
#define DoC_ECCSyndrome1 0x1011
|
||||
#define DoC_ECCSyndrome2 0x1012
|
||||
#define DoC_ECCSyndrome3 0x1013
|
||||
#define DoC_ECCSyndrome4 0x1014
|
||||
#define DoC_ECCSyndrome5 0x1015
|
||||
#define DoC_AliasResolution 0x101b
|
||||
#define DoC_ConfigInput 0x101c
|
||||
#define DoC_ReadPipeInit 0x101d
|
||||
#define DoC_WritePipeTerm 0x101e
|
||||
#define DoC_LastDataRead 0x101f
|
||||
#define DoC_NOP 0x1020
|
||||
|
||||
#define DoC_Mil_CDSN_IO 0x0800
|
||||
#define DoC_2k_CDSN_IO 0x1800
|
||||
|
||||
#define DoC_Mplus_NOP 0x1002
|
||||
#define DoC_Mplus_AliasResolution 0x1004
|
||||
#define DoC_Mplus_DOCControl 0x1006
|
||||
#define DoC_Mplus_AccessStatus 0x1008
|
||||
#define DoC_Mplus_DeviceSelect 0x1008
|
||||
#define DoC_Mplus_Configuration 0x100a
|
||||
#define DoC_Mplus_OutputControl 0x100c
|
||||
#define DoC_Mplus_FlashControl 0x1020
|
||||
#define DoC_Mplus_FlashSelect 0x1022
|
||||
#define DoC_Mplus_FlashCmd 0x1024
|
||||
#define DoC_Mplus_FlashAddress 0x1026
|
||||
#define DoC_Mplus_FlashData0 0x1028
|
||||
#define DoC_Mplus_FlashData1 0x1029
|
||||
#define DoC_Mplus_ReadPipeInit 0x102a
|
||||
#define DoC_Mplus_LastDataRead 0x102c
|
||||
#define DoC_Mplus_LastDataRead1 0x102d
|
||||
#define DoC_Mplus_WritePipeTerm 0x102e
|
||||
#define DoC_Mplus_ECCSyndrome0 0x1040
|
||||
#define DoC_Mplus_ECCSyndrome1 0x1041
|
||||
#define DoC_Mplus_ECCSyndrome2 0x1042
|
||||
#define DoC_Mplus_ECCSyndrome3 0x1043
|
||||
#define DoC_Mplus_ECCSyndrome4 0x1044
|
||||
#define DoC_Mplus_ECCSyndrome5 0x1045
|
||||
#define DoC_Mplus_ECCConf 0x1046
|
||||
#define DoC_Mplus_Toggle 0x1046
|
||||
#define DoC_Mplus_DownloadStatus 0x1074
|
||||
#define DoC_Mplus_CtrlConfirm 0x1076
|
||||
#define DoC_Mplus_Power 0x1fff
|
||||
|
||||
/* How to access the device?
|
||||
* On ARM, it'll be mmap'd directly with 32-bit wide accesses.
|
||||
* On PPC, it's mmap'd and 16-bit wide.
|
||||
* Others use readb/writeb
|
||||
*/
|
||||
#if defined(__arm__)
|
||||
#define ReadDOC_(adr, reg) ((unsigned char)(*(volatile __u32 *)(((unsigned long)adr)+((reg)<<2))))
|
||||
#define WriteDOC_(d, adr, reg) do{ *(volatile __u32 *)(((unsigned long)adr)+((reg)<<2)) = (__u32)d; wmb();} while(0)
|
||||
#define DOC_IOREMAP_LEN 0x8000
|
||||
#elif defined(__ppc__)
|
||||
#define ReadDOC_(adr, reg) ((unsigned char)(*(volatile __u16 *)(((unsigned long)adr)+((reg)<<1))))
|
||||
#define WriteDOC_(d, adr, reg) do{ *(volatile __u16 *)(((unsigned long)adr)+((reg)<<1)) = (__u16)d; wmb();} while(0)
|
||||
#define DOC_IOREMAP_LEN 0x4000
|
||||
#else
|
||||
#define ReadDOC_(adr, reg) readb((void __iomem *)(adr) + (reg))
|
||||
#define WriteDOC_(d, adr, reg) writeb(d, (void __iomem *)(adr) + (reg))
|
||||
#define DOC_IOREMAP_LEN 0x2000
|
||||
|
||||
#endif
|
||||
|
||||
#if defined(__i386__) || defined(__x86_64__)
|
||||
#define USE_MEMCPY
|
||||
#endif
|
||||
|
||||
/* These are provided to directly use the DoC_xxx defines */
|
||||
#define ReadDOC(adr, reg) ReadDOC_(adr,DoC_##reg)
|
||||
#define WriteDOC(d, adr, reg) WriteDOC_(d,adr,DoC_##reg)
|
||||
|
||||
#define DOC_MODE_RESET 0
|
||||
#define DOC_MODE_NORMAL 1
|
||||
#define DOC_MODE_RESERVED1 2
|
||||
#define DOC_MODE_RESERVED2 3
|
||||
|
||||
#define DOC_MODE_CLR_ERR 0x80
|
||||
#define DOC_MODE_RST_LAT 0x10
|
||||
#define DOC_MODE_BDECT 0x08
|
||||
#define DOC_MODE_MDWREN 0x04
|
||||
|
||||
#define DOC_ChipID_Doc2k 0x20
|
||||
#define DOC_ChipID_Doc2kTSOP 0x21 /* internal number for MTD */
|
||||
#define DOC_ChipID_DocMil 0x30
|
||||
#define DOC_ChipID_DocMilPlus32 0x40
|
||||
#define DOC_ChipID_DocMilPlus16 0x41
|
||||
|
||||
#define CDSN_CTRL_FR_B 0x80
|
||||
#define CDSN_CTRL_FR_B0 0x40
|
||||
#define CDSN_CTRL_FR_B1 0x80
|
||||
|
||||
#define CDSN_CTRL_ECC_IO 0x20
|
||||
#define CDSN_CTRL_FLASH_IO 0x10
|
||||
#define CDSN_CTRL_WP 0x08
|
||||
#define CDSN_CTRL_ALE 0x04
|
||||
#define CDSN_CTRL_CLE 0x02
|
||||
#define CDSN_CTRL_CE 0x01
|
||||
|
||||
#define DOC_ECC_RESET 0
|
||||
#define DOC_ECC_ERROR 0x80
|
||||
#define DOC_ECC_RW 0x20
|
||||
#define DOC_ECC__EN 0x08
|
||||
#define DOC_TOGGLE_BIT 0x04
|
||||
#define DOC_ECC_RESV 0x02
|
||||
#define DOC_ECC_IGNORE 0x01
|
||||
|
||||
#define DOC_FLASH_CE 0x80
|
||||
#define DOC_FLASH_WP 0x40
|
||||
#define DOC_FLASH_BANK 0x02
|
||||
|
||||
/* We have to also set the reserved bit 1 for enable */
|
||||
#define DOC_ECC_EN (DOC_ECC__EN | DOC_ECC_RESV)
|
||||
#define DOC_ECC_DIS (DOC_ECC_RESV)
|
||||
|
||||
struct Nand {
|
||||
char floor, chip;
|
||||
unsigned long curadr;
|
||||
unsigned char curmode;
|
||||
/* Also some erase/write/pipeline info when we get that far */
|
||||
};
|
||||
|
||||
#define MAX_FLOORS 4
|
||||
#define MAX_CHIPS 4
|
||||
|
||||
#define MAX_FLOORS_MIL 1
|
||||
#define MAX_CHIPS_MIL 1
|
||||
|
||||
#define MAX_FLOORS_MPLUS 2
|
||||
#define MAX_CHIPS_MPLUS 1
|
||||
|
||||
#define ADDR_COLUMN 1
|
||||
#define ADDR_PAGE 2
|
||||
#define ADDR_COLUMN_PAGE 3
|
||||
|
||||
struct DiskOnChip {
|
||||
unsigned long physadr;
|
||||
void __iomem *virtadr;
|
||||
unsigned long totlen;
|
||||
unsigned char ChipID; /* Type of DiskOnChip */
|
||||
int ioreg;
|
||||
|
||||
unsigned long mfr; /* Flash IDs - only one type of flash per device */
|
||||
unsigned long id;
|
||||
int chipshift;
|
||||
char page256;
|
||||
char pageadrlen;
|
||||
char interleave; /* Internal interleaving - Millennium Plus style */
|
||||
unsigned long erasesize;
|
||||
|
||||
int curfloor;
|
||||
int curchip;
|
||||
|
||||
int numchips;
|
||||
struct Nand *chips;
|
||||
struct mtd_info *nextdoc;
|
||||
struct mutex lock;
|
||||
};
|
||||
|
||||
int doc_decode_ecc(unsigned char sector[512], unsigned char ecc1[6]);
|
||||
|
||||
#endif /* __MTD_DOC2000_H__ */
|
||||
90
include/linux/mtd/flashchip.h
Normal file
90
include/linux/mtd/flashchip.h
Normal file
@@ -0,0 +1,90 @@
|
||||
|
||||
/*
|
||||
* struct flchip definition
|
||||
*
|
||||
* Contains information about the location and state of a given flash device
|
||||
*
|
||||
* (C) 2000 Red Hat. GPLd.
|
||||
*
|
||||
* $Id: flashchip.h,v 1.1.1.1 2007/06/12 07:27:16 eyryu Exp $
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __MTD_FLASHCHIP_H__
|
||||
#define __MTD_FLASHCHIP_H__
|
||||
|
||||
/* For spinlocks. sched.h includes spinlock.h from whichever directory it
|
||||
* happens to be in - so we don't have to care whether we're on 2.2, which
|
||||
* has asm/spinlock.h, or 2.4, which has linux/spinlock.h
|
||||
*/
|
||||
#include <linux/sched.h>
|
||||
|
||||
typedef enum {
|
||||
FL_READY,
|
||||
FL_STATUS,
|
||||
FL_CFI_QUERY,
|
||||
FL_JEDEC_QUERY,
|
||||
FL_ERASING,
|
||||
FL_ERASE_SUSPENDING,
|
||||
FL_ERASE_SUSPENDED,
|
||||
FL_WRITING,
|
||||
FL_WRITING_TO_BUFFER,
|
||||
FL_OTP_WRITE,
|
||||
FL_WRITE_SUSPENDING,
|
||||
FL_WRITE_SUSPENDED,
|
||||
FL_PM_SUSPENDED,
|
||||
FL_SYNCING,
|
||||
FL_UNLOADING,
|
||||
FL_LOCKING,
|
||||
FL_UNLOCKING,
|
||||
FL_POINT,
|
||||
FL_XIP_WHILE_ERASING,
|
||||
FL_XIP_WHILE_WRITING,
|
||||
FL_UNKNOWN
|
||||
} flstate_t;
|
||||
|
||||
|
||||
|
||||
/* NOTE: confusingly, this can be used to refer to more than one chip at a time,
|
||||
if they're interleaved. This can even refer to individual partitions on
|
||||
the same physical chip when present. */
|
||||
|
||||
struct flchip {
|
||||
unsigned long start; /* Offset within the map */
|
||||
// unsigned long len;
|
||||
/* We omit len for now, because when we group them together
|
||||
we insist that they're all of the same size, and the chip size
|
||||
is held in the next level up. If we get more versatile later,
|
||||
it'll make it a damn sight harder to find which chip we want from
|
||||
a given offset, and we'll want to add the per-chip length field
|
||||
back in.
|
||||
*/
|
||||
int ref_point_counter;
|
||||
flstate_t state;
|
||||
flstate_t oldstate;
|
||||
|
||||
unsigned int write_suspended:1;
|
||||
unsigned int erase_suspended:1;
|
||||
unsigned long in_progress_block_addr;
|
||||
|
||||
spinlock_t *mutex;
|
||||
spinlock_t _spinlock; /* We do it like this because sometimes they'll be shared. */
|
||||
wait_queue_head_t wq; /* Wait on here when we're waiting for the chip
|
||||
to be ready */
|
||||
int word_write_time;
|
||||
int buffer_write_time;
|
||||
int erase_time;
|
||||
|
||||
void *priv;
|
||||
};
|
||||
|
||||
/* This is used to handle contention on write/erase operations
|
||||
between partitions of the same physical chip. */
|
||||
struct flchip_shared {
|
||||
spinlock_t lock;
|
||||
struct flchip *writing;
|
||||
struct flchip *erasing;
|
||||
};
|
||||
|
||||
|
||||
#endif /* __MTD_FLASHCHIP_H__ */
|
||||
76
include/linux/mtd/ftl.h
Normal file
76
include/linux/mtd/ftl.h
Normal file
@@ -0,0 +1,76 @@
|
||||
/*
|
||||
* $Id: ftl.h,v 1.1.1.1 2007/06/12 07:27:16 eyryu Exp $
|
||||
*
|
||||
* Derived from (and probably identical to):
|
||||
* ftl.h 1.7 1999/10/25 20:23:17
|
||||
*
|
||||
* The contents of this file are subject to the Mozilla Public License
|
||||
* Version 1.1 (the "License"); you may not use this file except in
|
||||
* compliance with the License. You may obtain a copy of the License
|
||||
* at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS IS"
|
||||
* basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
|
||||
* the License for the specific language governing rights and
|
||||
* limitations under the License.
|
||||
*
|
||||
* The initial developer of the original code is David A. Hinds
|
||||
* <dahinds@users.sourceforge.net>. Portions created by David A. Hinds
|
||||
* are Copyright (C) 1999 David A. Hinds. All Rights Reserved.
|
||||
*
|
||||
* Alternatively, the contents of this file may be used under the
|
||||
* terms of the GNU General Public License version 2 (the "GPL"), in
|
||||
* which case the provisions of the GPL are applicable instead of the
|
||||
* above. If you wish to allow the use of your version of this file
|
||||
* only under the terms of the GPL and not to allow others to use
|
||||
* your version of this file under the MPL, indicate your decision by
|
||||
* deleting the provisions above and replace them with the notice and
|
||||
* other provisions required by the GPL. If you do not delete the
|
||||
* provisions above, a recipient may use your version of this file
|
||||
* under either the MPL or the GPL.
|
||||
*/
|
||||
|
||||
#ifndef _LINUX_FTL_H
|
||||
#define _LINUX_FTL_H
|
||||
|
||||
typedef struct erase_unit_header_t {
|
||||
u_int8_t LinkTargetTuple[5];
|
||||
u_int8_t DataOrgTuple[10];
|
||||
u_int8_t NumTransferUnits;
|
||||
u_int32_t EraseCount;
|
||||
u_int16_t LogicalEUN;
|
||||
u_int8_t BlockSize;
|
||||
u_int8_t EraseUnitSize;
|
||||
u_int16_t FirstPhysicalEUN;
|
||||
u_int16_t NumEraseUnits;
|
||||
u_int32_t FormattedSize;
|
||||
u_int32_t FirstVMAddress;
|
||||
u_int16_t NumVMPages;
|
||||
u_int8_t Flags;
|
||||
u_int8_t Code;
|
||||
u_int32_t SerialNumber;
|
||||
u_int32_t AltEUHOffset;
|
||||
u_int32_t BAMOffset;
|
||||
u_int8_t Reserved[12];
|
||||
u_int8_t EndTuple[2];
|
||||
} erase_unit_header_t;
|
||||
|
||||
/* Flags in erase_unit_header_t */
|
||||
#define HIDDEN_AREA 0x01
|
||||
#define REVERSE_POLARITY 0x02
|
||||
#define DOUBLE_BAI 0x04
|
||||
|
||||
/* Definitions for block allocation information */
|
||||
|
||||
#define BLOCK_FREE(b) ((b) == 0xffffffff)
|
||||
#define BLOCK_DELETED(b) (((b) == 0) || ((b) == 0xfffffffe))
|
||||
|
||||
#define BLOCK_TYPE(b) ((b) & 0x7f)
|
||||
#define BLOCK_ADDRESS(b) ((b) & ~0x7f)
|
||||
#define BLOCK_NUMBER(b) ((b) >> 9)
|
||||
#define BLOCK_CONTROL 0x30
|
||||
#define BLOCK_DATA 0x40
|
||||
#define BLOCK_REPLACEMENT 0x60
|
||||
#define BLOCK_BAD 0x70
|
||||
|
||||
#endif /* _LINUX_FTL_H */
|
||||
23
include/linux/mtd/gen_probe.h
Normal file
23
include/linux/mtd/gen_probe.h
Normal file
@@ -0,0 +1,23 @@
|
||||
/*
|
||||
* (C) 2001, 2001 Red Hat, Inc.
|
||||
* GPL'd
|
||||
* $Id: gen_probe.h,v 1.1.1.1 2007/06/12 07:27:16 eyryu Exp $
|
||||
*/
|
||||
|
||||
#ifndef __LINUX_MTD_GEN_PROBE_H__
|
||||
#define __LINUX_MTD_GEN_PROBE_H__
|
||||
|
||||
#include <linux/mtd/flashchip.h>
|
||||
#include <linux/mtd/map.h>
|
||||
#include <linux/mtd/cfi.h>
|
||||
#include <linux/bitops.h>
|
||||
|
||||
struct chip_probe {
|
||||
char *name;
|
||||
int (*probe_chip)(struct map_info *map, __u32 base,
|
||||
unsigned long *chip_map, struct cfi_private *cfi);
|
||||
};
|
||||
|
||||
struct mtd_info *mtd_do_chip_probe(struct map_info *map, struct chip_probe *cp);
|
||||
|
||||
#endif /* __LINUX_MTD_GEN_PROBE_H__ */
|
||||
98
include/linux/mtd/iflash.h
Normal file
98
include/linux/mtd/iflash.h
Normal file
@@ -0,0 +1,98 @@
|
||||
/* $Id: iflash.h,v 1.1.1.1 2007/06/12 07:27:16 eyryu Exp $ */
|
||||
|
||||
#ifndef __MTD_IFLASH_H__
|
||||
#define __MTD_IFLASH_H__
|
||||
|
||||
/* Extended CIS registers for Series 2 and 2+ cards */
|
||||
/* The registers are all offsets from 0x4000 */
|
||||
#define CISREG_CSR 0x0100
|
||||
#define CISREG_WP 0x0104
|
||||
#define CISREG_RDYBSY 0x0140
|
||||
|
||||
/* Extended CIS registers for Series 2 cards */
|
||||
#define CISREG_SLEEP 0x0118
|
||||
#define CISREG_RDY_MASK 0x0120
|
||||
#define CISREG_RDY_STATUS 0x0130
|
||||
|
||||
/* Extended CIS registers for Series 2+ cards */
|
||||
#define CISREG_VCR 0x010c
|
||||
|
||||
/* Card Status Register */
|
||||
#define CSR_SRESET 0x20 /* Soft reset */
|
||||
#define CSR_CMWP 0x10 /* Common memory write protect */
|
||||
#define CSR_PWRDOWN 0x08 /* Power down status */
|
||||
#define CSR_CISWP 0x04 /* Common memory CIS WP */
|
||||
#define CSR_WP 0x02 /* Mechanical write protect */
|
||||
#define CSR_READY 0x01 /* Ready/busy status */
|
||||
|
||||
/* Write Protection Register */
|
||||
#define WP_BLKEN 0x04 /* Enable block locking */
|
||||
#define WP_CMWP 0x02 /* Common memory write protect */
|
||||
#define WP_CISWP 0x01 /* Common memory CIS WP */
|
||||
|
||||
/* Voltage Control Register */
|
||||
#define VCR_VCC_LEVEL 0x80 /* 0 = 5V, 1 = 3.3V */
|
||||
#define VCR_VPP_VALID 0x02 /* Vpp Valid */
|
||||
#define VCR_VPP_GEN 0x01 /* Integrated Vpp generator */
|
||||
|
||||
/* Ready/Busy Mode Register */
|
||||
#define RDYBSY_RACK 0x02 /* Ready acknowledge */
|
||||
#define RDYBSY_MODE 0x01 /* 1 = high performance */
|
||||
|
||||
#define LOW(x) ((x) & 0xff)
|
||||
|
||||
/* 28F008SA-Compatible Command Set */
|
||||
#define IF_READ_ARRAY 0xffff
|
||||
#define IF_INTEL_ID 0x9090
|
||||
#define IF_READ_CSR 0x7070
|
||||
#define IF_CLEAR_CSR 0x5050
|
||||
#define IF_WRITE 0x4040
|
||||
#define IF_BLOCK_ERASE 0x2020
|
||||
#define IF_ERASE_SUSPEND 0xb0b0
|
||||
#define IF_CONFIRM 0xd0d0
|
||||
|
||||
/* 28F016SA Performance Enhancement Commands */
|
||||
#define IF_READ_PAGE 0x7575
|
||||
#define IF_PAGE_SWAP 0x7272
|
||||
#define IF_SINGLE_LOAD 0x7474
|
||||
#define IF_SEQ_LOAD 0xe0e0
|
||||
#define IF_PAGE_WRITE 0x0c0c
|
||||
#define IF_RDY_MODE 0x9696
|
||||
#define IF_RDY_LEVEL 0x0101
|
||||
#define IF_RDY_PULSE_WRITE 0x0202
|
||||
#define IF_RDY_PULSE_ERASE 0x0303
|
||||
#define IF_RDY_DISABLE 0x0404
|
||||
#define IF_LOCK_BLOCK 0x7777
|
||||
#define IF_UPLOAD_STATUS 0x9797
|
||||
#define IF_READ_ESR 0x7171
|
||||
#define IF_ERASE_UNLOCKED 0xa7a7
|
||||
#define IF_SLEEP 0xf0f0
|
||||
#define IF_ABORT 0x8080
|
||||
#define IF_UPLOAD_DEVINFO 0x9999
|
||||
|
||||
/* Definitions for Compatible Status Register */
|
||||
#define CSR_WR_READY 0x8080 /* Write state machine status */
|
||||
#define CSR_ERA_SUSPEND 0x4040 /* Erase suspend status */
|
||||
#define CSR_ERA_ERR 0x2020 /* Erase status */
|
||||
#define CSR_WR_ERR 0x1010 /* Data write status */
|
||||
#define CSR_VPP_LOW 0x0808 /* Vpp status */
|
||||
|
||||
/* Definitions for Global Status Register */
|
||||
#define GSR_WR_READY 0x8080 /* Write state machine status */
|
||||
#define GSR_OP_SUSPEND 0x4040 /* Operation suspend status */
|
||||
#define GSR_OP_ERR 0x2020 /* Device operation status */
|
||||
#define GSR_SLEEP 0x1010 /* Device sleep status */
|
||||
#define GSR_QUEUE_FULL 0x0808 /* Queue status */
|
||||
#define GSR_PAGE_AVAIL 0x0404 /* Page buffer available status */
|
||||
#define GSR_PAGE_READY 0x0202 /* Page buffer status */
|
||||
#define GSR_PAGE_SELECT 0x0101 /* Page buffer select status */
|
||||
|
||||
/* Definitions for Block Status Register */
|
||||
#define BSR_READY 0x8080 /* Block status */
|
||||
#define BSR_UNLOCK 0x4040 /* Block lock status */
|
||||
#define BSR_FAILED 0x2020 /* Block operation status */
|
||||
#define BSR_ABORTED 0x1010 /* Operation abort status */
|
||||
#define BSR_QUEUE_FULL 0x0808 /* Queue status */
|
||||
#define BSR_VPP_LOW 0x0404 /* Vpp status */
|
||||
|
||||
#endif /* __MTD_IFLASH_H__ */
|
||||
62
include/linux/mtd/inftl.h
Normal file
62
include/linux/mtd/inftl.h
Normal file
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* inftl.h -- defines to support the Inverse NAND Flash Translation Layer
|
||||
*
|
||||
* (C) Copyright 2002, Greg Ungerer (gerg@snapgear.com)
|
||||
*
|
||||
* $Id: inftl.h,v 1.1.1.1 2007/06/12 07:27:16 eyryu Exp $
|
||||
*/
|
||||
|
||||
#ifndef __MTD_INFTL_H__
|
||||
#define __MTD_INFTL_H__
|
||||
|
||||
#ifndef __KERNEL__
|
||||
#error This is a kernel header. Perhaps include nftl-user.h instead?
|
||||
#endif
|
||||
|
||||
#include <linux/mtd/blktrans.h>
|
||||
#include <linux/mtd/mtd.h>
|
||||
#include <linux/mtd/nftl.h>
|
||||
|
||||
#include <mtd/inftl-user.h>
|
||||
|
||||
#ifndef INFTL_MAJOR
|
||||
#define INFTL_MAJOR 96
|
||||
#endif
|
||||
#define INFTL_PARTN_BITS 4
|
||||
|
||||
#ifdef __KERNEL__
|
||||
|
||||
struct INFTLrecord {
|
||||
struct mtd_blktrans_dev mbd;
|
||||
__u16 MediaUnit;
|
||||
__u32 EraseSize;
|
||||
struct INFTLMediaHeader MediaHdr;
|
||||
int usecount;
|
||||
unsigned char heads;
|
||||
unsigned char sectors;
|
||||
unsigned short cylinders;
|
||||
__u16 numvunits;
|
||||
__u16 firstEUN;
|
||||
__u16 lastEUN;
|
||||
__u16 numfreeEUNs;
|
||||
__u16 LastFreeEUN; /* To speed up finding a free EUN */
|
||||
int head,sect,cyl;
|
||||
__u16 *PUtable; /* Physical Unit Table */
|
||||
__u16 *VUtable; /* Virtual Unit Table */
|
||||
unsigned int nb_blocks; /* number of physical blocks */
|
||||
unsigned int nb_boot_blocks; /* number of blocks used by the bios */
|
||||
struct erase_info instr;
|
||||
struct nand_ecclayout oobinfo;
|
||||
};
|
||||
|
||||
int INFTL_mount(struct INFTLrecord *s);
|
||||
int INFTL_formatblock(struct INFTLrecord *s, int block);
|
||||
|
||||
extern char inftlmountrev[];
|
||||
|
||||
void INFTL_dumptables(struct INFTLrecord *s);
|
||||
void INFTL_dumpVUchains(struct INFTLrecord *s);
|
||||
|
||||
#endif /* __KERNEL__ */
|
||||
|
||||
#endif /* __MTD_INFTL_H__ */
|
||||
66
include/linux/mtd/jedec.h
Normal file
66
include/linux/mtd/jedec.h
Normal file
@@ -0,0 +1,66 @@
|
||||
|
||||
/* JEDEC Flash Interface.
|
||||
* This is an older type of interface for self programming flash. It is
|
||||
* commonly use in older AMD chips and is obsolete compared with CFI.
|
||||
* It is called JEDEC because the JEDEC association distributes the ID codes
|
||||
* for the chips.
|
||||
*
|
||||
* See the AMD flash databook for information on how to operate the interface.
|
||||
*
|
||||
* $Id: jedec.h,v 1.1.1.1 2007/06/12 07:27:16 eyryu Exp $
|
||||
*/
|
||||
|
||||
#ifndef __LINUX_MTD_JEDEC_H__
|
||||
#define __LINUX_MTD_JEDEC_H__
|
||||
|
||||
#include <linux/types.h>
|
||||
|
||||
#define MAX_JEDEC_CHIPS 16
|
||||
|
||||
// Listing of all supported chips and their information
|
||||
struct JEDECTable
|
||||
{
|
||||
__u16 jedec;
|
||||
char *name;
|
||||
unsigned long size;
|
||||
unsigned long sectorsize;
|
||||
__u32 capabilities;
|
||||
};
|
||||
|
||||
// JEDEC being 0 is the end of the chip array
|
||||
struct jedec_flash_chip
|
||||
{
|
||||
__u16 jedec;
|
||||
unsigned long size;
|
||||
unsigned long sectorsize;
|
||||
|
||||
// *(__u8*)(base + (adder << addrshift)) = data << datashift
|
||||
// Address size = size << addrshift
|
||||
unsigned long base; // Byte 0 of the flash, will be unaligned
|
||||
unsigned int datashift; // Useful for 32bit/16bit accesses
|
||||
unsigned int addrshift;
|
||||
unsigned long offset; // linerized start. base==offset for unbanked, uninterleaved flash
|
||||
|
||||
__u32 capabilities;
|
||||
|
||||
// These markers are filled in by the flash_chip_scan function
|
||||
unsigned long start;
|
||||
unsigned long length;
|
||||
};
|
||||
|
||||
struct jedec_private
|
||||
{
|
||||
unsigned long size; // Total size of all the devices
|
||||
|
||||
/* Bank handling. If sum(bank_fill) == size then this is linear flash.
|
||||
Otherwise the mapping has holes in it. bank_fill may be used to
|
||||
find the holes, but in the common symetric case
|
||||
bank_fill[0] == bank_fill[*], thus addresses may be computed
|
||||
mathmatically. bank_fill must be powers of two */
|
||||
unsigned is_banked;
|
||||
unsigned long bank_fill[MAX_JEDEC_CHIPS];
|
||||
|
||||
struct jedec_flash_chip chips[MAX_JEDEC_CHIPS];
|
||||
};
|
||||
|
||||
#endif
|
||||
436
include/linux/mtd/map.h
Normal file
436
include/linux/mtd/map.h
Normal file
@@ -0,0 +1,436 @@
|
||||
|
||||
/* Overhauled routines for dealing with different mmap regions of flash */
|
||||
/* $Id: map.h,v 1.1.1.1 2007/06/12 07:27:16 eyryu Exp $ */
|
||||
|
||||
#ifndef __LINUX_MTD_MAP_H__
|
||||
#define __LINUX_MTD_MAP_H__
|
||||
|
||||
#include <linux/types.h>
|
||||
#include <linux/list.h>
|
||||
#include <linux/string.h>
|
||||
|
||||
#include <linux/mtd/compatmac.h>
|
||||
|
||||
#include <asm/unaligned.h>
|
||||
#include <asm/system.h>
|
||||
#include <asm/io.h>
|
||||
|
||||
#ifdef CONFIG_MTD_MAP_BANK_WIDTH_1
|
||||
#define map_bankwidth(map) 1
|
||||
#define map_bankwidth_is_1(map) (map_bankwidth(map) == 1)
|
||||
#define map_bankwidth_is_large(map) (0)
|
||||
#define map_words(map) (1)
|
||||
#define MAX_MAP_BANKWIDTH 1
|
||||
#else
|
||||
#define map_bankwidth_is_1(map) (0)
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_MTD_MAP_BANK_WIDTH_2
|
||||
# ifdef map_bankwidth
|
||||
# undef map_bankwidth
|
||||
# define map_bankwidth(map) ((map)->bankwidth)
|
||||
# else
|
||||
# define map_bankwidth(map) 2
|
||||
# define map_bankwidth_is_large(map) (0)
|
||||
# define map_words(map) (1)
|
||||
# endif
|
||||
#define map_bankwidth_is_2(map) (map_bankwidth(map) == 2)
|
||||
#undef MAX_MAP_BANKWIDTH
|
||||
#define MAX_MAP_BANKWIDTH 2
|
||||
#else
|
||||
#define map_bankwidth_is_2(map) (0)
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_MTD_MAP_BANK_WIDTH_4
|
||||
# ifdef map_bankwidth
|
||||
# undef map_bankwidth
|
||||
# define map_bankwidth(map) ((map)->bankwidth)
|
||||
# else
|
||||
# define map_bankwidth(map) 4
|
||||
# define map_bankwidth_is_large(map) (0)
|
||||
# define map_words(map) (1)
|
||||
# endif
|
||||
#define map_bankwidth_is_4(map) (map_bankwidth(map) == 4)
|
||||
#undef MAX_MAP_BANKWIDTH
|
||||
#define MAX_MAP_BANKWIDTH 4
|
||||
#else
|
||||
#define map_bankwidth_is_4(map) (0)
|
||||
#endif
|
||||
|
||||
/* ensure we never evaluate anything shorted than an unsigned long
|
||||
* to zero, and ensure we'll never miss the end of an comparison (bjd) */
|
||||
|
||||
#define map_calc_words(map) ((map_bankwidth(map) + (sizeof(unsigned long)-1))/ sizeof(unsigned long))
|
||||
|
||||
#ifdef CONFIG_MTD_MAP_BANK_WIDTH_8
|
||||
# ifdef map_bankwidth
|
||||
# undef map_bankwidth
|
||||
# define map_bankwidth(map) ((map)->bankwidth)
|
||||
# if BITS_PER_LONG < 64
|
||||
# undef map_bankwidth_is_large
|
||||
# define map_bankwidth_is_large(map) (map_bankwidth(map) > BITS_PER_LONG/8)
|
||||
# undef map_words
|
||||
# define map_words(map) map_calc_words(map)
|
||||
# endif
|
||||
# else
|
||||
# define map_bankwidth(map) 8
|
||||
# define map_bankwidth_is_large(map) (BITS_PER_LONG < 64)
|
||||
# define map_words(map) map_calc_words(map)
|
||||
# endif
|
||||
#define map_bankwidth_is_8(map) (map_bankwidth(map) == 8)
|
||||
#undef MAX_MAP_BANKWIDTH
|
||||
#define MAX_MAP_BANKWIDTH 8
|
||||
#else
|
||||
#define map_bankwidth_is_8(map) (0)
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_MTD_MAP_BANK_WIDTH_16
|
||||
# ifdef map_bankwidth
|
||||
# undef map_bankwidth
|
||||
# define map_bankwidth(map) ((map)->bankwidth)
|
||||
# undef map_bankwidth_is_large
|
||||
# define map_bankwidth_is_large(map) (map_bankwidth(map) > BITS_PER_LONG/8)
|
||||
# undef map_words
|
||||
# define map_words(map) map_calc_words(map)
|
||||
# else
|
||||
# define map_bankwidth(map) 16
|
||||
# define map_bankwidth_is_large(map) (1)
|
||||
# define map_words(map) map_calc_words(map)
|
||||
# endif
|
||||
#define map_bankwidth_is_16(map) (map_bankwidth(map) == 16)
|
||||
#undef MAX_MAP_BANKWIDTH
|
||||
#define MAX_MAP_BANKWIDTH 16
|
||||
#else
|
||||
#define map_bankwidth_is_16(map) (0)
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_MTD_MAP_BANK_WIDTH_32
|
||||
# ifdef map_bankwidth
|
||||
# undef map_bankwidth
|
||||
# define map_bankwidth(map) ((map)->bankwidth)
|
||||
# undef map_bankwidth_is_large
|
||||
# define map_bankwidth_is_large(map) (map_bankwidth(map) > BITS_PER_LONG/8)
|
||||
# undef map_words
|
||||
# define map_words(map) map_calc_words(map)
|
||||
# else
|
||||
# define map_bankwidth(map) 32
|
||||
# define map_bankwidth_is_large(map) (1)
|
||||
# define map_words(map) map_calc_words(map)
|
||||
# endif
|
||||
#define map_bankwidth_is_32(map) (map_bankwidth(map) == 32)
|
||||
#undef MAX_MAP_BANKWIDTH
|
||||
#define MAX_MAP_BANKWIDTH 32
|
||||
#else
|
||||
#define map_bankwidth_is_32(map) (0)
|
||||
#endif
|
||||
|
||||
#ifndef map_bankwidth
|
||||
#error "No bus width supported. What's the point?"
|
||||
#endif
|
||||
|
||||
static inline int map_bankwidth_supported(int w)
|
||||
{
|
||||
switch (w) {
|
||||
#ifdef CONFIG_MTD_MAP_BANK_WIDTH_1
|
||||
case 1:
|
||||
#endif
|
||||
#ifdef CONFIG_MTD_MAP_BANK_WIDTH_2
|
||||
case 2:
|
||||
#endif
|
||||
#ifdef CONFIG_MTD_MAP_BANK_WIDTH_4
|
||||
case 4:
|
||||
#endif
|
||||
#ifdef CONFIG_MTD_MAP_BANK_WIDTH_8
|
||||
case 8:
|
||||
#endif
|
||||
#ifdef CONFIG_MTD_MAP_BANK_WIDTH_16
|
||||
case 16:
|
||||
#endif
|
||||
#ifdef CONFIG_MTD_MAP_BANK_WIDTH_32
|
||||
case 32:
|
||||
#endif
|
||||
return 1;
|
||||
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
#define MAX_MAP_LONGS ( ((MAX_MAP_BANKWIDTH*8) + BITS_PER_LONG - 1) / BITS_PER_LONG )
|
||||
|
||||
typedef union {
|
||||
unsigned long x[MAX_MAP_LONGS];
|
||||
} map_word;
|
||||
|
||||
/* The map stuff is very simple. You fill in your struct map_info with
|
||||
a handful of routines for accessing the device, making sure they handle
|
||||
paging etc. correctly if your device needs it. Then you pass it off
|
||||
to a chip probe routine -- either JEDEC or CFI probe or both -- via
|
||||
do_map_probe(). If a chip is recognised, the probe code will invoke the
|
||||
appropriate chip driver (if present) and return a struct mtd_info.
|
||||
At which point, you fill in the mtd->module with your own module
|
||||
address, and register it with the MTD core code. Or you could partition
|
||||
it and register the partitions instead, or keep it for your own private
|
||||
use; whatever.
|
||||
|
||||
The mtd->priv field will point to the struct map_info, and any further
|
||||
private data required by the chip driver is linked from the
|
||||
mtd->priv->fldrv_priv field. This allows the map driver to get at
|
||||
the destructor function map->fldrv_destroy() when it's tired
|
||||
of living.
|
||||
*/
|
||||
|
||||
struct map_info {
|
||||
char *name;
|
||||
unsigned long size;
|
||||
resource_size_t phys;
|
||||
#define NO_XIP (-1UL)
|
||||
|
||||
void __iomem *virt;
|
||||
void *cached;
|
||||
|
||||
int bankwidth; /* in octets. This isn't necessarily the width
|
||||
of actual bus cycles -- it's the repeat interval
|
||||
in bytes, before you are talking to the first chip again.
|
||||
*/
|
||||
|
||||
#ifdef CONFIG_MTD_COMPLEX_MAPPINGS
|
||||
map_word (*read)(struct map_info *, unsigned long);
|
||||
void (*copy_from)(struct map_info *, void *, unsigned long, ssize_t);
|
||||
|
||||
void (*write)(struct map_info *, const map_word, unsigned long);
|
||||
void (*copy_to)(struct map_info *, unsigned long, const void *, ssize_t);
|
||||
|
||||
/* We can perhaps put in 'point' and 'unpoint' methods, if we really
|
||||
want to enable XIP for non-linear mappings. Not yet though. */
|
||||
#endif
|
||||
/* It's possible for the map driver to use cached memory in its
|
||||
copy_from implementation (and _only_ with copy_from). However,
|
||||
when the chip driver knows some flash area has changed contents,
|
||||
it will signal it to the map driver through this routine to let
|
||||
the map driver invalidate the corresponding cache as needed.
|
||||
If there is no cache to care about this can be set to NULL. */
|
||||
void (*inval_cache)(struct map_info *, unsigned long, ssize_t);
|
||||
|
||||
/* set_vpp() must handle being reentered -- enable, enable, disable
|
||||
must leave it enabled. */
|
||||
void (*set_vpp)(struct map_info *, int);
|
||||
|
||||
unsigned long map_priv_1;
|
||||
unsigned long map_priv_2;
|
||||
void *fldrv_priv;
|
||||
struct mtd_chip_driver *fldrv;
|
||||
};
|
||||
|
||||
struct mtd_chip_driver {
|
||||
struct mtd_info *(*probe)(struct map_info *map);
|
||||
void (*destroy)(struct mtd_info *);
|
||||
struct module *module;
|
||||
char *name;
|
||||
struct list_head list;
|
||||
};
|
||||
|
||||
void register_mtd_chip_driver(struct mtd_chip_driver *);
|
||||
void unregister_mtd_chip_driver(struct mtd_chip_driver *);
|
||||
|
||||
struct mtd_info *do_map_probe(const char *name, struct map_info *map);
|
||||
void map_destroy(struct mtd_info *mtd);
|
||||
|
||||
#define ENABLE_VPP(map) do { if(map->set_vpp) map->set_vpp(map, 1); } while(0)
|
||||
#define DISABLE_VPP(map) do { if(map->set_vpp) map->set_vpp(map, 0); } while(0)
|
||||
|
||||
#define INVALIDATE_CACHED_RANGE(map, from, size) \
|
||||
do { if(map->inval_cache) map->inval_cache(map, from, size); } while(0)
|
||||
|
||||
|
||||
static inline int map_word_equal(struct map_info *map, map_word val1, map_word val2)
|
||||
{
|
||||
int i;
|
||||
for (i=0; i<map_words(map); i++) {
|
||||
if (val1.x[i] != val2.x[i])
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
|
||||
static inline map_word map_word_and(struct map_info *map, map_word val1, map_word val2)
|
||||
{
|
||||
map_word r;
|
||||
int i;
|
||||
|
||||
for (i=0; i<map_words(map); i++) {
|
||||
r.x[i] = val1.x[i] & val2.x[i];
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
static inline map_word map_word_clr(struct map_info *map, map_word val1, map_word val2)
|
||||
{
|
||||
map_word r;
|
||||
int i;
|
||||
|
||||
for (i=0; i<map_words(map); i++) {
|
||||
r.x[i] = val1.x[i] & ~val2.x[i];
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
static inline map_word map_word_or(struct map_info *map, map_word val1, map_word val2)
|
||||
{
|
||||
map_word r;
|
||||
int i;
|
||||
|
||||
for (i=0; i<map_words(map); i++) {
|
||||
r.x[i] = val1.x[i] | val2.x[i];
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
#define map_word_andequal(m, a, b, z) map_word_equal(m, z, map_word_and(m, a, b))
|
||||
|
||||
static inline int map_word_bitsset(struct map_info *map, map_word val1, map_word val2)
|
||||
{
|
||||
int i;
|
||||
|
||||
for (i=0; i<map_words(map); i++) {
|
||||
if (val1.x[i] & val2.x[i])
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static inline map_word map_word_load(struct map_info *map, const void *ptr)
|
||||
{
|
||||
map_word r;
|
||||
|
||||
if (map_bankwidth_is_1(map))
|
||||
r.x[0] = *(unsigned char *)ptr;
|
||||
else if (map_bankwidth_is_2(map))
|
||||
r.x[0] = get_unaligned((uint16_t *)ptr);
|
||||
else if (map_bankwidth_is_4(map))
|
||||
r.x[0] = get_unaligned((uint32_t *)ptr);
|
||||
#if BITS_PER_LONG >= 64
|
||||
else if (map_bankwidth_is_8(map))
|
||||
r.x[0] = get_unaligned((uint64_t *)ptr);
|
||||
#endif
|
||||
else if (map_bankwidth_is_large(map))
|
||||
memcpy(r.x, ptr, map->bankwidth);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
static inline map_word map_word_load_partial(struct map_info *map, map_word orig, const unsigned char *buf, int start, int len)
|
||||
{
|
||||
int i;
|
||||
|
||||
if (map_bankwidth_is_large(map)) {
|
||||
char *dest = (char *)&orig;
|
||||
memcpy(dest+start, buf, len);
|
||||
} else {
|
||||
for (i=start; i < start+len; i++) {
|
||||
int bitpos;
|
||||
#ifdef __LITTLE_ENDIAN
|
||||
bitpos = i*8;
|
||||
#else /* __BIG_ENDIAN */
|
||||
bitpos = (map_bankwidth(map)-1-i)*8;
|
||||
#endif
|
||||
orig.x[0] &= ~(0xff << bitpos);
|
||||
orig.x[0] |= buf[i-start] << bitpos;
|
||||
}
|
||||
}
|
||||
return orig;
|
||||
}
|
||||
|
||||
#if BITS_PER_LONG < 64
|
||||
#define MAP_FF_LIMIT 4
|
||||
#else
|
||||
#define MAP_FF_LIMIT 8
|
||||
#endif
|
||||
|
||||
static inline map_word map_word_ff(struct map_info *map)
|
||||
{
|
||||
map_word r;
|
||||
int i;
|
||||
|
||||
if (map_bankwidth(map) < MAP_FF_LIMIT) {
|
||||
int bw = 8 * map_bankwidth(map);
|
||||
r.x[0] = (1 << bw) - 1;
|
||||
} else {
|
||||
for (i=0; i<map_words(map); i++)
|
||||
r.x[i] = ~0UL;
|
||||
}
|
||||
return r;
|
||||
}
|
||||
|
||||
static inline map_word inline_map_read(struct map_info *map, unsigned long ofs)
|
||||
{
|
||||
map_word r;
|
||||
|
||||
if (map_bankwidth_is_1(map))
|
||||
r.x[0] = __raw_readb(map->virt + ofs);
|
||||
else if (map_bankwidth_is_2(map))
|
||||
r.x[0] = __raw_readw(map->virt + ofs);
|
||||
else if (map_bankwidth_is_4(map))
|
||||
r.x[0] = __raw_readl(map->virt + ofs);
|
||||
#if BITS_PER_LONG >= 64
|
||||
else if (map_bankwidth_is_8(map))
|
||||
r.x[0] = __raw_readq(map->virt + ofs);
|
||||
#endif
|
||||
else if (map_bankwidth_is_large(map))
|
||||
memcpy_fromio(r.x, map->virt+ofs, map->bankwidth);
|
||||
|
||||
return r;
|
||||
}
|
||||
|
||||
static inline void inline_map_write(struct map_info *map, const map_word datum, unsigned long ofs)
|
||||
{
|
||||
if (map_bankwidth_is_1(map))
|
||||
__raw_writeb(datum.x[0], map->virt + ofs);
|
||||
else if (map_bankwidth_is_2(map))
|
||||
__raw_writew(datum.x[0], map->virt + ofs);
|
||||
else if (map_bankwidth_is_4(map))
|
||||
__raw_writel(datum.x[0], map->virt + ofs);
|
||||
#if BITS_PER_LONG >= 64
|
||||
else if (map_bankwidth_is_8(map))
|
||||
__raw_writeq(datum.x[0], map->virt + ofs);
|
||||
#endif
|
||||
else if (map_bankwidth_is_large(map))
|
||||
memcpy_toio(map->virt+ofs, datum.x, map->bankwidth);
|
||||
mb();
|
||||
}
|
||||
|
||||
static inline void inline_map_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len)
|
||||
{
|
||||
if (map->cached)
|
||||
memcpy(to, (char *)map->cached + from, len);
|
||||
else
|
||||
memcpy_fromio(to, map->virt + from, len);
|
||||
}
|
||||
|
||||
static inline void inline_map_copy_to(struct map_info *map, unsigned long to, const void *from, ssize_t len)
|
||||
{
|
||||
memcpy_toio(map->virt + to, from, len);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_MTD_COMPLEX_MAPPINGS
|
||||
#define map_read(map, ofs) (map)->read(map, ofs)
|
||||
#define map_copy_from(map, to, from, len) (map)->copy_from(map, to, from, len)
|
||||
#define map_write(map, datum, ofs) (map)->write(map, datum, ofs)
|
||||
#define map_copy_to(map, to, from, len) (map)->copy_to(map, to, from, len)
|
||||
|
||||
extern void simple_map_init(struct map_info *);
|
||||
#define map_is_linear(map) (map->phys != NO_XIP)
|
||||
|
||||
#else
|
||||
#define map_read(map, ofs) inline_map_read(map, ofs)
|
||||
#define map_copy_from(map, to, from, len) inline_map_copy_from(map, to, from, len)
|
||||
#define map_write(map, datum, ofs) inline_map_write(map, datum, ofs)
|
||||
#define map_copy_to(map, to, from, len) inline_map_copy_to(map, to, from, len)
|
||||
|
||||
|
||||
#define simple_map_init(map) BUG_ON(!map_bankwidth_supported((map)->bankwidth))
|
||||
#define map_is_linear(map) ({ (void)(map); 1; })
|
||||
|
||||
#endif /* !CONFIG_MTD_COMPLEX_MAPPINGS */
|
||||
|
||||
#endif /* __LINUX_MTD_MAP_H__ */
|
||||
269
include/linux/mtd/mtd.h
Normal file
269
include/linux/mtd/mtd.h
Normal file
@@ -0,0 +1,269 @@
|
||||
/*
|
||||
* $Id: mtd.h,v 1.1.1.1 2007/06/12 07:27:16 eyryu Exp $
|
||||
*
|
||||
* Copyright (C) 1999-2003 David Woodhouse <dwmw2@infradead.org> et al.
|
||||
*
|
||||
* Released under GPL
|
||||
*/
|
||||
|
||||
#ifndef __MTD_MTD_H__
|
||||
#define __MTD_MTD_H__
|
||||
|
||||
#ifndef __KERNEL__
|
||||
#error This is a kernel header. Perhaps include mtd-user.h instead?
|
||||
#endif
|
||||
|
||||
#include <linux/types.h>
|
||||
#include <linux/module.h>
|
||||
#include <linux/uio.h>
|
||||
#include <linux/notifier.h>
|
||||
|
||||
#include <linux/mtd/compatmac.h>
|
||||
#include <mtd/mtd-abi.h>
|
||||
|
||||
#define MTD_CHAR_MAJOR 90
|
||||
#define MTD_BLOCK_MAJOR 31
|
||||
#define MAX_MTD_DEVICES 32
|
||||
|
||||
#define MTD_ERASE_PENDING 0x01
|
||||
#define MTD_ERASING 0x02
|
||||
#define MTD_ERASE_SUSPEND 0x04
|
||||
#define MTD_ERASE_DONE 0x08
|
||||
#define MTD_ERASE_FAILED 0x10
|
||||
|
||||
/* If the erase fails, fail_addr might indicate exactly which block failed. If
|
||||
fail_addr = 0xffffffff, the failure was not at the device level or was not
|
||||
specific to any particular block. */
|
||||
struct erase_info {
|
||||
struct mtd_info *mtd;
|
||||
u_int32_t addr;
|
||||
u_int32_t len;
|
||||
u_int32_t fail_addr;
|
||||
u_long time;
|
||||
u_long retries;
|
||||
u_int dev;
|
||||
u_int cell;
|
||||
void (*callback) (struct erase_info *self);
|
||||
u_long priv;
|
||||
u_char state;
|
||||
struct erase_info *next;
|
||||
};
|
||||
|
||||
struct mtd_erase_region_info {
|
||||
u_int32_t offset; /* At which this region starts, from the beginning of the MTD */
|
||||
u_int32_t erasesize; /* For this region */
|
||||
u_int32_t numblocks; /* Number of blocks of erasesize in this region */
|
||||
};
|
||||
|
||||
/*
|
||||
* oob operation modes
|
||||
*
|
||||
* MTD_OOB_PLACE: oob data are placed at the given offset
|
||||
* MTD_OOB_AUTO: oob data are automatically placed at the free areas
|
||||
* which are defined by the ecclayout
|
||||
* MTD_OOB_RAW: mode to read raw data+oob in one chunk. The oob data
|
||||
* is inserted into the data. Thats a raw image of the
|
||||
* flash contents.
|
||||
*/
|
||||
typedef enum {
|
||||
MTD_OOB_PLACE,
|
||||
MTD_OOB_AUTO,
|
||||
MTD_OOB_RAW,
|
||||
} mtd_oob_mode_t;
|
||||
|
||||
/**
|
||||
* struct mtd_oob_ops - oob operation operands
|
||||
* @mode: operation mode
|
||||
*
|
||||
* @len: number of data bytes to write/read
|
||||
*
|
||||
* @retlen: number of data bytes written/read
|
||||
*
|
||||
* @ooblen: number of oob bytes to write/read
|
||||
* @oobretlen: number of oob bytes written/read
|
||||
* @ooboffs: offset of oob data in the oob area (only relevant when
|
||||
* mode = MTD_OOB_PLACE)
|
||||
* @datbuf: data buffer - if NULL only oob data are read/written
|
||||
* @oobbuf: oob data buffer
|
||||
*
|
||||
* Note, it is allowed to read more then one OOB area at one go, but not write.
|
||||
* The interface assumes that the OOB write requests program only one page's
|
||||
* OOB area.
|
||||
*/
|
||||
struct mtd_oob_ops {
|
||||
mtd_oob_mode_t mode;
|
||||
size_t len;
|
||||
size_t retlen;
|
||||
size_t ooblen;
|
||||
size_t oobretlen;
|
||||
uint32_t ooboffs;
|
||||
uint8_t *datbuf;
|
||||
uint8_t *oobbuf;
|
||||
};
|
||||
|
||||
struct mtd_info {
|
||||
u_char type;
|
||||
u_int32_t flags;
|
||||
u_int32_t size; // Total size of the MTD
|
||||
|
||||
/* "Major" erase size for the device. Naïve users may take this
|
||||
* to be the only erase size available, or may use the more detailed
|
||||
* information below if they desire
|
||||
*/
|
||||
u_int32_t erasesize;
|
||||
/* Minimal writable flash unit size. In case of NOR flash it is 1 (even
|
||||
* though individual bits can be cleared), in case of NAND flash it is
|
||||
* one NAND page (or half, or one-fourths of it), in case of ECC-ed NOR
|
||||
* it is of ECC block size, etc. It is illegal to have writesize = 0.
|
||||
* Any driver registering a struct mtd_info must ensure a writesize of
|
||||
* 1 or larger.
|
||||
*/
|
||||
u_int32_t writesize;
|
||||
|
||||
u_int32_t oobsize; // Amount of OOB data per block (e.g. 16)
|
||||
u_int32_t oobavail; // Available OOB bytes per block
|
||||
|
||||
// Kernel-only stuff starts here.
|
||||
char *name;
|
||||
int index;
|
||||
|
||||
/* ecc layout structure pointer - read only ! */
|
||||
struct nand_ecclayout *ecclayout;
|
||||
|
||||
/* Data for variable erase regions. If numeraseregions is zero,
|
||||
* it means that the whole device has erasesize as given above.
|
||||
*/
|
||||
int numeraseregions;
|
||||
struct mtd_erase_region_info *eraseregions;
|
||||
|
||||
/* This really shouldn't be here. It can go away in 2.5 */
|
||||
u_int32_t bank_size;
|
||||
|
||||
int (*erase) (struct mtd_info *mtd, struct erase_info *instr);
|
||||
|
||||
/* This stuff for eXecute-In-Place */
|
||||
int (*point) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char **mtdbuf);
|
||||
|
||||
/* We probably shouldn't allow XIP if the unpoint isn't a NULL */
|
||||
void (*unpoint) (struct mtd_info *mtd, u_char * addr, loff_t from, size_t len);
|
||||
|
||||
|
||||
int (*read) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf);
|
||||
int (*write) (struct mtd_info *mtd, loff_t to, size_t len, size_t *retlen, const u_char *buf);
|
||||
|
||||
int (*read_oob) (struct mtd_info *mtd, loff_t from,
|
||||
struct mtd_oob_ops *ops);
|
||||
int (*write_oob) (struct mtd_info *mtd, loff_t to,
|
||||
struct mtd_oob_ops *ops);
|
||||
|
||||
/*
|
||||
* Methods to access the protection register area, present in some
|
||||
* flash devices. The user data is one time programmable but the
|
||||
* factory data is read only.
|
||||
*/
|
||||
int (*get_fact_prot_info) (struct mtd_info *mtd, struct otp_info *buf, size_t len);
|
||||
int (*read_fact_prot_reg) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf);
|
||||
int (*get_user_prot_info) (struct mtd_info *mtd, struct otp_info *buf, size_t len);
|
||||
int (*read_user_prot_reg) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf);
|
||||
int (*write_user_prot_reg) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf);
|
||||
int (*lock_user_prot_reg) (struct mtd_info *mtd, loff_t from, size_t len);
|
||||
|
||||
/* kvec-based read/write methods.
|
||||
NB: The 'count' parameter is the number of _vectors_, each of
|
||||
which contains an (ofs, len) tuple.
|
||||
*/
|
||||
int (*writev) (struct mtd_info *mtd, const struct kvec *vecs, unsigned long count, loff_t to, size_t *retlen);
|
||||
|
||||
/* Sync */
|
||||
void (*sync) (struct mtd_info *mtd);
|
||||
|
||||
/* Chip-supported device locking */
|
||||
int (*lock) (struct mtd_info *mtd, loff_t ofs, size_t len);
|
||||
int (*unlock) (struct mtd_info *mtd, loff_t ofs, size_t len);
|
||||
|
||||
/* Power Management functions */
|
||||
int (*suspend) (struct mtd_info *mtd);
|
||||
void (*resume) (struct mtd_info *mtd);
|
||||
|
||||
/* Bad block management functions */
|
||||
int (*block_isbad) (struct mtd_info *mtd, loff_t ofs);
|
||||
int (*block_markbad) (struct mtd_info *mtd, loff_t ofs);
|
||||
|
||||
struct notifier_block reboot_notifier; /* default mode before reboot */
|
||||
|
||||
/* ECC status information */
|
||||
struct mtd_ecc_stats ecc_stats;
|
||||
/* Subpage shift (NAND) */
|
||||
int subpage_sft;
|
||||
|
||||
void *priv;
|
||||
|
||||
struct module *owner;
|
||||
int usecount;
|
||||
|
||||
/* If the driver is something smart, like UBI, it may need to maintain
|
||||
* its own reference counting. The below functions are only for driver.
|
||||
* The driver may register its callbacks. These callbacks are not
|
||||
* supposed to be called by MTD users */
|
||||
int (*get_device) (struct mtd_info *mtd);
|
||||
void (*put_device) (struct mtd_info *mtd);
|
||||
};
|
||||
|
||||
|
||||
/* Kernel-side ioctl definitions */
|
||||
|
||||
extern int add_mtd_device(struct mtd_info *mtd);
|
||||
extern int del_mtd_device (struct mtd_info *mtd);
|
||||
|
||||
extern struct mtd_info *get_mtd_device(struct mtd_info *mtd, int num);
|
||||
extern struct mtd_info *get_mtd_device_nm(const char *name);
|
||||
|
||||
extern void put_mtd_device(struct mtd_info *mtd);
|
||||
|
||||
|
||||
struct mtd_notifier {
|
||||
void (*add)(struct mtd_info *mtd);
|
||||
void (*remove)(struct mtd_info *mtd);
|
||||
struct list_head list;
|
||||
};
|
||||
|
||||
|
||||
extern void register_mtd_user (struct mtd_notifier *new);
|
||||
extern int unregister_mtd_user (struct mtd_notifier *old);
|
||||
|
||||
int default_mtd_writev(struct mtd_info *mtd, const struct kvec *vecs,
|
||||
unsigned long count, loff_t to, size_t *retlen);
|
||||
|
||||
int default_mtd_readv(struct mtd_info *mtd, struct kvec *vecs,
|
||||
unsigned long count, loff_t from, size_t *retlen);
|
||||
|
||||
#ifdef CONFIG_MTD_PARTITIONS
|
||||
void mtd_erase_callback(struct erase_info *instr);
|
||||
#else
|
||||
static inline void mtd_erase_callback(struct erase_info *instr)
|
||||
{
|
||||
if (instr->callback)
|
||||
instr->callback(instr);
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Debugging macro and defines
|
||||
*/
|
||||
#define MTD_DEBUG_LEVEL0 (0) /* Quiet */
|
||||
#define MTD_DEBUG_LEVEL1 (1) /* Audible */
|
||||
#define MTD_DEBUG_LEVEL2 (2) /* Loud */
|
||||
#define MTD_DEBUG_LEVEL3 (3) /* Noisy */
|
||||
|
||||
#ifdef CONFIG_MTD_DEBUG
|
||||
#define DEBUG(n, args...) \
|
||||
do { \
|
||||
if (n <= CONFIG_MTD_DEBUG_VERBOSE) \
|
||||
printk(KERN_INFO args); \
|
||||
} while(0)
|
||||
#else /* CONFIG_MTD_DEBUG */
|
||||
#define DEBUG(n, args...) do { } while(0)
|
||||
|
||||
#endif /* CONFIG_MTD_DEBUG */
|
||||
|
||||
#endif /* __MTD_MTD_H__ */
|
||||
600
include/linux/mtd/nand.h
Normal file
600
include/linux/mtd/nand.h
Normal file
@@ -0,0 +1,600 @@
|
||||
/*
|
||||
* linux/include/linux/mtd/nand.h
|
||||
*
|
||||
* Copyright (c) 2000 David Woodhouse <dwmw2@mvhi.com>
|
||||
* Steven J. Hill <sjhill@realitydiluted.com>
|
||||
* Thomas Gleixner <tglx@linutronix.de>
|
||||
*
|
||||
* $Id: nand.h,v 1.1.1.1 2007/06/12 07:27:16 eyryu Exp $
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* Info:
|
||||
* Contains standard defines and IDs for NAND flash devices
|
||||
*
|
||||
* Changelog:
|
||||
* See git changelog.
|
||||
*/
|
||||
#ifndef __LINUX_MTD_NAND_H
|
||||
#define __LINUX_MTD_NAND_H
|
||||
|
||||
#include <linux/wait.h>
|
||||
#include <linux/spinlock.h>
|
||||
#include <linux/mtd/mtd.h>
|
||||
|
||||
struct mtd_info;
|
||||
/* Scan and identify a NAND device */
|
||||
extern int nand_scan (struct mtd_info *mtd, int max_chips);
|
||||
/* Separate phases of nand_scan(), allowing board driver to intervene
|
||||
* and override command or ECC setup according to flash type */
|
||||
extern int nand_scan_ident(struct mtd_info *mtd, int max_chips);
|
||||
extern int nand_scan_tail(struct mtd_info *mtd);
|
||||
|
||||
/* Free resources held by the NAND device */
|
||||
extern void nand_release (struct mtd_info *mtd);
|
||||
|
||||
/* Internal helper for board drivers which need to override command function */
|
||||
extern void nand_wait_ready(struct mtd_info *mtd);
|
||||
|
||||
/* The maximum number of NAND chips in an array */
|
||||
#define NAND_MAX_CHIPS 8
|
||||
|
||||
/* This constant declares the max. oobsize / page, which
|
||||
* is supported now. If you add a chip with bigger oobsize/page
|
||||
* adjust this accordingly.
|
||||
*/
|
||||
#define NAND_MAX_OOBSIZE 64
|
||||
#define NAND_MAX_PAGESIZE 2048
|
||||
|
||||
/*
|
||||
* Constants for hardware specific CLE/ALE/NCE function
|
||||
*
|
||||
* These are bits which can be or'ed to set/clear multiple
|
||||
* bits in one go.
|
||||
*/
|
||||
/* Select the chip by setting nCE to low */
|
||||
#define NAND_NCE 0x01
|
||||
/* Select the command latch by setting CLE to high */
|
||||
#define NAND_CLE 0x02
|
||||
/* Select the address latch by setting ALE to high */
|
||||
#define NAND_ALE 0x04
|
||||
|
||||
#define NAND_CTRL_CLE (NAND_NCE | NAND_CLE)
|
||||
#define NAND_CTRL_ALE (NAND_NCE | NAND_ALE)
|
||||
#define NAND_CTRL_CHANGE 0x80
|
||||
|
||||
/*
|
||||
* Standard NAND flash commands
|
||||
*/
|
||||
#define NAND_CMD_READ0 0
|
||||
#define NAND_CMD_READ1 1
|
||||
#define NAND_CMD_RNDOUT 5
|
||||
#define NAND_CMD_PAGEPROG 0x10
|
||||
#define NAND_CMD_READOOB 0x50
|
||||
#define NAND_CMD_ERASE1 0x60
|
||||
#define NAND_CMD_STATUS 0x70
|
||||
#define NAND_CMD_STATUS_MULTI 0x71
|
||||
#define NAND_CMD_SEQIN 0x80
|
||||
#define NAND_CMD_RNDIN 0x85
|
||||
#define NAND_CMD_READID 0x90
|
||||
#define NAND_CMD_ERASE2 0xd0
|
||||
#define NAND_CMD_RESET 0xff
|
||||
|
||||
/* Extended commands for large page devices */
|
||||
#define NAND_CMD_READSTART 0x30
|
||||
#define NAND_CMD_RNDOUTSTART 0xE0
|
||||
#define NAND_CMD_CACHEDPROG 0x15
|
||||
|
||||
/* Extended commands for AG-AND device */
|
||||
/*
|
||||
* Note: the command for NAND_CMD_DEPLETE1 is really 0x00 but
|
||||
* there is no way to distinguish that from NAND_CMD_READ0
|
||||
* until the remaining sequence of commands has been completed
|
||||
* so add a high order bit and mask it off in the command.
|
||||
*/
|
||||
#define NAND_CMD_DEPLETE1 0x100
|
||||
#define NAND_CMD_DEPLETE2 0x38
|
||||
#define NAND_CMD_STATUS_MULTI 0x71
|
||||
#define NAND_CMD_STATUS_ERROR 0x72
|
||||
/* multi-bank error status (banks 0-3) */
|
||||
#define NAND_CMD_STATUS_ERROR0 0x73
|
||||
#define NAND_CMD_STATUS_ERROR1 0x74
|
||||
#define NAND_CMD_STATUS_ERROR2 0x75
|
||||
#define NAND_CMD_STATUS_ERROR3 0x76
|
||||
#define NAND_CMD_STATUS_RESET 0x7f
|
||||
#define NAND_CMD_STATUS_CLEAR 0xff
|
||||
|
||||
#define NAND_CMD_NONE -1
|
||||
|
||||
/* Status bits */
|
||||
#define NAND_STATUS_FAIL 0x01
|
||||
#define NAND_STATUS_FAIL_N1 0x02
|
||||
#define NAND_STATUS_TRUE_READY 0x20
|
||||
#define NAND_STATUS_READY 0x40
|
||||
#define NAND_STATUS_WP 0x80
|
||||
|
||||
/*
|
||||
* Constants for ECC_MODES
|
||||
*/
|
||||
typedef enum {
|
||||
NAND_ECC_NONE,
|
||||
NAND_ECC_SOFT,
|
||||
NAND_ECC_HW,
|
||||
NAND_ECC_HW_SYNDROME,
|
||||
} nand_ecc_modes_t;
|
||||
|
||||
/*
|
||||
* Constants for Hardware ECC
|
||||
*/
|
||||
/* Reset Hardware ECC for read */
|
||||
#define NAND_ECC_READ 0
|
||||
/* Reset Hardware ECC for write */
|
||||
#define NAND_ECC_WRITE 1
|
||||
/* Enable Hardware ECC before syndrom is read back from flash */
|
||||
#define NAND_ECC_READSYN 2
|
||||
|
||||
/* Bit mask for flags passed to do_nand_read_ecc */
|
||||
#define NAND_GET_DEVICE 0x80
|
||||
|
||||
|
||||
/* Option constants for bizarre disfunctionality and real
|
||||
* features
|
||||
*/
|
||||
/* Chip can not auto increment pages */
|
||||
#define NAND_NO_AUTOINCR 0x00000001
|
||||
/* Buswitdh is 16 bit */
|
||||
#define NAND_BUSWIDTH_16 0x00000002
|
||||
/* Device supports partial programming without padding */
|
||||
#define NAND_NO_PADDING 0x00000004
|
||||
/* Chip has cache program function */
|
||||
#define NAND_CACHEPRG 0x00000008
|
||||
/* Chip has copy back function */
|
||||
#define NAND_COPYBACK 0x00000010
|
||||
/* AND Chip which has 4 banks and a confusing page / block
|
||||
* assignment. See Renesas datasheet for further information */
|
||||
#define NAND_IS_AND 0x00000020
|
||||
/* Chip has a array of 4 pages which can be read without
|
||||
* additional ready /busy waits */
|
||||
#define NAND_4PAGE_ARRAY 0x00000040
|
||||
/* Chip requires that BBT is periodically rewritten to prevent
|
||||
* bits from adjacent blocks from 'leaking' in altering data.
|
||||
* This happens with the Renesas AG-AND chips, possibly others. */
|
||||
#define BBT_AUTO_REFRESH 0x00000080
|
||||
/* Chip does not require ready check on read. True
|
||||
* for all large page devices, as they do not support
|
||||
* autoincrement.*/
|
||||
#define NAND_NO_READRDY 0x00000100
|
||||
/* Chip does not allow subpage writes */
|
||||
#define NAND_NO_SUBPAGE_WRITE 0x00000200
|
||||
|
||||
|
||||
/* Options valid for Samsung large page devices */
|
||||
#define NAND_SAMSUNG_LP_OPTIONS \
|
||||
(NAND_NO_PADDING | NAND_CACHEPRG | NAND_COPYBACK)
|
||||
|
||||
/* Macros to identify the above */
|
||||
#define NAND_CANAUTOINCR(chip) (!(chip->options & NAND_NO_AUTOINCR))
|
||||
#define NAND_MUST_PAD(chip) (!(chip->options & NAND_NO_PADDING))
|
||||
#define NAND_HAS_CACHEPROG(chip) ((chip->options & NAND_CACHEPRG))
|
||||
#define NAND_HAS_COPYBACK(chip) ((chip->options & NAND_COPYBACK))
|
||||
|
||||
/* Mask to zero out the chip options, which come from the id table */
|
||||
#define NAND_CHIPOPTIONS_MSK (0x0000ffff & ~NAND_NO_AUTOINCR)
|
||||
|
||||
/* Non chip related options */
|
||||
/* Use a flash based bad block table. This option is passed to the
|
||||
* default bad block table function. */
|
||||
#define NAND_USE_FLASH_BBT 0x00010000
|
||||
/* This option skips the bbt scan during initialization. */
|
||||
#define NAND_SKIP_BBTSCAN 0x00020000
|
||||
/* This option is defined if the board driver allocates its own buffers
|
||||
(e.g. because it needs them DMA-coherent */
|
||||
#define NAND_OWN_BUFFERS 0x00040000
|
||||
/* Options set by nand scan */
|
||||
/* Nand scan has allocated controller struct */
|
||||
#define NAND_CONTROLLER_ALLOC 0x80000000
|
||||
|
||||
/* Cell info constants */
|
||||
#define NAND_CI_CHIPNR_MSK 0x03
|
||||
#define NAND_CI_CELLTYPE_MSK 0x0C
|
||||
|
||||
/*
|
||||
* nand_state_t - chip states
|
||||
* Enumeration for NAND flash chip state
|
||||
*/
|
||||
typedef enum {
|
||||
FL_READY,
|
||||
FL_READING,
|
||||
FL_WRITING,
|
||||
FL_ERASING,
|
||||
FL_SYNCING,
|
||||
FL_CACHEDPRG,
|
||||
FL_PM_SUSPENDED,
|
||||
} nand_state_t;
|
||||
|
||||
/* Keep gcc happy */
|
||||
struct nand_chip;
|
||||
|
||||
/**
|
||||
* struct nand_hw_control - Control structure for hardware controller (e.g ECC generator) shared among independent devices
|
||||
* @lock: protection lock
|
||||
* @active: the mtd device which holds the controller currently
|
||||
* @wq: wait queue to sleep on if a NAND operation is in progress
|
||||
* used instead of the per chip wait queue when a hw controller is available
|
||||
*/
|
||||
struct nand_hw_control {
|
||||
spinlock_t lock;
|
||||
struct nand_chip *active;
|
||||
wait_queue_head_t wq;
|
||||
};
|
||||
|
||||
/**
|
||||
* struct nand_ecc_ctrl - Control structure for ecc
|
||||
* @mode: ecc mode
|
||||
* @steps: number of ecc steps per page
|
||||
* @size: data bytes per ecc step
|
||||
* @bytes: ecc bytes per step
|
||||
* @total: total number of ecc bytes per page
|
||||
* @prepad: padding information for syndrome based ecc generators
|
||||
* @postpad: padding information for syndrome based ecc generators
|
||||
* @layout: ECC layout control struct pointer
|
||||
* @hwctl: function to control hardware ecc generator. Must only
|
||||
* be provided if an hardware ECC is available
|
||||
* @calculate: function for ecc calculation or readback from ecc hardware
|
||||
* @correct: function for ecc correction, matching to ecc generator (sw/hw)
|
||||
* @read_page_raw: function to read a raw page without ECC
|
||||
* @write_page_raw: function to write a raw page without ECC
|
||||
* @read_page: function to read a page according to the ecc generator requirements
|
||||
* @write_page: function to write a page according to the ecc generator requirements
|
||||
* @read_oob: function to read chip OOB data
|
||||
* @write_oob: function to write chip OOB data
|
||||
*/
|
||||
struct nand_ecc_ctrl {
|
||||
nand_ecc_modes_t mode;
|
||||
int steps;
|
||||
int size;
|
||||
int bytes;
|
||||
int total;
|
||||
int prepad;
|
||||
int postpad;
|
||||
struct nand_ecclayout *layout;
|
||||
void (*hwctl)(struct mtd_info *mtd, int mode);
|
||||
int (*calculate)(struct mtd_info *mtd,
|
||||
const uint8_t *dat,
|
||||
uint8_t *ecc_code);
|
||||
int (*correct)(struct mtd_info *mtd, uint8_t *dat,
|
||||
uint8_t *read_ecc,
|
||||
uint8_t *calc_ecc);
|
||||
int (*read_page_raw)(struct mtd_info *mtd,
|
||||
struct nand_chip *chip,
|
||||
uint8_t *buf);
|
||||
void (*write_page_raw)(struct mtd_info *mtd,
|
||||
struct nand_chip *chip,
|
||||
const uint8_t *buf);
|
||||
int (*read_page)(struct mtd_info *mtd,
|
||||
struct nand_chip *chip,
|
||||
uint8_t *buf);
|
||||
void (*write_page)(struct mtd_info *mtd,
|
||||
struct nand_chip *chip,
|
||||
const uint8_t *buf);
|
||||
int (*read_oob)(struct mtd_info *mtd,
|
||||
struct nand_chip *chip,
|
||||
int page,
|
||||
int sndcmd);
|
||||
int (*write_oob)(struct mtd_info *mtd,
|
||||
struct nand_chip *chip,
|
||||
int page);
|
||||
};
|
||||
|
||||
/**
|
||||
* struct nand_buffers - buffer structure for read/write
|
||||
* @ecccalc: buffer for calculated ecc
|
||||
* @ecccode: buffer for ecc read from flash
|
||||
* @databuf: buffer for data - dynamically sized
|
||||
*
|
||||
* Do not change the order of buffers. databuf and oobrbuf must be in
|
||||
* consecutive order.
|
||||
*/
|
||||
struct nand_buffers {
|
||||
uint8_t ecccalc[NAND_MAX_OOBSIZE];
|
||||
uint8_t ecccode[NAND_MAX_OOBSIZE];
|
||||
uint8_t databuf[NAND_MAX_PAGESIZE + NAND_MAX_OOBSIZE];
|
||||
};
|
||||
|
||||
/**
|
||||
* struct nand_chip - NAND Private Flash Chip Data
|
||||
* @IO_ADDR_R: [BOARDSPECIFIC] address to read the 8 I/O lines of the flash device
|
||||
* @IO_ADDR_W: [BOARDSPECIFIC] address to write the 8 I/O lines of the flash device
|
||||
* @read_byte: [REPLACEABLE] read one byte from the chip
|
||||
* @read_word: [REPLACEABLE] read one word from the chip
|
||||
* @write_buf: [REPLACEABLE] write data from the buffer to the chip
|
||||
* @read_buf: [REPLACEABLE] read data from the chip into the buffer
|
||||
* @verify_buf: [REPLACEABLE] verify buffer contents against the chip data
|
||||
* @select_chip: [REPLACEABLE] select chip nr
|
||||
* @block_bad: [REPLACEABLE] check, if the block is bad
|
||||
* @block_markbad: [REPLACEABLE] mark the block bad
|
||||
* @cmd_ctrl: [BOARDSPECIFIC] hardwarespecific funtion for controlling
|
||||
* ALE/CLE/nCE. Also used to write command and address
|
||||
* @dev_ready: [BOARDSPECIFIC] hardwarespecific function for accesing device ready/busy line
|
||||
* If set to NULL no access to ready/busy is available and the ready/busy information
|
||||
* is read from the chip status register
|
||||
* @cmdfunc: [REPLACEABLE] hardwarespecific function for writing commands to the chip
|
||||
* @waitfunc: [REPLACEABLE] hardwarespecific function for wait on ready
|
||||
* @ecc: [BOARDSPECIFIC] ecc control ctructure
|
||||
* @buffers: buffer structure for read/write
|
||||
* @hwcontrol: platform-specific hardware control structure
|
||||
* @ops: oob operation operands
|
||||
* @erase_cmd: [INTERN] erase command write function, selectable due to AND support
|
||||
* @scan_bbt: [REPLACEABLE] function to scan bad block table
|
||||
* @chip_delay: [BOARDSPECIFIC] chip dependent delay for transfering data from array to read regs (tR)
|
||||
* @wq: [INTERN] wait queue to sleep on if a NAND operation is in progress
|
||||
* @state: [INTERN] the current state of the NAND device
|
||||
* @oob_poi: poison value buffer
|
||||
* @page_shift: [INTERN] number of address bits in a page (column address bits)
|
||||
* @phys_erase_shift: [INTERN] number of address bits in a physical eraseblock
|
||||
* @bbt_erase_shift: [INTERN] number of address bits in a bbt entry
|
||||
* @chip_shift: [INTERN] number of address bits in one chip
|
||||
* @datbuf: [INTERN] internal buffer for one page + oob
|
||||
* @oobbuf: [INTERN] oob buffer for one eraseblock
|
||||
* @oobdirty: [INTERN] indicates that oob_buf must be reinitialized
|
||||
* @data_poi: [INTERN] pointer to a data buffer
|
||||
* @options: [BOARDSPECIFIC] various chip options. They can partly be set to inform nand_scan about
|
||||
* special functionality. See the defines for further explanation
|
||||
* @badblockpos: [INTERN] position of the bad block marker in the oob area
|
||||
* @cellinfo: [INTERN] MLC/multichip data from chip ident
|
||||
* @numchips: [INTERN] number of physical chips
|
||||
* @chipsize: [INTERN] the size of one chip for multichip arrays
|
||||
* @pagemask: [INTERN] page number mask = number of (pages / chip) - 1
|
||||
* @pagebuf: [INTERN] holds the pagenumber which is currently in data_buf
|
||||
* @subpagesize: [INTERN] holds the subpagesize
|
||||
* @ecclayout: [REPLACEABLE] the default ecc placement scheme
|
||||
* @bbt: [INTERN] bad block table pointer
|
||||
* @bbt_td: [REPLACEABLE] bad block table descriptor for flash lookup
|
||||
* @bbt_md: [REPLACEABLE] bad block table mirror descriptor
|
||||
* @badblock_pattern: [REPLACEABLE] bad block scan pattern used for initial bad block scan
|
||||
* @controller: [REPLACEABLE] a pointer to a hardware controller structure
|
||||
* which is shared among multiple independend devices
|
||||
* @priv: [OPTIONAL] pointer to private chip date
|
||||
* @errstat: [OPTIONAL] hardware specific function to perform additional error status checks
|
||||
* (determine if errors are correctable)
|
||||
* @write_page: [REPLACEABLE] High-level page write function
|
||||
*/
|
||||
|
||||
struct nand_chip {
|
||||
void __iomem *IO_ADDR_R;
|
||||
void __iomem *IO_ADDR_W;
|
||||
|
||||
uint8_t (*read_byte)(struct mtd_info *mtd);
|
||||
u16 (*read_word)(struct mtd_info *mtd);
|
||||
void (*write_buf)(struct mtd_info *mtd, const uint8_t *buf, int len);
|
||||
void (*read_buf)(struct mtd_info *mtd, uint8_t *buf, int len);
|
||||
int (*verify_buf)(struct mtd_info *mtd, const uint8_t *buf, int len);
|
||||
void (*select_chip)(struct mtd_info *mtd, int chip);
|
||||
int (*block_bad)(struct mtd_info *mtd, loff_t ofs, int getchip);
|
||||
int (*block_markbad)(struct mtd_info *mtd, loff_t ofs);
|
||||
void (*cmd_ctrl)(struct mtd_info *mtd, int dat,
|
||||
unsigned int ctrl);
|
||||
int (*dev_ready)(struct mtd_info *mtd);
|
||||
void (*cmdfunc)(struct mtd_info *mtd, unsigned command, int column, int page_addr);
|
||||
int (*waitfunc)(struct mtd_info *mtd, struct nand_chip *this);
|
||||
void (*erase_cmd)(struct mtd_info *mtd, int page);
|
||||
int (*scan_bbt)(struct mtd_info *mtd);
|
||||
int (*errstat)(struct mtd_info *mtd, struct nand_chip *this, int state, int status, int page);
|
||||
int (*write_page)(struct mtd_info *mtd, struct nand_chip *chip,
|
||||
const uint8_t *buf, int page, int cached, int raw);
|
||||
|
||||
int chip_delay;
|
||||
unsigned int options;
|
||||
|
||||
int page_shift;
|
||||
int phys_erase_shift;
|
||||
int bbt_erase_shift;
|
||||
int chip_shift;
|
||||
int numchips;
|
||||
unsigned long chipsize;
|
||||
int pagemask;
|
||||
int pagebuf;
|
||||
int subpagesize;
|
||||
uint8_t cellinfo;
|
||||
int badblockpos;
|
||||
|
||||
nand_state_t state;
|
||||
|
||||
uint8_t *oob_poi;
|
||||
struct nand_hw_control *controller;
|
||||
struct nand_ecclayout *ecclayout;
|
||||
|
||||
struct nand_ecc_ctrl ecc;
|
||||
struct nand_buffers *buffers;
|
||||
struct nand_hw_control hwcontrol;
|
||||
|
||||
struct mtd_oob_ops ops;
|
||||
|
||||
uint8_t *bbt;
|
||||
struct nand_bbt_descr *bbt_td;
|
||||
struct nand_bbt_descr *bbt_md;
|
||||
|
||||
struct nand_bbt_descr *badblock_pattern;
|
||||
|
||||
void *priv;
|
||||
};
|
||||
|
||||
/*
|
||||
* NAND Flash Manufacturer ID Codes
|
||||
*/
|
||||
#define NAND_MFR_TOSHIBA 0x98
|
||||
#define NAND_MFR_SAMSUNG 0xec
|
||||
#define NAND_MFR_FUJITSU 0x04
|
||||
#define NAND_MFR_NATIONAL 0x8f
|
||||
#define NAND_MFR_RENESAS 0x07
|
||||
#define NAND_MFR_STMICRO 0x20
|
||||
#define NAND_MFR_HYNIX 0xad
|
||||
|
||||
/**
|
||||
* struct nand_flash_dev - NAND Flash Device ID Structure
|
||||
* @name: Identify the device type
|
||||
* @id: device ID code
|
||||
* @pagesize: Pagesize in bytes. Either 256 or 512 or 0
|
||||
* If the pagesize is 0, then the real pagesize
|
||||
* and the eraseize are determined from the
|
||||
* extended id bytes in the chip
|
||||
* @erasesize: Size of an erase block in the flash device.
|
||||
* @chipsize: Total chipsize in Mega Bytes
|
||||
* @options: Bitfield to store chip relevant options
|
||||
*/
|
||||
struct nand_flash_dev {
|
||||
char *name;
|
||||
int id;
|
||||
unsigned long pagesize;
|
||||
unsigned long chipsize;
|
||||
unsigned long erasesize;
|
||||
unsigned long options;
|
||||
};
|
||||
|
||||
/**
|
||||
* struct nand_manufacturers - NAND Flash Manufacturer ID Structure
|
||||
* @name: Manufacturer name
|
||||
* @id: manufacturer ID code of device.
|
||||
*/
|
||||
struct nand_manufacturers {
|
||||
int id;
|
||||
char * name;
|
||||
};
|
||||
|
||||
extern struct nand_flash_dev nand_flash_ids[];
|
||||
extern struct nand_manufacturers nand_manuf_ids[];
|
||||
|
||||
/**
|
||||
* struct nand_bbt_descr - bad block table descriptor
|
||||
* @options: options for this descriptor
|
||||
* @pages: the page(s) where we find the bbt, used with option BBT_ABSPAGE
|
||||
* when bbt is searched, then we store the found bbts pages here.
|
||||
* Its an array and supports up to 8 chips now
|
||||
* @offs: offset of the pattern in the oob area of the page
|
||||
* @veroffs: offset of the bbt version counter in the oob are of the page
|
||||
* @version: version read from the bbt page during scan
|
||||
* @len: length of the pattern, if 0 no pattern check is performed
|
||||
* @maxblocks: maximum number of blocks to search for a bbt. This number of
|
||||
* blocks is reserved at the end of the device where the tables are
|
||||
* written.
|
||||
* @reserved_block_code: if non-0, this pattern denotes a reserved (rather than
|
||||
* bad) block in the stored bbt
|
||||
* @pattern: pattern to identify bad block table or factory marked good /
|
||||
* bad blocks, can be NULL, if len = 0
|
||||
*
|
||||
* Descriptor for the bad block table marker and the descriptor for the
|
||||
* pattern which identifies good and bad blocks. The assumption is made
|
||||
* that the pattern and the version count are always located in the oob area
|
||||
* of the first block.
|
||||
*/
|
||||
struct nand_bbt_descr {
|
||||
int options;
|
||||
int pages[NAND_MAX_CHIPS];
|
||||
int offs;
|
||||
int veroffs;
|
||||
uint8_t version[NAND_MAX_CHIPS];
|
||||
int len;
|
||||
int maxblocks;
|
||||
int reserved_block_code;
|
||||
uint8_t *pattern;
|
||||
};
|
||||
|
||||
/* Options for the bad block table descriptors */
|
||||
|
||||
/* The number of bits used per block in the bbt on the device */
|
||||
#define NAND_BBT_NRBITS_MSK 0x0000000F
|
||||
#define NAND_BBT_1BIT 0x00000001
|
||||
#define NAND_BBT_2BIT 0x00000002
|
||||
#define NAND_BBT_4BIT 0x00000004
|
||||
#define NAND_BBT_8BIT 0x00000008
|
||||
/* The bad block table is in the last good block of the device */
|
||||
#define NAND_BBT_LASTBLOCK 0x00000010
|
||||
/* The bbt is at the given page, else we must scan for the bbt */
|
||||
#define NAND_BBT_ABSPAGE 0x00000020
|
||||
/* The bbt is at the given page, else we must scan for the bbt */
|
||||
#define NAND_BBT_SEARCH 0x00000040
|
||||
/* bbt is stored per chip on multichip devices */
|
||||
#define NAND_BBT_PERCHIP 0x00000080
|
||||
/* bbt has a version counter at offset veroffs */
|
||||
#define NAND_BBT_VERSION 0x00000100
|
||||
/* Create a bbt if none axists */
|
||||
#define NAND_BBT_CREATE 0x00000200
|
||||
/* Search good / bad pattern through all pages of a block */
|
||||
#define NAND_BBT_SCANALLPAGES 0x00000400
|
||||
/* Scan block empty during good / bad block scan */
|
||||
#define NAND_BBT_SCANEMPTY 0x00000800
|
||||
/* Write bbt if neccecary */
|
||||
#define NAND_BBT_WRITE 0x00001000
|
||||
/* Read and write back block contents when writing bbt */
|
||||
#define NAND_BBT_SAVECONTENT 0x00002000
|
||||
/* Search good / bad pattern on the first and the second page */
|
||||
#define NAND_BBT_SCAN2NDPAGE 0x00004000
|
||||
|
||||
/* The maximum number of blocks to scan for a bbt */
|
||||
#define NAND_BBT_SCAN_MAXBLOCKS 4
|
||||
|
||||
extern int nand_scan_bbt(struct mtd_info *mtd, struct nand_bbt_descr *bd);
|
||||
extern int nand_update_bbt(struct mtd_info *mtd, loff_t offs);
|
||||
extern int nand_default_bbt(struct mtd_info *mtd);
|
||||
extern int nand_isbad_bbt(struct mtd_info *mtd, loff_t offs, int allowbbt);
|
||||
extern int nand_erase_nand(struct mtd_info *mtd, struct erase_info *instr,
|
||||
int allowbbt);
|
||||
extern int nand_do_read(struct mtd_info *mtd, loff_t from, size_t len,
|
||||
size_t * retlen, uint8_t * buf);
|
||||
|
||||
/*
|
||||
* Constants for oob configuration
|
||||
*/
|
||||
#define NAND_SMALL_BADBLOCK_POS 5
|
||||
#define NAND_LARGE_BADBLOCK_POS 0
|
||||
|
||||
/**
|
||||
* struct platform_nand_chip - chip level device structure
|
||||
* @nr_chips: max. number of chips to scan for
|
||||
* @chip_offset: chip number offset
|
||||
* @nr_partitions: number of partitions pointed to by partitions (or zero)
|
||||
* @partitions: mtd partition list
|
||||
* @chip_delay: R/B delay value in us
|
||||
* @options: Option flags, e.g. 16bit buswidth
|
||||
* @ecclayout: ecc layout info structure
|
||||
* @priv: hardware controller specific settings
|
||||
*/
|
||||
struct platform_nand_chip {
|
||||
int nr_chips;
|
||||
int chip_offset;
|
||||
int nr_partitions;
|
||||
struct mtd_partition *partitions;
|
||||
struct nand_ecclayout *ecclayout;
|
||||
int chip_delay;
|
||||
unsigned int options;
|
||||
void *priv;
|
||||
};
|
||||
|
||||
/**
|
||||
* struct platform_nand_ctrl - controller level device structure
|
||||
* @hwcontrol: platform specific hardware control structure
|
||||
* @dev_ready: platform specific function to read ready/busy pin
|
||||
* @select_chip: platform specific chip select function
|
||||
* @priv: private data to transport driver specific settings
|
||||
*
|
||||
* All fields are optional and depend on the hardware driver requirements
|
||||
*/
|
||||
struct platform_nand_ctrl {
|
||||
void (*hwcontrol)(struct mtd_info *mtd, int cmd);
|
||||
int (*dev_ready)(struct mtd_info *mtd);
|
||||
void (*select_chip)(struct mtd_info *mtd, int chip);
|
||||
void *priv;
|
||||
};
|
||||
|
||||
/* Some helpers to access the data structures */
|
||||
static inline
|
||||
struct platform_nand_chip *get_platform_nandchip(struct mtd_info *mtd)
|
||||
{
|
||||
struct nand_chip *chip = mtd->priv;
|
||||
|
||||
return chip->priv;
|
||||
}
|
||||
|
||||
#endif /* __LINUX_MTD_NAND_H */
|
||||
30
include/linux/mtd/nand_ecc.h
Normal file
30
include/linux/mtd/nand_ecc.h
Normal file
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
* drivers/mtd/nand_ecc.h
|
||||
*
|
||||
* Copyright (C) 2000 Steven J. Hill (sjhill@realitydiluted.com)
|
||||
*
|
||||
* $Id: nand_ecc.h,v 1.1.1.1 2007/06/12 07:27:16 eyryu Exp $
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This file is the header for the ECC algorithm.
|
||||
*/
|
||||
|
||||
#ifndef __MTD_NAND_ECC_H__
|
||||
#define __MTD_NAND_ECC_H__
|
||||
|
||||
struct mtd_info;
|
||||
|
||||
/*
|
||||
* Calculate 3 byte ECC code for 256 byte block
|
||||
*/
|
||||
int nand_calculate_ecc(struct mtd_info *mtd, const u_char *dat, u_char *ecc_code);
|
||||
|
||||
/*
|
||||
* Detect and correct a 1 bit error for 256 byte block
|
||||
*/
|
||||
int nand_correct_data(struct mtd_info *mtd, u_char *dat, u_char *read_ecc, u_char *calc_ecc);
|
||||
|
||||
#endif /* __MTD_NAND_ECC_H__ */
|
||||
67
include/linux/mtd/ndfc.h
Normal file
67
include/linux/mtd/ndfc.h
Normal file
@@ -0,0 +1,67 @@
|
||||
/*
|
||||
* linux/include/linux/mtd/ndfc.h
|
||||
*
|
||||
* Copyright (c) 2006 Thomas Gleixner <tglx@linutronix.de>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* Info:
|
||||
* Contains defines, datastructures for ndfc nand controller
|
||||
*
|
||||
*/
|
||||
#ifndef __LINUX_MTD_NDFC_H
|
||||
#define __LINUX_MTD_NDFC_H
|
||||
|
||||
/* NDFC Register definitions */
|
||||
#define NDFC_CMD 0x00
|
||||
#define NDFC_ALE 0x04
|
||||
#define NDFC_DATA 0x08
|
||||
#define NDFC_ECC 0x10
|
||||
#define NDFC_BCFG0 0x30
|
||||
#define NDFC_BCFG1 0x34
|
||||
#define NDFC_BCFG2 0x38
|
||||
#define NDFC_BCFG3 0x3c
|
||||
#define NDFC_CCR 0x40
|
||||
#define NDFC_STAT 0x44
|
||||
#define NDFC_HWCTL 0x48
|
||||
#define NDFC_REVID 0x50
|
||||
|
||||
#define NDFC_STAT_IS_READY 0x01000000
|
||||
|
||||
#define NDFC_CCR_RESET_CE 0x80000000 /* CE Reset */
|
||||
#define NDFC_CCR_RESET_ECC 0x40000000 /* ECC Reset */
|
||||
#define NDFC_CCR_RIE 0x20000000 /* Interrupt Enable on Device Rdy */
|
||||
#define NDFC_CCR_REN 0x10000000 /* Enable wait for Rdy in LinearR */
|
||||
#define NDFC_CCR_ROMEN 0x08000000 /* Enable ROM In LinearR */
|
||||
#define NDFC_CCR_ARE 0x04000000 /* Auto-Read Enable */
|
||||
#define NDFC_CCR_BS(x) (((x) & 0x3) << 24) /* Select Bank on CE[x] */
|
||||
#define NDFC_CCR_BS_MASK 0x03000000 /* Select Bank */
|
||||
#define NDFC_CCR_ARAC0 0x00000000 /* 3 Addr, 1 Col 2 Row 512b page */
|
||||
#define NDFC_CCR_ARAC1 0x00001000 /* 4 Addr, 1 Col 3 Row 512b page */
|
||||
#define NDFC_CCR_ARAC2 0x00002000 /* 4 Addr, 2 Col 2 Row 2K page */
|
||||
#define NDFC_CCR_ARAC3 0x00003000 /* 5 Addr, 2 Col 3 Row 2K page */
|
||||
#define NDFC_CCR_ARAC_MASK 0x00003000 /* Auto-Read mode Addr Cycles */
|
||||
#define NDFC_CCR_RPG 0x0000C000 /* Auto-Read Page */
|
||||
#define NDFC_CCR_EBCC 0x00000004 /* EBC Configuration Completed */
|
||||
#define NDFC_CCR_DHC 0x00000002 /* Direct Hardware Control Enable */
|
||||
|
||||
#define NDFC_BxCFG_EN 0x80000000 /* Bank Enable */
|
||||
#define NDFC_BxCFG_CED 0x40000000 /* nCE Style */
|
||||
#define NDFC_BxCFG_SZ_MASK 0x08000000 /* Bank Size */
|
||||
#define NDFC_BxCFG_SZ_8BIT 0x00000000 /* 8bit */
|
||||
#define NDFC_BxCFG_SZ_16BIT 0x08000000 /* 16bit */
|
||||
|
||||
#define NDFC_MAX_BANKS 4
|
||||
|
||||
struct ndfc_controller_settings {
|
||||
uint32_t ccr_settings;
|
||||
uint64_t ndfc_erpn;
|
||||
};
|
||||
|
||||
struct ndfc_chip_settings {
|
||||
uint32_t bank_settings;
|
||||
};
|
||||
|
||||
#endif
|
||||
54
include/linux/mtd/nftl.h
Normal file
54
include/linux/mtd/nftl.h
Normal file
@@ -0,0 +1,54 @@
|
||||
/*
|
||||
* $Id: nftl.h,v 1.1.1.1 2007/06/12 07:27:16 eyryu Exp $
|
||||
*
|
||||
* (C) 1999-2003 David Woodhouse <dwmw2@infradead.org>
|
||||
*/
|
||||
|
||||
#ifndef __MTD_NFTL_H__
|
||||
#define __MTD_NFTL_H__
|
||||
|
||||
#include <linux/mtd/mtd.h>
|
||||
#include <linux/mtd/blktrans.h>
|
||||
|
||||
#include <mtd/nftl-user.h>
|
||||
|
||||
/* these info are used in ReplUnitTable */
|
||||
#define BLOCK_NIL 0xffff /* last block of a chain */
|
||||
#define BLOCK_FREE 0xfffe /* free block */
|
||||
#define BLOCK_NOTEXPLORED 0xfffd /* non explored block, only used during mounting */
|
||||
#define BLOCK_RESERVED 0xfffc /* bios block or bad block */
|
||||
|
||||
struct NFTLrecord {
|
||||
struct mtd_blktrans_dev mbd;
|
||||
__u16 MediaUnit, SpareMediaUnit;
|
||||
__u32 EraseSize;
|
||||
struct NFTLMediaHeader MediaHdr;
|
||||
int usecount;
|
||||
unsigned char heads;
|
||||
unsigned char sectors;
|
||||
unsigned short cylinders;
|
||||
__u16 numvunits;
|
||||
__u16 lastEUN; /* should be suppressed */
|
||||
__u16 numfreeEUNs;
|
||||
__u16 LastFreeEUN; /* To speed up finding a free EUN */
|
||||
int head,sect,cyl;
|
||||
__u16 *EUNtable; /* [numvunits]: First EUN for each virtual unit */
|
||||
__u16 *ReplUnitTable; /* [numEUNs]: ReplUnitNumber for each */
|
||||
unsigned int nb_blocks; /* number of physical blocks */
|
||||
unsigned int nb_boot_blocks; /* number of blocks used by the bios */
|
||||
struct erase_info instr;
|
||||
struct nand_ecclayout oobinfo;
|
||||
};
|
||||
|
||||
int NFTL_mount(struct NFTLrecord *s);
|
||||
int NFTL_formatblock(struct NFTLrecord *s, int block);
|
||||
|
||||
#ifndef NFTL_MAJOR
|
||||
#define NFTL_MAJOR 93
|
||||
#endif
|
||||
|
||||
#define MAX_NFTLS 16
|
||||
#define MAX_SECTORS_PER_UNIT 64
|
||||
#define NFTL_PARTN_BITS 4
|
||||
|
||||
#endif /* __MTD_NFTL_H__ */
|
||||
178
include/linux/mtd/onenand.h
Normal file
178
include/linux/mtd/onenand.h
Normal file
@@ -0,0 +1,178 @@
|
||||
/*
|
||||
* linux/include/linux/mtd/onenand.h
|
||||
*
|
||||
* Copyright (C) 2005-2007 Samsung Electronics
|
||||
* Kyungmin Park <kyungmin.park@samsung.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*/
|
||||
|
||||
#ifndef __LINUX_MTD_ONENAND_H
|
||||
#define __LINUX_MTD_ONENAND_H
|
||||
|
||||
#include <linux/spinlock.h>
|
||||
#include <linux/completion.h>
|
||||
#include <linux/mtd/onenand_regs.h>
|
||||
#include <linux/mtd/bbm.h>
|
||||
|
||||
#define MAX_BUFFERRAM 2
|
||||
|
||||
/* Scan and identify a OneNAND device */
|
||||
extern int onenand_scan(struct mtd_info *mtd, int max_chips);
|
||||
/* Free resources held by the OneNAND device */
|
||||
extern void onenand_release(struct mtd_info *mtd);
|
||||
|
||||
/*
|
||||
* onenand_state_t - chip states
|
||||
* Enumeration for OneNAND flash chip state
|
||||
*/
|
||||
typedef enum {
|
||||
FL_READY,
|
||||
FL_READING,
|
||||
FL_WRITING,
|
||||
FL_ERASING,
|
||||
FL_SYNCING,
|
||||
FL_LOCKING,
|
||||
FL_RESETING,
|
||||
FL_OTPING,
|
||||
FL_PM_SUSPENDED,
|
||||
} onenand_state_t;
|
||||
|
||||
/**
|
||||
* struct onenand_bufferram - OneNAND BufferRAM Data
|
||||
* @blockpage: block & page address in BufferRAM
|
||||
*/
|
||||
struct onenand_bufferram {
|
||||
int blockpage;
|
||||
};
|
||||
|
||||
/**
|
||||
* struct onenand_chip - OneNAND Private Flash Chip Data
|
||||
* @base: [BOARDSPECIFIC] address to access OneNAND
|
||||
* @chipsize: [INTERN] the size of one chip for multichip arrays
|
||||
* @device_id: [INTERN] device ID
|
||||
* @density_mask: chip density, used for DDP devices
|
||||
* @verstion_id: [INTERN] version ID
|
||||
* @options: [BOARDSPECIFIC] various chip options. They can
|
||||
* partly be set to inform onenand_scan about
|
||||
* @erase_shift: [INTERN] number of address bits in a block
|
||||
* @page_shift: [INTERN] number of address bits in a page
|
||||
* @page_mask: [INTERN] a page per block mask
|
||||
* @bufferram_index: [INTERN] BufferRAM index
|
||||
* @bufferram: [INTERN] BufferRAM info
|
||||
* @readw: [REPLACEABLE] hardware specific function for read short
|
||||
* @writew: [REPLACEABLE] hardware specific function for write short
|
||||
* @command: [REPLACEABLE] hardware specific function for writing
|
||||
* commands to the chip
|
||||
* @wait: [REPLACEABLE] hardware specific function for wait on ready
|
||||
* @read_bufferram: [REPLACEABLE] hardware specific function for BufferRAM Area
|
||||
* @write_bufferram: [REPLACEABLE] hardware specific function for BufferRAM Area
|
||||
* @read_word: [REPLACEABLE] hardware specific function for read
|
||||
* register of OneNAND
|
||||
* @write_word: [REPLACEABLE] hardware specific function for write
|
||||
* register of OneNAND
|
||||
* @mmcontrol: sync burst read function
|
||||
* @block_markbad: function to mark a block as bad
|
||||
* @scan_bbt: [REPLACEALBE] hardware specific function for scanning
|
||||
* Bad block Table
|
||||
* @chip_lock: [INTERN] spinlock used to protect access to this
|
||||
* structure and the chip
|
||||
* @wq: [INTERN] wait queue to sleep on if a OneNAND
|
||||
* operation is in progress
|
||||
* @state: [INTERN] the current state of the OneNAND device
|
||||
* @page_buf: [INTERN] page main data buffer
|
||||
* @oob_buf: [INTERN] page oob data buffer
|
||||
* @subpagesize: [INTERN] holds the subpagesize
|
||||
* @ecclayout: [REPLACEABLE] the default ecc placement scheme
|
||||
* @bbm: [REPLACEABLE] pointer to Bad Block Management
|
||||
* @priv: [OPTIONAL] pointer to private chip date
|
||||
*/
|
||||
struct onenand_chip {
|
||||
void __iomem *base;
|
||||
unsigned int chipsize;
|
||||
unsigned int device_id;
|
||||
unsigned int version_id;
|
||||
unsigned int density_mask;
|
||||
unsigned int options;
|
||||
|
||||
unsigned int erase_shift;
|
||||
unsigned int page_shift;
|
||||
unsigned int page_mask;
|
||||
|
||||
unsigned int bufferram_index;
|
||||
struct onenand_bufferram bufferram[MAX_BUFFERRAM];
|
||||
|
||||
int (*command)(struct mtd_info *mtd, int cmd, loff_t address, size_t len);
|
||||
int (*wait)(struct mtd_info *mtd, int state);
|
||||
int (*read_bufferram)(struct mtd_info *mtd, int area,
|
||||
unsigned char *buffer, int offset, size_t count);
|
||||
int (*write_bufferram)(struct mtd_info *mtd, int area,
|
||||
const unsigned char *buffer, int offset, size_t count);
|
||||
unsigned short (*read_word)(void __iomem *addr);
|
||||
void (*write_word)(unsigned short value, void __iomem *addr);
|
||||
void (*mmcontrol)(struct mtd_info *mtd, int sync_read);
|
||||
int (*block_markbad)(struct mtd_info *mtd, loff_t ofs);
|
||||
int (*scan_bbt)(struct mtd_info *mtd);
|
||||
|
||||
struct completion complete;
|
||||
int irq;
|
||||
|
||||
spinlock_t chip_lock;
|
||||
wait_queue_head_t wq;
|
||||
onenand_state_t state;
|
||||
unsigned char *page_buf;
|
||||
unsigned char *oob_buf;
|
||||
|
||||
int subpagesize;
|
||||
struct nand_ecclayout *ecclayout;
|
||||
|
||||
void *bbm;
|
||||
|
||||
void *priv;
|
||||
};
|
||||
|
||||
/*
|
||||
* Helper macros
|
||||
*/
|
||||
#define ONENAND_CURRENT_BUFFERRAM(this) (this->bufferram_index)
|
||||
#define ONENAND_NEXT_BUFFERRAM(this) (this->bufferram_index ^ 1)
|
||||
#define ONENAND_SET_NEXT_BUFFERRAM(this) (this->bufferram_index ^= 1)
|
||||
#define ONENAND_SET_PREV_BUFFERRAM(this) (this->bufferram_index ^= 1)
|
||||
|
||||
#define ONENAND_GET_SYS_CFG1(this) \
|
||||
(this->read_word(this->base + ONENAND_REG_SYS_CFG1))
|
||||
#define ONENAND_SET_SYS_CFG1(v, this) \
|
||||
(this->write_word(v, this->base + ONENAND_REG_SYS_CFG1))
|
||||
|
||||
#define ONENAND_IS_DDP(this) \
|
||||
(this->device_id & ONENAND_DEVICE_IS_DDP)
|
||||
|
||||
/* Check byte access in OneNAND */
|
||||
#define ONENAND_CHECK_BYTE_ACCESS(addr) (addr & 0x1)
|
||||
|
||||
/*
|
||||
* Options bits
|
||||
*/
|
||||
#define ONENAND_HAS_CONT_LOCK (0x0001)
|
||||
#define ONENAND_HAS_UNLOCK_ALL (0x0002)
|
||||
#define ONENAND_PAGEBUF_ALLOC (0x1000)
|
||||
#define ONENAND_OOBBUF_ALLOC (0x2000)
|
||||
|
||||
/*
|
||||
* OneNAND Flash Manufacturer ID Codes
|
||||
*/
|
||||
#define ONENAND_MFR_SAMSUNG 0xec
|
||||
|
||||
/**
|
||||
* struct onenand_manufacturers - NAND Flash Manufacturer ID Structure
|
||||
* @name: Manufacturer name
|
||||
* @id: manufacturer ID code of device.
|
||||
*/
|
||||
struct onenand_manufacturers {
|
||||
int id;
|
||||
char *name;
|
||||
};
|
||||
|
||||
#endif /* __LINUX_MTD_ONENAND_H */
|
||||
194
include/linux/mtd/onenand_regs.h
Normal file
194
include/linux/mtd/onenand_regs.h
Normal file
@@ -0,0 +1,194 @@
|
||||
/*
|
||||
* linux/include/linux/mtd/onenand_regs.h
|
||||
*
|
||||
* OneNAND Register header file
|
||||
*
|
||||
* Copyright (C) 2005-2007 Samsung Electronics
|
||||
* Kyungmin Park <kyungmin.park@samsung.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*/
|
||||
|
||||
#ifndef __ONENAND_REG_H
|
||||
#define __ONENAND_REG_H
|
||||
|
||||
/* Memory Address Map Translation (Word order) */
|
||||
#define ONENAND_MEMORY_MAP(x) ((x) << 1)
|
||||
|
||||
/*
|
||||
* External BufferRAM area
|
||||
*/
|
||||
#define ONENAND_BOOTRAM ONENAND_MEMORY_MAP(0x0000)
|
||||
#define ONENAND_DATARAM ONENAND_MEMORY_MAP(0x0200)
|
||||
#define ONENAND_SPARERAM ONENAND_MEMORY_MAP(0x8010)
|
||||
|
||||
/*
|
||||
* OneNAND Registers
|
||||
*/
|
||||
#define ONENAND_REG_MANUFACTURER_ID ONENAND_MEMORY_MAP(0xF000)
|
||||
#define ONENAND_REG_DEVICE_ID ONENAND_MEMORY_MAP(0xF001)
|
||||
#define ONENAND_REG_VERSION_ID ONENAND_MEMORY_MAP(0xF002)
|
||||
#define ONENAND_REG_DATA_BUFFER_SIZE ONENAND_MEMORY_MAP(0xF003)
|
||||
#define ONENAND_REG_BOOT_BUFFER_SIZE ONENAND_MEMORY_MAP(0xF004)
|
||||
#define ONENAND_REG_NUM_BUFFERS ONENAND_MEMORY_MAP(0xF005)
|
||||
#define ONENAND_REG_TECHNOLOGY ONENAND_MEMORY_MAP(0xF006)
|
||||
|
||||
#define ONENAND_REG_START_ADDRESS1 ONENAND_MEMORY_MAP(0xF100)
|
||||
#define ONENAND_REG_START_ADDRESS2 ONENAND_MEMORY_MAP(0xF101)
|
||||
#define ONENAND_REG_START_ADDRESS3 ONENAND_MEMORY_MAP(0xF102)
|
||||
#define ONENAND_REG_START_ADDRESS4 ONENAND_MEMORY_MAP(0xF103)
|
||||
#define ONENAND_REG_START_ADDRESS5 ONENAND_MEMORY_MAP(0xF104)
|
||||
#define ONENAND_REG_START_ADDRESS6 ONENAND_MEMORY_MAP(0xF105)
|
||||
#define ONENAND_REG_START_ADDRESS7 ONENAND_MEMORY_MAP(0xF106)
|
||||
#define ONENAND_REG_START_ADDRESS8 ONENAND_MEMORY_MAP(0xF107)
|
||||
|
||||
#define ONENAND_REG_START_BUFFER ONENAND_MEMORY_MAP(0xF200)
|
||||
#define ONENAND_REG_COMMAND ONENAND_MEMORY_MAP(0xF220)
|
||||
#define ONENAND_REG_SYS_CFG1 ONENAND_MEMORY_MAP(0xF221)
|
||||
#define ONENAND_REG_SYS_CFG2 ONENAND_MEMORY_MAP(0xF222)
|
||||
#define ONENAND_REG_CTRL_STATUS ONENAND_MEMORY_MAP(0xF240)
|
||||
#define ONENAND_REG_INTERRUPT ONENAND_MEMORY_MAP(0xF241)
|
||||
#define ONENAND_REG_START_BLOCK_ADDRESS ONENAND_MEMORY_MAP(0xF24C)
|
||||
#define ONENAND_REG_END_BLOCK_ADDRESS ONENAND_MEMORY_MAP(0xF24D)
|
||||
#define ONENAND_REG_WP_STATUS ONENAND_MEMORY_MAP(0xF24E)
|
||||
|
||||
#define ONENAND_REG_ECC_STATUS ONENAND_MEMORY_MAP(0xFF00)
|
||||
#define ONENAND_REG_ECC_M0 ONENAND_MEMORY_MAP(0xFF01)
|
||||
#define ONENAND_REG_ECC_S0 ONENAND_MEMORY_MAP(0xFF02)
|
||||
#define ONENAND_REG_ECC_M1 ONENAND_MEMORY_MAP(0xFF03)
|
||||
#define ONENAND_REG_ECC_S1 ONENAND_MEMORY_MAP(0xFF04)
|
||||
#define ONENAND_REG_ECC_M2 ONENAND_MEMORY_MAP(0xFF05)
|
||||
#define ONENAND_REG_ECC_S2 ONENAND_MEMORY_MAP(0xFF06)
|
||||
#define ONENAND_REG_ECC_M3 ONENAND_MEMORY_MAP(0xFF07)
|
||||
#define ONENAND_REG_ECC_S3 ONENAND_MEMORY_MAP(0xFF08)
|
||||
|
||||
/*
|
||||
* Device ID Register F001h (R)
|
||||
*/
|
||||
#define ONENAND_DEVICE_DENSITY_SHIFT (4)
|
||||
#define ONENAND_DEVICE_IS_DDP (1 << 3)
|
||||
#define ONENAND_DEVICE_IS_DEMUX (1 << 2)
|
||||
#define ONENAND_DEVICE_VCC_MASK (0x3)
|
||||
|
||||
#define ONENAND_DEVICE_DENSITY_512Mb (0x002)
|
||||
#define ONENAND_DEVICE_DENSITY_1Gb (0x003)
|
||||
|
||||
/*
|
||||
* Version ID Register F002h (R)
|
||||
*/
|
||||
#define ONENAND_VERSION_PROCESS_SHIFT (8)
|
||||
|
||||
/*
|
||||
* Start Address 1 F100h (R/W) & Start Address 2 F101h (R/W)
|
||||
*/
|
||||
#define ONENAND_DDP_SHIFT (15)
|
||||
#define ONENAND_DDP_CHIP0 (0)
|
||||
#define ONENAND_DDP_CHIP1 (1 << ONENAND_DDP_SHIFT)
|
||||
|
||||
/*
|
||||
* Start Address 8 F107h (R/W)
|
||||
*/
|
||||
#define ONENAND_FPA_MASK (0x3f)
|
||||
#define ONENAND_FPA_SHIFT (2)
|
||||
#define ONENAND_FSA_MASK (0x03)
|
||||
|
||||
/*
|
||||
* Start Buffer Register F200h (R/W)
|
||||
*/
|
||||
#define ONENAND_BSA_MASK (0x03)
|
||||
#define ONENAND_BSA_SHIFT (8)
|
||||
#define ONENAND_BSA_BOOTRAM (0 << 2)
|
||||
#define ONENAND_BSA_DATARAM0 (2 << 2)
|
||||
#define ONENAND_BSA_DATARAM1 (3 << 2)
|
||||
#define ONENAND_BSC_MASK (0x03)
|
||||
|
||||
/*
|
||||
* Command Register F220h (R/W)
|
||||
*/
|
||||
#define ONENAND_CMD_READ (0x00)
|
||||
#define ONENAND_CMD_READOOB (0x13)
|
||||
#define ONENAND_CMD_PROG (0x80)
|
||||
#define ONENAND_CMD_PROGOOB (0x1A)
|
||||
#define ONENAND_CMD_UNLOCK (0x23)
|
||||
#define ONENAND_CMD_LOCK (0x2A)
|
||||
#define ONENAND_CMD_LOCK_TIGHT (0x2C)
|
||||
#define ONENAND_CMD_UNLOCK_ALL (0x27)
|
||||
#define ONENAND_CMD_ERASE (0x94)
|
||||
#define ONENAND_CMD_RESET (0xF0)
|
||||
#define ONENAND_CMD_OTP_ACCESS (0x65)
|
||||
#define ONENAND_CMD_READID (0x90)
|
||||
|
||||
/* NOTE: Those are not *REAL* commands */
|
||||
#define ONENAND_CMD_BUFFERRAM (0x1978)
|
||||
|
||||
/*
|
||||
* System Configuration 1 Register F221h (R, R/W)
|
||||
*/
|
||||
#define ONENAND_SYS_CFG1_SYNC_READ (1 << 15)
|
||||
#define ONENAND_SYS_CFG1_BRL_7 (7 << 12)
|
||||
#define ONENAND_SYS_CFG1_BRL_6 (6 << 12)
|
||||
#define ONENAND_SYS_CFG1_BRL_5 (5 << 12)
|
||||
#define ONENAND_SYS_CFG1_BRL_4 (4 << 12)
|
||||
#define ONENAND_SYS_CFG1_BRL_3 (3 << 12)
|
||||
#define ONENAND_SYS_CFG1_BRL_10 (2 << 12)
|
||||
#define ONENAND_SYS_CFG1_BRL_9 (1 << 12)
|
||||
#define ONENAND_SYS_CFG1_BRL_8 (0 << 12)
|
||||
#define ONENAND_SYS_CFG1_BRL_SHIFT (12)
|
||||
#define ONENAND_SYS_CFG1_BL_32 (4 << 9)
|
||||
#define ONENAND_SYS_CFG1_BL_16 (3 << 9)
|
||||
#define ONENAND_SYS_CFG1_BL_8 (2 << 9)
|
||||
#define ONENAND_SYS_CFG1_BL_4 (1 << 9)
|
||||
#define ONENAND_SYS_CFG1_BL_CONT (0 << 9)
|
||||
#define ONENAND_SYS_CFG1_BL_SHIFT (9)
|
||||
#define ONENAND_SYS_CFG1_NO_ECC (1 << 8)
|
||||
#define ONENAND_SYS_CFG1_RDY (1 << 7)
|
||||
#define ONENAND_SYS_CFG1_INT (1 << 6)
|
||||
#define ONENAND_SYS_CFG1_IOBE (1 << 5)
|
||||
#define ONENAND_SYS_CFG1_RDY_CONF (1 << 4)
|
||||
|
||||
/*
|
||||
* Controller Status Register F240h (R)
|
||||
*/
|
||||
#define ONENAND_CTRL_ONGO (1 << 15)
|
||||
#define ONENAND_CTRL_LOCK (1 << 14)
|
||||
#define ONENAND_CTRL_LOAD (1 << 13)
|
||||
#define ONENAND_CTRL_PROGRAM (1 << 12)
|
||||
#define ONENAND_CTRL_ERASE (1 << 11)
|
||||
#define ONENAND_CTRL_ERROR (1 << 10)
|
||||
#define ONENAND_CTRL_RSTB (1 << 7)
|
||||
#define ONENAND_CTRL_OTP_L (1 << 6)
|
||||
#define ONENAND_CTRL_OTP_BL (1 << 5)
|
||||
|
||||
/*
|
||||
* Interrupt Status Register F241h (R)
|
||||
*/
|
||||
#define ONENAND_INT_MASTER (1 << 15)
|
||||
#define ONENAND_INT_READ (1 << 7)
|
||||
#define ONENAND_INT_WRITE (1 << 6)
|
||||
#define ONENAND_INT_ERASE (1 << 5)
|
||||
#define ONENAND_INT_RESET (1 << 4)
|
||||
#define ONENAND_INT_CLEAR (0 << 0)
|
||||
|
||||
/*
|
||||
* NAND Flash Write Protection Status Register F24Eh (R)
|
||||
*/
|
||||
#define ONENAND_WP_US (1 << 2)
|
||||
#define ONENAND_WP_LS (1 << 1)
|
||||
#define ONENAND_WP_LTS (1 << 0)
|
||||
|
||||
/*
|
||||
* ECC Status Reigser FF00h (R)
|
||||
*/
|
||||
#define ONENAND_ECC_1BIT (1 << 0)
|
||||
#define ONENAND_ECC_1BIT_ALL (0x5555)
|
||||
#define ONENAND_ECC_2BIT (1 << 1)
|
||||
#define ONENAND_ECC_2BIT_ALL (0xAAAA)
|
||||
|
||||
/*
|
||||
* One-Time Programmable (OTP)
|
||||
*/
|
||||
#define ONENAND_OTP_LOCK_OFFSET (14)
|
||||
|
||||
#endif /* __ONENAND_REG_H */
|
||||
75
include/linux/mtd/partitions.h
Normal file
75
include/linux/mtd/partitions.h
Normal file
@@ -0,0 +1,75 @@
|
||||
/*
|
||||
* MTD partitioning layer definitions
|
||||
*
|
||||
* (C) 2000 Nicolas Pitre <nico@cam.org>
|
||||
*
|
||||
* This code is GPL
|
||||
*
|
||||
* $Id: partitions.h,v 1.1.1.1 2007/06/12 07:27:16 eyryu Exp $
|
||||
*/
|
||||
|
||||
#ifndef MTD_PARTITIONS_H
|
||||
#define MTD_PARTITIONS_H
|
||||
|
||||
#include <linux/types.h>
|
||||
|
||||
|
||||
/*
|
||||
* Partition definition structure:
|
||||
*
|
||||
* An array of struct partition is passed along with a MTD object to
|
||||
* add_mtd_partitions() to create them.
|
||||
*
|
||||
* For each partition, these fields are available:
|
||||
* name: string that will be used to label the partition's MTD device.
|
||||
* size: the partition size; if defined as MTDPART_SIZ_FULL, the partition
|
||||
* will extend to the end of the master MTD device.
|
||||
* offset: absolute starting position within the master MTD device; if
|
||||
* defined as MTDPART_OFS_APPEND, the partition will start where the
|
||||
* previous one ended; if MTDPART_OFS_NXTBLK, at the next erase block.
|
||||
* mask_flags: contains flags that have to be masked (removed) from the
|
||||
* master MTD flag set for the corresponding MTD partition.
|
||||
* For example, to force a read-only partition, simply adding
|
||||
* MTD_WRITEABLE to the mask_flags will do the trick.
|
||||
*
|
||||
* Note: writeable partitions require their size and offset be
|
||||
* erasesize aligned (e.g. use MTDPART_OFS_NEXTBLK).
|
||||
*/
|
||||
|
||||
struct mtd_partition {
|
||||
char *name; /* identifier string */
|
||||
u_int32_t size; /* partition size */
|
||||
u_int32_t offset; /* offset within the master MTD space */
|
||||
u_int32_t mask_flags; /* master MTD flags to mask out for this partition */
|
||||
struct nand_ecclayout *ecclayout; /* out of band layout for this partition (NAND only)*/
|
||||
struct mtd_info **mtdp; /* pointer to store the MTD object */
|
||||
};
|
||||
|
||||
#define MTDPART_OFS_NXTBLK (-2)
|
||||
#define MTDPART_OFS_APPEND (-1)
|
||||
#define MTDPART_SIZ_FULL (0)
|
||||
|
||||
|
||||
int add_mtd_partitions(struct mtd_info *, const struct mtd_partition *, int);
|
||||
int del_mtd_partitions(struct mtd_info *);
|
||||
|
||||
/*
|
||||
* Functions dealing with the various ways of partitioning the space
|
||||
*/
|
||||
|
||||
struct mtd_part_parser {
|
||||
struct list_head list;
|
||||
struct module *owner;
|
||||
const char *name;
|
||||
int (*parse_fn)(struct mtd_info *, struct mtd_partition **, unsigned long);
|
||||
};
|
||||
|
||||
extern int register_mtd_parser(struct mtd_part_parser *parser);
|
||||
extern int deregister_mtd_parser(struct mtd_part_parser *parser);
|
||||
extern int parse_mtd_partitions(struct mtd_info *master, const char **types,
|
||||
struct mtd_partition **pparts, unsigned long origin);
|
||||
|
||||
#define put_partition_parser(p) do { module_put((p)->owner); } while(0)
|
||||
|
||||
#endif
|
||||
|
||||
53
include/linux/mtd/physmap.h
Normal file
53
include/linux/mtd/physmap.h
Normal file
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
* For boards with physically mapped flash and using
|
||||
* drivers/mtd/maps/physmap.c mapping driver.
|
||||
*
|
||||
* $Id: physmap.h,v 1.1.1.1 2007/06/12 07:27:16 eyryu Exp $
|
||||
*
|
||||
* Copyright (C) 2003 MontaVista Software Inc.
|
||||
* Author: Jun Sun, jsun@mvista.com or jsun@junsun.net
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation; either version 2 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __LINUX_MTD_PHYSMAP__
|
||||
#define __LINUX_MTD_PHYSMAP__
|
||||
|
||||
#include <linux/mtd/mtd.h>
|
||||
#include <linux/mtd/partitions.h>
|
||||
|
||||
struct map_info;
|
||||
|
||||
struct physmap_flash_data {
|
||||
unsigned int width;
|
||||
void (*set_vpp)(struct map_info *, int);
|
||||
unsigned int nr_parts;
|
||||
struct mtd_partition *parts;
|
||||
};
|
||||
|
||||
/*
|
||||
* Board needs to specify the exact mapping during their setup time.
|
||||
*/
|
||||
void physmap_configure(unsigned long addr, unsigned long size,
|
||||
int bankwidth, void (*set_vpp)(struct map_info *, int) );
|
||||
|
||||
#ifdef CONFIG_MTD_PARTITIONS
|
||||
|
||||
/*
|
||||
* Machines that wish to do flash partition may want to call this function in
|
||||
* their setup routine.
|
||||
*
|
||||
* physmap_set_partitions(mypartitions, num_parts);
|
||||
*
|
||||
* Note that one can always override this hard-coded partition with
|
||||
* command line partition (you need to enable CONFIG_MTD_CMDLINE_PARTS).
|
||||
*/
|
||||
void physmap_set_partitions(struct mtd_partition *parts, int num_parts);
|
||||
|
||||
#endif /* defined(CONFIG_MTD_PARTITIONS) */
|
||||
|
||||
#endif /* __LINUX_MTD_PHYSMAP__ */
|
||||
35
include/linux/mtd/plat-ram.h
Normal file
35
include/linux/mtd/plat-ram.h
Normal file
@@ -0,0 +1,35 @@
|
||||
/* linux/include/linux/mtd/plat-ram.h
|
||||
*
|
||||
* (c) 2004 Simtec Electronics
|
||||
* http://www.simtec.co.uk/products/SWLINUX/
|
||||
* Ben Dooks <ben@simtec.co.uk>
|
||||
*
|
||||
* Generic platform device based RAM map
|
||||
*
|
||||
* $Id: plat-ram.h,v 1.1.1.1 2007/06/12 07:27:16 eyryu Exp $
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef __LINUX_MTD_PLATRAM_H
|
||||
#define __LINUX_MTD_PLATRAM_H __FILE__
|
||||
|
||||
#define PLATRAM_RO (0)
|
||||
#define PLATRAM_RW (1)
|
||||
|
||||
struct platdata_mtd_ram {
|
||||
char *mapname;
|
||||
char **probes;
|
||||
struct mtd_partition *partitions;
|
||||
int nr_partitions;
|
||||
int bankwidth;
|
||||
|
||||
/* control callbacks */
|
||||
|
||||
void (*set_rw)(struct device *dev, int to);
|
||||
};
|
||||
|
||||
#endif /* __LINUX_MTD_PLATRAM_H */
|
||||
79
include/linux/mtd/pmc551.h
Normal file
79
include/linux/mtd/pmc551.h
Normal file
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* $Id: pmc551.h,v 1.1.1.1 2007/06/12 07:27:16 eyryu Exp $
|
||||
*
|
||||
* PMC551 PCI Mezzanine Ram Device
|
||||
*
|
||||
* Author:
|
||||
* Mark Ferrell
|
||||
* Copyright 1999,2000 Nortel Networks
|
||||
*
|
||||
* License:
|
||||
* As part of this driver was derrived from the slram.c driver it falls
|
||||
* under the same license, which is GNU General Public License v2
|
||||
*/
|
||||
|
||||
#ifndef __MTD_PMC551_H__
|
||||
#define __MTD_PMC551_H__
|
||||
|
||||
#include <linux/mtd/mtd.h>
|
||||
|
||||
#define PMC551_VERSION "$Id: pmc551.h,v 1.1.1.1 2007/06/12 07:27:16 eyryu Exp $\n"\
|
||||
"Ramix PMC551 PCI Mezzanine Ram Driver. (C) 1999,2000 Nortel Networks.\n"
|
||||
|
||||
/*
|
||||
* Our personal and private information
|
||||
*/
|
||||
struct mypriv {
|
||||
struct pci_dev *dev;
|
||||
u_char *start;
|
||||
u32 base_map0;
|
||||
u32 curr_map0;
|
||||
u32 asize;
|
||||
struct mtd_info *nextpmc551;
|
||||
};
|
||||
|
||||
/*
|
||||
* Function Prototypes
|
||||
*/
|
||||
static int pmc551_erase(struct mtd_info *, struct erase_info *);
|
||||
static void pmc551_unpoint(struct mtd_info *, u_char *, loff_t, size_t);
|
||||
static int pmc551_point (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char **mtdbuf);
|
||||
static int pmc551_read(struct mtd_info *, loff_t, size_t, size_t *, u_char *);
|
||||
static int pmc551_write(struct mtd_info *, loff_t, size_t, size_t *, const u_char *);
|
||||
|
||||
|
||||
/*
|
||||
* Define the PCI ID's if the kernel doesn't define them for us
|
||||
*/
|
||||
#ifndef PCI_VENDOR_ID_V3_SEMI
|
||||
#define PCI_VENDOR_ID_V3_SEMI 0x11b0
|
||||
#endif
|
||||
|
||||
#ifndef PCI_DEVICE_ID_V3_SEMI_V370PDC
|
||||
#define PCI_DEVICE_ID_V3_SEMI_V370PDC 0x0200
|
||||
#endif
|
||||
|
||||
|
||||
#define PMC551_PCI_MEM_MAP0 0x50
|
||||
#define PMC551_PCI_MEM_MAP1 0x54
|
||||
#define PMC551_PCI_MEM_MAP_MAP_ADDR_MASK 0x3ff00000
|
||||
#define PMC551_PCI_MEM_MAP_APERTURE_MASK 0x000000f0
|
||||
#define PMC551_PCI_MEM_MAP_REG_EN 0x00000002
|
||||
#define PMC551_PCI_MEM_MAP_ENABLE 0x00000001
|
||||
|
||||
#define PMC551_SDRAM_MA 0x60
|
||||
#define PMC551_SDRAM_CMD 0x62
|
||||
#define PMC551_DRAM_CFG 0x64
|
||||
#define PMC551_SYS_CTRL_REG 0x78
|
||||
|
||||
#define PMC551_DRAM_BLK0 0x68
|
||||
#define PMC551_DRAM_BLK1 0x6c
|
||||
#define PMC551_DRAM_BLK2 0x70
|
||||
#define PMC551_DRAM_BLK3 0x74
|
||||
#define PMC551_DRAM_BLK_GET_SIZE(x) (524288<<((x>>4)&0x0f))
|
||||
#define PMC551_DRAM_BLK_SET_COL_MUX(x,v) (((x) & ~0x00007000) | (((v) & 0x7) << 12))
|
||||
#define PMC551_DRAM_BLK_SET_ROW_MUX(x,v) (((x) & ~0x00000f00) | (((v) & 0xf) << 8))
|
||||
|
||||
|
||||
#endif /* __MTD_PMC551_H__ */
|
||||
|
||||
202
include/linux/mtd/ubi.h
Normal file
202
include/linux/mtd/ubi.h
Normal file
@@ -0,0 +1,202 @@
|
||||
/*
|
||||
* Copyright (c) International Business Machines Corp., 2006
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
|
||||
* the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
*
|
||||
* Author: Artem Bityutskiy (Битюцкий Артём)
|
||||
*/
|
||||
|
||||
#ifndef __LINUX_UBI_H__
|
||||
#define __LINUX_UBI_H__
|
||||
|
||||
#include <asm/ioctl.h>
|
||||
#include <linux/types.h>
|
||||
#include <mtd/ubi-user.h>
|
||||
|
||||
/*
|
||||
* UBI data type hint constants.
|
||||
*
|
||||
* UBI_LONGTERM: long-term data
|
||||
* UBI_SHORTTERM: short-term data
|
||||
* UBI_UNKNOWN: data persistence is unknown
|
||||
*
|
||||
* These constants are used when data is written to UBI volumes in order to
|
||||
* help the UBI wear-leveling unit to find more appropriate physical
|
||||
* eraseblocks.
|
||||
*/
|
||||
enum {
|
||||
UBI_LONGTERM = 1,
|
||||
UBI_SHORTTERM,
|
||||
UBI_UNKNOWN
|
||||
};
|
||||
|
||||
/*
|
||||
* enum ubi_open_mode - UBI volume open mode constants.
|
||||
*
|
||||
* UBI_READONLY: read-only mode
|
||||
* UBI_READWRITE: read-write mode
|
||||
* UBI_EXCLUSIVE: exclusive mode
|
||||
*/
|
||||
enum {
|
||||
UBI_READONLY = 1,
|
||||
UBI_READWRITE,
|
||||
UBI_EXCLUSIVE
|
||||
};
|
||||
|
||||
/**
|
||||
* struct ubi_volume_info - UBI volume description data structure.
|
||||
* @vol_id: volume ID
|
||||
* @ubi_num: UBI device number this volume belongs to
|
||||
* @size: how many physical eraseblocks are reserved for this volume
|
||||
* @used_bytes: how many bytes of data this volume contains
|
||||
* @used_ebs: how many physical eraseblocks of this volume actually contain any
|
||||
* data
|
||||
* @vol_type: volume type (%UBI_DYNAMIC_VOLUME or %UBI_STATIC_VOLUME)
|
||||
* @corrupted: non-zero if the volume is corrupted (static volumes only)
|
||||
* @upd_marker: non-zero if the volume has update marker set
|
||||
* @alignment: volume alignment
|
||||
* @usable_leb_size: how many bytes are available in logical eraseblocks of
|
||||
* this volume
|
||||
* @name_len: volume name length
|
||||
* @name: volume name
|
||||
* @cdev: UBI volume character device major and minor numbers
|
||||
*
|
||||
* The @corrupted flag is only relevant to static volumes and is always zero
|
||||
* for dynamic ones. This is because UBI does not care about dynamic volume
|
||||
* data protection and only cares about protecting static volume data.
|
||||
*
|
||||
* The @upd_marker flag is set if the volume update operation was interrupted.
|
||||
* Before touching the volume data during the update operation, UBI first sets
|
||||
* the update marker flag for this volume. If the volume update operation was
|
||||
* further interrupted, the update marker indicates this. If the update marker
|
||||
* is set, the contents of the volume is certainly damaged and a new volume
|
||||
* update operation has to be started.
|
||||
*
|
||||
* To put it differently, @corrupted and @upd_marker fields have different
|
||||
* semantics:
|
||||
* o the @corrupted flag means that this static volume is corrupted for some
|
||||
* reasons, but not because an interrupted volume update
|
||||
* o the @upd_marker field means that the volume is damaged because of an
|
||||
* interrupted update operation.
|
||||
*
|
||||
* I.e., the @corrupted flag is never set if the @upd_marker flag is set.
|
||||
*
|
||||
* The @used_bytes and @used_ebs fields are only really needed for static
|
||||
* volumes and contain the number of bytes stored in this static volume and how
|
||||
* many eraseblock this data occupies. In case of dynamic volumes, the
|
||||
* @used_bytes field is equivalent to @size*@usable_leb_size, and the @used_ebs
|
||||
* field is equivalent to @size.
|
||||
*
|
||||
* In general, logical eraseblock size is a property of the UBI device, not
|
||||
* of the UBI volume. Indeed, the logical eraseblock size depends on the
|
||||
* physical eraseblock size and on how much bytes UBI headers consume. But
|
||||
* because of the volume alignment (@alignment), the usable size of logical
|
||||
* eraseblocks if a volume may be less. The following equation is true:
|
||||
* @usable_leb_size = LEB size - (LEB size mod @alignment),
|
||||
* where LEB size is the logical eraseblock size defined by the UBI device.
|
||||
*
|
||||
* The alignment is multiple to the minimal flash input/output unit size or %1
|
||||
* if all the available space is used.
|
||||
*
|
||||
* To put this differently, alignment may be considered is a way to change
|
||||
* volume logical eraseblock sizes.
|
||||
*/
|
||||
struct ubi_volume_info {
|
||||
int ubi_num;
|
||||
int vol_id;
|
||||
int size;
|
||||
long long used_bytes;
|
||||
int used_ebs;
|
||||
int vol_type;
|
||||
int corrupted;
|
||||
int upd_marker;
|
||||
int alignment;
|
||||
int usable_leb_size;
|
||||
int name_len;
|
||||
const char *name;
|
||||
dev_t cdev;
|
||||
};
|
||||
|
||||
/**
|
||||
* struct ubi_device_info - UBI device description data structure.
|
||||
* @ubi_num: ubi device number
|
||||
* @leb_size: logical eraseblock size on this UBI device
|
||||
* @min_io_size: minimal I/O unit size
|
||||
* @ro_mode: if this device is in read-only mode
|
||||
* @cdev: UBI character device major and minor numbers
|
||||
*
|
||||
* Note, @leb_size is the logical eraseblock size offered by the UBI device.
|
||||
* Volumes of this UBI device may have smaller logical eraseblock size if their
|
||||
* alignment is not equivalent to %1.
|
||||
*/
|
||||
struct ubi_device_info {
|
||||
int ubi_num;
|
||||
int leb_size;
|
||||
int min_io_size;
|
||||
int ro_mode;
|
||||
dev_t cdev;
|
||||
};
|
||||
|
||||
/* UBI descriptor given to users when they open UBI volumes */
|
||||
struct ubi_volume_desc;
|
||||
|
||||
int ubi_get_device_info(int ubi_num, struct ubi_device_info *di);
|
||||
void ubi_get_volume_info(struct ubi_volume_desc *desc,
|
||||
struct ubi_volume_info *vi);
|
||||
struct ubi_volume_desc *ubi_open_volume(int ubi_num, int vol_id, int mode);
|
||||
struct ubi_volume_desc *ubi_open_volume_nm(int ubi_num, const char *name,
|
||||
int mode);
|
||||
void ubi_close_volume(struct ubi_volume_desc *desc);
|
||||
int ubi_leb_read(struct ubi_volume_desc *desc, int lnum, char *buf, int offset,
|
||||
int len, int check);
|
||||
int ubi_leb_write(struct ubi_volume_desc *desc, int lnum, const void *buf,
|
||||
int offset, int len, int dtype);
|
||||
int ubi_leb_change(struct ubi_volume_desc *desc, int lnum, const void *buf,
|
||||
int len, int dtype);
|
||||
int ubi_leb_erase(struct ubi_volume_desc *desc, int lnum);
|
||||
int ubi_leb_unmap(struct ubi_volume_desc *desc, int lnum);
|
||||
int ubi_is_mapped(struct ubi_volume_desc *desc, int lnum);
|
||||
|
||||
/*
|
||||
* This function is the same as the 'ubi_leb_read()' function, but it does not
|
||||
* provide the checking capability.
|
||||
*/
|
||||
static inline int ubi_read(struct ubi_volume_desc *desc, int lnum, char *buf,
|
||||
int offset, int len)
|
||||
{
|
||||
return ubi_leb_read(desc, lnum, buf, offset, len, 0);
|
||||
}
|
||||
|
||||
/*
|
||||
* This function is the same as the 'ubi_leb_write()' functions, but it does
|
||||
* not have the data type argument.
|
||||
*/
|
||||
static inline int ubi_write(struct ubi_volume_desc *desc, int lnum,
|
||||
const void *buf, int offset, int len)
|
||||
{
|
||||
return ubi_leb_write(desc, lnum, buf, offset, len, UBI_UNKNOWN);
|
||||
}
|
||||
|
||||
/*
|
||||
* This function is the same as the 'ubi_leb_change()' functions, but it does
|
||||
* not have the data type argument.
|
||||
*/
|
||||
static inline int ubi_change(struct ubi_volume_desc *desc, int lnum,
|
||||
const void *buf, int len)
|
||||
{
|
||||
return ubi_leb_change(desc, lnum, buf, len, UBI_UNKNOWN);
|
||||
}
|
||||
|
||||
#endif /* !__LINUX_UBI_H__ */
|
||||
101
include/linux/mtd/xip.h
Normal file
101
include/linux/mtd/xip.h
Normal file
@@ -0,0 +1,101 @@
|
||||
/*
|
||||
* MTD primitives for XIP support
|
||||
*
|
||||
* Author: Nicolas Pitre
|
||||
* Created: Nov 2, 2004
|
||||
* Copyright: (C) 2004 MontaVista Software, Inc.
|
||||
*
|
||||
* This XIP support for MTD has been loosely inspired
|
||||
* by an earlier patch authored by David Woodhouse.
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* $Id: xip.h,v 1.1.1.1 2007/06/12 07:27:16 eyryu Exp $
|
||||
*/
|
||||
|
||||
#ifndef __LINUX_MTD_XIP_H__
|
||||
#define __LINUX_MTD_XIP_H__
|
||||
|
||||
|
||||
#ifdef CONFIG_MTD_XIP
|
||||
|
||||
/*
|
||||
* We really don't want gcc to guess anything.
|
||||
* We absolutely _need_ proper inlining.
|
||||
*/
|
||||
#include <linux/compiler.h>
|
||||
|
||||
/*
|
||||
* Function that are modifying the flash state away from array mode must
|
||||
* obviously not be running from flash. The __xipram is therefore marking
|
||||
* those functions so they get relocated to ram.
|
||||
*/
|
||||
#define __xipram noinline __attribute__ ((__section__ (".data")))
|
||||
|
||||
/*
|
||||
* Each architecture has to provide the following macros. They must access
|
||||
* the hardware directly and not rely on any other (XIP) functions since they
|
||||
* won't be available when used (flash not in array mode).
|
||||
*
|
||||
* xip_irqpending()
|
||||
*
|
||||
* return non zero when any hardware interrupt is pending.
|
||||
*
|
||||
* xip_currtime()
|
||||
*
|
||||
* return a platform specific time reference to be used with
|
||||
* xip_elapsed_since().
|
||||
*
|
||||
* xip_elapsed_since(x)
|
||||
*
|
||||
* return in usecs the elapsed timebetween now and the reference x as
|
||||
* returned by xip_currtime().
|
||||
*
|
||||
* note 1: convertion to usec can be approximated, as long as the
|
||||
* returned value is <= the real elapsed time.
|
||||
* note 2: this should be able to cope with a few seconds without
|
||||
* overflowing.
|
||||
*
|
||||
* xip_iprefetch()
|
||||
*
|
||||
* Macro to fill instruction prefetch
|
||||
* e.g. a series of nops: asm volatile (".rep 8; nop; .endr");
|
||||
*/
|
||||
|
||||
#include <asm/mtd-xip.h>
|
||||
|
||||
#ifndef xip_irqpending
|
||||
|
||||
#warning "missing IRQ and timer primitives for XIP MTD support"
|
||||
#warning "some of the XIP MTD support code will be disabled"
|
||||
#warning "your system will therefore be unresponsive when writing or erasing flash"
|
||||
|
||||
#define xip_irqpending() (0)
|
||||
#define xip_currtime() (0)
|
||||
#define xip_elapsed_since(x) (0)
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef xip_iprefetch
|
||||
#define xip_iprefetch() do { } while (0)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* xip_cpu_idle() is used when waiting for a delay equal or larger than
|
||||
* the system timer tick period. This should put the CPU into idle mode
|
||||
* to save power and to be woken up only when some interrupts are pending.
|
||||
* This should not rely upon standard kernel code.
|
||||
*/
|
||||
#ifndef xip_cpu_idle
|
||||
#define xip_cpu_idle() do { } while (0)
|
||||
#endif
|
||||
|
||||
#else
|
||||
|
||||
#define __xipram
|
||||
|
||||
#endif /* CONFIG_MTD_XIP */
|
||||
|
||||
#endif /* __LINUX_MTD_XIP_H__ */
|
||||
Reference in New Issue
Block a user