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