2 #include <linux/module.h>
3 #include <linux/platform_device.h>
4 #include <linux/mtd/nand.h>
5 #include <linux/mtd/mtd.h>
6 #include <linux/mtd/partitions.h>
7 #include <linux/delay.h>
11 #include <asm/bootinfo.h>
13 #define IDT434_REG_BASE ((volatile void *) KSEG1ADDR(0x18000000))
15 #define GPIOF 0x050000
16 #define GPIOC 0x050004
17 #define GPIOD 0x050008
19 #define GPIO_RDY (1 << 0x08)
20 #define GPIO_WPX (1 << 0x09)
21 #define GPIO_ALE (1 << 0x0a)
22 #define GPIO_CLE (1 << 0x0b)
24 #define DEV2BASE 0x010020
26 #define LO_WPX (1 << 0)
27 #define LO_ALE (1 << 1)
28 #define LO_CLE (1 << 2)
29 #define LO_CEX (1 << 3)
30 #define LO_FOFF (1 << 5)
31 #define LO_SPICS (1 << 6)
32 #define LO_ULED (1 << 7)
34 #define MEM32(x) *((volatile unsigned *) (x))
36 struct rb500_nand_info
{
37 struct nand_chip chip
;
39 void __iomem
*io_base
;
40 #ifdef CONFIG_MTD_PARTITIONS
42 struct mtd_partition
*parts
;
49 static struct mtd_partition partition_info
[] = {
51 name
:"RouterBoard NAND Boot",
53 size
:4 * 1024 * 1024},
56 offset
:MTDPART_OFS_NXTBLK
,
57 size
:MTDPART_SIZ_FULL
}
60 extern void changeLatchU5(unsigned char orMask
, unsigned char nandMask
);
62 static int rb500_dev_ready(struct mtd_info
*mtd
)
64 return MEM32(IDT434_REG_BASE
+ GPIOD
) & GPIO_RDY
;
68 * hardware specific access to control-lines
71 * NAND_CLE: bit 2 -> bit 3
72 * NAND_ALE: bit 3 -> bit 2
74 static void rbmips_hwcontrol500(struct mtd_info
*mtd
, int cmd
,
77 struct nand_chip
*chip
= mtd
->priv
;
78 unsigned char orbits
, nandbits
;
80 if (ctrl
& NAND_CTRL_CHANGE
) {
82 orbits
= (ctrl
& NAND_CLE
) << 1;
83 orbits
|= (ctrl
& NAND_ALE
) >> 1;
85 nandbits
= (~ctrl
& NAND_CLE
) << 1;
86 nandbits
|= (~ctrl
& NAND_ALE
) >> 1;
88 changeLatchU5(orbits
, nandbits
);
90 if (cmd
!= NAND_CMD_NONE
)
91 writeb(cmd
, chip
->IO_ADDR_W
);
95 unsigned get_rbnand_block_size(struct rb500_nand_info
*data
)
98 return data
->mtd
.writesize
;
103 EXPORT_SYMBOL(get_rbnand_block_size
);
105 static int rbmips_probe(struct platform_device
*pdev
)
107 struct rb500_nand_info
*data
;
111 /* Allocate memory for the structure */
112 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
114 dev_err(&pdev
->dev
, "Failed to allocate device structure\n");
118 data
->io_base
= ioremap(pdev
->resource
[0].start
, pdev
->resource
[0].end
- pdev
->resource
[0].start
+ 1);
120 if (data
->io_base
== NULL
) {
121 dev_err(&pdev
->dev
, "ioremap failed\n");
126 /* FIXME : this seems to work only for newer RB500, check the version to set the right flags accordingly */
127 data
->flags1
= LO_FOFF
| LO_CEX
;
128 data
->flags2
= LO_ULED
| LO_ALE
| LO_CLE
| LO_WPX
;
130 changeLatchU5(data
->flags1
, data
->flags2
);
132 data
->chip
.cmd_ctrl
= rbmips_hwcontrol500
;
134 data
->chip
.dev_ready
= rb500_dev_ready
;
135 data
->chip
.IO_ADDR_W
= (unsigned char *)KSEG1ADDR(MEM32(IDT434_REG_BASE
+ DEV2BASE
));
136 data
->chip
.IO_ADDR_R
= data
->chip
.IO_ADDR_W
;
138 data
->chip
.ecc
.mode
= NAND_ECC_SOFT
;
139 data
->chip
.chip_delay
= 25;
140 data
->chip
.options
|= NAND_NO_AUTOINCR
;
142 data
->chip
.priv
= &data
;
143 data
->mtd
.priv
= &data
->chip
;
144 data
->mtd
.owner
= THIS_MODULE
;
146 b
= (int *) KSEG1ADDR(0x18010020);
147 printk("dev2base 0x%08x mask 0x%08x c 0x%08x tc 0x%08x\n", b
[0],
150 platform_set_drvdata(pdev
, data
);
152 /* Why do we need to scan 4 times ? */
153 if (nand_scan(&data
->mtd
, 1) && nand_scan(&data
->mtd
, 1) && nand_scan(&data
->mtd
, 1) && nand_scan(&data
->mtd
, 1)) {
154 printk(KERN_INFO
"RB500 nand device not found\n");
159 printk(KERN_INFO
"RB500 NAND\n");
160 add_mtd_partitions(&data
->mtd
, partition_info
, 2);
163 res
= add_mtd_device(&data
->mtd
);
167 nand_release(&data
->mtd
);
169 platform_set_drvdata(pdev
, NULL
);
170 iounmap(data
->io_base
);
175 static int __devexit
rbmips_remove(struct platform_device
*pdev
)
177 struct rb500_nand_info
*data
= platform_get_drvdata(pdev
);
179 nand_release(&data
->mtd
);
180 iounmap(data
->io_base
);
186 static struct platform_driver rb500_nand_driver
= {
187 .probe
= rbmips_probe
,
188 .remove
= rbmips_remove
,
190 .name
= "rb500-nand",
191 .owner
= THIS_MODULE
,
195 static int __init
rb500_nand_init(void)
198 err
= platform_driver_register(&rb500_nand_driver
);
202 static void __exit
rb500_nand_exit(void)
204 platform_driver_unregister(&rb500_nand_driver
);
207 module_init(rb500_nand_init
);
208 module_exit(rb500_nand_exit
);
210 MODULE_LICENSE("GPL");
211 MODULE_AUTHOR("David Goodenough, Felix Fietkau, Florian Fainelli");
212 MODULE_DESCRIPTION("RouterBOARD 500 NAND driver");