2 * NAND Flash Controller Device Driver
3 * Copyright © 2009-2010, Intel Corporation and its suppliers.
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms and conditions of the GNU General Public License,
7 * version 2, as published by the Free Software Foundation.
9 * This program is distributed in the hope it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
15 #include <linux/bitfield.h>
16 #include <linux/completion.h>
17 #include <linux/dma-mapping.h>
18 #include <linux/interrupt.h>
20 #include <linux/module.h>
21 #include <linux/mtd/mtd.h>
22 #include <linux/mtd/rawnand.h>
23 #include <linux/slab.h>
24 #include <linux/spinlock.h>
28 MODULE_LICENSE("GPL");
30 #define DENALI_NAND_NAME "denali-nand"
32 /* for Indexed Addressing */
33 #define DENALI_INDEXED_CTRL 0x00
34 #define DENALI_INDEXED_DATA 0x10
36 #define DENALI_MAP00 (0 << 26) /* direct access to buffer */
37 #define DENALI_MAP01 (1 << 26) /* read/write pages in PIO */
38 #define DENALI_MAP10 (2 << 26) /* high-level control plane */
39 #define DENALI_MAP11 (3 << 26) /* direct controller access */
41 /* MAP11 access cycle type */
42 #define DENALI_MAP11_CMD ((DENALI_MAP11) | 0) /* command cycle */
43 #define DENALI_MAP11_ADDR ((DENALI_MAP11) | 1) /* address cycle */
44 #define DENALI_MAP11_DATA ((DENALI_MAP11) | 2) /* data cycle */
47 #define DENALI_ERASE 0x01
49 #define DENALI_BANK(denali) ((denali)->active_bank << 24)
51 #define DENALI_INVALID_BANK -1
52 #define DENALI_NR_BANKS 4
55 * The bus interface clock, clk_x, is phase aligned with the core clock. The
56 * clk_x is an integral multiple N of the core clk. The value N is configured
57 * at IP delivery time, and its available value is 4, 5, or 6. We need to align
58 * to the largest value to make it work with any possible configuration.
60 #define DENALI_CLK_X_MULT 6
62 static inline struct denali_nand_info
*mtd_to_denali(struct mtd_info
*mtd
)
64 return container_of(mtd_to_nand(mtd
), struct denali_nand_info
, nand
);
68 * Direct Addressing - the slave address forms the control information (command
69 * type, bank, block, and page address). The slave data is the actual data to
70 * be transferred. This mode requires 28 bits of address region allocated.
72 static u32
denali_direct_read(struct denali_nand_info
*denali
, u32 addr
)
74 return ioread32(denali
->host
+ addr
);
77 static void denali_direct_write(struct denali_nand_info
*denali
, u32 addr
,
80 iowrite32(data
, denali
->host
+ addr
);
84 * Indexed Addressing - address translation module intervenes in passing the
85 * control information. This mode reduces the required address range. The
86 * control information and transferred data are latched by the registers in
87 * the translation module.
89 static u32
denali_indexed_read(struct denali_nand_info
*denali
, u32 addr
)
91 iowrite32(addr
, denali
->host
+ DENALI_INDEXED_CTRL
);
92 return ioread32(denali
->host
+ DENALI_INDEXED_DATA
);
95 static void denali_indexed_write(struct denali_nand_info
*denali
, u32 addr
,
98 iowrite32(addr
, denali
->host
+ DENALI_INDEXED_CTRL
);
99 iowrite32(data
, denali
->host
+ DENALI_INDEXED_DATA
);
103 * Use the configuration feature register to determine the maximum number of
104 * banks that the hardware supports.
106 static void denali_detect_max_banks(struct denali_nand_info
*denali
)
108 uint32_t features
= ioread32(denali
->reg
+ FEATURES
);
110 denali
->max_banks
= 1 << FIELD_GET(FEATURES__N_BANKS
, features
);
112 /* the encoding changed from rev 5.0 to 5.1 */
113 if (denali
->revision
< 0x0501)
114 denali
->max_banks
<<= 1;
117 static void denali_enable_irq(struct denali_nand_info
*denali
)
121 for (i
= 0; i
< DENALI_NR_BANKS
; i
++)
122 iowrite32(U32_MAX
, denali
->reg
+ INTR_EN(i
));
123 iowrite32(GLOBAL_INT_EN_FLAG
, denali
->reg
+ GLOBAL_INT_ENABLE
);
126 static void denali_disable_irq(struct denali_nand_info
*denali
)
130 for (i
= 0; i
< DENALI_NR_BANKS
; i
++)
131 iowrite32(0, denali
->reg
+ INTR_EN(i
));
132 iowrite32(0, denali
->reg
+ GLOBAL_INT_ENABLE
);
135 static void denali_clear_irq(struct denali_nand_info
*denali
,
136 int bank
, uint32_t irq_status
)
138 /* write one to clear bits */
139 iowrite32(irq_status
, denali
->reg
+ INTR_STATUS(bank
));
142 static void denali_clear_irq_all(struct denali_nand_info
*denali
)
146 for (i
= 0; i
< DENALI_NR_BANKS
; i
++)
147 denali_clear_irq(denali
, i
, U32_MAX
);
150 static irqreturn_t
denali_isr(int irq
, void *dev_id
)
152 struct denali_nand_info
*denali
= dev_id
;
153 irqreturn_t ret
= IRQ_NONE
;
157 spin_lock(&denali
->irq_lock
);
159 for (i
= 0; i
< DENALI_NR_BANKS
; i
++) {
160 irq_status
= ioread32(denali
->reg
+ INTR_STATUS(i
));
164 denali_clear_irq(denali
, i
, irq_status
);
166 if (i
!= denali
->active_bank
)
169 denali
->irq_status
|= irq_status
;
171 if (denali
->irq_status
& denali
->irq_mask
)
172 complete(&denali
->complete
);
175 spin_unlock(&denali
->irq_lock
);
180 static void denali_reset_irq(struct denali_nand_info
*denali
)
184 spin_lock_irqsave(&denali
->irq_lock
, flags
);
185 denali
->irq_status
= 0;
186 denali
->irq_mask
= 0;
187 spin_unlock_irqrestore(&denali
->irq_lock
, flags
);
190 static uint32_t denali_wait_for_irq(struct denali_nand_info
*denali
,
193 unsigned long time_left
, flags
;
196 spin_lock_irqsave(&denali
->irq_lock
, flags
);
198 irq_status
= denali
->irq_status
;
200 if (irq_mask
& irq_status
) {
201 /* return immediately if the IRQ has already happened. */
202 spin_unlock_irqrestore(&denali
->irq_lock
, flags
);
206 denali
->irq_mask
= irq_mask
;
207 reinit_completion(&denali
->complete
);
208 spin_unlock_irqrestore(&denali
->irq_lock
, flags
);
210 time_left
= wait_for_completion_timeout(&denali
->complete
,
211 msecs_to_jiffies(1000));
213 dev_err(denali
->dev
, "timeout while waiting for irq 0x%x\n",
218 return denali
->irq_status
;
221 static uint32_t denali_check_irq(struct denali_nand_info
*denali
)
226 spin_lock_irqsave(&denali
->irq_lock
, flags
);
227 irq_status
= denali
->irq_status
;
228 spin_unlock_irqrestore(&denali
->irq_lock
, flags
);
233 static void denali_read_buf(struct mtd_info
*mtd
, uint8_t *buf
, int len
)
235 struct denali_nand_info
*denali
= mtd_to_denali(mtd
);
236 u32 addr
= DENALI_MAP11_DATA
| DENALI_BANK(denali
);
239 for (i
= 0; i
< len
; i
++)
240 buf
[i
] = denali
->host_read(denali
, addr
);
243 static void denali_write_buf(struct mtd_info
*mtd
, const uint8_t *buf
, int len
)
245 struct denali_nand_info
*denali
= mtd_to_denali(mtd
);
246 u32 addr
= DENALI_MAP11_DATA
| DENALI_BANK(denali
);
249 for (i
= 0; i
< len
; i
++)
250 denali
->host_write(denali
, addr
, buf
[i
]);
253 static void denali_read_buf16(struct mtd_info
*mtd
, uint8_t *buf
, int len
)
255 struct denali_nand_info
*denali
= mtd_to_denali(mtd
);
256 u32 addr
= DENALI_MAP11_DATA
| DENALI_BANK(denali
);
257 uint16_t *buf16
= (uint16_t *)buf
;
260 for (i
= 0; i
< len
/ 2; i
++)
261 buf16
[i
] = denali
->host_read(denali
, addr
);
264 static void denali_write_buf16(struct mtd_info
*mtd
, const uint8_t *buf
,
267 struct denali_nand_info
*denali
= mtd_to_denali(mtd
);
268 u32 addr
= DENALI_MAP11_DATA
| DENALI_BANK(denali
);
269 const uint16_t *buf16
= (const uint16_t *)buf
;
272 for (i
= 0; i
< len
/ 2; i
++)
273 denali
->host_write(denali
, addr
, buf16
[i
]);
276 static uint8_t denali_read_byte(struct mtd_info
*mtd
)
280 denali_read_buf(mtd
, &byte
, 1);
285 static void denali_write_byte(struct mtd_info
*mtd
, uint8_t byte
)
287 denali_write_buf(mtd
, &byte
, 1);
290 static uint16_t denali_read_word(struct mtd_info
*mtd
)
294 denali_read_buf16(mtd
, (uint8_t *)&word
, 2);
299 static void denali_cmd_ctrl(struct mtd_info
*mtd
, int dat
, unsigned int ctrl
)
301 struct denali_nand_info
*denali
= mtd_to_denali(mtd
);
305 type
= DENALI_MAP11_CMD
;
306 else if (ctrl
& NAND_ALE
)
307 type
= DENALI_MAP11_ADDR
;
312 * Some commands are followed by chip->dev_ready or chip->waitfunc.
313 * irq_status must be cleared here to catch the R/B# interrupt later.
315 if (ctrl
& NAND_CTRL_CHANGE
)
316 denali_reset_irq(denali
);
318 denali
->host_write(denali
, DENALI_BANK(denali
) | type
, dat
);
321 static int denali_dev_ready(struct mtd_info
*mtd
)
323 struct denali_nand_info
*denali
= mtd_to_denali(mtd
);
325 return !!(denali_check_irq(denali
) & INTR__INT_ACT
);
328 static int denali_check_erased_page(struct mtd_info
*mtd
,
329 struct nand_chip
*chip
, uint8_t *buf
,
330 unsigned long uncor_ecc_flags
,
331 unsigned int max_bitflips
)
333 struct denali_nand_info
*denali
= mtd_to_denali(mtd
);
334 uint8_t *ecc_code
= chip
->oob_poi
+ denali
->oob_skip_bytes
;
335 int ecc_steps
= chip
->ecc
.steps
;
336 int ecc_size
= chip
->ecc
.size
;
337 int ecc_bytes
= chip
->ecc
.bytes
;
340 for (i
= 0; i
< ecc_steps
; i
++) {
341 if (!(uncor_ecc_flags
& BIT(i
)))
344 stat
= nand_check_erased_ecc_chunk(buf
, ecc_size
,
349 mtd
->ecc_stats
.failed
++;
351 mtd
->ecc_stats
.corrected
+= stat
;
352 max_bitflips
= max_t(unsigned int, max_bitflips
, stat
);
356 ecc_code
+= ecc_bytes
;
362 static int denali_hw_ecc_fixup(struct mtd_info
*mtd
,
363 struct denali_nand_info
*denali
,
364 unsigned long *uncor_ecc_flags
)
366 struct nand_chip
*chip
= mtd_to_nand(mtd
);
367 int bank
= denali
->active_bank
;
369 unsigned int max_bitflips
;
371 ecc_cor
= ioread32(denali
->reg
+ ECC_COR_INFO(bank
));
372 ecc_cor
>>= ECC_COR_INFO__SHIFT(bank
);
374 if (ecc_cor
& ECC_COR_INFO__UNCOR_ERR
) {
376 * This flag is set when uncorrectable error occurs at least in
377 * one ECC sector. We can not know "how many sectors", or
378 * "which sector(s)". We need erase-page check for all sectors.
380 *uncor_ecc_flags
= GENMASK(chip
->ecc
.steps
- 1, 0);
384 max_bitflips
= FIELD_GET(ECC_COR_INFO__MAX_ERRORS
, ecc_cor
);
387 * The register holds the maximum of per-sector corrected bitflips.
388 * This is suitable for the return value of the ->read_page() callback.
389 * Unfortunately, we can not know the total number of corrected bits in
390 * the page. Increase the stats by max_bitflips. (compromised solution)
392 mtd
->ecc_stats
.corrected
+= max_bitflips
;
397 static int denali_sw_ecc_fixup(struct mtd_info
*mtd
,
398 struct denali_nand_info
*denali
,
399 unsigned long *uncor_ecc_flags
, uint8_t *buf
)
401 unsigned int ecc_size
= denali
->nand
.ecc
.size
;
402 unsigned int bitflips
= 0;
403 unsigned int max_bitflips
= 0;
404 uint32_t err_addr
, err_cor_info
;
405 unsigned int err_byte
, err_sector
, err_device
;
406 uint8_t err_cor_value
;
407 unsigned int prev_sector
= 0;
410 denali_reset_irq(denali
);
413 err_addr
= ioread32(denali
->reg
+ ECC_ERROR_ADDRESS
);
414 err_sector
= FIELD_GET(ECC_ERROR_ADDRESS__SECTOR
, err_addr
);
415 err_byte
= FIELD_GET(ECC_ERROR_ADDRESS__OFFSET
, err_addr
);
417 err_cor_info
= ioread32(denali
->reg
+ ERR_CORRECTION_INFO
);
418 err_cor_value
= FIELD_GET(ERR_CORRECTION_INFO__BYTE
,
420 err_device
= FIELD_GET(ERR_CORRECTION_INFO__DEVICE
,
423 /* reset the bitflip counter when crossing ECC sector */
424 if (err_sector
!= prev_sector
)
427 if (err_cor_info
& ERR_CORRECTION_INFO__UNCOR
) {
429 * Check later if this is a real ECC error, or
432 *uncor_ecc_flags
|= BIT(err_sector
);
433 } else if (err_byte
< ecc_size
) {
435 * If err_byte is larger than ecc_size, means error
436 * happened in OOB, so we ignore it. It's no need for
437 * us to correct it err_device is represented the NAND
438 * error bits are happened in if there are more than
439 * one NAND connected.
442 unsigned int flips_in_byte
;
444 offset
= (err_sector
* ecc_size
+ err_byte
) *
445 denali
->devs_per_cs
+ err_device
;
447 /* correct the ECC error */
448 flips_in_byte
= hweight8(buf
[offset
] ^ err_cor_value
);
449 buf
[offset
] ^= err_cor_value
;
450 mtd
->ecc_stats
.corrected
+= flips_in_byte
;
451 bitflips
+= flips_in_byte
;
453 max_bitflips
= max(max_bitflips
, bitflips
);
456 prev_sector
= err_sector
;
457 } while (!(err_cor_info
& ERR_CORRECTION_INFO__LAST_ERR
));
460 * Once handle all ECC errors, controller will trigger an
461 * ECC_TRANSACTION_DONE interrupt.
463 irq_status
= denali_wait_for_irq(denali
, INTR__ECC_TRANSACTION_DONE
);
464 if (!(irq_status
& INTR__ECC_TRANSACTION_DONE
))
470 static void denali_setup_dma64(struct denali_nand_info
*denali
,
471 dma_addr_t dma_addr
, int page
, int write
)
474 const int page_count
= 1;
476 mode
= DENALI_MAP10
| DENALI_BANK(denali
) | page
;
478 /* DMA is a three step process */
481 * 1. setup transfer type, interrupt when complete,
482 * burst len = 64 bytes, the number of pages
484 denali
->host_write(denali
, mode
,
485 0x01002000 | (64 << 16) | (write
<< 8) | page_count
);
487 /* 2. set memory low address */
488 denali
->host_write(denali
, mode
, lower_32_bits(dma_addr
));
490 /* 3. set memory high address */
491 denali
->host_write(denali
, mode
, upper_32_bits(dma_addr
));
494 static void denali_setup_dma32(struct denali_nand_info
*denali
,
495 dma_addr_t dma_addr
, int page
, int write
)
498 const int page_count
= 1;
500 mode
= DENALI_MAP10
| DENALI_BANK(denali
);
502 /* DMA is a four step process */
504 /* 1. setup transfer type and # of pages */
505 denali
->host_write(denali
, mode
| page
,
506 0x2000 | (write
<< 8) | page_count
);
508 /* 2. set memory high address bits 23:8 */
509 denali
->host_write(denali
, mode
| ((dma_addr
>> 16) << 8), 0x2200);
511 /* 3. set memory low address bits 23:8 */
512 denali
->host_write(denali
, mode
| ((dma_addr
& 0xffff) << 8), 0x2300);
514 /* 4. interrupt when complete, burst len = 64 bytes */
515 denali
->host_write(denali
, mode
| 0x14000, 0x2400);
518 static int denali_pio_read(struct denali_nand_info
*denali
, void *buf
,
519 size_t size
, int page
, int raw
)
521 u32 addr
= DENALI_MAP01
| DENALI_BANK(denali
) | page
;
522 uint32_t *buf32
= (uint32_t *)buf
;
523 uint32_t irq_status
, ecc_err_mask
;
526 if (denali
->caps
& DENALI_CAP_HW_ECC_FIXUP
)
527 ecc_err_mask
= INTR__ECC_UNCOR_ERR
;
529 ecc_err_mask
= INTR__ECC_ERR
;
531 denali_reset_irq(denali
);
533 for (i
= 0; i
< size
/ 4; i
++)
534 *buf32
++ = denali
->host_read(denali
, addr
);
536 irq_status
= denali_wait_for_irq(denali
, INTR__PAGE_XFER_INC
);
537 if (!(irq_status
& INTR__PAGE_XFER_INC
))
540 if (irq_status
& INTR__ERASED_PAGE
)
541 memset(buf
, 0xff, size
);
543 return irq_status
& ecc_err_mask
? -EBADMSG
: 0;
546 static int denali_pio_write(struct denali_nand_info
*denali
,
547 const void *buf
, size_t size
, int page
, int raw
)
549 u32 addr
= DENALI_MAP01
| DENALI_BANK(denali
) | page
;
550 const uint32_t *buf32
= (uint32_t *)buf
;
554 denali_reset_irq(denali
);
556 for (i
= 0; i
< size
/ 4; i
++)
557 denali
->host_write(denali
, addr
, *buf32
++);
559 irq_status
= denali_wait_for_irq(denali
,
560 INTR__PROGRAM_COMP
| INTR__PROGRAM_FAIL
);
561 if (!(irq_status
& INTR__PROGRAM_COMP
))
567 static int denali_pio_xfer(struct denali_nand_info
*denali
, void *buf
,
568 size_t size
, int page
, int raw
, int write
)
571 return denali_pio_write(denali
, buf
, size
, page
, raw
);
573 return denali_pio_read(denali
, buf
, size
, page
, raw
);
576 static int denali_dma_xfer(struct denali_nand_info
*denali
, void *buf
,
577 size_t size
, int page
, int raw
, int write
)
580 uint32_t irq_mask
, irq_status
, ecc_err_mask
;
581 enum dma_data_direction dir
= write
? DMA_TO_DEVICE
: DMA_FROM_DEVICE
;
584 dma_addr
= dma_map_single(denali
->dev
, buf
, size
, dir
);
585 if (dma_mapping_error(denali
->dev
, dma_addr
)) {
586 dev_dbg(denali
->dev
, "Failed to DMA-map buffer. Trying PIO.\n");
587 return denali_pio_xfer(denali
, buf
, size
, page
, raw
, write
);
592 * INTR__PROGRAM_COMP is never asserted for the DMA transfer.
593 * We can use INTR__DMA_CMD_COMP instead. This flag is asserted
594 * when the page program is completed.
596 irq_mask
= INTR__DMA_CMD_COMP
| INTR__PROGRAM_FAIL
;
598 } else if (denali
->caps
& DENALI_CAP_HW_ECC_FIXUP
) {
599 irq_mask
= INTR__DMA_CMD_COMP
;
600 ecc_err_mask
= INTR__ECC_UNCOR_ERR
;
602 irq_mask
= INTR__DMA_CMD_COMP
;
603 ecc_err_mask
= INTR__ECC_ERR
;
606 iowrite32(DMA_ENABLE__FLAG
, denali
->reg
+ DMA_ENABLE
);
608 denali_reset_irq(denali
);
609 denali
->setup_dma(denali
, dma_addr
, page
, write
);
611 irq_status
= denali_wait_for_irq(denali
, irq_mask
);
612 if (!(irq_status
& INTR__DMA_CMD_COMP
))
614 else if (irq_status
& ecc_err_mask
)
617 iowrite32(0, denali
->reg
+ DMA_ENABLE
);
619 dma_unmap_single(denali
->dev
, dma_addr
, size
, dir
);
621 if (irq_status
& INTR__ERASED_PAGE
)
622 memset(buf
, 0xff, size
);
627 static int denali_data_xfer(struct denali_nand_info
*denali
, void *buf
,
628 size_t size
, int page
, int raw
, int write
)
630 iowrite32(raw
? 0 : ECC_ENABLE__FLAG
, denali
->reg
+ ECC_ENABLE
);
631 iowrite32(raw
? TRANSFER_SPARE_REG__FLAG
: 0,
632 denali
->reg
+ TRANSFER_SPARE_REG
);
634 if (denali
->dma_avail
)
635 return denali_dma_xfer(denali
, buf
, size
, page
, raw
, write
);
637 return denali_pio_xfer(denali
, buf
, size
, page
, raw
, write
);
640 static void denali_oob_xfer(struct mtd_info
*mtd
, struct nand_chip
*chip
,
643 struct denali_nand_info
*denali
= mtd_to_denali(mtd
);
644 int writesize
= mtd
->writesize
;
645 int oobsize
= mtd
->oobsize
;
646 uint8_t *bufpoi
= chip
->oob_poi
;
647 int ecc_steps
= chip
->ecc
.steps
;
648 int ecc_size
= chip
->ecc
.size
;
649 int ecc_bytes
= chip
->ecc
.bytes
;
650 int oob_skip
= denali
->oob_skip_bytes
;
651 size_t size
= writesize
+ oobsize
;
654 /* BBM at the beginning of the OOB area */
656 nand_prog_page_begin_op(chip
, page
, writesize
, bufpoi
,
659 nand_read_page_op(chip
, page
, writesize
, bufpoi
, oob_skip
);
663 for (i
= 0; i
< ecc_steps
; i
++) {
664 pos
= ecc_size
+ i
* (ecc_size
+ ecc_bytes
);
667 if (pos
>= writesize
)
669 else if (pos
+ len
> writesize
)
670 len
= writesize
- pos
;
673 nand_change_write_column_op(chip
, pos
, bufpoi
, len
,
676 nand_change_read_column_op(chip
, pos
, bufpoi
, len
,
679 if (len
< ecc_bytes
) {
680 len
= ecc_bytes
- len
;
682 nand_change_write_column_op(chip
, writesize
+
686 nand_change_read_column_op(chip
, writesize
+
694 len
= oobsize
- (bufpoi
- chip
->oob_poi
);
696 nand_change_write_column_op(chip
, size
- len
, bufpoi
, len
,
699 nand_change_read_column_op(chip
, size
- len
, bufpoi
, len
,
703 static int denali_read_page_raw(struct mtd_info
*mtd
, struct nand_chip
*chip
,
704 uint8_t *buf
, int oob_required
, int page
)
706 struct denali_nand_info
*denali
= mtd_to_denali(mtd
);
707 int writesize
= mtd
->writesize
;
708 int oobsize
= mtd
->oobsize
;
709 int ecc_steps
= chip
->ecc
.steps
;
710 int ecc_size
= chip
->ecc
.size
;
711 int ecc_bytes
= chip
->ecc
.bytes
;
712 void *tmp_buf
= denali
->buf
;
713 int oob_skip
= denali
->oob_skip_bytes
;
714 size_t size
= writesize
+ oobsize
;
715 int ret
, i
, pos
, len
;
717 ret
= denali_data_xfer(denali
, tmp_buf
, size
, page
, 1, 0);
721 /* Arrange the buffer for syndrome payload/ecc layout */
723 for (i
= 0; i
< ecc_steps
; i
++) {
724 pos
= i
* (ecc_size
+ ecc_bytes
);
727 if (pos
>= writesize
)
729 else if (pos
+ len
> writesize
)
730 len
= writesize
- pos
;
732 memcpy(buf
, tmp_buf
+ pos
, len
);
734 if (len
< ecc_size
) {
735 len
= ecc_size
- len
;
736 memcpy(buf
, tmp_buf
+ writesize
+ oob_skip
,
744 uint8_t *oob
= chip
->oob_poi
;
746 /* BBM at the beginning of the OOB area */
747 memcpy(oob
, tmp_buf
+ writesize
, oob_skip
);
751 for (i
= 0; i
< ecc_steps
; i
++) {
752 pos
= ecc_size
+ i
* (ecc_size
+ ecc_bytes
);
755 if (pos
>= writesize
)
757 else if (pos
+ len
> writesize
)
758 len
= writesize
- pos
;
760 memcpy(oob
, tmp_buf
+ pos
, len
);
762 if (len
< ecc_bytes
) {
763 len
= ecc_bytes
- len
;
764 memcpy(oob
, tmp_buf
+ writesize
+ oob_skip
,
771 len
= oobsize
- (oob
- chip
->oob_poi
);
772 memcpy(oob
, tmp_buf
+ size
- len
, len
);
778 static int denali_read_oob(struct mtd_info
*mtd
, struct nand_chip
*chip
,
781 denali_oob_xfer(mtd
, chip
, page
, 0);
786 static int denali_write_oob(struct mtd_info
*mtd
, struct nand_chip
*chip
,
789 struct denali_nand_info
*denali
= mtd_to_denali(mtd
);
791 denali_reset_irq(denali
);
793 denali_oob_xfer(mtd
, chip
, page
, 1);
795 return nand_prog_page_end_op(chip
);
798 static int denali_read_page(struct mtd_info
*mtd
, struct nand_chip
*chip
,
799 uint8_t *buf
, int oob_required
, int page
)
801 struct denali_nand_info
*denali
= mtd_to_denali(mtd
);
802 unsigned long uncor_ecc_flags
= 0;
806 ret
= denali_data_xfer(denali
, buf
, mtd
->writesize
, page
, 0, 0);
807 if (ret
&& ret
!= -EBADMSG
)
810 if (denali
->caps
& DENALI_CAP_HW_ECC_FIXUP
)
811 stat
= denali_hw_ecc_fixup(mtd
, denali
, &uncor_ecc_flags
);
812 else if (ret
== -EBADMSG
)
813 stat
= denali_sw_ecc_fixup(mtd
, denali
, &uncor_ecc_flags
, buf
);
818 if (uncor_ecc_flags
) {
819 ret
= denali_read_oob(mtd
, chip
, page
);
823 stat
= denali_check_erased_page(mtd
, chip
, buf
,
824 uncor_ecc_flags
, stat
);
830 static int denali_write_page_raw(struct mtd_info
*mtd
, struct nand_chip
*chip
,
831 const uint8_t *buf
, int oob_required
, int page
)
833 struct denali_nand_info
*denali
= mtd_to_denali(mtd
);
834 int writesize
= mtd
->writesize
;
835 int oobsize
= mtd
->oobsize
;
836 int ecc_steps
= chip
->ecc
.steps
;
837 int ecc_size
= chip
->ecc
.size
;
838 int ecc_bytes
= chip
->ecc
.bytes
;
839 void *tmp_buf
= denali
->buf
;
840 int oob_skip
= denali
->oob_skip_bytes
;
841 size_t size
= writesize
+ oobsize
;
845 * Fill the buffer with 0xff first except the full page transfer.
846 * This simplifies the logic.
848 if (!buf
|| !oob_required
)
849 memset(tmp_buf
, 0xff, size
);
851 /* Arrange the buffer for syndrome payload/ecc layout */
853 for (i
= 0; i
< ecc_steps
; i
++) {
854 pos
= i
* (ecc_size
+ ecc_bytes
);
857 if (pos
>= writesize
)
859 else if (pos
+ len
> writesize
)
860 len
= writesize
- pos
;
862 memcpy(tmp_buf
+ pos
, buf
, len
);
864 if (len
< ecc_size
) {
865 len
= ecc_size
- len
;
866 memcpy(tmp_buf
+ writesize
+ oob_skip
, buf
,
874 const uint8_t *oob
= chip
->oob_poi
;
876 /* BBM at the beginning of the OOB area */
877 memcpy(tmp_buf
+ writesize
, oob
, oob_skip
);
881 for (i
= 0; i
< ecc_steps
; i
++) {
882 pos
= ecc_size
+ i
* (ecc_size
+ ecc_bytes
);
885 if (pos
>= writesize
)
887 else if (pos
+ len
> writesize
)
888 len
= writesize
- pos
;
890 memcpy(tmp_buf
+ pos
, oob
, len
);
892 if (len
< ecc_bytes
) {
893 len
= ecc_bytes
- len
;
894 memcpy(tmp_buf
+ writesize
+ oob_skip
, oob
,
901 len
= oobsize
- (oob
- chip
->oob_poi
);
902 memcpy(tmp_buf
+ size
- len
, oob
, len
);
905 return denali_data_xfer(denali
, tmp_buf
, size
, page
, 1, 1);
908 static int denali_write_page(struct mtd_info
*mtd
, struct nand_chip
*chip
,
909 const uint8_t *buf
, int oob_required
, int page
)
911 struct denali_nand_info
*denali
= mtd_to_denali(mtd
);
913 return denali_data_xfer(denali
, (void *)buf
, mtd
->writesize
,
917 static void denali_select_chip(struct mtd_info
*mtd
, int chip
)
919 struct denali_nand_info
*denali
= mtd_to_denali(mtd
);
921 denali
->active_bank
= chip
;
924 static int denali_waitfunc(struct mtd_info
*mtd
, struct nand_chip
*chip
)
926 struct denali_nand_info
*denali
= mtd_to_denali(mtd
);
929 /* R/B# pin transitioned from low to high? */
930 irq_status
= denali_wait_for_irq(denali
, INTR__INT_ACT
);
932 return irq_status
& INTR__INT_ACT
? 0 : NAND_STATUS_FAIL
;
935 static int denali_erase(struct mtd_info
*mtd
, int page
)
937 struct denali_nand_info
*denali
= mtd_to_denali(mtd
);
940 denali_reset_irq(denali
);
942 denali
->host_write(denali
, DENALI_MAP10
| DENALI_BANK(denali
) | page
,
945 /* wait for erase to complete or failure to occur */
946 irq_status
= denali_wait_for_irq(denali
,
947 INTR__ERASE_COMP
| INTR__ERASE_FAIL
);
949 return irq_status
& INTR__ERASE_COMP
? 0 : -EIO
;
952 static int denali_setup_data_interface(struct mtd_info
*mtd
, int chipnr
,
953 const struct nand_data_interface
*conf
)
955 struct denali_nand_info
*denali
= mtd_to_denali(mtd
);
956 const struct nand_sdr_timings
*timings
;
958 int acc_clks
, re_2_we
, re_2_re
, we_2_re
, addr_2_data
;
959 int rdwr_en_lo
, rdwr_en_hi
, rdwr_en_lo_hi
, cs_setup
;
960 int addr_2_data_mask
;
963 timings
= nand_get_sdr_timings(conf
);
965 return PTR_ERR(timings
);
967 /* clk_x period in picoseconds */
968 t_clk
= DIV_ROUND_DOWN_ULL(1000000000000ULL, denali
->clk_x_rate
);
972 if (chipnr
== NAND_DATA_IFACE_CHECK_ONLY
)
975 /* tREA -> ACC_CLKS */
976 acc_clks
= DIV_ROUND_UP(timings
->tREA_max
, t_clk
);
977 acc_clks
= min_t(int, acc_clks
, ACC_CLKS__VALUE
);
979 tmp
= ioread32(denali
->reg
+ ACC_CLKS
);
980 tmp
&= ~ACC_CLKS__VALUE
;
981 tmp
|= FIELD_PREP(ACC_CLKS__VALUE
, acc_clks
);
982 iowrite32(tmp
, denali
->reg
+ ACC_CLKS
);
984 /* tRWH -> RE_2_WE */
985 re_2_we
= DIV_ROUND_UP(timings
->tRHW_min
, t_clk
);
986 re_2_we
= min_t(int, re_2_we
, RE_2_WE__VALUE
);
988 tmp
= ioread32(denali
->reg
+ RE_2_WE
);
989 tmp
&= ~RE_2_WE__VALUE
;
990 tmp
|= FIELD_PREP(RE_2_WE__VALUE
, re_2_we
);
991 iowrite32(tmp
, denali
->reg
+ RE_2_WE
);
993 /* tRHZ -> RE_2_RE */
994 re_2_re
= DIV_ROUND_UP(timings
->tRHZ_max
, t_clk
);
995 re_2_re
= min_t(int, re_2_re
, RE_2_RE__VALUE
);
997 tmp
= ioread32(denali
->reg
+ RE_2_RE
);
998 tmp
&= ~RE_2_RE__VALUE
;
999 tmp
|= FIELD_PREP(RE_2_RE__VALUE
, re_2_re
);
1000 iowrite32(tmp
, denali
->reg
+ RE_2_RE
);
1003 * tCCS, tWHR -> WE_2_RE
1005 * With WE_2_RE properly set, the Denali controller automatically takes
1006 * care of the delay; the driver need not set NAND_WAIT_TCCS.
1008 we_2_re
= DIV_ROUND_UP(max(timings
->tCCS_min
, timings
->tWHR_min
),
1010 we_2_re
= min_t(int, we_2_re
, TWHR2_AND_WE_2_RE__WE_2_RE
);
1012 tmp
= ioread32(denali
->reg
+ TWHR2_AND_WE_2_RE
);
1013 tmp
&= ~TWHR2_AND_WE_2_RE__WE_2_RE
;
1014 tmp
|= FIELD_PREP(TWHR2_AND_WE_2_RE__WE_2_RE
, we_2_re
);
1015 iowrite32(tmp
, denali
->reg
+ TWHR2_AND_WE_2_RE
);
1017 /* tADL -> ADDR_2_DATA */
1019 /* for older versions, ADDR_2_DATA is only 6 bit wide */
1020 addr_2_data_mask
= TCWAW_AND_ADDR_2_DATA__ADDR_2_DATA
;
1021 if (denali
->revision
< 0x0501)
1022 addr_2_data_mask
>>= 1;
1024 addr_2_data
= DIV_ROUND_UP(timings
->tADL_min
, t_clk
);
1025 addr_2_data
= min_t(int, addr_2_data
, addr_2_data_mask
);
1027 tmp
= ioread32(denali
->reg
+ TCWAW_AND_ADDR_2_DATA
);
1028 tmp
&= ~TCWAW_AND_ADDR_2_DATA__ADDR_2_DATA
;
1029 tmp
|= FIELD_PREP(TCWAW_AND_ADDR_2_DATA__ADDR_2_DATA
, addr_2_data
);
1030 iowrite32(tmp
, denali
->reg
+ TCWAW_AND_ADDR_2_DATA
);
1032 /* tREH, tWH -> RDWR_EN_HI_CNT */
1033 rdwr_en_hi
= DIV_ROUND_UP(max(timings
->tREH_min
, timings
->tWH_min
),
1035 rdwr_en_hi
= min_t(int, rdwr_en_hi
, RDWR_EN_HI_CNT__VALUE
);
1037 tmp
= ioread32(denali
->reg
+ RDWR_EN_HI_CNT
);
1038 tmp
&= ~RDWR_EN_HI_CNT__VALUE
;
1039 tmp
|= FIELD_PREP(RDWR_EN_HI_CNT__VALUE
, rdwr_en_hi
);
1040 iowrite32(tmp
, denali
->reg
+ RDWR_EN_HI_CNT
);
1042 /* tRP, tWP -> RDWR_EN_LO_CNT */
1043 rdwr_en_lo
= DIV_ROUND_UP(max(timings
->tRP_min
, timings
->tWP_min
),
1045 rdwr_en_lo_hi
= DIV_ROUND_UP(max(timings
->tRC_min
, timings
->tWC_min
),
1047 rdwr_en_lo_hi
= max(rdwr_en_lo_hi
, DENALI_CLK_X_MULT
);
1048 rdwr_en_lo
= max(rdwr_en_lo
, rdwr_en_lo_hi
- rdwr_en_hi
);
1049 rdwr_en_lo
= min_t(int, rdwr_en_lo
, RDWR_EN_LO_CNT__VALUE
);
1051 tmp
= ioread32(denali
->reg
+ RDWR_EN_LO_CNT
);
1052 tmp
&= ~RDWR_EN_LO_CNT__VALUE
;
1053 tmp
|= FIELD_PREP(RDWR_EN_LO_CNT__VALUE
, rdwr_en_lo
);
1054 iowrite32(tmp
, denali
->reg
+ RDWR_EN_LO_CNT
);
1056 /* tCS, tCEA -> CS_SETUP_CNT */
1057 cs_setup
= max3((int)DIV_ROUND_UP(timings
->tCS_min
, t_clk
) - rdwr_en_lo
,
1058 (int)DIV_ROUND_UP(timings
->tCEA_max
, t_clk
) - acc_clks
,
1060 cs_setup
= min_t(int, cs_setup
, CS_SETUP_CNT__VALUE
);
1062 tmp
= ioread32(denali
->reg
+ CS_SETUP_CNT
);
1063 tmp
&= ~CS_SETUP_CNT__VALUE
;
1064 tmp
|= FIELD_PREP(CS_SETUP_CNT__VALUE
, cs_setup
);
1065 iowrite32(tmp
, denali
->reg
+ CS_SETUP_CNT
);
1070 static void denali_reset_banks(struct denali_nand_info
*denali
)
1075 for (i
= 0; i
< denali
->max_banks
; i
++) {
1076 denali
->active_bank
= i
;
1078 denali_reset_irq(denali
);
1080 iowrite32(DEVICE_RESET__BANK(i
),
1081 denali
->reg
+ DEVICE_RESET
);
1083 irq_status
= denali_wait_for_irq(denali
,
1084 INTR__RST_COMP
| INTR__INT_ACT
| INTR__TIME_OUT
);
1085 if (!(irq_status
& INTR__INT_ACT
))
1089 dev_dbg(denali
->dev
, "%d chips connected\n", i
);
1090 denali
->max_banks
= i
;
1093 static void denali_hw_init(struct denali_nand_info
*denali
)
1096 * The REVISION register may not be reliable. Platforms are allowed to
1099 if (!denali
->revision
)
1100 denali
->revision
= swab16(ioread32(denali
->reg
+ REVISION
));
1103 * tell driver how many bit controller will skip before
1104 * writing ECC code in OOB, this register may be already
1105 * set by firmware. So we read this value out.
1106 * if this value is 0, just let it be.
1108 denali
->oob_skip_bytes
= ioread32(denali
->reg
+ SPARE_AREA_SKIP_BYTES
);
1109 denali_detect_max_banks(denali
);
1110 iowrite32(0x0F, denali
->reg
+ RB_PIN_ENABLED
);
1111 iowrite32(CHIP_EN_DONT_CARE__FLAG
, denali
->reg
+ CHIP_ENABLE_DONT_CARE
);
1113 iowrite32(0xffff, denali
->reg
+ SPARE_AREA_MARKER
);
1116 int denali_calc_ecc_bytes(int step_size
, int strength
)
1118 /* BCH code. Denali requires ecc.bytes to be multiple of 2 */
1119 return DIV_ROUND_UP(strength
* fls(step_size
* 8), 16) * 2;
1121 EXPORT_SYMBOL(denali_calc_ecc_bytes
);
1123 static int denali_ecc_setup(struct mtd_info
*mtd
, struct nand_chip
*chip
,
1124 struct denali_nand_info
*denali
)
1126 int oobavail
= mtd
->oobsize
- denali
->oob_skip_bytes
;
1130 * If .size and .strength are already set (usually by DT),
1131 * check if they are supported by this controller.
1133 if (chip
->ecc
.size
&& chip
->ecc
.strength
)
1134 return nand_check_ecc_caps(chip
, denali
->ecc_caps
, oobavail
);
1137 * We want .size and .strength closest to the chip's requirement
1138 * unless NAND_ECC_MAXIMIZE is requested.
1140 if (!(chip
->ecc
.options
& NAND_ECC_MAXIMIZE
)) {
1141 ret
= nand_match_ecc_req(chip
, denali
->ecc_caps
, oobavail
);
1146 /* Max ECC strength is the last thing we can do */
1147 return nand_maximize_ecc(chip
, denali
->ecc_caps
, oobavail
);
1150 static int denali_ooblayout_ecc(struct mtd_info
*mtd
, int section
,
1151 struct mtd_oob_region
*oobregion
)
1153 struct denali_nand_info
*denali
= mtd_to_denali(mtd
);
1154 struct nand_chip
*chip
= mtd_to_nand(mtd
);
1159 oobregion
->offset
= denali
->oob_skip_bytes
;
1160 oobregion
->length
= chip
->ecc
.total
;
1165 static int denali_ooblayout_free(struct mtd_info
*mtd
, int section
,
1166 struct mtd_oob_region
*oobregion
)
1168 struct denali_nand_info
*denali
= mtd_to_denali(mtd
);
1169 struct nand_chip
*chip
= mtd_to_nand(mtd
);
1174 oobregion
->offset
= chip
->ecc
.total
+ denali
->oob_skip_bytes
;
1175 oobregion
->length
= mtd
->oobsize
- oobregion
->offset
;
1180 static const struct mtd_ooblayout_ops denali_ooblayout_ops
= {
1181 .ecc
= denali_ooblayout_ecc
,
1182 .free
= denali_ooblayout_free
,
1185 static int denali_multidev_fixup(struct denali_nand_info
*denali
)
1187 struct nand_chip
*chip
= &denali
->nand
;
1188 struct mtd_info
*mtd
= nand_to_mtd(chip
);
1191 * Support for multi device:
1192 * When the IP configuration is x16 capable and two x8 chips are
1193 * connected in parallel, DEVICES_CONNECTED should be set to 2.
1194 * In this case, the core framework knows nothing about this fact,
1195 * so we should tell it the _logical_ pagesize and anything necessary.
1197 denali
->devs_per_cs
= ioread32(denali
->reg
+ DEVICES_CONNECTED
);
1200 * On some SoCs, DEVICES_CONNECTED is not auto-detected.
1201 * For those, DEVICES_CONNECTED is left to 0. Set 1 if it is the case.
1203 if (denali
->devs_per_cs
== 0) {
1204 denali
->devs_per_cs
= 1;
1205 iowrite32(1, denali
->reg
+ DEVICES_CONNECTED
);
1208 if (denali
->devs_per_cs
== 1)
1211 if (denali
->devs_per_cs
!= 2) {
1212 dev_err(denali
->dev
, "unsupported number of devices %d\n",
1213 denali
->devs_per_cs
);
1217 /* 2 chips in parallel */
1219 mtd
->erasesize
<<= 1;
1220 mtd
->writesize
<<= 1;
1222 chip
->chipsize
<<= 1;
1223 chip
->page_shift
+= 1;
1224 chip
->phys_erase_shift
+= 1;
1225 chip
->bbt_erase_shift
+= 1;
1226 chip
->chip_shift
+= 1;
1227 chip
->pagemask
<<= 1;
1228 chip
->ecc
.size
<<= 1;
1229 chip
->ecc
.bytes
<<= 1;
1230 chip
->ecc
.strength
<<= 1;
1231 denali
->oob_skip_bytes
<<= 1;
1236 int denali_init(struct denali_nand_info
*denali
)
1238 struct nand_chip
*chip
= &denali
->nand
;
1239 struct mtd_info
*mtd
= nand_to_mtd(chip
);
1240 u32 features
= ioread32(denali
->reg
+ FEATURES
);
1243 mtd
->dev
.parent
= denali
->dev
;
1244 denali_hw_init(denali
);
1246 init_completion(&denali
->complete
);
1247 spin_lock_init(&denali
->irq_lock
);
1249 denali_clear_irq_all(denali
);
1251 ret
= devm_request_irq(denali
->dev
, denali
->irq
, denali_isr
,
1252 IRQF_SHARED
, DENALI_NAND_NAME
, denali
);
1254 dev_err(denali
->dev
, "Unable to request IRQ\n");
1258 denali_enable_irq(denali
);
1259 denali_reset_banks(denali
);
1261 denali
->active_bank
= DENALI_INVALID_BANK
;
1263 nand_set_flash_node(chip
, denali
->dev
->of_node
);
1264 /* Fallback to the default name if DT did not give "label" property */
1266 mtd
->name
= "denali-nand";
1268 chip
->select_chip
= denali_select_chip
;
1269 chip
->read_byte
= denali_read_byte
;
1270 chip
->write_byte
= denali_write_byte
;
1271 chip
->read_word
= denali_read_word
;
1272 chip
->cmd_ctrl
= denali_cmd_ctrl
;
1273 chip
->dev_ready
= denali_dev_ready
;
1274 chip
->waitfunc
= denali_waitfunc
;
1276 if (features
& FEATURES__INDEX_ADDR
) {
1277 denali
->host_read
= denali_indexed_read
;
1278 denali
->host_write
= denali_indexed_write
;
1280 denali
->host_read
= denali_direct_read
;
1281 denali
->host_write
= denali_direct_write
;
1284 /* clk rate info is needed for setup_data_interface */
1285 if (denali
->clk_x_rate
)
1286 chip
->setup_data_interface
= denali_setup_data_interface
;
1288 ret
= nand_scan_ident(mtd
, denali
->max_banks
, NULL
);
1292 if (ioread32(denali
->reg
+ FEATURES
) & FEATURES__DMA
)
1293 denali
->dma_avail
= 1;
1295 if (denali
->dma_avail
) {
1296 int dma_bit
= denali
->caps
& DENALI_CAP_DMA_64BIT
? 64 : 32;
1298 ret
= dma_set_mask(denali
->dev
, DMA_BIT_MASK(dma_bit
));
1300 dev_info(denali
->dev
,
1301 "Failed to set DMA mask. Disabling DMA.\n");
1302 denali
->dma_avail
= 0;
1306 if (denali
->dma_avail
) {
1307 chip
->options
|= NAND_USE_BOUNCE_BUFFER
;
1308 chip
->buf_align
= 16;
1309 if (denali
->caps
& DENALI_CAP_DMA_64BIT
)
1310 denali
->setup_dma
= denali_setup_dma64
;
1312 denali
->setup_dma
= denali_setup_dma32
;
1315 chip
->bbt_options
|= NAND_BBT_USE_FLASH
;
1316 chip
->bbt_options
|= NAND_BBT_NO_OOB
;
1317 chip
->ecc
.mode
= NAND_ECC_HW_SYNDROME
;
1318 chip
->options
|= NAND_NO_SUBPAGE_WRITE
;
1320 ret
= denali_ecc_setup(mtd
, chip
, denali
);
1322 dev_err(denali
->dev
, "Failed to setup ECC settings.\n");
1326 dev_dbg(denali
->dev
,
1327 "chosen ECC settings: step=%d, strength=%d, bytes=%d\n",
1328 chip
->ecc
.size
, chip
->ecc
.strength
, chip
->ecc
.bytes
);
1330 iowrite32(FIELD_PREP(ECC_CORRECTION__ERASE_THRESHOLD
, 1) |
1331 FIELD_PREP(ECC_CORRECTION__VALUE
, chip
->ecc
.strength
),
1332 denali
->reg
+ ECC_CORRECTION
);
1333 iowrite32(mtd
->erasesize
/ mtd
->writesize
,
1334 denali
->reg
+ PAGES_PER_BLOCK
);
1335 iowrite32(chip
->options
& NAND_BUSWIDTH_16
? 1 : 0,
1336 denali
->reg
+ DEVICE_WIDTH
);
1337 iowrite32(chip
->options
& NAND_ROW_ADDR_3
? 0 : TWO_ROW_ADDR_CYCLES__FLAG
,
1338 denali
->reg
+ TWO_ROW_ADDR_CYCLES
);
1339 iowrite32(mtd
->writesize
, denali
->reg
+ DEVICE_MAIN_AREA_SIZE
);
1340 iowrite32(mtd
->oobsize
, denali
->reg
+ DEVICE_SPARE_AREA_SIZE
);
1342 iowrite32(chip
->ecc
.size
, denali
->reg
+ CFG_DATA_BLOCK_SIZE
);
1343 iowrite32(chip
->ecc
.size
, denali
->reg
+ CFG_LAST_DATA_BLOCK_SIZE
);
1344 /* chip->ecc.steps is set by nand_scan_tail(); not available here */
1345 iowrite32(mtd
->writesize
/ chip
->ecc
.size
,
1346 denali
->reg
+ CFG_NUM_DATA_BLOCKS
);
1348 mtd_set_ooblayout(mtd
, &denali_ooblayout_ops
);
1350 if (chip
->options
& NAND_BUSWIDTH_16
) {
1351 chip
->read_buf
= denali_read_buf16
;
1352 chip
->write_buf
= denali_write_buf16
;
1354 chip
->read_buf
= denali_read_buf
;
1355 chip
->write_buf
= denali_write_buf
;
1357 chip
->ecc
.read_page
= denali_read_page
;
1358 chip
->ecc
.read_page_raw
= denali_read_page_raw
;
1359 chip
->ecc
.write_page
= denali_write_page
;
1360 chip
->ecc
.write_page_raw
= denali_write_page_raw
;
1361 chip
->ecc
.read_oob
= denali_read_oob
;
1362 chip
->ecc
.write_oob
= denali_write_oob
;
1363 chip
->erase
= denali_erase
;
1365 ret
= denali_multidev_fixup(denali
);
1370 * This buffer is DMA-mapped by denali_{read,write}_page_raw. Do not
1371 * use devm_kmalloc() because the memory allocated by devm_ does not
1372 * guarantee DMA-safe alignment.
1374 denali
->buf
= kmalloc(mtd
->writesize
+ mtd
->oobsize
, GFP_KERNEL
);
1380 ret
= nand_scan_tail(mtd
);
1384 ret
= mtd_device_register(mtd
, NULL
, 0);
1386 dev_err(denali
->dev
, "Failed to register MTD: %d\n", ret
);
1394 denali_disable_irq(denali
);
1398 EXPORT_SYMBOL(denali_init
);
1400 void denali_remove(struct denali_nand_info
*denali
)
1402 struct mtd_info
*mtd
= nand_to_mtd(&denali
->nand
);
1406 denali_disable_irq(denali
);
1408 EXPORT_SYMBOL(denali_remove
);