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" |
Sriram Periyasamy | bc2bd45 | 2017-11-22 17:39:46 +0530 | [diff] [blame] | 22 | #include "skl-i2s.h" |
Jeeja KP | 473eb87 | 2015-07-21 23:53:55 +0530 | [diff] [blame] | 23 | |
Pankaj Bharadiya | 3b47c9d | 2017-11-07 16:16:21 +0530 | [diff] [blame] | 24 | #define NHLT_ACPI_HEADER_SIG "NHLT" |
| 25 | |
Jeeja KP | 473eb87 | 2015-07-21 23:53:55 +0530 | [diff] [blame] | 26 | /* Unique identification for getting NHLT blobs */ |
Andy Shevchenko | 94116f8 | 2017-06-05 19:40:46 +0300 | [diff] [blame] | 27 | static guid_t osc_guid = |
| 28 | GUID_INIT(0xA69F886E, 0x6CEB, 0x4594, |
| 29 | 0xA4, 0x1F, 0x7B, 0x5D, 0xCE, 0x24, 0xC5, 0x53); |
Jeeja KP | 473eb87 | 2015-07-21 23:53:55 +0530 | [diff] [blame] | 30 | |
Jeeja KP | c286b3f | 2016-05-05 11:19:19 +0530 | [diff] [blame] | 31 | struct nhlt_acpi_table *skl_nhlt_init(struct device *dev) |
Jeeja KP | 473eb87 | 2015-07-21 23:53:55 +0530 | [diff] [blame] | 32 | { |
| 33 | acpi_handle handle; |
| 34 | union acpi_object *obj; |
| 35 | struct nhlt_resource_desc *nhlt_ptr = NULL; |
Jeeja KP | c286b3f | 2016-05-05 11:19:19 +0530 | [diff] [blame] | 36 | struct nhlt_acpi_table *nhlt_table = NULL; |
Jeeja KP | 473eb87 | 2015-07-21 23:53:55 +0530 | [diff] [blame] | 37 | |
Vinod Koul | 6ad0005 | 2017-03-24 23:10:30 +0530 | [diff] [blame] | 38 | handle = ACPI_HANDLE(dev); |
| 39 | if (!handle) { |
| 40 | dev_err(dev, "Didn't find ACPI_HANDLE\n"); |
Jeeja KP | 473eb87 | 2015-07-21 23:53:55 +0530 | [diff] [blame] | 41 | return NULL; |
| 42 | } |
| 43 | |
Andy Shevchenko | 94116f8 | 2017-06-05 19:40:46 +0300 | [diff] [blame] | 44 | obj = acpi_evaluate_dsm(handle, &osc_guid, 1, 1, NULL); |
Jeeja KP | 473eb87 | 2015-07-21 23:53:55 +0530 | [diff] [blame] | 45 | if (obj && obj->type == ACPI_TYPE_BUFFER) { |
| 46 | nhlt_ptr = (struct nhlt_resource_desc *)obj->buffer.pointer; |
Takashi Iwai | 20a1ea2 | 2018-01-03 16:38:46 +0100 | [diff] [blame] | 47 | if (nhlt_ptr->length) |
| 48 | nhlt_table = (struct nhlt_acpi_table *) |
Jeeja KP | c286b3f | 2016-05-05 11:19:19 +0530 | [diff] [blame] | 49 | memremap(nhlt_ptr->min_addr, nhlt_ptr->length, |
Dan Williams | ba40a85 | 2015-10-09 18:16:36 -0400 | [diff] [blame] | 50 | MEMREMAP_WB); |
Jeeja KP | c286b3f | 2016-05-05 11:19:19 +0530 | [diff] [blame] | 51 | ACPI_FREE(obj); |
Pankaj Bharadiya | 3b47c9d | 2017-11-07 16:16:21 +0530 | [diff] [blame] | 52 | if (nhlt_table && (strncmp(nhlt_table->header.signature, |
| 53 | NHLT_ACPI_HEADER_SIG, |
| 54 | strlen(NHLT_ACPI_HEADER_SIG)) != 0)) { |
| 55 | memunmap(nhlt_table); |
| 56 | dev_err(dev, "NHLT ACPI header signature incorrect\n"); |
| 57 | return NULL; |
| 58 | } |
Jeeja KP | c286b3f | 2016-05-05 11:19:19 +0530 | [diff] [blame] | 59 | return nhlt_table; |
Jeeja KP | 473eb87 | 2015-07-21 23:53:55 +0530 | [diff] [blame] | 60 | } |
| 61 | |
| 62 | dev_err(dev, "device specific method to extract NHLT blob failed\n"); |
| 63 | return NULL; |
| 64 | } |
| 65 | |
Jeeja KP | c286b3f | 2016-05-05 11:19:19 +0530 | [diff] [blame] | 66 | void skl_nhlt_free(struct nhlt_acpi_table *nhlt) |
Jeeja KP | 473eb87 | 2015-07-21 23:53:55 +0530 | [diff] [blame] | 67 | { |
Jeeja KP | c286b3f | 2016-05-05 11:19:19 +0530 | [diff] [blame] | 68 | memunmap((void *) nhlt); |
Jeeja KP | 473eb87 | 2015-07-21 23:53:55 +0530 | [diff] [blame] | 69 | } |
| 70 | |
| 71 | static struct nhlt_specific_cfg *skl_get_specific_cfg( |
| 72 | struct device *dev, struct nhlt_fmt *fmt, |
Jeeja KP | 16882d2 | 2015-10-27 09:22:58 +0900 | [diff] [blame] | 73 | u8 no_ch, u32 rate, u16 bps, u8 linktype) |
Jeeja KP | 473eb87 | 2015-07-21 23:53:55 +0530 | [diff] [blame] | 74 | { |
| 75 | struct nhlt_specific_cfg *sp_config; |
| 76 | struct wav_fmt *wfmt; |
| 77 | struct nhlt_fmt_cfg *fmt_config = fmt->fmt_config; |
| 78 | int i; |
| 79 | |
| 80 | dev_dbg(dev, "Format count =%d\n", fmt->fmt_count); |
| 81 | |
| 82 | for (i = 0; i < fmt->fmt_count; i++) { |
| 83 | wfmt = &fmt_config->fmt_ext.fmt; |
| 84 | dev_dbg(dev, "ch=%d fmt=%d s_rate=%d\n", wfmt->channels, |
| 85 | wfmt->bits_per_sample, wfmt->samples_per_sec); |
Jeeja KP | 16882d2 | 2015-10-27 09:22:58 +0900 | [diff] [blame] | 86 | if (wfmt->channels == no_ch && wfmt->bits_per_sample == bps) { |
| 87 | /* |
| 88 | * if link type is dmic ignore rate check as the blob is |
| 89 | * generic for all rates |
| 90 | */ |
Jeeja KP | 473eb87 | 2015-07-21 23:53:55 +0530 | [diff] [blame] | 91 | sp_config = &fmt_config->config; |
Jeeja KP | 16882d2 | 2015-10-27 09:22:58 +0900 | [diff] [blame] | 92 | if (linktype == NHLT_LINK_DMIC) |
| 93 | return sp_config; |
Jeeja KP | 473eb87 | 2015-07-21 23:53:55 +0530 | [diff] [blame] | 94 | |
Jeeja KP | 16882d2 | 2015-10-27 09:22:58 +0900 | [diff] [blame] | 95 | if (wfmt->samples_per_sec == rate) |
| 96 | return sp_config; |
Jeeja KP | 473eb87 | 2015-07-21 23:53:55 +0530 | [diff] [blame] | 97 | } |
| 98 | |
| 99 | fmt_config = (struct nhlt_fmt_cfg *)(fmt_config->config.caps + |
| 100 | fmt_config->config.size); |
| 101 | } |
| 102 | |
| 103 | return NULL; |
| 104 | } |
| 105 | |
| 106 | static void dump_config(struct device *dev, u32 instance_id, u8 linktype, |
| 107 | u8 s_fmt, u8 num_channels, u32 s_rate, u8 dirn, u16 bps) |
| 108 | { |
| 109 | dev_dbg(dev, "Input configuration\n"); |
| 110 | dev_dbg(dev, "ch=%d fmt=%d s_rate=%d\n", num_channels, s_fmt, s_rate); |
| 111 | dev_dbg(dev, "vbus_id=%d link_type=%d\n", instance_id, linktype); |
| 112 | dev_dbg(dev, "bits_per_sample=%d\n", bps); |
| 113 | } |
| 114 | |
| 115 | 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] | 116 | u32 instance_id, u8 link_type, u8 dirn, u8 dev_type) |
Jeeja KP | 473eb87 | 2015-07-21 23:53:55 +0530 | [diff] [blame] | 117 | { |
Senthilnathan Veppur | db2f586 | 2017-02-09 16:44:01 +0530 | [diff] [blame] | 118 | dev_dbg(dev, "vbus_id=%d link_type=%d dir=%d dev_type = %d\n", |
| 119 | epnt->virtual_bus_id, epnt->linktype, |
| 120 | epnt->direction, epnt->device_type); |
Jeeja KP | 473eb87 | 2015-07-21 23:53:55 +0530 | [diff] [blame] | 121 | |
| 122 | if ((epnt->virtual_bus_id == instance_id) && |
| 123 | (epnt->linktype == link_type) && |
Guneshwor Singh | e02b033 | 2017-12-06 16:34:04 +0530 | [diff] [blame] | 124 | (epnt->direction == dirn)) { |
| 125 | /* do not check dev_type for DMIC link type */ |
| 126 | if (epnt->linktype == NHLT_LINK_DMIC) |
| 127 | return true; |
| 128 | |
| 129 | if (epnt->device_type == dev_type) |
| 130 | return true; |
| 131 | } |
| 132 | |
| 133 | return false; |
Jeeja KP | 473eb87 | 2015-07-21 23:53:55 +0530 | [diff] [blame] | 134 | } |
| 135 | |
| 136 | struct nhlt_specific_cfg |
| 137 | *skl_get_ep_blob(struct skl *skl, u32 instance, u8 link_type, |
Senthilnathan Veppur | db2f586 | 2017-02-09 16:44:01 +0530 | [diff] [blame] | 138 | u8 s_fmt, u8 num_ch, u32 s_rate, |
| 139 | u8 dirn, u8 dev_type) |
Jeeja KP | 473eb87 | 2015-07-21 23:53:55 +0530 | [diff] [blame] | 140 | { |
| 141 | struct nhlt_fmt *fmt; |
| 142 | struct nhlt_endpoint *epnt; |
| 143 | struct hdac_bus *bus = ebus_to_hbus(&skl->ebus); |
| 144 | struct device *dev = bus->dev; |
| 145 | struct nhlt_specific_cfg *sp_config; |
Jeeja KP | c286b3f | 2016-05-05 11:19:19 +0530 | [diff] [blame] | 146 | struct nhlt_acpi_table *nhlt = skl->nhlt; |
Jeeja KP | 83b5024 | 2015-10-27 09:22:50 +0900 | [diff] [blame] | 147 | u16 bps = (s_fmt == 16) ? 16 : 32; |
Jeeja KP | 473eb87 | 2015-07-21 23:53:55 +0530 | [diff] [blame] | 148 | u8 j; |
| 149 | |
| 150 | dump_config(dev, instance, link_type, s_fmt, num_ch, s_rate, dirn, bps); |
| 151 | |
| 152 | epnt = (struct nhlt_endpoint *)nhlt->desc; |
| 153 | |
| 154 | dev_dbg(dev, "endpoint count =%d\n", nhlt->endpoint_count); |
| 155 | |
| 156 | for (j = 0; j < nhlt->endpoint_count; j++) { |
Senthilnathan Veppur | db2f586 | 2017-02-09 16:44:01 +0530 | [diff] [blame] | 157 | if (skl_check_ep_match(dev, epnt, instance, link_type, |
| 158 | dirn, dev_type)) { |
Jeeja KP | 473eb87 | 2015-07-21 23:53:55 +0530 | [diff] [blame] | 159 | fmt = (struct nhlt_fmt *)(epnt->config.caps + |
| 160 | epnt->config.size); |
Jeeja KP | 16882d2 | 2015-10-27 09:22:58 +0900 | [diff] [blame] | 161 | sp_config = skl_get_specific_cfg(dev, fmt, num_ch, |
| 162 | s_rate, bps, link_type); |
Jeeja KP | 473eb87 | 2015-07-21 23:53:55 +0530 | [diff] [blame] | 163 | if (sp_config) |
| 164 | return sp_config; |
| 165 | } |
| 166 | |
| 167 | epnt = (struct nhlt_endpoint *)((u8 *)epnt + epnt->length); |
| 168 | } |
| 169 | |
| 170 | return NULL; |
| 171 | } |
Vinod Koul | 4b235c4 | 2016-02-19 11:42:34 +0530 | [diff] [blame] | 172 | |
Yong Zhi | f65cf7d6 | 2016-05-26 21:30:15 -0700 | [diff] [blame] | 173 | int skl_get_dmic_geo(struct skl *skl) |
| 174 | { |
| 175 | struct nhlt_acpi_table *nhlt = (struct nhlt_acpi_table *)skl->nhlt; |
| 176 | struct nhlt_endpoint *epnt; |
| 177 | struct nhlt_dmic_array_config *cfg; |
| 178 | struct device *dev = &skl->pci->dev; |
| 179 | unsigned int dmic_geo = 0; |
| 180 | u8 j; |
| 181 | |
| 182 | epnt = (struct nhlt_endpoint *)nhlt->desc; |
| 183 | |
| 184 | for (j = 0; j < nhlt->endpoint_count; j++) { |
| 185 | if (epnt->linktype == NHLT_LINK_DMIC) { |
| 186 | cfg = (struct nhlt_dmic_array_config *) |
| 187 | (epnt->config.caps); |
| 188 | switch (cfg->array_type) { |
| 189 | case NHLT_MIC_ARRAY_2CH_SMALL: |
| 190 | case NHLT_MIC_ARRAY_2CH_BIG: |
| 191 | dmic_geo |= MIC_ARRAY_2CH; |
| 192 | break; |
| 193 | |
| 194 | case NHLT_MIC_ARRAY_4CH_1ST_GEOM: |
| 195 | case NHLT_MIC_ARRAY_4CH_L_SHAPED: |
| 196 | case NHLT_MIC_ARRAY_4CH_2ND_GEOM: |
| 197 | dmic_geo |= MIC_ARRAY_4CH; |
| 198 | break; |
| 199 | |
| 200 | default: |
| 201 | dev_warn(dev, "undefined DMIC array_type 0x%0x\n", |
| 202 | cfg->array_type); |
| 203 | |
| 204 | } |
| 205 | } |
| 206 | epnt = (struct nhlt_endpoint *)((u8 *)epnt + epnt->length); |
| 207 | } |
| 208 | |
| 209 | return dmic_geo; |
| 210 | } |
| 211 | |
Subhransu S. Prusty | 0cf5a17 | 2017-01-11 16:31:02 +0530 | [diff] [blame] | 212 | static void skl_nhlt_trim_space(char *trim) |
Vinod Koul | 4b235c4 | 2016-02-19 11:42:34 +0530 | [diff] [blame] | 213 | { |
Subhransu S. Prusty | 0cf5a17 | 2017-01-11 16:31:02 +0530 | [diff] [blame] | 214 | char *s = trim; |
Vinod Koul | 4b235c4 | 2016-02-19 11:42:34 +0530 | [diff] [blame] | 215 | int cnt; |
| 216 | int i; |
| 217 | |
| 218 | cnt = 0; |
| 219 | for (i = 0; s[i]; i++) { |
| 220 | if (!isspace(s[i])) |
| 221 | s[cnt++] = s[i]; |
| 222 | } |
| 223 | |
| 224 | s[cnt] = '\0'; |
| 225 | } |
| 226 | |
| 227 | int skl_nhlt_update_topology_bin(struct skl *skl) |
| 228 | { |
| 229 | struct nhlt_acpi_table *nhlt = (struct nhlt_acpi_table *)skl->nhlt; |
| 230 | struct hdac_bus *bus = ebus_to_hbus(&skl->ebus); |
| 231 | struct device *dev = bus->dev; |
| 232 | |
| 233 | dev_dbg(dev, "oem_id %.6s, oem_table_id %8s oem_revision %d\n", |
| 234 | nhlt->header.oem_id, nhlt->header.oem_table_id, |
| 235 | nhlt->header.oem_revision); |
| 236 | |
| 237 | snprintf(skl->tplg_name, sizeof(skl->tplg_name), "%x-%.6s-%.8s-%d%s", |
| 238 | skl->pci_id, nhlt->header.oem_id, nhlt->header.oem_table_id, |
| 239 | nhlt->header.oem_revision, "-tplg.bin"); |
| 240 | |
Subhransu S. Prusty | 0cf5a17 | 2017-01-11 16:31:02 +0530 | [diff] [blame] | 241 | skl_nhlt_trim_space(skl->tplg_name); |
Vinod Koul | 4b235c4 | 2016-02-19 11:42:34 +0530 | [diff] [blame] | 242 | |
| 243 | return 0; |
| 244 | } |
Subhransu S. Prusty | 0cf5a17 | 2017-01-11 16:31:02 +0530 | [diff] [blame] | 245 | |
| 246 | static ssize_t skl_nhlt_platform_id_show(struct device *dev, |
| 247 | struct device_attribute *attr, char *buf) |
| 248 | { |
| 249 | struct pci_dev *pci = to_pci_dev(dev); |
| 250 | struct hdac_ext_bus *ebus = pci_get_drvdata(pci); |
| 251 | struct skl *skl = ebus_to_skl(ebus); |
| 252 | struct nhlt_acpi_table *nhlt = (struct nhlt_acpi_table *)skl->nhlt; |
| 253 | char platform_id[32]; |
| 254 | |
| 255 | sprintf(platform_id, "%x-%.6s-%.8s-%d", skl->pci_id, |
| 256 | nhlt->header.oem_id, nhlt->header.oem_table_id, |
| 257 | nhlt->header.oem_revision); |
| 258 | |
| 259 | skl_nhlt_trim_space(platform_id); |
| 260 | return sprintf(buf, "%s\n", platform_id); |
| 261 | } |
| 262 | |
| 263 | static DEVICE_ATTR(platform_id, 0444, skl_nhlt_platform_id_show, NULL); |
| 264 | |
| 265 | int skl_nhlt_create_sysfs(struct skl *skl) |
| 266 | { |
| 267 | struct device *dev = &skl->pci->dev; |
| 268 | |
| 269 | if (sysfs_create_file(&dev->kobj, &dev_attr_platform_id.attr)) |
| 270 | dev_warn(dev, "Error creating sysfs entry\n"); |
| 271 | |
| 272 | return 0; |
| 273 | } |
| 274 | |
| 275 | void skl_nhlt_remove_sysfs(struct skl *skl) |
| 276 | { |
| 277 | struct device *dev = &skl->pci->dev; |
| 278 | |
| 279 | sysfs_remove_file(&dev->kobj, &dev_attr_platform_id.attr); |
| 280 | } |
Sriram Periyasamy | bc2bd45 | 2017-11-22 17:39:46 +0530 | [diff] [blame] | 281 | |
| 282 | /* |
| 283 | * Queries NHLT for all the fmt configuration for a particular endpoint and |
| 284 | * stores all possible rates supported in a rate table for the corresponding |
| 285 | * sclk/sclkfs. |
| 286 | */ |
Guneshwor Singh | 8e79ec9 | 2017-12-04 10:30:11 +0530 | [diff] [blame] | 287 | static void skl_get_ssp_clks(struct skl *skl, struct skl_ssp_clk *ssp_clks, |
Sriram Periyasamy | bc2bd45 | 2017-11-22 17:39:46 +0530 | [diff] [blame] | 288 | struct nhlt_fmt *fmt, u8 id) |
| 289 | { |
| 290 | struct skl_i2s_config_blob_legacy *i2s_config; |
| 291 | struct skl_clk_parent_src *parent; |
| 292 | struct skl_ssp_clk *sclk, *sclkfs; |
| 293 | struct nhlt_fmt_cfg *fmt_cfg; |
| 294 | struct wav_fmt_ext *wav_fmt; |
| 295 | unsigned long rate = 0; |
| 296 | bool present = false; |
| 297 | int rate_index = 0; |
| 298 | u16 channels, bps; |
| 299 | u8 clk_src; |
| 300 | int i, j; |
| 301 | u32 fs; |
| 302 | |
| 303 | sclk = &ssp_clks[SKL_SCLK_OFS]; |
| 304 | sclkfs = &ssp_clks[SKL_SCLKFS_OFS]; |
| 305 | |
| 306 | if (fmt->fmt_count == 0) |
| 307 | return; |
| 308 | |
| 309 | for (i = 0; i < fmt->fmt_count; i++) { |
| 310 | fmt_cfg = &fmt->fmt_config[i]; |
| 311 | wav_fmt = &fmt_cfg->fmt_ext; |
| 312 | |
| 313 | channels = wav_fmt->fmt.channels; |
| 314 | bps = wav_fmt->fmt.bits_per_sample; |
| 315 | fs = wav_fmt->fmt.samples_per_sec; |
| 316 | |
| 317 | /* |
| 318 | * In case of TDM configuration on a ssp, there can |
| 319 | * be more than one blob in which channel masks are |
| 320 | * different for each usecase for a specific rate and bps. |
| 321 | * But the sclk rate will be generated for the total |
| 322 | * number of channels used for that endpoint. |
| 323 | * |
| 324 | * So for the given fs and bps, choose blob which has |
| 325 | * the superset of all channels for that endpoint and |
| 326 | * derive the rate. |
| 327 | */ |
| 328 | for (j = i; j < fmt->fmt_count; j++) { |
| 329 | fmt_cfg = &fmt->fmt_config[j]; |
| 330 | wav_fmt = &fmt_cfg->fmt_ext; |
| 331 | if ((fs == wav_fmt->fmt.samples_per_sec) && |
| 332 | (bps == wav_fmt->fmt.bits_per_sample)) |
| 333 | channels = max_t(u16, channels, |
| 334 | wav_fmt->fmt.channels); |
| 335 | } |
| 336 | |
| 337 | rate = channels * bps * fs; |
| 338 | |
| 339 | /* check if the rate is added already to the given SSP's sclk */ |
Dan Carpenter | 87684d3 | 2017-12-08 14:54:25 +0300 | [diff] [blame] | 340 | for (j = 0; (j < SKL_MAX_CLK_RATES) && |
| 341 | (sclk[id].rate_cfg[j].rate != 0); j++) { |
Sriram Periyasamy | bc2bd45 | 2017-11-22 17:39:46 +0530 | [diff] [blame] | 342 | if (sclk[id].rate_cfg[j].rate == rate) { |
| 343 | present = true; |
| 344 | break; |
| 345 | } |
| 346 | } |
| 347 | |
| 348 | /* Fill rate and parent for sclk/sclkfs */ |
| 349 | if (!present) { |
| 350 | /* MCLK Divider Source Select */ |
| 351 | i2s_config = (struct skl_i2s_config_blob_legacy *) |
| 352 | fmt->fmt_config[0].config.caps; |
| 353 | clk_src = ((i2s_config->mclk.mdivctrl) |
| 354 | & SKL_MNDSS_DIV_CLK_SRC_MASK) >> |
| 355 | SKL_SHIFT(SKL_MNDSS_DIV_CLK_SRC_MASK); |
| 356 | |
| 357 | parent = skl_get_parent_clk(clk_src); |
| 358 | |
| 359 | /* |
| 360 | * Do not copy the config data if there is no parent |
| 361 | * clock available for this clock source select |
| 362 | */ |
| 363 | if (!parent) |
| 364 | continue; |
| 365 | |
| 366 | sclk[id].rate_cfg[rate_index].rate = rate; |
| 367 | sclk[id].rate_cfg[rate_index].config = fmt_cfg; |
| 368 | sclkfs[id].rate_cfg[rate_index].rate = rate; |
| 369 | sclkfs[id].rate_cfg[rate_index].config = fmt_cfg; |
| 370 | sclk[id].parent_name = parent->name; |
| 371 | sclkfs[id].parent_name = parent->name; |
| 372 | |
| 373 | rate_index++; |
| 374 | } |
| 375 | } |
| 376 | } |
| 377 | |
Guneshwor Singh | 8e79ec9 | 2017-12-04 10:30:11 +0530 | [diff] [blame] | 378 | static void skl_get_mclk(struct skl *skl, struct skl_ssp_clk *mclk, |
Sriram Periyasamy | bc2bd45 | 2017-11-22 17:39:46 +0530 | [diff] [blame] | 379 | struct nhlt_fmt *fmt, u8 id) |
| 380 | { |
| 381 | struct skl_i2s_config_blob_legacy *i2s_config; |
| 382 | struct nhlt_specific_cfg *fmt_cfg; |
| 383 | struct skl_clk_parent_src *parent; |
| 384 | u32 clkdiv, div_ratio; |
| 385 | u8 clk_src; |
| 386 | |
| 387 | fmt_cfg = &fmt->fmt_config[0].config; |
| 388 | i2s_config = (struct skl_i2s_config_blob_legacy *)fmt_cfg->caps; |
| 389 | |
| 390 | /* MCLK Divider Source Select */ |
| 391 | clk_src = ((i2s_config->mclk.mdivctrl) & SKL_MCLK_DIV_CLK_SRC_MASK) >> |
| 392 | SKL_SHIFT(SKL_MCLK_DIV_CLK_SRC_MASK); |
| 393 | |
| 394 | clkdiv = i2s_config->mclk.mdivr & SKL_MCLK_DIV_RATIO_MASK; |
| 395 | |
| 396 | /* bypass divider */ |
| 397 | div_ratio = 1; |
| 398 | |
| 399 | if (clkdiv != SKL_MCLK_DIV_RATIO_MASK) |
| 400 | /* Divider is 2 + clkdiv */ |
| 401 | div_ratio = clkdiv + 2; |
| 402 | |
| 403 | /* Calculate MCLK rate from source using div value */ |
| 404 | parent = skl_get_parent_clk(clk_src); |
| 405 | if (!parent) |
| 406 | return; |
| 407 | |
| 408 | mclk[id].rate_cfg[0].rate = parent->rate/div_ratio; |
| 409 | mclk[id].rate_cfg[0].config = &fmt->fmt_config[0]; |
| 410 | mclk[id].parent_name = parent->name; |
| 411 | } |
| 412 | |
| 413 | void skl_get_clks(struct skl *skl, struct skl_ssp_clk *ssp_clks) |
| 414 | { |
| 415 | struct nhlt_acpi_table *nhlt = (struct nhlt_acpi_table *)skl->nhlt; |
| 416 | struct nhlt_endpoint *epnt; |
| 417 | struct nhlt_fmt *fmt; |
| 418 | int i; |
| 419 | u8 id; |
| 420 | |
| 421 | epnt = (struct nhlt_endpoint *)nhlt->desc; |
| 422 | for (i = 0; i < nhlt->endpoint_count; i++) { |
| 423 | if (epnt->linktype == NHLT_LINK_SSP) { |
| 424 | id = epnt->virtual_bus_id; |
| 425 | |
| 426 | fmt = (struct nhlt_fmt *)(epnt->config.caps |
| 427 | + epnt->config.size); |
| 428 | |
| 429 | skl_get_ssp_clks(skl, ssp_clks, fmt, id); |
| 430 | skl_get_mclk(skl, ssp_clks, fmt, id); |
| 431 | } |
| 432 | epnt = (struct nhlt_endpoint *)((u8 *)epnt + epnt->length); |
| 433 | } |
| 434 | } |