All of lore.kernel.org
 help / color / mirror / Atom feed
From: Witold Sadowski <wsadowski@marvell.com>
To: <linux-kernel@vger.kernel.org>, <linux-spi@vger.kernel.org>,
	<devicetree@vger.kernel.org>
Cc: <broonie@kernel.org>, <robh@kernel.org>,
	<krzysztof.kozlowski+dt@linaro.org>, <conor+dt@kernel.org>,
	<pthombar@cadence.com>, Piyush Malgujar <pmalgujar@marvell.com>,
	"Witold Sadowski" <wsadowski@marvell.com>
Subject: [PATCH v3 4/5] spi: cadence: Allow to read basic xSPI configuration from ACPI
Date: Wed, 17 Apr 2024 18:13:51 -0700	[thread overview]
Message-ID: <20240418011353.1764672-5-wsadowski@marvell.com> (raw)
In-Reply-To: <20240418011353.1764672-1-wsadowski@marvell.com>

From: Piyush Malgujar <pmalgujar@marvell.com>

These changes enables to read the configs from ACPI tables as required
for successful probing in ACPI uefi environment.
In case of ACPI disabled/dts based environment, it will continue to
read configs from dts as before

Signed-off-by: Piyush Malgujar <pmalgujar@marvell.com>
Signed-off-by: Witold Sadowski <wsadowski@marvell.com>
---
 drivers/spi/spi-cadence-xspi.c | 97 +++++++++++++++++++++++++++++++---
 1 file changed, 90 insertions(+), 7 deletions(-)

diff --git a/drivers/spi/spi-cadence-xspi.c b/drivers/spi/spi-cadence-xspi.c
index 5d36f9177f3c..e4ebfad8a1cb 100644
--- a/drivers/spi/spi-cadence-xspi.c
+++ b/drivers/spi/spi-cadence-xspi.c
@@ -2,6 +2,7 @@
 // Cadence XSPI flash controller driver
 // Copyright (C) 2020-21 Cadence
 
+#include <linux/acpi.h>
 #include <linux/completion.h>
 #include <linux/delay.h>
 #include <linux/err.h>
@@ -14,6 +15,7 @@
 #include <linux/of.h>
 #include <linux/platform_device.h>
 #include <linux/pm_runtime.h>
+#include <linux/property.h>
 #include <linux/spi/spi.h>
 #include <linux/spi/spi-mem.h>
 #include <linux/bitfield.h>
@@ -700,6 +702,67 @@ static int cdns_xspi_mem_op(struct cdns_xspi_dev *cdns_xspi,
 					   (dir != SPI_MEM_NO_DATA));
 }
 
