1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17#ifndef __DRIVERS_MTD_NAND_GPMI_NAND_H
18#define __DRIVERS_MTD_NAND_GPMI_NAND_H
19
20#include <linux/mtd/nand.h>
21#include <linux/platform_device.h>
22#include <linux/dma-mapping.h>
23#include <linux/fsl/mxs-dma.h>
24
25#define GPMI_CLK_MAX 5
26struct resources {
27 void __iomem *gpmi_regs;
28 void __iomem *bch_regs;
29 unsigned int bch_low_interrupt;
30 unsigned int bch_high_interrupt;
31 unsigned int dma_low_channel;
32 unsigned int dma_high_channel;
33 struct clk *clock[GPMI_CLK_MAX];
34};
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57struct bch_geometry {
58 unsigned int gf_len;
59 unsigned int ecc_strength;
60 unsigned int page_size;
61 unsigned int metadata_size;
62 unsigned int ecc_chunk_size;
63 unsigned int ecc_chunk_count;
64 unsigned int payload_size;
65 unsigned int auxiliary_size;
66 unsigned int auxiliary_status_offset;
67 unsigned int block_mark_byte_offset;
68 unsigned int block_mark_bit_offset;
69};
70
71
72
73
74
75
76
77struct boot_rom_geometry {
78 unsigned int stride_size_in_pages;
79 unsigned int search_area_stride_exponent;
80};
81
82
83enum dma_ops_type {
84 DMA_FOR_COMMAND = 1,
85 DMA_FOR_READ_DATA,
86 DMA_FOR_WRITE_DATA,
87 DMA_FOR_READ_ECC_PAGE,
88 DMA_FOR_WRITE_ECC_PAGE
89};
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114struct nand_timing {
115 int8_t data_setup_in_ns;
116 int8_t data_hold_in_ns;
117 int8_t address_setup_in_ns;
118 int8_t gpmi_sample_delay_in_ns;
119 int8_t tREA_in_ns;
120 int8_t tRLOH_in_ns;
121 int8_t tRHOH_in_ns;
122};
123
124struct gpmi_nand_data {
125
126#define GPMI_ASYNC_EDO_ENABLED (1 << 0)
127#define GPMI_TIMING_INIT_OK (1 << 1)
128 int flags;
129
130
131 struct device *dev;
132 struct platform_device *pdev;
133 struct gpmi_nand_platform_data *pdata;
134
135
136 struct resources resources;
137
138
139 struct nand_timing timing;
140 int timing_mode;
141
142
143 struct bch_geometry bch_geometry;
144 struct completion bch_done;
145
146
147 bool swap_block_mark;
148 struct boot_rom_geometry rom_geometry;
149
150
151 struct nand_chip nand;
152 struct mtd_info mtd;
153
154
155 int current_chip;
156 unsigned int command_length;
157
158
159 uint8_t *upper_buf;
160 int upper_len;
161
162
163 bool direct_dma_map_ok;
164
165 struct scatterlist cmd_sgl;
166 char *cmd_buffer;
167
168 struct scatterlist data_sgl;
169 char *data_buffer_dma;
170
171 void *page_buffer_virt;
172 dma_addr_t page_buffer_phys;
173 unsigned int page_buffer_size;
174
175 void *payload_virt;
176 dma_addr_t payload_phys;
177
178 void *auxiliary_virt;
179 dma_addr_t auxiliary_phys;
180
181
182#define DMA_CHANS 8
183 struct dma_chan *dma_chans[DMA_CHANS];
184 struct mxs_dma_data dma_data;
185 enum dma_ops_type last_dma_type;
186 enum dma_ops_type dma_type;
187 struct completion dma_done;
188
189
190 void *private;
191};
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206struct gpmi_nfc_hardware_timing {
207
208 uint8_t data_setup_in_cycles;
209 uint8_t data_hold_in_cycles;
210 uint8_t address_setup_in_cycles;
211
212
213 uint16_t device_busy_timeout;
214#define GPMI_DEFAULT_BUSY_TIMEOUT 0x500
215
216
217 bool use_half_periods;
218 uint8_t sample_delay_factor;
219 uint8_t wrn_dly_sel;
220};
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245struct timing_threshod {
246 const unsigned int max_chip_count;
247 const unsigned int max_data_setup_cycles;
248 const unsigned int internal_data_setup_in_ns;
249 const unsigned int max_sample_delay_factor;
250 const unsigned int max_dll_clock_period_in_ns;
251 const unsigned int max_dll_delay_in_ns;
252 unsigned long clock_frequency_in_hz;
253
254};
255
256
257extern int common_nfc_set_geometry(struct gpmi_nand_data *);
258extern struct dma_chan *get_dma_chan(struct gpmi_nand_data *);
259extern void prepare_data_dma(struct gpmi_nand_data *,
260 enum dma_data_direction dr);
261extern int start_dma_without_bch_irq(struct gpmi_nand_data *,
262 struct dma_async_tx_descriptor *);
263extern int start_dma_with_bch_irq(struct gpmi_nand_data *,
264 struct dma_async_tx_descriptor *);
265
266
267extern int gpmi_init(struct gpmi_nand_data *);
268extern int gpmi_extra_init(struct gpmi_nand_data *);
269extern void gpmi_clear_bch(struct gpmi_nand_data *);
270extern void gpmi_dump_info(struct gpmi_nand_data *);
271extern int bch_set_geometry(struct gpmi_nand_data *);
272extern int gpmi_is_ready(struct gpmi_nand_data *, unsigned chip);
273extern int gpmi_send_command(struct gpmi_nand_data *);
274extern void gpmi_begin(struct gpmi_nand_data *);
275extern void gpmi_end(struct gpmi_nand_data *);
276extern int gpmi_read_data(struct gpmi_nand_data *);
277extern int gpmi_send_data(struct gpmi_nand_data *);
278extern int gpmi_send_page(struct gpmi_nand_data *,
279 dma_addr_t payload, dma_addr_t auxiliary);
280extern int gpmi_read_page(struct gpmi_nand_data *,
281 dma_addr_t payload, dma_addr_t auxiliary);
282
283
284#define STATUS_GOOD 0x00
285#define STATUS_ERASED 0xff
286#define STATUS_UNCORRECTABLE 0xfe
287
288
289#define IS_MX23 0x0
290#define IS_MX28 0x1
291#define IS_MX6Q 0x2
292#define GPMI_IS_MX23(x) ((x)->pdev->id_entry->driver_data == IS_MX23)
293#define GPMI_IS_MX28(x) ((x)->pdev->id_entry->driver_data == IS_MX28)
294#define GPMI_IS_MX6Q(x) ((x)->pdev->id_entry->driver_data == IS_MX6Q)
295#endif
296