Re: [PATCH v3] net: ftgmac100: Request clock and set speed

From: Andrew Jeffery
Date: Mon Oct 16 2017 - 22:00:37 EST


On Fri, 2017-10-13 at 12:16 +0800, Joel Stanley wrote:
> According to the ASPEED datasheet, gigabit speeds require a clock of
> 100MHz or higher. Other speeds require 25MHz or higher. This patch
> configures a 100MHz clock if the system has a direct-attached
> PHY, or 25MHz if the system is running NC-SI which is limited to 100MHz.
>Â
> There appear to be no other upstream users of the FTGMAC100 driver it is
> hard to know the clocking requirements of other platforms. Therefore a
> conservative approach was taken with enabling clocks. If the platform is
> not ASPEED, both requesting the clock and configuring the speed is
> skipped.
>Â
> Signed-off-by: Joel Stanley <joel@xxxxxxxxx>

Tested on an AST2500 EVB and an OpenPOWER Palmetto (AST2400) machine.
Confirmed clock rates were nominally what was requested, and successfully
downloaded a 100MB test file.

Tested-by: Andrew Jeffery <andrew@xxxxxxxx>

> ---
> Andrew, can you please give this one a spin on hardware?
>Â
> v3:
> Â- Fix errors from v2
> v2:
> Â- only touch the clocks on Aspeed platforms
> Â- unconditionally call clk_unprepare_disable
>Â
> Âdrivers/net/ethernet/faraday/ftgmac100.c | 26 ++++++++++++++++++++++++++
> Â1 file changed, 26 insertions(+)
>Â
> diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
> index 9ed8e4b81530..78db8e62a83f 100644
> --- a/drivers/net/ethernet/faraday/ftgmac100.c
> +++ b/drivers/net/ethernet/faraday/ftgmac100.c
> @@ -21,6 +21,7 @@
> Â
> Â#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
> Â
> +#include <linux/clk.h>
> Â#include <linux/dma-mapping.h>
> Â#include <linux/etherdevice.h>
> Â#include <linux/ethtool.h>
> @@ -59,6 +60,9 @@
> Â/* Min number of tx ring entries before stopping queue */
> Â#define TX_THRESHOLD (MAX_SKB_FRAGS + 1)
> Â
> +#define FTGMAC_100MHZ 100000000
> +#define FTGMAC_25MHZ 25000000
> +
> Âstruct ftgmac100 {
> Â /* Registers */
> Â struct resource *res;
> @@ -96,6 +100,7 @@ struct ftgmac100 {
> Â struct napi_struct napi;
> Â struct work_struct reset_task;
> Â struct mii_bus *mii_bus;
> + struct clk *clk;
> Â
> Â /* Link management */
> Â int cur_speed;
> @@ -1734,6 +1739,22 @@ static void ftgmac100_ncsi_handler(struct ncsi_dev *nd)
> Â ÂÂÂÂnd->link_up ? "up" : "down");
> Â}
> Â
> +static void ftgmac100_setup_clk(struct ftgmac100 *priv)
> +{
> + priv->clk = devm_clk_get(priv->dev, NULL);
> + if (IS_ERR(priv->clk))
> + return;
> +
> + clk_prepare_enable(priv->clk);
> +
> + /* Aspeed specifies a 100MHz clock is required for up to
> + Â* 1000Mbit link speeds. As NCSI is limited to 100Mbit, 25MHz
> + Â* is sufficient
> + Â*/
> + clk_set_rate(priv->clk, priv->use_ncsi ? FTGMAC_25MHZ :
> + FTGMAC_100MHZ);
> +}
> +
> Âstatic int ftgmac100_probe(struct platform_device *pdev)
> Â{
> Â struct resource *res;
> @@ -1830,6 +1851,9 @@ static int ftgmac100_probe(struct platform_device *pdev)
> Â goto err_setup_mdio;
> Â }
> Â
> + if (priv->is_aspeed)
> + ftgmac100_setup_clk(priv);
> +
> Â /* Default ring sizes */
> Â priv->rx_q_entries = priv->new_rx_q_entries = DEF_RX_QUEUE_ENTRIES;
> Â priv->tx_q_entries = priv->new_tx_q_entries = DEF_TX_QUEUE_ENTRIES;
> @@ -1883,6 +1907,8 @@ static int ftgmac100_remove(struct platform_device *pdev)
> Â
> Â unregister_netdev(netdev);
> Â
> + clk_disable_unprepare(priv->clk);
> +
> Â /* There's a small chance the reset task will have been re-queued,
> Â Â* during stop, make sure it's gone before we free the structure.
> Â Â*/

Attachment: signature.asc
Description: This is a digitally signed message part