xref: /linux/include/sound/hda_chmap.h (revision b2441318)
1*b2441318SGreg Kroah-Hartman /* SPDX-License-Identifier: GPL-2.0 */
267b90cb8SSubhransu S. Prusty /*
367b90cb8SSubhransu S. Prusty  * For multichannel support
467b90cb8SSubhransu S. Prusty  */
567b90cb8SSubhransu S. Prusty 
667b90cb8SSubhransu S. Prusty #ifndef __SOUND_HDA_CHMAP_H
767b90cb8SSubhransu S. Prusty #define __SOUND_HDA_CHMAP_H
867b90cb8SSubhransu S. Prusty 
92f6e8a85SSubhransu S. Prusty #include <sound/pcm.h>
1067b90cb8SSubhransu S. Prusty #include <sound/hdaudio.h>
1167b90cb8SSubhransu S. Prusty 
12828cb4edSSubhransu S. Prusty 
13828cb4edSSubhransu S. Prusty #define SND_PRINT_CHANNEL_ALLOCATION_ADVISED_BUFSIZE 80
14828cb4edSSubhransu S. Prusty 
15f302240dSSubhransu S. Prusty struct hdac_cea_channel_speaker_allocation {
1667b90cb8SSubhransu S. Prusty 	int ca_index;
1767b90cb8SSubhransu S. Prusty 	int speakers[8];
1867b90cb8SSubhransu S. Prusty 
1967b90cb8SSubhransu S. Prusty 	/* derived values, just for convenience */
2067b90cb8SSubhransu S. Prusty 	int channels;
2167b90cb8SSubhransu S. Prusty 	int spk_mask;
2267b90cb8SSubhransu S. Prusty };
2367b90cb8SSubhransu S. Prusty struct hdac_chmap;
2467b90cb8SSubhransu S. Prusty 
2567b90cb8SSubhransu S. Prusty struct hdac_chmap_ops {
2667b90cb8SSubhransu S. Prusty 	/*
2767b90cb8SSubhransu S. Prusty 	 * Helpers for producing the channel map TLVs. These can be overridden
2867b90cb8SSubhransu S. Prusty 	 * for devices that have non-standard mapping requirements.
2967b90cb8SSubhransu S. Prusty 	 */
3067b90cb8SSubhransu S. Prusty 	int (*chmap_cea_alloc_validate_get_type)(struct hdac_chmap *chmap,
31f302240dSSubhransu S. Prusty 		struct hdac_cea_channel_speaker_allocation *cap, int channels);
32828cb4edSSubhransu S. Prusty 	void (*cea_alloc_to_tlv_chmap)(struct hdac_chmap *hchmap,
33828cb4edSSubhransu S. Prusty 		struct hdac_cea_channel_speaker_allocation *cap,
3467b90cb8SSubhransu S. Prusty 		unsigned int *chmap, int channels);
3567b90cb8SSubhransu S. Prusty 
3667b90cb8SSubhransu S. Prusty 	/* check that the user-given chmap is supported */
37828cb4edSSubhransu S. Prusty 	int (*chmap_validate)(struct hdac_chmap *hchmap, int ca,
38828cb4edSSubhransu S. Prusty 			int channels, unsigned char *chmap);
399b3dc8aaSSubhransu S. Prusty 
4044fde3b8SSubhransu S. Prusty 	int (*get_spk_alloc)(struct hdac_device *hdac, int pcm_idx);
4144fde3b8SSubhransu S. Prusty 
429b3dc8aaSSubhransu S. Prusty 	void (*get_chmap)(struct hdac_device *hdac, int pcm_idx,
439b3dc8aaSSubhransu S. Prusty 					unsigned char *chmap);
449b3dc8aaSSubhransu S. Prusty 	void (*set_chmap)(struct hdac_device *hdac, int pcm_idx,
459b3dc8aaSSubhransu S. Prusty 			unsigned char *chmap, int prepared);
469b3dc8aaSSubhransu S. Prusty 	bool (*is_pcm_attached)(struct hdac_device *hdac, int pcm_idx);
47739ffee9SSubhransu S. Prusty 
48739ffee9SSubhransu S. Prusty 	/* get and set channel assigned to each HDMI ASP (audio sample packet) slot */
49739ffee9SSubhransu S. Prusty 	int (*pin_get_slot_channel)(struct hdac_device *codec,
50739ffee9SSubhransu S. Prusty 			hda_nid_t pin_nid, int asp_slot);
51739ffee9SSubhransu S. Prusty 	int (*pin_set_slot_channel)(struct hdac_device *codec,
52739ffee9SSubhransu S. Prusty 			hda_nid_t pin_nid, int asp_slot, int channel);
53739ffee9SSubhransu S. Prusty 	void (*set_channel_count)(struct hdac_device *codec,
54739ffee9SSubhransu S. Prusty 				hda_nid_t cvt_nid, int chs);
5567b90cb8SSubhransu S. Prusty };
5667b90cb8SSubhransu S. Prusty 
5767b90cb8SSubhransu S. Prusty struct hdac_chmap {
5867b90cb8SSubhransu S. Prusty 	unsigned int channels_max; /* max over all cvts */
5967b90cb8SSubhransu S. Prusty 	struct hdac_chmap_ops ops;
6067b90cb8SSubhransu S. Prusty 	struct hdac_device *hdac;
6167b90cb8SSubhransu S. Prusty };
6267b90cb8SSubhransu S. Prusty 
63739ffee9SSubhransu S. Prusty void snd_hdac_register_chmap_ops(struct hdac_device *hdac,
64739ffee9SSubhransu S. Prusty 				struct hdac_chmap *chmap);
65bb63f726SSubhransu S. Prusty int snd_hdac_channel_allocation(struct hdac_device *hdac, int spk_alloc,
662f6e8a85SSubhransu S. Prusty 			int channels, bool chmap_set,
672f6e8a85SSubhransu S. Prusty 			bool non_pcm, unsigned char *map);
68bb63f726SSubhransu S. Prusty int snd_hdac_get_active_channels(int ca);
69bb63f726SSubhransu S. Prusty void snd_hdac_setup_channel_mapping(struct hdac_chmap *chmap,
702f6e8a85SSubhransu S. Prusty 		       hda_nid_t pin_nid, bool non_pcm, int ca,
712f6e8a85SSubhransu S. Prusty 		       int channels, unsigned char *map,
722f6e8a85SSubhransu S. Prusty 		       bool chmap_set);
73bb63f726SSubhransu S. Prusty void snd_hdac_print_channel_allocation(int spk_alloc, char *buf, int buflen);
74bb63f726SSubhransu S. Prusty struct hdac_cea_channel_speaker_allocation *snd_hdac_get_ch_alloc_from_ca(int ca);
75bb63f726SSubhransu S. Prusty int snd_hdac_chmap_to_spk_mask(unsigned char c);
76bb63f726SSubhransu S. Prusty int snd_hdac_spk_to_chmap(int spk);
772f6e8a85SSubhransu S. Prusty int snd_hdac_add_chmap_ctls(struct snd_pcm *pcm, int pcm_idx,
782f6e8a85SSubhransu S. Prusty 				struct hdac_chmap *chmap);
7967b90cb8SSubhransu S. Prusty #endif /* __SOUND_HDA_CHMAP_H */
80