1d7e8ce10SKyungmin Park /* 2d7e8ce10SKyungmin Park * linux/include/linux/mtd/onenand.h 3d7e8ce10SKyungmin Park * 4d7e8ce10SKyungmin Park * Copyright (C) 2005-2007 Samsung Electronics 5d7e8ce10SKyungmin Park * Kyungmin Park <kyungmin.park@samsung.com> 6d7e8ce10SKyungmin Park * 7d7e8ce10SKyungmin Park * This program is free software; you can redistribute it and/or modify 8d7e8ce10SKyungmin Park * it under the terms of the GNU General Public License version 2 as 9d7e8ce10SKyungmin Park * published by the Free Software Foundation. 10d7e8ce10SKyungmin Park */ 11d7e8ce10SKyungmin Park 12d7e8ce10SKyungmin Park #ifndef __LINUX_MTD_ONENAND_H 13d7e8ce10SKyungmin Park #define __LINUX_MTD_ONENAND_H 14d7e8ce10SKyungmin Park 15d7e8ce10SKyungmin Park #include <linux/mtd/onenand_regs.h> 16d7e8ce10SKyungmin Park 17d7e8ce10SKyungmin Park /* Note: The header order is impoertant */ 18d7e8ce10SKyungmin Park #include <onenand_uboot.h> 19d7e8ce10SKyungmin Park 20*7b15e2bbSMike Frysinger #include <linux/compat.h> 21d7e8ce10SKyungmin Park #include <linux/mtd/bbm.h> 22d7e8ce10SKyungmin Park 23cacbe919SAmul Kumar Saha #define MAX_DIES 2 24d7e8ce10SKyungmin Park #define MAX_BUFFERRAM 2 25cacbe919SAmul Kumar Saha #define MAX_ONENAND_PAGESIZE (4096 + 128) 26d7e8ce10SKyungmin Park 27d7e8ce10SKyungmin Park /* Scan and identify a OneNAND device */ 28d7e8ce10SKyungmin Park extern int onenand_scan (struct mtd_info *mtd, int max_chips); 29d7e8ce10SKyungmin Park /* Free resources held by the OneNAND device */ 30d7e8ce10SKyungmin Park extern void onenand_release (struct mtd_info *mtd); 31d7e8ce10SKyungmin Park 32d7e8ce10SKyungmin Park /** 33d7e8ce10SKyungmin Park * struct onenand_bufferram - OneNAND BufferRAM Data 34ef0921d6SKyungmin Park * @param blockpage block & page address in BufferRAM 35d7e8ce10SKyungmin Park */ 36d7e8ce10SKyungmin Park struct onenand_bufferram { 37ef0921d6SKyungmin Park int blockpage; 38d7e8ce10SKyungmin Park }; 39d7e8ce10SKyungmin Park 40d7e8ce10SKyungmin Park /** 41d7e8ce10SKyungmin Park * struct onenand_chip - OneNAND Private Flash Chip Data 42d7e8ce10SKyungmin Park * @param base [BOARDSPECIFIC] address to access OneNAND 43cacbe919SAmul Kumar Saha * @dies: [INTERN][FLEXONENAND] number of dies on chip 44cacbe919SAmul Kumar Saha * @boundary: [INTERN][FLEXONENAND] Boundary of the dies 45cacbe919SAmul Kumar Saha * @diesize: [INTERN][FLEXONENAND] Size of the dies 46d7e8ce10SKyungmin Park * @param chipsize [INTERN] the size of one chip for multichip arrays 47d7e8ce10SKyungmin Park * @param device_id [INTERN] device ID 48d7e8ce10SKyungmin Park * @param verstion_id [INTERN] version ID 49cacbe919SAmul Kumar Saha * @technology [INTERN] describes the internal NAND array technology such as SLC or MLC. 50cacbe919SAmul Kumar Saha * @density_mask: [INTERN] chip density, used for DDP devices 51d7e8ce10SKyungmin Park * @param options [BOARDSPECIFIC] various chip options. They can partly be set to inform onenand_scan about 52d7e8ce10SKyungmin Park * @param erase_shift [INTERN] number of address bits in a block 53d7e8ce10SKyungmin Park * @param page_shift [INTERN] number of address bits in a page 54d7e8ce10SKyungmin Park * @param ppb_shift [INTERN] number of address bits in a pages per block 55d7e8ce10SKyungmin Park * @param page_mask [INTERN] a page per block mask 56c45912d8SScott Wood * @param writesize [INTERN] a real page size 57d7e8ce10SKyungmin Park * @param bufferam_index [INTERN] BufferRAM index 58d7e8ce10SKyungmin Park * @param bufferam [INTERN] BufferRAM info 59d7e8ce10SKyungmin Park * @param readw [REPLACEABLE] hardware specific function for read short 60d7e8ce10SKyungmin Park * @param writew [REPLACEABLE] hardware specific function for write short 61d7e8ce10SKyungmin Park * @param command [REPLACEABLE] hardware specific function for writing commands to the chip 62d7e8ce10SKyungmin Park * @param wait [REPLACEABLE] hardware specific function for wait on ready 63d7e8ce10SKyungmin Park * @param read_bufferram [REPLACEABLE] hardware specific function for BufferRAM Area 64d7e8ce10SKyungmin Park * @param write_bufferram [REPLACEABLE] hardware specific function for BufferRAM Area 65d7e8ce10SKyungmin Park * @param chip_lock [INTERN] spinlock used to protect access to this structure and the chip 66d7e8ce10SKyungmin Park * @param wq [INTERN] wait queue to sleep on if a OneNAND operation is in progress 67d7e8ce10SKyungmin Park * @param state [INTERN] the current state of the OneNAND device 68d7e8ce10SKyungmin Park * @param autooob [REPLACEABLE] the default (auto)placement scheme 69d7e8ce10SKyungmin Park * @param priv [OPTIONAL] pointer to private chip date 70d7e8ce10SKyungmin Park */ 71d7e8ce10SKyungmin Park struct onenand_chip { 72d7e8ce10SKyungmin Park void __iomem *base; 73cacbe919SAmul Kumar Saha unsigned int dies; 74cacbe919SAmul Kumar Saha unsigned int boundary[MAX_DIES]; 75cacbe919SAmul Kumar Saha unsigned int diesize[MAX_DIES]; 76d7e8ce10SKyungmin Park unsigned int chipsize; 77d7e8ce10SKyungmin Park unsigned int device_id; 78ef0921d6SKyungmin Park unsigned int version_id; 79cacbe919SAmul Kumar Saha unsigned int technology; 80ef0921d6SKyungmin Park unsigned int density_mask; 81d7e8ce10SKyungmin Park unsigned int options; 82d7e8ce10SKyungmin Park 83d7e8ce10SKyungmin Park unsigned int erase_shift; 84d7e8ce10SKyungmin Park unsigned int page_shift; 85d7e8ce10SKyungmin Park unsigned int ppb_shift; /* Pages per block shift */ 86d7e8ce10SKyungmin Park unsigned int page_mask; 87bfd7f386SKyungmin Park unsigned int writesize; 88d7e8ce10SKyungmin Park 89d7e8ce10SKyungmin Park unsigned int bufferram_index; 90d7e8ce10SKyungmin Park struct onenand_bufferram bufferram[MAX_BUFFERRAM]; 91d7e8ce10SKyungmin Park 92d7e8ce10SKyungmin Park int (*command) (struct mtd_info *mtd, int cmd, loff_t address, 93d7e8ce10SKyungmin Park size_t len); 94d7e8ce10SKyungmin Park int (*wait) (struct mtd_info *mtd, int state); 95ef0921d6SKyungmin Park int (*bbt_wait) (struct mtd_info *mtd, int state); 96ce3277a6SKyungmin Park void (*unlock_all)(struct mtd_info *mtd); 97ef0921d6SKyungmin Park int (*read_bufferram) (struct mtd_info *mtd, loff_t addr, int area, 98d7e8ce10SKyungmin Park unsigned char *buffer, int offset, size_t count); 99ef0921d6SKyungmin Park int (*write_bufferram) (struct mtd_info *mtd, loff_t addr, int area, 100d7e8ce10SKyungmin Park const unsigned char *buffer, int offset, 101d7e8ce10SKyungmin Park size_t count); 102d7e8ce10SKyungmin Park unsigned short (*read_word) (void __iomem *addr); 103d7e8ce10SKyungmin Park void (*write_word) (unsigned short value, void __iomem *addr); 1046b3967bbSLukasz Majewski int (*chip_probe)(struct mtd_info *mtd); 105d7e8ce10SKyungmin Park void (*mmcontrol) (struct mtd_info *mtd, int sync_read); 106d438d508SKyungmin Park int (*block_markbad)(struct mtd_info *mtd, loff_t ofs); 107d438d508SKyungmin Park int (*scan_bbt)(struct mtd_info *mtd); 108d7e8ce10SKyungmin Park 109ef0921d6SKyungmin Park unsigned char *main_buf; 110ef0921d6SKyungmin Park unsigned char *spare_buf; 111ef0921d6SKyungmin Park #ifdef DONT_USE_UBOOT 112ef0921d6SKyungmin Park spinlock_t chip_lock; 113ef0921d6SKyungmin Park wait_queue_head_t wq; 114ef0921d6SKyungmin Park #endif 115d438d508SKyungmin Park int state; 116bfd7f386SKyungmin Park unsigned char *page_buf; 117bfd7f386SKyungmin Park unsigned char *oob_buf; 118d7e8ce10SKyungmin Park 119d7e8ce10SKyungmin Park struct nand_oobinfo *autooob; 1201ae39862SStefan Roese int subpagesize; 121bfd7f386SKyungmin Park struct nand_ecclayout *ecclayout; 122d7e8ce10SKyungmin Park 123d7e8ce10SKyungmin Park void *bbm; 124d7e8ce10SKyungmin Park 125d7e8ce10SKyungmin Park void *priv; 126d7e8ce10SKyungmin Park }; 127d7e8ce10SKyungmin Park 128bfd7f386SKyungmin Park /* 129bfd7f386SKyungmin Park * Helper macros 130bfd7f386SKyungmin Park */ 131d7e8ce10SKyungmin Park #define ONENAND_CURRENT_BUFFERRAM(this) (this->bufferram_index) 132d7e8ce10SKyungmin Park #define ONENAND_NEXT_BUFFERRAM(this) (this->bufferram_index ^ 1) 133d7e8ce10SKyungmin Park #define ONENAND_SET_NEXT_BUFFERRAM(this) (this->bufferram_index ^= 1) 134bfd7f386SKyungmin Park #define ONENAND_SET_PREV_BUFFERRAM(this) (this->bufferram_index ^= 1) 135bfd7f386SKyungmin Park #define ONENAND_SET_BUFFERRAM0(this) (this->bufferram_index = 0) 136bfd7f386SKyungmin Park #define ONENAND_SET_BUFFERRAM1(this) (this->bufferram_index = 1) 137bfd7f386SKyungmin Park 138cacbe919SAmul Kumar Saha #define FLEXONENAND(this) (this->device_id & DEVICE_IS_FLEXONENAND) 139cacbe919SAmul Kumar Saha #define ONENAND_IS_MLC(this) (this->technology & ONENAND_TECHNOLOGY_IS_MLC) 140bfd7f386SKyungmin Park #define ONENAND_IS_DDP(this) \ 141bfd7f386SKyungmin Park (this->device_id & ONENAND_DEVICE_IS_DDP) 142bfd7f386SKyungmin Park 143e26fd3d3SLukasz Majewski #define ONENAND_IS_4KB_PAGE(this) \ 144e26fd3d3SLukasz Majewski (this->options & ONENAND_HAS_4KB_PAGE) 145e26fd3d3SLukasz Majewski 146bfd7f386SKyungmin Park #define ONENAND_IS_2PLANE(this) (0) 147d7e8ce10SKyungmin Park 148d7e8ce10SKyungmin Park /* 149d7e8ce10SKyungmin Park * Options bits 150d7e8ce10SKyungmin Park */ 151ef0921d6SKyungmin Park #define ONENAND_HAS_CONT_LOCK (0x0001) 152ef0921d6SKyungmin Park #define ONENAND_HAS_UNLOCK_ALL (0x0002) 153ef0921d6SKyungmin Park #define ONENAND_HAS_2PLANE (0x0004) 154e26fd3d3SLukasz Majewski #define ONENAND_HAS_4KB_PAGE (0x0008) 1554678d674SMinkyu Kang #define ONENAND_RUNTIME_BADBLOCK_CHECK (0x0200) 156bfd7f386SKyungmin Park #define ONENAND_PAGEBUF_ALLOC (0x1000) 157bfd7f386SKyungmin Park #define ONENAND_OOBBUF_ALLOC (0x2000) 158d7e8ce10SKyungmin Park 159d7e8ce10SKyungmin Park /* 160d7e8ce10SKyungmin Park * OneNAND Flash Manufacturer ID Codes 161d7e8ce10SKyungmin Park */ 162456be17dSEnric Balletbo i Serra #define ONENAND_MFR_NUMONYX 0x20 163d7e8ce10SKyungmin Park #define ONENAND_MFR_SAMSUNG 0xec 164d7e8ce10SKyungmin Park 165d7e8ce10SKyungmin Park /** 166d7e8ce10SKyungmin Park * struct nand_manufacturers - NAND Flash Manufacturer ID Structure 167d7e8ce10SKyungmin Park * @param name: Manufacturer name 168d7e8ce10SKyungmin Park * @param id: manufacturer ID code of device. 169d7e8ce10SKyungmin Park */ 170d7e8ce10SKyungmin Park struct onenand_manufacturers { 171d7e8ce10SKyungmin Park int id; 172d7e8ce10SKyungmin Park char *name; 173d7e8ce10SKyungmin Park }; 174d7e8ce10SKyungmin Park 175bfd7f386SKyungmin Park int onenand_bbt_read_oob(struct mtd_info *mtd, loff_t from, 176bfd7f386SKyungmin Park struct mtd_oob_ops *ops); 177bfd7f386SKyungmin Park 178cacbe919SAmul Kumar Saha unsigned int onenand_block(struct onenand_chip *this, loff_t addr); 179cacbe919SAmul Kumar Saha int flexonenand_region(struct mtd_info *mtd, loff_t addr); 180d7e8ce10SKyungmin Park #endif /* __LINUX_MTD_ONENAND_H */ 181