drivers/hid/hid-plantronics.c

Source file repositories/reference/linux-study-clean/drivers/hid/hid-plantronics.c

File Facts

System
Linux kernel
Corpus path
drivers/hid/hid-plantronics.c
Extension
.c
Size
7233 bytes
Lines
251
Domain
Driver Families
Bucket
drivers/hid
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

struct plt_drv_data {
	unsigned long device_type;
	unsigned long last_key_ts;
	unsigned long double_key_to;
	__u16 last_key;
};

static int plantronics_input_mapping(struct hid_device *hdev,
				     struct hid_input *hi,
				     struct hid_field *field,
				     struct hid_usage *usage,
				     unsigned long **bit, int *max)
{
	unsigned short mapped_key;
	struct plt_drv_data *drv_data = hid_get_drvdata(hdev);
	unsigned long plt_type = drv_data->device_type;
	int allow_mute = usage->hid == HID_TELEPHONY_MUTE;
	int allow_consumer = field->application == HID_CP_CONSUMERCONTROL &&
			(usage->hid & HID_USAGE_PAGE) == HID_UP_CONSUMER &&
			usage->hid != HID_CONSUMER_MUTE;

	/* special case for PTT products */
	if (field->application == HID_GD_JOYSTICK)
		goto defaulted;

	/* non-standard types or multi-HID interfaces - plt_type is PID */
	if (!(plt_type & HID_USAGE_PAGE)) {
		switch (plt_type) {
		case PLT_DA60:
			if (allow_consumer)
				goto defaulted;
			if (usage->hid == HID_CONSUMER_MUTE) {
				mapped_key = KEY_MICMUTE;
				goto mapped;
			}
			break;
		default:
			if (allow_consumer || allow_mute)
				goto defaulted;
		}
		goto ignored;
	}

	/* handle standard consumer control mapping */
	/* and standard telephony mic mute mapping */
	if (allow_consumer || allow_mute)
		goto defaulted;

	/* handle vendor unique types - plt_type is 0xffa0uuuu or 0xffa2uuuu */
	/* if not 'basic telephony compliant' - map vendor unique controls */
	if (!((plt_type & HID_USAGE) >= PLT_BASIC_TELEPHONY &&
	      (plt_type & HID_USAGE) != PLT_BASIC_EXCEPTION) &&
	      !((field->application ^ plt_type) & HID_USAGE_PAGE))
		switch (usage->hid) {
		case PLT1_VOL_UP:
		case PLT2_VOL_UP:
			mapped_key = KEY_VOLUMEUP;
			goto mapped;
		case PLT1_VOL_DOWN:
		case PLT2_VOL_DOWN:
			mapped_key = KEY_VOLUMEDOWN;
			goto mapped;
		case PLT1_MIC_MUTE:
		case PLT2_MIC_MUTE:
			mapped_key = KEY_MICMUTE;
			goto mapped;
		}

/*
 * Future mapping of call control or other usages,
 * if and when keys are defined would go here
 * otherwise, ignore everything else that was not mapped
 */

ignored:
	hid_dbg(hdev, "usage: %08x (appl: %08x) - ignored\n",
		usage->hid, field->application);
	return -1;

defaulted:
	hid_dbg(hdev, "usage: %08x (appl: %08x) - defaulted\n",
		usage->hid, field->application);
	return 0;

mapped:
	hid_map_usage_clear(hi, usage, bit, max, EV_KEY, mapped_key);
	hid_dbg(hdev, "usage: %08x (appl: %08x) - mapped to key %d\n",
		usage->hid, field->application, mapped_key);
	return 1;
}

Annotation

Implementation Notes