Commit e7ecc27e authored by Takashi Iwai's avatar Takashi Iwai

ALSA: hda - Introduce bit flags to snd_hda_codec_read/write()

snd_hda_codec_read(), snd_hda_codec_write() & co take the argument
"direct" that indicates whether the given NID is a direct reference or
an indirect reference.  However, the indirect reference is practically
unimplemented and never exists.  And moreover, we don't need the
indication of indirect reference at this high level, as NID can be
represented in 16bit values at this point.

Meanwhile, there are some cases where it'd be nice to give some
operational options to these functions.  So, we can reuse this
argument as a new bit flag!  Pretty frugal, eh?

All callers so far pass zero to this argument, thus there is no
behavior change by this replacement.

The real usage of this new bit option will be added in the following
patches.
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 36bb00d4
...@@ -185,20 +185,19 @@ EXPORT_SYMBOL_HDA(snd_hda_get_jack_type); ...@@ -185,20 +185,19 @@ EXPORT_SYMBOL_HDA(snd_hda_get_jack_type);
* Compose a 32bit command word to be sent to the HD-audio controller * Compose a 32bit command word to be sent to the HD-audio controller
*/ */
static inline unsigned int static inline unsigned int
make_codec_cmd(struct hda_codec *codec, hda_nid_t nid, int direct, make_codec_cmd(struct hda_codec *codec, hda_nid_t nid, int flags,
unsigned int verb, unsigned int parm) unsigned int verb, unsigned int parm)
{ {
u32 val; u32 val;
if ((codec->addr & ~0xf) || (direct & ~1) || (nid & ~0x7f) || if ((codec->addr & ~0xf) || (nid & ~0x7f) ||
(verb & ~0xfff) || (parm & ~0xffff)) { (verb & ~0xfff) || (parm & ~0xffff)) {
printk(KERN_ERR "hda-codec: out of range cmd %x:%x:%x:%x:%x\n", printk(KERN_ERR "hda-codec: out of range cmd %x:%x:%x:%x\n",
codec->addr, direct, nid, verb, parm); codec->addr, nid, verb, parm);
return ~0; return ~0;
} }
val = (u32)codec->addr << 28; val = (u32)codec->addr << 28;
val |= (u32)direct << 27;
val |= (u32)nid << 20; val |= (u32)nid << 20;
val |= verb << 8; val |= verb << 8;
val |= parm; val |= parm;
...@@ -209,7 +208,7 @@ make_codec_cmd(struct hda_codec *codec, hda_nid_t nid, int direct, ...@@ -209,7 +208,7 @@ make_codec_cmd(struct hda_codec *codec, hda_nid_t nid, int direct,
* Send and receive a verb * Send and receive a verb
*/ */
static int codec_exec_verb(struct hda_codec *codec, unsigned int cmd, static int codec_exec_verb(struct hda_codec *codec, unsigned int cmd,
unsigned int *res) int flags, unsigned int *res)
{ {
struct hda_bus *bus = codec->bus; struct hda_bus *bus = codec->bus;
int err; int err;
...@@ -255,7 +254,7 @@ static int codec_exec_verb(struct hda_codec *codec, unsigned int cmd, ...@@ -255,7 +254,7 @@ static int codec_exec_verb(struct hda_codec *codec, unsigned int cmd,
* snd_hda_codec_read - send a command and get the response * snd_hda_codec_read - send a command and get the response
* @codec: the HDA codec * @codec: the HDA codec
* @nid: NID to send the command * @nid: NID to send the command
* @direct: direct flag * @flags: optional bit flags
* @verb: the verb to send * @verb: the verb to send
* @parm: the parameter for the verb * @parm: the parameter for the verb
* *
...@@ -264,12 +263,12 @@ static int codec_exec_verb(struct hda_codec *codec, unsigned int cmd, ...@@ -264,12 +263,12 @@ static int codec_exec_verb(struct hda_codec *codec, unsigned int cmd,
* Returns the obtained response value, or -1 for an error. * Returns the obtained response value, or -1 for an error.
*/ */
unsigned int snd_hda_codec_read(struct hda_codec *codec, hda_nid_t nid, unsigned int snd_hda_codec_read(struct hda_codec *codec, hda_nid_t nid,
int direct, int flags,
unsigned int verb, unsigned int parm) unsigned int verb, unsigned int parm)
{ {
unsigned cmd = make_codec_cmd(codec, nid, direct, verb, parm); unsigned cmd = make_codec_cmd(codec, nid, flags, verb, parm);
unsigned int res; unsigned int res;
if (codec_exec_verb(codec, cmd, &res)) if (codec_exec_verb(codec, cmd, flags, &res))
return -1; return -1;
return res; return res;
} }
...@@ -279,7 +278,7 @@ EXPORT_SYMBOL_HDA(snd_hda_codec_read); ...@@ -279,7 +278,7 @@ EXPORT_SYMBOL_HDA(snd_hda_codec_read);
* snd_hda_codec_write - send a single command without waiting for response * snd_hda_codec_write - send a single command without waiting for response
* @codec: the HDA codec * @codec: the HDA codec
* @nid: NID to send the command * @nid: NID to send the command
* @direct: direct flag * @flags: optional bit flags
* @verb: the verb to send * @verb: the verb to send
* @parm: the parameter for the verb * @parm: the parameter for the verb
* *
...@@ -287,12 +286,12 @@ EXPORT_SYMBOL_HDA(snd_hda_codec_read); ...@@ -287,12 +286,12 @@ EXPORT_SYMBOL_HDA(snd_hda_codec_read);
* *
* Returns 0 if successful, or a negative error code. * Returns 0 if successful, or a negative error code.
*/ */
int snd_hda_codec_write(struct hda_codec *codec, hda_nid_t nid, int direct, int snd_hda_codec_write(struct hda_codec *codec, hda_nid_t nid, int flags,
unsigned int verb, unsigned int parm) unsigned int verb, unsigned int parm)
{ {
unsigned int cmd = make_codec_cmd(codec, nid, direct, verb, parm); unsigned int cmd = make_codec_cmd(codec, nid, flags, verb, parm);
unsigned int res; unsigned int res;
return codec_exec_verb(codec, cmd, return codec_exec_verb(codec, cmd, flags,
codec->bus->sync_write ? &res : NULL); codec->bus->sync_write ? &res : NULL);
} }
EXPORT_SYMBOL_HDA(snd_hda_codec_write); EXPORT_SYMBOL_HDA(snd_hda_codec_write);
...@@ -3582,7 +3581,7 @@ EXPORT_SYMBOL_HDA(snd_hda_create_spdif_in_ctls); ...@@ -3582,7 +3581,7 @@ EXPORT_SYMBOL_HDA(snd_hda_create_spdif_in_ctls);
* snd_hda_codec_write_cache - send a single command with caching * snd_hda_codec_write_cache - send a single command with caching
* @codec: the HDA codec * @codec: the HDA codec
* @nid: NID to send the command * @nid: NID to send the command
* @direct: direct flag * @flags: optional bit flags
* @verb: the verb to send * @verb: the verb to send
* @parm: the parameter for the verb * @parm: the parameter for the verb
* *
...@@ -3591,7 +3590,7 @@ EXPORT_SYMBOL_HDA(snd_hda_create_spdif_in_ctls); ...@@ -3591,7 +3590,7 @@ EXPORT_SYMBOL_HDA(snd_hda_create_spdif_in_ctls);
* Returns 0 if successful, or a negative error code. * Returns 0 if successful, or a negative error code.
*/ */
int snd_hda_codec_write_cache(struct hda_codec *codec, hda_nid_t nid, int snd_hda_codec_write_cache(struct hda_codec *codec, hda_nid_t nid,
int direct, unsigned int verb, unsigned int parm) int flags, unsigned int verb, unsigned int parm)
{ {
int err; int err;
struct hda_cache_head *c; struct hda_cache_head *c;
...@@ -3600,7 +3599,7 @@ int snd_hda_codec_write_cache(struct hda_codec *codec, hda_nid_t nid, ...@@ -3600,7 +3599,7 @@ int snd_hda_codec_write_cache(struct hda_codec *codec, hda_nid_t nid,
cache_only = codec->cached_write; cache_only = codec->cached_write;
if (!cache_only) { if (!cache_only) {
err = snd_hda_codec_write(codec, nid, direct, verb, parm); err = snd_hda_codec_write(codec, nid, flags, verb, parm);
if (err < 0) if (err < 0)
return err; return err;
} }
...@@ -3624,7 +3623,7 @@ EXPORT_SYMBOL_HDA(snd_hda_codec_write_cache); ...@@ -3624,7 +3623,7 @@ EXPORT_SYMBOL_HDA(snd_hda_codec_write_cache);
* snd_hda_codec_update_cache - check cache and write the cmd only when needed * snd_hda_codec_update_cache - check cache and write the cmd only when needed
* @codec: the HDA codec * @codec: the HDA codec
* @nid: NID to send the command * @nid: NID to send the command
* @direct: direct flag * @flags: optional bit flags
* @verb: the verb to send * @verb: the verb to send
* @parm: the parameter for the verb * @parm: the parameter for the verb
* *
...@@ -3635,7 +3634,7 @@ EXPORT_SYMBOL_HDA(snd_hda_codec_write_cache); ...@@ -3635,7 +3634,7 @@ EXPORT_SYMBOL_HDA(snd_hda_codec_write_cache);
* Returns 0 if successful, or a negative error code. * Returns 0 if successful, or a negative error code.
*/ */
int snd_hda_codec_update_cache(struct hda_codec *codec, hda_nid_t nid, int snd_hda_codec_update_cache(struct hda_codec *codec, hda_nid_t nid,
int direct, unsigned int verb, unsigned int parm) int flags, unsigned int verb, unsigned int parm)
{ {
struct hda_cache_head *c; struct hda_cache_head *c;
u32 key; u32 key;
...@@ -3651,7 +3650,7 @@ int snd_hda_codec_update_cache(struct hda_codec *codec, hda_nid_t nid, ...@@ -3651,7 +3650,7 @@ int snd_hda_codec_update_cache(struct hda_codec *codec, hda_nid_t nid,
return 0; return 0;
} }
mutex_unlock(&codec->bus->cmd_mutex); mutex_unlock(&codec->bus->cmd_mutex);
return snd_hda_codec_write_cache(codec, nid, direct, verb, parm); return snd_hda_codec_write_cache(codec, nid, flags, verb, parm);
} }
EXPORT_SYMBOL_HDA(snd_hda_codec_update_cache); EXPORT_SYMBOL_HDA(snd_hda_codec_update_cache);
......
...@@ -945,9 +945,9 @@ int snd_hda_codec_update_widgets(struct hda_codec *codec); ...@@ -945,9 +945,9 @@ int snd_hda_codec_update_widgets(struct hda_codec *codec);
* low level functions * low level functions
*/ */
unsigned int snd_hda_codec_read(struct hda_codec *codec, hda_nid_t nid, unsigned int snd_hda_codec_read(struct hda_codec *codec, hda_nid_t nid,
int direct, int flags,
unsigned int verb, unsigned int parm); unsigned int verb, unsigned int parm);
int snd_hda_codec_write(struct hda_codec *codec, hda_nid_t nid, int direct, int snd_hda_codec_write(struct hda_codec *codec, hda_nid_t nid, int flags,
unsigned int verb, unsigned int parm); unsigned int verb, unsigned int parm);
#define snd_hda_param_read(codec, nid, param) \ #define snd_hda_param_read(codec, nid, param) \
snd_hda_codec_read(codec, nid, 0, AC_VERB_PARAMETERS, param) snd_hda_codec_read(codec, nid, 0, AC_VERB_PARAMETERS, param)
...@@ -986,11 +986,11 @@ int snd_hda_queue_unsol_event(struct hda_bus *bus, u32 res, u32 res_ex); ...@@ -986,11 +986,11 @@ int snd_hda_queue_unsol_event(struct hda_bus *bus, u32 res, u32 res_ex);
/* cached write */ /* cached write */
int snd_hda_codec_write_cache(struct hda_codec *codec, hda_nid_t nid, int snd_hda_codec_write_cache(struct hda_codec *codec, hda_nid_t nid,
int direct, unsigned int verb, unsigned int parm); int flags, unsigned int verb, unsigned int parm);
void snd_hda_sequence_write_cache(struct hda_codec *codec, void snd_hda_sequence_write_cache(struct hda_codec *codec,
const struct hda_verb *seq); const struct hda_verb *seq);
int snd_hda_codec_update_cache(struct hda_codec *codec, hda_nid_t nid, int snd_hda_codec_update_cache(struct hda_codec *codec, hda_nid_t nid,
int direct, unsigned int verb, unsigned int parm); int flags, unsigned int verb, unsigned int parm);
void snd_hda_codec_resume_cache(struct hda_codec *codec); void snd_hda_codec_resume_cache(struct hda_codec *codec);
/* both for cmd & amp caches */ /* both for cmd & amp caches */
void snd_hda_codec_flush_cache(struct hda_codec *codec); void snd_hda_codec_flush_cache(struct hda_codec *codec);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment