Skip to contentSkip to conversation

spi: microchip: pci1xxxx: Load SPI driver for SPI endpoint of PCI1XXXX switch

PATCH In review Tharun Kumar P 2 participants 8 messages Oct 6, 2022 – Nov 29, 2022 SPI

lore
Share & tools
lore
#0 lore raw

v2 cover spi: microchip: pci1xxxx: Load SPI driver for SPI endpoint of PCI1XXXX switch

Microchip PCI1XXXX is an unmanaged PCIe3.1a switch for consumer, industrial, and automotive applications. This switch has multiple downstream ports. One of the switch's downstream ports is a multifunction endpoint; one of those functions supports SPI functionality. This series of patches provides the SPI controller driver for the SPI function of the multifunction PCIe endpoint of the switch.

RFC -> V2:
- Added logic to handle chip select disable case
- Set SPI_MASTER_MUST_TX flag
- Added logic to ensure current transaction is complete before suspending

Tharun Kumar P (2):
spi: microchip: pci1xxxx: Add driver for SPI controller of PCI1XXXX
PCIe switch
spi: microchip: pci1xxxx: Add suspend and resume support for PCI1XXXX
SPI driver

 drivers/spi/Kconfig        |   9 +
 drivers/spi/Makefile       |   1 +
 drivers/spi/spi-pci1xxxx.c | 475 +++++++++++++++++++++++++++++++++++++
 3 files changed, 485 insertions(+)
 create mode 100644 drivers/spi/spi-pci1xxxx.c
Signature · 1 line
2.25.1
#1 lore raw

PATCH v2 1/2 spi: microchip: pci1xxxx: Add driver for SPI controller of PCI1XXXX PCIe switch

Microchip pci1xxxx is a PCIe switch with a multi-function endpoint on one of its downstream ports. SPI is one of the functions in the multi-function endpoint. This function has 2 SPI masters, operates at a maximum frequency of 30 MHz and supports 7 client devices per master. This patch adds complete functionality to the SPI function except for suspend and resume.

---
 drivers/spi/Kconfig        |   9 +
 drivers/spi/Makefile       |   1 +
 drivers/spi/spi-pci1xxxx.c | 397 +++++++++++++++++++++++++++++++++++++
 3 files changed, 407 insertions(+)
 create mode 100644 drivers/spi/spi-pci1xxxx.c
drivers/spi/Kconfig +9 -0
index 9987c3f2bd1c..08ca811440f9 100644
@@ -701,6 +701,15 @@ config SPI_ORION
 	  This enables using the SPI master controller on the Orion
 	  and MVEBU chips.
 
+config SPI_PCI1XXXX
+	tristate "PCI1XXXX SPI Bus support"
+	depends on PCI
+	help
+	  Say "yes" to Enable the SPI Bus support for the PCI1xxxx card
+	  This is a PCI to SPI Bus driver
+	  This driver can be built as module. If so, the module will be
+	  called as spi-pci1xxxx.
+
 config SPI_PIC32
 	tristate "Microchip PIC32 series SPI"
 	depends on MACH_PIC32 || COMPILE_TEST
drivers/spi/Makefile +1 -0
index 15d2f3835e45..b75fa3988f96 100644
@@ -93,6 +93,7 @@ obj-$(CONFIG_SPI_OMAP_100K)		+= spi-omap-100k.o
 obj-$(CONFIG_SPI_OMAP24XX)		+= spi-omap2-mcspi.o
 obj-$(CONFIG_SPI_TI_QSPI)		+= spi-ti-qspi.o
 obj-$(CONFIG_SPI_ORION)			+= spi-orion.o
+obj-$(CONFIG_SPI_PCI1XXXX)		+= spi-pci1xxxx.o
 obj-$(CONFIG_SPI_PIC32)			+= spi-pic32.o
 obj-$(CONFIG_SPI_PIC32_SQI)		+= spi-pic32-sqi.o
 obj-$(CONFIG_SPI_PL022)			+= spi-pl022.o
drivers/spi/spi-pci1xxxx.c new file +397 -0

397 lines not on this page · raw message

Signature · 1 line
2.25.1
#2 lore raw

PATCH v2 2/2 spi: microchip: pci1xxxx: Add suspend and resume support for PCI1XXXX SPI driver

In reply to Tharun Kumar P

Implement suspend, resume callbacks, store config at suspend and restore config at time of resume

---
 drivers/spi/spi-pci1xxxx.c | 78 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 78 insertions(+)
