1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20#include <linux/pci.h>
21#include "skl.h"
22
23
24static u8 OSC_UUID[16] = {0x6E, 0x88, 0x9F, 0xA6, 0xEB, 0x6C, 0x94, 0x45,
25 0xA4, 0x1F, 0x7B, 0x5D, 0xCE, 0x24, 0xC5, 0x53};
26
27#define DSDT_NHLT_PATH "\\_SB.PCI0.HDAS"
28
29struct nhlt_acpi_table *skl_nhlt_init(struct device *dev)
30{
31 acpi_handle handle;
32 union acpi_object *obj;
33 struct nhlt_resource_desc *nhlt_ptr = NULL;
34 struct nhlt_acpi_table *nhlt_table = NULL;
35
36 if (ACPI_FAILURE(acpi_get_handle(NULL, DSDT_NHLT_PATH, &handle))) {
37 dev_err(dev, "Requested NHLT device not found\n");
38 return NULL;
39 }
40
41 obj = acpi_evaluate_dsm(handle, OSC_UUID, 1, 1, NULL);
42 if (obj && obj->type == ACPI_TYPE_BUFFER) {
43 nhlt_ptr = (struct nhlt_resource_desc *)obj->buffer.pointer;
44 nhlt_table = (struct nhlt_acpi_table *)
45 ioremap_cache(nhlt_ptr->min_addr, nhlt_ptr->length);
46 ACPI_FREE(obj);
47 return nhlt_table;
48 }
49
50 dev_err(dev, "device specific method to extract NHLT blob failed\n");
51 return NULL;
52}
53
54void skl_nhlt_free(struct nhlt_acpi_table *nhlt)
55{
56 iounmap((void *) nhlt);
57}
58
59static 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)
62{
63 struct nhlt_specific_cfg *sp_config;
64 struct wav_fmt *wfmt;
65 struct nhlt_fmt_cfg *fmt_config = fmt->fmt_config;
66 int i;
67
68 dev_dbg(dev, "Format count =%d\n", fmt->fmt_count);
69
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) {
75
76
77
78
79 sp_config = &fmt_config->config;
80 if (linktype == NHLT_LINK_DMIC)
81 return sp_config;
82
83 if (wfmt->samples_per_sec == rate)
84 return sp_config;
85 }
86
87 fmt_config = (struct nhlt_fmt_cfg *)(fmt_config->config.caps +
88 fmt_config->config.size);
89 }
90
91 return NULL;
92}
93
94static 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)
96{
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);
101}
102
103static bool skl_check_ep_match(struct device *dev, struct nhlt_endpoint *epnt,
104 u32 instance_id, u8 link_type, u8 dirn)
105{
106 dev_dbg(dev, "vbus_id=%d link_type=%d dir=%d\n",
107 epnt->virtual_bus_id, epnt->linktype, epnt->direction);
108
109 if ((epnt->virtual_bus_id == instance_id) &&
110 (epnt->linktype == link_type) &&
111 (epnt->direction == dirn))
112 return true;
113 else
114 return false;
115}
116
117struct 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)
120{
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;
128 u8 j;
129
130 dump_config(dev, instance, link_type, s_fmt, num_ch, s_rate, dirn, bps);
131
132 epnt = (struct nhlt_endpoint *)nhlt->desc;
133
134 dev_dbg(dev, "endpoint count =%d\n", nhlt->endpoint_count);
135
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 +
139 epnt->config.size);
140 sp_config = skl_get_specific_cfg(dev, fmt, num_ch,
141 s_rate, bps, link_type);
142 if (sp_config)
143 return sp_config;
144 }
145
146 epnt = (struct nhlt_endpoint *)((u8 *)epnt + epnt->length);
147 }
148
149 return NULL;
150}
151
152int skl_get_dmic_geo(struct skl *skl)
153{
154 struct nhlt_acpi_table *nhlt = (struct nhlt_acpi_table *)skl->nhlt;
155 struct nhlt_endpoint *epnt;
156 struct nhlt_dmic_array_config *cfg;
157 struct device *dev = &skl->pci->dev;
158 unsigned int dmic_geo = 0;
159 u8 j;
160
161 epnt = (struct nhlt_endpoint *)nhlt->desc;
162
163 for (j = 0; j < nhlt->endpoint_count; j++) {
164 if (epnt->linktype == NHLT_LINK_DMIC) {
165 cfg = (struct nhlt_dmic_array_config *)
166 (epnt->config.caps);
167 switch (cfg->array_type) {
168 case NHLT_MIC_ARRAY_2CH_SMALL:
169 case NHLT_MIC_ARRAY_2CH_BIG:
170 dmic_geo |= MIC_ARRAY_2CH;
171 break;
172
173 case NHLT_MIC_ARRAY_4CH_1ST_GEOM:
174 case NHLT_MIC_ARRAY_4CH_L_SHAPED:
175 case NHLT_MIC_ARRAY_4CH_2ND_GEOM:
176 dmic_geo |= MIC_ARRAY_4CH;
177 break;
178
179 default:
180 dev_warn(dev, "undefined DMIC array_type 0x%0x\n",
181 cfg->array_type);
182
183 }
184 }
185 epnt = (struct nhlt_endpoint *)((u8 *)epnt + epnt->length);
186 }
187
188 return dmic_geo;
189}
190
191static void skl_nhlt_trim_space(struct skl *skl)
192{
193 char *s = skl->tplg_name;
194 int cnt;
195 int i;
196
197 cnt = 0;
198 for (i = 0; s[i]; i++) {
199 if (!isspace(s[i]))
200 s[cnt++] = s[i];
201 }
202
203 s[cnt] = '\0';
204}
205
206int skl_nhlt_update_topology_bin(struct skl *skl)
207{
208 struct nhlt_acpi_table *nhlt = (struct nhlt_acpi_table *)skl->nhlt;
209 struct hdac_bus *bus = ebus_to_hbus(&skl->ebus);
210 struct device *dev = bus->dev;
211
212 dev_dbg(dev, "oem_id %.6s, oem_table_id %8s oem_revision %d\n",
213 nhlt->header.oem_id, nhlt->header.oem_table_id,
214 nhlt->header.oem_revision);
215
216 snprintf(skl->tplg_name, sizeof(skl->tplg_name), "%x-%.6s-%.8s-%d%s",
217 skl->pci_id, nhlt->header.oem_id, nhlt->header.oem_table_id,
218 nhlt->header.oem_revision, "-tplg.bin");
219
220 skl_nhlt_trim_space(skl);
221
222 return 0;
223}
224