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 iproc_nand_soc
{
26 struct brcmnand_soc soc
;
28 void __iomem
*idm_base
;
29 void __iomem
*ext_base
;
33 #define IPROC_NAND_CTLR_READY_OFFSET 0x10
34 #define IPROC_NAND_CTLR_READY BIT(0)
36 #define IPROC_NAND_IO_CTRL_OFFSET 0x00
37 #define IPROC_NAND_APB_LE_MODE BIT(24)
38 #define IPROC_NAND_INT_CTRL_READ_ENABLE BIT(6)
40 static bool iproc_nand_intc_ack(struct brcmnand_soc
*soc
)
42 struct iproc_nand_soc
*priv
=
43 container_of(soc
, struct iproc_nand_soc
, soc
);
44 void __iomem
*mmio
= priv
->ext_base
+ IPROC_NAND_CTLR_READY_OFFSET
;
45 u32 val
= brcmnand_readl(mmio
);
47 if (val
& IPROC_NAND_CTLR_READY
) {
48 brcmnand_writel(IPROC_NAND_CTLR_READY
, mmio
);
55 static void iproc_nand_intc_set(struct brcmnand_soc
*soc
, bool en
)
57 struct iproc_nand_soc
*priv
=
58 container_of(soc
, struct iproc_nand_soc
, soc
);
59 void __iomem
*mmio
= priv
->idm_base
+ IPROC_NAND_IO_CTRL_OFFSET
;
63 spin_lock_irqsave(&priv
->idm_lock
, flags
);
65 val
= brcmnand_readl(mmio
);
68 val
|= IPROC_NAND_INT_CTRL_READ_ENABLE
;
70 val
&= ~IPROC_NAND_INT_CTRL_READ_ENABLE
;
72 brcmnand_writel(val
, mmio
);
74 spin_unlock_irqrestore(&priv
->idm_lock
, flags
);
77 static void iproc_nand_apb_access(struct brcmnand_soc
*soc
, bool prepare
)
79 struct iproc_nand_soc
*priv
=
80 container_of(soc
, struct iproc_nand_soc
, soc
);
81 void __iomem
*mmio
= priv
->idm_base
+ IPROC_NAND_IO_CTRL_OFFSET
;
85 spin_lock_irqsave(&priv
->idm_lock
, flags
);
87 val
= brcmnand_readl(mmio
);
90 val
|= IPROC_NAND_APB_LE_MODE
;
92 val
&= ~IPROC_NAND_APB_LE_MODE
;
94 brcmnand_writel(val
, mmio
);
96 spin_unlock_irqrestore(&priv
->idm_lock
, flags
);
99 static int iproc_nand_probe(struct platform_device
*pdev
)
101 struct device
*dev
= &pdev
->dev
;
102 struct iproc_nand_soc
*priv
;
103 struct brcmnand_soc
*soc
;
104 struct resource
*res
;
106 priv
= devm_kzalloc(dev
, sizeof(*priv
), GFP_KERNEL
);
111 spin_lock_init(&priv
->idm_lock
);
113 res
= platform_get_resource_byname(pdev
, IORESOURCE_MEM
, "iproc-idm");
114 priv
->idm_base
= devm_ioremap_resource(dev
, res
);
115 if (IS_ERR(priv
->idm_base
))
116 return PTR_ERR(priv
->idm_base
);
118 res
= platform_get_resource_byname(pdev
, IORESOURCE_MEM
, "iproc-ext");
119 priv
->ext_base
= devm_ioremap_resource(dev
, res
);
120 if (IS_ERR(priv
->ext_base
))
121 return PTR_ERR(priv
->ext_base
);
123 soc
->ctlrdy_ack
= iproc_nand_intc_ack
;
124 soc
->ctlrdy_set_enabled
= iproc_nand_intc_set
;
125 soc
->prepare_data_bus
= iproc_nand_apb_access
;
127 return brcmnand_probe(pdev
, soc
);
130 static const struct of_device_id iproc_nand_of_match
[] = {
131 { .compatible
= "brcm,nand-iproc" },
134 MODULE_DEVICE_TABLE(of
, iproc_nand_of_match
);
136 static struct platform_driver iproc_nand_driver
= {
137 .probe
= iproc_nand_probe
,
138 .remove
= brcmnand_remove
,
140 .name
= "iproc_nand",
141 .pm
= &brcmnand_pm_ops
,
142 .of_match_table
= iproc_nand_of_match
,
145 module_platform_driver(iproc_nand_driver
);
147 MODULE_LICENSE("GPL v2");
148 MODULE_AUTHOR("Brian Norris");
149 MODULE_AUTHOR("Ray Jui");
150 MODULE_DESCRIPTION("NAND driver for Broadcom IPROC-based SoCs");