linux-staging.lists.linux.dev archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/10] staging: mt7621-pci: complete review
@ 2021-05-05 12:17 Sergio Paracuellos
  2021-05-05 12:17 ` [PATCH 01/10] staging: mt7621-pci: make use of kernel clock apis Sergio Paracuellos
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: Sergio Paracuellos @ 2021-05-05 12:17 UTC (permalink / raw)
  To: linux-staging; +Cc: gregkh, neil, ilya.lipnitskiy

This patchet contains different missing stuff to give this driver
a try to get mainlined into a proper place in the kernel:
- Make use of kernel clock apis.
- Avoid to request gpio mode since it is already being requested
through the pin control driver.
- Properly map interrupts using 'interrupt-map' and 'interrupt-map-mask'
device tree properties instead of using a custom 'map_irq' callback.
- Use msleep instead of mdelay in remaining places.
- Other minor cleanups.

After this changes, LOC decreased a bit which is always a good thing :-).

All of this has been tested in two different boards resulting in
a working platform:
 - GNUBee PC1
 - HiLink HLK-7621A Evaluation Board.

Best regards,
    Sergio Paracuellos

Sergio Paracuellos (10):
  staging: mt7621-pci: make use of kernel clock apis
  staging: mt7621-pci: avoid to set gpio mode in driver
  staging: mt7621-pci: remove some not needed includes
  staging: mt7621-pci: group io resource assignments all together
  staging: mt7621-pci: replace mdelay with msleep
  staging: mt7621-pci: directly return 'mt7621_pcie_register_host'
  staging: mt7621-pci: avoid custom 'map_irq' function
  staging: mt7621-pci: remove two blank lines
  staging: mt7621-dts: use 'interrupt-map' and 'interrupt-map-mask'
  staging: mt7621-dts: properly organize pcie node

 drivers/staging/mt7621-dts/mt7621.dtsi  |  34 ++++--
 drivers/staging/mt7621-pci/pci-mt7621.c | 154 +++++-------------------
 2 files changed, 48 insertions(+), 140 deletions(-)

-- 
2.25.1


^ permalink raw reply	[flat|nested] 11+ messages in thread

* [PATCH 01/10] staging: mt7621-pci: make use of kernel clock apis
  2021-05-05 12:17 [PATCH 00/10] staging: mt7621-pci: complete review Sergio Paracuellos
@ 2021-05-05 12:17 ` Sergio Paracuellos
  2021-05-05 12:17 ` [PATCH 02/10] staging: mt7621-pci: avoid to set gpio mode in driver Sergio Paracuellos
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Sergio Paracuellos @ 2021-05-05 12:17 UTC (permalink / raw)
  To: linux-staging; +Cc: gregkh, neil, ilya.lipnitskiy

MT7621 SoC clock driver has already mainlined in 
'commit 48df7a26f470 ("clk: ralink: add clock driver for mt7621 SoC")'
Hence, we can make use of kernel clock apis and avoid to
directly set bits in clock gate related registers for pci.

Signed-off-by: Sergio Paracuellos <sergio.paracuellos@gmail.com>
---
 drivers/staging/mt7621-pci/pci-mt7621.c | 44 +++++++++++++++----------
 1 file changed, 26 insertions(+), 18 deletions(-)

diff --git a/drivers/staging/mt7621-pci/pci-mt7621.c b/drivers/staging/mt7621-pci/pci-mt7621.c
index 115250115f10..f490c7a1397d 100644
--- a/drivers/staging/mt7621-pci/pci-mt7621.c
+++ b/drivers/staging/mt7621-pci/pci-mt7621.c
@@ -16,6 +16,7 @@
  */
 
 #include <linux/bitops.h>
+#include <linux/clk.h>
 #include <linux/delay.h>
 #include <linux/gpio/consumer.h>
 #include <linux/iopoll.h>
@@ -43,9 +44,6 @@
 #define PCIE_FTS_NUM_MASK		GENMASK(15, 8)
 #define PCIE_FTS_NUM_L0(x)		(((x) & 0xff) << 8)
 
-/* rt_sysc_membase relative registers */
-#define RALINK_CLKCFG1			0x30
-
 /* Host-PCI bridge registers */
 #define RALINK_PCI_PCICFG_ADDR		0x0000
 #define RALINK_PCI_PCIMSK_ADDR		0x000C
@@ -79,7 +77,6 @@
 #define PCIE_BAR_MAP_MAX		GENMASK(30, 16)
 #define PCIE_BAR_ENABLE			BIT(0)
 #define PCIE_PORT_INT_EN(x)		BIT(20 + (x))
-#define PCIE_PORT_CLK_EN(x)		BIT(24 + (x))
 #define PCIE_PORT_LINKUP		BIT(0)
 
 #define PERST_MODE_MASK			GENMASK(11, 10)
@@ -91,6 +88,7 @@
  * @base: I/O mapped register base
  * @list: port list
  * @pcie: pointer to PCIe host info
+ * @clk: pointer to the port clock gate
  * @phy: pointer to PHY control block
  * @pcie_rst: pointer to port reset control
  * @gpio_rst: gpio reset
@@ -102,6 +100,7 @@ struct mt7621_pcie_port {
 	void __iomem *base;
 	struct list_head list;
 	struct mt7621_pcie *pcie;
+	struct clk *clk;
 	struct phy *phy;
 	struct reset_control *pcie_rst;
 	struct gpio_desc *gpio_rst;
@@ -222,16 +221,6 @@ static inline bool mt7621_pcie_port_is_linkup(struct mt7621_pcie_port *port)
 	return (pcie_port_read(port, RALINK_PCI_STATUS) & PCIE_PORT_LINKUP) != 0;
 }
 
-static inline void mt7621_pcie_port_clk_enable(struct mt7621_pcie_port *port)
-{
-	rt_sysc_m32(0, PCIE_PORT_CLK_EN(port->slot), RALINK_CLKCFG1);
-}
-
-static inline void mt7621_pcie_port_clk_disable(struct mt7621_pcie_port *port)
-{
-	rt_sysc_m32(PCIE_PORT_CLK_EN(port->slot), 0, RALINK_CLKCFG1);
-}
-
 static inline void mt7621_control_assert(struct mt7621_pcie_port *port)
 {
 	struct mt7621_pcie *pcie = port->pcie;
@@ -351,6 +340,13 @@ static int mt7621_pcie_parse_port(struct mt7621_pcie *pcie,
 	if (IS_ERR(port->base))
 		return PTR_ERR(port->base);
 
+	snprintf(name, sizeof(name), "pcie%d", slot);
+	port->clk = devm_clk_get(dev, name);
+	if (IS_ERR(port->clk)) {
+		dev_err(dev, "failed to get pcie%d clock\n", slot);
+		return PTR_ERR(port->clk);
+	}
+
 	snprintf(name, sizeof(name), "pcie%d", slot);
 	port->pcie_rst = devm_reset_control_get_exclusive(dev, name);
 	if (PTR_ERR(port->pcie_rst) == -EPROBE_DEFER) {
@@ -512,7 +508,7 @@ static void mt7621_pcie_init_ports(struct mt7621_pcie *pcie)
 			dev_err(dev, "pcie%d no card, disable it (RST & CLK)\n",
 				slot);
 			mt7621_control_assert(port);
-			mt7621_pcie_port_clk_disable(port);
+			clk_disable_unprepare(port->clk);
 			port->enabled = false;
 
 			if (slot == 0) {
@@ -547,13 +543,14 @@ static void mt7621_pcie_enable_port(struct mt7621_pcie_port *port)
 		   offset + RALINK_PCI_CLASS);
 }
 
-static void mt7621_pcie_enable_ports(struct mt7621_pcie *pcie)
+static int mt7621_pcie_enable_ports(struct mt7621_pcie *pcie)
 {
 	struct device *dev = pcie->dev;
 	struct mt7621_pcie_port *port;
 	u8 num_slots_enabled = 0;
 	u32 slot;
 	u32 val;
+	int err;
 
 	/* Setup MEMWIN and IOWIN */
 	pcie_write(pcie, 0xffffffff, RALINK_PCI_MEMBASE);
@@ -561,7 +558,12 @@ static void mt7621_pcie_enable_ports(struct mt7621_pcie *pcie)
 
 	list_for_each_entry(port, &pcie->ports, list) {
 		if (port->enabled) {
-			mt7621_pcie_port_clk_enable(port);
+			err = clk_prepare_enable(port->clk);
+			if (err) {
+				dev_err(dev, "enabling clk pcie%d\n", slot);
+				return err;
+			}
+
 			mt7621_pcie_enable_port(port);
 			dev_info(dev, "PCIE%d enabled\n", port->slot);
 			num_slots_enabled++;
@@ -578,6 +580,8 @@ static void mt7621_pcie_enable_ports(struct mt7621_pcie *pcie)
 		val |= PCIE_FTS_NUM_L0(0x50);
 		write_config(pcie, slot, PCIE_FTS_NUM, val);
 	}
+
+	return 0;
 }
 
 static int mt7621_pcie_init_virtual_bridges(struct mt7621_pcie *pcie)
@@ -694,7 +698,11 @@ static int mt7621_pci_probe(struct platform_device *pdev)
 		return 0;
 	}
 
-	mt7621_pcie_enable_ports(pcie);
+	err = mt7621_pcie_enable_ports(pcie);
+	if (err) {
+		dev_err(dev, "Error enabling pcie ports\n");
+		return err;
+	}
 
 	setup_cm_memory_region(pcie);
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 02/10] staging: mt7621-pci: avoid to set gpio mode in driver
  2021-05-05 12:17 [PATCH 00/10] staging: mt7621-pci: complete review Sergio Paracuellos
  2021-05-05 12:17 ` [PATCH 01/10] staging: mt7621-pci: make use of kernel clock apis Sergio Paracuellos
