Skip to content

Commit 6cadd42

Browse files
committed
Merge tag 'nand/for-5.18' into mtd/next
Raw NAND core changes: * Rework of_get_nand_bus_width() * Remove of_get_nand_on_flash_bbt() wrapper * Protect access to rawnand devices while in suspend * bindings: Document the wp-gpios property Rax NAND controller driver changes: * atmel: Fix refcount issue in atmel_nand_controller_init * nandsim: - Add NS_PAGE_BYTE_SHIFT macro to replace the repeat pattern - Merge repeat codes in ns_switch_state - Replace overflow check with kzalloc to single kcalloc * rockchip: Fix platform_get_irq.cocci warning * stm32_fmc2: Add NAND Write Protect support * pl353: Set the nand chip node as the flash node * brcmnand: Fix sparse warnings in bcma_nand * omap_elm: Remove redundant variable 'errors' * gpmi: - Support fast edo timings for mx28 - Validate controller clock rate - Fix controller timings setting * brcmnand: - Add BCMA shim - BCMA controller uses command shift of 0 - Allow platform data instantation - Add platform data structure for BCMA - Allow working without interrupts - Move OF operations out of brcmnand_init_cs() - Avoid pdev in brcmnand_init_cs() - Allow SoC to provide I/O operations - Assign soc as early as possible Onenand changes: * Check for error irq Signed-off-by: Miquel Raynal <[email protected]>
2 parents 4e371d9 + fecbd4a commit 6cadd42

File tree

20 files changed

+467
-139
lines changed

20 files changed

+467
-139
lines changed

Documentation/devicetree/bindings/mtd/nand-controller.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,13 @@ patternProperties:
116116
Ready/Busy pins. Active state refers to the NAND ready state and
117117
should be set to GPIOD_ACTIVE_HIGH unless the signal is inverted.
118118

119+
wp-gpios:
120+
description:
121+
Contains one GPIO descriptor for the Write Protect pin.
122+
Active state refers to the NAND Write Protect state and should be
123+
set to GPIOD_ACTIVE_LOW unless the signal is inverted.
124+
maxItems: 1
125+
119126
required:
120127
- reg
121128

MAINTAINERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4026,6 +4026,7 @@ L: [email protected]
40264026
40274027
S: Maintained
40284028
F: drivers/mtd/nand/raw/brcmnand/
4029+
F: include/linux/platform_data/brcmnand.h
40294030

40304031
BROADCOM STB PCIE DRIVER
40314032
M: Jim Quinlan <[email protected]>

drivers/bcma/driver_chipcommon_nflash.c

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,28 @@
77

88
#include "bcma_private.h"
99

10+
#include <linux/bitops.h>
1011
#include <linux/platform_device.h>
12+
#include <linux/platform_data/brcmnand.h>
1113
#include <linux/bcma/bcma.h>
1214

15+
/* Alternate NAND controller driver name in order to allow both bcm47xxnflash
16+
* and bcma_brcmnand to be built into the same kernel image.
17+
*/
18+
static const char *bcma_nflash_alt_name = "bcma_brcmnand";
19+
1320
struct platform_device bcma_nflash_dev = {
1421
.name = "bcma_nflash",
1522
.num_resources = 0,
1623
};
1724

25+
static const char *probes[] = { "bcm47xxpart", NULL };
26+
1827
/* Initialize NAND flash access */
1928
int bcma_nflash_init(struct bcma_drv_cc *cc)
2029
{
2130
struct bcma_bus *bus = cc->core->bus;
31+
u32 reg;
2232

2333
if (bus->chipinfo.id != BCMA_CHIP_ID_BCM4706 &&
2434
cc->core->id.rev != 38) {
@@ -33,8 +43,16 @@ int bcma_nflash_init(struct bcma_drv_cc *cc)
3343

3444
cc->nflash.present = true;
3545
if (cc->core->id.rev == 38 &&
36-
(cc->status & BCMA_CC_CHIPST_5357_NAND_BOOT))
46+
(cc->status & BCMA_CC_CHIPST_5357_NAND_BOOT)) {
3747
cc->nflash.boot = true;
48+
/* Determine the chip select that is being used */
49+
reg = bcma_cc_read32(cc, BCMA_CC_NAND_CS_NAND_SELECT) & 0xff;
50+
cc->nflash.brcmnand_info.chip_select = ffs(reg) - 1;
51+
cc->nflash.brcmnand_info.part_probe_types = probes;
52+
cc->nflash.brcmnand_info.ecc_stepsize = 512;
53+
cc->nflash.brcmnand_info.ecc_strength = 1;
54+
bcma_nflash_dev.name = bcma_nflash_alt_name;
55+
}
3856

3957
/* Prepare platform device, but don't register it yet. It's too early,
4058
* malloc (required by device_private_init) is not available yet. */

drivers/mtd/nand/onenand/generic.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,12 @@ static int generic_onenand_probe(struct platform_device *pdev)
5353
}
5454

