skl-nhlt.c 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  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 "skl.h"
  21. /* Unique identification for getting NHLT blobs */
  22. static u8 OSC_UUID[16] = {0x6E, 0x88, 0x9F, 0xA6, 0xEB, 0x6C, 0x94, 0x45,
  23. 0xA4, 0x1F, 0x7B, 0x5D, 0xCE, 0x24, 0xC5, 0x53};
  24. #define DSDT_NHLT_PATH "\\_SB.PCI0.HDAS"
  25. void *skl_nhlt_init(struct device *dev)
  26. {
  27. acpi_handle handle;
  28. union acpi_object *obj;
  29. struct nhlt_resource_desc *nhlt_ptr = NULL;
  30. if (ACPI_FAILURE(acpi_get_handle(NULL, DSDT_NHLT_PATH, &handle))) {
  31. dev_err(dev, "Requested NHLT device not found\n");
  32. return NULL;
  33. }
  34. obj = acpi_evaluate_dsm(handle, OSC_UUID, 1, 1, NULL);
  35. if (obj && obj->type == ACPI_TYPE_BUFFER) {
  36. nhlt_ptr = (struct nhlt_resource_desc *)obj->buffer.pointer;
  37. return memremap(nhlt_ptr->min_addr, nhlt_ptr->length,
  38. MEMREMAP_WB);
  39. }
  40. dev_err(dev, "device specific method to extract NHLT blob failed\n");
  41. return NULL;
  42. }
  43. void skl_nhlt_free(void *addr)
  44. {
  45. memunmap(addr);
  46. }
  47. static struct nhlt_specific_cfg *skl_get_specific_cfg(
  48. struct device *dev, struct nhlt_fmt *fmt,
  49. u8 no_ch, u32 rate, u16 bps)
  50. {
  51. struct nhlt_specific_cfg *sp_config;
  52. struct wav_fmt *wfmt;
  53. struct nhlt_fmt_cfg *fmt_config = fmt->fmt_config;
  54. int i;
  55. dev_dbg(dev, "Format count =%d\n", fmt->fmt_count);
  56. for (i = 0; i < fmt->fmt_count; i++) {
  57. wfmt = &fmt_config->fmt_ext.fmt;
  58. dev_dbg(dev, "ch=%d fmt=%d s_rate=%d\n", wfmt->channels,
  59. wfmt->bits_per_sample, wfmt->samples_per_sec);
  60. if (wfmt->channels == no_ch && wfmt->samples_per_sec == rate &&
  61. wfmt->bits_per_sample == bps) {
  62. sp_config = &fmt_config->config;
  63. return sp_config;
  64. }
  65. fmt_config = (struct nhlt_fmt_cfg *)(fmt_config->config.caps +
  66. fmt_config->config.size);
  67. }
  68. return NULL;
  69. }
  70. static void dump_config(struct device *dev, u32 instance_id, u8 linktype,
  71. u8 s_fmt, u8 num_channels, u32 s_rate, u8 dirn, u16 bps)
  72. {
  73. dev_dbg(dev, "Input configuration\n");
  74. dev_dbg(dev, "ch=%d fmt=%d s_rate=%d\n", num_channels, s_fmt, s_rate);
  75. dev_dbg(dev, "vbus_id=%d link_type=%d\n", instance_id, linktype);
  76. dev_dbg(dev, "bits_per_sample=%d\n", bps);
  77. }
  78. static bool skl_check_ep_match(struct device *dev, struct nhlt_endpoint *epnt,
  79. u32 instance_id, u8 link_type, u8 dirn)
  80. {
  81. dev_dbg(dev, "vbus_id=%d link_type=%d dir=%d\n",
  82. epnt->virtual_bus_id, epnt->linktype, epnt->direction);
  83. if ((epnt->virtual_bus_id == instance_id) &&
  84. (epnt->linktype == link_type) &&
  85. (epnt->direction == dirn))
  86. return true;
  87. else
  88. return false;
  89. }
  90. struct nhlt_specific_cfg
  91. *skl_get_ep_blob(struct skl *skl, u32 instance, u8 link_type,
  92. u8 s_fmt, u8 num_ch, u32 s_rate, u8 dirn)
  93. {
  94. struct nhlt_fmt *fmt;
  95. struct nhlt_endpoint *epnt;
  96. struct hdac_bus *bus = ebus_to_hbus(&skl->ebus);
  97. struct device *dev = bus->dev;
  98. struct nhlt_specific_cfg *sp_config;
  99. struct nhlt_acpi_table *nhlt = (struct nhlt_acpi_table *)skl->nhlt;
  100. u16 bps = num_ch * s_fmt;
  101. u8 j;
  102. dump_config(dev, instance, link_type, s_fmt, num_ch, s_rate, dirn, bps);
  103. epnt = (struct nhlt_endpoint *)nhlt->desc;
  104. dev_dbg(dev, "endpoint count =%d\n", nhlt->endpoint_count);
  105. for (j = 0; j < nhlt->endpoint_count; j++) {
  106. if (skl_check_ep_match(dev, epnt, instance, link_type, dirn)) {
  107. fmt = (struct nhlt_fmt *)(epnt->config.caps +
  108. epnt->config.size);
  109. sp_config = skl_get_specific_cfg(dev, fmt, num_ch, s_rate, bps);
  110. if (sp_config)
  111. return sp_config;
  112. }
  113. epnt = (struct nhlt_endpoint *)((u8 *)epnt + epnt->length);
  114. }
  115. return NULL;
  116. }