2 * Copyright © 2015 Broadcom Corporation
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.
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.
14 #include <linux/device.h>
16 #include <linux/ioport.h>
17 #include <linux/module.h>
19 #include <linux/of_address.h>
20 #include <linux/platform_device.h>
21 #include <linux/slab.h>
25 struct bcm63138_nand_soc_priv
{
29 #define BCM63138_NAND_INT_STATUS 0x00
30 #define BCM63138_NAND_INT_EN 0x04
33 BCM63138_CTLRDY
= BIT(4),
36 static bool bcm63138_nand_intc_ack(struct brcmnand_soc
*soc
)
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
);
42 if (val
& BCM63138_CTLRDY
) {
43 brcmnand_writel(val
& ~BCM63138_CTLRDY
, mmio
);
50 static void bcm63138_nand_intc_set(struct brcmnand_soc
*soc
, bool en
)
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
);
57 val
|= BCM63138_CTLRDY
;
59 val
&= ~BCM63138_CTLRDY
;
61 brcmnand_writel(val
, mmio
);
64 static int bcm63138_nand_probe(struct platform_device
*pdev
)
66 struct device
*dev
= &pdev
->dev
;
67 struct bcm63138_nand_soc_priv
*priv
;
68 struct brcmnand_soc
*soc
;
71 soc
= devm_kzalloc(dev
, sizeof(*soc
), GFP_KERNEL
);
75 priv
= devm_kzalloc(dev
, sizeof(*priv
), GFP_KERNEL
);
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
);
86 soc
->ctlrdy_ack
= bcm63138_nand_intc_ack
;
87 soc
->ctlrdy_set_enabled
= bcm63138_nand_intc_set
;
89 return brcmnand_probe(pdev
, soc
);
92 static const struct of_device_id bcm63138_nand_of_match
[] = {
93 { .compatible
= "brcm,nand-bcm63138" },
96 MODULE_DEVICE_TABLE(of
, bcm63138_nand_of_match
);
98 static struct platform_driver bcm63138_nand_driver
= {
99 .probe
= bcm63138_nand_probe
,
100 .remove
= brcmnand_remove
,
102 .name
= "bcm63138_nand",
103 .pm
= &brcmnand_pm_ops
,
104 .of_match_table
= bcm63138_nand_of_match
,
107 module_platform_driver(bcm63138_nand_driver
);
109 MODULE_LICENSE("GPL v2");
110 MODULE_AUTHOR("Brian Norris");
111 MODULE_DESCRIPTION("NAND driver for BCM63138");