21 #include <linux/kernel.h>
23 #include <linux/slab.h>
26 #include <linux/module.h>
37 #define RTC_FROM4_MAX_CHIPS 2
40 #define SH77X9_BCR1 ((volatile unsigned short *)(0xFFFFFF60))
41 #define SH77X9_BCR2 ((volatile unsigned short *)(0xFFFFFF62))
42 #define SH77X9_WCR1 ((volatile unsigned short *)(0xFFFFFF64))
43 #define SH77X9_WCR2 ((volatile unsigned short *)(0xFFFFFF66))
44 #define SH77X9_MCR ((volatile unsigned short *)(0xFFFFFF68))
45 #define SH77X9_PCR ((volatile unsigned short *)(0xFFFFFF6C))
46 #define SH77X9_FRQCR ((volatile unsigned short *)(0xFFFFFF80))
52 #define RTC_FROM4_FIO_BASE 0x14000000
55 #define RTC_FROM4_CLE (1 << 5)
56 #define RTC_FROM4_ALE (1 << 4)
59 #define RTC_FROM4_NAND_ADDR_SLOT3 (0x00800000)
60 #define RTC_FROM4_NAND_ADDR_SLOT4 (0x00C00000)
61 #define RTC_FROM4_NAND_ADDR_FPGA (0x01000000)
63 #define RTC_FROM4_NAND_ADDR_MASK (RTC_FROM4_NAND_ADDR_SLOT3 | RTC_FROM4_NAND_ADDR_SLOT4 | RTC_FROM4_NAND_ADDR_FPGA)
66 #define RTC_FROM4_FPGA_SR (RTC_FROM4_NAND_ADDR_FPGA | 0x00000002)
67 #define RTC_FROM4_DEVICE_READY 0x0001
71 #define RTC_FROM4_RS_ECC_CTL (RTC_FROM4_NAND_ADDR_FPGA | 0x00000050)
72 #define RTC_FROM4_RS_ECC_CTL_CLR (1 << 7)
73 #define RTC_FROM4_RS_ECC_CTL_GEN (1 << 6)
74 #define RTC_FROM4_RS_ECC_CTL_FD_E (1 << 5)
77 #define RTC_FROM4_RS_ECC (RTC_FROM4_NAND_ADDR_FPGA | 0x00000060)
78 #define RTC_FROM4_RS_ECCN (RTC_FROM4_NAND_ADDR_FPGA | 0x00000080)
81 #define RTC_FROM4_RS_ECC_CHK (RTC_FROM4_NAND_ADDR_FPGA | 0x00000070)
82 #define RTC_FROM4_RS_ECC_CHK_ERROR (1 << 7)
84 #define ERR_STAT_ECC_AVAILABLE 0x20
87 #define RTC_FROM4_HWECC 1
90 #define RTC_FROM4_NO_VIRTBLOCKS 0
99 .name =
"Renesas flash partition 1",
104 #define NUM_PARTITIONS 1
112 static uint8_t bbt_pattern[] = {
'B',
'b',
't',
'0' };
113 static uint8_t mirror_pattern[] = {
'1',
't',
'b',
'B' };
122 .pattern = bbt_pattern
132 .pattern = mirror_pattern
135 #ifdef RTC_FROM4_HWECC
146 0, 1, 2, 3, 4, 5, 6, 7,
147 8, 9, 10, 11, 12, 13, 14, 15,
148 16, 17, 18, 19, 20, 21, 22, 23,
149 24, 25, 26, 27, 28, 29, 30, 31},
150 .oobfree = {{32, 32}}
167 static void rtc_from4_hwcontrol(
struct mtd_info *mtd,
int cmd,
190 static void rtc_from4_nand_select_chip(
struct mtd_info *mtd,
int chip)
219 static int rtc_from4_nand_device_ready(
struct mtd_info *mtd)
242 static void deplete(
struct mtd_info *mtd,
int chip)
261 #ifdef RTC_FROM4_HWECC
270 static void rtc_from4_enable_hwecc(
struct mtd_info *mtd,
int mode)
272 volatile unsigned short *rs_ecc_ctl = (
volatile unsigned short *)(rtc_from4_fio_base +
RTC_FROM4_RS_ECC_CTL);
316 volatile unsigned short *rs_eccn = (
volatile unsigned short *)(rtc_from4_fio_base +
RTC_FROM4_RS_ECCN);
317 unsigned short value;
320 for (i = 0; i < 8; i++) {
322 ecc_code[
i] = (
unsigned char)value;
346 volatile unsigned short *rs_ecc;
355 rs_ecc = (
volatile unsigned short *)(rtc_from4_fio_base +
RTC_FROM4_RS_ECC);
356 for (i = 0; i < 8; i++) {
357 ecc[
i] = bitrev8(*rs_ecc);
367 par[0] = (((
uint16_t) ecc[6] >> 2) & 0x03f) | (((
uint16_t) ecc[7] << 6) & 0x3c0);
370 for (i = 0; i < 6; i++) {
372 for (j = 1; j < 6; j++)
373 if (par[j] != rs_decoder->
nn)
374 syn[
i] ^= rs_decoder->
alpha_to[rs_modnn(rs_decoder, par[j] + i * j)];
381 res = decode_rs8(rs_decoder, (
uint8_t *) buf, par, 512, syn, 0,
NULL, 0xff,
NULL);
383 pr_debug(
"rtc_from4_correct_data: " "ECC corrected %d errors on read\n", res);
416 for (i = 0; i < 4; i++) {
417 if (!(status & 1 << (i + 1)))
426 er_stat |= 1 << (i + 1);
431 unsigned long corrected = mtd->
ecc_stats.corrected;
455 if (rtn || (mtd->
ecc_stats.corrected - corrected) > 1)
472 static int __init rtc_from4_init(
void)
475 unsigned short bcr1, bcr2, wcr2;
481 if (!rtc_from4_mtd) {
482 printk(
"Unable to allocate Renesas NAND MTD device structure.\n");
487 this = (
struct nand_chip *)(&rtc_from4_mtd[1]);
494 rtc_from4_mtd->
priv =
this;
516 this->
cmd_ctrl = rtc_from4_hwcontrol;
522 this->
dev_ready = rtc_from4_nand_device_ready;
524 #ifdef RTC_FROM4_HWECC
528 this->ecc.size = 512;
530 this->ecc.strength = 3;
532 this->
errstat = rtc_from4_errstat;
534 this->ecc.layout = &rtc_from4_nand_oobinfo;
535 this->ecc.hwctl = rtc_from4_enable_hwecc;
536 this->ecc.calculate = rtc_from4_calculate_ecc;
537 this->ecc.correct = rtc_from4_correct_data;
548 rs_decoder =
init_rs(10, 0x409, 0, 1, 6);
561 this->
bbt_td = &rtc_from4_bbt_main_descr;
562 this->
bbt_md = &rtc_from4_bbt_mirror_descr;
571 for (i = 0; i < this->
numchips; i++) {
572 deplete(rtc_from4_mtd, i);
575 #if RTC_FROM4_NO_VIRTBLOCKS
579 rtc_from4_mtd->
flags |= MTD_NO_VIRTBLOCKS;
595 kfree(rtc_from4_mtd);
604 static void __exit rtc_from4_cleanup(
void)
610 kfree(rtc_from4_mtd);
612 #ifdef RTC_FROM4_HWECC
624 MODULE_DESCRIPTION(
"Board-specific glue layer for AG-AND flash on Renesas FROM_BOARD4");