@ 2021-05-05 12:17 ` Sergio Paracuellos
  2021-05-05 12:17 ` [PATCH 03/10] staging: mt7621-pci: remove some not needed includes Sergio Paracuellos
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Sergio Paracuellos @ 2021-05-05 12:17 UTC (permalink / raw)
  To: linux-staging; +Cc: gregkh, neil, ilya.lipnitskiy

Gpio mode for the pcie pins must be request from device
tree using pinctrl driver. Pinctrl driver is already setting
this pcie pins as GPIO if it is requested. Hence, remove it
from here.

Signed-off-by: Sergio Paracuellos <sergio.paracuellos@gmail.com>
---
 drivers/staging/mt7621-pci/pci-mt7621.c | 7 -------
 1 file changed, 7 deletions(-)

diff --git a/drivers/staging/mt7621-pci/pci-mt7621.c b/drivers/staging/mt7621-pci/pci-mt7621.c
index f490c7a1397d..984e333408a0 100644
--- a/drivers/staging/mt7621-pci/pci-mt7621.c
+++ b/drivers/staging/mt7621-pci/pci-mt7621.c
@@ -36,9 +36,6 @@
 
 #include "../../pci/pci.h"
 
-/* sysctl */
-#define MT7621_GPIO_MODE		0x60
-
 /* MediaTek specific configuration registers */
 #define PCIE_FTS_NUM			0x70c
 #define PCIE_FTS_NUM_MASK		GENMASK(15, 8)
