]>
Commit | Line | Data |
---|---|---|
cd5f6346 KP |
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> | |
cdc00130 | 17 | #include <linux/mtd/bbm.h> |
cd5f6346 KP |
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, | |
493c6460 KP |
38 | FL_RESETING, |
39 | FL_OTPING, | |
a41371eb | 40 | FL_PM_SUSPENDED, |
cd5f6346 KP |
41 | } onenand_state_t; |
42 | ||
43 | /** | |
44 | * struct onenand_bufferram - OneNAND BufferRAM Data | |
45 | * @param block block address in BufferRAM | |
46 | * @param page page address in BufferRAM | |
47 | * @param valid valid flag | |
48 | */ | |
49 | struct onenand_bufferram { | |
50 | int block; | |
51 | int page; | |
52 | int valid; | |
53 | }; | |
54 | ||
55 | /** | |
56 | * struct onenand_chip - OneNAND Private Flash Chip Data | |
57 | * @param base [BOARDSPECIFIC] address to access OneNAND | |
58 | * @param chipsize [INTERN] the size of one chip for multichip arrays | |
59 | * @param device_id [INTERN] device ID | |
60 | * @param verstion_id [INTERN] version ID | |
61 | * @param options [BOARDSPECIFIC] various chip options. They can partly be set to inform onenand_scan about | |
62 | * @param erase_shift [INTERN] number of address bits in a block | |
63 | * @param page_shift [INTERN] number of address bits in a page | |
64 | * @param ppb_shift [INTERN] number of address bits in a pages per block | |
65 | * @param page_mask [INTERN] a page per block mask | |
66 | * @param bufferam_index [INTERN] BufferRAM index | |
67 | * @param bufferam [INTERN] BufferRAM info | |
68 | * @param readw [REPLACEABLE] hardware specific function for read short | |
69 | * @param writew [REPLACEABLE] hardware specific function for write short | |
70 | * @param command [REPLACEABLE] hardware specific function for writing commands to the chip | |
71 | * @param wait [REPLACEABLE] hardware specific function for wait on ready | |
72 | * @param read_bufferram [REPLACEABLE] hardware specific function for BufferRAM Area | |
73 | * @param write_bufferram [REPLACEABLE] hardware specific function for BufferRAM Area | |
cdc00130 KP |
74 | * @param read_word [REPLACEABLE] hardware specific function for read register of OneNAND |
75 | * @param write_word [REPLACEABLE] hardware specific function for write register of OneNAND | |
76 | * @param scan_bbt [REPLACEALBE] hardware specific function for scaning Bad block Table | |
cd5f6346 KP |
77 | * @param chip_lock [INTERN] spinlock used to protect access to this structure and the chip |
78 | * @param wq [INTERN] wait queue to sleep on if a OneNAND operation is in progress | |
79 | * @param state [INTERN] the current state of the OneNAND device | |
5bd34c09 | 80 | * @param ecclayout [REPLACEABLE] the default ecc placement scheme |
61ecfa87 | 81 | * @param bbm [REPLACEABLE] pointer to Bad Block Management |
cd5f6346 KP |
82 | * @param priv [OPTIONAL] pointer to private chip date |
83 | */ | |
84 | struct onenand_chip { | |
85 | void __iomem *base; | |
86 | unsigned int chipsize; | |
87 | unsigned int device_id; | |
83a36838 | 88 | unsigned int density_mask; |
cd5f6346 KP |
89 | unsigned int options; |
90 | ||
91 | unsigned int erase_shift; | |
92 | unsigned int page_shift; | |
93 | unsigned int ppb_shift; /* Pages per block shift */ | |
94 | unsigned int page_mask; | |
95 | ||
96 | unsigned int bufferram_index; | |
97 | struct onenand_bufferram bufferram[MAX_BUFFERRAM]; | |
98 | ||
99 | int (*command)(struct mtd_info *mtd, int cmd, loff_t address, size_t len); | |
100 | int (*wait)(struct mtd_info *mtd, int state); | |
101 | int (*read_bufferram)(struct mtd_info *mtd, int area, | |
102 | unsigned char *buffer, int offset, size_t count); | |
103 | int (*write_bufferram)(struct mtd_info *mtd, int area, | |
104 | const unsigned char *buffer, int offset, size_t count); | |
105 | unsigned short (*read_word)(void __iomem *addr); | |
106 | void (*write_word)(unsigned short value, void __iomem *addr); | |
52b0eea7 | 107 | void (*mmcontrol)(struct mtd_info *mtd, int sync_read); |
cdc00130 KP |
108 | int (*block_markbad)(struct mtd_info *mtd, loff_t ofs); |
109 | int (*scan_bbt)(struct mtd_info *mtd); | |
cd5f6346 KP |
110 | |
111 | spinlock_t chip_lock; | |
112 | wait_queue_head_t wq; | |
113 | onenand_state_t state; | |
532a37cf | 114 | unsigned char *page_buf; |
cd5f6346 | 115 | |
5bd34c09 | 116 | struct nand_ecclayout *ecclayout; |
cd5f6346 | 117 | |
5bd34c09 | 118 | void *bbm; |
cdc00130 | 119 | |
cd5f6346 KP |
120 | void *priv; |
121 | }; | |
122 | ||
fcc31470 KP |
123 | /* |
124 | * Helper macros | |
125 | */ | |
cd5f6346 KP |
126 | #define ONENAND_CURRENT_BUFFERRAM(this) (this->bufferram_index) |
127 | #define ONENAND_NEXT_BUFFERRAM(this) (this->bufferram_index ^ 1) | |
128 | #define ONENAND_SET_NEXT_BUFFERRAM(this) (this->bufferram_index ^= 1) | |
129 | ||
fcc31470 KP |
130 | #define ONENAND_GET_SYS_CFG1(this) \ |
131 | (this->read_word(this->base + ONENAND_REG_SYS_CFG1)) | |
132 | #define ONENAND_SET_SYS_CFG1(v, this) \ | |
133 | (this->write_word(v, this->base + ONENAND_REG_SYS_CFG1)) | |
134 | ||
9c01f87d KP |
135 | /* Check byte access in OneNAND */ |
136 | #define ONENAND_CHECK_BYTE_ACCESS(addr) (addr & 0x1) | |
137 | ||
cd5f6346 KP |
138 | /* |
139 | * Options bits | |
140 | */ | |
141 | #define ONENAND_CONT_LOCK (0x0001) | |
532a37cf | 142 | #define ONENAND_PAGEBUF_ALLOC (0x1000) |
cd5f6346 KP |
143 | |
144 | /* | |
145 | * OneNAND Flash Manufacturer ID Codes | |
146 | */ | |
147 | #define ONENAND_MFR_SAMSUNG 0xec | |
cd5f6346 KP |
148 | |
149 | /** | |
150 | * struct nand_manufacturers - NAND Flash Manufacturer ID Structure | |
151 | * @param name: Manufacturer name | |
152 | * @param id: manufacturer ID code of device. | |
153 | */ | |
154 | struct onenand_manufacturers { | |
155 | int id; | |
156 | char *name; | |
157 | }; | |
158 | ||
159 | #endif /* __LINUX_MTD_ONENAND_H */ |