Skip to contentSkip to conversation

spi: mt7621: Move SPI driver out of staging

PATCH Superseded Stefan Roese 2 participants 4 messages Mar 14, 2019 – Mar 25, 2019

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 spi: mt7621: Move SPI driver out of staging

This patch moves the MT7621 SPI driver, which is used on some Ralink / MediaTek MT76xx MIPS SoC's, out of the staging directory. No changes to the source code are done in this patch.

This driver version was tested successfully on an MT7688 based platform with an SPI NOR on CS0 and an SPI NAND on CS1 without any issues (so far).

This patch also documents the devicetree bindings for the MT7621 SPI device driver.

Cc Rob Herring <[email protected]>
Cc Mark Brown <[email protected]>
Cc Greg Kroah-Hartman <[email protected]>
Cc NeilBrown <[email protected]>
Cc Sankalp Negi <[email protected]>
Cc Chuanhong Guo <[email protected]>
Cc John Crispin <[email protected]>
Cc Armando Miraglia <[email protected]>
---
 .../devicetree/bindings/spi/spi-mt7621.txt    |  26 ++
 drivers/spi/Kconfig                           |   6 +
 drivers/spi/Makefile                          |   1 +
 drivers/spi/spi-mt7621.c                      | 422 ++++++++++++++++++
 drivers/staging/Kconfig                       |   2 -
 drivers/staging/Makefile                      |   1 -
 drivers/staging/mt7621-spi/Kconfig            |   6 -
 drivers/staging/mt7621-spi/Makefile           |   1 -
 drivers/staging/mt7621-spi/TODO               |   5 -
 drivers/staging/mt7621-spi/spi-mt7621.c       | 422 ------------------
 10 files changed, 455 insertions(+), 437 deletions(-)
 create mode 100644 Documentation/devicetree/bindings/spi/spi-mt7621.txt
 create mode 100644 drivers/spi/spi-mt7621.c
 delete mode 100644 drivers/staging/mt7621-spi/Kconfig
 delete mode 100644 drivers/staging/mt7621-spi/Makefile
 delete mode 100644 drivers/staging/mt7621-spi/TODO
 delete mode 100644 drivers/staging/mt7621-spi/spi-mt7621.c
Documentation/devicetree/bindings/spi/spi-mt7621.txt new file +26 -0
new file mode 100644
index 000000000000..d5baec0fa56e
@@ -0,0 +1,26 @@
+Binding for MTK SPI controller (MT7621 MIPS)
+
+Required properties:
+- compatible: Should be one of the following:
+  - "ralink,mt7621-spi": for mt7621/mt7628/mt7688 platforms
+- #address-cells: should be 1.
+- #size-cells: should be 0.
+- reg: Address and length of the register set for the device
+- resets: phandle to the reset controller asserting this device in
+          reset
+  See ../reset/reset.txt for details.
+
+Optional properties:
+- cs-gpios: see spi-bus.txt.
+
+Example:
+
+- SoC Specific Portion:
+spi0: spi@b00 {
+	compatible = "ralink,mt7621-spi";
+	reg = <0xb00 0x100>;
+	#address-cells = <1>;
+	#size-cells = <0>;
+	resets = <&rstctrl 18>;
+	reset-names = "spi";
+};
drivers/spi/Kconfig +6 -0
index f761655e2a36..202952f9da56 100644
@@ -426,6 +426,12 @@ config SPI_MT65XX
 	  say Y or M here.If you are not sure, say N.
 	  SPI drivers for Mediatek MT65XX and MT81XX series ARM SoCs.
 
+config SPI_MT7621
+	tristate "MediaTek MT7621 SPI Controller"
+	depends on RALINK
+	help
+	  This selects a driver for the MediaTek MT7621 SPI Controller.
+
 config SPI_NPCM_PSPI
 	tristate "Nuvoton NPCM PSPI Controller"
 	depends on ARCH_NPCM || COMPILE_TEST
