Skip to content

Commit 689c691

Browse files
andim2tiwai
authored andcommitted
ALSA: azt3328: improve snd_azf3328_codec_setdmaa()
- add some WARN_ONCE - add multi-I/O helper (and use helper struct) - fix off-by-1 DMA length bug - better variable naming Signed-off-by: Andreas Mohr <andi@lisas.de> Signed-off-by: Takashi Iwai <tiwai@suse.de>
1 parent da237f3 commit 689c691

1 file changed

Lines changed: 51 additions & 15 deletions

File tree

‎sound/pci/azt3328.c‎

Lines changed: 51 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@
175175

176176
#include <asm/io.h>
177177
#include <linux/init.h>
178+
#include <linux/bug.h> /* WARN_ONCE */
178179
#include <linux/pci.h>
179180
#include <linux/delay.h>
180181
#include <linux/slab.h>
@@ -421,6 +422,21 @@ snd_azf3328_codec_outl(const struct snd_azf3328_codec_data *codec,
421422
outl(value, codec->io_base + reg);
422423
}
423424

425+
static inline void
426+
snd_azf3328_codec_outl_multi(const struct snd_azf3328_codec_data *codec,
427+
unsigned reg, const void *buffer, int count
428+
)
429+
{
430+
unsigned long addr = codec->io_base + reg;
431+
if (count) {
432+
const u32 *buf = buffer;
433+
do {
434+
outl(*buf++, addr);
435+
addr += 4;
436+
} while (--count);
437+
}
438+
}
439+
424440
static inline u32
425441
snd_azf3328_codec_inl(const struct snd_azf3328_codec_data *codec, unsigned reg)
426442
{
@@ -1124,34 +1140,54 @@ snd_azf3328_ctrl_codec_activity(struct snd_azf3328 *chip,
11241140
static void
11251141
snd_azf3328_codec_setdmaa(struct snd_azf3328_codec_data *codec,
11261142
unsigned long addr,
1127-
unsigned int count,
1128-
unsigned int size
1143+
unsigned int period_bytes,
1144+
unsigned int buffer_bytes
11291145
)
11301146
{
11311147
snd_azf3328_dbgcallenter();
1148+
WARN_ONCE(period_bytes & 1, "odd period length!?\n");
1149+
WARN_ONCE(buffer_bytes != 2 * period_bytes,
1150+
"missed our input expectations! %u vs. %u\n",
1151+
buffer_bytes, period_bytes);
11321152
if (!codec->running) {
11331153
/* AZF3328 uses a two buffer pointer DMA transfer approach */
11341154

1135-
unsigned long flags, addr_area2;
1155+
unsigned long flags;
11361156

11371157
/* width 32bit (prevent overflow): */
1138-
u32 count_areas, lengths;
1158+
u32 area_length;
1159+
struct codec_setup_io {
1160+
u32 dma_start_1;
1161+
u32 dma_start_2;
1162+
u32 dma_lengths;
1163+
} __attribute__((packed)) setup_io;
11391164

1140-
count_areas = size/2;
1141-
addr_area2 = addr+count_areas;
1142-
snd_azf3328_dbgcodec("setdma: buffers %08lx[%u] / %08lx[%u]\n",
1143-
addr, count_areas, addr_area2, count_areas);
1165+
area_length = buffer_bytes/2;
11441166

1145-
count_areas--; /* max. index */
1167+
setup_io.dma_start_1 = addr;
1168+
setup_io.dma_start_2 = addr+area_length;
1169+
1170+
snd_azf3328_dbgcodec(
1171+
"setdma: buffers %08x[%u] / %08x[%u], %u, %u\n",
1172+
setup_io.dma_start_1, area_length,
1173+
setup_io.dma_start_2, area_length,
1174+
period_bytes, buffer_bytes);
1175+
1176+
/* Hmm, are we really supposed to decrement this by 1??
1177+
Most definitely certainly not: configuring full length does
1178+
work properly (i.e. likely better), and BTW we
1179+
violated possibly differing frame sizes with this...
1180+
1181+
area_length--; |* max. index *|
1182+
*/
11461183

11471184
/* build combined I/O buffer length word */
1148-
lengths = (count_areas << 16) | (count_areas);
1185+
setup_io.dma_lengths = (area_length << 16) | (area_length);
1186+
11491187
spin_lock_irqsave(codec->lock, flags);
1150-
snd_azf3328_codec_outl(codec, IDX_IO_CODEC_DMA_START_1, addr);
1151-
snd_azf3328_codec_outl(codec, IDX_IO_CODEC_DMA_START_2,
1152-
addr_area2);
1153-
snd_azf3328_codec_outl(codec, IDX_IO_CODEC_DMA_LENGTHS,
1154-
lengths);
1188+
snd_azf3328_codec_outl_multi(
1189+
codec, IDX_IO_CODEC_DMA_START_1, &setup_io, 3
1190+
);
11551191
spin_unlock_irqrestore(codec->lock, flags);
11561192
}
11571193
snd_azf3328_dbgcallleave();

0 commit comments

Comments
 (0)