All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 0/4] staging: mt7621-pci-phy: driver cleanups
@ 2019-04-17 11:58 Sergio Paracuellos
  2019-04-17 11:58 ` [PATCH v2 1/4] staging: mt7621-pci-phy: use 'platform_get_resource' Sergio Paracuellos
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Sergio Paracuellos @ 2019-04-17 11:58 UTC (permalink / raw)
  To: gregkh; +Cc: neil, driverdev-devel

This series makes some cleanups pointed out here from Kishon Vijay
Abraham I:

* https://lkml.org/lkml/2019/4/17/53

Changes in v2:
    - add patch to make use of regmap API instead of readl and writel.

Other changes:
    - make use of platform_get_resource.
    - make use of soc_device_match.
    - clean a bit error paths and not needed locals in 'probe' function.

This changes have been only compile-tested.

Hope this helps.

Best regards,
    Sergio Paracuellos

Sergio Paracuellos (4):
  staging: mt7621-pci-phy: use 'platform_get_resource'
  staging: mt7621-pci-phy: remove some unnecessary local variables
  staging: mt7621-pci-phy: add quirks for 'E2' revision using
    'soc_device_attribute'
  staging: mt7621-pci-phy: convert driver to use kernel regmap API's

 .../staging/mt7621-pci-phy/pci-mt7621-phy.c   | 132 ++++++++++--------
 1 file changed, 77 insertions(+), 55 deletions(-)

-- 
2.19.1

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

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

* [PATCH v2 1/4] staging: mt7621-pci-phy: use 'platform_get_resource'
  2019-04-17 11:58 [PATCH v2 0/4] staging: mt7621-pci-phy: driver cleanups Sergio Paracuellos
@ 2019-04-17 11:58 ` Sergio Paracuellos
  2019-04-17 11:58 ` [PATCH v2 2/4] staging: mt7621-pci-phy: remove some unnecessary local variables Sergio Paracuellos
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Sergio Paracuellos @ 2019-04-17 11:58 UTC (permalink / raw)
  To: gregkh; +Cc: neil, driverdev-devel

Driver is using 'of_address_to_resource' to get memory resources.
Make use of 'platform_get_resource' instead which is more accurate
for a platform driver. This also makes possible to delete a local
variable which is not needed anymore.

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

diff --git a/drivers/staging/mt7621-pci-phy/pci-mt7621-phy.c b/drivers/staging/mt7621-pci-phy/pci-mt7621-phy.c
index aa3ae7777632..bac188f00f4e 100644
--- a/drivers/staging/mt7621-pci-phy/pci-mt7621-phy.c
+++ b/drivers/staging/mt7621-pci-phy/pci-mt7621-phy.c
@@ -308,11 +308,10 @@ static struct phy *mt7621_pcie_phy_of_xlate(struct device *dev,
 static int mt7621_pci_phy_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
-	struct device_node *np = dev->of_node;
 	struct device_node *child_np;
 	struct phy_provider *provider;
 	struct mt7621_pci_phy *phy;
-	struct resource res;
+	struct resource *res;
 	int port, ret;
 	void __iomem *port_base;
 
@@ -329,13 +328,13 @@ static int mt7621_pci_phy_probe(struct platform_device *pdev)
 	phy->dev = dev;
 	platform_set_drvdata(pdev, phy);
 
-	ret = of_address_to_resource(np, 0, &res);
-	if (ret) {
+	res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
+	if (!res) {
 		dev_err(dev, "failed to get address resource\n");
-		return ret;
+		return -ENXIO;
 	}
 
-	port_base = devm_ioremap_resource(dev, &res);
+	port_base = devm_ioremap_resource(dev, res);
 	if (IS_ERR(port_base)) {
 		dev_err(dev, "failed to remap phy regs\n");
 		return PTR_ERR(port_base);
-- 
2.19.1

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

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

* [PATCH v2 2/4] staging: mt7621-pci-phy: remove some unnecessary local variables
  2019-04-17 11:58 [PATCH v2 0/4] staging: mt7621-pci-phy: driver cleanups Sergio Paracuellos
  2019-04-17 11:58 ` [PATCH v2 1/4] staging: mt7621-pci-phy: use 'platform_get_resource' Sergio Paracuellos
