]> git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/blame - sound/soc/intel/skylake/skl-nhlt.c
ASoC: Intel: Skylake: Add NHLT support to get BE config
[mirror_ubuntu-eoan-kernel.git] / sound / soc / intel / skylake / skl-nhlt.c
CommitLineData
473eb87a
JK
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/acpi.h>
21#include "skl.h"
22
23/* Unique identification for getting NHLT blobs */
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
29void __iomem *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
35 if (ACPI_FAILURE(acpi_get_handle(NULL, DSDT_NHLT_PATH, &handle))) {
36 dev_err(dev, "Requested NHLT device not found\n");
37 return NULL;
38 }
39
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
44 return ioremap_cache(nhlt_ptr->min_addr, nhlt_ptr->length);
45 }
46
47 dev_err(dev, "device specific method to extract NHLT blob failed\n");
48 return NULL;
49}
50
51void skl_nhlt_free(void __iomem *addr)
52{
53 iounmap(addr);
54 addr = NULL;
55}
56
57static struct nhlt_specific_cfg *skl_get_specific_cfg(
58 struct device *dev, struct nhlt_fmt *fmt,
59 u8 no_ch, u8 rate, u16 bps)
60{
61 struct nhlt_specific_cfg *sp_config;
62 struct wav_fmt *wfmt;
63 struct nhlt_fmt_cfg *fmt_config = fmt->fmt_config;
64 int i;
65
66 dev_dbg(dev, "Format count =%d\n", fmt->fmt_count);
67
68 for (i = 0; i < fmt->fmt_count; i++) {
69 wfmt = &fmt_config->fmt_ext.fmt;
70 dev_dbg(dev, "ch=%d fmt=%d s_rate=%d\n", wfmt->channels,
71 wfmt->bits_per_sample, wfmt->samples_per_sec);
72 if (wfmt->channels == no_ch && wfmt->samples_per_sec == rate &&
73 wfmt->bits_per_sample == bps) {
74 sp_config = &fmt_config->config;
75
76 return sp_config;
77 }
78
79 fmt_config = (struct nhlt_fmt_cfg *)(fmt_config->config.caps +
80 fmt_config->config.size);
81 }
82
83 return NULL;
84}
85
86static void dump_config(struct device *dev, u32 instance_id, u8 linktype,
87 u8 s_fmt, u8 num_channels, u32 s_rate, u8 dirn, u16 bps)
88{
89 dev_dbg(dev, "Input configuration\n");
90 dev_dbg(dev, "ch=%d fmt=%d s_rate=%d\n", num_channels, s_fmt, s_rate);
91 dev_dbg(dev, "vbus_id=%d link_type=%d\n", instance_id, linktype);
92 dev_dbg(dev, "bits_per_sample=%d\n", bps);
93}
94
95static bool skl_check_ep_match(struct device *dev, struct nhlt_endpoint *epnt,
96 u32 instance_id, u8 link_type, u8 dirn)
97{
98 dev_dbg(dev, "vbus_id=%d link_type=%d dir=%d\n",
99 epnt->virtual_bus_id, epnt->linktype, epnt->direction);
100
101 if ((epnt->virtual_bus_id == instance_id) &&
102 (epnt->linktype == link_type) &&
103 (epnt->direction == dirn))
104 return true;
105 else
106 return false;
107}
108
109struct nhlt_specific_cfg
110*skl_get_ep_blob(struct skl *skl, u32 instance, u8 link_type,
111 u8 s_fmt, u8 num_ch, u32 s_rate, u8 dirn)
112{
113 struct nhlt_fmt *fmt;
114 struct nhlt_endpoint *epnt;
115 struct hdac_bus *bus = ebus_to_hbus(&skl->ebus);
116 struct device *dev = bus->dev;
117 struct nhlt_specific_cfg *sp_config;
118 struct nhlt_acpi_table *nhlt = (struct nhlt_acpi_table *)skl->nhlt;
119 u16 bps = num_ch * s_fmt;
120 u8 j;
121
122 dump_config(dev, instance, link_type, s_fmt, num_ch, s_rate, dirn, bps);
123
124 epnt = (struct nhlt_endpoint *)nhlt->desc;
125
126 dev_dbg(dev, "endpoint count =%d\n", nhlt->endpoint_count);
127
128 for (j = 0; j < nhlt->endpoint_count; j++) {
129 if (skl_check_ep_match(dev, epnt, instance, link_type, dirn)) {
130 fmt = (struct nhlt_fmt *)(epnt->config.caps +
131 epnt->config.size);
132 sp_config = skl_get_specific_cfg(dev, fmt, num_ch, s_rate, bps);
133 if (sp_config)
134 return sp_config;
135 }
136
137 epnt = (struct nhlt_endpoint *)((u8 *)epnt + epnt->length);
138 }
139
140 return NULL;
141}