@@ -79,8 +76,6 @@
 #define PCIE_PORT_INT_EN(x)		BIT(20 + (x))
 #define PCIE_PORT_LINKUP		BIT(0)
 
-#define PERST_MODE_MASK			GENMASK(11, 10)
-#define PERST_MODE_GPIO			BIT(10)
 #define PERST_DELAY_MS			100
 
 /**
@@ -478,8 +473,6 @@ static void mt7621_pcie_init_ports(struct mt7621_pcie *pcie)
 	struct mt7621_pcie_port *port, *tmp;
 	int err;
 
-	rt_sysc_m32(PERST_MODE_MASK, PERST_MODE_GPIO, MT7621_GPIO_MODE);
-
 	mt7621_pcie_reset_assert(pcie);
 	mt7621_pcie_reset_rc_deassert(pcie);
 
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 03/10] staging: mt7621-pci: remove some not needed includes
  2021-05-05 12:17 [PATCH 00/10] staging: mt7621-pci: complete review Sergio Paracuellos
  2021-05-05 12:17 ` [PATCH 01/10] staging: mt7621-pci: make use of kernel clock apis Sergio Paracuellos
  2021-05-05 12:17 ` [PATCH 02/10] staging: mt7621-pci: avoid to set gpio mode in driver Sergio Paracuellos
@ 2021-05-05 12:17 ` Sergio Paracuellos
  2021-05-05 12:17 ` [PATCH 04/10] staging: mt7621-pci: group io resource assignments all together Sergio Paracuellos
                   ` (6 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Sergio Paracuellos @ 2021-05-05 12:17 UTC (permalink / raw)
  To: linux-staging; +Cc: gregkh, neil, ilya.lipnitskiy

Some includes used here are not really necessary for
the code to compile properly. Hence remove them.

Signed-off-by: Sergio Paracuellos <sergio.paracuellos@gmail.com>
---
 drivers/staging/mt7621-pci/pci-mt7621.c | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/drivers/staging/mt7621-pci/pci-mt7621.c b/drivers/staging/mt7621-pci/pci-mt7621.c
index 984e333408a0..1b3d6ba0b85a 100644
--- a/drivers/staging/mt7621-pci/pci-mt7621.c
+++ b/drivers/staging/mt7621-pci/pci-mt7621.c
@@ -19,7 +19,6 @@
 #include <linux/clk.h>
 #include <linux/delay.h>
 #include <linux/gpio/consumer.h>
-#include <linux/iopoll.h>
 #include <linux/module.h>
 #include <linux/of.h>
 #include <linux/of_address.h>
@@ -31,10 +30,6 @@
 #include <linux/platform_device.h>
 #include <linux/reset.h>
 #include <linux/sys_soc.h>
-#include <mt7621.h>
-#include <ralink_regs.h>
-
-#include "../../pci/pci.h"
 
 /* MediaTek specific configuration registers */
 #define PCIE_FTS_NUM			0x70c
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 04/10] staging: mt7621-pci: group io resource assignments all together
  2021-05-05 12:17 [PATCH 00/10] staging: mt7621-pci: complete review Sergio Paracuellos
                   ` (2 preceding siblings ...)
  2021-05-05 12:17 ` [PATCH 03/10] staging: mt7621-pci: remove some not needed includes Sergio Paracuellos
@ 2021-05-05 12:17 ` Sergio Paracuellos
  2021-05-05 12:17 ` [PATCH 05/10] staging: mt7621-pci: replace mdelay with msleep Sergio Paracuellos
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Sergio Paracuellos @ 2021-05-05 12:17 UTC (permalink / raw)
  To: linux-staging; +Cc: gregkh, neil, ilya.lipnitskiy

To improve a bit readabily group all the IO resource related
assignments together.

Signed-off-by: Sergio Paracuellos <sergio.paracuellos@gmail.com>
---
 drivers/staging/mt7621-pci/pci-mt7621.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/mt7621-pci/pci-mt7621.c b/drivers/staging/mt7621-pci/pci-mt7621.c
index 1b3d6ba0b85a..296f50fb3571 100644
--- a/drivers/staging/mt7621-pci/pci-mt7621.c
+++ b/drivers/staging/mt7621-pci/pci-mt7621.c
@@ -284,17 +284,17 @@ static int mt7621_pci_parse_request_of_pci_ranges(struct pci_host_bridge *host)
 	 * well for MIPS platforms that don't define PCI_IOBASE, so set the IO
 	 * resource manually instead.
 	 */
-	pcie->io.name = node->full_name;
-	pcie->io.parent = pcie->io.child = pcie->io.sibling = NULL;
 	for_each_of_pci_range(&parser, &range) {
 		switch (range.flags & IORESOURCE_TYPE_BITS) {
 		case IORESOURCE_IO:
 			pcie->io_map_base =
 				(unsigned long)ioremap(range.cpu_addr,
 						       range.size);
+			pcie->io.name = node->full_name;
 			pcie->io.flags = range.flags;
 			pcie->io.start = range.cpu_addr;
 			pcie->io.end = range.cpu_addr + range.size - 1;
+			pcie->io.parent = pcie->io.child = pcie->io.sibling = NULL;
 			set_io_port_base(pcie->io_map_base);
 			break;
 		}
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 05/10] staging: mt7621-pci: replace mdelay with msleep
  2021-05-05 12:17 [PATCH 00/10] staging: mt7621-pci: complete review Sergio Paracuellos
                   ` (3 preceding siblings ...)
  2021-05-05 12:17 ` [PATCH 04/10] staging: mt7621-pci: group io resource assignments all together Sergio Paracuellos
@ 2021-05-05 12:17 ` Sergio Paracuellos
  2021-05-05 12:17 ` [PATCH 06/10] staging: mt7621-pci: directly return 'mt7621_pcie_register_host' Sergio Paracuellos
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Sergio Paracuellos @ 2021-05-05 12:17 UTC (permalink / raw)
  To: linux-staging; +Cc: gregkh, neil, ilya.lipnitskiy

There are two mdelay calls in driver code located in
'mt7621_pcie_reset_assert' and 'mt7621_pcie_reset_rc_deassert'
functions. Both of them are not called in an interrupt handler
nor holding any spinlock. Hence, the function mdelay in them
can be replaced with msleep, to reduce busy wait.

Signed-off-by: Sergio Paracuellos <sergio.paracuellos@gmail.com>
---
 drivers/staging/mt7621-pci/pci-mt7621.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/drivers/staging/mt7621-pci/pci-mt7621.c b/drivers/staging/mt7621-pci/pci-mt7621.c
index 296f50fb3571..40bb2e8a1177 100644
--- a/drivers/staging/mt7621-pci/pci-mt7621.c
+++ b/drivers/staging/mt7621-pci/pci-mt7621.c
@@ -441,7 +441,7 @@ static void mt7621_pcie_reset_assert(struct mt7621_pcie *pcie)
 		mt7621_rst_gpio_pcie_assert(port);
 	}
 
-	mdelay(PERST_DELAY_MS);
+	msleep(PERST_DELAY_MS);
 }
 
 static void mt7621_pcie_reset_rc_deassert(struct mt7621_pcie *pcie)
@@ -459,7 +459,7 @@ static void mt7621_pcie_reset_ep_deassert(struct mt7621_pcie *pcie)
 	list_for_each_entry(port, &pcie->ports, list)
 		mt7621_rst_gpio_pcie_deassert(port);
 
-	mdelay(PERST_DELAY_MS);
+	msleep(PERST_DELAY_MS);
 }
 
 static void mt7621_pcie_init_ports(struct mt7621_pcie *pcie)
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 06/10] staging: mt7621-pci: directly return 'mt7621_pcie_register_host'
  2021-05-05 12:17 [PATCH 00/10] staging: mt7621-pci: complete review Sergio Paracuellos
                   ` (4 preceding siblings ...)
  2021-05-05 12:17 ` [PATCH 05/10] staging: mt7621-pci: replace mdelay with msleep Sergio Paracuellos
@ 2021-05-05 12:17 ` Sergio Paracuellos
  2021-05-05 12:17 ` [PATCH 07/10] staging: mt7621-pci: avoid custom 'map_irq' function Sergio Paracuellos
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Sergio Paracuellos @ 2021-05-05 12:17 UTC (permalink / raw)
  To: linux-staging; +Cc: gregkh, neil, ilya.lipnitskiy

Return code after call function 'mt7621_pcie_register_host' is
being checked to give an error message. This function internally
is calling 'pci_host_probe' which if something fails will complain
already. Hence, directly return result of this call making decrease
a bit LOC.

Signed-off-by: Sergio Paracuellos <sergio.paracuellos@gmail.com>
---
 drivers/staging/mt7621-pci/pci-mt7621.c | 8 +-------
 1 file changed, 1 insertion(+), 7 deletions(-)

diff --git a/drivers/staging/mt7621-pci/pci-mt7621.c b/drivers/staging/mt7621-pci/pci-mt7621.c
index 40bb2e8a1177..331bd8b47d99 100644
--- a/drivers/staging/mt7621-pci/pci-mt7621.c
+++ b/drivers/staging/mt7621-pci/pci-mt7621.c
@@ -694,13 +694,7 @@ static int mt7621_pci_probe(struct platform_device *pdev)
 
 	setup_cm_memory_region(pcie);
 