@ 2019-04-17 11:58 ` Sergio Paracuellos
  2019-04-17 11:58 ` [PATCH v2 3/4] staging: mt7621-pci-phy: add quirks for 'E2' revision using 'soc_device_attribute' Sergio Paracuellos
  2019-04-17 11:58 ` [PATCH v2 4/4] staging: mt7621-pci-phy: convert driver to use kernel regmap API's Sergio Paracuellos
  3 siblings, 0 replies; 5+ messages in thread
From: Sergio Paracuellos @ 2019-04-17 11:58 UTC (permalink / raw)
  To: gregkh; +Cc: neil, driverdev-devel

Device tree is not using child nodes anymore so the 'child_np' variable
can safely removed. This also simplifies the error path to be able to
directly return errors removing also the 'ret' variable.

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

diff --git a/drivers/staging/mt7621-pci-phy/pci-mt7621-phy.c b/drivers/staging/mt7621-pci-phy/pci-mt7621-phy.c
index bac188f00f4e..21f980cc2d8f 100644
--- a/drivers/staging/mt7621-pci-phy/pci-mt7621-phy.c
+++ b/drivers/staging/mt7621-pci-phy/pci-mt7621-phy.c
@@ -308,11 +308,10 @@ static struct phy *mt7621_pcie_phy_of_xlate(struct device *dev,
 static int mt7621_pci_phy_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
-	struct device_node *child_np;
 	struct phy_provider *provider;
 	struct mt7621_pci_phy *phy;
 	struct resource *res;
-	int port, ret;
+	int port;
 	void __iomem *port_base;
 
 	phy = devm_kzalloc(dev, sizeof(*phy), GFP_KERNEL);
@@ -345,18 +344,15 @@ static int mt7621_pci_phy_probe(struct platform_device *pdev)
 		struct phy *pphy;
 
 		instance = devm_kzalloc(dev, sizeof(*instance), GFP_KERNEL);
-		if (!instance) {
-			ret = -ENOMEM;
-			goto put_child;
-		}
+		if (!instance)
+			return -ENOMEM;
 
 		phy->phys[port] = instance;
 
 		pphy = devm_phy_create(dev, dev->of_node, &mt7621_pci_phy_ops);
 		if (IS_ERR(phy)) {
 			dev_err(dev, "failed to create phy\n");
-			ret = PTR_ERR(phy);
-			goto put_child;
+			return PTR_ERR(phy);
 		}
 
 		instance->port_base = port_base;
@@ -368,10 +364,6 @@ static int mt7621_pci_phy_probe(struct platform_device *pdev)
 	provider = devm_of_phy_provider_register(dev, mt7621_pcie_phy_of_xlate);
 
 	return PTR_ERR_OR_ZERO(provider);
-
-put_child:
-	of_node_put(child_np);
-	return ret;
 }
 
 static const struct of_device_id mt7621_pci_phy_ids[] = {
-- 
2.19.1

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

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

* [PATCH v2 3/4] staging: mt7621-pci-phy: add quirks for 'E2' revision using 'soc_device_attribute'
  2019-04-17 11:58 [PATCH v2 0/4] staging: mt7621-pci-phy: driver cleanups Sergio Paracuellos
  2019-04-17 11:58 ` [PATCH v2 1/4] staging: mt7621-pci-phy: use 'platform_get_resource' Sergio Paracuellos
  2019-04-17 11:58 ` [PATCH v2 2/4] staging: mt7621-pci-phy: remove some unnecessary local variables Sergio Paracuellos
@ 2019-04-17 11:58 ` Sergio Paracuellos
  2019-04-17 11:58 ` [PATCH v2 4/4] staging: mt7621-pci-phy: convert driver to use kernel regmap API's Sergio Paracuellos
  3 siblings, 0 replies; 5+ messages in thread
From: Sergio Paracuellos @ 2019-04-17 11:58 UTC (permalink / raw)
  To: gregkh; +Cc: neil, driverdev-devel

Depending on revision of the chip, 'mt7621_bypass_pipe_rst' function
must be executed. Add better support for this using 'soc_device_match'
in driver probe function.

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

diff --git a/drivers/staging/mt7621-pci-phy/pci-mt7621-phy.c b/drivers/staging/mt7621-pci-phy/pci-mt7621-phy.c
index 21f980cc2d8f..f762369d6792 100644
--- a/drivers/staging/mt7621-pci-phy/pci-mt7621-phy.c
+++ b/drivers/staging/mt7621-pci-phy/pci-mt7621-phy.c
@@ -11,11 +11,11 @@
 #include <linux/of_device.h>
 #include <linux/phy/phy.h>
 #include <linux/platform_device.h>
+#include <linux/sys_soc.h>
 #include <mt7621.h>
 #include <ralink_regs.h>
 
 #define RALINK_CLKCFG1				0x30
-#define CHIP_REV_MT7621_E2			0x0101
 
 #define PCIE_PORT_CLK_EN(x)			BIT(24 + (x))
 
@@ -97,11 +97,14 @@ struct mt7621_pci_phy_instance {
  * @dev: pointer to device
  * @phys: pointer to Mt7621 PHY device
  * @nphys: number of PHY devices for this core
+ * @bypass_pipe_rst: mark if 'mt7621_bypass_pipe_rst'
+ * needs to be executed. Depends on chip revision.
  */
 struct mt7621_pci_phy {
 	struct device *dev;
 	struct mt7621_pci_phy_instance **phys;
 	int nphys;
+	bool bypass_pipe_rst;
 };
 
 static inline u32 phy_read(struct mt7621_pci_phy_instance *instance, u32 reg)
@@ -232,9 +235,8 @@ static int mt7621_pci_phy_init(struct phy *phy)
 {
 	struct mt7621_pci_phy_instance *instance = phy_get_drvdata(phy);
 	struct mt7621_pci_phy *mphy = dev_get_drvdata(phy->dev.parent);
-	u32 chip_rev_id = rt_sysc_r32(SYSC_REG_CHIP_REV);
 
-	if ((chip_rev_id & 0xFFFF) == CHIP_REV_MT7621_E2)
+	if (mphy->bypass_pipe_rst)
 		mt7621_bypass_pipe_rst(mphy, instance);
 
 	mt7621_set_phy_for_ssc(mphy, instance);
@@ -305,9 +307,14 @@ static struct phy *mt7621_pcie_phy_of_xlate(struct device *dev,
 	return mt7621_phy->phys[args->args[0]]->phy;
 }
 
+static const struct soc_device_attribute mt7621_pci_quirks_match[] = {
+	{ .soc_id = "mt7621", .revision = "E2" }
+};
+
 static int mt7621_pci_phy_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
+	const struct soc_device_attribute *attr;
 	struct phy_provider *provider;
 	struct mt7621_pci_phy *phy;
 	struct resource *res;
@@ -324,6 +331,10 @@ static int mt7621_pci_phy_probe(struct platform_device *pdev)
 	if (!phy->phys)
 		return -ENOMEM;
 
+	attr = soc_device_match(mt7621_pci_quirks_match);
+	if (attr)
+		phy->bypass_pipe_rst = true;
+
 	phy->dev = dev;
 	platform_set_drvdata(pdev, phy);
 
-- 
2.19.1

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

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

* [PATCH v2 4/4] staging: mt7621-pci-phy: convert driver to use kernel regmap API's
  2019-04-17 11:58 [PATCH v2 0/4] staging: mt7621-pci-phy: driver cleanups Sergio Paracuellos
                   ` (2 preceding siblings ...)
  2019-04-17 11:58 ` [PATCH v2 3/4] staging: mt7621-pci-phy: add quirks for 'E2' revision using 'soc_device_attribute' Sergio Paracuellos
@ 2019-04-17 11:58 ` Sergio Paracuellos
  3 siblings, 0 replies; 5+ messages in thread