5555
info->onenand.mmcontrol = pdata ? pdata->mmcontrol : NULL;
56-
info->onenand.irq = platform_get_irq(pdev, 0);
56+
57+
err = platform_get_irq(pdev, 0);
58+
if (err < 0)
59+
goto out_iounmap;
60+
61+
info->onenand.irq = err;
5762

5863
info->mtd.dev.parent = &pdev->dev;
5964
info->mtd.priv = &info->onenand;

drivers/mtd/nand/raw/Kconfig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,19 @@ config MTD_NAND_BRCMNAND
210210
originally designed for Set-Top Box but is used on various BCM7xxx,
211211
BCM3xxx, BCM63xxx, iProc/Cygnus and more.
212212

213+
if MTD_NAND_BRCMNAND
214+
215+
config MTD_NAND_BRCMNAND_BCMA
216+
tristate "Broadcom BCMA NAND controller"
217+
depends on BCMA_NFLASH
218+
depends on BCMA
219+
help
220+
Enables the BRCMNAND controller over BCMA on BCM47186/BCM5358 SoCs.
221+
The glue driver will take care of performing the low-level I/O
222+
operations to interface the BRCMNAND controller over the BCMA bus.
223+
224+
endif # MTD_NAND_BRCMNAND
225+
213226
config MTD_NAND_BCM47XXNFLASH
214227
tristate "BCM4706 BCMA NAND controller"
215228
depends on BCMA_NFLASH

drivers/mtd/nand/raw/atmel/nand-controller.c

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2060,24 +2060,32 @@ static int atmel_nand_controller_init(struct atmel_nand_controller *nc,
20602060
nc->mck = of_clk_get(dev->parent->of_node, 0);
20612061
if (IS_ERR(nc->mck)) {
20622062
dev_err(dev, "Failed to retrieve MCK clk\n");
2063-
return PTR_ERR(nc->mck);
2063+
ret = PTR_ERR(nc->mck);
2064+
goto out_release_dma;
20642065
}
20652066

20662067
np = of_parse_phandle(dev->parent->of_node, "atmel,smc", 0);
20672068
if (!np) {
20682069
dev_err(dev, "Missing or invalid atmel,smc property\n");
2069-
return -EINVAL;
2070+
ret = -EINVAL;
2071+
goto out_release_dma;
20702072
}
20712073

20722074
nc->smc = syscon_node_to_regmap(np);
20732075
of_node_put(np);
20742076
if (IS_ERR(nc->smc)) {
20752077
ret = PTR_ERR(nc->smc);
20762078
dev_err(dev, "Could not get SMC regmap (err = %d)\n", ret);
2077-
return ret;
2079+
goto out_release_dma;
20782080
}
20792081

20802082
return 0;
2083+
2084+
out_release_dma:
2085+
if (nc->dmac)
2086+
dma_release_channel(nc->dmac);
2087+
2088+
return ret;
20812089
}
20822090

20832091
static int

