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 /* Deprecated and no longer supported by the code */ 49 #define SOF_SDW_FOUR_SPK BIT(4) 50 #define SOF_SDW_TGL_HDMI BIT(5) 51 #define SOF_SDW_PCH_DMIC BIT(6) 52 #define SOF_SSP_PORT(x) (((x) & GENMASK(5, 0)) << 7) 53 #define SOF_SSP_GET_PORT(quirk) (((quirk) >> 7) & GENMASK(5, 0)) 54 /* Deprecated and no longer supported by the code */ 55 #define SOF_SDW_NO_AGGREGATION BIT(14) 56 /* If a CODEC has an optional speaker output, this quirk will enable it */ 57 #define SOF_CODEC_SPKR BIT(15) 58 59 /* BT audio offload: reserve 3 bits for future */ 60 #define SOF_BT_OFFLOAD_SSP_SHIFT 15 61 #define SOF_BT_OFFLOAD_SSP_MASK (GENMASK(17, 15)) 62 #define SOF_BT_OFFLOAD_SSP(quirk) \ 63 (((quirk) << SOF_BT_OFFLOAD_SSP_SHIFT) & SOF_BT_OFFLOAD_SSP_MASK) 64 #define SOF_SSP_BT_OFFLOAD_PRESENT BIT(18) 65 66 #define SOF_SDW_DAI_TYPE_JACK 0 67 #define SOF_SDW_DAI_TYPE_AMP 1 68 #define SOF_SDW_DAI_TYPE_MIC 2 69 70 #define SOF_SDW_MAX_DAI_NUM 8 71 72 struct sof_sdw_codec_info; 73 74 struct sof_sdw_dai_info { 75 const bool direction[2]; /* playback & capture support */ 76 const char *dai_name; 77 const int dai_type; 78 const int dailink[2]; /* dailink id for each direction */ 79 int (*init)(struct snd_soc_card *card, 80 struct snd_soc_dai_link *dai_links, 81 struct sof_sdw_codec_info *info, 82 bool playback); 83 int (*exit)(struct snd_soc_card *card, struct snd_soc_dai_link *dai_link); 84 int (*rtd_init)(struct snd_soc_pcm_runtime *rtd); 85 bool rtd_init_done; /* Indicate that the rtd_init callback is done */ 86 unsigned long quirk; 87 }; 88 89 struct sof_sdw_codec_info { 90 const int part_id; 91 const int version_id; 92 const char *codec_name; 93 int amp_num; 94 const u8 acpi_id[ACPI_ID_LEN]; 95 const bool ignore_pch_dmic; 96 const struct snd_soc_ops *ops; 97 struct sof_sdw_dai_info dais[SOF_SDW_MAX_DAI_NUM]; 98 const int dai_num; 99 100 int (*codec_card_late_probe)(struct snd_soc_card *card); 101 }; 102 103 struct mc_private { 104 struct snd_soc_jack sdw_headset; 105 struct sof_hdmi_private hdmi; 106 struct device *headset_codec_dev; /* only one headset per card */ 107 struct device *amp_dev1, *amp_dev2; 108 /* To store SDW Pin index for each SoundWire link */ 109 unsigned int sdw_pin_index[SDW_MAX_LINKS]; 110 bool append_dai_type; 111 bool ignore_pch_dmic; 112 }; 113 114 extern unsigned long sof_sdw_quirk; 115 116 struct snd_soc_dai *get_codec_dai_by_name(struct snd_soc_pcm_runtime *rtd, 117 const char * const dai_name[], 118 int num_dais); 119 120 int sdw_startup(struct snd_pcm_substream *substream); 121 int sdw_prepare(struct snd_pcm_substream *substream); 122 int sdw_trigger(struct snd_pcm_substream *substream, int cmd); 123 int sdw_hw_params(struct snd_pcm_substream *substream, 124 struct snd_pcm_hw_params *params); 125 int sdw_hw_free(struct snd_pcm_substream *substream); 126 void sdw_shutdown(struct snd_pcm_substream *substream); 127 128 /* generic HDMI support */ 129 int sof_sdw_hdmi_init(struct snd_soc_pcm_runtime *rtd); 130 131 int sof_sdw_hdmi_card_late_probe(struct snd_soc_card *card); 132 133 /* DMIC support */ 134 int sof_sdw_dmic_init(struct snd_soc_pcm_runtime *rtd); 135 136 /* RT711 support */ 137 int sof_sdw_rt711_init(struct snd_soc_card *card, 138 struct snd_soc_dai_link *dai_links, 139 struct sof_sdw_codec_info *info, 140 bool playback); 141 int sof_sdw_rt711_exit(struct snd_soc_card *card, struct snd_soc_dai_link *dai_link); 142 143 /* RT711-SDCA support */ 144 int sof_sdw_rt_sdca_jack_init(struct snd_soc_card *card, 145 struct snd_soc_dai_link *dai_links, 146 struct sof_sdw_codec_info *info, 147 bool playback); 148 int sof_sdw_rt_sdca_jack_exit(struct snd_soc_card *card, struct snd_soc_dai_link *dai_link); 149 150 /* RT1308 I2S support */ 151 extern struct snd_soc_ops sof_sdw_rt1308_i2s_ops; 152 153 /* generic amp support */ 154 int sof_sdw_rt_amp_init(struct snd_soc_card *card, 155 struct snd_soc_dai_link *dai_links, 156 struct sof_sdw_codec_info *info, 157 bool playback); 158 int sof_sdw_rt_amp_exit(struct snd_soc_card *card, struct snd_soc_dai_link *dai_link); 159 160 /* MAXIM codec support */ 161 int sof_sdw_maxim_init(struct snd_soc_card *card, 162 struct snd_soc_dai_link *dai_links, 163 struct sof_sdw_codec_info *info, 164 bool playback); 165 166 /* CS42L43 support */ 167 int sof_sdw_cs42l43_spk_init(struct snd_soc_card *card, 168 struct snd_soc_dai_link *dai_links, 169 struct sof_sdw_codec_info *info, 170 bool playback); 171 172 /* CS AMP support */ 173 int sof_sdw_cs_amp_init(struct snd_soc_card *card, 174 struct snd_soc_dai_link *dai_links, 175 struct sof_sdw_codec_info *info, 176 bool playback); 177 178 /* dai_link init callbacks */ 179 180 int cs42l42_rtd_init(struct snd_soc_pcm_runtime *rtd); 181 int cs42l43_hs_rtd_init(struct snd_soc_pcm_runtime *rtd); 182 int cs42l43_spk_rtd_init(struct snd_soc_pcm_runtime *rtd); 183 int cs42l43_dmic_rtd_init(struct snd_soc_pcm_runtime *rtd); 184 int cs_spk_rtd_init(struct snd_soc_pcm_runtime *rtd); 185 int maxim_spk_rtd_init(struct snd_soc_pcm_runtime *rtd); 186 int rt5682_rtd_init(struct snd_soc_pcm_runtime *rtd); 187 int rt700_rtd_init(struct snd_soc_pcm_runtime *rtd); 188 int rt711_rtd_init(struct snd_soc_pcm_runtime *rtd); 189 int rt712_spk_rtd_init(struct snd_soc_pcm_runtime *rtd); 190 int rt722_spk_rtd_init(struct snd_soc_pcm_runtime *rtd); 191 int rt_dmic_rtd_init(struct snd_soc_pcm_runtime *rtd); 192 int rt_amp_spk_rtd_init(struct snd_soc_pcm_runtime *rtd); 193 int rt_sdca_jack_rtd_init(struct snd_soc_pcm_runtime *rtd); 194 195 #endif 196