116-net-macb-add-capability-to-not-set-the-clock-rate.patch 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. From 1b15259551b701f416aa024050a2e619860bd0d8 Mon Sep 17 00:00:00 2001
  2. From: Claudiu Beznea <[email protected]>
  3. Date: Wed, 9 Dec 2020 15:03:33 +0200
  4. Subject: [PATCH 116/247] net: macb: add capability to not set the clock rate
  5. SAMA7G5's ethernet IPs TX clock could be provided by its generic clock or
  6. by the external clock provided by the PHY. The internal IP logic divides
  7. properly this clock depending on the link speed. The patch adds a new
  8. capability so that macb_set_tx_clock() to not be called for IPs having
  9. this capability (the clock rate, in case of generic clock, is set at the
  10. boot time via device tree and the driver only enables it).
  11. Signed-off-by: Claudiu Beznea <[email protected]>
  12. Reviewed-by: Andrew Lunn <[email protected]>
  13. Signed-off-by: David S. Miller <[email protected]>
  14. ---
  15. drivers/net/ethernet/cadence/macb.h | 1 +
  16. drivers/net/ethernet/cadence/macb_main.c | 18 +++++++++---------
  17. 2 files changed, 10 insertions(+), 9 deletions(-)
  18. diff --git a/drivers/net/ethernet/cadence/macb.h b/drivers/net/ethernet/cadence/macb.h
  19. index e9385a1390a9..23d294748779 100644
  20. --- a/drivers/net/ethernet/cadence/macb.h
  21. +++ b/drivers/net/ethernet/cadence/macb.h
  22. @@ -658,6 +658,7 @@
  23. #define MACB_CAPS_GEM_HAS_PTP 0x00000040
  24. #define MACB_CAPS_BD_RD_PREFETCH 0x00000080
  25. #define MACB_CAPS_NEEDS_RSTONUBR 0x00000100
  26. +#define MACB_CAPS_CLK_HW_CHG 0x04000000
  27. #define MACB_CAPS_MACB_IS_EMAC 0x08000000
  28. #define MACB_CAPS_FIFO_MODE 0x10000000
  29. #define MACB_CAPS_GIGABIT_MODE_AVAILABLE 0x20000000
  30. diff --git a/drivers/net/ethernet/cadence/macb_main.c b/drivers/net/ethernet/cadence/macb_main.c
  31. index a8326b75eca8..5d0d11eb6711 100644
  32. --- a/drivers/net/ethernet/cadence/macb_main.c
  33. +++ b/drivers/net/ethernet/cadence/macb_main.c
  34. @@ -457,15 +457,14 @@ static void macb_init_buffers(struct macb *bp)
  35. /**
  36. * macb_set_tx_clk() - Set a clock to a new frequency
  37. - * @clk: Pointer to the clock to change
  38. + * @bp: pointer to struct macb
  39. * @speed: New frequency in Hz
  40. - * @dev: Pointer to the struct net_device
  41. */
  42. -static void macb_set_tx_clk(struct clk *clk, int speed, struct net_device *dev)
  43. +static void macb_set_tx_clk(struct macb *bp, int speed)
  44. {
  45. long ferr, rate, rate_rounded;
  46. - if (!clk)
  47. + if (!bp->tx_clk || !(bp->caps & MACB_CAPS_CLK_HW_CHG))
  48. return;
  49. switch (speed) {
  50. @@ -482,7 +481,7 @@ static void macb_set_tx_clk(struct clk *clk, int speed, struct net_device *dev)
  51. return;
  52. }
  53. - rate_rounded = clk_round_rate(clk, rate);
  54. + rate_rounded = clk_round_rate(bp->tx_clk, rate);
  55. if (rate_rounded < 0)
  56. return;
  57. @@ -492,11 +491,12 @@ static void macb_set_tx_clk(struct clk *clk, int speed, struct net_device *dev)
  58. ferr = abs(rate_rounded - rate);
  59. ferr = DIV_ROUND_UP(ferr, rate / 100000);
  60. if (ferr > 5)
  61. - netdev_warn(dev, "unable to generate target frequency: %ld Hz\n",
  62. + netdev_warn(bp->dev,
  63. + "unable to generate target frequency: %ld Hz\n",
  64. rate);
  65. - if (clk_set_rate(clk, rate_rounded))
  66. - netdev_err(dev, "adjusting tx_clk failed.\n");
  67. + if (clk_set_rate(bp->tx_clk, rate_rounded))
  68. + netdev_err(bp->dev, "adjusting tx_clk failed.\n");
  69. }
  70. static void macb_validate(struct phylink_config *config,
  71. @@ -649,7 +649,7 @@ static void macb_mac_link_up(struct phylink_config *config,
  72. if (rx_pause)
  73. ctrl |= MACB_BIT(PAE);
  74. - macb_set_tx_clk(bp->tx_clk, speed, ndev);
  75. + macb_set_tx_clk(bp, speed);
  76. /* Initialize rings & buffers as clearing MACB_BIT(TE) in link down
  77. * cleared the pipeline and control registers.
  78. --
  79. 2.32.0