1 /*==============================================================================*/
3 /* This module is derived from the 2.4 driver shipped by Microtik for their */
4 /* Routerboard 1xx and 5xx series boards. It provides support for the built in */
5 /* NAND flash on the Routerboard 1xx series boards for Linux 2.6.19+. */
6 /* Licence: Original Microtik code seems not to have a licence. */
7 /* Rewritten code all GPL V2. */
8 /* Copyright(C) 2007 david.goodenough@linkchoose.co.uk (for rewriten code) */
9 /*==============================================================================*/
11 #include <linux/init.h>
12 #include <linux/mtd/nand.h>
13 #include <linux/mtd/mtd.h>
14 #include <linux/mtd/partitions.h>
15 #include <linux/delay.h>
19 #include <asm/bootinfo.h>
20 #include <asm/mach-adm5120/adm5120_info.h>
21 #include <asm/mach-adm5120/adm5120_defs.h>
23 #define SMEM1(x) (*((volatile unsigned char *) (KSEG1ADDR(ADM5120_SRAM1_BASE) + x)))
25 #define NAND_RW_REG 0x0 //data register
26 #define NAND_SET_CEn 0x1 //CE# low
27 #define NAND_CLR_CEn 0x2 //CE# high
28 #define NAND_CLR_CLE 0x3 //CLE low
29 #define NAND_SET_CLE 0x4 //CLE high
30 #define NAND_CLR_ALE 0x5 //ALE low
31 #define NAND_SET_ALE 0x6 //ALE high
32 #define NAND_SET_SPn 0x7 //SP# low (use spare area)
33 #define NAND_CLR_SPn 0x8 //SP# high (do not use spare area)
34 #define NAND_SET_WPn 0x9 //WP# low
35 #define NAND_CLR_WPn 0xA //WP# high
36 #define NAND_STS_REG 0xB //Status register
38 #define MEM32(x) *((volatile unsigned *) (x))
39 static void __iomem
*p_nand
;
41 static int rb100_dev_ready(struct mtd_info
*mtd
) {
42 return SMEM1(NAND_STS_REG
) & 0x80;
45 static void rbmips_hwcontrol100(struct mtd_info
*mtd
, int cmd
, unsigned int ctrl
) {
46 struct nand_chip
*chip
= mtd
->priv
;
47 if (ctrl
& NAND_CTRL_CHANGE
) {
48 SMEM1((( ctrl
& NAND_CLE
) ? NAND_SET_CLE
: NAND_CLR_CLE
)) = 0x01;
49 SMEM1((( ctrl
& NAND_ALE
) ? NAND_SET_ALE
: NAND_CLR_ALE
)) = 0x01;
50 SMEM1((( ctrl
& NAND_NCE
) ? NAND_SET_CEn
: NAND_CLR_CEn
)) = 0x01;
52 if( cmd
!= NAND_CMD_NONE
)
53 writeb( cmd
, chip
->IO_ADDR_W
);
56 static struct mtd_partition partition_info
[] = {
58 name
: "RouterBoard NAND Boot",
64 offset
: MTDPART_OFS_NXTBLK
,
65 size
: MTDPART_SIZ_FULL
69 static struct mtd_info rmtd
;
70 static struct nand_chip rnand
;
71 /*========================================================================*/
72 /* We need to use the OLD Yaffs-1 OOB layout, otherwise the RB bootloader */
73 /* will not be able to find the kernel that we load. So set the oobinfo */
74 /* when creating the partitions. */
75 /*========================================================================*/
76 static struct nand_ecclayout rb_ecclayout
= {
78 .eccpos
= { 8, 9, 10, 13, 14, 15 },
80 .oobfree
= { { 0, 4 }, { 6, 2 }, { 11, 2 }, { 4, 1} }
82 static unsigned init_ok
= 0;
84 unsigned get_rbnand_block_size(void) {
85 return init_ok
? rmtd
.writesize
: 0;
88 EXPORT_SYMBOL(get_rbnand_block_size
);
90 int __init
rbmips_init(void) {
92 if (!adm5120_nand_boot
)
95 memset(&rmtd
, 0, sizeof(rmtd
));
96 memset(&rnand
, 0, sizeof(rnand
));
97 printk(KERN_INFO
"RB1xx nand\n");
98 MEM32(0xB2000064) = 0x100;
99 MEM32(0xB2000008) = 0x1;
100 SMEM1(NAND_SET_SPn
) = 0x01;
101 SMEM1(NAND_CLR_WPn
) = 0x01;
102 rnand
.IO_ADDR_R
= (unsigned char *)KSEG1ADDR(ADM5120_SRAM1_BASE
);
103 rnand
.IO_ADDR_W
= rnand
.IO_ADDR_R
;
104 rnand
.cmd_ctrl
= rbmips_hwcontrol100
;
105 rnand
.dev_ready
= rb100_dev_ready
;
106 p_nand
= (void __iomem
*)ioremap(( unsigned long)ADM5120_SRAM1_BASE
, 0x1000);
108 printk(KERN_WARNING
"RB1xx nand Unable ioremap buffer\n");
111 rnand
.ecc
.mode
= NAND_ECC_SOFT
;
112 rnand
.ecc
.layout
= &rb_ecclayout
;
113 rnand
.chip_delay
= 25;
114 rnand
.options
|= NAND_NO_AUTOINCR
;
116 if (nand_scan(&rmtd
, 1) && nand_scan(&rmtd
, 1)
117 && nand_scan(&rmtd
, 1) && nand_scan(&rmtd
, 1)) {
118 printk(KERN_INFO
"RB1xxx nand device not found\n");
119 iounmap ((void *)p_nand
);
122 add_mtd_partitions(&rmtd
, partition_info
, 2);
127 module_init(rbmips_init
);