drivers/input/mouse/cyapa.c

Source file repositories/reference/linux-study-clean/drivers/input/mouse/cyapa.c

File Facts

System
Linux kernel
Corpus path
drivers/input/mouse/cyapa.c
Extension
.c
Size
37764 bytes
Lines
1500
Domain
Driver Families
Bucket
drivers/input
Inferred role
Driver Families: implementation source
Status
source implementation candidate

Why This File Exists

Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.

Dependency Surface

Detected Declarations

Annotated Snippet

if (!smbus) {
			cmd[0] = 0x00;
			cmd[1] = 0x00;
			error = cyapa_i2c_write(cyapa, 0, 2, cmd);
			if (error)
				goto error;

			msleep(50);

			error = cyapa_i2c_read(cyapa, BL_HEAD_OFFSET,
					BL_STATUS_SIZE, status);
			if (error)
				goto error;
		}
	} while (--retries > 0 && !smbus);

	goto error;

out_detected:
	if (cyapa->state <= CYAPA_STATE_BL_BUSY)
		return -EAGAIN;
	return 0;

error:
	return (error < 0) ? error : -EAGAIN;
}

/*
 * Poll device for its status in a loop, waiting up to timeout for a response.
 *
 * When the device switches state, it usually takes ~300 ms.
 * However, when running a new firmware image, the device must calibrate its
 * sensors, which can take as long as 2 seconds.
 *
 * Note: The timeout has granularity of the polling rate, which is 100 ms.
 *
 * Returns:
 *   0 when the device eventually responds with a valid non-busy state.
 *   -ETIMEDOUT if device never responds (too many -EAGAIN)
 *   -EAGAIN    if bootload is busy, or unknown state.
 *   < 0        other errors
 */
int cyapa_poll_state(struct cyapa *cyapa, unsigned int timeout)
{
	int error;
	int tries = timeout / 100;

	do {
		error = cyapa_get_state(cyapa);
		if (!error && cyapa->state > CYAPA_STATE_BL_BUSY)
			return 0;

		msleep(100);
	} while (tries--);

	return (error == -EAGAIN || error == -ETIMEDOUT) ? -ETIMEDOUT : error;
}

/*
 * Check if device is operational.
 *
 * An operational device is responding, has exited bootloader, and has
 * firmware supported by this driver.
 *
 * Returns:
 *   -ENODEV no device
 *   -EBUSY  no device or in bootloader
 *   -EIO    failure while reading from device
 *   -ETIMEDOUT timeout failure for bus idle or bus no response
 *   -EAGAIN device is still in bootloader
 *           if ->state = CYAPA_STATE_BL_IDLE, device has invalid firmware
 *   -EINVAL device is in operational mode, but not supported by this driver
 *   0       device is supported
 */
static int cyapa_check_is_operational(struct cyapa *cyapa)
{
	int error;

	error = cyapa_poll_state(cyapa, 4000);
	if (error)
		return error;

	switch (cyapa->gen) {
	case CYAPA_GEN6:
		cyapa->ops = &cyapa_gen6_ops;
		break;
	case CYAPA_GEN5:
		cyapa->ops = &cyapa_gen5_ops;
		break;
	case CYAPA_GEN3:

Annotation

Implementation Notes