2019-05-29 22:17:59 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2015-06-11 16:41:49 +08:00
|
|
|
/*
|
|
|
|
* hdac-ext-stream.c - HD-audio extended stream operations.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2015 Intel Corp
|
|
|
|
* Author: Jeeja KP <jeeja.kp@intel.com>
|
|
|
|
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
*
|
|
|
|
* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <linux/delay.h>
|
2015-06-17 13:50:16 +08:00
|
|
|
#include <linux/slab.h>
|
2015-06-11 16:41:49 +08:00
|
|
|
#include <sound/pcm.h>
|
|
|
|
#include <sound/hda_register.h>
|
|
|
|
#include <sound/hdaudio_ext.h>
|
|
|
|
|
|
|
|
/**
|
|
|
|
* snd_hdac_ext_stream_init - initialize each stream (aka device)
|
2018-06-02 11:53:50 +08:00
|
|
|
* @bus: HD-audio core bus
|
2021-12-17 07:11:28 +08:00
|
|
|
* @hext_stream: HD-audio ext core stream object to initialize
|
2015-06-11 16:41:49 +08:00
|
|
|
* @idx: stream index number
|
|
|
|
* @direction: stream direction (SNDRV_PCM_STREAM_PLAYBACK or SNDRV_PCM_STREAM_CAPTURE)
|
|
|
|
* @tag: the tag id to assign
|
|
|
|
*
|
|
|
|
* initialize the stream, if ppcap is enabled then init those and then
|
|
|
|
* invoke hdac stream initialization routine
|
|
|
|
*/
|
2018-06-02 11:53:50 +08:00
|
|
|
void snd_hdac_ext_stream_init(struct hdac_bus *bus,
|
2021-12-17 07:11:28 +08:00
|
|
|
struct hdac_ext_stream *hext_stream,
|
|
|
|
int idx, int direction, int tag)
|
2015-06-11 16:41:49 +08:00
|
|
|
{
|
2016-08-04 18:16:01 +08:00
|
|
|
if (bus->ppcap) {
|
2021-12-17 07:11:28 +08:00
|
|
|
hext_stream->pphc_addr = bus->ppcap + AZX_PPHC_BASE +
|
2015-06-11 16:41:49 +08:00
|
|
|
AZX_PPHC_INTERVAL * idx;
|
|
|
|
|
2021-12-17 07:11:28 +08:00
|
|
|
hext_stream->pplc_addr = bus->ppcap + AZX_PPLC_BASE +
|
2018-06-02 11:53:50 +08:00
|
|
|
AZX_PPLC_MULTI * bus->num_streams +
|
2015-06-11 16:41:49 +08:00
|
|
|
AZX_PPLC_INTERVAL * idx;
|
|
|
|
}
|
|
|
|
|
2016-08-04 18:16:01 +08:00
|
|
|
if (bus->spbcap) {
|
2021-12-17 07:11:28 +08:00
|
|
|
hext_stream->spib_addr = bus->spbcap + AZX_SPB_BASE +
|
2015-08-22 00:06:20 +08:00
|
|
|
AZX_SPB_INTERVAL * idx +
|
|
|
|
AZX_SPB_SPIB;
|
|
|
|
|
2021-12-17 07:11:28 +08:00
|
|
|
hext_stream->fifo_addr = bus->spbcap + AZX_SPB_BASE +
|
2015-08-22 00:06:20 +08:00
|
|
|
AZX_SPB_INTERVAL * idx +
|
|
|
|
AZX_SPB_MAXFIFO;
|
|
|
|
}
|
|
|
|
|
2016-08-04 18:16:01 +08:00
|
|
|
if (bus->drsmcap)
|
2021-12-17 07:11:28 +08:00
|
|
|
hext_stream->dpibr_addr = bus->drsmcap + AZX_DRSM_BASE +
|
2015-12-18 17:41:59 +08:00
|
|
|
AZX_DRSM_INTERVAL * idx;
|
|
|
|
|
2021-12-17 07:11:28 +08:00
|
|
|
hext_stream->decoupled = false;
|
|
|
|
snd_hdac_stream_init(bus, &hext_stream->hstream, idx, direction, tag);
|
2015-06-11 16:41:49 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(snd_hdac_ext_stream_init);
|
|
|
|
|
2015-06-17 13:50:16 +08:00
|
|
|
/**
|
|
|
|
* snd_hdac_ext_stream_init_all - create and initialize the stream objects
|
|
|
|
* for an extended hda bus
|
2018-06-02 11:53:50 +08:00
|
|
|
* @bus: HD-audio core bus
|
2015-06-17 13:50:16 +08:00
|
|
|
* @start_idx: start index for streams
|
|
|
|
* @num_stream: number of streams to initialize
|
|
|
|
* @dir: direction of streams
|
|
|
|
*/
|
2018-06-02 11:53:50 +08:00
|
|
|
int snd_hdac_ext_stream_init_all(struct hdac_bus *bus, int start_idx,
|
2021-12-17 07:11:28 +08:00
|
|
|
int num_stream, int dir)
|
2015-06-17 13:50:16 +08:00
|
|
|
{
|
|
|
|
int stream_tag = 0;
|
|
|
|
int i, tag, idx = start_idx;
|
|
|
|
|
|
|
|
for (i = 0; i < num_stream; i++) {
|
2021-12-17 07:11:28 +08:00
|
|
|
struct hdac_ext_stream *hext_stream =
|
|
|
|
kzalloc(sizeof(*hext_stream), GFP_KERNEL);
|
|
|
|
if (!hext_stream)
|
2015-06-17 13:50:16 +08:00
|
|
|
return -ENOMEM;
|
|
|
|
tag = ++stream_tag;
|
2021-12-17 07:11:28 +08:00
|
|
|
snd_hdac_ext_stream_init(bus, hext_stream, idx, dir, tag);
|
2015-06-17 13:50:16 +08:00
|
|
|
idx++;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(snd_hdac_ext_stream_init_all);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* snd_hdac_stream_free_all - free hdac extended stream objects
|
|
|
|
*
|
2018-06-02 11:53:50 +08:00
|
|
|
* @bus: HD-audio core bus
|
2015-06-17 13:50:16 +08:00
|
|
|
*/
|
2018-06-02 11:53:50 +08:00
|
|
|
void snd_hdac_stream_free_all(struct hdac_bus *bus)
|
2015-06-17 13:50:16 +08:00
|
|
|
{
|
2016-03-15 19:09:23 +08:00
|
|
|
struct hdac_stream *s, *_s;
|
2021-12-17 07:11:28 +08:00
|
|
|
struct hdac_ext_stream *hext_stream;
|
2015-06-17 13:50:16 +08:00
|
|
|
|
2016-03-15 19:09:23 +08:00
|
|
|
list_for_each_entry_safe(s, _s, &bus->stream_list, list) {
|
2021-12-17 07:11:28 +08:00
|
|
|
hext_stream = stream_to_hdac_ext_stream(s);
|
|
|
|
snd_hdac_ext_stream_decouple(bus, hext_stream, false);
|
2015-06-17 13:50:16 +08:00
|
|
|
list_del(&s->list);
|
2021-12-17 07:11:28 +08:00
|
|
|
kfree(hext_stream);
|
2015-06-17 13:50:16 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(snd_hdac_stream_free_all);
|
|
|
|
|
2021-09-25 03:24:16 +08:00
|
|
|
void snd_hdac_ext_stream_decouple_locked(struct hdac_bus *bus,
|
2021-12-17 07:11:28 +08:00
|
|
|
struct hdac_ext_stream *hext_stream,
|
2021-09-25 03:24:16 +08:00
|
|
|
bool decouple)
|
2015-06-11 16:41:49 +08:00
|
|
|
{
|
2021-12-17 07:11:28 +08:00
|
|
|
struct hdac_stream *hstream = &hext_stream->hstream;
|
2017-01-02 15:14:28 +08:00
|
|
|
u32 val;
|
|
|
|
int mask = AZX_PPCTL_PROCEN(hstream->index);
|
2015-06-11 16:41:49 +08:00
|
|
|
|
2017-01-02 15:14:28 +08:00
|
|
|
val = readw(bus->ppcap + AZX_REG_PP_PPCTL) & mask;
|
|
|
|
|
|
|
|
if (decouple && !val)
|
|
|
|
snd_hdac_updatel(bus->ppcap, AZX_REG_PP_PPCTL, mask, mask);
|
|
|
|
else if (!decouple && val)
|
|
|
|
snd_hdac_updatel(bus->ppcap, AZX_REG_PP_PPCTL, mask, 0);
|
|
|
|
|
2021-12-17 07:11:28 +08:00
|
|
|
hext_stream->decoupled = decouple;
|
2021-09-25 03:24:16 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(snd_hdac_ext_stream_decouple_locked);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* snd_hdac_ext_stream_decouple - decouple the hdac stream
|
|
|
|
* @bus: HD-audio core bus
|
2021-12-17 07:11:28 +08:00
|
|
|
* @hext_stream: HD-audio ext core stream object to initialize
|
2021-09-25 03:24:16 +08:00
|
|
|
* @decouple: flag to decouple
|
|
|
|
*/
|
|
|
|
void snd_hdac_ext_stream_decouple(struct hdac_bus *bus,
|
2021-12-17 07:11:28 +08:00
|
|
|
struct hdac_ext_stream *hext_stream, bool decouple)
|
2021-09-25 03:24:16 +08:00
|
|
|
{
|
|
|
|
spin_lock_irq(&bus->reg_lock);
|
2021-12-17 07:11:28 +08:00
|
|
|
snd_hdac_ext_stream_decouple_locked(bus, hext_stream, decouple);
|
2015-06-11 16:41:49 +08:00
|
|
|
spin_unlock_irq(&bus->reg_lock);
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(snd_hdac_ext_stream_decouple);
|
|
|
|
|
|
|
|
/**
|
2021-03-02 01:46:17 +08:00
|
|
|
* snd_hdac_ext_link_stream_start - start a stream
|
2021-12-17 07:11:28 +08:00
|
|
|
* @hext_stream: HD-audio ext core stream to start
|
2015-06-11 16:41:49 +08:00
|
|
|
*/
|
2021-12-17 07:11:28 +08:00
|
|
|
void snd_hdac_ext_link_stream_start(struct hdac_ext_stream *hext_stream)
|
2015-06-11 16:41:49 +08:00
|
|
|
{
|
2021-12-17 07:11:28 +08:00
|
|
|
snd_hdac_updatel(hext_stream->pplc_addr, AZX_REG_PPLCCTL,
|
2018-09-03 10:47:09 +08:00
|
|
|
AZX_PPLCCTL_RUN, AZX_PPLCCTL_RUN);
|
2015-06-11 16:41:49 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(snd_hdac_ext_link_stream_start);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* snd_hdac_ext_link_stream_clear - stop a stream DMA
|
2021-12-17 07:11:28 +08:00
|
|
|
* @hext_stream: HD-audio ext core stream to stop
|
2015-06-11 16:41:49 +08:00
|
|
|
*/
|
2021-12-17 07:11:28 +08:00
|
|
|
void snd_hdac_ext_link_stream_clear(struct hdac_ext_stream *hext_stream)
|
2015-06-11 16:41:49 +08:00
|
|
|
{
|
2021-12-17 07:11:28 +08:00
|
|
|
snd_hdac_updatel(hext_stream->pplc_addr, AZX_REG_PPLCCTL, AZX_PPLCCTL_RUN, 0);
|
2015-06-11 16:41:49 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(snd_hdac_ext_link_stream_clear);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* snd_hdac_ext_link_stream_reset - reset a stream
|
2021-12-17 07:11:28 +08:00
|
|
|
* @hext_stream: HD-audio ext core stream to reset
|
2015-06-11 16:41:49 +08:00
|
|
|
*/
|
2021-12-17 07:11:28 +08:00
|
|
|
void snd_hdac_ext_link_stream_reset(struct hdac_ext_stream *hext_stream)
|
2015-06-11 16:41:49 +08:00
|
|
|
{
|
|
|
|
unsigned char val;
|
|
|
|
int timeout;
|
|
|
|
|
2021-12-17 07:11:28 +08:00
|
|
|
snd_hdac_ext_link_stream_clear(hext_stream);
|
2015-06-11 16:41:49 +08:00
|
|
|
|
2021-12-17 07:11:28 +08:00
|
|
|
snd_hdac_updatel(hext_stream->pplc_addr, AZX_REG_PPLCCTL,
|
2018-09-03 10:47:09 +08:00
|
|
|
AZX_PPLCCTL_STRST, AZX_PPLCCTL_STRST);
|
2015-06-11 16:41:49 +08:00
|
|
|
udelay(3);
|
|
|
|
timeout = 50;
|
|
|
|
do {
|
2021-12-17 07:11:28 +08:00
|
|
|
val = readl(hext_stream->pplc_addr + AZX_REG_PPLCCTL) &
|
2015-06-11 16:41:49 +08:00
|
|
|
AZX_PPLCCTL_STRST;
|
|
|
|
if (val)
|
|
|
|
break;
|
|
|
|
udelay(3);
|
|
|
|
} while (--timeout);
|
|
|
|
val &= ~AZX_PPLCCTL_STRST;
|
2021-12-17 07:11:28 +08:00
|
|
|
writel(val, hext_stream->pplc_addr + AZX_REG_PPLCCTL);
|
2015-06-11 16:41:49 +08:00
|
|
|
udelay(3);
|
|
|
|
|
|
|
|
timeout = 50;
|
|
|
|
/* waiting for hardware to report that the stream is out of reset */
|
|
|
|
do {
|
2021-12-17 07:11:28 +08:00
|
|
|
val = readl(hext_stream->pplc_addr + AZX_REG_PPLCCTL) & AZX_PPLCCTL_STRST;
|
2015-06-11 16:41:49 +08:00
|
|
|
if (!val)
|
|
|
|
break;
|
|
|
|
udelay(3);
|
|
|
|
} while (--timeout);
|
|
|
|
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(snd_hdac_ext_link_stream_reset);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* snd_hdac_ext_link_stream_setup - set up the SD for streaming
|
2021-12-17 07:11:28 +08:00
|
|
|
* @hext_stream: HD-audio ext core stream to set up
|
2015-06-11 16:41:49 +08:00
|
|
|
* @fmt: stream format
|
|
|
|
*/
|
2021-12-17 07:11:28 +08:00
|
|
|
int snd_hdac_ext_link_stream_setup(struct hdac_ext_stream *hext_stream, int fmt)
|
2015-06-11 16:41:49 +08:00
|
|
|
{
|
2021-12-17 07:11:28 +08:00
|
|
|
struct hdac_stream *hstream = &hext_stream->hstream;
|
2015-06-11 16:41:49 +08:00
|
|
|
unsigned int val;
|
|
|
|
|
|
|
|
/* make sure the run bit is zero for SD */
|
2021-12-17 07:11:28 +08:00
|
|
|
snd_hdac_ext_link_stream_clear(hext_stream);
|
2015-06-11 16:41:49 +08:00
|
|
|
/* program the stream_tag */
|
2021-12-17 07:11:28 +08:00
|
|
|
val = readl(hext_stream->pplc_addr + AZX_REG_PPLCCTL);
|
2015-06-11 16:41:49 +08:00
|
|
|
val = (val & ~AZX_PPLCCTL_STRM_MASK) |
|
|
|
|
(hstream->stream_tag << AZX_PPLCCTL_STRM_SHIFT);
|
2021-12-17 07:11:28 +08:00
|
|
|
writel(val, hext_stream->pplc_addr + AZX_REG_PPLCCTL);
|
2015-06-11 16:41:49 +08:00
|
|
|
|
|
|
|
/* program the stream format */
|
2021-12-17 07:11:28 +08:00
|
|
|
writew(fmt, hext_stream->pplc_addr + AZX_REG_PPLCFMT);
|
2015-06-11 16:41:49 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(snd_hdac_ext_link_stream_setup);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* snd_hdac_ext_link_set_stream_id - maps stream id to link output
|
|
|
|
* @link: HD-audio ext link to set up
|
|
|
|
* @stream: stream id
|
|
|
|
*/
|
|
|
|
void snd_hdac_ext_link_set_stream_id(struct hdac_ext_link *link,
|
2021-12-17 07:11:28 +08:00
|
|
|
int stream)
|
2015-06-11 16:41:49 +08:00
|
|
|
{
|
2015-10-05 22:09:48 +08:00
|
|
|
snd_hdac_updatew(link->ml_addr, AZX_REG_ML_LOSIDV, (1 << stream), 1 << stream);
|
2015-06-11 16:41:49 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(snd_hdac_ext_link_set_stream_id);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* snd_hdac_ext_link_clear_stream_id - maps stream id to link output
|
|
|
|
* @link: HD-audio ext link to set up
|
|
|
|
* @stream: stream id
|
|
|
|
*/
|
|
|
|
void snd_hdac_ext_link_clear_stream_id(struct hdac_ext_link *link,
|
|
|
|
int stream)
|
|
|
|
{
|
2018-09-03 10:47:09 +08:00
|
|
|
snd_hdac_updatew(link->ml_addr, AZX_REG_ML_LOSIDV, (1 << stream), 0);
|
2015-06-11 16:41:49 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(snd_hdac_ext_link_clear_stream_id);
|
|
|
|
|
|
|
|
static struct hdac_ext_stream *
|
2018-06-02 11:53:50 +08:00
|
|
|
hdac_ext_link_stream_assign(struct hdac_bus *bus,
|
2021-12-17 07:11:28 +08:00
|
|
|
struct snd_pcm_substream *substream)
|
2015-06-11 16:41:49 +08:00
|
|
|
{
|
|
|
|
struct hdac_ext_stream *res = NULL;
|
2021-12-17 07:11:28 +08:00
|
|
|
struct hdac_stream *hstream = NULL;
|
2015-06-11 16:41:49 +08:00
|
|
|
|
2018-06-02 11:53:50 +08:00
|
|
|
if (!bus->ppcap) {
|
|
|
|
dev_err(bus->dev, "stream type not supported\n");
|
2015-06-11 16:41:49 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2021-09-25 03:24:16 +08:00
|
|
|
spin_lock_irq(&bus->reg_lock);
|
2021-12-17 07:11:28 +08:00
|
|
|
list_for_each_entry(hstream, &bus->stream_list, list) {
|
|
|
|
struct hdac_ext_stream *hext_stream = container_of(hstream,
|
|
|
|
struct hdac_ext_stream,
|
|
|
|
hstream);
|
|
|
|
if (hstream->direction != substream->stream)
|
2015-06-11 16:41:49 +08:00
|
|
|
continue;
|
|
|
|
|
|
|
|
/* check if decoupled stream and not in use is available */
|
2021-12-17 07:11:28 +08:00
|
|
|
if (hext_stream->decoupled && !hext_stream->link_locked) {
|
|
|
|
res = hext_stream;
|
2015-06-11 16:41:49 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-12-17 07:11:28 +08:00
|
|
|
if (!hext_stream->link_locked) {
|
|
|
|
snd_hdac_ext_stream_decouple_locked(bus, hext_stream, true);
|
|
|
|
res = hext_stream;
|
2015-06-11 16:41:49 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (res) {
|
|
|
|
res->link_locked = 1;
|
|
|
|
res->link_substream = substream;
|
|
|
|
}
|
2021-09-25 03:24:16 +08:00
|
|
|
spin_unlock_irq(&bus->reg_lock);
|
2015-06-11 16:41:49 +08:00
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
static struct hdac_ext_stream *
|
2018-06-02 11:53:50 +08:00
|
|
|
hdac_ext_host_stream_assign(struct hdac_bus *bus,
|
2021-12-17 07:11:28 +08:00
|
|
|
struct snd_pcm_substream *substream)
|
2015-06-11 16:41:49 +08:00
|
|
|
{
|
|
|
|
struct hdac_ext_stream *res = NULL;
|
2021-12-17 07:11:28 +08:00
|
|
|
struct hdac_stream *hstream = NULL;
|
2015-06-11 16:41:49 +08:00
|
|
|
|
2018-06-02 11:53:50 +08:00
|
|
|
if (!bus->ppcap) {
|
|
|
|
dev_err(bus->dev, "stream type not supported\n");
|
2015-06-11 16:41:49 +08:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2021-09-25 03:24:16 +08:00
|
|
|
spin_lock_irq(&bus->reg_lock);
|
2021-12-17 07:11:28 +08:00
|
|
|
list_for_each_entry(hstream, &bus->stream_list, list) {
|
|
|
|
struct hdac_ext_stream *hext_stream = container_of(hstream,
|
|
|
|
struct hdac_ext_stream,
|
|
|
|
hstream);
|
|
|
|
if (hstream->direction != substream->stream)
|
2015-06-11 16:41:49 +08:00
|
|
|
continue;
|
|
|
|
|
2021-12-17 07:11:28 +08:00
|
|
|
if (!hstream->opened) {
|
|
|
|
if (!hext_stream->decoupled)
|
|
|
|
snd_hdac_ext_stream_decouple_locked(bus, hext_stream, true);
|
|
|
|
res = hext_stream;
|
2015-06-11 16:41:49 +08:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (res) {
|
|
|
|
res->hstream.opened = 1;
|
|
|
|
res->hstream.running = 0;
|
|
|
|
res->hstream.substream = substream;
|
|
|
|
}
|
2021-09-25 03:24:16 +08:00
|
|
|
spin_unlock_irq(&bus->reg_lock);
|
2015-06-11 16:41:49 +08:00
|
|
|
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* snd_hdac_ext_stream_assign - assign a stream for the PCM
|
2018-06-02 11:53:50 +08:00
|
|
|
* @bus: HD-audio core bus
|
2015-06-11 16:41:49 +08:00
|
|
|
* @substream: PCM substream to assign
|
|
|
|
* @type: type of stream (coupled, host or link stream)
|
|
|
|
*
|
|
|
|
* This assigns the stream based on the type (coupled/host/link), for the
|
|
|
|
* given PCM substream, assigns it and returns the stream object
|
|
|
|
*
|
|
|
|
* coupled: Looks for an unused stream
|
|
|
|
* host: Looks for an unused decoupled host stream
|
|
|
|
* link: Looks for an unused decoupled link stream
|
|
|
|
*
|
|
|
|
* If no stream is free, returns NULL. The function tries to keep using
|
|
|
|
* the same stream object when it's used beforehand. when a stream is
|
|
|
|
* decoupled, it becomes a host stream and link stream.
|
|
|
|
*/
|
2018-06-02 11:53:50 +08:00
|
|
|
struct hdac_ext_stream *snd_hdac_ext_stream_assign(struct hdac_bus *bus,
|
2015-06-11 16:41:49 +08:00
|
|
|
struct snd_pcm_substream *substream,
|
|
|
|
int type)
|
|
|
|
{
|
2021-12-17 07:11:28 +08:00
|
|
|
struct hdac_ext_stream *hext_stream = NULL;
|
|
|
|
struct hdac_stream *hstream = NULL;
|
2015-06-11 16:41:49 +08:00
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case HDAC_EXT_STREAM_TYPE_COUPLED:
|
2021-12-17 07:11:28 +08:00
|
|
|
hstream = snd_hdac_stream_assign(bus, substream);
|
|
|
|
if (hstream)
|
|
|
|
hext_stream = container_of(hstream,
|
|
|
|
struct hdac_ext_stream,
|
|
|
|
hstream);
|
|
|
|
return hext_stream;
|
2015-06-11 16:41:49 +08:00
|
|
|
|
|
|
|
case HDAC_EXT_STREAM_TYPE_HOST:
|
2018-06-02 11:53:50 +08:00
|
|
|
return hdac_ext_host_stream_assign(bus, substream);
|
2015-06-11 16:41:49 +08:00
|
|
|
|
|
|
|
case HDAC_EXT_STREAM_TYPE_LINK:
|
2018-06-02 11:53:50 +08:00
|
|
|
return hdac_ext_link_stream_assign(bus, substream);
|
2015-06-11 16:41:49 +08:00
|
|
|
|
|
|
|
default:
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(snd_hdac_ext_stream_assign);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* snd_hdac_ext_stream_release - release the assigned stream
|
2021-12-17 07:11:28 +08:00
|
|
|
* @hext_stream: HD-audio ext core stream to release
|
2015-06-11 16:41:49 +08:00
|
|
|
* @type: type of stream (coupled, host or link stream)
|
|
|
|
*
|
|
|
|
* Release the stream that has been assigned by snd_hdac_ext_stream_assign().
|
|
|
|
*/
|
2021-12-17 07:11:28 +08:00
|
|
|
void snd_hdac_ext_stream_release(struct hdac_ext_stream *hext_stream, int type)
|
2015-06-11 16:41:49 +08:00
|
|
|
{
|
2021-12-17 07:11:28 +08:00
|
|
|
struct hdac_bus *bus = hext_stream->hstream.bus;
|
2015-06-11 16:41:49 +08:00
|
|
|
|
|
|
|
switch (type) {
|
|
|
|
case HDAC_EXT_STREAM_TYPE_COUPLED:
|
2021-12-17 07:11:28 +08:00
|
|
|
snd_hdac_stream_release(&hext_stream->hstream);
|
2015-06-11 16:41:49 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case HDAC_EXT_STREAM_TYPE_HOST:
|
2021-09-25 03:24:16 +08:00
|
|
|
spin_lock_irq(&bus->reg_lock);
|
2021-12-17 07:11:28 +08:00
|
|
|
if (hext_stream->decoupled && !hext_stream->link_locked)
|
|
|
|
snd_hdac_ext_stream_decouple_locked(bus, hext_stream, false);
|
2021-09-25 03:24:16 +08:00
|
|
|
spin_unlock_irq(&bus->reg_lock);
|
2021-12-17 07:11:28 +08:00
|
|
|
snd_hdac_stream_release(&hext_stream->hstream);
|
2015-06-11 16:41:49 +08:00
|
|
|
break;
|
|
|
|
|
|
|
|
case HDAC_EXT_STREAM_TYPE_LINK:
|
|
|
|
spin_lock_irq(&bus->reg_lock);
|
2021-12-17 07:11:28 +08:00
|
|
|
if (hext_stream->decoupled && !hext_stream->hstream.opened)
|
|
|
|
snd_hdac_ext_stream_decouple_locked(bus, hext_stream, false);
|
|
|
|
hext_stream->link_locked = 0;
|
|
|
|
hext_stream->link_substream = NULL;
|
2015-06-11 16:41:49 +08:00
|
|
|
spin_unlock_irq(&bus->reg_lock);
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
dev_dbg(bus->dev, "Invalid type %d\n", type);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(snd_hdac_ext_stream_release);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* snd_hdac_ext_stream_spbcap_enable - enable SPIB for a stream
|
2018-06-02 11:53:50 +08:00
|
|
|
* @bus: HD-audio core bus
|
2015-06-11 16:41:49 +08:00
|
|
|
* @enable: flag to enable/disable SPIB
|
|
|
|
* @index: stream index for which SPIB need to be enabled
|
|
|
|
*/
|
2018-06-02 11:53:50 +08:00
|
|
|
void snd_hdac_ext_stream_spbcap_enable(struct hdac_bus *bus,
|
2015-06-11 16:41:49 +08:00
|
|
|
bool enable, int index)
|
|
|
|
{
|
|
|
|
u32 mask = 0;
|
|
|
|
|
2016-08-04 18:16:01 +08:00
|
|
|
if (!bus->spbcap) {
|
2016-09-17 00:36:05 +08:00
|
|
|
dev_err(bus->dev, "Address of SPB capability is NULL\n");
|
2015-06-11 16:41:49 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mask |= (1 << index);
|
|
|
|
|
|
|
|
if (enable)
|
2018-09-03 10:47:09 +08:00
|
|
|
snd_hdac_updatel(bus->spbcap, AZX_REG_SPB_SPBFCCTL, mask, mask);
|
2015-06-11 16:41:49 +08:00
|
|
|
else
|
2016-08-04 18:16:01 +08:00
|
|
|
snd_hdac_updatel(bus->spbcap, AZX_REG_SPB_SPBFCCTL, mask, 0);
|
2015-06-11 16:41:49 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(snd_hdac_ext_stream_spbcap_enable);
|
|
|
|
|
2015-08-22 00:06:20 +08:00
|
|
|
/**
|
|
|
|
* snd_hdac_ext_stream_set_spib - sets the spib value of a stream
|
2018-06-02 11:53:50 +08:00
|
|
|
* @bus: HD-audio core bus
|
2021-12-17 07:11:28 +08:00
|
|
|
* @hext_stream: hdac_ext_stream
|
2015-08-22 00:06:20 +08:00
|
|
|
* @value: spib value to set
|
|
|
|
*/
|
2018-06-02 11:53:50 +08:00
|
|
|
int snd_hdac_ext_stream_set_spib(struct hdac_bus *bus,
|
2021-12-17 07:11:28 +08:00
|
|
|
struct hdac_ext_stream *hext_stream, u32 value)
|
2015-08-22 00:06:20 +08:00
|
|
|
{
|
|
|
|
|
2016-08-04 18:16:01 +08:00
|
|
|
if (!bus->spbcap) {
|
2016-09-17 00:36:05 +08:00
|
|
|
dev_err(bus->dev, "Address of SPB capability is NULL\n");
|
2015-08-22 00:06:20 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2021-12-17 07:11:28 +08:00
|
|
|
writel(value, hext_stream->spib_addr);
|
2015-08-22 00:06:20 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(snd_hdac_ext_stream_set_spib);
|
|
|
|
|
|
|
|
/**
|
2015-08-23 14:22:50 +08:00
|
|
|
* snd_hdac_ext_stream_get_spbmaxfifo - gets the spib value of a stream
|
2018-06-02 11:53:50 +08:00
|
|
|
* @bus: HD-audio core bus
|
2021-12-17 07:11:28 +08:00
|
|
|
* @hext_stream: hdac_ext_stream
|
2015-08-22 00:06:20 +08:00
|
|
|
*
|
|
|
|
* Return maxfifo for the stream
|
|
|
|
*/
|
2018-06-02 11:53:50 +08:00
|
|
|
int snd_hdac_ext_stream_get_spbmaxfifo(struct hdac_bus *bus,
|
2021-12-17 07:11:28 +08:00
|
|
|
struct hdac_ext_stream *hext_stream)
|
2015-08-22 00:06:20 +08:00
|
|
|
{
|
|
|
|
|
2016-08-04 18:16:01 +08:00
|
|
|
if (!bus->spbcap) {
|
2016-09-17 00:36:05 +08:00
|
|
|
dev_err(bus->dev, "Address of SPB capability is NULL\n");
|
2015-08-22 00:06:20 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2021-12-17 07:11:28 +08:00
|
|
|
return readl(hext_stream->fifo_addr);
|
2015-08-22 00:06:20 +08:00
|
|
|
}
|
2015-08-23 14:22:50 +08:00
|
|
|
EXPORT_SYMBOL_GPL(snd_hdac_ext_stream_get_spbmaxfifo);
|
2015-08-22 00:06:20 +08:00
|
|
|
|
2015-12-18 17:41:59 +08:00
|
|
|
/**
|
|
|
|
* snd_hdac_ext_stream_drsm_enable - enable DMA resume for a stream
|
2018-06-02 11:53:50 +08:00
|
|
|
* @bus: HD-audio core bus
|
2015-12-18 17:41:59 +08:00
|
|
|
* @enable: flag to enable/disable DRSM
|
|
|
|
* @index: stream index for which DRSM need to be enabled
|
|
|
|
*/
|
2018-06-02 11:53:50 +08:00
|
|
|
void snd_hdac_ext_stream_drsm_enable(struct hdac_bus *bus,
|
2015-12-18 17:41:59 +08:00
|
|
|
bool enable, int index)
|
|
|
|
{
|
|
|
|
u32 mask = 0;
|
|
|
|
|
2016-08-04 18:16:01 +08:00
|
|
|
if (!bus->drsmcap) {
|
2016-09-17 00:36:05 +08:00
|
|
|
dev_err(bus->dev, "Address of DRSM capability is NULL\n");
|
2015-12-18 17:41:59 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
mask |= (1 << index);
|
|
|
|
|
|
|
|
if (enable)
|
2018-09-03 10:47:09 +08:00
|
|
|
snd_hdac_updatel(bus->drsmcap, AZX_REG_DRSM_CTL, mask, mask);
|
2015-12-18 17:41:59 +08:00
|
|
|
else
|
2016-08-04 18:16:01 +08:00
|
|
|
snd_hdac_updatel(bus->drsmcap, AZX_REG_DRSM_CTL, mask, 0);
|
2015-12-18 17:41:59 +08:00
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(snd_hdac_ext_stream_drsm_enable);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* snd_hdac_ext_stream_set_dpibr - sets the dpibr value of a stream
|
2018-06-02 11:53:50 +08:00
|
|
|
* @bus: HD-audio core bus
|
2021-12-17 07:11:28 +08:00
|
|
|
* @hext_stream: hdac_ext_stream
|
2015-12-18 17:41:59 +08:00
|
|
|
* @value: dpib value to set
|
|
|
|
*/
|
2018-06-02 11:53:50 +08:00
|
|
|
int snd_hdac_ext_stream_set_dpibr(struct hdac_bus *bus,
|
2021-12-17 07:11:28 +08:00
|
|
|
struct hdac_ext_stream *hext_stream, u32 value)
|
2015-12-18 17:41:59 +08:00
|
|
|
{
|
|
|
|
|
2016-08-04 18:16:01 +08:00
|
|
|
if (!bus->drsmcap) {
|
2016-09-17 00:36:05 +08:00
|
|
|
dev_err(bus->dev, "Address of DRSM capability is NULL\n");
|
2015-12-18 17:41:59 +08:00
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2021-12-17 07:11:28 +08:00
|
|
|
writel(value, hext_stream->dpibr_addr);
|
2015-12-18 17:41:59 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(snd_hdac_ext_stream_set_dpibr);
|
|
|
|
|
|
|
|
/**
|
|
|
|
* snd_hdac_ext_stream_set_lpib - sets the lpib value of a stream
|
2021-12-17 07:11:28 +08:00
|
|
|
* @hext_stream: hdac_ext_stream
|
2015-12-18 17:41:59 +08:00
|
|
|
* @value: lpib value to set
|
|
|
|
*/
|
2021-12-17 07:11:28 +08:00
|
|
|
int snd_hdac_ext_stream_set_lpib(struct hdac_ext_stream *hext_stream, u32 value)
|
2015-12-18 17:41:59 +08:00
|
|
|
{
|
2021-12-17 07:11:28 +08:00
|
|
|
snd_hdac_stream_writel(&hext_stream->hstream, SD_LPIB, value);
|
2015-12-18 17:41:59 +08:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
EXPORT_SYMBOL_GPL(snd_hdac_ext_stream_set_lpib);
|