Hardware-Dependent Devices

Some chips need user-space access for special controls or for loading the micro code. In such a case, you can create a hwdep (hardware-dependent) device. The hwdep API is defined in <sound/hwdep.h>. You can find examples in opl3 driver or isa/sb/sb16_csp.c.

The creation of the hwdep instance is done via snd_hwdep_new().

  struct snd_hwdep *hw;
  snd_hwdep_new(card, "My HWDEP", 0, &hw);


where the third argument is the index number.

You can then pass any pointer value to the private_data. If you assign a private data, you should define the destructor, too. The destructor function is set in the private_free field.

  struct mydata *p = kmalloc(sizeof(*p), GFP_KERNEL);
  hw->private_data = p;
  hw->private_free = mydata_free;


and the implementation of the destructor would be:

  static void mydata_free(struct snd_hwdep *hw)
          struct mydata *p = hw->private_data;


The arbitrary file operations can be defined for this instance. The file operators are defined in the ops table. For example, assume that this chip needs an ioctl.

  hw->ops.open = mydata_open;
  hw->ops.ioctl = mydata_ioctl;
  hw->ops.release = mydata_release;


And implement the callback functions as you like.