1 /* SPDX-License-Identifier: GPL-2.0-only 2 * Copyright (c) 2020 Intel Corporation 3 */ 4 5 /* 6 * sof_sdw_common.h - prototypes for common helpers 7 */ 8 9 #ifndef SND_SOC_SOF_SDW_COMMON_H 10 #define SND_SOC_SOF_SDW_COMMON_H 11 12 #include <linux/bits.h> 13 #include <linux/types.h> 14 #include <sound/soc.h> 15 #include "sof_hdmi_common.h" 16 17 #define MAX_NO_PROPS 2 18 #define MAX_HDMI_NUM 4 19 #define SDW_UNUSED_DAI_ID -1 20 #define SDW_JACK_OUT_DAI_ID 0 21 #define SDW_JACK_IN_DAI_ID 1 22 #define SDW_AMP_OUT_DAI_ID 2 23 #define SDW_AMP_IN_DAI_ID 3 24 #define SDW_DMIC_DAI_ID 4 25 #define SDW_MAX_CPU_DAIS 16 26 #define SDW_INTEL_BIDIR_PDI_BASE 2 27 28 #define SDW_MAX_LINKS 4 29 30 /* 8 combinations with 4 links + unused group 0 */ 31 #define SDW_MAX_GROUPS 9 32 33 enum { 34 SOF_PRE_TGL_HDMI_COUNT = 3, 35 SOF_TGL_HDMI_COUNT = 4, 36 }; 37 38 enum { 39 SOF_I2S_SSP0 = BIT(0), 40 SOF_I2S_SSP1 = BIT(1), 41 SOF_I2S_SSP2 = BIT(2), 42 SOF_I2S_SSP3 = BIT(3), 43 SOF_I2S_SSP4 = BIT(4), 44 SOF_I2S_SSP5 = BIT(5), 45 }; 46 47 #define SOF_JACK_JDSRC(quirk) ((quirk) & GENMASK(3, 0)) 48 #define SOF_SDW_FOUR_SPK BIT(4) 49 #define SOF_SDW_TGL_HDMI BIT(5) 50 #define SOF_SDW_PCH_DMIC BIT(6) 51 #define SOF_SSP_PORT(x) (((x) & GENMASK(5, 0)) << 7) 52 #define SOF_SSP_GET_PORT(quirk) (((quirk) >> 7) & GENMASK(5, 0)) 53 /* Deprecated and no longer supported by the code */ 54 #define SOF_SDW_NO_AGGREGATION BIT(14) 55 /* If a CODEC has an optional speaker output, this quirk will enable it */ 56 #define SOF_CODEC_SPKR BIT(15) 57 58 /* BT audio offload: reserve 3 bits for future */ 59 #define SOF_BT_OFFLOAD_SSP_SHIFT 15 60 #define SOF_BT_OFFLOAD_SSP_MASK (GENMASK(17, 15)) 61 #define SOF_BT_OFFLOAD_SSP(quirk) \ 62 (((quirk) << SOF_BT_OFFLOAD_SSP_SHIFT) & SOF_BT_OFFLOAD_SSP_MASK) 63 #define SOF_SSP_BT_OFFLOAD_PRESENT BIT(18) 64 65 #define SOF_SDW_DAI_TYPE_JACK 0 66 #define SOF_SDW_DAI_TYPE_AMP 1 67 #define SOF_SDW_DAI_TYPE_MIC 2 68 69 #define SOF_SDW_MAX_DAI_NUM 8 70 71 struct sof_sdw_codec_info; 72 73 struct sof_sdw_dai_info { 74 const bool direction[2]; /* playback & capture support */ 75 const char *dai_name; 76 const int dai_type; 77 const int dailink[2]; /* dailink id for each direction */ 78 int (*init)(struct snd_soc_card *card, 79 struct snd_soc_dai_link *dai_links, 80 struct sof_sdw_codec_info *info, 81 bool playback); 82 int (*exit)(struct snd_soc_card *card, struct snd_soc_dai_link *dai_link); 83 int (*rtd_init)(struct snd_soc_pcm_runtime *rtd); 84 bool rtd_init_done; /* Indicate that the rtd_init callback is done */ 85 unsigned long quirk; 86 }; 87 88 struct sof_sdw_codec_info { 89 const int part_id; 90 const int version_id; 91 const char *codec_name; 92 int amp_num; 93 const u8 acpi_id[ACPI_ID_LEN]; 94 const bool ignore_pch_dmic; 95 const struct snd_soc_ops *ops; 96 struct sof_sdw_dai_info dais[SOF_SDW_MAX_DAI_NUM]; 97 const int dai_num; 98 99 int (*codec_card_late_probe)(struct snd_soc_card *card); 100 }; 101 102 struct mc_private { 103 struct snd_soc_jack sdw_headset; 104 struct sof_hdmi_private hdmi; 105 struct device *headset_codec_dev; /* only one headset per card */ 106 struct device *amp_dev1, *amp_dev2; 107 /* To store SDW Pin index for each SoundWire link */ 108 unsigned int sdw_pin_index[SDW_MAX_LINKS]; 109 bool append_dai_type; 110 bool ignore_pch_dmic; 111 }; 112 113 extern unsigned long sof_sdw_quirk; 114 115 struct snd_soc_dai *get_codec_dai_by_name(struct snd_soc_pcm_runtime *rtd, 116 const char * const dai_name[], 117 int num_dais); 118 119 int sdw_startup(struct snd_pcm_substream *substream); 120 int sdw_prepare(struct snd_pcm_substream *substream); 121 int sdw_trigger(struct snd_pcm_substream *substream, int cmd); 122 int sdw_hw_params(struct snd_pcm_substream *substream, 123 struct snd_pcm_hw_params *params); 124 int sdw_hw_free(struct snd_pcm_substream *substream); 125 void sdw_shutdown(struct snd_pcm_substream *substream); 126 127 /* generic HDMI support */ 128 int sof_sdw_hdmi_init(struct snd_soc_pcm_runtime *rtd); 129 130 int sof_sdw_hdmi_card_late_probe(struct snd_soc_card *card); 131 132 /* DMIC support */ 133 int sof_sdw_dmic_init(struct snd_soc_pcm_runtime *rtd); 134 135 /* RT711 support */ 136 int sof_sdw_rt711_init(struct snd_soc_card *card, 137 struct snd_soc_dai_link *dai_links, 138 struct sof_sdw_codec_info *info, 139 bool playback); 140 int sof_sdw_rt711_exit(struct snd_soc_card *card, struct snd_soc_dai_link *dai_link); 141 142 /* RT711-SDCA support */ 143 int sof_sdw_rt_sdca_jack_init(struct snd_soc_card *card, 144 struct snd_soc_dai_link *dai_links, 145 struct sof_sdw_codec_info *info, 146 bool playback); 147 int sof_sdw_rt_sdca_jack_exit(struct snd_soc_card *card, struct snd_soc_dai_link *dai_link); 148 149 /* RT1308 I2S support */ 150 extern struct snd_soc_ops sof_sdw_rt1308_i2s_ops; 151 152 /* generic amp support */ 153 int sof_sdw_rt_amp_init(struct snd_soc_card *card, 154 struct snd_soc_dai_link *dai_links, 155 struct sof_sdw_codec_info *info, 156 bool playback); 157 int sof_sdw_rt_amp_exit(struct snd_soc_card *card, struct snd_soc_dai_link *dai_link); 158 159 /* MAXIM codec support */ 160 int sof_sdw_maxim_init(struct snd_soc_card *card, 161 struct snd_soc_dai_link *dai_links, 162 struct sof_sdw_codec_info *info, 163 bool playback); 164 165 /* CS42L43 support */ 166 int sof_sdw_cs42l43_spk_init(struct snd_soc_card *card, 167 struct snd_soc_dai_link *dai_links, 168 struct sof_sdw_codec_info *info, 169 bool playback); 170 171 /* CS AMP support */ 172 int sof_sdw_cs_amp_init(struct snd_soc_card *card, 173 struct snd_soc_dai_link *dai_links, 174 struct sof_sdw_codec_info *info, 175 bool playback); 176 177 /* dai_link init callbacks */ 178 179 int cs42l42_rtd_init(struct snd_soc_pcm_runtime *rtd); 180 int cs42l43_hs_rtd_init(struct snd_soc_pcm_runtime *rtd); 181 int cs42l43_spk_rtd_init(struct snd_soc_pcm_runtime *rtd); 182 int cs42l43_dmic_rtd_init(struct snd_soc_pcm_runtime *rtd); 183 int cs_spk_rtd_init(struct snd_soc_pcm_runtime *rtd); 184 int maxim_spk_rtd_init(struct snd_soc_pcm_runtime *rtd); 185 int rt5682_rtd_init(struct snd_soc_pcm_runtime *rtd); 186 int rt700_rtd_init(struct snd_soc_pcm_runtime *rtd); 187 int rt711_rtd_init(struct snd_soc_pcm_runtime *rtd); 188 int rt712_spk_rtd_init(struct snd_soc_pcm_runtime *rtd); 189 int rt722_spk_rtd_init(struct snd_soc_pcm_runtime *rtd); 190 int rt_dmic_rtd_init(struct snd_soc_pcm_runtime *rtd); 191 int rt_amp_spk_rtd_init(struct snd_soc_pcm_runtime *rtd); 192 int rt_sdca_jack_rtd_init(struct snd_soc_pcm_runtime *rtd); 193 194 #endif 195