drivers/spi/spi-pci1xxxx.c +78 -0
index 958503a4d911..a31c3b612a43 100644
@@ -57,6 +57,9 @@
 #define SPI_CHIP_SEL_COUNT 7
 #define VENDOR_ID_MCHP 0x1055
 
+#define SPI_SUSPEND_CONFIG 0x101
+#define SPI_RESUME_CONFIG 0x303
+
 struct pci1xxxx_spi_internal {
 	u8 hw_inst;
 	bool spi_xfer_in_progress;
@@ -383,10 +386,85 @@ static int pci1xxxx_spi_probe(struct pci_dev *pdev, const struct pci_device_id *
 	return ret;
 }
 
+static void store_restore_config(struct pci1xxxx_spi *spi_ptr,
+				 struct pci1xxxx_spi_internal *spi_sub_ptr,
+				 u8 inst, bool store)
+{
+	u32 regval;
+
+	if (store) {
+		regval = readl(spi_ptr->reg_base +
+			       SPI_MST_CTL_REG_OFFSET(spi_sub_ptr->hw_inst));
+		regval &= SPI_MST_CTL_DEVSEL_MASK;
+		spi_sub_ptr->prev_val.dev_sel = (regval >> 25) & 7;
+		regval = readl(spi_ptr->reg_base +
+			       SPI_PCI_CTRL_REG_OFFSET(spi_sub_ptr->hw_inst));
+		regval &= SPI_MSI_VECTOR_SEL_MASK;
+		spi_sub_ptr->prev_val.msi_vector_sel = (regval >> 4) & 1;
+	} else {
+		regval = readl(spi_ptr->reg_base + SPI_MST_CTL_REG_OFFSET(inst));
+		regval &= ~SPI_MST_CTL_DEVSEL_MASK;
+		regval |= (spi_sub_ptr->prev_val.dev_sel << 25);
+		writel(regval,
+		       spi_ptr->reg_base + SPI_MST_CTL_REG_OFFSET(inst));
+		writel((spi_sub_ptr->prev_val.msi_vector_sel << 4),
+			spi_ptr->reg_base + SPI_PCI_CTRL_REG_OFFSET(inst));
+	}
+}
+
+static int pci1xxxx_spi_resume(struct device *dev)
+{
+	struct pci1xxxx_spi *spi_ptr = dev_get_drvdata(dev);
+	struct pci1xxxx_spi_internal *spi_sub_ptr;
+	u32 regval = SPI_RESUME_CONFIG;
+	u8 iter;
+
+	for (iter = 0; iter < spi_ptr->total_hw_instances; iter++) {
+		spi_sub_ptr = spi_ptr->spi_int[iter];
+		spi_master_resume(spi_sub_ptr->spi_host);
+		writel(regval, spi_ptr->reg_base +
+		       SPI_MST_EVENT_MASK_REG_OFFSET(iter));
+
+		/* Restore config at resume */
+		store_restore_config(spi_ptr, spi_sub_ptr, iter, 0);
+	}
+
+	return 0;
+}
+
+static int pci1xxxx_spi_suspend(struct device *dev)
+{
+	struct pci1xxxx_spi *spi_ptr = dev_get_drvdata(dev);
+	struct pci1xxxx_spi_internal *spi_sub_ptr;
+	u32 reg1 = SPI_SUSPEND_CONFIG;
+	u8 iter;
+
+	for (iter = 0; iter < spi_ptr->total_hw_instances; iter++) {
+		spi_sub_ptr = spi_ptr->spi_int[iter];
+
+		while (spi_sub_ptr->spi_xfer_in_progress)
+			msleep(20);
+
+		/* Store existing config before suspend */
+		store_restore_config(spi_ptr, spi_sub_ptr, iter, 1);
+		spi_master_suspend(spi_sub_ptr->spi_host);
+		writel(reg1, spi_ptr->reg_base +
+		       SPI_MST_EVENT_MASK_REG_OFFSET(iter));
+	}
+
+	return 0;
+}
+
+static DEFINE_SIMPLE_DEV_PM_OPS(spi_pm_ops, pci1xxxx_spi_suspend,
+				pci1xxxx_spi_resume);
+
 static struct pci_driver pci1xxxx_spi_driver = {
 	.name		= DRV_NAME,
 	.id_table	= pci1xxxx_spi_pci_id_table,
 	.probe		= pci1xxxx_spi_probe,
+	.driver		=	{
+		.pm = pm_sleep_ptr(&spi_pm_ops),
+	},
 };
 
 module_pci_driver(pci1xxxx_spi_driver);
Signature · 1 line
2.25.1
maintainer
#3 lore raw

Re: [PATCH v2 SPI for-next 2/2] spi: microchip: pci1xxxx: Add suspend and resume support for PCI1XXXX SPI driver

Quoted 9 lines · Tharun Kumar P
drivers/spi/spi-pci1xxxx.c +9 -0
+static int pci1xxxx_spi_resume(struct device *dev)
+{
+	struct pci1xxxx_spi *spi_ptr = dev_get_drvdata(dev);
+	struct pci1xxxx_spi_internal *spi_sub_ptr;
+	u32 regval = SPI_RESUME_CONFIG;
+	u8 iter;
+
+	for (iter = 0; iter < spi_ptr->total_hw_instances; iter++) {
+		spi_sub_ptr = spi_ptr->spi_int[iter];

drivers/spi/spi-pci1xxxx.c static int pci1xxxx_spi_probe(struct pci_dev *pdev, const struct pci_device_id * · line 433

Quoted 10 lines
drivers/spi/spi-pci1xxxx.c +10 -0
+		spi_master_resume(spi_sub_ptr->spi_host);
+		writel(regval, spi_ptr->reg_base +
+		       SPI_MST_EVENT_MASK_REG_OFFSET(iter));
+
+		/* Restore config at resume */
+		store_restore_config(spi_ptr, spi_sub_ptr, iter, 0);
+	}
+
+	return 0;
+}

There should be a call to spi_controller_suspend() in here (and similarly in resume) to tell the controller to stop the queue of operations.

#4 lore raw

Re: [PATCH v2 SPI for-next 2/2] spi: microchip: pci1xxxx: Add suspend and resume support for PCI1XXXX SPI driver

Quoted 3 lines · Mark Brown

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe
There should be a call to spi_controller_suspend() in here (and similarly in >

resume) to tell the controller to stop the queue of operations.

Okay, I will update code.

Thanks,
Tharun Kumar P

#5 lore raw

Re: [PATCH v2 SPI for-next 2/2] spi: microchip: pci1xxxx: Add suspend and resume support for PCI1XXXX SPI driver

In reply to Mark Brown
Quoted 5 lines · Mark Brown

EXTERNAL EMAIL: Do not click links or open attachments unless you know the content is safe

There should be a call to spi_controller_suspend() in here (and similarly in resume) to tell the controller to stop the queue of operations.

In the suspend and resume callbacks, spi_master_suspend and spi_master_resume APIs are used which in turn calls spi_controller_suspend and spi_controller_resume APIs respectively.

Thanks,
Tharun Kumar P

maintainer
#6 lore raw

Re: (subset) [PATCH v2 SPI for-next 0/2] spi: microchip: pci1xxxx: Load SPI driver for SPI endpoint of PCI1XXXX switch

In reply to Tharun Kumar P
Quoted 8 lines · Tharun Kumar P

Microchip PCI1XXXX is an unmanaged PCIe3.1a switch for consumer, industrial, and automotive applications. This switch has multiple downstream ports. One of the switch's downstream ports is a multifunction endpoint; one of those functions supports SPI functionality. This series of patches provides the SPI controller driver for the SPI function of the multifunction PCIe endpoint of the switch.

[...]

Applied to

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

Thanks!

[1/2] spi: microchip: pci1xxxx: Add driver for SPI controller of PCI1XXXX PCIe switch

      commit: 1cc0cbea7167af524a7f7b2d0d2f19f7a324e807

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

maintainer
#7 lore raw
In reply to Tharun Kumar P
Quoted 8 lines · Tharun Kumar P

Microchip PCI1XXXX is an unmanaged PCIe3.1a switch for consumer, industrial, and automotive applications. This switch has multiple downstream ports. One of the switch's downstream ports is a multifunction endpoint; one of those functions supports SPI functionality. This series of patches provides the SPI controller driver for the SPI function of the multifunction PCIe endpoint of the switch.

[...]

Applied to

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

Thanks!

[1/2] spi: microchip: pci1xxxx: Add driver for SPI controller of PCI1XXXX PCIe switch
(no commit info)
[2/2] spi: microchip: pci1xxxx: Add suspend and resume support for PCI1XXXX SPI driver

      commit: 7ba63521a1e9d8ca6fb55ead19e6e2b850b8fd80

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