xref: /OK3568_Linux_fs/kernel/include/sound/hda_chmap.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0 */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * For multichannel support
4*4882a593Smuzhiyun  */
5*4882a593Smuzhiyun 
6*4882a593Smuzhiyun #ifndef __SOUND_HDA_CHMAP_H
7*4882a593Smuzhiyun #define __SOUND_HDA_CHMAP_H
8*4882a593Smuzhiyun 
9*4882a593Smuzhiyun #include <sound/pcm.h>
10*4882a593Smuzhiyun #include <sound/hdaudio.h>
11*4882a593Smuzhiyun 
12*4882a593Smuzhiyun 
13*4882a593Smuzhiyun #define SND_PRINT_CHANNEL_ALLOCATION_ADVISED_BUFSIZE 80
14*4882a593Smuzhiyun 
15*4882a593Smuzhiyun struct hdac_cea_channel_speaker_allocation {
16*4882a593Smuzhiyun 	int ca_index;
17*4882a593Smuzhiyun 	int speakers[8];
18*4882a593Smuzhiyun 
19*4882a593Smuzhiyun 	/* derived values, just for convenience */
20*4882a593Smuzhiyun 	int channels;
21*4882a593Smuzhiyun 	int spk_mask;
22*4882a593Smuzhiyun };
23*4882a593Smuzhiyun struct hdac_chmap;
24*4882a593Smuzhiyun 
25*4882a593Smuzhiyun struct hdac_chmap_ops {
26*4882a593Smuzhiyun 	/*
27*4882a593Smuzhiyun 	 * Helpers for producing the channel map TLVs. These can be overridden
28*4882a593Smuzhiyun 	 * for devices that have non-standard mapping requirements.
29*4882a593Smuzhiyun 	 */
30*4882a593Smuzhiyun 	int (*chmap_cea_alloc_validate_get_type)(struct hdac_chmap *chmap,
31*4882a593Smuzhiyun 		struct hdac_cea_channel_speaker_allocation *cap, int channels);
32*4882a593Smuzhiyun 	void (*cea_alloc_to_tlv_chmap)(struct hdac_chmap *hchmap,
33*4882a593Smuzhiyun 		struct hdac_cea_channel_speaker_allocation *cap,
34*4882a593Smuzhiyun 		unsigned int *chmap, int channels);
35*4882a593Smuzhiyun 
36*4882a593Smuzhiyun 	/* check that the user-given chmap is supported */
37*4882a593Smuzhiyun 	int (*chmap_validate)(struct hdac_chmap *hchmap, int ca,
38*4882a593Smuzhiyun 			int channels, unsigned char *chmap);
39*4882a593Smuzhiyun 
40*4882a593Smuzhiyun 	int (*get_spk_alloc)(struct hdac_device *hdac, int pcm_idx);
41*4882a593Smuzhiyun 
42*4882a593Smuzhiyun 	void (*get_chmap)(struct hdac_device *hdac, int pcm_idx,
43*4882a593Smuzhiyun 					unsigned char *chmap);
44*4882a593Smuzhiyun 	void (*set_chmap)(struct hdac_device *hdac, int pcm_idx,
45*4882a593Smuzhiyun 			unsigned char *chmap, int prepared);
46*4882a593Smuzhiyun 	bool (*is_pcm_attached)(struct hdac_device *hdac, int pcm_idx);
47*4882a593Smuzhiyun 
48*4882a593Smuzhiyun 	/* get and set channel assigned to each HDMI ASP (audio sample packet) slot */
49*4882a593Smuzhiyun 	int (*pin_get_slot_channel)(struct hdac_device *codec,
50*4882a593Smuzhiyun 			hda_nid_t pin_nid, int asp_slot);
51*4882a593Smuzhiyun 	int (*pin_set_slot_channel)(struct hdac_device *codec,
52*4882a593Smuzhiyun 			hda_nid_t pin_nid, int asp_slot, int channel);
53*4882a593Smuzhiyun 	void (*set_channel_count)(struct hdac_device *codec,
54*4882a593Smuzhiyun 				hda_nid_t cvt_nid, int chs);
55*4882a593Smuzhiyun };
56*4882a593Smuzhiyun 
57*4882a593Smuzhiyun struct hdac_chmap {
58*4882a593Smuzhiyun 	unsigned int channels_max; /* max over all cvts */
59*4882a593Smuzhiyun 	struct hdac_chmap_ops ops;
60*4882a593Smuzhiyun 	struct hdac_device *hdac;
61*4882a593Smuzhiyun };
62*4882a593Smuzhiyun 
63*4882a593Smuzhiyun void snd_hdac_register_chmap_ops(struct hdac_device *hdac,
64*4882a593Smuzhiyun 				struct hdac_chmap *chmap);
65*4882a593Smuzhiyun int snd_hdac_channel_allocation(struct hdac_device *hdac, int spk_alloc,
66*4882a593Smuzhiyun 			int channels, bool chmap_set,
67*4882a593Smuzhiyun 			bool non_pcm, unsigned char *map);
68*4882a593Smuzhiyun int snd_hdac_get_active_channels(int ca);
69*4882a593Smuzhiyun void snd_hdac_setup_channel_mapping(struct hdac_chmap *chmap,
70*4882a593Smuzhiyun 		       hda_nid_t pin_nid, bool non_pcm, int ca,
71*4882a593Smuzhiyun 		       int channels, unsigned char *map,
72*4882a593Smuzhiyun 		       bool chmap_set);
73*4882a593Smuzhiyun void snd_hdac_print_channel_allocation(int spk_alloc, char *buf, int buflen);
74*4882a593Smuzhiyun struct hdac_cea_channel_speaker_allocation *snd_hdac_get_ch_alloc_from_ca(int ca);
75*4882a593Smuzhiyun int snd_hdac_chmap_to_spk_mask(unsigned char c);
76*4882a593Smuzhiyun int snd_hdac_spk_to_chmap(int spk);
77*4882a593Smuzhiyun int snd_hdac_add_chmap_ctls(struct snd_pcm *pcm, int pcm_idx,
78*4882a593Smuzhiyun 				struct hdac_chmap *chmap);
79*4882a593Smuzhiyun #endif /* __SOUND_HDA_CHMAP_H */
80