lib/nhlt: add helper functions for adding endpoints
In order to ease the porting of supporting NHLT endpoints introduce a nhlt_endpoint_descriptor structure as well as corresponding helper functions. Change-Id: I68edaf681b4e60502f6ddbbd04de21d8aa072296 Signed-off-by: Aaron Durbin <adurbin@chromium.org> Reviewed-on: https://review.coreboot.org/15486 Reviewed-by: Furquan Shaikh <furquan@google.com> Tested-by: build bot (Jenkins)
This commit is contained in:
parent
78461a9d55
commit
ed0f6d7cb7
|
@ -57,6 +57,43 @@ struct nhlt *nhlt_init(void);
|
||||||
/* Return the size of the NHLT table including APCI header. */
|
/* Return the size of the NHLT table including APCI header. */
|
||||||
size_t nhlt_current_size(struct nhlt *nhlt);
|
size_t nhlt_current_size(struct nhlt *nhlt);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Helper functions for adding NHLT devices utilizing an nhlt_endp_descriptor
|
||||||
|
* to drive the logic.
|
||||||
|
*/
|
||||||
|
|
||||||
|
struct nhlt_endp_descriptor {
|
||||||
|
/* NHLT endpoint types. */
|
||||||
|
int link;
|
||||||
|
int device;
|
||||||
|
int direction;
|
||||||
|
uint16_t vid;
|
||||||
|
uint16_t did;
|
||||||
|
/* Optional endpoint specific configuration data. */
|
||||||
|
const void *cfg;
|
||||||
|
size_t cfg_size;
|
||||||
|
/* Formats supported for endpoint. */
|
||||||
|
const struct nhlt_format_config *formats;
|
||||||
|
size_t num_formats;
|
||||||
|
};
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Add the number of endpoints described by each descriptor. The virtual bus
|
||||||
|
* id for each descriptor is the default value of 0.
|
||||||
|
* Returns < 0 on error, 0 on success.
|
||||||
|
*/
|
||||||
|
int nhlt_add_endpoints(struct nhlt *nhlt,
|
||||||
|
const struct nhlt_endp_descriptor *epds,
|
||||||
|
size_t num_epds);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Add the number of endpoints associated with a single NHLT SSP instance id.
|
||||||
|
* Each endpoint described in the endpoint descriptor array uses the provided
|
||||||
|
* virtual bus id. Returns < 0 on error, 0 on success.
|
||||||
|
*/
|
||||||
|
int nhlt_add_ssp_endpoints(struct nhlt *nhlt, int virtual_bus_id,
|
||||||
|
const struct nhlt_endp_descriptor *epds, size_t num_epds);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Add endpoint to NHLT object. Returns NULL on error.
|
* Add endpoint to NHLT object. Returns NULL on error.
|
||||||
*
|
*
|
||||||
|
|
|
@ -24,6 +24,7 @@
|
||||||
#define NHLT_RID 1
|
#define NHLT_RID 1
|
||||||
#define NHLT_SSID 1
|
#define NHLT_SSID 1
|
||||||
#define WAVEFORMAT_TAG 0xfffe
|
#define WAVEFORMAT_TAG 0xfffe
|
||||||
|
#define DEFAULT_VIRTUAL_BUS_ID 0
|
||||||
|
|
||||||
static const struct sub_format pcm_subformat = {
|
static const struct sub_format pcm_subformat = {
|
||||||
.data1 = 0x00000001,
|
.data1 = 0x00000001,
|
||||||
|
@ -68,7 +69,7 @@ struct nhlt_endpoint *nhlt_add_endpoint(struct nhlt *nhlt, int link_type,
|
||||||
endp->subsystem_id = NHLT_SSID;
|
endp->subsystem_id = NHLT_SSID;
|
||||||
endp->device_type = device_type;
|
endp->device_type = device_type;
|
||||||
endp->direction = dir;
|
endp->direction = dir;
|
||||||
endp->virtual_bus_id = 0;
|
endp->virtual_bus_id = DEFAULT_VIRTUAL_BUS_ID;
|
||||||
|
|
||||||
nhlt->num_endpoints++;
|
nhlt->num_endpoints++;
|
||||||
|
|
||||||
|
@ -437,3 +438,60 @@ uintptr_t nhlt_serialize_oem_overrides(struct nhlt *nhlt,
|
||||||
|
|
||||||
return acpi_addr;
|
return acpi_addr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int _nhlt_add_single_endpoint(struct nhlt *nhlt, int virtual_bus_id,
|
||||||
|
const struct nhlt_endp_descriptor *epd)
|
||||||
|
{
|
||||||
|
struct nhlt_endpoint *endp;
|
||||||
|
|
||||||
|
endp = nhlt_add_endpoint(nhlt, epd->link, epd->device, epd->direction,
|
||||||
|
epd->vid, epd->did);
|
||||||
|
|
||||||
|
if (endp == NULL)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
endp->virtual_bus_id = virtual_bus_id;
|
||||||
|
|
||||||
|
if (nhlt_endpoint_append_config(endp, epd->cfg, epd->cfg_size))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
if (nhlt_endpoint_add_formats(endp, epd->formats, epd->num_formats))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
static int _nhlt_add_endpoints(struct nhlt *nhlt, int virtual_bus_id,
|
||||||
|
const struct nhlt_endp_descriptor *epds,
|
||||||
|
size_t num_epds)
|
||||||
|
{
|
||||||
|
size_t i;
|
||||||
|
|
||||||
|
for (i = 0; i < num_epds; i++)
|
||||||
|
if (_nhlt_add_single_endpoint(nhlt, virtual_bus_id, &epds[i]))
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int nhlt_add_endpoints(struct nhlt *nhlt,
|
||||||
|
const struct nhlt_endp_descriptor *epds,
|
||||||
|
size_t num_epds)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
ret = _nhlt_add_endpoints(nhlt, DEFAULT_VIRTUAL_BUS_ID, epds, num_epds);
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
|
int nhlt_add_ssp_endpoints(struct nhlt *nhlt, int virtual_bus_id,
|
||||||
|
const struct nhlt_endp_descriptor *epds, size_t num_epds)
|
||||||
|
{
|
||||||
|
int ret;
|
||||||
|
|
||||||
|
ret = _nhlt_add_endpoints(nhlt, virtual_bus_id, epds, num_epds);
|
||||||
|
|
||||||
|
if (!ret)
|
||||||
|
nhlt_next_instance(nhlt, NHLT_LINK_SSP);
|
||||||
|
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue