]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blob - drivers/mtd/nand/brcmnand/bcm63138_nand.c
mtd: brcmnand: add BCM63138 support
[mirror_ubuntu-hirsute-kernel.git] / drivers / mtd / nand / brcmnand / bcm63138_nand.c
1 /*
2 * Copyright © 2015 Broadcom Corporation
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 */
13
14 #include <linux/device.h>
15 #include <linux/io.h>
16 #include <linux/ioport.h>
17 #include <linux/module.h>
18 #include <linux/of.h>
19 #include <linux/of_address.h>
20 #include <linux/platform_device.h>
21 #include <linux/slab.h>
22
23 #include "brcmnand.h"
24
25 struct bcm63138_nand_soc_priv {
26 void __iomem *base;
27 };
28
29 #define BCM63138_NAND_INT_STATUS 0x00
30 #define BCM63138_NAND_INT_EN 0x04
31
32 enum {
33 BCM63138_CTLRDY = BIT(4),
34 };
35
36 static bool bcm63138_nand_intc_ack(struct brcmnand_soc *soc)
37 {
38 struct bcm63138_nand_soc_priv *priv = soc->priv;
39 void __iomem *mmio = priv->base + BCM63138_NAND_INT_STATUS;
40 u32 val = brcmnand_readl(mmio);
41
42 if (val & BCM63138_CTLRDY) {
43 brcmnand_writel(val & ~BCM63138_CTLRDY, mmio);
44 return true;
45 }
46
47 return false;
48 }
49
50 static void bcm63138_nand_intc_set(struct brcmnand_soc *soc, bool en)
51 {
52 struct bcm63138_nand_soc_priv *priv = soc->priv;
53 void __iomem *mmio = priv->base + BCM63138_NAND_INT_EN;
54 u32 val = brcmnand_readl(mmio);
55
56 if (en)
57 val |= BCM63138_CTLRDY;
58 else
59 val &= ~BCM63138_CTLRDY;
60
61 brcmnand_writel(val, mmio);
62 }
63
64 static int bcm63138_nand_probe(struct platform_device *pdev)
65 {
66 struct device *dev = &pdev->dev;
67 struct bcm63138_nand_soc_priv *priv;
68 struct brcmnand_soc *soc;
69 struct resource *res;
70
71 soc = devm_kzalloc(dev, sizeof(*soc), GFP_KERNEL);
72 if (!soc)
73 return -ENOMEM;
74
75 priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
76 if (!priv)
77 return -ENOMEM;
78
79 res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "nand-int-base");
80 priv->base = devm_ioremap_resource(dev, res);
81 if (IS_ERR(priv->base))
82 return PTR_ERR(priv->base);
83
84 soc->pdev = pdev;
85 soc->priv = priv;
86 soc->ctlrdy_ack = bcm63138_nand_intc_ack;
87 soc->ctlrdy_set_enabled = bcm63138_nand_intc_set;
88
89 return brcmnand_probe(pdev, soc);
90 }
91
92 static const struct of_device_id bcm63138_nand_of_match[] = {
93 { .compatible = "brcm,nand-bcm63138" },
94 {},
95 };
96 MODULE_DEVICE_TABLE(of, bcm63138_nand_of_match);
97
98 static struct platform_driver bcm63138_nand_driver = {
99 .probe = bcm63138_nand_probe,
100 .remove = brcmnand_remove,
101 .driver = {
102 .name = "bcm63138_nand",
103 .pm = &brcmnand_pm_ops,
104 .of_match_table = bcm63138_nand_of_match,
105 }
106 };
107 module_platform_driver(bcm63138_nand_driver);
108
109 MODULE_LICENSE("GPL v2");
110 MODULE_AUTHOR("Brian Norris");
111 MODULE_DESCRIPTION("NAND driver for BCM63138");