/** * snd_hdac_device_init - initialize the HD-audio codec base device * @codec: device to initialize * @bus: but to attach * @name: device name string * @addr: codec address * * Returns zero for success or a negative error code. * * This function increments the runtime PM counter and marks it active. * The caller needs to turn it off appropriately later. * * The caller needs to set the device's release op properly by itself.
*/ int snd_hdac_device_init(struct hdac_device *codec, struct hdac_bus *bus, constchar *name, unsignedint addr)
{ struct device *dev;
hda_nid_t fg; int err;
err = snd_hdac_bus_add_device(bus, codec); if (err < 0) goto error;
/* fill parameters */
codec->vendor_id = snd_hdac_read_parm(codec, AC_NODE_ROOT,
AC_PAR_VENDOR_ID); if (codec->vendor_id == -1) { /* read again, hopefully the access method was corrected * in the last read...
*/
codec->vendor_id = snd_hdac_read_parm(codec, AC_NODE_ROOT,
AC_PAR_VENDOR_ID);
}
/** * snd_hdac_device_exit - clean up the HD-audio codec base device * @codec: device to clean up
*/ void snd_hdac_device_exit(struct hdac_device *codec)
{
pm_runtime_put_noidle(&codec->dev); /* keep balance of runtime PM child_count in parent device */
pm_runtime_set_suspended(&codec->dev);
snd_hdac_bus_remove_device(codec->bus, codec);
kfree(codec->vendor_name);
kfree(codec->chip_name);
}
EXPORT_SYMBOL_GPL(snd_hdac_device_exit);
/** * snd_hdac_device_register - register the hd-audio codec base device * @codec: the device to register
*/ int snd_hdac_device_register(struct hdac_device *codec)
{ int err;
/** * snd_hdac_device_unregister - unregister the hd-audio codec base device * @codec: the device to unregister
*/ void snd_hdac_device_unregister(struct hdac_device *codec)
{ if (device_is_registered(&codec->dev)) {
mutex_lock(&codec->widget_lock);
hda_widget_sysfs_exit(codec);
mutex_unlock(&codec->widget_lock);
device_del(&codec->dev);
snd_hdac_bus_remove_device(codec->bus, codec);
}
}
EXPORT_SYMBOL_GPL(snd_hdac_device_unregister);
/** * snd_hdac_device_set_chip_name - set/update the codec name * @codec: the HDAC device * @name: name string to set * * Returns 0 if the name is set or updated, or a negative error code.
*/ int snd_hdac_device_set_chip_name(struct hdac_device *codec, constchar *name)
{ char *newname;
if (!name) return 0;
newname = kstrdup(name, GFP_KERNEL); if (!newname) return -ENOMEM;
kfree(codec->chip_name);
codec->chip_name = newname; return 0;
}
EXPORT_SYMBOL_GPL(snd_hdac_device_set_chip_name);
/** * snd_hdac_codec_modalias - give the module alias name * @codec: HDAC device * @buf: string buffer to store * @size: string buffer size * * Returns the size of string, like snprintf(), or a negative error code.
*/ int snd_hdac_codec_modalias(conststruct hdac_device *codec, char *buf, size_t size)
{ return scnprintf(buf, size, "hdaudio:v%08Xr%08Xa%02X\n",
codec->vendor_id, codec->revision_id, codec->type);
}
EXPORT_SYMBOL_GPL(snd_hdac_codec_modalias);
/** * snd_hdac_make_cmd - compose a 32bit command word to be sent to the * HD-audio controller * @codec: the codec object * @nid: NID to encode * @verb: verb to encode * @parm: parameter to encode * * Return an encoded command verb or -1 for error.
*/ staticunsignedint snd_hdac_make_cmd(struct hdac_device *codec, hda_nid_t nid, unsignedint verb, unsignedint parm)
{
u32 val, addr;
val = addr << 28;
val |= (u32)nid << 20;
val |= verb << 8;
val |= parm; return val;
}
/** * 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, unsignedint cmd, unsignedint flags, unsignedint *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);
}
/** * snd_hdac_read - execute a verb * @codec: the codec object * @nid: NID to execute a verb * @verb: verb to execute * @parm: parameter for a verb * @res: the pointer to store the result, NULL if running async * * Returns zero if successful, or a negative error code.
*/ int snd_hdac_read(struct hdac_device *codec, hda_nid_t nid, unsignedint verb, unsignedint parm, unsignedint *res)
{ unsignedint cmd = snd_hdac_make_cmd(codec, nid, verb, parm);
/** * _snd_hdac_read_parm - read a parmeter * @codec: the codec object * @nid: NID to read a parameter * @parm: parameter to read * @res: pointer to store the read value * * This function returns zero or an error unlike snd_hdac_read_parm().
*/ int _snd_hdac_read_parm(struct hdac_device *codec, hda_nid_t nid, int parm, unsignedint *res)
{ unsignedint cmd;
/** * snd_hdac_read_parm_uncached - read a codec parameter without caching * @codec: the codec object * @nid: NID to read a parameter * @parm: parameter to read * * Returns -1 for error. If you need to distinguish the error more * strictly, use snd_hdac_read() directly.
*/ int snd_hdac_read_parm_uncached(struct hdac_device *codec, hda_nid_t nid, int parm)
{ unsignedint cmd, val;
/** * snd_hdac_get_sub_nodes - get start NID and number of subtree nodes * @codec: the codec object * @nid: NID to inspect * @start_id: the pointer to store the starting NID * * Returns the number of subtree nodes or zero if not found. * This function reads parameters always without caching.
*/ int snd_hdac_get_sub_nodes(struct hdac_device *codec, hda_nid_t nid,
hda_nid_t *start_id)
{ unsignedint parm;
/** * snd_hdac_get_connections - get a widget connection list * @codec: the codec object * @nid: NID * @conn_list: the array to store the results, can be NULL * @max_conns: the max size of the given array * * Returns the number of connected widgets, zero for no connection, or a * negative error code. When the number of elements don't fit with the * given array size, it returns -ENOSPC. * * When @conn_list is NULL, it just checks the number of connections.
*/ int snd_hdac_get_connections(struct hdac_device *codec, hda_nid_t nid,
hda_nid_t *conn_list, int max_conns)
{ unsignedint parm; int i, conn_len, conns, err; unsignedint shift, num_elems, mask;
hda_nid_t prev_nid; int null_count = 0;
parm = get_num_conns(codec, nid); if (!parm) return 0;
if (parm & AC_CLIST_LONG) { /* long form */
shift = 16;
num_elems = 2;
} else { /* short form */
shift = 8;
num_elems = 4;
}
conn_len = parm & AC_CLIST_LENGTH;
mask = (1 << (shift-1)) - 1;
if (!conn_len) return 0; /* no connection */
if (conn_len == 1) { /* single connection */
err = snd_hdac_read(codec, nid, AC_VERB_GET_CONNECT_LIST, 0,
&parm); if (err < 0) return err; if (conn_list)
conn_list[0] = parm & mask; return 1;
}
/* multi connection */
conns = 0;
prev_nid = 0; for (i = 0; i < conn_len; i++) { int range_val;
hda_nid_t val, n;
if (i % num_elems == 0) {
err = snd_hdac_read(codec, nid,
AC_VERB_GET_CONNECT_LIST, i,
&parm); if (err < 0) return -EIO;
}
range_val = !!(parm & (1 << (shift-1))); /* ranges */
val = parm & mask; if (val == 0 && null_count++) { /* no second chance */
dev_dbg(&codec->dev, "invalid CONNECT_LIST verb %x[%i]:%x\n",
nid, i, parm); return 0;
}
parm >>= shift; if (range_val) { /* ranges between the previous and this one */ if (!prev_nid || prev_nid >= val) {
dev_warn(&codec->dev, "invalid dep_range_val %x:%x\n",
prev_nid, val); continue;
} for (n = prev_nid + 1; n <= val; n++) { if (conn_list) { if (conns >= max_conns) return -ENOSPC;
conn_list[conns] = n;
}
conns++;
}
} else { if (conn_list) { if (conns >= max_conns) return -ENOSPC;
conn_list[conns] = val;
}
conns++;
}
prev_nid = val;
} return conns;
}
EXPORT_SYMBOL_GPL(snd_hdac_get_connections);
#ifdef CONFIG_PM /** * snd_hdac_power_up - power up the codec * @codec: the codec object * * This function calls the runtime PM helper to power up the given codec. * Unlike snd_hdac_power_up_pm(), you should call this only for the code * path that isn't included in PM path. Otherwise it gets stuck. * * Returns zero if successful, or a negative error code.
*/ int snd_hdac_power_up(struct hdac_device *codec)
{ return pm_runtime_get_sync(&codec->dev);
}
EXPORT_SYMBOL_GPL(snd_hdac_power_up);
/** * snd_hdac_power_down - power down the codec * @codec: the codec object * * Returns zero if successful, or a negative error code.
*/ int snd_hdac_power_down(struct hdac_device *codec)
{ struct device *dev = &codec->dev;
/** * snd_hdac_power_up_pm - power up the codec * @codec: the codec object * * This function can be called in a recursive code path like init code * which may be called by PM suspend/resume again. OTOH, if a power-up * call must wake up the sleeper (e.g. in a kctl callback), use * snd_hdac_power_up() instead. * * Returns zero if successful, or a negative error code.
*/ int snd_hdac_power_up_pm(struct hdac_device *codec)
{ if (!atomic_inc_not_zero(&codec->in_pm)) return snd_hdac_power_up(codec); return 0;
}
EXPORT_SYMBOL_GPL(snd_hdac_power_up_pm);
/* like snd_hdac_power_up_pm(), but only increment the pm count when * already powered up. Returns -1 if not powered up, 1 if incremented * or 0 if unchanged. Only used in hdac_regmap.c
*/ int snd_hdac_keep_power_up(struct hdac_device *codec)
{ if (!atomic_inc_not_zero(&codec->in_pm)) { int ret = pm_runtime_get_if_active(&codec->dev); if (!ret) return -1; if (ret < 0) return 0;
} return 1;
}
/** * snd_hdac_power_down_pm - power down the codec * @codec: the codec object * * Like snd_hdac_power_up_pm(), this function is used in a recursive * code path like init code which may be called by PM suspend/resume again. * * Returns zero if successful, or a negative error code.
*/ int snd_hdac_power_down_pm(struct hdac_device *codec)
{ if (atomic_dec_if_positive(&codec->in_pm) < 0) return snd_hdac_power_down(codec); return 0;
}
EXPORT_SYMBOL_GPL(snd_hdac_power_down_pm); #endif
/* not autodetected value */
{ 9600, SNDRV_PCM_RATE_KNOT, HDA_RATE(48, 1, 5) },
{ 0 } /* terminator */
};
static snd_pcm_format_t snd_hdac_format_normalize(snd_pcm_format_t format)
{ switch (format) { case SNDRV_PCM_FORMAT_S20_LE: case SNDRV_PCM_FORMAT_S24_LE: return SNDRV_PCM_FORMAT_S32_LE;
case SNDRV_PCM_FORMAT_U20_LE: case SNDRV_PCM_FORMAT_U24_LE: return SNDRV_PCM_FORMAT_U32_LE;
case SNDRV_PCM_FORMAT_S20_BE: case SNDRV_PCM_FORMAT_S24_BE: return SNDRV_PCM_FORMAT_S32_BE;
case SNDRV_PCM_FORMAT_U20_BE: case SNDRV_PCM_FORMAT_U24_BE: return SNDRV_PCM_FORMAT_U32_BE;
default: return format;
}
}
/** * snd_hdac_stream_format_bits - obtain bits per sample value. * @format: the PCM format. * @subformat: the PCM subformat. * @maxbits: the maximum bits per sample. * * Return: The number of bits per sample.
*/ unsignedint snd_hdac_stream_format_bits(snd_pcm_format_t format, snd_pcm_subformat_t subformat, unsignedint maxbits)
{ struct snd_pcm_hw_params params; unsignedint bits;
/** * snd_hdac_stream_format - convert format parameters to SDxFMT value. * @channels: the number of channels. * @bits: bits per sample. * @rate: the sample rate. * * Return: The format bitset or zero if invalid.
*/ unsignedint snd_hdac_stream_format(unsignedint channels, unsignedint bits, unsignedint rate)
{ unsignedint val = 0; int i;
for (i = 0; rate_bits[i].hz; i++) { if (rate_bits[i].hz == rate) {
val = rate_bits[i].hda_fmt; break;
}
}
if (!rate_bits[i].hz) return 0;
if (channels == 0 || channels > 16) return 0;
val |= channels - 1;
switch (bits) { case 8:
val |= AC_FMT_BITS_8; break; case 16:
val |= AC_FMT_BITS_16; break; case 20:
val |= AC_FMT_BITS_20; break; case 24:
val |= AC_FMT_BITS_24; break; case 32:
val |= AC_FMT_BITS_32; break; default: return 0;
}
/** * snd_hdac_spdif_stream_format - convert format parameters to SDxFMT value. * @channels: the number of channels. * @bits: bits per sample. * @rate: the sample rate. * @spdif_ctls: HD-audio SPDIF status bits (0 if irrelevant). * * Return: The format bitset or zero if invalid.
*/ unsignedint snd_hdac_spdif_stream_format(unsignedint channels, unsignedint bits, unsignedint rate, unsignedshort spdif_ctls)
{ unsignedint val = snd_hdac_stream_format(channels, bits, rate);
if (val && spdif_ctls & AC_DIG1_NONAUDIO)
val |= AC_FMT_TYPE_NON_PCM;
/** * snd_hdac_query_supported_pcm - query the supported PCM rates and formats * @codec: the codec object * @nid: NID to query * @ratesp: the pointer to store the detected rate bitflags * @formatsp: the pointer to store the detected formats * @subformatsp: the pointer to store the detected subformats for S32_LE format * @bpsp: the pointer to store the detected format widths * * Queries the supported PCM rates and formats. The NULL @ratesp, @formatsp, * @subformatsp or @bpsp argument is ignored. * * Returns 0 if successful, otherwise a negative error code.
*/ int snd_hdac_query_supported_pcm(struct hdac_device *codec, hda_nid_t nid,
u32 *ratesp, u64 *formatsp, u32 *subformatsp, unsignedint *bpsp)
{ unsignedint i, val, wcaps;
wcaps = snd_hdac_get_wcaps(codec, nid);
val = query_pcm_param(codec, nid);
if (ratesp) {
u32 rates = 0; for (i = 0; i < AC_PAR_PCM_RATE_BITS; i++) { if (val & (1 << i))
rates |= rate_bits[i].alsa_bits;
} if (rates == 0) {
dev_err(&codec->dev, "rates == 0 (nid=0x%x, val=0x%x, ovrd=%i)\n",
nid, val,
(wcaps & AC_WCAP_FORMAT_OVRD) ? 1 : 0); return -EIO;
}
*ratesp = rates;
}
/** * snd_hdac_is_supported_format - Check the validity of the format * @codec: the codec object * @nid: NID to check * @format: the HD-audio format value to check * * Check whether the given node supports the format value. * * Returns true if supported, false if not.
*/ bool snd_hdac_is_supported_format(struct hdac_device *codec, hda_nid_t nid, unsignedint format)
{ int i; unsignedint val = 0, rate, stream;
val = query_pcm_param(codec, nid); if (!val) returnfalse;
rate = format & 0xff00; for (i = 0; i < AC_PAR_PCM_RATE_BITS; i++) if (rate_bits[i].hda_fmt == rate) { if (val & (1 << i)) break; returnfalse;
} if (i >= AC_PAR_PCM_RATE_BITS) returnfalse;
stream = query_stream_param(codec, nid); if (!stream) returnfalse;
if (stream & AC_SUPFMT_PCM) { switch (format & 0xf0) { case 0x00: if (!(val & AC_SUPPCM_BITS_8)) returnfalse; break; case 0x10: if (!(val & AC_SUPPCM_BITS_16)) returnfalse; break; case 0x20: if (!(val & AC_SUPPCM_BITS_20)) returnfalse; break; case 0x30: if (!(val & AC_SUPPCM_BITS_24)) returnfalse; break; case 0x40: if (!(val & AC_SUPPCM_BITS_32)) returnfalse; break; default: returnfalse;
}
} else { /* FIXME: check for float32 and AC3? */
}
/** * 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, unsignedint verb, unsignedint 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, unsignedint verb, unsignedint 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, unsignedint target_state)
{ unsignedint state = codec_read(hdac, nid, 0,
AC_VERB_GET_POWER_STATE, 0);
if (state & AC_PWRST_ERROR) returntrue;
state = (state >> 4) & 0x0f; return (state == target_state);
}
EXPORT_SYMBOL_GPL(snd_hdac_check_power_state); /** * snd_hdac_sync_power_state - wait until actual power state matches * with the target state * * @codec: the HDAC device * @nid: NID to send the command * @power_state: target power state to wait for * * Return power state or PS_ERROR if codec rejects GET verb.
*/ unsignedint snd_hdac_sync_power_state(struct hdac_device *codec,
hda_nid_t nid, unsignedint power_state)
{ unsignedlong end_time = jiffies + msecs_to_jiffies(500); unsignedint state, actual_state, count;
for (count = 0; count < 500; count++) {
state = snd_hdac_codec_read(codec, nid, 0,
AC_VERB_GET_POWER_STATE, 0); if (state & AC_PWRST_ERROR) {
msleep(20); break;
}
actual_state = (state >> 4) & 0x0f; if (actual_state == power_state) break; if (time_after_eq(jiffies, end_time)) break; /* wait until the codec reachs to the target state */
msleep(1);
} return state;
}
EXPORT_SYMBOL_GPL(snd_hdac_sync_power_state);
Messung V0.5
¤ Dauer der Verarbeitung: 0.32 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.