mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: kuldip dwivedi <kuldip.dwivedi@puresoftware.com>
To: Mark Brown <broonie@kernel.org>,
	linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: Qiang Zhao <qiang.zhao@nxp.com>,
	Pankaj Bansal <pankaj.bansal@nxp.com>,
	Varun Sethi <V.Sethi@nxp.com>,
	kuldip dwivedi <kuldip.dwivedi@puresoftware.com>,
	tanveer <tanveer.alam@puresoftware.com>
Subject: [PATCH] spi: spi-fsl-dspi: Add ACPI support
Date: Fri, 21 Aug 2020 18:40:29 +0530	[thread overview]
Message-ID: <20200821131029.11440-1-kuldip.dwivedi@puresoftware.com> (raw)

Currently fsl DSPI driver has support of DT only. Adding ACPI
support to the drive so that it can be used by UEFI firmware
boot in ACPI mode. This driver will be probed if any firmware
will expose HID "NXP0005" in DSDT table.

Signed-off-by: tanveer <tanveer.alam@puresoftware.com>
Signed-off-by: kuldip dwivedi <kuldip.dwivedi@puresoftware.com>
---
 drivers/spi/spi-fsl-dspi.c | 91 +++++++++++++++++++++++++++++---------
 1 file changed, 69 insertions(+), 22 deletions(-)

diff --git a/drivers/spi/spi-fsl-dspi.c b/drivers/spi/spi-fsl-dspi.c
index 91c6affe139c..7100a8a0a30e 100644
--- a/drivers/spi/spi-fsl-dspi.c
+++ b/drivers/spi/spi-fsl-dspi.c
@@ -2,10 +2,12 @@
 //
 // Copyright 2013 Freescale Semiconductor, Inc.
 // Copyright 2020 NXP
+// Copyright 2020 Puresoftware Ltd.
 //
 // Freescale DSPI driver
 // This file contains a driver for the Freescale DSPI
 
+#include <linux/acpi.h>
 #include <linux/clk.h>
 #include <linux/delay.h>
 #include <linux/dmaengine.h>
@@ -1070,6 +1072,12 @@ static void dspi_cleanup(struct spi_device *spi)
 	kfree(chip);
 }
 
+static const struct acpi_device_id fsl_dspi_acpi_ids[] = {
+	{ "NXP0005", .driver_data = (kernel_ulong_t)&devtype_data[LS2085A], },
+	{},
+};
+MODULE_DEVICE_TABLE(acpi, fsl_dspi_acpi_ids);
+
 static const struct of_device_id fsl_dspi_dt_ids[] = {
 	{
 		.compatible = "fsl,vf610-dspi",
@@ -1272,6 +1280,7 @@ static int dspi_probe(struct platform_device *pdev)
 	struct resource *res;
 	void __iomem *base;
 	bool big_endian;
+	u32 clk_rate;
 
 	ctlr = spi_alloc_master(&pdev->dev, sizeof(struct fsl_dspi));
 	if (!ctlr)
@@ -1300,20 +1309,41 @@ static int dspi_probe(struct platform_device *pdev)
 		big_endian = true;
 	} else {
 
-		ret = of_property_read_u32(np, "spi-num-chipselects", &cs_num);
+		if (is_acpi_node(pdev->dev.fwnode))
+			ret = device_property_read_u32(&pdev->dev,
+					"spi-num-chipselects", &cs_num);
+		else
+			ret = of_property_read_u32(np,
+					"spi-num-chipselects", &cs_num);
 		if (ret < 0) {
 			dev_err(&pdev->dev, "can't get spi-num-chipselects\n");
 			goto out_ctlr_put;
 		}
 		ctlr->num_chipselect = cs_num;
 
-		of_property_read_u32(np, "bus-num", &bus_num);
+		if (is_acpi_node(pdev->dev.fwnode)) {
+			ret = device_property_read_u32(&pdev->dev,
+							"bus-num", &bus_num);
+			if (ret < 0) {
+				dev_err(&pdev->dev, "can't get bus-num\n");
+				goto out_ctlr_put;
+			}
+		} else {
+			of_property_read_u32(np, "bus-num", &bus_num);
+		}
 		ctlr->bus_num = bus_num;
 
-		if (of_property_read_bool(np, "spi-slave"))
-			ctlr->slave = true;
+		if (!is_acpi_node(pdev->dev.fwnode)) {
+			if (of_property_read_bool(np, "spi-slave"))
+				ctlr->slave = true;
+		}
+
+		if (is_acpi_node(pdev->dev.fwnode))
+			dspi->devtype_data = device_get_match_data(&pdev->dev);
+		else
+			dspi->devtype_data =
+				of_device_get_match_data(&pdev->dev);
 
-		dspi->devtype_data = of_device_get_match_data(&pdev->dev);
 		if (!dspi->devtype_data) {
 			dev_err(&pdev->dev, "can't get devtype_data\n");
 			ret = -EFAULT;
@@ -1367,15 +1397,18 @@ static int dspi_probe(struct platform_device *pdev)
 		}
 	}
 
-	dspi->clk = devm_clk_get(&pdev->dev, "dspi");
-	if (IS_ERR(dspi->clk)) {
-		ret = PTR_ERR(dspi->clk);
-		dev_err(&pdev->dev, "unable to get clock\n");
-		goto out_ctlr_put;
+	if (!is_acpi_node(pdev->dev.fwnode)) {
+		dspi->clk = devm_clk_get(&pdev->dev, "dspi");
+		if (IS_ERR(dspi->clk)) {
+			ret = PTR_ERR(dspi->clk);
+			dev_err(&pdev->dev, "unable to get clock\n");
+			goto out_ctlr_put;
+		}
+
+		ret = clk_prepare_enable(dspi->clk);
+		if (ret)
+			goto out_ctlr_put;
 	}
-	ret = clk_prepare_enable(dspi->clk);
-	if (ret)
-		goto out_ctlr_put;
 
 	ret = dspi_init(dspi);
 	if (ret)
@@ -1408,8 +1441,21 @@ static int dspi_probe(struct platform_device *pdev)
 		}
 	}
 
