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 #define SOF_SDW_NO_AGGREGATION BIT(14) 54 55 /* BT audio offload: reserve 3 bits for future */ 56 #define SOF_BT_OFFLOAD_SSP_SHIFT 15 57 #define SOF_BT_OFFLOAD_SSP_MASK (GENMASK(17, 15)) 58 #define SOF_BT_OFFLOAD_SSP(quirk) \ 59 (((quirk) << SOF_BT_OFFLOAD_SSP_SHIFT) & SOF_BT_OFFLOAD_SSP_MASK) 60 #define SOF_SSP_BT_OFFLOAD_PRESENT BIT(18) 61 62 #define SOF_SDW_DAI_TYPE_JACK 0 63 #define SOF_SDW_DAI_TYPE_AMP 1 64 #define SOF_SDW_DAI_TYPE_MIC 2 65 66 #define SOF_SDW_MAX_DAI_NUM 3 67 68 struct sof_sdw_codec_info; 69 70 struct sof_sdw_dai_info { 71 const bool direction[2]; /* playback & capture support */ 72 const char *dai_name; 73 const int dai_type; 74 const int dailink[2]; /* dailink id for each direction */ 75 int (*init)(struct snd_soc_card *card, 76 const struct snd_soc_acpi_link_adr *link, 77 struct snd_soc_dai_link *dai_links, 78 struct sof_sdw_codec_info *info, 79 bool playback); 80 int (*exit)(struct snd_soc_card *card, struct snd_soc_dai_link *dai_link); 81 }; 82 83 struct sof_sdw_codec_info { 84 const int part_id; 85 const int version_id; 86 const char *codec_name; 87 int amp_num; 88 const u8 acpi_id[ACPI_ID_LEN]; 89 const bool ignore_pch_dmic; 90 const struct snd_soc_ops *ops; 91 struct sof_sdw_dai_info dais[SOF_SDW_MAX_DAI_NUM]; 92 const int dai_num; 93 94 int (*codec_card_late_probe)(struct snd_soc_card *card); 95 }; 96 97 struct mc_private { 98 struct snd_soc_jack sdw_headset; 99 struct sof_hdmi_private hdmi; 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_spk_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_dmic_init(struct snd_soc_card *card, 147 const struct snd_soc_acpi_link_adr *link, 148 struct snd_soc_dai_link *dai_links, 149 struct sof_sdw_codec_info *info, 150 bool playback); 151 152 /* RT700 support */ 153 int sof_sdw_rt700_init(struct snd_soc_card *card, 154 const struct snd_soc_acpi_link_adr *link, 155 struct snd_soc_dai_link *dai_links, 156 struct sof_sdw_codec_info *info, 157 bool playback); 158 159 /* RT1308 I2S support */ 160 extern struct snd_soc_ops sof_sdw_rt1308_i2s_ops; 161 162 /* generic amp support */ 163 int sof_sdw_rt_amp_init(struct snd_soc_card *card, 164 const struct snd_soc_acpi_link_adr *link, 165 struct snd_soc_dai_link *dai_links, 166 struct sof_sdw_codec_info *info, 167 bool playback); 168 int sof_sdw_rt_amp_exit(struct snd_soc_card *card, struct snd_soc_dai_link *dai_link); 169 170 /* RT1316 support */ 171 172 /* RT715 support */ 173 int sof_sdw_rt715_init(struct snd_soc_card *card, 174 const struct snd_soc_acpi_link_adr *link, 175 struct snd_soc_dai_link *dai_links, 176 struct sof_sdw_codec_info *info, 177 bool playback); 178 179 /* RT715-SDCA support */ 180 int sof_sdw_rt715_sdca_init(struct snd_soc_card *card, 181 const struct snd_soc_acpi_link_adr *link, 182 struct snd_soc_dai_link *dai_links, 183 struct sof_sdw_codec_info *info, 184 bool playback); 185 186 /* RT722-SDCA support */ 187 int sof_sdw_rt722_spk_init(struct snd_soc_card *card, 188 const struct snd_soc_acpi_link_adr *link, 189 struct snd_soc_dai_link *dai_links, 190 struct sof_sdw_codec_info *info, 191 bool playback); 192 int sof_sdw_rt722_sdca_dmic_init(struct snd_soc_card *card, 193 const struct snd_soc_acpi_link_adr *link, 194 struct snd_soc_dai_link *dai_links, 195 struct sof_sdw_codec_info *info, 196 bool playback); 197 198 /* MAXIM codec support */ 199 int sof_sdw_maxim_init(struct snd_soc_card *card, 200 const struct snd_soc_acpi_link_adr *link, 201 struct snd_soc_dai_link *dai_links, 202 struct sof_sdw_codec_info *info, 203 bool playback); 204 205 /* RT5682 support */ 206 int sof_sdw_rt5682_init(struct snd_soc_card *card, 207 const struct snd_soc_acpi_link_adr *link, 208 struct snd_soc_dai_link *dai_links, 209 struct sof_sdw_codec_info *info, 210 bool playback); 211 212 /* CS42L42 support */ 213 int sof_sdw_cs42l42_init(struct snd_soc_card *card, 214 const struct snd_soc_acpi_link_adr *link, 215 struct snd_soc_dai_link *dai_links, 216 struct sof_sdw_codec_info *info, 217 bool playback); 218 219 /* CS42L43 support */ 220 int sof_sdw_cs42l43_hs_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 int sof_sdw_cs42l43_dmic_init(struct snd_soc_card *card, 227 const struct snd_soc_acpi_link_adr *link, 228 struct snd_soc_dai_link *dai_links, 229 struct sof_sdw_codec_info *info, 230 bool playback); 231 232 /* CS AMP support */ 233 int sof_sdw_cs_amp_init(struct snd_soc_card *card, 234 const struct snd_soc_acpi_link_adr *link, 235 struct snd_soc_dai_link *dai_links, 236 struct sof_sdw_codec_info *info, 237 bool playback); 238 #endif 239