xref: /OK3568_Linux_fs/kernel/include/sound/hda_codec.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-or-later */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * Universal Interface for Intel High Definition Audio Codec
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  * Copyright (c) 2004 Takashi Iwai <tiwai@suse.de>
6*4882a593Smuzhiyun  */
7*4882a593Smuzhiyun 
8*4882a593Smuzhiyun #ifndef __SOUND_HDA_CODEC_H
9*4882a593Smuzhiyun #define __SOUND_HDA_CODEC_H
10*4882a593Smuzhiyun 
11*4882a593Smuzhiyun #include <linux/kref.h>
12*4882a593Smuzhiyun #include <linux/mod_devicetable.h>
13*4882a593Smuzhiyun #include <sound/info.h>
14*4882a593Smuzhiyun #include <sound/control.h>
15*4882a593Smuzhiyun #include <sound/pcm.h>
16*4882a593Smuzhiyun #include <sound/hwdep.h>
17*4882a593Smuzhiyun #include <sound/hdaudio.h>
18*4882a593Smuzhiyun #include <sound/hda_verbs.h>
19*4882a593Smuzhiyun #include <sound/hda_regmap.h>
20*4882a593Smuzhiyun 
21*4882a593Smuzhiyun #define IS_BXT(pci) ((pci)->vendor == 0x8086 && (pci)->device == 0x5a98)
22*4882a593Smuzhiyun #define IS_CFL(pci) ((pci)->vendor == 0x8086 && (pci)->device == 0xa348)
23*4882a593Smuzhiyun 
24*4882a593Smuzhiyun /*
25*4882a593Smuzhiyun  * Structures
26*4882a593Smuzhiyun  */
27*4882a593Smuzhiyun 
28*4882a593Smuzhiyun struct hda_bus;
29*4882a593Smuzhiyun struct hda_beep;
30*4882a593Smuzhiyun struct hda_codec;
31*4882a593Smuzhiyun struct hda_pcm;
32*4882a593Smuzhiyun struct hda_pcm_stream;
33*4882a593Smuzhiyun 
34*4882a593Smuzhiyun /*
35*4882a593Smuzhiyun  * codec bus
36*4882a593Smuzhiyun  *
37*4882a593Smuzhiyun  * each controller needs to creata a hda_bus to assign the accessor.
38*4882a593Smuzhiyun  * A hda_bus contains several codecs in the list codec_list.
39*4882a593Smuzhiyun  */
40*4882a593Smuzhiyun struct hda_bus {
41*4882a593Smuzhiyun 	struct hdac_bus core;
42*4882a593Smuzhiyun 
43*4882a593Smuzhiyun 	struct snd_card *card;
44*4882a593Smuzhiyun 
45*4882a593Smuzhiyun 	struct pci_dev *pci;
46*4882a593Smuzhiyun 	const char *modelname;
47*4882a593Smuzhiyun 
48*4882a593Smuzhiyun 	struct mutex prepare_mutex;
49*4882a593Smuzhiyun 
50*4882a593Smuzhiyun 	/* assigned PCMs */
51*4882a593Smuzhiyun 	DECLARE_BITMAP(pcm_dev_bits, SNDRV_PCM_DEVICES);
52*4882a593Smuzhiyun 
53*4882a593Smuzhiyun 	/* misc op flags */
54*4882a593Smuzhiyun 	unsigned int allow_bus_reset:1;	/* allow bus reset at fatal error */
55*4882a593Smuzhiyun 	/* status for codec/controller */
56*4882a593Smuzhiyun 	unsigned int shutdown :1;	/* being unloaded */
57*4882a593Smuzhiyun 	unsigned int response_reset:1;	/* controller was reset */
58*4882a593Smuzhiyun 	unsigned int in_reset:1;	/* during reset operation */
59*4882a593Smuzhiyun 	unsigned int no_response_fallback:1; /* don't fallback at RIRB error */
60*4882a593Smuzhiyun 	unsigned int bus_probing :1;	/* during probing process */
61*4882a593Smuzhiyun 	unsigned int keep_power:1;	/* keep power up for notification */
62*4882a593Smuzhiyun 
63*4882a593Smuzhiyun 	int primary_dig_out_type;	/* primary digital out PCM type */
64*4882a593Smuzhiyun 	unsigned int mixer_assigned;	/* codec addr for mixer name */
65*4882a593Smuzhiyun };
66*4882a593Smuzhiyun 
67*4882a593Smuzhiyun /* from hdac_bus to hda_bus */
68*4882a593Smuzhiyun #define to_hda_bus(bus)		container_of(bus, struct hda_bus, core)
69*4882a593Smuzhiyun 
70*4882a593Smuzhiyun /*
71*4882a593Smuzhiyun  * codec preset
72*4882a593Smuzhiyun  *
73*4882a593Smuzhiyun  * Known codecs have the patch to build and set up the controls/PCMs
74*4882a593Smuzhiyun  * better than the generic parser.
75*4882a593Smuzhiyun  */
76*4882a593Smuzhiyun typedef int (*hda_codec_patch_t)(struct hda_codec *);
77*4882a593Smuzhiyun 
78*4882a593Smuzhiyun #define HDA_CODEC_ID_SKIP_PROBE		0x00000001
79*4882a593Smuzhiyun #define HDA_CODEC_ID_GENERIC_HDMI	0x00000101
80*4882a593Smuzhiyun #define HDA_CODEC_ID_GENERIC		0x00000201
81*4882a593Smuzhiyun 
82*4882a593Smuzhiyun #define HDA_CODEC_REV_ENTRY(_vid, _rev, _name, _patch) \
83*4882a593Smuzhiyun 	{ .vendor_id = (_vid), .rev_id = (_rev), .name = (_name), \
84*4882a593Smuzhiyun 	  .api_version = HDA_DEV_LEGACY, \
85*4882a593Smuzhiyun 	  .driver_data = (unsigned long)(_patch) }
86*4882a593Smuzhiyun #define HDA_CODEC_ENTRY(_vid, _name, _patch) \
87*4882a593Smuzhiyun 	HDA_CODEC_REV_ENTRY(_vid, 0, _name, _patch)
88*4882a593Smuzhiyun 
89*4882a593Smuzhiyun struct hda_codec_driver {
90*4882a593Smuzhiyun 	struct hdac_driver core;
91*4882a593Smuzhiyun 	const struct hda_device_id *id;
92*4882a593Smuzhiyun };
93*4882a593Smuzhiyun 
94*4882a593Smuzhiyun int __hda_codec_driver_register(struct hda_codec_driver *drv, const char *name,
95*4882a593Smuzhiyun 			       struct module *owner);
96*4882a593Smuzhiyun #define hda_codec_driver_register(drv) \
97*4882a593Smuzhiyun 	__hda_codec_driver_register(drv, KBUILD_MODNAME, THIS_MODULE)
98*4882a593Smuzhiyun void hda_codec_driver_unregister(struct hda_codec_driver *drv);
99*4882a593Smuzhiyun #define module_hda_codec_driver(drv) \
100*4882a593Smuzhiyun 	module_driver(drv, hda_codec_driver_register, \
101*4882a593Smuzhiyun 		      hda_codec_driver_unregister)
102*4882a593Smuzhiyun 
103*4882a593Smuzhiyun /* ops set by the preset patch */
104*4882a593Smuzhiyun struct hda_codec_ops {
105*4882a593Smuzhiyun 	int (*build_controls)(struct hda_codec *codec);
106*4882a593Smuzhiyun 	int (*build_pcms)(struct hda_codec *codec);
107*4882a593Smuzhiyun 	int (*init)(struct hda_codec *codec);
108*4882a593Smuzhiyun 	void (*free)(struct hda_codec *codec);
109*4882a593Smuzhiyun 	void (*unsol_event)(struct hda_codec *codec, unsigned int res);
110*4882a593Smuzhiyun 	void (*set_power_state)(struct hda_codec *codec, hda_nid_t fg,
111*4882a593Smuzhiyun 				unsigned int power_state);
112*4882a593Smuzhiyun #ifdef CONFIG_PM
113*4882a593Smuzhiyun 	int (*suspend)(struct hda_codec *codec);
114*4882a593Smuzhiyun 	int (*resume)(struct hda_codec *codec);
115*4882a593Smuzhiyun 	int (*check_power_status)(struct hda_codec *codec, hda_nid_t nid);
116*4882a593Smuzhiyun #endif
117*4882a593Smuzhiyun 	void (*reboot_notify)(struct hda_codec *codec);
118*4882a593Smuzhiyun 	void (*stream_pm)(struct hda_codec *codec, hda_nid_t nid, bool on);
119*4882a593Smuzhiyun };
120*4882a593Smuzhiyun 
121*4882a593Smuzhiyun /* PCM callbacks */
122*4882a593Smuzhiyun struct hda_pcm_ops {
123*4882a593Smuzhiyun 	int (*open)(struct hda_pcm_stream *info, struct hda_codec *codec,
124*4882a593Smuzhiyun 		    struct snd_pcm_substream *substream);
125*4882a593Smuzhiyun 	int (*close)(struct hda_pcm_stream *info, struct hda_codec *codec,
126*4882a593Smuzhiyun 		     struct snd_pcm_substream *substream);
127*4882a593Smuzhiyun 	int (*prepare)(struct hda_pcm_stream *info, struct hda_codec *codec,
128*4882a593Smuzhiyun 		       unsigned int stream_tag, unsigned int format,
129*4882a593Smuzhiyun 		       struct snd_pcm_substream *substream);
130*4882a593Smuzhiyun 	int (*cleanup)(struct hda_pcm_stream *info, struct hda_codec *codec,
131*4882a593Smuzhiyun 		       struct snd_pcm_substream *substream);
132*4882a593Smuzhiyun 	unsigned int (*get_delay)(struct hda_pcm_stream *info,
133*4882a593Smuzhiyun 				  struct hda_codec *codec,
134*4882a593Smuzhiyun 				  struct snd_pcm_substream *substream);
135*4882a593Smuzhiyun };
136*4882a593Smuzhiyun 
137*4882a593Smuzhiyun /* PCM information for each substream */
138*4882a593Smuzhiyun struct hda_pcm_stream {
139*4882a593Smuzhiyun 	unsigned int substreams;	/* number of substreams, 0 = not exist*/
140*4882a593Smuzhiyun 	unsigned int channels_min;	/* min. number of channels */
141*4882a593Smuzhiyun 	unsigned int channels_max;	/* max. number of channels */
142*4882a593Smuzhiyun 	hda_nid_t nid;	/* default NID to query rates/formats/bps, or set up */
143*4882a593Smuzhiyun 	u32 rates;	/* supported rates */
144*4882a593Smuzhiyun 	u64 formats;	/* supported formats (SNDRV_PCM_FMTBIT_) */
145*4882a593Smuzhiyun 	unsigned int maxbps;	/* supported max. bit per sample */
146*4882a593Smuzhiyun 	const struct snd_pcm_chmap_elem *chmap; /* chmap to override */
147*4882a593Smuzhiyun 	struct hda_pcm_ops ops;
148*4882a593Smuzhiyun };
149*4882a593Smuzhiyun 
150*4882a593Smuzhiyun /* PCM types */
151*4882a593Smuzhiyun enum {
152*4882a593Smuzhiyun 	HDA_PCM_TYPE_AUDIO,
153*4882a593Smuzhiyun 	HDA_PCM_TYPE_SPDIF,
154*4882a593Smuzhiyun 	HDA_PCM_TYPE_HDMI,
155*4882a593Smuzhiyun 	HDA_PCM_TYPE_MODEM,
156*4882a593Smuzhiyun 	HDA_PCM_NTYPES
157*4882a593Smuzhiyun };
158*4882a593Smuzhiyun 
159*4882a593Smuzhiyun #define SNDRV_PCM_INVALID_DEVICE	(-1)
160*4882a593Smuzhiyun /* for PCM creation */
161*4882a593Smuzhiyun struct hda_pcm {
162*4882a593Smuzhiyun 	char *name;
163*4882a593Smuzhiyun 	struct hda_pcm_stream stream[2];
164*4882a593Smuzhiyun 	unsigned int pcm_type;	/* HDA_PCM_TYPE_XXX */
165*4882a593Smuzhiyun 	int device;		/* device number to assign */
166*4882a593Smuzhiyun 	struct snd_pcm *pcm;	/* assigned PCM instance */
167*4882a593Smuzhiyun 	bool own_chmap;		/* codec driver provides own channel maps */
168*4882a593Smuzhiyun 	/* private: */
169*4882a593Smuzhiyun 	struct hda_codec *codec;
170*4882a593Smuzhiyun 	struct kref kref;
171*4882a593Smuzhiyun 	struct list_head list;
172*4882a593Smuzhiyun };
173*4882a593Smuzhiyun 
174*4882a593Smuzhiyun /* codec information */
175*4882a593Smuzhiyun struct hda_codec {
176*4882a593Smuzhiyun 	struct hdac_device core;
177*4882a593Smuzhiyun 	struct hda_bus *bus;
178*4882a593Smuzhiyun 	struct snd_card *card;
179*4882a593Smuzhiyun 	unsigned int addr;	/* codec addr*/
180*4882a593Smuzhiyun 	u32 probe_id; /* overridden id for probing */
181*4882a593Smuzhiyun 
182*4882a593Smuzhiyun 	/* detected preset */
183*4882a593Smuzhiyun 	const struct hda_device_id *preset;
184*4882a593Smuzhiyun 	const char *modelname;	/* model name for preset */
185*4882a593Smuzhiyun 
186*4882a593Smuzhiyun 	/* set by patch */
187*4882a593Smuzhiyun 	struct hda_codec_ops patch_ops;
188*4882a593Smuzhiyun 
189*4882a593Smuzhiyun 	/* PCM to create, set by patch_ops.build_pcms callback */
190*4882a593Smuzhiyun 	struct list_head pcm_list_head;
191*4882a593Smuzhiyun 
192*4882a593Smuzhiyun 	/* codec specific info */
193*4882a593Smuzhiyun 	void *spec;
194*4882a593Smuzhiyun 
195*4882a593Smuzhiyun 	/* beep device */
196*4882a593Smuzhiyun 	struct hda_beep *beep;
197*4882a593Smuzhiyun 	unsigned int beep_mode;
198*4882a593Smuzhiyun 
199*4882a593Smuzhiyun 	/* widget capabilities cache */
200*4882a593Smuzhiyun 	u32 *wcaps;
201*4882a593Smuzhiyun 
202*4882a593Smuzhiyun 	struct snd_array mixers;	/* list of assigned mixer elements */
203*4882a593Smuzhiyun 	struct snd_array nids;		/* list of mapped mixer elements */
204*4882a593Smuzhiyun 
205*4882a593Smuzhiyun 	struct list_head conn_list;	/* linked-list of connection-list */
206*4882a593Smuzhiyun 
207*4882a593Smuzhiyun 	struct mutex spdif_mutex;
208*4882a593Smuzhiyun 	struct mutex control_mutex;
209*4882a593Smuzhiyun 	struct snd_array spdif_out;
210*4882a593Smuzhiyun 	unsigned int spdif_in_enable;	/* SPDIF input enable? */
211*4882a593Smuzhiyun 	const hda_nid_t *follower_dig_outs; /* optional digital out follower widgets */
212*4882a593Smuzhiyun 	struct snd_array init_pins;	/* initial (BIOS) pin configurations */
213*4882a593Smuzhiyun 	struct snd_array driver_pins;	/* pin configs set by codec parser */
214*4882a593Smuzhiyun 	struct snd_array cvt_setups;	/* audio convert setups */
215*4882a593Smuzhiyun 
216*4882a593Smuzhiyun 	struct mutex user_mutex;
217*4882a593Smuzhiyun #ifdef CONFIG_SND_HDA_RECONFIG
218*4882a593Smuzhiyun 	struct snd_array init_verbs;	/* additional init verbs */
219*4882a593Smuzhiyun 	struct snd_array hints;		/* additional hints */
220*4882a593Smuzhiyun 	struct snd_array user_pins;	/* default pin configs to override */
221*4882a593Smuzhiyun #endif
222*4882a593Smuzhiyun 
223*4882a593Smuzhiyun #ifdef CONFIG_SND_HDA_HWDEP
224*4882a593Smuzhiyun 	struct snd_hwdep *hwdep;	/* assigned hwdep device */
225*4882a593Smuzhiyun #endif
226*4882a593Smuzhiyun 
227*4882a593Smuzhiyun 	/* misc flags */
228*4882a593Smuzhiyun 	unsigned int configured:1; /* codec was configured */
229*4882a593Smuzhiyun 	unsigned int in_freeing:1; /* being released */
230*4882a593Smuzhiyun 	unsigned int registered:1; /* codec was registered */
231*4882a593Smuzhiyun 	unsigned int display_power_control:1; /* needs display power */
232*4882a593Smuzhiyun 	unsigned int spdif_status_reset :1; /* needs to toggle SPDIF for each
233*4882a593Smuzhiyun 					     * status change
234*4882a593Smuzhiyun 					     * (e.g. Realtek codecs)
235*4882a593Smuzhiyun 					     */
236*4882a593Smuzhiyun 	unsigned int pin_amp_workaround:1; /* pin out-amp takes index
237*4882a593Smuzhiyun 					    * (e.g. Conexant codecs)
238*4882a593Smuzhiyun 					    */
239*4882a593Smuzhiyun 	unsigned int single_adc_amp:1; /* adc in-amp takes no index
240*4882a593Smuzhiyun 					* (e.g. CX20549 codec)
241*4882a593Smuzhiyun 					*/
242*4882a593Smuzhiyun 	unsigned int no_sticky_stream:1; /* no sticky-PCM stream assignment */
243*4882a593Smuzhiyun 	unsigned int pins_shutup:1;	/* pins are shut up */
244*4882a593Smuzhiyun 	unsigned int no_trigger_sense:1; /* don't trigger at pin-sensing */
245*4882a593Smuzhiyun 	unsigned int no_jack_detect:1;	/* Machine has no jack-detection */
246*4882a593Smuzhiyun 	unsigned int inv_eapd:1; /* broken h/w: inverted EAPD control */
247*4882a593Smuzhiyun 	unsigned int inv_jack_detect:1;	/* broken h/w: inverted detection bit */
248*4882a593Smuzhiyun 	unsigned int pcm_format_first:1; /* PCM format must be set first */
249*4882a593Smuzhiyun 	unsigned int cached_write:1;	/* write only to caches */
250*4882a593Smuzhiyun 	unsigned int dp_mst:1; /* support DP1.2 Multi-stream transport */
251*4882a593Smuzhiyun 	unsigned int dump_coef:1; /* dump processing coefs in codec proc file */
252*4882a593Smuzhiyun 	unsigned int power_save_node:1; /* advanced PM for each widget */
253*4882a593Smuzhiyun 	unsigned int auto_runtime_pm:1; /* enable automatic codec runtime pm */
254*4882a593Smuzhiyun 	unsigned int force_pin_prefix:1; /* Add location prefix */
255*4882a593Smuzhiyun 	unsigned int link_down_at_suspend:1; /* link down at runtime suspend */
256*4882a593Smuzhiyun 	unsigned int relaxed_resume:1;	/* don't resume forcibly for jack */
257*4882a593Smuzhiyun 	unsigned int forced_resume:1; /* forced resume for jack */
258*4882a593Smuzhiyun 	unsigned int mst_no_extra_pcms:1; /* no backup PCMs for DP-MST */
259*4882a593Smuzhiyun 
260*4882a593Smuzhiyun #ifdef CONFIG_PM
261*4882a593Smuzhiyun 	unsigned long power_on_acct;
262*4882a593Smuzhiyun 	unsigned long power_off_acct;
263*4882a593Smuzhiyun 	unsigned long power_jiffies;
264*4882a593Smuzhiyun #endif
265*4882a593Smuzhiyun 
266*4882a593Smuzhiyun 	/* filter the requested power state per nid */
267*4882a593Smuzhiyun 	unsigned int (*power_filter)(struct hda_codec *codec, hda_nid_t nid,
268*4882a593Smuzhiyun 				     unsigned int power_state);
269*4882a593Smuzhiyun 
270*4882a593Smuzhiyun 	/* codec-specific additional proc output */
271*4882a593Smuzhiyun 	void (*proc_widget_hook)(struct snd_info_buffer *buffer,
272*4882a593Smuzhiyun 				 struct hda_codec *codec, hda_nid_t nid);
273*4882a593Smuzhiyun 
274*4882a593Smuzhiyun 	/* jack detection */
275*4882a593Smuzhiyun 	struct snd_array jacktbl;
276*4882a593Smuzhiyun 	unsigned long jackpoll_interval; /* In jiffies. Zero means no poll, rely on unsol events */
277*4882a593Smuzhiyun 	struct delayed_work jackpoll_work;
278*4882a593Smuzhiyun 
279*4882a593Smuzhiyun 	int depop_delay; /* depop delay in ms, -1 for default delay time */
280*4882a593Smuzhiyun 
281*4882a593Smuzhiyun 	/* fix-up list */
282*4882a593Smuzhiyun 	int fixup_id;
283*4882a593Smuzhiyun 	const struct hda_fixup *fixup_list;
284*4882a593Smuzhiyun 	const char *fixup_name;
285*4882a593Smuzhiyun 
286*4882a593Smuzhiyun 	/* additional init verbs */
287*4882a593Smuzhiyun 	struct snd_array verbs;
288*4882a593Smuzhiyun };
289*4882a593Smuzhiyun 
290*4882a593Smuzhiyun #define dev_to_hda_codec(_dev)	container_of(_dev, struct hda_codec, core.dev)
291*4882a593Smuzhiyun #define hda_codec_dev(_dev)	(&(_dev)->core.dev)
292*4882a593Smuzhiyun 
293*4882a593Smuzhiyun #define hdac_to_hda_priv(_hdac) \
294*4882a593Smuzhiyun 			container_of(_hdac, struct hdac_hda_priv, codec.core)
295*4882a593Smuzhiyun #define hdac_to_hda_codec(_hdac) container_of(_hdac, struct hda_codec, core)
296*4882a593Smuzhiyun 
297*4882a593Smuzhiyun #define list_for_each_codec(c, bus) \
298*4882a593Smuzhiyun 	list_for_each_entry(c, &(bus)->core.codec_list, core.list)
299*4882a593Smuzhiyun #define list_for_each_codec_safe(c, n, bus)				\
300*4882a593Smuzhiyun 	list_for_each_entry_safe(c, n, &(bus)->core.codec_list, core.list)
301*4882a593Smuzhiyun 
302*4882a593Smuzhiyun /* snd_hda_codec_read/write optional flags */
303*4882a593Smuzhiyun #define HDA_RW_NO_RESPONSE_FALLBACK	(1 << 0)
304*4882a593Smuzhiyun 
305*4882a593Smuzhiyun /*
306*4882a593Smuzhiyun  * constructors
307*4882a593Smuzhiyun  */
308*4882a593Smuzhiyun int snd_hda_codec_new(struct hda_bus *bus, struct snd_card *card,
309*4882a593Smuzhiyun 		      unsigned int codec_addr, struct hda_codec **codecp);
310*4882a593Smuzhiyun int snd_hda_codec_device_new(struct hda_bus *bus, struct snd_card *card,
311*4882a593Smuzhiyun 		      unsigned int codec_addr, struct hda_codec *codec);
312*4882a593Smuzhiyun int snd_hda_codec_configure(struct hda_codec *codec);
313*4882a593Smuzhiyun int snd_hda_codec_update_widgets(struct hda_codec *codec);
314*4882a593Smuzhiyun 
315*4882a593Smuzhiyun /*
316*4882a593Smuzhiyun  * low level functions
317*4882a593Smuzhiyun  */
318*4882a593Smuzhiyun static inline unsigned int
snd_hda_codec_read(struct hda_codec * codec,hda_nid_t nid,int flags,unsigned int verb,unsigned int parm)319*4882a593Smuzhiyun snd_hda_codec_read(struct hda_codec *codec, hda_nid_t nid,
320*4882a593Smuzhiyun 				int flags,
321*4882a593Smuzhiyun 				unsigned int verb, unsigned int parm)
322*4882a593Smuzhiyun {
323*4882a593Smuzhiyun 	return snd_hdac_codec_read(&codec->core, nid, flags, verb, parm);
324*4882a593Smuzhiyun }
325*4882a593Smuzhiyun 
326*4882a593Smuzhiyun static inline int
snd_hda_codec_write(struct hda_codec * codec,hda_nid_t nid,int flags,unsigned int verb,unsigned int parm)327*4882a593Smuzhiyun snd_hda_codec_write(struct hda_codec *codec, hda_nid_t nid, int flags,
328*4882a593Smuzhiyun 			unsigned int verb, unsigned int parm)
329*4882a593Smuzhiyun {
330*4882a593Smuzhiyun 	return snd_hdac_codec_write(&codec->core, nid, flags, verb, parm);
331*4882a593Smuzhiyun }
332*4882a593Smuzhiyun 
333*4882a593Smuzhiyun #define snd_hda_param_read(codec, nid, param) \
334*4882a593Smuzhiyun 	snd_hdac_read_parm(&(codec)->core, nid, param)
335*4882a593Smuzhiyun #define snd_hda_get_sub_nodes(codec, nid, start_nid) \
336*4882a593Smuzhiyun 	snd_hdac_get_sub_nodes(&(codec)->core, nid, start_nid)
337*4882a593Smuzhiyun int snd_hda_get_connections(struct hda_codec *codec, hda_nid_t nid,
338*4882a593Smuzhiyun 			    hda_nid_t *conn_list, int max_conns);
339*4882a593Smuzhiyun static inline int
snd_hda_get_num_conns(struct hda_codec * codec,hda_nid_t nid)340*4882a593Smuzhiyun snd_hda_get_num_conns(struct hda_codec *codec, hda_nid_t nid)
341*4882a593Smuzhiyun {
342*4882a593Smuzhiyun 	return snd_hda_get_connections(codec, nid, NULL, 0);
343*4882a593Smuzhiyun }
344*4882a593Smuzhiyun 
345*4882a593Smuzhiyun #define snd_hda_get_raw_connections(codec, nid, list, max_conns) \
346*4882a593Smuzhiyun 	snd_hdac_get_connections(&(codec)->core, nid, list, max_conns)
347*4882a593Smuzhiyun #define snd_hda_get_num_raw_conns(codec, nid) \
348*4882a593Smuzhiyun 	snd_hdac_get_connections(&(codec)->core, nid, NULL, 0);
349*4882a593Smuzhiyun 
350*4882a593Smuzhiyun int snd_hda_get_conn_list(struct hda_codec *codec, hda_nid_t nid,
351*4882a593Smuzhiyun 			  const hda_nid_t **listp);
352*4882a593Smuzhiyun int snd_hda_override_conn_list(struct hda_codec *codec, hda_nid_t nid, int nums,
353*4882a593Smuzhiyun 			  const hda_nid_t *list);
354*4882a593Smuzhiyun int snd_hda_get_conn_index(struct hda_codec *codec, hda_nid_t mux,
355*4882a593Smuzhiyun 			   hda_nid_t nid, int recursive);
356*4882a593Smuzhiyun unsigned int snd_hda_get_num_devices(struct hda_codec *codec, hda_nid_t nid);
357*4882a593Smuzhiyun int snd_hda_get_devices(struct hda_codec *codec, hda_nid_t nid,
358*4882a593Smuzhiyun 			u8 *dev_list, int max_devices);
359*4882a593Smuzhiyun int snd_hda_get_dev_select(struct hda_codec *codec, hda_nid_t nid);
360*4882a593Smuzhiyun int snd_hda_set_dev_select(struct hda_codec *codec, hda_nid_t nid, int dev_id);
361*4882a593Smuzhiyun 
362*4882a593Smuzhiyun struct hda_verb {
363*4882a593Smuzhiyun 	hda_nid_t nid;
364*4882a593Smuzhiyun 	u32 verb;
365*4882a593Smuzhiyun 	u32 param;
366*4882a593Smuzhiyun };
367*4882a593Smuzhiyun 
368*4882a593Smuzhiyun void snd_hda_sequence_write(struct hda_codec *codec,
369*4882a593Smuzhiyun 			    const struct hda_verb *seq);
370*4882a593Smuzhiyun 
371*4882a593Smuzhiyun /* cached write */
372*4882a593Smuzhiyun static inline int
snd_hda_codec_write_cache(struct hda_codec * codec,hda_nid_t nid,int flags,unsigned int verb,unsigned int parm)373*4882a593Smuzhiyun snd_hda_codec_write_cache(struct hda_codec *codec, hda_nid_t nid,
374*4882a593Smuzhiyun 			  int flags, unsigned int verb, unsigned int parm)
375*4882a593Smuzhiyun {
376*4882a593Smuzhiyun 	return snd_hdac_regmap_write(&codec->core, nid, verb, parm);
377*4882a593Smuzhiyun }
378*4882a593Smuzhiyun 
379*4882a593Smuzhiyun /* the struct for codec->pin_configs */
380*4882a593Smuzhiyun struct hda_pincfg {
381*4882a593Smuzhiyun 	hda_nid_t nid;
382*4882a593Smuzhiyun 	unsigned char ctrl;	/* original pin control value */
383*4882a593Smuzhiyun 	unsigned char target;	/* target pin control value */
384*4882a593Smuzhiyun 	unsigned int cfg;	/* default configuration */
385*4882a593Smuzhiyun };
386*4882a593Smuzhiyun 
387*4882a593Smuzhiyun unsigned int snd_hda_codec_get_pincfg(struct hda_codec *codec, hda_nid_t nid);
388*4882a593Smuzhiyun int snd_hda_codec_set_pincfg(struct hda_codec *codec, hda_nid_t nid,
389*4882a593Smuzhiyun 			     unsigned int cfg);
390*4882a593Smuzhiyun int snd_hda_add_pincfg(struct hda_codec *codec, struct snd_array *list,
391*4882a593Smuzhiyun 		       hda_nid_t nid, unsigned int cfg); /* for hwdep */
392*4882a593Smuzhiyun void snd_hda_shutup_pins(struct hda_codec *codec);
393*4882a593Smuzhiyun 
394*4882a593Smuzhiyun /* SPDIF controls */
395*4882a593Smuzhiyun struct hda_spdif_out {
396*4882a593Smuzhiyun 	hda_nid_t nid;		/* Converter nid values relate to */
397*4882a593Smuzhiyun 	unsigned int status;	/* IEC958 status bits */
398*4882a593Smuzhiyun 	unsigned short ctls;	/* SPDIF control bits */
399*4882a593Smuzhiyun };
400*4882a593Smuzhiyun struct hda_spdif_out *snd_hda_spdif_out_of_nid(struct hda_codec *codec,
401*4882a593Smuzhiyun 					       hda_nid_t nid);
402*4882a593Smuzhiyun void snd_hda_spdif_ctls_unassign(struct hda_codec *codec, int idx);
403*4882a593Smuzhiyun void snd_hda_spdif_ctls_assign(struct hda_codec *codec, int idx, hda_nid_t nid);
404*4882a593Smuzhiyun 
405*4882a593Smuzhiyun /*
406*4882a593Smuzhiyun  * Mixer
407*4882a593Smuzhiyun  */
408*4882a593Smuzhiyun int snd_hda_codec_build_controls(struct hda_codec *codec);
409*4882a593Smuzhiyun 
410*4882a593Smuzhiyun /*
411*4882a593Smuzhiyun  * PCM
412*4882a593Smuzhiyun  */
413*4882a593Smuzhiyun int snd_hda_codec_parse_pcms(struct hda_codec *codec);
414*4882a593Smuzhiyun int snd_hda_codec_build_pcms(struct hda_codec *codec);
415*4882a593Smuzhiyun 
416*4882a593Smuzhiyun __printf(2, 3)
417*4882a593Smuzhiyun struct hda_pcm *snd_hda_codec_pcm_new(struct hda_codec *codec,
418*4882a593Smuzhiyun 				      const char *fmt, ...);
419*4882a593Smuzhiyun 
420*4882a593Smuzhiyun void snd_hda_codec_cleanup_for_unbind(struct hda_codec *codec);
421*4882a593Smuzhiyun 
snd_hda_codec_pcm_get(struct hda_pcm * pcm)422*4882a593Smuzhiyun static inline void snd_hda_codec_pcm_get(struct hda_pcm *pcm)
423*4882a593Smuzhiyun {
424*4882a593Smuzhiyun 	kref_get(&pcm->kref);
425*4882a593Smuzhiyun }
426*4882a593Smuzhiyun void snd_hda_codec_pcm_put(struct hda_pcm *pcm);
427*4882a593Smuzhiyun 
428*4882a593Smuzhiyun int snd_hda_codec_prepare(struct hda_codec *codec,
429*4882a593Smuzhiyun 			  struct hda_pcm_stream *hinfo,
430*4882a593Smuzhiyun 			  unsigned int stream,
431*4882a593Smuzhiyun 			  unsigned int format,
432*4882a593Smuzhiyun 			  struct snd_pcm_substream *substream);
433*4882a593Smuzhiyun void snd_hda_codec_cleanup(struct hda_codec *codec,
434*4882a593Smuzhiyun 			   struct hda_pcm_stream *hinfo,
435*4882a593Smuzhiyun 			   struct snd_pcm_substream *substream);
436*4882a593Smuzhiyun 
437*4882a593Smuzhiyun void snd_hda_codec_setup_stream(struct hda_codec *codec, hda_nid_t nid,
438*4882a593Smuzhiyun 				u32 stream_tag,
439*4882a593Smuzhiyun 				int channel_id, int format);
440*4882a593Smuzhiyun void __snd_hda_codec_cleanup_stream(struct hda_codec *codec, hda_nid_t nid,
441*4882a593Smuzhiyun 				    int do_now);
442*4882a593Smuzhiyun #define snd_hda_codec_cleanup_stream(codec, nid) \
443*4882a593Smuzhiyun 	__snd_hda_codec_cleanup_stream(codec, nid, 0)
444*4882a593Smuzhiyun 
445*4882a593Smuzhiyun #define snd_hda_query_supported_pcm(codec, nid, ratesp, fmtsp, bpsp) \
446*4882a593Smuzhiyun 	snd_hdac_query_supported_pcm(&(codec)->core, nid, ratesp, fmtsp, bpsp)
447*4882a593Smuzhiyun #define snd_hda_is_supported_format(codec, nid, fmt) \
448*4882a593Smuzhiyun 	snd_hdac_is_supported_format(&(codec)->core, nid, fmt)
449*4882a593Smuzhiyun 
450*4882a593Smuzhiyun extern const struct snd_pcm_chmap_elem snd_pcm_2_1_chmaps[];
451*4882a593Smuzhiyun 
452*4882a593Smuzhiyun int snd_hda_attach_pcm_stream(struct hda_bus *_bus, struct hda_codec *codec,
453*4882a593Smuzhiyun 			      struct hda_pcm *cpcm);
454*4882a593Smuzhiyun 
455*4882a593Smuzhiyun /*
456*4882a593Smuzhiyun  * Misc
457*4882a593Smuzhiyun  */
458*4882a593Smuzhiyun void snd_hda_get_codec_name(struct hda_codec *codec, char *name, int namelen);
459*4882a593Smuzhiyun void snd_hda_codec_set_power_to_all(struct hda_codec *codec, hda_nid_t fg,
460*4882a593Smuzhiyun 				    unsigned int power_state);
461*4882a593Smuzhiyun 
462*4882a593Smuzhiyun int snd_hda_lock_devices(struct hda_bus *bus);
463*4882a593Smuzhiyun void snd_hda_unlock_devices(struct hda_bus *bus);
464*4882a593Smuzhiyun void snd_hda_bus_reset(struct hda_bus *bus);
465*4882a593Smuzhiyun void snd_hda_bus_reset_codecs(struct hda_bus *bus);
466*4882a593Smuzhiyun 
467*4882a593Smuzhiyun int snd_hda_codec_set_name(struct hda_codec *codec, const char *name);
468*4882a593Smuzhiyun 
469*4882a593Smuzhiyun /*
470*4882a593Smuzhiyun  * power management
471*4882a593Smuzhiyun  */
472*4882a593Smuzhiyun extern const struct dev_pm_ops hda_codec_driver_pm;
473*4882a593Smuzhiyun 
474*4882a593Smuzhiyun static inline
hda_call_check_power_status(struct hda_codec * codec,hda_nid_t nid)475*4882a593Smuzhiyun int hda_call_check_power_status(struct hda_codec *codec, hda_nid_t nid)
476*4882a593Smuzhiyun {
477*4882a593Smuzhiyun #ifdef CONFIG_PM
478*4882a593Smuzhiyun 	if (codec->patch_ops.check_power_status)
479*4882a593Smuzhiyun 		return codec->patch_ops.check_power_status(codec, nid);
480*4882a593Smuzhiyun #endif
481*4882a593Smuzhiyun 	return 0;
482*4882a593Smuzhiyun }
483*4882a593Smuzhiyun 
484*4882a593Smuzhiyun /*
485*4882a593Smuzhiyun  * power saving
486*4882a593Smuzhiyun  */
487*4882a593Smuzhiyun #define snd_hda_power_up(codec)		snd_hdac_power_up(&(codec)->core)
488*4882a593Smuzhiyun #define snd_hda_power_up_pm(codec)	snd_hdac_power_up_pm(&(codec)->core)
489*4882a593Smuzhiyun #define snd_hda_power_down(codec)	snd_hdac_power_down(&(codec)->core)
490*4882a593Smuzhiyun #define snd_hda_power_down_pm(codec)	snd_hdac_power_down_pm(&(codec)->core)
491*4882a593Smuzhiyun #ifdef CONFIG_PM
492*4882a593Smuzhiyun void snd_hda_set_power_save(struct hda_bus *bus, int delay);
493*4882a593Smuzhiyun void snd_hda_update_power_acct(struct hda_codec *codec);
494*4882a593Smuzhiyun #else
snd_hda_set_power_save(struct hda_bus * bus,int delay)495*4882a593Smuzhiyun static inline void snd_hda_set_power_save(struct hda_bus *bus, int delay) {}
496*4882a593Smuzhiyun #endif
497*4882a593Smuzhiyun 
hda_codec_need_resume(struct hda_codec * codec)498*4882a593Smuzhiyun static inline bool hda_codec_need_resume(struct hda_codec *codec)
499*4882a593Smuzhiyun {
500*4882a593Smuzhiyun 	return !codec->relaxed_resume && codec->jacktbl.used;
501*4882a593Smuzhiyun }
502*4882a593Smuzhiyun 
503*4882a593Smuzhiyun #ifdef CONFIG_SND_HDA_PATCH_LOADER
504*4882a593Smuzhiyun /*
505*4882a593Smuzhiyun  * patch firmware
506*4882a593Smuzhiyun  */
507*4882a593Smuzhiyun int snd_hda_load_patch(struct hda_bus *bus, size_t size, const void *buf);
508*4882a593Smuzhiyun #endif
509*4882a593Smuzhiyun 
510*4882a593Smuzhiyun #ifdef CONFIG_SND_HDA_DSP_LOADER
511*4882a593Smuzhiyun int snd_hda_codec_load_dsp_prepare(struct hda_codec *codec, unsigned int format,
512*4882a593Smuzhiyun 				   unsigned int size,
513*4882a593Smuzhiyun 				   struct snd_dma_buffer *bufp);
514*4882a593Smuzhiyun void snd_hda_codec_load_dsp_trigger(struct hda_codec *codec, bool start);
515*4882a593Smuzhiyun void snd_hda_codec_load_dsp_cleanup(struct hda_codec *codec,
516*4882a593Smuzhiyun 				    struct snd_dma_buffer *dmab);
517*4882a593Smuzhiyun #else
518*4882a593Smuzhiyun static inline int
snd_hda_codec_load_dsp_prepare(struct hda_codec * codec,unsigned int format,unsigned int size,struct snd_dma_buffer * bufp)519*4882a593Smuzhiyun snd_hda_codec_load_dsp_prepare(struct hda_codec *codec, unsigned int format,
520*4882a593Smuzhiyun 				unsigned int size,
521*4882a593Smuzhiyun 				struct snd_dma_buffer *bufp)
522*4882a593Smuzhiyun {
523*4882a593Smuzhiyun 	return -ENOSYS;
524*4882a593Smuzhiyun }
525*4882a593Smuzhiyun static inline void
snd_hda_codec_load_dsp_trigger(struct hda_codec * codec,bool start)526*4882a593Smuzhiyun snd_hda_codec_load_dsp_trigger(struct hda_codec *codec, bool start) {}
527*4882a593Smuzhiyun static inline void
snd_hda_codec_load_dsp_cleanup(struct hda_codec * codec,struct snd_dma_buffer * dmab)528*4882a593Smuzhiyun snd_hda_codec_load_dsp_cleanup(struct hda_codec *codec,
529*4882a593Smuzhiyun 				struct snd_dma_buffer *dmab) {}
530*4882a593Smuzhiyun #endif
531*4882a593Smuzhiyun 
532*4882a593Smuzhiyun #endif /* __SOUND_HDA_CODEC_H */
533