ALSA: opl3: 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.

Some debug prints are cleaned up with a macro, too.

Reviewed-by: Jaroslav Kysela <perex@perex.cz>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
Link: https://patch.msgid.link/20240807133452.9424-7-tiwai@suse.de
This commit is contained in:
Takashi Iwai 2024-08-07 15:33:56 +02:00
parent 1e594f9a7b
commit a2fa882d6d
4 changed files with 56 additions and 73 deletions

View File

@ -92,7 +92,7 @@ static int snd_opl3_detect(struct snd_opl3 * opl3)
opl3->command(opl3, OPL3_LEFT | OPL3_REG_TIMER_CONTROL, OPL3_IRQ_RESET); opl3->command(opl3, OPL3_LEFT | OPL3_REG_TIMER_CONTROL, OPL3_IRQ_RESET);
signature = stat1 = inb(opl3->l_port); /* Status register */ signature = stat1 = inb(opl3->l_port); /* Status register */
if ((stat1 & 0xe0) != 0x00) { /* Should be 0x00 */ if ((stat1 & 0xe0) != 0x00) { /* Should be 0x00 */
snd_printd("OPL3: stat1 = 0x%x\n", stat1); dev_dbg(opl3->card->dev, "OPL3: stat1 = 0x%x\n", stat1);
return -ENODEV; return -ENODEV;
} }
/* Set timer1 to 0xff */ /* Set timer1 to 0xff */
@ -108,7 +108,7 @@ static int snd_opl3_detect(struct snd_opl3 * opl3)
/* Reset the IRQ of the FM chip */ /* Reset the IRQ of the FM chip */
opl3->command(opl3, OPL3_LEFT | OPL3_REG_TIMER_CONTROL, OPL3_IRQ_RESET); opl3->command(opl3, OPL3_LEFT | OPL3_REG_TIMER_CONTROL, OPL3_IRQ_RESET);
if ((stat2 & 0xe0) != 0xc0) { /* There is no YM3812 */ if ((stat2 & 0xe0) != 0xc0) { /* There is no YM3812 */
snd_printd("OPL3: stat2 = 0x%x\n", stat2); dev_dbg(opl3->card->dev, "OPL3: stat2 = 0x%x\n", stat2);
return -ENODEV; return -ENODEV;
} }
@ -289,9 +289,6 @@ void snd_opl3_interrupt(struct snd_hwdep * hw)
opl3 = hw->private_data; opl3 = hw->private_data;
status = inb(opl3->l_port); status = inb(opl3->l_port);
#if 0
snd_printk(KERN_DEBUG "AdLib IRQ status = 0x%x\n", status);
#endif
if (!(status & 0x80)) if (!(status & 0x80))
return; return;
@ -365,7 +362,8 @@ EXPORT_SYMBOL(snd_opl3_new);
int snd_opl3_init(struct snd_opl3 *opl3) int snd_opl3_init(struct snd_opl3 *opl3)
{ {
if (! opl3->command) { if (! opl3->command) {
printk(KERN_ERR "snd_opl3_init: command not defined!\n"); dev_err(opl3->card->dev,
"snd_opl3_init: command not defined!\n");
return -EINVAL; return -EINVAL;
} }
@ -405,14 +403,14 @@ int snd_opl3_create(struct snd_card *card,
if (! integrated) { if (! integrated) {
opl3->res_l_port = request_region(l_port, 2, "OPL2/3 (left)"); opl3->res_l_port = request_region(l_port, 2, "OPL2/3 (left)");
if (!opl3->res_l_port) { if (!opl3->res_l_port) {
snd_printk(KERN_ERR "opl3: can't grab left port 0x%lx\n", l_port); dev_err(card->dev, "opl3: can't grab left port 0x%lx\n", l_port);
snd_device_free(card, opl3); snd_device_free(card, opl3);
return -EBUSY; return -EBUSY;
} }
if (r_port != 0) { if (r_port != 0) {
opl3->res_r_port = request_region(r_port, 2, "OPL2/3 (right)"); opl3->res_r_port = request_region(r_port, 2, "OPL2/3 (right)");
if (!opl3->res_r_port) { if (!opl3->res_r_port) {
snd_printk(KERN_ERR "opl3: can't grab right port 0x%lx\n", r_port); dev_err(card->dev, "opl3: can't grab right port 0x%lx\n", r_port);
snd_device_free(card, opl3); snd_device_free(card, opl3);
return -EBUSY; return -EBUSY;
} }
@ -432,8 +430,8 @@ int snd_opl3_create(struct snd_card *card,
opl3->command = &snd_opl2_command; opl3->command = &snd_opl2_command;
err = snd_opl3_detect(opl3); err = snd_opl3_detect(opl3);
if (err < 0) { if (err < 0) {
snd_printd("OPL2/3 chip not detected at 0x%lx/0x%lx\n", dev_dbg(card->dev, "OPL2/3 chip not detected at 0x%lx/0x%lx\n",
opl3->l_port, opl3->r_port); opl3->l_port, opl3->r_port);
snd_device_free(card, opl3); snd_device_free(card, opl3);
return err; return err;
} }

View File

@ -11,6 +11,13 @@
#include "opl3_voice.h" #include "opl3_voice.h"
#include <sound/asoundef.h> #include <sound/asoundef.h>
#ifdef DEBUG_MIDI
#define opl3_dbg(opl3, fmt, ...) \
dev_dbg(((struct snd_opl3 *)(opl3))->card->dev, fmt, ##__VA_ARGS__)
#else
#define opl3_dbg(opl3, fmt, ...) do {} while (0)
#endif
static void snd_opl3_note_off_unsafe(void *p, int note, int vel, static void snd_opl3_note_off_unsafe(void *p, int note, int vel,
struct snd_midi_channel *chan); struct snd_midi_channel *chan);
/* /*
@ -107,14 +114,17 @@ static void snd_opl3_calc_pitch(unsigned char *fnum, unsigned char *blocknum,
#ifdef DEBUG_ALLOC #ifdef DEBUG_ALLOC
static void debug_alloc(struct snd_opl3 *opl3, char *s, int voice) { static void debug_alloc(struct snd_opl3 *opl3, char *s, int voice)
{
int i; int i;
char *str = "x.24"; const char *str = "x.24";
char buf[MAX_OPL3_VOICES + 1];
printk(KERN_DEBUG "time %.5i: %s [%.2i]: ", opl3->use_time, s, voice);
for (i = 0; i < opl3->max_voices; i++) for (i = 0; i < opl3->max_voices; i++)
printk(KERN_CONT "%c", *(str + opl3->voices[i].state + 1)); buf[i] = str[opl3->voices[i].state + 1];
printk(KERN_CONT "\n"); buf[i] = 0;
dev_dbg(opl3->card->dev, "time %.5i: %s [%.2i]: %s\n",
opl3->use_time, s, voice, buf);
} }
#endif #endif
@ -203,9 +213,10 @@ static int opl3_get_voice(struct snd_opl3 *opl3, int instr_4op,
for (i = 0; i < END; i++) { for (i = 0; i < END; i++) {
if (best[i].voice >= 0) { if (best[i].voice >= 0) {
#ifdef DEBUG_ALLOC #ifdef DEBUG_ALLOC
printk(KERN_DEBUG "%s %iop allocation on voice %i\n", dev_dbg(opl3->card->dev,
alloc_type[i], instr_4op ? 4 : 2, "%s %iop allocation on voice %i\n",
best[i].voice); alloc_type[i], instr_4op ? 4 : 2,
best[i].voice);
#endif #endif
return best[i].voice; return best[i].voice;
} }
@ -302,10 +313,8 @@ void snd_opl3_note_on(void *p, int note, int vel, struct snd_midi_channel *chan)
opl3 = p; opl3 = p;
#ifdef DEBUG_MIDI opl3_dbg(opl3, "Note on, ch %i, inst %i, note %i, vel %i\n",
snd_printk(KERN_DEBUG "Note on, ch %i, inst %i, note %i, vel %i\n", chan->number, chan->midi_program, note, vel);
chan->number, chan->midi_program, note, vel);
#endif
/* in SYNTH mode, application takes care of voices */ /* in SYNTH mode, application takes care of voices */
/* in SEQ mode, drum voice numbers are notes on drum channel */ /* in SEQ mode, drum voice numbers are notes on drum channel */
@ -358,10 +367,8 @@ void snd_opl3_note_on(void *p, int note, int vel, struct snd_midi_channel *chan)
spin_unlock_irqrestore(&opl3->voice_lock, flags); spin_unlock_irqrestore(&opl3->voice_lock, flags);
return; return;
} }
#ifdef DEBUG_MIDI opl3_dbg(opl3, " --> OPL%i instrument: %s\n",
snd_printk(KERN_DEBUG " --> OPL%i instrument: %s\n", instr_4op ? 3 : 2, patch->name);
instr_4op ? 3 : 2, patch->name);
#endif
/* in SYNTH mode, application takes care of voices */ /* in SYNTH mode, application takes care of voices */
/* in SEQ mode, allocate voice on free OPL3 channel */ /* in SEQ mode, allocate voice on free OPL3 channel */
if (opl3->synth_mode == SNDRV_OPL3_MODE_SEQ) { if (opl3->synth_mode == SNDRV_OPL3_MODE_SEQ) {
@ -422,10 +429,8 @@ void snd_opl3_note_on(void *p, int note, int vel, struct snd_midi_channel *chan)
} }
} }
#ifdef DEBUG_MIDI opl3_dbg(opl3, " --> setting OPL3 connection: 0x%x\n",
snd_printk(KERN_DEBUG " --> setting OPL3 connection: 0x%x\n", opl3->connection_reg);
opl3->connection_reg);
#endif
/* /*
* calculate volume depending on connection * calculate volume depending on connection
* between FM operators (see include/opl3.h) * between FM operators (see include/opl3.h)
@ -457,9 +462,7 @@ void snd_opl3_note_on(void *p, int note, int vel, struct snd_midi_channel *chan)
/* Program the FM voice characteristics */ /* Program the FM voice characteristics */
for (i = 0; i < (instr_4op ? 4 : 2); i++) { for (i = 0; i < (instr_4op ? 4 : 2); i++) {
#ifdef DEBUG_MIDI opl3_dbg(opl3, " --> programming operator %i\n", i);
snd_printk(KERN_DEBUG " --> programming operator %i\n", i);
#endif
op_offset = snd_opl3_regmap[voice_offset][i]; op_offset = snd_opl3_regmap[voice_offset][i];
/* Set OPL3 AM_VIB register of requested voice/operator */ /* Set OPL3 AM_VIB register of requested voice/operator */
@ -537,9 +540,7 @@ void snd_opl3_note_on(void *p, int note, int vel, struct snd_midi_channel *chan)
/* Set output sound flag */ /* Set output sound flag */
blocknum |= OPL3_KEYON_BIT; blocknum |= OPL3_KEYON_BIT;
#ifdef DEBUG_MIDI opl3_dbg(opl3, " --> trigger voice %i\n", voice);
snd_printk(KERN_DEBUG " --> trigger voice %i\n", voice);
#endif
/* Set OPL3 KEYON_BLOCK register of requested voice */ /* Set OPL3 KEYON_BLOCK register of requested voice */
opl3_reg = reg_side | (OPL3_REG_KEYON_BLOCK + voice_offset); opl3_reg = reg_side | (OPL3_REG_KEYON_BLOCK + voice_offset);
opl3->command(opl3, opl3_reg, blocknum); opl3->command(opl3, opl3_reg, blocknum);
@ -593,9 +594,7 @@ void snd_opl3_note_on(void *p, int note, int vel, struct snd_midi_channel *chan)
bank = 0; bank = 0;
prg = extra_prg - 1; prg = extra_prg - 1;
} }
#ifdef DEBUG_MIDI opl3_dbg(opl3, " *** allocating extra program\n");
snd_printk(KERN_DEBUG " *** allocating extra program\n");
#endif
goto __extra_prg; goto __extra_prg;
} }
spin_unlock_irqrestore(&opl3->voice_lock, flags); spin_unlock_irqrestore(&opl3->voice_lock, flags);
@ -624,9 +623,7 @@ static void snd_opl3_kill_voice(struct snd_opl3 *opl3, int voice)
} }
/* kill voice */ /* kill voice */
#ifdef DEBUG_MIDI opl3_dbg(opl3, " --> kill voice %i\n", voice);
snd_printk(KERN_DEBUG " --> kill voice %i\n", voice);
#endif
opl3_reg = reg_side | (OPL3_REG_KEYON_BLOCK + voice_offset); opl3_reg = reg_side | (OPL3_REG_KEYON_BLOCK + voice_offset);
/* clear Key ON bit */ /* clear Key ON bit */
opl3->command(opl3, opl3_reg, vp->keyon_reg); opl3->command(opl3, opl3_reg, vp->keyon_reg);
@ -660,10 +657,8 @@ static void snd_opl3_note_off_unsafe(void *p, int note, int vel,
opl3 = p; opl3 = p;
#ifdef DEBUG_MIDI opl3_dbg(opl3, "Note off, ch %i, inst %i, note %i\n",
snd_printk(KERN_DEBUG "Note off, ch %i, inst %i, note %i\n", chan->number, chan->midi_program, note);
chan->number, chan->midi_program, note);
#endif
if (opl3->synth_mode == SNDRV_OPL3_MODE_SEQ) { if (opl3->synth_mode == SNDRV_OPL3_MODE_SEQ) {
if (chan->drum_channel && use_internal_drums) { if (chan->drum_channel && use_internal_drums) {
@ -703,10 +698,8 @@ void snd_opl3_note_off(void *p, int note, int vel,
*/ */
void snd_opl3_key_press(void *p, int note, int vel, struct snd_midi_channel *chan) void snd_opl3_key_press(void *p, int note, int vel, struct snd_midi_channel *chan)
{ {
#ifdef DEBUG_MIDI opl3_dbg(p, "Key pressure, ch#: %i, inst#: %i\n",
snd_printk(KERN_DEBUG "Key pressure, ch#: %i, inst#: %i\n", chan->number, chan->midi_program);
chan->number, chan->midi_program);
#endif
} }
/* /*
@ -714,10 +707,8 @@ void snd_opl3_key_press(void *p, int note, int vel, struct snd_midi_channel *cha
*/ */
void snd_opl3_terminate_note(void *p, int note, struct snd_midi_channel *chan) void snd_opl3_terminate_note(void *p, int note, struct snd_midi_channel *chan)
{ {
#ifdef DEBUG_MIDI opl3_dbg(p, "Terminate note, ch#: %i, inst#: %i\n",
snd_printk(KERN_DEBUG "Terminate note, ch#: %i, inst#: %i\n", chan->number, chan->midi_program);
chan->number, chan->midi_program);
#endif
} }
static void snd_opl3_update_pitch(struct snd_opl3 *opl3, int voice) static void snd_opl3_update_pitch(struct snd_opl3 *opl3, int voice)
@ -803,10 +794,8 @@ void snd_opl3_control(void *p, int type, struct snd_midi_channel *chan)
struct snd_opl3 *opl3; struct snd_opl3 *opl3;
opl3 = p; opl3 = p;
#ifdef DEBUG_MIDI opl3_dbg(opl3, "Controller, TYPE = %i, ch#: %i, inst#: %i\n",
snd_printk(KERN_DEBUG "Controller, TYPE = %i, ch#: %i, inst#: %i\n", type, chan->number, chan->midi_program);
type, chan->number, chan->midi_program);
#endif
switch (type) { switch (type) {
case MIDI_CTL_MSB_MODWHEEL: case MIDI_CTL_MSB_MODWHEEL:
@ -837,10 +826,8 @@ void snd_opl3_control(void *p, int type, struct snd_midi_channel *chan)
void snd_opl3_nrpn(void *p, struct snd_midi_channel *chan, void snd_opl3_nrpn(void *p, struct snd_midi_channel *chan,
struct snd_midi_channel_set *chset) struct snd_midi_channel_set *chset)
{ {
#ifdef DEBUG_MIDI opl3_dbg(p, "NRPN, ch#: %i, inst#: %i\n",
snd_printk(KERN_DEBUG "NRPN, ch#: %i, inst#: %i\n", chan->number, chan->midi_program);
chan->number, chan->midi_program);
#endif
} }
/* /*
@ -849,7 +836,5 @@ void snd_opl3_nrpn(void *p, struct snd_midi_channel *chan,
void snd_opl3_sysex(void *p, unsigned char *buf, int len, void snd_opl3_sysex(void *p, unsigned char *buf, int len,
int parsed, struct snd_midi_channel_set *chset) int parsed, struct snd_midi_channel_set *chset)
{ {
#ifdef DEBUG_MIDI opl3_dbg(p, "SYSEX\n");
snd_printk(KERN_DEBUG "SYSEX\n");
#endif
} }

View File

@ -193,14 +193,14 @@ static int snd_opl3_load_patch_seq_oss(struct snd_seq_oss_arg *arg, int format,
return -EINVAL; return -EINVAL;
if (count < (int)sizeof(sbi)) { if (count < (int)sizeof(sbi)) {
snd_printk(KERN_ERR "FM Error: Patch record too short\n"); dev_err(opl3->card->dev, "FM Error: Patch record too short\n");
return -EINVAL; return -EINVAL;
} }
if (copy_from_user(&sbi, buf, sizeof(sbi))) if (copy_from_user(&sbi, buf, sizeof(sbi)))
return -EFAULT; return -EFAULT;
if (sbi.channel < 0 || sbi.channel >= SBFM_MAXINSTR) { if (sbi.channel < 0 || sbi.channel >= SBFM_MAXINSTR) {
snd_printk(KERN_ERR "FM Error: Invalid instrument number %d\n", dev_err(opl3->card->dev, "FM Error: Invalid instrument number %d\n",
sbi.channel); sbi.channel);
return -EINVAL; return -EINVAL;
} }
@ -220,13 +220,15 @@ static int snd_opl3_load_patch_seq_oss(struct snd_seq_oss_arg *arg, int format,
static int snd_opl3_ioctl_seq_oss(struct snd_seq_oss_arg *arg, unsigned int cmd, static int snd_opl3_ioctl_seq_oss(struct snd_seq_oss_arg *arg, unsigned int cmd,
unsigned long ioarg) unsigned long ioarg)
{ {
struct snd_opl3 *opl3;
if (snd_BUG_ON(!arg)) if (snd_BUG_ON(!arg))
return -ENXIO; return -ENXIO;
opl3 = arg->private_data;
switch (cmd) { switch (cmd) {
case SNDCTL_FM_LOAD_INSTR: case SNDCTL_FM_LOAD_INSTR:
snd_printk(KERN_ERR "OPL3: " dev_err(opl3->card->dev,
"Obsolete ioctl(SNDCTL_FM_LOAD_INSTR) used. " "OPL3: Obsolete ioctl(SNDCTL_FM_LOAD_INSTR) used. Fix the program.\n");
"Fix the program.\n");
return -EINVAL; return -EINVAL;
case SNDCTL_SYNTH_MEMAVL: case SNDCTL_SYNTH_MEMAVL:

View File

@ -158,10 +158,8 @@ int snd_opl3_ioctl(struct snd_hwdep * hw, struct file *file,
return 0; return 0;
#endif #endif
#ifdef CONFIG_SND_DEBUG
default: default:
snd_printk(KERN_WARNING "unknown IOCTL: 0x%x\n", cmd); dev_dbg(opl3->card->dev, "unknown IOCTL: 0x%x\n", cmd);
#endif
} }
return -ENOTTY; return -ENOTTY;
} }