Пример #1
0
static int abituguru_write(struct abituguru_data *data,
	u8 bank_addr, u8 sensor_addr, u8 *buf, int count)
{
	
	int i, timeout = ABIT_UGURU_READY_TIMEOUT;

	
	i = abituguru_send_address(data, bank_addr, sensor_addr,
		ABIT_UGURU_MAX_RETRIES);
	if (i)
		return i;

	
	for (i = 0; i < count; i++) {
		if (abituguru_wait(data, ABIT_UGURU_STATUS_WRITE)) {
			ABIT_UGURU_DEBUG(1, "timeout exceeded waiting for "
				"write state (bank: %d, sensor: %d)\n",
				(int)bank_addr, (int)sensor_addr);
			break;
		}
		outb(buf[i], data->addr + ABIT_UGURU_CMD);
	}

	
	if (abituguru_wait(data, ABIT_UGURU_STATUS_READ)) {
		ABIT_UGURU_DEBUG(1, "timeout exceeded waiting for read state "
			"after write (bank: %d, sensor: %d)\n", (int)bank_addr,
			(int)sensor_addr);
		return -EIO;
	}

	
	while (inb_p(data->addr + ABIT_UGURU_CMD) != 0xAC) {
		timeout--;
		if (timeout == 0) {
			ABIT_UGURU_DEBUG(1, "CMD reg does not hold 0xAC after "
				"write (bank: %d, sensor: %d)\n",
				(int)bank_addr, (int)sensor_addr);
			return -EIO;
		}
		msleep(0);
	}

	
	abituguru_ready(data);

	return i;
}
static int abituguru_read(struct abituguru_data *data,
                          u8 bank_addr, u8 sensor_addr, u8 *buf, int count, int retries)
{
    int i;


    i = abituguru_send_address(data, bank_addr, sensor_addr, retries);
    if (i)
        return i;


    for (i = 0; i < count; i++) {
        if (abituguru_wait(data, ABIT_UGURU_STATUS_READ)) {
            ABIT_UGURU_DEBUG(retries ? 1 : 3,
                             "timeout exceeded waiting for "
                             "read state (bank: %d, sensor: %d)\n",
                             (int)bank_addr, (int)sensor_addr);
            break;
        }
        buf[i] = inb(data->addr + ABIT_UGURU_CMD);
    }


    abituguru_ready(data);

    return i;
}
static int abituguru_send_address(struct abituguru_data *data,
                                  u8 bank_addr, u8 sensor_addr, int retries)
{
    int report_errors = retries;

    for (;;) {
        if (abituguru_ready(data) != 0)
            return -EIO;
        outb(bank_addr, data->addr + ABIT_UGURU_DATA);
        data->uguru_ready = 0;

        if (abituguru_wait(data, ABIT_UGURU_STATUS_INPUT)) {
            if (retries) {
                ABIT_UGURU_DEBUG(3, "timeout exceeded "
                                 "waiting for more input state, %d "
                                 "tries remaining\n", retries);
                set_current_state(TASK_UNINTERRUPTIBLE);
                schedule_timeout(ABIT_UGURU_RETRY_DELAY);
                retries--;
                continue;
            }
            if (report_errors)
                ABIT_UGURU_DEBUG(1, "timeout exceeded "
                                 "waiting for more input state "
                                 "(bank: %d)\n", (int)bank_addr);
            return -EBUSY;
        }
        outb(sensor_addr, data->addr + ABIT_UGURU_CMD);
        return 0;
    }
}
Пример #4
0
static int abituguru_ready(struct abituguru_data *data)
{
	int timeout = ABIT_UGURU_READY_TIMEOUT;

	if (data->uguru_ready)
		return 0;

	
	outb(0x00, data->addr + ABIT_UGURU_DATA);

	
	if (abituguru_wait(data, ABIT_UGURU_STATUS_READY)) {
		ABIT_UGURU_DEBUG(1,
			"timeout exceeded waiting for ready state\n");
		return -EIO;
	}

	
	while (inb_p(data->addr + ABIT_UGURU_CMD) != 0xAC) {
		timeout--;
		if (timeout == 0) {
			ABIT_UGURU_DEBUG(1,
			   "CMD reg does not hold 0xAC after ready command\n");
			return -EIO;
		}
		msleep(0);
	}

	
	timeout = ABIT_UGURU_READY_TIMEOUT;
	while (inb_p(data->addr + ABIT_UGURU_DATA) != ABIT_UGURU_STATUS_INPUT) {
		timeout--;
		if (timeout == 0) {
			ABIT_UGURU_DEBUG(1,
				"state != more input after ready command\n");
			return -EIO;
		}
		msleep(0);
	}

	data->uguru_ready = 1;
	return 0;
}