summaryrefslogtreecommitdiff
path: root/common/cmd_nettest.c
blob: 249d7b612ea4d56d69afe8053901778cca354e54 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
/*
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*/

#include <common.h>
#include <command.h>
#include <COMMINF.H>

#ifdef SLT_UBOOT
extern int main_function(int argc, char *argv[]);

int do_mactest (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
{
    ModeSwitch = MODE_DEDICATED;
    return main_function( argc, argv);
}

int do_ncsitest (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
{
    ModeSwitch = MODE_NSCI;
    return main_function( argc, argv);
}

U_BOOT_CMD(
    mactest,    CONFIG_SYS_MAXARGS, 0,  do_mactest,
    "mactest - Dedicated LAN test program \n",
    NULL
);
U_BOOT_CMD(
    ncsitest,    CONFIG_SYS_MAXARGS, 0,  do_ncsitest,
    "ncsitest- Share LAN (NC-SI) test program \n",
    NULL
);

// ------------------------------------------------------------------------------
int do_phyread (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
{
    int     MACnum;
    int     PHYreg;
    ULONG   result_data;
    int     ret = 0;
    int     PHYaddr;
    int     timeout = 0;    

    do {
        if ( argc != 4 ) {
            printf(" Wrong parameter number.\n" );
            printf(" phyr mac addr reg\n"  );
            printf("   mac     : 0 or 1.   [hex]\n"  );
            printf("   PHY addr: 0 to 31.  [hex]\n"  );
            printf("   register: 0 to 0xFF.[hex]\n"  );
            printf(" example: phyr 0 0 1\n"  );
            ret = -1;
            break;
        }

        MACnum  = strtoul(argv[1], NULL, 16);
        PHYaddr = strtoul(argv[2], NULL, 16);
        PHYreg  = strtoul(argv[3], NULL, 16);
        
        if ( MACnum == 0 ) {
            // Set MAC 0
            H_MAC_BASE  = MAC_BASE1;
        }
        else if ( MACnum == 1 ) {
                // Set MAC 1
                H_MAC_BASE  = MAC_BASE2;
        }
        else {
            printf("wrong parameter (mac number)\n");
            ret = -1;
            break;
        }
        MAC_PHYBASE = H_MAC_BASE;
        
        if ( ( PHYaddr < 0 ) || ( PHYaddr > 31 ) ) {
            printf("wrong parameter (PHY address)\n");
            ret = -1;
            break;
        }
            
        MAC_40h_old = ReadSOC_DD( H_MAC_BASE + 0x40 );
        AST2300_NewMDIO = (MAC_40h_old & 0x80000000) ? 1 : 0;
        
        if ( AST2300_NewMDIO ) {
            WriteSOC_DD( MAC_PHYBASE + 0x60, MAC_PHYRd_New | (PHYaddr << 5) | ( PHYreg & 0x1f ) );
            while ( ReadSOC_DD( MAC_PHYBASE + 0x60 ) & MAC_PHYBusy_New ) {
                if ( ++timeout > TIME_OUT_PHY_RW ) {
                    ret = -1;
                    break;
                }
            }
            DELAY(Delay_PHYRd);
            result_data = ReadSOC_DD( MAC_PHYBASE + 0x64 ) & 0xffff;  
        } 
        else {
            WriteSOC_DD( MAC_PHYBASE + 0x60, MDC_Thres | MAC_PHYRd | (PHYaddr << 16) | ((PHYreg & 0x1f) << 21) );
            while ( ReadSOC_DD( MAC_PHYBASE + 0x60 ) & MAC_PHYRd ) {
                if ( ++timeout > TIME_OUT_PHY_RW ) {
                    ret = -1;
                    break;
                }
            }
            DELAY( Delay_PHYRd );
            result_data = ReadSOC_DD( MAC_PHYBASE + 0x64 ) >> 16;
        }
        printf(" PHY[%d] reg[%2X] = %08lX\n", PHYaddr, PHYreg, result_data ); 
    } while ( 0 );
    
    return ret;
}


int do_phywrite (cmd_tbl_t * cmdtp, int flag, int argc, char *argv[])
{
    int     MACnum;
    int     PHYreg;
    int     PHYaddr;
    ULONG   reg_data;
    int     ret     = 0;
    int     timeout = 0;    
    
    do {
        if ( argc != 5 )
        {
            printf(" Wrong parameter number.\n" );
            printf(" phyw mac addr reg data\n"  );
            printf("   mac     : 0 or 1.     [hex]\n"  );
            printf("   PHY addr: 0 to 31.    [hex]\n"  );
            printf("   register: 0 to 0xFF.  [hex]\n"  );
            printf("   data    : 0 to 0xFFFF.[hex]\n"  );
            printf(" example: phyw 0 0 0 610\n"  );
            ret = -1;
            break;
        }
        
        MACnum   = strtoul(argv[1], NULL, 16);
        PHYaddr  = strtoul(argv[2], NULL, 16);
        PHYreg   = strtoul(argv[3], NULL, 16);
        reg_data = strtoul(argv[4], NULL, 16);
        
        if ( MACnum == 0 ) {
            // Set MAC 0
            H_MAC_BASE  = MAC_BASE1;
        }
        else if ( MACnum == 1 ) {
                // Set MAC 1
                H_MAC_BASE  = MAC_BASE2;
        }
        else {
            printf("wrong parameter (mac number)\n");
            ret = -1;
            break;
        }
        MAC_PHYBASE = H_MAC_BASE;
        
        if ( ( PHYaddr < 0 ) || ( PHYaddr > 31 ) ) {
            printf("wrong parameter (PHY address)\n");
            ret = -1;
            break;
        }
        
        MAC_40h_old = ReadSOC_DD( H_MAC_BASE + 0x40 );
        AST2300_NewMDIO = (MAC_40h_old & 0x80000000) ? 1 : 0;
        
        if (AST2300_NewMDIO) {
            WriteSOC_DD( MAC_PHYBASE + 0x60, ( reg_data << 16 ) | MAC_PHYWr_New | (PHYaddr<<5) | (PHYreg & 0x1f));

            while ( ReadSOC_DD( MAC_PHYBASE + 0x60 ) & MAC_PHYBusy_New ) {
                if ( ++timeout > TIME_OUT_PHY_RW ) {
                    ret = -1;
                    break;
                }
            }
        } 
        else {
            WriteSOC_DD( MAC_PHYBASE + 0x64, reg_data );
            WriteSOC_DD( MAC_PHYBASE + 0x60, MDC_Thres | MAC_PHYWr | (PHYaddr<<16) | ((PHYreg & 0x1f) << 21));

            while ( ReadSOC_DD( MAC_PHYBASE + 0x60 ) & MAC_PHYWr ) {
                if ( ++timeout > TIME_OUT_PHY_RW ) {
                    ret = -1;
                    break;
                }
            }
        } // End if (AST2300_NewMDIO)
        
        printf("Write: PHY[%d] reg[%2X] = %08lX\n", PHYaddr, PHYreg, reg_data );     
    } while ( 0 );

    return ret;
}

U_BOOT_CMD(
    phyr,    CONFIG_SYS_MAXARGS, 0,  do_phyread,
    "phyr    - Read PHY register.  (phyr mac addr reg)\n",
    NULL
);

U_BOOT_CMD(
    phyw,    CONFIG_SYS_MAXARGS, 0,  do_phywrite,
    "phyw    - Write PHY register. (phyw mac addr reg data)\n",
    NULL
);

#endif // End SLT_UBOOT