Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0
0002  *
0003  * soc-jack.h
0004  *
0005  * Copyright (C) 2019 Renesas Electronics Corp.
0006  * Kuninori Morimoto <kuninori.morimoto.gx@renesas.com>
0007  */
0008 #ifndef __SOC_JACK_H
0009 #define __SOC_JACK_H
0010 
0011 /**
0012  * struct snd_soc_jack_pin - Describes a pin to update based on jack detection
0013  *
0014  * @pin:    name of the pin to update
0015  * @mask:   bits to check for in reported jack status
0016  * @invert: if non-zero then pin is enabled when status is not reported
0017  * @list:   internal list entry
0018  */
0019 struct snd_soc_jack_pin {
0020     struct list_head list;
0021     const char *pin;
0022     int mask;
0023     bool invert;
0024 };
0025 
0026 /**
0027  * struct snd_soc_jack_zone - Describes voltage zones of jack detection
0028  *
0029  * @min_mv: start voltage in mv
0030  * @max_mv: end voltage in mv
0031  * @jack_type: type of jack that is expected for this voltage
0032  * @debounce_time: debounce_time for jack, codec driver should wait for this
0033  *      duration before reading the adc for voltages
0034  * @list:   internal list entry
0035  */
0036 struct snd_soc_jack_zone {
0037     unsigned int min_mv;
0038     unsigned int max_mv;
0039     unsigned int jack_type;
0040     unsigned int debounce_time;
0041     struct list_head list;
0042 };
0043 
0044 /**
0045  * struct snd_soc_jack_gpio - Describes a gpio pin for jack detection
0046  *
0047  * @gpio:         legacy gpio number
0048  * @idx:          gpio descriptor index within the function of the GPIO
0049  *                consumer device
0050  * @gpiod_dev:    GPIO consumer device
0051  * @name:         gpio name. Also as connection ID for the GPIO consumer
0052  *                device function name lookup
0053  * @report:       value to report when jack detected
0054  * @invert:       report presence in low state
0055  * @debounce_time: debounce time in ms
0056  * @wake:     enable as wake source
0057  * @jack_status_check: callback function which overrides the detection
0058  *             to provide more complex checks (eg, reading an
0059  *             ADC).
0060  */
0061 struct snd_soc_jack_gpio {
0062     unsigned int gpio;
0063     unsigned int idx;
0064     struct device *gpiod_dev;
0065     const char *name;
0066     int report;
0067     int invert;
0068     int debounce_time;
0069     bool wake;
0070 
0071     /* private: */
0072     struct snd_soc_jack *jack;
0073     struct delayed_work work;
0074     struct notifier_block pm_notifier;
0075     struct gpio_desc *desc;
0076 
0077     void *data;
0078     /* public: */
0079     int (*jack_status_check)(void *data);
0080 };
0081 
0082 struct snd_soc_jack {
0083     struct mutex mutex;
0084     struct snd_jack *jack;
0085     struct snd_soc_card *card;
0086     struct list_head pins;
0087     int status;
0088     struct blocking_notifier_head notifier;
0089     struct list_head jack_zones;
0090 };
0091 
0092 /* Jack reporting */
0093 void snd_soc_jack_report(struct snd_soc_jack *jack, int status, int mask);
0094 int snd_soc_jack_add_pins(struct snd_soc_jack *jack, int count,
0095               struct snd_soc_jack_pin *pins);
0096 void snd_soc_jack_notifier_register(struct snd_soc_jack *jack,
0097                     struct notifier_block *nb);
0098 void snd_soc_jack_notifier_unregister(struct snd_soc_jack *jack,
0099                       struct notifier_block *nb);
0100 int snd_soc_jack_add_zones(struct snd_soc_jack *jack, int count,
0101                struct snd_soc_jack_zone *zones);
0102 int snd_soc_jack_get_type(struct snd_soc_jack *jack, int micbias_voltage);
0103 #ifdef CONFIG_GPIOLIB
0104 int snd_soc_jack_add_gpios(struct snd_soc_jack *jack, int count,
0105                struct snd_soc_jack_gpio *gpios);
0106 int snd_soc_jack_add_gpiods(struct device *gpiod_dev,
0107                 struct snd_soc_jack *jack,
0108                 int count, struct snd_soc_jack_gpio *gpios);
0109 void snd_soc_jack_free_gpios(struct snd_soc_jack *jack, int count,
0110                  struct snd_soc_jack_gpio *gpios);
0111 #else
0112 static inline int snd_soc_jack_add_gpios(struct snd_soc_jack *jack, int count,
0113                      struct snd_soc_jack_gpio *gpios)
0114 {
0115     return 0;
0116 }
0117 
0118 static inline int snd_soc_jack_add_gpiods(struct device *gpiod_dev,
0119                       struct snd_soc_jack *jack,
0120                       int count,
0121                       struct snd_soc_jack_gpio *gpios)
0122 {
0123     return 0;
0124 }
0125 
0126 static inline void snd_soc_jack_free_gpios(struct snd_soc_jack *jack, int count,
0127                        struct snd_soc_jack_gpio *gpios)
0128 {
0129 }
0130 #endif
0131 
0132 #endif /* __SOC_JACK_H */