All of lore.kernel.org
 help / color / mirror / Atom feed
* ioctl request code for specific alsa control
@ 2008-05-13 18:31 Peter Wurmsdobler
  2008-05-14  9:17 ` Clemens Ladisch
  0 siblings, 1 reply; 4+ messages in thread
From: Peter Wurmsdobler @ 2008-05-13 18:31 UTC (permalink / raw)
  To: alsa-devel

Hello,

The driver for our audio hardware provides 6 snd_kcontrol_new_t 
structures, with their proper callbacks, members and name. One is called 
pmic_control_pb_vol (.name = "Master Playback Volume") in the driver, 
but appears somehow as "Master" in amixer and can be successfully 
written to using the OSS interface and ioctl as:

     int mixerFd = open("/dev/mixer", O_RDWR);
     if (mixerFd >= 0) {
         unsigned int leftright;
         ioctl(mixerFd, SOUND_MIXER_WRITE_VOLUME, &leftright);
         close(mixerFd);
     }

It is a big enigma for me that the ioctl with the request code used 
above arrives automagically in the particular audio driver and calls 
pmic_pb_volume_put() defined in pmic_control_pb_vol.

Another control is called pmic_control_op_sw (.name = "Master Output 
Playback Volume") and appears in amixer as "Master Output" (in fact it 
is not a volume control but a switch). It is possible to set the output 
device using amixer. My questions are:

What is the ioctl request code for a particular snd_kcontrol_new_t 
defined in the driver?

Alternatively, how does the OSS layer in ALSA map the different ALSA 
controls to the predefined and fixed OSS controls?

The hard way (and what I am currently trying as last resort) is to write 
to all of them and see what happens.

Many thanks for your help,
peter

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: ioctl request code for specific alsa control
  2008-05-13 18:31 ioctl request code for specific alsa control Peter Wurmsdobler
@ 2008-05-14  9:17 ` Clemens Ladisch
       [not found]   ` <482AB7A1.6090303@wurmsdobler.org>
  0 siblings, 1 reply; 4+ messages in thread
From: Clemens Ladisch @ 2008-05-14  9:17 UTC (permalink / raw)
  To: Peter Wurmsdobler; +Cc: alsa-devel

Peter Wurmsdobler wrote:
> ...
> Another control is called pmic_control_op_sw (.name = "Master Output
> Playback Volume") and appears in amixer as "Master Output" (in fact it
> is not a volume control but a switch).

Then I'd guess its name should be "Master Playback Switch".
See Documentation/sound/alsa/ControlNames.txt.

> What is the ioctl request code for a particular snd_kcontrol_new_t
> defined in the driver?

ALSA controls do not have separate ioctl codes.  Controls are identified
by their name (or by their ID, which is a number that ALSA assigns
automatically).  There is one ioctl request that writes the value of a
control and which gets the control ID as parameter.

> Alternatively, how does the OSS layer in ALSA map the different ALSA
> controls to the predefined and fixed OSS controls?

The OSS API has some predefined mixer controls that are identifed by a
number or ioctl request.  By default, ALSA maps these OSS controls to
certain ALSA control names; see section "Mixer Elements" in
Documentation/sound/alsa/OSS-Emulation.txt.


HTH
Clemens

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: ioctl request code for specific alsa control
       [not found]   ` <482AB7A1.6090303@wurmsdobler.org>
@ 2008-05-15  7:28     ` Clemens Ladisch
  2008-05-16  9:16       ` Peter Wurmsdobler
  0 siblings, 1 reply; 4+ messages in thread
From: Clemens Ladisch @ 2008-05-15  7:28 UTC (permalink / raw)
  To: Peter Wurmsdobler; +Cc: alsa-devel

Peter Wurmsdobler wrote:
> What ioctl request code would I have to pass in order to reach this
> control's put/get methods?

snd_ctl_elem_write() (alsa-lib/src/control/control.c)
snd_ctl_hw_elem_write() (alsa-lib/src/control/control_hw.c)
ioctl(SNDRV_CTL_IOCTL_ELEM_WRITE)
snd_ctl_ioctl() (linux/sound/core/control.c)
snd_ctl_elem_write_user()
snd_ctl_elem_write()
kctl->put()


HTH
Clemens

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: ioctl request code for specific alsa control
  2008-05-15  7:28     ` Clemens Ladisch
@ 2008-05-16  9:16       ` Peter Wurmsdobler
  0 siblings, 0 replies; 4+ messages in thread
From: Peter Wurmsdobler @ 2008-05-16  9:16 UTC (permalink / raw)
  To: Clemens Ladisch; +Cc: alsa-devel

Hello,

Thanks for your help.

>> What ioctl request code would I have to pass in order to reach this
>> control's put/get methods?
> 
> snd_ctl_elem_write() (alsa-lib/src/control/control.c)
> snd_ctl_hw_elem_write() (alsa-lib/src/control/control_hw.c)
> ioctl(SNDRV_CTL_IOCTL_ELEM_WRITE)
> snd_ctl_ioctl() (linux/sound/core/control.c)
> snd_ctl_elem_write_user()
> snd_ctl_elem_write()
> kctl->put()
This is the path in the alsa world. I have followed this code as well, 
and it uses the alsa control element as payload into the ioctl.

I have taken a more pragmatic and certainly less orthodox one:

         ioctl(mixerFd, SOUND_MIXER_WRITE_VOLUME, &leftright);

will eventually call the put method of a kernel control 
pmic_control_pb_vol with the name "Master Playback Volume".

The function snd_mixer_oss_build_input() appears to be responsible for 
creating this link, by looking through a list of words such as "Master", 
"CD", etc in conjunction with expressions such as "%s Playback Volume". 
It probably will then try to match the names of the alsa kernel controls 
and set the put function pointer if appropriate.

Consequently, if I rename the control responsible for the output, 
pmic_control_op_sw, to something for which a ioctl exists, e.g. "CD", 
then it works as a pseudo volume control and I can use:

         ioctl(mixerFd, SOUND_MIXER_WRITE_CD, &output);

This approach is admittedly a hack, but it works. This ioctl will result 
in the call of the fake CD control and its put method.

If I had renamed the the output control "Master Output Switch", I could 
not have used a volume control and hence I would not know what ioctl 
request code to use.

Regards,
peter

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2008-05-16  9:16 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-05-13 18:31 ioctl request code for specific alsa control Peter Wurmsdobler
2008-05-14  9:17 ` Clemens Ladisch
     [not found]   ` <482AB7A1.6090303@wurmsdobler.org>
2008-05-15  7:28     ` Clemens Ladisch
2008-05-16  9:16       ` Peter Wurmsdobler

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.