linux/sound/soc/sof/intel/hda.c
<<
>>
Prefs
   1// SPDX-License-Identifier: (GPL-2.0-only OR BSD-3-Clause)
   2//
   3// This file is provided under a dual BSD/GPLv2 license.  When using or
   4// redistributing this file, you may do so under either license.
   5//
   6// Copyright(c) 2018 Intel Corporation. All rights reserved.
   7//
   8// Authors: Liam Girdwood <liam.r.girdwood@linux.intel.com>
   9//          Ranjani Sridharan <ranjani.sridharan@linux.intel.com>
  10//          Rander Wang <rander.wang@intel.com>
  11//          Keyon Jie <yang.jie@linux.intel.com>
  12//
  13
  14/*
  15 * Hardware interface for generic Intel audio DSP HDA IP
  16 */
  17
  18#include <sound/hdaudio_ext.h>
  19#include <sound/hda_register.h>
  20
  21#include <linux/acpi.h>
  22#include <linux/module.h>
  23#include <linux/soundwire/sdw.h>
  24#include <linux/soundwire/sdw_intel.h>
  25#include <sound/intel-dsp-config.h>
  26#include <sound/intel-nhlt.h>
  27#include <sound/sof.h>
  28#include <sound/sof/xtensa.h>
  29#include "../sof-audio.h"
  30#include "../sof-pci-dev.h"
  31#include "../ops.h"
  32#include "hda.h"
  33
  34#if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA)
  35#include <sound/soc-acpi-intel-match.h>
  36#endif
  37
  38/* platform specific devices */
  39#include "shim.h"
  40
  41#define EXCEPT_MAX_HDR_SIZE     0x400
  42#define HDA_EXT_ROM_STATUS_SIZE 8
  43
  44#if IS_ENABLED(CONFIG_SND_SOC_SOF_INTEL_SOUNDWIRE)
  45
  46/*
  47 * The default for SoundWire clock stop quirks is to power gate the IP
  48 * and do a Bus Reset, this will need to be modified when the DSP
  49 * needs to remain in D0i3 so that the Master does not lose context
  50 * and enumeration is not required on clock restart
  51 */
  52static int sdw_clock_stop_quirks = SDW_INTEL_CLK_STOP_BUS_RESET;
  53module_param(sdw_clock_stop_quirks, int, 0444);
  54MODULE_PARM_DESC(sdw_clock_stop_quirks, "SOF SoundWire clock stop quirks");
  55
  56static int sdw_params_stream(struct device *dev,
  57                             struct sdw_intel_stream_params_data *params_data)
  58{
  59        struct snd_sof_dev *sdev = dev_get_drvdata(dev);
  60        struct snd_soc_dai *d = params_data->dai;
  61        struct sof_ipc_dai_config config;
  62        struct sof_ipc_reply reply;
  63        int link_id = params_data->link_id;
  64        int alh_stream_id = params_data->alh_stream_id;
  65        int ret;
  66        u32 size = sizeof(config);
  67
  68        memset(&config, 0, size);
  69        config.hdr.size = size;
  70        config.hdr.cmd = SOF_IPC_GLB_DAI_MSG | SOF_IPC_DAI_CONFIG;
  71        config.type = SOF_DAI_INTEL_ALH;
  72        config.dai_index = (link_id << 8) | (d->id);
  73        config.alh.stream_id = alh_stream_id;
  74
  75        /* send message to DSP */
  76        ret = sof_ipc_tx_message(sdev->ipc,
  77                                 config.hdr.cmd, &config, size, &reply,
  78                                 sizeof(reply));
  79        if (ret < 0) {
  80                dev_err(sdev->dev,
  81                        "error: failed to set DAI hw_params for link %d dai->id %d ALH %d\n",
  82                        link_id, d->id, alh_stream_id);
  83        }
  84
  85        return ret;
  86}
  87
  88static int sdw_free_stream(struct device *dev,
  89                           struct sdw_intel_stream_free_data *free_data)
  90{
  91        struct snd_sof_dev *sdev = dev_get_drvdata(dev);
  92        struct snd_soc_dai *d = free_data->dai;
  93        struct sof_ipc_dai_config config;
  94        struct sof_ipc_reply reply;
  95        int link_id = free_data->link_id;
  96        int ret;
  97        u32 size = sizeof(config);
  98
  99        memset(&config, 0, size);
 100        config.hdr.size = size;
 101        config.hdr.cmd = SOF_IPC_GLB_DAI_MSG | SOF_IPC_DAI_CONFIG;
 102        config.type = SOF_DAI_INTEL_ALH;
 103        config.dai_index = (link_id << 8) | d->id;
 104        config.alh.stream_id = 0xFFFF; /* invalid value on purpose */
 105
 106        /* send message to DSP */
 107        ret = sof_ipc_tx_message(sdev->ipc,
 108                                 config.hdr.cmd, &config, size, &reply,
 109                                 sizeof(reply));
 110        if (ret < 0) {
 111                dev_err(sdev->dev,
 112                        "error: failed to free stream for link %d dai->id %d\n",
 113                        link_id, d->id);
 114        }
 115
 116        return ret;
 117}
 118
 119static const struct sdw_intel_ops sdw_callback = {
 120        .params_stream = sdw_params_stream,
 121        .free_stream = sdw_free_stream,
 122};
 123
 124void hda_sdw_int_enable(struct snd_sof_dev *sdev, bool enable)
 125{
 126        sdw_intel_enable_irq(sdev->bar[HDA_DSP_BAR], enable);
 127}
 128
 129static int hda_sdw_acpi_scan(struct snd_sof_dev *sdev)
 130{
 131        struct sof_intel_hda_dev *hdev;
 132        acpi_handle handle;
 133        int ret;
 134
 135        handle = ACPI_HANDLE(sdev->dev);
 136
 137        /* save ACPI info for the probe step */
 138        hdev = sdev->pdata->hw_pdata;
 139
 140        ret = sdw_intel_acpi_scan(handle, &hdev->info);
 141        if (ret < 0)
 142                return -EINVAL;
 143
 144        return 0;
 145}
 146
 147static int hda_sdw_probe(struct snd_sof_dev *sdev)
 148{
 149        struct sof_intel_hda_dev *hdev;
 150        struct sdw_intel_res res;
 151        void *sdw;
 152
 153        hdev = sdev->pdata->hw_pdata;
 154
 155        memset(&res, 0, sizeof(res));
 156
 157        res.mmio_base = sdev->bar[HDA_DSP_BAR];
 158        res.irq = sdev->ipc_irq;
 159        res.handle = hdev->info.handle;
 160        res.parent = sdev->dev;
 161        res.ops = &sdw_callback;
 162        res.dev = sdev->dev;
 163        res.clock_stop_quirks = sdw_clock_stop_quirks;
 164
 165        /*
 166         * ops and arg fields are not populated for now,
 167         * they will be needed when the DAI callbacks are
 168         * provided
 169         */
 170
 171        /* we could filter links here if needed, e.g for quirks */
 172        res.count = hdev->info.count;
 173        res.link_mask = hdev->info.link_mask;
 174
 175        sdw = sdw_intel_probe(&res);
 176        if (!sdw) {
 177                dev_err(sdev->dev, "error: SoundWire probe failed\n");
 178                return -EINVAL;
 179        }
 180
 181        /* save context */
 182        hdev->sdw = sdw;
 183
 184        return 0;
 185}
 186
 187int hda_sdw_startup(struct snd_sof_dev *sdev)
 188{
 189        struct sof_intel_hda_dev *hdev;
 190        struct snd_sof_pdata *pdata = sdev->pdata;
 191
 192        hdev = sdev->pdata->hw_pdata;
 193
 194        if (!hdev->sdw)
 195                return 0;
 196
 197        if (pdata->machine && !pdata->machine->mach_params.link_mask)
 198                return 0;
 199
 200        return sdw_intel_startup(hdev->sdw);
 201}
 202
 203static int hda_sdw_exit(struct snd_sof_dev *sdev)
 204{
 205        struct sof_intel_hda_dev *hdev;
 206
 207        hdev = sdev->pdata->hw_pdata;
 208
 209        hda_sdw_int_enable(sdev, false);
 210
 211        if (hdev->sdw)
 212                sdw_intel_exit(hdev->sdw);
 213        hdev->sdw = NULL;
 214
 215        return 0;
 216}
 217
 218static bool hda_dsp_check_sdw_irq(struct snd_sof_dev *sdev)
 219{
 220        struct sof_intel_hda_dev *hdev;
 221        bool ret = false;
 222        u32 irq_status;
 223
 224        hdev = sdev->pdata->hw_pdata;
 225
 226        if (!hdev->sdw)
 227                return ret;
 228
 229        /* store status */
 230        irq_status = snd_sof_dsp_read(sdev, HDA_DSP_BAR, HDA_DSP_REG_ADSPIS2);
 231
 232        /* invalid message ? */
 233        if (irq_status == 0xffffffff)
 234                goto out;
 235
 236        /* SDW message ? */
 237        if (irq_status & HDA_DSP_REG_ADSPIS2_SNDW)
 238                ret = true;
 239
 240out:
 241        return ret;
 242}
 243
 244static irqreturn_t hda_dsp_sdw_thread(int irq, void *context)
 245{
 246        return sdw_intel_thread(irq, context);
 247}
 248
 249static bool hda_sdw_check_wakeen_irq(struct snd_sof_dev *sdev)
 250{
 251        struct sof_intel_hda_dev *hdev;
 252
 253        hdev = sdev->pdata->hw_pdata;
 254        if (hdev->sdw &&
 255            snd_sof_dsp_read(sdev, HDA_DSP_BAR,
 256                             HDA_DSP_REG_SNDW_WAKE_STS))
 257                return true;
 258
 259        return false;
 260}
 261
 262void hda_sdw_process_wakeen(struct snd_sof_dev *sdev)
 263{
 264        struct sof_intel_hda_dev *hdev;
 265
 266        hdev = sdev->pdata->hw_pdata;
 267        if (!hdev->sdw)
 268                return;
 269
 270        sdw_intel_process_wakeen_event(hdev->sdw);
 271}
 272
 273#endif
 274
 275/*
 276 * Debug
 277 */
 278
 279struct hda_dsp_msg_code {
 280        u32 code;
 281        const char *msg;
 282};
 283
 284#if IS_ENABLED(CONFIG_SND_SOC_SOF_DEBUG)
 285static bool hda_use_msi = true;
 286module_param_named(use_msi, hda_use_msi, bool, 0444);
 287MODULE_PARM_DESC(use_msi, "SOF HDA use PCI MSI mode");
 288#else
 289#define hda_use_msi     (1)
 290#endif
 291
 292static char *hda_model;
 293module_param(hda_model, charp, 0444);
 294MODULE_PARM_DESC(hda_model, "Use the given HDA board model.");
 295
 296#if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA) || IS_ENABLED(CONFIG_SND_SOC_SOF_INTEL_SOUNDWIRE)
 297static int hda_dmic_num = -1;
 298module_param_named(dmic_num, hda_dmic_num, int, 0444);
 299MODULE_PARM_DESC(dmic_num, "SOF HDA DMIC number");
 300#endif
 301
 302#if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA)
 303static bool hda_codec_use_common_hdmi = IS_ENABLED(CONFIG_SND_HDA_CODEC_HDMI);
 304module_param_named(use_common_hdmi, hda_codec_use_common_hdmi, bool, 0444);
 305MODULE_PARM_DESC(use_common_hdmi, "SOF HDA use common HDMI codec driver");
 306#endif
 307
 308static const struct hda_dsp_msg_code hda_dsp_rom_msg[] = {
 309        {HDA_DSP_ROM_FW_MANIFEST_LOADED, "status: manifest loaded"},
 310        {HDA_DSP_ROM_FW_FW_LOADED, "status: fw loaded"},
 311        {HDA_DSP_ROM_FW_ENTERED, "status: fw entered"},
 312        {HDA_DSP_ROM_CSE_ERROR, "error: cse error"},
 313        {HDA_DSP_ROM_CSE_WRONG_RESPONSE, "error: cse wrong response"},
 314        {HDA_DSP_ROM_IMR_TO_SMALL, "error: IMR too small"},
 315        {HDA_DSP_ROM_BASE_FW_NOT_FOUND, "error: base fw not found"},
 316        {HDA_DSP_ROM_CSE_VALIDATION_FAILED, "error: signature verification failed"},
 317        {HDA_DSP_ROM_IPC_FATAL_ERROR, "error: ipc fatal error"},
 318        {HDA_DSP_ROM_L2_CACHE_ERROR, "error: L2 cache error"},
 319        {HDA_DSP_ROM_LOAD_OFFSET_TO_SMALL, "error: load offset too small"},
 320        {HDA_DSP_ROM_API_PTR_INVALID, "error: API ptr invalid"},
 321        {HDA_DSP_ROM_BASEFW_INCOMPAT, "error: base fw incompatible"},
 322        {HDA_DSP_ROM_UNHANDLED_INTERRUPT, "error: unhandled interrupt"},
 323        {HDA_DSP_ROM_MEMORY_HOLE_ECC, "error: ECC memory hole"},
 324        {HDA_DSP_ROM_KERNEL_EXCEPTION, "error: kernel exception"},
 325        {HDA_DSP_ROM_USER_EXCEPTION, "error: user exception"},
 326        {HDA_DSP_ROM_UNEXPECTED_RESET, "error: unexpected reset"},
 327        {HDA_DSP_ROM_NULL_FW_ENTRY,     "error: null FW entry point"},
 328};
 329
 330static void hda_dsp_get_status(struct snd_sof_dev *sdev)
 331{
 332        u32 status;
 333        int i;
 334
 335        status = snd_sof_dsp_read(sdev, HDA_DSP_BAR,
 336                                  HDA_DSP_SRAM_REG_ROM_STATUS);
 337
 338        for (i = 0; i < ARRAY_SIZE(hda_dsp_rom_msg); i++) {
 339                if (status == hda_dsp_rom_msg[i].code) {
 340                        dev_err(sdev->dev, "%s - code %8.8x\n",
 341                                hda_dsp_rom_msg[i].msg, status);
 342                        return;
 343                }
 344        }
 345
 346        /* not for us, must be generic sof message */
 347        dev_dbg(sdev->dev, "unknown ROM status value %8.8x\n", status);
 348}
 349
 350static void hda_dsp_get_registers(struct snd_sof_dev *sdev,
 351                                  struct sof_ipc_dsp_oops_xtensa *xoops,
 352                                  struct sof_ipc_panic_info *panic_info,
 353                                  u32 *stack, size_t stack_words)
 354{
 355        u32 offset = sdev->dsp_oops_offset;
 356
 357        /* first read registers */
 358        sof_mailbox_read(sdev, offset, xoops, sizeof(*xoops));
 359
 360        /* note: variable AR register array is not read */
 361
 362        /* then get panic info */
 363        if (xoops->arch_hdr.totalsize > EXCEPT_MAX_HDR_SIZE) {
 364                dev_err(sdev->dev, "invalid header size 0x%x. FW oops is bogus\n",
 365                        xoops->arch_hdr.totalsize);
 366                return;
 367        }
 368        offset += xoops->arch_hdr.totalsize;
 369        sof_block_read(sdev, sdev->mmio_bar, offset,
 370                       panic_info, sizeof(*panic_info));
 371
 372        /* then get the stack */
 373        offset += sizeof(*panic_info);
 374        sof_block_read(sdev, sdev->mmio_bar, offset, stack,
 375                       stack_words * sizeof(u32));
 376}
 377
 378/* dump the first 8 dwords representing the extended ROM status */
 379static void hda_dsp_dump_ext_rom_status(struct snd_sof_dev *sdev, u32 flags)
 380{
 381        char msg[128];
 382        int len = 0;
 383        u32 value;
 384        int i;
 385
 386        for (i = 0; i < HDA_EXT_ROM_STATUS_SIZE; i++) {
 387                value = snd_sof_dsp_read(sdev, HDA_DSP_BAR, HDA_DSP_SRAM_REG_ROM_STATUS + i * 0x4);
 388                len += snprintf(msg + len, sizeof(msg) - len, " 0x%x", value);
 389        }
 390
 391        sof_dev_dbg_or_err(sdev->dev, flags & SOF_DBG_DUMP_FORCE_ERR_LEVEL,
 392                           "extended rom status: %s", msg);
 393
 394}
 395
 396void hda_dsp_dump(struct snd_sof_dev *sdev, u32 flags)
 397{
 398        struct sof_ipc_dsp_oops_xtensa xoops;
 399        struct sof_ipc_panic_info panic_info;
 400        u32 stack[HDA_DSP_STACK_DUMP_SIZE];
 401
 402        /* print ROM/FW status */
 403        hda_dsp_get_status(sdev);
 404
 405        /* print panic info if FW boot is complete. Otherwise, print the extended ROM status */
 406        if (sdev->fw_state == SOF_FW_BOOT_COMPLETE) {
 407                u32 status = snd_sof_dsp_read(sdev, HDA_DSP_BAR, HDA_DSP_SRAM_REG_FW_STATUS);
 408                u32 panic = snd_sof_dsp_read(sdev, HDA_DSP_BAR, HDA_DSP_SRAM_REG_FW_TRACEP);
 409
 410                hda_dsp_get_registers(sdev, &xoops, &panic_info, stack,
 411                                      HDA_DSP_STACK_DUMP_SIZE);
 412                snd_sof_get_status(sdev, status, panic, &xoops, &panic_info,
 413                                   stack, HDA_DSP_STACK_DUMP_SIZE);
 414        } else {
 415                hda_dsp_dump_ext_rom_status(sdev, flags);
 416        }
 417}
 418
 419void hda_ipc_irq_dump(struct snd_sof_dev *sdev)
 420{
 421        struct hdac_bus *bus = sof_to_bus(sdev);
 422        u32 adspis;
 423        u32 intsts;
 424        u32 intctl;
 425        u32 ppsts;
 426        u8 rirbsts;
 427
 428        /* read key IRQ stats and config registers */
 429        adspis = snd_sof_dsp_read(sdev, HDA_DSP_BAR, HDA_DSP_REG_ADSPIS);
 430        intsts = snd_sof_dsp_read(sdev, HDA_DSP_HDA_BAR, SOF_HDA_INTSTS);
 431        intctl = snd_sof_dsp_read(sdev, HDA_DSP_HDA_BAR, SOF_HDA_INTCTL);
 432        ppsts = snd_sof_dsp_read(sdev, HDA_DSP_PP_BAR, SOF_HDA_REG_PP_PPSTS);
 433        rirbsts = snd_hdac_chip_readb(bus, RIRBSTS);
 434
 435        dev_err(sdev->dev,
 436                "error: hda irq intsts 0x%8.8x intlctl 0x%8.8x rirb %2.2x\n",
 437                intsts, intctl, rirbsts);
 438        dev_err(sdev->dev,
 439                "error: dsp irq ppsts 0x%8.8x adspis 0x%8.8x\n",
 440                ppsts, adspis);
 441}
 442
 443void hda_ipc_dump(struct snd_sof_dev *sdev)
 444{
 445        u32 hipcie;
 446        u32 hipct;
 447        u32 hipcctl;
 448
 449        hda_ipc_irq_dump(sdev);
 450
 451        /* read IPC status */
 452        hipcie = snd_sof_dsp_read(sdev, HDA_DSP_BAR, HDA_DSP_REG_HIPCIE);
 453        hipct = snd_sof_dsp_read(sdev, HDA_DSP_BAR, HDA_DSP_REG_HIPCT);
 454        hipcctl = snd_sof_dsp_read(sdev, HDA_DSP_BAR, HDA_DSP_REG_HIPCCTL);
 455
 456        /* dump the IPC regs */
 457        /* TODO: parse the raw msg */
 458        dev_err(sdev->dev,
 459                "error: host status 0x%8.8x dsp status 0x%8.8x mask 0x%8.8x\n",
 460                hipcie, hipct, hipcctl);
 461}
 462
 463static int hda_init(struct snd_sof_dev *sdev)
 464{
 465        struct hda_bus *hbus;
 466        struct hdac_bus *bus;
 467        struct pci_dev *pci = to_pci_dev(sdev->dev);
 468        int ret;
 469
 470        hbus = sof_to_hbus(sdev);
 471        bus = sof_to_bus(sdev);
 472
 473        /* HDA bus init */
 474        sof_hda_bus_init(bus, &pci->dev);
 475
 476        bus->use_posbuf = 1;
 477        bus->bdl_pos_adj = 0;
 478        bus->sync_write = 1;
 479
 480        mutex_init(&hbus->prepare_mutex);
 481        hbus->pci = pci;
 482        hbus->mixer_assigned = -1;
 483        hbus->modelname = hda_model;
 484
 485        /* initialise hdac bus */
 486        bus->addr = pci_resource_start(pci, 0);
 487        bus->remap_addr = pci_ioremap_bar(pci, 0);
 488        if (!bus->remap_addr) {
 489                dev_err(bus->dev, "error: ioremap error\n");
 490                return -ENXIO;
 491        }
 492
 493        /* HDA base */
 494        sdev->bar[HDA_DSP_HDA_BAR] = bus->remap_addr;
 495
 496        /* init i915 and HDMI codecs */
 497        ret = hda_codec_i915_init(sdev);
 498        if (ret < 0)
 499                dev_warn(sdev->dev, "init of i915 and HDMI codec failed\n");
 500
 501        /* get controller capabilities */
 502        ret = hda_dsp_ctrl_get_caps(sdev);
 503        if (ret < 0)
 504                dev_err(sdev->dev, "error: get caps error\n");
 505
 506        return ret;
 507}
 508
 509#if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA) || IS_ENABLED(CONFIG_SND_SOC_SOF_INTEL_SOUNDWIRE)
 510
 511static int check_nhlt_dmic(struct snd_sof_dev *sdev)
 512{
 513        struct nhlt_acpi_table *nhlt;
 514        int dmic_num;
 515
 516        nhlt = intel_nhlt_init(sdev->dev);
 517        if (nhlt) {
 518                dmic_num = intel_nhlt_get_dmic_geo(sdev->dev, nhlt);
 519                intel_nhlt_free(nhlt);
 520                if (dmic_num >= 1 && dmic_num <= 4)
 521                        return dmic_num;
 522        }
 523
 524        return 0;
 525}
 526
 527static const char *fixup_tplg_name(struct snd_sof_dev *sdev,
 528                                   const char *sof_tplg_filename,
 529                                   const char *idisp_str,
 530                                   const char *dmic_str)
 531{
 532        const char *tplg_filename = NULL;
 533        char *filename, *tmp;
 534        const char *split_ext;
 535
 536        filename = kstrdup(sof_tplg_filename, GFP_KERNEL);
 537        if (!filename)
 538                return NULL;
 539
 540        /* this assumes a .tplg extension */
 541        tmp = filename;
 542        split_ext = strsep(&tmp, ".");
 543        if (split_ext)
 544                tplg_filename = devm_kasprintf(sdev->dev, GFP_KERNEL,
 545                                               "%s%s%s.tplg",
 546                                               split_ext, idisp_str, dmic_str);
 547        kfree(filename);
 548
 549        return tplg_filename;
 550}
 551
 552static int dmic_topology_fixup(struct snd_sof_dev *sdev,
 553                               const char **tplg_filename,
 554                               const char *idisp_str,
 555                               int *dmic_found)
 556{
 557        const char *default_tplg_filename = *tplg_filename;
 558        const char *fixed_tplg_filename;
 559        const char *dmic_str;
 560        int dmic_num;
 561
 562        /* first check NHLT for DMICs */
 563        dmic_num = check_nhlt_dmic(sdev);
 564
 565        /* allow for module parameter override */
 566        if (hda_dmic_num != -1) {
 567                dev_dbg(sdev->dev,
 568                        "overriding DMICs detected in NHLT tables %d by kernel param %d\n",
 569                        dmic_num, hda_dmic_num);
 570                dmic_num = hda_dmic_num;
 571        }
 572
 573        switch (dmic_num) {
 574        case 1:
 575                dmic_str = "-1ch";
 576                break;
 577        case 2:
 578                dmic_str = "-2ch";
 579                break;
 580        case 3:
 581                dmic_str = "-3ch";
 582                break;
 583        case 4:
 584                dmic_str = "-4ch";
 585                break;
 586        default:
 587                dmic_num = 0;
 588                dmic_str = "";
 589                break;
 590        }
 591
 592        fixed_tplg_filename = fixup_tplg_name(sdev, default_tplg_filename,
 593                                              idisp_str, dmic_str);
 594        if (!fixed_tplg_filename)
 595                return -ENOMEM;
 596
 597        dev_info(sdev->dev, "DMICs detected in NHLT tables: %d\n", dmic_num);
 598        *dmic_found = dmic_num;
 599        *tplg_filename = fixed_tplg_filename;
 600
 601        return 0;
 602}
 603#endif
 604
 605static int hda_init_caps(struct snd_sof_dev *sdev)
 606{
 607        struct hdac_bus *bus = sof_to_bus(sdev);
 608        struct snd_sof_pdata *pdata = sdev->pdata;
 609#if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA)
 610        struct hdac_ext_link *hlink;
 611#endif
 612        struct sof_intel_hda_dev *hdev = pdata->hw_pdata;
 613        u32 link_mask;
 614        int ret = 0;
 615
 616        /* check if dsp is there */
 617        if (bus->ppcap)
 618                dev_dbg(sdev->dev, "PP capability, will probe DSP later.\n");
 619
 620        /* Init HDA controller after i915 init */
 621        ret = hda_dsp_ctrl_init_chip(sdev, true);
 622        if (ret < 0) {
 623                dev_err(bus->dev, "error: init chip failed with ret: %d\n",
 624                        ret);
 625                return ret;
 626        }
 627
 628        /* scan SoundWire capabilities exposed by DSDT */
 629        ret = hda_sdw_acpi_scan(sdev);
 630        if (ret < 0) {
 631                dev_dbg(sdev->dev, "skipping SoundWire, not detected with ACPI scan\n");
 632                goto skip_soundwire;
 633        }
 634
 635        link_mask = hdev->info.link_mask;
 636        if (!link_mask) {
 637                dev_dbg(sdev->dev, "skipping SoundWire, no links enabled\n");
 638                goto skip_soundwire;
 639        }
 640
 641        /*
 642         * probe/allocate SoundWire resources.
 643         * The hardware configuration takes place in hda_sdw_startup
 644         * after power rails are enabled.
 645         * It's entirely possible to have a mix of I2S/DMIC/SoundWire
 646         * devices, so we allocate the resources in all cases.
 647         */
 648        ret = hda_sdw_probe(sdev);
 649        if (ret < 0) {
 650                dev_err(sdev->dev, "error: SoundWire probe error\n");
 651                return ret;
 652        }
 653
 654skip_soundwire:
 655
 656#if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA)
 657        if (bus->mlcap)
 658                snd_hdac_ext_bus_get_ml_capabilities(bus);
 659
 660        /* create codec instances */
 661        hda_codec_probe_bus(sdev, hda_codec_use_common_hdmi);
 662
 663        if (!HDA_IDISP_CODEC(bus->codec_mask))
 664                hda_codec_i915_display_power(sdev, false);
 665
 666        /*
 667         * we are done probing so decrement link counts
 668         */
 669        list_for_each_entry(hlink, &bus->hlink_list, list)
 670                snd_hdac_ext_bus_link_put(bus, hlink);
 671#endif
 672        return 0;
 673}
 674
 675static const struct sof_intel_dsp_desc
 676        *get_chip_info(struct snd_sof_pdata *pdata)
 677{
 678        const struct sof_dev_desc *desc = pdata->desc;
 679        const struct sof_intel_dsp_desc *chip_info;
 680
 681        chip_info = desc->chip_info;
 682
 683        return chip_info;
 684}
 685
 686static irqreturn_t hda_dsp_interrupt_handler(int irq, void *context)
 687{
 688        struct snd_sof_dev *sdev = context;
 689
 690        /*
 691         * Get global interrupt status. It includes all hardware interrupt
 692         * sources in the Intel HD Audio controller.
 693         */
 694        if (snd_sof_dsp_read(sdev, HDA_DSP_HDA_BAR, SOF_HDA_INTSTS) &
 695            SOF_HDA_INTSTS_GIS) {
 696
 697                /* disable GIE interrupt */
 698                snd_sof_dsp_update_bits(sdev, HDA_DSP_HDA_BAR,
 699                                        SOF_HDA_INTCTL,
 700                                        SOF_HDA_INT_GLOBAL_EN,
 701                                        0);
 702
 703                return IRQ_WAKE_THREAD;
 704        }
 705
 706        return IRQ_NONE;
 707}
 708
 709static irqreturn_t hda_dsp_interrupt_thread(int irq, void *context)
 710{
 711        struct snd_sof_dev *sdev = context;
 712        struct sof_intel_hda_dev *hdev = sdev->pdata->hw_pdata;
 713
 714        /* deal with streams and controller first */
 715        if (hda_dsp_check_stream_irq(sdev))
 716                hda_dsp_stream_threaded_handler(irq, sdev);
 717
 718        if (hda_dsp_check_ipc_irq(sdev))
 719                sof_ops(sdev)->irq_thread(irq, sdev);
 720
 721        if (hda_dsp_check_sdw_irq(sdev))
 722                hda_dsp_sdw_thread(irq, hdev->sdw);
 723
 724        if (hda_sdw_check_wakeen_irq(sdev))
 725                hda_sdw_process_wakeen(sdev);
 726
 727        /* enable GIE interrupt */
 728        snd_sof_dsp_update_bits(sdev, HDA_DSP_HDA_BAR,
 729                                SOF_HDA_INTCTL,
 730                                SOF_HDA_INT_GLOBAL_EN,
 731                                SOF_HDA_INT_GLOBAL_EN);
 732
 733        return IRQ_HANDLED;
 734}
 735
 736int hda_dsp_probe(struct snd_sof_dev *sdev)
 737{
 738        struct pci_dev *pci = to_pci_dev(sdev->dev);
 739        struct sof_intel_hda_dev *hdev;
 740        struct hdac_bus *bus;
 741        const struct sof_intel_dsp_desc *chip;
 742        int ret = 0;
 743
 744        /*
 745         * detect DSP by checking class/subclass/prog-id information
 746         * class=04 subclass 03 prog-if 00: no DSP, legacy driver is required
 747         * class=04 subclass 01 prog-if 00: DSP is present
 748         *   (and may be required e.g. for DMIC or SSP support)
 749         * class=04 subclass 03 prog-if 80: either of DSP or legacy mode works
 750         */
 751        if (pci->class == 0x040300) {
 752                dev_err(sdev->dev, "error: the DSP is not enabled on this platform, aborting probe\n");
 753                return -ENODEV;
 754        } else if (pci->class != 0x040100 && pci->class != 0x040380) {
 755                dev_err(sdev->dev, "error: unknown PCI class/subclass/prog-if 0x%06x found, aborting probe\n", pci->class);
 756                return -ENODEV;
 757        }
 758        dev_info(sdev->dev, "DSP detected with PCI class/subclass/prog-if 0x%06x\n", pci->class);
 759
 760        chip = get_chip_info(sdev->pdata);
 761        if (!chip) {
 762                dev_err(sdev->dev, "error: no such device supported, chip id:%x\n",
 763                        pci->device);
 764                ret = -EIO;
 765                goto err;
 766        }
 767
 768        hdev = devm_kzalloc(sdev->dev, sizeof(*hdev), GFP_KERNEL);
 769        if (!hdev)
 770                return -ENOMEM;
 771        sdev->pdata->hw_pdata = hdev;
 772        hdev->desc = chip;
 773
 774        hdev->dmic_dev = platform_device_register_data(sdev->dev, "dmic-codec",
 775                                                       PLATFORM_DEVID_NONE,
 776                                                       NULL, 0);
 777        if (IS_ERR(hdev->dmic_dev)) {
 778                dev_err(sdev->dev, "error: failed to create DMIC device\n");
 779                return PTR_ERR(hdev->dmic_dev);
 780        }
 781
 782        /*
 783         * use position update IPC if either it is forced
 784         * or we don't have other choice
 785         */
 786#if IS_ENABLED(CONFIG_SND_SOC_SOF_DEBUG_FORCE_IPC_POSITION)
 787        hdev->no_ipc_position = 0;
 788#else
 789        hdev->no_ipc_position = sof_ops(sdev)->pcm_pointer ? 1 : 0;
 790#endif
 791
 792        /* set up HDA base */
 793        bus = sof_to_bus(sdev);
 794        ret = hda_init(sdev);
 795        if (ret < 0)
 796                goto hdac_bus_unmap;
 797
 798        /* DSP base */
 799        sdev->bar[HDA_DSP_BAR] = pci_ioremap_bar(pci, HDA_DSP_BAR);
 800        if (!sdev->bar[HDA_DSP_BAR]) {
 801                dev_err(sdev->dev, "error: ioremap error\n");
 802                ret = -ENXIO;
 803                goto hdac_bus_unmap;
 804        }
 805
 806        sdev->mmio_bar = HDA_DSP_BAR;
 807        sdev->mailbox_bar = HDA_DSP_BAR;
 808
 809        /* allow 64bit DMA address if supported by H/W */
 810        if (dma_set_mask_and_coherent(&pci->dev, DMA_BIT_MASK(64))) {
 811                dev_dbg(sdev->dev, "DMA mask is 32 bit\n");
 812                dma_set_mask_and_coherent(&pci->dev, DMA_BIT_MASK(32));
 813        }
 814
 815        /* init streams */
 816        ret = hda_dsp_stream_init(sdev);
 817        if (ret < 0) {
 818                dev_err(sdev->dev, "error: failed to init streams\n");
 819                /*
 820                 * not all errors are due to memory issues, but trying
 821                 * to free everything does not harm
 822                 */
 823                goto free_streams;
 824        }
 825
 826        /*
 827         * register our IRQ
 828         * let's try to enable msi firstly
 829         * if it fails, use legacy interrupt mode
 830         * TODO: support msi multiple vectors
 831         */
 832        if (hda_use_msi && pci_alloc_irq_vectors(pci, 1, 1, PCI_IRQ_MSI) > 0) {
 833                dev_info(sdev->dev, "use msi interrupt mode\n");
 834                sdev->ipc_irq = pci_irq_vector(pci, 0);
 835                /* initialised to "false" by kzalloc() */
 836                sdev->msi_enabled = true;
 837        }
 838
 839        if (!sdev->msi_enabled) {
 840                dev_info(sdev->dev, "use legacy interrupt mode\n");
 841                /*
 842                 * in IO-APIC mode, hda->irq and ipc_irq are using the same
 843                 * irq number of pci->irq
 844                 */
 845                sdev->ipc_irq = pci->irq;
 846        }
 847
 848        dev_dbg(sdev->dev, "using IPC IRQ %d\n", sdev->ipc_irq);
 849        ret = request_threaded_irq(sdev->ipc_irq, hda_dsp_interrupt_handler,
 850                                   hda_dsp_interrupt_thread,
 851                                   IRQF_SHARED, "AudioDSP", sdev);
 852        if (ret < 0) {
 853                dev_err(sdev->dev, "error: failed to register IPC IRQ %d\n",
 854                        sdev->ipc_irq);
 855                goto free_irq_vector;
 856        }
 857
 858        pci_set_master(pci);
 859        synchronize_irq(pci->irq);
 860
 861        /*
 862         * clear TCSEL to clear playback on some HD Audio
 863         * codecs. PCI TCSEL is defined in the Intel manuals.
 864         */
 865        snd_sof_pci_update_bits(sdev, PCI_TCSEL, 0x07, 0);
 866
 867        /* init HDA capabilities */
 868        ret = hda_init_caps(sdev);
 869        if (ret < 0)
 870                goto free_ipc_irq;
 871
 872        /* enable ppcap interrupt */
 873        hda_dsp_ctrl_ppcap_enable(sdev, true);
 874        hda_dsp_ctrl_ppcap_int_enable(sdev, true);
 875
 876        /* set default mailbox offset for FW ready message */
 877        sdev->dsp_box.offset = HDA_DSP_MBOX_UPLINK_OFFSET;
 878
 879        INIT_DELAYED_WORK(&hdev->d0i3_work, hda_dsp_d0i3_work);
 880
 881        return 0;
 882
 883free_ipc_irq:
 884        free_irq(sdev->ipc_irq, sdev);
 885free_irq_vector:
 886        if (sdev->msi_enabled)
 887                pci_free_irq_vectors(pci);
 888free_streams:
 889        hda_dsp_stream_free(sdev);
 890/* dsp_unmap: not currently used */
 891        iounmap(sdev->bar[HDA_DSP_BAR]);
 892hdac_bus_unmap:
 893        platform_device_unregister(hdev->dmic_dev);
 894        iounmap(bus->remap_addr);
 895        hda_codec_i915_exit(sdev);
 896err:
 897        return ret;
 898}
 899
 900int hda_dsp_remove(struct snd_sof_dev *sdev)
 901{
 902        struct sof_intel_hda_dev *hda = sdev->pdata->hw_pdata;
 903        struct hdac_bus *bus = sof_to_bus(sdev);
 904        struct pci_dev *pci = to_pci_dev(sdev->dev);
 905        const struct sof_intel_dsp_desc *chip = hda->desc;
 906
 907        /* cancel any attempt for DSP D0I3 */
 908        cancel_delayed_work_sync(&hda->d0i3_work);
 909
 910#if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA)
 911        /* codec removal, invoke bus_device_remove */
 912        snd_hdac_ext_bus_device_remove(bus);
 913#endif
 914
 915        hda_sdw_exit(sdev);
 916
 917        if (!IS_ERR_OR_NULL(hda->dmic_dev))
 918                platform_device_unregister(hda->dmic_dev);
 919
 920        /* disable DSP IRQ */
 921        snd_sof_dsp_update_bits(sdev, HDA_DSP_PP_BAR, SOF_HDA_REG_PP_PPCTL,
 922                                SOF_HDA_PPCTL_PIE, 0);
 923
 924        /* disable CIE and GIE interrupts */
 925        snd_sof_dsp_update_bits(sdev, HDA_DSP_HDA_BAR, SOF_HDA_INTCTL,
 926                                SOF_HDA_INT_CTRL_EN | SOF_HDA_INT_GLOBAL_EN, 0);
 927
 928        /* disable cores */
 929        if (chip)
 930                snd_sof_dsp_core_power_down(sdev, chip->host_managed_cores_mask);
 931
 932        /* disable DSP */
 933        snd_sof_dsp_update_bits(sdev, HDA_DSP_PP_BAR, SOF_HDA_REG_PP_PPCTL,
 934                                SOF_HDA_PPCTL_GPROCEN, 0);
 935
 936        free_irq(sdev->ipc_irq, sdev);
 937        if (sdev->msi_enabled)
 938                pci_free_irq_vectors(pci);
 939
 940        hda_dsp_stream_free(sdev);
 941#if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA)
 942        snd_hdac_link_free_all(bus);
 943#endif
 944
 945        iounmap(sdev->bar[HDA_DSP_BAR]);
 946        iounmap(bus->remap_addr);
 947
 948#if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA)
 949        snd_hdac_ext_bus_exit(bus);
 950#endif
 951        hda_codec_i915_exit(sdev);
 952
 953        return 0;
 954}
 955
 956#if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA)
 957static int hda_generic_machine_select(struct snd_sof_dev *sdev)
 958{
 959        struct hdac_bus *bus = sof_to_bus(sdev);
 960        struct snd_soc_acpi_mach_params *mach_params;
 961        struct snd_soc_acpi_mach *hda_mach;
 962        struct snd_sof_pdata *pdata = sdev->pdata;
 963        const char *tplg_filename;
 964        const char *idisp_str;
 965        int dmic_num = 0;
 966        int codec_num = 0;
 967        int ret;
 968        int i;
 969
 970        /* codec detection */
 971        if (!bus->codec_mask) {
 972                dev_info(bus->dev, "no hda codecs found!\n");
 973        } else {
 974                dev_info(bus->dev, "hda codecs found, mask %lx\n",
 975                         bus->codec_mask);
 976
 977                for (i = 0; i < HDA_MAX_CODECS; i++) {
 978                        if (bus->codec_mask & (1 << i))
 979                                codec_num++;
 980                }
 981
 982                /*
 983                 * If no machine driver is found, then:
 984                 *
 985                 * generic hda machine driver can handle:
 986                 *  - one HDMI codec, and/or
 987                 *  - one external HDAudio codec
 988                 */
 989                if (!pdata->machine && codec_num <= 2) {
 990                        hda_mach = snd_soc_acpi_intel_hda_machines;
 991
 992                        dev_info(bus->dev, "using HDA machine driver %s now\n",
 993                                 hda_mach->drv_name);
 994
 995                        if (codec_num == 1 && HDA_IDISP_CODEC(bus->codec_mask))
 996                                idisp_str = "-idisp";
 997                        else
 998                                idisp_str = "";
 999
1000                        /* topology: use the info from hda_machines */
1001                        tplg_filename = hda_mach->sof_tplg_filename;
1002                        ret = dmic_topology_fixup(sdev, &tplg_filename, idisp_str, &dmic_num);
1003                        if (ret < 0)
1004                                return ret;
1005
1006                        hda_mach->mach_params.dmic_num = dmic_num;
1007                        pdata->machine = hda_mach;
1008                        pdata->tplg_filename = tplg_filename;
1009
1010                        if (codec_num == 2) {
1011                                /*
1012                                 * Prevent SoundWire links from starting when an external
1013                                 * HDaudio codec is used
1014                                 */
1015                                hda_mach->mach_params.link_mask = 0;
1016                        }
1017                }
1018        }
1019
1020        /* used by hda machine driver to create dai links */
1021        if (pdata->machine) {
1022                mach_params = (struct snd_soc_acpi_mach_params *)
1023                        &pdata->machine->mach_params;
1024                mach_params->codec_mask = bus->codec_mask;
1025                mach_params->common_hdmi_codec_drv = hda_codec_use_common_hdmi;
1026        }
1027
1028        return 0;
1029}
1030#else
1031static int hda_generic_machine_select(struct snd_sof_dev *sdev)
1032{
1033        return 0;
1034}
1035#endif
1036
1037#if IS_ENABLED(CONFIG_SND_SOC_SOF_INTEL_SOUNDWIRE)
1038/* Check if all Slaves defined on the link can be found */
1039static bool link_slaves_found(struct snd_sof_dev *sdev,
1040                              const struct snd_soc_acpi_link_adr *link,
1041                              struct sdw_intel_ctx *sdw)
1042{
1043        struct hdac_bus *bus = sof_to_bus(sdev);
1044        struct sdw_intel_slave_id *ids = sdw->ids;
1045        int num_slaves = sdw->num_slaves;
1046        unsigned int part_id, link_id, unique_id, mfg_id;
1047        int i, j, k;
1048
1049        for (i = 0; i < link->num_adr; i++) {
1050                u64 adr = link->adr_d[i].adr;
1051                int reported_part_count = 0;
1052
1053                mfg_id = SDW_MFG_ID(adr);
1054                part_id = SDW_PART_ID(adr);
1055                link_id = SDW_DISCO_LINK_ID(adr);
1056
1057                for (j = 0; j < num_slaves; j++) {
1058                        /* find out how many identical parts were reported on that link */
1059                        if (ids[j].link_id == link_id &&
1060                            ids[j].id.part_id == part_id &&
1061                            ids[j].id.mfg_id == mfg_id)
1062                                reported_part_count++;
1063                }
1064
1065                for (j = 0; j < num_slaves; j++) {
1066                        int expected_part_count = 0;
1067
1068                        if (ids[j].link_id != link_id ||
1069                            ids[j].id.part_id != part_id ||
1070                            ids[j].id.mfg_id != mfg_id)
1071                                continue;
1072
1073                        /* find out how many identical parts are expected */
1074                        for (k = 0; k < link->num_adr; k++) {
1075                                u64 adr2 = link->adr_d[k].adr;
1076                                unsigned int part_id2, link_id2, mfg_id2;
1077
1078                                mfg_id2 = SDW_MFG_ID(adr2);
1079                                part_id2 = SDW_PART_ID(adr2);
1080                                link_id2 = SDW_DISCO_LINK_ID(adr2);
1081
1082                                if (link_id2 == link_id &&
1083                                    part_id2 == part_id &&
1084                                    mfg_id2 == mfg_id)
1085                                        expected_part_count++;
1086                        }
1087
1088                        if (reported_part_count == expected_part_count) {
1089                                /*
1090                                 * we have to check unique id
1091                                 * if there is more than one
1092                                 * Slave on the link
1093                                 */
1094                                unique_id = SDW_UNIQUE_ID(adr);
1095                                if (reported_part_count == 1 ||
1096                                    ids[j].id.unique_id == unique_id) {
1097                                        dev_dbg(bus->dev, "found %x at link %d\n",
1098                                                part_id, link_id);
1099                                        break;
1100                                }
1101                        } else {
1102                                dev_dbg(bus->dev, "part %x reported %d expected %d on link %d, skipping\n",
1103                                        part_id, reported_part_count, expected_part_count, link_id);
1104                        }
1105                }
1106                if (j == num_slaves) {
1107                        dev_dbg(bus->dev,
1108                                "Slave %x not found\n",
1109                                part_id);
1110                        return false;
1111                }
1112        }
1113        return true;
1114}
1115
1116static int hda_sdw_machine_select(struct snd_sof_dev *sdev)
1117{
1118        struct snd_sof_pdata *pdata = sdev->pdata;
1119        const struct snd_soc_acpi_link_adr *link;
1120        struct snd_soc_acpi_mach *mach;
1121        struct sof_intel_hda_dev *hdev;
1122        u32 link_mask;
1123        int i;
1124
1125        hdev = pdata->hw_pdata;
1126        link_mask = hdev->info.link_mask;
1127
1128        /*
1129         * Select SoundWire machine driver if needed using the
1130         * alternate tables. This case deals with SoundWire-only
1131         * machines, for mixed cases with I2C/I2S the detection relies
1132         * on the HID list.
1133         */
1134        if (link_mask && !pdata->machine) {
1135                for (mach = pdata->desc->alt_machines;
1136                     mach && mach->link_mask; mach++) {
1137                        /*
1138                         * On some platforms such as Up Extreme all links
1139                         * are enabled but only one link can be used by
1140                         * external codec. Instead of exact match of two masks,
1141                         * first check whether link_mask of mach is subset of
1142                         * link_mask supported by hw and then go on searching
1143                         * link_adr
1144                         */
1145                        if (~link_mask & mach->link_mask)
1146                                continue;
1147
1148                        /* No need to match adr if there is no links defined */
1149                        if (!mach->links)
1150                                break;
1151
1152                        link = mach->links;
1153                        for (i = 0; i < hdev->info.count && link->num_adr;
1154                             i++, link++) {
1155                                /*
1156                                 * Try next machine if any expected Slaves
1157                                 * are not found on this link.
1158                                 */
1159                                if (!link_slaves_found(sdev, link, hdev->sdw))
1160                                        break;
1161                        }
1162                        /* Found if all Slaves are checked */
1163                        if (i == hdev->info.count || !link->num_adr)
1164                                break;
1165                }
1166                if (mach && mach->link_mask) {
1167                        int dmic_num = 0;
1168
1169                        pdata->machine = mach;
1170                        mach->mach_params.links = mach->links;
1171                        mach->mach_params.link_mask = mach->link_mask;
1172                        mach->mach_params.platform = dev_name(sdev->dev);
1173                        if (mach->sof_fw_filename)
1174                                pdata->fw_filename = mach->sof_fw_filename;
1175                        else
1176                                pdata->fw_filename = pdata->desc->default_fw_filename;
1177                        pdata->tplg_filename = mach->sof_tplg_filename;
1178
1179                        /*
1180                         * DMICs use up to 4 pins and are typically pin-muxed with SoundWire
1181                         * link 2 and 3, thus we only try to enable dmics if all conditions
1182                         * are true:
1183                         * a) link 2 and 3 are not used by SoundWire
1184                         * b) the NHLT table reports the presence of microphones
1185                         */
1186                        if (!(mach->link_mask & GENMASK(3, 2))) {
1187                                const char *tplg_filename = mach->sof_tplg_filename;
1188                                int ret;
1189
1190                                ret = dmic_topology_fixup(sdev, &tplg_filename, "", &dmic_num);
1191
1192                                if (ret < 0)
1193                                        return ret;
1194
1195                                pdata->tplg_filename = tplg_filename;
1196                        }
1197                        mach->mach_params.dmic_num = dmic_num;
1198
1199                        dev_dbg(sdev->dev,
1200                                "SoundWire machine driver %s topology %s\n",
1201                                mach->drv_name,
1202                                pdata->tplg_filename);
1203                } else {
1204                        dev_info(sdev->dev,
1205                                 "No SoundWire machine driver found\n");
1206                }
1207        }
1208
1209        return 0;
1210}
1211#else
1212static int hda_sdw_machine_select(struct snd_sof_dev *sdev)
1213{
1214        return 0;
1215}
1216#endif
1217
1218void hda_set_mach_params(const struct snd_soc_acpi_mach *mach,
1219                         struct snd_sof_dev *sdev)
1220{
1221        struct snd_sof_pdata *pdata = sdev->pdata;
1222        const struct sof_dev_desc *desc = pdata->desc;
1223        struct snd_soc_acpi_mach_params *mach_params;
1224
1225        mach_params = (struct snd_soc_acpi_mach_params *)&mach->mach_params;
1226        mach_params->platform = dev_name(sdev->dev);
1227        mach_params->num_dai_drivers = desc->ops->num_drv;
1228        mach_params->dai_drivers = desc->ops->drv;
1229}
1230
1231void hda_machine_select(struct snd_sof_dev *sdev)
1232{
1233        struct snd_sof_pdata *sof_pdata = sdev->pdata;
1234        const struct sof_dev_desc *desc = sof_pdata->desc;
1235        struct snd_soc_acpi_mach *mach;
1236
1237        mach = snd_soc_acpi_find_machine(desc->machines);
1238        if (mach) {
1239                /*
1240                 * If tplg file name is overridden, use it instead of
1241                 * the one set in mach table
1242                 */
1243                if (!sof_pdata->tplg_filename)
1244                        sof_pdata->tplg_filename = mach->sof_tplg_filename;
1245
1246                sof_pdata->machine = mach;
1247
1248                if (mach->link_mask) {
1249                        mach->mach_params.links = mach->links;
1250                        mach->mach_params.link_mask = mach->link_mask;
1251                }
1252        }
1253
1254        /*
1255         * If I2S fails, try SoundWire
1256         */
1257        hda_sdw_machine_select(sdev);
1258
1259        /*
1260         * Choose HDA generic machine driver if mach is NULL.
1261         * Otherwise, set certain mach params.
1262         */
1263        hda_generic_machine_select(sdev);
1264
1265        if (!sof_pdata->machine)
1266                dev_warn(sdev->dev, "warning: No matching ASoC machine driver found\n");
1267}
1268
1269int hda_pci_intel_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
1270{
1271        int ret;
1272
1273        ret = snd_intel_dsp_driver_probe(pci);
1274        if (ret != SND_INTEL_DSP_DRIVER_ANY && ret != SND_INTEL_DSP_DRIVER_SOF) {
1275                dev_dbg(&pci->dev, "SOF PCI driver not selected, aborting probe\n");
1276                return -ENODEV;
1277        }
1278
1279        return sof_pci_probe(pci, pci_id);
1280}
1281EXPORT_SYMBOL_NS(hda_pci_intel_probe, SND_SOC_SOF_INTEL_HDA_COMMON);
1282
1283MODULE_LICENSE("Dual BSD/GPL");
1284MODULE_IMPORT_NS(SND_SOC_SOF_PCI_DEV);
1285MODULE_IMPORT_NS(SND_SOC_SOF_HDA_AUDIO_CODEC);
1286MODULE_IMPORT_NS(SND_SOC_SOF_HDA_AUDIO_CODEC_I915);
1287MODULE_IMPORT_NS(SND_SOC_SOF_XTENSA);
1288MODULE_IMPORT_NS(SND_INTEL_SOUNDWIRE_ACPI);
1289MODULE_IMPORT_NS(SOUNDWIRE_INTEL_INIT);
1290