Skip to content

Commit fbd9b54

Browse files
Christophe Kerellomiquelraynal
authored andcommitted
mtd: rawnand: stm32_fmc2: get resources from parent node
FMC2 EBI support has been added. Common resources (registers base address and clock) can now be shared between the 2 drivers using "st,stm32mp1-fmc2-nfc" compatible string. It means that the common resources should now be found in the parent device when EBI node is available. 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 51c88a8 commit fbd9b54

File tree

2 files changed

+51
-23
lines changed

2 files changed

+51
-23
lines changed

drivers/mtd/nand/raw/Kconfig

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,8 +415,7 @@ config MTD_NAND_TEGRA
415415
config MTD_NAND_STM32_FMC2
416416
tristate "Support for NAND controller on STM32MP SoCs"
417417
depends on MACH_STM32MP157 || COMPILE_TEST
418-
select REGMAP
419-
select REGMAP_MMIO
418+
select MFD_SYSCON
420419
help
421420
Enables support for NAND Flash chips on SoCs containing the FMC2
422421
NAND controller. This controller is found on STM32MP SoCs.

drivers/mtd/nand/raw/stm32_fmc2_nand.c

Lines changed: 50 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111
#include <linux/errno.h>
1212
#include <linux/interrupt.h>
1313
#include <linux/iopoll.h>
14+
#include <linux/mfd/syscon.h>
1415
#include <linux/module.h>
1516
#include <linux/mtd/rawnand.h>
17+
#include <linux/of_address.h>
1618
#include <linux/pinctrl/consumer.h>
1719
#include <linux/platform_device.h>
1820
#include <linux/regmap.h>
@@ -204,16 +206,6 @@
204206
#define FMC2_BCHDSR4_EBP7 GENMASK(12, 0)
205207
#define FMC2_BCHDSR4_EBP8 GENMASK(28, 16)
206208

