Lines Matching +full:enable +full:- +full:gpios

1 // SPDX-License-Identifier: GPL-2.0+
3 // soc-jack.c -- ALSA SoC jack handling
21 * snd_soc_jack_report - Report the current status for a jack
44 dapm = &jack->card->dapm; in snd_soc_jack_report()
46 mutex_lock(&jack->mutex); in snd_soc_jack_report()
48 jack->status &= ~mask; in snd_soc_jack_report()
49 jack->status |= status & mask; in snd_soc_jack_report()
53 list_for_each_entry(pin, &jack->pins, list) { in snd_soc_jack_report()
54 int enable = pin->mask & jack->status; in snd_soc_jack_report() local
56 if (pin->invert) in snd_soc_jack_report()
57 enable = !enable; in snd_soc_jack_report()
59 if (enable) in snd_soc_jack_report()
60 snd_soc_dapm_enable_pin(dapm, pin->pin); in snd_soc_jack_report()
62 snd_soc_dapm_disable_pin(dapm, pin->pin); in snd_soc_jack_report()
69 blocking_notifier_call_chain(&jack->notifier, jack->status, jack); in snd_soc_jack_report()
74 snd_jack_report(jack->jack, jack->status); in snd_soc_jack_report()
76 mutex_unlock(&jack->mutex); in snd_soc_jack_report()
81 * snd_soc_jack_add_zones - Associate voltage zones with jack
97 list_add(&(zones[i].list), &jack->jack_zones); in snd_soc_jack_add_zones()
104 * snd_soc_jack_get_type - Based on the mic bias value, this function returns
117 list_for_each_entry(zone, &jack->jack_zones, list) { in snd_soc_jack_get_type()
118 if (micbias_voltage >= zone->min_mv && in snd_soc_jack_get_type()
119 micbias_voltage < zone->max_mv) in snd_soc_jack_get_type()
120 return zone->jack_type; in snd_soc_jack_get_type()
127 * snd_soc_jack_add_pins - Associate DAPM pins with an ASoC jack
144 dev_err(jack->card->dev, "ASoC: No name for pin %d\n", in snd_soc_jack_add_pins()
146 return -EINVAL; in snd_soc_jack_add_pins()
149 dev_err(jack->card->dev, "ASoC: No mask for pin %d" in snd_soc_jack_add_pins()
151 return -EINVAL; in snd_soc_jack_add_pins()
155 list_add(&(pins[i].list), &jack->pins); in snd_soc_jack_add_pins()
156 snd_jack_add_new_kctl(jack->jack, pins[i].pin, pins[i].mask); in snd_soc_jack_add_pins()
170 * snd_soc_jack_notifier_register - Register a notifier for jack status
184 blocking_notifier_chain_register(&jack->notifier, nb); in snd_soc_jack_notifier_register()
189 * snd_soc_jack_notifier_unregister - Unregister a notifier for jack status
199 blocking_notifier_chain_unregister(&jack->notifier, nb); in snd_soc_jack_notifier_unregister()
207 struct snd_soc_jack_gpio *gpios; member
213 struct snd_soc_jack *jack = gpio->jack; in snd_soc_jack_gpio_detect()
214 int enable; in snd_soc_jack_gpio_detect() local
217 enable = gpiod_get_value_cansleep(gpio->desc); in snd_soc_jack_gpio_detect()
218 if (gpio->invert) in snd_soc_jack_gpio_detect()
219 enable = !enable; in snd_soc_jack_gpio_detect()
221 if (enable) in snd_soc_jack_gpio_detect()
222 report = gpio->report; in snd_soc_jack_gpio_detect()
226 if (gpio->jack_status_check) in snd_soc_jack_gpio_detect()
227 report = gpio->jack_status_check(gpio->data); in snd_soc_jack_gpio_detect()
229 snd_soc_jack_report(jack, report, gpio->report); in snd_soc_jack_gpio_detect()
236 struct device *dev = gpio->jack->card->dev; in gpio_handler()
238 trace_snd_soc_jack_irq(gpio->name); in gpio_handler()
241 pm_wakeup_event(dev, gpio->debounce_time + 50); in gpio_handler()
243 queue_delayed_work(system_power_efficient_wq, &gpio->work, in gpio_handler()
244 msecs_to_jiffies(gpio->debounce_time)); in gpio_handler()
272 queue_delayed_work(system_power_efficient_wq, &gpio->work, 0); in snd_soc_jack_pm_notifier()
280 struct snd_soc_jack_gpio *gpios) in jack_free_gpios() argument
285 gpiod_unexport(gpios[i].desc); in jack_free_gpios()
286 unregister_pm_notifier(&gpios[i].pm_notifier); in jack_free_gpios()
287 free_irq(gpiod_to_irq(gpios[i].desc), &gpios[i]); in jack_free_gpios()
288 cancel_delayed_work_sync(&gpios[i].work); in jack_free_gpios()
289 gpiod_put(gpios[i].desc); in jack_free_gpios()
290 gpios[i].jack = NULL; in jack_free_gpios()
298 jack_free_gpios(tbl->jack, tbl->count, tbl->gpios); in jack_devres_free_gpios()
302 * snd_soc_jack_add_gpios - Associate GPIO pins with an ASoC jack
306 * @gpios: array of gpio pins
312 struct snd_soc_jack_gpio *gpios) in snd_soc_jack_add_gpios() argument
319 return -ENOMEM; in snd_soc_jack_add_gpios()
320 tbl->jack = jack; in snd_soc_jack_add_gpios()
321 tbl->count = count; in snd_soc_jack_add_gpios()
322 tbl->gpios = gpios; in snd_soc_jack_add_gpios()
325 if (!gpios[i].name) { in snd_soc_jack_add_gpios()
326 dev_err(jack->card->dev, in snd_soc_jack_add_gpios()
328 ret = -EINVAL; in snd_soc_jack_add_gpios()
332 if (gpios[i].desc) { in snd_soc_jack_add_gpios()
335 } else if (gpios[i].gpiod_dev) { in snd_soc_jack_add_gpios()
337 gpios[i].desc = gpiod_get_index(gpios[i].gpiod_dev, in snd_soc_jack_add_gpios()
338 gpios[i].name, in snd_soc_jack_add_gpios()
339 gpios[i].idx, GPIOD_IN); in snd_soc_jack_add_gpios()
340 if (IS_ERR(gpios[i].desc)) { in snd_soc_jack_add_gpios()
341 ret = PTR_ERR(gpios[i].desc); in snd_soc_jack_add_gpios()
342 dev_err(gpios[i].gpiod_dev, in snd_soc_jack_add_gpios()
349 if (!gpio_is_valid(gpios[i].gpio)) { in snd_soc_jack_add_gpios()
350 dev_err(jack->card->dev, in snd_soc_jack_add_gpios()
352 gpios[i].gpio); in snd_soc_jack_add_gpios()
353 ret = -EINVAL; in snd_soc_jack_add_gpios()
357 ret = gpio_request_one(gpios[i].gpio, GPIOF_IN, in snd_soc_jack_add_gpios()
358 gpios[i].name); in snd_soc_jack_add_gpios()
362 gpios[i].desc = gpio_to_desc(gpios[i].gpio); in snd_soc_jack_add_gpios()
365 INIT_DELAYED_WORK(&gpios[i].work, gpio_work); in snd_soc_jack_add_gpios()
366 gpios[i].jack = jack; in snd_soc_jack_add_gpios()
368 ret = request_any_context_irq(gpiod_to_irq(gpios[i].desc), in snd_soc_jack_add_gpios()
372 gpios[i].name, in snd_soc_jack_add_gpios()
373 &gpios[i]); in snd_soc_jack_add_gpios()
377 if (gpios[i].wake) { in snd_soc_jack_add_gpios()
378 ret = irq_set_irq_wake(gpiod_to_irq(gpios[i].desc), 1); in snd_soc_jack_add_gpios()
380 dev_err(jack->card->dev, in snd_soc_jack_add_gpios()
389 gpios[i].pm_notifier.notifier_call = snd_soc_jack_pm_notifier; in snd_soc_jack_add_gpios()
390 register_pm_notifier(&gpios[i].pm_notifier); in snd_soc_jack_add_gpios()
393 gpiod_export(gpios[i].desc, false); in snd_soc_jack_add_gpios()
396 schedule_delayed_work(&gpios[i].work, in snd_soc_jack_add_gpios()
397 msecs_to_jiffies(gpios[i].debounce_time)); in snd_soc_jack_add_gpios()
400 devres_add(jack->card->dev, tbl); in snd_soc_jack_add_gpios()
404 gpio_free(gpios[i].gpio); in snd_soc_jack_add_gpios()
406 jack_free_gpios(jack, i, gpios); in snd_soc_jack_add_gpios()
414 * snd_soc_jack_add_gpiods - Associate GPIO descriptor pins with an ASoC jack
419 * @gpios: array of gpio pins
426 int count, struct snd_soc_jack_gpio *gpios) in snd_soc_jack_add_gpiods() argument
431 gpios[i].gpiod_dev = gpiod_dev; in snd_soc_jack_add_gpiods()
433 return snd_soc_jack_add_gpios(jack, count, gpios); in snd_soc_jack_add_gpiods()
438 * snd_soc_jack_free_gpios - Release GPIO pins' resources of an ASoC jack
442 * @gpios: array of gpio pins
447 struct snd_soc_jack_gpio *gpios) in snd_soc_jack_free_gpios() argument
449 jack_free_gpios(jack, count, gpios); in snd_soc_jack_free_gpios()
450 devres_destroy(jack->card->dev, jack_devres_free_gpios, NULL, NULL); in snd_soc_jack_free_gpios()