示例#1
0
文件: smbus.c 项目: 0ida/coreboot
unsigned char do_smbus_read_byte(unsigned smbus_io_base,
                                 unsigned char device,
                                 unsigned char address)
{
    unsigned char error = 0;

    if ((smbus_check_stop_condition(smbus_io_base))) {
        error = 1;
        goto err;
    }

    if ((smbus_start_condition(smbus_io_base))) {
        error = 2;
        goto err;
    }

    if ((smbus_send_slave_address(smbus_io_base, device << 1))) {
        error = 3;
        goto err;
    }

    smbus_ack(smbus_io_base, 1);

    if ((smbus_send_command(smbus_io_base, address))) {
        error = 4;
        goto err;
    }

    if ((smbus_start_condition(smbus_io_base))) {
        error = 5;
        goto err;
    }

    if ((smbus_send_slave_address(smbus_io_base, (device << 1) | 0x01))) {
        error = 6;
        goto err;
    }

    if ((smbus_stop_condition(smbus_io_base))) {
        error = 7;
        goto err;
    }

    return smbus_get_result(smbus_io_base);

err:
    print_debug("SMBUS READ ERROR:");
    print_debug_hex8(error);
    print_debug(" device:");
    print_debug_hex8(device);
    print_debug("\n");
    /* stop, clean up the error, and leave */
    smbus_stop_condition(smbus_io_base);
    outb(inb(smbus_io_base + SMB_STS), smbus_io_base + SMB_STS);
    outb(0x0, smbus_io_base + SMB_STS);
    return 0xFF;
}
示例#2
0
/* Send config data to System Management Controller via SMB. */
static int smc_send_config(unsigned char config_data)
{
	if (smbus_check_stop_condition(SMBUS_IO_BASE))
		return 1;
	if (smbus_start_condition(SMBUS_IO_BASE))
		return 2;
	if (smbus_send_slave_address(SMBUS_IO_BASE, 0x50)) // SMC address
		return 3;
	if (smbus_send_command(SMBUS_IO_BASE, 0x28)) // set config data
		return 4;
	if (smbus_send_command(SMBUS_IO_BASE, 0x01)) // data length
		return 5;
	if (smbus_send_command(SMBUS_IO_BASE, config_data))
		return 6;
	smbus_stop_condition(SMBUS_IO_BASE);
	return 0;
}