linux-spi.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Raju Rangoju <Raju.Rangoju@amd.com>
To: <broonie@kernel.org>, <linux-spi@vger.kernel.org>,
	<linux-kernel@vger.kernel.org>
Cc: <Raju.Rangoju@amd.com>, <krishnamoorthi.m@amd.com>,
	<akshata.mukundshetty@amd.com>
Subject: [PATCH 03/10] spi: espi_amd: Add eSPI get config IOCTL command
Date: Fri, 14 Mar 2025 00:04:33 +0530	[thread overview]
Message-ID: <20250313183440.261872-4-Raju.Rangoju@amd.com> (raw)
In-Reply-To: <20250313183440.261872-1-Raju.Rangoju@amd.com>

This patch introduces an IOCTL command to retrieve the configuration of
the eSPI controller and eSPI slave0. The configuration parameters include
the frequency, channel, and IO mode.

Co-developed-by: Krishnamoorthi M <krishnamoorthi.m@amd.com>
Signed-off-by: Krishnamoorthi M <krishnamoorthi.m@amd.com>
Co-developed-by: Akshata MukundShetty <akshata.mukundshetty@amd.com>
Signed-off-by: Akshata MukundShetty <akshata.mukundshetty@amd.com>
Signed-off-by: Raju Rangoju <Raju.Rangoju@amd.com>
---
 drivers/spi/espi-amd-dev.c | 69 ++++++++++++++++++++++++++++++++++++++
 drivers/spi/espi-amd.h     |  1 +
 2 files changed, 70 insertions(+)

diff --git a/drivers/spi/espi-amd-dev.c b/drivers/spi/espi-amd-dev.c
index 5f25ad2b1eef..79224f4f86fa 100644
--- a/drivers/spi/espi-amd-dev.c
+++ b/drivers/spi/espi-amd-dev.c
@@ -100,6 +100,72 @@ static int amd_espi_ioctl_set_conf(struct amd_espi *amd_espi, unsigned long arg)
 	return ret;
 }
 
