Lines Matching +full:regulator +full:- +full:haptic
1 // SPDX-License-Identifier: GPL-2.0-only
17 #include <linux/regulator/consumer.h>
92 * struct drv2667_data -
97 * @regulator: Pointer to the regulator for the IC
107 struct regulator *regulator; member
138 freq = (haptics->frequency * 1000) / 78125; in drv2667_set_waveform_freq()
140 dev_err(&haptics->client->dev, in drv2667_set_waveform_freq()
142 return -EINVAL; in drv2667_set_waveform_freq()
145 error = regmap_read(haptics->regmap, DRV2667_PAGE, &read_buf); in drv2667_set_waveform_freq()
147 dev_err(&haptics->client->dev, in drv2667_set_waveform_freq()
149 return -EIO; in drv2667_set_waveform_freq()
153 haptics->page != read_buf) { in drv2667_set_waveform_freq()
154 error = regmap_write(haptics->regmap, in drv2667_set_waveform_freq()
155 DRV2667_PAGE, haptics->page); in drv2667_set_waveform_freq()
157 dev_err(&haptics->client->dev, in drv2667_set_waveform_freq()
159 return -EIO; in drv2667_set_waveform_freq()
163 error = regmap_write(haptics->regmap, DRV2667_RAM_FREQ, freq); in drv2667_set_waveform_freq()
165 dev_err(&haptics->client->dev, in drv2667_set_waveform_freq()
170 haptics->page != read_buf) { in drv2667_set_waveform_freq()
171 error = regmap_write(haptics->regmap, DRV2667_PAGE, read_buf); in drv2667_set_waveform_freq()
173 dev_err(&haptics->client->dev, in drv2667_set_waveform_freq()
175 return -EIO; in drv2667_set_waveform_freq()
187 if (haptics->magnitude) { in drv2667_worker()
188 error = regmap_write(haptics->regmap, in drv2667_worker()
189 DRV2667_PAGE, haptics->page); in drv2667_worker()
191 dev_err(&haptics->client->dev, in drv2667_worker()
196 error = regmap_write(haptics->regmap, DRV2667_RAM_AMP, in drv2667_worker()
197 haptics->magnitude); in drv2667_worker()
199 dev_err(&haptics->client->dev, in drv2667_worker()
204 error = regmap_write(haptics->regmap, in drv2667_worker()
207 dev_err(&haptics->client->dev, in drv2667_worker()
212 error = regmap_write(haptics->regmap, in drv2667_worker()
215 dev_err(&haptics->client->dev, in drv2667_worker()
219 error = regmap_update_bits(haptics->regmap, DRV2667_CTRL_2, in drv2667_worker()
222 dev_err(&haptics->client->dev, in drv2667_worker()
233 if (effect->u.rumble.strong_magnitude > 0) in drv2667_haptics_play()
234 haptics->magnitude = effect->u.rumble.strong_magnitude; in drv2667_haptics_play()
235 else if (effect->u.rumble.weak_magnitude > 0) in drv2667_haptics_play()
236 haptics->magnitude = effect->u.rumble.weak_magnitude; in drv2667_haptics_play()
238 haptics->magnitude = 0; in drv2667_haptics_play()
240 schedule_work(&haptics->work); in drv2667_haptics_play()
250 cancel_work_sync(&haptics->work); in drv2667_close()
252 error = regmap_update_bits(haptics->regmap, DRV2667_CTRL_2, in drv2667_close()
255 dev_err(&haptics->client->dev, in drv2667_close()
282 /* Set default haptic frequency to 195Hz on Page 1*/ in drv2667_init()
283 haptics->frequency = 195; in drv2667_init()
284 haptics->page = DRV2667_PAGE_1; in drv2667_init()
286 error = regmap_register_patch(haptics->regmap, in drv2667_init()
290 dev_err(&haptics->client->dev, in drv2667_init()
296 error = regmap_write(haptics->regmap, DRV2667_PAGE, haptics->page); in drv2667_init()
298 dev_err(&haptics->client->dev, "Failed to set page: %d\n", in drv2667_init()
307 error = regmap_register_patch(haptics->regmap, in drv2667_init()
311 dev_err(&haptics->client->dev, in drv2667_init()
317 error = regmap_write(haptics->regmap, DRV2667_PAGE, DRV2667_PAGE_0); in drv2667_init()
321 regmap_write(haptics->regmap, DRV2667_PAGE, DRV2667_PAGE_0); in drv2667_init()
341 haptics = devm_kzalloc(&client->dev, sizeof(*haptics), GFP_KERNEL); in drv2667_probe()
343 return -ENOMEM; in drv2667_probe()
345 haptics->regulator = devm_regulator_get(&client->dev, "vbat"); in drv2667_probe()
346 if (IS_ERR(haptics->regulator)) { in drv2667_probe()
347 error = PTR_ERR(haptics->regulator); in drv2667_probe()
348 dev_err(&client->dev, in drv2667_probe()
349 "unable to get regulator, error: %d\n", error); in drv2667_probe()
353 haptics->input_dev = devm_input_allocate_device(&client->dev); in drv2667_probe()
354 if (!haptics->input_dev) { in drv2667_probe()
355 dev_err(&client->dev, "Failed to allocate input device\n"); in drv2667_probe()
356 return -ENOMEM; in drv2667_probe()
359 haptics->input_dev->name = "drv2667:haptics"; in drv2667_probe()
360 haptics->input_dev->dev.parent = client->dev.parent; in drv2667_probe()
361 haptics->input_dev->close = drv2667_close; in drv2667_probe()
362 input_set_drvdata(haptics->input_dev, haptics); in drv2667_probe()
363 input_set_capability(haptics->input_dev, EV_FF, FF_RUMBLE); in drv2667_probe()
365 error = input_ff_create_memless(haptics->input_dev, NULL, in drv2667_probe()
368 dev_err(&client->dev, "input_ff_create() failed: %d\n", in drv2667_probe()
373 INIT_WORK(&haptics->work, drv2667_worker); in drv2667_probe()
375 haptics->client = client; in drv2667_probe()
378 haptics->regmap = devm_regmap_init_i2c(client, &drv2667_regmap_config); in drv2667_probe()
379 if (IS_ERR(haptics->regmap)) { in drv2667_probe()
380 error = PTR_ERR(haptics->regmap); in drv2667_probe()
381 dev_err(&client->dev, "Failed to allocate register map: %d\n", in drv2667_probe()
388 dev_err(&client->dev, "Device init failed: %d\n", error); in drv2667_probe()
392 error = input_register_device(haptics->input_dev); in drv2667_probe()
394 dev_err(&client->dev, "couldn't register input device: %d\n", in drv2667_probe()
407 guard(mutex)(&haptics->input_dev->mutex); in drv2667_suspend()
409 if (input_device_enabled(haptics->input_dev)) { in drv2667_suspend()
410 error = regmap_update_bits(haptics->regmap, DRV2667_CTRL_2, in drv2667_suspend()
414 regulator_disable(haptics->regulator); in drv2667_suspend()
418 error = regulator_disable(haptics->regulator); in drv2667_suspend()
420 dev_err(dev, "Failed to disable regulator\n"); in drv2667_suspend()
421 regmap_update_bits(haptics->regmap, in drv2667_suspend()
436 guard(mutex)(&haptics->input_dev->mutex); in drv2667_resume()
438 if (input_device_enabled(haptics->input_dev)) { in drv2667_resume()
439 error = regulator_enable(haptics->regulator); in drv2667_resume()
441 dev_err(dev, "Failed to enable regulator\n"); in drv2667_resume()
445 error = regmap_update_bits(haptics->regmap, DRV2667_CTRL_2, in drv2667_resume()
449 regulator_disable(haptics->regulator); in drv2667_resume()
477 .name = "drv2667-haptics",