2020-09-11 14:45:57

by kuldip dwivedi

[permalink] [raw]
Subject: [PATCH v3] spi: spi-nxp-fspi: Add ACPI support

Currently NXP fspi driver has support of DT only. Adding ACPI
support to the driver so that it can be used by UEFI firmware
booting in ACPI mode. This driver will be probed if any firmware
will expose HID "NXP0009" in DSDT table.

Signed-off-by: kuldip dwivedi <[email protected]>
---

Notes:
1. Add ACPI match table, NXP members are added to confirm HID for FSPI
2. Change the DT specific APIs to device property APIs
so that same API can be used in DT and ACPi mode.
3. Add node specific checks to use indexed based lookup API in case of
ACPI.
if (is_acpi_node(f->dev->fwnode))
res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
else
res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "fspi_base");
4. Omit clock configuration part - in ACPI world, the firmware
is responsible for clock maintenance.
5. This patch is tested on LX2160A platform

drivers/spi/spi-nxp-fspi.c | 69 +++++++++++++++++++++++++++-----------
1 file changed, 50 insertions(+), 19 deletions(-)

diff --git a/drivers/spi/spi-nxp-fspi.c b/drivers/spi/spi-nxp-fspi.c
index 1ccda82da206..0d41406c036d 100644
--- a/drivers/spi/spi-nxp-fspi.c
+++ b/drivers/spi/spi-nxp-fspi.c
@@ -3,7 +3,8 @@
/*
* NXP FlexSPI(FSPI) controller driver.
*
- * Copyright 2019 NXP.
+ * Copyright 2019-2020 NXP
+ * Copyright 2020 Puresoftware Ltd.
*
* FlexSPI is a flexsible SPI host controller which supports two SPI
* channels and up to 4 external devices. Each channel supports
@@ -30,6 +31,7 @@
* Frieder Schrempf <[email protected]>
*/

+#include <linux/acpi.h>
#include <linux/bitops.h>
#include <linux/clk.h>
#include <linux/completion.h>
@@ -563,6 +565,9 @@ static int nxp_fspi_clk_prep_enable(struct nxp_fspi *f)
{
int ret;

+ if (is_acpi_node(f->dev->fwnode))
+ return 0;
+
ret = clk_prepare_enable(f->clk_en);
if (ret)
return ret;
@@ -576,10 +581,15 @@ static int nxp_fspi_clk_prep_enable(struct nxp_fspi *f)
return 0;
}

-static void nxp_fspi_clk_disable_unprep(struct nxp_fspi *f)
+static int nxp_fspi_clk_disable_unprep(struct nxp_fspi *f)
{
+ if (is_acpi_node(f->dev->fwnode))
+ return 0;
+
clk_disable_unprepare(f->clk);
clk_disable_unprepare(f->clk_en);
+
+ return 0;
}

/*
@@ -1001,7 +1011,7 @@ static int nxp_fspi_probe(struct platform_device *pdev)

f = spi_controller_get_devdata(ctlr);
f->dev = dev;
- f->devtype_data = of_device_get_match_data(dev);
+ f->devtype_data = device_get_match_data(dev);
if (!f->devtype_data) {
ret = -ENODEV;
goto err_put_ctrl;
@@ -1010,7 +1020,12 @@ static int nxp_fspi_probe(struct platform_device *pdev)
platform_set_drvdata(pdev, f);

/* find the resources - configuration register address space */
- res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "fspi_base");
+ if (is_acpi_node(f->dev->fwnode))
+ res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+ else
+ res = platform_get_resource_byname(pdev,
+ IORESOURCE_MEM, "fspi_base");
+
f->iobase = devm_ioremap_resource(dev, res);
if (IS_ERR(f->iobase)) {
ret = PTR_ERR(f->iobase);
@@ -1018,7 +1033,12 @@ static int nxp_fspi_probe(struct platform_device *pdev)
}

