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 16 #define MAX_NO_PROPS 2 17 #define MAX_HDMI_NUM 4 18 #define SDW_UNUSED_DAI_ID -1 19 #define SDW_JACK_OUT_DAI_ID 0 20 #define SDW_JACK_IN_DAI_ID 1 21 #define SDW_AMP_OUT_DAI_ID 2 22 #define SDW_AMP_IN_DAI_ID 3 23 #define SDW_DMIC_DAI_ID 4 24 #define SDW_MAX_CPU_DAIS 16 25 #define SDW_INTEL_BIDIR_PDI_BASE 2 26 27 #define SDW_MAX_LINKS 4 28 29 /* 8 combinations with 4 links + unused group 0 */ 30 #define SDW_MAX_GROUPS 9 31 32 enum { 33 SOF_PRE_TGL_HDMI_COUNT = 3, 34 SOF_TGL_HDMI_COUNT = 4, 35 }; 36 37 enum { 38 SOF_I2S_SSP0 = BIT(0), 39 SOF_I2S_SSP1 = BIT(1), 40 SOF_I2S_SSP2 = BIT(2), 41 SOF_I2S_SSP3 = BIT(3), 42 SOF_I2S_SSP4 = BIT(4), 43 SOF_I2S_SSP5 = BIT(5), 44 }; 45 46 #define SOF_JACK_JDSRC(quirk) ((quirk) & GENMASK(3, 0)) 47 #define SOF_SDW_FOUR_SPK BIT(4) 48 #define SOF_SDW_TGL_HDMI BIT(5) 49 #define SOF_SDW_PCH_DMIC BIT(6) 50 #define SOF_SSP_PORT(x) (((x) & GENMASK(5, 0)) << 7) 51 #define SOF_SSP_GET_PORT(quirk) (((quirk) >> 7) & GENMASK(5, 0)) 52 #define SOF_SDW_NO_AGGREGATION BIT(14) 53 54 /* BT audio offload: reserve 3 bits for future */ 55 #define SOF_BT_OFFLOAD_SSP_SHIFT 15 56 #define SOF_BT_OFFLOAD_SSP_MASK (GENMASK(17, 15)) 57 #define SOF_BT_OFFLOAD_SSP(quirk) \ 58 (((quirk) << SOF_BT_OFFLOAD_SSP_SHIFT) & SOF_BT_OFFLOAD_SSP_MASK) 59 #define SOF_SSP_BT_OFFLOAD_PRESENT BIT(18) 60 61 #define SOF_SDW_DAI_TYPE_JACK 0 62 #define SOF_SDW_DAI_TYPE_AMP 1 63 #define SOF_SDW_DAI_TYPE_MIC 2 64 65 #define SOF_SDW_MAX_DAI_NUM 3 66 67 struct sof_sdw_codec_info; 68 69 struct sof_sdw_dai_info { 70 const bool direction[2]; /* playback & capture support */ 71 const char *dai_name; 72 const int dai_type; 73 const int dailink[2]; /* dailink id for each direction */ 74 int (*init)(struct snd_soc_card *card, 75 const struct snd_soc_acpi_link_adr *link, 76 struct snd_soc_dai_link *dai_links, 77 struct sof_sdw_codec_info *info, 78 bool playback); 79 int (*exit)(struct snd_soc_card *card, struct snd_soc_dai_link *dai_link); 80 }; 81 82 struct sof_sdw_codec_info { 83 const int part_id; 84 const int version_id; 85 const char *codec_name; 86 int amp_num; 87 const u8 acpi_id[ACPI_ID_LEN]; 88 const bool ignore_pch_dmic; 89 const struct snd_soc_ops *ops; 90 struct sof_sdw_dai_info dais[SOF_SDW_MAX_DAI_NUM]; 91 const int dai_num; 92 93 int (*codec_card_late_probe)(struct snd_soc_card *card); 94 }; 95 96 struct mc_private { 97 struct list_head hdmi_pcm_list; 98 bool idisp_codec; 99 struct snd_soc_jack sdw_headset; 100 struct device *headset_codec_dev; /* only one headset per card */ 101 struct device *amp_dev1, *amp_dev2; 102 /* To store SDW Pin index for each SoundWire link */ 103 unsigned int sdw_pin_index[SDW_MAX_LINKS]; 104 }; 105 106 extern unsigned long sof_sdw_quirk; 107 108 int sdw_startup(struct snd_pcm_substream *substream); 109 int sdw_prepare(struct snd_pcm_substream *substream); 110 int sdw_trigger(struct snd_pcm_substream *substream, int cmd); 111 int sdw_hw_params(struct snd_pcm_substream *substream, 112 struct snd_pcm_hw_params *params); 113 int sdw_hw_free(struct snd_pcm_substream *substream); 114 void sdw_shutdown(struct snd_pcm_substream *substream); 115 116 /* generic HDMI support */ 117 int sof_sdw_hdmi_init(struct snd_soc_pcm_runtime *rtd); 118 119 int sof_sdw_hdmi_card_late_probe(struct snd_soc_card *card); 120 121 /* DMIC support */ 122 int sof_sdw_dmic_init(struct snd_soc_pcm_runtime *rtd); 123 124 /* RT711 support */ 125 int sof_sdw_rt711_init(struct snd_soc_card *card, 126 const struct snd_soc_acpi_link_adr *link, 127 struct snd_soc_dai_link *dai_links, 128 struct sof_sdw_codec_info *info, 129 bool playback); 130 int sof_sdw_rt711_exit(struct snd_soc_card *card, struct snd_soc_dai_link *dai_link); 131 132 /* RT711-SDCA support */ 133 int sof_sdw_rt_sdca_jack_init(struct snd_soc_card *card, 134 const struct snd_soc_acpi_link_adr *link, 135 struct snd_soc_dai_link *dai_links, 136 struct sof_sdw_codec_info *info, 137 bool playback); 138 int sof_sdw_rt_sdca_jack_exit(struct snd_soc_card *card, struct snd_soc_dai_link *dai_link); 139 140 /* RT712-SDCA support */ 141 int sof_sdw_rt712_sdca_init(struct snd_soc_card *card, 142 const struct snd_soc_acpi_link_adr *link, 143 struct snd_soc_dai_link *dai_links, 144 struct sof_sdw_codec_info *info, 145 bool playback); 146 int sof_sdw_rt712_sdca_exit(struct snd_soc_card *card, struct snd_soc_dai_link *dai_link); 147 int sof_sdw_rt712_spk_init(struct snd_soc_card *card, 148 const struct snd_soc_acpi_link_adr *link, 149 struct snd_soc_dai_link *dai_links, 150 struct sof_sdw_codec_info *info, 151 bool playback); 152 int sof_sdw_rt712_sdca_dmic_init(struct snd_soc_card *card, 153 const struct snd_soc_acpi_link_adr *link, 154 struct snd_soc_dai_link *dai_links, 155 struct sof_sdw_codec_info *info, 156 bool playback); 157 158 /* RT700 support */ 159 int sof_sdw_rt700_init(struct snd_soc_card *card, 160 const struct snd_soc_acpi_link_adr *link, 161 struct snd_soc_dai_link *dai_links, 162 struct sof_sdw_codec_info *info, 163 bool playback); 164 165 /* RT1308 I2S support */ 166 extern struct snd_soc_ops sof_sdw_rt1308_i2s_ops; 167 168 /* generic amp support */ 169 int sof_sdw_rt_amp_init(struct snd_soc_card *card, 170 const struct snd_soc_acpi_link_adr *link, 171 struct snd_soc_dai_link *dai_links, 172 struct sof_sdw_codec_info *info, 173 bool playback); 174 int sof_sdw_rt_amp_exit(struct snd_soc_card *card, struct snd_soc_dai_link *dai_link); 175 176 /* RT1316 support */ 177 178 /* RT715 support */ 179 int sof_sdw_rt715_init(struct snd_soc_card *card, 180 const struct snd_soc_acpi_link_adr *link, 181 struct snd_soc_dai_link *dai_links, 182 struct sof_sdw_codec_info *info, 183 bool playback); 184 185 /* RT715-SDCA support */ 186 int sof_sdw_rt715_sdca_init(struct snd_soc_card *card, 187 const struct snd_soc_acpi_link_adr *link, 188 struct snd_soc_dai_link *dai_links, 189 struct sof_sdw_codec_info *info, 190 bool playback); 191 192 /* MAXIM codec support */ 193 int sof_sdw_maxim_init(struct snd_soc_card *card, 194 const struct snd_soc_acpi_link_adr *link, 195 struct snd_soc_dai_link *dai_links, 196 struct sof_sdw_codec_info *info, 197 bool playback); 198 199 /* RT5682 support */ 200 int sof_sdw_rt5682_init(struct snd_soc_card *card, 201 const struct snd_soc_acpi_link_adr *link, 202 struct snd_soc_dai_link *dai_links, 203 struct sof_sdw_codec_info *info, 204 bool playback); 205 206 /* CS42L42 support */ 207 int sof_sdw_cs42l42_init(struct snd_soc_card *card, 208 const struct snd_soc_acpi_link_adr *link, 209 struct snd_soc_dai_link *dai_links, 210 struct sof_sdw_codec_info *info, 211 bool playback); 212 213 /* CS42L43 support */ 214 int sof_sdw_cs42l43_hs_init(struct snd_soc_card *card, 215 const struct snd_soc_acpi_link_adr *link, 216 struct snd_soc_dai_link *dai_links, 217 struct sof_sdw_codec_info *info, 218 bool playback); 219 220 int sof_sdw_cs42l43_dmic_init(struct snd_soc_card *card, 221 const struct snd_soc_acpi_link_adr *link, 222 struct snd_soc_dai_link *dai_links, 223 struct sof_sdw_codec_info *info, 224 bool playback); 225 226 /* CS AMP support */ 227 int sof_sdw_cs_amp_init(struct snd_soc_card *card, 228 const struct snd_soc_acpi_link_adr *link, 229 struct snd_soc_dai_link *dai_links, 230 struct sof_sdw_codec_info *info, 231 bool playback); 232 #endif 233