Saurabh Satija | 734aa87 | 2016-06-21 14:22:16 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2016 Intel Corp. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; either version 2 of the License, or |
| 9 | * (at your option) any later version. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | */ |
| 16 | |
| 17 | #include <console/console.h> |
| 18 | #include <nhlt.h> |
| 19 | #include <soc/nhlt.h> |
| 20 | |
Sathyanarayana Nujella | 3e0a3fb | 2016-10-26 17:31:36 -0700 | [diff] [blame] | 21 | static const struct nhlt_format_config dmic_1ch_formats[] = { |
| 22 | /* 48 KHz 16-bits per sample. */ |
| 23 | { |
| 24 | .num_channels = 1, |
| 25 | .sample_freq_khz = 48, |
| 26 | .container_bits_per_sample = 16, |
| 27 | .valid_bits_per_sample = 16, |
| 28 | .settings_file = "dmic-1ch-48khz-16b.bin", |
| 29 | }, |
| 30 | }; |
| 31 | |
| 32 | static const struct nhlt_dmic_array_config dmic_1ch_mic_config = { |
| 33 | .tdm_config = { |
| 34 | .config_type = NHLT_TDM_MIC_ARRAY, |
| 35 | }, |
| 36 | .array_type = NHLT_MIC_ARRAY_VENDOR_DEFINED, |
| 37 | }; |
| 38 | |
| 39 | static const struct nhlt_endp_descriptor dmic_1ch_descriptors[] = { |
| 40 | { |
| 41 | .link = NHLT_LINK_PDM, |
| 42 | .device = NHLT_PDM_DEV, |
| 43 | .direction = NHLT_DIR_CAPTURE, |
| 44 | .vid = NHLT_VID, |
| 45 | .did = NHLT_DID_DMIC, |
| 46 | .cfg = &dmic_1ch_mic_config, |
| 47 | .cfg_size = sizeof(dmic_1ch_mic_config), |
| 48 | .formats = dmic_1ch_formats, |
| 49 | .num_formats = ARRAY_SIZE(dmic_1ch_formats), |
| 50 | }, |
| 51 | }; |
| 52 | |
Saurabh Satija | 734aa87 | 2016-06-21 14:22:16 -0700 | [diff] [blame] | 53 | static const struct nhlt_format_config dmic_2ch_formats[] = { |
| 54 | /* 48 KHz 16-bits per sample. */ |
| 55 | { |
| 56 | .num_channels = 2, |
| 57 | .sample_freq_khz = 48, |
| 58 | .container_bits_per_sample = 16, |
| 59 | .valid_bits_per_sample = 16, |
| 60 | .settings_file = "dmic-2ch-48khz-16b.bin", |
| 61 | }, |
| 62 | }; |
| 63 | |
| 64 | static const struct nhlt_dmic_array_config dmic_2ch_mic_config = { |
| 65 | .tdm_config = { |
| 66 | .config_type = NHLT_TDM_MIC_ARRAY, |
| 67 | }, |
| 68 | .array_type = NHLT_MIC_ARRAY_2CH_SMALL, |
| 69 | }; |
| 70 | |
| 71 | static const struct nhlt_endp_descriptor dmic_2ch_descriptors[] = { |
| 72 | { |
| 73 | .link = NHLT_LINK_PDM, |
| 74 | .device = NHLT_PDM_DEV, |
| 75 | .direction = NHLT_DIR_CAPTURE, |
| 76 | .vid = NHLT_VID, |
| 77 | .did = NHLT_DID_DMIC, |
| 78 | .cfg = &dmic_2ch_mic_config, |
| 79 | .cfg_size = sizeof(dmic_2ch_mic_config), |
| 80 | .formats = dmic_2ch_formats, |
| 81 | .num_formats = ARRAY_SIZE(dmic_2ch_formats), |
| 82 | }, |
| 83 | }; |
| 84 | |
Sathyanarayana Nujella | 3e0a3fb | 2016-10-26 17:31:36 -0700 | [diff] [blame] | 85 | static const struct nhlt_format_config dmic_4ch_formats[] = { |
| 86 | /* 48 KHz 16-bits per sample. */ |
| 87 | { |
| 88 | .num_channels = 4, |
| 89 | .sample_freq_khz = 48, |
| 90 | .container_bits_per_sample = 16, |
| 91 | .valid_bits_per_sample = 16, |
| 92 | .settings_file = "dmic-4ch-48khz-16b.bin", |
| 93 | }, |
| 94 | }; |
| 95 | |
| 96 | static const struct nhlt_dmic_array_config dmic_4ch_mic_config = { |
| 97 | .tdm_config = { |
| 98 | .config_type = NHLT_TDM_MIC_ARRAY, |
| 99 | }, |
| 100 | .array_type = NHLT_MIC_ARRAY_4CH_L_SHAPED, |
| 101 | }; |
| 102 | |
| 103 | static const struct nhlt_endp_descriptor dmic_4ch_descriptors[] = { |
| 104 | { |
| 105 | .link = NHLT_LINK_PDM, |
| 106 | .device = NHLT_PDM_DEV, |
| 107 | .direction = NHLT_DIR_CAPTURE, |
| 108 | .vid = NHLT_VID, |
| 109 | .did = NHLT_DID_DMIC, |
| 110 | .cfg = &dmic_4ch_mic_config, |
| 111 | .cfg_size = sizeof(dmic_4ch_mic_config), |
| 112 | .formats = dmic_4ch_formats, |
| 113 | .num_formats = ARRAY_SIZE(dmic_4ch_formats), |
| 114 | }, |
| 115 | }; |
| 116 | |
Saurabh Satija | 734aa87 | 2016-06-21 14:22:16 -0700 | [diff] [blame] | 117 | static const struct nhlt_format_config da7219_formats[] = { |
| 118 | /* 48 KHz 24-bits per sample. */ |
| 119 | { |
| 120 | .num_channels = 2, |
| 121 | .sample_freq_khz = 48, |
| 122 | .container_bits_per_sample = 32, |
| 123 | .valid_bits_per_sample = 24, |
| 124 | .settings_file = "dialog-2ch-48khz-24b.bin", |
| 125 | }, |
| 126 | }; |
| 127 | |
| 128 | static const struct nhlt_tdm_config tdm_config = { |
| 129 | .virtual_slot = 0, |
| 130 | .config_type = NHLT_TDM_BASIC, |
| 131 | }; |
| 132 | |
| 133 | static const struct nhlt_endp_descriptor da7219_descriptors[] = { |
| 134 | /* Render Endpoint */ |
| 135 | { |
| 136 | .link = NHLT_LINK_SSP, |
| 137 | .device = NHLT_SSP_DEV_I2S, |
| 138 | .direction = NHLT_DIR_RENDER, |
| 139 | .vid = NHLT_VID, |
| 140 | .did = NHLT_DID_SSP, |
| 141 | .cfg = &tdm_config, |
| 142 | .cfg_size = sizeof(tdm_config), |
| 143 | .formats = da7219_formats, |
| 144 | .num_formats = ARRAY_SIZE(da7219_formats), |
| 145 | }, |
| 146 | /* Capture Endpoint */ |
| 147 | { |
| 148 | .link = NHLT_LINK_SSP, |
| 149 | .device = NHLT_SSP_DEV_I2S, |
| 150 | .direction = NHLT_DIR_CAPTURE, |
| 151 | .vid = NHLT_VID, |
| 152 | .did = NHLT_DID_SSP, |
| 153 | .cfg = &tdm_config, |
| 154 | .cfg_size = sizeof(tdm_config), |
| 155 | .formats = da7219_formats, |
| 156 | .num_formats = ARRAY_SIZE(da7219_formats), |
| 157 | }, |
| 158 | }; |
| 159 | |
| 160 | static const struct nhlt_format_config max98357_formats[] = { |
| 161 | /* 48 KHz 24-bits per sample. */ |
| 162 | { |
| 163 | .num_channels = 2, |
| 164 | .sample_freq_khz = 48, |
| 165 | .container_bits_per_sample = 32, |
| 166 | .valid_bits_per_sample = 24, |
| 167 | .settings_file = "max98357-render-2ch-48khz-24b.bin", |
| 168 | }, |
| 169 | }; |
| 170 | |
| 171 | static const struct nhlt_endp_descriptor max98357_descriptors[] = { |
| 172 | { |
| 173 | .link = NHLT_LINK_SSP, |
| 174 | .device = NHLT_SSP_DEV_I2S, |
| 175 | .direction = NHLT_DIR_RENDER, |
| 176 | .vid = NHLT_VID, |
| 177 | .did = NHLT_DID_SSP, |
| 178 | .formats = max98357_formats, |
| 179 | .num_formats = ARRAY_SIZE(max98357_formats), |
| 180 | }, |
| 181 | }; |
| 182 | |
| 183 | int nhlt_soc_add_dmic_array(struct nhlt *nhlt, int num_channels) |
| 184 | { |
Sathyanarayana Nujella | 3e0a3fb | 2016-10-26 17:31:36 -0700 | [diff] [blame] | 185 | switch (num_channels) { |
Lee Leahy | a444753 | 2017-03-09 10:45:02 -0800 | [diff] [blame] | 186 | case 1: |
| 187 | return nhlt_add_endpoints(nhlt, dmic_1ch_descriptors, |
| 188 | ARRAY_SIZE(dmic_1ch_descriptors)); |
| 189 | case 2: |
| 190 | return nhlt_add_endpoints(nhlt, dmic_2ch_descriptors, |
| 191 | ARRAY_SIZE(dmic_2ch_descriptors)); |
| 192 | case 4: |
| 193 | return nhlt_add_endpoints(nhlt, dmic_4ch_descriptors, |
| 194 | ARRAY_SIZE(dmic_4ch_descriptors)); |
| 195 | default: |
| 196 | return -1; |
Sathyanarayana Nujella | 3e0a3fb | 2016-10-26 17:31:36 -0700 | [diff] [blame] | 197 | } |
Saurabh Satija | 734aa87 | 2016-06-21 14:22:16 -0700 | [diff] [blame] | 198 | } |
| 199 | |
Naveen Manohar | 532b8d5 | 2018-04-27 15:24:45 +0530 | [diff] [blame^] | 200 | /* |
| 201 | * The same DSP firmware settings are used for both the capture and |
| 202 | * render endpoints. |
| 203 | */ |
| 204 | static const struct nhlt_format_config rt5682_formats[] = { |
| 205 | /* 48 KHz 24-bits per sample. */ |
| 206 | { |
| 207 | .num_channels = 2, |
| 208 | .sample_freq_khz = 48, |
| 209 | .container_bits_per_sample = 32, |
| 210 | .valid_bits_per_sample = 24, |
| 211 | .speaker_mask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT, |
| 212 | .settings_file = "rt5682-2ch-48khz-24b.bin", |
| 213 | }, |
| 214 | }; |
| 215 | |
| 216 | /* |
| 217 | * The rt5682 just has headphones and a mic. Both the capture and render |
| 218 | * endpoints occupy the same virtual slot. |
| 219 | */ |
| 220 | static const struct nhlt_endp_descriptor rt5682_descriptors[] = { |
| 221 | /* Render Endpoint */ |
| 222 | { |
| 223 | .link = NHLT_LINK_SSP, |
| 224 | .device = NHLT_SSP_DEV_I2S, |
| 225 | .direction = NHLT_DIR_RENDER, |
| 226 | .vid = NHLT_VID, |
| 227 | .did = NHLT_DID_SSP, |
| 228 | .cfg = &tdm_config, |
| 229 | .cfg_size = sizeof(tdm_config), |
| 230 | .formats = rt5682_formats, |
| 231 | .num_formats = ARRAY_SIZE(rt5682_formats), |
| 232 | }, |
| 233 | /* Capture Endpoint */ |
| 234 | { |
| 235 | .link = NHLT_LINK_SSP, |
| 236 | .device = NHLT_SSP_DEV_I2S, |
| 237 | .direction = NHLT_DIR_CAPTURE, |
| 238 | .vid = NHLT_VID, |
| 239 | .did = NHLT_DID_SSP, |
| 240 | .cfg = &tdm_config, |
| 241 | .cfg_size = sizeof(tdm_config), |
| 242 | .formats = rt5682_formats, |
| 243 | .num_formats = ARRAY_SIZE(rt5682_formats), |
| 244 | }, |
| 245 | }; |
| 246 | |
Saurabh Satija | 734aa87 | 2016-06-21 14:22:16 -0700 | [diff] [blame] | 247 | int nhlt_soc_add_da7219(struct nhlt *nhlt, int hwlink) |
| 248 | { |
| 249 | /* Virtual bus id of SSP links are the hardware port ids proper. */ |
| 250 | return nhlt_add_ssp_endpoints(nhlt, hwlink, da7219_descriptors, |
| 251 | ARRAY_SIZE(da7219_descriptors)); |
| 252 | } |
| 253 | |
| 254 | int nhlt_soc_add_max98357(struct nhlt *nhlt, int hwlink) |
| 255 | { |
| 256 | /* Virtual bus id of SSP links are the hardware port ids proper. */ |
| 257 | return nhlt_add_ssp_endpoints(nhlt, hwlink, max98357_descriptors, |
| 258 | ARRAY_SIZE(max98357_descriptors)); |
| 259 | } |
Naveen Manohar | 532b8d5 | 2018-04-27 15:24:45 +0530 | [diff] [blame^] | 260 | |
| 261 | int nhlt_soc_add_rt5682(struct nhlt *nhlt, int hwlink) |
| 262 | { |
| 263 | /* Virtual bus id of SSP links are the hardware port ids proper. */ |
| 264 | return nhlt_add_ssp_endpoints(nhlt, hwlink, rt5682_descriptors, |
| 265 | ARRAY_SIZE(rt5682_descriptors)); |
| 266 | } |