-	err = mt7621_pcie_register_host(bridge);
-	if (err) {
-		dev_err(dev, "Error registering host\n");
-		return err;
-	}
-
-	return 0;
+	return mt7621_pcie_register_host(bridge);
 }
 
 static const struct of_device_id mt7621_pci_ids[] = {
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 07/10] staging: mt7621-pci: avoid custom 'map_irq' function
  2021-05-05 12:17 [PATCH 00/10] staging: mt7621-pci: complete review Sergio Paracuellos
                   ` (5 preceding siblings ...)
  2021-05-05 12:17 ` [PATCH 06/10] staging: mt7621-pci: directly return 'mt7621_pcie_register_host' Sergio Paracuellos
@ 2021-05-05 12:17 ` Sergio Paracuellos
  2021-05-05 12:17 ` [PATCH 08/10] staging: mt7621-pci: remove two blank lines Sergio Paracuellos
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 11+ messages in thread
From: Sergio Paracuellos @ 2021-05-05 12:17 UTC (permalink / raw)
  To: linux-staging; +Cc: gregkh, neil, ilya.lipnitskiy

Custom function for 'map_irq' was introduced in
commit fab6710e4c51 ("staging: mt7621-pci: fix PCIe interrupt mapping")

After some testing in an adquired device with a similar
pci layout that those that was having problems, I got
into a better way to solve the issue just using device tree
'interrupt-map' and 'interrupt-map-mask' properties. For
this to be possible we must avoid custom configuration of
the virtual bridges registers from driver code. Doing in
this way buses are not reconfigured so we can properly
use bus related bits and mask in device tree to map
correctly the interrupts. Hence remove custom configuration
of the bridges as well as custom 'map_irq' related stuff.

Signed-off-by: Sergio Paracuellos <sergio.paracuellos@gmail.com>
---
 drivers/staging/mt7621-pci/pci-mt7621.c | 88 -------------------------
 1 file changed, 88 deletions(-)

diff --git a/drivers/staging/mt7621-pci/pci-mt7621.c b/drivers/staging/mt7621-pci/pci-mt7621.c
index 331bd8b47d99..c675e74ce507 100644
--- a/drivers/staging/mt7621-pci/pci-mt7621.c
+++ b/drivers/staging/mt7621-pci/pci-mt7621.c
@@ -22,7 +22,6 @@
 #include <linux/module.h>
 #include <linux/of.h>
 #include <linux/of_address.h>
-#include <linux/of_irq.h>
 #include <linux/of_pci.h>
 #include <linux/of_platform.h>
 #include <linux/pci.h>
@@ -44,15 +43,6 @@
 #define RALINK_PCI_MEMBASE		0x0028
 #define RALINK_PCI_IOBASE		0x002C
 
-/* PCICFG virtual bridges */
-#define PCIE_P2P_CNT			3
-#define PCIE_P2P_BR_DEVNUM_SHIFT(p)	(16 + (p) * 4)
-#define PCIE_P2P_BR_DEVNUM0_SHIFT	PCIE_P2P_BR_DEVNUM_SHIFT(0)
-#define PCIE_P2P_BR_DEVNUM1_SHIFT	PCIE_P2P_BR_DEVNUM_SHIFT(1)
-#define PCIE_P2P_BR_DEVNUM2_SHIFT	PCIE_P2P_BR_DEVNUM_SHIFT(2)
-#define PCIE_P2P_BR_DEVNUM_MASK		0xf
-#define PCIE_P2P_BR_DEVNUM_MASK_FULL	(0xfff << PCIE_P2P_BR_DEVNUM0_SHIFT)
-
 /* PCIe RC control registers */
 #define MT7621_PCIE_OFFSET		0x2000
 #define MT7621_NEXT_PORT		0x1000
@@ -83,7 +73,6 @@
  * @pcie_rst: pointer to port reset control
  * @gpio_rst: gpio reset
  * @slot: port slot
- * @irq: GIC irq
  * @enabled: indicates if port is enabled
  */
 struct mt7621_pcie_port {
@@ -95,7 +84,6 @@ struct mt7621_pcie_port {
 	struct reset_control *pcie_rst;
 	struct gpio_desc *gpio_rst;
 	u32 slot;
-	int irq;
 	bool enabled;
 };
 
@@ -107,7 +95,6 @@ struct mt7621_pcie_port {
  * @dev: Pointer to PCIe device
  * @io_map_base: virtual memory base address for io
  * @ports: pointer to PCIe port information
- * @irq_map: irq mapping info according pcie link status
  * @resets_inverted: depends on chip revision
  * reset lines are inverted.
  */
@@ -118,7 +105,6 @@ struct mt7621_pcie {
 	struct resource *mem;
 	unsigned long io_map_base;
 	struct list_head ports;
-	int irq_map[PCIE_P2P_CNT];
 	bool resets_inverted;
 };
 
@@ -253,16 +239,6 @@ static void setup_cm_memory_region(struct mt7621_pcie *pcie)
 	}
 }
 