-	ctlr->max_speed_hz =
-		clk_get_rate(dspi->clk) / dspi->devtype_data->max_clock_factor;
+	if (is_acpi_node(pdev->dev.fwnode)) {
+		ret = device_property_read_u32(&pdev->dev,
+					       "clock-frequency", &clk_rate);
+		if (ret < 0) {
+			dev_err(&pdev->dev, "can't get clock-frequency\n");
+			goto out_ctlr_put;
+		}
+
+		ctlr->max_speed_hz =
+			clk_rate / dspi->devtype_data->max_clock_factor;
+	} else {
+		clk_rate = clk_get_rate(dspi->clk);
+		ctlr->max_speed_hz =
+			clk_rate / dspi->devtype_data->max_clock_factor;
+	}
 
 	if (dspi->devtype_data->trans_mode != DSPI_DMA_MODE)
 		ctlr->ptp_sts_supported = true;
@@ -1465,13 +1511,14 @@ static void dspi_shutdown(struct platform_device *pdev)
 }
 
 static struct platform_driver fsl_dspi_driver = {
-	.driver.name		= DRIVER_NAME,
-	.driver.of_match_table	= fsl_dspi_dt_ids,
-	.driver.owner		= THIS_MODULE,
-	.driver.pm		= &dspi_pm,
-	.probe			= dspi_probe,
-	.remove			= dspi_remove,
-	.shutdown		= dspi_shutdown,
+	.driver.name			= DRIVER_NAME,
+	.driver.of_match_table		= fsl_dspi_dt_ids,
+	.driver.acpi_match_table	= ACPI_PTR(fsl_dspi_acpi_ids),
+	.driver.owner			= THIS_MODULE,
+	.driver.pm			= &dspi_pm,
+	.probe				= dspi_probe,
+	.remove				= dspi_remove,
+	.shutdown			= dspi_shutdown,
 };
 module_platform_driver(fsl_dspi_driver);
 
-- 
2.17.1


             reply	other threads:[~2020-08-21 13:12 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-08-21 13:10 kuldip dwivedi [this message]
2020-08-21 14:07 ` Mark Brown
2020-08-22 14:07   ` Kuldip Dwivedi
2020-08-22 15:21     ` Vladimir Oltean
2020-08-24 11:25       ` Mark Brown
2020-08-26  8:19         ` Qiang Zhao
2020-08-26 10:19           ` Mark Brown
2020-08-26 11:10       ` Qiang Zhao
2020-08-26 11:47         ` Vladimir Oltean
2020-08-26 14:23           ` Mark Brown
2020-08-26 14:47             ` Vladimir Oltean
2020-08-26 15:13               ` Kuldip Dwivedi
2020-08-26 16:09                 ` Vladimir Oltean
2020-08-26 17:02                   ` Mark Brown
2020-08-26 18:30                     ` Vladimir Oltean
2020-08-26 18:36                       ` Mark Brown
2020-08-26 16:55               ` Mark Brown
2020-08-26 18:33                 ` Vladimir Oltean
2020-08-26 18:42                   ` Mark Brown
2020-08-21 16:49 ` kernel test robot
2020-08-22 18:33 ` Vladimir Oltean
2020-08-26 19:34   ` Andy Shevchenko
2020-08-26 19:36     ` Andy Shevchenko
2020-08-26 19:56       ` Vladimir Oltean
2020-08-26 20:41         ` Mark Brown
2020-08-26 20:41     ` Vladimir Oltean
2020-08-26 20:45       ` Mark Brown
2020-08-26 21:06         ` Vladimir Oltean
2020-08-27 11:32           ` Mark Brown

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20200821131029.11440-1-kuldip.dwivedi@puresoftware.com \
    --to=kuldip.dwivedi@puresoftware.com \
    --cc=V.Sethi@nxp.com \
    --cc=broonie@kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=pankaj.bansal@nxp.com \
    --cc=qiang.zhao@nxp.com \
    --cc=tanveer.alam@puresoftware.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®