linux/sound/soc/sof/sof-acpi-dev.c
<<
>>
Prefs
   1// SPDX-License-Identifier: (GPL-2.0 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// Author: Liam Girdwood <liam.r.girdwood@linux.intel.com>
   9//
  10
  11#include <linux/acpi.h>
  12#include <linux/firmware.h>
  13#include <linux/module.h>
  14#include <linux/pm_runtime.h>
  15#include <sound/soc-acpi.h>
  16#include <sound/soc-acpi-intel-match.h>
  17#include <sound/sof.h>
  18#include "../intel/common/soc-intel-quirks.h"
  19#include "ops.h"
  20
  21/* platform specific devices */
  22#include "intel/shim.h"
  23
  24static char *fw_path;
  25module_param(fw_path, charp, 0444);
  26MODULE_PARM_DESC(fw_path, "alternate path for SOF firmware.");
  27
  28static char *tplg_path;
  29module_param(tplg_path, charp, 0444);
  30MODULE_PARM_DESC(tplg_path, "alternate path for SOF topology.");
  31
  32#if IS_ENABLED(CONFIG_SND_SOC_SOF_HASWELL)
  33static const struct sof_dev_desc sof_acpi_haswell_desc = {
  34        .machines = snd_soc_acpi_intel_haswell_machines,
  35        .resindex_lpe_base = 0,
  36        .resindex_pcicfg_base = 1,
  37        .resindex_imr_base = -1,
  38        .irqindex_host_ipc = 0,
  39        .chip_info = &hsw_chip_info,
  40        .default_fw_path = "intel/sof",
  41        .default_tplg_path = "intel/sof-tplg",
  42        .nocodec_fw_filename = "sof-hsw.ri",
  43        .nocodec_tplg_filename = "sof-hsw-nocodec.tplg",
  44        .ops = &sof_hsw_ops,
  45        .arch_ops = &sof_xtensa_arch_ops
  46};
  47#endif
  48
  49#if IS_ENABLED(CONFIG_SND_SOC_SOF_BROADWELL)
  50static const struct sof_dev_desc sof_acpi_broadwell_desc = {
  51        .machines = snd_soc_acpi_intel_broadwell_machines,
  52        .resindex_lpe_base = 0,
  53        .resindex_pcicfg_base = 1,
  54        .resindex_imr_base = -1,
  55        .irqindex_host_ipc = 0,
  56        .chip_info = &bdw_chip_info,
  57        .default_fw_path = "intel/sof",
  58        .default_tplg_path = "intel/sof-tplg",
  59        .nocodec_fw_filename = "sof-bdw.ri",
  60        .nocodec_tplg_filename = "sof-bdw-nocodec.tplg",
  61        .ops = &sof_bdw_ops,
  62        .arch_ops = &sof_xtensa_arch_ops
  63};
  64#endif
  65
  66#if IS_ENABLED(CONFIG_SND_SOC_SOF_BAYTRAIL)
  67
  68/* BYTCR uses different IRQ index */
  69static const struct sof_dev_desc sof_acpi_baytrailcr_desc = {
  70        .machines = snd_soc_acpi_intel_baytrail_machines,
  71        .resindex_lpe_base = 0,
  72        .resindex_pcicfg_base = 1,
  73        .resindex_imr_base = 2,
  74        .irqindex_host_ipc = 0,
  75        .chip_info = &byt_chip_info,
  76        .default_fw_path = "intel/sof",
  77        .default_tplg_path = "intel/sof-tplg",
  78        .nocodec_fw_filename = "sof-byt.ri",
  79        .nocodec_tplg_filename = "sof-byt-nocodec.tplg",
  80        .ops = &sof_byt_ops,
  81        .arch_ops = &sof_xtensa_arch_ops
  82};
  83
  84static const struct sof_dev_desc sof_acpi_baytrail_desc = {
  85        .machines = snd_soc_acpi_intel_baytrail_machines,
  86        .resindex_lpe_base = 0,
  87        .resindex_pcicfg_base = 1,
  88        .resindex_imr_base = 2,
  89        .irqindex_host_ipc = 5,
  90        .chip_info = &byt_chip_info,
  91        .default_fw_path = "intel/sof",
  92        .default_tplg_path = "intel/sof-tplg",
  93        .nocodec_fw_filename = "sof-byt.ri",
  94        .nocodec_tplg_filename = "sof-byt-nocodec.tplg",
  95        .ops = &sof_byt_ops,
  96        .arch_ops = &sof_xtensa_arch_ops
  97};
  98
  99static const struct sof_dev_desc sof_acpi_cherrytrail_desc = {
 100        .machines = snd_soc_acpi_intel_cherrytrail_machines,
 101        .resindex_lpe_base = 0,
 102        .resindex_pcicfg_base = 1,
 103        .resindex_imr_base = 2,
 104        .irqindex_host_ipc = 5,
 105        .chip_info = &cht_chip_info,
 106        .default_fw_path = "intel/sof",
 107        .default_tplg_path = "intel/sof-tplg",
 108        .nocodec_fw_filename = "sof-cht.ri",
 109        .nocodec_tplg_filename = "sof-cht-nocodec.tplg",
 110        .ops = &sof_cht_ops,
 111        .arch_ops = &sof_xtensa_arch_ops
 112};
 113
 114#endif
 115
 116static const struct dev_pm_ops sof_acpi_pm = {
 117        SET_SYSTEM_SLEEP_PM_OPS(snd_sof_suspend, snd_sof_resume)
 118        SET_RUNTIME_PM_OPS(snd_sof_runtime_suspend, snd_sof_runtime_resume,
 119                           snd_sof_runtime_idle)
 120};
 121
 122static void sof_acpi_probe_complete(struct device *dev)
 123{
 124        /* allow runtime_pm */
 125        pm_runtime_set_autosuspend_delay(dev, SND_SOF_SUSPEND_DELAY_MS);
 126        pm_runtime_use_autosuspend(dev);
 127        pm_runtime_enable(dev);
 128}
 129
 130static int sof_acpi_probe(struct platform_device *pdev)
 131{
 132        struct device *dev = &pdev->dev;
 133        const struct sof_dev_desc *desc;
 134        struct snd_soc_acpi_mach *mach;
 135        struct snd_sof_pdata *sof_pdata;
 136        const struct snd_sof_dsp_ops *ops;
 137        int ret;
 138
 139        dev_dbg(&pdev->dev, "ACPI DSP detected");
 140
 141        sof_pdata = devm_kzalloc(dev, sizeof(*sof_pdata), GFP_KERNEL);
 142        if (!sof_pdata)
 143                return -ENOMEM;
 144
 145        desc = device_get_match_data(dev);
 146        if (!desc)
 147                return -ENODEV;
 148
 149#if IS_ENABLED(CONFIG_SND_SOC_SOF_BAYTRAIL)
 150        if (desc == &sof_acpi_baytrail_desc && soc_intel_is_byt_cr(pdev))
 151                desc = &sof_acpi_baytrailcr_desc;
 152#endif
 153
 154        /* get ops for platform */
 155        ops = desc->ops;
 156        if (!ops) {
 157                dev_err(dev, "error: no matching ACPI descriptor ops\n");
 158                return -ENODEV;
 159        }
 160
 161#if IS_ENABLED(CONFIG_SND_SOC_SOF_FORCE_NOCODEC_MODE)
 162        /* force nocodec mode */
 163        dev_warn(dev, "Force to use nocodec mode\n");
 164        mach = devm_kzalloc(dev, sizeof(*mach), GFP_KERNEL);
 165        if (!mach)
 166                return -ENOMEM;
 167        ret = sof_nocodec_setup(dev, sof_pdata, mach, desc, ops);
 168        if (ret < 0)
 169                return ret;
 170#else
 171        /* find machine */
 172        mach = snd_soc_acpi_find_machine(desc->machines);
 173        if (!mach) {
 174                dev_warn(dev, "warning: No matching ASoC machine driver found\n");
 175        } else {
 176                sof_pdata->fw_filename = mach->sof_fw_filename;
 177                sof_pdata->tplg_filename = mach->sof_tplg_filename;
 178        }
 179#endif
 180
 181        if (mach) {
 182                mach->mach_params.platform = dev_name(dev);
 183                mach->mach_params.acpi_ipc_irq_index = desc->irqindex_host_ipc;
 184        }
 185
 186        sof_pdata->machine = mach;
 187        sof_pdata->desc = desc;
 188        sof_pdata->dev = &pdev->dev;
 189        sof_pdata->platform = dev_name(dev);
 190
 191        /* alternate fw and tplg filenames ? */
 192        if (fw_path)
 193                sof_pdata->fw_filename_prefix = fw_path;
 194        else
 195                sof_pdata->fw_filename_prefix =
 196                        sof_pdata->desc->default_fw_path;
 197
 198        if (tplg_path)
 199                sof_pdata->tplg_filename_prefix = tplg_path;
 200        else
 201                sof_pdata->tplg_filename_prefix =
 202                        sof_pdata->desc->default_tplg_path;
 203
 204#if IS_ENABLED(CONFIG_SND_SOC_SOF_PROBE_WORK_QUEUE)
 205        /* set callback to enable runtime_pm */
 206        sof_pdata->sof_probe_complete = sof_acpi_probe_complete;
 207#endif
 208        /* call sof helper for DSP hardware probe */
 209        ret = snd_sof_device_probe(dev, sof_pdata);
 210        if (ret) {
 211                dev_err(dev, "error: failed to probe DSP hardware!\n");
 212                return ret;
 213        }
 214
 215#if !IS_ENABLED(CONFIG_SND_SOC_SOF_PROBE_WORK_QUEUE)
 216        sof_acpi_probe_complete(dev);
 217#endif
 218
 219        return ret;
 220}
 221
 222static int sof_acpi_remove(struct platform_device *pdev)
 223{
 224        pm_runtime_disable(&pdev->dev);
 225
 226        /* call sof helper for DSP hardware remove */
 227        snd_sof_device_remove(&pdev->dev);
 228
 229        return 0;
 230}
 231
 232static const struct acpi_device_id sof_acpi_match[] = {
 233#if IS_ENABLED(CONFIG_SND_SOC_SOF_HASWELL)
 234        { "INT33C8", (unsigned long)&sof_acpi_haswell_desc },
 235#endif
 236#if IS_ENABLED(CONFIG_SND_SOC_SOF_BROADWELL)
 237        { "INT3438", (unsigned long)&sof_acpi_broadwell_desc },
 238#endif
 239#if IS_ENABLED(CONFIG_SND_SOC_SOF_BAYTRAIL)
 240        { "80860F28", (unsigned long)&sof_acpi_baytrail_desc },
 241        { "808622A8", (unsigned long)&sof_acpi_cherrytrail_desc },
 242#endif
 243        { }
 244};
 245MODULE_DEVICE_TABLE(acpi, sof_acpi_match);
 246
 247/* acpi_driver definition */
 248static struct platform_driver snd_sof_acpi_driver = {
 249        .probe = sof_acpi_probe,
 250        .remove = sof_acpi_remove,
 251        .driver = {
 252                .name = "sof-audio-acpi",
 253                .pm = &sof_acpi_pm,
 254                .acpi_match_table = ACPI_PTR(sof_acpi_match),
 255        },
 256};
 257module_platform_driver(snd_sof_acpi_driver);
 258
 259MODULE_LICENSE("Dual BSD/GPL");
 260