After the card is created, you can attach the components (devices) to the card instance. In an ALSA driver, a component is represented as a struct snd_device object. A component can be a PCM instance, a control interface, a raw MIDI interface, etc. Each such instance has one component entry.

A component can be created via snd_device_new() function.

  snd_device_new(card, SNDRV_DEV_XXX, chip, &ops);


This takes the card pointer, the device-level (SNDRV_DEV_XXX), the data pointer, and the callback pointers (&ops). The device-level defines the type of components and the order of registration and de-registration. For most components, the device-level is already defined. For a user-defined component, you can use SNDRV_DEV_LOWLEVEL.

This function itself doesn't allocate the data space. The data must be allocated manually beforehand, and its pointer is passed as the argument. This pointer is used as the (chip identifier in the above example) for the instance.

Each pre-defined ALSA component such as ac97 and pcm calls snd_device_new() inside its constructor. The destructor for each component is defined in the callback pointers. Hence, you don't need to take care of calling a destructor for such a component.

If you wish to create your own component, you need to set the destructor function to the dev_free callback in the ops, so that it can be released automatically via snd_card_free(). The next example will show an implementation of chip-specific data.