drivers/input/misc/max8997_haptic.c

Source file repositories/reference/linux-study-clean/drivers/input/misc/max8997_haptic.c

File Facts

System
Linux kernel
Corpus path
drivers/input/misc/max8997_haptic.c
Extension
.c
Size
9833 bytes
Lines
393
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 max8997_haptic {
	struct device *dev;
	struct i2c_client *client;
	struct input_dev *input_dev;
	struct regulator *regulator;

	struct work_struct work;
	struct mutex mutex;

	bool enabled;
	unsigned int level;

	struct pwm_device *pwm;
	unsigned int pwm_period;
	enum max8997_haptic_pwm_divisor pwm_divisor;

	enum max8997_haptic_motor_type type;
	enum max8997_haptic_pulse_mode mode;

	unsigned int internal_mode_pattern;
	unsigned int pattern_cycle;
	unsigned int pattern_signal_period;
};

static void max8997_haptic_set_internal_duty_cycle(struct max8997_haptic *chip)
{
	u8 duty_index = DIV_ROUND_UP(chip->level * 64, 100);

	switch (chip->internal_mode_pattern) {
	case 0:
		max8997_write_reg(chip->client,
				  MAX8997_HAPTIC_REG_SIGPWMDC1, duty_index);
		break;
	case 1:
		max8997_write_reg(chip->client,
				  MAX8997_HAPTIC_REG_SIGPWMDC2, duty_index);
		break;
	case 2:
		max8997_write_reg(chip->client,
				  MAX8997_HAPTIC_REG_SIGPWMDC3, duty_index);
		break;
	case 3:
		max8997_write_reg(chip->client,
				  MAX8997_HAPTIC_REG_SIGPWMDC4, duty_index);
		break;
	default:
		break;
	}
}

static void max8997_haptic_configure(struct max8997_haptic *chip)
{
	u8 value;

	value = chip->type << MAX8997_MOTOR_TYPE_SHIFT |
		chip->enabled << MAX8997_ENABLE_SHIFT |
		chip->mode << MAX8997_MODE_SHIFT | chip->pwm_divisor;
	max8997_write_reg(chip->client, MAX8997_HAPTIC_REG_CONF2, value);

	if (chip->mode == MAX8997_INTERNAL_MODE && chip->enabled) {
		value = chip->internal_mode_pattern << MAX8997_CYCLE_SHIFT |
			chip->internal_mode_pattern << MAX8997_SIG_PERIOD_SHIFT |
			chip->internal_mode_pattern << MAX8997_SIG_DUTY_SHIFT |
			chip->internal_mode_pattern << MAX8997_PWM_DUTY_SHIFT;
		max8997_write_reg(chip->client,
			MAX8997_HAPTIC_REG_DRVCONF, value);

		switch (chip->internal_mode_pattern) {
		case 0:
			value = chip->pattern_cycle << 4;
			max8997_write_reg(chip->client,
				MAX8997_HAPTIC_REG_CYCLECONF1, value);
			value = chip->pattern_signal_period;
			max8997_write_reg(chip->client,
				MAX8997_HAPTIC_REG_SIGCONF1, value);
			break;

		case 1:
			value = chip->pattern_cycle;
			max8997_write_reg(chip->client,
				MAX8997_HAPTIC_REG_CYCLECONF1, value);
			value = chip->pattern_signal_period;
			max8997_write_reg(chip->client,
				MAX8997_HAPTIC_REG_SIGCONF2, value);
			break;

		case 2:
			value = chip->pattern_cycle << 4;
			max8997_write_reg(chip->client,
				MAX8997_HAPTIC_REG_CYCLECONF2, value);

Annotation

Implementation Notes