2 * This program is free software; you can redistribute it and/or modify it
3 * under the terms of the GNU General Public License version 2 as published
4 * by the Free Software Foundation.
7 #include <linux/module.h>
8 #include <linux/mtd/nand.h>
9 #include <linux/of_gpio.h>
10 #include <linux/of_platform.h>
11 #include <linux/clk.h>
12 #include <linux/reset.h>
13 #include <mach/utils.h>
16 #define NAND_CMD_ALE BIT(18)
17 #define NAND_CMD_CLE BIT(19)
19 #define NAND_CMD_RESET 0xff
20 #define NAND_CMD (NAND_CMD_CS | NAND_CMD_CLE)
21 #define NAND_ADDR (NAND_CMD_CS | NAND_CMD_ALE)
22 #define NAND_DATA (NAND_CMD_CS)
24 static void oxnas_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl)
26 struct nand_chip *this = mtd->priv;
27 unsigned long nandaddr = (unsigned long) this->IO_ADDR_W;
29 if (ctrl & NAND_CTRL_CHANGE) {
30 nandaddr &= ~(NAND_CMD | NAND_ADDR);
33 else if (ctrl & NAND_ALE)
34 nandaddr |= NAND_ADDR;
35 this->IO_ADDR_W = (void __iomem *) nandaddr;
38 if (cmd != NAND_CMD_NONE)
39 writeb(cmd, (void __iomem *) nandaddr);
42 static int oxnas_nand_probe(struct platform_device *pdev)
44 /* enable clock and release static block reset */
45 struct clk *clk = of_clk_get(pdev->dev.of_node, 0);
50 clk_prepare_enable(clk);
51 device_reset(&pdev->dev);
56 /* allow users to override the partition in DT using the cmdline */
57 static const char * part_probes[] = { "cmdlinepart", "ofpart", NULL };
59 static struct platform_nand_data oxnas_nand_data = {
63 .part_probe_types = part_probes,
66 .probe = oxnas_nand_probe,
67 .cmd_ctrl = oxnas_cmd_ctrl,
72 * Try to find the node inside the DT. If it is available attach out
75 static int __init oxnas_register_nand(void)
77 struct device_node *node;
78 struct platform_device *pdev;
80 node = of_find_compatible_node(NULL, NULL, "plxtech,nand-nas782x");
83 pdev = of_find_device_by_node(node);
86 pdev->dev.platform_data = &oxnas_nand_data;
91 subsys_initcall(oxnas_register_nand);
93 static const struct of_device_id oxnas_nand_ids[] = {
94 { .compatible = "plxtech,nand-nas782x"},
97 MODULE_DEVICE_TABLE(of, oxnas_nand_ids);
99 MODULE_LICENSE("GPL");
100 MODULE_AUTHOR("Ma Haijun");
101 MODULE_DESCRIPTION("NAND glue for Oxnas platforms");
102 MODULE_ALIAS("platform:oxnas_nand");