lixuefeng
8 years ago
14 changed files with 4928 additions and 52 deletions
File diff suppressed because it is too large
@ -0,0 +1,198 @@ |
|||
#ifndef _GMAC_H_ |
|||
#define _GMAC_H_ |
|||
|
|||
#define u16 unsigned short |
|||
#if 0 |
|||
#define GMAC0_MAC_REG_ADDR 0xffffffffbbe10000 |
|||
#define GMAC0_DMA_REG_ADDR 0xffffffffbbe11000 |
|||
#define GMAC1_MAC_REG_ADDR 0xffffffffbbe18000 |
|||
#define GMAC1_DMA_REG_ADDR 0xffffffffbbe19000 |
|||
|
|||
#define GMAC0_RX_DESC_BASE 0x9000000000060000 |
|||
#define GMAC1_RX_DESC_BASE 0x9000000000060200 |
|||
#define GMAC0_RX_DESC_BASE_PHY 0x60000 |
|||
|
|||
#define GMAC0_RDES0_VALUE 0x80000000 |
|||
#define GMAC0_RDES1_VALUE 0x4110 |
|||
#define GMAC0_RDES1_END_VALUE 0x8100 |
|||
|
|||
#define GMAC0_TX_DESC_BASE 0x9000000000040000 |
|||
#define GMAC1_TX_DESC_BASE 0x9000000000040200 |
|||
#define GMAC0_TX_DESC_BASE_PHY 0x40000 |
|||
#else |
|||
#define GMAC0_MAC_REG_ADDR 0xffffffffbbe10000 |
|||
#define GMAC0_DMA_REG_ADDR 0xffffffffbbe11000 |
|||
#define GMAC1_MAC_REG_ADDR 0xffffffffbbe18000 |
|||
#define GMAC1_DMA_REG_ADDR 0xffffffffbbe19000 |
|||
|
|||
#define GMAC0_RX_DESC_BASE 0xa0060000 |
|||
#define GMAC1_RX_DESC_BASE 0xa0060200 |
|||
#define GMAC0_RX_DESC_BASE_PHY 0x60000 |
|||
|
|||
#define GMAC0_RDES0_VALUE 0x80000000 |
|||
#define GMAC0_RDES1_VALUE 0x4110 |
|||
#define GMAC0_RDES1_END_VALUE 0x8100 |
|||
|
|||
#define GMAC0_TX_DESC_BASE 0xa0040000 |
|||
#define GMAC1_TX_DESC_BASE 0xa0040200 |
|||
#define GMAC0_TX_DESC_BASE_PHY 0x40000 |
|||
#endif |
|||
#define GMAC0_TDES0_VALUE 0xb0100000 |
|||
#define GMAC0_TDES0_VALUE_END 0xb0200000 |
|||
#define GMAC0_TDES1_VALUE 0x100 |
|||
|
|||
#define DmaBusMode_SWR 0x1 |
|||
#define DmaBusMode_PBL 0X400 |
|||
#define GmacConfig_DM (1 << 11) |
|||
#define GmacConfig_IFG 0xc000 |
|||
#define GmacFrameFilter_RA (1 << 31) |
|||
#define GmacConfig_RE (1 << 2) |
|||
#define GmacConfig_TE (1 << 3) |
|||
#define DmaControl_SR (1 << 1) |
|||
#define DmaControl_ST (1 << 13) |
|||
#define DmaControl_TSF (1 << 21) |
|||
#define DmaControl_RSF (1 << 25) |
|||
|
|||
#define SGMII_STATUS 0xd8 |
|||
#define SGMII_STATUS_LINK_STATUS (1 << 3) |
|||
|
|||
/*RTL8211E REG*/ |
|||
#define PHY_BMCR 0x0 |
|||
#define PHY_BMCR_LOOPBACK (1 << 14) |
|||
#define PHY_BMCR_SPEED (0X2000) |
|||
#define PHY_BMCR_DUPLEX (1 << 8) |
|||
#define PHY_PHYSR 0x11 |
|||
#define PHY_PHYSR_LINK_STATUS (1 << 10) |
|||
|
|||
#define TX_BUF_SIZE 0xc00 |
|||
|
|||
#define ls_readl(x) (*(volatile u32*)(x)) |
|||
|
|||
#define DEFAULT_DELAY_VARIABLE 10 |
|||
#define DEFAULT_LOOP_VARIABLE 10000 |
|||
#define SYNOP_PHY_LOOPBACK 1 |
|||
|
|||
/* Error Codes */ |
|||
#define ESYNOPGMACNOERR 0 |
|||
#define ESYNOPGMACNOMEM 1 |
|||
#define ESYNOPGMACPHYERR 2 |
|||
#define ESYNOPGMACBUSY 3 |
|||
|
|||
enum GmacRegisters |
|||
{ |
|||
GmacConfig = 0x0000, /* Mac config Register */ |
|||
GmacFrameFilter = 0x0004, /* Mac frame filtering controls */ |
|||
GmacHashHigh = 0x0008, /* Multi-cast hash table high */ |
|||
GmacHashLow = 0x000C, /* Multi-cast hash table low */ |
|||
GmacGmiiAddr = 0x0010, /* GMII address Register(ext. Phy) */ |
|||
GmacGmiiData = 0x0014, /* GMII data Register(ext. Phy) */ |
|||
GmacFlowControl = 0x0018, /* Flow control Register */ |
|||
GmacVlan = 0x001C, /* VLAN tag Register (IEEE 802.1Q) */ |
|||
|
|||
GmacVersion = 0x0020, /* GMAC Core Version Register */ |
|||
GmacWakeupAddr = 0x0028, /* GMAC wake-up frame filter adrress reg */ |
|||
GmacPmtCtrlStatus = 0x002C, /* PMT control and status register */ |
|||
|
|||
GmacInterruptStatus = 0x0038, /* Mac Interrupt ststus register */ |
|||
GmacInterruptMask = 0x003C, /* Mac Interrupt Mask register */ |
|||
|
|||
GmacAddr0High = 0x0040, /* Mac address0 high Register */ |
|||
GmacAddr0Low = 0x0044, /* Mac address0 low Register */ |
|||
GmacAddr1High = 0x0048, /* Mac address1 high Register */ |
|||
GmacAddr1Low = 0x004C, /* Mac address1 low Register */ |
|||
GmacAddr2High = 0x0050, /* Mac address2 high Register */ |
|||
GmacAddr2Low = 0x0054, /* Mac address2 low Register */ |
|||
GmacAddr3High = 0x0058, /* Mac address3 high Register */ |
|||
GmacAddr3Low = 0x005C, /* Mac address3 low Register */ |
|||
GmacAddr4High = 0x0060, /* Mac address4 high Register */ |
|||
GmacAddr4Low = 0x0064, /* Mac address4 low Register */ |
|||
GmacAddr5High = 0x0068, /* Mac address5 high Register */ |
|||
GmacAddr5Low = 0x006C, /* Mac address5 low Register */ |
|||
GmacAddr6High = 0x0070, /* Mac address6 high Register */ |
|||
GmacAddr6Low = 0x0074, /* Mac address6 low Register */ |
|||
GmacAddr7High = 0x0078, /* Mac address7 high Register */ |
|||
GmacAddr7Low = 0x007C, /* Mac address7 low Register */ |
|||
GmacAddr8High = 0x0080, /* Mac address8 high Register */ |
|||
GmacAddr8Low = 0x0084, /* Mac address8 low Register */ |
|||
GmacAddr9High = 0x0088, /* Mac address9 high Register */ |
|||
GmacAddr9Low = 0x008C, /* Mac address9 low Register */ |
|||
GmacAddr10High = 0x0090, /* Mac address10 high Register */ |
|||
GmacAddr10Low = 0x0094, /* Mac address10 low Register */ |
|||
GmacAddr11High = 0x0098, /* Mac address11 high Register */ |
|||
GmacAddr11Low = 0x009C, /* Mac address11 low Register */ |
|||
GmacAddr12High = 0x00A0, /* Mac address12 high Register */ |
|||
GmacAddr12Low = 0x00A4, /* Mac address12 low Register */ |
|||
GmacAddr13High = 0x00A8, /* Mac address13 high Register */ |
|||
GmacAddr13Low = 0x00AC, /* Mac address13 low Register */ |
|||
GmacAddr14High = 0x00B0, /* Mac address14 high Register */ |
|||
GmacAddr14Low = 0x00B4, /* Mac address14 low Register */ |
|||
GmacAddr15High = 0x00B8, /* Mac address15 high Register */ |
|||
GmacAddr15Low = 0x00BC, /* Mac address15 low Register */ |
|||
|
|||
/*Time Stamp Register Map*/ |
|||
GmacTSControl = 0x0700, /* Controls the Timestamp update logic : only when IEEE 1588 time stamping is enabled in corekit */ |
|||
|
|||
GmacTSSubSecIncr = 0x0704, /* 8 bit value by which sub second register is incremented : only when IEEE 1588 time stamping without external timestamp input */ |
|||
|
|||
GmacTSHigh = 0x0708, /* 32 bit seconds(MS) : only when IEEE 1588 time stamping without external timestamp input */ |
|||
GmacTSLow = 0x070C, /* 32 bit nano seconds(MS) : only when IEEE 1588 time stamping without external timestamp input */ |
|||
|
|||
GmacTSHighUpdate = 0x0710, /* 32 bit seconds(MS) to be written/added/subtracted : only when IEEE 1588 time stamping without external timestamp input */ |
|||
GmacTSLowUpdate = 0x0714, /* 32 bit nano seconds(MS) to be writeen/added/subtracted : only when IEEE 1588 time stamping without external timestamp input */ |
|||
|
|||
GmacTSAddend = 0x0718, /* Used by Software to readjust the clock frequency linearly : only when IEEE 1588 time stamping without external timestamp input */ |
|||
|
|||
GmacTSTargetTimeHigh = 0x071C, /* 32 bit seconds(MS) to be compared with system time : only when IEEE 1588 time stamping without external timestamp input */ |
|||
GmacTSTargetTimeLow = 0x0720, /* 32 bit nano seconds(MS) to be compared with system time : only when IEEE 1588 time stamping without external timestamp input */ |
|||
|
|||
GmacTSHighWord = 0x0724, /* Time Stamp Higher Word Register (Version 2 only); only lower 16 bits are valid */ |
|||
//GmacTSHighWordUpdate = 0x072C, /* Time Stamp Higher Word Update Register (Version 2 only); only lower 16 bits are valid */
|
|||
|
|||
GmacTSStatus = 0x0728, /* Time Stamp Status Register */ |
|||
}; |
|||
/**********************************************************
|
|||
* GMAC DMA registers |
|||
* For Pci based system address is BARx + GmaDmaBase |
|||
* For any other system translation is done accordingly |
|||
**********************************************************/ |
|||
|
|||
enum DmaRegisters |
|||
{ |
|||
DmaBusMode = 0x0000, /* CSR0 - Bus Mode Register */ |
|||
DmaTxPollDemand = 0x0004, /* CSR1 - Transmit Poll Demand Register */ |
|||
DmaRxPollDemand = 0x0008, /* CSR2 - Receive Poll Demand Register */ |
|||
DmaRxBaseAddr = 0x000C, /* CSR3 - Receive Descriptor list base address */ |
|||
DmaTxBaseAddr = 0x0010, /* CSR4 - Transmit Descriptor list base address */ |
|||
DmaStatus = 0x0014, /* CSR5 - Dma status Register */ |
|||
DmaControl = 0x0018, /* CSR6 - Dma Operation Mode Register */ |
|||
DmaInterrupt = 0x001C, /* CSR7 - Interrupt enable */ |
|||
DmaMissedFr = 0x0020, /* CSR8 - Missed Frame & Buffer overflow Counter */ |
|||
DmaTxCurrDesc = 0x0048, /* - Current host Tx Desc Register */ |
|||
DmaRxCurrDesc = 0x004C, /* - Current host Rx Desc Register */ |
|||
DmaTxCurrAddr = 0x0050, /* CSR20 - Current host transmit buffer address */ |
|||
DmaRxCurrAddr = 0x0054, /* CSR21 - Current host receive buffer address */ |
|||
}; |
|||
|
|||
|
|||
enum GmacGmiiAddrReg |
|||
{ |
|||
GmiiDevMask = 0x0000F800, /* (PA)GMII device address 15:11 RW 0x00 */ |
|||
GmiiDevShift = 11, |
|||
|
|||
GmiiRegMask = 0x000007C0, /* (GR)GMII register in selected Phy 10:6 RW 0x00 */ |
|||
GmiiRegShift = 6, |
|||
|
|||
GmiiCsrClkMask = 0x0000001C, /*CSR Clock bit Mask 4:2 */ |
|||
GmiiCsrClk5 = 0x00000014, /* (CR)CSR Clock Range 250-300 MHz 4:2 RW 000 */ |
|||
GmiiCsrClk4 = 0x00000010, /* 150-250 MHz */ |
|||
GmiiCsrClk3 = 0x0000000C, /* 35-60 MHz */ |
|||
GmiiCsrClk2 = 0x00000008, /* 20-35 MHz */ |
|||
GmiiCsrClk1 = 0x00000004, /* 100-150 MHz */ |
|||
GmiiCsrClk0 = 0x00000000, /* 60-100 MHz */ |
|||
|
|||
GmiiWrite = 0x00000002, /* (GW)Write to register 1 RW */ |
|||
GmiiRead = 0x00000000, /* Read from register 0 */ |
|||
|
|||
GmiiBusy = 0x00000001, /* (GB)GMII interface is busy 0 RW 0 */ |
|||
}; |
|||
#endif /*_GMAC_H_*/ |
@ -0,0 +1,130 @@ |
|||
//cpu fan pwm1 output,pwm2 intput.
|
|||
#include <stdio.h> |
|||
#include <pmon.h> |
|||
|
|||
#define LS2H_PWM_REG_BASE 0xbbea0000 //2H 0x1fea0000
|
|||
#define PWM_LOWBUF_OFFSET 0x4 |
|||
#define PWM_FULLBUF_OFFSET 0x8 |
|||
#define PWM_CTRL_OFFSET 0xc |
|||
#define PWM_CTRL_EN (1 << 0) |
|||
#define PWM_CTRL_CAPTE (1 << 8) |
|||
|
|||
#define LS2H_GPIOCFG 0xbbd000c0 //2H gpiocfg
|
|||
|
|||
#define read_w(x) (*(volatile unsigned int*)(x)) |
|||
#define write_w(x,val) (*(volatile unsigned int*)(x) = val) |
|||
|
|||
//#define DEBUG
|
|||
#ifdef DEBUG |
|||
#define dbg(format, arg...) printf(format, ## arg) |
|||
#else |
|||
#define dbg(format, arg...) |
|||
#endif |
|||
|
|||
static int fan_speed(ac,av) |
|||
int ac; |
|||
char *av[]; |
|||
{ |
|||
unsigned int tmp, tmp1, tmp_speed, total_val = 0, i; |
|||
|
|||
read_w(LS2H_GPIOCFG) |= ((0xf << 12) | (1 << 17));//pwm enable,pwm2 output
|
|||
dbg("gpiocfg->%x\n", read_w(LS2H_GPIOCFG)); |
|||
delay(0x400000);//wait for the pwm intput value valide.
|
|||
for (i = 0;i < 20;i++) { |
|||
read_w(LS2H_PWM_REG_BASE + (0x10 * 2) + PWM_CTRL_OFFSET) |= (PWM_CTRL_CAPTE | PWM_CTRL_EN); |
|||
dbg("pwm2 ctrl->%x\n", read_w(LS2H_GPIOCFG)); |
|||
speed_read: |
|||
tmp = read_w(LS2H_PWM_REG_BASE + (0x10 * 2) + PWM_LOWBUF_OFFSET); |
|||
dbg("tmp->%x\n", tmp); |
|||
tmp1 = read_w(LS2H_PWM_REG_BASE + (0x10 * 2) + PWM_FULLBUF_OFFSET); |
|||
dbg("tmp1->%x\n", tmp1); |
|||
if ((tmp > tmp1) || (tmp < 0x1000) || (tmp < 0x1000)) |
|||
goto speed_read; |
|||
|
|||
// tmp_speed = (1000000000 * 60)/((1000 / 125) * tmp1 * 2); //this code is overflow.
|
|||
tmp_speed = (62500000 * 6)/(tmp1 / 10); |
|||
dbg("fan speed -> %d\n", tmp_speed); |
|||
total_val += tmp_speed; |
|||
} |
|||
dbg("total fan speed -> %d\n", total_val); |
|||
tmp_speed = total_val / 20; |
|||
if(ac == 1) |
|||
printf("fan speed -> %d\n", tmp_speed); |
|||
return tmp_speed; |
|||
} |
|||
|
|||
static int fan_set(ac, av) |
|||
int ac; |
|||
char *av[]; |
|||
{ |
|||
unsigned int speed, tmp_speed, tmp_speed1, goal_speed, tmp_reg; |
|||
int i; |
|||
if (ac < 2) { |
|||
printf("parameter is error!\n"); |
|||
return -1; |
|||
} |
|||
|
|||
if (read_w(LS2H_PWM_REG_BASE + (0x10 * 1) + PWM_FULLBUF_OFFSET) == 0) { |
|||
read_w(LS2H_GPIOCFG) |= ((0xf << 12) | (1 << 17));//pwm enable
|
|||
dbg("gpiocfg->%x\n", read_w(LS2H_GPIOCFG)); |
|||
write_w(LS2H_PWM_REG_BASE + (0x10 * 1) + PWM_FULLBUF_OFFSET,0x1000); |
|||
write_w(LS2H_PWM_REG_BASE + (0x10 * 1) + PWM_LOWBUF_OFFSET,0x800); |
|||
write_w(LS2H_PWM_REG_BASE + (0x10 * 1) + PWM_CTRL_OFFSET,PWM_CTRL_EN); |
|||
} |
|||
goal_speed = atoi(av[1]); |
|||
printf("goal fan speed %d\n",goal_speed); |
|||
if ((goal_speed > 4700) && (goal_speed < 2200)) { |
|||
printf("goal speed can not complete!The fan speed is (2200 - 4600)\n"); |
|||
return -2; |
|||
} |
|||
speed = fan_speed(); |
|||
tmp_reg = read_w(LS2H_PWM_REG_BASE + (0x10 * 1) + PWM_LOWBUF_OFFSET); |
|||
|
|||
if (goal_speed > speed){ |
|||
for (i = tmp_reg;i > 0x80; i -= 0x40) { |
|||
dbg("value 0x%x\n",i); |
|||
write_w(LS2H_PWM_REG_BASE + (0x10 * 1) + PWM_LOWBUF_OFFSET, i); |
|||
speed = fan_speed(); |
|||
if (speed > goal_speed) { |
|||
tmp_speed1 = speed - goal_speed; |
|||
dbg("tmp_speed1 %d tmp_speed %d\n",tmp_speed1,tmp_speed); |
|||
if(tmp_speed1 > tmp_speed) |
|||
write_w(LS2H_PWM_REG_BASE + (0x10 * 1) + PWM_LOWBUF_OFFSET, i + 0x40); |
|||
break; |
|||
} |
|||
tmp_speed = goal_speed - speed; |
|||
} |
|||
} else if (goal_speed < speed) { |
|||
for (i = tmp_reg;i < 0x1000; i += 0x40) { |
|||
dbg("2 value 0x%x\n",i); |
|||
write_w(LS2H_PWM_REG_BASE + (0x10 * 1) + PWM_LOWBUF_OFFSET, i); |
|||
speed = fan_speed(); |
|||
if (speed < goal_speed) { |
|||
tmp_speed1 = goal_speed - speed; |
|||
dbg("2 tmp_speed1 %d tmp_speed %d\n",tmp_speed1,tmp_speed); |
|||
if(tmp_speed1 > tmp_speed) |
|||
write_w(LS2H_PWM_REG_BASE + (0x10 * 1) + PWM_LOWBUF_OFFSET, i - 0x40); |
|||
break; |
|||
} |
|||
tmp_speed = speed - goal_speed; |
|||
} |
|||
} |
|||
printf("ctual fan speed %d\n",fan_speed()); |
|||
return 0; |
|||
} |
|||
|
|||
static const Cmd Cmds[] = |
|||
{ |
|||
{"Misc"}, |
|||
{"fan_speed", "", 0, "3a2h fan speed test ", fan_speed, 1, 99, 0}, |
|||
{"fan_set", "", 0, "3a2h set fan speed test ", fan_set, 1, 99, 0}, |
|||
{0, 0} |
|||
}; |
|||
|
|||
static void init_cmd __P((void)) __attribute__ ((constructor)); |
|||
|
|||
void |
|||
init_cmd() |
|||
{ |
|||
cmdlist_expand(Cmds, 1); |
|||
} |
@ -0,0 +1,597 @@ |
|||
/* $Id: fan.c,v 1.1.1.1 2006/09/14 01:59:08 xqch Exp $ */ |
|||
/*
|
|||
* Copyright (c) 2001 Opsycon AB (www.opsycon.se) |
|||
* |
|||
* Redistribution and use in source and binary forms, with or without |
|||
* modification, are permitted provided that the following conditions |
|||
* are met: |
|||
* 1. Redistributions of source code must retain the above copyright |
|||
* notice, this list of conditions and the following disclaimer. |
|||
* 2. Redistributions in binary form must reproduce the above copyright |
|||
* notice, this list of conditions and the following disclaimer in the |
|||
* documentation and/or other materials provided with the distribution. |
|||
* 3. All advertising materials mentioning features or use of this software |
|||
* must display the following acknowledgement: |
|||
* This product includes software developed by Opsycon AB, Sweden. |
|||
* 4. The name of the author may not be used to endorse or promote products |
|||
* derived from this software without specific prior written permission. |
|||
* |
|||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS |
|||
* OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
|||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
|||
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY |
|||
* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
|||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
|||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
|||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
|||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
|||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
|||
* SUCH DAMAGE. |
|||
* |
|||
*/ |
|||
|
|||
#include <stdio.h> |
|||
#include <string.h> |
|||
#include <stdlib.h> |
|||
#include <sys/device.h> |
|||
#include <sys/queue.h> |
|||
|
|||
#include <pmon.h> |
|||
|
|||
#include "gmac.h" |
|||
|
|||
#define read32(x) (*(volatile unsigned int *)(x)) |
|||
#define read8(x) (*(volatile unsigned char *)(x)) |
|||
|
|||
unsigned char |
|||
cmd_usbtest(ac, av) |
|||
int ac; |
|||
char *av[]; |
|||
{ |
|||
unsigned int base = 0xbbe00000; |
|||
int port,test_mode; |
|||
if (ac != 3){ |
|||
printf("Usage:usbtest <port > <T> \n"); |
|||
printf("port0: 0\n"); |
|||
printf("port1: 1\n"); |
|||
printf("port2: 2\n"); |
|||
printf("port3: 3\n"); |
|||
printf("port4: 4\n"); |
|||
printf("port5: 5\n"); |
|||
printf("<T> 1: J_STATE\n"); |
|||
printf("<T> 2: K_STATE\n"); |
|||
printf("<T> 3: SE0_NAK\n"); |
|||
printf("<T> 4: Packet\n"); |
|||
printf("<T> 5: FORCE_ENABLE\n"); |
|||
printf("For example:usbtest 1 1 \n"); |
|||
return 0; |
|||
} |
|||
|
|||
port = atoi(av[1]); |
|||
test_mode = atoi(av[2]); |
|||
|
|||
read32(0xbbe00010) = 0x2; |
|||
switch (port) { |
|||
case 0: |
|||
read32(base | 0x54) = ((test_mode << 16) | 0x3084); |
|||
break; |
|||
case 1: |
|||
read32(base | 0x58) = ((test_mode << 16) | 0x3084); |
|||
break; |
|||
case 2: |
|||
read32(base | 0x5c) = ((test_mode << 16) | 0x3084); |
|||
break; |
|||
case 3: |
|||
read32(base | 0x60) = ((test_mode << 16) | 0x3084); |
|||
break; |
|||
case 4: |
|||
read32(base | 0x64) = ((test_mode << 16) | 0x3084); |
|||
break; |
|||
case 5: |
|||
read32(base | 0x68) = ((test_mode << 16) | 0x3084); |
|||
break; |
|||
default: |
|||
printf("the port number is error!\n"); |
|||
break; |
|||
} |
|||
|
|||
if (test_mode == 5) |
|||
read8(0xbBe00010) = 0x1; |
|||
|
|||
return(1); |
|||
} |
|||
|
|||
cmd_satatest(ac, av) |
|||
int ac; |
|||
char *av[]; |
|||
{ |
|||
|
|||
unsigned int port, gen; |
|||
unsigned int base; |
|||
int test_mode; |
|||
if (ac != 4){ |
|||
printf("Usage:satatest <port > <gen> <test_mode>\n"); |
|||
printf("port0: 0\n"); |
|||
printf("port1: 1\n"); |
|||
printf("gen1: 1\n"); |
|||
printf("gen2: 2\n"); |
|||
printf("test_mode: 0x0 SSOP( Simultaneous switching outputs pattern)\n"); |
|||
printf("test_mode: 0x1 HTDP( High transition density pattern) \n"); |
|||
printf("test_mode: 0x2 LTDP( Low transition density pattern) \n"); |
|||
printf("test_mode: 0x3 LFSCP( Low frequency spectral component pattern)\n"); |
|||
printf("test_mode: 0x4 COMP( Composite pattern) \n"); |
|||
printf("test_mode: 0x5 LBP( Lone bit pattern) \n"); |
|||
printf("test_mode: 0x6 MFTP( Mid frequency test pattern)\n"); |
|||
printf("test_mode: 0x7 HFTP( High frequency test pattern)\n"); |
|||
printf("test_mode: 0x8 LFTP( Low frequency test pattern)\n"); |
|||
|
|||
return 0; |
|||
} |
|||
|
|||
port = atoi(av[1]); |
|||
gen = atoi(av[2]); |
|||
test_mode = atoi(av[3]); |
|||
|
|||
base = (0xbbe38000 + port * 0x100); |
|||
// printf(" -> 0x%x\n", (gen == 1 ? 0x0 : 0x9));
|
|||
if (gen == 1) |
|||
read8(base | 0x12) = 0x0; |
|||
else if (gen == 2) |
|||
read8(base | 0x12) = 0x9; |
|||
|
|||
read8(base | 0x10) = 0x1; |
|||
read32(0xbbe300f4) = port * 0x10000; |
|||
read32(0xbbe300a4) = (0x10000 | test_mode); |
|||
|
|||
return(1); |
|||
|
|||
} |
|||
|
|||
unsigned char |
|||
cmd_pcietest(ac, av) |
|||
int ac; |
|||
char *av[]; |
|||
{ |
|||
unsigned int port, gen; |
|||
unsigned int base,test_mode; |
|||
unsigned int pcie_clock_source; |
|||
|
|||
if (ac < 2){ |
|||
|
|||
printf("if test gen1:pcietest <gen1>\n"); |
|||
printf("if test gen2:pcietest <gen2> <gen2_test_mode> \n"); |
|||
printf("gen1: 1\n"); |
|||
printf("gen2: 2\n"); |
|||
printf("gen2_test_mode: 1 ->0xf052, -3.5db De-emphasis \n"); |
|||
printf("gen2_test_mode: 2 ->0xf012, -6db De-emphasis \n"); |
|||
printf("gen2_test_mode: 3 ->0xf452, -3.5db De-emphasis, modified compliance \n"); |
|||
printf("gen2_test_mode: 4 ->0xf412, -6db De-emphasis, modified compliance \n"); |
|||
printf("gen2_test_mode: 5 ->0xfc12, -6db De-emphasis, modified compliance, compliance \n"); |
|||
printf("gen2_test_mode: 6 ->0xfc52, -3.5db De-emphasis, modified compliance, compliance SOS \n"); |
|||
printf("For example:pcietest 2 1 \n"); |
|||
return 0; |
|||
} |
|||
gen = atoi(av[1]); |
|||
if (gen == 2) { |
|||
test_mode = atoi(av[2]); |
|||
read32(0xb811407c) = 0x533c42;// the low 4 bit must be 2.
|
|||
} |
|||
|
|||
base = 0xb8110000; |
|||
read32(base | 0x480c) = 0x2040f; |
|||
for (port = 0;port < 4;port++) { |
|||
read8(base | (port * 0x100) | 0x11) = 0x21; |
|||
read8(base | (port * 0x100) | 0x10) = 0xb; |
|||
} |
|||
|
|||
if (gen == 2) { |
|||
for (port = 0;port < 4;port++) |
|||
read8(base | (port * 0x100) | 0x12) = 0xa; |
|||
} |
|||
|
|||
read32(base | 0x8000) = 0xff204c; |
|||
if (gen == 0x1) { |
|||
read32(base | 0x40a0) = 0xfc51; |
|||
} else if (gen == 0x2){ |
|||
switch (test_mode) { |
|||
case 1: |
|||
read32(base | 0x40a0) = 0xf052; |
|||
break; |
|||
case 2: |
|||
read32(base | 0x40a0) = 0xf012; |
|||
break; |
|||
case 3: |
|||
read32(base | 0x40a0) = 0xf452; |
|||
break; |
|||
case 4: |
|||
read32(base | 0x40a0) = 0xf412; |
|||
break; |
|||
case 5: |
|||
read32(base | 0x40a0) = 0xfc52; |
|||
break; |
|||
case 6: |
|||
read32(base | 0x40a0) = 0xfc12; |
|||
break; |
|||
default: |
|||
printf("The test mode is error!\n"); |
|||
break; |
|||
} |
|||
printf("test_mode = 0x%lx\n",test_mode); |
|||
} |
|||
|
|||
read32(base | 0x4708) = 0x7028004; |
|||
|
|||
return(1); |
|||
} |
|||
|
|||
#define u64 unsigned long |
|||
#define u32 unsigned int |
|||
#define u16 unsigned short |
|||
#define u8 unsigned char |
|||
#define GMAC0_MAC_REG_ADDR 0xffffffffbbe10000 |
|||
#define GMAC0_DMA_REG_ADDR 0xffffffffbbe11000 |
|||
#define GMAC1_MAC_REG_ADDR 0xffffffffbbe18000 |
|||
#define GMAC1_DMA_REG_ADDR 0xffffffffbbe19000 |
|||
|
|||
#define PHY_REG20 20 |
|||
#define PHY_REG0 0 |
|||
#define PHY_REG16 16 |
|||
#define PHY_LOOPBACK (1 << 14) |
|||
#define PHY_SPEED0 (1 << 13) |
|||
#define PHY_DUMPLEX_FULL (1 << 8) |
|||
#define PHY_SPEED1 (1 << 6) |
|||
#define PHY_MODE_100M (PHY_SPEED0 & ~PHY_SPEED1) |
|||
|
|||
static u32 gmac_read(u64 base, u32 reg) |
|||
{ |
|||
u64 addr; |
|||
u32 data; |
|||
|
|||
addr = base + (u64)reg; |
|||
data = ls_readl(addr); |
|||
return data; |
|||
} |
|||
|
|||
static void gmac_write(u64 base, u32 reg, u32 data) |
|||
{ |
|||
u64 addr; |
|||
|
|||
addr = base + (u64)reg; |
|||
ls_readl(addr) = data; |
|||
return; |
|||
} |
|||
|
|||
static signed int gmac_phy_read(u64 base,u32 PhyBase, u32 reg, u16 * data ) |
|||
{ |
|||
u32 addr; |
|||
u32 loop_variable; |
|||
addr = ((PhyBase << GmiiDevShift) & GmiiDevMask) | ((reg << GmiiRegShift) & GmiiRegMask) | GmiiCsrClk3; |
|||
addr = addr | GmiiBusy ; |
|||
|
|||
gmac_write(base,GmacGmiiAddr,addr); |
|||
|
|||
for(loop_variable = 0; loop_variable < DEFAULT_LOOP_VARIABLE; loop_variable++){ |
|||
if (!(gmac_read(base,GmacGmiiAddr) & GmiiBusy)){ |
|||
break; |
|||
} |
|||
int i = DEFAULT_DELAY_VARIABLE; |
|||
while (i--); |
|||
} |
|||
if(loop_variable < DEFAULT_LOOP_VARIABLE) |
|||
* data = (u16)(gmac_read(base,GmacGmiiData) & 0xFFFF); |
|||
else{ |
|||
tgt_printf("\rError::: PHY not responding Busy bit didnot get cleared !!!!!!\n"); |
|||
return -ESYNOPGMACPHYERR; |
|||
} |
|||
|
|||
return -ESYNOPGMACNOERR; |
|||
} |
|||
|
|||
static signed int gmac_phy_write(u64 base, u32 PhyBase, u32 reg, u16 data) |
|||
{ |
|||
u32 addr; |
|||
u32 loop_variable; |
|||
gmac_write(base,GmacGmiiData,data); |
|||
|
|||
addr = ((PhyBase << GmiiDevShift) & GmiiDevMask) | ((reg << GmiiRegShift) & GmiiRegMask) | GmiiWrite | GmiiCsrClk3; |
|||
|
|||
addr = addr | GmiiBusy ; |
|||
gmac_write(base,GmacGmiiAddr,addr); |
|||
for(loop_variable = 0; loop_variable < DEFAULT_LOOP_VARIABLE; loop_variable++){ |
|||
if (!(gmac_read(base,GmacGmiiAddr) & GmiiBusy)){ |
|||
break; |
|||
} |
|||
int i = DEFAULT_DELAY_VARIABLE; |
|||
while (i--); |
|||
} |
|||
|
|||
if(loop_variable < DEFAULT_LOOP_VARIABLE){ |
|||
return -ESYNOPGMACNOERR; |
|||
} |
|||
else{ |
|||
tgt_printf("\rError::: PHY not responding Busy bit didnot get cleared !!!!!!\n"); |
|||
return -ESYNOPGMACPHYERR; |
|||
} |
|||
} |
|||
|
|||
unsigned char |
|||
cmd_lantest(ac, av) |
|||
int ac; |
|||
char *av[]; |
|||
{ |
|||
unsigned int base,test_mode,id; |
|||
unsigned short data; |
|||
u64 mac_base; |
|||
if (ac < 2){ |
|||
printf("lantest: lantest <testmode>\n"); |
|||
printf("testmode1: 1\n"); |
|||
printf("testmode2: 2\n"); |
|||
printf("testmode3: 3\n"); |
|||
printf("testmode4: 4\n"); |
|||
printf("For example:lantest 1 \n"); |
|||
return 0; |
|||
} |
|||
test_mode = atoi(av[1]); |
|||
|
|||
for (id = 0;id < 2;id++) { |
|||
if (id == 0) |
|||
mac_base = GMAC0_MAC_REG_ADDR; |
|||
else if (id == 1) |
|||
mac_base = GMAC1_MAC_REG_ADDR; |
|||
|
|||
switch (test_mode) { |
|||
case 1: |
|||
gmac_phy_read(mac_base,16,9,&data); |
|||
printf("phy 9 register value = 0x%lx\n",data); |
|||
gmac_phy_read(mac_base,16,10,&data); |
|||
printf("phy 10 register value = 0x%lx\n",data); |
|||
gmac_phy_write(mac_base,16,9,(1 << 13)); |
|||
gmac_phy_read(mac_base,16,9,&data); |
|||
printf("changed phy 9 register value = 0x%lx\n",data); |
|||
gmac_phy_read(mac_base,16,10,&data); |
|||
printf("changed phy 10 register value = 0x%lx\n",data); |
|||
break; |
|||
case 2: |
|||
gmac_phy_read(mac_base,16,9,&data); |
|||
printf("phy 9 register value = 0x%lx\n",data); |
|||
gmac_phy_read(mac_base,16,10,&data); |
|||
printf("phy 10 register value = 0x%lx\n",data); |
|||
gmac_phy_write(mac_base,16,9, (0x2 << 13)); |
|||
gmac_phy_read(mac_base,16,9,&data); |
|||
printf("changed phy 9 register value = 0x%lx\n",data); |
|||
gmac_phy_read(mac_base,16,10,&data); |
|||
printf("changed phy 10 register value = 0x%lx\n",data); |
|||
break; |
|||
case 3: |
|||
gmac_phy_read(mac_base,16,9,&data); |
|||
printf("phy 9 register value = 0x%lx\n",data); |
|||
gmac_phy_read(mac_base,16,10,&data); |
|||
printf("phy 10 register value = 0x%lx\n",data); |
|||
gmac_phy_write(mac_base,16,9,(0x3 << 13)); |
|||
gmac_phy_read(mac_base,16,9,&data); |
|||
printf("changed phy 9 register value = 0x%lx\n",data); |
|||
gmac_phy_read(mac_base,16,10,&data); |
|||
printf("changed phy 10 register value = 0x%lx\n",data); |
|||
break; |
|||
case 4: |
|||
gmac_phy_read(mac_base,16,9,&data); |
|||
printf("phy 9 register value = 0x%lx\n",data); |
|||
gmac_phy_read(mac_base,16,10,&data); |
|||
printf("phy 10 register value = 0x%lx\n",data); |
|||
gmac_phy_write(mac_base,16,9, (0x4 << 13)); |
|||
gmac_phy_read(mac_base,16,9,&data); |
|||
printf("changed phy 9 register value = 0x%lx\n",data); |
|||
gmac_phy_read(mac_base,16,10,&data); |
|||
printf("changed phy 10 register value = 0x%lx\n",data); |
|||
break; |
|||
default: |
|||
printf("Test mode is error!\n"); |
|||
break; |
|||
} |
|||
} |
|||
|
|||
return(1); |
|||
} |
|||
int gmac_w18(void) |
|||
{ |
|||
unsigned char offset; |
|||
unsigned char id; |
|||
unsigned long long mac_base; |
|||
unsigned short data; |
|||
for (id = 0;id < 2;id++) { |
|||
if (id == 0) { |
|||
mac_base = GMAC0_MAC_REG_ADDR; |
|||
} else if (id == 1){ |
|||
mac_base = GMAC1_MAC_REG_ADDR; |
|||
} |
|||
/*
|
|||
gmac_phy_read(mac_base,16,16,&data); |
|||
data |= 0x300; |
|||
gmac_phy_write(mac_base,16,16,data); |
|||
gmac_phy_read(mac_base,16,16,&data); |
|||
*/ |
|||
gmac_phy_read(mac_base,16,19,&data); |
|||
data = 0x10; |
|||
gmac_phy_write(mac_base,16,18,data); |
|||
gmac_phy_read(mac_base,16,18,&data); |
|||
|
|||
gmac_phy_read(mac_base,16,19,&data); |
|||
|
|||
gmac_phy_read(mac_base,16,24,&data); |
|||
data = data | 0x800; |
|||
gmac_phy_write(mac_base,16,24,data); |
|||
|
|||
gmac_phy_read(mac_base,16,27,&data); |
|||
data = data & (~(1 << 10)); |
|||
gmac_phy_write(mac_base,16,27,data); |
|||
|
|||
gmac_phy_read(mac_base,16,0,&data); |
|||
data = data | 0x8000; |
|||
gmac_phy_write(mac_base,16,0,data); |
|||
} |
|||
return 0; |
|||
} |
|||
int gmac_w(ac, av) |
|||
int ac; |
|||
char *av[]; |
|||
{ |
|||
unsigned char offset; |
|||
unsigned char id; |
|||
unsigned long long mac_base; |
|||
unsigned short data; |
|||
if (ac == 3) { |
|||
data = 0x1e1; |
|||
printf("data 0x%lx\n",data); |
|||
for (id = 0;id < 2;id++) { |
|||
if (id == 0) { |
|||
mac_base = GMAC0_MAC_REG_ADDR; |
|||
gmac_phy_write(mac_base,16,4,data); |
|||
gmac_phy_read(mac_base,16,4,&data); |
|||
printf("gmac0 4 0x%lx\n",data); |
|||
gmac_phy_read(mac_base,16,0x00,&data); |
|||
gmac_phy_write(mac_base,16,0x00,data); |
|||
} else if (id == 1){ |
|||
data = 0xffff; |
|||
mac_base = GMAC1_MAC_REG_ADDR; |
|||
gmac_phy_write(mac_base,16,4,data); |
|||
gmac_phy_read(mac_base,16,4,&data); |
|||
printf("gmac1 4 0x%lx\n",data); |
|||
gmac_phy_read(mac_base,16,0x00,&data); |
|||
data = data | 0x8000; |
|||
gmac_phy_write(mac_base,16,0x00,data); |
|||
} |
|||
|
|||
} |
|||
} |
|||
if (ac == 1) { |
|||
printf("data 0x%lx\n",data); |
|||
for (id = 0;id < 2;id++) { |
|||
if (id == 0) { |
|||
data = 0x10; |
|||
mac_base = GMAC0_MAC_REG_ADDR; |
|||
gmac_phy_write(mac_base,16,18,data); |
|||
gmac_phy_read(mac_base,16,18,&data); |
|||
printf("gmac0 4 0x%lx\n",data); |
|||
gmac_phy_read(mac_base,16,0,&data); |
|||
data = data | 0x8000; |
|||
gmac_phy_write(mac_base,16,0,data); |
|||
} else if (id == 1){ |
|||
data = 0x10; |
|||
mac_base = GMAC1_MAC_REG_ADDR; |
|||
gmac_phy_write(mac_base,16,18,data); |
|||
gmac_phy_read(mac_base,16,18,&data); |
|||
printf("gmac1 4 0x%lx\n",data); |
|||
gmac_phy_read(mac_base,16,0,&data); |
|||
data = data | 0x8000; |
|||
gmac_phy_write(mac_base,16,0,data); |
|||
} |
|||
|
|||
} |
|||
} |
|||
if (ac == 2) { |
|||
for (id = 0;id < 2;id++) { |
|||
if (id == 0) |
|||
mac_base = GMAC0_MAC_REG_ADDR; |
|||
else if (id == 1) |
|||
mac_base = GMAC1_MAC_REG_ADDR; |
|||
|
|||
data = 0x40; |
|||
gmac_phy_write(mac_base,16,18,data); |
|||
gmac_phy_read(mac_base,16,0x00,&data); |
|||
data = data | 0x8000; |
|||
gmac_phy_write(mac_base,16,0x00,data); |
|||
} |
|||
} |
|||
return 0; |
|||
} |
|||
int gmacphy_write(ac, av) |
|||
int ac; |
|||
char *av[]; |
|||
{ |
|||
unsigned char offset; |
|||
if (ac != 3) { |
|||
printf("the parameters is error!\n"); |
|||
printf("gmacphy_write <offset> <data>\n"); |
|||
return -1; |
|||
} |
|||
|
|||
offset = atoi(av[1]); |
|||
|
|||
unsigned char id; |
|||
unsigned long long mac_base; |
|||
unsigned short data; |
|||
data = atoi(av[2]); |
|||
printf("data 0x%lx\n",data); |
|||
for (id = 0;id < 2;id++) { |
|||
if (id == 0) |
|||
mac_base = GMAC0_MAC_REG_ADDR; |
|||
else if (id == 1) |
|||
mac_base = GMAC1_MAC_REG_ADDR; |
|||
|
|||
gmac_phy_write(mac_base,16,offset,data); |
|||
} |
|||
return 0; |
|||
} |
|||
int gmacphy_read(ac, av) |
|||
int ac; |
|||
char *av[]; |
|||
{ |
|||
unsigned char offset; |
|||
unsigned char id; |
|||
unsigned long long mac_base; |
|||
unsigned short data; |
|||
if (ac == 1) { |
|||
for (id = 0;id < 2;id++) { |
|||
if (id == 0) |
|||
mac_base = GMAC0_MAC_REG_ADDR; |
|||
else if (id == 1) |
|||
mac_base = GMAC1_MAC_REG_ADDR; |
|||
|
|||
for (offset = 0;offset < 32;offset++) { |
|||
gmac_phy_read(mac_base,16,offset,&data); |
|||
printf("gmac%d reg(%d) %lx\n",id,offset,data); |
|||
} |
|||
} |
|||
|
|||
return -1; |
|||
} |
|||
|
|||
offset = atoi(av[1]); |
|||
|
|||
for (id = 0;id < 2;id++) { |
|||
if (id == 0) |
|||
mac_base = GMAC0_MAC_REG_ADDR; |
|||
else if (id == 1) |
|||
mac_base = GMAC1_MAC_REG_ADDR; |
|||
|
|||
gmac_phy_read(mac_base,16,offset,&data); |
|||
printf("gmac%d reg(%d) %lx\n",id,offset,data); |
|||
} |
|||
return 0; |
|||
} |
|||
/*
|
|||
* |
|||
* Command table registration |
|||
* ========================== |
|||
*/ |
|||
|
|||
static const Cmd Cmds[] = |
|||
{ |
|||
{"Misc"}, |
|||
{"usbtest", "", 0, "3a2h usbtest : usbtest ", cmd_usbtest, 1, 99, 0}, |
|||
{"gmacphy_read", "", 0, "read gmac phy reg", gmacphy_read, 1, 99, 0}, |
|||
{"gmacphy_write", "", 0, "read gmac phy reg", gmacphy_write, 1, 99, 0}, |
|||
{"gmac_w", "", 0, "read gmac phy reg", gmac_w, 1, 99, 0}, |
|||
{"lantest", "", 0, "3a2h lantest : lantest ", cmd_lantest, 1, 99, 0}, |
|||
{"pcietest", "", 0, "3a2h pcietest: pcietest ", cmd_pcietest, 1, 99, 0}, |
|||
{"satatest", "", 0, "3a2h satatest: satatest ", cmd_satatest, 1, 99, 0}, |
|||
{0, 0} |
|||
}; |
|||
|
|||
static void init_cmd __P((void)) __attribute__ ((constructor)); |
|||
|
|||
void |
|||
init_cmd() |
|||
{ |
|||
cmdlist_expand(Cmds, 1); |
|||
} |
Loading…
Reference in new issue