Skip to content

Commit

Permalink
ALSA: hda - Support indirect execution of verbs
Browse files Browse the repository at this point in the history
Add an overriding exec_verb op to struct hdac_device so that the call
via snd_hdac_exec_verb() can switch to a different route depending on
the setup.  The codec driver sets this field so that it can handle the
errors or applying quirks appropriately.  Furthermore, this mechanism
will be used for smooth transition for the regmap support in later
patches.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
  • Loading branch information
Takashi Iwai committed Mar 23, 2015
1 parent 3256be6 commit 0585244
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 6 deletions.
6 changes: 6 additions & 0 deletions include/sound/hdaudio.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ struct hdac_device {
const char *vendor_name; /* codec vendor name */
const char *chip_name; /* codec chip name */

/* verb exec op override */
int (*exec_verb)(struct hdac_device *dev, unsigned int cmd,
unsigned int flags, unsigned int *res);

/* widgets */
unsigned int num_nodes;
hda_nid_t start_nid, end_nid;
Expand Down Expand Up @@ -82,6 +86,8 @@ int snd_hdac_refresh_widgets(struct hdac_device *codec);

unsigned int snd_hdac_make_cmd(struct hdac_device *codec, hda_nid_t nid,
unsigned int verb, unsigned int parm);
int snd_hdac_exec_verb(struct hdac_device *codec, unsigned int cmd,
unsigned int flags, unsigned int *res);
int snd_hdac_read(struct hdac_device *codec, hda_nid_t nid,
unsigned int verb, unsigned int parm, unsigned int *res);
int snd_hdac_read_parm(struct hdac_device *codec, hda_nid_t nid, int parm);
Expand Down
24 changes: 23 additions & 1 deletion sound/hda/hdac_device.c
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,28 @@ unsigned int snd_hdac_make_cmd(struct hdac_device *codec, hda_nid_t nid,
}
EXPORT_SYMBOL_GPL(snd_hdac_make_cmd);

/**
* snd_hdac_exec_verb - execute an encoded verb
* @codec: the codec object
* @cmd: encoded verb to execute
* @flags: optional flags, pass zero for default
* @res: the pointer to store the result, NULL if running async
*
* Returns zero if successful, or a negative error code.
*
* This calls the exec_verb op when set in hdac_codec. If not,
* call the default snd_hdac_bus_exec_verb().
*/
int snd_hdac_exec_verb(struct hdac_device *codec, unsigned int cmd,
unsigned int flags, unsigned int *res)
{
if (codec->exec_verb)
return codec->exec_verb(codec, cmd, flags, res);
return snd_hdac_bus_exec_verb(codec->bus, codec->addr, cmd, res);
}
EXPORT_SYMBOL_GPL(snd_hdac_exec_verb);


/**
* snd_hdac_read - execute a verb
* @codec: the codec object
Expand All @@ -208,7 +230,7 @@ int snd_hdac_read(struct hdac_device *codec, hda_nid_t nid,
{
unsigned int cmd = snd_hdac_make_cmd(codec, nid, verb, parm);

return snd_hdac_bus_exec_verb(codec->bus, codec->addr, cmd, res);
return snd_hdac_exec_verb(codec, cmd, 0, res);
}
EXPORT_SYMBOL_GPL(snd_hdac_read);

Expand Down
12 changes: 7 additions & 5 deletions sound/pci/hda/hda_codec.c
Original file line number Diff line number Diff line change
Expand Up @@ -124,11 +124,12 @@ const char *snd_hda_get_jack_type(u32 cfg)
EXPORT_SYMBOL_GPL(snd_hda_get_jack_type);

/*
* Send and receive a verb
* Send and receive a verb - passed to exec_verb override for hdac_device
*/
static int codec_exec_verb(struct hda_codec *codec, unsigned int cmd,
int flags, unsigned int *res)
static int codec_exec_verb(struct hdac_device *dev, unsigned int cmd,
unsigned int flags, unsigned int *res)
{
struct hda_codec *codec = container_of(dev, struct hda_codec, core);
struct hda_bus *bus = codec->bus;
int err;

Expand Down Expand Up @@ -177,7 +178,7 @@ unsigned int snd_hda_codec_read(struct hda_codec *codec, hda_nid_t nid,
{
unsigned int cmd = snd_hdac_make_cmd(&codec->core, nid, verb, parm);
unsigned int res;
if (codec_exec_verb(codec, cmd, flags, &res))
if (snd_hdac_exec_verb(&codec->core, cmd, flags, &res))
return -1;
return res;
}
Expand All @@ -199,7 +200,7 @@ int snd_hda_codec_write(struct hda_codec *codec, hda_nid_t nid, int flags,
unsigned int verb, unsigned int parm)
{
unsigned int cmd = snd_hdac_make_cmd(&codec->core, nid, verb, parm);
return codec_exec_verb(codec, cmd, flags, NULL);
return snd_hdac_exec_verb(&codec->core, cmd, flags, NULL);
}
EXPORT_SYMBOL_GPL(snd_hda_codec_write);

Expand Down Expand Up @@ -1026,6 +1027,7 @@ int snd_hda_codec_new(struct hda_bus *bus, struct snd_card *card,

codec->core.dev.release = snd_hda_codec_dev_release;
codec->core.type = HDA_DEV_LEGACY;
codec->core.exec_verb = codec_exec_verb;

codec->bus = bus;
codec->card = card;
Expand Down

0 comments on commit 0585244

Please sign in to comment.