xref: /openbmc/linux/include/sound/jack.h (revision 5cc6f623)
11a59d1b8SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-or-later */
2e76d8ceaSMark Brown #ifndef __SOUND_JACK_H
3e76d8ceaSMark Brown #define __SOUND_JACK_H
4e76d8ceaSMark Brown 
5e76d8ceaSMark Brown /*
6e76d8ceaSMark Brown  *  Jack abstraction layer
7e76d8ceaSMark Brown  *
8e76d8ceaSMark Brown  *  Copyright 2008 Wolfson Microelectronics plc
9e76d8ceaSMark Brown  */
10e76d8ceaSMark Brown 
11e76d8ceaSMark Brown #include <sound/core.h>
12e76d8ceaSMark Brown 
13e76d8ceaSMark Brown struct input_dev;
14e76d8ceaSMark Brown 
15e76d8ceaSMark Brown /**
16e83280f9STakashi Iwai  * enum snd_jack_types - Jack types which can be reported
17e83280f9STakashi Iwai  * @SND_JACK_HEADPHONE: Headphone
18e83280f9STakashi Iwai  * @SND_JACK_MICROPHONE: Microphone
19e83280f9STakashi Iwai  * @SND_JACK_HEADSET: Headset
20e83280f9STakashi Iwai  * @SND_JACK_LINEOUT: Line out
21e83280f9STakashi Iwai  * @SND_JACK_MECHANICAL: Mechanical switch
22e83280f9STakashi Iwai  * @SND_JACK_VIDEOOUT: Video out
23e83280f9STakashi Iwai  * @SND_JACK_AVOUT: AV (Audio Video) out
24e83280f9STakashi Iwai  * @SND_JACK_LINEIN:  Line in
25e83280f9STakashi Iwai  * @SND_JACK_BTN_0: Button 0
26e83280f9STakashi Iwai  * @SND_JACK_BTN_1: Button 1
27e83280f9STakashi Iwai  * @SND_JACK_BTN_2: Button 2
28e83280f9STakashi Iwai  * @SND_JACK_BTN_3: Button 3
29e83280f9STakashi Iwai  * @SND_JACK_BTN_4: Button 4
30e83280f9STakashi Iwai  * @SND_JACK_BTN_5: Button 5
317b366d5fSTakashi Iwai  *
327b366d5fSTakashi Iwai  * These values are used as a bitmask.
33bd8a71a7SMark Brown  *
34bd8a71a7SMark Brown  * Note that this must be kept in sync with the lookup table in
35bd8a71a7SMark Brown  * sound/core/jack.c.
36e76d8ceaSMark Brown  */
37e76d8ceaSMark Brown enum snd_jack_types {
38e76d8ceaSMark Brown 	SND_JACK_HEADPHONE	= 0x0001,
39e76d8ceaSMark Brown 	SND_JACK_MICROPHONE	= 0x0002,
40e76d8ceaSMark Brown 	SND_JACK_HEADSET	= SND_JACK_HEADPHONE | SND_JACK_MICROPHONE,
41a53ccab3SMatthew Ranostay 	SND_JACK_LINEOUT	= 0x0004,
42cdc69364SMark Brown 	SND_JACK_MECHANICAL	= 0x0008, /* If detected separately */
43d506fc32SJani Nikula 	SND_JACK_VIDEOOUT	= 0x0010,
44d506fc32SJani Nikula 	SND_JACK_AVOUT		= SND_JACK_LINEOUT | SND_JACK_VIDEOOUT,
457c2f8e40SDavid Henningsson 	SND_JACK_LINEIN		= 0x0020,
46ebb812cbSMark Brown 
47ebb812cbSMark Brown 	/* Kept separate from switches to facilitate implementation */
48ebb812cbSMark Brown 	SND_JACK_BTN_0		= 0x4000,
49ebb812cbSMark Brown 	SND_JACK_BTN_1		= 0x2000,
50ebb812cbSMark Brown 	SND_JACK_BTN_2		= 0x1000,
51831853c8SMark Brown 	SND_JACK_BTN_3		= 0x0800,
52831853c8SMark Brown 	SND_JACK_BTN_4		= 0x0400,
53831853c8SMark Brown 	SND_JACK_BTN_5		= 0x0200,
54e76d8ceaSMark Brown };
55e76d8ceaSMark Brown 
5653803aeaSMark Brown /* Keep in sync with definitions above */
5753803aeaSMark Brown #define SND_JACK_SWITCH_TYPES 6
5853803aeaSMark Brown 
59e76d8ceaSMark Brown struct snd_jack {
609058cbe1SJie Yang 	struct list_head kctl_list;
619058cbe1SJie Yang 	struct snd_card *card;
62fe0d128cSTakashi Iwai 	const char *id;
63fe0d128cSTakashi Iwai #ifdef CONFIG_SND_JACK_INPUT_DEV
64fe0d128cSTakashi Iwai 	struct input_dev *input_dev;
655cc6f623SAmadeusz Sławiński 	struct mutex input_dev_lock;
66e76d8ceaSMark Brown 	int registered;
67e76d8ceaSMark Brown 	int type;
68e76d8ceaSMark Brown 	char name[100];
69831853c8SMark Brown 	unsigned int key[6];   /* Keep in sync with definitions above */
70fe0d128cSTakashi Iwai #endif /* CONFIG_SND_JACK_INPUT_DEV */
712d670ea2SHui Wang 	int hw_status_cache;
729d59065cSTakashi Iwai 	void *private_data;
739d59065cSTakashi Iwai 	void (*private_free)(struct snd_jack *);
74e76d8ceaSMark Brown };
75e76d8ceaSMark Brown 
76e76d8ceaSMark Brown #ifdef CONFIG_SND_JACK
77e76d8ceaSMark Brown 
78e76d8ceaSMark Brown int snd_jack_new(struct snd_card *card, const char *id, int type,
794e3f0dc6SJie Yang 		 struct snd_jack **jack, bool initial_kctl, bool phantom_jack);
809058cbe1SJie Yang int snd_jack_add_new_kctl(struct snd_jack *jack, const char * name, int mask);
81fe0d128cSTakashi Iwai #ifdef CONFIG_SND_JACK_INPUT_DEV
82e76d8ceaSMark Brown void snd_jack_set_parent(struct snd_jack *jack, struct device *parent);
83ebb812cbSMark Brown int snd_jack_set_key(struct snd_jack *jack, enum snd_jack_types type,
84ebb812cbSMark Brown 		     int keytype);
85fe0d128cSTakashi Iwai #endif
86e76d8ceaSMark Brown void snd_jack_report(struct snd_jack *jack, int status);
87e76d8ceaSMark Brown 
88e76d8ceaSMark Brown #else
snd_jack_new(struct snd_card * card,const char * id,int type,struct snd_jack ** jack,bool initial_kctl,bool phantom_jack)89e76d8ceaSMark Brown static inline int snd_jack_new(struct snd_card *card, const char *id, int type,
904e3f0dc6SJie Yang 			       struct snd_jack **jack, bool initial_kctl, bool phantom_jack)
91e76d8ceaSMark Brown {
92e76d8ceaSMark Brown 	return 0;
93e76d8ceaSMark Brown }
94e76d8ceaSMark Brown 
snd_jack_add_new_kctl(struct snd_jack * jack,const char * name,int mask)959058cbe1SJie Yang static inline int snd_jack_add_new_kctl(struct snd_jack *jack, const char * name, int mask)
969058cbe1SJie Yang {
979058cbe1SJie Yang 	return 0;
989058cbe1SJie Yang }
999058cbe1SJie Yang 
snd_jack_report(struct snd_jack * jack,int status)100fe0d128cSTakashi Iwai static inline void snd_jack_report(struct snd_jack *jack, int status)
101fe0d128cSTakashi Iwai {
102fe0d128cSTakashi Iwai }
103fe0d128cSTakashi Iwai 
104fe0d128cSTakashi Iwai #endif
105fe0d128cSTakashi Iwai 
106fe0d128cSTakashi Iwai #if !defined(CONFIG_SND_JACK) || !defined(CONFIG_SND_JACK_INPUT_DEV)
snd_jack_set_parent(struct snd_jack * jack,struct device * parent)107e76d8ceaSMark Brown static inline void snd_jack_set_parent(struct snd_jack *jack,
108e76d8ceaSMark Brown 				       struct device *parent)
109e76d8ceaSMark Brown {
110e76d8ceaSMark Brown }
111e76d8ceaSMark Brown 
snd_jack_set_key(struct snd_jack * jack,enum snd_jack_types type,int keytype)112bf35df66STakashi Iwai static inline int snd_jack_set_key(struct snd_jack *jack,
113bf35df66STakashi Iwai 				   enum snd_jack_types type,
114bf35df66STakashi Iwai 				   int keytype)
115bf35df66STakashi Iwai {
116bf35df66STakashi Iwai 	return 0;
117bf35df66STakashi Iwai }
118fe0d128cSTakashi Iwai #endif /* !CONFIG_SND_JACK || !CONFIG_SND_JACK_INPUT_DEV */
119e76d8ceaSMark Brown 
120e76d8ceaSMark Brown #endif
121