18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * For multichannel support
48c2ecf20Sopenharmony_ci */
58c2ecf20Sopenharmony_ci
68c2ecf20Sopenharmony_ci#ifndef __SOUND_HDA_CHMAP_H
78c2ecf20Sopenharmony_ci#define __SOUND_HDA_CHMAP_H
88c2ecf20Sopenharmony_ci
98c2ecf20Sopenharmony_ci#include <sound/pcm.h>
108c2ecf20Sopenharmony_ci#include <sound/hdaudio.h>
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ci
138c2ecf20Sopenharmony_ci#define SND_PRINT_CHANNEL_ALLOCATION_ADVISED_BUFSIZE 80
148c2ecf20Sopenharmony_ci
158c2ecf20Sopenharmony_cistruct hdac_cea_channel_speaker_allocation {
168c2ecf20Sopenharmony_ci	int ca_index;
178c2ecf20Sopenharmony_ci	int speakers[8];
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ci	/* derived values, just for convenience */
208c2ecf20Sopenharmony_ci	int channels;
218c2ecf20Sopenharmony_ci	int spk_mask;
228c2ecf20Sopenharmony_ci};
238c2ecf20Sopenharmony_cistruct hdac_chmap;
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_cistruct hdac_chmap_ops {
268c2ecf20Sopenharmony_ci	/*
278c2ecf20Sopenharmony_ci	 * Helpers for producing the channel map TLVs. These can be overridden
288c2ecf20Sopenharmony_ci	 * for devices that have non-standard mapping requirements.
298c2ecf20Sopenharmony_ci	 */
308c2ecf20Sopenharmony_ci	int (*chmap_cea_alloc_validate_get_type)(struct hdac_chmap *chmap,
318c2ecf20Sopenharmony_ci		struct hdac_cea_channel_speaker_allocation *cap, int channels);
328c2ecf20Sopenharmony_ci	void (*cea_alloc_to_tlv_chmap)(struct hdac_chmap *hchmap,
338c2ecf20Sopenharmony_ci		struct hdac_cea_channel_speaker_allocation *cap,
348c2ecf20Sopenharmony_ci		unsigned int *chmap, int channels);
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_ci	/* check that the user-given chmap is supported */
378c2ecf20Sopenharmony_ci	int (*chmap_validate)(struct hdac_chmap *hchmap, int ca,
388c2ecf20Sopenharmony_ci			int channels, unsigned char *chmap);
398c2ecf20Sopenharmony_ci
408c2ecf20Sopenharmony_ci	int (*get_spk_alloc)(struct hdac_device *hdac, int pcm_idx);
418c2ecf20Sopenharmony_ci
428c2ecf20Sopenharmony_ci	void (*get_chmap)(struct hdac_device *hdac, int pcm_idx,
438c2ecf20Sopenharmony_ci					unsigned char *chmap);
448c2ecf20Sopenharmony_ci	void (*set_chmap)(struct hdac_device *hdac, int pcm_idx,
458c2ecf20Sopenharmony_ci			unsigned char *chmap, int prepared);
468c2ecf20Sopenharmony_ci	bool (*is_pcm_attached)(struct hdac_device *hdac, int pcm_idx);
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci	/* get and set channel assigned to each HDMI ASP (audio sample packet) slot */
498c2ecf20Sopenharmony_ci	int (*pin_get_slot_channel)(struct hdac_device *codec,
508c2ecf20Sopenharmony_ci			hda_nid_t pin_nid, int asp_slot);
518c2ecf20Sopenharmony_ci	int (*pin_set_slot_channel)(struct hdac_device *codec,
528c2ecf20Sopenharmony_ci			hda_nid_t pin_nid, int asp_slot, int channel);
538c2ecf20Sopenharmony_ci	void (*set_channel_count)(struct hdac_device *codec,
548c2ecf20Sopenharmony_ci				hda_nid_t cvt_nid, int chs);
558c2ecf20Sopenharmony_ci};
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_cistruct hdac_chmap {
588c2ecf20Sopenharmony_ci	unsigned int channels_max; /* max over all cvts */
598c2ecf20Sopenharmony_ci	struct hdac_chmap_ops ops;
608c2ecf20Sopenharmony_ci	struct hdac_device *hdac;
618c2ecf20Sopenharmony_ci};
628c2ecf20Sopenharmony_ci
638c2ecf20Sopenharmony_civoid snd_hdac_register_chmap_ops(struct hdac_device *hdac,
648c2ecf20Sopenharmony_ci				struct hdac_chmap *chmap);
658c2ecf20Sopenharmony_ciint snd_hdac_channel_allocation(struct hdac_device *hdac, int spk_alloc,
668c2ecf20Sopenharmony_ci			int channels, bool chmap_set,
678c2ecf20Sopenharmony_ci			bool non_pcm, unsigned char *map);
688c2ecf20Sopenharmony_ciint snd_hdac_get_active_channels(int ca);
698c2ecf20Sopenharmony_civoid snd_hdac_setup_channel_mapping(struct hdac_chmap *chmap,
708c2ecf20Sopenharmony_ci		       hda_nid_t pin_nid, bool non_pcm, int ca,
718c2ecf20Sopenharmony_ci		       int channels, unsigned char *map,
728c2ecf20Sopenharmony_ci		       bool chmap_set);
738c2ecf20Sopenharmony_civoid snd_hdac_print_channel_allocation(int spk_alloc, char *buf, int buflen);
748c2ecf20Sopenharmony_cistruct hdac_cea_channel_speaker_allocation *snd_hdac_get_ch_alloc_from_ca(int ca);
758c2ecf20Sopenharmony_ciint snd_hdac_chmap_to_spk_mask(unsigned char c);
768c2ecf20Sopenharmony_ciint snd_hdac_spk_to_chmap(int spk);
778c2ecf20Sopenharmony_ciint snd_hdac_add_chmap_ctls(struct snd_pcm *pcm, int pcm_idx,
788c2ecf20Sopenharmony_ci				struct hdac_chmap *chmap);
798c2ecf20Sopenharmony_ci#endif /* __SOUND_HDA_CHMAP_H */
80