Skip to content

Commit

Permalink
ASoC: SOF: hda: refine to support both with/without HDA links.
Browse files Browse the repository at this point in the history
We uses CONFIG_SND_SOC_SOF_HDA to enable HDA links on SOF, here refine
SOF HDA code to split them and make both select/unselect the config
CONFIG_SND_SOC_SOF_HDA works.

Signed-off-by: Keyon Jie <[email protected]>
  • Loading branch information
keyonjie committed Jul 27, 2018
1 parent 3ea24e9 commit bd37bda
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 71 deletions.
7 changes: 5 additions & 2 deletions sound/soc/sof/intel/hda-codec.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
* This file is provided under a dual BSD/GPLv2 license. When using or
* redistributing this file, you may do so under either license.
*
* Copyright(c) 2017 Intel Corporation. All rights reserved.
* Copyright(c) 2018 Intel Corporation. All rights reserved.
*
* Authors: Jeeja KP <[email protected]>
* Keyon Jie <[email protected]>
Expand All @@ -22,7 +22,6 @@
#include <sound/hda_i915.h>
#include <sound/hda_register.h>
#include <sound/hdaudio.h>
#include <sound/hda_i915.h>

#include "../../../pci/hda/hda_codec.h"
#include "../../codecs/hdac_hda.h"
Expand Down Expand Up @@ -112,6 +111,7 @@ int hda_codec_probe_bus(struct snd_sof_dev *sdev)

return 0;
}
EXPORT_SYMBOL(hda_codec_probe_bus);

int hda_codec_i915_init(struct snd_sof_dev *sdev)
{
Expand All @@ -129,4 +129,7 @@ int hda_codec_i915_init(struct snd_sof_dev *sdev)

return ret;
}
EXPORT_SYMBOL(hda_codec_i915_init);

MODULE_LICENSE("Dual BSD/GPL");

30 changes: 21 additions & 9 deletions sound/soc/sof/intel/hda-ctrl.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,9 @@ int hda_dsp_ctrl_link_reset(struct snd_sof_dev *sdev)

int hda_dsp_ctrl_get_caps(struct snd_sof_dev *sdev)
{
struct hdac_bus *bus = sof_to_bus(sdev);
u32 cap, offset, feature;
int ret = -ENODEV, count = 0;
int count = 0;

offset = snd_sof_dsp_read(sdev, HDA_DSP_HDA_BAR, SOF_HDA_LLCH);

Expand All @@ -103,21 +104,30 @@ int hda_dsp_ctrl_get_caps(struct snd_sof_dev *sdev)
case SOF_HDA_PP_CAP_ID:
dev_dbg(sdev->dev, "found DSP capability at 0x%x\n",
offset);
sdev->bar[HDA_DSP_PP_BAR] = sdev->bar[HDA_DSP_HDA_BAR] +
offset;
ret = 0;
bus->ppcap = bus->remap_addr + offset;
sdev->bar[HDA_DSP_PP_BAR] = bus->ppcap;
break;
case SOF_HDA_SPIB_CAP_ID:
dev_dbg(sdev->dev, "found SPIB capability at 0x%x\n",
offset);
sdev->bar[HDA_DSP_SPIB_BAR] =
sdev->bar[HDA_DSP_HDA_BAR] + offset;
bus->spbcap = bus->remap_addr + offset;
sdev->bar[HDA_DSP_SPIB_BAR] = bus->spbcap;
break;
case SOF_HDA_DRSM_CAP_ID:
dev_dbg(sdev->dev, "found DRSM capability at 0x%x\n",
offset);
sdev->bar[HDA_DSP_DRSM_BAR] =
sdev->bar[HDA_DSP_HDA_BAR] + offset;
bus->drsmcap = bus->remap_addr + offset;
sdev->bar[HDA_DSP_DRSM_BAR] = bus->drsmcap;
break;
case SOF_HDA_GTS_CAP_ID:
dev_dbg(sdev->dev, "found GTS capability at 0x%x\n",
offset);
bus->gtscap = bus->remap_addr + offset;
break;
case SOF_HDA_ML_CAP_ID:
dev_dbg(sdev->dev, "found ML capability at 0x%x\n",
offset);
bus->mlcap = bus->remap_addr + offset;
break;
default:
dev_vdbg(sdev->dev, "found capability %d at 0x%x\n",
Expand All @@ -128,7 +138,7 @@ int hda_dsp_ctrl_get_caps(struct snd_sof_dev *sdev)
offset = cap & SOF_HDA_CAP_NEXT_MASK;
} while (count++ <= SOF_HDA_MAX_CAPS && offset);

return ret;
return 0;
}

