static inline void WRITE_SERCSR(u32 val, u32 *addr, int line)
{
	csr_out32(val, addr);
#if SIBYTE_1956_WAR
	csr_out32(last_mode1[line], uart_states[line].mode_1);
#endif
}
static inline u32 READ_SERCSR(u32 *addr, int line)
{
	u32 val = csr_in32(addr);
#if SIBYTE_1956_WAR
	csr_out32(last_mode1[line], uart_states[line].mode_1);
#endif
	return val;
}
/* 
 * registering functions to load algorithms at runtime 
 */
int i2c_sibyte_add_bus(struct i2c_adapter *i2c_adap, int speed)
{
	int i;
	struct i2c_algo_sibyte_data *adap = i2c_adap->algo_data;

	/* register new adapter to i2c module... */

	i2c_adap->id |= i2c_sibyte_algo.id;
	i2c_adap->algo = &i2c_sibyte_algo;
        
        /* Set the frequency to 100 kHz */
        csr_out32(speed, SMB_CSR(adap,R_SMB_FREQ));
        csr_out32(0, SMB_CSR(adap,R_SMB_CONTROL));

	/* scan bus */
	if (bit_scan) {
                union i2c_smbus_data data;
                int rc;
		printk(KERN_INFO " i2c-algo-sibyte.o: scanning bus %s.\n",
		       i2c_adap->name);
		for (i = 0x00; i < 0x7f; i++) {
                        /* XXXKW is this a realistic probe? */
                        rc = smbus_xfer(i2c_adap, i, 0, I2C_SMBUS_READ, 0,
                                        I2C_SMBUS_BYTE_DATA, &data);
			if (!rc) {
				printk("(%02x)",i); 
			} else 
				printk("."); 
		}
		printk("\n");
	}

#ifdef MODULE
	MOD_INC_USE_COUNT;
#endif
	i2c_add_adapter(i2c_adap);

	return 0;
}
static int smbus_xfer(struct i2c_adapter *i2c_adap, u16 addr,
                      unsigned short flags, char read_write,
                      u8 command, int size, union i2c_smbus_data * data)
{
    struct i2c_algo_sibyte_data *adap = i2c_adap->algo_data;
    int data_bytes = 0;
    int error;

    while (csr_in32(SMB_CSR(adap, R_SMB_STATUS)) & M_SMB_BUSY)
        ;

    switch (size) {
    case I2C_SMBUS_QUICK:
        csr_out32((V_SMB_ADDR(addr) | (read_write == I2C_SMBUS_READ ? M_SMB_QDATA : 0) |
                   V_SMB_TT_QUICKCMD), SMB_CSR(adap, R_SMB_START));
        break;
    case I2C_SMBUS_BYTE:
        if (read_write == I2C_SMBUS_READ) {
            csr_out32((V_SMB_ADDR(addr) | V_SMB_TT_RD1BYTE),
                      SMB_CSR(adap, R_SMB_START));
            data_bytes = 1;
        } else {
            csr_out32(V_SMB_CMD(command), SMB_CSR(adap, R_SMB_CMD));
            csr_out32((V_SMB_ADDR(addr) | V_SMB_TT_WR1BYTE),
                      SMB_CSR(adap, R_SMB_START));
        }
        break;
    case I2C_SMBUS_BYTE_DATA:
        csr_out32(V_SMB_CMD(command), SMB_CSR(adap, R_SMB_CMD));
        if (read_write == I2C_SMBUS_READ) {
            csr_out32((V_SMB_ADDR(addr) | V_SMB_TT_CMD_RD1BYTE),
                      SMB_CSR(adap, R_SMB_START));
            data_bytes = 1;
        } else {
            csr_out32(V_SMB_LB(data->byte), SMB_CSR(adap, R_SMB_DATA));
            csr_out32((V_SMB_ADDR(addr) | V_SMB_TT_WR2BYTE),
                      SMB_CSR(adap, R_SMB_START));
        }
        break;
    case I2C_SMBUS_WORD_DATA:
        csr_out32(V_SMB_CMD(command), SMB_CSR(adap, R_SMB_CMD));
        if (read_write == I2C_SMBUS_READ) {
            csr_out32((V_SMB_ADDR(addr) | V_SMB_TT_CMD_RD2BYTE),
                      SMB_CSR(adap, R_SMB_START));
            data_bytes = 2;
        } else {
            csr_out32(V_SMB_LB(data->word & 0xff), SMB_CSR(adap, R_SMB_DATA));
            csr_out32(V_SMB_MB(data->word >> 8), SMB_CSR(adap, R_SMB_DATA));
            csr_out32((V_SMB_ADDR(addr) | V_SMB_TT_WR2BYTE),
                      SMB_CSR(adap, R_SMB_START));
        }
        break;
    default:
        return -1;      /* XXXKW better error code? */
    }

    while (csr_in32(SMB_CSR(adap, R_SMB_STATUS)) & M_SMB_BUSY)
        ;

    error = csr_in32(SMB_CSR(adap, R_SMB_STATUS));
    if (error & M_SMB_ERROR) {
        /* Clear error bit by writing a 1 */
        csr_out32(M_SMB_ERROR, SMB_CSR(adap, R_SMB_STATUS));
        return -1;      /* XXXKW better error code? */
    }

    if (data_bytes == 1)
        data->byte = csr_in32(SMB_CSR(adap, R_SMB_DATA)) & 0xff;
    if (data_bytes == 2)
        data->word = csr_in32(SMB_CSR(adap, R_SMB_DATA)) & 0xffff;

    return 0;
}