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