void hda_dsp_ctrl_enable_miscbdcge(struct snd_sof_dev *sdev, bool enable)
Expand All @@ -138,6 +148,7 @@ void hda_dsp_ctrl_enable_miscbdcge(struct snd_sof_dev *sdev, bool enable)
snd_sof_pci_update_bits(sdev, PCI_CGCTL, PCI_CGCTL_MISCBDCGE_MASK, val);
}

#if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA)
/*
* While performing reset, controller may not come back properly causing
* issues, so recommendation is to set CGCTL.MISCBDCGE to 0 then do reset
Expand All @@ -154,4 +165,5 @@ int hda_dsp_ctrl_init_chip(struct snd_sof_dev *sdev, bool full_reset)

return ret;
}
#endif

5 changes: 3 additions & 2 deletions sound/soc/sof/intel/hda-stream.c
Original file line number Diff line number Diff line change
Expand Up @@ -475,6 +475,7 @@ irqreturn_t hda_dsp_stream_interrupt(int irq, void *context)
return IRQ_NONE;
}

#if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA)
/* clear rirb int */
status = snd_sof_dsp_read(sdev, HDA_DSP_HDA_BAR, SOF_HDA_RIRBSTS);
if (status & RIRB_INT_MASK) {
Expand All @@ -483,11 +484,12 @@ irqreturn_t hda_dsp_stream_interrupt(int irq, void *context)
snd_sof_dsp_write(sdev, HDA_DSP_HDA_BAR, SOF_HDA_RIRBSTS,
RIRB_INT_MASK);
}
#endif

spin_unlock(&bus->reg_lock);

return snd_sof_dsp_read(sdev, HDA_DSP_HDA_BAR, SOF_HDA_INTSTS)
? IRQ_WAKE_THREAD : IRQ_HANDLED;
& SOF_HDA_INT_ALL_STREAM ? IRQ_WAKE_THREAD : IRQ_HANDLED;
}

irqreturn_t hda_dsp_stream_threaded_handler(int irq, void *context)
Expand Down Expand Up @@ -579,7 +581,6 @@ int hda_dsp_stream_init(struct snd_sof_dev *sdev)
return -ENOMEM;
}


/* mem alloc for the CORB/RIRB ringbuffers */
ret = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, &pci->dev,
PAGE_SIZE, &bus->rb);
Expand Down
70 changes: 12 additions & 58 deletions sound/soc/sof/intel/hda.c
Original file line number Diff line number Diff line change
Expand Up @@ -306,38 +306,13 @@ static const struct sof_intel_dsp_desc *get_chip_info(int pci_id)
return NULL;
}

#if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA)

#if 0
static int sof_hda_acquire_irq(struct hda_bus *hbus, int do_disconnect)
{
int ret;

/* register our IRQ */
ret = request_threaded_irq(hbus->pci->irq, sof_hda_stream_interrupt,
sof_hda_stream_threaded_handler,
IRQF_SHARED, "SOFHDA", &hbus->core);

if (ret) {
dev_err(hbus->core.dev,
"unable to grab IRQ %d, disabling device\n",
hbus->pci->irq);
return ret;
}

hbus->core.irq = hbus->pci->irq;
pci_intx(hbus->pci, 1);

return 0;
}
#endif

