Lines Matching refs:haptic
3 * Regulator haptic driver
13 #include <linux/platform_data/regulator-haptic.h>
36 static int regulator_haptic_toggle(struct regulator_haptic *haptic, bool on)
40 if (haptic->active != on) {
42 error = on ? regulator_enable(haptic->regulator) :
43 regulator_disable(haptic->regulator);
45 dev_err(haptic->dev,
51 haptic->active = on;
57 static int regulator_haptic_set_voltage(struct regulator_haptic *haptic,
64 volt_mag_multi = (u64)(haptic->max_volt - haptic->min_volt) * magnitude;
67 error = regulator_set_voltage(haptic->regulator,
68 intensity + haptic->min_volt,
69 haptic->max_volt);
71 dev_err(haptic->dev, "cannot set regulator voltage to %d: %d\n",
72 intensity + haptic->min_volt, error);
76 regulator_haptic_toggle(haptic, !!magnitude);
83 struct regulator_haptic *haptic = container_of(work,
86 mutex_lock(&haptic->mutex);
88 if (!haptic->suspended)
89 regulator_haptic_set_voltage(haptic, haptic->magnitude);
91 mutex_unlock(&haptic->mutex);
97 struct regulator_haptic *haptic = input_get_drvdata(input);
99 haptic->magnitude = effect->u.rumble.strong_magnitude;
100 if (!haptic->magnitude)
101 haptic->magnitude = effect->u.rumble.weak_magnitude;
103 schedule_work(&haptic->work);
110 struct regulator_haptic *haptic = input_get_drvdata(input);
112 cancel_work_sync(&haptic->work);
113 regulator_haptic_set_voltage(haptic, 0);
117 regulator_haptic_parse_dt(struct device *dev, struct regulator_haptic *haptic)
128 error = of_property_read_u32(node, "max-microvolt", &haptic->max_volt);
134 error = of_property_read_u32(node, "min-microvolt", &haptic->min_volt);
146 struct regulator_haptic *haptic;
150 haptic = devm_kzalloc(&pdev->dev, sizeof(*haptic), GFP_KERNEL);
151 if (!haptic)
154 platform_set_drvdata(pdev, haptic);
155 haptic->dev = &pdev->dev;
156 mutex_init(&haptic->mutex);
157 INIT_WORK(&haptic->work, regulator_haptic_work);
160 haptic->max_volt = pdata->max_volt;
161 haptic->min_volt = pdata->min_volt;
163 error = regulator_haptic_parse_dt(&pdev->dev, haptic);
171 haptic->regulator = devm_regulator_get_exclusive(&pdev->dev, "haptic");
172 if (IS_ERR(haptic->regulator)) {
174 return PTR_ERR(haptic->regulator);
181 haptic->input_dev = input_dev;
182 haptic->input_dev->name = "regulator-haptic";
183 haptic->input_dev->dev.parent = &pdev->dev;
184 haptic->input_dev->close = regulator_haptic_close;
185 input_set_drvdata(haptic->input_dev, haptic);
186 input_set_capability(haptic->input_dev, EV_FF, FF_RUMBLE);
195 error = input_register_device(haptic->input_dev);
207 struct regulator_haptic *haptic = platform_get_drvdata(pdev);
210 error = mutex_lock_interruptible(&haptic->mutex);
214 regulator_haptic_set_voltage(haptic, 0);
216 haptic->suspended = true;
218 mutex_unlock(&haptic->mutex);
226 struct regulator_haptic *haptic = platform_get_drvdata(pdev);
229 mutex_lock(&haptic->mutex);
231 haptic->suspended = false;
233 magnitude = READ_ONCE(haptic->magnitude);
235 regulator_haptic_set_voltage(haptic, magnitude);
237 mutex_unlock(&haptic->mutex);
246 { .compatible = "regulator-haptic" },
254 .name = "regulator-haptic",
263 MODULE_DESCRIPTION("Regulator haptic driver");