From: Sergio Paracuellos @ 2019-04-17 11:58 UTC (permalink / raw)
  To: gregkh; +Cc: neil, driverdev-devel

Instead of using writel and readl use regmap API which makes
the driver maintainability easier.

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

diff --git a/drivers/staging/mt7621-pci-phy/pci-mt7621-phy.c b/drivers/staging/mt7621-pci-phy/pci-mt7621-phy.c
index f762369d6792..2576f179e30a 100644
--- a/drivers/staging/mt7621-pci-phy/pci-mt7621-phy.c
+++ b/drivers/staging/mt7621-pci-phy/pci-mt7621-phy.c
@@ -11,6 +11,7 @@
 #include <linux/of_device.h>
 #include <linux/phy/phy.h>
 #include <linux/platform_device.h>
+#include <linux/regmap.h>
 #include <linux/sys_soc.h>
 #include <mt7621.h>
 #include <ralink_regs.h>
@@ -95,6 +96,7 @@ struct mt7621_pci_phy_instance {
 /**
  * struct mt7621_pci_phy - Mt7621 Pcie PHY core
  * @dev: pointer to device
+ * @regmap: kernel regmap pointer
  * @phys: pointer to Mt7621 PHY device
  * @nphys: number of PHY devices for this core
  * @bypass_pipe_rst: mark if 'mt7621_bypass_pipe_rst'
@@ -102,20 +104,24 @@ struct mt7621_pci_phy_instance {
  */
 struct mt7621_pci_phy {
 	struct device *dev;
+	struct regmap *regmap;
 	struct mt7621_pci_phy_instance **phys;
 	int nphys;
 	bool bypass_pipe_rst;
 };
 
-static inline u32 phy_read(struct mt7621_pci_phy_instance *instance, u32 reg)
+static inline u32 phy_read(struct mt7621_pci_phy *phy, u32 reg)
 {
-	return readl(instance->port_base + reg);
+	u32 val;
+
+	regmap_read(phy->regmap, reg, &val);
+
+	return val;
 }
 
-static inline void phy_write(struct mt7621_pci_phy_instance *instance,
-			     u32 val, u32 reg)
+static inline void phy_write(struct mt7621_pci_phy *phy, u32 val, u32 reg)
 {
-	writel(val, instance->port_base + reg);
+	regmap_write(phy->regmap, reg, val);
 }
 
 static void mt7621_bypass_pipe_rst(struct mt7621_pci_phy *phy,
@@ -125,10 +131,10 @@ static void mt7621_bypass_pipe_rst(struct mt7621_pci_phy *phy,
 		RG_PE1_PIPE_REG : RG_PE1_PIPE_REG + RG_P0_TO_P1_WIDTH;
 	u32 reg;
 
-	reg = phy_read(instance, offset);
+	reg = phy_read(phy, offset);
 	reg &= ~(RG_PE1_PIPE_RST | RG_PE1_PIPE_CMD_FRC);
 	reg |= (RG_PE1_PIPE_RST | RG_PE1_PIPE_CMD_FRC);
-	phy_write(instance, reg, offset);
+	phy_write(phy, reg, offset);
 }
 
 static void mt7621_set_phy_for_ssc(struct mt7621_pci_phy *phy,
@@ -142,72 +148,72 @@ static void mt7621_set_phy_for_ssc(struct mt7621_pci_phy *phy,
 	reg = (reg >> 6) & 0x7;
 	/* Set PCIe Port PHY to disable SSC */
 	/* Debug Xtal Type */
-	val = phy_read(instance, RG_PE1_FRC_H_XTAL_REG);
+	val = phy_read(phy, RG_PE1_FRC_H_XTAL_REG);
 	val &= ~(RG_PE1_FRC_H_XTAL_TYPE | RG_PE1_H_XTAL_TYPE);
 	val |= RG_PE1_FRC_H_XTAL_TYPE;
 	val |= RG_PE1_H_XTAL_TYPE_VAL(0x00);
-	phy_write(instance, val, RG_PE1_FRC_H_XTAL_REG);
+	phy_write(phy, val, RG_PE1_FRC_H_XTAL_REG);
 
 	/* disable port */
 	offset = (instance->index != 1) ?
 		RG_PE1_FRC_PHY_REG : RG_PE1_FRC_PHY_REG + RG_P0_TO_P1_WIDTH;
-	val = phy_read(instance, offset);
+	val = phy_read(phy, offset);
 	val &= ~(RG_PE1_FRC_PHY_EN | RG_PE1_PHY_EN);
 	val |= RG_PE1_FRC_PHY_EN;
-	phy_write(instance, val, offset);
+	phy_write(phy, val, offset);
 
 	/* Set Pre-divider ratio (for host mode) */
-	val = phy_read(instance, RG_PE1_H_PLL_REG);
+	val = phy_read(phy, RG_PE1_H_PLL_REG);
 	val &= ~(RG_PE1_H_PLL_PREDIV);
 
 	if (reg <= 5 && reg >= 3) { /* 40MHz Xtal */
 		val |= RG_PE1_H_PLL_PREDIV_VAL(0x01);
-		phy_write(instance, val, RG_PE1_H_PLL_REG);
+		phy_write(phy, val, RG_PE1_H_PLL_REG);
 		dev_info(dev, "Xtal is 40MHz\n");
 	} else { /* 25MHz | 20MHz Xtal */
 		val |= RG_PE1_H_PLL_PREDIV_VAL(0x00);
-		phy_write(instance, val, RG_PE1_H_PLL_REG);
+		phy_write(phy, val, RG_PE1_H_PLL_REG);
 		if (reg >= 6) {
 			dev_info(dev, "Xtal is 25MHz\n");
 
 			/* Select feedback clock */
-			val = phy_read(instance, RG_PE1_H_PLL_FBKSEL_REG);
+			val = phy_read(phy, RG_PE1_H_PLL_FBKSEL_REG);
 			val &= ~(RG_PE1_H_PLL_FBKSEL);
 			val |= RG_PE1_H_PLL_FBKSEL_VAL(0x01);
-			phy_write(instance, val, RG_PE1_H_PLL_FBKSEL_REG);
+			phy_write(phy, val, RG_PE1_H_PLL_FBKSEL_REG);
 
 			/* DDS NCPO PCW (for host mode) */
-			val = phy_read(instance, RG_PE1_H_LCDDS_SSC_PRD_REG);
+			val = phy_read(phy, RG_PE1_H_LCDDS_SSC_PRD_REG);
 			val &= ~(RG_PE1_H_LCDDS_SSC_PRD);
 			val |= RG_PE1_H_LCDDS_SSC_PRD_VAL(0x18000000);
-			phy_write(instance, val, RG_PE1_H_LCDDS_SSC_PRD_REG);
+			phy_write(phy, val, RG_PE1_H_LCDDS_SSC_PRD_REG);
 
 			/* DDS SSC dither period control */
-			val = phy_read(instance, RG_PE1_H_LCDDS_SSC_PRD_REG);
+			val = phy_read(phy, RG_PE1_H_LCDDS_SSC_PRD_REG);
 			val &= ~(RG_PE1_H_LCDDS_SSC_PRD);
 			val |= RG_PE1_H_LCDDS_SSC_PRD_VAL(0x18d);
-			phy_write(instance, val, RG_PE1_H_LCDDS_SSC_PRD_REG);
+			phy_write(phy, val, RG_PE1_H_LCDDS_SSC_PRD_REG);
 
 			/* DDS SSC dither amplitude control */
-			val = phy_read(instance, RG_PE1_H_LCDDS_SSC_DELTA_REG);
+			val = phy_read(phy, RG_PE1_H_LCDDS_SSC_DELTA_REG);
 			val &= ~(RG_PE1_H_LCDDS_SSC_DELTA |
 				 RG_PE1_H_LCDDS_SSC_DELTA1);
 			val |= RG_PE1_H_LCDDS_SSC_DELTA_VAL(0x4a);
 			val |= RG_PE1_H_LCDDS_SSC_DELTA1_VAL(0x4a);
-			phy_write(instance, val, RG_PE1_H_LCDDS_SSC_DELTA_REG);
+			phy_write(phy, val, RG_PE1_H_LCDDS_SSC_DELTA_REG);
 		} else {
 			dev_info(dev, "Xtal is 20MHz\n");
 		}
 	}
 
 	/* DDS clock inversion */
-	val = phy_read(instance, RG_PE1_LCDDS_CLK_PH_INV_REG);
+	val = phy_read(phy, RG_PE1_LCDDS_CLK_PH_INV_REG);
 	val &= ~(RG_PE1_LCDDS_CLK_PH_INV);
 	val |= RG_PE1_LCDDS_CLK_PH_INV;
-	phy_write(instance, val, RG_PE1_LCDDS_CLK_PH_INV_REG);
+	phy_write(phy, val, RG_PE1_LCDDS_CLK_PH_INV_REG);
 
 	/* Set PLL bits */
-	val = phy_read(instance, RG_PE1_H_PLL_REG);
+	val = phy_read(phy, RG_PE1_H_PLL_REG);
 	val &= ~(RG_PE1_H_PLL_BC | RG_PE1_H_PLL_BP | RG_PE1_H_PLL_IR |
 		 RG_PE1_H_PLL_IC | RG_PE1_PLL_DIVEN);
 	val |= RG_PE1_H_PLL_BC_VAL(0x02);
@@ -215,19 +221,19 @@ static void mt7621_set_phy_for_ssc(struct mt7621_pci_phy *phy,
 	val |= RG_PE1_H_PLL_IR_VAL(0x02);
 	val |= RG_PE1_H_PLL_IC_VAL(0x01);
 	val |= RG_PE1_PLL_DIVEN_VAL(0x02);
-	phy_write(instance, val, RG_PE1_H_PLL_REG);
+	phy_write(phy, val, RG_PE1_H_PLL_REG);
 
-	val = phy_read(instance, RG_PE1_H_PLL_BR_REG);
+	val = phy_read(phy, RG_PE1_H_PLL_BR_REG);
 	val &= ~(RG_PE1_H_PLL_BR);
 	val |= RG_PE1_H_PLL_BR_VAL(0x00);
-	phy_write(instance, val, RG_PE1_H_PLL_BR_REG);
+	phy_write(phy, val, RG_PE1_H_PLL_BR_REG);
 
 	if (reg <= 5 && reg >= 3) { /* 40MHz Xtal */
 		/* set force mode enable of da_pe1_mstckdiv */
-		val = phy_read(instance, RG_PE1_MSTCKDIV_REG);
+		val = phy_read(phy, RG_PE1_MSTCKDIV_REG);
 		val &= ~(RG_PE1_MSTCKDIV | RG_PE1_FRC_MSTCKDIV);
 		val |= (RG_PE1_MSTCKDIV_VAL(0x01) | RG_PE1_FRC_MSTCKDIV);
-		phy_write(instance, val, RG_PE1_MSTCKDIV_REG);
+		phy_write(phy, val, RG_PE1_MSTCKDIV_REG);
 	}
 }
 
@@ -247,15 +253,16 @@ static int mt7621_pci_phy_init(struct phy *phy)
 static int mt7621_pci_phy_power_on(struct phy *phy)
 {
 	struct mt7621_pci_phy_instance *instance = phy_get_drvdata(phy);
+	struct mt7621_pci_phy *mphy = dev_get_drvdata(phy->dev.parent);
 	u32 offset = (instance->index != 1) ?
 		RG_PE1_FRC_PHY_REG : RG_PE1_FRC_PHY_REG + RG_P0_TO_P1_WIDTH;
 	u32 val;
 
 	/* Enable PHY and disable force mode */
-	val = phy_read(instance, offset);
+	val = phy_read(mphy, offset);
 	val &= ~(RG_PE1_FRC_PHY_EN | RG_PE1_PHY_EN);
 	val |= (RG_PE1_FRC_PHY_EN | RG_PE1_PHY_EN);
-	phy_write(instance, val, offset);
+	phy_write(mphy, val, offset);
 
 	return 0;
 }
@@ -263,15 +270,16 @@ static int mt7621_pci_phy_power_on(struct phy *phy)
 static int mt7621_pci_phy_power_off(struct phy *phy)
 {
 	struct mt7621_pci_phy_instance *instance = phy_get_drvdata(phy);
+	struct mt7621_pci_phy *mphy = dev_get_drvdata(phy->dev.parent);
 	u32 offset = (instance->index != 1) ?
 		RG_PE1_FRC_PHY_REG : RG_PE1_FRC_PHY_REG + RG_P0_TO_P1_WIDTH;
 	u32 val;
 
 	/* Disable PHY */
-	val = phy_read(instance, offset);
+	val = phy_read(mphy, offset);
 	val &= ~(RG_PE1_FRC_PHY_EN | RG_PE1_PHY_EN);
 	val |= RG_PE1_FRC_PHY_EN;
-	phy_write(instance, val, offset);
+	phy_write(mphy, val, offset);
 
 	return 0;
 }
@@ -311,6 +319,13 @@ static const struct soc_device_attribute mt7621_pci_quirks_match[] = {
 	{ .soc_id = "mt7621", .revision = "E2" }
 };
 
+static const struct regmap_config mt7621_pci_phy_regmap_config = {
+	.reg_bits = 32,
+	.val_bits = 32,
+	.reg_stride = 4,
+	.max_register = 0x700,
+};
+
 static int mt7621_pci_phy_probe(struct platform_device *pdev)
 {
 	struct device *dev = &pdev->dev;
@@ -350,6 +365,11 @@ static int mt7621_pci_phy_probe(struct platform_device *pdev)
 		return PTR_ERR(port_base);
 	}
 
+	phy->regmap = devm_regmap_init_mmio(phy->dev, port_base,
+					    &mt7621_pci_phy_regmap_config);
+	if (IS_ERR(phy->regmap))
+		return PTR_ERR(phy->regmap);
+
 	for (port = 0; port < MAX_PHYS; port++) {
 		struct mt7621_pci_phy_instance *instance;
 		struct phy *pphy;
-- 
2.19.1

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

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

end of thread, other threads:[~2019-04-17 11:58 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-17 11:58 [PATCH v2 0/4] staging: mt7621-pci-phy: driver cleanups Sergio Paracuellos
2019-04-17 11:58 ` [PATCH v2 1/4] staging: mt7621-pci-phy: use 'platform_get_resource' Sergio Paracuellos
2019-04-17 11:58 ` [PATCH v2 2/4] staging: mt7621-pci-phy: remove some unnecessary local variables Sergio Paracuellos
2019-04-17 11:58 ` [PATCH v2 3/4] staging: mt7621-pci-phy: add quirks for 'E2' revision using 'soc_device_attribute' Sergio Paracuellos
2019-04-17 11:58 ` [PATCH v2 4/4] staging: mt7621-pci-phy: convert driver to use kernel regmap API's Sergio Paracuellos

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.