drivers/mtd/nand/raw/brcmnand/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,5 @@ obj-$(CONFIG_MTD_NAND_BRCMNAND) += bcm63138_nand.o
66
obj-$(CONFIG_MTD_NAND_BRCMNAND) += bcm6368_nand.o
77
obj-$(CONFIG_MTD_NAND_BRCMNAND) += brcmstb_nand.o
88
obj-$(CONFIG_MTD_NAND_BRCMNAND) += brcmnand.o
9+
10+
obj-$(CONFIG_MTD_NAND_BRCMNAND_BCMA) += bcma_nand.o
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
// SPDX-License-Identifier: GPL-2.0-only
2+
/*
3+
* Copyright © 2021 Broadcom
4+
*/
5+
#include <linux/bcma/bcma.h>
6+
#include <linux/bcma/bcma_driver_chipcommon.h>
7+
#include <linux/device.h>
8+
#include <linux/module.h>
9+
#include <linux/platform_device.h>
10+
11+
#include "brcmnand.h"
12+
13+
struct brcmnand_bcma_soc {
14+
struct brcmnand_soc soc;
15+
struct bcma_drv_cc *cc;
16+
};
17+
18+
static inline bool brcmnand_bcma_needs_swapping(u32 offset)
19+
{
20+
switch (offset) {
21+
case BCMA_CC_NAND_SPARE_RD0:
22+
case BCMA_CC_NAND_SPARE_RD4:
23+
case BCMA_CC_NAND_SPARE_RD8:
24+
case BCMA_CC_NAND_SPARE_RD12:
25+
case BCMA_CC_NAND_SPARE_WR0:
26+
case BCMA_CC_NAND_SPARE_WR4:
27+
case BCMA_CC_NAND_SPARE_WR8:
28+
case BCMA_CC_NAND_SPARE_WR12:
29+
case BCMA_CC_NAND_DEVID:
30+
case BCMA_CC_NAND_DEVID_X:
31+
case BCMA_CC_NAND_SPARE_RD16:
32+
case BCMA_CC_NAND_SPARE_RD20:
33+
case BCMA_CC_NAND_SPARE_RD24:
34+
case BCMA_CC_NAND_SPARE_RD28:
35+
return true;
36+
}
37+
38+
return false;
39+
}
40+
41+
static inline struct brcmnand_bcma_soc *to_bcma_soc(struct brcmnand_soc *soc)
42+
{
43+
return container_of(soc, struct brcmnand_bcma_soc, soc);
44+
}
45+
46+
static u32 brcmnand_bcma_read_reg(struct brcmnand_soc *soc, u32 offset)
47+
{
48+
struct brcmnand_bcma_soc *sc = to_bcma_soc(soc);
49+
u32 val;
50+
51+
/* Offset into the NAND block and deal with the flash cache separately */
52+
if (offset == BRCMNAND_NON_MMIO_FC_ADDR)
53+
offset = BCMA_CC_NAND_CACHE_DATA;
54+
else
55+
offset += BCMA_CC_NAND_REVISION;
56+
57+
val = bcma_cc_read32(sc->cc, offset);
58+
59+
/* Swap if necessary */
60+
if (brcmnand_bcma_needs_swapping(offset))
61+
val = be32_to_cpu((__force __be32)val);
62+
return val;
63+
}
64+
65+
static void brcmnand_bcma_write_reg(struct brcmnand_soc *soc, u32 val,
66+
u32 offset)
67+
{
68+
struct brcmnand_bcma_soc *sc = to_bcma_soc(soc);
69+
70+
/* Offset into the NAND block */
71+
if (offset == BRCMNAND_NON_MMIO_FC_ADDR)
72+
offset = BCMA_CC_NAND_CACHE_DATA;
73+
else
74+
offset += BCMA_CC_NAND_REVISION;
75+
76+
/* Swap if necessary */
77+
if (brcmnand_bcma_needs_swapping(offset))
78+
val = (__force u32)cpu_to_be32(val);
79+
80+
bcma_cc_write32(sc->cc, offset, val);
81+
}
82+
83+
static struct brcmnand_io_ops brcmnand_bcma_io_ops = {
84+
.read_reg = brcmnand_bcma_read_reg,
85+
.write_reg = brcmnand_bcma_write_reg,
86+
};
87+
88+
static void brcmnand_bcma_prepare_data_bus(struct brcmnand_soc *soc, bool prepare,
89+
bool is_param)
90+
{
91+
struct brcmnand_bcma_soc *sc = to_bcma_soc(soc);
92+
93+
/* Reset the cache address to ensure we are already accessing the
94+
* beginning of a sub-page.
95+
*/
96+
bcma_cc_write32(sc->cc, BCMA_CC_NAND_CACHE_ADDR, 0);
97+
}
98+
99+
static int brcmnand_bcma_nand_probe(struct platform_device *pdev)
100+
{
101+
struct bcma_nflash *nflash = dev_get_platdata(&pdev->dev);
102+
struct brcmnand_bcma_soc *soc;
103+
104+
soc = devm_kzalloc(&pdev->dev, sizeof(*soc), GFP_KERNEL);
105+
if (!soc)
106+
return -ENOMEM;
107+
108+
soc->cc = container_of(nflash, struct bcma_drv_cc, nflash);
109+
soc->soc.prepare_data_bus = brcmnand_bcma_prepare_data_bus;
110+
soc->soc.ops = &brcmnand_bcma_io_ops;
111+
112+
if (soc->cc->core->bus->chipinfo.id == BCMA_CHIP_ID_BCM4706) {
113+
dev_err(&pdev->dev, "Use bcm47xxnflash for 4706!\n");
114+
return -ENODEV;
115+
}
116+
117+
return brcmnand_probe(pdev, &soc->soc);
118+
}
119+
120+
static struct platform_driver brcmnand_bcma_nand_driver = {
121+
.probe = brcmnand_bcma_nand_probe,
122+
.remove = brcmnand_remove,
123+
.driver = {
124+
.name = "bcma_brcmnand",
125+
.pm = &brcmnand_pm_ops,
126+
}
127+
};
128+
module_platform_driver(brcmnand_bcma_nand_driver);
129+
130+
MODULE_LICENSE("GPL v2");
131+
MODULE_AUTHOR("Broadcom");
132+
MODULE_DESCRIPTION("NAND controller driver glue for BCMA chips");

0 commit comments

Comments
 (0)