static int hda_init(struct snd_sof_dev *sdev)
{
struct hda_bus *hbus;
struct hdac_bus *bus;
struct hdac_ext_bus_ops *ext_ops;
struct hdac_ext_bus_ops *ext_ops = NULL;
struct pci_dev *pci = sdev->pci;
int ret;

hbus = sof_to_hbus(sdev);
bus = sof_to_bus(sdev);
Expand All @@ -346,7 +321,7 @@ static int hda_init(struct snd_sof_dev *sdev)
#if IS_ENABLED(CONFIG_SND_SOC_HDAC_HDA)
ext_ops = snd_soc_hdac_hda_get_ops();
#endif
snd_hdac_ext_bus_init(bus, &pci->dev, NULL, NULL, ext_ops);
sof_hda_bus_init(bus, &pci->dev, ext_ops);
bus->use_posbuf = 1;
bus->bdl_pos_adj = 0;

Expand All @@ -363,20 +338,19 @@ static int hda_init(struct snd_sof_dev *sdev)
return -ENXIO;
}

// FIXME: we do this alot !
hda_dsp_ctrl_init_chip(sdev, true);

snd_hdac_bus_parse_capabilities(bus);

/* update BARs for sof, don't need parse them again */
/* HDA base */
sdev->bar[HDA_DSP_HDA_BAR] = bus->remap_addr;
sdev->bar[HDA_DSP_PP_BAR] = bus->ppcap;
sdev->bar[HDA_DSP_SPIB_BAR] = bus->spbcap;
sdev->bar[HDA_DSP_DRSM_BAR] = bus->drsmcap;

return 0;
/* get controller capabilities */
ret = hda_dsp_ctrl_get_caps(sdev);
if (ret < 0)
dev_err(&pci->dev, "error: get caps error\n");

return ret;
}

#if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA)

static int hda_init_caps(struct snd_sof_dev *sdev)
{
struct hdac_bus *bus = sof_to_bus(sdev);
Expand Down Expand Up @@ -440,26 +414,6 @@ static int hda_init_caps(struct snd_sof_dev *sdev)

#else

static int hda_init(struct snd_sof_dev *sdev)
{
struct pci_dev *pci = sdev->pci;
int ret;

/* HDA base */
sdev->bar[HDA_DSP_HDA_BAR] = pci_ioremap_bar(pci, HDA_DSP_HDA_BAR);
if (!sdev->bar[HDA_DSP_HDA_BAR]) {
dev_err(&pci->dev, "error: ioremap error\n");
return -ENXIO;
}

/* get controller capabilities */
ret = hda_dsp_ctrl_get_caps(sdev);
if (ret < 0)
dev_err(&pci->dev, "error: get caps error\n");

return 0;
}

static int hda_init_caps(struct snd_sof_dev *sdev)
{
/*
Expand Down
12 changes: 12 additions & 0 deletions sound/soc/sof/intel/hda.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@
#define SOF_HDA_CAP_ID_MASK (0xFFF << SOF_HDA_CAP_ID_OFF)
#define SOF_HDA_CAP_NEXT_MASK 0xFFFF

#define SOF_HDA_GTS_CAP_ID 0x1
#define SOF_HDA_ML_CAP_ID 0x2

#define SOF_HDA_PP_CAP_ID 0x3
#define SOF_HDA_REG_PP_PPCH 0x10
#define SOF_HDA_REG_PP_PPCTL 0x04
Expand Down Expand Up @@ -461,11 +464,20 @@ int hda_dsp_ctrl_link_reset(struct snd_sof_dev *sdev);
void hda_dsp_ctrl_enable_miscbdcge(struct snd_sof_dev *sdev, bool enable);
int hda_dsp_ctrl_init_chip(struct snd_sof_dev *sdev, bool full_reset);

#if IS_ENABLED(CONFIG_SND_SOC_SOF_HDA)
/*
* HDA Codec operations.
*/
int hda_codec_probe_bus(struct snd_sof_dev *sdev);
int hda_codec_i915_init(struct snd_sof_dev *sdev);
#endif

/*
* HDA bus operations.
*/
int sof_hda_bus_init(struct hdac_bus *bus, struct device *dev,
const struct hdac_ext_bus_ops *ext_ops);


/*
* Trace Control.
Expand Down

0 comments on commit bd37bda

Please sign in to comment.