// SPDX-License-Identifier: GPL-2.0+ // // soc-jack.c -- ALSA SoC jack handling // // Copyright 2008 Wolfson Microelectronics PLC. // // Author: Mark Brown <[email protected]> #include <sound/jack.h> #include <sound/soc.h> #include <linux/gpio/consumer.h> #include <linux/interrupt.h> #include <linux/workqueue.h> #include <linux/delay.h> #include <linux/export.h> #include <linux/suspend.h> #include <trace/events/asoc.h> /** * snd_soc_jack_report - Report the current status for a jack * * @jack: the jack * @status: a bitmask of enum snd_jack_type values that are currently detected. * @mask: a bitmask of enum snd_jack_type values that being reported. * * If configured using snd_soc_jack_add_pins() then the associated * DAPM pins will be enabled or disabled as appropriate and DAPM * synchronised. * * Note: This function uses mutexes and should be called from a * context which can sleep (such as a workqueue). */ void snd_soc_jack_report(struct snd_soc_jack *jack, int status, int mask) { … } EXPORT_SYMBOL_GPL(…); /** * snd_soc_jack_add_zones - Associate voltage zones with jack * * @jack: ASoC jack * @count: Number of zones * @zones: Array of zones * * After this function has been called the zones specified in the * array will be associated with the jack. */ int snd_soc_jack_add_zones(struct snd_soc_jack *jack, int count, struct snd_soc_jack_zone *zones) { … } EXPORT_SYMBOL_GPL(…); /** * snd_soc_jack_get_type - Based on the mic bias value, this function returns * the type of jack from the zones declared in the jack type * * @jack: ASoC jack * @micbias_voltage: mic bias voltage at adc channel when jack is plugged in * * Based on the mic bias value passed, this function helps identify * the type of jack from the already declared jack zones */ int snd_soc_jack_get_type(struct snd_soc_jack *jack, int micbias_voltage) { … } EXPORT_SYMBOL_GPL(…); /** * snd_soc_jack_add_pins - Associate DAPM pins with an ASoC jack * * @jack: ASoC jack created with snd_soc_card_jack_new_pins() * @count: Number of pins * @pins: Array of pins * * After this function has been called the DAPM pins specified in the * pins array will have their status updated to reflect the current * state of the jack whenever the jack status is updated. */ int snd_soc_jack_add_pins(struct snd_soc_jack *jack, int count, struct snd_soc_jack_pin *pins) { … } EXPORT_SYMBOL_GPL(…); /** * snd_soc_jack_notifier_register - Register a notifier for jack status * * @jack: ASoC jack * @nb: Notifier block to register * * Register for notification of the current status of the jack. Note * that it is not possible to report additional jack events in the * callback from the notifier, this is intended to support * applications such as enabling electrical detection only when a * mechanical detection event has occurred. */ void snd_soc_jack_notifier_register(struct snd_soc_jack *jack, struct notifier_block *nb) { … } EXPORT_SYMBOL_GPL(…); /** * snd_soc_jack_notifier_unregister - Unregister a notifier for jack status * * @jack: ASoC jack * @nb: Notifier block to unregister * * Stop notifying for status changes. */ void snd_soc_jack_notifier_unregister(struct snd_soc_jack *jack, struct notifier_block *nb) { … } EXPORT_SYMBOL_GPL(…); #ifdef CONFIG_GPIOLIB struct jack_gpio_tbl { … }; /* gpio detect */ static void snd_soc_jack_gpio_detect(struct snd_soc_jack_gpio *gpio) { … } /* irq handler for gpio pin */ static irqreturn_t gpio_handler(int irq, void *data) { … } /* gpio work */ static void gpio_work(struct work_struct *work) { … } static int snd_soc_jack_pm_notifier(struct notifier_block *nb, unsigned long action, void *data) { … } static void jack_free_gpios(struct snd_soc_jack *jack, int count, struct snd_soc_jack_gpio *gpios) { … } static void jack_devres_free_gpios(struct device *dev, void *res) { … } /** * snd_soc_jack_add_gpios - Associate GPIO pins with an ASoC jack * * @jack: ASoC jack * @count: number of pins * @gpios: array of gpio pins * * This function will request gpio, set data direction and request irq * for each gpio in the array. */ int snd_soc_jack_add_gpios(struct snd_soc_jack *jack, int count, struct snd_soc_jack_gpio *gpios) { … } EXPORT_SYMBOL_GPL(…); /** * snd_soc_jack_add_gpiods - Associate GPIO descriptor pins with an ASoC jack * * @gpiod_dev: GPIO consumer device * @jack: ASoC jack * @count: number of pins * @gpios: array of gpio pins * * This function will request gpio, set data direction and request irq * for each gpio in the array. */ int snd_soc_jack_add_gpiods(struct device *gpiod_dev, struct snd_soc_jack *jack, int count, struct snd_soc_jack_gpio *gpios) { … } EXPORT_SYMBOL_GPL(…); /** * snd_soc_jack_free_gpios - Release GPIO pins' resources of an ASoC jack * * @jack: ASoC jack * @count: number of pins * @gpios: array of gpio pins * * Release gpio and irq resources for gpio pins associated with an ASoC jack. */ void snd_soc_jack_free_gpios(struct snd_soc_jack *jack, int count, struct snd_soc_jack_gpio *gpios) { … } EXPORT_SYMBOL_GPL(…); #endif /* CONFIG_GPIOLIB */