The real constructor of PCI drivers is probe callback. The
probe callback and other component-constructors which are called
from probe callback should be defined with
__devinit prefix. You
cannot use __init prefix for them,
because any PCI device could be a hotplug device.
In the probe callback, the following scheme is often used.
static int dev;
....
if (dev >= SNDRV_CARDS)
return -ENODEV;
if (!enable[dev]) {
dev++;
return -ENOENT;
}
At each time probe callback is called, check the availability of the device. If not available, simply increment the device index and returns. dev will be incremented also later (step 7).
The detail will be explained in the section Management of Cards and Components.
In this part, the PCI resources are allocated.
struct mychip *chip;
....
if ((err = snd_mychip_create(card, pci, &chip)) < 0) {
snd_card_free(card);
return err;
}
strcpy(card->driver, "My Chip");
strcpy(card->shortname, "My Own Chip 123");
sprintf(card->longname, "%s at 0x%lx irq %i",
card->shortname, chip->ioport, chip->irq);
The shortname field is a string shown as more verbose name. The longname field contains the information which is shown in /proc/asound/cards.
Here you define the basic components such as PCM, mixer (e.g. AC97), MIDI (e.g. MPU-401), and other interfaces. Also, if you want a proc file, define it here, too.
Will be explained in the section Management of Cards and Components, too.
In the above, the card record is stored. This pointer is referred in the remove callback and power-management callbacks, too.