2 * skl-nhlt.c - Intel SKL Platform NHLT parsing
4 * Copyright (C) 2015 Intel Corp
5 * Author: Sanjiv Kumar <sanjiv.kumar@intel.com>
6 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2 of the License.
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
22 /* Unique identification for getting NHLT blobs */
23 static u8 OSC_UUID
[16] = {0x6E, 0x88, 0x9F, 0xA6, 0xEB, 0x6C, 0x94, 0x45,
24 0xA4, 0x1F, 0x7B, 0x5D, 0xCE, 0x24, 0xC5, 0x53};
26 #define DSDT_NHLT_PATH "\\_SB.PCI0.HDAS"
28 struct nhlt_acpi_table
*skl_nhlt_init(struct device
*dev
)
31 union acpi_object
*obj
;
32 struct nhlt_resource_desc
*nhlt_ptr
= NULL
;
33 struct nhlt_acpi_table
*nhlt_table
= NULL
;
35 if (ACPI_FAILURE(acpi_get_handle(NULL
, DSDT_NHLT_PATH
, &handle
))) {
36 dev_err(dev
, "Requested NHLT device not found\n");
40 obj
= acpi_evaluate_dsm(handle
, OSC_UUID
, 1, 1, NULL
);
41 if (obj
&& obj
->type
== ACPI_TYPE_BUFFER
) {
42 nhlt_ptr
= (struct nhlt_resource_desc
*)obj
->buffer
.pointer
;
43 nhlt_table
= (struct nhlt_acpi_table
*)
44 memremap(nhlt_ptr
->min_addr
, nhlt_ptr
->length
,
50 dev_err(dev
, "device specific method to extract NHLT blob failed\n");
54 void skl_nhlt_free(struct nhlt_acpi_table
*nhlt
)
56 memunmap((void *) nhlt
);
59 static struct nhlt_specific_cfg
*skl_get_specific_cfg(
60 struct device
*dev
, struct nhlt_fmt
*fmt
,
61 u8 no_ch
, u32 rate
, u16 bps
, u8 linktype
)
63 struct nhlt_specific_cfg
*sp_config
;
65 struct nhlt_fmt_cfg
*fmt_config
= fmt
->fmt_config
;
68 dev_dbg(dev
, "Format count =%d\n", fmt
->fmt_count
);
70 for (i
= 0; i
< fmt
->fmt_count
; i
++) {
71 wfmt
= &fmt_config
->fmt_ext
.fmt
;
72 dev_dbg(dev
, "ch=%d fmt=%d s_rate=%d\n", wfmt
->channels
,
73 wfmt
->bits_per_sample
, wfmt
->samples_per_sec
);
74 if (wfmt
->channels
== no_ch
&& wfmt
->bits_per_sample
== bps
) {
76 * if link type is dmic ignore rate check as the blob is
77 * generic for all rates
79 sp_config
= &fmt_config
->config
;
80 if (linktype
== NHLT_LINK_DMIC
)
83 if (wfmt
->samples_per_sec
== rate
)
87 fmt_config
= (struct nhlt_fmt_cfg
*)(fmt_config
->config
.caps
+
88 fmt_config
->config
.size
);
94 static void dump_config(struct device
*dev
, u32 instance_id
, u8 linktype
,
95 u8 s_fmt
, u8 num_channels
, u32 s_rate
, u8 dirn
, u16 bps
)
97 dev_dbg(dev
, "Input configuration\n");
98 dev_dbg(dev
, "ch=%d fmt=%d s_rate=%d\n", num_channels
, s_fmt
, s_rate
);
99 dev_dbg(dev
, "vbus_id=%d link_type=%d\n", instance_id
, linktype
);
100 dev_dbg(dev
, "bits_per_sample=%d\n", bps
);
103 static bool skl_check_ep_match(struct device
*dev
, struct nhlt_endpoint
*epnt
,
104 u32 instance_id
, u8 link_type
, u8 dirn
)
106 dev_dbg(dev
, "vbus_id=%d link_type=%d dir=%d\n",
107 epnt
->virtual_bus_id
, epnt
->linktype
, epnt
->direction
);
109 if ((epnt
->virtual_bus_id
== instance_id
) &&
110 (epnt
->linktype
== link_type
) &&
111 (epnt
->direction
== dirn
))
117 struct nhlt_specific_cfg
118 *skl_get_ep_blob(struct skl
*skl
, u32 instance
, u8 link_type
,
119 u8 s_fmt
, u8 num_ch
, u32 s_rate
, u8 dirn
)
121 struct nhlt_fmt
*fmt
;
122 struct nhlt_endpoint
*epnt
;
123 struct hdac_bus
*bus
= ebus_to_hbus(&skl
->ebus
);
124 struct device
*dev
= bus
->dev
;
125 struct nhlt_specific_cfg
*sp_config
;
126 struct nhlt_acpi_table
*nhlt
= skl
->nhlt
;
127 u16 bps
= (s_fmt
== 16) ? 16 : 32;
130 dump_config(dev
, instance
, link_type
, s_fmt
, num_ch
, s_rate
, dirn
, bps
);
132 epnt
= (struct nhlt_endpoint
*)nhlt
->desc
;
134 dev_dbg(dev
, "endpoint count =%d\n", nhlt
->endpoint_count
);
136 for (j
= 0; j
< nhlt
->endpoint_count
; j
++) {
137 if (skl_check_ep_match(dev
, epnt
, instance
, link_type
, dirn
)) {
138 fmt
= (struct nhlt_fmt
*)(epnt
->config
.caps
+
140 sp_config
= skl_get_specific_cfg(dev
, fmt
, num_ch
,
141 s_rate
, bps
, link_type
);
146 epnt
= (struct nhlt_endpoint
*)((u8
*)epnt
+ epnt
->length
);
152 static void skl_nhlt_trim_space(struct skl
*skl
)
154 char *s
= skl
->tplg_name
;
159 for (i
= 0; s
[i
]; i
++) {
167 int skl_nhlt_update_topology_bin(struct skl
*skl
)
169 struct nhlt_acpi_table
*nhlt
= (struct nhlt_acpi_table
*)skl
->nhlt
;
170 struct hdac_bus
*bus
= ebus_to_hbus(&skl
->ebus
);
171 struct device
*dev
= bus
->dev
;
173 dev_dbg(dev
, "oem_id %.6s, oem_table_id %8s oem_revision %d\n",
174 nhlt
->header
.oem_id
, nhlt
->header
.oem_table_id
,
175 nhlt
->header
.oem_revision
);
177 snprintf(skl
->tplg_name
, sizeof(skl
->tplg_name
), "%x-%.6s-%.8s-%d%s",
178 skl
->pci_id
, nhlt
->header
.oem_id
, nhlt
->header
.oem_table_id
,
179 nhlt
->header
.oem_revision
, "-tplg.bin");
181 skl_nhlt_trim_space(skl
);
This page took 0.034904 seconds and 5 git commands to generate.