The chip-specific information, e.g. the i/o port address, its resource pointer, or the irq number, is stored in the chip-specific record.
In general, there are two ways to allocate the chip record.
snd_card_new(). As mentioned above, you can pass the extra-data-length to the 4th argument of snd_card_new(), i.e.
mychip is the type of the chip record.
In return, the allocated record can be accessed as
With this method, you don't have to allocate twice. The record is released together with the card instance. After allocating a card instance via
snd_card_new() (with
NULL on the 4th arg), call
kzalloc().
struct snd_card *card;
struct mychip *chip;
card = snd_card_new(index[dev], id[dev], THIS_MODULE, NULL);
.....
chip = kzalloc(sizeof(*chip), GFP_KERNEL);
The chip record should have the field to hold the card pointer at least,
Then, set the card pointer in the returned chip instance.
Next, initialize the fields, and register this chip
record as a low-level device with a specified
ops,
static struct snd_device_ops ops = {
.dev_free = snd_mychip_dev_free,
};
....
snd_device_new(card, SNDRV_DEV_LOWLEVEL, chip, &ops);
snd_mychip_dev_free() is the
device-destructor function, which will call the real
destructor.
static int snd_mychip_dev_free(struct snd_device *device)
{
return snd_mychip_free(device->device_data);
}
snd_mychip_free() is the real destructor.