2019-05-29 22:17:59 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2015-07-22 02:23:55 +08:00
|
|
|
/*
|
|
|
|
* skl-nhlt.c - Intel SKL Platform NHLT parsing
|
|
|
|
*
|
|
|
|
* Copyright (C) 2015 Intel Corp
|
|
|
|
* Author: Sanjiv Kumar <sanjiv.kumar@intel.com>
|
|
|
|
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
*
|
|
|
|
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
*/
|
2016-05-27 12:30:15 +08:00
|
|
|
#include <linux/pci.h>
|
2019-07-29 23:51:47 +08:00
|
|
|
#include <sound/intel-nhlt.h>
|
2015-07-22 02:23:55 +08:00
|
|
|
#include "skl.h"
|
2017-11-22 20:09:46 +08:00
|
|
|
#include "skl-i2s.h"
|
2015-07-22 02:23:55 +08:00
|
|
|
|
|
|
|
static struct nhlt_specific_cfg *skl_get_specific_cfg(
|
|
|
|
struct device *dev, struct nhlt_fmt *fmt,
|
2015-10-27 08:22:58 +08:00
|
|
|
u8 no_ch, u32 rate, u16 bps, u8 linktype)
|
2015-07-22 02:23:55 +08:00
|
|
|
{
|
|
|
|
struct nhlt_specific_cfg *sp_config;
|
|
|
|
struct wav_fmt *wfmt;
|
|
|
|
struct nhlt_fmt_cfg *fmt_config = fmt->fmt_config;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
dev_dbg(dev, "Format count =%d\n", fmt->fmt_count);
|
|
|
|
|
|
|
|
for (i = 0; i < fmt->fmt_count; i++) {
|
|
|
|
wfmt = &fmt_config->fmt_ext.fmt;
|
|
|
|
dev_dbg(dev, "ch=%d fmt=%d s_rate=%d\n", wfmt->channels,
|
|
|
|
wfmt->bits_per_sample, wfmt->samples_per_sec);
|
2015-10-27 08:22:58 +08:00
|
|
|
if (wfmt->channels == no_ch && wfmt->bits_per_sample == bps) {
|
|
|
|
/*
|
|
|
|
* if link type is dmic ignore rate check as the blob is
|
|
|
|
* generic for all rates
|
|
|
|
*/
|
2015-07-22 02:23:55 +08:00
|
|
|
sp_config = &fmt_config->config;
|
2015-10-27 08:22:58 +08:00
|
|
|
if (linktype == NHLT_LINK_DMIC)
|
|
|
|
return sp_config;
|
2015-07-22 02:23:55 +08:00
|
|
|
|
2015-10-27 08:22:58 +08:00
|
|
|
if (wfmt->samples_per_sec == rate)
|
|
|
|
return sp_config;
|
2015-07-22 02:23:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
fmt_config = (struct nhlt_fmt_cfg *)(fmt_config->config.caps +
|
|
|
|
fmt_config->config.size);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void dump_config(struct device *dev, u32 instance_id, u8 linktype,
|
|
|
|
u8 s_fmt, u8 num_channels, u32 s_rate, u8 dirn, u16 bps)
|
|
|
|
{
|
|
|
|
dev_dbg(dev, "Input configuration\n");
|
|
|
|
dev_dbg(dev, "ch=%d fmt=%d s_rate=%d\n", num_channels, s_fmt, s_rate);
|
|
|
|
dev_dbg(dev, "vbus_id=%d link_type=%d\n", instance_id, linktype);
|
|
|
|
dev_dbg(dev, "bits_per_sample=%d\n", bps);
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool skl_check_ep_match(struct device *dev, struct nhlt_endpoint *epnt,
|
2017-02-09 19:14:01 +08:00
|
|
|
u32 instance_id, u8 link_type, u8 dirn, u8 dev_type)
|
2015-07-22 02:23:55 +08:00
|
|
|
{
|
2017-02-09 19:14:01 +08:00
|
|
|
dev_dbg(dev, "vbus_id=%d link_type=%d dir=%d dev_type = %d\n",
|
|
|
|
epnt->virtual_bus_id, epnt->linktype,
|
|
|
|
epnt->direction, epnt->device_type);
|
2015-07-22 02:23:55 +08:00
|
|
|
|
|
|
|
if ((epnt->virtual_bus_id == instance_id) &&
|
|
|
|
(epnt->linktype == link_type) &&
|
2017-12-06 19:04:04 +08:00
|
|
|
(epnt->direction == dirn)) {
|
|
|
|
/* do not check dev_type for DMIC link type */
|
|
|
|
if (epnt->linktype == NHLT_LINK_DMIC)
|
|
|
|
return true;
|
|
|
|
|
|
|
|
if (epnt->device_type == dev_type)
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
2015-07-22 02:23:55 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
struct nhlt_specific_cfg
|
2019-07-23 22:58:48 +08:00
|
|
|
*skl_get_ep_blob(struct skl_dev *skl, u32 instance, u8 link_type,
|
2017-02-09 19:14:01 +08:00
|
|
|
u8 s_fmt, u8 num_ch, u32 s_rate,
|
|
|
|
u8 dirn, u8 dev_type)
|
2015-07-22 02:23:55 +08:00
|
|
|
{
|
|
|
|
struct nhlt_fmt *fmt;
|
|
|
|
struct nhlt_endpoint *epnt;
|
2018-06-02 11:53:50 +08:00
|
|
|
struct hdac_bus *bus = skl_to_bus(skl);
|
2015-07-22 02:23:55 +08:00
|
|
|
struct device *dev = bus->dev;
|
|
|
|
struct nhlt_specific_cfg *sp_config;
|
2016-05-05 13:49:19 +08:00
|
|
|
struct nhlt_acpi_table *nhlt = skl->nhlt;
|
2015-10-27 08:22:50 +08:00
|
|
|
u16 bps = (s_fmt == 16) ? 16 : 32;
|
2015-07-22 02:23:55 +08:00
|
|
|
u8 j;
|
|
|
|
|
|
|
|
dump_config(dev, instance, link_type, s_fmt, num_ch, s_rate, dirn, bps);
|
|
|
|
|
|
|
|
epnt = (struct nhlt_endpoint *)nhlt->desc;
|
|
|
|
|
|
|
|
dev_dbg(dev, "endpoint count =%d\n", nhlt->endpoint_count);
|
|
|
|
|
|
|
|
for (j = 0; j < nhlt->endpoint_count; j++) {
|
2017-02-09 19:14:01 +08:00
|
|
|
if (skl_check_ep_match(dev, epnt, instance, link_type,
|
|
|
|
dirn, dev_type)) {
|
2015-07-22 02:23:55 +08:00
|
|
|
fmt = (struct nhlt_fmt *)(epnt->config.caps +
|
|
|
|
epnt->config.size);
|
2015-10-27 08:22:58 +08:00
|
|
|
sp_config = skl_get_specific_cfg(dev, fmt, num_ch,
|
|
|
|
s_rate, bps, link_type);
|
2015-07-22 02:23:55 +08:00
|
|
|
if (sp_config)
|
|
|
|
return sp_config;
|
|
|
|
}
|
|
|
|
|
|
|
|
epnt = (struct nhlt_endpoint *)((u8 *)epnt + epnt->length);
|
|
|
|
}
|
|
|
|
|
|
|
|
return NULL;
|
|
|
|
}
|
2016-02-19 14:12:34 +08:00
|
|
|
|
2017-01-11 19:01:02 +08:00
|
|
|
static void skl_nhlt_trim_space(char *trim)
|
2016-02-19 14:12:34 +08:00
|
|
|
{
|
2017-01-11 19:01:02 +08:00
|
|
|
char *s = trim;
|
2016-02-19 14:12:34 +08:00
|
|
|
int cnt;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
cnt = 0;
|
|
|
|
for (i = 0; s[i]; i++) {
|
|
|
|
if (!isspace(s[i]))
|
|
|
|
s[cnt++] = s[i];
|
|
|
|
}
|
|
|
|
|
|
|
|
s[cnt] = '\0';
|
|
|
|
}
|
|
|
|
|
2019-07-23 22:58:48 +08:00
|
|
|
int skl_nhlt_update_topology_bin(struct skl_dev *skl)
|
2016-02-19 14:12:34 +08:00
|
|
|
{
|
|
|
|
struct nhlt_acpi_table *nhlt = (struct nhlt_acpi_table *)skl->nhlt;
|
2018-06-02 11:53:50 +08:00
|
|
|
struct hdac_bus *bus = skl_to_bus(skl);
|
2016-02-19 14:12:34 +08:00
|
|
|
struct device *dev = bus->dev;
|
|
|
|
|
2019-08-27 22:17:12 +08:00
|
|
|
dev_dbg(dev, "oem_id %.6s, oem_table_id %.8s oem_revision %d\n",
|
2016-02-19 14:12:34 +08:00
|
|
|
nhlt->header.oem_id, nhlt->header.oem_table_id,
|
|
|
|
nhlt->header.oem_revision);
|
|
|
|
|
|
|
|
snprintf(skl->tplg_name, sizeof(skl->tplg_name), "%x-%.6s-%.8s-%d%s",
|
|
|
|
skl->pci_id, nhlt->header.oem_id, nhlt->header.oem_table_id,
|
|
|
|
nhlt->header.oem_revision, "-tplg.bin");
|
|
|
|
|
2017-01-11 19:01:02 +08:00
|
|
|
skl_nhlt_trim_space(skl->tplg_name);
|
2016-02-19 14:12:34 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2017-01-11 19:01:02 +08:00
|
|
|
|
|
|
|
static ssize_t skl_nhlt_platform_id_show(struct device *dev,
|
|
|
|
struct device_attribute *attr, char *buf)
|
|
|
|
{
|
|
|
|
struct pci_dev *pci = to_pci_dev(dev);
|
2018-06-02 11:53:50 +08:00
|
|
|
struct hdac_bus *bus = pci_get_drvdata(pci);
|
2019-07-23 22:58:48 +08:00
|
|
|
struct skl_dev *skl = bus_to_skl(bus);
|
2017-01-11 19:01:02 +08:00
|
|
|
struct nhlt_acpi_table *nhlt = (struct nhlt_acpi_table *)skl->nhlt;
|
|
|
|
char platform_id[32];
|
|
|
|
|
|
|
|
sprintf(platform_id, "%x-%.6s-%.8s-%d", skl->pci_id,
|
|
|
|
nhlt->header.oem_id, nhlt->header.oem_table_id,
|
|
|
|
nhlt->header.oem_revision);
|
|
|
|
|
|
|
|
skl_nhlt_trim_space(platform_id);
|
|
|
|
return sprintf(buf, "%s\n", platform_id);
|
|
|
|
}
|
|
|
|
|
|
|
|
static DEVICE_ATTR(platform_id, 0444, skl_nhlt_platform_id_show, NULL);
|
|
|
|
|
2019-07-23 22:58:48 +08:00
|
|
|
int skl_nhlt_create_sysfs(struct skl_dev *skl)
|
2017-01-11 19:01:02 +08:00
|
|
|
{
|
|
|
|
struct device *dev = &skl->pci->dev;
|
|
|
|
|
|
|
|
if (sysfs_create_file(&dev->kobj, &dev_attr_platform_id.attr))
|
|
|
|
dev_warn(dev, "Error creating sysfs entry\n");
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-07-23 22:58:48 +08:00
|
|
|
void skl_nhlt_remove_sysfs(struct skl_dev *skl)
|
2017-01-11 19:01:02 +08:00
|
|
|
{
|
|
|
|
struct device *dev = &skl->pci->dev;
|
|
|
|
|
2020-03-05 22:53:11 +08:00
|
|
|
if (skl->nhlt)
|
|
|
|
sysfs_remove_file(&dev->kobj, &dev_attr_platform_id.attr);
|
2017-01-11 19:01:02 +08:00
|
|
|
}
|
2017-11-22 20:09:46 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Queries NHLT for all the fmt configuration for a particular endpoint and
|
|
|
|
* stores all possible rates supported in a rate table for the corresponding
|
|
|
|
* sclk/sclkfs.
|
|
|
|
*/
|
2019-07-23 22:58:48 +08:00
|
|
|
static void skl_get_ssp_clks(struct skl_dev *skl, struct skl_ssp_clk *ssp_clks,
|
2017-11-22 20:09:46 +08:00
|
|
|
struct nhlt_fmt *fmt, u8 id)
|
|
|
|
{
|
2018-01-04 19:25:15 +08:00
|
|
|
struct skl_i2s_config_blob_ext *i2s_config_ext;
|
2017-11-22 20:09:46 +08:00
|
|
|
struct skl_i2s_config_blob_legacy *i2s_config;
|
|
|
|
struct skl_clk_parent_src *parent;
|
|
|
|
struct skl_ssp_clk *sclk, *sclkfs;
|
|
|
|
struct nhlt_fmt_cfg *fmt_cfg;
|
|
|
|
struct wav_fmt_ext *wav_fmt;
|
|
|
|
unsigned long rate = 0;
|
|
|
|
bool present = false;
|
|
|
|
int rate_index = 0;
|
|
|
|
u16 channels, bps;
|
|
|
|
u8 clk_src;
|
|
|
|
int i, j;
|
|
|
|
u32 fs;
|
|
|
|
|
|
|
|
sclk = &ssp_clks[SKL_SCLK_OFS];
|
|
|
|
sclkfs = &ssp_clks[SKL_SCLKFS_OFS];
|
|
|
|
|
|
|
|
if (fmt->fmt_count == 0)
|
|
|
|
return;
|
|
|
|
|
|
|
|
for (i = 0; i < fmt->fmt_count; i++) {
|
|
|
|
fmt_cfg = &fmt->fmt_config[i];
|
|
|
|
wav_fmt = &fmt_cfg->fmt_ext;
|
|
|
|
|
|
|
|
channels = wav_fmt->fmt.channels;
|
|
|
|
bps = wav_fmt->fmt.bits_per_sample;
|
|
|
|
fs = wav_fmt->fmt.samples_per_sec;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* In case of TDM configuration on a ssp, there can
|
|
|
|
* be more than one blob in which channel masks are
|
|
|
|
* different for each usecase for a specific rate and bps.
|
|
|
|
* But the sclk rate will be generated for the total
|
|
|
|
* number of channels used for that endpoint.
|
|
|
|
*
|
|
|
|
* So for the given fs and bps, choose blob which has
|
|
|
|
* the superset of all channels for that endpoint and
|
|
|
|
* derive the rate.
|
|
|
|
*/
|
|
|
|
for (j = i; j < fmt->fmt_count; j++) {
|
|
|
|
fmt_cfg = &fmt->fmt_config[j];
|
|
|
|
wav_fmt = &fmt_cfg->fmt_ext;
|
|
|
|
if ((fs == wav_fmt->fmt.samples_per_sec) &&
|
|
|
|
(bps == wav_fmt->fmt.bits_per_sample))
|
|
|
|
channels = max_t(u16, channels,
|
|
|
|
wav_fmt->fmt.channels);
|
|
|
|
}
|
|
|
|
|
|
|
|
rate = channels * bps * fs;
|
|
|
|
|
|
|
|
/* check if the rate is added already to the given SSP's sclk */
|
2017-12-08 19:54:25 +08:00
|
|
|
for (j = 0; (j < SKL_MAX_CLK_RATES) &&
|
|
|
|
(sclk[id].rate_cfg[j].rate != 0); j++) {
|
2017-11-22 20:09:46 +08:00
|
|
|
if (sclk[id].rate_cfg[j].rate == rate) {
|
|
|
|
present = true;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Fill rate and parent for sclk/sclkfs */
|
|
|
|
if (!present) {
|
2018-01-04 19:25:15 +08:00
|
|
|
i2s_config_ext = (struct skl_i2s_config_blob_ext *)
|
2017-11-22 20:09:46 +08:00
|
|
|
fmt->fmt_config[0].config.caps;
|
2018-01-04 19:25:15 +08:00
|
|
|
|
|
|
|
/* MCLK Divider Source Select */
|
|
|
|
if (is_legacy_blob(i2s_config_ext->hdr.sig)) {
|
|
|
|
i2s_config = ext_to_legacy_blob(i2s_config_ext);
|
|
|
|
clk_src = get_clk_src(i2s_config->mclk,
|
|
|
|
SKL_MNDSS_DIV_CLK_SRC_MASK);
|
|
|
|
} else {
|
|
|
|
clk_src = get_clk_src(i2s_config_ext->mclk,
|
|
|
|
SKL_MNDSS_DIV_CLK_SRC_MASK);
|
|
|
|
}
|
2017-11-22 20:09:46 +08:00
|
|
|
|
|
|
|
parent = skl_get_parent_clk(clk_src);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Do not copy the config data if there is no parent
|
|
|
|
* clock available for this clock source select
|
|
|
|
*/
|
|
|
|
if (!parent)
|
|
|
|
continue;
|
|
|
|
|
|
|
|
sclk[id].rate_cfg[rate_index].rate = rate;
|
|
|
|
sclk[id].rate_cfg[rate_index].config = fmt_cfg;
|
|
|
|
sclkfs[id].rate_cfg[rate_index].rate = rate;
|
|
|
|
sclkfs[id].rate_cfg[rate_index].config = fmt_cfg;
|
|
|
|
sclk[id].parent_name = parent->name;
|
|
|
|
sclkfs[id].parent_name = parent->name;
|
|
|
|
|
|
|
|
rate_index++;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-07-23 22:58:48 +08:00
|
|
|
static void skl_get_mclk(struct skl_dev *skl, struct skl_ssp_clk *mclk,
|
2017-11-22 20:09:46 +08:00
|
|
|
struct nhlt_fmt *fmt, u8 id)
|
|
|
|
{
|
2018-01-04 19:25:15 +08:00
|
|
|
struct skl_i2s_config_blob_ext *i2s_config_ext;
|
2017-11-22 20:09:46 +08:00
|
|
|
struct skl_i2s_config_blob_legacy *i2s_config;
|
|
|
|
struct nhlt_specific_cfg *fmt_cfg;
|
|
|
|
struct skl_clk_parent_src *parent;
|
|
|
|
u32 clkdiv, div_ratio;
|
|
|
|
u8 clk_src;
|
|
|
|
|
|
|
|
fmt_cfg = &fmt->fmt_config[0].config;
|
2018-01-04 19:25:15 +08:00
|
|
|
i2s_config_ext = (struct skl_i2s_config_blob_ext *)fmt_cfg->caps;
|
|
|
|
|
|
|
|
/* MCLK Divider Source Select and divider */
|
|
|
|
if (is_legacy_blob(i2s_config_ext->hdr.sig)) {
|
|
|
|
i2s_config = ext_to_legacy_blob(i2s_config_ext);
|
|
|
|
clk_src = get_clk_src(i2s_config->mclk,
|
|
|
|
SKL_MCLK_DIV_CLK_SRC_MASK);
|
|
|
|
clkdiv = i2s_config->mclk.mdivr &
|
|
|
|
SKL_MCLK_DIV_RATIO_MASK;
|
|
|
|
} else {
|
|
|
|
clk_src = get_clk_src(i2s_config_ext->mclk,
|
|
|
|
SKL_MCLK_DIV_CLK_SRC_MASK);
|
|
|
|
clkdiv = i2s_config_ext->mclk.mdivr[0] &
|
|
|
|
SKL_MCLK_DIV_RATIO_MASK;
|
|
|
|
}
|
2017-11-22 20:09:46 +08:00
|
|
|
|
|
|
|
/* bypass divider */
|
|
|
|
div_ratio = 1;
|
|
|
|
|
|
|
|
if (clkdiv != SKL_MCLK_DIV_RATIO_MASK)
|
|
|
|
/* Divider is 2 + clkdiv */
|
|
|
|
div_ratio = clkdiv + 2;
|
|
|
|
|
|
|
|
/* Calculate MCLK rate from source using div value */
|
|
|
|
parent = skl_get_parent_clk(clk_src);
|
|
|
|
if (!parent)
|
|
|
|
return;
|
|
|
|
|
|
|
|
mclk[id].rate_cfg[0].rate = parent->rate/div_ratio;
|
|
|
|
mclk[id].rate_cfg[0].config = &fmt->fmt_config[0];
|
|
|
|
mclk[id].parent_name = parent->name;
|
|
|
|
}
|
|
|
|
|
2019-07-23 22:58:48 +08:00
|
|
|
void skl_get_clks(struct skl_dev *skl, struct skl_ssp_clk *ssp_clks)
|
2017-11-22 20:09:46 +08:00
|
|
|
{
|
|
|
|
struct nhlt_acpi_table *nhlt = (struct nhlt_acpi_table *)skl->nhlt;
|
|
|
|
struct nhlt_endpoint *epnt;
|
|
|
|
struct nhlt_fmt *fmt;
|
|
|
|
int i;
|
|
|
|
u8 id;
|
|
|
|
|
|
|
|
epnt = (struct nhlt_endpoint *)nhlt->desc;
|
|
|
|
for (i = 0; i < nhlt->endpoint_count; i++) {
|
|
|
|
if (epnt->linktype == NHLT_LINK_SSP) {
|
|
|
|
id = epnt->virtual_bus_id;
|
|
|
|
|
|
|
|
fmt = (struct nhlt_fmt *)(epnt->config.caps
|
|
|
|
+ epnt->config.size);
|
|
|
|
|
|
|
|
skl_get_ssp_clks(skl, ssp_clks, fmt, id);
|
|
|
|
skl_get_mclk(skl, ssp_clks, fmt, id);
|
|
|
|
}
|
|
|
|
epnt = (struct nhlt_endpoint *)((u8 *)epnt + epnt->length);
|
|
|
|
}
|
|
|
|
}
|