linux/sound/soc/sof/sof-acpi-dev.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// 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/intel-dsp-config.h>
  16#include <sound/soc-acpi.h>
  17#include <sound/soc-acpi-intel-match.h>
  18#include <sound/sof.h>
  19#include "../intel/common/soc-intel-quirks.h"
  20#include "ops.h"
  21
  22/* platform specific devices */
  23#include "intel/shim.h"
  24
  25static char *fw_path;
  26module_param(fw_path, charp, 0444);
  27MODULE_PARM_DESC(fw_path, "alternate path for SOF firmware.");
  28
  29static char *tplg_path;
  30module_param(tplg_path, charp, 0444);
  31MODULE_PARM_DESC(tplg_path, "alternate path for SOF topology.");
  32
  33static int sof_acpi_debug;
  34module_param_named(sof_acpi_debug, sof_acpi_debug, int, 0444);
  35MODULE_PARM_DESC(sof_acpi_debug, "SOF ACPI debug options (0x0 all off)");
  36
  37#define SOF_ACPI_DISABLE_PM_RUNTIME BIT(0)
  38
  39#if IS_ENABLED(CONFIG_ACPI) && IS_ENABLED(CONFIG_SND_SOC_SOF_BROADWELL)
  40static const struct sof_dev_desc sof_acpi_broadwell_desc = {
  41        .machines = snd_soc_acpi_intel_broadwell_machines,
  42        .resindex_lpe_base = 0,
  43        .resindex_pcicfg_base = 1,
  44        .resindex_imr_base = -1,
  45        .irqindex_host_ipc = 0,
  46        .chip_info = &bdw_chip_info,
  47        .default_fw_path = "intel/sof",
  48        .default_tplg_path = "intel/sof-tplg",
  49        .default_fw_filename = "sof-bdw.ri",
  50        .nocodec_tplg_filename = "sof-bdw-nocodec.tplg",
  51        .ops = &sof_bdw_ops,
  52};
  53#endif
  54
  55#if IS_ENABLED(CONFIG_ACPI) && IS_ENABLED(CONFIG_SND_SOC_SOF_BAYTRAIL)
  56
  57/* BYTCR uses different IRQ index */
  58static const struct sof_dev_desc sof_acpi_baytrailcr_desc = {
  59        .machines = snd_soc_acpi_intel_baytrail_machines,
  60        .resindex_lpe_base = 0,
  61        .resindex_pcicfg_base = 1,
  62        .resindex_imr_base = 2,
  63        .irqindex_host_ipc = 0,
  64        .chip_info = &byt_chip_info,
  65        .default_fw_path = "intel/sof",
  66        .default_tplg_path = "intel/sof-tplg",
  67        .default_fw_filename = "sof-byt.ri",
  68        .nocodec_tplg_filename = "sof-byt-nocodec.tplg",
  69        .ops = &sof_byt_ops,
  70};
  71
  72static const struct sof_dev_desc sof_acpi_baytrail_desc = {
  73        .machines = snd_soc_acpi_intel_baytrail_machines,
  74        .resindex_lpe_base = 0,
  75        .resindex_pcicfg_base = 1,
  76        .resindex_imr_base = 2,
  77        .irqindex_host_ipc = 5,
  78        .chip_info = &byt_chip_info,
  79        .default_fw_path = "intel/sof",
  80        .default_tplg_path = "intel/sof-tplg",
  81        .default_fw_filename = "sof-byt.ri",
  82        .nocodec_tplg_filename = "sof-byt-nocodec.tplg",
  83        .ops = &sof_byt_ops,
  84};
  85
  86static const struct sof_dev_desc sof_acpi_cherrytrail_desc = {
  87        .machines = snd_soc_acpi_intel_cherrytrail_machines,
  88        .resindex_lpe_base = 0,
  89        .resindex_pcicfg_base = 1,
  90        .resindex_imr_base = 2,
  91        .irqindex_host_ipc = 5,
  92        .chip_info = &cht_chip_info,
  93        .default_fw_path = "intel/sof",
  94        .default_tplg_path = "intel/sof-tplg",
  95        .default_fw_filename = "sof-cht.ri",
  96        .nocodec_tplg_filename = "sof-cht-nocodec.tplg",
  97        .ops = &sof_cht_ops,
  98};
  99
 100#endif
 101
 102static const struct dev_pm_ops sof_acpi_pm = {
 103        SET_SYSTEM_SLEEP_PM_OPS(snd_sof_suspend, snd_sof_resume)
 104        SET_RUNTIME_PM_OPS(snd_sof_runtime_suspend, snd_sof_runtime_resume,
 105                           snd_sof_runtime_idle)
 106};
 107
 108static void sof_acpi_probe_complete(struct device *dev)
 109{
 110        dev_dbg(dev, "Completing SOF ACPI probe");
 111
 112        if (sof_acpi_debug & SOF_ACPI_DISABLE_PM_RUNTIME)
 113                return;
 114
 115        /* allow runtime_pm */
 116        pm_runtime_set_autosuspend_delay(dev, SND_SOF_SUSPEND_DELAY_MS);
 117        pm_runtime_use_autosuspend(dev);
 118        pm_runtime_enable(dev);
 119}
 120
 121static int sof_acpi_probe(struct platform_device *pdev)
 122{
 123        struct device *dev = &pdev->dev;
 124        const struct acpi_device_id *id;
 125        const struct sof_dev_desc *desc;
 126        struct snd_sof_pdata *sof_pdata;
 127        const struct snd_sof_dsp_ops *ops;
 128        int ret;
 129
 130        id = acpi_match_device(dev->driver->acpi_match_table, dev);
 131        if (!id)
 132                return -ENODEV;
 133
 134        if (IS_REACHABLE(CONFIG_SND_INTEL_DSP_CONFIG)) {
 135                ret = snd_intel_acpi_dsp_driver_probe(dev, id->id);
 136                if (ret != SND_INTEL_DSP_DRIVER_ANY && ret != SND_INTEL_DSP_DRIVER_SOF) {
 137                        dev_dbg(dev, "SOF ACPI driver not selected, aborting probe\n");
 138                        return -ENODEV;
 139                }
 140        }
 141        dev_dbg(dev, "ACPI DSP detected");
 142
 143        sof_pdata = devm_kzalloc(dev, sizeof(*sof_pdata), GFP_KERNEL);
 144        if (!sof_pdata)
 145                return -ENOMEM;
 146
 147        desc = device_get_match_data(dev);
 148        if (!desc)
 149                return -ENODEV;
 150
 151#if IS_ENABLED(CONFIG_ACPI) && IS_ENABLED(CONFIG_SND_SOC_SOF_BAYTRAIL)
 152        if (desc == &sof_acpi_baytrail_desc && soc_intel_is_byt_cr(pdev))
 153                desc = &sof_acpi_baytrailcr_desc;
 154#endif
 155
 156        /* get ops for platform */
 157        ops = desc->ops;
 158        if (!ops) {
 159                dev_err(dev, "error: no matching ACPI descriptor ops\n");
 160                return -ENODEV;
 161        }
 162
 163        sof_pdata->desc = desc;
 164        sof_pdata->dev = &pdev->dev;
 165        sof_pdata->fw_filename = desc->default_fw_filename;
 166
 167        /* alternate fw and tplg filenames ? */
 168        if (fw_path)
 169                sof_pdata->fw_filename_prefix = fw_path;
 170        else
 171                sof_pdata->fw_filename_prefix =
 172                        sof_pdata->desc->default_fw_path;
 173
 174        if (tplg_path)
 175                sof_pdata->tplg_filename_prefix = tplg_path;
 176        else
 177                sof_pdata->tplg_filename_prefix =
 178                        sof_pdata->desc->default_tplg_path;
 179
 180#if IS_ENABLED(CONFIG_SND_SOC_SOF_PROBE_WORK_QUEUE)
 181        /* set callback to enable runtime_pm */
 182        sof_pdata->sof_probe_complete = sof_acpi_probe_complete;
 183#endif
 184        /* call sof helper for DSP hardware probe */
 185        ret = snd_sof_device_probe(dev, sof_pdata);
 186        if (ret) {
 187                dev_err(dev, "error: failed to probe DSP hardware!\n");
 188                return ret;
 189        }
 190
 191#if !IS_ENABLED(CONFIG_SND_SOC_SOF_PROBE_WORK_QUEUE)
 192        sof_acpi_probe_complete(dev);
 193#endif
 194
 195        return ret;
 196}
 197
 198static int sof_acpi_remove(struct platform_device *pdev)
 199{
 200        if (!(sof_acpi_debug & SOF_ACPI_DISABLE_PM_RUNTIME))
 201                pm_runtime_disable(&pdev->dev);
 202
 203        /* call sof helper for DSP hardware remove */
 204        snd_sof_device_remove(&pdev->dev);
 205
 206        return 0;
 207}
 208
 209#ifdef CONFIG_ACPI
 210static const struct acpi_device_id sof_acpi_match[] = {
 211#if IS_ENABLED(CONFIG_SND_SOC_SOF_BROADWELL)
 212        { "INT3438", (unsigned long)&sof_acpi_broadwell_desc },
 213#endif
 214#if IS_ENABLED(CONFIG_SND_SOC_SOF_BAYTRAIL)
 215        { "80860F28", (unsigned long)&sof_acpi_baytrail_desc },
 216        { "808622A8", (unsigned long)&sof_acpi_cherrytrail_desc },
 217#endif
 218        { }
 219};
 220MODULE_DEVICE_TABLE(acpi, sof_acpi_match);
 221#endif
 222
 223/* acpi_driver definition */
 224static struct platform_driver snd_sof_acpi_driver = {
 225        .probe = sof_acpi_probe,
 226        .remove = sof_acpi_remove,
 227        .driver = {
 228                .name = "sof-audio-acpi",
 229                .pm = &sof_acpi_pm,
 230                .acpi_match_table = ACPI_PTR(sof_acpi_match),
 231        },
 232};
 233module_platform_driver(snd_sof_acpi_driver);
 234
 235MODULE_LICENSE("Dual BSD/GPL");
 236MODULE_IMPORT_NS(SND_SOC_SOF_BAYTRAIL);
 237MODULE_IMPORT_NS(SND_SOC_SOF_BROADWELL);
 238