Skip to content

Commit

Permalink
ALSA: hdac: Copy codec helpers to core
Browse files Browse the repository at this point in the history
The current codec helpers are local to hda code and needs to be moved to
core so that other users can use it.
The helpers to read/write the codec and to check the
power state of widgets is copied

Signed-off-by: Subhransu S. Prusty <[email protected]>
Signed-off-by: Vinod Koul <[email protected]>
Signed-off-by: Takashi Iwai <[email protected]>
  • Loading branch information
Subhransu S. Prusty authored and tiwai committed Oct 8, 2015
1 parent a04267f commit 1b5e616
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 0 deletions.
6 changes: 6 additions & 0 deletions include/sound/hdaudio.h
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ int snd_hdac_query_supported_pcm(struct hdac_device *codec, hda_nid_t nid,
bool snd_hdac_is_supported_format(struct hdac_device *codec, hda_nid_t nid,
unsigned int format);

int snd_hdac_codec_read(struct hdac_device *hdac, hda_nid_t nid,
int flags, unsigned int verb, unsigned int parm);
int snd_hdac_codec_write(struct hdac_device *hdac, hda_nid_t nid,
int flags, unsigned int verb, unsigned int parm);
bool snd_hdac_check_power_state(struct hdac_device *hdac,
hda_nid_t nid, unsigned int target_state);
/**
* snd_hdac_read_parm - read a codec parameter
* @codec: the codec object
Expand Down
81 changes: 81 additions & 0 deletions sound/hda/hdac_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -952,3 +952,84 @@ bool snd_hdac_is_supported_format(struct hdac_device *codec, hda_nid_t nid,
return true;
}
EXPORT_SYMBOL_GPL(snd_hdac_is_supported_format);

static unsigned int codec_read(struct hdac_device *hdac, hda_nid_t nid,
int flags, unsigned int verb, unsigned int parm)
{
unsigned int cmd = snd_hdac_make_cmd(hdac, nid, verb, parm);
unsigned int res;

if (snd_hdac_exec_verb(hdac, cmd, flags, &res))
return -1;

return res;
}

static int codec_write(struct hdac_device *hdac, hda_nid_t nid,
int flags, unsigned int verb, unsigned int parm)
{
unsigned int cmd = snd_hdac_make_cmd(hdac, nid, verb, parm);

return snd_hdac_exec_verb(hdac, cmd, flags, NULL);
}

/**
* snd_hdac_codec_read - send a command and get the response
* @hdac: the HDAC device
* @nid: NID to send the command
* @flags: optional bit flags
* @verb: the verb to send
* @parm: the parameter for the verb
*
* Send a single command and read the corresponding response.
*
* Returns the obtained response value, or -1 for an error.
*/
int snd_hdac_codec_read(struct hdac_device *hdac, hda_nid_t nid,
int flags, unsigned int verb, unsigned int parm)
{
return codec_read(hdac, nid, flags, verb, parm);
}
EXPORT_SYMBOL_GPL(snd_hdac_codec_read);

/**
* snd_hdac_codec_write - send a single command without waiting for response
* @hdac: the HDAC device
* @nid: NID to send the command
* @flags: optional bit flags
* @verb: the verb to send
* @parm: the parameter for the verb
*
* Send a single command without waiting for response.
*
* Returns 0 if successful, or a negative error code.
*/
int snd_hdac_codec_write(struct hdac_device *hdac, hda_nid_t nid,
int flags, unsigned int verb, unsigned int parm)
{
return codec_write(hdac, nid, flags, verb, parm);
}
EXPORT_SYMBOL_GPL(snd_hdac_codec_write);

/*
* snd_hdac_check_power_state: check whether the actual power state matches
* with the target state
*
* @hdac: the HDAC device
* @nid: NID to send the command
* @target_state: target state to check for
*
* Return true if state matches, false if not
*/
bool snd_hdac_check_power_state(struct hdac_device *hdac,
hda_nid_t nid, unsigned int target_state)
{
unsigned int state = codec_read(hdac, nid, 0,
AC_VERB_GET_POWER_STATE, 0);

if (state & AC_PWRST_ERROR)
return true;
state = (state >> 4) & 0x0f;
return (state == target_state);
}
EXPORT_SYMBOL_GPL(snd_hdac_check_power_state);

0 comments on commit 1b5e616

Please sign in to comment.