Skip to content

Commit 966be68

Browse files
arikimarilupyuen
authored andcommitted
arch/imx9/enet: Add MII clock calculation
Add MII clock calculation from root clock Remove MII clock divider define Signed-off-by: Ari Kimari <ari.kimari@tii.ae>
1 parent c036d23 commit 966be68

1 file changed

Lines changed: 35 additions & 13 deletions

File tree

arch/arm64/src/imx9/imx9_enet.c

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
#include "chip.h"
6262
#include "hardware/imx9_enet.h"
6363
#include "imx9_enet.h"
64+
#include "imx9_clockconfig.h"
6465

6566
#include "imx9_ccm.h"
6667
#include "imx9_iomuxc.h"
@@ -128,16 +129,6 @@
128129

129130
#define PHY_RESET_WAIT_COUNT (10)
130131

131-
/* Estimate the MII_SPEED in order to get an MDC close to 2.5MHz,
132-
* based on the internal module (ENET) clock:
133-
134-
* MII clock frequency = 133 MHz / ((26 + 1) x 2) = 2.5 MHz
135-
*
136-
* TODO: This is hard-coded for now, could be properly calculated
137-
*/
138-
139-
#define IMX9_MII_SPEED 26
140-
141132
/* Interrupt groups */
142133

143134
#define RX_INTERRUPTS (ENET_INT_RXF | ENET_INT_RXB)
@@ -1928,12 +1919,43 @@ static int imx9_phyintenable(struct imx9_driver_s *priv)
19281919

19291920
static void imx9_initmii(struct imx9_driver_s *priv)
19301921
{
1931-
/* Speed is based on the peripheral (bus) clock; hold time is 2 module
1932-
* clock. This hold time value may need to be increased on some platforms
1922+
uint32_t divider;
1923+
uint32_t freq = 0;
1924+
1925+
/* Wakeup_axi_clk is root clock for MII */
1926+
1927+
imx9_get_rootclock(CCM_WAKEUP_AXI_CLK_ROOT, &freq);
1928+
if (!freq)
1929+
{
1930+
nerr("Root clock is zero\n");
1931+
return;
1932+
}
1933+
1934+
/* MII clock frequency must be <= 2,5 MHz
1935+
*
1936+
* Divider = (root clock / (2 * 2,5MHZ)) - 1
1937+
*
1938+
*/
1939+
1940+
divider = freq / 5000000;
1941+
1942+
/* round up */
1943+
1944+
if (freq % 5000000)
1945+
{
1946+
divider++;
1947+
}
1948+
1949+
divider--;
1950+
1951+
DEBUGASSERT(divider > 0 && divider < 64);
1952+
1953+
/* Hold time is 2 module clock. This hold time value may need
1954+
* to be increased on some platforms
19331955
*/
19341956

19351957
imx9_enet_putreg32(priv, ENET_MSCR_HOLDTIME_2CYCLES |
1936-
IMX9_MII_SPEED << ENET_MSCR_MII_SPEED_SHIFT,
1958+
divider << ENET_MSCR_MII_SPEED_SHIFT,
19371959
IMX9_ENET_MSCR_OFFSET);
19381960
}
19391961

0 commit comments

Comments
 (0)