drivers/spi/Makefile +1 -0
index d8fc03c9faa2..369f29a8a6af 100644
@@ -60,6 +60,7 @@ obj-$(CONFIG_SPI_MPC512x_PSC)		+= spi-mpc512x-psc.o
 obj-$(CONFIG_SPI_MPC52xx_PSC)		+= spi-mpc52xx-psc.o
 obj-$(CONFIG_SPI_MPC52xx)		+= spi-mpc52xx.o
 obj-$(CONFIG_SPI_MT65XX)                += spi-mt65xx.o
+obj-$(CONFIG_SPI_MT7621)		+= spi-mt7621.o
 obj-$(CONFIG_SPI_MXIC)			+= spi-mxic.o
 obj-$(CONFIG_SPI_MXS)			+= spi-mxs.o
 obj-$(CONFIG_SPI_NPCM_PSPI)		+= spi-npcm-pspi.o
drivers/spi/spi-mt7621.c new file +422 -0

422 lines not on this page · raw message

drivers/staging/Kconfig +0 -2
index c0901b96cfe4..3241bd50d139 100644
@@ -106,8 +106,6 @@ source "drivers/staging/mt7621-pci-phy/Kconfig"
 
 source "drivers/staging/mt7621-pinctrl/Kconfig"
 
-source "drivers/staging/mt7621-spi/Kconfig"
-
 source "drivers/staging/mt7621-dma/Kconfig"
 
 source "drivers/staging/ralink-gdma/Kconfig"
drivers/staging/Makefile +0 -1
index 57c6bce13ff4..296ff11ecfae 100644
@@ -43,7 +43,6 @@ obj-$(CONFIG_PI433)		+= pi433/
 obj-$(CONFIG_PCI_MT7621)	+= mt7621-pci/
 obj-$(CONFIG_PCI_MT7621_PHY)	+= mt7621-pci-phy/
 obj-$(CONFIG_PINCTRL_RT2880)	+= mt7621-pinctrl/
-obj-$(CONFIG_SPI_MT7621)	+= mt7621-spi/
 obj-$(CONFIG_SOC_MT7621)	+= mt7621-dma/
 obj-$(CONFIG_DMA_RALINK)	+= ralink-gdma/
 obj-$(CONFIG_MTK_MMC)		+= mt7621-mmc/
drivers/staging/mt7621-spi/Kconfig deleted +0 -6
deleted file mode 100644
index 0b90f4cfa426..000000000000
@@ -1,6 +0,0 @@
-config SPI_MT7621
-	tristate "MediaTek MT7621 SPI Controller"
-	depends on RALINK
-	help
-	  This selects a driver for the MediaTek MT7621 SPI Controller.
-
drivers/staging/mt7621-spi/Makefile deleted +0 -1
deleted file mode 100644
index 3be508f63bac..000000000000
@@ -1 +0,0 @@
-obj-$(CONFIG_SPI_MT7621)		+= spi-mt7621.o
drivers/staging/mt7621-spi/TODO deleted +0 -5
deleted file mode 100644
index fdbc5002c32a..000000000000
@@ -1,5 +0,0 @@
-
-- general code review and clean up
-- ensure device-tree requirements are documented
-
-Cc: NeilBrown <[email protected]>
drivers/staging/mt7621-spi/spi-mt7621.c deleted +0 -422

422 lines not on this page · raw message

Signature · 1 line
2.21.0
maintainer
#1 lore raw

On Thu, Mar 14, 2019 at 12:52:12PM +0100, Stefan Roese wrote:

This looks pretty good, a few trivial issues below but nothing major I think.

drivers/spi/Kconfig config SPI_MT65XX · line 434

Quoted 6 lines
drivers/spi/Kconfig +6 -0
+config SPI_MT7621
+	tristate "MediaTek MT7621 SPI Controller"
+	depends on RALINK
+	help
+	  This selects a driver for the MediaTek MT7621 SPI Controller.
+

I'm not seeing any build time dependency on this, please add an || COMPILE_TEST to help with build testing.

drivers/spi/spi-mt7621.c line 4

