ALSA: ymfpci: Add error messages for abritrary IO ports on older chips
authorTasos Sahanidis <tasos@tasossah.com>
Wed, 29 Mar 2023 03:42:04 +0000 (06:42 +0300)
committerTakashi Iwai <tiwai@suse.de>
Wed, 29 Mar 2023 06:27:48 +0000 (08:27 +0200)
As an end user, it can be confusing to request an arbitrary IO port be
used only to find out that it doesn't work without an obvious reason,
especially since /sys/module/snd_ymfpci/parameters/{fm,joystick,mpu}_port
indicate 0 after the module has been loaded.

In my case, I was unaware that the YMF724 did not support such usage, and
thus ended up spending time attempting to debug the issue.

Now, when a user attempts to request an IO port that isn't supported by
the hardware, the following message is printed:

[   25.549530] snd_ymfpci 0000:06:05.0: The Yamaha DS-1 (YMF724F) does not support arbitrary IO ports for FM (requested 0x1234)

Signed-off-by: Tasos Sahanidis <tasos@tasossah.com>
Link: https://lore.kernel.org/r/20230329034204.171901-1-tasos@tasossah.com
Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/pci/ymfpci/ymfpci.c

index 1e198e4..de5dc53 100644 (file)
@@ -98,8 +98,10 @@ static int snd_ymfpci_create_gameport(struct snd_ymfpci *chip, int dev,
                case 0x204: legacy_ctrl2 |= 2 << 6; break;
                case 0x205: legacy_ctrl2 |= 3 << 6; break;
                default:
-                       dev_err(chip->card->dev,
-                               "invalid joystick port %#x", io_port);
+                       if (io_port > 0)
+                               dev_err(chip->card->dev,
+                                       "The %s does not support arbitrary IO ports for the game port (requested 0x%x)\n",
+                                       chip->card->shortname, (unsigned int)io_port);
                        return -EINVAL;
                }
        }
@@ -186,6 +188,13 @@ static int snd_card_ymfpci_probe(struct pci_dev *pci,
        default: model = str = "???"; break;
        }
 
+       strcpy(card->driver, str);
+       sprintf(card->shortname, "Yamaha %s (%s)", model, str);
+       sprintf(card->longname, "%s at 0x%lx, irq %i",
+               card->shortname,
+               chip->reg_area_phys,
+               chip->irq);
+
        legacy_ctrl = 0;
        legacy_ctrl2 = 0x0800;  /* SBEN = 0, SMOD = 01, LAD = 0 */
 
@@ -218,7 +227,13 @@ static int snd_card_ymfpci_probe(struct pci_dev *pci,
                case 0x398: legacy_ctrl2 |= 1; break;
                case 0x3a0: legacy_ctrl2 |= 2; break;
                case 0x3a8: legacy_ctrl2 |= 3; break;
-               default: fm_port[dev] = 0; break;
+               default:
+                       if (fm_port[dev] > 0)
+                               dev_err(card->dev,
+                                       "The %s does not support arbitrary IO ports for FM (requested 0x%x)\n",
+                                       card->shortname, (unsigned int)fm_port[dev]);
+                       fm_port[dev] = 0;
+                       break;
                }
                if (fm_port[dev] > 0)
                        fm_res = devm_request_region(&pci->dev, fm_port[dev],
@@ -234,7 +249,13 @@ static int snd_card_ymfpci_probe(struct pci_dev *pci,
                case 0x300: legacy_ctrl2 |= 1 << 4; break;
                case 0x332: legacy_ctrl2 |= 2 << 4; break;
                case 0x334: legacy_ctrl2 |= 3 << 4; break;
-               default: mpu_port[dev] = 0; break;
+               default:
+                       if (mpu_port[dev] > 0)
+                               dev_err(card->dev,
+                                       "The %s does not support arbitrary IO ports for MPU-401 (requested 0x%x)\n",
+                                       card->shortname, (unsigned int)mpu_port[dev]);
+                       mpu_port[dev] = 0;
+                       break;
                }
                if (mpu_port[dev] > 0)
                        mpu_res = devm_request_region(&pci->dev, mpu_port[dev],
@@ -257,12 +278,6 @@ static int snd_card_ymfpci_probe(struct pci_dev *pci,
        if (err  < 0)
                return err;
 
-       strcpy(card->driver, str);
-       sprintf(card->shortname, "Yamaha %s (%s)", model, str);
-       sprintf(card->longname, "%s at 0x%lx, irq %i",
-               card->shortname,
-               chip->reg_area_phys,
-               chip->irq);
        err = snd_ymfpci_pcm(chip, 0);
        if (err < 0)
                return err;