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
= {
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
)
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
]) {
187 org
= flctl
->done_buff
[index
];
188 flctl
->done_buff
[index
] = org
^ (data
& 0xFF);
193 writel(0, FL4ECCCR(flctl
));
196 printk(KERN_ERR
"wait_recfifo_ready(): Timeout occured \n");
197 return 1; /* timeout */
200 static void wait_wecfifo_ready(struct sh_flctl
*flctl
)
202 uint32_t timeout
= LOOP_TIMEOUT_MAX
;
207 len
= (readl(FLDTCNTR(flctl
)) >> 24) & 0xFF;
212 printk(KERN_ERR
"wait_wecfifo_ready(): Timeout occured \n");
215 static void read_datareg(struct sh_flctl
*flctl
, int offset
)
218 unsigned long *buf
= (unsigned long *)&flctl
->done_buff
[offset
];
220 wait_completion(flctl
);
222 data
= readl(FLDATAR(flctl
));
223 *buf
= le32_to_cpu(data
);
226 static void read_fiforeg(struct sh_flctl
*flctl
, int rlen
, int offset
)
229 unsigned long *buf
= (unsigned long *)&flctl
->done_buff
[offset
];
230 void *fifo_addr
= (void *)FLDTFIFO(flctl
);
232 len_4align
= (rlen
+ 3) / 4;
234 for (i
= 0; i
< len_4align
; i
++) {
235 wait_rfifo_ready(flctl
);
236 buf
[i
] = readl(fifo_addr
);
237 buf
[i
] = be32_to_cpu(buf
[i
]);
241 static int read_ecfiforeg(struct sh_flctl
*flctl
, uint8_t *buff
)
244 unsigned long *ecc_buf
= (unsigned long *)buff
;
245 void *fifo_addr
= (void *)FLECFIFO(flctl
);
247 for (i
= 0; i
< 4; i
++) {
248 if (wait_recfifo_ready(flctl
))
250 ecc_buf
[i
] = readl(fifo_addr
);
251 ecc_buf
[i
] = be32_to_cpu(ecc_buf
[i
]);
257 static void write_fiforeg(struct sh_flctl
*flctl
, int rlen
, int offset
)
260 unsigned long *data
= (unsigned long *)&flctl
->done_buff
[offset
];
261 void *fifo_addr
= (void *)FLDTFIFO(flctl
);
263 len_4align
= (rlen
+ 3) / 4;
264 for (i
= 0; i
< len_4align
; i
++) {
265 wait_wfifo_ready(flctl
);
266 writel(cpu_to_be32(data
[i
]), fifo_addr
);
270 static void set_cmd_regs(struct mtd_info
*mtd
, uint32_t cmd
, uint32_t flcmcdr_val
)
272 struct sh_flctl
*flctl
= mtd_to_flctl(mtd
);
273 uint32_t flcmncr_val
= readl(FLCMNCR(flctl
));
274 uint32_t flcmdcr_val
, addr_len_bytes
= 0;
276 /* Set SNAND bit if page size is 2048byte */
277 if (flctl
->page_size
)
278 flcmncr_val
|= SNAND_E
;
280 flcmncr_val
&= ~SNAND_E
;
282 /* default FLCMDCR val */
283 flcmdcr_val
= DOCMD1_E
| DOADR_E
;
285 /* Set for FLCMDCR */
287 case NAND_CMD_ERASE1
:
288 addr_len_bytes
= flctl
->erase_ADRCNT
;
289 flcmdcr_val
|= DOCMD2_E
;
292 case NAND_CMD_READOOB
:
293 addr_len_bytes
= flctl
->rw_ADRCNT
;
294 flcmdcr_val
|= CDSRC_E
;
297 /* This case is that cmd is READ0 or READ1 or READ00 */
298 flcmdcr_val
&= ~DOADR_E
; /* ONLY execute 1st cmd */
300 case NAND_CMD_PAGEPROG
:
301 addr_len_bytes
= flctl
->rw_ADRCNT
;
302 flcmdcr_val
|= DOCMD2_E
| CDSRC_E
| SELRW
;
304 case NAND_CMD_READID
:
305 flcmncr_val
&= ~SNAND_E
;
306 addr_len_bytes
= ADRCNT_1
;
308 case NAND_CMD_STATUS
:
310 flcmncr_val
&= ~SNAND_E
;
311 flcmdcr_val
&= ~(DOADR_E
| DOSR_E
);
317 /* Set address bytes parameter */
318 flcmdcr_val
|= addr_len_bytes
;
320 /* Now actually write */
321 writel(flcmncr_val
, FLCMNCR(flctl
));
322 writel(flcmdcr_val
, FLCMDCR(flctl
));
323 writel(flcmcdr_val
, FLCMCDR(flctl
));
326 static int flctl_read_page_hwecc(struct mtd_info
*mtd
, struct nand_chip
*chip
,
329 int i
, eccsize
= chip
->ecc
.size
;
330 int eccbytes
= chip
->ecc
.bytes
;
331 int eccsteps
= chip
->ecc
.steps
;
333 struct sh_flctl
*flctl
= mtd_to_flctl(mtd
);
335 for (i
= 0; eccsteps
; eccsteps
--, i
+= eccbytes
, p
+= eccsize
)
336 chip
->read_buf(mtd
, p
, eccsize
);
338 for (i
= 0; eccsteps
; eccsteps
--, i
+= eccbytes
, p
+= eccsize
) {
339 if (flctl
->hwecc_cant_correct
[i
])
340 mtd
->ecc_stats
.failed
++;
342 mtd
->ecc_stats
.corrected
+= 0;
348 static void flctl_write_page_hwecc(struct mtd_info
*mtd
, struct nand_chip
*chip
,
351 int i
, eccsize
= chip
->ecc
.size
;
352 int eccbytes
= chip
->ecc
.bytes
;
353 int eccsteps
= chip
->ecc
.steps
;
354 const uint8_t *p
= buf
;
356 for (i
= 0; eccsteps
; eccsteps
--, i
+= eccbytes
, p
+= eccsize
)
357 chip
->write_buf(mtd
, p
, eccsize
);
360 static void execmd_read_page_sector(struct mtd_info
*mtd
, int page_addr
)
362 struct sh_flctl
*flctl
= mtd_to_flctl(mtd
);
363 int sector
, page_sectors
;
365 if (flctl
->page_size
)
370 writel(readl(FLCMNCR(flctl
)) | ACM_SACCES_MODE
| _4ECCCORRECT
,
373 set_cmd_regs(mtd
, NAND_CMD_READ0
,
374 (NAND_CMD_READSTART
<< 8) | NAND_CMD_READ0
);
376 for (sector
= 0; sector
< page_sectors
; sector
++) {
380 writel(readl(FLCMDCR(flctl
)) | 1, FLCMDCR(flctl
));
381 writel(page_addr
<< 2 | sector
, FLADR(flctl
));
383 start_translation(flctl
);
384 read_fiforeg(flctl
, 512, 512 * sector
);
386 ret
= read_ecfiforeg(flctl
,
387 &flctl
->done_buff
[mtd
->writesize
+ 16 * sector
]);
390 flctl
->hwecc_cant_correct
[sector
] = 1;
392 writel(0x0, FL4ECCCR(flctl
));
393 wait_completion(flctl
);
395 writel(readl(FLCMNCR(flctl
)) & ~(ACM_SACCES_MODE
| _4ECCCORRECT
),
399 static void execmd_read_oob(struct mtd_info
*mtd
, int page_addr
)
401 struct sh_flctl
*flctl
= mtd_to_flctl(mtd
);
403 set_cmd_regs(mtd
, NAND_CMD_READ0
,
404 (NAND_CMD_READSTART
<< 8) | NAND_CMD_READ0
);
407 if (flctl
->page_size
) {
409 /* In case that the page size is 2k */
410 for (i
= 0; i
< 16 * 3; i
++)
411 flctl
->done_buff
[i
] = 0xFF;
413 set_addr(mtd
, 3 * 528 + 512, page_addr
);
414 writel(16, FLDTCNTR(flctl
));
416 start_translation(flctl
);
417 read_fiforeg(flctl
, 16, 16 * 3);
418 wait_completion(flctl
);
420 /* In case that the page size is 512b */
421 set_addr(mtd
, 512, page_addr
);
422 writel(16, FLDTCNTR(flctl
));
424 start_translation(flctl
);
425 read_fiforeg(flctl
, 16, 0);
426 wait_completion(flctl
);
430 static void execmd_write_page_sector(struct mtd_info
*mtd
)
432 struct sh_flctl
*flctl
= mtd_to_flctl(mtd
);
433 int i
, page_addr
= flctl
->seqin_page_addr
;
434 int sector
, page_sectors
;
436 if (flctl
->page_size
)
441 writel(readl(FLCMNCR(flctl
)) | ACM_SACCES_MODE
, FLCMNCR(flctl
));
443 set_cmd_regs(mtd
, NAND_CMD_PAGEPROG
,
444 (NAND_CMD_PAGEPROG
<< 8) | NAND_CMD_SEQIN
);
446 for (sector
= 0; sector
< page_sectors
; sector
++) {
448 writel(readl(FLCMDCR(flctl
)) | 1, FLCMDCR(flctl
));
449 writel(page_addr
<< 2 | sector
, FLADR(flctl
));
451 start_translation(flctl
);
452 write_fiforeg(flctl
, 512, 512 * sector
);
454 for (i
= 0; i
< 4; i
++) {
455 wait_wecfifo_ready(flctl
); /* wait for write ready */
456 writel(0xFFFFFFFF, FLECFIFO(flctl
));
458 wait_completion(flctl
);
461 writel(readl(FLCMNCR(flctl
)) & ~ACM_SACCES_MODE
, FLCMNCR(flctl
));
464 static void execmd_write_oob(struct mtd_info
*mtd
)
466 struct sh_flctl
*flctl
= mtd_to_flctl(mtd
);
467 int page_addr
= flctl
->seqin_page_addr
;
468 int sector
, page_sectors
;
470 if (flctl
->page_size
) {
478 set_cmd_regs(mtd
, NAND_CMD_PAGEPROG
,
479 (NAND_CMD_PAGEPROG
<< 8) | NAND_CMD_SEQIN
);
481 for (; sector
< page_sectors
; sector
++) {
483 set_addr(mtd
, sector
* 528 + 512, page_addr
);
484 writel(16, FLDTCNTR(flctl
)); /* set read size */
486 start_translation(flctl
);
487 write_fiforeg(flctl
, 16, 16 * sector
);
488 wait_completion(flctl
);
492 static void flctl_cmdfunc(struct mtd_info
*mtd
, unsigned int command
,
493 int column
, int page_addr
)
495 struct sh_flctl
*flctl
= mtd_to_flctl(mtd
);
496 uint32_t read_cmd
= 0;
498 flctl
->read_bytes
= 0;
499 if (command
!= NAND_CMD_PAGEPROG
)
506 /* read page with hwecc */
507 execmd_read_page_sector(mtd
, page_addr
);
511 if (flctl
->page_size
)
512 set_cmd_regs(mtd
, command
, (NAND_CMD_READSTART
<< 8)
515 set_cmd_regs(mtd
, command
, command
);
517 set_addr(mtd
, 0, page_addr
);
519 flctl
->read_bytes
= mtd
->writesize
+ mtd
->oobsize
;
520 flctl
->index
+= column
;
521 goto read_normal_exit
;
523 case NAND_CMD_READOOB
:
525 /* read page with hwecc */
526 execmd_read_oob(mtd
, page_addr
);
531 if (flctl
->page_size
) {
532 set_cmd_regs(mtd
, command
, (NAND_CMD_READSTART
<< 8)
534 set_addr(mtd
, mtd
->writesize
, page_addr
);
536 set_cmd_regs(mtd
, command
, command
);
537 set_addr(mtd
, 0, page_addr
);
539 flctl
->read_bytes
= mtd
->oobsize
;
540 goto read_normal_exit
;
542 case NAND_CMD_READID
:
544 set_cmd_regs(mtd
, command
, command
);
547 flctl
->read_bytes
= 4;
548 writel(flctl
->read_bytes
, FLDTCNTR(flctl
)); /* set read size */
549 start_translation(flctl
);
550 read_datareg(flctl
, 0); /* read and end */
553 case NAND_CMD_ERASE1
:
554 flctl
->erase1_page_addr
= page_addr
;
557 case NAND_CMD_ERASE2
:
558 set_cmd_regs(mtd
, NAND_CMD_ERASE1
,
559 (command
<< 8) | NAND_CMD_ERASE1
);
560 set_addr(mtd
, -1, flctl
->erase1_page_addr
);
561 start_translation(flctl
);
562 wait_completion(flctl
);
566 if (!flctl
->page_size
) {
567 /* output read command */
568 if (column
>= mtd
->writesize
) {
569 column
-= mtd
->writesize
;
570 read_cmd
= NAND_CMD_READOOB
;
571 } else if (column
< 256) {
572 read_cmd
= NAND_CMD_READ0
;
575 read_cmd
= NAND_CMD_READ1
;
578 flctl
->seqin_column
= column
;
579 flctl
->seqin_page_addr
= page_addr
;
580 flctl
->seqin_read_cmd
= read_cmd
;
583 case NAND_CMD_PAGEPROG
:
585 if (!flctl
->page_size
) {
586 set_cmd_regs(mtd
, NAND_CMD_SEQIN
,
587 flctl
->seqin_read_cmd
);
588 set_addr(mtd
, -1, -1);
589 writel(0, FLDTCNTR(flctl
)); /* set 0 size */
590 start_translation(flctl
);
591 wait_completion(flctl
);
594 /* write page with hwecc */
595 if (flctl
->seqin_column
== mtd
->writesize
)
596 execmd_write_oob(mtd
);
597 else if (!flctl
->seqin_column
)
598 execmd_write_page_sector(mtd
);
600 printk(KERN_ERR
"Invalid address !?\n");
603 set_cmd_regs(mtd
, command
, (command
<< 8) | NAND_CMD_SEQIN
);
604 set_addr(mtd
, flctl
->seqin_column
, flctl
->seqin_page_addr
);
605 writel(flctl
->index
, FLDTCNTR(flctl
)); /* set write size */
606 start_translation(flctl
);
607 write_fiforeg(flctl
, flctl
->index
, 0);
608 wait_completion(flctl
);
611 case NAND_CMD_STATUS
:
612 set_cmd_regs(mtd
, command
, command
);
613 set_addr(mtd
, -1, -1);
615 flctl
->read_bytes
= 1;
616 writel(flctl
->read_bytes
, FLDTCNTR(flctl
)); /* set read size */
617 start_translation(flctl
);
618 read_datareg(flctl
, 0); /* read and end */
622 set_cmd_regs(mtd
, command
, command
);
623 set_addr(mtd
, -1, -1);
625 writel(0, FLDTCNTR(flctl
)); /* set 0 size */
626 start_translation(flctl
);
627 wait_completion(flctl
);
636 writel(flctl
->read_bytes
, FLDTCNTR(flctl
)); /* set read size */
637 start_translation(flctl
);
638 read_fiforeg(flctl
, flctl
->read_bytes
, 0);
639 wait_completion(flctl
);
643 static void flctl_select_chip(struct mtd_info
*mtd
, int chipnr
)
645 struct sh_flctl
*flctl
= mtd_to_flctl(mtd
);
646 uint32_t flcmncr_val
= readl(FLCMNCR(flctl
));
650 flcmncr_val
&= ~CE0_ENABLE
;
651 writel(flcmncr_val
, FLCMNCR(flctl
));
654 flcmncr_val
|= CE0_ENABLE
;
655 writel(flcmncr_val
, FLCMNCR(flctl
));
662 static void flctl_write_buf(struct mtd_info
*mtd
, const uint8_t *buf
, int len
)
664 struct sh_flctl
*flctl
= mtd_to_flctl(mtd
);
665 int i
, index
= flctl
->index
;
667 for (i
= 0; i
< len
; i
++)
668 flctl
->done_buff
[index
+ i
] = buf
[i
];
672 static uint8_t flctl_read_byte(struct mtd_info
*mtd
)
674 struct sh_flctl
*flctl
= mtd_to_flctl(mtd
);
675 int index
= flctl
->index
;
678 data
= flctl
->done_buff
[index
];
683 static void flctl_read_buf(struct mtd_info
*mtd
, uint8_t *buf
, int len
)
687 for (i
= 0; i
< len
; i
++)
688 buf
[i
] = flctl_read_byte(mtd
);
691 static int flctl_verify_buf(struct mtd_info
*mtd
, const u_char
*buf
, int len
)
695 for (i
= 0; i
< len
; i
++)
696 if (buf
[i
] != flctl_read_byte(mtd
))
701 static void flctl_register_init(struct sh_flctl
*flctl
, unsigned long val
)
703 writel(val
, FLCMNCR(flctl
));
706 static int flctl_chip_init_tail(struct mtd_info
*mtd
)
708 struct sh_flctl
*flctl
= mtd_to_flctl(mtd
);
709 struct nand_chip
*chip
= &flctl
->chip
;
711 if (mtd
->writesize
== 512) {
712 flctl
->page_size
= 0;
713 if (chip
->chipsize
> (32 << 20)) {
715 flctl
->rw_ADRCNT
= ADRCNT_4
;
716 flctl
->erase_ADRCNT
= ADRCNT_3
;
717 } else if (chip
->chipsize
> (2 << 16)) {
719 flctl
->rw_ADRCNT
= ADRCNT_3
;
720 flctl
->erase_ADRCNT
= ADRCNT_2
;
722 flctl
->rw_ADRCNT
= ADRCNT_2
;
723 flctl
->erase_ADRCNT
= ADRCNT_1
;
726 flctl
->page_size
= 1;
727 if (chip
->chipsize
> (128 << 20)) {
729 flctl
->rw_ADRCNT
= ADRCNT2_E
;
730 flctl
->erase_ADRCNT
= ADRCNT_3
;
731 } else if (chip
->chipsize
> (8 << 16)) {
733 flctl
->rw_ADRCNT
= ADRCNT_4
;
734 flctl
->erase_ADRCNT
= ADRCNT_2
;
736 flctl
->rw_ADRCNT
= ADRCNT_3
;
737 flctl
->erase_ADRCNT
= ADRCNT_1
;
742 if (mtd
->writesize
== 512) {
743 chip
->ecc
.layout
= &flctl_4secc_oob_16
;
744 chip
->badblock_pattern
= &flctl_4secc_smallpage
;
746 chip
->ecc
.layout
= &flctl_4secc_oob_64
;
747 chip
->badblock_pattern
= &flctl_4secc_largepage
;
750 chip
->ecc
.size
= 512;
751 chip
->ecc
.bytes
= 10;
752 chip
->ecc
.read_page
= flctl_read_page_hwecc
;
753 chip
->ecc
.write_page
= flctl_write_page_hwecc
;
754 chip
->ecc
.mode
= NAND_ECC_HW
;
756 /* 4 symbols ECC enabled */
757 writel(readl(FLCMNCR(flctl
)) | _4ECCEN
| ECCPOS2
| ECCPOS_02
,
760 chip
->ecc
.mode
= NAND_ECC_SOFT
;
766 static int __init
flctl_probe(struct platform_device
*pdev
)
768 struct resource
*res
;
769 struct sh_flctl
*flctl
;
770 struct mtd_info
*flctl_mtd
;
771 struct nand_chip
*nand
;
772 struct sh_flctl_platform_data
*pdata
;
775 pdata
= pdev
->dev
.platform_data
;
777 printk(KERN_ERR
"sh_flctl platform_data not found.\n");
781 flctl
= kzalloc(sizeof(struct sh_flctl
), GFP_KERNEL
);
783 printk(KERN_ERR
"Unable to allocate NAND MTD dev structure.\n");
787 res
= platform_get_resource(pdev
, IORESOURCE_MEM
, 0);
789 printk(KERN_ERR
"%s: resource not found.\n", __func__
);
794 flctl
->reg
= ioremap(res
->start
, res
->end
- res
->start
+ 1);
795 if (flctl
->reg
== NULL
) {
796 printk(KERN_ERR
"%s: ioremap error.\n", __func__
);
801 platform_set_drvdata(pdev
, flctl
);
802 flctl_mtd
= &flctl
->mtd
;
804 flctl_mtd
->priv
= nand
;
805 flctl
->hwecc
= pdata
->has_hwecc
;
807 flctl_register_init(flctl
, pdata
->flcmncr_val
);
809 nand
->options
= NAND_NO_AUTOINCR
;
811 /* Set address of hardware control function */
812 /* 20 us command delay time */
813 nand
->chip_delay
= 20;
815 nand
->read_byte
= flctl_read_byte
;
816 nand
->write_buf
= flctl_write_buf
;
817 nand
->read_buf
= flctl_read_buf
;
818 nand
->verify_buf
= flctl_verify_buf
;
819 nand
->select_chip
= flctl_select_chip
;
820 nand
->cmdfunc
= flctl_cmdfunc
;
822 ret
= nand_scan_ident(flctl_mtd
, 1);
826 ret
= flctl_chip_init_tail(flctl_mtd
);
830 ret
= nand_scan_tail(flctl_mtd
);
834 add_mtd_partitions(flctl_mtd
, pdata
->parts
, pdata
->nr_parts
);
843 static int __exit
flctl_remove(struct platform_device
*pdev
)
845 struct sh_flctl
*flctl
= platform_get_drvdata(pdev
);
847 nand_release(&flctl
->mtd
);
853 static struct platform_driver flctl_driver
= {
854 .probe
= flctl_probe
,
855 .remove
= flctl_remove
,
858 .owner
= THIS_MODULE
,
862 static int __init
flctl_nand_init(void)
864 return platform_driver_register(&flctl_driver
);
867 static void __exit
flctl_nand_cleanup(void)
869 platform_driver_unregister(&flctl_driver
);
872 module_init(flctl_nand_init
);
873 module_exit(flctl_nand_cleanup
);
875 MODULE_LICENSE("GPL");
876 MODULE_AUTHOR("Yoshihiro Shimoda");
877 MODULE_DESCRIPTION("SuperH FLCTL driver");
878 MODULE_ALIAS("platform:sh_flctl");