+static int amd_espi_ioctl_get_conf(struct amd_espi *amd_espi, unsigned long arg)
+{
+	u32 op_freq, io_mode, slave_conf;
+	struct config *config;
+	int ret;
+
+	config = kzalloc(sizeof(*config), GFP_KERNEL);
+	if (!config)
+		return -ENOMEM;
+
+	ret = amd_espi_get_general_config(amd_espi, &slave_conf);
+	if (ret != CB_SUCCESS)
+		goto get_config_free;
+
+	/* Get IO mode configuration */
+	io_mode = (slave_conf & GENMASK(27, 26)) >> ESPI_SLAVE_IO_MODE_SEL_SHIFT;
+	switch (io_mode) {
+	case IO_MODE_SINGLE:
+	case IO_MODE_DUAL:
+	case IO_MODE_QUAD:
+		config->io_mode = io_mode;
+		break;
+	default:
+		dev_err(amd_espi->dev, "Invalid IO mode\n");
+		ret = -EOPNOTSUPP;
+		goto get_config_free;
+	}
+
+	/* Get operating frequency configuration */
+	op_freq = (slave_conf & GENMASK(22, 20)) >> ESPI_SLAVE_OP_FREQ_SEL_SHIFT;
+	switch (op_freq) {
+	case SLAVE_OP_FREQ_16:
+	case SLAVE_OP_FREQ_33:
+	case SLAVE_OP_FREQ_66:
+		config->op_freq = op_freq;
+		break;
+	default:
+		dev_err(amd_espi->dev, "Invalid operating frequency\n");
+		ret = -EOPNOTSUPP;
+		goto get_config_free;
+	}
+
+	/* Get channel configuration */
+	ret = amd_espi_get_channel_config(amd_espi);
+	config->channel_mode = 0;
+
+	if (ret == -EOPNOTSUPP) {
+		config->channel_mode = CHAN_NOT_ENABLED;
+	} else {
+		if (ret & CHANNEL_MODE_PC)
+			config->channel_mode |= CHANNEL_MODE_PC;
+		if (ret & CHANNEL_MODE_VW)
+			config->channel_mode |= CHANNEL_MODE_VW;
+	}
+
+	if (copy_to_user((void __user *)arg, config, sizeof(struct config))) {
+		ret = -EFAULT;
+		goto get_config_free;
+	}
+	ret = 0;
+
+get_config_free:
+	kfree(config);
+	return ret;
+}
+
 static long amd_espi_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
 {
 	struct amd_espi *amd_espi = filp->private_data;
@@ -113,6 +179,9 @@ static long amd_espi_ioctl(struct file *filp, unsigned int cmd, unsigned long ar
 	case ESPI_SET_CONFIG:
 		ret = amd_espi_ioctl_set_conf(amd_espi, arg);
 		break;
+	case ESPI_GET_CONFIG:
+		ret = amd_espi_ioctl_get_conf(amd_espi, arg);
+		break;
 	default:
 		dev_err(amd_espi->dev, "ESPI command not found, returning error\n");
 		ret = -EINVAL;
diff --git a/drivers/spi/espi-amd.h b/drivers/spi/espi-amd.h
index 1de53426059b..bc15f7417c37 100644
--- a/drivers/spi/espi-amd.h
+++ b/drivers/spi/espi-amd.h
@@ -141,6 +141,7 @@
 /* IOCTL calls */
 #define ESPI_MAGIC_NUMBER            'i'
 #define ESPI_SET_CONFIG              _IOW(ESPI_MAGIC_NUMBER, 0x1, struct config)
+#define ESPI_GET_CONFIG              _IOR(ESPI_MAGIC_NUMBER, 0x2, struct config)
 
 /*
  * enum amd_espi_versions - eSPI controller versions
-- 
2.34.1


  parent reply	other threads:[~2025-03-13 18:35 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-03-13 18:34 [PATCH 00/10] spi: Add driver to support AMD eSPI controller Raju Rangoju
2025-03-13 18:34 ` [PATCH 01/10] spi: espi_amd: Add AMD eSPI controller driver support Raju Rangoju
2025-03-17 14:06   ` Mark Brown
2025-03-26 10:00     ` Rangoju, Raju
2025-03-13 18:34 ` [PATCH 02/10] spi: espi_amd: Add eSPI set config IOCTL command Raju Rangoju
2025-03-17 14:07   ` Mark Brown
2025-03-26 10:03     ` Rangoju, Raju
2025-03-13 18:34 ` Raju Rangoju [this message]
2025-03-13 18:34 ` [PATCH 04/10] spi: espi_amd: Add eSPI inband-reset " Raju Rangoju
2025-03-13 18:34 ` [PATCH 05/10] spi: espi_amd: Add eSPI set IO mode " Raju Rangoju
2025-03-13 18:34 ` [PATCH 06/10] spi: espi_amd: Add eSPI set channel " Raju Rangoju
2025-03-13 18:34 ` [PATCH 07/10] spi: espi_amd: Add eSPI set frequency " Raju Rangoju
2025-03-13 18:34 ` [PATCH 08/10] spi: espi_amd: Add support for IO/MMIO configuration Raju Rangoju
2025-03-17 14:10   ` Mark Brown
2025-03-26 10:12     ` Rangoju, Raju
2025-03-13 18:34 ` [PATCH 09/10] spi: espi_amd: Add eSPI PC channel IO read/write IOCTL commands Raju Rangoju
2025-03-13 18:34 ` [PATCH 10/10] spi: espi_amd: Add eSPI PC channel MMIO " Raju Rangoju
2025-03-17 14:14 ` [PATCH 00/10] spi: Add driver to support AMD eSPI controller Mark Brown
2025-03-26  9:55   ` Rangoju, Raju
2025-03-26 11:05     ` Mark Brown
2025-04-02 11:43       ` Rangoju, Raju

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=20250313183440.261872-4-Raju.Rangoju@amd.com \
    --to=raju.rangoju@amd.com \
    --cc=akshata.mukundshetty@amd.com \
    --cc=broonie@kernel.org \
    --cc=krishnamoorthi.m@amd.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-spi@vger.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).