|
61 | 61 | #include "chip.h" |
62 | 62 | #include "hardware/imx9_enet.h" |
63 | 63 | #include "imx9_enet.h" |
| 64 | +#include "imx9_clockconfig.h" |
64 | 65 |
|
65 | 66 | #include "imx9_ccm.h" |
66 | 67 | #include "imx9_iomuxc.h" |
|
128 | 129 |
|
129 | 130 | #define PHY_RESET_WAIT_COUNT (10) |
130 | 131 |
|
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 | | - |
141 | 132 | /* Interrupt groups */ |
142 | 133 |
|
143 | 134 | #define RX_INTERRUPTS (ENET_INT_RXF | ENET_INT_RXB) |
@@ -1928,12 +1919,43 @@ static int imx9_phyintenable(struct imx9_driver_s *priv) |
1928 | 1919 |
|
1929 | 1920 | static void imx9_initmii(struct imx9_driver_s *priv) |
1930 | 1921 | { |
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 |
1933 | 1955 | */ |
1934 | 1956 |
|
1935 | 1957 | imx9_enet_putreg32(priv, ENET_MSCR_HOLDTIME_2CYCLES | |
1936 | | - IMX9_MII_SPEED << ENET_MSCR_MII_SPEED_SHIFT, |
| 1958 | + divider << ENET_MSCR_MII_SPEED_SHIFT, |
1937 | 1959 | IMX9_ENET_MSCR_OFFSET); |
1938 | 1960 | } |
1939 | 1961 |
|
|
0 commit comments