coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
nhlt.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2 
3 #include <nhlt.h>
4 #include <soc/nhlt.h>
5 
6 static const struct nhlt_format_config dmic_1ch_formats[] = {
7  /* 48 KHz 16-bits per sample. */
8  {
9  .num_channels = 1,
10  .sample_freq_khz = 48,
11  .container_bits_per_sample = 16,
12  .valid_bits_per_sample = 16,
13  .settings_file = "dmic-1ch-48khz-16b.bin",
14  },
15 };
16 
17 static const struct nhlt_dmic_array_config dmic_1ch_mic_config = {
18  .tdm_config = {
20  },
21  .array_type = NHLT_MIC_ARRAY_VENDOR_DEFINED,
22 };
23 
24 static const struct nhlt_endp_descriptor dmic_1ch_descriptors[] = {
25  {
27  .device = NHLT_PDM_DEV,
28  .direction = NHLT_DIR_CAPTURE,
29  .vid = NHLT_VID,
30  .did = NHLT_DID_DMIC,
31  .cfg = &dmic_1ch_mic_config,
32  .cfg_size = sizeof(dmic_1ch_mic_config),
35  },
36 };
37 
38 static const struct nhlt_format_config dmic_2ch_formats[] = {
39  /* 48 KHz 16-bits per sample. */
40  {
41  .num_channels = 2,
42  .sample_freq_khz = 48,
43  .container_bits_per_sample = 16,
44  .valid_bits_per_sample = 16,
45  .settings_file = "dmic-2ch-48khz-16b.bin",
46  },
47 };
48 
49 static const struct nhlt_dmic_array_config dmic_2ch_mic_config = {
50  .tdm_config = {
52  },
53  .array_type = NHLT_MIC_ARRAY_2CH_SMALL,
54 };
55 
56 static const struct nhlt_endp_descriptor dmic_2ch_descriptors[] = {
57  {
59  .device = NHLT_PDM_DEV,
60  .direction = NHLT_DIR_CAPTURE,
61  .vid = NHLT_VID,
62  .did = NHLT_DID_DMIC,
63  .cfg = &dmic_2ch_mic_config,
64  .cfg_size = sizeof(dmic_2ch_mic_config),
67  },
68 };
69 
70 static const struct nhlt_format_config dmic_4ch_formats[] = {
71  /* 48 KHz 16-bits per sample. */
72  {
73  .num_channels = 4,
74  .sample_freq_khz = 48,
75  .container_bits_per_sample = 16,
76  .valid_bits_per_sample = 16,
77  .settings_file = "dmic-4ch-48khz-16b.bin",
78  },
79 };
80 
81 static const struct nhlt_dmic_array_config dmic_4ch_mic_config = {
82  .tdm_config = {
84  },
85  .array_type = NHLT_MIC_ARRAY_4CH_L_SHAPED,
86 };
87 
88 static const struct nhlt_endp_descriptor dmic_4ch_descriptors[] = {
89  {
91  .device = NHLT_PDM_DEV,
92  .direction = NHLT_DIR_CAPTURE,
93  .vid = NHLT_VID,
94  .did = NHLT_DID_DMIC,
95  .cfg = &dmic_4ch_mic_config,
96  .cfg_size = sizeof(dmic_4ch_mic_config),
99  },
100 };
101 
102 static const struct nhlt_format_config da7219_formats[] = {
103  /* 48 KHz 24-bits per sample. */
104  {
105  .num_channels = 2,
106  .sample_freq_khz = 48,
107  .container_bits_per_sample = 32,
108  .valid_bits_per_sample = 24,
109  .settings_file = "dialog-2ch-48khz-24b.bin",
110  },
111 };
112 
113 static const struct nhlt_tdm_config tdm_config = {
114  .virtual_slot = 0,
115  .config_type = NHLT_TDM_BASIC,
116 };
117 
118 static const struct nhlt_endp_descriptor da7219_descriptors[] = {
119  /* Render Endpoint */
120  {
121  .link = NHLT_LINK_SSP,
122  .device = NHLT_SSP_DEV_I2S,
123  .direction = NHLT_DIR_RENDER,
124  .vid = NHLT_VID,
125  .did = NHLT_DID_SSP,
126  .cfg = &tdm_config,
127  .cfg_size = sizeof(tdm_config),
130  },
131  /* Capture Endpoint */
132  {
133  .link = NHLT_LINK_SSP,
134  .device = NHLT_SSP_DEV_I2S,
135  .direction = NHLT_DIR_CAPTURE,
136  .vid = NHLT_VID,
137  .did = NHLT_DID_SSP,
138  .cfg = &tdm_config,
139  .cfg_size = sizeof(tdm_config),
142  },
143 };
144 
145 static const struct nhlt_format_config max98357_formats[] = {
146  /* 48 KHz 24-bits per sample. */
147  {
148  .num_channels = 2,
149  .sample_freq_khz = 48,
150  .container_bits_per_sample = 32,
151  .valid_bits_per_sample = 24,
152  .settings_file = "max98357-render-2ch-48khz-24b.bin",
153  },
154 };
155 
156 static const struct nhlt_endp_descriptor max98357_descriptors[] = {
157  {
158  .link = NHLT_LINK_SSP,
159  .device = NHLT_SSP_DEV_I2S,
160  .direction = NHLT_DIR_RENDER,
161  .vid = NHLT_VID,
162  .did = NHLT_DID_SSP,
163  .formats = max98357_formats,
164  .num_formats = ARRAY_SIZE(max98357_formats),
165  },
166 };
167 
168 int nhlt_soc_add_dmic_array(struct nhlt *nhlt, int num_channels)
169 {
170  switch (num_channels) {
171  case 1:
174  case 2:
177  case 4:
180  default:
181  return -1;
182  }
183 }
184 
185 /*
186  * The same DSP firmware settings are used for both the capture and
187  * render endpoints.
188 */
189 static const struct nhlt_format_config rt5682_formats[] = {
190  /* 48 KHz 24-bits per sample. */
191  {
192  .num_channels = 2,
193  .sample_freq_khz = 48,
194  .container_bits_per_sample = 32,
195  .valid_bits_per_sample = 24,
196  .speaker_mask = SPEAKER_FRONT_LEFT | SPEAKER_FRONT_RIGHT,
197  .settings_file = "rt5682-2ch-48khz-24b.bin",
198  },
199 };
200 
201 /*
202  * The rt5682 just has headphones and a mic. Both the capture and render
203  * endpoints occupy the same virtual slot.
204 */
205 static const struct nhlt_endp_descriptor rt5682_descriptors[] = {
206  /* Render Endpoint */
207  {
208  .link = NHLT_LINK_SSP,
209  .device = NHLT_SSP_DEV_I2S,
210  .direction = NHLT_DIR_RENDER,
211  .vid = NHLT_VID,
212  .did = NHLT_DID_SSP,
213  .cfg = &tdm_config,
214  .cfg_size = sizeof(tdm_config),
217  },
218  /* Capture Endpoint */
219  {
220  .link = NHLT_LINK_SSP,
221  .device = NHLT_SSP_DEV_I2S,
222  .direction = NHLT_DIR_CAPTURE,
223  .vid = NHLT_VID,
224  .did = NHLT_DID_SSP,
225  .cfg = &tdm_config,
226  .cfg_size = sizeof(tdm_config),
229  },
230 };
231 
232 int nhlt_soc_add_da7219(struct nhlt *nhlt, int hwlink)
233 {
234  /* Virtual bus id of SSP links are the hardware port ids proper. */
237 }
238 
239 int nhlt_soc_add_max98357(struct nhlt *nhlt, int hwlink)
240 {
241  /* Virtual bus id of SSP links are the hardware port ids proper. */
244 }
245 
246 int nhlt_soc_add_rt5682(struct nhlt *nhlt, int hwlink)
247 {
248  /* Virtual bus id of SSP links are the hardware port ids proper. */
251 }
#define ARRAY_SIZE(a)
Definition: helpers.h:12
@ NHLT_LINK_SSP
Definition: nhlt.h:176
@ NHLT_LINK_PDM
Definition: nhlt.h:175
@ NHLT_TDM_BASIC
Definition: nhlt.h:300
@ NHLT_TDM_MIC_ARRAY
Definition: nhlt.h:301
@ NHLT_MIC_ARRAY_4CH_L_SHAPED
Definition: nhlt.h:317
@ NHLT_MIC_ARRAY_2CH_SMALL
Definition: nhlt.h:314
@ NHLT_MIC_ARRAY_VENDOR_DEFINED
Definition: nhlt.h:319
@ NHLT_PDM_DEV
Definition: nhlt.h:189
@ NHLT_SSP_DEV_I2S
Definition: nhlt.h:185
@ SPEAKER_FRONT_LEFT
Definition: nhlt.h:203
@ SPEAKER_FRONT_RIGHT
Definition: nhlt.h:204
@ NHLT_DIR_RENDER
Definition: nhlt.h:195
@ NHLT_DIR_CAPTURE
Definition: nhlt.h:196
int nhlt_add_ssp_endpoints(struct nhlt *nhlt, int virtual_bus_id, const struct nhlt_endp_descriptor *epds, size_t num_epds)
Definition: nhlt.c:468
int nhlt_add_endpoints(struct nhlt *nhlt, const struct nhlt_endp_descriptor *epds, size_t num_epds)
Definition: nhlt.c:459
#define NHLT_DID_SSP
Definition: nhlt.h:11
#define NHLT_VID
Definition: nhlt.h:8
#define NHLT_DID_DMIC
Definition: nhlt.h:9
static const struct nhlt_format_config dmic_4ch_formats[]
Definition: nhlt.c:70
int nhlt_soc_add_da7219(struct nhlt *nhlt, int hwlink)
Definition: nhlt.c:232
static const struct nhlt_endp_descriptor rt5682_descriptors[]
Definition: nhlt.c:205
int nhlt_soc_add_dmic_array(struct nhlt *nhlt, int num_channels)
Definition: nhlt.c:168
static const struct nhlt_endp_descriptor dmic_4ch_descriptors[]
Definition: nhlt.c:88
static const struct nhlt_endp_descriptor dmic_1ch_descriptors[]
Definition: nhlt.c:24
int nhlt_soc_add_rt5682(struct nhlt *nhlt, int hwlink)
Definition: nhlt.c:246
static const struct nhlt_endp_descriptor da7219_descriptors[]
Definition: nhlt.c:118
static const struct nhlt_dmic_array_config dmic_1ch_mic_config
Definition: nhlt.c:17
static const struct nhlt_format_config rt5682_formats[]
Definition: nhlt.c:189
static const struct nhlt_format_config max98357_formats[]
Definition: nhlt.c:145
static const struct nhlt_endp_descriptor dmic_2ch_descriptors[]
Definition: nhlt.c:56
static const struct nhlt_format_config da7219_formats[]
Definition: nhlt.c:102
static const struct nhlt_endp_descriptor max98357_descriptors[]
Definition: nhlt.c:156
static const struct nhlt_dmic_array_config dmic_2ch_mic_config
Definition: nhlt.c:49
static const struct nhlt_format_config dmic_1ch_formats[]
Definition: nhlt.c:6
static const struct nhlt_format_config dmic_2ch_formats[]
Definition: nhlt.c:38
int nhlt_soc_add_max98357(struct nhlt *nhlt, int hwlink)
Definition: nhlt.c:239
static const struct nhlt_dmic_array_config dmic_4ch_mic_config
Definition: nhlt.c:81
static const struct nhlt_tdm_config tdm_config
Definition: nhlt.c:113
struct nhlt_tdm_config tdm_config
Definition: nhlt.h:305
const struct nhlt_format_config * formats
Definition: nhlt.h:63
size_t num_formats
Definition: nhlt.h:64
int num_channels
Definition: nhlt.h:260
uint8_t config_type
Definition: nhlt.h:296
uint8_t virtual_slot
Definition: nhlt.h:295
Definition: nhlt.h:287