drivers/input/keyboard/tm2-touchkey.c

Source file repositories/reference/linux-study-clean/drivers/input/keyboard/tm2-touchkey.c

File Facts

System
Linux kernel
Corpus path
drivers/input/keyboard/tm2-touchkey.c
Extension
.c
Size
9672 bytes
Lines
367
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 touchkey_variant {
	u8 keycode_reg;
	u8 base_reg;
	u8 cmd_led_on;
	u8 cmd_led_off;
	bool no_reg;
	bool fixed_regulator;
};

struct tm2_touchkey_data {
	struct i2c_client *client;
	struct input_dev *input_dev;
	struct led_classdev led_dev;
	struct regulator *vdd;
	struct regulator_bulk_data regulators[3];
	const struct touchkey_variant *variant;
	u32 keycodes[4];
	int num_keycodes;
};

static const struct touchkey_variant tm2_touchkey_variant = {
	.keycode_reg = 0x03,
	.base_reg = 0x00,
	.cmd_led_on = TM2_TOUCHKEY_CMD_LED_ON,
	.cmd_led_off = TM2_TOUCHKEY_CMD_LED_OFF,
};

static const struct touchkey_variant midas_touchkey_variant = {
	.keycode_reg = 0x00,
	.base_reg = 0x00,
	.cmd_led_on = TM2_TOUCHKEY_CMD_LED_ON,
	.cmd_led_off = TM2_TOUCHKEY_CMD_LED_OFF,
};

static struct touchkey_variant aries_touchkey_variant = {
	.no_reg = true,
	.fixed_regulator = true,
	.cmd_led_on = ARIES_TOUCHKEY_CMD_LED_ON,
	.cmd_led_off = ARIES_TOUCHKEY_CMD_LED_OFF,
};

static const struct touchkey_variant tc360_touchkey_variant = {
	.keycode_reg = 0x00,
	.base_reg = 0x00,
	.fixed_regulator = true,
	.cmd_led_on = TM2_TOUCHKEY_CMD_LED_ON,
	.cmd_led_off = TM2_TOUCHKEY_CMD_LED_OFF,
};

static int tm2_touchkey_led_brightness_set(struct led_classdev *led_dev,
					    enum led_brightness brightness)
{
	struct tm2_touchkey_data *touchkey =
		container_of(led_dev, struct tm2_touchkey_data, led_dev);
	u32 volt;
	u8 data;

	if (brightness == LED_OFF) {
		volt = TM2_TOUCHKEY_LED_VOLTAGE_MIN;
		data = touchkey->variant->cmd_led_off;
	} else {
		volt = TM2_TOUCHKEY_LED_VOLTAGE_MAX;
		data = touchkey->variant->cmd_led_on;
	}

	if (!touchkey->variant->fixed_regulator)
		regulator_set_voltage(touchkey->vdd, volt, volt);

	return touchkey->variant->no_reg ?
		i2c_smbus_write_byte(touchkey->client, data) :
		i2c_smbus_write_byte_data(touchkey->client,
					  touchkey->variant->base_reg, data);
}

static int tm2_touchkey_power_enable(struct tm2_touchkey_data *touchkey)
{
	int error;

	error = regulator_bulk_enable(ARRAY_SIZE(touchkey->regulators),
				      touchkey->regulators);
	if (error)
		return error;

	/* waiting for device initialization, at least 150ms */
	msleep(150);

	return 0;
}

static void tm2_touchkey_power_disable(void *data)

Annotation

Implementation Notes