162306a36Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 262306a36Sopenharmony_ci * 362306a36Sopenharmony_ci * soc-jack.h 462306a36Sopenharmony_ci * 562306a36Sopenharmony_ci * Copyright (C) 2019 Renesas Electronics Corp. 662306a36Sopenharmony_ci * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com> 762306a36Sopenharmony_ci */ 862306a36Sopenharmony_ci#ifndef __SOC_JACK_H 962306a36Sopenharmony_ci#define __SOC_JACK_H 1062306a36Sopenharmony_ci 1162306a36Sopenharmony_ci/** 1262306a36Sopenharmony_ci * struct snd_soc_jack_pin - Describes a pin to update based on jack detection 1362306a36Sopenharmony_ci * 1462306a36Sopenharmony_ci * @pin: name of the pin to update 1562306a36Sopenharmony_ci * @mask: bits to check for in reported jack status 1662306a36Sopenharmony_ci * @invert: if non-zero then pin is enabled when status is not reported 1762306a36Sopenharmony_ci * @list: internal list entry 1862306a36Sopenharmony_ci */ 1962306a36Sopenharmony_cistruct snd_soc_jack_pin { 2062306a36Sopenharmony_ci struct list_head list; 2162306a36Sopenharmony_ci const char *pin; 2262306a36Sopenharmony_ci int mask; 2362306a36Sopenharmony_ci bool invert; 2462306a36Sopenharmony_ci}; 2562306a36Sopenharmony_ci 2662306a36Sopenharmony_ci/** 2762306a36Sopenharmony_ci * struct snd_soc_jack_zone - Describes voltage zones of jack detection 2862306a36Sopenharmony_ci * 2962306a36Sopenharmony_ci * @min_mv: start voltage in mv 3062306a36Sopenharmony_ci * @max_mv: end voltage in mv 3162306a36Sopenharmony_ci * @jack_type: type of jack that is expected for this voltage 3262306a36Sopenharmony_ci * @debounce_time: debounce_time for jack, codec driver should wait for this 3362306a36Sopenharmony_ci * duration before reading the adc for voltages 3462306a36Sopenharmony_ci * @list: internal list entry 3562306a36Sopenharmony_ci */ 3662306a36Sopenharmony_cistruct snd_soc_jack_zone { 3762306a36Sopenharmony_ci unsigned int min_mv; 3862306a36Sopenharmony_ci unsigned int max_mv; 3962306a36Sopenharmony_ci unsigned int jack_type; 4062306a36Sopenharmony_ci unsigned int debounce_time; 4162306a36Sopenharmony_ci struct list_head list; 4262306a36Sopenharmony_ci}; 4362306a36Sopenharmony_ci 4462306a36Sopenharmony_ci/** 4562306a36Sopenharmony_ci * struct snd_soc_jack_gpio - Describes a gpio pin for jack detection 4662306a36Sopenharmony_ci * 4762306a36Sopenharmony_ci * @gpio: legacy gpio number 4862306a36Sopenharmony_ci * @idx: gpio descriptor index within the function of the GPIO 4962306a36Sopenharmony_ci * consumer device 5062306a36Sopenharmony_ci * @gpiod_dev: GPIO consumer device 5162306a36Sopenharmony_ci * @name: gpio name. Also as connection ID for the GPIO consumer 5262306a36Sopenharmony_ci * device function name lookup 5362306a36Sopenharmony_ci * @report: value to report when jack detected 5462306a36Sopenharmony_ci * @invert: report presence in low state 5562306a36Sopenharmony_ci * @debounce_time: debounce time in ms 5662306a36Sopenharmony_ci * @wake: enable as wake source 5762306a36Sopenharmony_ci * @jack_status_check: callback function which overrides the detection 5862306a36Sopenharmony_ci * to provide more complex checks (eg, reading an 5962306a36Sopenharmony_ci * ADC). 6062306a36Sopenharmony_ci */ 6162306a36Sopenharmony_cistruct snd_soc_jack_gpio { 6262306a36Sopenharmony_ci unsigned int gpio; 6362306a36Sopenharmony_ci unsigned int idx; 6462306a36Sopenharmony_ci struct device *gpiod_dev; 6562306a36Sopenharmony_ci const char *name; 6662306a36Sopenharmony_ci int report; 6762306a36Sopenharmony_ci int invert; 6862306a36Sopenharmony_ci int debounce_time; 6962306a36Sopenharmony_ci bool wake; 7062306a36Sopenharmony_ci 7162306a36Sopenharmony_ci /* private: */ 7262306a36Sopenharmony_ci struct snd_soc_jack *jack; 7362306a36Sopenharmony_ci struct delayed_work work; 7462306a36Sopenharmony_ci struct notifier_block pm_notifier; 7562306a36Sopenharmony_ci struct gpio_desc *desc; 7662306a36Sopenharmony_ci 7762306a36Sopenharmony_ci void *data; 7862306a36Sopenharmony_ci /* public: */ 7962306a36Sopenharmony_ci int (*jack_status_check)(void *data); 8062306a36Sopenharmony_ci}; 8162306a36Sopenharmony_ci 8262306a36Sopenharmony_cistruct snd_soc_jack { 8362306a36Sopenharmony_ci struct mutex mutex; 8462306a36Sopenharmony_ci struct snd_jack *jack; 8562306a36Sopenharmony_ci struct snd_soc_card *card; 8662306a36Sopenharmony_ci struct list_head pins; 8762306a36Sopenharmony_ci int status; 8862306a36Sopenharmony_ci struct blocking_notifier_head notifier; 8962306a36Sopenharmony_ci struct list_head jack_zones; 9062306a36Sopenharmony_ci}; 9162306a36Sopenharmony_ci 9262306a36Sopenharmony_ci/* Jack reporting */ 9362306a36Sopenharmony_civoid snd_soc_jack_report(struct snd_soc_jack *jack, int status, int mask); 9462306a36Sopenharmony_ciint snd_soc_jack_add_pins(struct snd_soc_jack *jack, int count, 9562306a36Sopenharmony_ci struct snd_soc_jack_pin *pins); 9662306a36Sopenharmony_civoid snd_soc_jack_notifier_register(struct snd_soc_jack *jack, 9762306a36Sopenharmony_ci struct notifier_block *nb); 9862306a36Sopenharmony_civoid snd_soc_jack_notifier_unregister(struct snd_soc_jack *jack, 9962306a36Sopenharmony_ci struct notifier_block *nb); 10062306a36Sopenharmony_ciint snd_soc_jack_add_zones(struct snd_soc_jack *jack, int count, 10162306a36Sopenharmony_ci struct snd_soc_jack_zone *zones); 10262306a36Sopenharmony_ciint snd_soc_jack_get_type(struct snd_soc_jack *jack, int micbias_voltage); 10362306a36Sopenharmony_ci#ifdef CONFIG_GPIOLIB 10462306a36Sopenharmony_ciint snd_soc_jack_add_gpios(struct snd_soc_jack *jack, int count, 10562306a36Sopenharmony_ci struct snd_soc_jack_gpio *gpios); 10662306a36Sopenharmony_ciint snd_soc_jack_add_gpiods(struct device *gpiod_dev, 10762306a36Sopenharmony_ci struct snd_soc_jack *jack, 10862306a36Sopenharmony_ci int count, struct snd_soc_jack_gpio *gpios); 10962306a36Sopenharmony_civoid snd_soc_jack_free_gpios(struct snd_soc_jack *jack, int count, 11062306a36Sopenharmony_ci struct snd_soc_jack_gpio *gpios); 11162306a36Sopenharmony_ci#else 11262306a36Sopenharmony_cistatic inline int snd_soc_jack_add_gpios(struct snd_soc_jack *jack, int count, 11362306a36Sopenharmony_ci struct snd_soc_jack_gpio *gpios) 11462306a36Sopenharmony_ci{ 11562306a36Sopenharmony_ci return 0; 11662306a36Sopenharmony_ci} 11762306a36Sopenharmony_ci 11862306a36Sopenharmony_cistatic inline int snd_soc_jack_add_gpiods(struct device *gpiod_dev, 11962306a36Sopenharmony_ci struct snd_soc_jack *jack, 12062306a36Sopenharmony_ci int count, 12162306a36Sopenharmony_ci struct snd_soc_jack_gpio *gpios) 12262306a36Sopenharmony_ci{ 12362306a36Sopenharmony_ci return 0; 12462306a36Sopenharmony_ci} 12562306a36Sopenharmony_ci 12662306a36Sopenharmony_cistatic inline void snd_soc_jack_free_gpios(struct snd_soc_jack *jack, int count, 12762306a36Sopenharmony_ci struct snd_soc_jack_gpio *gpios) 12862306a36Sopenharmony_ci{ 12962306a36Sopenharmony_ci} 13062306a36Sopenharmony_ci#endif 13162306a36Sopenharmony_ci 13262306a36Sopenharmony_ci#endif /* __SOC_JACK_H */ 133