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 extern char *board_type
;
38 struct rb500_nand_info
{
39 struct nand_chip chip
;
41 void __iomem
*io_base
;
42 #ifdef CONFIG_MTD_PARTITIONS
44 struct mtd_partition
*parts
;
51 static struct mtd_partition partition_info
[] = {
53 name
:"RouterBoard NAND Boot",
55 size
:4 * 1024 * 1024},
58 offset
:MTDPART_OFS_NXTBLK
,
59 size
:MTDPART_SIZ_FULL
}
62 extern void changeLatchU5(unsigned char orMask
, unsigned char nandMask
);
64 static int rb500_dev_ready(struct mtd_info
*mtd
)
66 return MEM32(IDT434_REG_BASE
+ GPIOD
) & GPIO_RDY
;
70 * hardware specific access to control-lines
73 * NAND_CLE: bit 2 -> bit 3
74 * NAND_ALE: bit 3 -> bit 2
76 static void rbmips_hwcontrol500(struct mtd_info
*mtd
, int cmd
,
79 struct nand_chip
*chip
= mtd
->priv
;
80 unsigned char orbits
, nandbits
;
82 if (ctrl
& NAND_CTRL_CHANGE
) {
84 orbits
= (ctrl
& NAND_CLE
) << 1;
85 orbits
|= (ctrl
& NAND_ALE
) >> 1;
87 nandbits
= (~ctrl
& NAND_CLE
) << 1;
88 nandbits
|= (~ctrl
& NAND_ALE
) >> 1;
90 changeLatchU5(orbits
, nandbits
);
92 if (cmd
!= NAND_CMD_NONE
)
93 writeb(cmd
, chip
->IO_ADDR_W
);
97 unsigned get_rbnand_block_size(struct rb500_nand_info
*data
)
100 return data
->mtd
.writesize
;
105 EXPORT_SYMBOL(get_rbnand_block_size
);
107 static int rbmips_probe(struct platform_device
*pdev
)
109 struct rb500_nand_info
*data
;
113 /* Allocate memory for the structure */
114 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
116 dev_err(&pdev
->dev
, "Failed to allocate device structure\n");
120 data
->io_base
= ioremap(pdev
->resource
[0].start
, pdev
->resource
[0].end
- pdev
->resource
[0].start
+ 1);
122 if (data
->io_base
== NULL
) {
123 dev_err(&pdev
->dev
, "ioremap failed\n");
128 if (!strcmp(board_type
, "500r5")) {
129 data
->flags1
= LO_FOFF
| LO_CEX
;
130 data
->flags2
= LO_ULED
| LO_ALE
| LO_CLE
| LO_WPX
;
133 data
->flags1
= LO_WPX
| LO_FOFF
| LO_CEX
;
134 data
->flags2
= LO_ULED
| LO_ALE
| LO_CLE
;
137 changeLatchU5(data
->flags1
, data
->flags2
);
139 data
->chip
.cmd_ctrl
= rbmips_hwcontrol500
;
141 data
->chip
.dev_ready
= rb500_dev_ready
;
142 data
->chip
.IO_ADDR_W
= (unsigned char *)KSEG1ADDR(MEM32(IDT434_REG_BASE
+ DEV2BASE
));
143 data
->chip
.IO_ADDR_R
= data
->chip
.IO_ADDR_W
;
145 data
->chip
.ecc
.mode
= NAND_ECC_SOFT
;
146 data
->chip
.chip_delay
= 25;
147 data
->chip
.options
|= NAND_NO_AUTOINCR
;
149 data
->chip
.priv
= &data
;
150 data
->mtd
.priv
= &data
->chip
;
151 data
->mtd
.owner
= THIS_MODULE
;
153 b
= (int *) KSEG1ADDR(0x18010020);
154 printk("dev2base 0x%08x mask 0x%08x c 0x%08x tc 0x%08x\n", b
[0],
157 platform_set_drvdata(pdev
, data
);
159 /* Why do we need to scan 4 times ? */
160 if (nand_scan(&data
->mtd
, 1) && nand_scan(&data
->mtd
, 1) && nand_scan(&data
->mtd
, 1) && nand_scan(&data
->mtd
, 1)) {
161 printk(KERN_INFO
"RB500 nand device not found\n");
166 printk(KERN_INFO
"RB500 NAND\n");
167 add_mtd_partitions(&data
->mtd
, partition_info
, 2);
170 res
= add_mtd_device(&data
->mtd
);
174 nand_release(&data
->mtd
);
176 platform_set_drvdata(pdev
, NULL
);
177 iounmap(data
->io_base
);
182 static int __devexit
rbmips_remove(struct platform_device
*pdev
)
184 struct rb500_nand_info
*data
= platform_get_drvdata(pdev
);
186 nand_release(&data
->mtd
);
187 iounmap(data
->io_base
);
193 static struct platform_driver rb500_nand_driver
= {
194 .probe
= rbmips_probe
,
195 .remove
= rbmips_remove
,
197 .name
= "rb500-nand",
198 .owner
= THIS_MODULE
,
202 static int __init
rb500_nand_init(void)
205 err
= platform_driver_register(&rb500_nand_driver
);
209 static void __exit
rb500_nand_exit(void)
211 platform_driver_unregister(&rb500_nand_driver
);
214 module_init(rb500_nand_init
);
215 module_exit(rb500_nand_exit
);
217 MODULE_LICENSE("GPL");
218 MODULE_AUTHOR("David Goodenough, Felix Fietkau, Florian Fainelli");
219 MODULE_DESCRIPTION("RouterBOARD 500 NAND driver");