Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  *  linux/include/linux/mtd/onenand.h
0004  *
0005  *  Copyright © 2005-2009 Samsung Electronics
0006  *  Kyungmin Park <kyungmin.park@samsung.com>
0007  */
0008 
0009 #ifndef __LINUX_MTD_ONENAND_H
0010 #define __LINUX_MTD_ONENAND_H
0011 
0012 #include <linux/spinlock.h>
0013 #include <linux/completion.h>
0014 #include <linux/mtd/flashchip.h>
0015 #include <linux/mtd/onenand_regs.h>
0016 #include <linux/mtd/bbm.h>
0017 
0018 #define MAX_DIES        2
0019 #define MAX_BUFFERRAM       2
0020 
0021 /* Scan and identify a OneNAND device */
0022 extern int onenand_scan(struct mtd_info *mtd, int max_chips);
0023 /* Free resources held by the OneNAND device */
0024 extern void onenand_release(struct mtd_info *mtd);
0025 
0026 /**
0027  * struct onenand_bufferram - OneNAND BufferRAM Data
0028  * @blockpage:      block & page address in BufferRAM
0029  */
0030 struct onenand_bufferram {
0031     int blockpage;
0032 };
0033 
0034 /**
0035  * struct onenand_chip - OneNAND Private Flash Chip Data
0036  * @base:       [BOARDSPECIFIC] address to access OneNAND
0037  * @dies:       [INTERN][FLEX-ONENAND] number of dies on chip
0038  * @boundary:       [INTERN][FLEX-ONENAND] Boundary of the dies
0039  * @diesize:        [INTERN][FLEX-ONENAND] Size of the dies
0040  * @chipsize:       [INTERN] the size of one chip for multichip arrays
0041  *          FIXME For Flex-OneNAND, chipsize holds maximum possible
0042  *          device size ie when all blocks are considered MLC
0043  * @device_id:      [INTERN] device ID
0044  * @density_mask:   chip density, used for DDP devices
0045  * @verstion_id:    [INTERN] version ID
0046  * @options:        [BOARDSPECIFIC] various chip options. They can
0047  *          partly be set to inform onenand_scan about
0048  * @erase_shift:    [INTERN] number of address bits in a block
0049  * @page_shift:     [INTERN] number of address bits in a page
0050  * @page_mask:      [INTERN] a page per block mask
0051  * @writesize:      [INTERN] a real page size
0052  * @bufferram_index:    [INTERN] BufferRAM index
0053  * @bufferram:      [INTERN] BufferRAM info
0054  * @readw:      [REPLACEABLE] hardware specific function for read short
0055  * @writew:     [REPLACEABLE] hardware specific function for write short
0056  * @command:        [REPLACEABLE] hardware specific function for writing
0057  *          commands to the chip
0058  * @wait:       [REPLACEABLE] hardware specific function for wait on ready
0059  * @bbt_wait:       [REPLACEABLE] hardware specific function for bbt wait on ready
0060  * @unlock_all:     [REPLACEABLE] hardware specific function for unlock all
0061  * @read_bufferram: [REPLACEABLE] hardware specific function for BufferRAM Area
0062  * @write_bufferram:    [REPLACEABLE] hardware specific function for BufferRAM Area
0063  * @read_word:      [REPLACEABLE] hardware specific function for read
0064  *          register of OneNAND
0065  * @write_word:     [REPLACEABLE] hardware specific function for write
0066  *          register of OneNAND
0067  * @mmcontrol:      sync burst read function
0068  * @chip_probe:     [REPLACEABLE] hardware specific function for chip probe
0069  * @block_markbad:  function to mark a block as bad
0070  * @scan_bbt:       [REPLACEALBE] hardware specific function for scanning
0071  *          Bad block Table
0072  * @chip_lock:      [INTERN] spinlock used to protect access to this
0073  *          structure and the chip
0074  * @wq:         [INTERN] wait queue to sleep on if a OneNAND
0075  *          operation is in progress
0076  * @state:      [INTERN] the current state of the OneNAND device
0077  * @page_buf:       [INTERN] page main data buffer
0078  * @oob_buf:        [INTERN] page oob data buffer
0079  * @subpagesize:    [INTERN] holds the subpagesize
0080  * @bbm:        [REPLACEABLE] pointer to Bad Block Management
0081  * @priv:       [OPTIONAL] pointer to private chip date
0082  */
0083 struct onenand_chip {
0084     void __iomem        *base;
0085     unsigned        dies;
0086     unsigned        boundary[MAX_DIES];
0087     loff_t          diesize[MAX_DIES];
0088     unsigned int        chipsize;
0089     unsigned int        device_id;
0090     unsigned int        version_id;
0091     unsigned int        technology;
0092     unsigned int        density_mask;
0093     unsigned int        options;
0094     unsigned int        badblockpos;
0095 
0096     unsigned int        erase_shift;
0097     unsigned int        page_shift;
0098     unsigned int        page_mask;
0099     unsigned int        writesize;
0100 
0101     unsigned int        bufferram_index;
0102     struct onenand_bufferram    bufferram[MAX_BUFFERRAM];
0103 
0104     int (*command)(struct mtd_info *mtd, int cmd, loff_t address, size_t len);
0105     int (*wait)(struct mtd_info *mtd, int state);
0106     int (*bbt_wait)(struct mtd_info *mtd, int state);
0107     void (*unlock_all)(struct mtd_info *mtd);
0108     int (*read_bufferram)(struct mtd_info *mtd, int area,
0109             unsigned char *buffer, int offset, size_t count);
0110     int (*write_bufferram)(struct mtd_info *mtd, int area,
0111             const unsigned char *buffer, int offset, size_t count);
0112     unsigned short (*read_word)(void __iomem *addr);
0113     void (*write_word)(unsigned short value, void __iomem *addr);
0114     void (*mmcontrol)(struct mtd_info *mtd, int sync_read);
0115     int (*chip_probe)(struct mtd_info *mtd);
0116     int (*block_markbad)(struct mtd_info *mtd, loff_t ofs);
0117     int (*scan_bbt)(struct mtd_info *mtd);
0118     int (*enable)(struct mtd_info *mtd);
0119     int (*disable)(struct mtd_info *mtd);
0120 
0121     struct completion   complete;
0122     int         irq;
0123 
0124     spinlock_t      chip_lock;
0125     wait_queue_head_t   wq;
0126     flstate_t       state;
0127     unsigned char       *page_buf;
0128     unsigned char       *oob_buf;
0129 #ifdef CONFIG_MTD_ONENAND_VERIFY_WRITE
0130     unsigned char       *verify_buf;
0131 #endif
0132 
0133     int         subpagesize;
0134 
0135     void            *bbm;
0136 
0137     void            *priv;
0138 
0139     /*
0140      * Shows that the current operation is composed
0141      * of sequence of commands. For example, cache program.
0142      * Such command status OnGo bit is checked at the end of
0143      * sequence.
0144      */
0145     unsigned int        ongoing;
0146 };
0147 
0148 /*
0149  * Helper macros
0150  */
0151 #define ONENAND_PAGES_PER_BLOCK        (1<<6)
0152 
0153 #define ONENAND_CURRENT_BUFFERRAM(this)     (this->bufferram_index)
0154 #define ONENAND_NEXT_BUFFERRAM(this)        (this->bufferram_index ^ 1)
0155 #define ONENAND_SET_NEXT_BUFFERRAM(this)    (this->bufferram_index ^= 1)
0156 #define ONENAND_SET_PREV_BUFFERRAM(this)    (this->bufferram_index ^= 1)
0157 #define ONENAND_SET_BUFFERRAM0(this)        (this->bufferram_index = 0)
0158 #define ONENAND_SET_BUFFERRAM1(this)        (this->bufferram_index = 1)
0159 
0160 #define FLEXONENAND(this)                       \
0161     (this->device_id & DEVICE_IS_FLEXONENAND)
0162 #define ONENAND_GET_SYS_CFG1(this)                  \
0163     (this->read_word(this->base + ONENAND_REG_SYS_CFG1))
0164 #define ONENAND_SET_SYS_CFG1(v, this)                   \
0165     (this->write_word(v, this->base + ONENAND_REG_SYS_CFG1))
0166 
0167 #define ONENAND_IS_DDP(this)                        \
0168     (this->device_id & ONENAND_DEVICE_IS_DDP)
0169 
0170 #define ONENAND_IS_MLC(this)                        \
0171     (this->technology & ONENAND_TECHNOLOGY_IS_MLC)
0172 
0173 #ifdef CONFIG_MTD_ONENAND_2X_PROGRAM
0174 #define ONENAND_IS_2PLANE(this)                     \
0175     (this->options & ONENAND_HAS_2PLANE)
0176 #else
0177 #define ONENAND_IS_2PLANE(this)         (0)
0178 #endif
0179 
0180 #define ONENAND_IS_CACHE_PROGRAM(this)                  \
0181     (this->options & ONENAND_HAS_CACHE_PROGRAM)
0182 
0183 #define ONENAND_IS_NOP_1(this)                      \
0184     (this->options & ONENAND_HAS_NOP_1)
0185 
0186 /* Check byte access in OneNAND */
0187 #define ONENAND_CHECK_BYTE_ACCESS(addr)     (addr & 0x1)
0188 
0189 #define ONENAND_BADBLOCK_POS        0
0190 
0191 /*
0192  * Options bits
0193  */
0194 #define ONENAND_HAS_CONT_LOCK       (0x0001)
0195 #define ONENAND_HAS_UNLOCK_ALL      (0x0002)
0196 #define ONENAND_HAS_2PLANE      (0x0004)
0197 #define ONENAND_HAS_4KB_PAGE        (0x0008)
0198 #define ONENAND_HAS_CACHE_PROGRAM   (0x0010)
0199 #define ONENAND_HAS_NOP_1       (0x0020)
0200 #define ONENAND_SKIP_UNLOCK_CHECK   (0x0100)
0201 #define ONENAND_PAGEBUF_ALLOC       (0x1000)
0202 #define ONENAND_OOBBUF_ALLOC        (0x2000)
0203 #define ONENAND_SKIP_INITIAL_UNLOCKING  (0x4000)
0204 
0205 #define ONENAND_IS_4KB_PAGE(this)                   \
0206     (this->options & ONENAND_HAS_4KB_PAGE)
0207 
0208 /*
0209  * OneNAND Flash Manufacturer ID Codes
0210  */
0211 #define ONENAND_MFR_SAMSUNG 0xec
0212 #define ONENAND_MFR_NUMONYX 0x20
0213 
0214 /**
0215  * struct onenand_manufacturers - NAND Flash Manufacturer ID Structure
0216  * @name:   Manufacturer name
0217  * @id:     manufacturer ID code of device.
0218 */
0219 struct onenand_manufacturers {
0220         int id;
0221         char *name;
0222 };
0223 
0224 int onenand_bbt_read_oob(struct mtd_info *mtd, loff_t from,
0225              struct mtd_oob_ops *ops);
0226 unsigned onenand_block(struct onenand_chip *this, loff_t addr);
0227 loff_t onenand_addr(struct onenand_chip *this, int block);
0228 int flexonenand_region(struct mtd_info *mtd, loff_t addr);
0229 
0230 struct mtd_partition;
0231 
0232 struct onenand_platform_data {
0233     void        (*mmcontrol)(struct mtd_info *mtd, int sync_read);
0234     int     (*read_bufferram)(struct mtd_info *mtd, int area,
0235             unsigned char *buffer, int offset, size_t count);
0236     struct mtd_partition *parts;
0237     unsigned int    nr_parts;
0238 };
0239 
0240 #endif  /* __LINUX_MTD_ONENAND_H */