Cleanup of code, output formatting, and indentation.

master
wdenk 21 years ago
parent 78137c3c93
commit b56ddc636d
  1. 2
      drivers/s3c24x0_i2c.c
  2. 150
      drivers/smc91111.c

@ -56,7 +56,7 @@
#define I2C_START_STOP 0x20 /* START / STOP */
#define I2C_TXRX_ENA 0x10 /* I2C Tx/Rx enable */
#define I2C_TIMEOUT 1 /* 1 seconde */
#define I2C_TIMEOUT 1 /* 1 second */
static int GetI2CSDA(void)

@ -295,15 +295,15 @@ static void smc_write_phy_register(byte phyreg, word phydata);
#endif /* !CONFIG_SMC91111_EXT_PHY */
static int poll4int( byte mask, int timeout ) {
static int poll4int (byte mask, int timeout)
{
int tmo = get_timer (0) + timeout * CFG_HZ;
int is_timeout = 0;
word old_bank = SMC_inw (BSR_REG);
PRINTK2 ("Polling...\n");
SMC_SELECT_BANK (2);
while((SMC_inw(SMC91111_INT_REG) & mask) == 0)
{
while ((SMC_inw (SMC91111_INT_REG) & mask) == 0) {
if (get_timer (0) >= tmo) {
is_timeout = 1;
break;
@ -323,10 +323,12 @@ static int poll4int( byte mask, int timeout ) {
static inline void smc_wait_mmu_release_complete (void)
{
int count = 0;
/* assume bank 2 selected */
while (SMC_inw (MMU_CMD_REG) & MC_BUSY) {
udelay (1); /* Wait until not busy */
if( ++count > 200) break;
if (++count > 200)
break;
}
}
@ -536,8 +538,7 @@ again:
}
PRINTK2 ("%s: memory allocation, try %d succeeded ...\n",
SMC_DEV_NAME,
try);
SMC_DEV_NAME, try);
/* I can send the packet now.. */
@ -549,8 +550,7 @@ again:
packet_no = SMC_inb (AR_REG);
if (packet_no & AR_FAILED) {
/* or isn't there? BAD CHIP! */
printf("%s: Memory allocation failed. \n",
SMC_DEV_NAME);
printf ("%s: Memory allocation failed. \n", SMC_DEV_NAME);
return 0;
}
@ -588,7 +588,8 @@ again:
#ifdef USE_32_BIT
SMC_outsl (SMC91111_DATA_REG, buf, length >> 2);
if (length & 0x2)
SMC_outw(*((word *)(buf + (length & 0xFFFFFFFC))), SMC91111_DATA_REG);
SMC_outw (*((word *) (buf + (length & 0xFFFFFFFC))),
SMC91111_DATA_REG);
#else
SMC_outsw (SMC91111_DATA_REG, buf, (length) >> 1);
#endif /* USE_32_BIT */
@ -606,15 +607,13 @@ again:
/* poll for TX INT */
if (poll4int (IM_TX_INT, SMC_TX_TIMEOUT)) {
/* sending failed */
PRINTK2("%s: TX timeout, sending failed...\n",
SMC_DEV_NAME);
PRINTK2 ("%s: TX timeout, sending failed...\n", SMC_DEV_NAME);
/* release packet */
SMC_outw (MC_FREEPKT, MMU_CMD_REG);
/* wait for MMU getting ready (low) */
while (SMC_inw(MMU_CMD_REG) & MC_BUSY)
{
while (SMC_inw (MMU_CMD_REG) & MC_BUSY) {
udelay (10);
}
@ -625,14 +624,14 @@ again:
} else {
/* ack. int */
SMC_outw (IM_TX_INT, SMC91111_INT_REG);
PRINTK2("%s: Sent packet of length %d \n", SMC_DEV_NAME, length);
PRINTK2 ("%s: Sent packet of length %d \n", SMC_DEV_NAME,
length);
/* release packet */
SMC_outw (MC_FREEPKT, MMU_CMD_REG);
/* wait for MMU getting ready (low) */
while (SMC_inw(MMU_CMD_REG) & MC_BUSY)
{
while (SMC_inw (MMU_CMD_REG) & MC_BUSY) {
udelay (10);
}
@ -692,7 +691,6 @@ static int smc_open(bd_t *bd)
memset (bd->bi_enetaddr, 0, 6); /* hack to make error stick! upper code will abort if not set */
return (-1); /* upper code ignores this, but NOT bi_enetaddr */
}
#ifdef USE_32_BIT
for (i = 0; i < 6; i += 2) {
word address;
@ -709,22 +707,6 @@ static int smc_open(bd_t *bd)
return 0;
}
#if 0 /* dead code? -- wd */
#ifdef USE_32_BIT
void
insl32(r,b,l)
{
int __i ;
dword *__b2;
__b2 = (dword *) b;
for (__i = 0; __i < l; __i++) {
*(__b2 + __i) = *(dword *)(r+0x10000300);
}
}
#endif
#endif
/*-------------------------------------------------------------
.
. smc_rcv - receive a packet from the card
@ -925,14 +907,12 @@ static void smc_dump_mii_stream(byte* bits, int size)
int i;
printf ("BIT#:");
for (i = 0; i < size; ++i)
{
for (i = 0; i < size; ++i) {
printf ("%d", i % 10);
}
printf ("\nMDOE:");
for (i = 0; i < size; ++i)
{
for (i = 0; i < size; ++i) {
if (bits[i] & MII_MDOE)
printf ("1");
else
@ -940,8 +920,7 @@ static void smc_dump_mii_stream(byte* bits, int size)
}
printf ("\nMDO :");
for (i = 0; i < size; ++i)
{
for (i = 0; i < size; ++i) {
if (bits[i] & MII_MDO)
printf ("1");
else
@ -949,8 +928,7 @@ static void smc_dump_mii_stream(byte* bits, int size)
}
printf ("\nMDI :");
for (i = 0; i < size; ++i)
{
for (i = 0; i < size; ++i) {
if (bits[i] & MII_MDI)
printf ("1");
else
@ -991,8 +969,7 @@ static word smc_read_phy_register(byte phyreg)
/* Output the PHY address, msb first */
mask = (byte) 0x10;
for (i = 0; i < 5; ++i)
{
for (i = 0; i < 5; ++i) {
if (phyaddr & mask)
bits[clk_idx++] = MII_MDOE | MII_MDO;
else
@ -1004,8 +981,7 @@ static word smc_read_phy_register(byte phyreg)
/* Output the phy register number, msb first */
mask = (byte) 0x10;
for (i = 0; i < 5; ++i)
{
for (i = 0; i < 5; ++i) {
if (phyreg & mask)
bits[clk_idx++] = MII_MDOE | MII_MDO;
else
@ -1042,8 +1018,7 @@ static word smc_read_phy_register(byte phyreg)
mii_reg &= ~(MII_MDOE | MII_MCLK | MII_MDI | MII_MDO);
/* Clock all 64 cycles */
for (i = 0; i < sizeof bits; ++i)
{
for (i = 0; i < sizeof bits; ++i) {
/* Clock Low - output data */
SMC_outw (mii_reg | bits[i], MII_REG);
udelay (SMC_PHY_CLOCK_DELAY);
@ -1065,8 +1040,7 @@ static word smc_read_phy_register(byte phyreg)
/* Recover input data */
phydata = 0;
for (i = 0; i < 16; ++i)
{
for (i = 0; i < 16; ++i) {
phydata <<= 1;
if (bits[input_idx++] & MII_MDI)
@ -1110,8 +1084,7 @@ static void smc_write_phy_register(byte phyreg, word phydata)
/* Output the PHY address, msb first */
mask = (byte) 0x10;
for (i = 0; i < 5; ++i)
{
for (i = 0; i < 5; ++i) {
if (phyaddr & mask)
bits[clk_idx++] = MII_MDOE | MII_MDO;
else
@ -1123,8 +1096,7 @@ static void smc_write_phy_register(byte phyreg, word phydata)
/* Output the phy register number, msb first */
mask = (byte) 0x10;
for (i = 0; i < 5; ++i)
{
for (i = 0; i < 5; ++i) {
if (phyreg & mask)
bits[clk_idx++] = MII_MDOE | MII_MDO;
else
@ -1140,8 +1112,7 @@ static void smc_write_phy_register(byte phyreg, word phydata)
/* Write out 16 bits of data, msb first */
mask = 0x8000;
for (i = 0; i < 16; ++i)
{
for (i = 0; i < 16; ++i) {
if (phydata & mask)
bits[clk_idx++] = MII_MDOE | MII_MDO;
else
@ -1167,8 +1138,7 @@ static void smc_write_phy_register(byte phyreg, word phydata)
mii_reg &= ~(MII_MDOE | MII_MCLK | MII_MDI | MII_MDO);
/* Clock all cycles */
for (i = 0; i < sizeof bits; ++i)
{
for (i = 0; i < sizeof bits; ++i) {
/* Clock Low - output data */
SMC_outw (mii_reg | bits[i], MII_REG);
udelay (SMC_PHY_CLOCK_DELAY);
@ -1233,11 +1203,9 @@ static void smc_phy_configure()
/* Wait for the reset to complete, or time out */
timeout = 6; /* Wait up to 3 seconds */
while (timeout--)
{
while (timeout--) {
if (!(smc_read_phy_register (PHY_CNTL_REG)
& PHY_CNTL_RST))
{
& PHY_CNTL_RST)) {
/* reset complete */
break;
}
@ -1245,8 +1213,7 @@ static void smc_phy_configure()
smc_wait_ms (500); /* wait 500 millisecs */
}
if (timeout < 1)
{
if (timeout < 1) {
printf ("%s:PHY reset timed out\n", SMC_DEV_NAME);
goto smc_phy_configure_exit;
}
@ -1295,11 +1262,9 @@ static void smc_phy_configure()
/* 2 to 3 seconds. */
/* Wait for the reset to complete, or time out */
timeout = 20; /* Wait up to 10 seconds */
while (timeout--)
{
while (timeout--) {
status = smc_read_phy_register (PHY_STAT_REG);
if (status & PHY_STAT_ANEG_ACK)
{
if (status & PHY_STAT_ANEG_ACK) {
/* auto-negotiate complete */
break;
}
@ -1307,30 +1272,29 @@ static void smc_phy_configure()
smc_wait_ms (500); /* wait 500 millisecs */
/* Restart auto-negotiation if remote fault */
if (status & PHY_STAT_REM_FLT)
{
printf("%s:PHY remote fault detected\n", SMC_DEV_NAME);
if (status & PHY_STAT_REM_FLT) {
printf ("%s:PHY remote fault detected\n",
SMC_DEV_NAME);
/* Restart auto-negotiation */
printf ("%s:PHY restarting auto-negotiation\n",
SMC_DEV_NAME);
smc_write_phy_register (PHY_CNTL_REG,
PHY_CNTL_ANEG_EN | PHY_CNTL_ANEG_RST |
PHY_CNTL_SPEED | PHY_CNTL_DPLX);
PHY_CNTL_ANEG_EN |
PHY_CNTL_ANEG_RST |
PHY_CNTL_SPEED |
PHY_CNTL_DPLX);
}
}
if (timeout < 1)
{
printf("%s:PHY auto-negotiate timed out\n",
SMC_DEV_NAME);
if (timeout < 1) {
printf ("%s:PHY auto-negotiate timed out\n", SMC_DEV_NAME);
printf ("%s:PHY auto-negotiate timed out\n", SMC_DEV_NAME);
failed = 1;
}
/* Fail if we detected an auto-negotiate remote fault */
if (status & PHY_STAT_REM_FLT)
{
if (status & PHY_STAT_REM_FLT) {
printf ("%s:PHY remote fault detected\n", SMC_DEV_NAME);
printf ("%s:PHY remote fault detected\n", SMC_DEV_NAME);
failed = 1;
@ -1428,20 +1392,37 @@ int smc_get_ethaddr(bd_t *bd)
if (!env_present) { /* if NO env */
if (rom_valid) { /* but ROM is valid */
v_mac = v_rom_mac;
sprintf (s_env_mac, "%02X:%02X:%02X:%02X:%02X:%02X", v_mac[0],
v_mac[1] ,v_mac[2], v_mac[3],v_mac[4], v_mac[5]) ;
sprintf (s_env_mac, "%02X:%02X:%02X:%02X:%02X:%02X",
v_mac[0], v_mac[1], v_mac[2], v_mac[3],
v_mac[4], v_mac[5]);
setenv ("ethaddr", s_env_mac);
} else { /* no env, bad ROM */
printf ("\n*** ERROR: ethaddr is NOT set !!\n");
return (-1);
}
}else /* good env, don't care ROM */
} else { /* good env, don't care ROM */
v_mac = v_env_mac; /* always use a good env over a ROM */
}
if(env_present && rom_valid) /* if both env and ROM are good */
if (env_present && rom_valid) { /* if both env and ROM are good */
if (memcmp (v_env_mac, v_rom_mac, 6) != 0) {
printf ("\n*** Warning: Environment and ROM MAC addresses don't match\n");
printf ("*** Using Environment MAC\n");
-----
printf ("\nWarning: MAC addresses don't match:\n");
printf ("\tHW MAC address: "
"%02X:%02X:%02X:%02X:%02X:%02X\n",
v_rom_mac[0], v_rom_mac[1],
v_rom_mac[2], v_rom_mac[3],
v_rom_mac[4], v_rom_mac[5] );
printf ("\t\"ethaddr\" value: "
"%02X:%02X:%02X:%02X:%02X:%02X\n",
v_env_mac[0], v_env_mac[1],
v_env_mac[2], v_env_mac[3],
v_env_mac[4], v_env_mac[5]) ;
debug ("### Set MAC addr from environment\n");
memcpy (addr, env_enetaddr, 6);
}
}
memcpy (bd->bi_enetaddr, v_mac, 6); /* update global address to match env (allows env changing) */
smc_set_mac_addr (v_mac); /* use old function to update smc default */
@ -1451,14 +1432,14 @@ int smc_get_ethaddr(bd_t *bd)
int get_rom_mac (char *v_rom_mac)
{
int is_rom_present = 0;
#ifdef HARDCODE_MAC /* used for testing or to supress run time warnings */
char hw_mac_addr[] = { 0x02, 0x80, 0xad, 0x20, 0x31, 0xb8 };
memcpy (v_rom_mac, hw_mac_addr, 6);
return (1);
#else
if(is_rom_present)
{
if (is_rom_present) {
/* if eeprom contents are valid
* extract mac address into hw_mac_addr, 8 or 16 bit accesses
* memcpy (v_rom_mac, hc_mac_addr, 6);
@ -1469,5 +1450,4 @@ int get_rom_mac(char *v_rom_mac)
return (0);
#endif
}
#endif /* CONFIG_DRIVER_SMC91111 */

Loading…
Cancel
Save