/*
 * lan91c111_io.c
 *
 * Routines for accessing the lan91c111 ethernet controller attached to our CF slots
 */

#include <common.h>
#include <command.h>
#include <config.h>
#include "../../drivers/smc91111.h"
#include "../../drivers/lan91c111_io.h"

#ifdef CONFIG_DRIVER_SMC91111

inline byte SMC_inb(dword offset)
{
    return *(volatile byte *) (CONFIG_SMC91111_BASE + ((offset * 2) + 1));
}

inline void SMC_outb(byte value, dword offset)
{
    *(volatile byte *) (CONFIG_SMC91111_BASE + ((offset * 2) + 1)) = value;
}

inline word SMC_inw(dword offset)
{
    word w;
    w = (((word) SMC_inb(offset) & 0xFF) | ((word) SMC_inb(offset + 1) << 8));
    return w;
}

inline void SMC_outw(word value, dword offset)
{
    SMC_outb((byte)(value & 0xFF), offset);
    SMC_outb((byte)(value >> 8), offset + 1);
}

inline void SMC_insw(dword offset, volatile uchar * buf, dword len)
{
    volatile byte *p = (volatile byte *) buf;
    while (len-- > 0) {
        *p++ = SMC_inb(offset);
        *p++ = SMC_inb(offset + 1);
    }
}

inline void SMC_outsw(dword offset, uchar * buf, dword len)
{
    volatile byte *p = (volatile byte *) buf;

    while (len-- > 0) {
        SMC_outb(*p++, offset);
        SMC_outb(*p++, offset + 1);
    }
}

#endif
