Kyungmin Park | cd5f634 | 2005-07-11 11:41:53 +0100 | [diff] [blame] | 1 | /* |
| 2 | * linux/include/linux/mtd/onenand.h |
| 3 | * |
| 4 | * Copyright (C) 2005 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/spinlock.h> |
| 16 | #include <linux/mtd/onenand_regs.h> |
Kyungmin Park | cdc0013 | 2005-09-03 07:15:48 +0100 | [diff] [blame] | 17 | #include <linux/mtd/bbm.h> |
Kyungmin Park | cd5f634 | 2005-07-11 11:41:53 +0100 | [diff] [blame] | 18 | |
| 19 | #define MAX_BUFFERRAM 2 |
| 20 | |
| 21 | /* Scan and identify a OneNAND device */ |
| 22 | extern int onenand_scan(struct mtd_info *mtd, int max_chips); |
| 23 | /* Free resources held by the OneNAND device */ |
| 24 | extern void onenand_release(struct mtd_info *mtd); |
| 25 | |
| 26 | /** |
| 27 | * onenand_state_t - chip states |
| 28 | * Enumeration for OneNAND flash chip state |
| 29 | */ |
| 30 | typedef enum { |
| 31 | FL_READY, |
| 32 | FL_READING, |
| 33 | FL_WRITING, |
| 34 | FL_ERASING, |
| 35 | FL_SYNCING, |
| 36 | FL_UNLOCKING, |
| 37 | FL_LOCKING, |
Kyungmin Park | a41371e | 2005-09-29 03:55:31 +0100 | [diff] [blame] | 38 | FL_PM_SUSPENDED, |
Kyungmin Park | cd5f634 | 2005-07-11 11:41:53 +0100 | [diff] [blame] | 39 | } onenand_state_t; |
| 40 | |
| 41 | /** |
| 42 | * struct onenand_bufferram - OneNAND BufferRAM Data |
| 43 | * @param block block address in BufferRAM |
| 44 | * @param page page address in BufferRAM |
| 45 | * @param valid valid flag |
| 46 | */ |
| 47 | struct onenand_bufferram { |
| 48 | int block; |
| 49 | int page; |
| 50 | int valid; |
| 51 | }; |
| 52 | |
| 53 | /** |
| 54 | * struct onenand_chip - OneNAND Private Flash Chip Data |
| 55 | * @param base [BOARDSPECIFIC] address to access OneNAND |
| 56 | * @param chipsize [INTERN] the size of one chip for multichip arrays |
| 57 | * @param device_id [INTERN] device ID |
| 58 | * @param verstion_id [INTERN] version ID |
| 59 | * @param options [BOARDSPECIFIC] various chip options. They can partly be set to inform onenand_scan about |
| 60 | * @param erase_shift [INTERN] number of address bits in a block |
| 61 | * @param page_shift [INTERN] number of address bits in a page |
| 62 | * @param ppb_shift [INTERN] number of address bits in a pages per block |
| 63 | * @param page_mask [INTERN] a page per block mask |
| 64 | * @param bufferam_index [INTERN] BufferRAM index |
| 65 | * @param bufferam [INTERN] BufferRAM info |
| 66 | * @param readw [REPLACEABLE] hardware specific function for read short |
| 67 | * @param writew [REPLACEABLE] hardware specific function for write short |
| 68 | * @param command [REPLACEABLE] hardware specific function for writing commands to the chip |
| 69 | * @param wait [REPLACEABLE] hardware specific function for wait on ready |
| 70 | * @param read_bufferram [REPLACEABLE] hardware specific function for BufferRAM Area |
| 71 | * @param write_bufferram [REPLACEABLE] hardware specific function for BufferRAM Area |
Kyungmin Park | cdc0013 | 2005-09-03 07:15:48 +0100 | [diff] [blame] | 72 | * @param read_word [REPLACEABLE] hardware specific function for read register of OneNAND |
| 73 | * @param write_word [REPLACEABLE] hardware specific function for write register of OneNAND |
| 74 | * @param scan_bbt [REPLACEALBE] hardware specific function for scaning Bad block Table |
Kyungmin Park | cd5f634 | 2005-07-11 11:41:53 +0100 | [diff] [blame] | 75 | * @param chip_lock [INTERN] spinlock used to protect access to this structure and the chip |
| 76 | * @param wq [INTERN] wait queue to sleep on if a OneNAND operation is in progress |
| 77 | * @param state [INTERN] the current state of the OneNAND device |
| 78 | * @param autooob [REPLACEABLE] the default (auto)placement scheme |
Thomas Gleixner | 61ecfa8 | 2005-11-07 11:15:31 +0000 | [diff] [blame] | 79 | * @param bbm [REPLACEABLE] pointer to Bad Block Management |
Kyungmin Park | cd5f634 | 2005-07-11 11:41:53 +0100 | [diff] [blame] | 80 | * @param priv [OPTIONAL] pointer to private chip date |
| 81 | */ |
| 82 | struct onenand_chip { |
| 83 | void __iomem *base; |
| 84 | unsigned int chipsize; |
| 85 | unsigned int device_id; |
Kyungmin Park | 83a3683 | 2005-09-29 04:53:16 +0100 | [diff] [blame] | 86 | unsigned int density_mask; |
Kyungmin Park | cd5f634 | 2005-07-11 11:41:53 +0100 | [diff] [blame] | 87 | unsigned int options; |
| 88 | |
| 89 | unsigned int erase_shift; |
| 90 | unsigned int page_shift; |
| 91 | unsigned int ppb_shift; /* Pages per block shift */ |
| 92 | unsigned int page_mask; |
| 93 | |
| 94 | unsigned int bufferram_index; |
| 95 | struct onenand_bufferram bufferram[MAX_BUFFERRAM]; |
| 96 | |
| 97 | int (*command)(struct mtd_info *mtd, int cmd, loff_t address, size_t len); |
| 98 | int (*wait)(struct mtd_info *mtd, int state); |
| 99 | int (*read_bufferram)(struct mtd_info *mtd, int area, |
| 100 | unsigned char *buffer, int offset, size_t count); |
| 101 | int (*write_bufferram)(struct mtd_info *mtd, int area, |
| 102 | const unsigned char *buffer, int offset, size_t count); |
| 103 | unsigned short (*read_word)(void __iomem *addr); |
| 104 | void (*write_word)(unsigned short value, void __iomem *addr); |
Kyungmin Park | 52b0eea | 2005-09-03 07:07:19 +0100 | [diff] [blame] | 105 | void (*mmcontrol)(struct mtd_info *mtd, int sync_read); |
Kyungmin Park | cdc0013 | 2005-09-03 07:15:48 +0100 | [diff] [blame] | 106 | int (*block_markbad)(struct mtd_info *mtd, loff_t ofs); |
| 107 | int (*scan_bbt)(struct mtd_info *mtd); |
Kyungmin Park | cd5f634 | 2005-07-11 11:41:53 +0100 | [diff] [blame] | 108 | |
| 109 | spinlock_t chip_lock; |
| 110 | wait_queue_head_t wq; |
| 111 | onenand_state_t state; |
Kyungmin Park | 532a37c | 2005-12-16 11:17:29 +0900 | [diff] [blame] | 112 | unsigned char *page_buf; |
Kyungmin Park | cd5f634 | 2005-07-11 11:41:53 +0100 | [diff] [blame] | 113 | |
| 114 | struct nand_oobinfo *autooob; |
| 115 | |
Kyungmin Park | cdc0013 | 2005-09-03 07:15:48 +0100 | [diff] [blame] | 116 | void *bbm; |
| 117 | |
Kyungmin Park | cd5f634 | 2005-07-11 11:41:53 +0100 | [diff] [blame] | 118 | void *priv; |
| 119 | }; |
| 120 | |
Kyungmin Park | fcc3147 | 2005-09-03 07:20:08 +0100 | [diff] [blame] | 121 | /* |
| 122 | * Helper macros |
| 123 | */ |
Kyungmin Park | cd5f634 | 2005-07-11 11:41:53 +0100 | [diff] [blame] | 124 | #define ONENAND_CURRENT_BUFFERRAM(this) (this->bufferram_index) |
| 125 | #define ONENAND_NEXT_BUFFERRAM(this) (this->bufferram_index ^ 1) |
| 126 | #define ONENAND_SET_NEXT_BUFFERRAM(this) (this->bufferram_index ^= 1) |
| 127 | |
Kyungmin Park | fcc3147 | 2005-09-03 07:20:08 +0100 | [diff] [blame] | 128 | #define ONENAND_GET_SYS_CFG1(this) \ |
| 129 | (this->read_word(this->base + ONENAND_REG_SYS_CFG1)) |
| 130 | #define ONENAND_SET_SYS_CFG1(v, this) \ |
| 131 | (this->write_word(v, this->base + ONENAND_REG_SYS_CFG1)) |
| 132 | |
Kyungmin Park | cd5f634 | 2005-07-11 11:41:53 +0100 | [diff] [blame] | 133 | /* |
| 134 | * Options bits |
| 135 | */ |
| 136 | #define ONENAND_CONT_LOCK (0x0001) |
Kyungmin Park | 532a37c | 2005-12-16 11:17:29 +0900 | [diff] [blame] | 137 | #define ONENAND_PAGEBUF_ALLOC (0x1000) |
Kyungmin Park | cd5f634 | 2005-07-11 11:41:53 +0100 | [diff] [blame] | 138 | |
| 139 | /* |
| 140 | * OneNAND Flash Manufacturer ID Codes |
| 141 | */ |
| 142 | #define ONENAND_MFR_SAMSUNG 0xec |
Kyungmin Park | cd5f634 | 2005-07-11 11:41:53 +0100 | [diff] [blame] | 143 | |
| 144 | /** |
| 145 | * struct nand_manufacturers - NAND Flash Manufacturer ID Structure |
| 146 | * @param name: Manufacturer name |
| 147 | * @param id: manufacturer ID code of device. |
| 148 | */ |
| 149 | struct onenand_manufacturers { |
| 150 | int id; |
| 151 | char *name; |
| 152 | }; |
| 153 | |
| 154 | #endif /* __LINUX_MTD_ONENAND_H */ |