Commit e1b239f3 authored by Takashi Iwai's avatar Takashi Iwai

ALSA: x86: Refactor PCM process engine

This is again a big rewrite of the driver; now it touches the code to
process PCM stream transfers.

The most fundamental change is that the driver may support more than
four periods.  Instead of keeping the same index between both the ring
buffer (with the fixed four buffer descriptors) and the PCM buffer
periods, we keep difference indices for both (bd_head and pcm_head
fields).  In addition, when the periods are more than four, we need to
track both head and next indices.  That is, we now have three indices:
bd_head, pcm_head and pcm_filled.

Also, the driver works better for periods < 4, too: the remaining BDs
out of four are marked as invalid, so that the hardware skips those
BDs in its loop.

By this flexibility, we can use even ALSA-lib dmix plugin, which
requires 16 periods as default.

The buffer size could be up to 20bit, so the max buffer size was
increased accordingly.  However, the buffer pre-allocation is kept as
the old value (600kB) as default.  The reason is the limited number of
BDs: since it doesn't suffice for the useful SG page management that
can fit with the usual page allocator like some other drivers, we have
to still allocate continuous pages, hence we shouldn't take too big
memories there.
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 1cf05ba2
This diff is collapsed.
......@@ -64,24 +64,15 @@
struct pcm_stream_info {
struct snd_pcm_substream *substream;
u64 buffer_rendered;
u32 ring_buf_size;
int substream_refcount;
bool running;
};
struct ring_buf_info {
u32 buf_addr;
u32 buf_size;
u8 is_valid;
};
/*
* struct snd_intelhad - intelhad driver structure
*
* @card: ptr to hold card details
* @connected: the monitor connection status
* @buf_info: ring buffer info
* @stream_info: stream information
* @eld: holds ELD info
* @curr_buf: pointer to hold current active ring buf
......@@ -91,26 +82,29 @@ struct ring_buf_info {
* @buff_done: id of current buffer done intr
* @dev: platoform device handle
* @chmap: holds channel map info
* @underrun_count: PCM stream underrun counter
*/
struct snd_intelhad {
struct snd_card *card;
bool connected;
struct ring_buf_info buf_info[HAD_NUM_OF_RING_BUFS];
struct pcm_stream_info stream_info;
unsigned char eld[HDMI_MAX_ELD_BYTES];
bool dp_output;
enum intel_had_aud_buf_type curr_buf;
int valid_buf_cnt;
unsigned int aes_bits;
spinlock_t had_spinlock;
enum intel_had_aud_buf_type buff_done;
struct device *dev;
struct snd_pcm_chmap *chmap;
int underrun_count;
int tmds_clock_speed;
int link_rate;
/* ring buffer (BD) position index */
unsigned int bd_head;
/* PCM buffer position indices */
unsigned int pcmbuf_head; /* being processed */
unsigned int pcmbuf_filled; /* to be filled */
unsigned int num_bds; /* number of BDs */
unsigned int period_bytes; /* PCM period size in bytes */
/* internal stuff */
int irq;
void __iomem *mmio_start;
......
......@@ -28,13 +28,13 @@
#define HAD_MAX_CHANNEL 8
#define HAD_NUM_OF_RING_BUFS 4
/* Assume 192KHz, 8channel, 25msec period */
#define HAD_MAX_BUFFER (600*1024)
#define HAD_MIN_BUFFER (32*1024)
#define HAD_MAX_PERIODS 4
#define HAD_MIN_PERIODS 4
#define HAD_MAX_PERIOD_BYTES (HAD_MAX_BUFFER/HAD_MIN_PERIODS)
#define HAD_MIN_PERIOD_BYTES 256
/* max 20bit address, aligned to 64 */
#define HAD_MAX_BUFFER ((1024 * 1024 - 1) & ~0x3f)
#define HAD_DEFAULT_BUFFER (600 * 1024) /* default prealloc size */
#define HAD_MAX_PERIODS 256 /* arbitrary, but should suffice */
#define HAD_MIN_PERIODS 2
#define HAD_MAX_PERIOD_BYTES ((HAD_MAX_BUFFER / HAD_MIN_PERIODS) & ~0x3f)
#define HAD_MIN_PERIOD_BYTES 1024 /* might be smaller */
#define HAD_FIFO_SIZE 0 /* fifo not being used */
#define MAX_SPEAKERS 8
......@@ -82,14 +82,6 @@
/* Naud Value */
#define DP_NAUD_VAL 32768
/* enum intel_had_aud_buf_type - HDMI controller ring buffer types */
enum intel_had_aud_buf_type {
HAD_BUF_TYPE_A = 0,
HAD_BUF_TYPE_B = 1,
HAD_BUF_TYPE_C = 2,
HAD_BUF_TYPE_D = 3,
};
/* HDMI Controller register offsets - audio domain common */
/* Base address for below regs = 0x65000 */
enum hdmi_ctrl_reg_offset_common {
......@@ -274,6 +266,9 @@ union aud_buf_addr {
u32 regval;
};
#define AUD_BUF_VALID (1U << 0)
#define AUD_BUF_INTR_EN (1U << 1)
/* Length of Audio Buffer */
union aud_buf_len {
struct {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment