1
2
3
4
5
6
7
8
9
10
11
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
25struct 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
32enum {
33 BCM63138_CTLRDY = BIT(4),
34};
35
36static 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
50static 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
64static 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
92static const struct of_device_id bcm63138_nand_of_match[] = {
93 { .compatible = "brcm,nand-bcm63138" },
94 {},
95};
96MODULE_DEVICE_TABLE(of, bcm63138_nand_of_match);
97
98static 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};
107module_platform_driver(bcm63138_nand_driver);
108
109MODULE_LICENSE("GPL v2");
110MODULE_AUTHOR("Brian Norris");
111MODULE_DESCRIPTION("NAND driver for BCM63138");
112