-static int mt7621_map_irq(const struct pci_dev *pdev, u8 slot, u8 pin)
-{
-	struct mt7621_pcie *pcie = pdev->bus->sysdata;
-	struct device *dev = pcie->dev;
-	int irq = pcie->irq_map[slot];
-
-	dev_info(dev, "bus=%d slot=%d irq=%d\n", pdev->bus->number, slot, irq);
-	return irq;
-}
-
 static int mt7621_pci_parse_request_of_pci_ranges(struct pci_host_bridge *host)
 {
 	struct mt7621_pcie *pcie = pci_host_bridge_priv(host);
@@ -359,12 +335,6 @@ static int mt7621_pcie_parse_port(struct mt7621_pcie *pcie,
 	port->slot = slot;
 	port->pcie = pcie;
 
-	port->irq = platform_get_irq(pdev, slot);
-	if (port->irq < 0) {
-		dev_err(dev, "Failed to get IRQ for PCIe%d\n", slot);
-		return -ENXIO;
-	}
-
 	INIT_LIST_HEAD(&port->list);
 	list_add_tail(&port->list, &pcie->ports);
 
@@ -572,63 +542,11 @@ static int mt7621_pcie_enable_ports(struct mt7621_pcie *pcie)
 	return 0;
 }
 
-static int mt7621_pcie_init_virtual_bridges(struct mt7621_pcie *pcie)
-{
-	u32 pcie_link_status = 0;
-	u32 n = 0;
-	int i = 0;
-	u32 p2p_br_devnum[PCIE_P2P_CNT];
-	int irqs[PCIE_P2P_CNT];
-	struct mt7621_pcie_port *port;
-
-	list_for_each_entry(port, &pcie->ports, list) {
-		u32 slot = port->slot;
-
-		irqs[i++] = port->irq;
-		if (port->enabled)
-			pcie_link_status |= BIT(slot);
-	}
-
-	if (pcie_link_status == 0)
-		return -1;
-
-	/*
-	 * Assign device numbers from zero to the enabled ports,
-	 * then assigning remaining device numbers to any disabled
-	 * ports.
-	 */
-	for (i = 0; i < PCIE_P2P_CNT; i++)
-		if (pcie_link_status & BIT(i))
-			p2p_br_devnum[i] = n++;
-
-	for (i = 0; i < PCIE_P2P_CNT; i++)
-		if ((pcie_link_status & BIT(i)) == 0)
-			p2p_br_devnum[i] = n++;
-
-	pcie_rmw(pcie, RALINK_PCI_PCICFG_ADDR,
-		 PCIE_P2P_BR_DEVNUM_MASK_FULL,
-		 (p2p_br_devnum[0] << PCIE_P2P_BR_DEVNUM0_SHIFT) |
-		 (p2p_br_devnum[1] << PCIE_P2P_BR_DEVNUM1_SHIFT) |
-		 (p2p_br_devnum[2] << PCIE_P2P_BR_DEVNUM2_SHIFT));
-
-	/* Assign IRQs */
-	n = 0;
-	for (i = 0; i < PCIE_P2P_CNT; i++)
-		if (pcie_link_status & BIT(i))
-			pcie->irq_map[n++] = irqs[i];
-
-	for (i = n; i < PCIE_P2P_CNT; i++)
-		pcie->irq_map[i] = -1;
-
-	return 0;
-}
-
 static int mt7621_pcie_register_host(struct pci_host_bridge *host)
 {
 	struct mt7621_pcie *pcie = pci_host_bridge_priv(host);
 
 	host->ops = &mt7621_pci_ops;
-	host->map_irq = mt7621_map_irq;
 	host->sysdata = pcie;
 
 	return pci_host_probe(host);
@@ -680,12 +598,6 @@ static int mt7621_pci_probe(struct platform_device *pdev)
 
 	mt7621_pcie_init_ports(pcie);
 
-	err = mt7621_pcie_init_virtual_bridges(pcie);
-	if (err) {
-		dev_err(dev, "Nothing is connected in virtual bridges. Exiting...");
-		return 0;
-	}
-
 	err = mt7621_pcie_enable_ports(pcie);
 	if (err) {
 		dev_err(dev, "Error enabling pcie ports\n");
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 08/10] staging: mt7621-pci: remove two blank lines
  2021-05-05 12:17 [PATCH 00/10] staging: mt7621-pci: complete review Sergio Paracuellos
                   ` (6 preceding siblings ...)
  2021-05-05 12:17 ` [PATCH 07/10] staging: mt7621-pci: avoid custom 'map_irq' function Sergio Paracuellos
@ 2021-05-05 12:17 ` Sergio Paracuellos
  2021-05-05 12:17 ` [PATCH 09/10] staging: mt7621-dts: use 'interrupt-map' and 'interrupt-map-mask' Sergio Paracuellos
  2021-05-05 12:17 ` [PATCH 10/10] staging: mt7621-dts: properly organize pcie node Sergio Paracuellos
  9 siblings, 0 replies; 11+ messages in thread
From: Sergio Paracuellos @ 2021-05-05 12:17 UTC (permalink / raw)
  To: linux-staging; +Cc: gregkh, neil, ilya.lipnitskiy

There are useless two blank lines in code that can
be removed. Hence, remove them.

Signed-off-by: Sergio Paracuellos <sergio.paracuellos@gmail.com>
---
 drivers/staging/mt7621-pci/pci-mt7621.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/staging/mt7621-pci/pci-mt7621.c b/drivers/staging/mt7621-pci/pci-mt7621.c
index c675e74ce507..fe1945819d25 100644
--- a/drivers/staging/mt7621-pci/pci-mt7621.c
+++ b/drivers/staging/mt7621-pci/pci-mt7621.c
@@ -548,7 +548,6 @@ static int mt7621_pcie_register_host(struct pci_host_bridge *host)
 
 	host->ops = &mt7621_pci_ops;
 	host->sysdata = pcie;
-
 	return pci_host_probe(host);
 }
 
@@ -622,5 +621,4 @@ static struct platform_driver mt7621_pci_driver = {
 		.of_match_table = of_match_ptr(mt7621_pci_ids),
 	},
 };
-
 builtin_platform_driver(mt7621_pci_driver);
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 09/10] staging: mt7621-dts: use 'interrupt-map' and 'interrupt-map-mask'
  2021-05-05 12:17 [PATCH 00/10] staging: mt7621-pci: complete review Sergio Paracuellos
                   ` (7 preceding siblings ...)
  2021-05-05 12:17 ` [PATCH 08/10] staging: mt7621-pci: remove two blank lines Sergio Paracuellos
@ 2021-05-05 12:17 ` Sergio Paracuellos
  2021-05-05 12:17 ` [PATCH 10/10] staging: mt7621-dts: properly organize pcie node Sergio Paracuellos
  9 siblings, 0 replies; 11+ messages in thread
From: Sergio Paracuellos @ 2021-05-05 12:17 UTC (permalink / raw)
  To: linux-staging; +Cc: gregkh, neil, ilya.lipnitskiy

Custom function for 'map_irq' was introduced in
commit fab6710e4c51 ("staging: mt7621-pci: fix PCIe interrupt mapping")

This is not really necessary and code has been fixed to avoid
custom configuration of the virtual bridges and make possible
to properly map the root ports interrupts using this standard
properties. Hence properly update device tree accordly.

Signed-off-by: Sergio Paracuellos <sergio.paracuellos@gmail.com>
---
 drivers/staging/mt7621-dts/mt7621.dtsi | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/drivers/staging/mt7621-dts/mt7621.dtsi b/drivers/staging/mt7621-dts/mt7621.dtsi
index f0c9ae757bcd..fadc76fdcaf1 100644
--- a/drivers/staging/mt7621-dts/mt7621.dtsi
+++ b/drivers/staging/mt7621-dts/mt7621.dtsi
@@ -502,10 +502,11 @@ pcie: pcie@1e140000 {
 			0x01000000 0 0x00000000 0x1e160000 0 0x00010000 /* io space */
 		>;
 
-		interrupt-parent = <&gic>;
-		interrupts = <GIC_SHARED 4 IRQ_TYPE_LEVEL_HIGH
-				GIC_SHARED 24 IRQ_TYPE_LEVEL_HIGH
-				GIC_SHARED 25 IRQ_TYPE_LEVEL_HIGH>;
+		#interrupt-cells = <1>;
+		interrupt-map-mask = <0xF800 0 0 0>;
+		interrupt-map = <0x0000 0 0 0 &gic GIC_SHARED 4 IRQ_TYPE_LEVEL_HIGH>,
+				<0x0800 0 0 0 &gic GIC_SHARED 24 IRQ_TYPE_LEVEL_HIGH>,
+				<0x1000 0 0 0 &gic GIC_SHARED 25 IRQ_TYPE_LEVEL_HIGH>;
 
 		status = "disabled";
 
@@ -524,6 +525,9 @@ pcie@0,0 {
 			reg = <0x0000 0 0 0 0>;
 			#address-cells = <3>;
 			#size-cells = <2>;
+			#interrupt-cells = <1>;
+			interrupt-map-mask = <0 0 0 0>;
+			interrupt-map = <0 0 0 0 &gic GIC_SHARED 4 IRQ_TYPE_LEVEL_HIGH>;
 			ranges;
 			bus-range = <0x00 0xff>;
 		};
@@ -532,6 +536,9 @@ pcie@1,0 {
 			reg = <0x0800 0 0 0 0>;
 			#address-cells = <3>;
 			#size-cells = <2>;
+			#interrupt-cells = <1>;
+			interrupt-map-mask = <0 0 0 0>;
+			interrupt-map = <0 0 0 0 &gic GIC_SHARED 24 IRQ_TYPE_LEVEL_HIGH>;
 			ranges;
 			bus-range = <0x00 0xff>;
 		};
@@ -540,6 +547,9 @@ pcie@2,0 {
 			reg = <0x1000 0 0 0 0>;
 			#address-cells = <3>;
 			#size-cells = <2>;
+			#interrupt-cells = <1>;
+			interrupt-map-mask = <0 0 0 0>;
+			interrupt-map = <0 0 0 0 &gic GIC_SHARED 25 IRQ_TYPE_LEVEL_HIGH>;
 			ranges;
 			bus-range = <0x00 0xff>;
 		};
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

* [PATCH 10/10] staging: mt7621-dts: properly organize pcie node
  2021-05-05 12:17 [PATCH 00/10] staging: mt7621-pci: complete review Sergio Paracuellos
                   ` (8 preceding siblings ...)
  2021-05-05 12:17 ` [PATCH 09/10] staging: mt7621-dts: use 'interrupt-map' and 'interrupt-map-mask' Sergio Paracuellos
@ 2021-05-05 12:17 ` Sergio Paracuellos
  9 siblings, 0 replies; 11+ messages in thread
From: Sergio Paracuellos @ 2021-05-05 12:17 UTC (permalink / raw)
  To: linux-staging; +Cc: gregkh, neil, ilya.lipnitskiy

Device tree pcie node for this SoC is using different
styles in its different properties. Hence properly
unify them to be able to write a a proper yaml schema
documentation.

Signed-off-by: Sergio Paracuellos <sergio.paracuellos@gmail.com>
---
 drivers/staging/mt7621-dts/mt7621.dtsi | 16 +++++++---------
 1 file changed, 7 insertions(+), 9 deletions(-)

diff --git a/drivers/staging/mt7621-dts/mt7621.dtsi b/drivers/staging/mt7621-dts/mt7621.dtsi
index fadc76fdcaf1..5759ba8742ca 100644
--- a/drivers/staging/mt7621-dts/mt7621.dtsi
+++ b/drivers/staging/mt7621-dts/mt7621.dtsi
@@ -484,10 +484,10 @@ fixed-link {
 
 	pcie: pcie@1e140000 {
 		compatible = "mediatek,mt7621-pci";
-		reg = <0x1e140000 0x100     /* host-pci bridge registers */
-			0x1e142000 0x100    /* pcie port 0 RC control registers */
-			0x1e143000 0x100    /* pcie port 1 RC control registers */
-			0x1e144000 0x100>;  /* pcie port 2 RC control registers */
+		reg = <0x1e140000 0x100>, /* host-pci bridge registers */
+		      <0x1e142000 0x100>, /* pcie port 0 RC control registers */
+		      <0x1e143000 0x100>, /* pcie port 1 RC control registers */
+		      <0x1e144000 0x100>; /* pcie port 2 RC control registers */
 		#address-cells = <3>;
 		#size-cells = <2>;
 
@@ -497,10 +497,8 @@ pcie: pcie@1e140000 {
 		device_type = "pci";
 
 		bus-range = <0 255>;
-		ranges = <
-			0x02000000 0 0x00000000 0x60000000 0 0x10000000 /* pci memory */
-			0x01000000 0 0x00000000 0x1e160000 0 0x00010000 /* io space */
-		>;
+		ranges = <0x02000000 0 0x00000000 0x60000000 0 0x10000000>, /* pci memory */
+			 <0x01000000 0 0x00000000 0x1e160000 0 0x00010000>; /* io space */
 
 		#interrupt-cells = <1>;
 		interrupt-map-mask = <0xF800 0 0 0>;
@@ -510,7 +508,7 @@ pcie: pcie@1e140000 {
 
 		status = "disabled";
 
-		resets = <&rstctrl 24 &rstctrl 25 &rstctrl 26>;
+		resets = <&rstctrl 24>, <&rstctrl 25>, <&rstctrl 26>;
 		reset-names = "pcie0", "pcie1", "pcie2";
 		clocks = <&sysc MT7621_CLK_PCIE0>,
 			 <&sysc MT7621_CLK_PCIE1>,
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2021-05-05 12:17 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-05 12:17 [PATCH 00/10] staging: mt7621-pci: complete review Sergio Paracuellos
2021-05-05 12:17 ` [PATCH 01/10] staging: mt7621-pci: make use of kernel clock apis Sergio Paracuellos
2021-05-05 12:17 ` [PATCH 02/10] staging: mt7621-pci: avoid to set gpio mode in driver Sergio Paracuellos
2021-05-05 12:17 ` [PATCH 03/10] staging: mt7621-pci: remove some not needed includes Sergio Paracuellos
2021-05-05 12:17 ` [PATCH 04/10] staging: mt7621-pci: group io resource assignments all together Sergio Paracuellos
2021-05-05 12:17 ` [PATCH 05/10] staging: mt7621-pci: replace mdelay with msleep Sergio Paracuellos
2021-05-05 12:17 ` [PATCH 06/10] staging: mt7621-pci: directly return 'mt7621_pcie_register_host' Sergio Paracuellos
2021-05-05 12:17 ` [PATCH 07/10] staging: mt7621-pci: avoid custom 'map_irq' function Sergio Paracuellos
2021-05-05 12:17 ` [PATCH 08/10] staging: mt7621-pci: remove two blank lines Sergio Paracuellos
2021-05-05 12:17 ` [PATCH 09/10] staging: mt7621-dts: use 'interrupt-map' and 'interrupt-map-mask' Sergio Paracuellos
2021-05-05 12:17 ` [PATCH 10/10] staging: mt7621-dts: properly organize pcie node Sergio Paracuellos

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).