Lines Matching +full:in +full:- +full:gpios

1 // SPDX-License-Identifier: GPL-2.0+
3 // soc-jack.c -- ALSA SoC jack handling
20 * snd_soc_jack_report - Report the current status for a jack
39 if (!jack || !jack->jack) in snd_soc_jack_report()
43 dapm = &jack->card->dapm; in snd_soc_jack_report()
45 mutex_lock(&jack->mutex); in snd_soc_jack_report()
47 jack->status &= ~mask; in snd_soc_jack_report()
48 jack->status |= status & mask; in snd_soc_jack_report()
52 list_for_each_entry(pin, &jack->pins, list) { in snd_soc_jack_report()
53 int enable = pin->mask & jack->status; in snd_soc_jack_report()
55 if (pin->invert) in snd_soc_jack_report()
59 snd_soc_dapm_enable_pin(dapm, pin->pin); in snd_soc_jack_report()
61 snd_soc_dapm_disable_pin(dapm, pin->pin); in snd_soc_jack_report()
68 blocking_notifier_call_chain(&jack->notifier, jack->status, jack); in snd_soc_jack_report()
73 snd_jack_report(jack->jack, jack->status); in snd_soc_jack_report()
75 mutex_unlock(&jack->mutex); in snd_soc_jack_report()
80 * snd_soc_jack_add_zones - Associate voltage zones with jack
86 * After this function has been called the zones specified in the
96 list_add(&(zones[i].list), &jack->jack_zones); in snd_soc_jack_add_zones()
103 * snd_soc_jack_get_type - Based on the mic bias value, this function returns
104 * the type of jack from the zones declared in the jack type
107 * @micbias_voltage: mic bias voltage at adc channel when jack is plugged in
116 list_for_each_entry(zone, &jack->jack_zones, list) { in snd_soc_jack_get_type()
117 if (micbias_voltage >= zone->min_mv && in snd_soc_jack_get_type()
118 micbias_voltage < zone->max_mv) in snd_soc_jack_get_type()
119 return zone->jack_type; in snd_soc_jack_get_type()
126 * snd_soc_jack_add_pins - Associate DAPM pins with an ASoC jack
132 * After this function has been called the DAPM pins specified in the
143 dev_err(jack->card->dev, "ASoC: No name for pin %d\n", in snd_soc_jack_add_pins()
145 return -EINVAL; in snd_soc_jack_add_pins()
148 dev_err(jack->card->dev, "ASoC: No mask for pin %d" in snd_soc_jack_add_pins()
150 return -EINVAL; in snd_soc_jack_add_pins()
154 list_add(&(pins[i].list), &jack->pins); in snd_soc_jack_add_pins()
155 snd_jack_add_new_kctl(jack->jack, pins[i].pin, pins[i].mask); in snd_soc_jack_add_pins()
169 * snd_soc_jack_notifier_register - Register a notifier for jack status
175 * that it is not possible to report additional jack events in the
183 blocking_notifier_chain_register(&jack->notifier, nb); in snd_soc_jack_notifier_register()
188 * snd_soc_jack_notifier_unregister - Unregister a notifier for jack status
198 blocking_notifier_chain_unregister(&jack->notifier, nb); in snd_soc_jack_notifier_unregister()
206 struct snd_soc_jack_gpio *gpios; member
212 struct snd_soc_jack *jack = gpio->jack; in snd_soc_jack_gpio_detect()
216 enable = gpiod_get_value_cansleep(gpio->desc); in snd_soc_jack_gpio_detect()
217 if (gpio->invert) in snd_soc_jack_gpio_detect()
221 report = gpio->report; in snd_soc_jack_gpio_detect()
225 if (gpio->jack_status_check) in snd_soc_jack_gpio_detect()
226 report = gpio->jack_status_check(gpio->data); in snd_soc_jack_gpio_detect()
228 snd_soc_jack_report(jack, report, gpio->report); in snd_soc_jack_gpio_detect()
235 struct device *dev = gpio->jack->card->dev; in gpio_handler()
237 trace_snd_soc_jack_irq(gpio->name); in gpio_handler()
240 pm_wakeup_event(dev, gpio->debounce_time + 50); in gpio_handler()
242 queue_delayed_work(system_power_efficient_wq, &gpio->work, in gpio_handler()
243 msecs_to_jiffies(gpio->debounce_time)); in gpio_handler()
271 queue_delayed_work(system_power_efficient_wq, &gpio->work, 0); in snd_soc_jack_pm_notifier()
279 struct snd_soc_jack_gpio *gpios) in jack_free_gpios() argument
284 gpiod_unexport(gpios[i].desc); in jack_free_gpios()
285 unregister_pm_notifier(&gpios[i].pm_notifier); in jack_free_gpios()
286 free_irq(gpiod_to_irq(gpios[i].desc), &gpios[i]); in jack_free_gpios()
287 cancel_delayed_work_sync(&gpios[i].work); in jack_free_gpios()
288 gpiod_put(gpios[i].desc); in jack_free_gpios()
289 gpios[i].jack = NULL; in jack_free_gpios()
297 jack_free_gpios(tbl->jack, tbl->count, tbl->gpios); in jack_devres_free_gpios()
301 * snd_soc_jack_add_gpios - Associate GPIO pins with an ASoC jack
305 * @gpios: array of gpio pins
308 * for each gpio in the array.
311 struct snd_soc_jack_gpio *gpios) in snd_soc_jack_add_gpios() argument
318 return -ENOMEM; in snd_soc_jack_add_gpios()
319 tbl->jack = jack; in snd_soc_jack_add_gpios()
320 tbl->count = count; in snd_soc_jack_add_gpios()
321 tbl->gpios = gpios; in snd_soc_jack_add_gpios()
324 if (!gpios[i].name) { in snd_soc_jack_add_gpios()
325 dev_err(jack->card->dev, in snd_soc_jack_add_gpios()
327 ret = -EINVAL; in snd_soc_jack_add_gpios()
331 if (gpios[i].desc) { in snd_soc_jack_add_gpios()
334 } else if (gpios[i].gpiod_dev) { in snd_soc_jack_add_gpios()
336 gpios[i].desc = gpiod_get_index(gpios[i].gpiod_dev, in snd_soc_jack_add_gpios()
337 gpios[i].name, in snd_soc_jack_add_gpios()
338 gpios[i].idx, GPIOD_IN); in snd_soc_jack_add_gpios()
339 if (IS_ERR(gpios[i].desc)) { in snd_soc_jack_add_gpios()
340 ret = PTR_ERR(gpios[i].desc); in snd_soc_jack_add_gpios()
341 dev_err(gpios[i].gpiod_dev, in snd_soc_jack_add_gpios()
347 dev_err(jack->card->dev, "ASoC: Invalid gpio at index %d\n", i); in snd_soc_jack_add_gpios()
348 ret = -EINVAL; in snd_soc_jack_add_gpios()
352 INIT_DELAYED_WORK(&gpios[i].work, gpio_work); in snd_soc_jack_add_gpios()
353 gpios[i].jack = jack; in snd_soc_jack_add_gpios()
355 ret = request_any_context_irq(gpiod_to_irq(gpios[i].desc), in snd_soc_jack_add_gpios()
360 gpios[i].name, in snd_soc_jack_add_gpios()
361 &gpios[i]); in snd_soc_jack_add_gpios()
365 if (gpios[i].wake) { in snd_soc_jack_add_gpios()
366 ret = irq_set_irq_wake(gpiod_to_irq(gpios[i].desc), 1); in snd_soc_jack_add_gpios()
368 dev_err(jack->card->dev, in snd_soc_jack_add_gpios()
377 gpios[i].pm_notifier.notifier_call = snd_soc_jack_pm_notifier; in snd_soc_jack_add_gpios()
378 register_pm_notifier(&gpios[i].pm_notifier); in snd_soc_jack_add_gpios()
381 gpiod_export(gpios[i].desc, false); in snd_soc_jack_add_gpios()
384 schedule_delayed_work(&gpios[i].work, in snd_soc_jack_add_gpios()
385 msecs_to_jiffies(gpios[i].debounce_time)); in snd_soc_jack_add_gpios()
388 devres_add(jack->card->dev, tbl); in snd_soc_jack_add_gpios()
392 jack_free_gpios(jack, i, gpios); in snd_soc_jack_add_gpios()
400 * snd_soc_jack_add_gpiods - Associate GPIO descriptor pins with an ASoC jack
405 * @gpios: array of gpio pins
408 * for each gpio in the array.
412 int count, struct snd_soc_jack_gpio *gpios) in snd_soc_jack_add_gpiods() argument
417 gpios[i].gpiod_dev = gpiod_dev; in snd_soc_jack_add_gpiods()
419 return snd_soc_jack_add_gpios(jack, count, gpios); in snd_soc_jack_add_gpiods()
424 * snd_soc_jack_free_gpios - Release GPIO pins' resources of an ASoC jack
428 * @gpios: array of gpio pins
433 struct snd_soc_jack_gpio *gpios) in snd_soc_jack_free_gpios() argument
435 jack_free_gpios(jack, count, gpios); in snd_soc_jack_free_gpios()
436 devres_destroy(jack->card->dev, jack_devres_free_gpios, NULL, NULL); in snd_soc_jack_free_gpios()