Added power management functions and defines.

This commit is contained in:
Jaroslav Kysela 2001-09-26 13:57:04 +00:00
parent 23d8f9a0b0
commit 3c59c6b11d
19 changed files with 195 additions and 0 deletions

View file

@ -363,6 +363,33 @@ int snd_ctl_rawmidi_prefer_subdevice(snd_ctl_t *ctl, int subdev)
return ctl->ops->rawmidi_prefer_subdevice(ctl, subdev);
}
/**
* \brief Set Power State to given SND_CTL_POWER_* value and do the power management
* \param ctl CTL handle
* \param state Desired Power State
* \return 0 on success otherwise a negative error code
*/
int snd_ctl_set_power_state(snd_ctl_t *ctl, unsigned int state)
{
assert(ctl);
if (ctl->ops->set_power_state)
return ctl->ops->set_power_state(ctl, state);
return -ENXIO;
}
/**
* \brief Get actual Power State
* \param ctl CTL handle
* \param state Destination value
* \return 0 on success otherwise a negative error code
*/
int snd_ctl_get_power_state(snd_ctl_t *ctl, unsigned int *state)
{
assert(ctl);
if (ctl->ops->get_power_state)
return ctl->ops->get_power_state(ctl, state);
return -ENXIO;
}
/**
* \brief Read an event

View file

@ -233,6 +233,22 @@ static int snd_ctl_hw_rawmidi_prefer_subdevice(snd_ctl_t *handle, int subdev)
return 0;
}
static int snd_ctl_hw_set_power_state(snd_ctl_t *handle, unsigned int state)
{
snd_ctl_hw_t *hw = handle->private_data;
if (ioctl(hw->fd, SNDRV_CTL_IOCTL_POWER, &state) < 0)
return -errno;
return 0;
}
static int snd_ctl_hw_get_power_state(snd_ctl_t *handle, unsigned int *state)
{
snd_ctl_hw_t *hw = handle->private_data;
if (ioctl(hw->fd, SNDRV_CTL_IOCTL_POWER_STATE, state) < 0)
return -errno;
return 0;
}
static int snd_ctl_hw_read(snd_ctl_t *handle, snd_ctl_event_t *event)
{
snd_ctl_hw_t *hw = handle->private_data;
@ -263,6 +279,8 @@ snd_ctl_ops_t snd_ctl_hw_ops = {
rawmidi_next_device: snd_ctl_hw_rawmidi_next_device,
rawmidi_info: snd_ctl_hw_rawmidi_info,
rawmidi_prefer_subdevice: snd_ctl_hw_rawmidi_prefer_subdevice,
set_power_state: snd_ctl_hw_set_power_state,
get_power_state: snd_ctl_hw_get_power_state,
read: snd_ctl_hw_read,
};

View file

@ -41,6 +41,8 @@ typedef struct _snd_ctl_ops {
int (*rawmidi_next_device)(snd_ctl_t *handle, int *device);
int (*rawmidi_info)(snd_ctl_t *handle, snd_rawmidi_info_t * info);
int (*rawmidi_prefer_subdevice)(snd_ctl_t *handle, int subdev);
int (*set_power_state)(snd_ctl_t *handle, unsigned int state);
int (*get_power_state)(snd_ctl_t *handle, unsigned int *state);
int (*read)(snd_ctl_t *handle, snd_ctl_event_t *event);
} snd_ctl_ops_t;

View file

@ -345,6 +345,32 @@ static int snd_ctl_shm_rawmidi_prefer_subdevice(snd_ctl_t *ctl, int subdev)
return err;
}
static int snd_ctl_shm_set_power_state(snd_ctl_t *ctl, unsigned int state)
{
snd_ctl_shm_t *shm = ctl->private_data;
volatile snd_ctl_shm_ctrl_t *ctrl = shm->ctrl;
int err;
ctrl->u.power_state = state;
ctrl->cmd = SNDRV_CTL_IOCTL_POWER;
err = snd_ctl_shm_action(ctl);
if (err < 0)
return err;
return err;
}
static int snd_ctl_shm_get_power_state(snd_ctl_t *ctl, unsigned int *state)
{
snd_ctl_shm_t *shm = ctl->private_data;
volatile snd_ctl_shm_ctrl_t *ctrl = shm->ctrl;
int err;
ctrl->cmd = SNDRV_CTL_IOCTL_POWER_STATE;
err = snd_ctl_shm_action(ctl);
if (err < 0)
return err;
*state = ctrl->u.power_state;
return err;
}
static int snd_ctl_shm_read(snd_ctl_t *ctl, snd_ctl_event_t *event)
{
snd_ctl_shm_t *shm;
@ -384,6 +410,8 @@ snd_ctl_ops_t snd_ctl_shm_ops = {
rawmidi_next_device: snd_ctl_shm_rawmidi_next_device,
rawmidi_info: snd_ctl_shm_rawmidi_info,
rawmidi_prefer_subdevice: snd_ctl_shm_rawmidi_prefer_subdevice,
set_power_state: snd_ctl_shm_set_power_state,
get_power_state: snd_ctl_shm_get_power_state,
read: snd_ctl_shm_read,
};