Quoted 5 lines
drivers/spi/spi-mt7621.c new file +4 -0
@@ -0,0 +1,422 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * spi-mt7621.c -- MediaTek MT7621 SPI controller driver
+ *

Please make the entire comment a C++ one to

drivers/spi/spi-mt7621.c line 11

Quoted 3 lines
drivers/spi/spi-mt7621.c new file +3 -0
+ * Some parts are based on spi-orion.c:
+ *   Author: Shadi Ammouri <[email protected]>
+ *   Copyright (C) 2007-2008 Marvell Ltd.

That driver dates from 2008 AFAICT, and had some changes after then?

drivers/spi/spi-mt7621.c line 106

Quoted 11 lines
drivers/spi/spi-mt7621.c new file +11 -0
+static void mt7621_spi_set_cs(struct spi_device *spi, int enable)
+{
+	struct mt7621_spi *rs = spidev_to_mt7621_spi(spi);
+	int cs = spi->chip_select;
+	u32 polar = 0;
+
+	mt7621_spi_reset(rs);
+	if (enable)
+		polar = BIT(cs);
+	mt7621_spi_write(rs, MT7621_SPI_POLAR, polar);
+}

Will doing a reset mess up the rate configuration and stuff that's done in _prepare(), or is _reset() perhaps not an entirely accurate name?

drivers/spi/spi-mt7621.c line 264

Quoted 3 lines
drivers/spi/spi-mt7621.c new file +3 -0
+	list_for_each_entry(t, &m->transfers, transfer_list)
+		if (t->speed_hz < speed)
+			speed = t->speed_hz;

This should be in the core if it's needed, it's going to be the same for all drivers.

drivers/spi/spi-mt7621.c line 369

Quoted 5 lines
drivers/spi/spi-mt7621.c new file +5 -0
+	master->setup = mt7621_spi_setup;
+	master->transfer_one_message = mt7621_spi_transfer_one_message;
+	master->bits_per_word_mask = SPI_BPW_MASK(8);
+	master->dev.of_node = pdev->dev.of_node;
+	master->num_chipselect = 2;

The driver should set SPI_CONTROLLER_HALF_DUPLEX in flags.

drivers/spi/spi-mt7621.c line 401

Quoted 1 line
drivers/spi/spi-mt7621.c new file +1 -0
+	clk_disable(rs->clk);

This needs to be clk_disable_unprepare() to ensure the clock is unprepared as well as disabled.

drivers/spi/spi-mt7621.c line 402

Quoted 1 line
drivers/spi/spi-mt7621.c new file +1 -0
+	spi_unregister_master(master);

Just use devm_spi_register_controller()? The _master() name is legacy and devm_ would make life easier.

_______________________________________________
devel mailing list
[email protected]
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

#2 lore raw
Quoted 5 lines · Mark Brown

On Thu, Mar 14, 2019 at 12:52:12PM +0100, Stefan Roese wrote:

This looks pretty good, a few trivial issues below but nothing major I think.

Quoted 9 lines

drivers/spi/Kconfig config SPI_MT65XX · line 434

Quoted 6 lines
drivers/spi/Kconfig +6 -0
+config SPI_MT7621
+	tristate "MediaTek MT7621 SPI Controller"
+	depends on RALINK
+	help
+	  This selects a driver for the MediaTek MT7621 SPI Controller.
+

I'm not seeing any build time dependency on this, please add an || COMPILE_TEST to help with build testing.

Okay, will add in v2.

Quoted 7 lines

drivers/spi/spi-mt7621.c line 4

Quoted 5 lines
drivers/spi/spi-mt7621.c new file +4 -0
@@ -0,0 +1,422 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * spi-mt7621.c -- MediaTek MT7621 SPI controller driver
+ *

Please make the entire comment a C++ one to

Will change in v2.

Quoted 5 lines

drivers/spi/spi-mt7621.c line 11

