Lines Matching +full:reset +full:- +full:bps
1 // SPDX-License-Identifier: GPL-2.0-only
3 * HD-audio codec core device
28 * snd_hdac_device_init - initialize the HD-audio codec base device
48 dev = &codec->dev;
50 dev->parent = bus->dev;
51 dev->bus = &snd_hda_bus_type;
52 dev->release = default_release;
53 dev->groups = hdac_dev_attr_groups;
57 codec->bus = bus;
58 codec->addr = addr;
59 codec->type = HDA_DEV_CORE;
60 mutex_init(&codec->widget_lock);
61 mutex_init(&codec->regmap_lock);
62 pm_runtime_set_active(&codec->dev);
63 pm_runtime_get_noresume(&codec->dev);
64 atomic_set(&codec->in_pm, 0);
71 codec->vendor_id = snd_hdac_read_parm(codec, AC_NODE_ROOT,
73 if (codec->vendor_id == -1) {
77 codec->vendor_id = snd_hdac_read_parm(codec, AC_NODE_ROOT,
81 codec->subsystem_id = snd_hdac_read_parm(codec, AC_NODE_ROOT,
83 codec->revision_id = snd_hdac_read_parm(codec, AC_NODE_ROOT,
87 if (!codec->afg && !codec->mfg) {
89 err = -ENODEV;
93 fg = codec->afg ? codec->afg : codec->mfg;
99 codec->power_caps = snd_hdac_read_parm(codec, fg, AC_PAR_POWER_STATE);
101 if (codec->subsystem_id == -1 || codec->subsystem_id == 0)
103 &codec->subsystem_id);
109 codec->chip_name = kasprintf(GFP_KERNEL, "ID %x",
110 codec->vendor_id & 0xffff);
111 if (!codec->chip_name) {
112 err = -ENOMEM;
119 put_device(&codec->dev);
125 * snd_hdac_device_exit - clean up the HD-audio codec base device
130 pm_runtime_put_noidle(&codec->dev);
132 pm_runtime_set_suspended(&codec->dev);
133 snd_hdac_bus_remove_device(codec->bus, codec);
134 kfree(codec->vendor_name);
135 kfree(codec->chip_name);
140 * snd_hdac_device_register - register the hd-audio codec base device
147 err = device_add(&codec->dev);
150 scoped_guard(mutex, &codec->widget_lock) {
154 device_del(&codec->dev);
163 * snd_hdac_device_unregister - unregister the hd-audio codec base device
168 if (device_is_registered(&codec->dev)) {
169 scoped_guard(mutex, &codec->widget_lock) {
172 device_del(&codec->dev);
173 snd_hdac_bus_remove_device(codec->bus, codec);
179 * snd_hdac_device_set_chip_name - set/update the codec name
193 return -ENOMEM;
194 kfree(codec->chip_name);
195 codec->chip_name = newname;
201 * snd_hdac_codec_modalias - give the module alias name
211 codec->vendor_id, codec->revision_id, codec->type);
216 * snd_hdac_make_cmd - compose a 32bit command word to be sent to the
217 * HD-audio controller
223 * Return an encoded command verb or -1 for error.
230 addr = codec->addr;
233 dev_err(&codec->dev, "out of range cmd %x:%x:%x:%x\n",
235 return -1;
246 * snd_hdac_exec_verb - execute an encoded verb
260 if (codec->exec_verb)
261 return codec->exec_verb(codec, cmd, flags, res);
262 return snd_hdac_bus_exec_verb(codec->bus, codec->addr, cmd, res);
267 * snd_hdac_read - execute a verb
286 * _snd_hdac_read_parm - read a parmeter
305 * snd_hdac_read_parm_uncached - read a codec parameter without caching
310 * Returns -1 for error. If you need to distinguish the error more
320 return -1;
326 * snd_hdac_override_parm - override read-only parameters
338 if (!codec->regmap)
339 return -EINVAL;
341 codec->caps_overwriting = true;
343 codec->caps_overwriting = false;
349 * snd_hdac_get_sub_nodes - get start NID and number of subtree nodes
363 if (parm == -1) {
386 codec->afg = nid;
387 codec->afg_function_id = function_id & 0xff;
388 codec->afg_unsol = (function_id >> 8) & 1;
391 codec->mfg = nid;
392 codec->mfg_function_id = function_id & 0xff;
393 codec->mfg_unsol = (function_id >> 8) & 1;
402 * snd_hdac_refresh_widgets - Reset the widget start/end nodes
414 guard(mutex)(&codec->widget_lock);
415 nums = snd_hdac_get_sub_nodes(codec, codec->afg, &start_nid);
417 dev_err(&codec->dev, "cannot read sub nodes for FG 0x%02x\n",
418 codec->afg);
419 return -EINVAL;
426 codec->num_nodes = nums;
427 codec->start_nid = start_nid;
428 codec->end_nid = start_nid + nums;
444 if (parm == -1)
450 * snd_hdac_get_connections - get a widget connection list
458 * given array size, it returns -ENOSPC.
485 mask = (1 << (shift-1)) - 1;
513 return -EIO;
515 range_val = !!(parm & (1 << (shift-1))); /* ranges */
518 dev_dbg(&codec->dev,
527 dev_warn(&codec->dev,
535 return -ENOSPC;
543 return -ENOSPC;
556 * snd_hdac_power_up - power up the codec
567 return pm_runtime_get_sync(&codec->dev);
572 * snd_hdac_power_down - power down the codec
579 struct device *dev = &codec->dev;
586 * snd_hdac_power_up_pm - power up the codec
590 * which may be called by PM suspend/resume again. OTOH, if a power-up
598 if (!atomic_inc_not_zero(&codec->in_pm))
605 * already powered up. Returns -1 if not powered up, 1 if incremented
610 if (!atomic_inc_not_zero(&codec->in_pm)) {
611 int ret = pm_runtime_get_if_active(&codec->dev);
613 return -1;
621 * snd_hdac_power_down_pm - power down the codec
631 if (atomic_dec_if_positive(&codec->in_pm) < 0)
657 { 0x13f6, "C-Media" },
665 { 0x434d, "C-Media" },
675 u16 vendor_id = codec->vendor_id >> 16;
677 for (c = hda_vendor_ids; c->id; c++) {
678 if (c->id == vendor_id) {
679 codec->vendor_name = kstrdup(c->name, GFP_KERNEL);
680 return codec->vendor_name ? 0 : -ENOMEM;
684 codec->vendor_name = kasprintf(GFP_KERNEL, "Generic %04x", vendor_id);
685 return codec->vendor_name ? 0 : -ENOMEM;
699 (AC_FMT_BASE_##base##K | (((mult) - 1) << AC_FMT_MULT_SHIFT) | \
700 (((div) - 1) << AC_FMT_DIV_SHIFT))
751 * snd_hdac_stream_format_bits - obtain bits per sample value.
778 * snd_hdac_stream_format - convert format parameters to SDxFMT value.
802 val |= channels - 1;
829 * snd_hdac_spdif_stream_format - convert format parameters to SDxFMT value.
833 * @spdif_ctls: HD-audio SPDIF status bits (0 if irrelevant).
853 if (nid != codec->afg &&
856 if (!val || val == -1)
857 val = snd_hdac_read_parm(codec, codec->afg, AC_PAR_PCM);
858 if (!val || val == -1)
867 if (!streams || streams == -1)
868 streams = snd_hdac_read_parm(codec, codec->afg, AC_PAR_STREAM);
869 if (!streams || streams == -1)
875 * snd_hdac_query_supported_pcm - query the supported PCM rates and formats
904 dev_err(&codec->dev,
908 return -EIO;
914 unsigned int streams, bps;
920 return -EIO;
922 bps = 0;
926 bps = 8;
930 bps = 16;
935 bps = 20;
940 bps = 24;
948 bps = 32;
955 if (!bps)
956 bps = 32;
965 bps = 8;
968 dev_err(&codec->dev,
973 return -EIO;
980 *bpsp = bps;
988 * snd_hdac_is_supported_format - Check the validity of the format
991 * @format: the HD-audio format value to check
1061 return -1;
1075 * snd_hdac_codec_read - send a command and get the response
1084 * Returns the obtained response value, or -1 for an error.
1094 * snd_hdac_codec_write - send a single command without waiting for response
1113 * snd_hdac_check_power_state - check whether the actual power state matches
1135 * snd_hdac_sync_power_state - wait until actual power state matches