iPXE
Functions | Variables
mii_bit.c File Reference
#include <stdint.h>
#include <unistd.h>
#include <ipxe/bitbash.h>
#include <ipxe/mii_bit.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
static uint32_t mii_bit_xfer (struct bit_basher *basher, uint32_t mask, uint32_t write)
 Transfer bits over MII bit-bashing interface.
static unsigned int mii_bit_rw (struct bit_basher *basher, unsigned int phy, unsigned int reg, unsigned int data, unsigned int cmd)
 Read or write via MII bit-bashing interface.
static int mii_bit_read (struct mii_interface *mdio, unsigned int phy, unsigned int reg)
 Read from MII register.
static int mii_bit_write (struct mii_interface *mdio, unsigned int phy, unsigned int reg, unsigned int data)
 Write to MII register.
void init_mii_bit_basher (struct mii_bit_basher *miibit)
 Initialise bit-bashing interface.

Variables

static struct mii_operations mii_bit_op
 MII bit basher operations.

Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
static uint32_t mii_bit_xfer ( struct bit_basher basher,
uint32_t  mask,
uint32_t  write 
) [static]

Transfer bits over MII bit-bashing interface.

Parameters:
basherBit basher
maskMask
writeData to write
Return values:
readData read

Definition at line 39 of file mii_bit.c.

References MII_BIT_MDC, MII_BIT_MDIO, read_bit(), udelay(), and write_bit().

Referenced by mii_bit_rw().

                                                               {
        uint32_t read = 0;
        int bit;

        for ( ; mask ; mask >>= 1 ) {

                /* Delay */
                udelay ( 1 );

                /* Write bit to basher */
                write_bit ( basher, MII_BIT_MDIO, ( write & mask ) );

                /* Read bit from basher */
                bit = read_bit ( basher, MII_BIT_MDIO );
                read <<= 1;
                read |= ( bit & 1 );

                /* Set clock high */
                write_bit ( basher, MII_BIT_MDC, 1 );

                /* Delay */
                udelay ( 1 );

                /* Set clock low */
                write_bit ( basher, MII_BIT_MDC, 0 );
        }
        return read;
}
static unsigned int mii_bit_rw ( struct bit_basher basher,
unsigned int  phy,
unsigned int  reg,
unsigned int  data,
unsigned int  cmd 
) [static]

Read or write via MII bit-bashing interface.

Parameters:
basherBit basher
phyPHY address
regRegister address
dataData to write
cmdCommand
Return values:
dataData read

Definition at line 79 of file mii_bit.c.

References data, MII_BIT_CMD_MASK, MII_BIT_CMD_RW, MII_BIT_DATA_MASK, MII_BIT_DRIVE, MII_BIT_PHY_MASK, MII_BIT_REG_MASK, MII_BIT_START, MII_BIT_START_MASK, MII_BIT_SWITCH, MII_BIT_SWITCH_MASK, mii_bit_xfer(), and write_bit().

Referenced by mii_bit_read(), and mii_bit_write().

                                                                       {

        /* Initiate drive for write */
        write_bit ( basher, MII_BIT_DRIVE, 1 );

        /* Write start */
        mii_bit_xfer ( basher, MII_BIT_START_MASK, MII_BIT_START );

        /* Write command */
        mii_bit_xfer ( basher, MII_BIT_CMD_MASK, cmd );

        /* Write PHY address */
        mii_bit_xfer ( basher, MII_BIT_PHY_MASK, phy );

        /* Write register address */
        mii_bit_xfer ( basher, MII_BIT_REG_MASK, reg );

        /* Switch drive to read if applicable */
        write_bit ( basher, MII_BIT_DRIVE, ( cmd & MII_BIT_CMD_RW ) );

        /* Allow space for turnaround */
        mii_bit_xfer ( basher, MII_BIT_SWITCH_MASK, MII_BIT_SWITCH );

        /* Read or write data */
        data = mii_bit_xfer (basher, MII_BIT_DATA_MASK, data );

        /* Initiate drive for read */
        write_bit ( basher, MII_BIT_DRIVE, 0 );

        return data;
}
static int mii_bit_read ( struct mii_interface mdio,
unsigned int  phy,
unsigned int  reg 
) [static]

Read from MII register.

Parameters:
mdioMII interface
phyPHY address
regRegister address
Return values:
dataData read, or negative error

Definition at line 121 of file mii_bit.c.

References mii_bit_basher::basher, container_of, MII_BIT_CMD_READ, and mii_bit_rw().

                                             {
        struct mii_bit_basher *miibit =
                container_of ( mdio, struct mii_bit_basher, mdio );
        struct bit_basher *basher = &miibit->basher;

        return mii_bit_rw ( basher, phy, reg, 0, MII_BIT_CMD_READ );
}
static int mii_bit_write ( struct mii_interface mdio,
unsigned int  phy,
unsigned int  reg,
unsigned int  data 
) [static]

Write to MII register.

Parameters:
mdioMII interface
phyPHY address
regRegister address
dataData to write
Return values:
rcReturn status code

Definition at line 139 of file mii_bit.c.

References mii_bit_basher::basher, container_of, MII_BIT_CMD_WRITE, and mii_bit_rw().

                                                                 {
        struct mii_bit_basher *miibit =
                container_of ( mdio, struct mii_bit_basher, mdio );
        struct bit_basher *basher = &miibit->basher;

        mii_bit_rw ( basher, phy, reg, data, MII_BIT_CMD_WRITE );
        return 0;
}
void init_mii_bit_basher ( struct mii_bit_basher miibit)

Initialise bit-bashing interface.

Parameters:
miibitMII bit basher

Definition at line 160 of file mii_bit.c.

References mii_bit_basher::mdio, and mdio_init().

Referenced by icplus_probe().

                                                           {
        mdio_init ( &miibit->mdio, &mii_bit_op );
};

Variable Documentation

struct mii_operations mii_bit_op [static]
Initial value:
 {
        .read = mii_bit_read,
        .write = mii_bit_write,
}

MII bit basher operations.

Definition at line 150 of file mii_bit.c.