2 * SuperH FLCTL nand controller
4 * Copyright © 2008 Renesas Solutions Corp.
5 * Copyright © 2008 Atom Create Engineering Co., Ltd.
7 * Based on fsl_elbc_nand.c, Copyright © 2006-2007 Freescale Semiconductor
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; version 2 of the License.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24 #include <linux/module.h>
25 #include <linux/kernel.h>
26 #include <linux/delay.h>
28 #include <linux/platform_device.h>
30 #include <linux/mtd/mtd.h>
31 #include <linux/mtd/nand.h>
32 #include <linux/mtd/partitions.h>
33 #include <linux/mtd/sh_flctl.h>
35 static struct nand_ecclayout flctl_4secc_oob_16
= {
37 .eccpos
= {0, 1, 2, 3, 4, 5, 6, 7, 8, 9},
43 static struct nand_ecclayout flctl_4secc_oob_64
= {
45 .eccpos
= {48, 49, 50, 51, 52, 53, 54, 55, 56, 57},
51 static uint8_t scan_ff_pattern
[] = { 0xff, 0xff };
53 static struct nand_bbt_descr flctl_4secc_smallpage
= {
54 .options
= NAND_BBT_SCAN2NDPAGE
,
57 .pattern
= scan_ff_pattern
,
60 static struct nand_bbt_descr flctl_4secc_largepage
= {
61 .options
= NAND_BBT_SCAN2NDPAGE
,
64 .pattern
= scan_ff_pattern
,
67 static void empty_fifo(struct sh_flctl
*flctl
)
69 writel(0x000c0000, FLINTDMACR(flctl
)); /* FIFO Clear */
70 writel(0x00000000, FLINTDMACR(flctl
)); /* Clear Error flags */
73 static void start_translation(struct sh_flctl
*flctl
)
75 writeb(TRSTRT
, FLTRCR(flctl
));
78 static void wait_completion(struct sh_flctl
*flctl
)
80 uint32_t timeout
= LOOP_TIMEOUT_MAX
;
83 if (readb(FLTRCR(flctl
)) & TREND
) {
84 writeb(0x0, FLTRCR(flctl
));
90 printk(KERN_ERR
"wait_completion(): Timeout occured \n");
91 writeb(0x0, FLTRCR(flctl
));
94 static void set_addr(struct mtd_info
*mtd
, int column
, int page_addr
)
96 struct sh_flctl
*flctl
= mtd_to_flctl(mtd
);
100 addr
= page_addr
; /* ERASE1 */
101 } else if (page_addr
!= -1) {
102 /* SEQIN, READ0, etc.. */
103 if (flctl
->page_size
) {
104 addr
= column
& 0x0FFF;
105 addr
|= (page_addr
& 0xff) << 16;
106 addr
|= ((page_addr
>> 8) & 0xff) << 24;
108 if (flctl
->rw_ADRCNT
== ADRCNT2_E
) {
110 addr2
= (page_addr
>> 16) & 0xff;
111 writel(addr2
, FLADR2(flctl
));
115 addr
|= (page_addr
& 0xff) << 8;
116 addr
|= ((page_addr
>> 8) & 0xff) << 16;
117 addr
|= ((page_addr
>> 16) & 0xff) << 24;
120 writel(addr
, FLADR(flctl
));
123 static void wait_rfifo_ready(struct sh_flctl
*flctl
)
125 uint32_t timeout
= LOOP_TIMEOUT_MAX
;
130 val
= readl(FLDTCNTR(flctl
)) >> 16;
135 printk(KERN_ERR
"wait_rfifo_ready(): Timeout occured \n");
138 static void wait_wfifo_ready(struct sh_flctl
*flctl
)
140 uint32_t len
, timeout
= LOOP_TIMEOUT_MAX
;
144 len
= (readl(FLDTCNTR(flctl
)) >> 16) & 0xFF;
149 printk(KERN_ERR
"wait_wfifo_ready(): Timeout occured \n");
152 static int wait_recfifo_ready(struct sh_flctl
*flctl
, int sector_number
)
154 uint32_t timeout
= LOOP_TIMEOUT_MAX
;
156 void __iomem
*ecc_reg
[4];
160 memset(checked
, 0, sizeof(checked
));
163 size
= readl(FLDTCNTR(flctl
)) >> 24;
165 return 0; /* success */
167 if (readl(FL4ECCCR(flctl
)) & _4ECCFA
)
168 return 1; /* can't correct */
171 if (!(readl(FL4ECCCR(flctl
)) & _4ECCEND
))
174 /* start error correction */
175 ecc_reg
[0] = FL4ECCRESULT0(flctl
);
176 ecc_reg
[1] = FL4ECCRESULT1(flctl
);
177 ecc_reg
[2] = FL4ECCRESULT2(flctl
);
178 ecc_reg
[3] = FL4ECCRESULT3(flctl
);
180 for (i
= 0; i
< 3; i
++) {
181 data
= readl(ecc_reg
[i
]);
182 if (data
!= INIT_FL4ECCRESULT_VAL
&& !checked
[i
]) {
186 if (flctl
->page_size
)
187 index
= (512 * sector_number
) +
192 org
= flctl
->done_buff
[index
];
193 flctl
->done_buff
[index
] = org
^ (data
& 0xFF);
198 writel(0, FL4ECCCR(flctl
));
201 printk(KERN_ERR
"wait_recfifo_ready(): Timeout occured \n");
202 return 1; /* timeout */
205 static void wait_wecfifo_ready(struct sh_flctl
*flctl
)
207 uint32_t timeout
= LOOP_TIMEOUT_MAX
;
212 len
= (readl(FLDTCNTR(flctl
)) >> 24) & 0xFF;
217 printk(KERN_ERR
"wait_wecfifo_ready(): Timeout occured \n");
220 static void read_datareg(struct sh_flctl
*flctl
, int offset
)
223 unsigned long *buf
= (unsigned long *)&flctl
->done_buff
[offset
];
225 wait_completion(flctl
);
227 data
= readl(FLDATAR(flctl
));
228 *buf
= le32_to_cpu(data
);
231 static void read_fiforeg(struct sh_flctl
*flctl
, int rlen
, int offset
)
234 unsigned long *buf
= (unsigned long *)&flctl
->done_buff
[offset
];
235 void *fifo_addr
= (void *)FLDTFIFO(flctl
);
237 len_4align
= (rlen
+ 3) / 4;
239 for (i
= 0; i
< len_4align
; i
++) {
240 wait_rfifo_ready(flctl
);
241 buf
[i
] = readl(fifo_addr
);
242 buf
[i
] = be32_to_cpu(buf
[i
]);
246 static int read_ecfiforeg(struct sh_flctl
*flctl
, uint8_t *buff
, int sector
)
249 unsigned long *ecc_buf
= (unsigned long *)buff
;
250 void *fifo_addr
= (void *)FLECFIFO(flctl
);
252 for (i
= 0; i
< 4; i
++) {
253 if (wait_recfifo_ready(flctl
, sector
))
255 ecc_buf
[i
] = readl(fifo_addr
);
256 ecc_buf
[i
] = be32_to_cpu(ecc_buf
[i
]);
262 static void write_fiforeg(struct sh_flctl
*flctl
, int rlen
, int offset
)
265 unsigned long *data
= (unsigned long *)&flctl
->done_buff
[offset
];
266 void *fifo_addr
= (void *)FLDTFIFO(flctl
);
268 len_4align
= (rlen
+ 3) / 4;
269 for (i
= 0; i
< len_4align
; i
++) {
270 wait_wfifo_ready(flctl
);
271 writel(cpu_to_be32(data
[i
]), fifo_addr
);
275 static void set_cmd_regs(struct mtd_info
*mtd
, uint32_t cmd
, uint32_t flcmcdr_val
)
277 struct sh_flctl
*flctl
= mtd_to_flctl(mtd
);
278 uint32_t flcmncr_val
= readl(FLCMNCR(flctl
));
279 uint32_t flcmdcr_val
, addr_len_bytes
= 0;
281 /* Set SNAND bit if page size is 2048byte */
282 if (flctl
->page_size
)
283 flcmncr_val
|= SNAND_E
;
285 flcmncr_val
&= ~SNAND_E
;
287 /* default FLCMDCR val */
288 flcmdcr_val
= DOCMD1_E
| DOADR_E
;
290 /* Set for FLCMDCR */
292 case NAND_CMD_ERASE1
:
293 addr_len_bytes
= flctl
->erase_ADRCNT
;
294 flcmdcr_val
|= DOCMD2_E
;
297 case NAND_CMD_READOOB
:
298 addr_len_bytes
= flctl
->rw_ADRCNT
;
299 flcmdcr_val
|= CDSRC_E
;
302 /* This case is that cmd is READ0 or READ1 or READ00 */
303 flcmdcr_val
&= ~DOADR_E
; /* ONLY execute 1st cmd */
305 case NAND_CMD_PAGEPROG
:
306 addr_len_bytes
= flctl
->rw_ADRCNT
;
307 flcmdcr_val
|= DOCMD2_E
| CDSRC_E
| SELRW
;
309 case NAND_CMD_READID
:
310 flcmncr_val
&= ~SNAND_E
;
311 addr_len_bytes
= ADRCNT_1
;
313 case NAND_CMD_STATUS
:
315 flcmncr_val
&= ~SNAND_E
;
316 flcmdcr_val
&= ~(DOADR_E
| DOSR_E
);
322 /* Set address bytes parameter */
323 flcmdcr_val
|= addr_len_bytes
;
325 /* Now actually write */
326 writel(flcmncr_val
, FLCMNCR(flctl
));
327 writel(flcmdcr_val
, FLCMDCR(flctl
));
328 writel(flcmcdr_val
, FLCMCDR(flctl
));
331 static int flctl_read_page_hwecc(struct mtd_info
*mtd
, struct nand_chip
*chip
,
334 int i
, eccsize
= chip
->ecc
.size
;
335 int eccbytes
= chip
->ecc
.bytes
;
336 int eccsteps
= chip
->ecc
.steps
;
338 struct sh_flctl
*flctl
= mtd_to_flctl(mtd
);
340 for (i
= 0; eccsteps
; eccsteps
--, i
+= eccbytes
, p
+= eccsize
)
341 chip
->read_buf(mtd
, p
, eccsize
);
343 for (i
= 0; eccsteps
; eccsteps
--, i
+= eccbytes
, p
+= eccsize
) {
344 if (flctl
->hwecc_cant_correct
[i
])
345 mtd
->ecc_stats
.failed
++;
347 mtd
->ecc_stats
.corrected
+= 0;
353 static void flctl_write_page_hwecc(struct mtd_info
*mtd
, struct nand_chip
*chip
,
356 int i
, eccsize
= chip
->ecc
.size
;
357 int eccbytes
= chip
->ecc
.bytes
;
358 int eccsteps
= chip
->ecc
.steps
;
359 const uint8_t *p
= buf
;
361 for (i
= 0; eccsteps
; eccsteps
--, i
+= eccbytes
, p
+= eccsize
)
362 chip
->write_buf(mtd
, p
, eccsize
);
365 static void execmd_read_page_sector(struct mtd_info
*mtd
, int page_addr
)
367 struct sh_flctl
*flctl
= mtd_to_flctl(mtd
);
368 int sector
, page_sectors
;
370 if (flctl
->page_size
)
375 writel(readl(FLCMNCR(flctl
)) | ACM_SACCES_MODE
| _4ECCCORRECT
,
378 set_cmd_regs(mtd
, NAND_CMD_READ0
,
379 (NAND_CMD_READSTART
<< 8) | NAND_CMD_READ0
);
381 for (sector
= 0; sector
< page_sectors
; sector
++) {
385 writel(readl(FLCMDCR(flctl
)) | 1, FLCMDCR(flctl
));
386 writel(page_addr
<< 2 | sector
, FLADR(flctl
));
388 start_translation(flctl
);
389 read_fiforeg(flctl
, 512, 512 * sector
);
391 ret
= read_ecfiforeg(flctl
,
392 &flctl
->done_buff
[mtd
->writesize
+ 16 * sector
],
396 flctl
->hwecc_cant_correct
[sector
] = 1;
398 writel(0x0, FL4ECCCR(flctl
));
399 wait_completion(flctl
);
401 writel(readl(FLCMNCR(flctl
)) & ~(ACM_SACCES_MODE
| _4ECCCORRECT
),
405 static void execmd_read_oob(struct mtd_info
*mtd
, int page_addr
)
407 struct sh_flctl
*flctl
= mtd_to_flctl(mtd
);
409 set_cmd_regs(mtd
, NAND_CMD_READ0
,
410 (NAND_CMD_READSTART
<< 8) | NAND_CMD_READ0
);
413 if (flctl
->page_size
) {
415 /* In case that the page size is 2k */
416 for (i
= 0; i
< 16 * 3; i
++)
417 flctl
->done_buff
[i
] = 0xFF;
419 set_addr(mtd
, 3 * 528 + 512, page_addr
);
420 writel(16, FLDTCNTR(flctl
));
422 start_translation(flctl
);
423 read_fiforeg(flctl
, 16, 16 * 3);
424 wait_completion(flctl
);
426 /* In case that the page size is 512b */
427 set_addr(mtd
, 512, page_addr
);
428 writel(16, FLDTCNTR(flctl
));
430 start_translation(flctl
);
431 read_fiforeg(flctl
, 16, 0);
432 wait_completion(flctl
);
436 static void execmd_write_page_sector(struct mtd_info
*mtd
)
438 struct sh_flctl
*flctl
= mtd_to_flctl(mtd
);
439 int i
, page_addr
= flctl
->seqin_page_addr
;
440 int sector
, page_sectors
;
442 if (flctl
->page_size
)
447 writel(readl(FLCMNCR(flctl
)) | ACM_SACCES_MODE
, FLCMNCR(flctl
));
449 set_cmd_regs(mtd
, NAND_CMD_PAGEPROG
,
450 (NAND_CMD_PAGEPROG
<< 8) | NAND_CMD_SEQIN
);
452 for (sector
= 0; sector
< page_sectors
; sector
++) {
454 writel(readl(FLCMDCR(flctl
)) | 1, FLCMDCR(flctl
));
455 writel(page_addr
<< 2 | sector
, FLADR(flctl
));
457 start_translation(flctl
);
458 write_fiforeg(flctl
, 512, 512 * sector
);
460 for (i
= 0; i
< 4; i
++) {
461 wait_wecfifo_ready(flctl
); /* wait for write ready */
462 writel(0xFFFFFFFF, FLECFIFO(flctl
));
464 wait_completion(flctl
);
467 writel(readl(FLCMNCR(flctl
)) & ~ACM_SACCES_MODE
, FLCMNCR(flctl
));
470 static void execmd_write_oob(struct mtd_info
*mtd
)
472 struct sh_flctl
*flctl
= mtd_to_flctl(mtd
);
473 int page_addr
= flctl
->seqin_page_addr
;
474 int sector
, page_sectors
;
476 if (flctl
->page_size
) {
484 set_cmd_regs(mtd
, NAND_CMD_PAGEPROG
,
485 (NAND_CMD_PAGEPROG
<< 8) | NAND_CMD_SEQIN
);
487 for (; sector
< page_sectors
; sector
++) {
489 set_addr(mtd
, sector
* 528 + 512, page_addr
);
490 writel(16, FLDTCNTR(flctl
)); /* set read size */
492 start_translation(flctl
);
493 write_fiforeg(flctl
, 16, 16 * sector
);
494 wait_completion(flctl
);
498 static void flctl_cmdfunc(struct mtd_info
*mtd
, unsigned int command
,
499 int column
, int page_addr
)
501 struct sh_flctl
*flctl
= mtd_to_flctl(mtd
);
502 uint32_t read_cmd
= 0;
504 flctl
->read_bytes
= 0;
505 if (command
!= NAND_CMD_PAGEPROG
)
512 /* read page with hwecc */
513 execmd_read_page_sector(mtd
, page_addr
);
517 if (flctl
->page_size
)
518 set_cmd_regs(mtd
, command
, (NAND_CMD_READSTART
<< 8)
521 set_cmd_regs(mtd
, command
, command
);
523 set_addr(mtd
, 0, page_addr
);
525 flctl
->read_bytes
= mtd
->writesize
+ mtd
->oobsize
;
526 flctl
->index
+= column
;
527 goto read_normal_exit
;
529 case NAND_CMD_READOOB
:
531 /* read page with hwecc */
532 execmd_read_oob(mtd
, page_addr
);
537 if (flctl
->page_size
) {
538 set_cmd_regs(mtd
, command
, (NAND_CMD_READSTART
<< 8)
540 set_addr(mtd
, mtd
->writesize
, page_addr
);
542 set_cmd_regs(mtd
, command
, command
);
543 set_addr(mtd
, 0, page_addr
);
545 flctl
->read_bytes
= mtd
->oobsize
;
546 goto read_normal_exit
;
548 case NAND_CMD_READID
:
550 set_cmd_regs(mtd
, command
, command
);
553 flctl
->read_bytes
= 4;
554 writel(flctl
->read_bytes
, FLDTCNTR(flctl
)); /* set read size */
555 start_translation(flctl
);
556 read_datareg(flctl
, 0); /* read and end */
559 case NAND_CMD_ERASE1
:
560 flctl
->erase1_page_addr
= page_addr
;
563 case NAND_CMD_ERASE2
:
564 set_cmd_regs(mtd
, NAND_CMD_ERASE1
,
565 (command
<< 8) | NAND_CMD_ERASE1
);
566 set_addr(mtd
, -1, flctl
->erase1_page_addr
);
567 start_translation(flctl
);
568 wait_completion(flctl
);
572 if (!flctl
->page_size
) {
573 /* output read command */
574 if (column
>= mtd
->writesize
) {
575 column
-= mtd
->writesize
;
576 read_cmd
= NAND_CMD_READOOB
;
577 } else if (column
< 256) {
578 read_cmd
= NAND_CMD_READ0
;
581 read_cmd
= NAND_CMD_READ1
;
584 flctl
->seqin_column
= column
;
585 flctl
->seqin_page_addr
= page_addr
;
586 flctl
->seqin_read_cmd
= read_cmd
;
589 case NAND_CMD_PAGEPROG
:
591 if (!flctl
->page_size
) {
592 set_cmd_regs(mtd
, NAND_CMD_SEQIN
,
593 flctl
->seqin_read_cmd
);
594 set_addr(mtd
, -1, -1);
595 writel(0, FLDTCNTR(flctl
)); /* set 0 size */
596 start_translation(flctl
);
597 wait_completion(flctl
);
600 /* write page with hwecc */
601 if (flctl
->seqin_column
== mtd
->writesize
)
602 execmd_write_oob(mtd
);
603 else if (!flctl
->seqin_column
)
604 execmd_write_page_sector(mtd
);
606 printk(KERN_ERR
"Invalid address !?\n");
609 set_cmd_regs(mtd
, command
, (command
<< 8) | NAND_CMD_SEQIN
);
610 set_addr(mtd
, flctl
->seqin_column
, flctl
->seqin_page_addr
);
611 writel(flctl
->index
, FLDTCNTR(flctl
)); /* set write size */
612 start_translation(flctl
);
613 write_fiforeg(flctl
, flctl
->index
, 0);
614 wait_completion(flctl
);
617 case NAND_CMD_STATUS
:
618 set_cmd_regs(mtd
, command
, command
);
619 set_addr(mtd
, -1, -1);
621 flctl
->read_bytes
= 1;
622 writel(flctl
->read_bytes
, FLDTCNTR(flctl
)); /* set read size */
623 start_translation(flctl
);
624 read_datareg(flctl
, 0); /* read and end */
628 set_cmd_regs(mtd
, command
, command
);
629 set_addr(mtd
, -1, -1);
631 writel(0, FLDTCNTR(flctl
)); /* set 0 size */
632 start_translation(flctl
);
633 wait_completion(flctl
);
642 writel(flctl
->read_bytes
, FLDTCNTR(flctl
)); /* set read size */
643 start_translation(flctl
);
644 read_fiforeg(flctl
, flctl
->read_bytes
, 0);
645 wait_completion(flctl
);
649 static void flctl_select_chip(struct mtd_info
*mtd
, int chipnr
)
651 struct sh_flctl
*flctl
= mtd_to_flctl(mtd
);
652 uint32_t flcmncr_val
= readl(FLCMNCR(flctl
));
656 flcmncr_val
&= ~CE0_ENABLE
;
657 writel(flcmncr_val
, FLCMNCR(flctl
));
660 flcmncr_val
|= CE0_ENABLE
;
661 writel(flcmncr_val
, FLCMNCR(flctl
));
668 static void flctl_write_buf(struct mtd_info
*mtd
, const uint8_t *buf
, int len
)
670 struct sh_flctl
*flctl
= mtd_to_flctl(mtd
);
671 int i
, index
= flctl
->index
;
673 for (i
= 0; i
< len
; i
++)
674 flctl
->done_buff
[index
+ i
] = buf
[i
];
678 static uint8_t flctl_read_byte(struct mtd_info
*mtd
)
680 struct sh_flctl
*flctl
= mtd_to_flctl(mtd
);
681 int index
= flctl
->index
;
684 data
= flctl
->done_buff
[index
];
689 static void flctl_read_buf(struct mtd_info
*mtd
, uint8_t *buf
, int len
)
693 for (i
= 0; i
< len
; i
++)
694 buf
[i
] = flctl_read_byte(mtd
);
697 static int flctl_verify_buf(struct mtd_info
*mtd
, const u_char
*buf
, int len
)
701 for (i
= 0; i
< len
; i
++)
702 if (buf
[i
] != flctl_read_byte(mtd
))
707 static void flctl_register_init(struct sh_flctl
*flctl
, unsigned long val
)
709 writel(val
, FLCMNCR(flctl
));
712 static int flctl_chip_init_tail(struct mtd_info
*mtd
)
714 struct sh_flctl
*flctl
= mtd_to_flctl(mtd
);
715 struct nand_chip
*chip
= &flctl
->chip
;
717 if (mtd
->writesize
== 512) {
718 flctl
->page_size
= 0;
719 if (chip
->chipsize
> (32 << 20)) {
721 flctl
->rw_ADRCNT
= ADRCNT_4
;
722 flctl
->erase_ADRCNT
= ADRCNT_3
;
723 } else if (chip
->chipsize
> (2 << 16)) {
725 flctl
->rw_ADRCNT
= ADRCNT_3
;
726 flctl
->erase_ADRCNT
= ADRCNT_2
;
728 flctl
->rw_ADRCNT
= ADRCNT_2
;
729 flctl
->erase_ADRCNT
= ADRCNT_1
;
732 flctl
->page_size
= 1;
733 if (chip
->chipsize
> (128 << 20)) {
735 flctl
->rw_ADRCNT
= ADRCNT2_E
;
736 flctl
->erase_ADRCNT
= ADRCNT_3
;
737 } else if (chip
->chipsize
> (8 << 16)) {
739 flctl
->rw_ADRCNT
= ADRCNT_4
;
740 flctl
->erase_ADRCNT
= ADRCNT_2
;
742 flctl
->rw_ADRCNT
= ADRCNT_3
;
743 flctl
->erase_ADRCNT
= ADRCNT_1
;
748 if (mtd
->writesize
== 512) {
749 chip
->ecc
.layout
= &flctl_4secc_oob_16
;
750 chip
->badblock_pattern
= &flctl_4secc_smallpage
;
752 chip
->ecc
.layout
= &flctl_4secc_oob_64
;
753 chip
->badblock_pattern
= &flctl_4secc_largepage
;
756 chip
->ecc
.size
= 512;
757 chip
->ecc
.bytes
= 10;
758 chip
->ecc
.read_page
= flctl_read_page_hwecc
;
759 chip
->ecc
.write_page
= flctl_write_page_hwecc
;
760 chip
->ecc
.mode
= NAND_ECC_HW
;
762 /* 4 symbols ECC enabled */
763 writel(readl(FLCMNCR(flctl
)) | _4ECCEN
| ECCPOS2
| ECCPOS_02
,
766 chip
->ecc
.mode
= NAND_ECC_SOFT
;
772 static int __init
flctl_probe(struct platform_device
*pdev
)
774 struct resource
*res
;
775 struct sh_flctl
*flctl
;
776 struct mtd_info
*flctl_mtd
;
777 struct nand_chip
*nand
;
778 struct sh_flctl_platform_data
*pdata
;
781 pdata
= pdev
->dev
.platform_data
;
783 printk(KERN_ERR
"sh_flctl platform_data not found.\n");
787 flctl
= kzalloc(sizeof(struct sh_flctl
), GFP_KERNEL
);
789 printk(KERN_ERR
"Unable to allocate NAND MTD dev structure.\n");
793 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
795 printk(KERN_ERR
"%s: resource not found.\n", __func__
);
800 flctl
->reg
= ioremap(res
->start
, res
->end
- res
->start
+ 1);
801 if (flctl
->reg
== NULL
) {
802 printk(KERN_ERR
"%s: ioremap error.\n", __func__
);
807 platform_set_drvdata(pdev
, flctl
);
808 flctl_mtd
= &flctl
->mtd
;
810 flctl_mtd
->priv
= nand
;
811 flctl
->hwecc
= pdata
->has_hwecc
;
813 flctl_register_init(flctl
, pdata
->flcmncr_val
);
815 nand
->options
= NAND_NO_AUTOINCR
;
817 /* Set address of hardware control function */
818 /* 20 us command delay time */
819 nand
->chip_delay
= 20;
821 nand
->read_byte
= flctl_read_byte
;
822 nand
->write_buf
= flctl_write_buf
;
823 nand
->read_buf
= flctl_read_buf
;
824 nand
->verify_buf
= flctl_verify_buf
;
825 nand
->select_chip
= flctl_select_chip
;
826 nand
->cmdfunc
= flctl_cmdfunc
;
828 ret
= nand_scan_ident(flctl_mtd
, 1);
832 ret
= flctl_chip_init_tail(flctl_mtd
);
836 ret
= nand_scan_tail(flctl_mtd
);
840 add_mtd_partitions(flctl_mtd
, pdata
->parts
, pdata
->nr_parts
);
849 static int __exit
flctl_remove(struct platform_device
*pdev
)
851 struct sh_flctl
*flctl
= platform_get_drvdata(pdev
);
853 nand_release(&flctl
->mtd
);
859 static struct platform_driver flctl_driver
= {
860 .probe
= flctl_probe
,
861 .remove
= flctl_remove
,
864 .owner
= THIS_MODULE
,
868 static int __init
flctl_nand_init(void)
870 return platform_driver_register(&flctl_driver
);
873 static void __exit
flctl_nand_cleanup(void)
875 platform_driver_unregister(&flctl_driver
);
878 module_init(flctl_nand_init
);
879 module_exit(flctl_nand_cleanup
);
881 MODULE_LICENSE("GPL");
882 MODULE_AUTHOR("Yoshihiro Shimoda");
883 MODULE_DESCRIPTION("SuperH FLCTL driver");
884 MODULE_ALIAS("platform:sh_flctl");