207-
/* Regmap registers configuration */
208-
#define FMC2_MAX_REGISTER 0x3fc
209-
210-
static const struct regmap_config stm32_fmc2_regmap_cfg = {
211-
.reg_bits = 32,
212-
.val_bits = 32,
213-
.reg_stride = sizeof(u32),
214-
.max_register = FMC2_MAX_REGISTER,
215-
};
216-
217209
enum stm32_fmc2_ecc {
218210
FMC2_ECC_HAM = 1,
219211
FMC2_ECC_BCH4 = 4,
@@ -253,6 +245,7 @@ struct stm32_fmc2_nfc {
253245
struct nand_controller base;
254246
struct stm32_fmc2_nand nand;
255247
struct device *dev;
248+
struct device *cdev;
256249
struct regmap *regmap;
257250
void __iomem *data_base[FMC2_MAX_CE];
258251
void __iomem *cmd_base[FMC2_MAX_CE];
@@ -1384,8 +1377,9 @@ static void stm32_fmc2_nfc_init(struct stm32_fmc2_nfc *nfc)
13841377
pcr |= FIELD_PREP(FMC2_PCR_TAR, FMC2_PCR_TAR_DEFAULT);
13851378

13861379
/* Enable FMC2 controller */
1387-
regmap_update_bits(nfc->regmap, FMC2_BCR1,
1388-
FMC2_BCR1_FMC2EN, FMC2_BCR1_FMC2EN);
1380+
if (nfc->dev == nfc->cdev)
1381+
regmap_update_bits(nfc->regmap, FMC2_BCR1,
1382+
FMC2_BCR1_FMC2EN, FMC2_BCR1_FMC2EN);
13891383

13901384
regmap_write(nfc->regmap, FMC2_PCR, pcr);
13911385
regmap_write(nfc->regmap, FMC2_PMEM, FMC2_PMEM_DEFAULT);
@@ -1815,6 +1809,33 @@ static int stm32_fmc2_nfc_parse_dt(struct stm32_fmc2_nfc *nfc)
18151809
return ret;
18161810
}
18171811

1812+
static int stm32_fmc2_nfc_set_cdev(struct stm32_fmc2_nfc *nfc)
1813+
{
1814+
struct device *dev = nfc->dev;
1815+
bool ebi_found = false;
1816+
1817+
if (dev->parent && of_device_is_compatible(dev->parent->of_node,
1818+
"st,stm32mp1-fmc2-ebi"))
1819+
ebi_found = true;
1820+
1821+
if (of_device_is_compatible(dev->of_node, "st,stm32mp1-fmc2-nfc")) {
1822+
if (ebi_found) {
1823+
nfc->cdev = dev->parent;
1824+
1825+
return 0;
1826+
}
1827+
1828+
return -EINVAL;
1829+
}
1830+
1831+
if (ebi_found)
1832+
return -EINVAL;
1833+
1834+
nfc->cdev = dev;
1835+
1836+
return 0;
1837+
}
1838+
18181839
static int stm32_fmc2_nfc_probe(struct platform_device *pdev)
18191840
{
18201841
struct device *dev = &pdev->dev;
@@ -1824,8 +1845,9 @@ static int stm32_fmc2_nfc_probe(struct platform_device *pdev)
18241845
struct resource *res;
18251846
struct mtd_info *mtd;
18261847
struct nand_chip *chip;
1827-
void __iomem *mmio;
1848+
struct resource cres;
18281849
int chip_cs, mem_region, ret, irq;
1850+
int start_region = 0;
18291851

18301852
nfc = devm_kzalloc(dev, sizeof(*nfc), GFP_KERNEL);
18311853
if (!nfc)
@@ -1835,22 +1857,28 @@ static int stm32_fmc2_nfc_probe(struct platform_device *pdev)
18351857
nand_controller_init(&nfc->base);
18361858
nfc->base.ops = &stm32_fmc2_nfc_controller_ops;
18371859

1860+
ret = stm32_fmc2_nfc_set_cdev(nfc);
1861+
if (ret)
1862+
return ret;
1863+
18381864
ret = stm32_fmc2_nfc_parse_dt(nfc);
18391865
if (ret)
18401866
return ret;
18411867

1842-
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
1843-
mmio = devm_ioremap_resource(dev, res);
1844-
if (IS_ERR(mmio))
1845-
return PTR_ERR(mmio);
1868+
ret = of_address_to_resource(nfc->cdev->of_node, 0, &cres);
1869+
if (ret)
1870+
return ret;
1871+
1872+
nfc->io_phys_addr = cres.start;
18461873

1847-
nfc->regmap = devm_regmap_init_mmio(dev, mmio, &stm32_fmc2_regmap_cfg);
1874+
nfc->regmap = device_node_to_regmap(nfc->cdev->of_node);
18481875
if (IS_ERR(nfc->regmap))
18491876
return PTR_ERR(nfc->regmap);
18501877

1851-
nfc->io_phys_addr = res->start;
1878+
if (nfc->dev == nfc->cdev)
1879+
start_region = 1;
18521880

1853-
for (chip_cs = 0, mem_region = 1; chip_cs < FMC2_MAX_CE;
1881+
for (chip_cs = 0, mem_region = start_region; chip_cs < FMC2_MAX_CE;
18541882
chip_cs++, mem_region += 3) {
18551883
if (!(nfc->cs_assigned & BIT(chip_cs)))
18561884
continue;
@@ -1888,7 +1916,7 @@ static int stm32_fmc2_nfc_probe(struct platform_device *pdev)
18881916

18891917
init_completion(&nfc->complete);
18901918

1891-
nfc->clk = devm_clk_get(dev, NULL);
1919+
nfc->clk = devm_clk_get(nfc->cdev, NULL);
18921920
if (IS_ERR(nfc->clk))
18931921
return PTR_ERR(nfc->clk);
18941922

@@ -2029,6 +2057,7 @@ static SIMPLE_DEV_PM_OPS(stm32_fmc2_nfc_pm_ops, stm32_fmc2_nfc_suspend,
20292057

20302058
static const struct of_device_id stm32_fmc2_nfc_match[] = {
20312059
{.compatible = "st,stm32mp15-fmc2"},
2060+
{.compatible = "st,stm32mp1-fmc2-nfc"},
20322061
{}
20332062
};
20342063
MODULE_DEVICE_TABLE(of, stm32_fmc2_nfc_match);

0 commit comments

Comments
 (0)