skl-nhlt.c 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  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. */
  20. #include <linux/pci.h>
  21. #include "skl.h"
  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};
  25. #define DSDT_NHLT_PATH "\\_SB.PCI0.HDAS"
  26. struct nhlt_acpi_table *skl_nhlt_init(struct device *dev)
  27. {
  28. acpi_handle handle;
  29. union acpi_object *obj;
  30. struct nhlt_resource_desc *nhlt_ptr = NULL;
  31. struct nhlt_acpi_table *nhlt_table = NULL;
  32. if (ACPI_FAILURE(acpi_get_handle(NULL, DSDT_NHLT_PATH, &handle))) {
  33. dev_err(dev, "Requested NHLT device not found\n");
  34. return NULL;
  35. }
  36. obj = acpi_evaluate_dsm(handle, OSC_UUID, 1, 1, NULL);
  37. if (obj && obj->type == ACPI_TYPE_BUFFER) {
  38. nhlt_ptr = (struct nhlt_resource_desc *)obj->buffer.pointer;
  39. if (nhlt_ptr->length)
  40. nhlt_table = (struct nhlt_acpi_table *)
  41. memremap(nhlt_ptr->min_addr, nhlt_ptr->length,
  42. MEMREMAP_WB);
  43. ACPI_FREE(obj);
  44. return nhlt_table;
  45. }
  46. dev_err(dev, "device specific method to extract NHLT blob failed\n");
  47. return NULL;
  48. }
  49. void skl_nhlt_free(struct nhlt_acpi_table *nhlt)
  50. {
  51. memunmap((void *) nhlt);
  52. }
  53. static struct nhlt_specific_cfg *skl_get_specific_cfg(
  54. struct device *dev, struct nhlt_fmt *fmt,
  55. u8 no_ch, u32 rate, u16 bps, u8 linktype)
  56. {
  57. struct nhlt_specific_cfg *sp_config;
  58. struct wav_fmt *wfmt;
  59. struct nhlt_fmt_cfg *fmt_config = fmt->fmt_config;
  60. int i;
  61. dev_dbg(dev, "Format count =%d\n", fmt->fmt_count);
  62. for (i = 0; i < fmt->fmt_count; i++) {
  63. wfmt = &fmt_config->fmt_ext.fmt;
  64. dev_dbg(dev, "ch=%d fmt=%d s_rate=%d\n", wfmt->channels,
  65. wfmt->bits_per_sample, wfmt->samples_per_sec);
  66. if (wfmt->channels == no_ch && wfmt->bits_per_sample == bps) {
  67. /*
  68. * if link type is dmic ignore rate check as the blob is
  69. * generic for all rates
  70. */
  71. sp_config = &fmt_config->config;
  72. if (linktype == NHLT_LINK_DMIC)
  73. return sp_config;
  74. if (wfmt->samples_per_sec == rate)
  75. return sp_config;
  76. }
  77. fmt_config = (struct nhlt_fmt_cfg *)(fmt_config->config.caps +
  78. fmt_config->config.size);
  79. }
  80. return NULL;
  81. }
  82. static void dump_config(struct device *dev, u32 instance_id, u8 linktype,
  83. u8 s_fmt, u8 num_channels, u32 s_rate, u8 dirn, u16 bps)
  84. {
  85. dev_dbg(dev, "Input configuration\n");
  86. dev_dbg(dev, "ch=%d fmt=%d s_rate=%d\n", num_channels, s_fmt, s_rate);
  87. dev_dbg(dev, "vbus_id=%d link_type=%d\n", instance_id, linktype);
  88. dev_dbg(dev, "bits_per_sample=%d\n", bps);
  89. }
  90. static bool skl_check_ep_match(struct device *dev, struct nhlt_endpoint *epnt,
  91. u32 instance_id, u8 link_type, u8 dirn)
  92. {
  93. dev_dbg(dev, "vbus_id=%d link_type=%d dir=%d\n",
  94. epnt->virtual_bus_id, epnt->linktype, epnt->direction);
  95. if ((epnt->virtual_bus_id == instance_id) &&
  96. (epnt->linktype == link_type) &&
  97. (epnt->direction == dirn))
  98. return true;
  99. else
  100. return false;
  101. }
  102. struct nhlt_specific_cfg
  103. *skl_get_ep_blob(struct skl *skl, u32 instance, u8 link_type,
  104. u8 s_fmt, u8 num_ch, u32 s_rate, u8 dirn)
  105. {
  106. struct nhlt_fmt *fmt;
  107. struct nhlt_endpoint *epnt;
  108. struct hdac_bus *bus = ebus_to_hbus(&skl->ebus);
  109. struct device *dev = bus->dev;
  110. struct nhlt_specific_cfg *sp_config;
  111. struct nhlt_acpi_table *nhlt = skl->nhlt;
  112. u16 bps = (s_fmt == 16) ? 16 : 32;
  113. u8 j;
  114. dump_config(dev, instance, link_type, s_fmt, num_ch, s_rate, dirn, bps);
  115. epnt = (struct nhlt_endpoint *)nhlt->desc;
  116. dev_dbg(dev, "endpoint count =%d\n", nhlt->endpoint_count);
  117. for (j = 0; j < nhlt->endpoint_count; j++) {
  118. if (skl_check_ep_match(dev, epnt, instance, link_type, dirn)) {
  119. fmt = (struct nhlt_fmt *)(epnt->config.caps +
  120. epnt->config.size);
  121. sp_config = skl_get_specific_cfg(dev, fmt, num_ch,
  122. s_rate, bps, link_type);
  123. if (sp_config)
  124. return sp_config;
  125. }
  126. epnt = (struct nhlt_endpoint *)((u8 *)epnt + epnt->length);
  127. }
  128. return NULL;
  129. }
  130. int skl_get_dmic_geo(struct skl *skl)
  131. {
  132. struct nhlt_acpi_table *nhlt = (struct nhlt_acpi_table *)skl->nhlt;
  133. struct nhlt_endpoint *epnt;
  134. struct nhlt_dmic_array_config *cfg;
  135. struct device *dev = &skl->pci->dev;
  136. unsigned int dmic_geo = 0;
  137. u8 j;
  138. epnt = (struct nhlt_endpoint *)nhlt->desc;
  139. for (j = 0; j < nhlt->endpoint_count; j++) {
  140. if (epnt->linktype == NHLT_LINK_DMIC) {
  141. cfg = (struct nhlt_dmic_array_config *)
  142. (epnt->config.caps);
  143. switch (cfg->array_type) {
  144. case NHLT_MIC_ARRAY_2CH_SMALL:
  145. case NHLT_MIC_ARRAY_2CH_BIG:
  146. dmic_geo |= MIC_ARRAY_2CH;
  147. break;
  148. case NHLT_MIC_ARRAY_4CH_1ST_GEOM:
  149. case NHLT_MIC_ARRAY_4CH_L_SHAPED:
  150. case NHLT_MIC_ARRAY_4CH_2ND_GEOM:
  151. dmic_geo |= MIC_ARRAY_4CH;
  152. break;
  153. default:
  154. dev_warn(dev, "undefined DMIC array_type 0x%0x\n",
  155. cfg->array_type);
  156. }
  157. }
  158. epnt = (struct nhlt_endpoint *)((u8 *)epnt + epnt->length);
  159. }
  160. return dmic_geo;
  161. }
  162. static void skl_nhlt_trim_space(struct skl *skl)
  163. {
  164. char *s = skl->tplg_name;
  165. int cnt;
  166. int i;
  167. cnt = 0;
  168. for (i = 0; s[i]; i++) {
  169. if (!isspace(s[i]))
  170. s[cnt++] = s[i];
  171. }
  172. s[cnt] = '\0';
  173. }
  174. int skl_nhlt_update_topology_bin(struct skl *skl)
  175. {
  176. struct nhlt_acpi_table *nhlt = (struct nhlt_acpi_table *)skl->nhlt;
  177. struct hdac_bus *bus = ebus_to_hbus(&skl->ebus);
  178. struct device *dev = bus->dev;
  179. dev_dbg(dev, "oem_id %.6s, oem_table_id %8s oem_revision %d\n",
  180. nhlt->header.oem_id, nhlt->header.oem_table_id,
  181. nhlt->header.oem_revision);
  182. snprintf(skl->tplg_name, sizeof(skl->tplg_name), "/*(DEBLOBBED)*/");
  183. skl_nhlt_trim_space(skl);
  184. return 0;
  185. }