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