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 * Copyright © 2012 John Crispin <blogic@openwrt.org>
8 * and oxnas_nand.c "NAND glue for Oxnas platforms"
9 * written by Ma Haijun <mahaijuns@gmail.com>
12 #include <linux/mtd/nand.h>
13 #include <linux/of_gpio.h>
14 #include <linux/of_platform.h>
15 #include <linux/clk.h>
16 #include <linux/reset.h>
19 #define NAND_CMD_ALE BIT(18)
20 #define NAND_CMD_CLE BIT(19)
22 #define NAND_CMD_RESET 0xff
23 #define NAND_CMD (NAND_CMD_CS | NAND_CMD_CLE)
24 #define NAND_ADDR (NAND_CMD_CS | NAND_CMD_ALE)
25 #define NAND_DATA (NAND_CMD_CS)
27 static void oxnas_cmd_ctrl(struct mtd_info *mtd, int cmd, unsigned int ctrl)
29 struct nand_chip *this = mtd->priv;
30 unsigned long nandaddr = (unsigned long) this->IO_ADDR_W;
32 if (ctrl & NAND_CTRL_CHANGE) {
33 nandaddr &= ~(NAND_CMD | NAND_ADDR);
36 else if (ctrl & NAND_ALE)
37 nandaddr |= NAND_ADDR;
38 this->IO_ADDR_W = (void __iomem *) nandaddr;
41 if (cmd != NAND_CMD_NONE)
42 writeb(cmd, (void __iomem *) nandaddr);
45 static int oxnas_nand_probe(struct platform_device *pdev)
47 /* enable clock and release static block reset */
48 struct clk *clk = of_clk_get(pdev->dev.of_node, 0);
53 clk_prepare_enable(clk);
54 device_reset(&pdev->dev);
59 /* allow users to override the partition in DT using the cmdline */
60 static const char * part_probes[] = { "cmdlinepart", "ofpart", NULL };
62 static struct platform_nand_data oxnas_nand_data = {
66 .part_probe_types = part_probes,
69 .probe = oxnas_nand_probe,
70 .cmd_ctrl = oxnas_cmd_ctrl,
75 * Try to find the node inside the DT. If it is available attach out
78 static int __init oxnas_register_nand(void)
80 struct device_node *node;
81 struct platform_device *pdev;
83 node = of_find_compatible_node(NULL, NULL, "plxtech,nand-nas782x");
86 pdev = of_find_device_by_node(node);
89 pdev->dev.platform_data = &oxnas_nand_data;
94 subsys_initcall(oxnas_register_nand);