+#ifdef CONFIG_ACPI
+static bool cdns_xspi_supports_op(struct spi_mem *mem,
+				  const struct spi_mem_op *op)
+{
+	struct spi_device *spi = mem->spi;
+	const union acpi_object *obj;
+	struct acpi_device *adev;
+
+	adev = ACPI_COMPANION(&spi->dev);
+
+	if (!acpi_dev_get_property(adev, "spi-tx-bus-width", ACPI_TYPE_INTEGER,
+				   &obj)) {
+		switch (obj->integer.value) {
+		case 1:
+			break;
+		case 2:
+			spi->mode |= SPI_TX_DUAL;
+			break;
+		case 4:
+			spi->mode |= SPI_TX_QUAD;
+			break;
+		case 8:
+			spi->mode |= SPI_TX_OCTAL;
+			break;
+		default:
+			dev_warn(&spi->dev,
+				 "spi-tx-bus-width %lld not supported\n",
+				 obj->integer.value);
+			break;
+		}
+	}
+
+	if (!acpi_dev_get_property(adev, "spi-rx-bus-width", ACPI_TYPE_INTEGER,
+				   &obj)) {
+		switch (obj->integer.value) {
+		case 1:
+			break;
+		case 2:
+			spi->mode |= SPI_RX_DUAL;
+			break;
+		case 4:
+			spi->mode |= SPI_RX_QUAD;
+			break;
+		case 8:
+			spi->mode |= SPI_RX_OCTAL;
+			break;
+		default:
+			dev_warn(&spi->dev,
+				 "spi-rx-bus-width %lld not supported\n",
+				 obj->integer.value);
+			break;
+		}
+	}
+
+	if (!spi_mem_default_supports_op(mem, op))
+		return false;
+
+	return true;
+}
+#endif
+
 static int cdns_xspi_mem_op_execute(struct spi_mem *mem,
 				    const struct spi_mem_op *op)
 {
@@ -723,6 +786,9 @@ static int cdns_xspi_adjust_mem_op_size(struct spi_mem *mem, struct spi_mem_op *
 }
 
 static const struct spi_controller_mem_ops cadence_xspi_mem_ops = {
+#ifdef CONFIG_ACPI
+	.supports_op = cdns_xspi_supports_op,
+#endif
 	.exec_op = cdns_xspi_mem_op_execute,
 	.adjust_op_size = cdns_xspi_adjust_mem_op_size,
 };
@@ -774,21 +840,20 @@ static irqreturn_t cdns_xspi_irq_handler(int this_irq, void *dev)
 
 static int cdns_xspi_of_get_plat_data(struct platform_device *pdev)
 {
-	struct device_node *node_prop = pdev->dev.of_node;
-	struct device_node *node_child;
+	struct fwnode_handle *fwnode_child;
 	unsigned int cs;
 
-	for_each_child_of_node(node_prop, node_child) {
-		if (!of_device_is_available(node_child))
+	device_for_each_child_node(&pdev->dev, fwnode_child) {
+		if (!fwnode_device_is_available(fwnode_child))
 			continue;
 
-		if (of_property_read_u32(node_child, "reg", &cs)) {
+		if (fwnode_property_read_u32(fwnode_child, "reg", &cs)) {
 			dev_err(&pdev->dev, "Couldn't get memory chip select\n");
-			of_node_put(node_child);
+			fwnode_handle_put(fwnode_child);
 			return -ENXIO;
 		} else if (cs >= CDNS_XSPI_MAX_BANKS) {
 			dev_err(&pdev->dev, "reg (cs) parameter value too large\n");
-			of_node_put(node_child);
+			fwnode_handle_put(fwnode_child);
 			return -ENXIO;
 		}
 	}
@@ -924,6 +989,21 @@ static int cdns_xspi_probe(struct platform_device *pdev)
 	return 0;
 }
 
+#ifdef CONFIG_ACPI
+static const struct acpi_device_id cdns_xspi_acpi_match[] = {
+	{
+		.id = "cdns,xspi-nor",
+		.driver_data = (kernel_ulong_t) &cdns_driver_data,
+	},
+	{
+		.id = "mrvl,xspi-nor",
+		.driver_data = (kernel_ulong_t) &mrvl_driver_data,
+	},
+	{},
+};
+MODULE_DEVICE_TABLE(acpi, cdns_xspi_acpi_match);
+#endif
+
 static const struct of_device_id cdns_xspi_of_match[] = {
 	{
 		.compatible = "cdns,xspi-nor",
@@ -942,6 +1022,9 @@ static struct platform_driver cdns_xspi_platform_driver = {
 	.driver = {
 		.name = CDNS_XSPI_NAME,
 		.of_match_table = cdns_xspi_of_match,
+#ifdef CONFIG_ACPI
+		.acpi_match_table = cdns_xspi_acpi_match,
+#endif
 	},
 };
 
-- 
2.43.0


  parent reply	other threads:[~2024-04-18  1:14 UTC|newest]

Thread overview: 39+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-29 19:48 [PATCH 0/5] Support for Cadence xSPI Marvell modifications Witold Sadowski
2024-03-29 19:48 ` [PATCH 1/5] spi: cadence: Add new bindings documentation for Cadence XSPI Witold Sadowski
2024-03-29 21:09   ` Rob Herring
2024-03-30 11:32   ` Krzysztof Kozlowski
2024-04-29  7:48     ` Krzysztof Kozlowski
2024-03-31 10:43   ` kernel test robot
2024-03-29 19:48 ` [PATCH 2/5] spi: cadence: Add Marvell IP modification changes Witold Sadowski
2024-03-30 11:33   ` Krzysztof Kozlowski
2024-04-29 14:55     ` [EXTERNAL] " Witold Sadowski
2024-04-30  7:56       ` Krzysztof Kozlowski
2024-03-31  7:46   ` kernel test robot
2024-03-31 10:50   ` Krzysztof Kozlowski
2024-03-29 19:48 ` [PATCH 3/5] spi: cadence: Force single modebyte Witold Sadowski
2024-03-29 19:48 ` [PATCH 4/5] driver: spi: cadence: Add ACPI support Witold Sadowski
2024-03-30 11:36   ` Krzysztof Kozlowski
2024-03-31  7:35   ` kernel test robot
2024-03-29 19:48 ` [PATCH 5/5] cadence-xspi: Add xfer capabilities Witold Sadowski
2024-03-30 11:37   ` Krzysztof Kozlowski
2024-03-31  3:25   ` kernel test robot
2024-04-18  1:13 ` [PATCH v3 0/5] Marvell HW overlay support for Cadence xSPI Witold Sadowski
2024-04-18  1:13   ` [PATCH v3 1/5] spi: cadence: Ensure data lines set to low during dummy-cycle period Witold Sadowski
2024-04-18  1:13   ` [PATCH v3 2/5] spi: cadence: Add MRVL overlay bindings documentation for Cadence XSPI Witold Sadowski
2024-04-18 16:22     ` Conor Dooley
2024-04-29 14:47       ` [EXTERNAL] " Witold Sadowski
2024-04-29 21:33         ` Conor Dooley
2024-04-29 22:59           ` Witold Sadowski
2024-04-30  7:58             ` Krzysztof Kozlowski
2024-04-18 17:48     ` Krzysztof Kozlowski
2024-04-29 14:35       ` [EXTERNAL] " Witold Sadowski
2024-04-18  1:13   ` [PATCH v3 3/5] spi: cadence: Add Marvell xSPI IP overlay changes Witold Sadowski
2024-04-18 19:36     ` kernel test robot
2024-04-18  1:13   ` Witold Sadowski [this message]
2024-04-18 17:51     ` [PATCH v3 4/5] spi: cadence: Allow to read basic xSPI configuration from ACPI Krzysztof Kozlowski
2024-04-29 14:30       ` [EXTERNAL] " Witold Sadowski
2024-04-30  8:00         ` Krzysztof Kozlowski
2024-05-08  8:04           ` Witold Sadowski
2024-05-08 11:46             ` Mark Brown
2024-05-09  1:07               ` Witold Sadowski
2024-04-18  1:13   ` [PATCH v3 5/5] spi: cadence: Add MRVL overlay xfer operation support Witold Sadowski

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=20240418011353.1764672-5-wsadowski@marvell.com \
    --to=wsadowski@marvell.com \
    --cc=broonie@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=krzysztof.kozlowski+dt@linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-spi@vger.kernel.org \
    --cc=pmalgujar@marvell.com \
    --cc=pthombar@cadence.com \
    --cc=robh@kernel.org \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.