/* find the resources - controller memory mapped space */
- res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "fspi_mmap");
+ if (is_acpi_node(f->dev->fwnode))
+ res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
+ else
+ res = platform_get_resource_byname(pdev,
+ IORESOURCE_MEM, "fspi_mmap");
+
if (!res) {
ret = -ENODEV;
goto err_put_ctrl;
@@ -1029,22 +1049,24 @@ static int nxp_fspi_probe(struct platform_device *pdev)
f->memmap_phy_size = resource_size(res);

/* find the clocks */
- f->clk_en = devm_clk_get(dev, "fspi_en");
- if (IS_ERR(f->clk_en)) {
- ret = PTR_ERR(f->clk_en);
- goto err_put_ctrl;
- }
+ if (dev_of_node(&pdev->dev)) {
+ f->clk_en = devm_clk_get(dev, "fspi_en");
+ if (IS_ERR(f->clk_en)) {
+ ret = PTR_ERR(f->clk_en);
+ goto err_put_ctrl;
+ }

- f->clk = devm_clk_get(dev, "fspi");
- if (IS_ERR(f->clk)) {
- ret = PTR_ERR(f->clk);
- goto err_put_ctrl;
- }
+ f->clk = devm_clk_get(dev, "fspi");
+ if (IS_ERR(f->clk)) {
+ ret = PTR_ERR(f->clk);
+ goto err_put_ctrl;
+ }

- ret = nxp_fspi_clk_prep_enable(f);
- if (ret) {
- dev_err(dev, "can not enable the clock\n");
- goto err_put_ctrl;
+ ret = nxp_fspi_clk_prep_enable(f);
+ if (ret) {
+ dev_err(dev, "can not enable the clock\n");
+ goto err_put_ctrl;
+ }
}

/* find the irq */
@@ -1127,6 +1149,14 @@ static const struct of_device_id nxp_fspi_dt_ids[] = {
};
MODULE_DEVICE_TABLE(of, nxp_fspi_dt_ids);

+#ifdef CONFIG_ACPI
+static const struct acpi_device_id nxp_fspi_acpi_ids[] = {
+ { "NXP0009", .driver_data = (kernel_ulong_t)&lx2160a_data, },
+ {}
+};
+MODULE_DEVICE_TABLE(acpi, nxp_fspi_acpi_ids);
+#endif
+
static const struct dev_pm_ops nxp_fspi_pm_ops = {
.suspend = nxp_fspi_suspend,
.resume = nxp_fspi_resume,
@@ -1136,6 +1166,7 @@ static struct platform_driver nxp_fspi_driver = {
.driver = {
.name = "nxp-fspi",
.of_match_table = nxp_fspi_dt_ids,
+ .acpi_match_table = ACPI_PTR(nxp_fspi_acpi_ids),
.pm = &nxp_fspi_pm_ops,
},
.probe = nxp_fspi_probe,
--
2.17.1


2020-09-11 16:46:24

by Ashish Kumar

[permalink] [raw]
Subject: RE: [EXT] [PATCH v3] spi: spi-nxp-fspi: Add ACPI support



> -----Original Message-----
> From: kuldip dwivedi <[email protected]>
> Sent: Friday, September 11, 2020 6:34 PM
> To: Ashish Kumar <[email protected]>; Yogesh Gaur
> <[email protected]>; Mark Brown <[email protected]>; linux-
> [email protected]; [email protected]
> Cc: Varun Sethi <[email protected]>; Arokia Samy <[email protected]>;
> Ard Biesheuvel <[email protected]>; Samer El-Haj-Mahmoud
> <[email protected]>; Paul Yang <[email protected]>;
> kuldip dwivedi <[email protected]>
> Subject: [EXT] [PATCH v3] spi: spi-nxp-fspi: Add ACPI support
>
> Caution: EXT Email
>
> Currently NXP fspi driver has support of DT only. Adding ACPI support to the
> driver so that it can be used by UEFI firmware booting in ACPI mode. This
> driver will be probed if any firmware will expose HID "NXP0009" in DSDT
> table.
>
> Signed-off-by: kuldip dwivedi <[email protected]>
Reviewed-by: Ashish Kumar <[email protected]>

Regards
Ashish
> ---
>
> Notes:
> 1. Add ACPI match table, NXP members are added to confirm HID for FSPI
> 2. Change the DT specific APIs to device property APIs
> so that same API can be used in DT and ACPi mode.
> 3. Add node specific checks to use indexed based lookup API in case of
> ACPI.
> if (is_acpi_node(f->dev->fwnode))
> res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> else
> res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
> "fspi_base");
> 4. Omit clock configuration part - in ACPI world, the firmware
> is responsible for clock maintenance.
> 5. This patch is tested on LX2160A platform
>
> drivers/spi/spi-nxp-fspi.c | 69 +++++++++++++++++++++++++++-----------
> 1 file changed, 50 insertions(+), 19 deletions(-)
>
> diff --git a/drivers/spi/spi-nxp-fspi.c b/drivers/spi/spi-nxp-fspi.c index
> 1ccda82da206..0d41406c036d 100644
> --- a/drivers/spi/spi-nxp-fspi.c
> +++ b/drivers/spi/spi-nxp-fspi.c
> @@ -3,7 +3,8 @@
> /*
> * NXP FlexSPI(FSPI) controller driver.
> *
> - * Copyright 2019 NXP.
> + * Copyright 2019-2020 NXP
> + * Copyright 2020 Puresoftware Ltd.
> *
> * FlexSPI is a flexsible SPI host controller which supports two SPI
> * channels and up to 4 external devices. Each channel supports @@ -30,6
> +31,7 @@
> * Frieder Schrempf <[email protected]>
> */
>
> +#include <linux/acpi.h>
> #include <linux/bitops.h>
> #include <linux/clk.h>
> #include <linux/completion.h>
> @@ -563,6 +565,9 @@ static int nxp_fspi_clk_prep_enable(struct nxp_fspi
> *f) {
> int ret;
>
> + if (is_acpi_node(f->dev->fwnode))
> + return 0;
> +
> ret = clk_prepare_enable(f->clk_en);
> if (ret)
> return ret;
> @@ -576,10 +581,15 @@ static int nxp_fspi_clk_prep_enable(struct
> nxp_fspi *f)
> return 0;
> }
>
> -static void nxp_fspi_clk_disable_unprep(struct nxp_fspi *f)
> +static int nxp_fspi_clk_disable_unprep(struct nxp_fspi *f)
> {
> + if (is_acpi_node(f->dev->fwnode))
> + return 0;
> +
> clk_disable_unprepare(f->clk);
> clk_disable_unprepare(f->clk_en);
> +
> + return 0;
> }
>
> /*
> @@ -1001,7 +1011,7 @@ static int nxp_fspi_probe(struct platform_device
> *pdev)
>
> f = spi_controller_get_devdata(ctlr);
> f->dev = dev;
> - f->devtype_data = of_device_get_match_data(dev);
> + f->devtype_data = device_get_match_data(dev);
> if (!f->devtype_data) {
> ret = -ENODEV;
> goto err_put_ctrl;
> @@ -1010,7 +1020,12 @@ static int nxp_fspi_probe(struct platform_device
> *pdev)
> platform_set_drvdata(pdev, f);
>
> /* find the resources - configuration register address space */
> - res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
> "fspi_base");
> + if (is_acpi_node(f->dev->fwnode))
> + res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
> + else
> + res = platform_get_resource_byname(pdev,
> + IORESOURCE_MEM, "fspi_base");
> +
> f->iobase = devm_ioremap_resource(dev, res);
> if (IS_ERR(f->iobase)) {
> ret = PTR_ERR(f->iobase); @@ -1018,7 +1033,12 @@ static int
> nxp_fspi_probe(struct platform_device *pdev)
> }
>
> /* find the resources - controller memory mapped space */
> - res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
> "fspi_mmap");
> + if (is_acpi_node(f->dev->fwnode))
> + res = platform_get_resource(pdev, IORESOURCE_MEM, 1);
> + else
> + res = platform_get_resource_byname(pdev,
> + IORESOURCE_MEM, "fspi_mmap");
> +
> if (!res) {
> ret = -ENODEV;
> goto err_put_ctrl;
> @@ -1029,22 +1049,24 @@ static int nxp_fspi_probe(struct platform_device
> *pdev)
> f->memmap_phy_size = resource_size(res);
>
> /* find the clocks */
> - f->clk_en = devm_clk_get(dev, "fspi_en");
> - if (IS_ERR(f->clk_en)) {
> - ret = PTR_ERR(f->clk_en);
> - goto err_put_ctrl;
> - }
> + if (dev_of_node(&pdev->dev)) {
> + f->clk_en = devm_clk_get(dev, "fspi_en");
> + if (IS_ERR(f->clk_en)) {
> + ret = PTR_ERR(f->clk_en);
> + goto err_put_ctrl;
> + }
>
> - f->clk = devm_clk_get(dev, "fspi");
> - if (IS_ERR(f->clk)) {
> - ret = PTR_ERR(f->clk);
> - goto err_put_ctrl;
> - }
> + f->clk = devm_clk_get(dev, "fspi");
> + if (IS_ERR(f->clk)) {
> + ret = PTR_ERR(f->clk);
> + goto err_put_ctrl;
> + }
>
> - ret = nxp_fspi_clk_prep_enable(f);
> - if (ret) {
> - dev_err(dev, "can not enable the clock\n");
> - goto err_put_ctrl;
> + ret = nxp_fspi_clk_prep_enable(f);
> + if (ret) {
> + dev_err(dev, "can not enable the clock\n");
> + goto err_put_ctrl;
> + }
> }
>
> /* find the irq */
> @@ -1127,6 +1149,14 @@ static const struct of_device_id nxp_fspi_dt_ids[]
> = { }; MODULE_DEVICE_TABLE(of, nxp_fspi_dt_ids);
>
> +#ifdef CONFIG_ACPI
> +static const struct acpi_device_id nxp_fspi_acpi_ids[] = {
> + { "NXP0009", .driver_data = (kernel_ulong_t)&lx2160a_data, },
> + {}
> +};
> +MODULE_DEVICE_TABLE(acpi, nxp_fspi_acpi_ids); #endif
> +
> static const struct dev_pm_ops nxp_fspi_pm_ops = {
> .suspend = nxp_fspi_suspend,
> .resume = nxp_fspi_resume,
> @@ -1136,6 +1166,7 @@ static struct platform_driver nxp_fspi_driver = {
> .driver = {
> .name = "nxp-fspi",
> .of_match_table = nxp_fspi_dt_ids,
> + .acpi_match_table = ACPI_PTR(nxp_fspi_acpi_ids),
> .pm = &nxp_fspi_pm_ops,
> },
> .probe = nxp_fspi_probe,
> --
> 2.17.1

2020-09-17 19:04:35

by Mark Brown

[permalink] [raw]
Subject: Re: [PATCH v3] spi: spi-nxp-fspi: Add ACPI support

On Fri, 11 Sep 2020 18:33:31 +0530, kuldip dwivedi wrote:
> Currently NXP fspi driver has support of DT only. Adding ACPI
> support to the driver so that it can be used by UEFI firmware
> booting in ACPI mode. This driver will be probed if any firmware
> will expose HID "NXP0009" in DSDT table.

Applied to

https://git.kernel.org/pub/scm/linux/kernel/git/broonie/spi.git for-next

Thanks!

[1/1] spi: spi-nxp-fspi: Add ACPI support
commit: 55ab8487e01d18466ddf596acc7a11e8c53b2812

All being well this means that it will be integrated into the linux-next
tree (usually sometime in the next 24 hours) and sent to Linus during
the next merge window (or sooner if it is a bug fix), however if
problems are discovered then the patch may be dropped or reverted.

You may get further e-mails resulting from automated or manual testing
and review of the tree, please engage with people reporting problems and
send followup patches addressing any issues that are reported if needed.

If any updates are required or you are submitting further changes they
should be sent as incremental updates against current git, existing
patches will not be replaced.

Please add any relevant lists and maintainers to the CCs when replying
to this mail.

Thanks,
Mark