/
nand2.h
441 lines (369 loc) · 9.08 KB
/
nand2.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
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
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
#include <linux/mtd/nand.h>
struct nand_device;
struct nand_controller;
struct nand_ecc_controller;
enum nand_action_type {
NAND_OP_ACTION,
NAND_PRIV_ACTION,
};
enum nand_action_state {
NAND_ACTION_CREATED,
NAND_ACTION_EXECUTED,
NAND_ACTION_WAITING,
NAND_ACTION_DONE,
};
struct nand_action {
struct list_head node;
enum nand_action_type type;
int status;
};
//enum nand_operation_dir {
// NAND_OP_NONE,
// NAND_OP_INPUT,
// NAND_OP_OUTPUT,
//};
#define NAND_OP_DIR_MSK GENMASK(1, 0)
#define NAND_OP_NO_DATA (0 << 0)
#define NAND_OP_INPUT (1 << 0)
#define NAND_OP_OUTPUT (2 << 0)
#define NAND_OP_WAIT_RDY_MSK GENMASK(3, 2)
#define NAND_OP_DO_NOT_WAIT (0 << 2)
#define NAND_OP_WAIT_LUN_RDY (1 << 2)
#define NAND_OP_WAIT_DEV_RDY (2 << 2)
#define NAND_OP_8BIT_MODE BIT(4)
struct nand_operation {
struct nand_action action;
// struct list_head node;
// struct nand_device *dev;
// int chip;
u32 flags;
u8 ncmds;
u8 cmds[2];
u8 naddrs;
u8 addrs[5];
// bool waitready;
int page;
int column;
enum nand_operation_dir dir;
struct {
union {
const u8 *out;
u8 *in;
};
size_t len;
} data;
unsigned long timeout;
// bool eightbitmode;
// void (*complete)(struct nand_operation *op);
// int result;
// void *priv;
};
struct nand_priv_action {
struct nand_action action;
int (*func)(struct nand_priv_action *action);
};
struct nand_action_seq {
struct list_head node;
struct list_head actions;
struct nand_device *dev;
int die;
struct nand_action *cur;
void *priv;
// int nops;
// struct nand_operation *ops;
};
struct nand_controller_ops {
int (*initialize)(struct nand_device *dev);
void (*cleanup)(struct nand_device *dev);
int (*add)(struct nand_device *dev);
int (*remove)(struct nand_device *dev);
int (*queue)(struct nand_action_seq *seq);
// int (*queue_op)(struct nand_operation *op);
// int (*queue_seq)(struct nand_operation_seq *seq);
// int (*launch_op)(struct nand_operation *op);
int (*apply_timings)(struct nand_device *dev);
bool (*supported)(struct nand_controller *controller,
const struct nand_operation *op);
};
struct nand_devices {
struct list_head list;
struct mutex lock;
};
struct nand_controller {
struct list_head node;
struct device dev;
spinlock_t lock;
struct nand_device *active;
wait_queue_head_t wq;
const struct nand_controller_ops *ops;
struct list_head queue;
struct nand_operation *cur;
struct nand_devices devices;
int numcs;
};
struct nand_basic_controller_ops {
int (*launch_op)(struct nand_device *dev,
const struct nand_operation *op);
};
struct nand_basic_controller {
struct nand_controller base;
struct nand_basic_controller_ops *ops;
struct list_head queue;
spinlock_t lock;
};
struct nand_driver {
struct device_driver driver;
const struct nand_device_id *id_table;
int (*probe)(struct nand_device *dev);
int (*remove)(struct nand_device *dev);
};
enum nand_sw_interface_type {
NAND_NONSTD,
NAND_ONFI,
NAND_JEDEC,
};
struct nand_onfi {
int version;
struct nand_onfi_params params;
};
struct nand_jedec {
int version;
struct nand_jedec_params params;
};
struct nand_sw_interface {
enum nand_sw_interface_type type;
union {
struct nand_onfi onfi;
struct nand_jedec jedec;
};
};
struct nand_ecc_controller_ops {
int (*read)(struct nand_device *dev, int page, int column,
void *buf, size_t len);
int (*write)(struct nand_device *dev, int page, int column,
const void *buf, size_t len);
int (*read_page_raw)(struct nand_device *dev,
void *buf, int oob_required, int page);
int (*write_page_raw)(struct nand_device *dev,
const void *buf, int oob_required);
int (*read_page)(struct nand_device *dev,
void *buf, int oob_required, int page);
int (*read_subpage)(struct nand_device *dev,
uint32_t offs, uint32_t len, void *buf, int page);
int (*write_subpage)(struct nand_device *dev,
uint32_t offset, uint32_t data_len,
const void *data_buf, int oob_required);
int (*write_page)(struct nand_device *dev,
const void *buf, int oob_required);
int (*write_oob_raw)(struct nand_device *dev, int page);
int (*read_oob_raw)(struct nand_device *dev, int page);
int (*read_oob)(struct nand_device *dev, int page);
int (*write_oob)(struct nand_device *dev, int page);
bool (*supported)(struct nand_ecc_controller *controller,
const struct nand_operation *op);
};
enum nand_page_region_type {
NAND_PAYLOAD_DATA,
NAND_OOB_AVAILABLE,
NAND_OOB_ECC,
};
struct nand_page_range {
int start;
int stop;
};
struct nand_page_region {
enum nand_page_region_type type;
struct nand_page_range phys;
struct nand_page_range virt;
};
struct nand_page_layout {
int nregions;
struct nand_page_area *regions;
};
struct nand_ecc_controller {
struct nand_ecc_controller_ops *ops;
};
struct nand_ecc_requirements {
int step;
int strength;
};
struct nand_ecc_desc {
int step;
int strength;
struct nand_page_layout pagelayout;
struct nand_ecclayout *ecclayout;
struct nand_ecc_controller *controller;
};
struct nand_ecc {
struct nand_ecc_requirements requirements;
struct nand_ecc_desc *desc;
};
struct nand_basic_ecc_controller_ops {
int (*enable)(struct nand_device *dev);
int (*disable)(struct nand_device *dev);
int (*reset)(struct nand_device *dev);
int (*read_chunk)(struct nand_device *dev, struct nand_operation *op,
int id);
int (*read_page)(struct nand_device *dev, struct nand_operation *op);
int (*write_subpage)(struct nand_device *dev,
struct nand_operation *op, int id);
int (*write_page)(struct nand_device *dev, struct nand_operation *op);
};
struct nand_basic_ecc_controller {
struct nand_ecc_controller base;
struct nand_basic_ecc_controller_ops *ops;
};
static inline struct nand_basic_ecc_controller *
to_basic_ecc_controller(struct nand_ecc_controller *controller)
{
return container_of(controller, struct nand_basic_ecc_controller,
base);
}
struct nand_bad_block {
int badblockpos;
int badblockbits;
uint8_t *bbt;
struct nand_bbt_descr *bbt_td;
struct nand_bbt_descr *bbt_md;
struct nand_bbt_descr *badblock_pattern;
};
enum nand_cs_type {
NAND_CS_GPIO,
NAND_CS_PRIV,
};
struct nand_cs {
enum nand_cs_type type;
int id;
union {
struct gpio_desc *gpio;
void *data;
};
int nusers;
};
enum nand_rb_type {
NAND_RB_NONE,
NAND_RB_GPIO,
NAND_RB_PRIV,
};
struct nand_rb {
enum nand_rb_type type;
int id;
union {
struct gpio_desc *gpio;
void *data;
};
int nusers;
};
enum nand_hw_interface_type {
NAND_SDR,
};
struct nand_hw_interface {
int buswidth;
enum nand_hw_interface_type type;
union {
struct nand_sdr_timings sdr;
} timings;
};
enum nand_die_type {
NAND_CS_DIE,
NAND_LUN_DIE
};
struct nand_die {
enum nand_die_type type;
struct list_head queue;
struct action_seq *cur;
struct nand_cs *cs;
struct nand_rb *rb;
};
struct nand_layout {
int page_shift;
int phys_erase_shift;
int bbt_erase_shift;
int pagemask;
int die_size;
int die_shift;
int ndies;
struct nand_die *dies;
};
struct nand_device {
struct list_head node;
struct device dev;
struct mtd_info mtd;
u8 id[2];
u64 size;
struct nand_layout layout;
u8 bits_per_cell;
/*
unsigned int options;
unsigned int bbt_options;
int page_shift;
int phys_erase_shift;
int bbt_erase_shift;
int chip_shift;
int numchips;
u64 chipsize;
int pagemask;
int pagebuf;
unsigned int pagebuf_bitflips;
int subpagesize;
u8 bits_per_cell;
*/
struct nand_hw_interface hw_interface;
struct nand_sw_interface sw_interface;
struct nand_controller *controller;
void *controller_priv;
int read_retries;
flstate_t state;
struct nand_ecc ecc;
struct nand_buffers *buffers;
struct nand_bad_block bb;
void *priv;
};
static inline int nand_onfi_feature(struct nand_device *dev)
{
return dev->sw_interface.type == NAND_ONFI ?
le16_to_cpu(dev->sw_interface.onfi.params.features) : 0;
}
static inline void nand_set_ctrldata(struct nand_device *dev, void *data)
{
dev->controller_priv = data;
}
static inline void *nand_get_ctrldata(struct nand_device *dev)
{
return dev->controller_priv;
}
static inline struct nand_device *dev_to_nand(struct device *dev)
{
return container_of(dev, struct nand_device, dev);
}
static inline struct nand_device *mtd_to_nand(struct mtd_info *mtd)
{
return container_of(mtd, struct nand_device, mtd);
}
static inline void *nand_controller_get_devdata(struct nand_controller *ctrl)
{
return dev_get_drvdata(&ctrl->dev);
}
static inline void nand_controller_set_devdata(struct nand_controller *ctrl,
void *data)
{
dev_set_drvdata(&ctrl->dev, data);
}
struct nand_controller *nand_controller_alloc(struct device *dev, unsigned size);
int nand_controller_register(struct nand_controller *ctrl);
int nand_controller_unregister(struct nand_controller *ctrl);
int nand_basic_launch_seq(struct nand_device *dev,
const struct nand_operation_seq *seq);
//static inline int nand_controller_exec_op_async(struct nand_operation *op)
//{
// return op->dev->controller->ops->queue_op(op);
//}
//
//int nand_controller_exec_op_sync(struct nand_operation *op);
static inline void nand_action_seq_init(struct nand_action_seq *seq,
struct nand_device *dev, int die)
{
INIT_LIST_HEAD(&seq->actions);
seq->dev = dev;
seq->die = die;
}