Skip to content

Commit 4b70c62

Browse files
shenkidavem330
authored andcommitted
net: ftgmac100: Request clock and set speed
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@jms.id.au> Tested-by: Andrew Jeffery <andrew@aj.id.au> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 8a5f216 commit 4b70c62

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

drivers/net/ethernet/faraday/ftgmac100.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121

2222
#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
2323

24+
#include <linux/clk.h>
2425
#include <linux/dma-mapping.h>
2526
#include <linux/etherdevice.h>
2627
#include <linux/ethtool.h>
@@ -59,6 +60,9 @@
5960
/* Min number of tx ring entries before stopping queue */
6061
#define TX_THRESHOLD (MAX_SKB_FRAGS + 1)
6162

63+
#define FTGMAC_100MHZ 100000000
64+
#define FTGMAC_25MHZ 25000000
65+
6266
struct ftgmac100 {
6367
/* Registers */
6468
struct resource *res;
@@ -96,6 +100,7 @@ struct ftgmac100 {
96100
struct napi_struct napi;
97101
struct work_struct reset_task;
98102
struct mii_bus *mii_bus;
103+
struct clk *clk;
99104

100105
/* Link management */
101106
int cur_speed;
@@ -1734,6 +1739,22 @@ static void ftgmac100_ncsi_handler(struct ncsi_dev *nd)
17341739
nd->link_up ? "up" : "down");
17351740
}
17361741

1742+
static void ftgmac100_setup_clk(struct ftgmac100 *priv)
1743+
{
1744+
priv->clk = devm_clk_get(priv->dev, NULL);
1745+
if (IS_ERR(priv->clk))
1746+
return;
1747+
1748+
clk_prepare_enable(priv->clk);
1749+
1750+
/* Aspeed specifies a 100MHz clock is required for up to
1751+
* 1000Mbit link speeds. As NCSI is limited to 100Mbit, 25MHz
1752+
* is sufficient
1753+
*/
1754+
clk_set_rate(priv->clk, priv->use_ncsi ? FTGMAC_25MHZ :
1755+
FTGMAC_100MHZ);
1756+
}
1757+
17371758
static int ftgmac100_probe(struct platform_device *pdev)
17381759
{
17391760
struct resource *res;
@@ -1830,6 +1851,9 @@ static int ftgmac100_probe(struct platform_device *pdev)
18301851
goto err_setup_mdio;
18311852
}
18321853

1854+
if (priv->is_aspeed)
1855+
ftgmac100_setup_clk(priv);
1856+
18331857
/* Default ring sizes */
18341858
priv->rx_q_entries = priv->new_rx_q_entries = DEF_RX_QUEUE_ENTRIES;
18351859
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)
18831907

18841908
unregister_netdev(netdev);
18851909

1910+
clk_disable_unprepare(priv->clk);
1911+
18861912
/* There's a small chance the reset task will have been re-queued,
18871913
* during stop, make sure it's gone before we free the structure.
18881914
*/

0 commit comments

Comments
 (0)