Skip to contentSkip to conversation

net: stmmac: platform: use generic device api

PATCH In review Ajay Gupta 4 participants 5 messages Jan 16, 2020 – Jan 17, 2020

Subsystems (4)
lore
Share & tools
lore

Ajay Gupta

author
#0 lore raw

PATCH 1/1 net: stmmac: platform: use generic device api

From: Ajay Gupta <[email protected]>

Use generic device api to allow reading more configuration parameter from both DT or ACPI based devices.

---
ACPI support related changes for dwc were reently queued [1] This patch is required to read more configuration parameter through ACPI table.

[1] https://marc.info/?l=linux-netdev&m=157661974305024&w=2

 .../ethernet/stmicro/stmmac/stmmac_platform.c | 49 +++++++++++--------
 1 file changed, 28 insertions(+), 21 deletions(-)
drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c +28 -21
index 4775f49d7f3b..0532e7258064 100644
@@ -398,6 +398,7 @@ stmmac_probe_config_dt(struct platform_device *pdev, const char **mac)
 	struct device_node *np = pdev->dev.of_node;
 	struct plat_stmmacenet_data *plat;
 	struct stmmac_dma_cfg *dma_cfg;
+	struct device *dev = &pdev->dev;
 	int rc;
 
 	plat = devm_kzalloc(&pdev->dev, sizeof(*plat), GFP_KERNEL);
@@ -412,9 +413,9 @@ stmmac_probe_config_dt(struct platform_device *pdev, const char **mac)
 		*mac = NULL;
 	}
 
-	rc = of_get_phy_mode(np, &plat->phy_interface);
-	if (rc)
-		return ERR_PTR(rc);
+	plat->phy_interface = device_get_phy_mode(dev);
+	if (plat->phy_interface < 0)
+		return ERR_PTR(plat->phy_interface);
 
 	plat->interface = stmmac_of_get_mac_mode(np);
 	if (plat->interface < 0)
@@ -428,7 +429,7 @@ stmmac_probe_config_dt(struct platform_device *pdev, const char **mac)
 	plat->phylink_node = np;
 
 	/* Get max speed of operation from device tree */
-	if (of_property_read_u32(np, "max-speed", &plat->max_speed))
+	if (device_property_read_u32(dev, "max-speed", &plat->max_speed))
 		plat->max_speed = -1;
 
 	plat->bus_id = of_alias_get_id(np, "ethernet");
@@ -442,12 +443,13 @@ stmmac_probe_config_dt(struct platform_device *pdev, const char **mac)
 	 * or get clk_csr from device tree.
 	 */
 	plat->clk_csr = -1;
-	of_property_read_u32(np, "clk_csr", &plat->clk_csr);
+	device_property_read_u32(dev, "clk_csr", &plat->clk_csr);
 
 	/* "snps,phy-addr" is not a standard property. Mark it as deprecated
 	 * and warn of its use. Remove this when phy node support is added.
 	 */
-	if (of_property_read_u32(np, "snps,phy-addr", &plat->phy_addr) == 0)
+	if (device_property_read_u32(dev, "snps,phy-addr", &plat->phy_addr)
+			== 0)
 		dev_warn(&pdev->dev, "snps,phy-addr property is deprecated\n");
 
 	/* To Configure PHY by using all device-tree supported properties */
@@ -455,15 +457,15 @@ stmmac_probe_config_dt(struct platform_device *pdev, const char **mac)
 	if (rc)
 		return ERR_PTR(rc);
 
-	of_property_read_u32(np, "tx-fifo-depth", &plat->tx_fifo_size);
+	device_property_read_u32(dev, "tx-fifo-depth", &plat->tx_fifo_size);
 
-	of_property_read_u32(np, "rx-fifo-depth", &plat->rx_fifo_size);
+	device_property_read_u32(dev, "rx-fifo-depth", &plat->rx_fifo_size);
 
 	plat->force_sf_dma_mode =
-		of_property_read_bool(np, "snps,force_sf_dma_mode");
+		device_property_read_bool(dev, "snps,force_sf_dma_mode");
 
 	plat->en_tx_lpi_clockgating =
-		of_property_read_bool(np, "snps,en-tx-lpi-clockgating");
+		device_property_read_bool(dev, "snps,en-tx-lpi-clockgating");
 
 	/* Set the maxmtu to a default of JUMBO_LEN in case the
 	 * parameter is not present in the device tree.
@@ -535,25 +537,30 @@ stmmac_probe_config_dt(struct platform_device *pdev, const char **mac)
 	}
 	plat->dma_cfg = dma_cfg;
 
-	of_property_read_u32(np, "snps,pbl", &dma_cfg->pbl);
+	device_property_read_u32(dev, "snps,pbl", &dma_cfg->pbl);
 	if (!dma_cfg->pbl)
 		dma_cfg->pbl = DEFAULT_DMA_PBL;
-	of_property_read_u32(np, "snps,txpbl", &dma_cfg->txpbl);
-	of_property_read_u32(np, "snps,rxpbl", &dma_cfg->rxpbl);
-	dma_cfg->pblx8 = !of_property_read_bool(np, "snps,no-pbl-x8");
-
-	dma_cfg->aal = of_property_read_bool(np, "snps,aal");
-	dma_cfg->fixed_burst = of_property_read_bool(np, "snps,fixed-burst");
-	dma_cfg->mixed_burst = of_property_read_bool(np, "snps,mixed-burst");
-
-	plat->force_thresh_dma_mode = of_property_read_bool(np, "snps,force_thresh_dma_mode");
+	device_property_read_u32(dev, "snps,txpbl", &dma_cfg->txpbl);
+	device_property_read_u32(dev, "snps,rxpbl", &dma_cfg->rxpbl);
+	dma_cfg->pblx8 = !device_property_read_bool(dev, "snps,no-pbl-x8");
+
+	dma_cfg->aal = device_property_read_bool(dev, "snps,aal");
+	dma_cfg->fixed_burst = device_property_read_bool(dev,
+							 "snps,fixed-burst");
+	dma_cfg->mixed_burst = device_property_read_bool(dev,
+							 "snps,mixed-burst");
+
+	plat->force_thresh_dma_mode =
+			device_property_read_bool(dev,
+						  "snps,force_thresh_dma_mode");
 	if (plat->force_thresh_dma_mode) {
 		plat->force_sf_dma_mode = 0;
 		dev_warn(&pdev->dev,
 			 "force_sf_dma_mode is ignored if force_thresh_dma_mode is set.\n");
 	}
 
-	of_property_read_u32(np, "snps,ps-speed", &plat->mac_port_sel_speed);
+	device_property_read_u32(dev, "snps,ps-speed",
+				 &plat->mac_port_sel_speed);
 
 	plat->axi = stmmac_axi_setup(pdev);
 
Signature · 1 line
2.17.1
#1 lore raw

Hi,

Quoted 7 lines · Ajay Gupta

From: Ajay Gupta <[email protected]>

Use generic device api to allow reading more configuration parameter from both DT or ACPI based devices.

Quoted 8 lines

---
ACPI support related changes for dwc were reently queued [1] This patch is required to read more configuration parameter through ACPI table.

[1] https://marc.info/?l=linux-netdev&m=157661974305024&w=2

 .../ethernet/stmicro/stmmac/stmmac_platform.c | 49 +++++++++++--------

Even after your changes, there's still a lot of DT specific code in there, such as the MDIO device node parsing. Plus the whole thing is wrapped in "#ifdef CONFIG_OF".

Maybe it would make more sense to split out the generic device API parts into a separate function?

Regards
ChenYu

#2 lore raw

Hi ChenYu

Quoted 31 lines

-----Original Message-----
From: Chen-Yu Tsai <[email protected]>
Sent: Thursday, January 16, 2020 7:34 PM
To: Ajay Gupta <[email protected]>
Cc: David Miller <[email protected]>; netdev <[email protected]>; Thierry Reding <[email protected]>; Ajay Gupta <[email protected]>
Subject: Re: [PATCH] net: stmmac: platform: use generic device api

External email: Use caution opening links or attachments

Hi,

Quoted 12 lines · Ajay Gupta

From: Ajay Gupta <[email protected]>

Use generic device api to allow reading more configuration parameter from both DT or ACPI based devices.

---
ACPI support related changes for dwc were reently queued [1] This patch is required to read more configuration parameter through ACPI table.

Quoted 4 lines

[1] https://marc.info/?l=linux-netdev&m=157661974305024&w=2

 .../ethernet/stmicro/stmmac/stmmac_platform.c | 49

+++++++++++--------

Quoted 6 lines

Even after your changes, there's still a lot of DT specific code in there, such as the MDIO device node parsing. Plus the whole thing is wrapped in "#ifdef CONFIG_OF".

Maybe it would make more sense to split out the generic device API parts into a separate function?

I am testing ACPI based device for dwmac-dwc-qos-eth controller. Also found that " phy_node " structure used across other controllers (dwmac-rk, dwmac-sun8i) plat->phy_node = of_parse_phandle(np, "phy-handle", 0);

It will require changes in other drivers and testing them. I don't have hardware for other controllers.
I am trying to add minimal change what can be tested in context of dwmac-dwc-qos-eth.

Thanks
Ajay

Quoted 4 lines

nvpublic

Regards
ChenYu

#4 lore raw

Hi Jose

Quoted 8 lines

-----Original Message-----
From: Jose Abreu <[email protected]>
Sent: Friday, January 17, 2020 12:29 AM
To: Ajay Gupta <[email protected]>; [email protected]
Cc: [email protected]; Thierry Reding <[email protected]>; Ajay Gupta <[email protected]>
Subject: RE: [PATCH] net: stmmac: platform: use generic device api

Quoted 4 lines

External email: Use caution opening links or attachments

Please cc' your patches according to "scripts/get_maintainer.pl" output.

Sure, will do that.

Quoted 4 lines

nvpublic
---
Thanks,
Jose Miguel Abreu