Jeeja KP | 473eb87 | 2015-07-21 23:53:55 +0530 | [diff] [blame] | 1 | /* |
| 2 | * skl-nhlt.c - Intel SKL Platform NHLT parsing |
| 3 | * |
| 4 | * Copyright (C) 2015 Intel Corp |
| 5 | * Author: Sanjiv Kumar <sanjiv.kumar@intel.com> |
| 6 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 7 | * |
| 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. |
| 11 | * |
| 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. |
| 16 | * |
| 17 | * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ |
| 18 | * |
| 19 | */ |
Yong Zhi | f65cf7d6 | 2016-05-26 21:30:15 -0700 | [diff] [blame] | 20 | #include <linux/pci.h> |
Jeeja KP | 473eb87 | 2015-07-21 23:53:55 +0530 | [diff] [blame] | 21 | #include "skl.h" |
| 22 | |
Pankaj Bharadiya | 3b47c9d | 2017-11-07 16:16:21 +0530 | [diff] [blame] | 23 | #define NHLT_ACPI_HEADER_SIG "NHLT" |
| 24 | |
Jeeja KP | 473eb87 | 2015-07-21 23:53:55 +0530 | [diff] [blame] | 25 | /* Unique identification for getting NHLT blobs */ |
Andy Shevchenko | 94116f8 | 2017-06-05 19:40:46 +0300 | [diff] [blame] | 26 | static guid_t osc_guid = |
| 27 | GUID_INIT(0xA69F886E, 0x6CEB, 0x4594, |
| 28 | 0xA4, 0x1F, 0x7B, 0x5D, 0xCE, 0x24, 0xC5, 0x53); |
Jeeja KP | 473eb87 | 2015-07-21 23:53:55 +0530 | [diff] [blame] | 29 | |
Jeeja KP | c286b3f | 2016-05-05 11:19:19 +0530 | [diff] [blame] | 30 | struct nhlt_acpi_table *skl_nhlt_init(struct device *dev) |
Jeeja KP | 473eb87 | 2015-07-21 23:53:55 +0530 | [diff] [blame] | 31 | { |
| 32 | acpi_handle handle; |
| 33 | union acpi_object *obj; |
| 34 | struct nhlt_resource_desc *nhlt_ptr = NULL; |
Jeeja KP | c286b3f | 2016-05-05 11:19:19 +0530 | [diff] [blame] | 35 | struct nhlt_acpi_table *nhlt_table = NULL; |
Jeeja KP | 473eb87 | 2015-07-21 23:53:55 +0530 | [diff] [blame] | 36 | |
Vinod Koul | 6ad0005 | 2017-03-24 23:10:30 +0530 | [diff] [blame] | 37 | handle = ACPI_HANDLE(dev); |
| 38 | if (!handle) { |
| 39 | dev_err(dev, "Didn't find ACPI_HANDLE\n"); |
Jeeja KP | 473eb87 | 2015-07-21 23:53:55 +0530 | [diff] [blame] | 40 | return NULL; |
| 41 | } |
| 42 | |
Andy Shevchenko | 94116f8 | 2017-06-05 19:40:46 +0300 | [diff] [blame] | 43 | obj = acpi_evaluate_dsm(handle, &osc_guid, 1, 1, NULL); |
Jeeja KP | 473eb87 | 2015-07-21 23:53:55 +0530 | [diff] [blame] | 44 | if (obj && obj->type == ACPI_TYPE_BUFFER) { |
| 45 | nhlt_ptr = (struct nhlt_resource_desc *)obj->buffer.pointer; |
Jeeja KP | c286b3f | 2016-05-05 11:19:19 +0530 | [diff] [blame] | 46 | nhlt_table = (struct nhlt_acpi_table *) |
| 47 | memremap(nhlt_ptr->min_addr, nhlt_ptr->length, |
Dan Williams | ba40a85 | 2015-10-09 18:16:36 -0400 | [diff] [blame] | 48 | MEMREMAP_WB); |
Jeeja KP | c286b3f | 2016-05-05 11:19:19 +0530 | [diff] [blame] | 49 | ACPI_FREE(obj); |
Pankaj Bharadiya | 3b47c9d | 2017-11-07 16:16:21 +0530 | [diff] [blame] | 50 | if (nhlt_table && (strncmp(nhlt_table->header.signature, |
| 51 | NHLT_ACPI_HEADER_SIG, |
| 52 | strlen(NHLT_ACPI_HEADER_SIG)) != 0)) { |
| 53 | memunmap(nhlt_table); |
| 54 | dev_err(dev, "NHLT ACPI header signature incorrect\n"); |
| 55 | return NULL; |
| 56 | } |
Jeeja KP | c286b3f | 2016-05-05 11:19:19 +0530 | [diff] [blame] | 57 | return nhlt_table; |
Jeeja KP | 473eb87 | 2015-07-21 23:53:55 +0530 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | dev_err(dev, "device specific method to extract NHLT blob failed\n"); |
| 61 | return NULL; |
| 62 | } |
| 63 | |
Jeeja KP | c286b3f | 2016-05-05 11:19:19 +0530 | [diff] [blame] | 64 | void skl_nhlt_free(struct nhlt_acpi_table *nhlt) |
Jeeja KP | 473eb87 | 2015-07-21 23:53:55 +0530 | [diff] [blame] | 65 | { |
Jeeja KP | c286b3f | 2016-05-05 11:19:19 +0530 | [diff] [blame] | 66 | memunmap((void *) nhlt); |
Jeeja KP | 473eb87 | 2015-07-21 23:53:55 +0530 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | static struct nhlt_specific_cfg *skl_get_specific_cfg( |
| 70 | struct device *dev, struct nhlt_fmt *fmt, |
Jeeja KP | 16882d2 | 2015-10-27 09:22:58 +0900 | [diff] [blame] | 71 | u8 no_ch, u32 rate, u16 bps, u8 linktype) |
Jeeja KP | 473eb87 | 2015-07-21 23:53:55 +0530 | [diff] [blame] | 72 | { |
| 73 | struct nhlt_specific_cfg *sp_config; |
| 74 | struct wav_fmt *wfmt; |
| 75 | struct nhlt_fmt_cfg *fmt_config = fmt->fmt_config; |
| 76 | int i; |
| 77 | |
| 78 | dev_dbg(dev, "Format count =%d\n", fmt->fmt_count); |
| 79 | |
| 80 | for (i = 0; i < fmt->fmt_count; i++) { |
| 81 | wfmt = &fmt_config->fmt_ext.fmt; |
| 82 | dev_dbg(dev, "ch=%d fmt=%d s_rate=%d\n", wfmt->channels, |
| 83 | wfmt->bits_per_sample, wfmt->samples_per_sec); |
Jeeja KP | 16882d2 | 2015-10-27 09:22:58 +0900 | [diff] [blame] | 84 | if (wfmt->channels == no_ch && wfmt->bits_per_sample == bps) { |
| 85 | /* |
| 86 | * if link type is dmic ignore rate check as the blob is |
| 87 | * generic for all rates |
| 88 | */ |
Jeeja KP | 473eb87 | 2015-07-21 23:53:55 +0530 | [diff] [blame] | 89 | sp_config = &fmt_config->config; |
Jeeja KP | 16882d2 | 2015-10-27 09:22:58 +0900 | [diff] [blame] | 90 | if (linktype == NHLT_LINK_DMIC) |
| 91 | return sp_config; |
Jeeja KP | 473eb87 | 2015-07-21 23:53:55 +0530 | [diff] [blame] | 92 | |
Jeeja KP | 16882d2 | 2015-10-27 09:22:58 +0900 | [diff] [blame] | 93 | if (wfmt->samples_per_sec == rate) |
| 94 | return sp_config; |
Jeeja KP | 473eb87 | 2015-07-21 23:53:55 +0530 | [diff] [blame] | 95 | } |
| 96 | |
| 97 | fmt_config = (struct nhlt_fmt_cfg *)(fmt_config->config.caps + |
| 98 | fmt_config->config.size); |
| 99 | } |
| 100 | |
| 101 | return NULL; |
| 102 | } |
| 103 | |
| 104 | static void dump_config(struct device *dev, u32 instance_id, u8 linktype, |
| 105 | u8 s_fmt, u8 num_channels, u32 s_rate, u8 dirn, u16 bps) |
| 106 | { |
| 107 | dev_dbg(dev, "Input configuration\n"); |
| 108 | dev_dbg(dev, "ch=%d fmt=%d s_rate=%d\n", num_channels, s_fmt, s_rate); |
| 109 | dev_dbg(dev, "vbus_id=%d link_type=%d\n", instance_id, linktype); |
| 110 | dev_dbg(dev, "bits_per_sample=%d\n", bps); |
| 111 | } |
| 112 | |
| 113 | static bool skl_check_ep_match(struct device *dev, struct nhlt_endpoint *epnt, |
Senthilnathan Veppur | db2f586 | 2017-02-09 16:44:01 +0530 | [diff] [blame] | 114 | u32 instance_id, u8 link_type, u8 dirn, u8 dev_type) |
Jeeja KP | 473eb87 | 2015-07-21 23:53:55 +0530 | [diff] [blame] | 115 | { |
Senthilnathan Veppur | db2f586 | 2017-02-09 16:44:01 +0530 | [diff] [blame] | 116 | dev_dbg(dev, "vbus_id=%d link_type=%d dir=%d dev_type = %d\n", |
| 117 | epnt->virtual_bus_id, epnt->linktype, |
| 118 | epnt->direction, epnt->device_type); |
Jeeja KP | 473eb87 | 2015-07-21 23:53:55 +0530 | [diff] [blame] | 119 | |
| 120 | if ((epnt->virtual_bus_id == instance_id) && |
| 121 | (epnt->linktype == link_type) && |
Guneshwor Singh | e02b033 | 2017-12-06 16:34:04 +0530 | [diff] [blame] | 122 | (epnt->direction == dirn)) { |
| 123 | /* do not check dev_type for DMIC link type */ |
| 124 | if (epnt->linktype == NHLT_LINK_DMIC) |
| 125 | return true; |
| 126 | |
| 127 | if (epnt->device_type == dev_type) |
| 128 | return true; |
| 129 | } |
| 130 | |
| 131 | return false; |
Jeeja KP | 473eb87 | 2015-07-21 23:53:55 +0530 | [diff] [blame] | 132 | } |
| 133 | |
| 134 | struct nhlt_specific_cfg |
| 135 | *skl_get_ep_blob(struct skl *skl, u32 instance, u8 link_type, |
Senthilnathan Veppur | db2f586 | 2017-02-09 16:44:01 +0530 | [diff] [blame] | 136 | u8 s_fmt, u8 num_ch, u32 s_rate, |
| 137 | u8 dirn, u8 dev_type) |
Jeeja KP | 473eb87 | 2015-07-21 23:53:55 +0530 | [diff] [blame] | 138 | { |
| 139 | struct nhlt_fmt *fmt; |
| 140 | struct nhlt_endpoint *epnt; |
| 141 | struct hdac_bus *bus = ebus_to_hbus(&skl->ebus); |
| 142 | struct device *dev = bus->dev; |
| 143 | struct nhlt_specific_cfg *sp_config; |
Jeeja KP | c286b3f | 2016-05-05 11:19:19 +0530 | [diff] [blame] | 144 | struct nhlt_acpi_table *nhlt = skl->nhlt; |
Jeeja KP | 83b5024 | 2015-10-27 09:22:50 +0900 | [diff] [blame] | 145 | u16 bps = (s_fmt == 16) ? 16 : 32; |
Jeeja KP | 473eb87 | 2015-07-21 23:53:55 +0530 | [diff] [blame] | 146 | u8 j; |
| 147 | |
| 148 | dump_config(dev, instance, link_type, s_fmt, num_ch, s_rate, dirn, bps); |
| 149 | |
| 150 | epnt = (struct nhlt_endpoint *)nhlt->desc; |
| 151 | |
| 152 | dev_dbg(dev, "endpoint count =%d\n", nhlt->endpoint_count); |
| 153 | |
| 154 | for (j = 0; j < nhlt->endpoint_count; j++) { |
Senthilnathan Veppur | db2f586 | 2017-02-09 16:44:01 +0530 | [diff] [blame] | 155 | if (skl_check_ep_match(dev, epnt, instance, link_type, |
| 156 | dirn, dev_type)) { |
Jeeja KP | 473eb87 | 2015-07-21 23:53:55 +0530 | [diff] [blame] | 157 | fmt = (struct nhlt_fmt *)(epnt->config.caps + |
| 158 | epnt->config.size); |
Jeeja KP | 16882d2 | 2015-10-27 09:22:58 +0900 | [diff] [blame] | 159 | sp_config = skl_get_specific_cfg(dev, fmt, num_ch, |
| 160 | s_rate, bps, link_type); |
Jeeja KP | 473eb87 | 2015-07-21 23:53:55 +0530 | [diff] [blame] | 161 | if (sp_config) |
| 162 | return sp_config; |
| 163 | } |
| 164 | |
| 165 | epnt = (struct nhlt_endpoint *)((u8 *)epnt + epnt->length); |
| 166 | } |
| 167 | |
| 168 | return NULL; |
| 169 | } |
Vinod Koul | 4b235c4 | 2016-02-19 11:42:34 +0530 | [diff] [blame] | 170 | |
Yong Zhi | f65cf7d6 | 2016-05-26 21:30:15 -0700 | [diff] [blame] | 171 | int skl_get_dmic_geo(struct skl *skl) |
| 172 | { |
| 173 | struct nhlt_acpi_table *nhlt = (struct nhlt_acpi_table *)skl->nhlt; |
| 174 | struct nhlt_endpoint *epnt; |
| 175 | struct nhlt_dmic_array_config *cfg; |
| 176 | struct device *dev = &skl->pci->dev; |
| 177 | unsigned int dmic_geo = 0; |
| 178 | u8 j; |
| 179 | |
| 180 | epnt = (struct nhlt_endpoint *)nhlt->desc; |
| 181 | |
| 182 | for (j = 0; j < nhlt->endpoint_count; j++) { |
| 183 | if (epnt->linktype == NHLT_LINK_DMIC) { |
| 184 | cfg = (struct nhlt_dmic_array_config *) |
| 185 | (epnt->config.caps); |
| 186 | switch (cfg->array_type) { |
| 187 | case NHLT_MIC_ARRAY_2CH_SMALL: |
| 188 | case NHLT_MIC_ARRAY_2CH_BIG: |
| 189 | dmic_geo |= MIC_ARRAY_2CH; |
| 190 | break; |
| 191 | |
| 192 | case NHLT_MIC_ARRAY_4CH_1ST_GEOM: |
| 193 | case NHLT_MIC_ARRAY_4CH_L_SHAPED: |
| 194 | case NHLT_MIC_ARRAY_4CH_2ND_GEOM: |
| 195 | dmic_geo |= MIC_ARRAY_4CH; |
| 196 | break; |
| 197 | |
| 198 | default: |
| 199 | dev_warn(dev, "undefined DMIC array_type 0x%0x\n", |
| 200 | cfg->array_type); |
| 201 | |
| 202 | } |
| 203 | } |
| 204 | epnt = (struct nhlt_endpoint *)((u8 *)epnt + epnt->length); |
| 205 | } |
| 206 | |
| 207 | return dmic_geo; |
| 208 | } |
| 209 | |
Subhransu S. Prusty | 0cf5a17 | 2017-01-11 16:31:02 +0530 | [diff] [blame] | 210 | static void skl_nhlt_trim_space(char *trim) |
Vinod Koul | 4b235c4 | 2016-02-19 11:42:34 +0530 | [diff] [blame] | 211 | { |
Subhransu S. Prusty | 0cf5a17 | 2017-01-11 16:31:02 +0530 | [diff] [blame] | 212 | char *s = trim; |
Vinod Koul | 4b235c4 | 2016-02-19 11:42:34 +0530 | [diff] [blame] | 213 | int cnt; |
| 214 | int i; |
| 215 | |
| 216 | cnt = 0; |
| 217 | for (i = 0; s[i]; i++) { |
| 218 | if (!isspace(s[i])) |
| 219 | s[cnt++] = s[i]; |
| 220 | } |
| 221 | |
| 222 | s[cnt] = '\0'; |
| 223 | } |
| 224 | |
| 225 | int skl_nhlt_update_topology_bin(struct skl *skl) |
| 226 | { |
| 227 | struct nhlt_acpi_table *nhlt = (struct nhlt_acpi_table *)skl->nhlt; |
| 228 | struct hdac_bus *bus = ebus_to_hbus(&skl->ebus); |
| 229 | struct device *dev = bus->dev; |
| 230 | |
| 231 | dev_dbg(dev, "oem_id %.6s, oem_table_id %8s oem_revision %d\n", |
| 232 | nhlt->header.oem_id, nhlt->header.oem_table_id, |
| 233 | nhlt->header.oem_revision); |
| 234 | |
| 235 | snprintf(skl->tplg_name, sizeof(skl->tplg_name), "%x-%.6s-%.8s-%d%s", |
| 236 | skl->pci_id, nhlt->header.oem_id, nhlt->header.oem_table_id, |
| 237 | nhlt->header.oem_revision, "-tplg.bin"); |
| 238 | |
Subhransu S. Prusty | 0cf5a17 | 2017-01-11 16:31:02 +0530 | [diff] [blame] | 239 | skl_nhlt_trim_space(skl->tplg_name); |
Vinod Koul | 4b235c4 | 2016-02-19 11:42:34 +0530 | [diff] [blame] | 240 | |
| 241 | return 0; |
| 242 | } |
Subhransu S. Prusty | 0cf5a17 | 2017-01-11 16:31:02 +0530 | [diff] [blame] | 243 | |
| 244 | static ssize_t skl_nhlt_platform_id_show(struct device *dev, |
| 245 | struct device_attribute *attr, char *buf) |
| 246 | { |
| 247 | struct pci_dev *pci = to_pci_dev(dev); |
| 248 | struct hdac_ext_bus *ebus = pci_get_drvdata(pci); |
| 249 | struct skl *skl = ebus_to_skl(ebus); |
| 250 | struct nhlt_acpi_table *nhlt = (struct nhlt_acpi_table *)skl->nhlt; |
| 251 | char platform_id[32]; |
| 252 | |
| 253 | sprintf(platform_id, "%x-%.6s-%.8s-%d", skl->pci_id, |
| 254 | nhlt->header.oem_id, nhlt->header.oem_table_id, |
| 255 | nhlt->header.oem_revision); |
| 256 | |
| 257 | skl_nhlt_trim_space(platform_id); |
| 258 | return sprintf(buf, "%s\n", platform_id); |
| 259 | } |
| 260 | |
| 261 | static DEVICE_ATTR(platform_id, 0444, skl_nhlt_platform_id_show, NULL); |
| 262 | |
| 263 | int skl_nhlt_create_sysfs(struct skl *skl) |
| 264 | { |
| 265 | struct device *dev = &skl->pci->dev; |
| 266 | |
| 267 | if (sysfs_create_file(&dev->kobj, &dev_attr_platform_id.attr)) |
| 268 | dev_warn(dev, "Error creating sysfs entry\n"); |
| 269 | |
| 270 | return 0; |
| 271 | } |
| 272 | |
| 273 | void skl_nhlt_remove_sysfs(struct skl *skl) |
| 274 | { |
| 275 | struct device *dev = &skl->pci->dev; |
| 276 | |
| 277 | sysfs_remove_file(&dev->kobj, &dev_attr_platform_id.attr); |
| 278 | } |