drivers/input/joystick/iforce/iforce-main.c

Source file repositories/reference/linux-study-clean/drivers/input/joystick/iforce/iforce-main.c

File Facts

System
Linux kernel
Corpus path
drivers/input/joystick/iforce/iforce-main.c
Extension
.c
Size
11253 bytes
Lines
401
Domain
Driver Families
Bucket
drivers/input
Inferred role
Driver Families: exported/initcall integration point
Status
integration 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 (test_bit(FF_CORE_IS_USED, iforce->core_effects[i].flags)) {
				dev_warn(&dev->dev,
					"%s: Device still owns effects\n",
					__func__);
				break;
			}
		}

		/* Disable force feedback playback */
		iforce_send_packet(iforce, FF_CMD_ENABLE, "\001");
		/* Wait for the command to complete */
		wait_event_interruptible(iforce->wait,
			!test_bit(IFORCE_XMIT_RUNNING, iforce->xmit_flags));
	}

	iforce->xport_ops->stop_io(iforce);
}

int iforce_init_device(struct device *parent, u16 bustype,
		       struct iforce *iforce)
{
	struct input_dev *input_dev;
	struct ff_device *ff;
	u8 c[] = "CEOV";
	u8 buf[IFORCE_MAX_LENGTH];
	size_t len;
	int i, error;
	int ff_effects = 0;

	input_dev = input_allocate_device();
	if (!input_dev)
		return -ENOMEM;

	init_waitqueue_head(&iforce->wait);
	spin_lock_init(&iforce->xmit_lock);
	mutex_init(&iforce->mem_mutex);
	iforce->xmit.buf = iforce->xmit_data;
	iforce->dev = input_dev;

/*
 * Input device fields.
 */

	input_dev->id.bustype = bustype;
	input_dev->dev.parent = parent;

	input_set_drvdata(input_dev, iforce);

	input_dev->name = "Unknown I-Force device";
	input_dev->open = iforce_open;
	input_dev->close = iforce_close;

/*
 * On-device memory allocation.
 */

	iforce->device_memory.name = "I-Force device effect memory";
	iforce->device_memory.start = 0;
	iforce->device_memory.end = 200;
	iforce->device_memory.flags = IORESOURCE_MEM;
	iforce->device_memory.parent = NULL;
	iforce->device_memory.child = NULL;
	iforce->device_memory.sibling = NULL;

/*
 * Wait until device ready - until it sends its first response.
 */

	for (i = 0; i < 20; i++)
		if (!iforce_get_id_packet(iforce, 'O', buf, &len))
			break;

	if (i == 20) { /* 5 seconds */
		dev_err(&input_dev->dev,
			"Timeout waiting for response from device.\n");
		error = -ENODEV;
		goto fail;
	}

/*
 * Get device info.
 */

	if (!iforce_get_id_packet(iforce, 'M', buf, &len) && len >= 3)
		input_dev->id.vendor = get_unaligned_le16(buf + 1);
	else
		dev_warn(&iforce->dev->dev, "Device does not respond to id packet M\n");

	if (!iforce_get_id_packet(iforce, 'P', buf, &len) && len >= 3)
		input_dev->id.product = get_unaligned_le16(buf + 1);

Annotation

Implementation Notes