📄 eprom.c
字号:
mask = 0x01 << (count - 1);
x = ( ushort_t )inb( bdp->memBase + CSR_EEPROM_CONTROL_REG );
x &= ~(EEDO | EEDI);
do
{
x &= ~EEDI;
if (data & mask)
x |= EEDI;
outb((bdp->memBase + CSR_EEPROM_CONTROL_REG), x);
drv_usecwait( EEPROM_CLOCK_DELAY);
RaiseClock(bdp, &x );
LowerClock(bdp, &x );
mask = mask >> 1;
} while (mask);
x &= ~EEDI;
outb((bdp->memBase + CSR_EEPROM_CONTROL_REG), x);
}
/*
* Procedure: ShiftInBits
*
* Description: This routine shifts data bits in from the EEPROM.
*
* Arguments:
* bdp - Ptr to this card's DL_bdconfig structure
*
* Returns:
* The contents of that particular EEPROM word
*/
static ushort_t
ShiftInBits( ethPciInfo *bdp )
{
ushort_t x, d, i;
x = ( ushort_t )inb( bdp->memBase + CSR_EEPROM_CONTROL_REG );
x &= ~( EEDO | EEDI);
d = 0;
for (i = 0; i < 16; i++) {
d = d << 1;
RaiseClock(bdp, &x );
x = ( ushort_t )inb( bdp->memBase + CSR_EEPROM_CONTROL_REG );
x &= ~(EEDI);
if (x & EEDO)
d |= 1;
LowerClock(bdp, &x );
}
return d;
}
/*
* Procedure: RaiseClock
*
* Description: This routine raises the EEPOM's clock input (EESK)
*
* Arguments:
* bdp - Ptr to this card's DL_bdconfig structure
* x - Ptr to the EEPROM control register's current value
*
* Returns: (none)
*/
static void
RaiseClock( ethPciInfo *bdp, ushort_t *x )
{
*x = *x | EESK;
outb((bdp->memBase + CSR_EEPROM_CONTROL_REG), *x);
drv_usecwait( EEPROM_CLOCK_DELAY);
}
/*
* Procedure: LowerClock
*
* Description: This routine lower's the EEPOM's clock input (EESK)
*
* Arguments:
* bdp - Ptr to this card's DL_bdconfig structure
* x - Ptr to the EEPROM control register's current value
*
* Returns: (none)
*/
static void
LowerClock( ethPciInfo *bdp, ushort_t *x )
{
*x = *x & ~EESK;
outb((bdp->memBase + CSR_EEPROM_CONTROL_REG), *x);
drv_usecwait( EEPROM_CLOCK_DELAY);
}
/*
* Procedure: WaitEEPROMCmdDone
*
* Description: This routine waits for the the EEPROM to finish its command.
* Specifically, it waits for EEDO (data out) to go high.
*
* Arguments:
* bdp - Ptr to this card's DL_bdconfig structure
*
* Returns:
* B_TRUE - If the command finished
* B_FALSE - If the command never finished (EEDO stayed low)
*/
static ushort_t
WaitEEPROMCmdDone( ethPciInfo *bdp )
{
ushort_t x, i;
StandBy( bdp );
for (i = 0; i < 30; i++) {
x = ( ushort_t )inb( bdp->memBase + CSR_EEPROM_CONTROL_REG );
if (x & EEDO)
return (B_TRUE);
drv_usecwait( EEPROM_CLOCK_DELAY);
}
return B_FALSE;
}
/*
* Procedure: StandBy
*
* Description: This routine lowers the EEPROM chip select (EECS) for a few
* microseconds.
*
* Arguments:
* bdp - Ptr to this card's DL_bdconfig structure
*
* Returns: (none)
*/
static void
StandBy( ethPciInfo *bdp )
{
ushort_t x;
x = ( ushort_t )inb( bdp->memBase + CSR_EEPROM_CONTROL_REG );
x &= ~(EECS | EESK);
outb((bdp->memBase + CSR_EEPROM_CONTROL_REG), x);
drv_usecwait(1);
x |= EECS;
outb((bdp->memBase + CSR_EEPROM_CONTROL_REG), x);
}
/*
* Procedure: EEpromCleanup
*
* Description: This routine returns the EEPROM to an idle state
*
* Arguments:
* bdp - Ptr to this card's DL_bdconfig structure
*
* Returns: (none)
*/
static void
EEpromCleanup( ethPciInfo *bdp )
{
ushort_t x;
x = ( ushort_t )inb( bdp->memBase + CSR_EEPROM_CONTROL_REG );
x &= ~(EECS | EEDI);
outb((bdp->memBase + CSR_EEPROM_CONTROL_REG), x);
RaiseClock(bdp, &x );
LowerClock(bdp, &x );
}
/*
* Procedure: eeEUpdateChecksum
*
* Description: Calculates the checksum and writes it to the EEProm. This
* routine assumes that the checksum word is the last word in
* a 64 word EEPROM. It calculates the checksum accroding to
* the formula: Checksum = 0xBABA - (sum of first 63 words).
*
* Arguments:
* bdp - Ptr to this card's DL_bdconfig structure
*
* Returns: (none)
*/
static void
eeEUpdateChecksum( ethPciInfo *bdp )
{
ushort_t Checksum = 0;
ushort_t Iter;
for (Iter = 0; Iter < DEFAULT_93C46_NUM; Iter ++)
{
Checksum += ReadEEprom( bdp, Iter );
}
Checksum = (ushort_t)0 - Checksum;
WriteEEprom( bdp, DEFAULT_93C46_NUM, Checksum );
}
/*
* Procedure: dumpEeprom
*
* Description: This routine serially output words in the EEPROM.
*
* Arguments:
* eth - Ptr to this card's DL_bdconfig structure
*
* Returns: (none)
*/
static void
dumpEeprom ( ethPciInfo *eth )
{
int i, rd;
printf ("Address\tHigh Byte\tLowByte\n");
for (i = 0; i < (DEFAULT_93C46_NUM+1); i++)
{
rd = ReadEEprom (eth, i);
printf ("0x%2x\t0x%2x\t0x%2x\n", i*2, rd & 0xff, rd >> 8);
}
}
#if 0
/*
* Procedure: eeE_rd_oembit
*
* Description: Reads the OEM bit from the eprom.
*
* Arguments:
* bdp - Ptr to this card's DL_bdconfig structure
*
* Returns: 0 if Intel card
1 if Non-Intel
*/
int
eeE_rd_oembit( ethPciInfo *bdp )
{
ushort_t EepromWordValue;
DL_LOG(strlog( DL_ID, 0, 3, SL_TRACE, "eeE_rd_oembit: begin." ));
/* Read the Compatibility_1 byte from the EEPROM. We Must use
* I/O do this, because have not yet memory mapped the CSR
*/
EepromWordValue = ReadEEprom( bdp, EEPROM_COMPATIBILITY_WORD);
/* only look at the bit 0 of the high order byte */
if ( ( (EepromWordValue >> 8) & 0x01 ) != 0x00 )
return( 1 ); /* it's NOT an Intel card */
else
return( 0 ); /* it's an Intel card */
}
/*
* Procedure: eeE_rd_vendor_info
*
* Description: Reads the subsystem_id and subsystem_vendor words from
* the eprom.
*
* Arguments:
* bdp - Ptr to this card's DL_bdconfig structure
* ven_info - Ptr to a eprom_vendor_info_t structure
*
* Returns: filled in DL_vendor_info_t structure; void return
*/
void
eeE_rd_vendor_info( ethPciInfo *bdp, ushort_t *sub_ven, ushort_t *sub_dev )
{
ushort_t EepromWordValue;
DL_LOG(strlog( DL_ID, 0, 3, SL_TRACE, "eeE_rd_vendor_info: begin." ));
/* Read the Subsystem_ID and Subsystem_Vendor words from the EEPROM.
* We Must use I/O to do this, because have not yet memory mapped the CSR
*/
/* read the subsystem ID */
EepromWordValue = ReadEEprom( bdp, EEPROM_SUBSYSTEM_ID_WORD);
*sub_dev = EepromWordValue;
/* read the subsystem vendor */
EepromWordValue = ReadEEprom( bdp, EEPROM_SUBSYSTEM_VENDOR_WORD);
*sub_ven = EepromWordValue;
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -