Lines Matching +full:enable +full:- +full:gpios
1 // SPDX-License-Identifier: GPL-2.0+
3 // soc-jack.c -- ALSA SoC jack handling
23 struct snd_soc_jack_gpio *gpios; member
27 * snd_soc_jack_report - Report the current status for a jack
45 int enable; in snd_soc_jack_report() local
51 dapm = &jack->card->dapm; in snd_soc_jack_report()
53 mutex_lock(&jack->mutex); in snd_soc_jack_report()
55 jack->status &= ~mask; in snd_soc_jack_report()
56 jack->status |= status & mask; in snd_soc_jack_report()
60 list_for_each_entry(pin, &jack->pins, list) { in snd_soc_jack_report()
61 enable = pin->mask & jack->status; in snd_soc_jack_report()
63 if (pin->invert) in snd_soc_jack_report()
64 enable = !enable; in snd_soc_jack_report()
66 if (enable) in snd_soc_jack_report()
67 snd_soc_dapm_enable_pin(dapm, pin->pin); in snd_soc_jack_report()
69 snd_soc_dapm_disable_pin(dapm, pin->pin); in snd_soc_jack_report()
76 blocking_notifier_call_chain(&jack->notifier, jack->status, jack); in snd_soc_jack_report()
81 snd_jack_report(jack->jack, jack->status); in snd_soc_jack_report()
83 mutex_unlock(&jack->mutex); in snd_soc_jack_report()
88 * snd_soc_jack_add_zones - Associate voltage zones with jack
104 list_add(&(zones[i].list), &jack->jack_zones); in snd_soc_jack_add_zones()
111 * snd_soc_jack_get_type - Based on the mic bias value, this function returns
124 list_for_each_entry(zone, &jack->jack_zones, list) { in snd_soc_jack_get_type()
125 if (micbias_voltage >= zone->min_mv && in snd_soc_jack_get_type()
126 micbias_voltage < zone->max_mv) in snd_soc_jack_get_type()
127 return zone->jack_type; in snd_soc_jack_get_type()
134 * snd_soc_jack_add_pins - Associate DAPM pins with an ASoC jack
151 dev_err(jack->card->dev, "ASoC: No name for pin %d\n", in snd_soc_jack_add_pins()
153 return -EINVAL; in snd_soc_jack_add_pins()
156 dev_err(jack->card->dev, "ASoC: No mask for pin %d" in snd_soc_jack_add_pins()
158 return -EINVAL; in snd_soc_jack_add_pins()
162 list_add(&(pins[i].list), &jack->pins); in snd_soc_jack_add_pins()
163 snd_jack_add_new_kctl(jack->jack, pins[i].pin, pins[i].mask); in snd_soc_jack_add_pins()
177 * snd_soc_jack_notifier_register - Register a notifier for jack status
191 blocking_notifier_chain_register(&jack->notifier, nb); in snd_soc_jack_notifier_register()
196 * snd_soc_jack_notifier_unregister - Unregister a notifier for jack status
206 blocking_notifier_chain_unregister(&jack->notifier, nb); in snd_soc_jack_notifier_unregister()
214 struct snd_soc_jack *jack = gpio->jack; in snd_soc_jack_gpio_detect()
215 int enable; in snd_soc_jack_gpio_detect() local
218 enable = gpiod_get_value_cansleep(gpio->desc); in snd_soc_jack_gpio_detect()
219 if (gpio->invert) in snd_soc_jack_gpio_detect()
220 enable = !enable; in snd_soc_jack_gpio_detect()
222 if (enable) in snd_soc_jack_gpio_detect()
223 report = gpio->report; in snd_soc_jack_gpio_detect()
227 if (gpio->jack_status_check) in snd_soc_jack_gpio_detect()
228 report = gpio->jack_status_check(gpio->data); in snd_soc_jack_gpio_detect()
230 snd_soc_jack_report(jack, report, gpio->report); in snd_soc_jack_gpio_detect()
237 struct device *dev = gpio->jack->card->dev; in gpio_handler()
239 trace_snd_soc_jack_irq(gpio->name); in gpio_handler()
242 pm_wakeup_event(dev, gpio->debounce_time + 50); in gpio_handler()
244 queue_delayed_work(system_power_efficient_wq, &gpio->work, in gpio_handler()
245 msecs_to_jiffies(gpio->debounce_time)); in gpio_handler()
273 queue_delayed_work(system_power_efficient_wq, &gpio->work, 0); in snd_soc_jack_pm_notifier()
281 struct snd_soc_jack_gpio *gpios) in jack_free_gpios() argument
286 gpiod_unexport(gpios[i].desc); in jack_free_gpios()
287 unregister_pm_notifier(&gpios[i].pm_notifier); in jack_free_gpios()
288 free_irq(gpiod_to_irq(gpios[i].desc), &gpios[i]); in jack_free_gpios()
289 cancel_delayed_work_sync(&gpios[i].work); in jack_free_gpios()
290 gpiod_put(gpios[i].desc); in jack_free_gpios()
291 gpios[i].jack = NULL; in jack_free_gpios()
299 jack_free_gpios(tbl->jack, tbl->count, tbl->gpios); in jack_devres_free_gpios()
303 * snd_soc_jack_add_gpios - Associate GPIO pins with an ASoC jack
307 * @gpios: array of gpio pins
313 struct snd_soc_jack_gpio *gpios) in snd_soc_jack_add_gpios() argument
320 return -ENOMEM; in snd_soc_jack_add_gpios()
321 tbl->jack = jack; in snd_soc_jack_add_gpios()
322 tbl->count = count; in snd_soc_jack_add_gpios()
323 tbl->gpios = gpios; in snd_soc_jack_add_gpios()
326 if (!gpios[i].name) { in snd_soc_jack_add_gpios()
327 dev_err(jack->card->dev, in snd_soc_jack_add_gpios()
329 ret = -EINVAL; in snd_soc_jack_add_gpios()
333 if (gpios[i].desc) { in snd_soc_jack_add_gpios()
336 } else if (gpios[i].gpiod_dev) { in snd_soc_jack_add_gpios()
338 gpios[i].desc = gpiod_get_index(gpios[i].gpiod_dev, in snd_soc_jack_add_gpios()
339 gpios[i].name, in snd_soc_jack_add_gpios()
340 gpios[i].idx, GPIOD_IN); in snd_soc_jack_add_gpios()
341 if (IS_ERR(gpios[i].desc)) { in snd_soc_jack_add_gpios()
342 ret = PTR_ERR(gpios[i].desc); in snd_soc_jack_add_gpios()
343 dev_err(gpios[i].gpiod_dev, in snd_soc_jack_add_gpios()
350 if (!gpio_is_valid(gpios[i].gpio)) { in snd_soc_jack_add_gpios()
351 dev_err(jack->card->dev, in snd_soc_jack_add_gpios()
353 gpios[i].gpio); in snd_soc_jack_add_gpios()
354 ret = -EINVAL; in snd_soc_jack_add_gpios()
358 ret = gpio_request_one(gpios[i].gpio, GPIOF_IN, in snd_soc_jack_add_gpios()
359 gpios[i].name); in snd_soc_jack_add_gpios()
363 gpios[i].desc = gpio_to_desc(gpios[i].gpio); in snd_soc_jack_add_gpios()
366 INIT_DELAYED_WORK(&gpios[i].work, gpio_work); in snd_soc_jack_add_gpios()
367 gpios[i].jack = jack; in snd_soc_jack_add_gpios()
369 ret = request_any_context_irq(gpiod_to_irq(gpios[i].desc), in snd_soc_jack_add_gpios()
373 gpios[i].name, in snd_soc_jack_add_gpios()
374 &gpios[i]); in snd_soc_jack_add_gpios()
378 if (gpios[i].wake) { in snd_soc_jack_add_gpios()
379 ret = irq_set_irq_wake(gpiod_to_irq(gpios[i].desc), 1); in snd_soc_jack_add_gpios()
381 dev_err(jack->card->dev, in snd_soc_jack_add_gpios()
390 gpios[i].pm_notifier.notifier_call = snd_soc_jack_pm_notifier; in snd_soc_jack_add_gpios()
391 register_pm_notifier(&gpios[i].pm_notifier); in snd_soc_jack_add_gpios()
394 gpiod_export(gpios[i].desc, false); in snd_soc_jack_add_gpios()
397 schedule_delayed_work(&gpios[i].work, in snd_soc_jack_add_gpios()
398 msecs_to_jiffies(gpios[i].debounce_time)); in snd_soc_jack_add_gpios()
401 devres_add(jack->card->dev, tbl); in snd_soc_jack_add_gpios()
405 gpio_free(gpios[i].gpio); in snd_soc_jack_add_gpios()
407 jack_free_gpios(jack, i, gpios); in snd_soc_jack_add_gpios()
415 * snd_soc_jack_add_gpiods - Associate GPIO descriptor pins with an ASoC jack
420 * @gpios: array of gpio pins
427 int count, struct snd_soc_jack_gpio *gpios) in snd_soc_jack_add_gpiods() argument
432 gpios[i].gpiod_dev = gpiod_dev; in snd_soc_jack_add_gpiods()
434 return snd_soc_jack_add_gpios(jack, count, gpios); in snd_soc_jack_add_gpiods()
439 * snd_soc_jack_free_gpios - Release GPIO pins' resources of an ASoC jack
443 * @gpios: array of gpio pins
448 struct snd_soc_jack_gpio *gpios) in snd_soc_jack_free_gpios() argument
450 jack_free_gpios(jack, count, gpios); in snd_soc_jack_free_gpios()
451 devres_destroy(jack->card->dev, jack_devres_free_gpios, NULL, NULL); in snd_soc_jack_free_gpios()