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