xref: /openbmc/linux/include/sound/soc-jack.h (revision 63705da3)
1 /* SPDX-License-Identifier: GPL-2.0
2  *
3  * soc-jack.h
4  *
5  * Copyright (C) 2019 Renesas Electronics Corp.
6  * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
7  */
8 #ifndef __SOC_JACK_H
9 #define __SOC_JACK_H
10 
11 /**
12  * struct snd_soc_jack_pin - Describes a pin to update based on jack detection
13  *
14  * @pin:    name of the pin to update
15  * @mask:   bits to check for in reported jack status
16  * @invert: if non-zero then pin is enabled when status is not reported
17  * @list:   internal list entry
18  */
19 struct snd_soc_jack_pin {
20 	struct list_head list;
21 	const char *pin;
22 	int mask;
23 	bool invert;
24 };
25 
26 /**
27  * struct snd_soc_jack_zone - Describes voltage zones of jack detection
28  *
29  * @min_mv: start voltage in mv
30  * @max_mv: end voltage in mv
31  * @jack_type: type of jack that is expected for this voltage
32  * @debounce_time: debounce_time for jack, codec driver should wait for this
33  *		duration before reading the adc for voltages
34  * @list:   internal list entry
35  */
36 struct snd_soc_jack_zone {
37 	unsigned int min_mv;
38 	unsigned int max_mv;
39 	unsigned int jack_type;
40 	unsigned int debounce_time;
41 	struct list_head list;
42 };
43 
44 /**
45  * struct snd_soc_jack_gpio - Describes a gpio pin for jack detection
46  *
47  * @gpio:         legacy gpio number
48  * @idx:          gpio descriptor index within the function of the GPIO
49  *                consumer device
50  * @gpiod_dev:    GPIO consumer device
51  * @name:         gpio name. Also as connection ID for the GPIO consumer
52  *                device function name lookup
53  * @report:       value to report when jack detected
54  * @invert:       report presence in low state
55  * @debounce_time: debounce time in ms
56  * @wake:	  enable as wake source
57  * @jack_status_check: callback function which overrides the detection
58  *		       to provide more complex checks (eg, reading an
59  *		       ADC).
60  */
61 struct snd_soc_jack_gpio {
62 	unsigned int gpio;
63 	unsigned int idx;
64 	struct device *gpiod_dev;
65 	const char *name;
66 	int report;
67 	int invert;
68 	int debounce_time;
69 	bool wake;
70 
71 	/* private: */
72 	struct snd_soc_jack *jack;
73 	struct delayed_work work;
74 	struct notifier_block pm_notifier;
75 	struct gpio_desc *desc;
76 
77 	void *data;
78 	/* public: */
79 	int (*jack_status_check)(void *data);
80 };
81 
82 struct snd_soc_jack {
83 	struct mutex mutex;
84 	struct snd_jack *jack;
85 	struct snd_soc_card *card;
86 	struct list_head pins;
87 	int status;
88 	struct blocking_notifier_head notifier;
89 	struct list_head jack_zones;
90 };
91 
92 /* Jack reporting */
93 void snd_soc_jack_report(struct snd_soc_jack *jack, int status, int mask);
94 int snd_soc_jack_add_pins(struct snd_soc_jack *jack, int count,
95 			  struct snd_soc_jack_pin *pins);
96 void snd_soc_jack_notifier_register(struct snd_soc_jack *jack,
97 				    struct notifier_block *nb);
98 void snd_soc_jack_notifier_unregister(struct snd_soc_jack *jack,
99 				      struct notifier_block *nb);
100 int snd_soc_jack_add_zones(struct snd_soc_jack *jack, int count,
101 			   struct snd_soc_jack_zone *zones);
102 int snd_soc_jack_get_type(struct snd_soc_jack *jack, int micbias_voltage);
103 #ifdef CONFIG_GPIOLIB
104 int snd_soc_jack_add_gpios(struct snd_soc_jack *jack, int count,
105 			   struct snd_soc_jack_gpio *gpios);
106 int snd_soc_jack_add_gpiods(struct device *gpiod_dev,
107 			    struct snd_soc_jack *jack,
108 			    int count, struct snd_soc_jack_gpio *gpios);
109 void snd_soc_jack_free_gpios(struct snd_soc_jack *jack, int count,
110 			     struct snd_soc_jack_gpio *gpios);
111 #else
112 static inline int snd_soc_jack_add_gpios(struct snd_soc_jack *jack, int count,
113 					 struct snd_soc_jack_gpio *gpios)
114 {
115 	return 0;
116 }
117 
118 static inline int snd_soc_jack_add_gpiods(struct device *gpiod_dev,
119 					  struct snd_soc_jack *jack,
120 					  int count,
121 					  struct snd_soc_jack_gpio *gpios)
122 {
123 	return 0;
124 }
125 
126 static inline void snd_soc_jack_free_gpios(struct snd_soc_jack *jack, int count,
127 					   struct snd_soc_jack_gpio *gpios)
128 {
129 }
130 #endif
131 
132 #endif /* __SOC_JACK_H */
133