Beispiel #1
0
static void max8997_haptic_enable(struct max8997_haptic *chip)
{
    int error;

    mutex_lock(&chip->mutex);

    error = max8997_haptic_set_duty_cycle(chip);
    if (error) {
        dev_err(chip->dev, "set_pwm_cycle failed, error: %d\n", error);
        goto out;
    }

    if (!chip->enabled) {
        error = regulator_enable(chip->regulator);
        if (error) {
            dev_err(chip->dev, "Failed to enable regulator\n");
            goto out;
        }
        max8997_haptic_configure(chip);
        if (chip->mode == MAX8997_EXTERNAL_MODE) {
            error = pwm_enable(chip->pwm);
            if (error) {
                dev_err(chip->dev, "Failed to enable PWM\n");
                regulator_disable(chip->regulator);
                goto out;
            }
        }
        chip->enabled = true;
    }

out:
    mutex_unlock(&chip->mutex);
}
static void max8997_haptic_disable(struct max8997_haptic *chip)
{
	mutex_lock(&chip->mutex);

	if (chip->enabled) {
		chip->enabled = false;
		max8997_haptic_configure(chip);
		if (chip->mode == MAX8997_EXTERNAL_MODE)
			pwm_disable(chip->pwm);
		regulator_disable(chip->regulator);
	}

	mutex_unlock(&chip->mutex);
}