Quoted 3 lines
drivers/spi/spi-mt7621.c new file +3 -0
+ * Some parts are based on spi-orion.c:
+ *   Author: Shadi Ammouri <[email protected]>
+ *   Copyright (C) 2007-2008 Marvell Ltd.

That driver dates from 2008 AFAICT, and had some changes after then?

The spi-orion driver? I didn't check. That's what in the header of this driver since quite some time. And I didn't want to change any copyright notices.

BTW: spi-orion still has the same copyright message.

Quoted 6 lines
Quoted 6 lines
drivers/spi/spi-mt7621.c new file +6 -0
+static void mt7621_spi_set_cs(struct spi_device *spi, int enable)
+{
+	struct mt7621_spi *rs = spidev_to_mt7621_spi(spi);
+	int cs = spi->chip_select;
+	u32 polar = 0;
+
Quoted 8 lines

drivers/spi/spi-mt7621.c line 106

Quoted 5 lines
drivers/spi/spi-mt7621.c new file +5 -0
+	mt7621_spi_reset(rs);
+	if (enable)
+		polar = BIT(cs);
+	mt7621_spi_write(rs, MT7621_SPI_POLAR, polar);
+}

Will doing a reset mess up the rate configuration and stuff that's done in _prepare(), or is _reset() perhaps not an entirely accurate name?

You are correct. The function name is not really matching its implementation. Will change in v2.

Quoted 6 lines

drivers/spi/spi-mt7621.c line 264

Quoted 3 lines
drivers/spi/spi-mt7621.c new file +3 -0
+	list_for_each_entry(t, &m->transfers, transfer_list)
+		if (t->speed_hz < speed)
+			speed = t->speed_hz;

This should be in the core if it's needed, it's going to be the same for all drivers.

I'm not sure here, other drivers might set the speed individually for each "spi_transfer" entry. In this driver its set only once: before beginning to transfer all entries. So should I really move this into the core and set all speed_hz values to the minimum one of the list?

Quoted 7 lines

drivers/spi/spi-mt7621.c line 369

Quoted 5 lines
drivers/spi/spi-mt7621.c new file +5 -0
+	master->setup = mt7621_spi_setup;
+	master->transfer_one_message = mt7621_spi_transfer_one_message;
+	master->bits_per_word_mask = SPI_BPW_MASK(8);
+	master->dev.of_node = pdev->dev.of_node;
+	master->num_chipselect = 2;

The driver should set SPI_CONTROLLER_HALF_DUPLEX in flags.

Will update in v2.

Quoted 4 lines

drivers/spi/spi-mt7621.c line 401

Quoted 1 line
drivers/spi/spi-mt7621.c new file +1 -0
+	clk_disable(rs->clk);

This needs to be clk_disable_unprepare() to ensure the clock is unprepared as well as disabled.

Okay, will change in v2.

Quoted 4 lines

drivers/spi/spi-mt7621.c line 402

Quoted 1 line
drivers/spi/spi-mt7621.c new file +1 -0
+	spi_unregister_master(master);

Just use devm_spi_register_controller()? The _master() name is legacy and devm_ would make life easier.

Yes, will change in v2.

Thanks for the review.

Thanks,
Stefan

maintainer
#3 lore raw
Quoted 9 lines · Stefan Roese
Quoted 6 lines · Mark Brown

drivers/spi/spi-mt7621.c line 264

Quoted 3 lines
drivers/spi/spi-mt7621.c new file +3 -0
+	list_for_each_entry(t, &m->transfers, transfer_list)
+		if (t->speed_hz < speed)
+			speed = t->speed_hz;

This should be in the core if it's needed, it's going to be the same for all drivers.

Quoted 4 lines

I'm not sure here, other drivers might set the speed individually for each "spi_transfer" entry. In this driver its set only once: before beginning to transfer all entries. So should I really move this into the core and set all speed_hz values to the minimum one of the list?

Oh, I see what it's doing... the driver should really be setting the speed per transfer, though in practice I'm not convinced that anything ever varies within a single message.

_______________________________________________
devel mailing list
[email protected]
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel