Kyungmin Park | d7e8ce1 | 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 | d438d50 | 2008-08-13 09:11:02 +0900 | [diff] [blame] | 20 | #include <linux/mtd/compat.h> |
Kyungmin Park | d7e8ce1 | 2007-09-10 17:15:14 +0900 | [diff] [blame] | 21 | #include <linux/mtd/bbm.h> |
| 22 | |
| 23 | #define MAX_BUFFERRAM 2 |
| 24 | #define MAX_ONENAND_PAGESIZE (2048 + 64) |
| 25 | |
| 26 | /* Scan and identify a OneNAND device */ |
| 27 | extern int onenand_scan (struct mtd_info *mtd, int max_chips); |
| 28 | /* Free resources held by the OneNAND device */ |
| 29 | extern void onenand_release (struct mtd_info *mtd); |
| 30 | |
| 31 | /** |
Kyungmin Park | d7e8ce1 | 2007-09-10 17:15:14 +0900 | [diff] [blame] | 32 | * struct onenand_bufferram - OneNAND BufferRAM Data |
Kyungmin Park | ef0921d | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 33 | * @param blockpage block & page address in BufferRAM |
Kyungmin Park | d7e8ce1 | 2007-09-10 17:15:14 +0900 | [diff] [blame] | 34 | */ |
| 35 | struct onenand_bufferram { |
Kyungmin Park | ef0921d | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 36 | int blockpage; |
Kyungmin Park | d7e8ce1 | 2007-09-10 17:15:14 +0900 | [diff] [blame] | 37 | }; |
| 38 | |
| 39 | /** |
| 40 | * struct onenand_chip - OneNAND Private Flash Chip Data |
| 41 | * @param base [BOARDSPECIFIC] address to access OneNAND |
| 42 | * @param chipsize [INTERN] the size of one chip for multichip arrays |
| 43 | * @param device_id [INTERN] device ID |
| 44 | * @param verstion_id [INTERN] version ID |
| 45 | * @param options [BOARDSPECIFIC] various chip options. They can partly be set to inform onenand_scan about |
| 46 | * @param erase_shift [INTERN] number of address bits in a block |
| 47 | * @param page_shift [INTERN] number of address bits in a page |
| 48 | * @param ppb_shift [INTERN] number of address bits in a pages per block |
| 49 | * @param page_mask [INTERN] a page per block mask |
Scott Wood | c45912d | 2008-10-24 16:20:43 -0500 | [diff] [blame] | 50 | * @param writesize [INTERN] a real page size |
Kyungmin Park | d7e8ce1 | 2007-09-10 17:15:14 +0900 | [diff] [blame] | 51 | * @param bufferam_index [INTERN] BufferRAM index |
| 52 | * @param bufferam [INTERN] BufferRAM info |
| 53 | * @param readw [REPLACEABLE] hardware specific function for read short |
| 54 | * @param writew [REPLACEABLE] hardware specific function for write short |
| 55 | * @param command [REPLACEABLE] hardware specific function for writing commands to the chip |
| 56 | * @param wait [REPLACEABLE] hardware specific function for wait on ready |
| 57 | * @param read_bufferram [REPLACEABLE] hardware specific function for BufferRAM Area |
| 58 | * @param write_bufferram [REPLACEABLE] hardware specific function for BufferRAM Area |
| 59 | * @param chip_lock [INTERN] spinlock used to protect access to this structure and the chip |
| 60 | * @param wq [INTERN] wait queue to sleep on if a OneNAND operation is in progress |
| 61 | * @param state [INTERN] the current state of the OneNAND device |
| 62 | * @param autooob [REPLACEABLE] the default (auto)placement scheme |
| 63 | * @param priv [OPTIONAL] pointer to private chip date |
| 64 | */ |
| 65 | struct onenand_chip { |
| 66 | void __iomem *base; |
| 67 | unsigned int chipsize; |
| 68 | unsigned int device_id; |
Kyungmin Park | ef0921d | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 69 | unsigned int version_id; |
| 70 | unsigned int density_mask; |
Kyungmin Park | d7e8ce1 | 2007-09-10 17:15:14 +0900 | [diff] [blame] | 71 | unsigned int options; |
| 72 | |
| 73 | unsigned int erase_shift; |
| 74 | unsigned int page_shift; |
| 75 | unsigned int ppb_shift; /* Pages per block shift */ |
| 76 | unsigned int page_mask; |
Kyungmin Park | bfd7f38 | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 77 | unsigned int writesize; |
Kyungmin Park | d7e8ce1 | 2007-09-10 17:15:14 +0900 | [diff] [blame] | 78 | |
| 79 | unsigned int bufferram_index; |
| 80 | struct onenand_bufferram bufferram[MAX_BUFFERRAM]; |
| 81 | |
Kyungmin Park | ef0921d | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 82 | int (*command) (struct mtd_info *mtd, int cmd, loff_t address, |
Kyungmin Park | d7e8ce1 | 2007-09-10 17:15:14 +0900 | [diff] [blame] | 83 | size_t len); |
Kyungmin Park | ef0921d | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 84 | int (*wait) (struct mtd_info *mtd, int state); |
| 85 | int (*bbt_wait) (struct mtd_info *mtd, int state); |
| 86 | int (*read_bufferram) (struct mtd_info *mtd, loff_t addr, int area, |
Kyungmin Park | d7e8ce1 | 2007-09-10 17:15:14 +0900 | [diff] [blame] | 87 | unsigned char *buffer, int offset, size_t count); |
Kyungmin Park | ef0921d | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 88 | int (*read_spareram) (struct mtd_info *mtd, loff_t addr, int area, |
| 89 | unsigned char *buffer, int offset, size_t count); |
| 90 | int (*write_bufferram) (struct mtd_info *mtd, loff_t addr, int area, |
Kyungmin Park | d7e8ce1 | 2007-09-10 17:15:14 +0900 | [diff] [blame] | 91 | const unsigned char *buffer, int offset, |
| 92 | size_t count); |
Kyungmin Park | ef0921d | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 93 | unsigned short (*read_word) (void __iomem *addr); |
| 94 | void (*write_word) (unsigned short value, void __iomem *addr); |
| 95 | void (*mmcontrol) (struct mtd_info *mtd, int sync_read); |
Kyungmin Park | d438d50 | 2008-08-13 09:11:02 +0900 | [diff] [blame] | 96 | int (*block_markbad)(struct mtd_info *mtd, loff_t ofs); |
| 97 | int (*scan_bbt)(struct mtd_info *mtd); |
Kyungmin Park | d7e8ce1 | 2007-09-10 17:15:14 +0900 | [diff] [blame] | 98 | |
Kyungmin Park | ef0921d | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 99 | unsigned char *main_buf; |
| 100 | unsigned char *spare_buf; |
| 101 | #ifdef DONT_USE_UBOOT |
| 102 | spinlock_t chip_lock; |
| 103 | wait_queue_head_t wq; |
| 104 | #endif |
Kyungmin Park | d438d50 | 2008-08-13 09:11:02 +0900 | [diff] [blame] | 105 | int state; |
Kyungmin Park | ef0921d | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 106 | unsigned char *page_buf; |
| 107 | unsigned char *oob_buf; |
Kyungmin Park | d7e8ce1 | 2007-09-10 17:15:14 +0900 | [diff] [blame] | 108 | |
| 109 | struct nand_oobinfo *autooob; |
Stefan Roese | 1ae3986 | 2008-12-02 11:06:47 +0100 | [diff] [blame^] | 110 | int subpagesize; |
Kyungmin Park | ef0921d | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 111 | struct nand_ecclayout *ecclayout; |
Kyungmin Park | d7e8ce1 | 2007-09-10 17:15:14 +0900 | [diff] [blame] | 112 | |
| 113 | void *bbm; |
| 114 | |
| 115 | void *priv; |
| 116 | }; |
| 117 | |
Kyungmin Park | bfd7f38 | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 118 | /* |
| 119 | * Helper macros |
| 120 | */ |
Kyungmin Park | d7e8ce1 | 2007-09-10 17:15:14 +0900 | [diff] [blame] | 121 | #define ONENAND_CURRENT_BUFFERRAM(this) (this->bufferram_index) |
| 122 | #define ONENAND_NEXT_BUFFERRAM(this) (this->bufferram_index ^ 1) |
| 123 | #define ONENAND_SET_NEXT_BUFFERRAM(this) (this->bufferram_index ^= 1) |
Kyungmin Park | bfd7f38 | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 124 | #define ONENAND_SET_PREV_BUFFERRAM(this) (this->bufferram_index ^= 1) |
| 125 | #define ONENAND_SET_BUFFERRAM0(this) (this->bufferram_index = 0) |
| 126 | #define ONENAND_SET_BUFFERRAM1(this) (this->bufferram_index = 1) |
| 127 | |
| 128 | #define ONENAND_IS_DDP(this) \ |
| 129 | (this->device_id & ONENAND_DEVICE_IS_DDP) |
| 130 | |
| 131 | #define ONENAND_IS_2PLANE(this) (0) |
Kyungmin Park | d7e8ce1 | 2007-09-10 17:15:14 +0900 | [diff] [blame] | 132 | |
| 133 | /* |
| 134 | * Options bits |
| 135 | */ |
Kyungmin Park | ef0921d | 2008-11-04 09:24:07 +0900 | [diff] [blame] | 136 | #define ONENAND_HAS_CONT_LOCK (0x0001) |
| 137 | #define ONENAND_HAS_UNLOCK_ALL (0x0002) |
| 138 | #define ONENAND_HAS_2PLANE (0x0004) |
Kyungmin Park | bfd7f38 | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 139 | #define ONENAND_PAGEBUF_ALLOC (0x1000) |
| 140 | #define ONENAND_OOBBUF_ALLOC (0x2000) |
Kyungmin Park | d7e8ce1 | 2007-09-10 17:15:14 +0900 | [diff] [blame] | 141 | |
| 142 | /* |
| 143 | * OneNAND Flash Manufacturer ID Codes |
| 144 | */ |
| 145 | #define ONENAND_MFR_SAMSUNG 0xec |
Kyungmin Park | d7e8ce1 | 2007-09-10 17:15:14 +0900 | [diff] [blame] | 146 | |
| 147 | /** |
| 148 | * struct nand_manufacturers - NAND Flash Manufacturer ID Structure |
| 149 | * @param name: Manufacturer name |
| 150 | * @param id: manufacturer ID code of device. |
| 151 | */ |
| 152 | struct onenand_manufacturers { |
| 153 | int id; |
| 154 | char *name; |
| 155 | }; |
| 156 | |
Kyungmin Park | bfd7f38 | 2008-08-19 08:42:53 +0900 | [diff] [blame] | 157 | int onenand_bbt_read_oob(struct mtd_info *mtd, loff_t from, |
| 158 | struct mtd_oob_ops *ops); |
| 159 | |
Kyungmin Park | d7e8ce1 | 2007-09-10 17:15:14 +0900 | [diff] [blame] | 160 | #endif /* __LINUX_MTD_ONENAND_H */ |