drivers/input/keyboard/iqs62x-keys.c

Source file repositories/reference/linux-study-clean/drivers/input/keyboard/iqs62x-keys.c

File Facts

System
Linux kernel
Corpus path
drivers/input/keyboard/iqs62x-keys.c
Extension
.c
Size
8842 bytes
Lines
334
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

struct iqs62x_switch_desc {
	enum iqs62x_event_flag flag;
	unsigned int code;
	bool enabled;
};

struct iqs62x_keys_private {
	struct iqs62x_core *iqs62x;
	struct input_dev *input;
	struct notifier_block notifier;
	struct iqs62x_switch_desc switches[ARRAY_SIZE(iqs62x_switch_names)];
	unsigned int keycode[IQS62X_NUM_KEYS];
	unsigned int keycodemax;
	u8 interval;
};

static int iqs62x_keys_parse_prop(struct platform_device *pdev,
				  struct iqs62x_keys_private *iqs62x_keys)
{
	unsigned int val;
	int ret, i;

	ret = device_property_count_u32(&pdev->dev, "linux,keycodes");
	if (ret > IQS62X_NUM_KEYS) {
		dev_err(&pdev->dev, "Too many keycodes present\n");
		return -EINVAL;
	} else if (ret < 0) {
		dev_err(&pdev->dev, "Failed to count keycodes: %d\n", ret);
		return ret;
	}
	iqs62x_keys->keycodemax = ret;

	ret = device_property_read_u32_array(&pdev->dev, "linux,keycodes",
					     iqs62x_keys->keycode,
					     iqs62x_keys->keycodemax);
	if (ret) {
		dev_err(&pdev->dev, "Failed to read keycodes: %d\n", ret);
		return ret;
	}

	for (i = 0; i < ARRAY_SIZE(iqs62x_keys->switches); i++) {
		struct fwnode_handle *child __free(fwnode_handle) =
			device_get_named_child_node(&pdev->dev,
						    iqs62x_switch_names[i]);
		if (!child)
			continue;

		ret = fwnode_property_read_u32(child, "linux,code", &val);
		if (ret) {
			dev_err(&pdev->dev, "Failed to read switch code: %d\n",
				ret);
			return ret;
		}
		iqs62x_keys->switches[i].code = val;
		iqs62x_keys->switches[i].enabled = true;

		if (fwnode_property_present(child, "azoteq,use-prox"))
			iqs62x_keys->switches[i].flag = (i == IQS62X_SW_HALL_N ?
							 IQS62X_EVENT_HALL_N_P :
							 IQS62X_EVENT_HALL_S_P);
		else
			iqs62x_keys->switches[i].flag = (i == IQS62X_SW_HALL_N ?
							 IQS62X_EVENT_HALL_N_T :
							 IQS62X_EVENT_HALL_S_T);
	}

	return 0;
}

static int iqs62x_keys_init(struct iqs62x_keys_private *iqs62x_keys)
{
	struct iqs62x_core *iqs62x = iqs62x_keys->iqs62x;
	enum iqs62x_event_flag flag;
	unsigned int event_reg, val;
	unsigned int event_mask = 0;
	int ret, i;

	switch (iqs62x->dev_desc->prod_num) {
	case IQS620_PROD_NUM:
	case IQS621_PROD_NUM:
	case IQS622_PROD_NUM:
		event_reg = IQS620_GLBL_EVENT_MASK;

		/*
		 * Discreet button, hysteresis and SAR UI flags represent keys
		 * and are unmasked if mapped to a valid keycode.
		 */
		for (i = 0; i < iqs62x_keys->keycodemax; i++) {
			if (iqs62x_keys->keycode[i] == KEY_RESERVED)
				continue;

Annotation

Implementation Notes