Skip to content

Commit 0bfad3b

Browse files
Christophe Kerellomiquelraynal
authored andcommitted
mtd: rawnand: stm32_fmc2: add MP25 support
FMC2 IP supports up to 4 chip select. On MP1 SoC, only 2 of them are available when on MP25 SoC, the 4 chip select are available. Let's use a platform data structure for parameters that will differ. Signed-off-by: Christophe Kerello <[email protected]> Signed-off-by: Miquel Raynal <[email protected]> Link: https://lore.kernel.org/linux-mtd/[email protected]
1 parent a9ae475 commit 0bfad3b

File tree

1 file changed

+45
-9
lines changed

1 file changed

+45
-9
lines changed

drivers/mtd/nand/raw/stm32_fmc2_nand.c

Lines changed: 45 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
#include <linux/module.h>
1717
#include <linux/mtd/rawnand.h>
1818
#include <linux/of_address.h>
19+
#include <linux/of_device.h>
1920
#include <linux/pinctrl/consumer.h>
2021
#include <linux/platform_device.h>
2122
#include <linux/regmap.h>
@@ -37,7 +38,7 @@
3738
#define FMC2_MAX_SG 16
3839

3940
/* Max chip enable */
40-
#define FMC2_MAX_CE 2
41+
#define FMC2_MAX_CE 4
4142

4243
/* Max ECC buffer length */
4344
#define FMC2_MAX_ECC_BUF_LEN (FMC2_BCHDSRS_LEN * FMC2_MAX_SG)
@@ -243,6 +244,13 @@ static inline struct stm32_fmc2_nand *to_fmc2_nand(struct nand_chip *chip)
243244
return container_of(chip, struct stm32_fmc2_nand, chip);
244245
}
245246

247+
struct stm32_fmc2_nfc;
248+
249+
struct stm32_fmc2_nfc_data {
250+
int max_ncs;
251+
int (*set_cdev)(struct stm32_fmc2_nfc *nfc);
252+
};
253+
246254
struct stm32_fmc2_nfc {
247255
struct nand_controller base;
248256
struct stm32_fmc2_nand nand;
@@ -256,6 +264,7 @@ struct stm32_fmc2_nfc {
256264
phys_addr_t data_phys_addr[FMC2_MAX_CE];
257265
struct clk *clk;
258266
u8 irq_state;
267+
const struct stm32_fmc2_nfc_data *data;
259268

260269
struct dma_chan *dma_tx_ch;
261270
struct dma_chan *dma_rx_ch;
@@ -1809,7 +1818,7 @@ static int stm32_fmc2_nfc_parse_child(struct stm32_fmc2_nfc *nfc,
18091818
return ret;
18101819
}
18111820

1812-
if (cs >= FMC2_MAX_CE) {
1821+
if (cs >= nfc->data->max_ncs) {
18131822
dev_err(nfc->dev, "invalid reg value: %d\n", cs);
18141823
return -EINVAL;
18151824
}
@@ -1915,9 +1924,17 @@ static int stm32_fmc2_nfc_probe(struct platform_device *pdev)
19151924
nand_controller_init(&nfc->base);
19161925
nfc->base.ops = &stm32_fmc2_nfc_controller_ops;
19171926

1918-
ret = stm32_fmc2_nfc_set_cdev(nfc);
1919-
if (ret)
1920-
return ret;
1927+
nfc->data = of_device_get_match_data(dev);
1928+
if (!nfc->data)
1929+
return -EINVAL;
1930+
1931+
if (nfc->data->set_cdev) {
1932+
ret = nfc->data->set_cdev(nfc);
1933+
if (ret)
1934+
return ret;
1935+
} else {
1936+
nfc->cdev = dev->parent;
1937+
}
19211938

19221939
ret = stm32_fmc2_nfc_parse_dt(nfc);
19231940
if (ret)
@@ -1936,7 +1953,7 @@ static int stm32_fmc2_nfc_probe(struct platform_device *pdev)
19361953
if (nfc->dev == nfc->cdev)
19371954
start_region = 1;
19381955

1939-
for (chip_cs = 0, mem_region = start_region; chip_cs < FMC2_MAX_CE;
1956+
for (chip_cs = 0, mem_region = start_region; chip_cs < nfc->data->max_ncs;
19401957
chip_cs++, mem_region += 3) {
19411958
if (!(nfc->cs_assigned & BIT(chip_cs)))
19421959
continue;
@@ -2092,7 +2109,7 @@ static int __maybe_unused stm32_fmc2_nfc_resume(struct device *dev)
20922109

20932110
stm32_fmc2_nfc_wp_disable(nand);
20942111

2095-
for (chip_cs = 0; chip_cs < FMC2_MAX_CE; chip_cs++) {
2112+
for (chip_cs = 0; chip_cs < nfc->data->max_ncs; chip_cs++) {
20962113
if (!(nfc->cs_assigned & BIT(chip_cs)))
20972114
continue;
20982115

@@ -2105,9 +2122,28 @@ static int __maybe_unused stm32_fmc2_nfc_resume(struct device *dev)
21052122
static SIMPLE_DEV_PM_OPS(stm32_fmc2_nfc_pm_ops, stm32_fmc2_nfc_suspend,
21062123
stm32_fmc2_nfc_resume);
21072124

2125+
static const struct stm32_fmc2_nfc_data stm32_fmc2_nfc_mp1_data = {
2126+
.max_ncs = 2,
2127+
.set_cdev = stm32_fmc2_nfc_set_cdev,
2128+
};
2129+
2130+
static const struct stm32_fmc2_nfc_data stm32_fmc2_nfc_mp25_data = {
2131+
.max_ncs = 4,
2132+
};
2133+
21082134
static const struct of_device_id stm32_fmc2_nfc_match[] = {
2109-
{.compatible = "st,stm32mp15-fmc2"},
2110-
{.compatible = "st,stm32mp1-fmc2-nfc"},
2135+
{
2136+
.compatible = "st,stm32mp15-fmc2",
2137+
.data = &stm32_fmc2_nfc_mp1_data,
2138+
},
2139+
{
2140+
.compatible = "st,stm32mp1-fmc2-nfc",
2141+
.data = &stm32_fmc2_nfc_mp1_data,
2142+
},
2143+
{
2144+
.compatible = "st,stm32mp25-fmc2-nfc",
2145+
.data = &stm32_fmc2_nfc_mp25_data,
2146+
},
21112147
{}
21122148
};
21132149
MODULE_DEVICE_TABLE(of, stm32_fmc2_nfc_match);

0 commit comments

Comments
 (0)