All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sergio Paracuellos <sergio.paracuellos@gmail.com>
To: gregkh@linuxfoundation.org
Cc: neil@brown.name, driverdev-devel@linuxdriverproject.org
Subject: [PATCH v6 04/33] staging: mt7621-pci: factor out 'mt7621_pcie_enable_port' function
Date: Sun,  4 Nov 2018 11:49:30 +0100	[thread overview]
Message-ID: <1541328599-18396-5-git-send-email-sergio.paracuellos@gmail.com> (raw)
In-Reply-To: <1541328599-18396-1-git-send-email-sergio.paracuellos@gmail.com>

Driver probe function is a mess and shall be refactored a lot. At first
make use of assert and deassert control factoring out a new function
called 'mt7621_pcie_enable_port'.

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

diff --git a/drivers/staging/mt7621-pci/pci-mt7621.c b/drivers/staging/mt7621-pci/pci-mt7621.c
index 04e82c3..9be5ca1 100644
--- a/drivers/staging/mt7621-pci/pci-mt7621.c
+++ b/drivers/staging/mt7621-pci/pci-mt7621.c
@@ -480,6 +480,39 @@ static int mt7621_pcie_parse_dt(struct mt7621_pcie *pcie)
 	return 0;
 }
 
+static int mt7621_pcie_enable_port(struct mt7621_pcie_port *port)
+{
+	struct mt7621_pcie *pcie = port->pcie;
+	struct device *dev = pcie->dev;
+	u32 slot = port->slot;
+	u32 val = 0;
+	int err;
+
+	err = clk_prepare_enable(port->pcie_clk);
+	if (err) {
+		dev_err(dev, "failed to enable pcie%d clock\n", slot);
+		return err;
+	}
+
+	reset_control_assert(port->pcie_rst);
+	reset_control_deassert(port->pcie_rst);
+
+	if ((pcie_port_read(port, RALINK_PCI_STATUS) & 0x1) == 0) {
+		dev_err(dev, "pcie%d no card, disable it (RST & CLK)\n", slot);
+		reset_control_assert(port->pcie_rst);
+		rt_sysc_m32(BIT(24 + slot), 0, RALINK_CLKCFG1);
+		pcie_link_status &= ~(1 << slot);
+	} else {
+		pcie_link_status |= BIT(slot);
+		val = pcie_read(pcie, RALINK_PCI_PCIMSK_ADDR);
+		/* enable pcie interrupt */
+		val |= BIT(20 + slot);
+		pcie_write(pcie, val, RALINK_PCI_PCIMSK_ADDR);
+	}
+
+	return 0;
+}
+
 static int mt7621_pcie_request_resources(struct mt7621_pcie *pcie,
 					 struct list_head *res)
 {
@@ -518,6 +551,7 @@ static int mt7621_pci_probe(struct platform_device *pdev)
 	struct device *dev = &pdev->dev;
 	struct mt7621_pcie *pcie;
 	struct pci_host_bridge *bridge;
+	struct mt7621_pcie_port *port, *tmp;
 	int err;
 	u32 val = 0;
 	LIST_HEAD(res);
@@ -546,12 +580,6 @@ static int mt7621_pci_probe(struct platform_device *pdev)
 	ioport_resource.start = 0;
 	ioport_resource.end = ~0UL; /* no limit */
 
-	val = RALINK_PCIE0_RST;
-	val |= RALINK_PCIE1_RST;
-	val |= RALINK_PCIE2_RST;
-
-	ASSERT_SYSRST_PCIE(RALINK_PCIE0_RST | RALINK_PCIE1_RST | RALINK_PCIE2_RST);
-
 	*(unsigned int *)(0xbe000060) &= ~(0x3 << 10 | 0x3 << 3);
 	*(unsigned int *)(0xbe000060) |=  BIT(10) | BIT(3);
 	mdelay(100);
@@ -561,11 +589,13 @@ static int mt7621_pci_probe(struct platform_device *pdev)
 
 	mdelay(100);
 
-	val = RALINK_PCIE0_RST;
-	val |= RALINK_PCIE1_RST;
-	val |= RALINK_PCIE2_RST;
-
-	DEASSERT_SYSRST_PCIE(val);
+	list_for_each_entry_safe(port, tmp, &pcie->ports, list) {
+		err = mt7621_pcie_enable_port(port);
+		if (err) {
+			dev_err(dev, "enabling port %d failed\n", port->slot);
+			list_del(&port->list);
+		}
+	}
 
 	if ((*(unsigned int *)(0xbe00000c) & 0xFFFF) == 0x0101) // MT7621 E2
 		bypass_pipe_rst(pcie);
@@ -591,42 +621,6 @@ static int mt7621_pci_probe(struct platform_device *pdev)
 	*(unsigned int *)(0xbe000620) |= BIT(19) | BIT(8) | BIT(7);		// set DATA
 	mdelay(1000);
 
-	if ((pcie_read(pcie, RT6855_PCIE0_OFFSET + RALINK_PCI_STATUS) & 0x1) == 0) {
-		printk("PCIE0 no card, disable it(RST&CLK)\n");
-		ASSERT_SYSRST_PCIE(RALINK_PCIE0_RST);
-		rt_sysc_m32(RALINK_PCIE0_CLK_EN, 0, RALINK_CLKCFG1);
-		pcie_link_status &= ~(BIT(0));
-	} else {
-		pcie_link_status |=  BIT(0);
-		val = pcie_read(pcie, RALINK_PCI_PCIMSK_ADDR);
-		val |= BIT(20); // enable pcie1 interrupt
-		pcie_write(pcie, val, RALINK_PCI_PCIMSK_ADDR);
-	}
-
-	if ((pcie_read(pcie, RT6855_PCIE1_OFFSET + RALINK_PCI_STATUS) & 0x1) == 0) {
-		printk("PCIE1 no card, disable it(RST&CLK)\n");
-		ASSERT_SYSRST_PCIE(RALINK_PCIE1_RST);
-		rt_sysc_m32(RALINK_PCIE1_CLK_EN, 0, RALINK_CLKCFG1);
-		pcie_link_status &= ~(BIT(1));
-	} else {
-		pcie_link_status |= BIT(1);
-		val = pcie_read(pcie, RALINK_PCI_PCIMSK_ADDR);
-		val |= BIT(21); // enable pcie1 interrupt
-		pcie_write(pcie, val, RALINK_PCI_PCIMSK_ADDR);
-	}
-
-	if ((pcie_read(pcie, RT6855_PCIE2_OFFSET + RALINK_PCI_STATUS) & 0x1) == 0) {
-		printk("PCIE2 no card, disable it(RST&CLK)\n");
-		ASSERT_SYSRST_PCIE(RALINK_PCIE2_RST);
-		rt_sysc_m32(RALINK_PCIE2_CLK_EN, 0, RALINK_CLKCFG1);
-		pcie_link_status &= ~(BIT(2));
-	} else {
-		pcie_link_status |=  BIT(2);
-		val = pcie_read(pcie, RALINK_PCI_PCIMSK_ADDR);
-		val |= BIT(22); // enable pcie2 interrupt
-		pcie_write(pcie, val, RALINK_PCI_PCIMSK_ADDR);
-	}
-
 	if (pcie_link_status == 0)
 		return 0;
 
-- 
2.7.4

_______________________________________________
devel mailing list
devel@linuxdriverproject.org
http://driverdev.linuxdriverproject.org/mailman/listinfo/driverdev-devel

  parent reply	other threads:[~2018-11-04 10:50 UTC|newest]

Thread overview: 46+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-11-04 10:49 [PATCH v6 00/33] staging: mt7621-pci: Parse ports info from DT and other minor cleanups Sergio Paracuellos
2018-11-04 10:49 ` [PATCH v6 01/33] staging: mt7621-pci: parse and init port data from device tree Sergio Paracuellos
2018-11-18 21:51   ` NeilBrown
2018-11-19  4:44     ` Sergio Paracuellos
2018-11-04 10:49 ` [PATCH v6 02/33] staging: mt7621-pci: replace return value if devm_pci_alloc_host_bridge call fails Sergio Paracuellos
2018-11-04 10:49 ` [PATCH v6 03/33] staging: mt7621-pci: add two helpers for read and write pcie register ports Sergio Paracuellos
2018-11-04 10:49 ` Sergio Paracuellos [this message]
2018-11-23 22:44   ` [PATCH v6 04/33] staging: mt7621-pci: factor out 'mt7621_pcie_enable_port' function NeilBrown
2018-11-04 10:49 ` [PATCH v6 05/33] staging: mt7621-pci: remove [ASSERT|DEASSERT]_SYSRST_PCIE macros Sergio Paracuellos
2018-11-04 10:49 ` [PATCH v6 06/33] staging: mt7621-pci: remove GPL2+ text from license header Sergio Paracuellos
2018-11-04 10:49 ` [PATCH v6 07/33] staging: mt7621-pci: remove two commented code lines Sergio Paracuellos
2018-11-04 10:49 ` [PATCH v6 08/33] staging: mt7621-pci: remove reset related unused macros Sergio Paracuellos
2018-11-04 10:49 ` [PATCH v6 09/33] staging: mt7621-pci: reagroup reset related macros all together Sergio Paracuellos
2018-11-04 10:49 ` [PATCH v6 10/33] staging: mt7621-pci: rewrite pcie phy related functions Sergio Paracuellos
2018-11-04 10:49 ` [PATCH v6 11/33] staging: mt7621-pci: factor out 'mt7621_enable_phy' function Sergio Paracuellos
2018-11-04 10:49 ` [PATCH v6 12/33] staging: mt7621-pci: debug port N_FTS inside 'mt7621_pcie_enable_port' Sergio Paracuellos
2018-11-04 10:49 ` [PATCH v6 13/33] staging: mt7621-pci: rename 'mt7621_pcie_enable_port' into 'mt7621_pcie_init_port' Sergio Paracuellos
2018-11-04 10:49 ` [PATCH v6 14/33] staging: mt7621-dts: add sysctl registers base address to pcie Sergio Paracuellos
2018-11-23 23:07   ` NeilBrown
2018-11-24  7:22     ` Sergio Paracuellos
2018-11-04 10:49 ` [PATCH v6 15/33] staging: mt7621-pci: remap and use sysctl from device tree Sergio Paracuellos
2018-11-04 10:49 ` [PATCH v6 16/33] staging: mt7621-pci: use a trailing */ on a separate line Sergio Paracuellos
2018-11-04 10:49 ` [PATCH v6 17/33] staging: mt7621-pci: use dev_* functions instead of printk Sergio Paracuellos
2018-11-04 10:49 ` [PATCH v6 18/33] staging: mt7621-pci: factor out 'mt7621_pcie_enable_ports' function Sergio Paracuellos
2018-11-04 10:49 ` [PATCH v6 19/33] staging: mt7621-pci: avoid use of global variable 'pcie_link_status' Sergio Paracuellos
2018-11-04 10:49 ` [PATCH v6 20/33] staging: mt7621-pci: factor out 'mt7621_pcie_init_ports' function Sergio Paracuellos
2018-11-04 10:49 ` [PATCH v6 21/33] staging: mt7621-pci: remove unused preprocessor definitions Sergio Paracuellos
2018-11-04 10:49 ` [PATCH v6 22/33] staging: mt7621-pci: reorder " Sergio Paracuellos
2018-11-04 10:49 ` [PATCH v6 23/33] staging: mt7621-pci: remove non sense comment Sergio Paracuellos
2018-11-04 10:49 ` [PATCH v6 24/33] staging: mt7621-pci: align function definition style along the code Sergio Paracuellos
2018-11-04 10:49 ` [PATCH v6 25/33] staging: mt7621-pci: rewrite RC FTS configuration Sergio Paracuellos
2018-11-04 10:49 ` [PATCH v6 26/33] staging: mt7621-pci: rewrite hardcoded code for enabling ports Sergio Paracuellos
2018-11-04 10:49 ` [PATCH v6 27/33] staging: mt7621-pci: add some definitions for enabling and disabling GEN and GEN1 clocks Sergio Paracuellos
2018-11-04 10:49 ` [PATCH v6 28/33] staging: mt7621-pci: use PERST_N instead of gpio control Sergio Paracuellos
2018-11-04 10:49 ` [PATCH v6 29/33] staging: mt7621-pci: use PCIE_PORT_LINKUP instead of hardcode value Sergio Paracuellos
2018-11-04 10:49 ` [PATCH v6 30/33] staging: mt7621-pci: enable interrupt when port is being enabled Sergio Paracuellos
2018-11-04 10:49 ` [PATCH v6 31/33] staging: mt7621-pci: factor out 'mt7621_pcie_enable_port' function Sergio Paracuellos
2018-11-04 10:49 ` [PATCH v6 32/33] staging: mt7621-pci: move some code into 'mt7621_pcie_init_ports' Sergio Paracuellos
2018-11-04 10:49 ` [PATCH v6 33/33] staging: mt7621-pci: replace 'mdelay()' with 'msleep()' Sergio Paracuellos
2018-11-05  8:09   ` Frans Klaver
2018-11-07 13:11     ` Sergio Paracuellos
2018-11-11 19:35 ` [PATCH v6 00/33] staging: mt7621-pci: Parse ports info from DT and other minor cleanups Greg KH
2018-11-11 21:40   ` NeilBrown
2018-11-12  5:44     ` Sergio Paracuellos
2018-11-24  0:21       ` NeilBrown
2018-11-24  7:38         ` Sergio Paracuellos

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=1541328599-18396-5-git-send-email-sergio.paracuellos@gmail.com \
    --to=sergio.paracuellos@gmail.com \
    --cc=driverdev-devel@linuxdriverproject.org \
    --cc=gregkh@linuxfoundation.org \
    --cc=neil@brown.name \
    /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.