1 /**********************************************************************************
2 * FILE PURPOSE: A very simple mdio driver
3 **********************************************************************************
4 * FILE NAME: mdio.c
5 *
6 * DESCRIPTION: Enables mdio and performs blind access
7 *
8 * @file mdio.c
9 *
10 * @brief
11 * Enables mdio and performs blind access
12 *
13 **********************************************************************************/
14 #include "types.h"
15 #include "mdio.h"
16 #include "device.h"
18 /***********************************************************************************
19 * FUNCTION PURPOSE: Provide an approximate delay
20 ***********************************************************************************
21 * DESCRIPTION: A delay in units of CPU cycles is executed
22 ***********************************************************************************/
23 void mdio_delay (uint32 del)
24 {
25 volatile unsigned int i;
27 for (i = 0; i < del/8; i++);
29 }
31 /***********************************************************************************
32 * FUNCTION PURPOSE: Perform blind MDIO access
33 ***********************************************************************************
34 * DESCRIPTION: Pre-configured mdio access is performed.
35 ***********************************************************************************/
36 void hwMdio (int16 nAccess, uint32 *access, uint16 clkdiv, uint32 delayCpuCycles)
37 {
38 int16 i;
40 /* Enable MDIO, set the divider. A divider value of 0 is not allowed */
41 if (clkdiv == 0)
42 clkdiv = 1;
44 MDIOR->CONTROL = (0x40000000 | clkdiv);
47 for (i = 0; i < nAccess; i++) {
49 /* Set the Go bit */
50 MDIOR->USERACCESS0 = (((uint32)1 << 31) | access[i]);
51 while (MDIOR->USERACCESS0 & 0x80000000);
53 mdio_delay (delayCpuCycles);
55 }
57 /* A big delay after the last configure */
58 mdio_delay (1000000);
60 }