blob: e4cfcf63fb0836c4b756dbfbe918bac8233de27d [file] [log] [blame]
Aaron Durbin9420a522015-11-17 16:31:00 -06001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright 2015 Google, Inc.
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; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 */
15
16#ifndef _NHLT_H_
17#define _NHLT_H_
18
19#include <stdint.h>
20#include <stddef.h>
21
22struct nhlt;
23struct nhlt_endpoint;
24struct nhlt_format;
25struct nhlt_format_config;
26
27/*
28 * Non HD Audio ACPI support. This table is typically used for Intel Smart
29 * Sound Technology DSP. It provides a way to encode opaque settings in
30 * the ACPI tables.
31 *
32 * While the structure fields of the NHLT structs are exposed below
33 * the SoC/chipset code should be the only other user manipulating the
34 * fields directly aside from the library itself.
35 *
36 * The NHLT table consists of endpoints which in turn contain different
37 * supporting stream formats. Each endpoint may contain a device specific
38 * configuration payload as well as each stream format.
39 *
40 * Most code should use the SoC variants of the functions because
41 * there is required logic needed to be performed by the SoC. The SoC
42 * code should be abstracting the inner details of these functions that
43 * specically apply to NHLT objects for that SoC.
44 *
45 * An example sequence:
46 *
47 * nhlt = nhlt_init()
Aaron Durbined114da2016-06-28 15:36:01 -050048 * ep = nhlt_add_endpoint()
Aaron Durbin9420a522015-11-17 16:31:00 -060049 * nhlt_endpoint_append_config(ep)
50 * nhlt_endpoint_add_formats(ep)
51 * nhlt_soc_serialize()
52 */
53
54/* Obtain an nhlt object for adding endpoints. Returns NULL on error. */
55struct nhlt *nhlt_init(void);
56
Subrata Banik1f83e9d2019-01-30 15:04:00 +053057/* Return the size of the NHLT table including ACPI header. */
Aaron Durbin9420a522015-11-17 16:31:00 -060058size_t nhlt_current_size(struct nhlt *nhlt);
59
60/*
Aaron Durbined0f6d72016-06-28 14:59:21 -050061 * Helper functions for adding NHLT devices utilizing an nhlt_endp_descriptor
62 * to drive the logic.
63 */
64
65struct nhlt_endp_descriptor {
66 /* NHLT endpoint types. */
67 int link;
68 int device;
69 int direction;
70 uint16_t vid;
71 uint16_t did;
72 /* Optional endpoint specific configuration data. */
73 const void *cfg;
74 size_t cfg_size;
75 /* Formats supported for endpoint. */
76 const struct nhlt_format_config *formats;
77 size_t num_formats;
78};
79
80/*
81 * Add the number of endpoints described by each descriptor. The virtual bus
82 * id for each descriptor is the default value of 0.
83 * Returns < 0 on error, 0 on success.
84 */
85int nhlt_add_endpoints(struct nhlt *nhlt,
86 const struct nhlt_endp_descriptor *epds,
87 size_t num_epds);
88
89/*
90 * Add the number of endpoints associated with a single NHLT SSP instance id.
91 * Each endpoint described in the endpoint descriptor array uses the provided
92 * virtual bus id. Returns < 0 on error, 0 on success.
93 */
94int nhlt_add_ssp_endpoints(struct nhlt *nhlt, int virtual_bus_id,
95 const struct nhlt_endp_descriptor *epds, size_t num_epds);
96
97/*
Aaron Durbin9420a522015-11-17 16:31:00 -060098 * Add endpoint to NHLT object. Returns NULL on error.
99 *
Aaron Durbined114da2016-06-28 15:36:01 -0500100 * generic nhlt_add_endpoint() is called by the SoC code to provide
Aaron Durbin9420a522015-11-17 16:31:00 -0600101 * the specific assumptions/uses for NHLT for that platform. All fields
102 * are the NHLT enumerations found within this header file.
103 */
104struct nhlt_endpoint *nhlt_add_endpoint(struct nhlt *nhlt, int link_type,
105 int device_type, int dir,
106 uint16_t vid, uint16_t did);
Aaron Durbin9420a522015-11-17 16:31:00 -0600107
108/*
109 * Append blob of configuration to the endpoint proper. Returns 0 on
110 * success, < 0 on error. A copy of the configuration is made so any
111 * resources pointed to by config can be freed after the call.
112 */
113int nhlt_endpoint_append_config(struct nhlt_endpoint *endpoint,
114 const void *config, size_t config_sz);
115
116/* Add a format type to the provided endpoint. Returns NULL on error. */
117struct nhlt_format *nhlt_add_format(struct nhlt_endpoint *endpoint,
118 int num_channels,
119 int sample_freq_khz,
120 int container_bits_per_sample,
121 int valid_bits_per_sample,
122 uint32_t speaker_mask);
123
124/*
125 * Append blob of configuration to the format proper. Returns 0 on
126 * success, < 0 on error. A copy of the configuration is made so any
127 * resources pointed to by config can be freed after the call.
128 */
129int nhlt_format_append_config(struct nhlt_format *format, const void *config,
130 size_t config_sz);
131
132/*
133 * Add num_formats described by formats to the endpoint. This function
134 * effectively wraps nhlt_add_format() and nhlt_format_config() using the
135 * data found in each nhlt_format_config object. Returns 0 on success, < 0
136 * on error.
137 */
138int nhlt_endpoint_add_formats(struct nhlt_endpoint *endpoint,
139 const struct nhlt_format_config *formats,
140 size_t num_formats);
141
142/*
143 * Increment the instance id for a given link type. This function is
144 * used for marking a device being completely added to the NHLT object.
145 * Subsequent endpoints added to the nhlt object with the same link type
146 * will use incremented instance id.
147 */
148void nhlt_next_instance(struct nhlt *nhlt, int link_type);
149
150/*
151 * Serialize NHLT object to ACPI table. Take in the beginning address of where
152 * the table will reside and return the address of the next ACPI table. On
153 * error 0 will be returned. The NHLT object is no longer valid after this
154 * function is called.
155 */
156uintptr_t nhlt_serialize(struct nhlt *nhlt, uintptr_t acpi_addr);
157
158/*
Fang, Yang A16ff8592016-01-28 16:52:33 -0800159 * Serialize NHLT object to ACPI table. Take in the beginning address of where
160 * the table will reside oem_id and oem_table_id and return the address of the
161 * next ACPI table. On error 0 will be returned. The NHLT object is no longer
162 * valid after thisfunction is called.
163 */
164uintptr_t nhlt_serialize_oem_overrides(struct nhlt *nhlt, uintptr_t acpi_addr,
Aaron Durbinb4afe3c2016-11-29 23:14:25 -0600165 const char *oem_id, const char *oem_table_id,
166 uint32_t oem_revision);
Fang, Yang A16ff8592016-01-28 16:52:33 -0800167
168/*
Aaron Durbin9420a522015-11-17 16:31:00 -0600169 * While very similar to nhlt_serialize() the SoC specific function allows
170 * the chipset to perform any needed accounting work such as updating ACPI
171 * field references for the serialized structure.
172 */
173uintptr_t nhlt_soc_serialize(struct nhlt *nhlt, uintptr_t acpi_addr);
174
Fang, Yang A16ff8592016-01-28 16:52:33 -0800175/*
176 * While very similar to nhlt_serialize_oem_overrides() the SoC specific
177 * function allows the chipset to perform any needed accounting work such
178 * as updating ACPI field references for the serialized structure.
179 */
180uintptr_t nhlt_soc_serialize_oem_overrides(struct nhlt *nhlt,
Aaron Durbinb4afe3c2016-11-29 23:14:25 -0600181 uintptr_t acpi_addr, const char *oem_id, const char *oem_table_id,
182 uint32_t oem_revision);
Fang, Yang A16ff8592016-01-28 16:52:33 -0800183
Aaron Durbin9420a522015-11-17 16:31:00 -0600184/* Link and device types. */
185enum {
186 NHLT_LINK_HDA,
187 NHLT_LINK_DSP,
188 NHLT_LINK_PDM,
189 NHLT_LINK_SSP,
190 NHLT_MAX_LINK_TYPES,
191};
192
193enum {
194 NHLT_SSP_DEV_BT, /* Bluetooth */
195 NHLT_SSP_DEV_MODEM,
196 NHLT_SSP_DEV_FM,
197 NHLT_SSP_DEV_RESERVED,
198 NHLT_SSP_DEV_I2S = 4,
199};
200
201enum {
202 NHLT_PDM_DEV,
203};
204
205/* Endpoint direction. */
206enum {
207 NHLT_DIR_RENDER,
208 NHLT_DIR_CAPTURE,
209 NHLT_DIR_BIDIRECTIONAL,
210};
211
212/* Channel Mask for an endpoint. While they are prefixed with 'SPEAKER' the
213 * channel masks are also used for capture devices. */
214enum {
215 SPEAKER_FRONT_LEFT = 1 << 0,
216 SPEAKER_FRONT_RIGHT = 1 << 1,
217 SPEAKER_FRONT_CENTER = 1 << 2,
218 SPEAKER_LOW_FREQUENCY = 1 << 3,
219 SPEAKER_BACK_LEFT = 1 << 4,
220 SPEAKER_BACK_RIGHT = 1 << 5,
221 SPEAKER_FRONT_LEFT_OF_CENTER = 1 << 6,
222 SPEAKER_FRONT_RIGHT_OF_CENTER = 1 << 7,
223 SPEAKER_BACK_CENTER = 1 << 8,
224 SPEAKER_SIDE_LEFT = 1 << 9,
225 SPEAKER_SIDE_RIGHT = 1 << 10,
226 SPEAKER_TOP_CENTER = 1 << 11,
227 SPEAKER_TOP_FRONT_LEFT = 1 << 12,
228 SPEAKER_TOP_FRONT_CENTER = 1 << 13,
229 SPEAKER_TOP_FRONT_RIGHT = 1 << 14,
230 SPEAKER_TOP_BACK_LEFT = 1 << 15,
231 SPEAKER_TOP_BACK_CENTER = 1 << 16,
232 SPEAKER_TOP_BACK_RIGHT = 1 << 17,
233};
234
235
236/* Supporting structures. Only SoC/chipset and the library code directly should
237 * be manipulating these structures. */
238struct sub_format {
239 uint32_t data1;
240 uint16_t data2;
241 uint16_t data3;
242 uint8_t data4[8];
243};
244
245struct nhlt_specific_config {
246 uint32_t size;
247 void *capabilities;
248};
249
250struct nhlt_waveform {
251 uint16_t tag;
252 uint16_t num_channels;
253 uint32_t samples_per_second;
254 uint32_t bytes_per_second;
255 uint16_t block_align;
256 uint16_t bits_per_sample;
257 uint16_t extra_size;
258 uint16_t valid_bits_per_sample;
259 uint32_t channel_mask;
260 struct sub_format sub_format;
261};
262
263struct nhlt_format {
264 struct nhlt_waveform waveform;
265 struct nhlt_specific_config config;
266};
267
268/*
269 * This struct is used by nhlt_endpoint_add_formats() for easily adding
270 * waveform formats with associated settings file.
271 */
272struct nhlt_format_config {
273 int num_channels;
274 int sample_freq_khz;
275 int container_bits_per_sample;
276 int valid_bits_per_sample;
277 uint32_t speaker_mask;
278 const char *settings_file;
279};
280
281/* Arbitrary max number of formats per endpoint. */
282#define MAX_FORMATS 2
283struct nhlt_endpoint {
284 uint32_t length;
285 uint8_t link_type;
286 uint8_t instance_id;
287 uint16_t vendor_id;
288 uint16_t device_id;
289 uint16_t revision_id;
290 uint32_t subsystem_id;
291 uint8_t device_type;
292 uint8_t direction;
293 uint8_t virtual_bus_id;
294 struct nhlt_specific_config config;
295 uint8_t num_formats;
296 struct nhlt_format formats[MAX_FORMATS];
297};
298
299#define MAX_ENDPOINTS 8
300struct nhlt {
Harsha Priya5c315112018-05-03 18:07:40 -0700301 uint32_t subsystem_id;
Aaron Durbin9420a522015-11-17 16:31:00 -0600302 uint8_t num_endpoints;
303 struct nhlt_endpoint endpoints[MAX_ENDPOINTS];
304 uint8_t current_instance_id[NHLT_MAX_LINK_TYPES];
305};
306
307struct nhlt_tdm_config {
308 uint8_t virtual_slot;
309 uint8_t config_type;
310};
311
312enum {
313 NHLT_TDM_BASIC,
314 NHLT_TDM_MIC_ARRAY,
315};
316
317struct nhlt_dmic_array_config {
318 struct nhlt_tdm_config tdm_config;
319 uint8_t array_type;
320};
321
322/*
323 * Microphone array definitions may be found here:
Jonathan Neuschäfera57cc2f2017-09-19 15:19:53 +0200324 * https://msdn.microsoft.com/en-us/library/windows/hardware/dn613960%28v=vs.85%29.aspx
Aaron Durbin9420a522015-11-17 16:31:00 -0600325 */
326enum {
327 NHLT_MIC_ARRAY_2CH_SMALL = 0xa,
328 NHLT_MIC_ARRAY_2CH_BIG = 0xb,
329 NHLT_MIC_ARRAY_4CH_1ST_GEOM = 0xc,
330 NHLT_MIC_ARRAY_4CH_L_SHAPED = 0xd,
331 NHLT_MIC_ARRAY_4CH_2ND_GEOM = 0xe,
332 NHLT_MIC_ARRAY_VENDOR_DEFINED = 0xf,
333};
334
335#endif