Lines Matching +full:loongson +full:- +full:audio

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; in snd_hdac_device_init()
50 dev->parent = bus->dev; in snd_hdac_device_init()
51 dev->bus = &snd_hda_bus_type; in snd_hdac_device_init()
52 dev->release = default_release; in snd_hdac_device_init()
53 dev->groups = hdac_dev_attr_groups; in snd_hdac_device_init()
57 codec->bus = bus; in snd_hdac_device_init()
58 codec->addr = addr; in snd_hdac_device_init()
59 codec->type = HDA_DEV_CORE; in snd_hdac_device_init()
60 mutex_init(&codec->widget_lock); in snd_hdac_device_init()
61 mutex_init(&codec->regmap_lock); in snd_hdac_device_init()
62 pm_runtime_set_active(&codec->dev); in snd_hdac_device_init()
63 pm_runtime_get_noresume(&codec->dev); in snd_hdac_device_init()
64 atomic_set(&codec->in_pm, 0); in snd_hdac_device_init()
71 codec->vendor_id = snd_hdac_read_parm(codec, AC_NODE_ROOT, in snd_hdac_device_init()
73 if (codec->vendor_id == -1) { in snd_hdac_device_init()
77 codec->vendor_id = snd_hdac_read_parm(codec, AC_NODE_ROOT, in snd_hdac_device_init()
81 codec->subsystem_id = snd_hdac_read_parm(codec, AC_NODE_ROOT, in snd_hdac_device_init()
83 codec->revision_id = snd_hdac_read_parm(codec, AC_NODE_ROOT, in snd_hdac_device_init()
87 if (!codec->afg && !codec->mfg) { in snd_hdac_device_init()
89 err = -ENODEV; in snd_hdac_device_init()
93 fg = codec->afg ? codec->afg : codec->mfg; in snd_hdac_device_init()
99 codec->power_caps = snd_hdac_read_parm(codec, fg, AC_PAR_POWER_STATE); in snd_hdac_device_init()
101 if (codec->subsystem_id == -1 || codec->subsystem_id == 0) in snd_hdac_device_init()
103 &codec->subsystem_id); in snd_hdac_device_init()
109 codec->chip_name = kasprintf(GFP_KERNEL, "ID %x", in snd_hdac_device_init()
110 codec->vendor_id & 0xffff); in snd_hdac_device_init()
111 if (!codec->chip_name) { in snd_hdac_device_init()
112 err = -ENOMEM; in snd_hdac_device_init()
119 put_device(&codec->dev); in snd_hdac_device_init()
125 * snd_hdac_device_exit - clean up the HD-audio codec base device
130 pm_runtime_put_noidle(&codec->dev); in snd_hdac_device_exit()
132 pm_runtime_set_suspended(&codec->dev); in snd_hdac_device_exit()
133 snd_hdac_bus_remove_device(codec->bus, codec); in snd_hdac_device_exit()
134 kfree(codec->vendor_name); in snd_hdac_device_exit()
135 kfree(codec->chip_name); in snd_hdac_device_exit()
140 * snd_hdac_device_register - register the hd-audio codec base device
147 err = device_add(&codec->dev); in snd_hdac_device_register()
150 mutex_lock(&codec->widget_lock); in snd_hdac_device_register()
152 mutex_unlock(&codec->widget_lock); in snd_hdac_device_register()
154 device_del(&codec->dev); in snd_hdac_device_register()
163 * snd_hdac_device_unregister - unregister the hd-audio codec base device
168 if (device_is_registered(&codec->dev)) { in snd_hdac_device_unregister()
169 mutex_lock(&codec->widget_lock); in snd_hdac_device_unregister()
171 mutex_unlock(&codec->widget_lock); in snd_hdac_device_unregister()
172 device_del(&codec->dev); in snd_hdac_device_unregister()
173 snd_hdac_bus_remove_device(codec->bus, codec); in snd_hdac_device_unregister()
179 * snd_hdac_device_set_chip_name - set/update the codec name
193 return -ENOMEM; in snd_hdac_device_set_chip_name()
194 kfree(codec->chip_name); in snd_hdac_device_set_chip_name()
195 codec->chip_name = newname; in snd_hdac_device_set_chip_name()
201 * snd_hdac_codec_modalias - give the module alias name
211 codec->vendor_id, codec->revision_id, codec->type); in snd_hdac_codec_modalias()
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; in snd_hdac_make_cmd()
233 dev_err(&codec->dev, "out of range cmd %x:%x:%x:%x\n", in snd_hdac_make_cmd()
235 return -1; in snd_hdac_make_cmd()
246 * snd_hdac_exec_verb - execute an encoded verb
260 if (codec->exec_verb) in snd_hdac_exec_verb()
261 return codec->exec_verb(codec, cmd, flags, res); in snd_hdac_exec_verb()
262 return snd_hdac_bus_exec_verb(codec->bus, codec->addr, cmd, res); in snd_hdac_exec_verb()
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; in snd_hdac_read_parm_uncached()
326 * snd_hdac_override_parm - override read-only parameters
338 if (!codec->regmap) in snd_hdac_override_parm()
339 return -EINVAL; in snd_hdac_override_parm()
341 codec->caps_overwriting = true; in snd_hdac_override_parm()
343 codec->caps_overwriting = false; in snd_hdac_override_parm()
349 * snd_hdac_get_sub_nodes - get start NID and number of subtree nodes
363 if (parm == -1) { in snd_hdac_get_sub_nodes()
386 codec->afg = nid; in setup_fg_nodes()
387 codec->afg_function_id = function_id & 0xff; in setup_fg_nodes()
388 codec->afg_unsol = (function_id >> 8) & 1; in setup_fg_nodes()
391 codec->mfg = nid; in setup_fg_nodes()
392 codec->mfg_function_id = function_id & 0xff; in setup_fg_nodes()
393 codec->mfg_unsol = (function_id >> 8) & 1; in setup_fg_nodes()
402 * snd_hdac_refresh_widgets - Reset the widget start/end nodes
414 mutex_lock(&codec->widget_lock); in snd_hdac_refresh_widgets()
415 nums = snd_hdac_get_sub_nodes(codec, codec->afg, &start_nid); in snd_hdac_refresh_widgets()
417 dev_err(&codec->dev, "cannot read sub nodes for FG 0x%02x\n", in snd_hdac_refresh_widgets()
418 codec->afg); in snd_hdac_refresh_widgets()
419 err = -EINVAL; in snd_hdac_refresh_widgets()
427 codec->num_nodes = nums; in snd_hdac_refresh_widgets()
428 codec->start_nid = start_nid; in snd_hdac_refresh_widgets()
429 codec->end_nid = start_nid + nums; in snd_hdac_refresh_widgets()
431 mutex_unlock(&codec->widget_lock); in snd_hdac_refresh_widgets()
447 if (parm == -1) in get_num_conns()
453 * snd_hdac_get_connections - get a widget connection list
461 * given array size, it returns -ENOSPC.
488 mask = (1 << (shift-1)) - 1; in snd_hdac_get_connections()
516 return -EIO; in snd_hdac_get_connections()
518 range_val = !!(parm & (1 << (shift-1))); /* ranges */ in snd_hdac_get_connections()
521 dev_dbg(&codec->dev, in snd_hdac_get_connections()
530 dev_warn(&codec->dev, in snd_hdac_get_connections()
538 return -ENOSPC; in snd_hdac_get_connections()
546 return -ENOSPC; in snd_hdac_get_connections()
559 * snd_hdac_power_up - power up the codec
570 return pm_runtime_get_sync(&codec->dev); in snd_hdac_power_up()
575 * snd_hdac_power_down - power down the codec
582 struct device *dev = &codec->dev; in snd_hdac_power_down()
590 * snd_hdac_power_up_pm - power up the codec
594 * which may be called by PM suspend/resume again. OTOH, if a power-up
602 if (!atomic_inc_not_zero(&codec->in_pm)) in snd_hdac_power_up_pm()
609 * already powered up. Returns -1 if not powered up, 1 if incremented
614 if (!atomic_inc_not_zero(&codec->in_pm)) { in snd_hdac_keep_power_up()
615 int ret = pm_runtime_get_if_active(&codec->dev); in snd_hdac_keep_power_up()
617 return -1; in snd_hdac_keep_power_up()
625 * snd_hdac_power_down_pm - power down the codec
635 if (atomic_dec_if_positive(&codec->in_pm) < 0) in snd_hdac_power_down_pm()
649 { 0x0014, "Loongson" },
661 { 0x13f6, "C-Media" },
669 { 0x434d, "C-Media" },
679 u16 vendor_id = codec->vendor_id >> 16; in get_codec_vendor_name()
681 for (c = hda_vendor_ids; c->id; c++) { in get_codec_vendor_name()
682 if (c->id == vendor_id) { in get_codec_vendor_name()
683 codec->vendor_name = kstrdup(c->name, GFP_KERNEL); in get_codec_vendor_name()
684 return codec->vendor_name ? 0 : -ENOMEM; in get_codec_vendor_name()
688 codec->vendor_name = kasprintf(GFP_KERNEL, "Generic %04x", vendor_id); in get_codec_vendor_name()
689 return codec->vendor_name ? 0 : -ENOMEM; in get_codec_vendor_name()
703 (AC_FMT_BASE_##base##K | (((mult) - 1) << AC_FMT_MULT_SHIFT) | \
704 (((div) - 1) << AC_FMT_DIV_SHIFT))
755 * snd_hdac_stream_format_bits - obtain bits per sample value.
782 * snd_hdac_stream_format - convert format parameters to SDxFMT value.
806 val |= channels - 1; in snd_hdac_stream_format()
833 * snd_hdac_spdif_stream_format - convert format parameters to SDxFMT value.
837 * @spdif_ctls: HD-audio SPDIF status bits (0 if irrelevant).
857 if (nid != codec->afg && in query_pcm_param()
860 if (!val || val == -1) in query_pcm_param()
861 val = snd_hdac_read_parm(codec, codec->afg, AC_PAR_PCM); in query_pcm_param()
862 if (!val || val == -1) in query_pcm_param()
871 if (!streams || streams == -1) in query_stream_param()
872 streams = snd_hdac_read_parm(codec, codec->afg, AC_PAR_STREAM); in query_stream_param()
873 if (!streams || streams == -1) in query_stream_param()
879 * snd_hdac_query_supported_pcm - query the supported PCM rates and formats
908 dev_err(&codec->dev, in snd_hdac_query_supported_pcm()
912 return -EIO; in snd_hdac_query_supported_pcm()
924 return -EIO; in snd_hdac_query_supported_pcm()
972 dev_err(&codec->dev, in snd_hdac_query_supported_pcm()
977 return -EIO; in snd_hdac_query_supported_pcm()
992 * snd_hdac_is_supported_format - Check the validity of the format
995 * @format: the HD-audio format value to check
1065 return -1; in codec_read()
1079 * snd_hdac_codec_read - send a command and get the response
1088 * Returns the obtained response value, or -1 for an error.
1098 * snd_hdac_codec_write - send a single command without waiting for response
1117 * snd_hdac_check_power_state - check whether the actual power state matches
1139 * snd_hdac_sync_power_state - wait until actual power state matches