1

ALSA: asihpi: Use standard print API

Use the standard print API with dev_*() instead of the old house-baked
one.  It gives better information and allows dynamically control of
debug prints.

The debug prints with a special macro snd_printddd() are replaced with
the conditional pr_debug().  Unfortunately dev_dbg() can't be applied
well due to the lack of the reference to the device pointer.

Reviewed-by: Jaroslav Kysela <perex@perex.cz>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Link: https://patch.msgid.link/20240807133452.9424-53-tiwai@suse.de
This commit is contained in:
Takashi Iwai 2024-08-07 15:34:42 +02:00
parent d41abde894
commit 7f5485c4d3
2 changed files with 44 additions and 59 deletions

View File

@ -36,19 +36,10 @@ MODULE_AUTHOR("AudioScience inc. <support@audioscience.com>");
MODULE_DESCRIPTION("AudioScience ALSA ASI5xxx ASI6xxx ASI87xx ASI89xx " MODULE_DESCRIPTION("AudioScience ALSA ASI5xxx ASI6xxx ASI87xx ASI89xx "
HPI_VER_STRING); HPI_VER_STRING);
#if defined CONFIG_SND_DEBUG_VERBOSE #ifdef ASIHPI_VERBOSE_DEBUG
/** #define asihpi_dbg(format, args...) pr_debug(format, ##args)
* snd_printddd - very verbose debug printk
* @format: format string
*
* Works like snd_printk() for debugging purposes.
* Ignored when CONFIG_SND_DEBUG_VERBOSE is not set.
* Must set snd module debug parameter to 3 to enable at runtime.
*/
#define snd_printddd(format, args...) \
__snd_printk(3, __FILE__, __LINE__, format, ##args)
#else #else
#define snd_printddd(format, args...) do { } while (0) #define asihpi_dbg(format, args...) do { } while (0)
#endif #endif
static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* index 0-MAX */ static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* index 0-MAX */
@ -260,8 +251,7 @@ static inline u16 hpi_stream_group_reset(u32 h_stream)
static u16 handle_error(u16 err, int line, char *filename) static u16 handle_error(u16 err, int line, char *filename)
{ {
if (err) if (err)
printk(KERN_WARNING pr_warn("in file %s, line %d: HPI error %d\n",
"in file %s, line %d: HPI error %d\n",
filename, line, err); filename, line, err);
return err; return err;
} }
@ -273,16 +263,18 @@ static u16 handle_error(u16 err, int line, char *filename)
static void print_hwparams(struct snd_pcm_substream *substream, static void print_hwparams(struct snd_pcm_substream *substream,
struct snd_pcm_hw_params *p) struct snd_pcm_hw_params *p)
{ {
struct device *dev = substream->pcm->card->dev;
char name[16]; char name[16];
snd_pcm_debug_name(substream, name, sizeof(name)); snd_pcm_debug_name(substream, name, sizeof(name));
snd_printdd("%s HWPARAMS\n", name); dev_dbg(dev, "%s HWPARAMS\n", name);
snd_printdd(" samplerate=%dHz channels=%d format=%d subformat=%d\n", dev_dbg(dev, " samplerate=%dHz channels=%d format=%d subformat=%d\n",
params_rate(p), params_channels(p), params_rate(p), params_channels(p),
params_format(p), params_subformat(p)); params_format(p), params_subformat(p));
snd_printdd(" buffer=%dB period=%dB period_size=%dB periods=%d\n", dev_dbg(dev, " buffer=%dB period=%dB period_size=%dB periods=%d\n",
params_buffer_bytes(p), params_period_bytes(p), params_buffer_bytes(p), params_period_bytes(p),
params_period_size(p), params_periods(p)); params_period_size(p), params_periods(p));
snd_printdd(" buffer_size=%d access=%d data_rate=%dB/s\n", dev_dbg(dev, " buffer_size=%d access=%d data_rate=%dB/s\n",
params_buffer_size(p), params_access(p), params_buffer_size(p), params_access(p),
params_rate(p) * params_channels(p) * params_rate(p) * params_channels(p) *
snd_pcm_format_width(params_format(p)) / 8); snd_pcm_format_width(params_format(p)) / 8);
@ -317,7 +309,8 @@ static const snd_pcm_format_t hpi_to_alsa_formats[] = {
}; };
static int snd_card_asihpi_format_alsa2hpi(snd_pcm_format_t alsa_format, static int snd_card_asihpi_format_alsa2hpi(struct snd_card_asihpi *asihpi,
snd_pcm_format_t alsa_format,
u16 *hpi_format) u16 *hpi_format)
{ {
u16 format; u16 format;
@ -330,7 +323,7 @@ static int snd_card_asihpi_format_alsa2hpi(snd_pcm_format_t alsa_format,
} }
} }
snd_printd(KERN_WARNING "failed match for alsa format %d\n", dev_dbg(asihpi->card->dev, "failed match for alsa format %d\n",
alsa_format); alsa_format);
*hpi_format = 0; *hpi_format = 0;
return -EINVAL; return -EINVAL;
@ -439,7 +432,7 @@ static int snd_card_asihpi_pcm_hw_params(struct snd_pcm_substream *substream,
unsigned int bytes_per_sec; unsigned int bytes_per_sec;
print_hwparams(substream, params); print_hwparams(substream, params);
err = snd_card_asihpi_format_alsa2hpi(params_format(params), &format); err = snd_card_asihpi_format_alsa2hpi(card, params_format(params), &format);
if (err) if (err)
return err; return err;
@ -461,13 +454,13 @@ static int snd_card_asihpi_pcm_hw_params(struct snd_pcm_substream *substream,
err = hpi_stream_host_buffer_attach(dpcm->h_stream, err = hpi_stream_host_buffer_attach(dpcm->h_stream,
params_buffer_bytes(params), runtime->dma_addr); params_buffer_bytes(params), runtime->dma_addr);
if (err == 0) { if (err == 0) {
snd_printdd( dev_dbg(card->card->dev,
"stream_host_buffer_attach success %u %lu\n", "stream_host_buffer_attach success %u %lu\n",
params_buffer_bytes(params), params_buffer_bytes(params),
(unsigned long)runtime->dma_addr); (unsigned long)runtime->dma_addr);
} else { } else {
snd_printd("stream_host_buffer_attach error %d\n", dev_dbg(card->card->dev,
err); "stream_host_buffer_attach error %d\n", err);
return -ENOMEM; return -ENOMEM;
} }
@ -569,7 +562,7 @@ static int snd_card_asihpi_trigger(struct snd_pcm_substream *substream,
switch (cmd) { switch (cmd) {
case SNDRV_PCM_TRIGGER_START: case SNDRV_PCM_TRIGGER_START:
snd_printdd("%s trigger start\n", name); dev_dbg(card->card->dev, "%s trigger start\n", name);
snd_pcm_group_for_each_entry(s, substream) { snd_pcm_group_for_each_entry(s, substream) {
struct snd_pcm_runtime *runtime = s->runtime; struct snd_pcm_runtime *runtime = s->runtime;
struct snd_card_asihpi_pcm *ds = runtime->private_data; struct snd_card_asihpi_pcm *ds = runtime->private_data;
@ -590,7 +583,7 @@ static int snd_card_asihpi_trigger(struct snd_pcm_substream *substream,
* data?? * data??
*/ */
unsigned int preload = ds->period_bytes * 1; unsigned int preload = ds->period_bytes * 1;
snd_printddd("%d preload %d\n", s->number, preload); asihpi_dbg("%d preload %d\n", s->number, preload);
hpi_handle_error(hpi_outstream_write_buf( hpi_handle_error(hpi_outstream_write_buf(
ds->h_stream, ds->h_stream,
&runtime->dma_area[0], &runtime->dma_area[0],
@ -600,7 +593,7 @@ static int snd_card_asihpi_trigger(struct snd_pcm_substream *substream,
} }
if (card->support_grouping) { if (card->support_grouping) {
snd_printdd("%d group\n", s->number); dev_dbg(card->card->dev, "%d group\n", s->number);
e = hpi_stream_group_add( e = hpi_stream_group_add(
dpcm->h_stream, dpcm->h_stream,
ds->h_stream); ds->h_stream);
@ -621,7 +614,7 @@ static int snd_card_asihpi_trigger(struct snd_pcm_substream *substream,
break; break;
case SNDRV_PCM_TRIGGER_STOP: case SNDRV_PCM_TRIGGER_STOP:
snd_printdd("%s trigger stop\n", name); dev_dbg(card->card->dev, "%s trigger stop\n", name);
card->pcm_stop(substream); card->pcm_stop(substream);
snd_pcm_group_for_each_entry(s, substream) { snd_pcm_group_for_each_entry(s, substream) {
if (snd_pcm_substream_chip(s) != card) if (snd_pcm_substream_chip(s) != card)
@ -635,7 +628,7 @@ static int snd_card_asihpi_trigger(struct snd_pcm_substream *substream,
__snd_pcm_set_state(s->runtime, SNDRV_PCM_STATE_SETUP); __snd_pcm_set_state(s->runtime, SNDRV_PCM_STATE_SETUP);
if (card->support_grouping) { if (card->support_grouping) {
snd_printdd("%d group\n", s->number); dev_dbg(card->card->dev, "%d group\n", s->number);
snd_pcm_trigger_done(s, substream); snd_pcm_trigger_done(s, substream);
} else } else
break; break;
@ -652,17 +645,17 @@ static int snd_card_asihpi_trigger(struct snd_pcm_substream *substream,
break; break;
case SNDRV_PCM_TRIGGER_PAUSE_RELEASE: case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
snd_printdd("%s trigger pause release\n", name); dev_dbg(card->card->dev, "%s trigger pause release\n", name);
card->pcm_start(substream); card->pcm_start(substream);
hpi_handle_error(hpi_stream_start(dpcm->h_stream)); hpi_handle_error(hpi_stream_start(dpcm->h_stream));
break; break;
case SNDRV_PCM_TRIGGER_PAUSE_PUSH: case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
snd_printdd("%s trigger pause push\n", name); dev_dbg(card->card->dev, "%s trigger pause push\n", name);
card->pcm_stop(substream); card->pcm_stop(substream);
hpi_handle_error(hpi_stream_stop(dpcm->h_stream)); hpi_handle_error(hpi_stream_stop(dpcm->h_stream));
break; break;
default: default:
snd_printd(KERN_ERR "\tINVALID\n"); dev_dbg(card->card->dev, "\tINVALID\n");
return -EINVAL; return -EINVAL;
} }
@ -760,12 +753,13 @@ static void snd_card_asihpi_timer_function(struct timer_list *t)
if (state == HPI_STATE_STOPPED) { if (state == HPI_STATE_STOPPED) {
if (bytes_avail == 0) { if (bytes_avail == 0) {
hpi_handle_error(hpi_stream_start(ds->h_stream)); hpi_handle_error(hpi_stream_start(ds->h_stream));
snd_printdd("P%d start\n", s->number); dev_dbg(card->card->dev,
"P%d start\n", s->number);
ds->drained_count = 0; ds->drained_count = 0;
} }
} else if (state == HPI_STATE_DRAINED) { } else if (state == HPI_STATE_DRAINED) {
snd_printd(KERN_WARNING "P%d drained\n", dev_dbg(card->card->dev,
s->number); "P%d drained\n", s->number);
ds->drained_count++; ds->drained_count++;
if (ds->drained_count > 20) { if (ds->drained_count > 20) {
snd_pcm_stop_xrun(s); snd_pcm_stop_xrun(s);
@ -790,7 +784,7 @@ static void snd_card_asihpi_timer_function(struct timer_list *t)
newdata); newdata);
} }
snd_printddd( asihpi_dbg(
"timer1, %s, %d, S=%d, elap=%d, rw=%d, dsp=%d, left=%d, aux=%d, space=%d, hw_ptr=%ld, appl_ptr=%ld\n", "timer1, %s, %d, S=%d, elap=%d, rw=%d, dsp=%d, left=%d, aux=%d, space=%d, hw_ptr=%ld, appl_ptr=%ld\n",
name, s->number, state, name, s->number, state,
ds->pcm_buf_elapsed_dma_ofs, ds->pcm_buf_elapsed_dma_ofs,
@ -821,7 +815,7 @@ static void snd_card_asihpi_timer_function(struct timer_list *t)
next_jiffies = max(next_jiffies, 1U); next_jiffies = max(next_jiffies, 1U);
dpcm->timer.expires = jiffies + next_jiffies; dpcm->timer.expires = jiffies + next_jiffies;
snd_printddd("timer2, jif=%d, buf_pos=%d, newdata=%d, xfer=%d\n", asihpi_dbg("timer2, jif=%d, buf_pos=%d, newdata=%d, xfer=%d\n",
next_jiffies, pcm_buf_dma_ofs, newdata, xfercount); next_jiffies, pcm_buf_dma_ofs, newdata, xfercount);
snd_pcm_group_for_each_entry(s, substream) { snd_pcm_group_for_each_entry(s, substream) {
@ -854,7 +848,7 @@ static void snd_card_asihpi_timer_function(struct timer_list *t)
} }
if (s->stream == SNDRV_PCM_STREAM_PLAYBACK) { if (s->stream == SNDRV_PCM_STREAM_PLAYBACK) {
snd_printddd("write1, P=%d, xfer=%d, buf_ofs=%d\n", asihpi_dbg("write1, P=%d, xfer=%d, buf_ofs=%d\n",
s->number, xfer1, buf_ofs); s->number, xfer1, buf_ofs);
hpi_handle_error( hpi_handle_error(
hpi_outstream_write_buf( hpi_outstream_write_buf(
@ -864,7 +858,7 @@ static void snd_card_asihpi_timer_function(struct timer_list *t)
if (xfer2) { if (xfer2) {
pd = s->runtime->dma_area; pd = s->runtime->dma_area;
snd_printddd("write2, P=%d, xfer=%d, buf_ofs=%d\n", asihpi_dbg("write2, P=%d, xfer=%d, buf_ofs=%d\n",
s->number, s->number,
xfercount - xfer1, buf_ofs); xfercount - xfer1, buf_ofs);
hpi_handle_error( hpi_handle_error(
@ -874,7 +868,7 @@ static void snd_card_asihpi_timer_function(struct timer_list *t)
&ds->format)); &ds->format));
} }
} else { } else {
snd_printddd("read1, C=%d, xfer=%d\n", asihpi_dbg("read1, C=%d, xfer=%d\n",
s->number, xfer1); s->number, xfer1);
hpi_handle_error( hpi_handle_error(
hpi_instream_read_buf( hpi_instream_read_buf(
@ -882,7 +876,7 @@ static void snd_card_asihpi_timer_function(struct timer_list *t)
pd, xfer1)); pd, xfer1));
if (xfer2) { if (xfer2) {
pd = s->runtime->dma_area; pd = s->runtime->dma_area;
snd_printddd("read2, C=%d, xfer=%d\n", asihpi_dbg("read2, C=%d, xfer=%d\n",
s->number, xfer2); s->number, xfer2);
hpi_handle_error( hpi_handle_error(
hpi_instream_read_buf( hpi_instream_read_buf(
@ -919,8 +913,6 @@ static int snd_card_asihpi_playback_prepare(struct snd_pcm_substream *
struct snd_pcm_runtime *runtime = substream->runtime; struct snd_pcm_runtime *runtime = substream->runtime;
struct snd_card_asihpi_pcm *dpcm = runtime->private_data; struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
snd_printdd("P%d prepare\n", substream->number);
hpi_handle_error(hpi_outstream_reset(dpcm->h_stream)); hpi_handle_error(hpi_outstream_reset(dpcm->h_stream));
dpcm->pcm_buf_host_rw_ofs = 0; dpcm->pcm_buf_host_rw_ofs = 0;
dpcm->pcm_buf_dma_ofs = 0; dpcm->pcm_buf_dma_ofs = 0;
@ -938,7 +930,7 @@ snd_card_asihpi_playback_pointer(struct snd_pcm_substream *substream)
snd_pcm_debug_name(substream, name, sizeof(name)); snd_pcm_debug_name(substream, name, sizeof(name));
ptr = bytes_to_frames(runtime, dpcm->pcm_buf_dma_ofs % dpcm->buffer_bytes); ptr = bytes_to_frames(runtime, dpcm->pcm_buf_dma_ofs % dpcm->buffer_bytes);
snd_printddd("%s, pointer=%ld\n", name, (unsigned long)ptr); asihpi_dbg("%s, pointer=%ld\n", name, (unsigned long)ptr);
return ptr; return ptr;
} }
@ -1060,8 +1052,6 @@ static int snd_card_asihpi_playback_open(struct snd_pcm_substream *substream)
snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_PERIOD_SIZE, snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
card->update_interval_frames, UINT_MAX); card->update_interval_frames, UINT_MAX);
snd_printdd("playback open\n");
return 0; return 0;
} }
@ -1071,8 +1061,6 @@ static int snd_card_asihpi_playback_close(struct snd_pcm_substream *substream)
struct snd_card_asihpi_pcm *dpcm = runtime->private_data; struct snd_card_asihpi_pcm *dpcm = runtime->private_data;
hpi_handle_error(hpi_outstream_close(dpcm->h_stream)); hpi_handle_error(hpi_outstream_close(dpcm->h_stream));
snd_printdd("playback close\n");
return 0; return 0;
} }
@ -1095,7 +1083,7 @@ snd_card_asihpi_capture_pointer(struct snd_pcm_substream *substream)
char name[16]; char name[16];
snd_pcm_debug_name(substream, name, sizeof(name)); snd_pcm_debug_name(substream, name, sizeof(name));
snd_printddd("%s, pointer=%d\n", name, dpcm->pcm_buf_dma_ofs); asihpi_dbg("%s, pointer=%d\n", name, dpcm->pcm_buf_dma_ofs);
/* NOTE Unlike playback can't use actual samples_played /* NOTE Unlike playback can't use actual samples_played
for the capture position, because those samples aren't yet in for the capture position, because those samples aren't yet in
the local buffer available for reading. the local buffer available for reading.
@ -1113,7 +1101,6 @@ static int snd_card_asihpi_capture_prepare(struct snd_pcm_substream *substream)
dpcm->pcm_buf_dma_ofs = 0; dpcm->pcm_buf_dma_ofs = 0;
dpcm->pcm_buf_elapsed_dma_ofs = 0; dpcm->pcm_buf_elapsed_dma_ofs = 0;
snd_printdd("Capture Prepare %d\n", substream->number);
return 0; return 0;
} }
@ -1162,7 +1149,8 @@ static int snd_card_asihpi_capture_open(struct snd_pcm_substream *substream)
if (dpcm == NULL) if (dpcm == NULL)
return -ENOMEM; return -ENOMEM;
snd_printdd("capture open adapter %d stream %d\n",
dev_dbg(card->card->dev, "capture open adapter %d stream %d\n",
card->hpi->adapter->index, substream->number); card->hpi->adapter->index, substream->number);
err = hpi_handle_error( err = hpi_handle_error(
@ -1413,8 +1401,6 @@ static void asihpi_ctl_init(struct snd_kcontrol_new *snd_control,
hpi_ctl->src_node_index, hpi_ctl->src_node_index,
dir, name); dir, name);
} }
/* printk(KERN_INFO "Adding %s %d to %d ", hpi_ctl->name,
hpi_ctl->wSrcNodeType, hpi_ctl->wDstNodeType); */
} }
/*------------------------------------------------------------ /*------------------------------------------------------------
@ -2175,9 +2161,8 @@ static int snd_asihpi_mux_get(struct snd_kcontrol *kcontrol,
return 0; return 0;
} }
} }
snd_printd(KERN_WARNING pr_warn("%s: Control %x failed to match mux source %hu %hu\n",
"Control %x failed to match mux source %hu %hu\n", __func__, h_control, source_type, source_index);
h_control, source_type, source_index);
ucontrol->value.enumerated.item[0] = 0; ucontrol->value.enumerated.item[0] = 0;
return 0; return 0;
} }

View File

@ -356,7 +356,7 @@ int asihpi_adapter_probe(struct pci_dev *pci_dev,
memset(&adapter, 0, sizeof(adapter)); memset(&adapter, 0, sizeof(adapter));
dev_printk(KERN_DEBUG, &pci_dev->dev, dev_dbg(&pci_dev->dev,
"probe %04x:%04x,%04x:%04x,%04x\n", pci_dev->vendor, "probe %04x:%04x,%04x:%04x,%04x\n", pci_dev->vendor,
pci_dev->device, pci_dev->subsystem_vendor, pci_dev->device, pci_dev->subsystem_vendor,
pci_dev->subsystem_device, pci_dev->devfn); pci_dev->subsystem_device, pci_dev->devfn);