linux-mips.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Andrew Murray <andrew.murray@arm.com>
To: Jiaxun Yang <jiaxun.yang@flygoat.com>
Cc: linux-mips@vger.kernel.org, davem@davemloft.net,
	robh+dt@kernel.org, mark.rutland@arm.com, axboe@kernel.dk,
	peppe.cavallaro@st.com, alexandre.torgue@st.com,
	joabreu@synopsys.com, bhelgaas@google.com,
	netdev@vger.kernel.org, devicetree@vger.kernel.org,
	linux-ide@vger.kernel.org, linux-pci@vger.kernel.org
Subject: Re: [PATCH 2/5] net: stmmac: Split devicetree parse
Date: Fri, 1 Nov 2019 12:18:04 +0000	[thread overview]
Message-ID: <20191101121802.GD9723@e119886-lin.cambridge.arm.com> (raw)
In-Reply-To: <20191030135347.3636-3-jiaxun.yang@flygoat.com>

On Wed, Oct 30, 2019 at 09:53:44PM +0800, Jiaxun Yang wrote:
> PCI based devices can share devicetree info parse with platform
> device based devices after split dt parse frpm dt probe.

s/frpm/from/

> 
> Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
> ---
>  .../ethernet/stmicro/stmmac/stmmac_platform.c | 63 ++++++++++++++-----
>  .../ethernet/stmicro/stmmac/stmmac_platform.h |  3 +
>  2 files changed, 49 insertions(+), 17 deletions(-)
> 
> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
> index 170c3a052b14..7e29bc76b7c3 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.c
> @@ -385,25 +385,19 @@ static int stmmac_of_get_mac_mode(struct device_node *np)
>  }
>  
>  /**
> - * stmmac_probe_config_dt - parse device-tree driver parameters
> - * @pdev: platform_device structure
> - * @mac: MAC address to use
> + * stmmac_parse_config_dt - parse device-tree driver parameters
> + * @np: device_mode structure
> + * @plat: plat_stmmacenet_data structure
>   * Description:
>   * this function is to read the driver parameters from device-tree and
>   * set some private fields that will be used by the main at runtime.
>   */
> -struct plat_stmmacenet_data *
> -stmmac_probe_config_dt(struct platform_device *pdev, const char **mac)
> +int stmmac_parse_config_dt(struct device_node *np,
> +				struct plat_stmmacenet_data *plat)
>  {
> -	struct device_node *np = pdev->dev.of_node;
> -	struct plat_stmmacenet_data *plat;
>  	struct stmmac_dma_cfg *dma_cfg;
>  	int rc;
>  
> -	plat = devm_kzalloc(&pdev->dev, sizeof(*plat), GFP_KERNEL);
> -	if (!plat)
> -		return ERR_PTR(-ENOMEM);
> -
>  	*mac = of_get_mac_address(np);
>  	if (IS_ERR(*mac)) {
>  		if (PTR_ERR(*mac) == -EPROBE_DEFER)
> @@ -414,7 +408,7 @@ stmmac_probe_config_dt(struct platform_device *pdev, const char **mac)
>  
>  	plat->phy_interface = of_get_phy_mode(np);
>  	if (plat->phy_interface < 0)
> -		return ERR_PTR(plat->phy_interface);
> +		return plat->phy_interface;
>  
>  	plat->interface = stmmac_of_get_mac_mode(np);
>  	if (plat->interface < 0)
> @@ -453,7 +447,7 @@ stmmac_probe_config_dt(struct platform_device *pdev, const char **mac)
>  	/* To Configure PHY by using all device-tree supported properties */
>  	rc = stmmac_dt_phy(plat, np, &pdev->dev);
>  	if (rc)
> -		return ERR_PTR(rc);
> +		return rc;
>  
>  	of_property_read_u32(np, "tx-fifo-depth", &plat->tx_fifo_size);
>  
> @@ -531,7 +525,7 @@ stmmac_probe_config_dt(struct platform_device *pdev, const char **mac)
>  			       GFP_KERNEL);
>  	if (!dma_cfg) {
>  		stmmac_remove_config_dt(pdev, plat);
> -		return ERR_PTR(-ENOMEM);
> +		return -ENOMEM;
>  	}
>  	plat->dma_cfg = dma_cfg;
>  
> @@ -560,7 +554,7 @@ stmmac_probe_config_dt(struct platform_device *pdev, const char **mac)
>  	rc = stmmac_mtl_setup(pdev, plat);
>  	if (rc) {
>  		stmmac_remove_config_dt(pdev, plat);
> -		return ERR_PTR(rc);
> +		return rc;
>  	}
>  
>  	/* clock setup */
> @@ -604,14 +598,43 @@ stmmac_probe_config_dt(struct platform_device *pdev, const char **mac)
>  		plat->stmmac_rst = NULL;
>  	}
>  
> -	return plat;
> +	return 0;
>  
>  error_hw_init:
>  	clk_disable_unprepare(plat->pclk);
>  error_pclk_get:
>  	clk_disable_unprepare(plat->stmmac_clk);
>  
> -	return ERR_PTR(-EPROBE_DEFER);
> +	return -EPROBE_DEFER;
> +}
> +
> +/**
> + * stmmac_probe_config_dt - probe and setup stmmac platform data by devicetree
> + * @pdev: platform_device structure
> + * @mac: MAC address to use
> + * Description:
> + * this function is to set up plat_stmmacenet_data  private structure
> + * for platform drivers.
> + */
> +struct plat_stmmacenet_data *
> +stmmac_probe_config_dt(struct platform_device *pdev, const char **mac)
> +{
> +	struct device_node *np = pdev->dev.of_node;
> +	struct plat_stmmacenet_data *plat;
> +	int rc;
> +
> +	plat = devm_kzalloc(&pdev->dev, sizeof(*plat), GFP_KERNEL);
> +	if (!plat)
> +		return ERR_PTR(-ENOMEM);
> +
> +	rc = stmmac_parse_config_dt(np, plat);
> +
> +	if (rc) {
> +		free(plat);

Given the devm_kzalloc - is the free really needed here?

Thanks,

Andrew Murray

> +		return ERR_PTR(rc);
> +	}
> +
> +	return plat;
>  }
>  
>  /**
> @@ -628,6 +651,11 @@ void stmmac_remove_config_dt(struct platform_device *pdev,
>  	of_node_put(plat->mdio_node);
>  }
>  #else
> +int stmmac_parse_config_dt(struct device_node *np,
> +				struct plat_stmmacenet_data *plat)
> +{
> +	return -EINVAL;
> +}
>  struct plat_stmmacenet_data *
>  stmmac_probe_config_dt(struct platform_device *pdev, const char **mac)
>  {
> @@ -639,6 +667,7 @@ void stmmac_remove_config_dt(struct platform_device *pdev,
>  {
>  }
>  #endif /* CONFIG_OF */
> +EXPORT_SYMBOL_GPL(stmmac_parse_config_dt);
>  EXPORT_SYMBOL_GPL(stmmac_probe_config_dt);
>  EXPORT_SYMBOL_GPL(stmmac_remove_config_dt);
>  
> diff --git a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.h b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.h
> index 3a4663b7b460..0e4aec1f502a 100644
> --- a/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.h
> +++ b/drivers/net/ethernet/stmicro/stmmac/stmmac_platform.h
> @@ -11,6 +11,9 @@
>  
>  #include "stmmac.h"
>  
> +int stmmac_parse_config_dt(struct device_node *np,
> +				struct plat_stmmacenet_data *plat);
> +
>  struct plat_stmmacenet_data *
>  stmmac_probe_config_dt(struct platform_device *pdev, const char **mac);
>  void stmmac_remove_config_dt(struct platform_device *pdev,
> -- 
> 2.23.0
> 

  reply	other threads:[~2019-11-01 12:18 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-30 13:53 [PATCH 0/5] PCI Devices for Loongson PCH Jiaxun Yang
2019-10-30 13:53 ` [PATCH 1/5] PCI: pci_ids: Add Loongson IDs Jiaxun Yang
2019-10-30 20:40   ` Bjorn Helgaas
2019-10-30 13:53 ` [PATCH 2/5] net: stmmac: Split devicetree parse Jiaxun Yang
2019-11-01 12:18   ` Andrew Murray [this message]
2019-11-01 22:43   ` kbuild test robot
2019-10-30 13:53 ` [PATCH 3/5] net: stmmac: pci: Add Loongson GMAC Jiaxun Yang
2019-10-30 20:36   ` Bjorn Helgaas
2019-10-30 13:53 ` [PATCH 4/5] dt-bindings: net: document loongson.pci-gmac Jiaxun Yang
2019-10-31  8:35   ` Simon Horman
2019-10-31 10:57     ` Jiaxun Yang
2019-10-31 20:42       ` Simon Horman
2019-10-30 13:53 ` [PATCH 5/5] libata/ahci: Apply non-standard BAR fix for Loongson Jiaxun Yang
2019-10-31 10:39   ` John Garry

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=20191101121802.GD9723@e119886-lin.cambridge.arm.com \
    --to=andrew.murray@arm.com \
    --cc=alexandre.torgue@st.com \
    --cc=axboe@kernel.dk \
    --cc=bhelgaas@google.com \
    --cc=davem@davemloft.net \
    --cc=devicetree@vger.kernel.org \
    --cc=jiaxun.yang@flygoat.com \
    --cc=joabreu@synopsys.com \
    --cc=linux-ide@vger.kernel.org \
    --cc=linux-mips@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=mark.rutland@arm.com \
    --cc=netdev@vger.kernel.org \
    --cc=peppe.cavallaro@st.com \
    --cc=robh+dt@kernel.org \
    /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 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).